Re: [Tutor] A further question about opening and closing files

2015-09-09 Thread Alan Gauld
On 09/09/15 20:42, Laura Creighton wrote: In a message of Wed, 09 Sep 2015 20:25:06 +0100, Alan Gauld writes: On 09/09/15 19:20, Laura Creighton wrote: If you are working on a small platform - think mobile device - and it has a single channel bus to the storage area then one of the worst things

Re: [Tutor] A further question about opening and closing files

2015-09-09 Thread Laura Creighton
In a message of Wed, 09 Sep 2015 20:25:06 +0100, Alan Gauld writes: >On 09/09/15 19:20, Laura Creighton wrote: >If you are working on a small platform - think mobile device - and it has >a single channel bus to the storage area then one of the worst things >you can do is write lots of small chunks

Re: [Tutor] A further question about opening and closing files

2015-09-09 Thread Alan Gauld
On 09/09/15 19:20, Laura Creighton wrote: In a message of Wed, 09 Sep 2015 17:42:05 +0100, Alan Gauld writes: You can force the writes (I see Laura has shown how) but mostly you should just let the OS do it's thing. Otherwise you risk cluttering up the IO bus and preventing other programs from w

Re: [Tutor] iterating through a directory

2015-09-09 Thread Mark Lawrence
On 09/09/2015 14:32, richard kappler wrote: Yes, many questions today. I'm working on a data feed script that feeds 'events' into our test environment. In production, we monitor a camera that captures an image as product passes by, gathers information such as barcodes and package ID from the imag

Re: [Tutor] More Pythonic?

2015-09-09 Thread Peter Otten
Timo wrote: > Op 09-09-15 om 15:41 schreef Steven D'Aprano: >> On Wed, Sep 09, 2015 at 09:05:23AM -0400, richard kappler wrote: >>> Would either or both of these work, if both, which is the better or more >>> Pythonic way to do it, and why? >> The first works, but isn't really the best way to do i

Re: [Tutor] A further question about opening and closing files

2015-09-09 Thread Steven D'Aprano
On Wed, Sep 09, 2015 at 08:20:44PM +0200, Laura Creighton wrote: > In a message of Wed, 09 Sep 2015 17:42:05 +0100, Alan Gauld writes: > >You can force the writes (I see Laura has shown how) but > >mostly you should just let the OS do it's thing. Otherwise > >you risk cluttering up the IO bus and p

Re: [Tutor] A further question about opening and closing files

2015-09-09 Thread Steven D'Aprano
On Wed, Sep 09, 2015 at 10:24:57AM -0400, richard kappler wrote: > Under a different subject line (More Pythonic?) Steven D'Aprano commented: > > > And this will repeatedly open the file, append one line, then close it > > again. Almost certainly not what you want -- it's wasteful and > > potentia

Re: [Tutor] More Pythonic?

2015-09-09 Thread Timo
Op 09-09-15 om 15:41 schreef Steven D'Aprano: On Wed, Sep 09, 2015 at 09:05:23AM -0400, richard kappler wrote: Would either or both of these work, if both, which is the better or more Pythonic way to do it, and why? The first works, but isn't really the best way to do it: ##

Re: [Tutor] A further question about opening and closing files

2015-09-09 Thread Laura Creighton
In a message of Wed, 09 Sep 2015 17:42:05 +0100, Alan Gauld writes: >You can force the writes (I see Laura has shown how) but >mostly you should just let the OS do it's thing. Otherwise >you risk cluttering up the IO bus and preventing other >programs from writing their files. Is this something we

Re: [Tutor] Creating lists with definite (n) items without repetitions

2015-09-09 Thread Francesco Loffredo via Tutor
On 09/09/2015 18:59, Oscar Benjamin wrote: On 9 September 2015 at 12:05, Francesco Loffredo via Tutor wrote: A quick solution is to add one "dummy" letter to the pool of the OP's golfers. I used "!" as the dummy one. This way, you end up with 101 triples, 11 of which contain the dummy player. B

Re: [Tutor] Creating lists with definite (n) items without repetitions

2015-09-09 Thread Oscar Benjamin
On 9 September 2015 at 12:05, Francesco Loffredo via Tutor wrote: > Oscar Benjamin wrote: > > The problem is that there are 26 people and they are divided into > groups of 3 each day. We would like to know if it is possible to > arrange it so that each player plays each other player ex

Re: [Tutor] A further question about opening and closing files

2015-09-09 Thread Alan Gauld
On 09/09/15 15:24, richard kappler wrote: f1 = open("output/test.log", 'a') f1.write("this is a test") f1.write("this is a test") f1.write('why isn\'t this writing') f1.close() monitoring test.log as I went. Nothing was written to the file until I closed it, or at least that's the way it a

Re: [Tutor] iterating through a directory

2015-09-09 Thread Alan Gauld
On 09/09/15 15:29, richard kappler wrote: Still not sure how to efficiently get the script to keep moving to the next file in the directory though, in other words, for each iteration in the loop, I want it to fetch, rename and send/save the next image in line. Hope that brings better understandi

Re: [Tutor] A further question about opening and closing files

