我如何创建名称是从用户输入的python文件,例如,如果创建了名为abc的用户输入“ abc”文件?请帮助我,我想创建文件。我不知道是什么原因造成的。我尝试了其他方法,但是它不起作用,这个问题与其他问题有所不同,因为我想创建用户想要的文件。
def admin():
p=open("password.txt","r")
a=p.read()
p.close()
password=input("Enter a Password: ")
if password==a:
print("Log In Successfull")
print("Press 1 to view current categories of Item.")
print("Press 2 to add new category. ( will include Name of category)")
print("Press 3 to add product to category.")
print("Press 4 to view a specific product")
print("Press 5 to delete a product.")
print("Press 6 to view view all orders purchased")
print("Press 7 to view purchase record of a specific customer by entering Nameas search criteria.")
choice=int(input())
if choice==1:
p=open("categories.txt","r")
if p.mode=="r":
contents=p.read()
print(contents)
if choice==2:
categories=[]
data=[]
print("Add product in a categore")
category=input("Enter Name of category: ")
name=input("Enter Name of product: ")
price=int(input("Enter Price of a Product: "))
quantity=int(input("Enter Quantity of a product: "))
data.append(category)
data.append(name)
data.append(quantity)
data.append(price)
print(data)
categories.append(data)
p=open("categories.txt","a+")
for i in categories:
for j in data:
p.write(str(j))
p.write("\n")
p.close()
else:
print("invalid Password")
num=int(input("Press 1 to change password."))
if num==1:
n=(input("Type New Password: "))
p=open("password.txt","w")
p.write(n)
print("New Password is: ",n)
while True:
print("Select the following.")
print("1. Admin")
print("2. Customer")
print("3. Quit")
n=int(input())
if n==1:
admin()
if n==3:
print("Good Bye. ")
break
请帮助我
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。