473,287 Members | 1,418 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,287 software developers and data experts.

Showing the method's class in expection's traceback

Hi!

is there anyway to show the class of a method in an exception's
traceback?

For example, the next code

class Some(object):
def foo(self,x):
raise Exception(x)

obj = Some()
obj.foo("some arg")

produces the next traceback

Traceback (most recent call last):
File "<string>", line 231, in run_nodebug
File "G:\dev\exceptions\sample.py", line 7, in <module>
obj.foo("some arg")
File "G:\dev\exceptions\sample.py", line 3, in foo
raise Exception(x)
Exception: some arg

I want to improve the line
File "G:\dev\exceptions\sample.py", line 3, in foo

to
File "G:\dev\exceptions\sample.py", line 3, in Some.foo

Is this improvement feasible
Jun 27 '08 #1
21 1661
Agustin Villena schrieb:
Hi!

is there anyway to show the class of a method in an exception's
traceback?

For example, the next code

class Some(object):
def foo(self,x):
raise Exception(x)

obj = Some()
obj.foo("some arg")

produces the next traceback

Traceback (most recent call last):
File "<string>", line 231, in run_nodebug
File "G:\dev\exceptions\sample.py", line 7, in <module>
obj.foo("some arg")
File "G:\dev\exceptions\sample.py", line 3, in foo
raise Exception(x)
Exception: some arg

I want to improve the line
File "G:\dev\exceptions\sample.py", line 3, in foo

to
File "G:\dev\exceptions\sample.py", line 3, in Some.foo

Is this improvement feasible
It should be. You can get a dictionary of the locals of an exception
stack frame, of which you could extract the self-parameter's class.

Diez
Jun 27 '08 #2
En Sun, 18 May 2008 17:31:44 -0300, Diez B. Roggisch <de***@nospam.web.deescribió:
Agustin Villena schrieb:
>is there anyway to show the class of a method in an exception's
traceback?

I want to improve the line
File "G:\dev\exceptions\sample.py", line 3, in foo

to
File "G:\dev\exceptions\sample.py", line 3, in Some.foo

Is this improvement feasible

It should be. You can get a dictionary of the locals of an exception
stack frame, of which you could extract the self-parameter's class.
That by itself is not enough, the method could be inherited; one should walk the base classes in the MRO to find the right one. And deal with classmethods and staticmethods. And decorators that don't preserve meta information... Hmmm, I think it isn't so trivial as it seems.

--
Gabriel Genellina

Jun 27 '08 #3
>
That by itself is not enough, the method could be inherited; one should
walk the base classes in the MRO to find the right one. And deal with
classmethods and staticmethods. And decorators that don't preserve meta
information... Hmmm, I think it isn't so trivial as it seems.
You might even have an instance-unique method. But I think the OP is
satisfied with a 90%-solution.

Diez
Jun 27 '08 #4
On May 18, 4:31 pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
Agustin Villena schrieb:
Hi!
is there anyway to show the class of amethodin an exception's
traceback?
For example, the next code
class Some(object):
def foo(self,x):
raise Exception(x)
obj = Some()
obj.foo("some arg")
produces the next traceback
Traceback (most recent call last):
File "<string>", line 231, in run_nodebug
File "G:\dev\exceptions\sample.py", line 7, in <module>
obj.foo("some arg")
File "G:\dev\exceptions\sample.py", line 3, in foo
raise Exception(x)
Exception: some arg
I want to improve the line
File "G:\dev\exceptions\sample.py", line 3, in foo
to
File "G:\dev\exceptions\sample.py", line 3, in Some.foo
Is this improvement feasible

It should be. You can get a dictionary of the locals of an exception
stack frame, of which you could extract the self-parameter's class.

Diez
Hi!

I digged on sys.exc_info() object and the traceback module and I
could't figure how I can get the locals() of the exception stackframe

Any advice?

