Re: [Tutor] Pythonic way

2018-11-21 Thread Alan Gauld via Tutor
On 20/11/2018 22:35, Steven D'Aprano wrote: > On Tue, Nov 20, 2018 at 08:22:01PM +, Alan Gauld via Tutor wrote: > >> I think that's a very deliberate feature of Python going back >> to its original purpose of being a teaching language that >> can be used beyond the classroom. > > I don't

Re: [Tutor] Pythonic way

2018-11-20 Thread Steven D'Aprano
On Tue, Nov 20, 2018 at 08:22:01PM +, Alan Gauld via Tutor wrote: > I think that's a very deliberate feature of Python going back > to its original purpose of being a teaching language that > can be used beyond the classroom. I don't think that is correct -- everything I've read is that

Re: [Tutor] Pythonic way

2018-11-20 Thread Mark Lawrence
On 20/11/2018 18:08, Avi Gross wrote: We have two completely separate ways to format strings that end up with fairly similar functionality. Actually, there is an implicit third way  You could argue five ways :-) 1. C printf style formatting

Re: [Tutor] Pythonic way

2018-11-20 Thread Alan Gauld via Tutor
On 20/11/2018 18:08, Avi Gross wrote: > ... So there isn’t really ONE pythonic way for many things. That's true and, I think, inevitable for anything developed in the open source world. If you compare it to a language entirely controlled by a single mind - like Oberon or Eiffel say - then there

Re: [Tutor] pythonic

2018-04-04 Thread Albert-Jan Roskam
Op 2 apr. 2018 15:31 schreef Steven D'Aprano : > > On Mon, Apr 02, 2018 at 06:49:52AM -0600, Mats Wichmann wrote: > > On 04/02/2018 02:56 AM, Alan Gauld via Tutor wrote: > > > On 02/04/18 04:19, Steven D'Aprano wrote: > > >> On Sun, Apr 01, 2018 at 10:58:51PM +0100, Alan

Re: [Tutor] pythonic

2018-04-02 Thread Steven D'Aprano
On Mon, Apr 02, 2018 at 04:28:10PM +0200, Peter Otten wrote: > > They look like string constants, but they're actually a hidden call to > > eval(). > > But because you cannot f-ify a string variable (without an additional eval() > call) you aren't tempted to feed them user-provided data. If

Re: [Tutor] pythonic

2018-04-02 Thread Mats Wichmann
On 04/02/2018 08:28 AM, Peter Otten wrote: > Steven D'Aprano wrote: > >> On Mon, Apr 02, 2018 at 06:49:52AM -0600, Mats Wichmann wrote: > >>> so since we're all learning things here, how would this play out with >>> the new f-strings? >> >> I don't think f-strings are even a bit Pythonic. >> >>

Re: [Tutor] pythonic

2018-04-02 Thread Peter Otten
Steven D'Aprano wrote: > On Mon, Apr 02, 2018 at 06:49:52AM -0600, Mats Wichmann wrote: >> so since we're all learning things here, how would this play out with >> the new f-strings? > > I don't think f-strings are even a bit Pythonic. > > They look like string constants, but they're actually

Re: [Tutor] pythonic

2018-04-02 Thread Steven D'Aprano
On Mon, Apr 02, 2018 at 06:49:52AM -0600, Mats Wichmann wrote: > On 04/02/2018 02:56 AM, Alan Gauld via Tutor wrote: > > On 02/04/18 04:19, Steven D'Aprano wrote: > >> On Sun, Apr 01, 2018 at 10:58:51PM +0100, Alan Gauld via Tutor wrote: > >>> On01/04/18 20:20, Albert-Jan Roskam wrote: >

Re: [Tutor] pythonic

2018-04-02 Thread leam hall
On Mon, Apr 2, 2018 at 9:01 AM, David Rock wrote: > It’s just as (if not more) pythonic to use the standard libraries. It’s very > common in a professional environment to not have access to outside (i.e., > internet) resources. I wouldn’t venture into Pypi unless there’s

Re: [Tutor] pythonic

2018-04-02 Thread David Rock
> On Mar 30, 2018, at 04:15, George Fischhof wrote: > > 2.) > argparse > > it is good, but you can write more Pythonic code using click > https://pypi.python.org/pypi/click/ > it is also Pythonic to use / know the Python ecosystem (the packages) It’s just as (if not more)

Re: [Tutor] pythonic

2018-04-02 Thread Mats Wichmann
On 04/02/2018 02:56 AM, Alan Gauld via Tutor wrote: > On 02/04/18 04:19, Steven D'Aprano wrote: >> On Sun, Apr 01, 2018 at 10:58:51PM +0100, Alan Gauld via Tutor wrote: >>> On01/04/18 20:20, Albert-Jan Roskam wrote: fmt="%Y-%m-%d %H:%M\n" f.write(now.strftime(fmt)) Lately I've been

Re: [Tutor] pythonic

