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

what is attribute method in python

I was learning spark and came across this line

Your SparkSession has an attribute called catalog which lists all the data inside the cluster. This attribute has a few methods for extracting different pieces of information. One of the most useful is the .listTables() method, which returns the names of al the tables in your cluster as a list e.g. spark.catalog.listTables().

My question is how an attribute can have methods in python. I tried to search a lot but could not find anything which could clear my confusion. I do know that class has attributes and methods and how to access them but I am confused that how can attribute(catalog) has methods(listTables()) and the way method is being called like catalog.listTables(). Can someone please share some examples or links. Thank you.

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 :

Everything is an object in python, and can therefore have a method. Here’s an example:

>>> class Test:
...     def __init__(self):
...         self.a = 3
...         self.b = 'abc'
...
>>> t = Test()
>>> t.a.bit_length()
2
>>> t.b.islower()
True

As you can see, both attributes of t have methods.

In the case of the attribute in the question, the object is some custom type that has the methods being described.

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