Eric Smith schrieb: > While implementing "".format(), I need to call the builtin format() > function, which I've already implemented (in > bltinmodule.c:builtin_format()). In the py3k branch, I just hardcoded > the same functionality into "".format(), which seems like the wrong > thing to do, given how complex the code is. > > I see 2 approaches: > > 1: exposing builtin_format(), probably giving it another name > (PyObject_Format?) and moving it somewhere other than bltinmodule.c. > > 2: Instead of calling the C code directly, lookup "format" in Python's > builtins, and call it. This, I think, would allow you to override the > global format() function if you wanted to modify the behavior (although > I can't think of any use case for wanting to do that). > > I don't see where either behavior is specified in the PEP. > > If option 2 is preferred, could someone give me a pointer to how to find > a builtin function from C code?
I don't know which option Guido prefers, but for looking up a function from the builtins, look at Python/import.c:PyImport_Import which does this with __import__. Georg -- Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com