1

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.

1
  • 1
    The attribute contains an instance of a class, and that class has methods. Commented Jun 25, 2022 at 14:07

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.