Olá pessoal. Estou transcrevendo as aulas de Python Collections no PyCharm.
Meu código está assim:
from operator import attrgetter
from functools import total_ordering
@total_ordering
class ContaSalario:
def __init__(self, codigo):
self._codigo = codigo
self._saldo = 0
def passaMes(self):
pass
def __eq__(self, other):
if type(self) != ContaSalario:
return False
return (self._codigo == outro.codigo and self._saldo == outro._saldo)
def deposita(self, valor):
self._saldo += valor
def __str__(self):
return (f'Conta = {self._codigo}, Saldo = {self._saldo}')
def __lt__(self, other):
if self._saldo < other._saldo:
return self._saldo < other._saldo
else:
return self._codigo < other._codigo
Mas estou recebendo erro ao tentar importar o total_ordering:
/Users/rafaelviegas/PycharmProjects/Collections/venv/bin/python /Users/rafaelviegas/PycharmProjects/Collections/collections.py
Traceback (most recent call last):
File "/Users/rafaelviegas/PycharmProjects/Collections/collections.py", line 2, in <module>
from functools import total_ordering
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/functools.py", line 18, in <module>
from collections import namedtuple
File "/Users/rafaelviegas/PycharmProjects/Collections/collections.py", line 2, in <module>
from functools import total_ordering
ImportError: cannot import name 'total_ordering' from partially initialized module 'functools' (most likely due to a circular import) (/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/functools.py)
Podem me ajudar? Não consegui encontrar solução no StackOverflow ou no google.