0

I try to convert these code below to script:

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

to 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

and in 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)

it shows

`TypeError: processingTime() missing 1 required positional argument: 'num_job'

when i call processingTime() Could you please help to check and a little explanation about script creation in Python?

Joe
  • 12,057
  • 5
  • 39
  • 55
Khái Duy
  • 59
  • 12

3 Answers3

1

You're invoking the method on the class, but it's an instance method. Make the method static and then it should work, like this:

@staticmethod
def processingTime(fileName, num_job):  # Note that the "self" param is removed
    ...
kristaps
  • 1,705
  • 11
  • 15
1

The reason to this error is you have not create instance of the class .

Do this

import pandas as pd
import numpy as np
import time

from src.fjsls.io.ExcelReadFile import ExcelReadFile
num_job=10
fileName = "JSP_dataset.xlsx"
e = ExcelReadFile(fileName, num_job)
pt = e.processingTime(fileName, num_job)

OR if you want to use this method directly use static method . This method are directly called by class name.

How that is use you can see this link

Static methods in Python?

Himanshu sharma
  • 7,487
  • 4
  • 42
  • 75
1

you are calling a function from a class:

you are calling it like

pt = ExcelReadFile.processingTime(fileName, num_job)

change this line to

obj=ExcelReadFile(fileName, num_job)
obj.processingTime(fileName, num_job)# at this line you will get the current
                                     # object value in the self

also, your question indentation is mistaken I edit it, please check it and accept the edit if that's right? then only we can understand it correctly.

abhi krishnan
  • 821
  • 6
  • 20