Linked Questions

566 votes
19 answers
282k views

I know that some other languages, such as PHP, support a concept of "variable variable names" - that is, the contents of a string can be used as part of a variable name. I heard that this is ...
user avatar
10 votes
2 answers
76k views

I'm just learning to program and am learning Python as my first language. As an exercise I'm trying to write an address book program. New contact are created by the user using the command prompt. ...
ShaunSoda's user avatar
  • 101
0 votes
4 answers
4k views

I'm looking for a way, in python 3.2, to create a large number of variables and assign them values. Something like X = 10 Y = 10 A = 0 B = 0 while X >= 0: while Y >= 0: cell[C]X[A] =...
Luingar's user avatar
  • 39
2 votes
5 answers
13k views

I am trying to automate populating a town by randomly generating households. I generate the name of the town, generate the number of households, the last name of each household and number of occupants ...
CromerMW's user avatar
0 votes
2 answers
18k views

I am trying to create variable for each iteration of the for loop: for i in range(10): x(i) = 'abc' so that I would get x1, x2, x3, x4, .... x10, all equal to 'abc' Anyone know how to do it? Thanks!...
Quy Vu Xuan's user avatar
1 vote
6 answers
9k views

My question is how to create variables "on the fly". I'm trying to generate an object with a random set of attributes. from random import randint, choice class Person(object): def ...
jtsmith1287's user avatar
  • 1,159
3 votes
5 answers
6k views

I'm trying to import datasets which have the following filenames (phone1, phone2, etc) df1 = pd.read_csv(r'C:\Users\...\phone1.csv') df2 = pd.read_csv(r'C:\Users\...\phone2.csv') df3 = pd.read_csv(r'C:...
siiddd's user avatar
  • 53
1 vote
2 answers
19k views

I'm trying to put together a programming project at my university, but I'm stuck. The "math" part I've got covered, but I need help with lists and loops in Python. I'm working with graphs, let me ...
kjubus's user avatar
  • 453
0 votes
1 answer
13k views

I have a function that I made to analyze experimental data (all individual .txt files) This function outputs a dictionary ({}) of Pandas Dataframes Is there a efficient way to iterate over this ...
Adi's user avatar
  • 141
2 votes
2 answers
6k views

I was just wondering if there was a way I could create variables from string like in the code below, I can create a file which includes the variable subject in the filename. filehandle = open('...
Sebastian Southwell's user avatar
-1 votes
2 answers
8k views

I am currently trying to write a simple program to calculate probabilities of possible combinations with dice of different sizes (e.g. : 6, 12, 4, 20). The problem i have is that it is supposed to be ...
Gwendal Delisle Arnold's user avatar
0 votes
3 answers
7k views

I have a file that stores variable names and values like below: name,David age,16 score,91.2 ... I want to write a python script that reads the file and automatically creates variables in an object ...
zleung's user avatar
  • 31
3 votes
2 answers
3k views

I'm a little new to Python, and was hoping that someone might be able to help me with a problem I've got. I have the need to instantiate multiple objects using the variables in a list. Let's say I ...
Simplified's user avatar
0 votes
5 answers
2k views

Is it possible to create a variable name based on the value of a string? I have a script that will read a file for blocks of information and store them in a dictionary. Each block's dictionary will ...
Rauffle's user avatar
  • 1,035
0 votes
1 answer
3k views

I would like to write this: x = 'something_{}'.format(1) exec('{} = {}'.format(x,np.zeros((2,2)))) Problem: I get SyntaxError: invalid syntax and I don't know how to solve it. Someone has an idea?
JrCaspian's user avatar
  • 327

15 30 50 per page
1
2 3 4 5
13