lundi 26 juillet 2021

Conditional import a module in python with if-statement

I have a code in production that requires to read certain modules if a parameter is given 1 and should not read certain modules if a parameter is zero. Here is a simple example:

if parameter==0: 
   import numpy as np 

if parameter ==1:
   import pandas as pd

Is there anyway to achieve this in python? I cannot import both modules at the same time.

Aucun commentaire:

Enregistrer un commentaire