Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9185285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:14:37+00:00 2026-06-17T19:14:37+00:00

>>> class Foo: … ‘it is a example’ … print ‘i am here’ …

  • 0
>>> class Foo:
...   'it is a example'
...   print 'i am here'
... 
i am here
>>> Foo.__name__
'Foo'
>>> Foo().__name__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: Foo instance has no attribute '__name__'
>>> Foo.__doc__
'it is a example'
>>> Foo().__doc__
'it is a example'
>>> Foo.__dict__
{'__module__': '__main__', '__doc__': 'it is a example'}
>>> Foo().__dict__
{}
>>> Foo.__module__
'__main__'
>>> Foo().__module__
'__main__'
>>> myname=Foo()
>>> myname.__name__
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
AttributeError: Foo instance has no attribute `__name__`

What is the reason instances have no attribute __name__?
maybe it is ok that the __name__ of instance-myname is myname.
would you mind tell me more logical, not the unreasonable grammar rules?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:14:38+00:00Added an answer on June 17, 2026 at 7:14 pm

    You’re seeing an artifact of the implementation of classes and instances. The __name__ attribute isn’t stored in the class dictionary; therefore, it can’t be seen from a direct instance lookup.

    Look at vars(Foo) to see that only __module__ and __doc__ are in the class dictionary and are visible to the instance.

    For the instance to access the name of a class, it has to work its way upward with Foo().__class__.__name__. Also note that classes have other attributes such as __bases__ that aren’t in the class dictionary and likewise cannot be directly accessed from the instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this example: class Foo(object): def __del__(self): print Foo died class Bar(object): def __init__(self):
class foo { public: void set(const int a) {b=a;} private: int b; }; Here
class Foo(object): pass foo = Foo() def bar(self): print 'bar' Foo.bar = bar foo.bar()
class Foo { public Foo(String s) {} } print new Foo() Why does this
class foo implements Countable { function count() { # do stuff here } }
Consider the following example class Foo{ public: Foo(int i):x(i){} int x; }; void bar(Foo
When I say class Foo extends Bar{ } What's the easiest (read most IDE
class Foo(object): def tick(self): print(something) class Bar(object): def __init__(self): self.foo = Foo() def tick(self):
class foo { public: void say_type_name() { std::cout << typeid(this).name() << std::endl; } };
class Foo(){ public List<string> SomeCollection; } I need to implement an event which can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.