Pythonic way to run the asyncio loop forever in python 3.10

2022-10-06 Thread David Jander
not even be a single coroutine involved. Someone else asked something similar here: https://stackoverflow.com/questions/65684730/what-is-the-pythonic-way-of-running-an-asyncio-event-loop-forever Unfortunately all proposed answers look like dirty hacks. In concrete, how do I do this nicel

Re: more pythonic way

2019-02-16 Thread Grant Edwards
On 2019-02-16, Barry wrote: > On 11 Feb 2019, at 20:00, Felix Lazaro Carbonell wrote: > >>> The most pythonic way is to do this: >>> >>> def find_monthly_expenses(month=datetime.date.today().month, >> year=datetime.date.today().year): >>>

Re: more pythonic way

2019-02-16 Thread Barry
On 11 Feb 2019, at 20:00, Felix Lazaro Carbonell wrote: >> The most pythonic way is to do this: >> >> def find_monthly_expenses(month=datetime.date.today().month, > year=datetime.date.today().year): >>... This has subtle bugs. The default is calculate

Re: more pythonic way

2019-02-11 Thread Jimmy Girardet
The first one is used very often. Less verbose Le 11 févr. 2019 à 20:41, à 20:41, Felix Lazaro Carbonell a écrit: > > >Hello to everyone: > >Could you please tell me wich way of writing this method is more >pythonic: > > > >.. > >def find_monthly_expenses(month=None, year=None): > >

Re: more pythonic way

2019-02-11 Thread Peter Otten
Felix Lazaro Carbonell wrote: > Hello to everyone: > Could you please tell me wich way of writing this method is more pythonic: > def find_monthly_expenses(month=None, year=None): > > month = month or datetime.date.today() > Or it should better be: > if not month: >

Re: more pythonic way

2019-02-11 Thread Peter Otten
today() >> >> Or it should better be: >> >> if not month: >> month = datetime.date.today() > > The most pythonic way is to do this: > >def find_monthly_expenses(month=datetime.date.today().month, >year=datetime.date.today().year)

Re: more pythonic way

2019-02-11 Thread Sivan Grünberg
tations or overrides, etc. > > > -Original Message- > From: Python-list [mailto:python-list-bounces+david.raymond= > tomtom@python.org] On Behalf Of Felix Lazaro Carbonell > Sent: Monday, February 11, 2019 2:30 PM > To: python-list@python.org > Subject: more py

Re: more pythonic way

2019-02-11 Thread Terry Reedy
On 2/11/2019 2:46 PM, Felix Lazaro Carbonell wrote: def find_monthly_expenses(month=None, year=None): month = month or datetime.date.today().month Or it should better be: if not month: month = datetime.date.today().month As a 20+ year veteran, I would be

RE: more pythonic way

2019-02-11 Thread David Raymond
lementations or overrides, etc. -Original Message- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom@python.org] On Behalf Of Felix Lazaro Carbonell Sent: Monday, February 11, 2019 2:30 PM To: python-list@python.org Subject: more pythonic way Hello to everyone: Could you

RE: more pythonic way

2019-02-11 Thread Felix Lazaro Carbonell
-Mensaje original- De: Python-list [mailto:python-list-bounces+felix=epepm.cupet...@python.org] En nombre de Grant Edwards Enviado el: lunes, 11 de febrero de 2019 02:46 p.m. Para: python-list@python.org Asunto: Re: more pythonic way On 2019-02-11, Felix Lazaro Carbonell wrote

RE: more pythonic way

2019-02-11 Thread Felix Lazaro Carbonell
Sorry I meant .. def find_monthly_expenses(month=None, year=None): month = month or datetime.date.today().month .. Or it should better be: ... if not month: month = datetime.date.today().month .. Cheers, Felix. -- https://mail.python.org/mailman

Re: more pythonic way

2019-02-11 Thread Grant Edwards
gt; if not month: > month = datetime.date.today() The most pythonic way is to do this: def find_monthly_expenses(month=datetime.date.today().month, year=datetime.date.today().year): ... And then start a month-long argument on the mailing list about how the behavior of parameter

