python - Which path does the dot in import use as the root directory?
学习ing
学习ing 2017-07-05 10:34:06
0
1
906
# in mylib.py file from . import xml from .xml import some_thing from ..xml import some_thing ...

Which path is used as the root directory for this type of explicit relative reference? In particular, when the above program itself is also a library, it is

by other users after it is released.
import mylib

Then what path is calculated relative to this time?

another question,

import os assert os.path.isdir(',')

no problem. But some libraries, such as PIL

import PIL PIL.Image(...) # 就会报错,找不到Image,需要显式的 import PIL.Image PIL.Image(...) # OK

This is why? Thank you in advance.

学习ing
学习ing

reply all (1)
代言
  1. .(dot) is based on your current running file path as the current path

  2. After being published, it will be referenced by other users. There is a Lib directory in your Python installation directory. Directly refer to the global modules in this directory like import os

import os os.path...

It can be run because os is a module and an executable python file

As for the PIL example, since I don’t have PIL, I can only irresponsibly guess that PIL is not a module

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!