I have tried to organize my Python (Python version 3.9.2) project better and have created following file structure (I am using VS Code on Macbook Air M2). When I try to call a function in the "function file structure" I get the following error message:
NameError: name 'getAssetHoldings' is not defined
# File structure:
# main.py
my_functions
_init_.py
stock_functions.py
utility_functions.py
# Content of files:
#main.py:
import my_functions
import pandas as pd
import seaborn as sns
# load transaction file
filepath_transact = os.path.abspath(f"/Users/Sandbox/Data/transactions.csv")
df_sq = pd.read_csv(filepath_transact,encoding = "ISO-8859-1",sep=';')
# get asset holdings (function resides in stock_functions.py)
df_assets = getAssetHoldings(df_sq)
print('Assets:', '\n',df_assets,'\n')
#_init.py:
from .stock_functions import *
from .utility_functions import *
print('hello')
#stock_functions.py:
import pandas as pd
import yfinance as yf
import pandas_market_calendars as mcal
def getAssetHoldings(df):
df_numberAssets_k = df_transactions[df_transactions['Transaktionen'].isin(['Buy'])]
df_numberAssets_k = df_numberAssets_k[['Symbol','Quantity']]
df_numberAssets_v = df_transactions[df_transactions['Transaktionen'].isin(['Sell'])]
df_numberAssets_v = df_numberAssets_k[['Symbol','Quantity']]
....
return df_current_assets
I tried to restart the kernel and import the libraries and functions several times.