Linked Questions
16 questions linked to/from Creating dynamically named variables from user input
233
votes
8
answers
625k
views
How can you dynamically create variables? [duplicate]
I want to create variables dynamically in Python. Does anyone have any creative means of doing this?
0
votes
3
answers
2k
views
How do you make a new variable while a program is running in python? [duplicate]
I'm working on a python program where it asks the user for input and then creates a variable with the same name as the user output, like this:
Input: Hello
And then it creates a new variable called ...
0
votes
2
answers
166
views
Create Variables Inside Program [duplicate]
EDIT: This is not a duplicate question. The answer received here actually creates new variables/objects inside the program. That this may or may not be what is actually best for me is immaterial. ...
0
votes
2
answers
100
views
Assigning the % operand in python in an iteration [duplicate]
If I have an array Numbers = [1, 2, 3] and a loop that depend on these numbers and inside the loop I have and a dictionary or some object that I want to name with the numbers in the array Numbers, how ...
-1
votes
1
answer
76
views
Multiple values for a given variable [duplicate]
I am new to Python, and I have no idea how to do this. Any help would be greatly appreciated.
I have 2 files that I am reading in : yesterday's people list and today's people list
I am attempting to ...
168
votes
3
answers
455k
views
Convert string to variable name in python [duplicate]
I have any string. like 'buffalo',
x='buffalo'
I want to convert this string to some variable name like,
buffalo=4
not only this example, I want to convert any input string to some variable name. ...
8
votes
2
answers
3k
views
How can I create multiple variables from a list of strings? [duplicate]
I have a list of strings such as:
names = ['apple','orange','banana']
And I would like to create a list for each element in the list, that would be named exactly as the string:
apple = []
...
8
votes
3
answers
11k
views
Is it possible to "dynamically" create local variables in Python? [duplicate]
Is it possible to create a local variables with Python code, given only the variable's name (a string), so that subsequent calls to "'xxx' in locals()" will return True?
Here's a visual :
>>&...
0
votes
3
answers
8k
views
Python creating variables with names from range [duplicate]
I want to use some code similar to what follows that actually works:
P = 20
n = 1
for x in range(1, P+1):
Ax = n #Hoping that you can name the variable from the current element in the range
n ...
-1
votes
5
answers
6k
views
how to create a new dictionary using for loop in python [duplicate]
suppose I have lists of strings like this
list1 = ["x","y","z"]
so how can create empty dictionaries like x = {}, y = {} and z = {} by iteration
Following method does nothing:
for i in list1:
...
0
votes
3
answers
2k
views
Is there a way to find objects in a list without iterating through the list?
Is there some easy way to access an object in a list, without using an index or iterating through the list?
In brief:
I'm reading in lines from a text file, splitting up the lines, and creating ...
2
votes
3
answers
464
views
Set class (self) variables from variables?
This is poor programming practice, yes, I know, but these scripts are purely mine and this technique would ease my coding a lot.
Right now, I have an SQLite database containing a set of key-value ...
-1
votes
1
answer
1k
views
How to make a variable name dependant on input in python?
I need to create multiple variables based on int input so that if input is 5 then variables are created like: worker1, worker2, worker3, etc.
Is there any way in which I could generate variables like ...
0
votes
3
answers
119
views
Looping Function to Define variables [closed]
Im trying to create a function that takes a list and assigns each of the strings in the list to a variable even when you dont know how many strings are in the list
Here is something i tried:
...
1
vote
3
answers
365
views
Assigning variables at run time?
I have an application that reads multiple variable names from one block of an input file. Then it reads the associated values from another block of the same file.. e.g. variable names read in as ABC,...