
l, v = self.parse_file(self.mpllineEdit.text()) Later on the book uses the above syntax. I still need to do a little experimenting to fully appreciate this. Cheers, Chris 2009/12/9 Chris O'Halloran <cmoman(a)gmail.com>:
Thanks for that useful reply. I'll tinker with the code some more later today.
http://www.packtpub.com/matplotlib-python-development
BTW, the more developed examples later in the book don't use the l, syntax
Cheers,
Chris
2009/12/9 Daniel Lawson <daniel(a)meta.net.nz>:
The line l, = plt.plot(x, y)
has got me slighty confused because
l = plt.plot(x, y)
also works, without the trailing comma after the l
I was wondering if any Python coders might comment to the comma's significance. I've scanned my four books on Python and can't find any reference.
plt.plot() returns an iterable type, and l, = plt.plot(x,y) will store the first result of the iterable return value into l.
It looks like it's returning a list that contains one value though, because if the list contains more than one value then l, = ..... would fail
Not having the , works as well - l will then be a list with one value, rather than the first value of the list.
def list1(): f = list() f.append(1) return f
list1() returns a list with one entry, the integer 1: >>> list1() [1]
you can store this list in a variable foo: >>> foo = list1() >>> foo [1]
Or you can store the first entry in the list in the variable foo by using foo, notation >>> foo, = list1() >>> foo 1
There probably is reasonable difference between the variable l containing a list of whatever plot() returns, and between it having the first value in the list that plot() returns, however in your code snippet, l is not used again after being called, so in practice it doesn't make any difference.
_______________________________________________ wlug mailing list | wlug(a)list.waikato.ac.nz Unsubscribe: http://list.waikato.ac.nz/mailman/listinfo/wlug