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

Vincent A. Primavera vincent_a_primavera at netzero.net
Thu Apr 12 08:26:47 EDT 2001


Hello,
	Thank you for the help.   It's nice to see someone willing to share 
knowledge instead of sarcasm.

	Vincent A. Primavera.

On Thursday 12 April 2001 15:07, Alex Martelli wrote:
> "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