more pythonic way

2019-02-11 Thread Felix Lazaro Carbonell
Hello to everyone: Could you please tell me wich way of writing this method is more pythonic: .. def find_monthly_expenses(month=None, year=None): month = month or datetime.date.today() .. Or it should better be: ... if not month: month = datetime.d

Re: Most pythonic way to implement byte stuffing algorithm

2018-04-17 Thread Travis Griggs
ally generalizes to >> is “what is the most pythonic way to transform one sequence of bytes where >> some bytes are passed through 1:1, but others are transformed to longer >> subsequences of bytes?” I’m pretty sure this rules out the use of >> transform() which expects a 1

Re: Most pythonic way to implement byte stuffing algorithm

2018-04-17 Thread MRAB
On 2018-04-17 17:02, Travis Griggs wrote: I posted this on SO, but… yeah… I'm doing some serial protocol stuff and want to implement a basic byte stuffing algorithm in python. Though really what this really generalizes to is “what is the most pythonic way to transform one sequence of

Re: Most pythonic way to implement byte stuffing algorithm

2018-04-17 Thread Grant Edwards
On 2018-04-17, Travis Griggs wrote: > I posted this on SO, but… yeah… > > I'm doing some serial protocol stuff and want to implement a basic > byte stuffing algorithm in python. Though really what this really > generalizes to is “what is the most pythonic way to transfo

Most pythonic way to implement byte stuffing algorithm

2018-04-17 Thread Travis Griggs
I posted this on SO, but… yeah… I'm doing some serial protocol stuff and want to implement a basic byte stuffing algorithm in python. Though really what this really generalizes to is “what is the most pythonic way to transform one sequence of bytes where some bytes are passed through 1:1

Re: Fast pythonic way to process a huge integer list

2016-01-07 Thread KP
On Wednesday, 6 January 2016 18:37:22 UTC-8, high5s...@gmail.com wrote: > I have a list of 163.840 integers. What is a fast & pythonic way to process > this list in 1,280 chunks of 128 integers? Thanks all for your valuable input - much appreciated! -- https://mail.python.org/mailma

Re: Fast pythonic way to process a huge integer list

2016-01-07 Thread Peter Otten
high5stor...@gmail.com wrote: > I have a list of 163.840 integers. What is a fast & pythonic way to > process this list in 1,280 chunks of 128 integers? What kind of processing do you have in mind? If it is about numbercrunching use a numpy.array. This can also easily change

Re: Fast pythonic way to process a huge integer list

2016-01-06 Thread Cameron Simpson
On 06Jan2016 18:36, high5stor...@gmail.com wrote: I have a list of 163.840 integers. What is a fast & pythonic way to process this list in 1,280 chunks of 128 integers? The depends. When you say "list", is it already a _python_ list? Or do you just mean that the intergers ar

Re: Fast pythonic way to process a huge integer list

2016-01-06 Thread Tim Chase
On 2016-01-06 18:36, high5stor...@gmail.com wrote: > I have a list of 163.840 integers. What is a fast & pythonic way to > process this list in 1,280 chunks of 128 integers? That's a modest list, far from huge. You have lots of options, but the following seems the most pythoni

Re: Fast pythonic way to process a huge integer list

2016-01-06 Thread Terry Reedy
On 1/6/2016 9:36 PM, high5stor...@gmail.com wrote: I have a list of 163.840 integers. What is a fast & pythonic way to process this list in 1,280 chunks of 128 integers? What have you tried that did not work? This is really pretty simple, but the detail depend on the meaning of '

Fast pythonic way to process a huge integer list

2016-01-06 Thread high5storage
I have a list of 163.840 integers. What is a fast & pythonic way to process this list in 1,280 chunks of 128 integers? -- https://mail.python.org/mailman/listinfo/python-list

Re: How to handle exceptions properly in a pythonic way?

2015-11-09 Thread zljubisic
Hi, > def get_html(...): > try: > ... actually go get the info > return info > except (ConnectionError, OSError, SocketError) as e: > raise ContentNotFoundError from e Personally, I never liked "early returns". I would rather used a variable and the last line in t

