473,503 Members | 1,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically add class method causes "SystemError: ... bad argument to internal function"

Hi, group,
I am trying to dynamically add a method to class by following
this post:

http://groups-beta.google.com/group/...8e91be352c6bfc

But I got the Error like the below:

*******Error**********************
Traceback (most recent call last):
File "C:\Documents and Settings\cwu\Desktop\t1.py", line 36, in ?
C().f2(1,2,4,x='x')
File "C:\Documents and Settings\cwu\Desktop\t1.py", line 19, in newf2
self.f()
SystemError: C:\sf\python\dist\src-maint23\Objects\cellobject.c:22: bad
argument to internal function
*******Error**********************

Anybody has a thought about this problem?

My sample code is pasted as the below:

*********Code*******************************
##import new
##import sys
##
##def safe_tuple(seq):
## """Force func_code attributes to tuples of strings.
##
##
## Many of the func_code attributes must take tuples, not lists,
## and *cannot* accept unicode items--they must be coerced to strings
## or the interpreter will crash.
## """
## seq = map(str, seq)
## return tuple(seq)
##
##class C:
## def __init__(self):
## def _generic(*a,**k):
## print vars()
## self.f()
##
## def _newmethod(newname):
## fcode = _generic.func_code
## #code( argcount, nlocals, stacksize, flags, codestring,
constants, names, varnames, filename, name, firstlineno, lnotab)
## fcode_new = new.code(fcode.co_argcount, fcode.co_nlocals,
fcode.co_stacksize,
## fcode.co_flags, fcode.co_code,
tuple(fcode.co_consts), # Notice co_consts should *not* be
safe_tupled.
## safe_tuple(fcode.co_names),
safe_tuple(fcode.co_varnames),
## fcode.co_filename,
## newname,
## fcode.co_firstlineno,
fcode.co_lnotab)
## return new.function(fcode_new,globals())
## setattr(self,'f2',_newmethod('newf2'))
##
## def f():
## print 'from f'
##
##C().f2(1,2,4,x='x')
##
##
**********Code************************

*Sorry, I have to put comment chars before the code to preserve the
proper indentation.

Thanks a lot!
CW

Jul 18 '05 #1
1 3843
I have noticed that the exception was caused by the call of "self.f()"
within my "_generic" function. It will raise SystemError exception
whenever I refer to any method or attribute of "self" within "_generic"
function. Otherwise, dynamically adding method works fine. I cannot
figure out what's the reason there.

CW

Jul 18 '05 #2

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

Similar topics

4
8882
by: Robert Ferrell | last post by:
I have a style question. I have a class with a method, m1, which needs a helper function, hf. I can put hf inside m1, or I can make it another method of the class. The only place hf should ever...
7
3325
by: Will Hartung | last post by:
I have this: <a class="pink_link" href="faq.html#q1">Go to question 1</a> And the CSS is simply: ..pink_link {color: #fa61b7; font-weight: bold;} So, I'm curious why my links are blue and...
0
2158
by: Benjamin Lukner | last post by:
Hi! I'd like to dynamically call API functions from different DLLs, depending on what platform the program runs. Now I'm wondering what the most simple way may be (without meta code and compiler...
0
1353
by: Marty Meyers | last post by:
TIA for your help! Using PHP 4.3.9 doing some code cleanup on an existing site. I have reduced the problem to: This File is marty.php: <? class Refs { function scriptDir() { echo "Refs are...
6
1820
by: John Nossluap | last post by:
I've got a third-party assembly dll containing an "internal" class with some public methods I would very much like to use. I understand the meaning and reason of setting the accessibility of the...
1
7997
by: Java Guy | last post by:
I'm trying to view a web page. IE tells me there are (Java?) errors on the page. Here they are: Line: 15 Char: 7 Error: Wrong number of arguments or invalid propert assignment Code: 0 URL:...
7
12571
by: gretean | last post by:
I have a problem that's driving me crazy involving Microsoft's ability to deduce template parameters. I am using Visual Studio .NET (aka VC7?), and it gives an error compiling the following code....
7
2458
by: desktop | last post by:
This page: http://www.eptacom.net/pubblicazioni/pub_eng/mdisp.html start with the line: "Virtual functions allow polymorphism on a single argument". What does that exactly mean? I guess it...
4
3370
by: robert | last post by:
On a server the binary (red hat) installed python2.4 and also a fresh compiled python2.5 spits "sem_post: Invalid argument". What is this and how can this solved? Robert ============== ...
0
7280
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,...
0
7330
jinu1996
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...
1
6991
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...
0
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
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,...
1
5014
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...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
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 ...
0
380
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...

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.