1
votes

I am trying to run a script(myscript.py) using python manage.py shell < scripts/myscript.py but nothing happens.

Here is my code

myscript.py

def foo(x):
    print(x+1)

if __name__ == '__main__':
    x = 10
    foo(x)

any help please

Note:

I am new to django

I am using python 3.6 and django 1.10.6

1
Make your script print out __name__ and you will see why. - Klaus D.
What output and error messages do you get? - Red Cricket
@RedCricket there is no error messages. it looks like __name__ is not '__main__' Output: Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> >>> >>> >>> >>> >>> >>> ... ... ... ... ... ... ... ... ... ... >>> ... ... ... ... ... ... ... ... ... >>> ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... >>> >>> ... ... ... ... ... ... ... ... ... ... now exiting InteractiveConsole... - Pahara Siagian
@KlausD. ok thank you. I'll try it - Pahara Siagian

1 Answers

1
votes

Since you are importing that script into shell, value of variable __name__ will not be __main__ (it will be the module name myscript). That means here that part of code is not executing.

For more info