Python scoping

vinej info.jyv at videotron.ca
Tue Oct 24 22:24:02 EDT 2000


I'm using python for a while now, and I'm always using a
remark like that.

if a == 1 :
    print "ok"
#if

for s in stocks :
    if s == 'end' :
        print "ok"
    #if
    print "something else"
#for

etc..

This is very simple and I'm sure that if something happening to my
code (erasing tabs by mistake), I can always find the original code.
I think that my programs are more readable like that.

JYV

Olivier Dagenais wrote:

> I saw a half-funny article on how you can get Python to support explicit
> scope start/end:  just prefix your brace or keyword with the '#' character,
> like so:
>
> for c in range ( 100 ):
> # do
>     print c,
> # next c
>
> ...or if you come from a C background...
>
> for c in range ( 100 ):
> #{
>     print c,
> #}
>
> and Python is smart enough to match two different styles, too:
>
> for c in range ( 100 ):
> # do
>     print c,
> #}
>
> Note, however, you still need to properly indent your code...
>
> --
> ----------------------------------------------------------------------
> Olivier A. Dagenais - Software Architect and Developer
> "Someone called 'Type your name here' is impersonating me on the
> internet and is posting exactly the same things I am posting!"
>
> "SuppamanX" <suppamanx at collector.org> wrote in message
> news:8FD6F80F0suppamanxcollectoror at 209.155.56.95...
> >    I have been using Python off and on for 6 months now and have grown to
> > love it from the beginning. However, there is a facett of Python that
> > annoys me somewhat. It is the 'scoping by indentation'. Coming from a
> > background of 'formal' languages (e.g. Pascal, C, Java,...), I am
> > accustomed to explicitly start and end my scopes with a braces. From a
> > readability standpoint, it gets quite problematic for especially for some
> > of the example code that I am trying to learn from.
> >
> > Can someone clarify why there is no explicit end for scopes?
> > (i.e. IFs, FORs, WHILEs, METHODs, etc...)
> >
> > Thanx




More information about the Python-list mailing list