Giter Club home page Giter Club logo

python-guide's Introduction

Hitchhiker's Guide to Python

Python Best Practices Guidebook

→ Read the free guide at: docs.python-guide.org

image


Work in progress. If you'd like to help, please do. There's a lot of work to be done.

This guide is currently under heavy development. This opinionated guide exists to provide both novice and expert Python developers a best practice handbook to the installation, configuration, and usage of Python on a daily basis.

Topics include:

  • Platform and version-specific installations
  • Py2app, Py2exe, bbfreeze, pyInstaller
  • Pip
  • Numpy, scipy, statpy, pyplot, matplotlib
  • Virtualenv
  • Fabric
  • Exhaustive module recommendations, grouped by topic/purpose
  • Which libraries to use for what
  • Server configurations & tools for various web frameworks
  • Documentation: writing it
  • Testing: Jenkins & tox guides
  • How to easily interface hg from git

If you aren't fond of reading reStructuredText, there is an almost up-to-date HTML version at docs.python-guide.org.

python-guide's People

Contributors

aaronw avatar alex avatar ambray avatar andrewmacgregor avatar apjanke avatar benregn avatar brianpainter avatar bzaczynski avatar campbellr avatar cli248 avatar dbader avatar dcrosta avatar epequeno avatar esc avatar kennethreitz avatar kisielk avatar mahmoudhossam avatar michael-f-bryan avatar micrypt avatar mpoulin avatar poulinconsulting avatar rgbkrk avatar rshipp avatar serra avatar sigmavirus24 avatar sirmackk avatar smithandrewl avatar tartley avatar tbarn avatar techtonik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-guide's Issues

Lawyer Up

Creative Commons Attribution-ShareAlike 3.0. Objections?

Launchpad translation.

Hi, i just created launchpad project which goal is to translate this guide for as lot languages as it's possible. If kennethreiz have nothing against maybe this link should be put into readme file? Also I can give right people right permissions at this LP project. What do you think?

Link is: https://launchpad.net/python-guide-pl

First i thought to make this only for polish, but after few minutes i thought "Why not for all?" I will change branch name, but I'm not sure what can i do with the link :( Anyway, maybe kennhethreitz will make another project, more official :P I have made already .pot template for 10 sentences (I just started).

Lawyer Up

Attribution-ShareAlike 3.0. Objections?

Python OSX installation confusion

Hi,

I heavily advice people to use the Python Guide but some of then just break their Python installation cause of confusion in OSX installation.

If you follow the guide, you'll install the osx-gcc-installer from kenneth, after that you install homebrew and it say to you, you must install the official command line tools.

And after that your Xcode installation will be broken.
If I well understand situation, osx-gcc-installer is know deprecated since we have official command line tools support from Apple ? For at least OSX "Lion" users ?

Before "Lion", people should choose between full Xcode installation or kenneth package ?

I think we must really removed osx-gcc-installer link on the guide and add the command line tools pkg instead or at least be more precise about this confusion.

Update for: Distribute merged into Setuptools 0.7+

Problem

  • Installation tutorial suggests to use Distribute, but Distribute has been merged into Setuptools 0.7+.

Resources

Proposed solution

  1. Replace Distribute installation instructions with just simply these commands for Setuptools:
    1. Download and install Setuptools from https://pypi.python.org/pypi/setuptools via ez_setup.py:

       $ python ez_setup.py
      

"What to do when your library gets popular"

This should include a section on "What to do when your library gets popular" addressing backwards compatibility, alpha and beta releases, how to bring in more committers, managing community expectations, and other similar topics.

TODO list, preferably with priority

Just wondering, can we get some sort of priority list of what to add onto the guide? On a related note, it'd be nice to see some sort of roadmap for where it's going; are we here to be, for example, an all out comprehensive wiki for all things Python?

License Comparison ideas

For http://docs.python-guide.org/en/latest/writing/license/, I have yet to find a comprehensive and simple comparison of open source licenses to reference.

http://paulmillr.com/posts/simple-description-of-popular-software-licenses/ is the best that I've found in graphic form and I believe the the information is accurate, but I'm not an expert!

Is the idea for the page to provide a simple listing of available licenses or suggest a 2-3 main license types depending on your situation?

(Sidenote, know of any statistics on what license type is used most on PyPI or preferred? Or what % of projects lack a license/trove classifier for license type?)

Are list comprehensions pythonic?

While I'd agree list comprehensions are generally nice, and make one feel very clever when using them, are they necessarily more pythonic than their counterparts?

In your section "Short Ways to Manipulate Lists" you call the following code "Bad",

# Filter elements greater than 4
a = [3, 4, 5]
b = []
for i in a:
    if i > 4:
        b.append(i)

and the following list comprehensions "Good",

b = [i for i in a if i > 4]
b = filter(lambda x: x > 4, a)

The section goes on to include more examples.

I would argue that calling the simpler code "Bad" simply because it takes up more space and doesn't include lambdas/one liners gives the wrong message, especially to beginners. Following the Zen of Python, specifically "Explicit is better than implicit", "Simple is better than complex", and "Readability counts" the list comprehensions could be qualified as less pythonic than the more explicit nested conditional clauses. However, this could be refuted by "Flat is better than nested".

I could be wrong, just thought I would bring it up.

html_title should be something more informative

# The name for this set of Sphinx documents.  If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
<title>The Hitchhiker’s Guide to Python! &mdash; pythonguide 0.0.1 documentation</title>

That isn’t very informative.

"Blueprint" link?

I saw "Blueprint" was listed as a systems administration tool. I'm just curious, do you have any link to this tool? I've never heard of it...

Vendorizing Dependencies

Hey, has anyone been working on the Vendorizing Dependencies section?

I've been waiting for it for quite a while, I basically got the hang of it by looking at ken's repos, but maybe there are some best practices I'm unaware of.

Would a pull request be accepted here? I could at least try to start writing something.

JSON

I was surprised to see there's nothing on JSON here, considering the existence of several good json libraries out there for python.

For example: I want to know why I should use simplejson vs the json module that ships with python.

"Mutable and Immutable Types" example

The best example in the Mutable and Immutable Types section of the Structuring Your Project page is:

# create a concatenated string from 0 to 19 (e.g. "012..1819")
nums = [str(n) for n in range(20)]
print "".join(nums)

It is considered the best example for being both more efficient and succinct.

Would this be a better example to use?

''.join(map(str, range(20)))

It's more succinct and is faster:

$ python -m timeit "nums = [str(n) for n in range(20)]; ''.join(nums)"
100000 loops, best of 3: 6.84 usec per loop

$ python -m timeit "''.join(map(str, range(20)))"
100000 loops, best of 3: 4.93 usec per loop

Perhaps prefer a set to a dict of empty values

The section "Create a length-N list of lists" includes a discussion on the O(n) performance of looking up a performance versus O(1) for a searching the keys of a dictionary that has empty values for each key. Specifically, the following code is presented:

d = {'s': [], 'p': [], 'a': [], 'm': []}
l = ['s', 'p', 'a', 'm']

def lookup_dict(d):
    return 's' in d

def lookup_list(l):
    return 's' in l

The text proceeds to recommend the use of this kind of dict over a list when looking through a set of values, for performance reasons:

Even though both functions look identical, because lookup_dict is utilizing the fact that dictionaries in python are hashtables, the lookup performance between the two is very different. Python will have to go through each item in the list to find a matching case, which is time consuming. By analysing the hash of the dictionary finding keys in the dict can be done very quickly.

Here are my potential beefs with this recommendation:

  1. It may be tempting to continue this as a discussion of lists of lists, but I don't believe this belongs under "Idioms." Perhaps it rather belongs in a section about data structures or performance.
  2. If the developer intends to only use the values (but no keys), I'd suggest recommend suggesting sets, a structure that is a much more fitting alternative for this use case. To be honest, I don't how the performance of the two compare, but even if sets are an inferior alternative (I doubt this when I think it over, but I have an insufficient understanding and no data to back it), it's a lot clearer. Assuming sets aren't vastly inferior, is there really a need to introduce an idiom when we have a competent data structure for the same thing?
  3. If you wish to suggest other structures than a list for performance, you might want to qualify that discussion with indicators as to when that would be appropriate. Without a caveat, this section looks like an endorsement of using lists for every case where you'll be searching the data structure. This is potentially justified (again, I lack an understanding about the underlying data structure), but my immediate hunch is that the overhead of hashing the values exceeds the time it takes to create a simpler element and search it sequentially. If you want to endorse a different data structure for performance reasons perhaps you'll want to say, "if you'll be looking this up multiple times, then you might want this."

Reading this over it all sounds far more critical than I mean it to be – I'm sort of cramming all the thoughts I have about this section into a single, almost exhaustive, discourse of retorts that I could imagine surfacing in a back-and-forth conversation about this. To compensate for my strident opposition, I should note that I think you're doing a great job.

make.bat file missing

Maybe the make.bat that Sphinx creates should be kept so that Windows contributors can easily build the files.

I18N

I have the plan to translate the guide to french, but there is not support for I18N, if you have no better recommendation, I will add the needed settings and adapt this Makefile https://gist.github.com/3742565 for this project.

What do you think ?

Worth mentioning unittest2?

Hey, just started scanning through the guide!

In the testing section, http://docs.python-guide.org/en/latest/writing/tests/#unittest2 covers the backport of unittest2 for Python 2.6.

As this is an "opinionated" guide and I'm assuming focused on current Python 2.7, is it worth mentioning backwards compatibility at this point?

Alternatively, since I would think backwards compatibly is a more advanced topic, perhaps it's worth pulling into a new section, that tox can link to?

Shinken

Take a look at http://shinken-monitoring.org/ for your Sysadmin section.

it's a Nagios replacement, but far better. and in python!

it's easy to write plugin and it scales very well.

Japanese translation

Thank you for the great guide of Python.
May I translate this guidebook to japanese?

Nitpicking in "gotchas: late binding"

Python's closures are late binding. This means that names within closures are looked up at the time the inner function is called.

I propose this wording be changed to

Python's closures are late binding. This means that the values of variables used in closures are looked up at the time the inner function is called.

The difference is illustrated by this code.

s = 'global'
def foo():
    s = 'nonlocal'
    def bar():
        print(s)
    del s
    bar()
foo()

Looking up the name at call time could be taken to mean that the variable to print is decided at call time. But in fact the variable (cell) is fixed at the time bar() is compiled, and it is just the value that is subject to change. In this case, the value is deleted and so NameError is raised.

(Yeah, I'm being a bit pedantic. I guess I'm really just testing out using github and the issue tracker. Nice guide. :) )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.