Home > other >  Use the from import clearly as long as the import zuoye_9_45 Restaurant, but the whole module perfor
Use the from import clearly as long as the import zuoye_9_45 Restaurant, but the whole module perfor

Time:09-25

File wenjian_9_45 content:
Class Restaurant () :
Def __init__ (self, restaurant_name cuisine_type, restaurant) :
Self. Restaurant_name=restaurant_name
Self. Cuisine_type=cuisine_type
The self. The restaurant=restaurant
Def describe_restaurant (self) :
Print (self restaurant_name, self. Cuisine_type)
Def open_restaurant (self) :
Print (' Restaurant is open.)
Def set_number_served (self, miles) :
The self. The restaurant=miles
Def read_number (self) :
Print (" My restaurant 's number is "+ STR (My_restaurant. Restaurant))
Def increment_number (self, increment_number) :
The self. The restaurant +=increment_number
Pork My_restaurant=Restaurant (' Zonda ', 'such as', 0)
Print (" My retaurant 's name is "+ My_restaurant. Restaurant_name)
Print (" My restaurant 's type is "+ My_restaurant. Cuisine_type)
My_restaurant. Read_number ()
My_restaurant. Describe_restaurant ()
My_restaurant. Open_restaurant ()
My_restaurant. Set_number_served (100)
My_restaurant. Read_number ()
My_restaurant. Increment_number (20)
My_restaurant. Read_number ()

The class User () :
Def __init__ (self, first_name, last_name, login_attempts) :
The self. The first_name=first_name
Self. Last_name=last_name
Self. Whole_name=first_name + "+ last_name
Self. Login_attempts=login_attempts
Def describe_user (self) :
Print (self. First_name. Title () + "+ self. Last_name. Title ())
Def greet_user (self) :
Print (' Hello, '+ self. Whole_name. Title ())
Def inrement_login_attempts (self) :
Self. Login_attempts +=1
Def reset_login_attempts (self) :
Self. Login_attempts=0
Me=User (' Zonda ', 'Jiang, 19)
Me. Describe_user ()
Me. Greet_user ()
Me. Inrement_login_attempts ()
Print (STR (me) login_attempts))
Me. Inrement_login_attempts ()
Print (STR (me) login_attempts))
Me. Inrement_login_attempts ()
Print (STR (me) login_attempts))
Me. Reset_login_attempts ()
Print (STR (me) login_attempts))


Import from zuoye_9_45 file Restaurant categories:
The from zuoye_9_45 import Restaurant
Pork My_restaurant=Restaurant (' Zonda ', 'such as', 0)
My_restaurant. Describe_restaurant ()

Results: My retaurant 's name is Zonda
My restaurant 's type is pork such as
My restaurant 's number is 0
Zonda pork such as
The Restaurant is open.
My restaurant 's number is 100
My restaurant 's number is 120
Zonda Jiang
Hello, Zonda Jiang
20
21
22
0
Zonda pork such as

The problem: as long as the import obviously zuoye_9_45 Restaurant, but the whole module perform again before the final class Restaurant

CodePudding user response:

Because you do not have the following code to lay down their function, the import will be executed

CodePudding user response:

You put the following code in the main function in
If __name__=="__main__ ':
XXXX
The import will not perform

CodePudding user response:

How to modify it

CodePudding user response:

Don't quite understand, can point in more detail

CodePudding user response:

To solve the problem! But I don't quite understand the meaning of this sentence, brother can explain
  • Related