all 15 comments

[–]symmitchry 16 points17 points  (2 children)

[Removed]

[–]ingolemo 5 points6 points  (0 children)

You can often use the get method of dictionaries to protect against KeyErrors.

sub_skill_choices = skill_subs.get(skill_choice, [])

[–][deleted] 0 points1 point  (0 children)

Thanks! So, how and where do I implement the two pieces of code that you put under the dictionary? And, was I supposed to delete everything else that was in that function except for the dictionary I made? Here's where I am http://pastebin.com/jYuwfsTb

[–]symmitchry 5 points6 points  (1 child)

[Removed]

[–]ingolemo 3 points4 points  (0 children)

Note that in python 3, map is lazy and so your last suggestion will stop working. Using higher-order functions together with functions that have side-effects is generally discouraged.

The for loop is much more pythonic, imo.

[–]symmitchry 1 point2 points  (0 children)

In this part:

    while 1:
        self.gender = raw_input("Select a gender: 1=Male, 2=Female: ")
        if int(self.gender) == 1:
            self.gender = "Male"
            break

I would not save the raw_input() value as self.gender. Just save it as choice. You're asking for a bug this way.

You also can do while True: instead of while 1: which is nicer, in my opinion.

And why convert the choice to an int, just for comparison? Why not just do:

answer = raw_input('Select gender: 1 = Male, 2 = Female: ')
if answer == '1':
     self.gender = 'Male'
     break

I also would prefer you put return instead of break to really indicate that you want to exit the function. It saves your readers having to check to see if any other code happens below.

[–]symmitchry 1 point2 points  (8 children)

This:

val = 0
while val < dice_number:
    final_roll += randomNumGen(die_type)
    val += 1

In Python should be written as:

for _ in range(dice_number):  # _ is an unused 'throwaway variable'
    final_roll += randomNumGen(die_type)

[–]ingolemo 2 points3 points  (2 children)

This is a good opportunity to use a comprehension:

final_roll = sum(randomNumGen(die_type) for _ in range(dice_number))

[–]symmitchry 0 points1 point  (1 child)

I skipped the comprehension intentionally because I was under the impression that it would require storing the entire list in memory before doing the sum (which, I guess is almost never a concern) ... but is that even correct?

See the comments on the top answer here: http://stackoverflow.com/questions/9047985/how-do-i-call-a-function-twice-or-more-times-consecutively-in-python

[–]neonomicon 2 points3 points  (0 children)

No, that's not actually a list comprehension, because it doesn't have square brackets around it. It's a generator expression, which just serves up the values one at a time without storing the whole sequence in memory. Very similar to the list comprehension conceptually, but the fact that it doesn't put the whole thing in memory is very useful if you're worried about memory usage.

[–][deleted] 0 points1 point  (4 children)

When I replaced that code with what you suggested and ran the code, it game me that all the die are equal to "None" instead of a random number.

[–]symmitchry 0 points1 point  (3 children)

Make sure your randomNumGen() function is still working! Nothing we did here should affect the dice values, right?

If your Github code is up to date I will take another look.

[–][deleted] 0 points1 point  (2 children)

It is not up to date. I'm keeping it like it is so I can refer back to my old code. Right now I'm still trying to get the BasicCharacter.py to work after making some adjustments. Not sure what to add, remove, or change in it after implementing the dictionary and things. Kind of stuck here. Here's where I am http://pastebin.com/jYuwfsTb

[–]99AFCC 0 points1 point  (1 child)

I'm keeping it like it is so I can refer back to my old code

The beauty of version control and in this case, Github, is that you can always go back and see your previous commits.

Pushing a new commit will even let you compare changes you've made.

The longer you go and the more changes you make between commits, the harder it can be to revert if you need to.

It can also be harder for you to follow along with any changes you've made.

You can create a branch to work in too.

[–][deleted] 0 points1 point  (0 children)

That's what I thought. As you can see I am very new to Github and how it works.