Skip to content

Conversation

@kevinburke
Copy link
Contributor

Make a few changes to the style page to make it read better.

I was also thinking about adding some examples of the 'best' way to do some things, like

# Check if object is True
# bad:

if attr == True:
    print 'It exists!'

# good:
if attr:
    print 'It exists!'


# Try to retrieve object from dictionary
# Bad
if d.has_key('tree'):
     fruit = d['tree']
else:
     fruit = 'default'

# Good
fruit = d.get('tree', 'default')

# Get some items from a list
# Bad
b = []
for item in a:
    if item < 5:
        b.append(item)

# Good
b = [item for item in a if item < 5]

What do you think?

@kennethreitz
Copy link
Contributor

The changes so far are great, as is the proposal. Do you want me to merge now or just wait until all of your proposed changes are in place?

@kevinburke
Copy link
Contributor Author

Leave it, I'll make the change but it may not be till the weekend.

@kennethreitz
Copy link
Contributor

Awesome, looking forward to it.

@kevinburke
Copy link
Contributor Author

OK, they're up

@kennethreitz
Copy link
Contributor

This is great. Thanks!

kennethreitz pushed a commit that referenced this pull request Mar 16, 2012
@kennethreitz kennethreitz merged commit a26f75e into realpython:master Mar 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants