1. First define a called module, file name cnf.py
#!/usr/bin/env python2. 7 #coding=utf-8"utf-8" ) class CNF (Object ): 'test' def getInfo (self): " The getInfo function of the CNF is called here "
2. Keynote module
" "The default encoding format in Python is the ASCII format, which fails to print correctly when the encoding format is not modified, so the error occurs when reading Chinese. The workaround is to add # at the beginning of the file-*-coding:utf-8-*-or #coding =utf-8it's all right." "#-*-coding:utf-8-*- # /usr/bin/EnvPython # import module Cnfimport cnfclass Test (Object): # global variable name name="Global _name"# Construct initialization variable def __init__ (self): # initialize P1 to Test yourself self.p1="AAAA"# Print the value of the global variable name, here in a different way than the Java constructor usage # in Java You can use SYSTEM.OUT.PRINTLN (name) directly; # instead of using System.out.println (Test.name); Print Test.name
# Copy the Cnf class in the CNF module to Test yourself, self.cnf=CNF. CNF () def used (self): print self.p1 print Test.name# Call Test yourself in the constructor to initialize the good CNF object and use the GetInfo () method print Self.cnf.getInfo () #静态类 @classmethod def Sssed (self): print"a static method is called Sssed"def Main (): # Instantiate Test object T=Test () t.used ()
# call static method sssed () test.sssed ()if__name__ = ='__main__': Main ()
Basic usage Instructions for Python