Best way to create this dict in python?

I would stop and consider why you are doing this. I can't help but think its not necessary Even if you decide this is necessary (which I doubt) - You are pretty much recreating globals() Type that into your interpretter and see if you still want to do this Organize it further like senderle suggested in your other post. And maybe post a broader question with help for organizing your project.

I would stop and consider why you are doing this. I can't help but think its not necessary. Even if you decide this is necessary (which I doubt) - You are pretty much recreating globals().

Type that into your interpretter and see if you still want to do this. Organize it further like senderle suggested in your other post. And maybe post a broader question with help for organizing your project.

Lol, and I can! +1 – senderle Mar 22 at 2:27 hah. You can what?

– jon_darkstar Mar 22 at 2:28 vote your comment up twice :) – senderle Mar 22 at 2:28 oh haha I didn't see it above. Yea I commented at first before I reconsidered and decided it was worth of an answer. Thank you =P – jon_darkstar Mar 22 at 2:29.

The first thing I would do is reformat that dictionary so there is one entry per line: vars_ = { 'attackUp' : attackUp, 'defenceUp' : defenceUp, 'magicUp' : magicUp, 'attType' : attType, 'weightDown': weightDown, # and so on } I have also lined up the columns so the whole list reads more easily.

You could make an array of variable names and pull them out of the locals dictionary. X, y, z = 5, 10, 20 l = locals() d = {} for v in 'x', 'y', 'z': dv = lv # d = {'y': 10, 'x': 5, 'z': 20} locals might work on it's own too if you're just wanting to look it up as a string. AttUp = locals()'attackUp'.

I'm having trouble imagining how locals()'attackUp' is any better than simply attackUp, especially since it's slower and will suppress important optimisations in Python. – Greg Hewgill Mar 22 at 2:34 I'm assuming he's wanting a way to lookup the variables based on the string version of their names so that he can dynamically call them, using locals would allow for that. – Mark Striemer Mar 22 at 2:40.

I totally agree with @miku - look at how you are using the values and seriously refactor. For example, a Character has Attributes (physical_attack, physical_defence, magic_attack, magic_defence, weight, speed) and Items; Weapons are Items, Swords and Axes and Spears and Bows are Weapons, a Saber is a Sword. Unarmed is a special default Weapon.

Charms are Items, but apparently Books and StringedInstruments are Weapons? Items have Attributes which are added to a Character's Attributes while equipped. Character also has level, location, target, and an accuracy rating for each weapon type (can a Weapon have an accuracy-modifier?).

If you break it down into a class hierarchy this way, it should be much easier to keep track of what you are doing.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions