🌐
Facebook
facebook.com › PythonDataScience › posts › -pep-8-python-程式碼風格指南-python-之父-guido-van-rossum程式碼更多時候是被讀而非寫的code-is-read-much- › 1086210728490552
【 PEP 8 - Python 程式碼風格指南】 ...
Explore the things you love · Log into Facebook · English (US) · فارسی · العربية · Türkçe · Deutsch · Français (France) · Polski · More languages…
🌐
Industry Wired
industrywired.com › industry wired › latest news › python at facebook: use cases and best practices
Python at Facebook: Use Cases and Best Practices
October 3, 2024 - Code readability is paramount in a collaborative environment. Facebook promotes the use of PEP 8, the official Python style guide.
🌐
Facebook
facebook.com › LearnRealPython › posts › code-style-the-hitchhikers-guide-to-python › 1169385825409799
Code Style — The Hitchhiker's Guide to #Python
Real Python. 160,150 likes · 540 talking about this. Online Python Training & Expert Community: Tutorials, Video Courses, Books, Quizzes...and More! Join 3,000,000 Monthly Readers at realpython.com
🌐
Facebook
facebook.com › groups › python › posts › 1154344422072787
Thoughts on Python's Pep 8 style guide? Disagreements or ...
Popular groups · Find communities for you · Over 1 billion people across the globe are using Facebook Groups to explore their favorite topics · Log in · Categories · Science & tech · Travel · Animals · Sports & fitness · Entertainment
🌐
Facebook
facebook.com › LearnRealPython › posts › -how-to-write-beautiful-python-code-with-pep-8-learn-how-to-write-high-quality-r › 1224413833240331
Real Python | Facebook
Real Python. 160,150 likes · 540 talking about this. Online Python Training & Expert Community: Tutorials, Video Courses, Books, Quizzes...and More! Join 3,000,000 Monthly Readers at realpython.com
🌐
Facebook
facebook.com › groups › python › posts › 682601819247052
What are the security risks of not using Python style guides?
Popular groups · Find communities for you · Over 1 billion people across the globe are using Facebook Groups to explore their favorite topics · Log in · Categories · Science & tech · Travel · Animals · Sports & fitness · Entertainment
🌐
Napwell
napwell.com › hpm61xf0 › facebook-python-style-guide-16ee1c
Napwell
Aviso legal: las referencias a una empresa, producto o servicios específicos en este Sitio no están controladas por GoDaddy.com LLC y no constituyen ni implican la asociación ni respaldo a anunciantes externos
🌐
Facebook
facebook.com › groups › pythonclcoding1 › posts › 26967374872861308
Popular groups | Facebook
Popular groups · Find communities for you · Over 1 billion people across the globe are using Facebook Groups to explore their favorite topics · Log in · Categories · Science & tech · Travel · Animals · Sports & fitness · Entertainment
Find elsewhere
🌐
Facebook
facebook.com › groups › python › posts › 556278378546064
Plz tell me important python codes and their uses and style
Popular groups · Find communities for you · Over 1 billion people across the globe are using Facebook Groups to explore their favorite topics · Log in · Categories · Science & tech · Travel · Animals · Sports & fitness · Entertainment
🌐
Facebook
facebook.com › groups › 409382926171440 › posts › 665023670607363
Style guide for #Python code
Popular groups · Find communities for you · Over 1 billion people across the globe are using Facebook Groups to explore their favorite topics · Log in · Categories · Science & tech · Travel · Animals · Sports & fitness · Entertainment
🌐
Facebook
facebook.com › groups › cs50 › posts › 1046617882151923
style50 guide for Python
Popular groups · Find communities for you · Over 1 billion people across the globe are using Facebook Groups to explore their favorite topics · Log in · Categories · Science & tech · Travel · Animals · Sports & fitness · Entertainment
🌐
Python
python.org › dev › peps › pep-0008
PEP 8 -- Style Guide for Python Code | Python.org
March 3, 2022 - Facebook · Twitter · Chat on IRC · Python>>> Python Developer's Guide>>> PEP Index>>> PEP 8 -- Style Guide for Python Code · Contents · Introduction · A Foolish Consistency is the Hobgoblin of Little Minds · Code Lay-out · Indentation · Tabs or Spaces?
🌐
Facebook
facebook.com › groups › pythonph › posts › 1704739089581886
I decided to document the way I write Python, so I wrote a ...
Popular groups · Find communities for you · Over 1 billion people across the globe are using Facebook Groups to explore their favorite topics · Log in · Categories · Science & tech · Travel · Animals · Sports & fitness · Entertainment
Top answer
1 of 3
22

