1

Is there any way to run directly python script in windows console such as Unix system?

#! /usr/bin/env python3.3
2
  • Possible duplicate of Shebang Notation: Python Scripts on Windows and Linux? Commented Aug 30, 2013 at 13:27
  • i think emulating unix behavior on windows isn't really a good idea. try something like what Stefan Näwe suggested below, or maybe fiddle with the "start" or "open" commands. if you really want your system to behave like a unix, you should consider using a unix or linux based one. Commented Aug 30, 2013 at 13:39

3 Answers 3

3

Or create a .BAT file that doubles as a python script:

@echo off
rem = '''
echo This is "%~f0" before Python

python -x "%~f0" %*

echo This is "%~f0" after Python

goto :end
'''

print "------------- Python code starts here --------------"
import sys
print sys.path
print sys.argv
print "------------- Python code ends here ----------------"

rem = '''
:end
rem '''
Sign up to request clarification or add additional context in comments.

Comments

0

Just double clicking a file with .py extension on Windows executes the script.

2 Comments

is there any way to run from CMD?
you mean besides python script_file.py? I'm not on windows and can't test, but try simply entering the filename and hitting Enter.
0

If you use the Python GUI + command line, you can run any .py file.

http://www.python.org/download/releases/3.3.2/#download

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.