python - Is it possible to pass a list of numbers as argument using <? -


i wondering how pass , retrieve list of numbers script using syntax:

python3 program.py < 1 2 3 4 

i know can pass arguments using following syntax:

python3 program.py 1 2 3 4 

and retrieve arguments using sys.argv:

print(sys.argv)  # list of arguments 

i have seen around, reason not able it.

note wondering if it's possible or not, not asking ways read standard input different first example above.

you've misunderstood syntax of proposed command.

here's simple python program prints out contents of standard input , command-line arguments:

# program.py  import sys  print("stdin:", sys.stdin.read()) print("args:", sys.argv) 

... , here's happens when call proposed syntax:

$ python3 program.py < 1 2 3 4 stdin: content of file '1'.  args: ['program.py', '2', '3', '4'] 

in other words, syntax redirects content of file '1' standard input, , supplies arguments '2', '3' , '4' program.

so, no, want isn't possible - not because of python, because of way shell works.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -