如何从 Python 上的保存文件 (N:\userFile) 中获取信息(帐户名)
How do I fetch information (an account name) from a save file (N:\userFile) on Python
我为学校计算项目创建了一台银行 ATM 机,所以我在 Python 中是编码新手。我创建了一段代码来保存用户名和 PIN 码,但我不知道如何让程序记住名称并 link 它与配对的 PIN 码。
balance_user = 500
balance_new = 0
print "Welcome to the Banking Bank PLC public ATM service"
user = raw_input("Please enter your ATM account name and insert your Banking Card. If you do not have an ATM account, please insert your Banking Card and enter New_User.")
if user == "New_User":
print "Weclome to the Banking Bank PLC ATM service."
user = raw_input ("Please enter an ATM account name that you wish to use to log onto the Banking Bank ATMs")
f1 =open('N:\userFile', 'a+')
print >> f1,user
print "Welcome", user, "to the Banking Bank PLC ATM service."
PIN = raw_input ("Please asign a P.I.N to this ATM account. 4 Numbers, no letters or symbols.")
f1 =open('N:\userFile', 'a+')
print >> f1, PIN
print PIN, ", do not forget this number."
print "Please log back into the ATM, using you new ATM account name and P.I.N"
这就是代码,它保存到一个文本文件中。数据都在那里,所以如果用户写 "BOB"
作为他们的名字和 "9999"
作为他们的 PIN,保存会说 "BOB 9999"
。我如何取回这些信息,以便当他们再次登录时银行 ATM 记住他们是谁?
Python 有关于如何 write/read 文件的很好的文档,只有很少的例子。 See here
看来您需要这样的东西:
f = open('N:\userFile', 'r')
for line in f:
# process line
print line
f.close()
我为学校计算项目创建了一台银行 ATM 机,所以我在 Python 中是编码新手。我创建了一段代码来保存用户名和 PIN 码,但我不知道如何让程序记住名称并 link 它与配对的 PIN 码。
balance_user = 500
balance_new = 0
print "Welcome to the Banking Bank PLC public ATM service"
user = raw_input("Please enter your ATM account name and insert your Banking Card. If you do not have an ATM account, please insert your Banking Card and enter New_User.")
if user == "New_User":
print "Weclome to the Banking Bank PLC ATM service."
user = raw_input ("Please enter an ATM account name that you wish to use to log onto the Banking Bank ATMs")
f1 =open('N:\userFile', 'a+')
print >> f1,user
print "Welcome", user, "to the Banking Bank PLC ATM service."
PIN = raw_input ("Please asign a P.I.N to this ATM account. 4 Numbers, no letters or symbols.")
f1 =open('N:\userFile', 'a+')
print >> f1, PIN
print PIN, ", do not forget this number."
print "Please log back into the ATM, using you new ATM account name and P.I.N"
这就是代码,它保存到一个文本文件中。数据都在那里,所以如果用户写 "BOB"
作为他们的名字和 "9999"
作为他们的 PIN,保存会说 "BOB 9999"
。我如何取回这些信息,以便当他们再次登录时银行 ATM 记住他们是谁?
Python 有关于如何 write/read 文件的很好的文档,只有很少的例子。 See here
看来您需要这样的东西:
f = open('N:\userFile', 'r')
for line in f:
# process line
print line
f.close()