Python open()不创建fi

2024-10-08 19:21:06 发布

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

此代码在调用时不创建文件。你知道吗

def editcam(filetext, filename, x, y, z):
    print 'opening file'
    filetext=re.sub(r'location <(\d+),(\d+),(\d+)>', 'location <%d,%d,%d>'% 
(x,y,z), filetext)
    fout=open(filename, 'w')
    print 'file opened'
    fout.write(filetext)
    fout.close()
    return

def main():
    editcam(getfile(),'tmp.pov',0,0,12)
    return

两个指纹都不起作用。没有错误消息。getfile()应该返回一个字符串。我试着把这个问题说出来回复sub调用并用硬编码字符串替换getfile()。都没改变什么。由于打印不起作用,因此似乎该方法甚至没有被调用。有什么想法吗?你知道吗


Tags: 文件字符串代码rereturndeflocationfilename
1条回答
网友
1楼 · 发布于 2024-10-08 19:21:06

我能用下面的代码让它工作。你知道吗

import re

def editcam(filetext, filename, x, y, z):
    print 'opening file'
    filetext=re.sub(r'location <(\d+),(\d+),(\d+)>', 'location <%d,%d,%d>'%
(x,y,z), filetext)
    fout=open(filename, 'w')
    print 'file opened'
    fout.write(filetext)
    fout.close()
    return

def main():
    editcam(__file__,'tmp.pov',0,0,12)
    return
main()

相关问题 更多 >

    热门问题