2

In Harmony, there is a let keyword that allows for declaration of variables that are scoped to the nearest block. For example

function foo() {
    if (true){
        let a = 100;
    }
    return a
}

will result in an error since a is only defined inside the if block.

I know I can use del to achieve the same thing, but that that is manual instead of automatic like the let keyword

XrXr
  • 2,027
  • 1
  • 14
  • 20

1 Answers1

2

Python creates scopes for every class, module, function or generator expression. There is no scoping within blocks of code. You might be able to achieve your intended goal using nested functions, e.g.:

def outside():
    def inside():
        var=5
    print var

Calling outside will result in:

outside()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 5, in outside
NameError: global name 'var' is not defined