Input string in bio-python via sys.argv

I want to pass the string stored in the txt file as an argument to python code using the sys.argv command. This is code called script.py

import sys
seq = sys.argv[1]
print seq

and this is the line stored in the seq.txt file: AAABBBCC

Now when i run

python script.py seq.txt

I get

seq.txt

as a conclusion. How can I get it to print a line in the seq.txt file.

+4
source share
3 answers
with open(argv[1]) as f:
    print(f.readlines())

You need to open a file like this before you can read and print it.

+4
source

You need to open the file to read its contents.

When you do this:

seq = sys.argv[1]

You just get the string value of what you provide your script arguments.

, seq , - :

fi = ""
with open(seq) as f:
    fi = f.readlines()

, , -, .:)

Python: Python

+1

What if I read the file in a variable first and then pass it to python?

$ my_var=$(<text_file.txt)
$ python python_file.py "$my_var"
+1
source

Source: https://habr.com/ru/post/1609504/


All Articles