Thanks
Agustin
Jun 27 '08 #5
En Mon, 19 May 2008 10:54:05 -0300, Agustin Villena
<ag*************@gmail.comescribió:
On May 18, 4:31 pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
>Agustin Villena schrieb:
is there anyway to show the class of amethodin an exception's
traceback?
I want to improve the line
File "G:\dev\exceptions\sample.py", line 3, in foo
to
File "G:\dev\exceptions\sample.py", line 3, in Some.foo

It should be. You can get a dictionary of the locals of an exception
stack frame, of which you could extract the self-parameter's class.

I digged on sys.exc_info() object and the traceback module and I
could't figure how I can get the locals() of the exception stackframe
Put this function in traceback.py, and replace the lines
name = co.co_name
with
name = guess_full_method_name(f)
everywhere.
Please read the docstring!!!

def guess_full_method_name(frame):
"""Guess classname.methodname for a given frame.

Only a guess!
Assumes the frame belongs to an instancemethod
whose first argument is "self", or a classmethod
whose first argument is "cls".
Doesn't handle correctly any other situation.
Returns the class name of the object on which
the method was called, not the class where
the method was actually defined.
"""
cls_name = None
fun_name = frame.f_code.co_name
self = frame.f_locals.get('self', None)
if self is None:
cls = frame.f_locals.get('cls', None)
else:
cls = getattr(self, '__class__', None)
if cls is not None:
cls_name = getattr(cls, '__name__', None)
if cls_name is not None:
return '%s.%s' % (cls_name, fun_name)
return fun_name

--
Gabriel Genellina

Jun 27 '08 #6
Gabriel Genellina a écrit :
En Sun, 18 May 2008 17:31:44 -0300, Diez B. Roggisch
<de***@nospam.web.deescribió:
>Agustin Villena schrieb:
>>is there anyway to show the class of a method in an exception's
traceback?

I want to improve the line File "G:\dev\exceptions\sample.py",
line 3, in foo

to File "G:\dev\exceptions\sample.py", line 3, in Some.foo

Is this improvement feasible
It should be. You can get a dictionary of the locals of an
exception stack frame, of which you could extract the
self-parameter's class.

That by itself is not enough, the method could be inherited; one
should walk the base classes in the MRO to find the right one. And
deal with classmethods and staticmethods. And decorators that don't
preserve meta information...
And monkeypatches.
Hmmm, I think it isn't so trivial as it
seems.
And not that useful - why would one care about the function being
defined in class X or Y when one have the exact file and line ?

Jun 27 '08 #7
Bruno Desthuilliers <br********************@websiteburo.invalidwrite s:
Gabriel Genellina a écrit :
>En Sun, 18 May 2008 17:31:44 -0300, Diez B. Roggisch
<de***@nospam.web.deescribió:
>>Agustin Villena schrieb:
>>>is there anyway to show the class of a method in an exception's
traceback?

I want to improve the line File "G:\dev\exceptions\sample.py",
line 3, in foo

to File "G:\dev\exceptions\sample.py", line 3, in Some.foo

Is this improvement feasible
It should be. You can get a dictionary of the locals of an
exception stack frame, of which you could extract the
self-parameter's class.

That by itself is not enough, the method could be inherited; one
should walk the base classes in the MRO to find the right one. And
deal with classmethods and staticmethods. And decorators that don't
preserve meta information...

And monkeypatches.
>Hmmm, I think it isn't so trivial as it
seems.

And not that useful - why would one care about the function being
defined in class X or Y when one have the exact file and line ?
Very obvious I would think. One can develop ones own interactive class
browser and code navigator. One can not bring up class help from "line 3
in x.py" but one can from "classname : MyClass at line 2 in z.py". With
the class name I can navigate directly to all sorts of class related
information without the need to delve into a physical usage of it e.g
program.py at line 3.
Jun 27 '08 #8
Richard G Riley a écrit :
Bruno Desthuilliers <br********************@websiteburo.invalidwrite s:
(snip)
>And not that useful - why would one care about the function being
defined in class X or Y when one have the exact file and line ?

