0
다음 중 올바른 Python 2.7 가져 오기 시나리오는 무엇입니까? 즉, stdlib 모듈을 섀도 잉하는 이름의 모듈을 가지고 있다면 import <module>
stdlib 또는 로컬 버전을 가져와야합니까? OSX에서 Python 절대 가져 오기
$ ls
__init__.py time.py
~/tmp $ cat time.py
def a():
print(¨a¨)
~/tmp $ python
Python 2.7.4 (default, Sep 26 2013, 03:20:26)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> dir(time)
['__doc__', '__name__', '__package__', 'accept2dyear', 'altzone', 'asctime', 'clock', 'ctime', 'daylight', 'gmtime', 'localtime', 'mktime', 'sleep', 'strftime', 'strptime', 'struct_time', 'time', 'timezone', 'tzname', 'tzset']
와 OSX
에 리눅스 에는
sdk$ ls
__init__.py time.py time.pyc
$ cat time.py
def a():
print("a")
$ python
Python 2.7.6 (default, Apr 9 2014, 11:48:52)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> dir(time)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'a']
PS : 윈도우 리눅스 따라 보인다 __future__ import absolute_import
에서 사용하는 현재 경로가 보통에 추가됩니다
두 OS 모두 파이썬 경로에 모듈이 포함되어 있습니까? – jonrsharpe
첫 번째 예제에서'~/tmp'로 cd하지 않았습니까? 거기에'__init __. py'가 있습니까? – juanchopanza
왜 같은 이름의 모듈을 사용하고 있습니까? –