When I run the command: “python manage.py shell < script.py” I get a an error message “NameError: name ‘socket’ is not defined” and when I use exec function to run the script.py inside “python manage.py shell” I don’t have any errors. Can someone explain me what’s the problem with the first command?
#socket.py
import socket
def allowed_gai_family():
return socket.AF_INET
print(allowed_gai_family())
I cannot recreate this behavior. This includes running it both under shell and shell_plus, and even trying variations like cat script.py | python manage.py shell
At no time do I get the error you’re describing. The only thing I can think of is a non-printable character in there somewhere causing issues.
If you’re calling your script socket.py
, it may shadow the standard library socket module. Call it something else like script.py
, as Ken used.
Good catch. Actually, I thought they were using ‘script.py’