Very obvious I would think. One can develop ones own interactive class
browser and code navigator.
From the traceback ?
One can not bring up class help from "line 3
in x.py" but one can from "classname : MyClass at line 2 in z.py". With
the class name I can navigate directly to all sorts of class related
information without the need to delve into a physical usage of it e.g
program.py at line 3.
Please bear with me, but I'm afraid I still don't get the point : I
don't need tracebacks to get to some object's info (help etc).

Jun 27 '08 #9
Bruno Desthuilliers <br********************@websiteburo.invalidwrite s:
Richard G Riley a écrit :
>Bruno Desthuilliers <br********************@websiteburo.invalidwrite s:

(snip)
>>And not that useful - why would one care about the function being
defined in class X or Y when one have the exact file and line ?

Very obvious I would think. One can develop ones own interactive class
browser and code navigator.

From the traceback ?
> One can not bring up class help from "line 3
in x.py" but one can from "classname : MyClass at line 2 in z.py". With
the class name I can navigate directly to all sorts of class related
information without the need to delve into a physical usage of it e.g
program.py at line 3.

Please bear with me, but I'm afraid I still don't get the point : I
don't need tracebacks to get to some object's info (help etc).
This is a view quite common to people when they are happy with what they
have. Some like to improve what they have. It is immediately apparent to
me why having a class name and method name in the traceback would be
immediately useful. Having written a few extensions to IDEs in the past
I know it would help me, and I suspect, the original poster. As a recent
"recruit" to Python I am quite surprised as how poor most of the query
like tools in the python shell are. The first thing I did was to move to
iPython. Still, horses for courses.
Jun 27 '08 #10
Richard G Riley a écrit :
Bruno Desthuilliers <br********************@websiteburo.invalidwrite s:
>Richard G Riley a écrit :
>>Bruno Desthuilliers <br********************@websiteburo.invalidwrite s:
(snip)
>>>And not that useful - why would one care about the function being
defined in class X or Y when one have the exact file and line ?
Very obvious I would think. One can develop ones own interactive class
browser and code navigator.
From the traceback ?
>> One can not bring up class help from "line 3
in x.py" but one can from "classname : MyClass at line 2 in z.py". With
the class name I can navigate directly to all sorts of class related
information without the need to delve into a physical usage of it e.g
program.py at line 3.
Please bear with me, but I'm afraid I still don't get the point : I
don't need tracebacks to get to some object's info (help etc).

This is a view quite common to people when they are happy with what they
have. Some like to improve what they have. It is immediately apparent to
me why having a class name and method name in the traceback would be
immediately useful.
Then please explain.
Having written a few extensions to IDEs in the past
I know it would help me,
To do what ?

Jun 27 '08 #11
And not that useful - why would one care about the function being
defined in class X or Y when one have the exact file and line ?
I have 3 reasons:

1) My developing time is expended running unit tests and browsing
tracebacks to find which is the real problem. Knowing the offender
class (instead of the method alone) makes me understand more quickly
which component of my software is failing.
2) There are some ocassions where I only have the traceback (e.g. when
analyzing an app's log) and no inmediate access to teh source code
3) And finally, for completeness: If a function is really a method, if
the traceback show only its name and not the class that defines it,
for me its a bug, because the method name has no sense out of its
class.

Just my two cents

Agustin

Jun 27 '08 #12
On 20 mayo, 12:10, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
En Mon, 19 May 2008 10:54:05 -0300, Agustin Villena
<agustin.vill...@gmail.comescribió:
On May 18, 4:31 pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
Agustin Villena schrieb:
is there anyway to show the class of amethodin anexception's
traceback?
I want to improve the line
File "G:\dev\exceptions\sample.py", line 3, in foo
to
File "G:\dev\exceptions\sample.py", line 3, in Some.foo
It should be. You can get a dictionary of the locals of anexception
stack frame, of which you could extract the self-parameter's class.
I digged on sys.exc_info() object and the traceback module and I
could't figure how I can get the locals() of theexceptionstackframe

