[Tutor] Read the builtin module source, also itchy ellipses.
kent37 at tds.net
Fri Nov 17 15:10:28 CET 2006
> I sometimes find it useful to read the source code of a module and for
> example I can type string.__file__ to find the location of the string
> However the .__file__ method is not available for the module builtin. Is
> it possible to read the source code for built in functions and if so how
> do I find them? I realise some/all may be written in C rather than
> python but it would still be interesting to read them.
It's all in C, see Python\bltinmodule.c in the source distribution.
> In an unrelated follow-up may I also ask: can the ellipsis (...) be used
> in code? I tried a googlecode search but none of the examples worked for
> me. Can someone post an example line of code that uses ... in it.
> This has been causing an itch in my brain, please reply with the scratch.
Syntactically ellipsis is allowed in a slice list as shown in the syntax
As a practical matter I think the only containers that actually support
this kind of slicing are the arrays in Numeric and numpy. Here is a
You could also support this syntax in a class of your own. Here is a
simple example that just captures the argument to __getitem__() to show
how the mechanism works:
In : class Foo(object):
...: def __getitem__(self, s):
...: self.s = s
...: return None
In : f=Foo()
In : f[...,1]
In : f.s
Out: (Ellipsis, 1)
More information about the Tutor