python - 类型错误:处理时间()缺少 1 个必需的位置参数:'num_job'
问题描述
我尝试将下面的这些代码转换为脚本:
import pandas as pd
import numpy as np
num_job=10 # number of jobs
pt_tmp=pd.read_excel("JSP_dataset.xlsx",sheet_name="Processing Time",index_col =[0])
pt=[list(map(int, pt_tmp.iloc[i])) for i in range(num_job)]
到 ExcelReadFile.py
import pandas as pd
class ExcelReadFile(object):
def __init__(self,fileName, num_job):
self.fileName = fileName
self.num_job = num_job
def processingTime(self, fileName, num_job):
pt_tmp=pd.read_excel(fileName,sheet_name="Processing Time", index_col =[0])
pt=[list(pt_tmp.iloc[i]) for i in range(num_job)]
return pt
并在 run.py
import pandas as pd
import numpy as np
import time
from src.fjsls.io.ExcelReadFile import ExcelReadFile
num_job=10
fileName = "JSP_dataset.xlsx"
pt = ExcelReadFile.processingTime(fileName, num_job)
表明
`TypeError: processingTime() 缺少 1 个必需的位置参数:'num_job'
当我打电话给processingTime()
你时,你能帮忙检查一下并解释一下在 Python 中创建脚本吗?
解决方案
您正在从一个类中调用一个函数:
你这样称呼它
pt = ExcelReadFile.processingTime(fileName, num_job)
将此行更改为
obj=ExcelReadFile(fileName, num_job)
obj.processingTime(fileName, num_job)# at this line you will get the current
# object value in the self
另外,您的问题缩进是错误的,我对其进行了编辑,如果正确,请检查并接受编辑?那么只有我们才能正确理解它。