3 ms·
How do you do this in Python? Or is this just an approach you can take in C/C++?
by legutierr 12y ago
How do you do this in Python? Or is this just an approach you can take in C/C++?
- ufo 12y agoYou should be able to do domething similar to the C example in most other languages with sane, lexical, variable scoping. Unfortunately, Python doesn't really play nice with nested scopes/functions so you are a bit out of luck here.
- eru 12y agoAll comprehensions get their own scope in Python 3.
- delluminatus 12y agoYou can't do it in Python, but it's not limited to C/C++ either; this is usually called "block scoping" and it's present in C/C++, C#, I think Ruby, Java, etc.
- lhc- 12y agoYou could define local functions inside your larger sequential function, and then call immediately. Not 100% the same, but in terms of reading-code-in-order, it would have the effect, and it would create the same scope restrictions as the listed code.