how to import a module if there is one with the same name in python

0

I have two main.py files, parser.py and I want from main.py to import parser.py but it does not matter what parser.py you create, what matters is a parser builtin module. How can I get the file that I create to import without having to change the name? I'm working with python 3.6

    
asked by Antonio Torres Vargas 04.05.2018 в 18:12
source

1 answer

1

You have 2 ways, use __import__() directly or change the name of the file you're using to finish or start with _ so you do not have to alter your code so much.

Example:

parse.py >> parser_.py  || parser1.py

and you only use the prefix " as " to mask the builtin , but I recommend that you replace the calls to the library since it is easier and safer

    
answered by 04.05.2018 в 18:49