I'm working on a project that takes data from excel and enters it into SAP. Everything works quite well until I try to import some variables between files.
output.py:
import openpyxl
import time
from data import *
import subprocess
wb = openpyxl.load_workbook("OutputProject.xlsm")
ws = wb.active
List = wb["List"]
Data = wb["Data"]
count = 0
for row in ws:
if not all([cell.value == None for cell in row]):
count += 1
count = count - 1
print(count)
i = 2
while i < count + 2:
vendornumber = List.cell(i,1).value
countrycode = List.cell(i,2).value
companycode = eval(countrycode + "_cc")
market = eval(countrycode + "_market")
asd = ['python', 'test2.py']
subprocess.Popen(asd).wait()
i = i + 1
time.sleep(1)
print("Done")
test2.py:
import sys
import win32com.client
import time
import subprocess
from output import *
def sap():
try:
path = r"C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe"
subprocess.Popen(path)
time.sleep(10)
SapGuiAuto = win32com.client.GetObject('SAPGUI')
if not type(SapGuiAuto) == win32com.client.CDispatch:
return
application = SapGuiAuto.GetScriptingEngine
if not type(application) == win32com.client.CDispatch:
SapGuiAuto = None
return
connection = application.OpenConnection("ECC Production", True)
if not type(connection) == win32com.client.CDispatch:
application = None
SapGuiAuto = None
return
session = connection.Children(0)
if not type(session) == win32com.client.CDispatch:
connection = None
application = None
SapGuiAuto = None
return
except:
print(sys.exc_info()[0])
print(sys.exc_info()[1])
print(sys.exc_info()[2])
finally:
session = None
connection = None
application = None
SapGuiAuto = None
sap()
Code works perfectly without below line:
from output import *
However I need to import variables defined in output file and this line makes the code loop and doing print(count) over and over again. Can someone explain why is it happening?
Thanks!