Hello! Recently I've decided to try something new and started watching the google tutorials for python (http://www.youtube.com/watch?v=haycL41dAhg) ... most of it was very clear and I've learned a lot... but since I am using a Win 7 and the man presenting is using a Mac, there were some difficulties... so my question here is... how do I start a .py program that takes a .txt file (eg. has a function to count the words in there)? In the video he just writes it into the terminal.. I'm thinking command prompt.. but I'm very confused :( Thanks in advance (sorry if it's hard to understand, I'm not a native english speaker)
Loading a file through python using Windows
Collapse
X
-
Open your command prompt. Change your current directory to the directory containing your script and data file, or you will need to enter the full path and file names. This assumes your python executable is on the system path.
At the command prompt, which may look something like "C:\Python27_64 >" enter:python script_name.py data_file_name. txtwhere "script_name.py " is the file name of your script and "data_file_name .txt" is the file name of your data file. In the example below, sys.argv[1] will be the file name of your data script. sys.argv[0] is the name of the python script.
Code:import sys print sys.argv print open(sys.argv[1]).read()
Comment