I have a little beginner issue doing imports between scripts, maybe someone can help?
I wrote 2 Modules:
- B01_Import_CSV_V1.py
In the import script, i did load a .csv and saved it as a pandas dataframe (named "df").
The plot script should process this data.
If I integrate the code of Import-Script in a main function (if __name__=="__main__": ), i learned that this code won´t be executed anymore while import. The plot script won´t work then:
Is there any way to execute scripts separately and then use the variables from each other?
There´s actually no advantage doing it separately YET, but there will be ;)
Thanks for helping! :)

I wrote 2 Modules:
- B01_Import_CSV_V1.py
In the import script, i did load a .csv and saved it as a pandas dataframe (named "df").
#if __name__=="__main__": import pandas as pd global df global df2 #%% load file via static path if True: tester=r'C:\local_calc\Python_DemoFiles\20220219_70788_406_02_C10_275C_Ges.csv' df=pd.read_csv(tester, sep=';',decimal=",", skipfooter=1300, engine='python') print ('FINISHED loading file ' + tester)- plot.py
The plot script should process this data.
#%% Imports import matplotlib.pyplot as plt import B01_Import_CSV_V1 #<- this works #from B01_Import_CSV_V1 import df #<- this does not work #%%% plot fig=plt.figure(figsize=(15,8)) ax=fig.add_subplot(111) ax2=ax.twinx() ax3=ax.twinx() ax.plot( df['70788.1.E602000_W1:6'], c = 'b')My question:
If I integrate the code of Import-Script in a main function (if __name__=="__main__": ), i learned that this code won´t be executed anymore while import. The plot script won´t work then:
Error: File "U:\031_Python\030_eigene_Scripte\D01_Plot_ConditioningData_V1.py", line 17, in <module>
from B01_Import_CSV_V1 import df
ImportError: cannot import name 'df' from 'B01_Import_CSV_V1' (U:\031_Python\030_eigene_Scripte\B01_Import_CSV_V1.py)
-> Does this mean, I always have to execute the csv-Import within the plot script?Is there any way to execute scripts separately and then use the variables from each other?
There´s actually no advantage doing it separately YET, but there will be ;)
Thanks for helping! :)