PEP 8 is pretty much "the root" of all common style guides.

Google's Python style guide has some parts that are quite well thought of, but others are idiosyncratic (the two-space indents instead of the popular four-space ones, and the CamelCase style for functions and methods instead of the camel_case style, are pretty major idiosyncrasies).

On to your specific questions:

1.- What is the most widely used column width? (the eternal question) I'm currently sticking to 80 columns (and it's a pain!)

80 columns is most popular

2.- What quotes to use? (I've seen everything and PEP 8 does not mention anything clear) I'm using single quotes for everything but docstrings, which use triple double quotes.

I prefer the style you're using, but even Google was not able to reach a consensus about this:-(

3.- Where do I put my imports? I'm putting them at file header in this order.

import sys import -rest of python modules needed-

import whatever import -rest of application modules-

Yes, excellent choice, and popular too.

4.- Can I use "import whatever.function as blah"? I saw some documents that disregard doing this.

I strongly recommend you always import modules -- not specific names from inside a module. This is not just style -- there are strong advantages e.g. in testability in doing that. The as clause is fine, to shorten a module's name or avoid clashes.

5.- Tabs or spaces for indenting? Currently using 4 spaces tabs.

Overwhelmingly most popular.

6.- Variable naming style? I'm using lowercase for everything but classes, which I put in camelCase.

Almost everybody names classes with uppercase initial and constants with all-uppercase.

2 of 3
2

1.- Most everyone has a 16:9 or 16:10 monitor now days. Even if they don't have a wide-screen they have lots of pixels, 80 cols isn't a big practical deal breaker like it was when everyone was hacking at the command line in a remote terminal window on a 4:3 monitor at 320 X 240. I usually end the line when it gets too long, which is subjective. I am at 2048 X 1152 on a 23" Monitor X 2.

2.- Single quotes by default so you don't have to escape Double quotes, Double quotes when you need to embed single quotes, and Triple quotes for strings with embedded newlines.

3.- Put them at the top of the file, sometimes you put them in the main function if they aren't needed globally to the module.

4.- It is a common idiom to rename some modules. A good example is the following.

try:
    # for Python 2.6.x
    import json
except ImportError:
    # for previous Pythons
    try:
        import simplejson as json
    except ImportError:
        sys.exit('easy_install simplejson')

but the preferred way to import just a class or function is from module import xxx with the optional as yyy if needed

5.- Always use SPACES! 2 or 4 as long as no TABS

6.- Classes should up UpperCaseCamelStyle, variables are lowercase sometimes lowerCamelCase or sometimes all_lowecase_separated_by_underscores, as are function names. "Constants" should be ALL_UPPER_CASE_SEPARATED_BY_UNDERSCORES

When in doubt refer to the PEP 8, the Python source, existing conventions in a code base. But the most import thing is to be internally consistent as possible. All Python code should look like it was written by the same person when ever possible.

🌐
Google
google.github.io › styleguide › pyguide.html
Google Style Guides | Style guides for Google-originated open-source projects
Python is the main dynamic language used at Google. This style guide is a list of dos and don’ts for Python programs.
🌐
Python
python.org › doc › essays › styleguide
Python Style Guide | Python.org
The style guide originally at this URL has been turned into two PEPs (Python Enhancement Proposals): PEP 8 for the main text, and PEP 257 for docstring conventions.