簡體   English   中英

在python中創建一個主函數並傳遞參數

[英]create a main function in python and passing arguments

我是 Python 新手,我用 jupyter notebook 用 Python 完成了我的第一個程序。 在這里,我的導師對我說,我必須將其轉換為帶有傳遞參數的腳本 .py。 我嘗試按字節執行此字節。

你能幫我如何開始腳本並將 New1 和 New 作為參數傳遞嗎?

df_equipment = pd.read_csv('C:/Users/Demonstrator/Downloads/New1.csv',delimiter=';', parse_dates=[0], infer_datetime_format = True)
df_energy2=pd.read_csv('C:/Users/Demonstrator/Downloads/New2.csv', delimiter=';', parse_dates=[0], infer_datetime_format = True)

謝謝

試試這個教程來使用 sys.argv 當您准備好對參數解析更加健壯時,請查看此argparse 教程

這是Pythion 教程中的一個示例

def printme( str ):
   "This prints a passed string into this function"
   print str
   return;

# Now you can call printme function
printme("I'm first call to user defined function!")
printme("Again second call to the same function")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM