In java, one can import a class statically by calling import static com.Abc
, for example. And then instead having to call Abc.doSomething()
you can just call doSomething()
. Is there an equivalent of this in Python, and if so, what is it?
You can just import the function directly. Consider the timedelta
function in Python's datetime
package. If I want to just import the function I use:
from datetime import timedelta
Then I can use the function on its own.
Also, I can rename packages to simplify things. For instance, it is a common convention to import matplotlib.pyplot
as plt
, pandas
as pd
, and seaborn
as sns
:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns