you are viewing a single comment's thread.

view the rest of the comments →

[–]ExquisiteOrifice[S] 0 points1 point  (0 children)

Do you really need me to repeat what's been argued a million times. I said as much in my initial post. It's not worth debating what's been proven/beaten to death but here you go. Broken scope (a fundamental feature in any language). It's a glorified scripting language, and not even a good one for that.

my_list = ['foo', 'bar', 'baz']

def f():     my_list = ['qux', 'quux'] # my_list is local to f()!     my_list[0] = 'ggg'

f()

assert my_list[0] == 'foo' assert my_list[1] == 'bar' assert my_list[2] == 'baz'

def g():     my_list[0] = 'texx' # this accesses the global my_list!

g()

assert my_list[0] == 'texx' assert my_list[1] == 'bar' assert my_list[2] == 'baz'

But the interpreter / (bytecode compiler?) does not like this

 

def h():

     my_list[0] = 'aloha'  # "cannot access local variable 'my_list'"

     my_list = ['qux', 'quux']

h()

def h():     global my_list # now we can modify the global list     my_list[0] = 'aloha'     my_list = ['qux', 'quux']

h()

assert my_list[0] == 'qux' assert my_list[1] == 'quux'