Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61770

Re: Downloading multiple files based on info extracted from CSV

From John Gordon <gordon@panix.com>
Newsgroups comp.lang.python
Subject Re: Downloading multiple files based on info extracted from CSV
Date 2013-12-12 22:21 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <l8dctq$gb8$1@reader1.panix.com> (permalink)
References <88346903-2af8-48cd-9829-37cedb717ae5@googlegroups.com>

Show all headers | 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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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