Re: Sharing: File Reader Generator with & w/o Policy

2014-03-16 Thread Steven D'Aprano
On Sat, 15 Mar 2014 23:47:30 -0500, Mark H Harris wrote: > The other thing I'm tempted to do is to find names (even new names) that > read like English closely (whatever I mean by that) so that there is no > question about what is going on to a non expert. > > for line in getnumline(file): >

Re: Sharing: File Reader Generator with & w/o Policy

2014-03-15 Thread Chris Angelico
On Sun, Mar 16, 2014 at 5:19 PM, Mark H Harris wrote: > On 3/16/14 12:41 AM, Chris Angelico wrote: >> To be quite frank, yes I do think it's a nutty idea. Like most nutty >> things, there's a kernel of something good in it, but that's not >> enough to build a system on :) > > >Thanks for your

Re: Sharing: File Reader Generator with & w/o Policy

2014-03-15 Thread Mark H Harris
On 3/16/14 12:41 AM, Chris Angelico wrote: Good stuff Chris, and thanks for the footnotes, I appreciate it. If getline() is doing nothing that the primitive doesn't, and getnumline is just enumerate, then they're not achieving anything beyond shielding you from the primitives. Yes.

Re: Sharing: File Reader Generator with & w/o Policy

2014-03-15 Thread Chris Angelico
On Sun, Mar 16, 2014 at 3:47 PM, Mark H Harris wrote: > On 3/15/14 10:48 PM, Chris Angelico wrote: >> >> There's a cost to refactoring. Suddenly there's a new primitive on the >> board - a new piece of language . . . Splitting out all sorts of things >> into >> >> generators when you could use wel

Re: Sharing: File Reader Generator with & w/o Policy

2014-03-15 Thread Mark H Harris
On 3/15/14 10:48 PM, Chris Angelico wrote: There's a cost to refactoring. Suddenly there's a new primitive on the board - a new piece of language . . . Splitting out all sorts of things into generators when you could use well-known primitives like enumerate gets expensive fast {snip} [1] https:

Re: Sharing: File Reader Generator with & w/o Policy

2014-03-15 Thread Chris Angelico
On Sun, Mar 16, 2014 at 2:34 PM, Mark H Harris wrote: > And you are right about another thing, I just want to use this thing over > and over. > > for line in getnumline(filename): > {whatever} > >There does seem to be just one way of doing this (file reads) but there > are actually many w

Re: Sharing: File Reader Generator with & w/o Policy

2014-03-15 Thread Mark H Harris
On 3/15/14 9:01 PM, Steven D'Aprano wrote: Reading from files is already pretty simple. I would expect that it will be harder to learn the specific details of custom, specialised, file readers that *almost*, but not quite, do what you want, than to just write a couple of lines of code to do what

Re: Sharing: File Reader Generator with & w/o Policy

2014-03-15 Thread Mark H Harris
On 3/15/14 8:32 PM, Mark Lawrence wrote: Start here http://docs.python.org/3/library/stdtypes.html#context-manager-types Thanks Mark. I have three books open, and that doc, and wading through. You might like to know (as an aside) that I'm done with gg. Got back up here with a real news read

Re: Sharing: File Reader Generator with & w/o Policy

2014-03-15 Thread Steven D'Aprano
On Sat, 15 Mar 2014 16:38:18 -0500, Mark H Harris wrote: > hi folks, I am posting to share a File Reader Generator which I have > been playing with, that simplifies reading of text files on-demand: like > log files, config files, small record flat data-bases, &c. Reading from files is already pre

Re: Sharing: File Reader Generator with & w/o Policy

2014-03-15 Thread Mark Lawrence
On 16/03/2014 01:06, Mark H Harris wrote: On 3/15/14 4:56 PM, MRAB wrote: You can also shorten it somewhat: Thanks, I like it... I shortened the fnName() also: #- # fn2Name(filename) generator: file reader iterable #-

Re: Sharing: File Reader Generator with & w/o Policy

2014-03-15 Thread Mark H Harris
On 3/15/14 4:56 PM, MRAB wrote: You can also shorten it somewhat: Thanks, I like it... I shortened the fnName() also: #- # fn2Name(filename) generator: file reader iterable #- de

Re: Sharing: File Reader Generator with & w/o Policy

2014-03-15 Thread Mark H Harris
On 3/15/14 4:56 PM, MRAB wrote: def fName(filename): try: with open(filename, 'r') as fh: for linein in fh: yield linein.strip('\n') except FileNotFoundError as err_code: print(err_code) [snip] The "with" confuses me because I am not sure s

Re: Sharing: File Reader Generator with & w/o Policy

2014-03-15 Thread Mark H Harris
On 3/15/14 4:56 PM, MRAB wrote: I don't like how it always swallows the exception, so you can't tell whether the file doesn't exist or exists but is empty, and no way to specify the file's encoding. Yes, the error handling needs more robustness/ and instead of printing the errcode, my actual m

Re: Sharing: File Reader Generator with & w/o Policy

2014-03-15 Thread MRAB
On 2014-03-15 21:38, Mark H Harris wrote: hi folks, I am posting to share a File Reader Generator which I have been playing with, that simplifies reading of text files on-demand: like log files, config files, small record flat data-bases, &c. I have two generators to share, one with & one withou

Sharing: File Reader Generator with & w/o Policy

2014-03-15 Thread Mark H Harris
hi folks, I am posting to share a File Reader Generator which I have been playing with, that simplifies reading of text files on-demand: like log files, config files, small record flat data-bases, &c. I have two generators to share, one with & one without "policy". The idea is to have the generat