NEWB problem with urllib2

Penn powderdrop at gmail.com
Mon Nov 9 20:48:01 EST 2009


Thanks Simon!

You are right.. I also believe it is something with Eclipse.

I've been working since... the module below runs.. but Eclipse is
still showing an error when I reference urlopen with a little red X...
saying it is an undefined variable in the IDE.. but not giving me an
runtime errors.




#URL LIBRARY
from urllib2 import *


def openfilereadaline(a):

    f = open(a)
    print f
    for line in f:
        print line.rstrip()
    f.close()

def openWebSite(a):

    ur = urlopen(a) #open url
    contents = ur.readlines()#readlines from url file
    fo = open("test.txt", "w")#open test.txt
    for line in contents:
        print "writing %s to a file" %(line,)
        fo.write(line)#write lines from url file to text file
    fo.close()#close text file

if __name__ == '__main__':

    openWebSite("http://www.daniweb.com/forums/thread161312.html")

    print "Hello World"



More information about the Python-list mailing list