In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the flashy skills of Python". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the flashy skills of Python?"
Show limited interfaces to the outside
When publishing python third-party package, you do not want all functions or class in the code to be externally import, add _ _ all__ attribute to _ _ init__.py
Fill in the name of the class or function that can be import in the list, which can limit the import and prevent other functions or classes from external import.
The usage of filter
Map and reduce are used more frequently than filter. Filter, as its name, filters out some elements according to certain rules.
A single example of decorator
Using decorators to implement a simple singleton pattern
Property decorator
Define private class properties
Combine property with decorators to privatize attributes (simpler and more secure implementation of get and set methods)
# python built-in function
Property (fget=None, fset=None, fdel=None, doc=None)
Fget is a function to get the value of an attribute, fset is a function to set the value of an attribute, fdel is a function to delete an attribute, and doc is a like a comment. From an implementation point of view, these parameters are optional
Property has three methods getter (), setter (), and delete () to specify fget, fset, and fdel. This means that the following line
Magic partial
The use of partial is very similar to the imitating function (function object) in C++.
The operation mode similar to partial is given in stackoverflow.
Mysterious eval
Eval I understand as an embedded python interpreter (this interpretation may be biased), which interprets the string as the corresponding code and executes it, and returns the execution result.
Take a look at the following example
Etattr
Getattr (object, name [, default]) Return the value of the named attribute of object. Name must be a string. If the string is the name of one of the object's attributes, the result is the value of that attribute. For example, getattr (x, 'foobar') is equivalent to x.foobar. If the named attribute does not exist, default is returned if provided, otherwise AttributeError is raised.
Through the name of type string, the value corresponding to the name property (method) of the object is returned. If the property does not exist, the default value is returned, which is equivalent to object.name.
Read and write csv files
String formatting
A feature that is very easy to use and many people don't know about.
> name = "andrew"
> "my name is {name}" .format (name=name)
'my name is andrew'
Thank you for your reading, the above is the content of "what are the flashy skills of Python?" after the study of this article, I believe you have a deeper understanding of what the flashy skills of Python have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.