[Tutor] running python from windows command prompt
Dave Angel
davea at davea.name
Wed Apr 10 14:14:21 CEST 2013
(Please don't hijack a thread with an unrelated question. You're no
doing yourself any favors, as any decent thread-viewer will hide your
new subject line, and group the whole thread with its original title.
That can cause your query to be ignored by many of the readers.)
To start a new thread, send the email to tutor at pyhon.org.
On 04/10/2013 04:57 AM, Arijit Ukil wrote:
> I like to run a python program "my_python.py" from windows command
> prompt. This program ( a function called testing) takes input as block
> data (say data = [1,2,3,4] and outputs processed single data.
>
> import math
>
> def avrg(data):
> return sum(data)/len(data)
>
> def testing (data):
> val = avrg(data)
> out = pow(val,2)
> return out
>
This program is missing some top-level code, so nobody is calling
testing(). As it stands, it does nothing visible to the user.
You say the program should "take input" from the user, but there are at
least 3 ways to do that.
1) The user could edit the source file, adding lines like:
mydata = (1, 9,43,7)
print ("results: %d" % testing(mydata) )
2) The user could put the source data into a file, such as a csv file
3) The user could have the parameters on the command line, after the
script name.
python my_python.py 1 9 43 7
Each of 2 and 3 require you to add some logic to process the data file
and/or commandline.
Please specify the problem more completely, and show us what you tried,
and somebody will probably be able to help you.
Also specify the Python version, as it can make a difference. For
example, avrg() function in Python 2.7 assumes either that its arguments
include a float, or that you want only an integer result. In Python 3,
it'll switch to float.
--
DaveA
More information about the Tutor
mailing list