Some language proposals.
Antoon Pardon
apardon at forel.vub.ac.be
Tue Feb 24 10:53:42 EST 2004
I'm rather new at this, so I don't know how I should
introduce this, nor whether these ideas are worth much
but here goes.
What I would like to change is access to variables on
an intermediate scope. Given the following example
def fun_1()
a = some_value
def fun_2()
# a is never the one above.
# on the left side of a statement.
The solution that I heard proposed was to use
a mutable variable. Something like
def fun_1():
a = [some_value]
def fun_2();
a[0] = new_value
And of course if you had a number of such variables
you could group then in an object
def fun_1():
class var_1:
pass
var_1.a = some_value
var_1.b = a_value_too
def fun_2():
var_1.a = new_value
var_1.b = next_value
Now my idea would be to look at the local variables in
a function like member variables of an object so that
you could write
def fun_1():
a = some_value
b = a_value_too
def fun_2():
fun_1.a = new_value
fun_1.b = next_value
This could maybe even extended further is seeing functions
like some kind of module which would allow something like
the following
def fun_1():
a = some_value
b = a_value_too
def fun_2():
from fun_1 import a, b
a = new_value
b = next_value
What do people think about this?
As far as I know the proposal doesn't break existing
code and seems in the spirit of python.
On a side note, what would people think about the idea of
a from ... import ... statement usable on any object? So
that we could do:
class A:
pass
A.a = ...
A.b = ...
from A import a, b
# from here a and be refer to A.a and A.b
--
Antoon Pardon
More information about the Python-list
mailing list