467,868 Members | 1,311 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,868 developers. It's quick & easy.

using reload(module)

Someone suggested I use reload when trying to reopen a script i've written (the suggestion was made in response to the problem ive reposted below)

however when i do reload(modolename) i only get this...

Expand|Select|Wrap|Line Numbers
  1. >>> reload(eps)
  2. <module 'eps' from 'eps.pyc'>
i know this is incredibly amateur to say, but the person who suggested it had their reload bolded and in color, as if it was recognized function such as import. Reload didn't do that for me. should it?

either way when i try to get a variable out of eps, that is from eps import stuff

stuff is the same (when it should be different) from when i originally imported eps, not what it would be after i reloaded it. In between the import and the reload i changed the text file that data is drawn from (see below).

any help would be much appreciated.

-pc

original problem:

When I'm testing a script in PythonWin after I import it once, it won't recognize some changes i've made sometimes. Like if its a script to do a web scrape...
the 1st time i try import testscript, it'll take the couple of seconds that is needed to do the scrape. thats good.

Then lets say i change a part of the scrape. For example one thing i often do is have a text file where i have names. My script will take a name out of the text file hten use it in a web address in order to do a scrape. for example
i'll have this pageroot "http://finance.google.com/finance?fstype=ii&q="
then i'll take a name "ge" from a text file and use it to find this web page to go to ... "http://finance.google.com/finance?fstype=ii&q=ge".

if i just import testscript again, then it won't recognize that i've changed the web address that i'm going to.

Does that make sense, should that happen? if so, how cna i get around it w/o closing and reopening PythonWin.

thanks
Oct 11 '07 #1
  • viewed: 1940
Share:
4 Replies
bvdet
Expert Mod 2GB
reload() works like this:
Expand|Select|Wrap|Line Numbers
  1. >>> import xtest
  2. >>> xtest.a
  3. 'This is the original assignment'
  4. >>> import xtest
  5. >>> xtest.a
  6. 'This is the original assignment'
  7. >>> reload(xtest)
  8. <module 'xtest' from 'C:\Python23\lib\xtest.py'>
  9. >>> xtest.a
  10. 'This is the revised assignment'
  11. >>> 
Oct 11 '07 #2
reload() works like this:
Expand|Select|Wrap|Line Numbers
  1. >>> import xtest
  2. >>> xtest.a
  3. 'This is the original assignment'
  4. >>> import xtest
  5. >>> xtest.a
  6. 'This is the original assignment'
  7. >>> reload(xtest)
  8. <module 'xtest' from 'C:\Python23\lib\xtest.py'>
  9. >>> xtest.a
  10. 'This is the revised assignment'
  11. >>> 

So is reload not actually equivalent to closing somethign like PythonWin then reopening and importing again?

Because if i do the long process it notices changes made in the text file that my script draws from. If i do a reload it doesn't....

any ideas how i can get it to recognize changes i' ve made in the text file that a script reads from w/o close and reopening PythonWin?

thanks
Oct 11 '07 #3
So is reload not actually equivalent to closing somethign like PythonWin then reopening and importing again?

Because if i do the long process it notices changes made in the text file that my script draws from. If i do a reload it doesn't....

any ideas how i can get it to recognize changes i' ve made in the text file that a script reads from w/o close and reopening PythonWin?

thanks
so i broke it down and did a small test and it worked, meaning there must be something funny w/ my script/logic....we'll be revisiting this subject soon, hopefully someone will be willing to help if i need it later
Oct 11 '07 #4
bartonc
Expert 4TB
so i broke it down and did a small test and it worked
Atta way, Patrick! That's the way to resolved issues.
we'll be revisiting this subject soon, hopefully someone will be willing to help if i need it later
Always!
Oct 11 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

66 posts views Thread by Ellinghaus, Lance | last post: by
2 posts views Thread by Robert Rothenberg | last post: by
4 posts views Thread by Lonnie Princehouse | last post: by
30 posts views Thread by Franck PEREZ | last post: by
3 posts views Thread by =?ISO-8859-1?Q?Gregory_Pi=F1ero?= | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.