Send mail
The following three points are required to use the Mail sending function:
1. Open the SMTP service in the mailbox settings
2, open the mailbox authorization code, remember this authorization code
3, install Yagmail, with pip install YAGMAIL-0.10.212-PY2.PY3-NONE-ANY.WHL, if directly with Pip install Yagmail Chinese will have garbled
ImportYagmailusername='[email protected]'passwd='ljia1990312' #Authorization CodeMail=yagmail. SMTP (user=username, password=passwd, Host='smtp.163.com' #smtp_ssl=true)#If use is QQ mailbox or use of company mailbox has security agreement, need smtp_ssl=trueMail.send (to=['[email protected]'],#If multiple recipients are written as ListCc='[email protected]',#ccsubject='learn to send mail',#message Headercontents='Hello, are you happy today? ',#message bodyAttachments=[r'C:\Users\acer\Desktop\QQ20180317103804.png'] )Print('sent successfully')
Concept of object-oriented 1, class, object, instance, instantiation, attribute, method
1) class: A kind, a model
2) object: Refers to the specific thing, the model is made of something called the object
3) Example: Instances and objects are a meaning
4) Instantiation: Instantiation is the process of making things
5) attribute: is the variable
6) Method: Is the function inside the class
2. Classic class and new type
1) Classic class:
class Person : Pass # class first capitalization classic class
2) New class:
class Person2 (object): # new class pass
In Python3, there is no difference between the classic class and the new class, which is the breadth first.
In Python2, multiple inheritance, the classic class depth first, form class breadth first.
The super () method cannot be used by the classic class in Python2
In Python3, both classic and new classes can be used
3. constructor function and instantiation use
classPerson :def __init__(self):#constructors, functions that are executed when the class is instantiated, are not required to be writtenself.nose=2#Properties, Variablesself.face=2Self.head=10self.wing=4Print('Start Testing') defdriver (self):Print('Test it.') defFly (self):Print('can fly') defEat (self):Print('Nabe, Cakes')
__init__ (self) is a constructor that is not required to be written in a class. And when using variables, start with self. The other functions of the class can be directly self. Call these variables.
Class in use, the first must be instantiated, the class name + () to be instantiated, as follows
The constructor is executed when instantiated, so the constructor is executed after the above instantiation, and the output becomes: "Start Test", which is the value of the last sentence of print in the constructor.
To use a variable or function inside a class, after instantiating it, add the name of the function or variable name directly to the instance, as follows:
Zz.eat () # output eat function performs content zz.fly () # output fly function execution Content zz.fly () # output fly function again execution content zz.driver () # output driver function execution Content print(zz.wing) # output Wing Variable value Print (zz.nose) # output nose Variable value
4. Use of class incoming parameters and call other functions in function
classPerson :def __init__(self, name):#Incoming ParametersSelf.name =name changes the passed in parameter to the variable inside the class Self.nose= 2Self.face= 2Self.head= 10self.wing= 4Print('Start Testing') defdriver (self):Print('Test it.') self.eat ()#calling functions inside a class defFly (self):Print('%s can fly'% self.name)#get the variables inside the class defEat (self):Print('%s eat hot pot, cake'% self.name)
Class is passed into the parameter, the parameter is changed into a variable inside the class, and then other places within the class can be called directly using the self.+ variable name.
In the above code, the class passed in the parameter name, in the constructor, the passed parameter into the class inside the variable Slef.name, in the following fly and eat function can be called directly to use.
And the functions inside the class can be called each other.
za = person (' Liu Jia ') za.fly () za.driver ()print(za.name)
The result of the execution is:
Start testing Liu Jia can fly test Liu Jia Eat hot pot, Cake Liu Jia
Python Learning (27) Mail sending and object-oriented programming (1)