Python: methods arguments limited to 256?
Hi, I have a python script in which I call a zsqlmethod and pass to it some args, If I pass 255 args everything ok (dont ask why I need so many args its not your business :-), If I pass more than 255 args to zsqlmethod then when hitting the python script "save changes" button I get the following error (Note: the error appears when clicking the save changes button of the Python Script): Exception Type ValueError Exception Value chr() arg not in range(256) Traceback (innermost last): * Module ZPublisher.Publish, line 100, in publish * Module ZPublisher.mapply, line 88, in mapply * Module ZPublisher.Publish, line 40, in call_object * Module Products.PythonScripts.PythonScript, line 132, in ZPythonScriptHTML_editAction * Module Products.PythonScripts.PythonScript, line 151, in ZPythonScript_edit * Module Products.QuotaFolder, line 240, in QA_ps_write * Module Products.PythonScripts.PythonScript, line 419, in write * Module Products.PythonScripts.PythonScript, line 272, in _makeFunction * Module Products.PythonScripts.PythonScript, line 231, in _compile * Module Products.PythonScripts.PythonScript, line 225, in _compiler * Module RestrictedPython.RCompile, line 85, in compile_restricted_function * Module RestrictedPython.RCompile, line 68, in compileAndTuplize * Module RestrictedPython.RCompile, line 63, in compile * Module compiler.pycodegen, line 245, in getCode * Module compiler.pyassem, line 371, in getCode * Module compiler.pyassem, line 477, in convertArgs * Module compiler.pyassem, line 513, in _convert_LOAD_CONST * Module compiler.pycodegen, line 245, in getCode * Module compiler.pyassem, line 373, in getCode * Module compiler.pyassem, line 579, in makeByteCode * Module compiler.pyassem, line 673, in addCode ValueError: chr() arg not in range(256) Any clue? Thanx, Julio Dinis Silva --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.593 / Virus Database: 376 - Release Date: 20/02/04
Julio Silva wrote:
Hi,
I have a python script in which I call a zsqlmethod and pass to it some args, If I pass 255 args everything ok (dont ask why I need so many args its not your business :-),
Dont care, passing that many args is not good design :)
If I pass more than 255 args to zsqlmethod then when hitting the python script "save changes" button I get the following error (Note: the error appears when clicking the save changes button of the Python Script):
Works here (can't believe I actually tried it). Even if it didn't work I happily consider this a reasonable limitation :) You probably have a character thats not in the standard ASCII range, eg: if you cut and paste from Word or have a unicode character. Try looking at the *args, and **kw notation if you must past that many arguments btw. -- Andy McKay ClearWind Consulting http://www.clearwind.ca
At 09:01, you wrote:
Julio Silva wrote:
Hi, I have a python script in which I call a zsqlmethod and pass to it some args, If I pass 255 args everything ok (dont ask why I need so many args its not your business :-),
Dont care, passing that many args is not good design :)
Well... we could start a thread on that matter but we dont have time, I find some real exceptional cases in my programming life, specialy in my glueware legacyware programming. Suppose you use zope to migrate legacy databases and suppose you find yourself with a legacy table with 400 fields, there you must start your brain in high creative mode and with default value infinite on patience variable :-)
If I pass more than 255 args to zsqlmethod then when hitting the python script "save changes" button I get the following error (Note: the error appears when clicking the save changes button of the Python Script):
Works here (can't believe I actually tried it). Even if it didn't work I happily consider this a reasonable limitation :)
You probably have a character thats not in the standard ASCII range, eg: if you cut and paste from Word or have a unicode character.
Thanks for you help Andy, but I'm positive certain by the debug I'm making that if I pass 255 parameters its ok, once I pass the 256th the error begin to arise, I have measures to certify there is no character encode problem, that was the first thing I checked. Make this test: create a python script and copy the code below into it and try to "save changes" you get the error. take out one parameter and hit "save changes" again you will be able to save the document with no errors. --------------------------------------------------- values=[] container.myzsqlmetho( a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'], a=values['a'] ) ------------------------------------------------- Best Regards, Julio Silva --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.593 / Virus Database: 376 - Release Date: 20/02/04
Make this test: create a python script and copy the code below into it and try to "save changes" you get the error. take out one parameter and hit "save changes" again you will be able to save the document with no errors.
Yep, I tryed with a dtml method and the error message was clear: Expression (Python) Syntax error: more than 255 arguments , for tag <dtml-call "myzsqlmethod(a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a, a=a) ">, on line 1 of sss Best Regards, Julio Dinis Silva --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.593 / Virus Database: 376 - Release Date: 20/02/04
Julio Silva wrote:
Make this test: create a python script and copy the code below into it and try to "save changes" you get the error. take out one parameter and hit "save changes" again you will be able to save the document with no errors.
Yep,
I tryed with a dtml method and the error message was clear:
Expression (Python) Syntax error: more than 255 arguments
, for tag <dtml-call "myzsqlmethod(a=a, a=a, a=a, a=a, a=a, a=a, a=a,
and what about <dtml-call "REQUEST.set('a001','x')"> <dtml-call "REQUEST.set('a002','x')"> ... <dtml-call "REQUEST.set('a256','x')"> <dtml-call myzsqlmethod> Not tested... -- Jaroslav Lukesh
Julio Silva wrote:
Well... we could start a thread on that matter but we dont have time, I find some real exceptional cases in my programming life, specialy in my glueware legacyware programming. Suppose you use zope to migrate legacy databases and suppose you find yourself with a legacy table with 400 fields, there you must start your brain in high creative mode and with default value infinite on patience variable :-)
Agreed, but there's still better ways to go, pass through a struct or object that contains the variables and access them in DTML ;)
Thanks for you help Andy, but I'm positive certain by the debug I'm making that if I pass 255 parameters its ok, once I pass the 256th the error begin to arise, I have measures to certify there is no character encode problem, that was the first thing I checked.
Make this test: create a python script and copy the code below into it and try to "save changes" you get the error. take out one parameter and hit "save changes" again you will be able to save the document with no errors.
Ah I was doing something slightly different in my test. I'll still say its a real edge case that does not need fixing, however the error message for a Python Script could be clearer. Anyway use *, and **... Here's my test case that passes in over 500 arguments into a Python Script and it works just fine. args = [] for x in range(256): args.append("%sx") kw = {} for x in range(256): kw["%sx" % x] = x container.someMethod(*args, **kw) print len(args), len(kw) return printed And that works fine ;) -- Andy McKay ClearWind Consulting http://www.clearwind.ca
participants (3)
-
Andy McKay -
Jaroslav Lukesh -
Julio Silva