FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!

Python - Files through CMD, Shell




The much bigger new challenge I have encountered in running through Python the Hard Way has been using files, accessing files, directly.

In part, the challenge was increased as I am unable, on one computer, to save my own Python files in the main Python directory.

On the computer in which I am able, I can call the files directly using CMD.

The first step I need to do is to write into the CMD
>cd\PythonNN (where NN is the version number, in my case 27)

from there, I am able to complete the rest of the path to my file:
>Libs\idlelibs\myfile.py

And whence, it runs.

I found it quite gratifying to run my own script directly through the computer rather than the Shell.

On both computers, I am able to run scripts through the Shell direct. This is particularly useful as Python the Hard Way has a number of exercises in which you must be able to do this.

For me to do this, I needed to do it this way:

first, in Shell,

>from subprocess import *
then
>call(["C:/PATH/PythonNN/Python.exe", "C:/PATH/myfile.py", 'arg1', 'arg2'])

Where PATH is the path leading to the execute or file and NN is the version number.

I also note that 1)it comes up in another window 2)on the Shell it provides a value 0 if the script ran without errors and 3)on one of my computers I need to import time and use sleep to keep the screen up for long enough to read it unless there is user input.



0 blog comments below




FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.