Put this function in traceback.py, and replace the lines
name = co.co_name
with
name = guess_full_method_name(f)
everywhere.
Please read the docstring!!!

def guess_full_method_name(frame):
"""Guess classname.methodname for a given frame.

Only a guess!
Assumes the frame belongs to an instancemethod
whose first argument is "self", or a classmethod
whose first argument is "cls".
Doesn't handle correctly any other situation.
Returns the class name of the object on which
the method was called, not the class where
the method was actually defined.
"""
cls_name = None
fun_name = frame.f_code.co_name
self = frame.f_locals.get('self', None)
if self is None:
cls = frame.f_locals.get('cls', None)
else:
cls = getattr(self, '__class__', None)
if cls is not None:
cls_name = getattr(cls, '__name__', None)
if cls_name is not None:
return '%s.%s' % (cls_name, fun_name)
return fun_name

--
Gabriel Genellina
Thanks! I'll try it

Agustin
Jun 27 '08 #13
Agustin Villena a écrit :
>And not that useful - why would one care about the function being
defined in class X or Y when one have the exact file and line ?

I have 3 reasons:

1) My developing time is expended running unit tests and browsing
tracebacks to find which is the real problem. Knowing the offender
class (instead of the method alone) makes me understand more quickly
which component of my software is failing.
This is only true when there is an obvious, one-to-one, unambiguous
relationship between the physical location of the error (file, line) and
the class of the object the method has been called on. Which is not
necessarily the case (inheritance, method decoration and monkeypatching
comes to mind here...).

Also, your above statement seems to imply that component==class, which
is not the case in Python.
2) There are some ocassions where I only have the traceback (e.g. when
analyzing an app's log) and no inmediate access to teh source code
Ok. But the above still apply...
3) And finally, for completeness: If a function is really a method, if
the traceback show only its name and not the class that defines it,
for me its a bug, because the method name has no sense out of its
class.
I'm not sure you really grasp what "methods" are in Python. What you
define (using the def statement) within a class is function, not a
method. It only becomes a method when it's looked up on an instance or
class object, and this 'method' is only a thin wrapper around the
instance, class and function objects. And FWIW, you don't need to define
the function within the class to make it a method:

# bar.py
def bar(obj):
print "function bar.bar called on obj %s" % obj
# foo.py

class Foo(object): pass

# baaz.py
from foo import Foo
import bar

Foo.baaz = bar.bar

def guux(obj):
print "function baaz.guux called on obj %s" % obj

# main.py
from baaz import Foo
f = Foo()
f.bar()

f.gnix = baae.guux.__get__(f, type(f))
f.gnix()

Not to say that your concerns are pointless, and that things cannot be
improved somehow, but this is not that trivial, and there may be
ambuiguities in some not so rare cases.
Jun 27 '08 #14
Bruno Desthuilliers <br********************@websiteburo.invalidwrote :
Not to say that your concerns are pointless, and that things cannot be
improved somehow, but this is not that trivial, and there may be
ambuiguities in some not so rare cases.
It might be worth considering an alternative approach here: a formatted
exception includes the relevant source lines (where possible).

The source lines are cached by the module linecache.py and it probably
wouldn't be too hard to build on the line cache so that it also scans the
source lines looking for class statements and recording the start and end
line numbers for each class.

That way any classname displayed would be based on the actual source
nesting and even static methods or functions injected from another class
would work 'correctly' (at some level).

--
Duncan Booth http://kupuguy.blogspot.com
Jun 27 '08 #15
On May 22, 5:19 am, Bruno Desthuilliers <bruno.
42.desthuilli...@websiteburo.invalidwrote:
Agustin Villena a écrit :
And not that useful - why would one care about the function being
defined in class X or Y when one have the exact file and line ?
I have 3 reasons:
1) My developing time is expended running unit tests and browsing
tracebacks to find which is the real problem. Knowing the offender
class (instead of the method alone) makes me understand more quickly
which component of my software is failing.

This is only true when there is an obvious, one-to-one, unambiguous
relationship between the physical location of the error (file, line) and
the class of the object the method has been called on. Which is not
necessarily the case (inheritance, method decoration and monkeypatching
comes to mind here...).

Also, your above statement seems to imply that component==class, which
is not the case in Python.
2) There are some ocassions where I only have the traceback (e.g. when
analyzing an app's log) and no inmediate access to teh source code

Ok. But the above still apply...
3) And finally, for completeness: If a function is really a method, if
the traceback show only its name and not the class that defines it,
for me its a bug, because the method name has no sense out of its
class.

I'm not sure you really grasp what "methods" are in Python. What you
define (using the def statement) within a class is function, not a
method. It only becomes a method when it's looked up on an instance or
class object, and this 'method' is only a thin wrapper around the
instance, class and function objects. And FWIW, you don't need to define
the function within the class to make it a method:

# bar.py
def bar(obj):
print "function bar.bar called on obj %s" % obj

# foo.py

class Foo(object): pass

# baaz.py
from foo import Foo
import bar

Foo.baaz = bar.bar

def guux(obj):
print "function baaz.guux called on obj %s" % obj

# main.py
from baaz import Foo
f = Foo()
f.bar()

f.gnix = baae.guux.__get__(f, type(f))
f.gnix()

Not to say that your concerns are pointless, and that things cannot be
improved somehow, but this is not that trivial, and there may be
ambuiguities in some not so rare cases.
Well, the solution given in an early response is good enough for me.

I don't see things like you, because I'm accustomed to design my
software
though classes and see the code in an "object = software's functional
atom/component" way
I agree that python's dynamic nature make things complicated here, but
for me it its just
an implementation problem derived of the recent OOP support of python
Jun 27 '08 #16
Agustin Villena wrote:
I don't see things like you, because I'm accustomed to design my
software
though classes and see the code in an "object = software's functional
atom/component" way
I agree that python's dynamic nature make things complicated here, but
for me it its just
an implementation problem derived of the recent OOP support of python
(laughs). I do hope you're either joking or wearing a flameproof suit.
Python's dynamic nature as an implementation problem. Hmmm..
And what's that about "recent" OOP support of Python?

Oh well...

TJG
Jun 27 '08 #17
Agustin Villena a écrit :
On May 22, 5:19 am, Bruno Desthuilliers <bruno.
42.desthuilli...@websiteburo.invalidwrote:
>Agustin Villena a écrit :
>>>And not that useful - why would one care about the function being
defined in class X or Y when one have the exact file and line ?
I have 3 reasons:
1) My developing time is expended running unit tests and browsing
tracebacks to find which is the real problem. Knowing the offender
class (instead of the method alone) makes me understand more quickly
which component of my software is failing.
This is only true when there is an obvious, one-to-one, unambiguous
relationship between the physical location of the error (file, line) and
the class of the object the method has been called on. Which is not
necessarily the case (inheritance, method decoration and monkeypatching
comes to mind here...).

Also, your above statement seems to imply that component==class, which
is not the case in Python.
>>2) There are some ocassions where I only have the traceback (e.g. when
analyzing an app's log) and no inmediate access to teh source code
Ok. But the above still apply...
>>3) And finally, for completeness: If a function is really a method, if
the traceback show only its name and not the class that defines it,
for me its a bug, because the method name has no sense out of its
class.
I'm not sure you really grasp what "methods" are in Python. What you
define (using the def statement) within a class is function, not a
method. It only becomes a method when it's looked up on an instance or
class object, and this 'method' is only a thin wrapper around the
instance, class and function objects. And FWIW, you don't need to define
the function within the class to make it a method:

# bar.py
def bar(obj):
print "function bar.bar called on obj %s" % obj

# foo.py

class Foo(object): pass

# baaz.py
from foo import Foo
import bar

Foo.baaz = bar.bar

def guux(obj):
print "function baaz.guux called on obj %s" % obj

# main.py
from baaz import Foo
f = Foo()
f.bar()

f.gnix = baae.guux.__get__(f, type(f))
f.gnix()