Re: How to handle exceptions properly in a pythonic way?

2015-11-09 Thread zljubisic
Hi, You are right. I am trying to address a few questions at the same time. As English is not my first language, I can only say that you have addressed them very well. Thanks. 1. Where to put the try/except block, inside or outside the function 2. How to deal with un-anticipated exceptions 3.

Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread tian . su . yale
Hi, If I may, I feel you are tying to address a few questions at the same time, although they are related 1. Where to put the try/except block, inside or outside the function 2. How to deal with un-anticipated exceptions 3. How to keep record My personal feelings are: 1. Kind of prefer try/except

Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread tian . su . yale
在 2015年11月4日星期三 UTC-6下午10:18:33,zlju...@gmail.com写道: > > Which would you prefer? > > So if I am just checking for the ConnectionError in get_html and a new > exception arises, I will have traceback to the get_html function showing that > unhandled exception has happened. > Now I have to put addi

Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread Chris Angelico
On Thu, Nov 5, 2015 at 3:18 PM, wrote: >> Which would you prefer? > > So if I am just checking for the ConnectionError in get_html and a new > exception arises, I will have traceback to the get_html function showing that > unhandled exception has happened. > Now I have to put additional excepti

Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread zljubisic
> Which would you prefer? So if I am just checking for the ConnectionError in get_html and a new exception arises, I will have traceback to the get_html function showing that unhandled exception has happened. Now I have to put additional exception block for managing the new exception in the get

Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread zljubisic
On Monday, 2 November 2015 21:59:45 UTC+1, Ian wrote: > I'm having a hard time understanding what question you're asking. :) I am really having a hard time to explain the problem as English is not my first language. > You > have a lot of discussion about where to handle exceptions, That's

Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread Chris Angelico
On Thu, Nov 5, 2015 at 2:41 PM, wrote: > Raising an exception forces me to put every call of the get_html function in > try/except block. > If I am returning a special value, than I can call get_html and then test the > value. > > I am not sure which approach is better. Raising an exception me

Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread zljubisic
> The best way is probably to do nothing at all, and let the caller handle > any exceptions. In that case every call of the get_html function has to be in the try/except block with many exceptions. Sometimes, it is enough just to know whether I managed to get the html or not. In that case, I coul

Re: How to handle exceptions properly in a pythonic way?

2015-11-02 Thread Ian Kelly
On Mon, Nov 2, 2015 at 12:24 PM, wrote: > I have read some articles that returning None is not a good approach, so I am > confused. > > How to handle exceptions properly in a pythonic way? I'm having a hard time understanding what question you're asking. You have a l

Re: How to handle exceptions properly in a pythonic way?

2015-11-02 Thread John Gordon
In <4b303213-62e2-42d4-b2f6-4fc1f6025...@googlegroups.com> zljubi...@gmail.com writes: > Let's say that I have the following simple function: > def get_html(url): > wpage = requests.get(url) > > return wpage.text > How to handle exceptions properly that can arise during execution

How to handle exceptions properly in a pythonic way?

2015-11-02 Thread zljubisic
e. Caller doesn't need try/except block anymore. Something like this: if get_html('www.abc.com/index.html') is not None: I_am_sure_that_html_has_been_downloaded_correctly Now if I want to catch a new exception, I can catch it in get_html function, which is the only change in the program. I

Re: Most Pythonic way to store (small) configuration

2015-08-06 Thread Chris Angelico
On Thu, Aug 6, 2015 at 5:33 PM, Steven D'Aprano wrote: > On Thursday 06 August 2015 10:07, Chris Angelico wrote: > >> On Thu, Aug 6, 2015 at 9:43 AM, Tim Chase >> wrote: >>> Significant whitespace? Not usually simple (just stuck touching a >>> project where someone committed with tons of trailin

Re: Most Pythonic way to store (small) configuration

