1

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

#! /usr/bin/env python3.3
  • Possible duplicate of [Shebang Notation: Python Scripts on Windows and Linux?](http://stackoverflow.com/questions/7574453/shebang-notation-python-scripts-on-windows-and-linux) – Frédéric Hamidi Aug 30 '13 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. – nonchip Aug 30 '13 at 13:39

3 Answers3

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 '''
Stefan Näwe
  • 3,040
  • 1
  • 18
  • 19
0

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

mavili
  • 3,385
  • 4
  • 30
  • 46
  • is there any way to run from CMD? –  Aug 30 '13 at 13:33
  • 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. – mavili Aug 30 '13 at 13:34
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

honyovk
  • 2,717
  • 18
  • 26