Can pdb be set to break on warnings?
Hello, I use pdb under Linux to debug my Python code, as in: python -m pdb myprogram.py By default it does a postmortem of unhandled exceptions, is there a way to get it to break on warnings? Thanks a lot, Lorcan. -- http://mail.python.org/mailman/listinfo/python-list
Re: Can pdb be set to break on warnings?
Fredrik Lundh wrote: > LorcanM wrote: > > > I use pdb under Linux to debug my Python code, as in: > > > > python -m pdb myprogram.py > > > > By default it does a postmortem of unhandled exceptions, is there a way > > to get it to break on warnings? > > is > > python -m pdb -Werror myprogram.py > > what you're looking for ? > > It sounds like what I want, but it doesn't work for me. When I try the above line of code, it replies: Error: -Werror does not exist I'm running Python 2.4.3 Thanks for the help, Lorcan. -- http://mail.python.org/mailman/listinfo/python-list
Re: Can pdb be set to break on warnings?
Fredrik Lundh wrote: > "LorcanM" wrote: > > >> python -m pdb -Werror myprogram.py > > > > It sounds like what I want, but it doesn't work for me. When I try the > > above line of code, it replies: > > > > Error: -Werror does not exist > > > > I'm running Python 2.4.3 > > sorry, pilot cut and paste error. try: > > python -Werror -m pdb myprogram.py > > (-m script must be the last option before the script arguments, for pretty > obvious reasons). > > Thanks for that - that does the trick, Lorcan. -- http://mail.python.org/mailman/listinfo/python-list
Re: Can I inherit member variables?
Thanks for the reply. I think there's a basic misunderstanding about the nature of inheritance on my side. What I want to do is instantiate the sub class (derived class) from within the animal class. I then expect the sub class to have inherited some basic properties that it knows it has (weight, colour). If I can expand the example I gave previously to try to make this a little clearer: class animal: def __init__(self, weight, colour): self.weight = weight self.colour = colour def describeMyself(self, type, measurement): if type == 'bird': myanimal = bird(measurement) elif type == 'fish': myanimal = fish(measurement) class bird(animal): def __init__(self, wingspan): self.wingspan = wingspan print "I'm a bird, weight %s, colour %s, wingspan %s" % (self.weight, self.colour, self.wingspan) class fish(animal): def __init__(self, length): self.length = length print "I'm a fish, weight %s, colour %s, length %s" % (self.weight, self.colour, self.length) It seems from what you say that the attributes (member variables) will have to be passed forward explicitly like any other function call. This of course is sensible, 'bird' or 'fish' are not tied to a specific instance of 'animal' when they are instantiated. Thanks for the help, Lorcan. Benjamin Niemann wrote: > You'll have to invoke the __init__ method of the superclass, this is not > done implicitly. And you probably want to add the weight and colour > attributes to your subclass in order to pass these to the animal > constructor. > > class fish(animal): > def __init__(self, length, weight, colour): > animal.__init__(self, weight, colour) > self.length = length > print self.weight, self.colour, self.length > -- http://mail.python.org/mailman/listinfo/python-list
Re: Can I inherit member variables?
Thanks a lot folks for all the help. Its a lot clearer now. If I could summarise my original misunderstanding about inheritance: I belived that a sub class inherited a *specific instance* of the super class. This is clearly not right - the misunderstanding arose as I was instantiating the super class from within the base class. As people have pointed out it seems strange to instantiate an 'animal' and then only later decide that it is a 'fish' or a 'bird'. Obviously my code is an analogy to the problem I'm tackling. What I'm doing is a bit more abstract: I'm instantiating a 'world' (as a super class) and then various 'worldviews' as sub-classes. The 'worldviews' must know about various aspects of the 'world' from which they are instantiated to be able to do what they need to do (as the 'bird' needs to know about 'weight' and 'colour' to be able to describe itself). Passing these aspects forward to the constructor of the sub class is the solution I've implemented and it works and looks sensible. Thanks again to all, Lorcan. -- http://mail.python.org/mailman/listinfo/python-list
Re: Can I inherit member variables?
Thanks Bruno, That is a more natural way to do it. The code looks a lot cleaner now. Lorcan. -- http://mail.python.org/mailman/listinfo/python-list