First quote the official passage
Python shows the philosophy of "Swiss Army Knife". This can be best demonstrated by the advanced and robust features of its larger package.
Xmlrpc.client and Xmlrpc.server modules make remote procedure calls easier. Although the module has such a name, use
Users do not need to have knowledge of XML or process XML. An email packet is a library that manages mail information, including MIME and other based
An information document for RFC 2822. Unlike the Smtplib and Poplib modules that actually send and receive information, the email package contains a
A complete toolset for constructing or parsing complex message structures (including attachments) and implementing Internet coding and header protocols. Xml.dom and
The Xml.sax package provides a powerful support for the popular Information Interchange format. Similarly, the CSV module supports direct in the common database format
Write. In combination, these modules and packages greatly simplify the exchange of data between Python applications and other tools. Internationalization
Supported by GetText, locale and codecs packages.
That's one of the advantages of Python.
The previous section discusses some of the basics and getting started, where you start talking about things like other languages
This time for convenience, we use vs2012, the method of installing Plug-ins in the previous document has been mentioned.
After all, the code needs to be saved, and modular programming is also very important, so you need to save the file in a different place, especially in different folders, here to show the established file structure
Print ("Test1.count do There")
Print (' newfolder1.test2.count do there ')
Print (dir (test1))
Print (dir (newfolder1.test2))
def count (a,b,c):
def count (a,b,c):
Print (' Use a folder! ')
First, we can set the startup file by right-clicking the. py file.
We can use the Import keyword to invoke other module files
Explain the __init__ file, if you want to call a folder file, that folder must have such a file, before calling the file must be initialized with this file, is executed, of course, it doesn't matter if it's empty.
The built-in function dir () is used to search for the module definition by module name, which returns a list of stored string types:
The order of execution is obvious, and we can see that in the. py file, although we've only seen one function, there are actually a lot of predefined variables, such as __name__, that means the file name.
Ii. scope and Class
Python and C + + are related in class, but here's an official quote
The Python class mechanism implements classes in the language with minimal new syntax and semantics. It is a mixture of Modula-3 in C + + language. Like modules, the Python class does not have an absolute barrier between the user and the definition, but relies on the elegance of the user not to "break into the definition". On the other hand, most of the important attributes of a class are preserved intact: the class inheritance mechanism allows multiple inheritance, and derived classes can overwrite any method or class in the base class (override), and you can invoke methods of the base class using the same method name. An object can contain any number of private data.
For the time being, let's talk about the scope of things, and still use a section of the official teaching code.
Def scope_test ():
Def do_local ():
Spam = "Local spam"
Def do_nonlocal ():
Spam = "nonlocal spam"
Def do_global ():
Spam = "Global spam"
Spam = "Test spam"
Print ("After local assignment:", spam)
Print ("After nonlocal assignment:", spam)
Print ("After global assignment:", spam)
Print ("In global scope:", spam)
nonlocal non-partial global global
Indeed, like C + +, design-time encapsulation is not as perfect as C #, leaving us with an opportunity to access from outside
Now let's talk about class
Inherited method Class Lei (Lei1,lei2,lei3 ...) No more mention here, you can inherit multiple classes.
One of the differences between Python2.7 and pytho3.3n is. 3.3 There is no classic class, all new classes, the original class object is not a parent class, then it is inherited from object, but in 3.3 became, in the absence of inheriting the parent class, it inherits the object class by default. Although it is a drag on efficiency, it also makes the code structure more complete.
This is somewhat related to the mainstream C #.
Let's just say it's a basic class.
def __init__ (SELF,NM,AG):
Print ("constructor run")
def shuchu (self):
X=person (' Wangji ', 20)
__init__ () is the so-called constructor, which is no longer mentioned here.
For friends who have studied C #, we can use self as this, and the first parameter to define the function is self,
The principle is the method of the object in Python, it needs to call itself first, so it counts as a parameter, here is written, the first parameter of the function we default to self can
We can try, the overload of the method is not good, but python as an object-oriented language, naturally does not lose the function of overloading this object-oriented language common to the important features .... In fact this place we have to use the default parameters to achieve this purpose. I don't know much about this place, but a method with a default parameter can really solve some of the problems associated with overloading.
All the methods in Python are essentially virtual methods, so rewriting is basically the same as other languages.