Printing in a Python Windows Loop

I noticed something strange when using the Django shell on Windows. I tested different calls with a simple script that:

for it in range(5): 
    print(it)

When I type this script in a Python environment or manage.py shellit works fine. But when I put this code in a file and execute it with python manage.py shell < myFile.py, nothing is displayed there, when I print in loops, then the output is "...".

I overcame this limitation by running it in the built-in console from Eclipse, but I am very curious why the output does not display well when the script is called from the output file.

Does anyone know what happened?

+4
source share
3 answers

It works as follows:

echo 'execfile("myFile.py")' | python manage.py shell
+1

, , Python 3+, execfile ,

echo 'execfile("myFile.py")' | python manage.py shell

echo exec(open('MyFile.py').read()) | python manage.py shell

!

+2

echo "for i in range(5): print i" | python manage.py shell

+1

Source: https://habr.com/ru/post/1532130/


All Articles