Olivier Turcotte Olivier Turcotte - 1 year ago 51
Python Question

PYTHON - Error while calling a outter function

This is the code where i created my function

#============= Importations =====================
from datetime import date

#============= Classe ===========================
class Pret :

#----------- Constructeur -----------------------------

def __init__(self,p_date:str,p_duree_max:int,p_nbr_renouv):
#.... Déclaration des données membres ....
self.__date_debut = None # date
self.__duree_max = 0 # int
self.__nbr_renouv = 0 # int
#.... Code ....
self.__date_debut = p_date
self.__duree_max = p_duree_max
self.__nbr_renouv = p_nbr_renouv

#----------- Autres méthodes -------------------------
def calculer_date_retour():
debut_a_auj= debut.toordinal()
return date_retour

The "calculer_date_retour" function should give me a date from "date_debut" and "duree_max" who's are given from this program :

#----------- Importations et fonctions ----------------
from datetime import date
from pret import Pret
#----------- Déclaration des variables ----------------
debut = None
dates = None
duree = 0
nbr_renouv = 0
compte_a = None
#----------- Code -----------
dates = date.today()
duree = 10
nbr_renouv = 2

compte_a=Pret(dates, duree, nbr_renouv)

but when i try the
it give me error like this:

Traceback (most recent call last):
File "Z:Fichier de test.py", line 25, in <module>
TypeError: calculer_date_retour() takes 0 positional arguments but 1 was given

basicly it say that i give an argument to it but i cant figure out where am i giving him one

Answer Source

When calling a function from a class, self is always given as a default argument, this means you need self as a parameter when definining the function

def calculer_date_retour(self):
    debut_a_auj= debut.toordinal()
    return date_retour
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download