我有两台带有Windows的计算机,我刚刚在其中一台计算机上发现,如果我直接运行python代码,例如:
test_args.py input1 input2
Run Code Online (Sandbox Code Playgroud)
Python不会识别我给出的输入,但这有效:
python test_args.py input1 input2
Run Code Online (Sandbox Code Playgroud)
我试过这段代码:
import sys
print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)
Run Code Online (Sandbox Code Playgroud)
第一种方式(test_args.py)返回:
Number of arguments: 1 arguments.
Argument List: ['D:\\Test\\args\\test_args.py']
Run Code Online (Sandbox Code Playgroud)
虽然sceond方式(python test_args.py input1 input2)返回:
Number of arguments: 3 arguments.
Argument List: ['D:\\Test\\args\\test_args.py', 'input1', 'input2']
Run Code Online (Sandbox Code Playgroud)
关于这可能发生什么的任何想法?此问题仅发生在我的一台计算机上,两台都有相同版本的Windows.
谢谢!
我在regedit关键字"python"中搜索,发现在"C:\ Python27\python.exe""%1"之后缺少%*的两个键:
电脑\ HKEY_CLASSES_ROOT \应用程序\ python.exe
电脑\ HKEY_CLASSES_ROOT\py_auto_file \壳\开放\命令
并且.py与py_auto_file相关联,即使我尝试了关联.py Python.File
更改两个键解决了这个问题,谢谢!
有没有办法可以将编译后的二进制文件作为包上传到 PyPI 中?以及如何检测不同的操作系统?
我注意到 PyPI 的某些包是这样做的,例如 Pyinstaller,但不确定如何实现它。
谢谢!
我正在写一个新文件的多行(最多可达几GB),如下所示:
for item in record:
output_pass.write('%s\n' %item)
Run Code Online (Sandbox Code Playgroud)
但是,由于我上次记录的'\n',我得到一个空白行,例如:
开始文件
record111111
reocrd222222
record333333
---a blank line---
Run Code Online (Sandbox Code Playgroud)
文件结束
由于我的文件很大,我不想再读取该文件.那么,是否有一种简单的方法来阻止这种或简单的方法从文件中删除最后一个'\n'?
我的解决方案
感谢您的帮助!
我想我不会将整个文件加载到记忆中,因为它可能会变得非常庞大.
我实际上是通过先编写第一条记录来解决这个问题,然后在循环中写下其余的一行.我把'\n'放在前面,所以它不会出现在最后一行.
但乔纳森是对的.我实际上现在在最后一行有'\n'问题,主要是我的强迫症.
这是我的代码:
rec_first = parser_fastq.next() #This is just an iterator of my file
output.write('%s' %('>'+rec_first[0].strip('@')))
output.write('\n%s' %(rec_first[1])) #I put '\n' in the front
count = 1
#Write the rest of lines
for rec_fastq in parser_fastq:
output.write('\n%s' %('>'+rec_fastq[0].strip('@')))
output.write('\n%s' %(rec_fastq[1]))
count += 1
print 'Extracting %ith record in %s ...' %(count, fastq_name) + '\b'*100,
output.close()
Run Code Online (Sandbox Code Playgroud)
print'\n%i记录被写入%s'%(count,fasta_name)