NEWB problem with urllib2

P

Penn

I just installed PyDev into Eclipse using the 'update' method and did
the standard installation. I allowed it to Auto Configure itself and
ran a "Hello World" module to make sure I was in the ballpark.

I got an starting module up and have run "Hello World" but now am
stuck on getting urlopen to import from urllib2 for the following
example.

from urllib2 import * # doesn't give me an error
ur = urlopen("http://www.daniweb.com/forums/thread161312.html") #
gives me Undefined Variable: urlopen

so I tried just

import urllib2 # Eclipse gives "Unresolved Import"

Is urllib2 not on my path? Isn't urllib2 in the standard installation
and shouldn't that automatically be on my path? If not, how can I get
it on the path?

ThankS!!
 
S

Simon Forman

I just installed PyDev into Eclipse using the 'update' method and did
the standard installation.  I allowed it to Auto Configure itself and
ran a "Hello World" module to make sure I was in the ballpark.

I got an starting module up and have run "Hello World" but now am
stuck on getting urlopen to import from urllib2 for the following
example.

from urllib2 import *    # doesn't give me an error
ur = urlopen("http://www.daniweb.com/forums/thread161312.html") #
gives me Undefined Variable: urlopen

so I tried just

import urllib2        # Eclipse gives "Unresolved Import"

Is urllib2 not on my path?  Isn't urllib2 in the standard installation
and shouldn't that automatically be on my path?  If not, how can I get
it on the path?

ThankS!!

This sounds more like a PyDev and/or Eclipse problem than an urllib2 problem. :)

One thing you can check: open the "raw" python interpreter outside of
Eclipse and try importing urllib2 there. You might also try the
interpreter interface within Eclipse (if it provides one.)

HTH
 
P

Penn

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top