'Using Python to run GOOGLEFINANCE() in GoogleSheets: not able to input stock symbol as a string

Using the following python code, I am succesfully able to write and execute the GOOGLEFINANCE() in Google Sheets:

cell_range_insert= 'B2'
values = [['=GOOGLEFINANCE("MSFT", "open", "7/6/2020","10/6/2020" , "WEEKLY")']]
body = {'values': values}

service.spreadsheets().values().update(
    spreadsheetId=spreadsheet_id,
    valueInputOption='USER_ENTERED',
    range=cell_range_insert,
    body=body
).execute()

Next, I tried to assign the stock symbol as a separate variable Ticker="MSFT" and then use it in the GOOGLEFINANCE() function as follows:

values = [['=GOOGLEFINANCE(' +str(Ticker) + ', "open", "7/6/2020","10/6/2020" , "WEEKLY")']]

However, now the spreadsheet does not work and it does not identify string MSFT as "MSFT" (attached photo)

Question: Can you suggest how to input the stock symbol variable (in this case Ticker) to the GOOGLEFINANCE() function so that Google Sheets treat it as a string?

enter image description here



Solution 1:[1]

Change to the code as follows resolved the issue:

values = [['=GOOGLEFINANCE("' + str(Ticker) + '", "open", "7/6/2020","10/6/2020" , "WEEKLY")']]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DaImTo