with open(sourceFileName, 'rt') as sourceFile:
sourceFileConents = sourceFile.read()
sourceFileConentsLength = len(sourceFileConents)
i = 0
while i < sourceFileConentsLength:
print(str(i) + ' ' + sourceFileConents[i])
i += 1
请原谅unPythonic for i循环,这
真正挑剔的Linux问题。
我有一个文本文件,叫做userec。我还有一个字符串变量'var_a‘。
我想要连接字符串值,假设它是'howdy‘到文本文件的顶部。
所以就像这样
echo $var_a | cat usrec > file_out
在这里,它通过管道将来自echo $var_a的输出作为一个文件,并将其添加到file_out的顶部,然后添加usrec文件的其余部分。
因此,如果userec文件只包含一行'This is the second line‘,那么file_out的内容应该是:
howdy
This is the second line.
我知道这个问题以前已经问过很多次了,所以和其他地方也一样。我还是做不到。如果我的英语不好,我很抱歉
在linux中删除文件要简单得多。只是os.remove(my_file)做了这件事,但是在windows中
os.remove(my_file)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: (file-name)
我的代码:
line_count = open(my_file, mode='r')