Python 脚本...我需要从命令提示符中输入 API 键进入 Main.py
Python script... I need to take API Key from the command prompt into Main.py
需要帮助从命令提示符中获取 API 键并将其插入 excel sheet 的特定单元格中。我打算将它添加到 Main.py。但不确定脚本中的位置。
API_key = input("What is the API key? \n")
然后我打算使用 Openpyxl 将其添加到 excel sheet 上的单元格中。但是我在哪里添加这段代码呢?在 Main.py 脚本中?直接取自 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")
您描述中的代码有效。
你可以这样做:
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")
需要帮助从命令提示符中获取 API 键并将其插入 excel sheet 的特定单元格中。我打算将它添加到 Main.py。但不确定脚本中的位置。
API_key = input("What is the API key? \n")
然后我打算使用 Openpyxl 将其添加到 excel sheet 上的单元格中。但是我在哪里添加这段代码呢?在 Main.py 脚本中?直接取自 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")
您描述中的代码有效。 你可以这样做:
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")