Re: [Tutor] python / gtk / Webkit app wrapper.

2013-06-28 Thread Alan Gauld
On 28/06/13 02:13, Darin Lawson Hosking wrote: Alan - This is my first python program (actually first anything, besides simple one line shell scripts) and if I broke protocol I do apologize. Its not a matter of breaking protocol, just posting where you get the highest chance of getting a good

Re: [Tutor] multiple function returns

2013-06-28 Thread Alan Gauld
On 28/06/13 05:18, Jim Mooney wrote: What's the Pythonic standard on multiple returns from a function? There is no standard. Multiple returns are quite common but they come with all the usual caveats for using them, they can introduce complexity and hard to find bugs so use them sensibly. Co

Re: [Tutor] unwanted 'zero' ending

2013-06-28 Thread Alan Gauld
On 28/06/13 02:32, Jim Mooney wrote: Hmm, so it seems a lot of trouble for a few hardcoded tests I could run myself from the IDE interpreter window. The point is that you should write the doc strings before you write the code. Then anyone can test that your function does at least work for the

Re: [Tutor] unwanted 'zero' ending

2013-06-28 Thread Steven D'Aprano
On 28/06/13 17:31, Peter Otten wrote: Whatever approach you pick, unittest, doctest, or a combination, your code will improve -- not just because you are verifying its correctness to some extent, but also because the inherent question "How can I test it?" will lead to a better overall structure.

Re: [Tutor] multiple function returns

2013-06-28 Thread Steven D'Aprano
On 28/06/13 14:18, Jim Mooney wrote: What's the Pythonic standard on multiple returns from a function? It seems easiest to just return from the point where the function fails or succeeds, even it that's multiple points. Or is it considered best to defer everything to one return at the end? The

Re: [Tutor] Need help appending data to a logfile

2013-06-28 Thread Dave Angel
On 06/28/2013 07:27 AM, Matt D wrote: As for the shutil.copy() function, how complex can it be? It takes two file names, source and destination. It does not need a with statement since it wants strings, not file handles. You might get into trouble on some OS's with the source file already o

Re: [Tutor] Need help appending data to a logfile

2013-06-28 Thread Steven D'Aprano
On 28/06/13 23:18, Matt D wrote: what if i did some thing like this i saw on stackoverflow: f = open("bigfile.txt", "w") That clears any existing content of bigfile.txt, and opens it for writing. Do you intend to clear the content? for tempfile in tempfiles: What is in tempfiles? A list

Re: [Tutor] multiple function returns

2013-06-28 Thread Dave Angel
On 06/28/2013 12:06 PM, Jim Mooney wrote: def foo(x): ... if x: ... return True ... return False I'll leave it to you to work out why that works. It's very handy! Hey, it saves typing an "else" and as you know, I'm the Lazy Typist. My program to make dicts, lists, etc from a

Re: [Tutor] multiple function returns

2013-06-28 Thread Alan Gauld
On 28/06/13 19:51, Jim Mooney wrote: Now you'll make me learn what lambda is. Ah, it's like an anonymous function in jQuery, That's the idea but Python lambdas are a bit crippled so its really an anonymous expression... :-( But if you know JQuery then lambdas should be easy to pick up. And t

Re: [Tutor] Need help appending data to a logfile

2013-06-28 Thread Alan Gauld
On 28/06/13 20:54, Matt D wrote: def openFile(self, evt): with wx.FileDialog(self, "Choose a file", os.getcwd(), "", "*.txt*", wx.SAVE) as dlg: if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() mypath = os.path.basename(path)

Re: [Tutor] Need help appending data to a logfile

2013-06-28 Thread Alan Gauld
On 28/06/13 22:25, Matt D wrote: Python UI. I have a thread that waits on new data and when it comes in it gets displayed in TextCtrl fields. every time this happens my logger puts those values into a text file one row at a time. this how i open and the file for logging data: # open a f

Re: [Tutor] Need help appending data to a logfile

2013-06-28 Thread Dave Angel
On 06/28/2013 08:04 PM, Alan Gauld wrote: On 28/06/13 22:25, Matt D wrote: Python UI. I have a thread that waits on new data and when it comes in it gets displayed in TextCtrl fields. every time this happens my logger puts those values into a text file one row at a time. this how i open and