[Tutor] Python Script Testing

Alan Gauld alan.gauld at yahoo.co.uk
Thu Mar 15 14:53:45 EDT 2018


Please always use Reply All or Reply List when responding to list emails.

Farwarding to list...

On 15/03/18 17:47, Gaurav Parashar wrote:
> Opening the file inside the script seems the only possible solution.
> As far as I remember about the coursera course, the gave the input
> file, and we need to upload the output file, running the script on our
> local system. So, the above method should work.
>
> On 15 Mar 2018 11:13 pm, "Alan Gauld via Tutor" <tutor at python.org
> <mailto:tutor at python.org>> wrote:
>
>     On 15/03/18 16:56, Preeti Saxena wrote:
>     > Hi,
>     >    I am new to python. I am trying to test my program, like a
>     coursera
>     > submission, which takes run time arguments using "raw_input()".
>     Is there a
>     > way I can write all the input data into a file and pass it from
>     command
>     > line to the script?
>
>     In normal Python yes, you can simply pass the file name as an
>     argument to the program or you can use input redirection to
>     read the data from the file as if it were input by a user.
>
>     Unfortunately neither of these options is likely to work in
>     a web environment - one of the disadvantages of using such
>     a tool. The issue is not a Python one but one with your
>     tutorial. I suggest you contact the authors directly to
>     ask if they can suggest a solution (or incorporate
>     such a feature).
>
>     > 1. I have to use "raw_input".
>     > 2. I do not wish to open a file inside the script as that will
>     beat the
>     > purpose.
>
>     In real-world python you could just use input redirection:
>
>     ########## data.txt ##########
>     Alan
>     ##############################
>
>     ########## myscript.py #######
>     name = raw_input("What's your name? ")
>     print "Hello ", name
>     ##############################
>
>     Executed with:
>
>     $ python myscript.py < data.txt
>
>
>     HTH
>     --
>     Alan G
>     Author of the Learn to Program web site
>     http://www.alan-g.me.uk/
>     http://www.amazon.com/author/alan_gauld
>     <http://www.amazon.com/author/alan_gauld>
>     Follow my photo-blog on Flickr at:
>     http://www.flickr.com/photos/alangauldphotos
>     <http://www.flickr.com/photos/alangauldphotos>
>
>
>     _______________________________________________
>     Tutor maillist  -  Tutor at python.org <mailto:Tutor at python.org>
>     To unsubscribe or change subscription options:
>     https://mail.python.org/mailman/listinfo/tutor
>     <https://mail.python.org/mailman/listinfo/tutor>
>

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list