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 1937
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...@g mail.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**********@g mail.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.Typ eError' Traceback (most recent call last)
/home/wildemar/<ipython consolein <module>()
<type 'exceptions.Typ eError'>: 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
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 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={}):
class C(object): pass
C.__bases__ = bases
dict = 0
|
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 class:"mystile">..... </p> </li> 3° style
...
</ul>
the call to class
|
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, the reason for new style classes are to make the whole type/object
thing work better together. There are a number of new features etc.
I think my problem is when new-style classes are used, at first I thought
that all classes become new-style...
|
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 syntax return old-style class, same as "class C:",
and not the new style "class C(object):" ?
| |
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 = "2px solid green";
When the field looses the focus, the border should change back to red.
|
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:
pass
class Bar(object):
pass
|
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 instead. The following is the java script that i am using and i am having trouble in using a class instead of a style tag because simply replacing the style=\"position:absolute;\" tag with class=\"posiAbs\" where in the external css ".posiAbs...
|
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 Web Content Form? I cannot
use style tags in a Web Content Form, and I am having trouble figuring out
how to add all the desired css properties to a
System.Web.UI.WebControls.Style object. Can anyone help me? Thanks.
--
Nathan Sokalski...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |