Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python class method invocation missing 1 required positional argument

I created class method to easen file reading. But the end result gives me error of file_read=Read_file.file_reading_through_class('./ConfigurationFile/configFile.csv') TypeError: Read_file.file_reading_through_class() missing 1 required positional argument: 'fileName'

the code is below;

import pandas as pd
import sys,os, time,re


class Read_file():
    def file_reading_through_class(self,fileName):
        if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
            path_actual = os.getcwd()
            path_main_folder = path_actual[:-4]
            path_result = path_main_folder + fileName
            print('frozen path', os.path.normpath(path_result))
            file_to_read = pd.read_json(path_result)
            return file_to_read
        else:
            file_to_read = pd.read_json(fileName)
            return file_to_read

file_read=Read_file.file_reading_through_class('./ConfigurationFile/configFile.csv')

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You will need to instantiate the class first.
self refers to the instance of the class.

rf = Read_file()
file_read = rf.file_reading_through_class('./ConfigurationFile/configFile.csv')

Or you can mark your function as a static method, and you can use your function the way you are using it.

@staticmethod
def file_reading_through_class(fileName):
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading