Python Forum
all of attributes and methods related to a special type
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
all of attributes and methods related to a special type
#1
hi
how can I see all attributes and methods related to a special type? for example, I want to see all methods and attributes related to lists, how can I do it?
I write in idle dir(list) and it shows some, but there is not del in the given list, but del can be used with list type to omit element(s) of it:
dir(list)
Output:
['__add__', '__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
'del' in dir(list)
Output:
False
mylist=[1,2,3,4,5]
del mylist[2]
mylist
Output:
[1, 2, 4, 5]
del mylist[0:2]
mylist
Output:
[4, 5]
thanks
Reply
#2
(Jan-18-2024, 06:48 AM)akbarza Wrote: how can I see all attributes and methods related to a special type? for example, I want to see all methods and attributes related to lists, how can I do it?

For that there is the documentation. However, Python's interactive interpreter has helpful feature as well:

>>> list.   # press two times TAB
list.append(  list.clear(   list.copy(    list.count(   list.extend(  list.index(   list.insert(  list.mro()    list.pop(     list.remove(  list.reverse( list.sort(
>>> help(list.count)
Help on method_descriptor:

count(self, value, /)
    Return number of occurrences of value.

# works on instances as well:
>>> spam = [1, 2]
>>> spam.   # two times TAB
spam.append(   spam.clear()   spam.copy()    spam.count(    spam.extend(   spam.index(    spam.insert(   spam.pop(      spam.remove(   spam.reverse() spam.sort(
akbarza likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
Also the del statement for list items is implemented via the __delitem__() method
« We can solve any problem by introducing an extra level of indirection »
Reply
#4
(Jan-18-2024, 10:59 AM)perfringo Wrote:
(Jan-18-2024, 06:48 AM)akbarza Wrote: how can I see all attributes and methods related to a special type? for example, I want to see all methods and attributes related to lists, how can I do it?

For that there is the documentation. However, Python's interactive interpreter has helpful feature as well:

>>> list.   # press two times TAB
list.append(  list.clear(   list.copy(    list.count(   list.extend(  list.index(   list.insert(  list.mro()    list.pop(     list.remove(  list.reverse( list.sort(
>>> help(list.count)
Help on method_descriptor:

count(self, value, /)
    Return number of occurrences of value.

# works on instances as well:
>>> spam = [1, 2]
>>> spam.   # two times TAB
spam.append(   spam.clear()   spam.copy()    spam.count(    spam.extend(   spam.index(    spam.insert(   spam.pop(      spam.remove(   spam.reverse() spam.sort(

thanks for reply
In IDLE, I typed list. and then pressed the tab key twice, it became list. and popped up a small window that contained all methods related to the list type. I tried several times, but I was not successful. also, I did it for spam ( as you have defined), but again I was not successful. what is the problem?
Reply
#5
(Jan-19-2024, 07:58 AM)akbarza Wrote: In IDLE, I typed list. and then pressed the tab key twice, it became list. and popped up a small window that contained all methods related to the list type. I tried several times, but I was not successful. also, I did it for spam ( as you have defined), but again I was not successful. what is the problem?

In IDLE you should write just list. and dropdown window with methods will appear in 1-2 seconds.
akbarza likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Special Methods in Class Nikhil 3 2,301 Mar-04-2021, 06:25 PM
Last Post: Nikhil
  Special Methods - what are they exactly? bytecrunch 1 1,689 Feb-07-2021, 01:38 AM
Last Post: Larz60+
  Although this is a talib related Q it's mostly related to python module installing.. Evalias123 4 5,705 Jan-10-2021, 11:39 PM
Last Post: Evalias123
  Type hinting - return type based on parameter micseydel 2 2,510 Jan-14-2020, 01:20 AM
Last Post: micseydel
  How to Create Very Very Special Class with too many magic methods ? harun2525 5 4,380 Apr-13-2017, 10:18 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020