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

时间:2019-12-24 12:17:25

标签: python file input

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

请帮助我

0 个答案:

没有答案