with
의 범위에 바인딩 된 전역 변수가 with
문에 as
슈트의 VAR
으로 만들 수 있습니까? f
변수 아래의 예에 할당 또한 외부 with
의 with
문 후 :소송으로 globaly가 with 문을 지정합니다. 파이썬
with open("some_text.txt") as f:
pass
print(f.closed)
print(f)
이 반환
>>> True
<_io.TextIOWrapper name='some_text.txt' mode='r' encoding='UTF-8'>
as
VAR 여전히 내가 내부 with
를 사용하는 경우에도 바인딩 함수 :
def longerThan10Chars(*files):
for my_file in files:
with open(my_file) as f:
for line in f:
if len(line) >= 10:
print(line)
print(f.closed)
여기서 f.closed
은 여전히 0을 인쇄합니다..
'with..as' 블록 뒤에'f'가 언 바운드되기를 원한다는 말입니까? –
@PatrickHaugh 네, 그게 내가 말하려고했던 것입니다. – amirteymuri
수 없습니다. 파이썬에는 세분화 된 범위가 없습니다. –