I have three files in one dir:
# Untitled-1.py
print("UTITLEDPY")
if __name__== "__main__":
from telegram.ext import Updater, CommandHandler, InlineQueryHandler
import logging
from telegram import InlineQueryResultArticle, InlineQueryResultPhoto, InputTextMessageContent
and
# test.py
import google_image_search
print("TESTPY")
and this one
# google_image_search.py
print("IMAGESPY")
When I run python3 Untitled-1.py
, I have the following output:
UTITLEDPY
IMAGESPY
TESTPY
Please, explain why. The expected output is UTITLEDPY
only.
[EDIT]
I added raise ValueError()
to test.py
:
# test.py
import google_image_search
print("TESTPY")
raise ValueError()
After that running python3 Untitled-1.py
gives the following output:
UTITLEDPY
IMAGESPY
TESTPY
Traceback (most recent call last):
File "Untitled-1.py", line 5, in <module>
from telegram.ext import Updater, CommandHandler, InlineQueryHandler
File "/usr/local/lib/python3.7/site-packages/telegram/__init__.py", line 47, in <module>
from .files.file import File
File "/usr/local/lib/python3.7/site-packages/telegram/files/file.py", line 24, in <module>
from future.backports.urllib import parse as urllib_parse
File "/usr/local/lib/python3.7/site-packages/future/backports/__init__.py", line 14, in <module>
import_top_level_modules()
File "/usr/local/lib/python3.7/site-packages/future/standard_library/__init__.py", line 810, in import_top_level_modules
with exclude_local_folder_imports(*TOP_LEVEL_MODULES):
File "/usr/local/lib/python3.7/site-packages/future/standard_library/__init__.py", line 781, in __enter__
module = __import__(m, level=0)
File "/Users/arturzielinski/Desktop/ibodi_bot/test.py", line 5, in <module>
raise ValueError()
ValueError
[EDIT2]
Renaming test.py
to test1.py
solved the issue. I now get the expected output.
2
Answers
Renaming
test.py
totest1.py
solved the issue. I now get the expected output.The culprit is that
TOP_LEVEL_MODULES
from https://python-future.org/_modules/future/standard_library.html imports test. Which happens to collide with your file that takes precedence.