简体   繁体   English

Python 脚本...我需要从命令提示符获取 API 密钥到 Main.py

[英]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.需要帮助从命令提示符获取 API 密钥并将其插入 Excel 工作表的特定单元格。 I plan to add it into Main.py.我打算将它添加到 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.然后我打算使用 Openpyxl 将其添加到 Excel 工作表上的单元格中。 But where do I add this code?但是我在哪里添加这段代码? In the Main.py script?在 Main.py 脚本中? Taken directly from the Openpyxl docs:直接取自 Openpyxl 文档:

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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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