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

Home Posts Topics Members FAQ

<build-in function> incompatible with <function>

Built-in functions don't bind to classes like regular functions. Is
this intended? (I do notice that the Python Reference Manual sec 3.2
under "Class Instance" refers to a "user-defined function"). Any ideas
what the reason is for this distinction between build-in functions and
normal functions?

It's rather inconvenient when implementing some methods (not the whole
class) in a C extension :-(

$ python
Python 2.4.2 (#1, Nov 3 2005, 12:41:57)
[GCC 3.4.3-20050110 (Gentoo Linux 3.4.3.20050110, ssp-3.4.3.20050110-0,
pie-8.7 on linux2
Type "help", "copyright" , "credits" or "license" for more information.
def normal_func(x): .... return x
.... class foo(object): .... a = normal_func
.... b = lambda x : x
.... c = abs
.... obj = foo()
obj.a <bound method foo.normal_func of <__main__.foo object at 0xb7c3766c>> obj.b <bound method foo.<lambda> of <__main__.foo object at 0xb7c3766c>> obj.c

<built-in function abs>

Jan 31 '06 #1
5 1590

"Luke" <lu**@deller.id .au> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
Built-in functions don't bind to classes like regular functions. Is
this intended? (I do notice that the Python Reference Manual sec 3.2
under "Class Instance" refers to a "user-defined function"). Any ideas
what the reason is for this distinction between build-in functions and
normal functions?


no, but does this help...
class Test: .... c = classmethod(abs )
.... obj = Test()
obj.c <bound method classobj.abs of <class __main__.Test at 0x00B2C060>>

Emile

Jan 31 '06 #2
Luke wrote:
Built-in functions don't bind to classes like regular functions. Is
this intended? (I do notice that the Python Reference Manual sec 3.2
under "Class Instance" refers to a "user-defined function"). Any ideas
what the reason is for this distinction between build-in functions and
normal functions?

It's rather inconvenient when implementing some methods (not the whole
class) in a C extension :-(

$ python
Python 2.4.2 (#1, Nov 3 2005, 12:41:57)
[GCC 3.4.3-20050110 (Gentoo Linux 3.4.3.20050110, ssp-3.4.3.20050110-0,
pie-8.7 on linux2
Type "help", "copyright" , "credits" or "license" for more information.
def normal_func(x):
... return x
...
class foo(object):
... a = normal_func
... b = lambda x : x
... c = abs
...
obj = foo()
obj.a
<bound method foo.normal_func of <__main__.foo object at 0xb7c3766c>>
obj.b
<bound method foo.<lambda> of <__main__.foo object at 0xb7c3766c>>
obj.c


<built-in function abs>


py> import types
py> def doit(x):
.... print x
....
py> class bob:
.... pass
....
py> b = bob
py> b.x = types.MethodTyp e(doit, b)
py> b.x
<bound method ?.doit of <class __main__.bob at 0x403d8b3c>>
py> b.x()
__main__.bob
Jan 31 '06 #3
Thanks James, though from the output of b.x() it appears that x is a
class method (ie the class is passed as the first parameter rather than
the instance)...

Jan 31 '06 #4
Luke wrote:
Thanks James, though from the output of b.x() it appears that x is a
class method (ie the class is passed as the first parameter rather than
the instance)...


Sorry, the one line was probably supposed to be

b = bob()

I forgot the parens:

py> b = bob()
py> b.x = types.MethodTyp e(doit, b)
py> b.x()
<__main__.bob instance at 0x404afb6c>
py> b.x
<bound method ?.doit of <__main__.bob instance at 0x404afb6c>>

James
Jan 31 '06 #5
James Stroud wrote:
Luke wrote:
Thanks James, though from the output of b.x() it appears that x is a
class method (ie the class is passed as the first parameter rather than
the instance)...


Sorry, the one line was probably supposed to be

b = bob()

I forgot the parens:

py> b = bob()
py> b.x = types.MethodTyp e(doit, b)
py> b.x()
<__main__.bob instance at 0x404afb6c>
py> b.x
<bound method ?.doit of <__main__.bob instance at 0x404afb6c>>

James


Also, you should know about the __abs__ method (this is probably what
you are really looking for:

py> class bob:
.... def __init__(self, aval):
.... self.value = aval
.... def __abs__(self):
.... return abs(self.value)
....
py> b = bob(-4)
py>
py> abs(b)
4
py> b.value
-4
You may want to have a look at this:

http://docs.python.org/ref/customization.html
Jan 31 '06 #6

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

Similar topics

3
2353
by: Jaroslaw Zabiello | last post by:
I got strange errors in Zope 2.7. METALError macro 'context/base' has incompatible version None, at line 1, column 1 One ZPT file (named 'base') defines some simply slots: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"
0
2018
by: Neil Sargent | last post by:
This is a general posting of how I fixed a problem created by using the Access 97 ODE Setup Wizard on a Windows XP machine. I hope it helps anyone who comes across the problem saves them the 3 days its taken me to sort out. The application generates the following error: "Incompatible version of the RPC stub" This occurs when trying to run Outlook to send an email. However I expect it would occur for any operation which uses...
7
593
by: Brian Stubblefield | last post by:
Dear clc members, I am new to C and am posting several messages concerning a large C program that I am debugging. I am encountering a "incompatible types in assignment" warning for the following code during the compile stage: #include <stdio.h> #include <signal.h>
1
2871
by: Josh Wilson | last post by:
Hey gang, So I have my stdin which is user defined file, and am wanting to write it to a temporary file (seems odd I know, but there is a sincere reason), and then use that file as the stdin for the remaining part of the program. I have combed the FAQ and got some preliminary questions answered, and tried to model this after what I have seen suggested to people previously, but for my strcpy and freopen I get, "warning: passing arg 1 of...
7
15778
by: Arun Kannan | last post by:
Hi We are planning to upgrade a MFC Application (.Exe) to compile on Dot Net Framework. I have opened the application in Visual Studio 2003. I changed the compiler option to /clr. I have set following properties -Basic Run Time checks to Default -Smaller Type Check to N -Runtime Library -Mutlit Threaded Debug threade -Use of MFC - use Standard windows libraries (tried with MFC as Static and Shared dll.. No luck Now, i am wondering...
0
1772
by: Brian Takita | last post by:
Hello, I'm getting the following error at the end of this message when trying to run the ReportManager and the ReportServer: Assembly system.data.dll security permission grant set is incompatible between appdomains. I had to apply KB 887787 (http://support.microsoft.com/?kbid=887787) to fix my previous error, which stated... Assembly microsoft.web.validatepathmodule.dll security permission grant
9
2560
by: Ali | last post by:
incompatible warning in C/C++ I am using MS Visual C/C++ 6.0. I get the following warning when compiling C:model.ex.c(1221) : warning C4133: '=' : incompatible types - from 'struct s_lsp_def *' to 'struct s_lsp_def *' In the .h file, I have ======================
6
5269
by: PraZ | last post by:
Hi all. Here is a simple code, which when compiled with gcc results in the warning "incompatible pointer type" for arg 1, as expected. But this is just what I want to do, because it makes it easy for me to handle the single dimensional stream I have as a multidimensional array inside the function func(). Now, I am just wondering if there is a way by which I can disable this incompatible pointer type warning in gcc. Any suggestions?
8
24234
by: fei.liu | last post by:
I have the following source code. It seems wierd to me why gca's value cannot be reassigned. It's afterall a pointer and has a pointer value. I am aware that the standard says it's not allowed. But I cannot convince myself why this is prohibited. static int ia = {64, 64, 64, 64}; static char ca = {'a', 'b', 'c', 'd'}; static int iaa = {64, 64, 64, 64}; static char caa = {'a', 'b', 'c', 'd'}; static char cab = "abcd";
0
4931
by: srikar | last post by:
Hi all, I am having a problem, when I am compiling the code in 32 bit option on a 64 bit machine using the macro CPPFLAGS= -m32 I am getting the following warnings from the linker . /`../bin/amd64_stat_gnu_02015/WriteFault.o' is incompatible with i386:x86-64 output /usr/bin/ld: warning: i386 architecture of input file `../bin/amd64_stat_gnu_02015/WriteLogic.o' is incompatible with i386:x86-64 output /usr/bin/ld: warning: i386...
0
10495
Oralloy
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...
1
10248
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
9085
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
7573
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
5469
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...
0
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4148
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
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2942
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.