简体   繁体   中英

Python script... I need to take API Key from the command prompt into Main.py

Need help to take an API key from the command prompt and insert it into a particular cell of an excel sheet. I plan to add it into Main.py. but not sure where in the script.

 API_key = input("What is the API key? \n")

Then I plan to use Openpyxl to add this into the cell on the excel sheet. But where do I add this code? In the Main.py script? Taken directly from the Openpyxl docs:

from openpyxl import Workbook
wb = Workbook()

# grab the active worksheet
ws = wb.active

# Data can be assigned directly to cells
ws['A1'] = API_key

# Save the file
wb.save("sample.xlsx")

The code in your description works. You can do it like this:

from openpyxl import Workbook
book = Workbook()
sheet = book.active
API_key = input("What is the API key? \n")
sheet['A1'] = API_key
book.save("sample.xlsx")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM