开发者社区> 问答> 正文

我如何创建从用户输入名称的python文件,例如,如果创建了名为abc的用户输入“ abc”文件?

我如何创建名称是从用户输入的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

请帮助我

展开
收起
几许相思几点泪 2019-12-24 21:17:43 620 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载