Код: Выделить всё
# infile.py
FILE1 = 'file1'
FILE2 = 'file2'
def getfile():
file = FILE1 if 'FILE1' in locals() else FILE2
print(f'{file=}')
if __name__ == '__main__':
getfile()
Код: Выделить всё
PS> .\infile.py
file='file2'
Код: Выделить всё
# Set breakpoint at first line in def getfile function
# Execute following:
file = FILE1 if 'FILE1' in locals() else FILE2
print(file)
file1
Мне также любопытно, почему я вижу разницу между тем, что делает Python, и тем, что показывает отладчик VS Code Python. Я что-то делаю не так или это баг?
Подробнее здесь: https://stackoverflow.com/questions/792 ... -scope-loo