Linked Questions
181 questions linked to/from How can you dynamically create variables?
1 vote
3 answers
65 views
Python: Use a variable when calling a definition [duplicate]
I'm currently making a game for CompSci class, and I want to shorten our random monster fights. Is there a way to make it so when I call a def I can change the name depending on a random variable? ...
-4 votes
2 answers
223 views
Python - Dynamically naming variables [duplicate]
I have a function in which variables of 'node1', 'node2', 'node3' are referenced. I would like to make it so that the second time the function is called, 'node1' become 'node1_a' and on the third ...
0 votes
2 answers
166 views
Calling data from a dictionary created in a for loop in python [duplicate]
I am having some problems retrieving data from a dictionary that is created in a for loop. In my code I have two dictionaries created and updated periodically, one from a machine database and one from ...
0 votes
1 answer
203 views
Python 2.7: set variable name [duplicate]
I would like to set the variable name in a for loop, like: for i in range(5): namei = i # this is a variable name It will give me: name0 = 0 name1 = 1 name2 = 2 name3 = 3 name4 = 4 does anyone ...
-4 votes
1 answer
108 views
How can I make my program create variables automatically and print them by it self? [duplicate]
I've got an idea for a program that I'm not sure how to implement. How can I make the program ask the user something -- input() -- as many times as user responds until x command is written and (and ...
0 votes
4 answers
138 views
How to connect strings in a list to the object to which the string refers [duplicate]
I'm having an absolute mind-block. This is my data: db_one = 1 db_two = 2 db_three = 3 db_four = 4 list_to_iterate = ['one','two','three','four'] for each_item in list_to_iterate: new_string = '...
0 votes
0 answers
133 views
Creating objects in a loop in Python [duplicate]
this is my first post so I am sorry if I get any formatting wrong. I have searched this before in stackoverflow and it did come up with a few responses but I didn't really understand as I couldn't ...
-3 votes
6 answers
130 views
Is is possible to join a variable and a number to make a new variable? [duplicate]
I am using Python 2.5. In the code below want to print either err1, err2 or err3 depending on the value of x. Is it possible to create the variables err1, err2 or err3 by joining "err" plus the value ...
0 votes
0 answers
119 views
Naming variable inside a for loop in python [duplicate]
I want to create 6 pandas dataframes from 6 text files. I want to name them according to the names of the text files. The text files are named as 'DAPC_min.txt' and so on. I want the dataframe names ...
0 votes
1 answer
70 views
Create a Class object using the username from incoming data [duplicate]
Python newbie here: I have a class ExampleState: ... My purpose is to create a class object unique to every user. I get the username from my client flutter app in django. So, instead of state = ...
0 votes
2 answers
90 views
Dynamically creating variables by need in python [duplicate]
I have a list of IDs I'm trying to manipulate in order to get long strings of the following format: "ID1,ID2,ID3,....,IDn". that is, a long string where the IDs are separated by commas, which are ...
0 votes
2 answers
62 views
How can I refer to a variable from a string? [duplicate]
I'm coding a text-based adventure game for my python project in school, and I'm currently creating a fight function. It involves a lot of dictionaries, hence why I need to refer to a variable from a ...
-2 votes
1 answer
63 views
Python - Is it possible to refer to multiple different variables using different variable? [duplicate]
Sorry if the title is confusing but I couldn't think of a better way to word it. I'm making a game with a friendship system and this is essentially what I'm trying to do: playerChar = "Adam";...
0 votes
1 answer
91 views
How do I create a different variable name inside a loop? [duplicate]
Here is the code to start with. Ignoring all the CSV jazz if you want, the important part is the loop. import csv Teacher_Array = [] class Teacher: def __init__ (self, login, password, name, ...
0 votes
1 answer
41 views
List of strings. New variables with those name (without classes). Python [duplicate]
if one had a list of strings, how could they create variables (empty list objects) with those names? pre_vars= ['list_1','list_2','list_3'] print list_1,list_2,list_3 >>> [],[],[] I saw ...