Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61770
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!panix!gordon |
|---|---|
| From | John Gordon <gordon@panix.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Downloading multiple files based on info extracted from CSV |
| Date | Thu, 12 Dec 2013 22:21:46 +0000 (UTC) |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 50 |
| Message-ID | <l8dctq$gb8$1@reader1.panix.com> (permalink) |
| References | <88346903-2af8-48cd-9829-37cedb717ae5@googlegroups.com> |
| NNTP-Posting-Host | panix3.panix.com |
| X-Trace | reader1.panix.com 1386886906 16744 166.84.1.3 (12 Dec 2013 22:21:46 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Thu, 12 Dec 2013 22:21:46 +0000 (UTC) |
| User-Agent | nn/6.7.3 |
| Xref | csiph.com comp.lang.python:61770 |
Show key headers only | View raw
In <88346903-2af8-48cd-9829-37cedb717ae5@googlegroups.com> Matt Graves <tunacubes@gmail.com> writes:
> import urllib
> import csv
> urls = []
> clientname = []
> ###This will set column 7 to be a list of urls
> with open('clients.csv', 'r') as f:
> reader = csv.reader(f)
> for column in reader:
> urls.append(column[7])
> ###And this will set column 0 as a list of client names
> with open('clients.csv', 'r') as g:
> reader = csv.reader(g)
> for column in reader:
> clientname.append(column[0])
> ###This SHOULD plug in the URL for F, and the client name for G.
> def downloadFile(urls, clientname):
> urllib.urlretrieve(f, "%g.csv") % clientname
> downloadFile(f,g)
> When I run it, I get : AttributeError: 'file' object has no attribute
> 'strip'
I think you're passing the wrong arguments to downloadFile(). You're
calling downloadFile(f, g), but f and g are file objects. Don't you want
to pass urls and clientname instead?
Even if the correct arguments are passed to downloadFile, I think you're
using them incorrectly. You don't even use the urls argument, and
clientname is supposed to be a list, so why aren't you looping through
it?
You aren't using string interpolation correctly on the call to urlretrieve.
Assuming your intent was to build a string and pass it as the second
argument, you have the close-parenthesis in the wrong place. The call
should look like this:
urllib.urlretrieve(f, "%g.csv" % clientname)
"%g" returns a floating-point value. Did you mean "%s" instead?)
--
John Gordon Imagine what it must be like for a real medical doctor to
gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Downloading multiple files based on info extracted from CSV Matt Graves <tunacubes@gmail.com> - 2013-12-12 13:43 -0800
Re: Downloading multiple files based on info extracted from CSV Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-12 22:19 +0000
Re: Downloading multiple files based on info extracted from CSV Chris Angelico <rosuav@gmail.com> - 2013-12-13 09:20 +1100
Re: Downloading multiple files based on info extracted from CSV Matt Graves <tunacubes@gmail.com> - 2013-12-16 06:17 -0800
Re: Downloading multiple files based on info extracted from CSV John Gordon <gordon@panix.com> - 2013-12-12 22:21 +0000
Re: Downloading multiple files based on info extracted from CSV Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-12 20:52 -0500
csiph-web