Linked Questions

39 questions linked to/from Getting the class name of an instance
205 votes
3 answers
180k views

I want to avoid calling a lot of isinstance() functions, so I'm looking for a way to get the concrete class name for an instance variable as a string. Any ideas?
user7305's user avatar
  • 6,031
15 votes
1 answer
9k views

I'm probably overlooking something simple. Given an instance of a class, I'd like to get just the class name. For example: class Foooo: pass instance = Foooo() print("instance.__class__ = "+str(...
Matthew Lund's user avatar
  • 4,112
0 votes
1 answer
359 views

I’m learning Python 3. My code numbers = [1, 2] print( type( numbers[0] )) outputs <class ‘int’> How do I print only ‘int’ or int
Global nomad's user avatar
  • 1,022
0 votes
1 answer
272 views

I have a list "values" it has the types information i just to print it properly in ipython notebook i am trying to print case1: > print values [<type 'str'>, <type 'str'>, <type ...
Lohith's user avatar
  • 954
2 votes
0 answers
753 views

I tried this: print(type(list(soup.children)[0])) but the output I get includes the word 'class' Output: [<class 'bs4.element.Tag'>] I'd like it to only show me 'bs4.element.Tag', just like if ...
-4 votes
1 answer
149 views

This line for i,k in (p[0].__dict__).items(): print (i,type(k)) prints code_event <class 'str'> code_event_system <class 'str'> event_no <class 'int'> group_no <class 'int'&...
Djikii's user avatar
  • 157
-5 votes
1 answer
263 views

Si a = np.array([0,1,2,3,4,5,6,7,8,9,10]) what type is A? well im trying to learn how to use python but im having a lot of problems, idk if you can help me
0 votes
0 answers
185 views

This might seem very trivial, but I cannot figure this out. In OOP language like c#, I can pass instance of self type to a function. For example, class Edge { void F(Edge e){ // Do something here. } }...
2 votes
1 answer
90 views

I have below Python code: class Shape(object): def draw(self): raise NotImplementedError class Triangle(Shape): def draw(self): print("draw triangle") class Square(Shape): ...
0 votes
1 answer
90 views

I made a method and called onto it with super() but I do not know how to write the name of the class in a print statement! from abc import ABC, abstractmethod class Clothing(ABC): @abstractmethod ...
Jecise's user avatar
  • 3
1 vote
1 answer
48 views

When I run this Python program, dog.bark() returns "This dog is barking" but dog.eat() returns "This animal is eating". I need dog.eat() to also return "This dog is eating&...
0 votes
0 answers
45 views

Given a class type, I'd like to get its name and print it to console. I have access to the class type but not an instance. class Foo: pass def print_class_names(klass): print(klass.__some_dunder?...
jacob_g's user avatar
  • 776
3 votes
0 answers
41 views

When I use the type function, it returns me: >>>print(type('string')) <class 'str'> class Test: pass test_obj = Test() >>>print(type(test_obj)) <class '__main__.Test'&...
0 votes
0 answers
27 views

In the following code I can access information in a notebook tab, in this case, the flag variable of the tab frame. This can be useful in several situations; in my case, when I drop one of the tabs. ...
amrsa's user avatar
  • 255
133 votes
10 answers
150k views

How do I get the name of the class I am currently in? Example: def get_input(class_name): [do things] return class_name_result class foo(): input = get_input([class name goes here]) Due ...

15 30 50 per page
1
2 3