0

Sorry, Im new to Python and have a basic q

I have 2 python files

FileA.py

Class ABC:
        def __init__(self, loggingLevel = 20):
            self.data = None
            logging.basicConfig(level=loggingLevel)
            pass


        def asd(self, text)
            *
            *
if __name__ == '__main__':
        X=ABC(10)
        Y=X.asd(text)

I have another file FileB.py from where i want to call function asd. I have the parameter 'text' to pass, but what should i pass for parameter 'self'. tried many options , but when it goes to File A, its failing as the value of self is not correct

sigmoid
  • 63
  • 1
  • 2
  • 7
  • Create an instance of the class ABC and call the function using "instance.functionname()" here the instance itself will be passed as self. No need to explicitly pass the self as Param. – Kajal Jun 03 '17 at 04:14
  • the answer is nothing. the self is internal for that class – mugabits Jun 03 '17 at 04:15
  • Self is self referencing object, before deep diving into python I would reckon to read this, can explain you what exactly self does. https://stackoverflow.com/questions/2709821/what-is-the-purpose-of-self – jdk2588 Jun 03 '17 at 04:17

1 Answers1

0

self is implicitly passed if you have a reference to an instance of the containing class. In other words, you can do the same thing that you did in main in the FileB.py:

FileB.py

from FileA import ABC

X = ABC(10)
Y = X.asd(text)
Sumner Evans
  • 8,951
  • 5
  • 30
  • 47
  • Thanks Sumner, its going into function asd, but after that there is s line in asd which says self.data[column] = self.data[column].str.replace(r'[\n\r\t]+', ' ') , where it is throwing error " TypeError: 'NoneType' object is not subscriptable" – sigmoid Jun 03 '17 at 04:29
  • 1
    The code you show sets `self.data` to `None` - you need to set it to some sort of subscriptable value for the line to show above to work. – cco Jun 03 '17 at 04:34
  • Also when FileA is run, its working fine. I set self.Data=[] in File A. When im calling from File B, its staying index should be integer and not str. – sigmoid Jun 03 '17 at 05:28