如何让我的子文件使用主文件中的定义?

我的main.py文件中有这句话:

import pandas as pd

from modules.my_self_defined import *

input='1.csv'
df=just_an_example(input)

在./modules/my_self_defined.py中:

def just_an_example(csv_file):
    a=pd.read_csv(csv_file)
    return a

然后,当我运行文件时,它说pd在./modules/my_self_defined.py中没有定义

我如何使它工作?

JMG987654321 回答:如何让我的子文件使用主文件中的定义?

您在my_self_defined.py中使用了熊猫(pd),而不是在main.py中使用。因此,请改为将其导入my_self_defined.py,它将起作用。

本文链接:https://www.f2er.com/3125260.html

大家都在问