Re: [Tutor] calling a method within a function
> I understand... but don't blame me if it hurts your head ;) First a few comments. Theres an awful lot of superfluous "stuff" in there that would make it much easier to read and work with. The docstring does not appear to be accurate and there are about 30 lines of commented code. Do you use a version control, system? That would avoid the need for all of that commenting. Even so the function is very long and could be easily broken into smaller, more maintainable chunks that would help you diagnose and manage problems more effectively. In the class you assifn self to D in init? If its just to avoid some typing you could just use D instead of self in the parameter list. The use of self is just a convention. However, for the sake of 3 characters I personally think its a convention worth following... However, to your problem,... > > The class is here: > http://python.pastebin.com/gPpep50Y > > The function is here: > http://python.pastebin.com/faK0vZ8U > > The issue is with the 'reflectance' method of the FlightData class > (line 76). You can see in the class definition I now just add > reflectance to self, but before I was trying to return it, and in the > function (line 38-40) I was calling the method to get the array. The reflectance method does not return anything, it will set your value to None. HTH, Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] calling a method within a function
I understand... but don't blame me if it hurts your head ;) The class is here: http://python.pastebin.com/gPpep50Y The function is here: http://python.pastebin.com/faK0vZ8U The issue is with the 'reflectance' method of the FlightData class (line 76). You can see in the class definition I now just add reflectance to self, but before I was trying to return it, and in the function (line 38-40) I was calling the method to get the array. On Ipython it worked fine to call the method and get a refl array. The array worked as expected (ie. refl.max(), refl.min() returned floats). But when I passed the same FlightData object to the function and called it inside it would not work. It would still return a numpy.ma.core.MaskedArray, but the max and min methods on the array returned empty values, which caused my function to crash. On Wed, Dec 8, 2010 at 2:18 AM, Alan Gauld wrote: > > "John" wrote > >> I have a strange problem with a piece of code I've written. It's a bit >> overly complicated to make an example with, but the gist is below. But >> in the example below, it works. However, in my example, when I call >> the method from within the function, it returns something other than >> what I expect. > > Care to give us a clue? > > What did you expect? > What did you get? > What does the real code look like? > > Its a bit hard to diagnose your problem based on a bit of code that > works and a loose description of your dissapointment with another > bit of code that may or may not work - depending on what you > expected! > > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Configuration `` Plone 2.5.3-final, CMF-1.6.4, Zope (Zope 2.9.7-final, python 2.4.4, linux2), Python 2.6 PIL 1.1.6 Mailman 2.1.9 Postfix 2.4.5 Procmail v3.22 2001/09/10 Basemap: 1.0 Matplotlib: 1.0.0 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] calling a method within a function
"John" wrote I have a strange problem with a piece of code I've written. It's a bit overly complicated to make an example with, but the gist is below. But in the example below, it works. However, in my example, when I call the method from within the function, it returns something other than what I expect. Care to give us a clue? What did you expect? What did you get? What does the real code look like? Its a bit hard to diagnose your problem based on a bit of code that works and a loose description of your dissapointment with another bit of code that may or may not work - depending on what you expected! -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] calling a method within a function
On 07/12/10 22:36, John wrote: Hello, I have a strange problem with a piece of code I've written. It's a bit overly complicated to make an example with, but the gist is below. But in the example below, it works. However, in my example, when I call the method from within the function, it returns something other than what I expect. If I call the method outside the function, it behaves properly??? It's hard to tell, from an example that doesn't display the same behaviour, what the problem is but it sounds like there must be some problem with the way you're calling the method from your function that isn't happening otherwise. Can you post the full source somewhere and mail a link to the mailing list? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] calling a method within a function
Hello, I have a strange problem with a piece of code I've written. It's a bit overly complicated to make an example with, but the gist is below. But in the example below, it works. However, in my example, when I call the method from within the function, it returns something other than what I expect. If I call the method outside the function, it behaves properly??? class DataHolder(): def __init__(self): self.x = np.arange(100) def f(self,wl): f = np.sin(self.x) ** wl return f def function(DH,wl=20): f = DH.f(wl) plt.plot(DH.x,f) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor