[Tutor] capitalize() but only first letter

Magnus Lycka magnus@thinkware.se
Sun Feb 9 19:16:51 2003


At 18:39 2003-02-09 -0500, Erik Price wrote:
>Sorry, I should have been more clear when I said "I'm not sure how this 
>works" -- I wasn't taking issue with the fact that Python lets just about 
>everything be an object, simply curious about how the re.sub() function 
>determined whether it should act upon a string or use a function.  Your 
>explanation makes it completely clear -- there's an internal type check 
>that decides which should be done based on what the argument is.

To be more precise, the code looks like this:

     if (PyCallable_Check(template)) {
         /* sub/subn takes either a function or a template */
         filter = template;
         Py_INCREF(filter);
         filter_is_callable = 1;
     } else {
         /* if not callable, check if it's a literal string */

It's in the pattern_subx function of _sre.c, which you can
find in the Python source code.

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Modules/_sre.c?rev=2.87&content-type=text/vnd.viewcvs-markup



-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se