Ned Batchelder writes:
> On 11/28/14 10:22 AM, Dave Angel wrote:
>> On 11/28/2014 10:04 AM, fetchinson . wrote:
>>> Hi all,
>>>
>>> I have a feeling that I should solve this by a context manager but
>>> since I've never used them I'm not sure what the optimal (in the
>>> python sense) solution is
On 11/28/2014 08:04 AM, fetchinson . wrote:
> Hi all,
>
> I have a feeling that I should solve this by a context manager but
> since I've never used them I'm not sure what the optimal (in the
> python sense) solution is. So basically what I do all the time is
> this:
I'd personally do it with a g
Chris Angelico :
> Since we're so good at it on this list, I will nit-pick: that's not a
> context manager class, that's an iterator class. A context manager has
> __enter__ and __exit__, an iterator has __iter__ (returning self) and
> __next__ (returning or raising StopIteration).
Excellent. Lea
On Sat, Nov 29, 2014 at 4:55 AM, Marko Rauhamaa wrote:
> I think the OP can learn from the comparison. One question, many
> lessons:
>
> * Here's how you write a generator.
>
> * Here's how you write a context manager class. You run into those
>quite often as well.
>
> * See how much more s
Dave Angel :
> Why would you prefer that over a generator function, as given earlier
> in the thread? See for example Ned's message. By using 'yield', you
> get Python to generate all the class boilerplate for you.
I think the OP can learn from the comparison. One question, many
lessons:
* Here
Please don't start a new thread when responding to an existing topic.
Just reply-List to the message you're responding to, and include some
context from that message.
On 11/28/2014 12:06 PM, ast wrote:
Hi
Here is a solution with a custom iterator which operate on files.
I tested it with a sma
Hi
Here is a solution with a custom iterator which operate on files.
I tested it with a small file. Just a remark, there are no empty line
on a file, there is at least '\n' at the end of each lines but maybe the
last one. If readline() got an emptyline, then the end of file has been
reached.
On 11/28/2014 11:01 AM, Ned Batchelder wrote:
On 11/28/14 10:22 AM, Dave Angel wrote:
On 11/28/2014 10:04 AM, fetchinson . wrote:
Hi all,
I have a feeling that I should solve this by a context manager but
since I've never used them I'm not sure what the optimal (in the
python sense) solution i
On 11/28/14 10:22 AM, Dave Angel wrote:
On 11/28/2014 10:04 AM, fetchinson . wrote:
Hi all,
I have a feeling that I should solve this by a context manager but
since I've never used them I'm not sure what the optimal (in the
python sense) solution is. So basically what I do all the time is
this:
On 11/28/14, Dave Angel wrote:
> On 11/28/2014 10:04 AM, fetchinson . wrote:
>> Hi all,
>>
>> I have a feeling that I should solve this by a context manager but
>> since I've never used them I'm not sure what the optimal (in the
>> python sense) solution is. So basically what I do all the time is
On 11/28/2014 10:04 AM, fetchinson . wrote:
Hi all,
I have a feeling that I should solve this by a context manager but
since I've never used them I'm not sure what the optimal (in the
python sense) solution is. So basically what I do all the time is
this:
for line in open( 'myfile' ):
if n
Hi all,
I have a feeling that I should solve this by a context manager but
since I've never used them I'm not sure what the optimal (in the
python sense) solution is. So basically what I do all the time is
this:
for line in open( 'myfile' ):
if not line:
# discard empty lines
12 matches
Mail list logo