我是相当新的代码,我有一个问题,在阅读文本文件。 对于我的代码,我需要要求用户键入一个特定的名称代码,以便继续执行代码。但是,用户可以使用不同的名称代码,我不知道如何制作,因此如果您键入其中一个代码,您可以继续。你知道吗
例如,文本文件如下所示
约翰123,x,x,x
苏珊233,x,x,x
康纳,x,x,x
我需要做的是接受这个名字标签,不管它是什么,并能够打印它之后。所有的名称标签都在一列中。你知道吗
file = open("paintingjobs.txt","r")
details = file.readlines()
for line in details:
estimatenum = input ("Please enter the estimate number.")
if estimatenum = line.split
到目前为止,这是我的代码,但是我不知道该怎么做来查看name标记是否有效,以允许用户继续。你知道吗
这里是另一个解决方案,没有
pickle
。我假设您的凭证每行存储一个。如果没有,你需要告诉我他们是怎么分开的。你知道吗您可以使用名为
pickle
的模块。这是一个python3.0内部库。在Python2.0中,它被称为:cPickle
;在这两种语言中,其他所有内容都是相同的。你知道吗请注意,你这样做不是一个安全的方法!你知道吗
这将保存一个名为
credentials.p
的文件。您可以按如下方式加载:以下是一些测试:
这相当于:
显示:
{'John': 1234, 'James': 4321, 'Julie': 6789}
显示:
Test: True
显示:
Test: False
相关问题 更多 >
编程相关推荐