3

我对python很陌生。我只想知道我们将在哪里导入文件,我们想在下面的 python 脚本中运行一个脚本。我只想导入或引用下面脚本中的文件

import fileinput, optparse

usage = """%prog HOCOMOCOv9_AD_TRANSFAC.txt > converted_transfac_matrices.txt

 This program reads matrices in a format used by the TRANSFAC database,
 and writes them in a format that can be used by Clover.  The TRANSFAC
 format looks something like this:

 AC  M00002
 XX
 P0      A      C      G      T
 01      4      4      3      0      V
 02      2      5      4      0      S
 03      3      2      4      2      N"""


op = optparse.OptionParser(usage=usage)
(opts, args) = op.parse_args()
if not args: op.error("please specify an input file")

title = []

for line in fileinput.input(args):
    w = line.split()
    key = w[0]
    if key in ("AC", "ID", "NA"):
        title.extend(w[1:])
    elif key.isdigit():
        if title:
            print ">" + " ".join(title)
            title = []
        print "\t".join(w[1:5])
4

1 回答 1

5

这?

with open('file.txt','r') as f_open:
    data = f_open.read()

print data

或者

f_open = open('file.txt','r')
data = f_open.read()
f_open.close()

print data

或者

python script.py

或者

python script.py text.txt

或者

import csv
with open('file.csv', 'rb') as open_csv:
    csv_reader = csv.reader(open_csv)

print csv_reader

有人不清楚帖子:S

于 2013-10-15T22:01:41.513 回答