Print

Print


Here's a method that might be simpler.

I'm guessing your Python script writes output to a file.  For 
simplicity, I'll assume that it's always the same output file, though 
you could make it more flexible.

You could write a batch file with two lines, one that runs the Python 
script and one that opens a text editor (or Excel, or whatever) with the 
output.  You could then tell Windows to use the batch file to open your 
input file.

For example, let's say your delimited text file is myinput.csv.  You 
have a Python script, myscript.py, that takes a file path as input. The 
beginning of your Python script might look like this:

import sys
infilepath = sys.argv[1]

The Python script reads the file (myinput.csv) and writes to a file 
called myoutput.txt.  You write a batch file, mybatch.bat, that looks 
like this:

C:\Python27\python.exe myscript.py %1
notepad myoutput.txt

If you have file paths with spaces in them, you'll need to use quotes in 
the batch file.

In Windows Explorer, right-click on myinput.csv, choose "Open with...", 
and navigate to the batch file.  You could even tell Windows that you 
always want to use this batch file when you double-click on a .csv file 
(or whatever your input file extension is).  Windows will provide the 
file path (myinput.csv) to the batch file, and the batch file will 
provide it to the Python script using the "%1" argument.

The second line of the batch file will simply open the output file so 
the user can see it.  You could also put that functionality in the 
Python script instead of the batch file, especially if you want the 
output file to have a different name each time.

-Jason Wise
On 11/7/2014 8:41 AM, Lachance, Michael - APHIS wrote:
>
> Good morning everyone,
>
> With guidance from this listserv I have successfully created a Python 
> script that reads through a delimited text file and outputs a summary 
> of the data stored in this file. I would like the non-technical folks 
> in my office to be able to use this script to get the summary of the 
> data. What is the best way to make this happen? We are going to be 
> running multiple files through the script one at a time and recording 
> the outputs in a spreadsheet.
>
> I would like them to be able to run the script by selecting the 
> relevant text file with an "Open" or "Browse" option and then be able 
> to click a button to execute the script with the selected file as the 
> input. The output would then come back as text in a window. I was 
> thinking this could easily be done via VBA but upon researching this 
> it appears it may be more complicated than I thought.
>
> Any suggestions or feedback?
>
> Kind regards,
>
> Michael Lachance
>
> Plant Protection Technician
>
> ALB Eradication Program USDA APHIS
>
> 151 West Boylston Drive
>
> Worcester, MA 01606
>
> *508.852.8050 (o)*
>
> *508.414.5673 (c)*
>
> The USDA is an equal opportunity provider and employer.
>
> Federal Relay Service (Voice/TTY/ASCII/Spanish) 1-800-877-8339
>
> This electronic message contains information generated by the USDA 
> solely for the intended recipients. Any unauthorized interception of 
> this message or the use or disclosure of the information it contains 
> may violate the law and subject the violator to civil or criminal 
> penalties. If you believe you have received this message in error, 
> please notify the sender and delete the email immediately.
>
> ------------------------------------------------------------------------- 
> This list (NEARC-L) is an unmoderated discussion list for all NEARC 
> Users.
>
> If you no longer wish to receive e-mail from this list, you can remove 
> yourself by going to http://listserv.uconn.edu/nearc-l.html.
>


------------------------------------------------------------------------- This list (NEARC-L) is an unmoderated discussion list for all NEARC Users.

If you no longer wish to receive e-mail from this list, you can remove yourself by going to http://listserv.uconn.edu/nearc-l.html.