473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Re: Get current class namespace.

Robert Rawlins wrote:
What’s the simplest way to access a classes namespace from within
itself. I want to use it in a custom __repr__() method so it prints the
current namespace for the class like package.module.class.
Name or namespace? You can access the class name from an instance via
the __class__ attribute:
>>class foo:
.... def __repr__(self):
.... return "<%s instance at %x>" % (
.... self.__class__.__name__, id(self)
.... )
....
>>foo()
<foo instance at c714e0>

The module the class was defined in is also available:
>>class foo:
.... def __repr__(self):
.... return "<%s.%s instance at %x>" % (
.... self.__class__.__module__, self.__class__.__name__,
.... id(self)
.... )
....
>>foo()
<__main__.foo instance at c9fbc0>

To get the namespace (that is, the collection of (name, value)
pairs that make up the class' contents), use vars(self.__class__)
(or vars(self), if you want the full instance).

</F>

Jul 16 '08 #1
0 1598

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Glen | last post by:
Hi, Is there a way to resolve the current namespace in a static method, such as Main() from within a console app? In a public method from a class instance, you can use the "this" keyword in...
2
by: Steve | last post by:
I have a general routine in a windows app to get an embedded resource using GetManifestResourceStream, Is it possible for when I call my routine to use some kind of reflection to get the current...
1
by: Islam Elkhayat | last post by:
How can i get my current Namespace & current class in my webform... I tried alot but i get ASP.myformname_aspx... Is there a way to get Current Namespace, class??
3
by: xzzy | last post by:
A. I need to access: System.Web.HttpContext.Current.Cache but get this error: "Object reference not set to an instance of the object" B. System.Web.HttpContext.Current.Cache is accessible...
1
by: Mike Walters | last post by:
Reading the current Namespace.Class, Assemble at runtime I am trying to get the Assemble, Namespace and Class name of a form at runtime. I have several assembles and namespaces in my app, I...
4
by: Greg Allen | last post by:
I have a web service and am trying to use WSE 2.0 to pass attachments. I have enabled both the checkboxes in the WSE properties page in VS. The problem occurs when I try to get the...
8
by: news.microsoft.com | last post by:
How do I get the class name for a current instance. For example, if I want to know the Class Name for the current form, how do I get this programatically. Thanks
1
by: Joseph Geretz | last post by:
I have a web service page which uses WSE 2.0 SP3 to return a file attachment on one of its method calls. All web service methods are functioning properly, except for this one method which uses WSE...
8
by: eric | last post by:
I have a 2.0 asp.net project. In a class contained within a seperate project, I am trying to reference HttpContext.Current.Session but Session is always null. I've tried implementing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.