1

I have a problem that I don't even know how to search for. Look at this simple class as an example:

class Student(object):
    def _init_(self):
        self.id = 0
    
    def inc(self):
        self.id += 1
 
std_gen = Student

What is the type of std_gen? I tried:

print(type(std_gen))

and I got this:

<class 'type'>

I need to find it's type and add it to a docstring. I can't even find something that returns True with isinstance(std_gen, something)

Edit: I found isinstance(std_gen, type) returns True but that barely makes sense in a docstring. What does that mean?

PouyaH
  • 31
  • 7
  • 2
    `std_gen` is just another name for `Student`, you did not actually instantiate the class (which would be written `Student()`). – jasonharper Jun 30 '20 at 16:31
  • https://stackoverflow.com/questions/510972/getting-the-class-name-of-an-instance – Pavan Chandaka Jun 30 '20 at 16:34
  • It can't be the same since `std_gen` acts as a constructor and what `std_gen()` returns is an instance of that class. – PouyaH Jun 30 '20 at 16:34
  • @PavanChandaka Could you explain a bit? I looked through the page and couldn't find the answer. – PouyaH Jun 30 '20 at 16:43

2 Answers2

1

Class Student is an instance of type 'type'. See metaclass for more information. So type(Student) is 'type'. So

s = Student()
std_gen = Student
type(s) // <class 'Student'>
type(std_gen) // <class 'type'>

To sum up, s is instance of Student, Student is instance of type and stu_gen is just alias of Student.

cjkkkk
  • 68
  • 5
0

I believe this is the solution that you're looking for.

print(type(std_gen()))
jonp77
  • 11
  • 4