What good habits should you develop in Python programming?

Source: Internet
Author: User
I think the programming habit is very important, in the beginning to develop these habits, not only can improve the speed of programming, but also to reduce the probability of the occurrence of bugs. I hope you will share good programming habits.

Reply content:

It is mentioned that you should strictly follow the Python Coding style specified in Pep 8 to write, read more English documents, and take a look at some excellent libraries (such as requests)

In fact all this, with Jetbrain Pycharm IDE is good:
(Python IDE & Django IDE for Web developers:jetbrains pycharm

-Free, full platform (Win, MacOS, Linux) for a complete IDE experience for Python

-What is the level of IntelliJ (IntelliJ) that is not lost? For me, IntelliJ's experience in writing Java is amputated eclipse.)

-Auto hint coding Style: Empty two lines between functions, 4 space indent, function name, etc, all will prompt you! It's more convenient than a PEP8 to check script.

-You can click any function, a lib, for all Python built-in Lib, and already installed third-party Lib is effective, you can quickly open the implementation of the third-party function, easy to view its documentation & implementation details (this does not have to manually go to the Python lib directory to go through, Especially helpful for learning good third-party Lib)

-Includes a reference to Unit Test,pycharm also provides One-click generate Test case

In a word, I recommend you just get started Python, early use of pycharm to develop, it feels like an experienced master, hand-in-hand staring at you programming ^^ 1. Develop the habit of reading documents and materials in English
2. Read the requests library author's written by this Python guide:the hitchhiker ' s Guide to python!
3. Follow the above to do the virtual environment, unpacking, List derivation, iterators, generators, adorners, abstract base classes, static methods, class methods, not just some of the above what the Daniel said the basic indentation, automated testing and the like
The most important thing is to write the characteristics of Python.

PyConChina2014 Hangzhou field @ Shihuanmin shared theme
idiomatic.py--How to write a Python code with a high B-grid

Original (Outside the wall):
https:// docs.google.com/present ation/d/1mer-sfltelltms_qxlwbw1aedx997jsn6ed3mcyv81k/edit#slide=id.g475844c86_0333

Translation (Personal translator):
Reprint: idiomatic.py

are small details, but these details show that the PY is different > each public function has a unit tests
> The names of public functions and classes accurately summarize their purpose
> Write docstring
> Do not write in-code comments (inline comment)
> Release code, no print.
> No more than 10 rows per function (excluding docstring) use duck types with caution, and for objects that are passed in as function arguments (especially instances of custom classes), it is best to use the Type/isinstance method for type checking before using, or Python3 Function Annotations function to make comments.

This increases the readability of the code and makes it easier for the IDE (such as Pycharm) to understand your code, providing more accurate error hints, code jumps, and auto-completion. 1, always open an interpreter to use. Forget the API direct Dir+help, forget the usage directly inside the interpreter to experiment.
Making the most of Python's ability to introspect is not only helpful for beginners to get started as soon as possible, but also useful for future use.

2,import Dafa is good. When dealing with a class of more general and complex problems with Python, first search for a wheel that has no ready-made wheels: There are a lot of packages available, and many projects are active on GitHub.

Although not specific programming habits, but all of my firsthand. The above points are the reasons why I like Python. (^_^) (¬_¬) There should is one--and preferably only one--obvious the-do it.
So
A good habit is to search for problems on StackOverflow, then memorize the answers you've adopted and use them later. It's best to read the PEP8 code style before you start coding. Otherwise, the old staff code reviews when see the new style of the wonderful people want to tear forced to tell you, the habit of writing test code is definitely a smart choice.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.