Jan-10-2023, 04:35 AM
I am not unable to figure out why Python cannot include single quotes on to the value of the variable string. I am trying to add single quote on the beginning and at the end of the of the data variable current_partnum on the line no. 14. This variable's value will then be use to make mysql query2 using this line of code:
[inline]
query2 = "SELECT PartNum, WareHouseCode, BinNum, TranQty FROM trans WHERE PartNum = {}".format(current_partnum)
[/inline]
So my final query should be:
SELECT PartNum, WareHouseCode, BinNum, TranQty FROM trans WHERE PartNum = '10670APRCONX22XXXX'
But instead I am getting this output:
[inline]
query2 = "SELECT PartNum, WareHouseCode, BinNum, TranQty FROM trans WHERE PartNum = {}".format(current_partnum)
[/inline]
So my final query should be:
SELECT PartNum, WareHouseCode, BinNum, TranQty FROM trans WHERE PartNum = '10670APRCONX22XXXX'
But instead I am getting this output:
Output:'ELECT PartNum, WareHouseCode, BinNum, TranQty FROM trans WHERE PartNum = '10670APRCONX22XXXXBelow is my code and its outputfor (var_partNum) in record:
#Start of Debug
print("\nHMS: Debug")
print(var_partNum[0])
print(var_partNum)
#End of Debug
current_partnum = ' '.join(var_partNum)
print("\nWorking on record "+ str(i) + " From " + str(total_records)) #Display active record number to track the progress
print(current_partnum)
#current_partnum = "!!{}!!".format(current_partnum)
print(current_partnum)
current_partnum = "'" + current_partnum + "'"
print(type(current_partnum))
print(current_partnum)
query2 = "SELECT PartNum, WareHouseCode, BinNum, TranQty FROM trans WHERE PartNum = {}".format(current_partnum)
print(query2)
cursor.execute(query2,(current_partnum)) #To get the details for each FG partnum and then process the query result to save into the excel file
record2 = cursor.fetchall()
found_record = cursor.rowcount
#Start of Debug
print("\nfound_record = " + str(found_record))
#End of DebugOutput:Found total records: 846
HMS: Debug
10670APRCONX22XXXX
('10670APRCONX22XXXX\r',)
Working on record 1 From 846
10670APRCONX22XXXX
10670APRCONX22XXXX
<class 'str'>
'10670APRCONX22XXXX
'ELECT PartNum, WareHouseCode, BinNum, TranQty FROM trans WHERE PartNum = '10670APRCONX22XXXXI don't understand why the SELECT statement the character S is replaced with single quotes.
