开发者

Python, saving 2 string outputs as 2 files

There are 2 string outputs. Let's call them output1 and output2. Both of them 开发者_JAVA技巧should be saved in one location, each of them should have the same name but having different file extension (both being text files in fact). How can this be done in Python? The program should have standard save dialog, asking for name and location. Thanks.


Use whatever GUI toolkit you're using to show the file dialog and get a base filename in filename. Then just

with open(filename + '.ext1', 'w') as f:
    f.write(output1)
with open(filename + '.ext2', 'w') as f:
    f.write(output2)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