Home > OS >  I Have 4-5 py file all of which uses same import libraries and Login using selenium python, Is their
I Have 4-5 py file all of which uses same import libraries and Login using selenium python, Is their

Time:01-14

Consider 3 file, a.py, b.py, c.py

a.py file

import time

import selenium

Login()

xyz


b.py file

import time

import selenium

Login()

abc,


c.py file

import time

import selenium

Login()

efg


what is the better way of managing the above file so that it should not repeat import statement and function.

CodePudding user response:

You can do like this:

# a.py
import time
import selenium

# b.py
from a import time, selenium #You can do like this...

# c.py
from b import * #...or like this

Anyway both the way of doing this are not recommended, you should better import al the needed modules at the beginning of your single files.

  •  Tags:  
  • Related