Houshou
Houshou

Reputation: 13

How to let my subfile use my definition in main file?

I have this sentence in my main.py file:

import pandas as pd

from modules.my_self_defined import *

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

in ./modules/my_self_defined.py:

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

Then when I run the file, it says pd is not defined in ./modules/my_self_defined.py

How could I make it work?

Upvotes: 1

Views: 73

Answers (1)

Yevhen Kuzmovych
Yevhen Kuzmovych

Reputation: 12140

You use pandas (pd) in my_self_defined.py, not in main.py. So import it in my_self_defined.py instead and it'll work.

Upvotes: 1

Related Questions