031 single case + job, 031 job

Source: Internet
Author: User

031 single case + job, 031 job

Class Person: _ v = None @ classmethod def get_instance (cls): if cls. _ v: return cls. _ v else: cls. _ v = Person () return cls. _ v # create object obj = Person without using class. get_instance () print (obj)

It seems quite different from Java, which makes me feel a little strange. What I can be sure of is the above. The Singleton mode cannot be implemented, and I will add it later.
Supplement:
I checked it and found it was wrong. I felt a problem. This is not the case for the found python2. * Singleton.

Python2. * type change, but an error will be reported. I will not analyze this error and it is complicated.

class  Singleton(object):    def __new__(cls,*args,**kwargs):        if not hasattr(cls,'_inst'):            cls._inst = super(Singleton,cls).__new__(cls,*args,**kwargs)             ###### TypeError:  object() takes no parameters        return  cls._instif  __name__ == '__main__':    class  A(Singleton):        def  __init__(self,s):            self.s = s    a = A('apple')    b = A('banana')    print(id(a), a.s)    print(id(b), b.s)

It may be better to use the top one. I'll take a look at other tutorials. Then add

 

 

Assignment: Course Selection System (My Back Cover/cover your face)
Roles: schools, students, courses, Lecturers
Requirements:
1. Create two schools in Beijing and Shanghai
2. Create three courses for linux, python, and go. linux \ py is available in Beijing, and go is available in Shanghai.
3. Course inclusion, cycle, price, create course through school
4. Create a class through the school, and associate the relevant courses and lecturers in the class
5. When creating a student, select a school and associate the student with a class.
5. Associate the instructor role with the school,
6. Two Role interfaces are provided.
6.1 student view, you can register, pay tuition, select a class,
6.2 In the instructor view, the lecturer can manage his/her own class, select a class in class, view the list of class students, and modify the score of the managed students.
6.3 Management View, creating lecturers, creating classes, and creating courses
7. The data generated by the above operations are serialized and saved to the file through pickle.

Source documentation

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.