Reputation: 763
I checked similar topics but could not find what I am looking for. I simply want to call a py script which includes a sqlite code from another py code and also pass macro variables to it. I simply want to assign a macro variable as run_date and pass the values I gave here to another python code I am calling, however I receive this error :
Traceback (most recent call last):
File "0_Data_Cleaning_Pipeline.py", line 42, in <module>
weekly_transactions['report_end_date'] = run_date
NameError: name 'run_date' is not defined
# CONNECT DATABASE
import pandas as pd
import os
import subprocess
from sqlalchemy import create_engine
import sqlite3
# connection to database
db = sqlite3.connect('gencodb.db')
# cursor
cursor = db.cursor()
# Libraries
# ENTER THE DATA WEEKS
run_date = '22/02/2020'
subprocess.call(" python 0_Data_Cleaning_Pipeline.py", shell=True)
Upvotes: 0
Views: 84
Reputation: 678
You can pass run date as a argument to the program you are calling with subprocess.call
like so
subprocess.call("python 0_Data_Cleaning_Pipeline.py".split() + [run_date], shell=True)
and in 0_Data_Cleaning_Pipeline.py
you can access the passed argument with
import sys
run_date = sys.argv[1]
Upvotes: 1