-1

I have a piece of code I'm trying to write. It is sort of like a lot of functions in one program. I'm giving it the form of a person. So I want to have different "accounts" in it that can change some things in it. This is what I have so far.

    from peewee import *
    import datetime
    from getpass import getpass

    db = SqliteDatabase("Butler_knows.db")

    class User(Model):
        name = TextField()
        password = TextField(), IntegerField()

        class Meta:
            database = db

    db.connect()

    New_not = raw_input("Do I know you? ")

    if New_not.strip().upper() == "NO":
        new_name = raw_input("What is your name? ")
        new_user = raw_input("What would you like me to call you? ")
        passwordcreate = getpass("What would you like your password to be?                ")

So what I want to know is, is there a way to use the input from "new_name" and use it as the variable for the dictionaries? This is using the peewee ORM. If you don't understand, this is what I mean.

    Randomname = User.create(name="Randomname", username="Randomname123",                     password="RandomPass")

That is how you create a user if you want to program a name you want. What should I do if I want to use the user's input as the name of the variable?

Raamis
  • 1
  • 1

2 Answers2

0

I think what you want to say is to use new_name as a key in the dictionary, which you can do as follows:

{new_name :[new_user, passwordcreate]}

but a better way could be:

{"name": new_name ,"user_name": new_user,"password": passwordcreate}
Yonas Kassa
  • 3,362
  • 1
  • 18
  • 27
0

Using user input as a variable name will only confuse you. How would you call the variable? It's better to make a variable 'name' and give it the value that the user specifies. I do think what you're looking for are tuples; key-value pairs. In Python, this is called a dictionary as has been laid out by yosemite_k.

J.A.K.
  • 115
  • 8