5 white python learning journey

Advanced Grammar

1.1 Management Module

First, tell us about the development of the module under development environment where it pyvharm, that is a python module file to point py suffix. Use simple module Needless to say, Here are some methods to use modules

Can also be used from the module name means that import * import all content, with the subsequent recommendations if __name__ = '__main__' statement as the program entry;

# Here p01 code module 
class Student ():
     DEF  the __init__ (Self, name = ' LHS ' , Age = 18 is):   # initialization init function of 
        the self.name = name 
        self.age = Age 

    DEF say (Self):                           # say function, self is a parameter 
        Print ( ' My name iS {0} ' .format (the self.name)) 


DEF sayHello ():
     Print ( ' available for purchase to My Home ' ) 


Print ( ' the I AM The First Module1 ' )

# Here is a code module p02 
Import P01      #   or import p01 as TU or from p01 import function name, class name 
STU = p01.Student ( ' LHS ' , 18 is)        # define a new instance of 
stu.say ()    # calling module function class 
p01.sayhello ()   # function call program modules run sequentially: first run again introduced into the module first module; Step say function call; a third step with sayHello () function 
# import method 2 
import the importlib   # introduction method two 
the TU = importlib.import_module ( ' P01 ' ) 
STU = TU.Student () 
stu.say ()

Search Path module: load modules, the system will search module import sys where this package, then use sys.path to acquire property through the list of paths; for general use append to add the path

1.2 package

Package is a way to organize the management code, the amplifier module

Introducing package: import package_name package name point is point function name class name; import modules on the package:

Import package.module 
        package.module. function name 
        package.module. class Function name 
        package.module. .var class     # This is a method of introducing three kinds of modules

Further introduction method
from package import module_name such content is not executed __init__ introduced inside
from package import * import all; that is, to use the function name to point class

from package.module import * class point is to use the function name to

__all__ = [ 'module 1', 'module 2'] # __all__ content execution only inside. The rest is not performed

1.3 Exception Handling

An exception is logically correct grammar problems arise under (such as lack of configuration). Exception is a class, it can be processed and used. In addition to the except (at least one), else, and are optional hfinally
following is a simple example

# Simple excursion case 
the try : 
    NUM = int (INPUT ( ' Please Number INPUT A ' )) 
    RST = 100 / NUM
     Print ( ' of The Last Number 0 {IS} ' .format (RST))
 except : # can be written here except NameError etc. B AS:
     Print ( ' ? the What DID you the INPUT ' ) 
    Exit ()
    

Prompt code placed on the wrong issue with except, the more specific the more forward placement error; the more errors found earlier, the more execution finally statement directly; In addition, all exceptions are subclasses of the exception, certainly interception.

Abnormalities can also be used to manually raise an exception is thrown. Direct attention to raise ValueEorror with custom exception must be a system abnormality such as a subclass of class lhserror (Va lueError):

1.4 Common Module

We used module in python are generally: calender time datatime timeit os shutil zip math string, in addition to the string exceptions, all other modules need to be imported before use.

calendar: contains the number of characters following parameters w l interval between each date the number of rows occupied by weekly c is a number of intervals between characters per month, the effect can be adjusted by the print control parameter values;

Import Calendar 
CAL = calendar.calendar (2017, W, L, C ) to adjust the parameter # WLC
 Print (CAL)   # output 2017 calendar 
calendar.isleap (0217) # determines whether it is a leap year 2017 
calendar.monthrange (2017,3) # return to the beginning of the week, a total of how many days. Tuple type
calendar.leapdays (1998,2018) # determine the number of leap years between left closed and opened
calnedar.monthcalenda (2018,3) # matrix print date, there is few, it is not of 0. The
Calendar. prcal (2018) # print calendar 2018
calendar.premonth (2018,3) # print March 2081 calendar
calendar.weekday (2018,3,26) # print out of the week
 

Time Module:

Timestamp --- 1970 at 0:00 on January 1. Miao seconds since experience whose type is int or float uncertain

UTC time --- also known as Coordinated Universal Time, GMT British standard
time to daylight saving time adjustment --- fast during the summer for an hour, but the essence is still 24 hours
time Ganso:
- a general time tuple contains;
- timezone for the next time when there is no daylight saving time interval, the current utc time zone and time difference of seconds, you are eight districts in East -28,800 output time.zone to display
- daylight () function to test whether the current state of daylight saving time

Today's  mood is a little nervous. I donnot want the thing to go worse, but it happens suddenly. Now her emotion is mild,but the scar remains in it. Though things dosen't over, I still affair that she will leave me in the future.I love her than any other girls, and I want to marry her. So please don't angry with me, I got hurt.

  

Guess you like

Origin www.cnblogs.com/icetree/p/11046958.html