using reload(module)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Patrick C
    New Member
    • Apr 2007
    • 54

    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(modolena me) i only get this...

    Code:
    >>> reload(eps)
    <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
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    reload() works like this:[code=Python]>>> import xtest
    >>> xtest.a
    'This is the original assignment'
    >>> import xtest
    >>> xtest.a
    'This is the original assignment'
    >>> reload(xtest)
    <module 'xtest' from 'C:\Python23\li b\xtest.py'>
    >>> xtest.a
    'This is the revised assignment'
    >>> [/code]

    Comment

    • Patrick C
      New Member
      • Apr 2007
      • 54

      #3
      Originally posted by bvdet
      reload() works like this:[code=Python]>>> import xtest
      >>> xtest.a
      'This is the original assignment'
      >>> import xtest
      >>> xtest.a
      'This is the original assignment'
      >>> reload(xtest)
      <module 'xtest' from 'C:\Python23\li b\xtest.py'>
      >>> xtest.a
      'This is the revised assignment'
      >>> [/code]

      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

      Comment

      • Patrick C
        New Member
        • Apr 2007
        • 54

        #4
        Originally posted by Patrick C
        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

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          Originally posted by Patrick C
          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!

          Comment

          Working...