Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a text file. But I dont want to input that file in my python script directly. I want to run my python script from command line with argument which is my text file. The command line that I want is : $Python.exe script.py C:/user/text_file.txt .

What I have tried:

<pre>
import sys

def main():
    infile = sys.argv[0]
    Array = ["f1", "f2", "f3", "f4"]
    with open(infile, "r") as input_file:
    	output_list = []
    	for rec in input_file.read().splitlines():
    		rec = rec[:-3]
    		FBlist = [rec[i:i+2] for i in range(0, len(rec), 2)]
    		output_list.append(FBlist)
    		print(output_list)



main()
Posted
Updated 6-Mar-19 22:47pm
v2

1 solution

I explained how to do this yesterday in your question at https://www.codeproject.com/Questions/1279057/How-to-read-a-file-in-external-path-with-Python-co[^]. If that does not work then use the original question to post comments. Please do not reopen the same query.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900