0
在python中写入文件时有硬性限制还是上限限制?我有一个包含约800万条记录的CSV文件,我的脚本随机化了这些行然后输出它。完成后,随机文件只有约500万条记录。任何想法会发生什么,或者如果实际上有一个我应该知道的限制? 在此先感谢。Python:写入文件的大小限制
编辑:这是我用来写入文件的代码。
def createOutputFile(fileIn, header, fileCap, extension):
outfileName = 'Randomized_Data.'+extension
if(header == 'Y' or header == 'y'):
infile = open(fileIn,'r')
headerline = infile.readline()
lines = open(fileIn).readlines() # read whole file
random.shuffle(lines) # randomize
lines = lines[:fileCap] # write up to the use specified length
with open(outfileName,'a+') as outfile:
if(not headerline==""):
outfile.write(headerline)
outfile.writelines(lines)
编辑2:关于fileCap
变量A的问题,这将是该文件的最大长度。
if (fc == ""):
# gets size of file (in rows)
file = open(fn)
fc = len(file.readlines())
else:
fc = int(fc)
其中作为fileCap
向我们展示您的代码:) –
没有限制,没有代码就没有别的可以做的事。 – Tuzane
该限制是您的磁盘大小或文件系统支持的最大文件大小。但是,如果程序无法写入文件,程序应该会提醒您。这听起来像是一个逻辑错误;正如Andrea所说,向我们展示您的代码。 –