Skip to content

Clean up the style page#101

Merged
kennethreitz merged 3 commits into
realpython:masterfrom
kevinburke:style
Mar 16, 2012
Merged

Clean up the style page#101
kennethreitz merged 3 commits into
realpython:masterfrom
kevinburke:style

Conversation

@kevinburke

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

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

@kennethreitz

Copy link
Copy Markdown
Contributor

Awesome, looking forward to it.

@kevinburke

Copy link
Copy Markdown
Contributor Author

OK, they're up

@kennethreitz

Copy link
Copy Markdown
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