473,809 Members | 2,809 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A class question

Hello,

Is there a way I can, for debugging, access the instance variable name from
within a class?
E.g:
Class X:
def debug(self):
print "My instance var is %s" % (some magic Python stuff)

So that:
>>>x = X()
x.debug()
My Instance var is x
( Without passing the name in like: x=X(name="x") )

Thx.
\d

Oct 29 '07
16 1374
for humans:
Sweet. Thanks, I'll give it a go. It's only for debugging and will make life
easier.

\d

Oct 29 '07 #11
vzcbeg vafcrpg
>
qrs _svaq(senzr, bow):
sbe anzr, inyhr va senzr.s_ybpnyf. vgrevgrzf():
vs inyhr vf bow:
erghea anzr
sbe anzr, inyhr va senzr.s_tybonyf .vgrevgrzf():
vs inyhr vf bow:
erghea anzr
envfr XrlReebe("Bowrp g abg sbhaq va senzr tybonyf be ybpnyf")

pynff K:
qrs qroht(frys):
cevag ("Pnyyre fgberf zr va %f (nzbat bgure cbffvoyr cynprf)"
% _svaq(vafcrpg.p heeragsenzr(1), frys))
Now that's taking i18n too far. Klingon is not a widely understood
language :D
\d

Oct 29 '07 #12
While Java's variable declarations bear a superficial (syntactical)
similarity to C, their semantics is in fact equivalent to the
object-reference semantics we know in Python.
I come from Z80A/GWBASIC/VB and a little C, I would describe a Python
variable as a pointer - in that it contains the address of something.
What that "something" is, is a little fuzzy. Right now I imagine it's to a
kind of structure which has meta info about the object as well as it's
actual address.

How far off would that be?

\d

Oct 30 '07 #13
En Tue, 30 Oct 2007 02:51:39 -0300, Donn Ingle <do********@gma il.com>
escribió:
>While Java's variable declarations bear a superficial (syntactical)
similarity to C, their semantics is in fact equivalent to the
object-reference semantics we know in Python.

I come from Z80A/GWBASIC/VB and a little C, I would describe a Python
variable as a pointer - in that it contains the address of something.
What that "something" is, is a little fuzzy. Right now I imagine it's to
a
kind of structure which has meta info about the object as well as it's
actual address.

How far off would that be?
Almost true. A Python variable is a name inside a namespace, pointing to a
Python object. Many names may point to the same object, of course.
An object (in CPython) is a structure containing a reference count,
followed by a pointer to the object's type, followed by the object
contents itself. The object contents may as simple as a single value (e.g.
int or float objects) or rather complex (like the frame object which
contains about 18 other values, including many pointers to other
structures and arrays).
The object's type would be what you call the meta info, and contains the
type name, many pointers to functions (implementing the type methods) and
some flags describing the type behavior.

--
Gabriel Genellina

Oct 30 '07 #14
Donn Ingle a écrit :
>>vzcbeg vafcrpg

qrs _svaq(senzr, bow):
sbe anzr, inyhr va senzr.s_ybpnyf. vgrevgrzf():
vs inyhr vf bow:
erghea anzr
sbe anzr, inyhr va senzr.s_tybonyf .vgrevgrzf():
vs inyhr vf bow:
erghea anzr
envfr XrlReebe("Bowrp g abg sbhaq va senzr tybonyf be ybpnyf")

pynff K:
qrs qroht(frys):
cevag ("Pnyyre fgberf zr va %f (nzbat bgure cbffvoyr cynprf)"
% _svaq(vafcrpg.p heeragsenzr(1), frys))


Now that's taking i18n too far. Klingon is not a widely understood
language :D
s/i18n/rot13/ !-)
Oct 30 '07 #15
Hrvoje Niksic a écrit :
Bruno Desthuilliers <br************ ********@wtf.we bsiteburo.oops. com>
writes:

>>>While Java's variable declarations bear a superficial (syntactical)
similarity to C, their semantics is in fact equivalent to the
object-reference semantics we know in Python. They implicitly refer
to objects allocated on the heap and, just like in Python, the same
object can be referenced by multiple variables.

You're talking about reference types here - not primitive types. And
even then, from what I remember (not having done any Java these last
4 years at least), Java's reference types are much closer to C++
references than to Python.


Feel free to look it up; I believe you will find the semantics of
assignment, parameter-passing, etc., exactly the same as in Python.
I'll do - while perhaps not in a near future !-) - and keep you informed.
Oct 30 '07 #16
On Oct 28, 6:01 am, Donn Ingle <donn.in...@gma il.comwrote:
Is there a way I can, for debugging, access the instance variable name from
within a class?
Shouldn't this be in a FAQ somewhere? It's the second time (at least!)
it comes up this week.

George

Oct 30 '07 #17

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

Similar topics

8
2858
by: Bryan Parkoff | last post by:
I find an interesting issue that one base class has only one copy for each derived class. It looks like that one base class will be copied into three base classes while derived class from base class is executed. It means that three derived classes are pointed to a separated copy of base class. I do not allow second and third copy of base class to be created, but it must remain only first copy of base class. It allows three derived...
20
2896
by: modemer | last post by:
Question is as in subject. For example: class BaseClass { public: void func() { do something; } // I don't want this function being overloaded in its inherited class };
1
2274
by: Alfonso Morra | last post by:
if I have a class template declared as ff: (BTW is this a partial specialization? - I think it is) template <typename T1, myenum_1 e1=OK, my_enum_2=NONE> class A { public: A(); virtual ~A() ;
21
4085
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class A { std::vector<B*> Bs; public:
0
1437
by: Sebastian Hiller | last post by:
Hello, i'm new to .Net (i'm using VB as language and i'm working in the code-behind mode) and i can't solve the following problem: I have a WebForm and want to Add a UserControl (classname:QuestionControl) as many times as there are rows in a DataTable (also named Questions) in a DataSet. But this UserControl is ,for reasons of structuring, not a member of the WebForm Object in which it should be displayed, it is member of another class...
6
2123
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is responsible for instantiating the orders class? Would it be the ui layer or the master class in the business layer? thanks,
2
1609
by: Chris Puncher | last post by:
Hi. I have a RCW class that was generated by the VS.NET2003 IDE when I added a COM dll reference to my project. This all works fine when I call methods on it. My initial problem is that in ASP.NET I would like to add this to the Session object whilst using SQLServer as the session storage. Unfortunately, as this required the RCW class to be serializable, this won't work, and throws an exception saying you can't Serialize the Session...
9
1656
by: needin4mation | last post by:
I have a .aspx file and it's src. I also have a third file, a class that the src references. Everything is in the same directory/folder. Everything has the same namespace. How do I reference the class in my c# .src file? I don't believe this is an ASP.NET question, but a OOP C# question, thus my post here. I have searched and I thought it was with: using FilterSQL; //the name of my class using reports.FilterSQL; //name of...
43
2103
by: Tony | last post by:
I'm working with GUI messaging and note that MFC encapsulates the message loop inside of a C++ class member function. Is this somehow inherently less robust than calling the message loop functions within main? (It just doesn't "feel" right to me). Example 1: class MyProg { public:
2
1512
by: K Viltersten | last post by:
Suppose there is the following class structure. class S {...} class A : S {...} class B : S {...} class A1 : A {void m(){...}} class B1 : B {void m(){...}} class B2 : B {...} Just to clarify the issue. A1 and B1 share a method (void m() ) AND B2 doesn't have that
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10383
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7661
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.