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 thin

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 Guido

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 https://docs.python.org/3/library/stdtypes.html

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 i

[Tutor] Pythonic way

2018-11-20 Thread Avi Gross
This is not a question or reply. Nor is it short. If not interested, feel free to delete. It is an observation based on recent experiences. We have had quite a few messages that pointed out how some people approach solving a problem using subconscious paradigms inherited from their past.

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 Gauld via Tutor wrote: > >

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 onl

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. >> >> T

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 a

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: > fmt="

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 something > you can’t

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) pythonic to use the s

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 u

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: > > format(datetime

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. > > > """Run if run as

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 generator

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 this > the "right" way

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 rewrite

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() ... > > no

[Tutor] pythonic

2018-03-29 Thread 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 this the "right" way to do it in python? #!/usr/bin/env python3 """Gene

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 now. Ignore or replac

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. > >

[Tutor] pythonic ascii decoding!

2017-07-31 Thread bruce
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. However, the following hasn;t always worked: s=s

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: class

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 o

[Tutor] Pythonic review (descriptors)

2015-04-28 Thread Sage Hack
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 I want to improve my Python coding skills but I'm not sure exactly what to study next. Right now I'm trying to use descriptors correctly and I'd like to k

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

2012-01-27 Thread Alan Gauld
On 27/01/12 06:44, Andre' Walker-Loud wrote: ... I have only had one programming class, and that was 15 years ago or so, > ...so these are not issues I am aware of. I often find myself joining strings (and have mostly used + to do it). String addition is OK in some languages, or at least bet

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

2012-01-27 Thread Blockheads Oi Oi
On 27/01/2012 06:44, Andre' Walker-Loud wrote: 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*

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 i

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 wrote: > spa...@gmail.com wrote: > >> Hello, >> >> My code is - >> >> l = len(m) >> item = str(m[1]) >> for i i

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 an

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

2012-01-26 Thread spawgi
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 anyone knows how to improve

Re: [Tutor] Pythonic nested lists

2010-10-04 Thread Alan Gauld
"col speed" 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 "0"s where the blanks go. b/ I create roworder (roworder = [[str(j)+str

[Tutor] Pythonic nested lists

2010-10-04 Thread col speed
Message: 6 Date: Tue, 28 Sep 2010 13:15:26 +0700 From: col speed To: tutor@python.org Subject: [Tutor] Pythonic nested lists Message-ID: Content-Type: text/plain; charset="iso-8859-1" Hi all, I've been trying to write a programme that solves sudoku problems for a while n

[Tutor] Pythonic nested lists

2010-09-27 Thread col speed
Hi all, I've been trying to write a programme that solves sudoku problems for a while now. I'm getting close, but would like to ask a few questions about the most pythonic way of doing some things. I've decided to create nested lists (row order, column order and square order) which correspond with

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'

Re: [Tutor] Pythonic way to normalize vertical whitespace

2009-05-08 Thread Kent Johnson
On Fri, May 8, 2009 at 1:03 PM, 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 >

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

[Tutor] Pythonic way to normalize vertical whitespace

2009-05-08 Thread python
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 than 1 blank line between paragr

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

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. > Wha

[Tutor] Pythonic way to extract delimited substrings

2008-04-14 Thread Malcolm Greene
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. Because the left and right delimiters a

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 /

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

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

2007-10-26 Thread Allen Fowler
Hello, 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? Thanks _

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

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 E

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: > inden

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

2006-03-21 Thread stv
Hey all, I would like to expand the "visual" representation of a tree hierarchy, given below, where child-ness is defined by indentation, and folder-ness is highlighted with a trailing '/' Input (test.txt): dir1/ file1 file2 1-1/ file3 file4