2015-08-06 Thread Steven D'Aprano
On Thursday 06 August 2015 10:07, Chris Angelico wrote: > On Thu, Aug 6, 2015 at 9:43 AM, Tim Chase > wrote: >> Significant whitespace? Not usually simple (just stuck touching a >> project where someone committed with tons of trailing whitespaces. >> grumble), so strip 'em off as if they're an e

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Rustom Mody
On Thursday, August 6, 2015 at 6:32:03 AM UTC+5:30, Rustom Mody wrote: > By contrast here is a more friendly error message (had put a comma where a > colon > required) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python3.4/ast.py", line 46, in literal_eval >

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Rustom Mody
On Thursday, August 6, 2015 at 2:31:52 AM UTC+5:30, Tim Chase wrote: > On 2015-08-05 06:37, Rustom Mody wrote: > > > config = {} > > > with open('config.ini') as f: > > > for row in f: > > > row = row.strip() > > > if not row or row.startswith(('#', ';')): > > > continue

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Chris Angelico
On Thu, Aug 6, 2015 at 9:43 AM, Tim Chase wrote: > Significant whitespace? Not usually simple (just stuck touching a > project where someone committed with tons of trailing whitespaces. > grumble), so strip 'em off as if they're an error condition. I've > never had a config-file where I wanted l

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Tim Chase
On 2015-08-06 00:47, Marko Rauhamaa wrote: > > There's a certain simplicity to simply having key/value pairs > > separated by an "=" and then letting the application do whatever > > it needs/wants with those key/value strings. > > That trap has lured in a lot of wildlife. > > What to do with li

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Marko Rauhamaa
Tim Chase : > There's a certain simplicity to simply having key/value pairs > separated by an "=" and then letting the application do whatever it > needs/wants with those key/value strings. That trap has lured in a lot of wildlife. What to do with lists? Is whitespace significant? Case in poin

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Tim Chase
On 2015-08-05 06:37, Rustom Mody wrote: > > config = {} > > with open('config.ini') as f: > > for row in f: > > row = row.strip() > > if not row or row.startswith(('#', ';')): > > continue > > k, _, v = row.partition('=') > > config[k.strip().upper()] = v.lst

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Rustom Mody
On Wednesday, August 5, 2015 at 7:38:46 PM UTC+5:30, Steven D'Aprano wrote: > On Wed, 5 Aug 2015 11:46 pm, Rustom Mody wrote: > > > On Sunday, August 2, 2015 at 3:44:51 PM UTC+5:30, Cecil Westerhof wrote: > >> There are a lot of ways to store configuration information: > >> - conf file > >> - xml

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Steven D'Aprano
On Wed, 5 Aug 2015 11:46 pm, Rustom Mody wrote: > On Sunday, August 2, 2015 at 3:44:51 PM UTC+5:30, Cecil Westerhof wrote: >> There are a lot of ways to store configuration information: >> - conf file >> - xml file >> - database >> - json file >> - and possible a lot of other ways > > One that I

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Grant Edwards
On 2015-08-05, Michael Torrie wrote: > On 08/04/2015 01:59 PM, Ben Finney wrote: >> marco.naw...@colosso.nl writes: >> >>> Why not use Python files itself as configuration files? >> >> Because configuration data will be user-editable. (If it's not >> user-editable, that is itself a poor design c

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Rustom Mody
On Sunday, August 2, 2015 at 3:44:51 PM UTC+5:30, Cecil Westerhof wrote: > There are a lot of ways to store configuration information: > - conf file > - xml file > - database > - json file > - and possible a lot of other ways One that I dont think has been mentioned: ast.literal_eval -- https://m

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Rustom Mody
On Wednesday, August 5, 2015 at 6:58:01 PM UTC+5:30, Tim Chase wrote: > On 2015-08-02 12:11, Cecil Westerhof wrote: > > There are a lot of ways to store configuration information: > > - conf file > > - xml file > > - database > > - json file > > - and possible a lot of other ways > > > > I want to

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Tim Chase
On 2015-08-02 12:11, Cecil Westerhof wrote: > There are a lot of ways to store configuration information: > - conf file > - xml file > - database > - json file > - and possible a lot of other ways > > I want to write a Python program to display cleaned log files. I do > not think I need a lot of c

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Chris Angelico
On Wed, Aug 5, 2015 at 6:32 PM, Steven D'Aprano wrote: > My own personal feeling is that using code as config is a little > disquieting. It's a bit of a code smell. Do you really need that much power > just to allow people to set some configuration settings? Using a Turing > Complete programming l

Re: Most Pythonic way to store (small) configuration

2015-08-05 Thread Steven D'Aprano
On Wednesday 05 August 2015 05:59, Ben Finney wrote: > marco.naw...@colosso.nl writes: > >> Why not use Python files itself as configuration files? > > Because configuration data will be user-editable. (If it's not > user-editable, that is itself a poor design choice.) > > If you allow executab

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Lele Gaifax
Rustom Mody writes: > Does yaml have comments? Yes, the same syntax as Python's. ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l...@metapensiero.it | -- Fortunato Depero, 1929.

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Rustom Mody
On Wednesday, August 5, 2015 at 10:19:11 AM UTC+5:30, Michael Torrie wrote: > On 08/04/2015 08:44 PM, wrote: > > On Tue, Aug 4, 2015, at 21:32, Michael Torrie wrote: > >> In many of my projects I put basic config variables in a file like > >> config.py and import that in each module that needs it.

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Michael Torrie
On 08/04/2015 08:19 PM, Cameron Simpson wrote: > So on the whole I am against python code as the config file format. Really, > who > needs a Turing complete configuration file? In Django's case, since you're intimately referring to certain classes and methods, particularly in the url mapping sec

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Michael Torrie
On 08/04/2015 08:44 PM, random...@fastmail.us wrote: > On Tue, Aug 4, 2015, at 21:32, Michael Torrie wrote: >> In many of my projects I put basic config variables in a file like >> config.py and import that in each module that needs it. The config >> module doubles as a global namespace for sharin

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread random832
On Tue, Aug 4, 2015, at 21:32, Michael Torrie wrote: > In many of my projects I put basic config variables in a file like > config.py and import that in each module that needs it. The config > module doubles as a global namespace for sharing between modules as well. What about JSONP? That is, a f

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Cameron Simpson
On 04Aug2015 19:32, Michael Torrie wrote: On 08/04/2015 01:59 PM, Ben Finney wrote: marco.naw...@colosso.nl writes: Why not use Python files itself as configuration files? Because configuration data will be user-editable. (If it's not user-editable, that is itself a poor design choice.) If

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Michael Torrie
On 08/04/2015 01:59 PM, Ben Finney wrote: > marco.naw...@colosso.nl writes: > >> Why not use Python files itself as configuration files? > > Because configuration data will be user-editable. (If it's not > user-editable, that is itself a poor design choice.) > > If you allow executable code to b

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Ben Finney
marco.naw...@colosso.nl writes: > Why not use Python files itself as configuration files? Because configuration data will be user-editable. (If it's not user-editable, that is itself a poor design choice.) If you allow executable code to be user-edited, that opens your program to arbitrary injec

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread marco . nawijn
On Tuesday, August 4, 2015 at 7:06:33 PM UTC+2, Irmen de Jong wrote: > On 4-8-2015 16:53, marco.naw...@colosso.nl wrote: > > Why not use Python files itself as configuration files? > > It could create a security risk if the config files are user-editable. > (it will make it easy to inject code int

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Irmen de Jong
On 4-8-2015 16:53, marco.naw...@colosso.nl wrote: > Why not use Python files itself as configuration files? It could create a security risk if the config files are user-editable. (it will make it easy to inject code into your application) Irmen -- https://mail.python.org/mailman/listinfo/python

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread marco . nawijn
On Sunday, August 2, 2015 at 12:14:51 PM UTC+2, Cecil Westerhof wrote: > There are a lot of ways to store configuration information: > - conf file > - xml file > - database > - json file > - and possible a lot of other ways > > I want to write a Python program to display cleaned log files. I do >

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread Jean-Michel Pichavant
- Original Message - > From: "Cecil Westerhof" > To: python-list@python.org > Sent: Sunday, 2 August, 2015 12:11:28 PM > Subject: Most Pythonic way to store (small) configuration > > There are a lot of ways to store configuration information: > - conf

Re: Most Pythonic way to store (small) configuration

2015-08-04 Thread c.buhtz
Dear Cecil, I subscribed to late to answer to your top-post in that thread. I had the same topic for myself in the last months and tried a lot of things. In your situation I would prefere the INI-file format, too. But doen't user 'configparser' for that. As other fellows described it's a bad sol

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-03 Thread Larry Hudson via Python-list
On 08/02/2015 01:58 PM, Joonas Liik wrote: I have this feeling that you would get a lot more useful anwsers if you were to describe your actual problem in stead of what you think the solution is. There might be other, better solutions but since we know so little about what you are doing we will l

Re: Most Pythonic way to store (small) configuration

2015-08-03 Thread Mark Lawrence
On 03/08/2015 14:38, Steven D'Aprano wrote: On Mon, 3 Aug 2015 02:02 pm, Dan Sommers wrote: Well, I have at least some non-zero chance of reading and writing JSON or XML by hand. Can the same be said for a sqlite database? Real programmers edit their SQL databases directly on the hard drive

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-03 Thread Mark Lawrence
On 02/08/2015 21:58, Joonas Liik wrote: I have this feeling that you would get a lot more useful anwsers if you were to describe your actual problem in stead of what you think the solution is. There might be other, better solutions but since we know so little about what you are doing we will like

Re: Most Pythonic way to store (small) configuration

2015-08-03 Thread Chris Angelico
On Mon, Aug 3, 2015 at 11:38 PM, Steven D'Aprano wrote: > On Mon, 3 Aug 2015 02:02 pm, Dan Sommers wrote: > >> Well, I have at least some non-zero chance of reading and writing JSON >> or XML by hand. Can the same be said for a sqlite database? > > > Real programmers edit their SQL databases dire

Re: Most Pythonic way to store (small) configuration

2015-08-03 Thread Steven D'Aprano
On Mon, 3 Aug 2015 02:02 pm, Dan Sommers wrote: > Well, I have at least some non-zero chance of reading and writing JSON > or XML by hand.  Can the same be said for a sqlite database? Real programmers edit their SQL databases directly on the hard drive platter using a magnetised needle and a ste

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-03 Thread Joonas Liik
I have this feeling that you would get a lot more useful anwsers if you were to describe your actual problem in stead of what you think the solution is. There might be other, better solutions but since we know so little about what you are doing we will likely never find them by just guessing.. --

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Dan Sommers
On Sun, 02 Aug 2015 16:11:14 -0500, Tim Chase wrote: > On 2015-08-02 21:54, Ben Finney wrote: >> So, both XML and JSON should be considered write-only, and produced >> only for consumption by a computer; they are a poor choice for >> presenting to a human. [snip] > I second Ben's thoughts again

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Tim Chase
On 2015-08-02 21:54, Ben Finney wrote: > So, both XML and JSON should be considered write-only, and produced > only for consumption by a computer; they are a poor choice for > presenting to a human. > > The “INI” format as handled by the Python ‘configparser’ module is > what I would recommend for

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Ben Finney
Cecil Westerhof writes: > On Sunday 2 Aug 2015 13:54 CEST, Ben Finney wrote: > > > So, both XML and JSON should be considered write-only, and produced > > only for consumption by a computer; they are a poor choice for > > presenting to a human. > > Well, I would use nested data. (A file will hav

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Cameron Simpson
On 02Aug2015 18:51, Cecil Westerhof wrote: On Sunday 2 Aug 2015 13:54 CEST, Ben Finney wrote: Cecil Westerhof writes: Because of this I think a human readable file would be best. I agree with that criterion; in the absence of compelling reasons otherwise, human-readable and -editable text

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-02 Thread Larry Hudson via Python-list
e go on as above, otherwise find *all* positions of the minimum, see which is followed by the smallest element, and then rotate that position to the front. Now that seems an awful lot of code for a (seemingly?) simple problem. Is there a nice, pythonic way to do this? Thanks for enlightening

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Lele Gaifax
Cecil Westerhof writes: > Well, I would use nested data. (A file will have extra fields besides > the name.) That is why I was thinking about json. But I will look into > it. An alternative, very similar to JSON but with some good cherries picked from YAML is AXON, which is my preferite these da

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-02 Thread Tim Chase
On 2015-08-01 13:34, Lukas Barth wrote: > I have a list of numbers that I treat as "circular", i.e. [1,2,3] > and [2,3,1] should be the same. Now I want to rotate these to a > well defined status, so that I can can compare them. > > If all elements are unique, the solution is easy: find the minimu

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Cecil Westerhof
On Sunday 2 Aug 2015 13:54 CEST, Ben Finney wrote: > Cecil Westerhof writes: > >> Because of this I think a human readable file would be best. > > I agree with that criterion; in the absence of compelling reasons > otherwise, human-readable and -editable text is a good default. > >> Personally I

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Mark Lawrence
On 02/08/2015 12:54, Ben Finney wrote: Cecil Westerhof writes: Because of this I think a human readable file would be best. The “INI” format as handled by the Python ‘configparser’ module is what I would recommend for a simple flat configuration file. It is more intuitive to edit, and has a

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Ben Finney
Cecil Westerhof writes: > Because of this I think a human readable file would be best. I agree with that criterion; in the absence of compelling reasons otherwise, human-readable and -editable text is a good default. > Personally I do not find XML very readable. So a conf or json file > looks t

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-02 Thread pavlovevidence
of code for a (seemingly?) simple problem. Is > there a nice, pythonic way to do this? > > Thanks for enlightening me! [[[Warning: all code untested, sorry!]]] The general problem (no assumptions about the items in the list except that they're all sortable together) is interesting.

Re: Most Pythonic way to store (small) configuration

2015-08-02 Thread Chris Angelico
On Sun, Aug 2, 2015 at 8:11 PM, Cecil Westerhof wrote: > Because of this I think a human readable file would be best. > Personally I do not find XML very readable. So a conf or json file > looks the most promising to me. And I would have a slight preference > for a json file. > > Any comments, tho

Most Pythonic way to store (small) configuration

2015-08-02 Thread Cecil Westerhof
There are a lot of ways to store configuration information: - conf file - xml file - database - json file - and possible a lot of other ways I want to write a Python program to display cleaned log files. I do not think I need a lot of configuration to be stored: - some things relating to the GUI -

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-02 Thread Steven D'Aprano
On Sun, 2 Aug 2015 08:51 am, Lukas Barth wrote: > On Saturday, August 1, 2015 at 11:37:48 PM UTC+2, Emile van Sebille wrote: >> Well, it looks to me that I don't know what a 'canonical rotation' is -- > > That's because it is not defined. ;) > > I need a way to rotate one of these lists in a way

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Marko Rauhamaa
Lukas Barth : > On Saturday, August 1, 2015 at 10:57:19 PM UTC+2, Marko Rauhamaa wrote: >> >> def circularly_equal(l1, l2): >> length = len(l1) >> if length != len(l2): >> return False >> twice = l1 + l1 >

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Paul Rubin
Paul Rubin writes: > H([b-a, c-b, d-c, a-d]) > where H is your favorite hash function on a list of that element type. I wrote that up unclearly. H is supposed to be a hash on one element, and then you combine H(b-a), H(c-b), etc. in a commutative way, such as by adding them. Still not sure if

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Paul Rubin
Lukas Barth writes: >> [Concatenated Hashes] > Also, that still doesn't compute that one "canonical ordering"... It was intended to get rid of the need. What is the actual application? How does this sound? To circularly hash [a,b,c,d] use: H([b-a, c-b, d-c, a-d]) where H is your favorite h

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Cameron Simpson
On 01Aug2015 15:55, Lukas Barth wrote: On Sunday, August 2, 2015 at 12:32:25 AM UTC+2, Cameron Simpson wrote: Fine. This also eliminates any solution which just computes a hash. Exactly. Might I suggest instead simply starting with the leftmost element in the first list; call this elem0. T

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread wolfram.hinderer--- via Python-list
ar twice in that list, i.e. I could search for the minimum, if that is > unique go on as above, otherwise find *all* positions of the minimum, see > which is followed by the smallest element, and then rotate that position to > the front. > > Now that seems an awful lot of code fo

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Josh English
On Saturday, August 1, 2015 at 3:52:25 PM UTC-7, Lukas Barth wrote: > On Saturday, August 1, 2015 at 11:37:48 PM UTC+2, Emile van Sebille wrote: > > Well, it looks to me that I don't know what a 'canonical rotation' is -- > > That's because it is not defined. ;) > > I need a way to rotate one of

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Lukas Barth
On Sunday, August 2, 2015 at 1:05:32 AM UTC+2, Oscar Benjamin wrote: > Do you really need the canonical rotation or just a hash that is invariant > under rotations? Having that canonical rotation would make the code simpler and faster, probably, but a rotationally invariant hash is a good start.

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Oscar Benjamin
On Sun, 2 Aug 2015 00:05 Oscar Benjamin wrote: On Sat, 1 Aug 2015 22:06 Lukas Barth wrote: Nice idea! But I actually really need those "canonic rotations", since I'm hashing them somewhere. Do you really need the canonical rotation or just a hash that is invariant under rotations? I don't

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Oscar Benjamin
On Sat, 1 Aug 2015 22:06 Lukas Barth wrote: Nice idea! But I actually really need those "canonic rotations", since I'm hashing them somewhere. Do you really need the canonical rotation or just a hash that is invariant under rotations? I don't know of a solution to the former that is better

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Lukas Barth
On Sunday, August 2, 2015 at 12:32:25 AM UTC+2, Cameron Simpson wrote: > Fine. This also eliminates any solution which just computes a hash. Exactly. > Might I suggest instead simply starting with the leftmost element in the > first > list; call this elem0. Then walk the second list from 0 to

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Joel Goldstick
On Sat, Aug 1, 2015 at 6:51 PM, Lukas Barth wrote: > On Saturday, August 1, 2015 at 11:37:48 PM UTC+2, Emile van Sebille wrote: >> Well, it looks to me that I don't know what a 'canonical rotation' is -- > > That's because it is not defined. ;) > > I need a way to rotate one of these lists in a wa

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Lukas Barth
On Saturday, August 1, 2015 at 11:43:28 PM UTC+2, Paul Rubin wrote: > How large are these lists supposed to be? Potentially large. Not so large though that iterating them (multiple times) should be a problem. > [Concatenated Hashes] > > If the lists are very large that doesn't sound so great d

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Lukas Barth
On Saturday, August 1, 2015 at 11:37:48 PM UTC+2, Emile van Sebille wrote: > Well, it looks to me that I don't know what a 'canonical rotation' is -- That's because it is not defined. ;) I need a way to rotate one of these lists in a way so that it will produce the same output every time, regar

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Cameron Simpson
On 01Aug2015 14:24, Lukas Barth wrote: Perhaps I should clarify a bit: - I definitely need a "canonical rotation" - just a comparison result is not enough Fine. This also eliminates any solution which just computes a hash. - It does not matter what that rotation is. Starting with the smalle

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Paul Rubin
Lukas Barth writes: > - It does not matter what that rotation is. Starting with the smallest > element was just an idea by me, any rotation that can easily produced > will do. How large are these lists supposed to be? If they're (say) 5 elements, you could make the hash code consist of the conca

Re: Most pythonic way of rotating a circular list to a canonical point

2015-08-01 Thread Emile van Sebille
On 8/1/2015 2:24 PM, Lukas Barth wrote: Perhaps I should clarify a bit: - I definitely need a "canonical rotation" - just a comparison result is not enough Well, it looks to me that I don't know what a 'canonical rotation' is -- there's no wikipedia article and googling yields all sorts of

  1   2   3   4   5   >