views:

1194

answers:

4

I'm trying to reload a module I have already inputted.

I understand that you only need to input once and retyping the input command won't produce the same affect without having had exited out of python's command prompt.

I just don't understand why this statement: reload (script4.py)

is giving me:

Traceback (most recent call last):

File "(stdin)", line 1, in (module)

NameError: name 'reload' is not defined

Also can someone explain step by step what that error message means?

AFTER FIRST 2 ANSWERS:

Using reload(script4) does NOT reload the module.

name reload is still "not defined".

A: 

You deleted your __builtins__ variable.

How to fix this? Don't delete __builtins__.

Also can someone explain step by step what that error message means?

It means python can't find the function "reload".

reload (script4.py)

This is incorrect. if you did "import script4", then you must do "reload(script4)"

Unknown
A: 

It looks like you have a space between the function name reload, and the first parenthesis. Also, you don't need to add .py to the module name--that's how the modules are identified by the interpreter.

The space after the function name is legal.
Ori Pessach
+8  A: 

reload is not a builtin in Python 3, so if that's what you're using the problem you see is expected. If you're on Python 2.*, what does dir(__builtins__) say...?

Edit: questioner specified they're on 3.*, so (if reloading is truly a must) they should use imp.reload (from the imp standard library module).

Alex Martelli
I am using python 3.1So what is the expression that correlates to 2.*'s reload in Python 3.1?
Lonnie Price
If you _must_ reload in `3.*`, see e.g. http://docs.python.org/dev/py3k/library/imp.html?highlight=reload#imp.reload .
Alex Martelli
+1  A: 

The .py looks like the problem. The following should work

import script4
reload(script4)
Fergal