2015-09-09 Thread richard kappler
Thanks, tried them both, both work great on Linux. Now I understand better. regards, Richard On Wed, Sep 9, 2015 at 11:28 AM, Laura Creighton wrote: > >I did a little experiment: > > > f1 = open("output/test.log", 'a') > f1.write("this is a test") > f1.write("this is a test") > >

Re: [Tutor] A further question about opening and closing files

2015-09-09 Thread Laura Creighton
>I did a little experiment: > f1 = open("output/test.log", 'a') f1.write("this is a test") f1.write("this is a test") f1.write('why isn\'t this writing') f1.close() If you want the thing written out, use f1.flush() whenever you want to make sure this happens. If you w

Re: [Tutor] Fwd: find second occurance of string in line

2015-09-09 Thread Laura Creighton
Peter Otten >Those who regularly need different configurations probably use virtualenv, >or virtual machines when the differences are not limited to Python. Use tox for this. https://testrun.org/tox/latest/ However for development purposes it often helps to have a --force the_one_that_I_want opt

Re: [Tutor] iterating through a directory

2015-09-09 Thread richard kappler
Albert-Jan, thanks for the response. shutil.copyfile does seem to be one of the tools I need to make the copying, renaming the copy and saving it elsewhere in one line instead of three or more. Still not sure how to efficiently get the script to keep moving to the next file in the directory though

[Tutor] A further question about opening and closing files

2015-09-09 Thread richard kappler
Under a different subject line (More Pythonic?) Steven D'Aprano commented: > And this will repeatedly open the file, append one line, then close it > again. Almost certainly not what you want -- it's wasteful and > potentially expensive. And I get that. It does bring up another question though. W

Re: [Tutor] Fwd: find second occurance of string in line

2015-09-09 Thread Peter Otten
Albert-Jan Roskam wrote: >> To: tutor@python.org >> From: __pete...@web.de >> Date: Tue, 8 Sep 2015 21:37:07 +0200 >> Subject: Re: [Tutor] Fwd: find second occurance of string in line >> >> Albert-Jan Roskam wrote: >> >> >> import lxml.etree >> >> >> >> tree = lxml.etree.parse("example.xml") >>

Re: [Tutor] iterating through a directory

2015-09-09 Thread Albert-Jan Roskam
> Date: Wed, 9 Sep 2015 09:32:34 -0400 > From: richkapp...@gmail.com > To: tutor@python.org > Subject: [Tutor] iterating through a directory > > Yes, many questions today. I'm working on a data feed script that feeds > 'events' into our test environment. In production, we monitor a camera that > c

Re: [Tutor] More Pythonic?

2015-09-09 Thread richard kappler
> It's not clear why you need the try...except: pass. Please provide some more background information. I don't need the try, this was more of a "are there different ways to do this, which is better and why?" experiment. I am learning, so tend to write script that is more brute force than elegant a

Re: [Tutor] More Pythonic?

2015-09-09 Thread Steven D'Aprano
On Wed, Sep 09, 2015 at 09:05:23AM -0400, richard kappler wrote: > Would either or both of these work, if both, which is the better or more > Pythonic way to do it, and why? The first works, but isn't really the best way to do it: > ### > > import whatIsNeeded > > writefile

[Tutor] Fwd: Fwd: find second occurance of string in line

2015-09-09 Thread richard kappler
> It looks likes I was not clear enough: XML doesn't have the concept of lines. When you process XML "by line" you have buggy code. No Peter, I'm pretty sure it was I who was less than clear. The xml data is generated by events, one line in a log for each event, so while xml doesn't have the conce

Re: [Tutor] More Pythonic?

2015-09-09 Thread Peter Otten
richard kappler wrote: > Would either or both of these work, if both, which is the better or more > Pythonic way to do it, and why? > > ### > > import whatIsNeeded > > writefile = open("writefile", 'a') > > with open(readfile, 'r') as f: > for line in f: > if ke

[Tutor] iterating through a directory

2015-09-09 Thread richard kappler
Yes, many questions today. I'm working on a data feed script that feeds 'events' into our test environment. In production, we monitor a camera that captures an image as product passes by, gathers information such as barcodes and package ID from the image, and then sends out the data as a line of xm

[Tutor] More Pythonic?

2015-09-09 Thread richard kappler
Would either or both of these work, if both, which is the better or more Pythonic way to do it, and why? ### import whatIsNeeded writefile = open("writefile", 'a') with open(readfile, 'r') as f: for line in f: if keyword in line: do stuff

Re: [Tutor] Creating lists with definite (n) items without repetitions

2015-09-09 Thread Francesco Loffredo via Tutor
Oscar Benjamin wrote: The problem is that there are 26 people and they are divided into groups of 3 each day. We would like to know if it is possible to arrange it so that each player plays each other player exactly once over some period of days. It is not exactly possible to

Re: [Tutor] find second occurance of string in line

2015-09-09 Thread Peter Otten
richard kappler wrote: > On Tue, Sep 8, 2015 at 1:40 PM, Peter Otten <__pete...@web.de> wrote: >> I'm inferring from the above that you do not really want the "second" >> timestamp in the line -- there is no line left intace anyway;) -- but >> rather >> the one in the ... part. >> >> Here's a way