从interp运行的Python脚本头

2024-05-23 20:35:39 发布

您现在位置:Python中文网/ 问答频道 /正文

Noob警告

我有一个脚本,我正试图在cmd提示符中运行(rename_oturep.py)。当我运行python rename_oturep.py时,出现以下错误:

File "rename_oturep.py", line 1
    Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
           ^
SyntaxError: invalid syntax

所以,当我尝试运行脚本时,脚本似乎是从解释器的头读取的。你知道吗

例如

输入:

X:\Python 3.8> python

输出:

Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

我已经删除了IDLE中的头信息&老实说,我不知道为什么它会将解释器头作为脚本的一部分来读取。我以前(几周前)成功运行过这个脚本,没有任何问题。为什么这只是一个问题?有没有人有类似的经历?你知道吗

下面是实际的脚本代码(从空闲直接复制):

import sys

import re


info = []


with open(sys.argv[1], 'r') as fasta_in:
    for line in fasta_in:
        info.append(line.replace('\r', '').rstrip('\n'))


seqs = []

list
for index, item in enumerate(info):
    if index == 0:
        ID = re.search('Otu[0-9]*',item[1:]).group(0)
    else:
        if index % 2 == 0:
            ID = re.search('Otu[0-9]*',item[1:]).group(0)
        else:
            seqs.append((ID, item))


with open("clean_repFasta.fasta", 'w') as fasta_out:
    for item in seqs:
        fasta_out.write('>' + item[0] + '\n' + item[1] + '\n')

Tags: inpyreinfo脚本idforindex
1条回答
网友
1楼 · 发布于 2024-05-23 20:35:39

您应该从开头的行中删除>。你知道吗

python文件应该看起来像是摆脱了语法错误

import sys

import re

info = []

with open(sys.argv[1], 'r') as fasta_in:
    for line in fasta_in:
        info.append(line.replace('\r', '').rstrip('\n'))

seqs = []

for index, item in enumerate(info):
    if index == 0:
        ID = re.search('Otu[0-9]*', item[1:]).group(0)
    else:
        if index % 2 == 0:
            ID = re.search('Otu[0-9]*', item[1:]).group(0)
        else:
            seqs.append((ID, item))

with open("clean_repFasta.fasta", 'w') as fasta_out:
    for item in seqs:
        fasta_out.write('>' + item[0] + '\n' + item[1] + '\n')

相关问题 更多 >