0

If I have a python code that currently works with static files but I wish to change it in a way that would allow it to accept dynamic files as well, how can I do so?

Like this is my code in python:

row = run('cat '+'/Users/minks/Documents/X-test.txt'+" | wc -l").split()[0] print("Test row size:") print(row) matrix_tmp_test = np.zeros((int(row),col), dtype=np.int64) print("Test matrix size:") print(matrix_tmp_test.size) 

Now if that file X_test.txt is dynamic and needs to be provided by command line instead, how can I do so via command line such that it goes and fit into the statement? There are other file calls in the python script as well so how can I ensure the dynamic file goes and fits into the above statement only?

1
  • You want to provide a file as input from the commandline? Commented Feb 19, 2016 at 12:17

1 Answer 1

3

You can pass file name from command line as

python_program.py filename import sys sys.argv[1] # would be your file name in program row = run('cat '+ sys.argv[1]+" | wc -l").split()[0] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.