problem with variable scoping

Moshe Zadka moshez at math.huji.ac.il
Thu May 27 01:51:27 EDT 1999


On Thu, 27 May 1999, Tim Peters wrote:

> > def process(line):
> >         ...
> >         if last_line_empty:
> >                 pass
> >         else:
> >                 print "<P>"
> >         last_line_empty = 1
> 
> C:
> 
> int last_line_empty = 0;
> 
> void process(const char* line)
> {
>   int last_line_empty;
>   if (last_line_empty)
>       ;
>   else
>       printf("<P>\n");
>   last_line_empty = 1;
> }

Ummmm.....Tim, I beg to differ: it is more like the C++

void process(const char *line)
{
  if (last_line_empty)
      ;
  else
      printf("<P>\n");
  int last_line_empty;

  last_line_empty = 1;
}

The  Python code shadows last_line_empty only *after* the "decleration"

would-be-interesting-if-python-had-set!-and-not-just-define-ly y'rs, Z.

--
Moshe Zadka <mzadka at geocities.com>. 
QOTD: My own exit is more likely to be horizontal then perpendicular.






More information about the Python-list mailing list