Найти - Пользователи
Полная версия: import и зоны видемости
Начало » Python для новичков » import и зоны видемости
1
Dartanyan
Суть вопроса, где лучше импортить либы в методах(функциях) которые запускает subproccess, или добавить их в самом начале файла

Есть две мысли что лучше импортировать там где юзает для красоты и скорости, но походу это будет и жрать больше памяти. Я прва?
py.user.next
http://legacy.python.org/dev/peps/pep-0008/#imports
Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants.
Dartanyan
это понятно, а всетаки влияет на что-то если я импортирую внутри метода?
py.user.next
>>> def f():
...   import os
...   print(os)
... 
>>> f()
<module 'os' from '/usr/lib/python3.3/os.py'>
>>> os
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'os' is not defined
>>>
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB