How to make your python code more powerful?

Source: Internet
Author: User
Tags coding standards
I feel that my python code is very frustrated and I think it looks like C ++. I think other people's python is so cool and awesome. How can I make my python look more powerful? Finally, I felt that my python code was very frustrated, and I was thrown up looking like C ++. I think other people's python is so cool and awesome. How can I make my python look more powerful? Response from Zhejiang (Hangzhou): This year (2014) Hangzhou PyCon has a topic called You can find the subtitle on the first page of the presentation:
Thank the lecturer @ Shi yuanmin for your presentation. Thank the lecturer @ Shi yuanmin for the presentation idiomatic. py. , It seems to be turning over
In fact, if you search for idiomatic python directly in the search engine, you will get a lot of related topics. If you look at it more often, you will certainly be able to take off the big hat "looks like C ++" and I will give it a dry offer:
Code Like a Pythonista: Idiomatic Python:

Http://python.net /~ Goodger/projects/pycon/2007/idiomatic/handout.html


Python Idioms:

Http://safehammad.com/downloads/python-idioms-2014-01-16.pdf


Write Idiomatic Python jeff Knupp: google by yourself

First of all, the most basic code specifications should be followed. The so-called "no rule" is not a square area. A good indent style and naming method make your code more concise;
Secondly, data abstraction and process abstraction are required. Recently, we have been reading SICP. The book has repeatedly emphasized abstraction and extracted public logic, looking at the code from a higher and more general perspective, the code that meets this requirement is undoubtedly like a deeply refined ore with a higher content;
Again, the code is much farther away from the C style, and the closer it is to Lisp, the more powerful it is. Functional programming is part of what you must try;
Finally, a few and refined comments are definitely the final touch. -You can use map to never use list comprehension.
-You can use lambda to never define a function name.
-You can use yield to never append to list and then return data.
-Add * args and ** kwargs to the function signature, regardless of whether it is used or not.
-Define an empty class named XXXMixin, and add this Mixin to the inheritance list no matter whether it is usable or not.
-Use super to call the function of the parent class, and use the previous one to let the code readers jump back and forth.

UPDATE: likes to likes... Everyone understands that I am at joking, right...
I think other people's python is so cool and awesome
You have already said that others' python is so cool that you must have your own set of measurement standards. Isn't it a matter that you know how to write it? If you have more questions
The comments are sufficient and conform to the coding standards. When submitting the main code and submitting the complete testing code, all the coverage rates are detected at 100%. This reflects the industry's conscience and practices.

After running for N years, there will be no bugs, no changes, and no changes are required.

Is it so powerful? The subject seems to want Python code to be more Pythonic.
How can I miss Python Cookbook?
Link to the Chinese version: Python Cookbook 3rd Edition Write LISP for a while before writing Python. Ask me for code view. Since PEP8 is mentioned upstairs, mention Pylint-code analysis for Python.
It's okay to give the code a score and scare them. It's no better than this score.

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.