Python中的输出文件 [英] Output file in Python

查看:108
本文介绍了Python中的输出文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我回来了。


经过大量的修修补补,并在论坛上问人们,我们制作了一个程序,可以成功地创造一个龙与地下城的角色扮演字符。最后,输出如下:


---------------------------- ------------------------------------

你的角色的性别是:男性

你的角色名字是:查理

你的角色'的种族是:Gnome

你的角色''上课是:战士

-------------------------------------- --------------------------

.............身体特征。 ...........

强度= 14

decterity = 15

构造= 10

.............精神特质...............

智力= 10

charisma = 9

智慧= 8

--------------------------- -------------------------------------

阵营:混沌中立



那当然是cmd。

我想知道的是这个,是不是可以把东西写进去python脚本使它将此输出保存为.txt文件?


比ks,现在我要过生日了!

Hello, I''m back.

After lots of tinkering, and asking guys here at the forum, we made a program that could successfully create a dungeons and dragons role playing character. In the end, the output looks like this:

----------------------------------------------------------------
Your character''s sex is: Male
Your character''s name is: Charlie
Your character''s race is: Gnome
Your character''s class is: Warrior
----------------------------------------------------------------
.............Physical Traits............
strength = 14
decterity = 15
constitution = 10
.............Mental Traits...............
intelligence = 10
charisma = 9
wisdom = 8
----------------------------------------------------------------
Alignment: Chaotic Neutral



And that is in cmd of course.
The thing I was wondering was this, is it possible to write something into the python script to make it save this output as a .txt file?

Thanks, now I''m off to a birthday!

推荐答案


您好,我回来了。


经过大量的修修补补,并在论坛上问问我们,我们制作了一个程序,可以成功创建一个龙与地下城扮演角色。最后,输出如下:


---------------------------- ------------------------------------

你的角色的性别是:男性

你的角色名字是:查理

你的角色'的种族是:Gnome

你的角色''上课是:战士

-------------------------------------- --------------------------

.............身体特征。 ...........

强度= 14

decterity = 15

构造= 10

.............精神特质...............

智力= 10

charisma = 9

智慧= 8

--------------------------- -------------------------------------

阵营:混沌中立



那当然是cmd。

我想知道的是这个,是不是可以把东西写进去python脚本使它将此输出保存为.txt文件?


比ks,现在我要过生日了!
Hello, I''m back.

After lots of tinkering, and asking guys here at the forum, we made a program that could successfully create a dungeons and dragons role playing character. In the end, the output looks like this:

----------------------------------------------------------------
Your character''s sex is: Male
Your character''s name is: Charlie
Your character''s race is: Gnome
Your character''s class is: Warrior
----------------------------------------------------------------
.............Physical Traits............
strength = 14
decterity = 15
constitution = 10
.............Mental Traits...............
intelligence = 10
charisma = 9
wisdom = 8
----------------------------------------------------------------
Alignment: Chaotic Neutral



And that is in cmd of course.
The thing I was wondering was this, is it possible to write something into the python script to make it save this output as a .txt file?

Thanks, now I''m off to a birthday!



是的。此代码

Yes. This code

展开 | 选择 | Wrap | 行号


或者如果它只是一个文件,请从命令行执行
or if its just one file, do it from the command line
展开 | 选择 | Wrap | 行号



是。此代码
Yes. This code
展开 | 选择 | Wrap | 行号


这篇关于Python中的输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