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

MethodType in python 2.2

Hi all,

I wonder why types.MethodType fails under python 2.2:

Python 2.2.2 (#1, Jun 25 2003, 18:52:43)
[GCC 3.3 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import types
class X: .... def f(self,attr): return getattr(self,attr)
.... g = types.MethodType(f,None)
....
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in X
TypeError: cannot create 'instance method' instances
The same code under 2.4 (and I believe 2.3) runs fine.

Python 2.4b1 (#1, Oct 25 2004, 17:07:48)
[GCC 3.3 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information. import types
class X: .... def f(self,attr): return getattr(self,attr)
.... g = types.MethodType(f,None)
.... X().f("f") <bound method X.f of <__main__.X instance at 0x2a97f23e18>> X().f("g")

<bound method X.f of <__main__.X instance at 0x2a97f23e60>>
Is it possible to get around this in 2.2 ? Thanks in advance,

George

Jul 18 '05 #1
0 1171

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

Similar topics

1
by: Emile van Sebille | last post by:
QOTW: "If we get 2.3.3c1 out in early December, we could release 2.3.3 final before the end of the year, and start 2004 with a 100% bug-free codebase <wink>." -- Tim Peters "cjOr proWe vbCould...
0
by: Emile van Sebille | last post by:
QOTW: "Have you ever used the copy module? I am *not* a beginner, and have used it *once* (and I can't remember what for, either)." -- Michael Hudson "It will likely take a little practice...
6
by: Schüle Daniel | last post by:
Hello all, >>> class Q: .... def bar(self): .... pass .... >>> import types >>> types.UnboundMethodType is types.MethodType True >>>
11
by: Alex Popescu | last post by:
Hi all! I am pretty new to Python, so please excuse me if I am missing something. Lately, I've been playing with decorators and I am a bit confused about some behavior. Here is the code that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.