开发者

Python, saving 2 string outputs as 2 files

开发者 https://www.devze.com 2023-03-03 14:31 出处:网络
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 extensio

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

精彩评论

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

关注公众号