0

I'm trying to define a variable accesible to all my files (modules) in a Python Project. To do so, I defined a file Config.py, in there I tried both

#Config.py  ##1

import pandas as pd
GDF=pd.DataFrame()


#Config.py  ##2

import pandas as pd

def init():
  global GDF
  GDF=pd.DataFrame()

The structure of the program is to have a table, and across several modules get some rows. I tried

#Functions.py 
import Config

def RandomFunct():
   Config.GDF.append([a,b,c,d],ignore_index=True)

#Main.py
import Config

some code
print(Config.GDF)

What I get is an empty DataFrame. I tried all possible alternatives exposed in this thread Using global variables between files? but to no avail.

Can anybody enlighten me on how to do it?

puppet
  • 707
  • 3
  • 16
  • 33

1 Answers1

1

It looks like you are not calling init() in main.py. Also you need to store the changes to DF

try

# Config.py
import pandas as pd

def init():
    global GDF
    GDF=pd.DataFrame()


#Functions.py 
import Config

def RandomFunct():
   Config.GDF = Config.GDF.append([a,b,c,d],ignore_index=True)

# main.py

import settings
import Functions

Config.init()
Functions.RandomFunct()
print(Config.GDF)
Andrew
  • 950
  • 7
  • 24
  • Apparently, what was amiss was that I did `Config.GDF.append()` instead of doing `Config.GDF=Config.GDF.append()`. It is now solved, thank you very much – puppet Jun 08 '18 at 21:35