2018-04-02 Thread Alan Gauld via Tutor
On 02/04/18 04:19, Steven D'Aprano wrote: > On Sun, Apr 01, 2018 at 10:58:51PM +0100, Alan Gauld via Tutor wrote: >> On01/04/18 20:20, Albert-Jan Roskam wrote: >>> fmt="%Y-%m-%d %H:%M\n" >>> f.write(now.strftime(fmt)) >>> Lately I've been using format(), which uses __format__, because I find it

Re: [Tutor] pythonic

2018-04-01 Thread Steven D'Aprano
On Sun, Apr 01, 2018 at 10:58:51PM +0100, Alan Gauld via Tutor wrote: > On01/04/18 20:20, Albert-Jan Roskam wrote: > > fmt="%Y-%m-%d %H:%M\n" > > f.write(now.strftime(fmt)) > > Lately I've been using format(), which uses __format__, because I find it > > slightly more readable: > >

Re: [Tutor] pythonic

2018-04-01 Thread Alan Gauld via Tutor
On01/04/18 20:20, Albert-Jan Roskam wrote: > fmt="%Y-%m-%d %H:%M\n" > f.write(now.strftime(fmt)) > Lately I've been using format(), which uses __format__, because I find it > slightly more readable: > format(datetime.now(), "%Y-%m-%d %H:%M") Interesting, I didn't know that format() recognised the

Re: [Tutor] pythonic

2018-04-01 Thread Albert-Jan Roskam
On Mar 30, 2018 10:39, Alan Gauld via Tutor wrote: > > On 30/03/18 03:48, Pat Martin wrote: > > > the "right" way to do it in python? > > More or less, a couple of comments below... > > > def Main(): > > Python function names begin with a lowercase letter by convention. > > >

Re: [Tutor] pythonic

2018-03-30 Thread Pat Martin
Thank you all for the ideas and comments, it is appreciated. I have some refactoring to do now. On Fri, Mar 30, 2018 at 2:22 AM, Peter Otten <__pete...@web.de> wrote: > Pat Martin wrote: > > > I have written the following program. It generates a template for Pelican > > web site static

Re: [Tutor] pythonic

2018-03-30 Thread George Fischhof
2018-03-30 4:48 GMT+02:00 Pat Martin : > Hello all, > > I have written the following program. It generates a template for Pelican > web site static generator. It works just fine, it generates the template > and then I put the info in it to customize. But I was wondering, is

Re: [Tutor] pythonic

2018-03-30 Thread Peter Otten
Pat Martin wrote: > I have written the following program. It generates a template for Pelican > web site static generator. It works just fine, it generates the template > and then I put the info in it to customize. But I was wondering, is this > the "right" way to do it in python? You may

Re: [Tutor] pythonic

2018-03-30 Thread Alan Gauld via Tutor
On 30/03/18 03:48, Pat Martin wrote: > the "right" way to do it in python? More or less, a couple of comments below... > def Main(): Python function names begin with a lowercase letter by convention. > """Run if run as a program.""" > parser = argparse.ArgumentParser() ... > >

Re: [Tutor] pythonic ascii decoding!

2017-07-31 Thread eryk sun
On Mon, Jul 31, 2017 at 3:39 PM, bruce wrote: > > So, is there a quick/dirty approach I can use to simply strip out the > "non-ascii" chars. I know, this might not be the "best/pythonic" way, > and that it might result in loss of some data/chars, but I can live > with it for

Re: [Tutor] pythonic ascii decoding!

2017-07-31 Thread Mats Wichmann
On 07/31/2017 09:39 AM, bruce wrote: > Hi guys. > > Testing getting data from a number of different US based/targeted > websites. So the input data source for the most part, will be "ascii". > I'm getting a few "weird" chars every now and then asn as fas as I can > tell, they should be utf-8. >

Re: [Tutor] Pythonic review (descriptors)

2015-04-28 Thread Alan Gauld
On 28/04/15 10:55, Sage Hack wrote: I'm looking for somebody willing to review parts of this code https://github.com/SageHack/cloud-buster and let me know what is not Pythonic :P https://github.com/SageHack/cloud-buster/tree/master/bust/descriptor The thing that jumps out to me is your use

Re: [Tutor] Pythonic review (descriptors)

2015-04-28 Thread Alan Gauld
On 28/04/15 10:55, Sage Hack wrote: I'm looking for somebody willing to review parts of this code https://github.com/SageHack/cloud-buster and let me know what is not Pythonic :P https://github.com/SageHack/cloud-buster/tree/master/bust/descriptor Another point re the PageTitle class:

Re: [Tutor] Pythonic way of concatenation of elements in an array

2012-01-26 Thread Steven D'Aprano
spa...@gmail.com wrote: Hello, My code is - l = len(m) item = str(m[1]) for i in range(2,l): item = item + - + str(m[i]) This code is part of a bigger function. It works fine. But I am not happy with the way I have written it. I think there is a better (Pythonic) way to rewrite it. If

