(Don't top-post. Either put your remarks immediately after the part
they reference, or at the end of the message. Otherwise, everything's
thoroughly out of order.)
Marco Rompré wrote:
I tried to enter model = Modele (nom_fichier) but it still does not work.
You didn't define the global nom_fichier till after that line. In
general, while you're learning, please avoid using the same names for
global values, class attributes, instance attributes, function parameter
names, and local variables. The rules for what a name means changes
depending on where the name is used.
<snip>
On Fri, Apr 23, 2010 at 11:22 PM, Steven D'Aprano <st...@pearwood.info>wrote:
On Sat, 24 Apr 2010 01:07:11 pm Marco Rompré wrote:
Here's my code:
[...]
class Modele:
"""
La definition d'un modele avec les magasins.
"""
def __init__(self, nom_fichier, magasins =[]):
self.nom_fichier = nom_fichier
self.magasins = magasins
[...]
if __name__ == '__main__':
modele = Modele()
This is where you got the error, because there's a required argument,
for parameter nom_fichier. So you could use
modele = Modele("thefile.txt")
nom_fichier = "magasinmodele.txt"
I'd call this something else, like g_nom_fichier. While you're
learning, you don't want to get confused between the multiple names that
look the same.
modele.charger(nom_fichier)
if modele.vide():
modele.initialiser(nom_fichier)
modele.afficher()
And here's my error :
Traceback (most recent call last):
File "F:\School\University\Session 4\Programmation
SIO\magasingolfmodele.py", line 187, in <module>
modele = Modele()
TypeError: __init__() takes at least 2 arguments (1 given)
You define Modele to require a nom_fichier argument, but then you try to
call it with no nom_fuchier.
<snip>
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor