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

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 3838
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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,...

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.