Dumb newbie back in shell

MartinRinehart at gmail.com MartinRinehart at gmail.com
Mon Dec 10 13:06:14 EST 2007


Not trying to write C, I'm trying to write Decaf, a language I've
designed (see www.MartinRinehart.com for more) but which doesn't
exist. Got to code the first bit in something. Later I can write Decaf
in Decaf. Chose Python as it looked like a faster write (learning
curve included) than C or C++.

Python is commonly called a "scripting" language because of its use as
one of the Ps in the LAMP stack. I'm using it as a general-purpose
programming language with the neat feature of being able to write
scripts in its own console.

Bruno Desthuilliers wrote:
> MartinRinehart at gmail.com a �crit :
> > OK, it's a scripting language.
>
> For which definition of "scripting language" ?-)
>
> >>>> def g():
> > ...    os.remove('tokeneizer.pyc')
> > ...    reload( tokeneizer )
> > ...    tokeneizer.tokenize('sample_decaf.d')
> > ...
> >
> > But that gets me to:
> >
> > ... line 110, in get_toks
> > UnboundLocalError: local variable 'line_ptr' referenced before
> > assignment
> >
> > Here's a bit of the code, with line #s
> >
> > ...
> > 68 global line_ptr
> > 69 global char_ptr
> > ...
> > 75 line_ptr = 0
> > 76 char_ptr = 0
> > ...
> > 109 def get_toks( text ):
> > 110     while line_ptr < last_line:
> > ...
> > So when is a global var global?
>
> Short answer : never !-)
>
> Long answer:
>
> First point: "global" really means "module level" - there's no
> "application global" namespaces.
>
> Second point: every name declared as the top-level is global - according
> to the above definition. So there's no need to declare them as such. The
> only place where you need the global statement is when you want to
> rebind a module-level name from within a function. And it's in this
> function that you need to declare the name as global.
>
> FWIW, this is documented.
>
> Last point: Python is not C, and it definitively doesn't have pointers.
> Trying to write C in Python is a waste of time and an experiment in
> frustration (just like trying to write language XXX in language YYY for
> any distinct values of XXX and YYY).
>
> HTH



More information about the Python-list mailing list