A Python limit I never expected to run intoI've known for a while that the Python interpreter has a few little internal limits and implementation quirks. I can accept that; limits on the sizes of internal objects are not unexpected, and you have to draw the line somewhere. But I was surprised to discover that the Python interpreter has a limit on how many arguments you can write in a function call; 255, as it happens. (The limitation is on explicit arguments in the source code; you can
call functions with many more arguments if you build a list and then use
' You might ask how anyone writes a function call with 255 arguments. In my case, one argument at a time; the function in question compiles a bunch of IP netblocks and ranges, in string form, into a set type object that other IP addresses get matched against. When I was only putting a few netblocks in the set, having them be function arguments made sense. (In fact I think that it still makes sense; I have to list them somehow, unless I exile them to a separate data file, so I might just do it directly as function arguments.) I probably should have noticed that something was wrong earlier, but I'm bad at noticing my programs growing unless they do it in large jumps. If they just grow by a function here and some entries in a list there, without forcing me to step back for an overall view, a few hundred lines can transform into a two thousand line hulk without me really noticing. The nitty gritty detailsBecause I got curious and looked it up in the CPython source: the
actual limit is 255 positional arguments plus an additional 255 keyword
arguments. It exists because of how the argument counts are encoded
into the Python bytecode; each one is effectively restricted to a byte.
Explicit Some quick experimentation with |
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |