2021年4月7日星期三

Python: Importing basic packages inside packages

I made a package that needs to import other packages like pandas and numpy. Here is the basic dir structure:

main.py    my_pkg/      __init__.py      test.py      

test.py contains something like this (I do not import anything)

def function():      foo=pd.read_csv(....)  

I tried doing this in main.py:

import pandas as pd  import numpy as np  from my_pkg import test    test.function()  

But I get this error:

NameError: name 'pd' is not defined  

How do I import pandas and numpy so that test.function() is able to use them?

https://stackoverflow.com/questions/66996396/python-importing-basic-packages-inside-packages April 08, 2021 at 10:05AM

没有评论:

发表评论