Not to say that your concerns are pointless, and that things cannot be
improved somehow, but this is not that trivial, and there may be
ambuiguities in some not so rare cases.

Well, the solution given in an early response is good enough for me.
Not for me.
I don't see things like you, because I'm accustomed to design my
software
though classes and see the code in an "object = software's functional
atom/component" way
I guess you mean 'class = software's functional atom/component' -
because it's perfectly legal, in Python, to have per-instance methods...

Now the fact that *you* see it that way doesn't mean Python (and most
Python users) have to share your views, so labelling the way it works as
"a bug" sounds a bit arrogant to me.
I agree that python's dynamic nature make things complicated here, but
for me it its just
an implementation problem derived of the recent OOP support of python
I beg your pardon ? "recent OOP support in Python" ? Python had classes
and objects years before Oak was renamed as Java and made public, you know.
Jun 27 '08 #18
En Thu, 22 May 2008 07:55:44 -0300, Duncan Booth <du**********@invalid.invalidescribió:
Bruno Desthuilliers <br********************@websiteburo.invalidwrote :
>Not to say that your concerns are pointless, and that things cannot be
improved somehow, but this is not that trivial, and there may be
ambuiguities in some not so rare cases.

It might be worth considering an alternative approach here: a formatted
exception includes the relevant source lines (where possible).
Just to note that the standard cgitb module already does that, among other things.

--
Gabriel Genellina

Jun 27 '08 #19
"Gabriel Genellina" <ga*******@yahoo.com.arwrote:
En Thu, 22 May 2008 07:55:44 -0300, Duncan Booth
<du**********@invalid.invalidescribió:
>Bruno Desthuilliers <br********************@websiteburo.invalid>
wrote:
>>Not to say that your concerns are pointless, and that things cannot
be improved somehow, but this is not that trivial, and there may be
ambuiguities in some not so rare cases.

It might be worth considering an alternative approach here: a
formatted exception includes the relevant source lines (where
possible).

Just to note that the standard cgitb module already does that, among
other things.
Anywhere Python prints a traceback already does that. The 'alternative
approach' I was suggesting was the part you snipped, i.e. extracting the
enclosing class name from the source.
Jun 27 '08 #20
En Sun, 25 May 2008 06:15:45 -0300, Duncan Booth <du**********@invalid.invalidescribió:
"Gabriel Genellina" <ga*******@yahoo.com.arwrote:
>En Thu, 22 May 2008 07:55:44 -0300, Duncan Booth
<du**********@invalid.invalidescribió:
>>>
It might be worth considering an alternative approach here: a
formatted exception includes the relevant source lines (where
possible).

Just to note that the standard cgitb module already does that, among
other things.
Anywhere Python prints a traceback already does that. The 'alternative
approach' I was suggesting was the part you snipped, i.e. extracting the
enclosing class name from the source.
Ah, sorry for the misunderstanding!

--
Gabriel Genellina

Jun 27 '08 #21
To this therad, I received 2 kinds of anwsers:
- some that help me in
- and other where some guy thinks that has the right to rule if my
need has some value

Thanksfully, Python is an open platform, and with the help obtained
here, now I can fullfill my needs.
Who is the arrogant?

