Reputation: 61
Here is my Function.........
from instrument import Instrument
import pandas as pd
def getpairsData():
global pairlist <<============= Defined Global variable
pairlist = Instrument.get_pairs_from_list() <<=============Call
return pairlist <<============= Available Global variable
"""It is being called by this loop....... #This loop will iterate over pairlist, and will pass one pair to get data, and save that data as file."""
for pair in pairlist: <<======= My Global variable above????
getData()
for i in range(0,11):
df1= pd.read_csv("./data/"+ str(files[i])+".csv")
print (df1.head())
import pandas as pd
import Utils
class Instrument():
def __init__(self,ob):
self.name=ob['name']
self.type=ob['type']
self.displayName = ob['displayName']
self.pipLocation = pow(10,ob['pipLocation']) # ex. - --> 0.0001
self.marginRate = ob['marginRate']
@classmethod
def get_pairs_from_list(cls): <<============= Receive Call 1
i_list = cls.get_instruments_list()
i_keys = [x.name for x in i_list]
df = pd.DataFrame(i_keys)
df = df.rename(columns={0: "Names"})
df['Names'] = df['Names'].str.replace("_", '')
print("You are here")
pairlist = df["Names"].tolist() # if it is being changed to a list with no keys
return pairlist <<============= Return Call 1
"""I am thinking the pairlist would return to the original function that is set as a Global variable and off to the races we go, but I am stuck on the print("You are here") not responding at all.
NameError: name 'pairlist' is not defined"""
Upvotes: 0
Views: 70
Reputation: 4510
As I don't have the full view of your implementation but I think your code should be something like below snippet:
from instrument import Instrument
import pandas as pd
def getpairsData():
global pairlist
pairlist = Instrument.get_pairs_from_list() # <<=============Call
return pairlist # <<============= Available Global variable
pairlist = getpairsData()
for pair in pairlist: # <<======= My Global variable above????
for i in range(0,11):
df1= pd.read_csv("./data/"+ str(files[i])+".csv")
print (df1.head())
import pandas as pd
import Utils
class Instrument():
def __init__(self,ob):
self.name=ob['name']
self.type=ob['type']
self.displayName = ob['displayName']
self.pipLocation = pow(10,ob['pipLocation']) # ex. - --> 0.0001
self.marginRate = ob['marginRate']
@classmethod
def get_pairs_from_list(cls): # <<============= Receive Call 1
i_list = cls.get_instruments_list()
i_keys = [x.name for x in i_list]
df = pd.DataFrame(i_keys)
df = df.rename(columns={0: "Names"})
df['Names'] = df['Names'].str.replace("_", '')
print("You are here")
pairlist = df["Names"].tolist() # if it is being changed to a list with no keys
return pairlist # <<============= Return Call 1
Upvotes: 2
Reputation: 61
"""I have found that @tdelaney explanation was correct. I never called
the variable because it was derived and then needed to be returned."""
@classmethod
def get_pairs_from_list(cls): <<============= Receive Call 1
i_list = cls.get_instruments_list()
i_keys = [x.name for x in i_list]
df = pd.DataFrame(i_keys)
df = df.rename(columns={0: "Names"})
df['Names'] = df['Names'].str.replace("_", '')
print("You are here")
pairlist = df["Names"].tolist() # if it is being changed to a list
with no keys
`return getpairsData(pairlist)` <<=========== Return Call with
Variable
Upvotes: 1