![](/img/trans.png)
[英]Add current file directory to Python interpreter path in PyCharm
[英]How to add directory or make directory to current path and use file
我想在當前路徑上創建一個目錄並在該路徑中添加一個 excel 文件並在腳本中使用該 excel 文件....請幫助我目前正在做
my_excel_file = Path(sys.argv[2])
if not my_excel_file.is_file():
print ("Excel File not exist")
logging.error("Excel File not exist")
exit(-2)
但我想在當前路徑中添加目錄'/tmp/old excel/n.xlsx'
並使用 n.xlsx 文件
如果不存在,此代碼將創建一個目錄和文件。 您還可以寫入該文件:
import os
filename = "tmp/old excel/n.xlsx"
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))
with open(filename, "w") as f:
f.write("content")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.