Linked Questions

205 votes
3 answers
179k views

How to get the concrete class name as a string? [duplicate]

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

Get just a class name without module, etc [duplicate]

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,102
0 votes
1 answer
353 views

Print only name of a class in Python [duplicate]

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
259 views

print list in proper way python [duplicate]

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
744 views

in Python 3.6, how do I print a type of a variable without seeing the word 'class' in the output [duplicate]

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 ...
Ohad Rozen's user avatar
-4 votes
1 answer
144 views

How to format my Python dictionary output? [duplicate]

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
242 views

If a = np.array([0,1,2,3,4,5,6,7,8,9,10]) what type is a? [duplicate]

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
Eli Charlotte Cervantes Callej's user avatar
0 votes
0 answers
180 views

Pass object of class type to function [duplicate]

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. } }...
stack underflow's user avatar
2 votes
1 answer
79 views

Is there Python Class instance have an attribute to get the class name? [duplicate]

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): ...
fanhualuojin154873's user avatar
0 votes
1 answer
88 views

How do I print class name in a method? [duplicate]

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
46 views

How do I use the name of any lower class as a variable in a higher class? [duplicate]

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&...
I really need help's user avatar
0 votes
0 answers
34 views

Get name of class from class type in python [duplicate]

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
34 views

Get type of object as simple class name [duplicate]

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'&...
Masked Raven's user avatar
0 votes
0 answers
27 views

Getting the name of the class of the tabs of a Tkinter notebook [duplicate]

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
  • 245
132 votes
10 answers
149k views

Get name of current class?

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 ...
Jonathan Ginsburg's user avatar

15 30 50 per page