Can I have a package and a module with the same name in Python?
ex:
import json
import myapp.json.jsoncustommodule
I don't know if this has anything to do with the fact that json is in Python built-in library.
In most languages, this is acceptable. However, Python seems to confuse both things, even if they are in different parent packages.
To answer your question, there's no issue with doing something like this in python.
However if you have a namespace conflict resulting from something like this:-
import json
from myspecialpackage import json
You will need to resolve it by using as
keyword, like this:-
from myspecialpackage import json as special_json
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.