Incrementing Variable Name

Started by
2 comments, last by Gallivan 16 years, 10 months ago
Is it possible in Python for a variable to be stated on one line and increment? Pseudo-code: User Input = x x = 4 VariableCreated%s %(x)= 0 List VariableCreated Output ------ Variable1 Variable2 Variable3 Variable4 I have tried it this way, and I know I'm doing it wrong. However, I have not the slightest clue as to what this may be called and as such I can't Google my problem. Any help you have would be hugely appreciated. :)
Advertisement

It depends. The term would be "metaprogramming", a very advanced topic, BUT... Chances are that's not what you *really* need to do. It's just the only way you know of, so far, to represent what you're thinking of. My guess is what you really need is a list. You need to store multiple values, the amount of which won't be known until run-time, and then access them by their number, correct?
I have no idea what that pseudocode is trying to do. Could you explain what you're trying to achieve, rather than how you're trying to achieve it? Are you trying to create a set of predictably named variables from within the code? And if so, why not just use a list or a dictionary?
Similiar to my other topic (I think it's right underneath if you need to reference), I'm trying to create tiles with names as [0 - 0], [0 - 1], etc.

These will also act as variables which will hold a simple sentence such as Forest, River, etc. So I need to create a set amount of these "tile variables" once the user generates their map-size.

I will read up on lists after school today, thanks. :)

EDIT: I didn't really adress the first reply. I believe that's exactly what I need to do. :D

This topic is closed to new replies.

Advertisement