python帮助 [英] python help

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

问题描述

当我执行add_player语句时,它不想编辑当前的ppp.txt文件。当我列出当前在ppp.txt文件中的玩家时,它似乎没问题,它只是添加一个新玩家似乎没有用。

When i do the add_player statement, it doesn''t want to edit the current ppp.txt file. When i list the players currently in the ppp.txt file its seems ok, its just adding a new player doesnt seem to work.

展开 | 选择 < span class =codeDivider> | Wrap | 行号

推荐答案

@manchesterboy


但是你的add函数只是将它附加到名为lis的列表中。你根本不把它写到文件中!


你需要为文件以正确的格式创建一个字符串(用分号等分隔),然后将其写入文件。你可以使用追加模式,所以像这样:

@manchesterboy
But your add function just appends it to the list called lis. You don''t write it to the file at all!

You need to create a string from the data in the right format for your file (separated by semi-colons etc), and then write it to file. You could probably use the append mode, so something like this:

展开 | 选择 | Wrap | 行号


我是编程新手,所以它花了我一些时间来习惯它

我的ppp.txt文件的格式是:

krapa; peter; pk; 565; 1; 2; 3; 55

例如。

所以要将下一个玩家添加到文本文件中,我需要执行以下操作:

players = open(" ppp.txt"," a")这允许我追加文件

players.write(我会使用( x [0],x [1] ...)文件(这一点令我困惑)

然后

players.close()

它的players.write()位。我很困惑,因为我们的讲座没有涉及。

感谢你的帮助
Im new to the programming, so its taking me some time to get used to it
my ppp.txt file is written in the format:
krapa;peter;p.k;565;1;2;3;55
for example.
so to add the next player onto the text file i would need to do the following:
players=open("ppp.txt","a") this allows me to append the file
the players.write(would i use the (x[0],x[1]...) file(this bit is confusing me)
then
players.close()
Its the players.write() bit. i am confused about, as it has not been covered in our lectures.
thanks for your help


你说你已经打开文件阅读和写作或仅用r +写作或w
You say you already have the file open it for reading and writing or for writing only with "r+" or "w"
展开 | 选择 | Wrap | 行号


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

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