Python Forum
What is all the info in the info window in Idle?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is all the info in the info window in Idle?
#2
Python has a rich data-model: https://docs.python.org/3/reference/data...-and-types

Some methods and attributes are created automatically.
For example, you can add the ability of comparison to your class and then all instances are sortable.
But after the creation of the class itself, it gets from object the attributes and methods assigned.
For example, the attribute __name__ holds the name of the class. But you have never created it, it's done automatically.
from functools import total_ordering


# adds additional methods to the class MyFoo
# for comparison
@total_ordering
class MyFoo:
    def __init__(self, value):
        self.value = value

    def __eq__(self, other):
        print("__eq__ called")
        return self.value == other.value

    def __lt__(self, other):
        print("__lt__ called")
        return self.value < other.value

    def __repr__(self):
        return f"MyFoo: {self.value}"

foos = [MyFoo(x) for x in range(10, -1, -1)]

print(foos)
foos.sort()
print(foos)
Output:
[MyFoo: 10, MyFoo: 9, MyFoo: 8, MyFoo: 7, MyFoo: 6, MyFoo: 5, MyFoo: 4, MyFoo: 3, MyFoo: 2, MyFoo: 1, MyFoo: 0] __lt__ called __lt__ called __lt__ called __lt__ called __lt__ called __lt__ called __lt__ called __lt__ called __lt__ called __lt__ called [MyFoo: 0, MyFoo: 1, MyFoo: 2, MyFoo: 3, MyFoo: 4, MyFoo: 5, MyFoo: 6, MyFoo: 7, MyFoo: 8, MyFoo: 9, MyFoo: 10]
There is another way with the use of dataclass.
They implement those required methods with the decorator syntax.
The same as a dataclass.

from dataclasses import dataclass


@dataclass(order=True)
class MyFoo2:
    value: int
Pedroski55 likes this post
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: What is all the info in the info window in Idle? - by DeaD_EyE - Jul-07-2023, 08:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I dont understand on how to create a Bot that can read info on the screen aloud RaySuS777 0 174 Jun-19-2024, 10:02 AM
Last Post: RaySuS777
  Bot that can read info on the screen aloud... RaySuS777 2 300 Jun-18-2024, 05:52 PM
Last Post: RaySuS777
  Input network device connection info from data file edroche3rd 6 1,331 Oct-12-2023, 02:18 AM
Last Post: edroche3rd
  Is there a way to call and focus any popup window outside of the main window app? Valjean 6 2,333 Oct-02-2023, 04:11 PM
Last Post: deanhystad
  Pyspark Window: perform sum over a window with specific conditions Shena76 0 1,327 Jun-13-2022, 08:59 AM
Last Post: Shena76
  [split] Py2exe Writing UNKNOWN-0.0.0-py3.7.egg-info sarahroxon7 1 1,047 Apr-20-2022, 08:02 AM
Last Post: VadimCr
  Taking info from Json & using it in Python Extra 8 2,583 Apr-02-2022, 04:45 PM
Last Post: Extra
  Hiding "undesired" info Extra 4 1,964 Jan-03-2022, 08:25 PM
Last Post: Extra
  Looking for data/info on a perticular data-proccesing problem. MvGulik 9 4,230 May-01-2021, 07:43 AM
Last Post: MvGulik
  IDLE editing window no longer works chris1 2 2,391 Feb-06-2021, 07:59 AM
Last Post: chris1

Forum Jump:

User Panel Messages

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