Python Forum
Why does pycharm return nothing when Python interpreter does?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why does pycharm return nothing when Python interpreter does?
#1
I'm trying to make a class that makes dictionaries which have index system just like lists. The problem comes with __repr__, for some reason it returns nothing in PyCharm but it does in the Python interpreter.

Here is the code:
class DictionnaireOrdonne:
    """Classe permettant de créer un dictionnaire ordonné comme une liste, avec des indices"""

    liste_clefs = []
    liste_valeurs = []

    def __init__(self, **clefs_valeurs):
        """classe prennent un nombre indéfinit de paramètres nommées"""

        self.clefs_valeurs = clefs_valeurs
        self._dictionnaire = {}

    def __repr__(self):
        """Cette méthode est appelée quand on appelle l'objet"""

        return str(self.clefs_valeurs)

    def __getitem__(self, key):
        """Cette méthode spéciale est appelée quand on fait objet[index]
                Elle redirige vers self._dictionnaire[index]"""

        return self._dictionnaire[key]

    def __setitem__(self, key, value):
        """Cette méthode est appelée quand on écrit objet[index] = valeur
                On redirige vers self._dictionnaire[index] = valeur"""

        self._dictionnaire[key] = value


test = DictionnaireOrdonne(one=1, two=2)
test
When I run it in PyCharm it returns:
Output:
Process finished with exit code 0
But in the Python interpreter I get:
Output:
{'one' : 1, 'two' : 2}
Someone please explain me why this is happening and how can I make it so that I get the same result from Python interpreter in PyCharm with only calling my object (test).
Reply


Messages In This Thread
Why does pycharm return nothing when Python interpreter does? - by Jessy - Nov-13-2019, 04:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  filtering python code the interpreter reads Skaperen 0 1,204 Feb-02-2022, 08:29 PM
Last Post: Skaperen
  Improved Python support in SonarLint (PyCharm! Eclipse!) ganncamp 0 2,528 Apr-29-2020, 06:25 PM
Last Post: ganncamp
  VS-Code or PyCharm Vs IDLE For Python Coding adt 14 10,463 Sep-01-2019, 05:17 AM
Last Post: adt
  Notepad++ with Python interpreter Truman 14 11,383 Feb-27-2019, 11:54 PM
Last Post: Truman
  clearing an interactive python interpreter/shell rootVIII 4 3,785 Jan-28-2019, 05:14 PM
Last Post: rootVIII
  Learn PyCharm and Python 3.6 Aug 2 15:00-16:00 GMT Larz60+ 0 2,759 Aug-01-2017, 07:51 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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