# Python
What others have written (library)
A:*foo1 Foo2 Foo3 Foo4
B:*foo2 foo1 Foo3 Foo4
From xx import xx
From XX is a bag of things
__xx__.py not open to the public
1 # filedemo.py 2 # -*-coding:utf-8-*- 3 4 Span style= "COLOR: #0000ff" >def Foodemo (): 5 print ( filldemo.filedemo.ffoodemo () "" Span style= "COLOR: #000000" >) 6
1 # demo.py 2 # -*-coding:utf-8-*- 3 from Import Foodemo 4 5 Foodemo ()
Homework Explanation
New shop.py
New login.py
0 with open ("Userinfo.txt") as File:
Equivalent to doing the following two lines of code at the same time
You don't have to worry about the file being closed.
file = open ("Userinfo.txt") #r read mode
File.close ()
1 #login.py2 #-*-coding:utf-8-*-3Userinfos = [] 4With open ("Userinfo.txt") as File:#ensure the timeliness of data5 forIteminchfile.readlines ():6 userinfos.addend (item)7 defLogin (NAME,PSW):8 forUserInfoinchUserinfos:9temp =Userinfo.split ()Ten ifName = = Temp[0] andPSW = = Temp[1]: One returnTrue#Landing Success A Else: - returnFalse#Login Failed
1 #shop.py2 #-*-coding:utf-8-*-3 fromLoginImportLogin4 #Login5Name = input ("Logo ID:")6PSW = input ("\r\nlogo PSW:")7 8 if(Login (NAME,PSW)):9 Print("\r\nok")Ten Else: One Print("\r\nno") A
two files which run first
0 The imported file executes the code once.
0 because Python is an explanatory language, the main function does not exist. PY Inside
0__name__ Each program has a default variable
If the file executing the code is a __main__
1 #logo.py2 #-*-coding:utf-8-*-3 Print(__name__)4Userinfos = [] 5With open ("Userinfo.txt") as File:#ensure the timeliness of data6 forIteminchfile.readlines ():7 userinfos.append (item)8 defLogin (NAME,PSW):9 forUserInfoinchUserinfos:Tentemp =Userinfo.split () One ifName = = Temp[0] andPSW = = Temp[1]: A returnTrue#Landing Success - Else: - returnFalse#Login Failed the - - if __name__=='__main__': - ifLogin (Input ("Name:"), Input ("\r\npassword")): + Print("\r\nok") - Else: + Print("\r\nno")
1 #shop.py2 #-*-coding:utf-8-*-3 fromLoginImportLogin4 #Login5 6 if __name__=='__main__':7Name = input ("Logo ID:")8PSW = input ("\r\nlogo PSW:")9 Ten if(Login (NAME,PSW)): One Print("\r\nok") A Else: - Print("\r\nno")
1 #user.py2 #-*-coding:utf-8-*-3Form LoginImportLogin4 defUserpay (Name,psw,money):5 ifLogin (NAME,PSW):6 Print("authorization to start the charge successfully)7 With open (file) as data:8 forIteminchdata.readlines ():9UserInfo =Item.split ()Ten ifName = =Userinfo[0]: OneUSERINFO[3]-= Money A Else - Print("Authorization Failure")
the way of the function
def foo (*arg):
An asterisk is a list of transmitted
def foo (**arg):
Two asterisk is a dictionary for transmission
007 Python Modules and functions