Re: [Tutor] Pythonic way of concatenation of elements in an array

2012-01-26 Thread spawgi
Hello Steven, Thanks a lot for the detailed answer. I will implement your suggestions. Really appreciate it. Thanks and Regards, Sumod On Fri, Jan 27, 2012 at 4:34 AM, Steven D'Aprano st...@pearwood.infowrote: spa...@gmail.com wrote: Hello, My code is - l = len(m) item = str(m[1]) for

Re: [Tutor] Pythonic way of concatenation of elements in an array

2012-01-26 Thread Andre' Walker-Loud
Hi Steven, (5) When assembling strings from substrings, never use repeated concatenation using + as that can be EXTREMELY slow. Use str.join to build the string in one assignment, instead of multiple assignments. Your code shown above is *very* inefficient and will be PAINFULLY slow if m

Re: [Tutor] Pythonic nested lists

2010-10-04 Thread Alan Gauld
col speed ajarnco...@gmail.com wrote HI again, I realise that I should have included more information in the above e-mail. Here goes: a/ I have a 9*9 nested list called rows, which contains the given numbers in a sudoku puzzle - with 0s where the blanks go. b/ I create roworder (roworder

Re: [Tutor] Pythonic way to normalize vertical whitespace

2009-05-09 Thread spir
Le Fri, 08 May 2009 13:03:47 -0400, pyt...@bdurham.com s'exprima ainsi: [...] Approaches: 1. split text to list of lines that get stripped then: a. walk this list building a new list of lines that track and ignore extra blank lines -OR- b. re-join lines and replace '\n\n\n' wth' \n\n' until

Re: [Tutor] Pythonic way to normalize vertical whitespace

2009-05-08 Thread bob gailer
pyt...@bdurham.com wrote: Note: Following cross-posted to python-list where it got queued due to suspicious subject line. I'm looking for suggestions on technique (not necessarily code) about the most pythonic way to normalize vertical whitespace in blocks of text so that there is never more

Re: [Tutor] Pythonic way to normalize vertical whitespace

2009-05-08 Thread Kent Johnson
On Fri, May 8, 2009 at 1:03 PM, pyt...@bdurham.com wrote: Note: Following cross-posted to python-list where it got queued due to suspicious subject line. I'm looking for suggestions on technique (not necessarily code) about the most pythonic way to normalize vertical whitespace in blocks of

Re: [Tutor] Pythonic way to extract delimited substrings

2008-04-14 Thread Kent Johnson
Malcolm Greene wrote: Suggestions on the best way to extract delimited substrings strings from a larger string? Background: I have a long multi-line string with expressions delimited with '(' and ')' markers. I would like to extract these substrings and process them in a loop. What

Re: [Tutor] Pythonic way to extract delimited substrings

2008-04-14 Thread Alan Gauld
Malcolm Greene [EMAIL PROTECTED] wrote in Background: I have a long multi-line string with expressions delimited with '(' and ')' markers. I would like to extract these substrings and process them in a loop. I know how to do this task with regular expressions, but I'm always cautious

Re: [Tutor] Pythonic way to try a few times, then raise exception?

2007-10-26 Thread Alan Gauld
Allen Fowler [EMAIL PROTECTED] wrote I have a block of code buried deep in a module that I expect to fail periodically. (Calls to other machines over slow network, and such.) Generally, though, trying it a second / third will work. Is there clean way to write this on Python? There

Re: [Tutor] Pythonic way to try a few times, then raise exception?

2007-10-26 Thread johnf
On Friday 26 October 2007 03:17:47 pm Alan Gauld wrote: Allen Fowler [EMAIL PROTECTED] wrote I have a block of code buried deep in a module that I expect to fail periodically. (Calls to other machines over slow network, and such.) Generally, though, trying it a second / third will

Re: [Tutor] Pythonic? Building a full path from a visual file tree

2006-03-21 Thread Kent Johnson
stv wrote: I considered several brute-force solutions, but I persevered and came to, what I think, is a more Pythonic solution. What do you think? Looks pretty sweet to me :-) import string def expand_tree(filetree): indent = '\t' stack = [] for f in filetree: indents =

Re: [Tutor] Pythonic? Building a full path from a visual file tree

2006-03-21 Thread stv
The list comp is fine but I don't think you need it at all, since you strip() the string before you add it to stack. Ahh yes. I used the rstrip() in development, printing intermediary output to stdout, so I could see what my input file-to-list looked like (and it looked ugly with all those

Re: [Tutor] Pythonic? Building a full path from a visual file tree

2006-03-21 Thread stv
On 3/21/06, stv [EMAIL PROTECTED] wrote: import string def expand_tree(filetree): indent = '\t' stack = [] for f in filetree: indents = f.count(indent) while len(stack) indents: stack.pop() stack.append(f.strip()) yield string.join(stack,'') if not