#define (was Re: python-list at python.org)

Alex Martelli aleaxit at yahoo.com
Thu Apr 12 11:07:08 EDT 2001


"Vincent A. Primavera" <vincent_a_primavera at netzero.net> wrote in message
news:mailman.987079936.13897.python-list at python.org...
> Hello,
> What I am trying to accomplish is to shorten statements such as
> stdscr.addstr(10, 10, 'This is a test...', curses.color_pair(1))... ;o}
> nothing too complicated.

You don't need a #define (i.e., macros) for this; just wrap this
statement into a function, with whatever arguments and defaults
you desire.

Suppose, for example, that (were this C) you would code:

#define SAY(text,y) stdscr_addstr(10, y, text, curses_color_pair(1))

The Pythonic equivalent would then be:

def SAY(text, y):
    stdscr.addstr(10, y, text, curses.color_pair(1))

and of course, you can have default-valued arguments:

def SAY(text, y, color=None):
    if color is None: color = curses.color_pair(1)
    stdscr.addstr(10, y, text, color)


Nothing too complicated -- just nice, powerful, simple.
I.e., Python.


Alex






More information about the Python-list mailing list