myfile = open('ilist.txt')
for line in myfile.readlines():
print line
Best,
Scott
for line in myfile:
print line
--
Bill Evans
squareFACTOR
bi...@squarefactor.com
office:407.637.2419
> --
> You received this message because you are subscribed to the Google Groups "Orlando Python Users Group" group.
> To post to this group, send email to orlan...@googlegroups.com.
> To unsubscribe from this group, send email to orlando-pug...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/orlando-pug?hl=en.
>
>
There's nothing incorrect with that. Check your assumptions. - chad
Yes, I redirected the output to a file and indeed it is working.
I wasn't explicit about what I'm trying to do. My textfile is a
newline delimited list of approximately 30000 .jpg names to which i
want to prepend a URL and download. This is what I have now:
import sys
myfile = open('ilist.txt')
for line in myfile.readlines():
sys.stdout.write('http://BASEURL/')
print line
Which results in this output:
http://BASEURL/6401287.jpg
6401288.jpg
6403421.jpg
6403422.jpg
6403423.jpg
6403426.jpg
6406701.jpg
6407044.jpg
Brand new to Python, reading about how the for loop works. Any help appreciated!
import urllib
with open('ilist.txt') as myfile:
for line in myfile:
url = "http://%s/%s" % (hostname, urllib.quote(line.rstrip("\n")),)
download(url) # elftr
>>> import urllib
>>> urllib.urlretrieve("http://www.google.com/intl/en_ALL/images/logo.gif", "logo.gif")
('logo.gif', <httplib.HTTPMessage instance at 0x012F6288>)
this downloads logo.gif to the current directory ( and you can find
out the current directory in with os.getcwd() )
documentation is here: http://docs.python.org/library/urllib.html
On Mar 2, 10:33 am, Chad MILLER <chadm...@gmail.com> wrote:
Make an output file of URLs with Python, and then read up on wget's '-i' option.
-chris
> Make an output file of URLs with Python, and then read up on wget's '-i' option.
This is what I ended up doing. The problem was my textfile was
formatted with ^M as the newline character and the python script was
treating the entire file as one line.
Thanks everyone for your help.
For five years, Python has had universal-newline support. It should
understand all of \r, \n, and \r\n idioms, for most normal
line-oriented file-operations. file.readlines() is one the the dark
corners that I don't use or know about, but I am pretty sure that,
regardless of newline idiom, a typically compiled Python would have
done the right thing with
for line in file("foo"):
f(line)