On 22 mayo, 11:59, Bruno Desthuilliers <bruno.
42.desthuilli...@websiteburo.invalidwrote:
Agustin Villena a écrit :
On May 22, 5:19 am, Bruno Desthuilliers <bruno.
42.desthuilli...@websiteburo.invalidwrote:
Agustin Villena a écrit :
>>And not that useful - why would one care about the function being
defined in class X or Y when one have the exact file and line ?
I have 3 reasons:
1) My developing time is expended running unit tests and browsing
tracebacks to find which is the real problem. Knowing the offender
class (instead of the method alone) makes me understand more quickly
which component of my software is failing.
This is only true when there is an obvious, one-to-one, unambiguous
relationship between the physical location of the error (file, line) and
the class of the object the method has been called on. Which is not
necessarily the case (inheritance, method decoration and monkeypatching
comes to mind here...).
Also, your above statement seems to imply that component==class, which
is not the case in Python.
>2) There are some ocassions where I only have the traceback (e.g. when
analyzing an app's log) and no inmediate access to teh source code
Ok. But the above still apply...
>3) And finally, for completeness: If a function is really a method, if
the tracebackshowonly its name and not the class that defines it,
for me its a bug, because the method name has no sense out of its
class.
I'm not sure you really grasp what "methods" are in Python. What you
define (using the def statement) within a class is function, not a
method. It only becomes a method when it's looked up on an instance or
class object, and this 'method' is only a thin wrapper around the
instance, class and function objects. And FWIW, you don't need to define
the function within the class to make it a method:
# bar.py
def bar(obj):
print "function bar.bar called on obj %s" % obj
# foo.py
class Foo(object): pass
# baaz.py
from foo import Foo
import bar
Foo.baaz = bar.bar
def guux(obj):
print "function baaz.guux called on obj %s" % obj
# main.py
from baaz import Foo
f = Foo()
f.bar()
f.gnix = baae.guux.__get__(f, type(f))
f.gnix()
Not to say that your concerns are pointless, and that things cannot be
improved somehow, but this is not that trivial, and there may be
ambuiguities in some not so rare cases.
Well, the solution given in an early response is good enough for me.

Not for me.
I don't see things like you, because I'm accustomed to design my
software
though classes and see the code in an "object = software's functional
atom/component" way

I guess you mean 'class = software's functional atom/component' -
because it's perfectly legal, in Python, to have per-instance methods...

Now the fact that *you* see it that way doesn't mean Python (and most
Python users) have to share your views, so labelling the way it works as
"a bug" sounds a bit arrogant to me.
I agree that python's dynamic nature make things complicated here, but
for me it its just
an implementation problem derived of the recent OOP support of python

I beg your pardon ? "recent OOP support in Python" ? Python had classes
and objects years before Oak was renamed as Java and made public, you know..
Jun 27 '08 #22

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

Similar topics

2
by: Andrew Dalke | last post by:
Out of curiosity, I tried passing using an invalid base for a class. I can't explain why I got the error messages I did. Can someone here enlighten me? # Here I'm just curious >>> def...
21
by: ron | last post by:
Why doesn't this work? >>> def foo(lst): .... class baz(object): .... def __getitem__(cls, idx): return cls.lst .... __getitem__=classmethod(__getitem__) .... baz.lst = lst .... ...
44
by: gregory.petrosyan | last post by:
Hello everybody! I have little problem: class A: def __init__(self, n): self.data = n def f(self, x = ????) print x All I want is to make self.data the default argument for self.f(). (I
3
by: AWasilenko | last post by:
I'm still in the process of learning python via a handful of books I bought. One book I am reading just introduced Base Class Methods. I found that I needed more understanding on this concept and...
3
by: ZhaoYingpu | last post by:
Hello,all I am using win32com to use com. and invoke a method as follows: void AddShapeInfo(LPCTSTR name, LONG type, IDispatch* pDisp); but i pass 0 or None to third parameter and get error info:...
21
by: John Henry | last post by:
Hi list, I have a need to create class methods on the fly. For example, if I do: class Dummy: def __init__(self): exec '''def method_dynamic(self):\n\treturn self.method_static("it's...
10
by: Steven W. Orr | last post by:
In the program below, I want this instance to end up calling repmeth whenever inst.m1 is called. As it is now, I get this error: Hello from init inst = <__main__.CC instance at 0x402105ec>...
12
by: Ratko | last post by:
Hi all, I was wondering if something like this is possible. Can a base class somehow know if a certain method has been overridden by the subclass? I appreciate any ideas. Thanks, Ratko
8
by: Fuzzyman | last post by:
Hello all, I may well be being dumb (it has happened before), but I'm struggling to fix some code breakage with Python 2.6. I have some code that looks for the '__lt__' method on a class: ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.