0

I'm having problems with trying to get python to recognize the latest file.

Take this simple function for example

def printme( str ):
   "This prints a passed string into this function"
   print(str)
   return

I then navigate to the directory and did an

import printme

Ran printme printme.printme("Hello"). It works fine.

I then I updated the function to print Hi. I then remove the module using del printme

def printme( str ):
       "This prints a passed string into this function"
       print('Hi' + str)
       return

Why doesn't python print "Hi" in front of the string?

Pat
  • 627
  • 1
  • 9
  • 24

1 Answers1

4

The contents of the module have already been loaded. Modules aren't loaded again and again every time they are imported. (That would be quite wasteful.) To load the module again, try

reload(printme)
khelwood
  • 55,782
  • 14
  • 81
  • 108
  • Related, `printme` was not the only reference to the module. If you had also run `import sys; del sys.modules['printme']`, then the module would have been removed from memory, and `import printme` would have actually reloaded the module. – chepner Sep 09 '14 at 15:52