class Test(object):
def execute(self,v):
return v
def escape(v):
return v
if __name__ == '__main__':
gert = Test()
print gert.m1('1')
print Test.m2('2')
Why doesn't this new style class work in python 2.5.1 ? 20 1898
gert wrote:
class Test(object):
def execute(self,v):
return v
def escape(v):
return v
if __name__ == '__main__':
gert = Test()
print gert.m1('1')
print Test.m2('2')
Why doesn't this new style class work in python 2.5.1 ?
why should it ?
On Nov 2, 12:27 pm, Boris Borcic <bbor...@gmail.comwrote:
gert wrote:
class Test(object):
def execute(self,v):
return v
def escape(v):
return v
if __name__ == '__main__':
gert = Test()
print gert.m1('1')
print Test.m2('2')
Why doesn't this new style class work in python 2.5.1 ?
why should it ?
I don't know I thought it was supported from 2.2?
On Nov 2, 12:31 pm, gert <gert.cuyk...@gmail.comwrote:
On Nov 2, 12:27 pm, Boris Borcic <bbor...@gmail.comwrote:
gert wrote:
class Test(object):
def execute(self,v):
return v
def escape(v):
return v
if __name__ == '__main__':
gert = Test()
print gert.m1('1')
print Test.m2('2')
Why doesn't this new style class work in python 2.5.1 ?
why should it ?
I don't know I thought it was supported from 2.2?
oops the code is like this but doesn't work
class Test(object):
def m1(self,v):
return v
def m2(v):
return v
if __name__ == '__main__':
gert = Test()
print gert.m1('1')
print Test.m2('2')
gert wrote:
On Nov 2, 12:27 pm, Boris Borcic <bbor...@gmail.comwrote:
>gert wrote:
>>class Test(object): def execute(self,v): return v def escape(v): return v if __name__ == '__main__': gert = Test() print gert.m1('1') print Test.m2('2') Why doesn't this new style class work in python 2.5.1 ?
why should it ?
I don't know I thought it was supported from 2.2?
Look at the error you get.
Repeat: LOOK AT THE ERROR YOU GET!
(Hint: "m1" not in ("execute", "escape"))
Nothing to do with old- or new-style classes.
/W
gert wrote:
On Nov 2, 12:27 pm, Boris Borcic <bbor...@gmail.comwrote:
>gert wrote:
>>class Test(object): def execute(self,v): return v def escape(v): return v if __name__ == '__main__': gert = Test() print gert.m1('1') print Test.m2('2') Why doesn't this new style class work in python 2.5.1 ?
why should it ?
I don't know I thought it was supported from 2.2?
I don't recall Python supporting non-existent method-calls (such
as m1/m2 when they aren't actually defined) in ANY version of Python.
But once you change that, you'll likely also want to investigate
the classmethod decorator if you want to create class-methods.
-tkc
>>>>"gert" == gert <ge**********@gmail.comwrites:
gertWhy doesn't this new style class work in python 2.5.1 ?
Whether you declare your class as a new style class or an old style
class, your code is completely and utterly broken. Calling non-existing
methods has never been a good way of getting things done. :-)
Martin
gert wrote:
oops the code is like this but doesn't work
class Test(object):
def m1(self,v):
return v
def m2(v):
return v
if __name__ == '__main__':
gert = Test()
print gert.m1('1')
print Test.m2('2')
Well, what do you think:
In [9]: gert = Test()
In [10]: print gert.m1('1')
....: print Test.m2('2')
....:
1
---------------------------------------------------------------------------
<type 'exceptions.TypeError' Traceback (most recent call last)
/home/wildemar/<ipython consolein <module>()
<type 'exceptions.TypeError'>: unbound method m2() must be called with Test instance as first argument (got str instance instead)
(Another hint: look at what m1 has that m2 lacks.)
/W
gert wrote:
[...]
>>>Why doesn't this new style class work in python 2.5.1 ? why should it ?
I don't know I thought it was supported from 2.2?
oops the code is like this but doesn't work
class Test(object):
def m1(self,v):
return v
def m2(v):
return v
if __name__ == '__main__':
gert = Test()
print gert.m1('1')
print Test.m2('2')
You should put a '@staticmethod' decorator before your m2 method definition
Could not one of you just say "@staticmethod" for once damnit :)
gert wrote:
On Nov 2, 12:27 pm, Boris Borcic <bbor...@gmail.comwrote:
>gert wrote:
>>class Test(object): def execute(self,v): return v def escape(v): return v if __name__ == '__main__': gert = Test() print gert.m1('1') print Test.m2('2') Why doesn't this new style class work in python 2.5.1 ?
why should it ?
I don't know I thought it was supported from 2.2?
I think what Boris was being exceedingly unhelpful in saying was "why
should it work when you're calling methods that do not exist"
I don't see 'm1' or 'm2' defined for the class 'Test'.
n
gert wrote:
Could not one of you just say "@staticmethod" for once damnit :)
No, since everyone's crystal balls are in repair.
Regards,
Björn
--
BOFH excuse #256:
You need to install an RTFM interface.
gert wrote:
oops the code is like this but doesn't work
For sake of the god of your choice, please always provide runnable
code as well as hints to
- what you think it should do
- what you want it to do
- what exact error message(s) you get
NOT just "it doesn't work".
Regards,
Björn
--
BOFH excuse #279:
The static electricity routing is acting up...
Bjoern Schliessmann wrote:
gert wrote:
>Could not one of you just say "@staticmethod" for once damnit :)
No, since everyone's crystal balls are in repair.
I don't even have crystal balls!
/W
On Nov 2, 2:10 pm, Wildemar Wildenburger
<lasses_w...@klapptsowieso.netwrote:
Bjoern Schliessmann wrote:
gert wrote:
Could not one of you just say "@staticmethod" for once damnit :)
No, since everyone's crystal balls are in repair.
I don't even have crystal balls!
/W
lol
Wildemar Wildenburger wrote:
Bjoern Schliessmann wrote:
>No, since everyone's crystal balls are in repair.
I don't even have crystal balls!
Not many are rich *and* impotent. :)
Regards,
Björn
--
BOFH excuse #14:
sounds like a Windows problem, try calling Microsoft support
gert wrote:
Could not one of you just say "@staticmethod" for once damnit :)
I did, did I not ?
gert wrote:
Could not one of you just say "@staticmethod" for once damnit :)
why were you asking if you knew the answer?
yeesh
On Nov 2, 4:04 pm, Boris Borcic <bbor...@gmail.comwrote:
gert wrote:
Could not one of you just say "@staticmethod" for once damnit :)
I did, did I not ?
i am sorry, yes you did :)
In article <ma**************************************@python.o rg>,
Nigel Rantor <wi****@wiggly.orgwrote:
> I think what Boris was being exceedingly unhelpful in saying was "why should it work when you're calling methods that do not exist"
http://www.catb.org/~esr/faqs/smart-questions.html
--
Aahz (aa**@pythoncraft.com) <* http://www.pythoncraft.com/
"Typing is cheap. Thinking is expensive." --Roy Smith
En Fri, 02 Nov 2007 08:58:32 -0300, gert <ge**********@gmail.comescribió:
Could not one of you just say "@staticmethod" for once damnit :)
Do we have to read your mind now? You miss-typed the method names the
first time. You could equally have forgotten to type the 'self' parameter.
Don't you expect too much?
BTW, most of the time staticmethods are NOT required at all. Using a plain
function instead is perfectly valid unless you have a special reason to
prefer a staticmethod.
--
Gabriel Genellina This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David MacQuigg |
last post by:
I have what looks like a bug trying to generate new style classes with
a factory function.
class Animal(object): pass
class Mammal(Animal): pass
def newAnimal(bases=(Animal,), dict={}):...
|
by: arreeess |
last post by:
i wont used three styles in the element of a list;
i have does so:
<ul>
<li> ............................. </li> first style
<li> <p> .....................</p> </li> 2° style
<li> <p...
|
by: lkrubner |
last post by:
How do I get all the div's on a page? I realize in IE I can use
document.all.
For the other browsers, I need to get an array of all the divs on the
page.
getElementByTagName()?????
|
by: Kalle Anke |
last post by:
I'm confused by the concepts of old-style vs new-style classes, I've read
most of the documents I found about this but it doesn't "click". Probably
because I wasn't around before 2.2.
Anyway,...
|
by: looping |
last post by:
For Python developers around.
>From Python 2.5 doc:
The list of base classes in a class definition can now be empty. As an
example, this is now legal:
class C():
pass
nice but why this...
|
by: Armin Gajda |
last post by:
Hi,
I have the following problem:
An input field get a border assigned by a style class (e.g. 2px solid red).
When the field gets the focus, we set the border to green.
element.style.border...
|
by: stephenpas |
last post by:
We are trying to monkey-patch a third-party library that mixes new and
old-style classes with multiple inheritance. In so doing we have
uncovered some unexpected behaviour:
<quote>
class Foo:...
|
by: Michellevt |
last post by:
Hi
I am working on a project (for college) and wondered if anyone can help me with my problem. In the project we are not allowed to make use of any "style" attributes but "class" attributes...
|
by: Nathan Sokalski |
last post by:
I have css that would normally be placed in style tags in the header of the
Master page that I want to add programmatically for a specific Web Content
Form (the *.aspx page). How do I do this for a...
|
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...
|
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"....
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
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...
|
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...
|
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...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
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...
|
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)...
| |