生信专题

Python | sys

2022-06-24  本文已影响0人  shwzhao
import sys

1. 命令行传参

$ cat test2.py
import sys

USAGE = "USAGE: python3 {0} input output".format(sys.argv[0])

print("\n" + USAGE)

input = sys.argv[1]

print("\nThe input file is " + input)
$ python3 test2.py INPUTFILE

USAGE: python3 test2.py input output

The input file is INPUTFILE

2. 程序控制

3. 标准输入、输出和错误

$ cat test.py
import sys

for i in sys.stdin:
    if i.startswith(">"):
        print(i.rstrip(), file=sys.stdout)
    else:
        print(i.rstrip(), file=sys.stderr)
$ cat a.fa
>gene1
ATCAGAGC
>gene2
CATCGGCAACC
$ cat a.fa | python3 test.py 1> geneid.txt 2> sequence.txt
$ cat geneid.txt
>gene1
>gene2
$ cat sequence.txt
ATCAGAGC
CATCGGCAACC

4. 查看信息

>>> sys.platform
'linux'
>>> sys.version
'3.8.5 (default, Sep  4 2020, 07:30:14) \n[GCC 7.3.0]'
上一篇下一篇

猜你喜欢

热点阅读