[Tutor] Running python from windows command prompt

Arijit Ukil arijit.ukil at tcs.com
Thu Apr 11 08:08:25 CEST 2013


Thanks for the help. Now I have modifed the code as:

import sys

def main(argv):

    data = int(sys.argv[1])
 
    avg = average (data)
 
    print "Average:", avg

def average(num_list):
    return sum(num_list)/len(num_list)

if __name__ == "__main__":
   main(sys.argv[1:])

When running in command line I am getting these errors:
In case 1. data = sys.argv[1]
In case 2, data = float(sys.argv[1])
In case 3, data = int (sys.argv[1])





Regards,
Arijit Ukil
Tata Consultancy Services
Mailto: arijit.ukil at tcs.com
Website: http://www.tcs.com
____________________________________________
Experience certainty.   IT Services
                        Business Solutions
                        Outsourcing
____________________________________________



From:
Alan Gauld <alan.gauld at btinternet.com>
To:
tutor at python.org
Date:
04/10/2013 10:58 PM
Subject:
Re: [Tutor] Running python from windows command prompt
Sent by:
"Tutor" <tutor-bounces+arijit.ukil=tcs.com at python.org>



On 10/04/13 13:32, 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.
>

Hopefully the code below is not your entire program. If it is it won't 
work. You define 2 functions but never call them.

Also you don't print anything so there is no visible output.
Finally this a code does not read the values from sys.argv.
(See my tutorial topic 'Talking to the user')

As for the error message, others have replied but basically you need
to either change to the folder that your file exists in or specify
the full path at the command prompt.

> import math
>
> def avrg(data):
>     return sum(data)/len(data)
>
> def testing (data):
>     val = avrg(data)
>     out = pow(val,2)
>     return out

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130411/ce7a1e8f/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 14160 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20130411/ce7a1e8f/attachment-0001.gif>


More information about the Tutor mailing list