[Tutor] color of "print" function

Emile van Sebille emile at fenx.com
Sat Jan 15 18:46:10 CET 2011


On 1/14/2011 4:48 PM Bill DeBroglie said...
> Hello all,
>
> I don't have a problem per se, but have noticed something that I'd like
> to figure out...

Ths best way to figure it out is  'use the source Luke'

Idle is written in python, and in python27/Lib/idlelib there's 
colordelegator.py, where you'll find

def make_pat():
     kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b"
     builtinlist = [str(name) for name in dir(__builtin__)
                                         if not name.startswith('_')]

keyword is imported above, and looking there you find 
python27/Lib/keyword.py which defines kwlist to include print.

 >>> import __builtin__
 >>> dir(__builtin__)

also includes print, so print is defined twice.

Further in ColorDelegator you find

      "KEYWORD": idleConf.GetHighlight(theme, "keyword"),
      "BUILTIN": idleConf.GetHighlight(theme, "builtin"),

So, keywords and builtins have their own colors defined in theme 
(whatever that is...)

So, I'll venture at this point that the source of the problem lies in 
print being defined in two sets having two colorization definitions.

The easy way to fix it would be to remove it from one list or the other 
in ColorDelegator to clear up the problem.

HTH,

Emile


>
> Sometimes the "print" function appears orange for me, sometimes it
> appears purple. Why does this happen and what's the difference anyway?
> This seems to be the only function that varies like this, but I'm just
> starting really so perhaps I'll come across more.
>
> The coloring seems to be fairly arbitrary. At least, I haven't noticed a
> pattern yet.
>
> Using Mac OS X 10.5.8 and Python 2.7.1
>
> Thank you for the help,
> bdb
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>




More information about the Tutor mailing list