Re: New module (written in C) for using the high-precision QD library

2015-08-01 Thread baruchel
Hi, Thank you for your answer.

Actually this is the third version I am writing for using the QD library; the 
first onPython using ctypes; the second one was in Cython; this one is in C. I 
don't claim being a Cython expert and maybe my Cython code was not optimal but 
I can say the C version is significantly quicker (and the binary is about half 
the size of the Cython binary).

I admit Cython is a great idea but for this very specific project I like rather 
using C: behind the scene thre is no need to interact with Python; data only 
relies on elementary C types, etc. I decided to migrate from Cython to C when I 
realized that I was merely embedding C in Cython almost all the time. 
Furthermore, the QD library is old, stable and simple. Once my module will be 
ready it won't evolve much; thus maintaining the project shouldn't be an issue.

I am using Python 2 with the people I am working with and I release my work as 
it; maybe I will rewrite it for Python 3 one day but it is not my immediate 
purpose.

Last day I started implementing the new type as dtype for Numpy; for the 
moment, I disabled this part in the code (because it is far to be really 
usable) but it can already be tried for having a short glance by uncommenting 
one line in the code. Best regards. tb.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: debugging during package development

2015-08-01 Thread Sebastian Luque
On Sat, 01 Aug 2015 15:30:34 +1000,
Ben Finney  wrote:

> Seb  writes:
>> With lots of debugging to do, the last thing I'd want is to worry
>> about the search path.

> Short answer: you need ‘python3 ./setup.py develop’.

> Medium-length answer: you need to add some infrastructure to get your
> project to the point where you can run ‘python3 ./setup.py develop’.

> Longer answer below.

>> So I've been searching for better ways to work, but I can't seem hit
>> the right keywords and come with all sorts of tangentially related
>> stuff.

> The Python module search path is an abstraction, with only a partial
> relationship to the location of modules files in the filesystem.

> The expectation is that a module (or a package of modules) will be
> *installed* to a location already in the module search path (with
> ‘python ./setup.py .

> This allows for cross-platform package management, especially on
> systems that don't have a working OS package manager. The trouble is
> that it does cause a significant learning curve for Python
> programmers, and is an ongoing sore point of Python.

>> I'm sure there must be some tool that sets up the development
>> environment when the package source is not on `sys.path`. Any advice
>> on this topic would be appreciated.

> What you need is to tell Distutils which Python modules form your
> project https://docs.python.org/3/library/distutils.html>.

> Once you've got a working ‘setup.py’ for your project, run ‘python3
> ./setup.py develop’ to allow your packages to be run in-place while
> you develop them.

This sounds exactly like what I was looking for.  I was growing tired of
doing 'python setup.py install', every time I wanted to debug something.
The subpackages' modules have inter-dependencies, which require the
whole package to be in `sys.path`.  Unfortunately, I have to stick with
Python 2.7...

Thank you,

-- 
Seb

-- 
https://mail.python.org/mailman/listinfo/python-list


Display a cleaned version of a XChat log

2015-08-01 Thread Cecil Westerhof
I discovered IRC again. ;-)

I want to use Python to display a cleaned version of the XChat logs.
One reason is that I keep channels open, and later want to look if
there was anything interesting. But most lines are status messages
that do not interest me and should be hidden from me.


A *VERY* rudimentary version is: http://pastebin.com/jD2c8GBV.

It gets rid of a lot of very uninteresting stuff, but also of a /me
line like:
Aug 01 15:44:14 * Cecil wants to use python to display cleaned xchat logs.

Is there a way to recognise that a line is a /me line?


I want to put it in a GUI of-course. A lot of stuff has to be added:
- selecting log files
- continuing where I left of
- displaying the message from a certain period
- automatically updating open channels
- notifying when there is a message for myself
- …

I am open for interesting feature to add and tips how to implement
things.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: My code won't work if I double click the saved file

2015-08-01 Thread Ben Iannitelli
> > On 29Jul2015 00:20, john  wrote:
> >> I have windows 8 running on my computer and I think I downloaded
> >> python 2 and 3 simultaneously or I think my computer has built in
> >> python 2 and I downloaded python 3.

John,

Sorry to back-track this conversation, but would you mind telling us some more 
about how you installed Python on your computer in the first place? 

For example, I run Windows 8.1 on my computer, and at the time that I installed 
Python I used the installer provided on the official Python site. When the 
wizard was done, I had a file called 'Python33' at the top level of C: (I 
haven't gotten around to Python 3.4 yet), so I know that I installed version 
3.3 at root level.

Everyone else: sorry if I messed up with this post somehow, it's my first time 
writing back to anyone on the newsletter.

-Ben I.
  -- 
https://mail.python.org/mailman/listinfo/python-list


Re: Improper Django Project error (solved)

2015-08-01 Thread Gary Roach

On 07/30/2015 11:15 PM, dieter wrote:

Gary Roach  writes:

Being new to Django and Python, I have two projects setup side by
side, each in it's own virtualenv wrapper.
The twr_project is running Django 1.7, python 2.7 and is set up to
duplicate the 'Tango With Rango' tutorial.
The archivedb project is running Django 1.8, python 2.7 and is my
actual project.

As this is more a "Django" (than a general "Python") question,
you might get better help in a "Django" mailing list/support forum.

Actually you are dead correct on that.



Your "subject" indicates that you likely see (somewhere)
the "Django" error message "Improper Django Project error".
Likely, you have corrupted you "Django" project setup.
Read about how "Django" projects must look like and fix your setup.
The real problem was that the settings.py files for Django 1.7 and 1.8 
have some very significant differences with the format of the TEMPLATES 
= [] tuple. So the  problem's solved --- sort of .

I am using Ninja-IDE as my IDE. I like it a lot.

At this point both projects are essentially identical with the
exception of name changes. The twr project work down to the first
template inclusion ( index.html ). The archivedb project refuses to
find the home.html template file. The system layout is exactly the
same.

I wiped the home.html file and attempted to re-install it but my IDE
gave the following error window:


Sorry, either settings file or virtualenv are missingthese are
required for Django Plugin to work in thepresent version, we are
working on fixing this.


I have virtualenv installed and active and the settings file is
present.

You should ask this question on a "Ninja-IDE" mailing list/support forum.
Ninja_IDE is just reporting an apparent problem. The real problem is 
that the browser can't find the file. A Django problem.




--
https://mail.python.org/mailman/listinfo/python-list


I'm a newbie and I'm stumped...

2015-08-01 Thread Dwight GoldWinde
Please help.

I am running Python 3.4 on my Mac mini, OS X 10.10.2, using Coderunner 2 as
my editor.

Here¹s the code:
#!/usr/bin/env python3
word = (input('Enter a word Œ))

When running this inside of Coderunner, I get the follow error, after
entering the word Œserendipity¹:

Enter a word serendipity

Traceback (most recent call last):

  File "test short.py", line 2, in 

word = (input('Enter a word '))

  File "", line 1, in 

NameError: name 'serendipity' is not defined






-- 
https://mail.python.org/mailman/listinfo/python-list


Which Python do I need for the below?

2015-08-01 Thread Joe Sanders
Hello- Which Python do I need for the below? with instructions please!

[cid:image001.png@01D0C9FD.677CDED0]



Kind Regards,

Gerald"Joe"Sanders
Customer Global Quality Accounts
951 SanDisk Drive, building #5 | Milpitas, CA 95035 USA | cell +1,512.818.7798
corporate + 1.408.801.1000 | 
joe.sand...@sandisk.com
[sd logo]






PLEASE NOTE: The information contained in this electronic mail message is 
intended only for the use of the designated recipient(s) named above. If the 
reader of this message is not the intended recipient, you are hereby notified 
that you have received this message in error and that any review, 
dissemination, distribution, or copying of this message is strictly prohibited. 
If you have received this communication in error, please notify the sender by 
telephone or e-mail (as shown above) immediately and destroy any and all copies 
of this message in your possession (whether hard copies or electronically 
stored copies).

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Javier
El martes, 21 de julio de 2015, 13:31:56 (UTC+2), Javier  escribió:
> Hello, I'm trying to understand and link asyncio with ordinary coroutines. 
> Now I just want to understand how to do this on asyncio:
> 
> 
> def foo():
> data = yield 8
> print(data)
> yield "bye"
> 
> def bar():
> f = foo()
> n = f.next()
> print(n)
> message = f.send("hello")
> print(message)
> 
> 
> What is the equivalent for coro.send("some data") in asyncio?
> 
> coro.send on an asyncio coroutine throws AssertionError: yield from wasn't 
> used with future.
> 
> 
> Thank you




Asyncio is a crazy headache! I realized that I can't use asyncio tcp servers 
with pickle! Asyncio is good as a concept but bad in real life. 

I think python's non blocking I/O is far from being something useful for 
developers till non-async code can invoke async code transparently. Duplicating 
all code/libs when you realize that something not fits asyncio is not a 
solution and even less a pythonic solution.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I'm a newbie and I'm stumped...

2015-08-01 Thread Joel Goldstick
On Thu, Jul 30, 2015 at 9:22 PM, Dwight GoldWinde  wrote:
> Please help.
>
> I am running Python 3.4 on my Mac mini, OS X 10.10.2, using Coderunner 2 as
> my editor.
>
> Here’s the code:
> #!/usr/bin/env python3
> word = (input('Enter a word ‘))
>
> When running this inside of Coderunner, I get the follow error, after
> entering the word ‘serendipity’:
>
> Enter a word serendipity
>
> Traceback (most recent call last):
>
>   File "test short.py", line 2, in 
>
> word = (input('Enter a word '))
>
>   File "", line 1, in 
>
> NameError: name 'serendipity' is not defined
>
>

The error you are getting is the error you would get if you were using
python 2.x.  So, are you sure you are running 3.4?  Can you go to a
shell and run it from command line?

also, use plain text to send mail
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I'm a newbie and I'm stumped...

2015-08-01 Thread Emile van Sebille

On 7/30/2015 6:22 PM, Dwight GoldWinde wrote:

I am running Python 3.4 on my Mac mini, OS X 10.10.2, using Coderunner 2 as
my editor.

Here¹s the code:
#!/usr/bin/env python3
word = (input('Enter a word Œ))

When running this inside of Coderunner, I get the follow error, after
entering the word Œserendipity¹:

Enter a word serendipity
Traceback (most recent call last):
   File "test short.py", line 2, in 
 word = (input('Enter a word '))
   File "", line 1, in 
NameError: name 'serendipity' is not defined


I'd look at which python is actually running (sys.version):

Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> word = (input('enter a word '))
enter a word test
>>>
emile@emile-OptiPlex-9010:~$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> word = (input('enter a word '))
enter a word test
Traceback (most recent call last):


Emile
  File "", line 1, in 
  File "", line 1, in 
NameError: name 'test' is not defined
>>>



--
https://mail.python.org/mailman/listinfo/python-list


Re: Which Python do I need for the below?

2015-08-01 Thread Emile van Sebille

On 7/29/2015 10:52 AM, Joe Sanders wrote:

Hello- Which Python do I need for the below? with instructions please!

[cid:image001.png@01D0C9FD.677CDED0]


Seeing that you have no responses yet I'm guessing most potential 
responders along with me are not opening attachments.


If the image is of screen output, please copy that as text and ask again 
-- you're more likely to get a response that way.


Emile




--
https://mail.python.org/mailman/listinfo/python-list


Re: Which Python do I need for the below?

2015-08-01 Thread Mark Lawrence

On 29/07/2015 18:52, Joe Sanders wrote:

Hello- Which Python do I need for the below? with instructions please!

Kind Regards,

*Gerald"Joe"Sanders*



For your 32 bit machine 
https://www.python.org/downloads/release/python-343/ "Windows x86 MSI 
installer" which is the last one listed.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Mark Lawrence

On 01/08/2015 17:07, Javier wrote:


Asyncio is a crazy headache! I realized that I can't use asyncio tcp servers 
with pickle! Asyncio is good as a concept but bad in real life.

I think python's non blocking I/O is far from being something useful for 
developers till non-async code can invoke async code transparently. Duplicating 
all code/libs when you realize that something not fits asyncio is not a 
solution and even less a pythonic solution.



I'll keep my eyes open for your solution on pypi as clearly you know 
better than the Python core developers.  Fully documented and tested of 
course.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Which Python do I need for the below?

2015-08-01 Thread Rustom Mody
On Saturday, August 1, 2015 at 10:07:37 PM UTC+5:30, Emile van Sebille wrote:
> On 7/29/2015 10:52 AM, Joe Sanders wrote:
> > Hello- Which Python do I need for the below? with instructions please!
> >
> > [cid:image001.png@01D0C9FD.677CDED0]
> 
> Seeing that you have no responses yet I'm guessing most potential 
> responders along with me are not opening attachments.

Most recipients are not receiving at all!
[I only see Emile's response. Evidently GG is deleting mails that have 
attachments]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Marko Rauhamaa
Javier :

> Asyncio is a crazy headache! I realized that I can't use asyncio tcp
> servers with pickle! Asyncio is good as a concept but bad in real
> life.
>
> I think python's non blocking I/O is far from being something useful
> for developers till non-async code can invoke async code
> transparently. Duplicating all code/libs when you realize that
> something not fits asyncio is not a solution and even less a pythonic
> solution.

After all these decades, we are still struggling to find the naturally
flowing paradigm for asynchronous programming. Different
approaches/libraries/frameworks don't usually mix well or at all.

First, I believe it has been a grave mistake to write a ton of utility
libraries that block. They make it easy to put together a prototype, but
before long you realize the mess they have led you to and the only way
out is a complete rewrite or a number of complicated adapters that drain
performance, hurt quality and don't really add true value.

Could asyncio be the basis of a de-facto Python way of doing
asynchronous programming? Maybe. GvR definitely has that intention.
However, I'm afraid the paradigm is quite unnatural. Essentially, it is
thread programming where blocking calls are replaced with funny syntax.
Most developers are familiar with multithreading, but they often are not
actively aware what functions are blocking. Reading from a socket is
blocking. Writing to a socket is blocking as well. Is file I/O blocking?
Is database access blocking? Is socket.getaddrinfo() blocking?

A function may be nonblocking in one release of a package but might then
become blocking in the next release.

I'm an advocate of the "callback hell" together with clearly expressed
finite state machines. They are super easy to understand. They lead to
very complicated code but the complications can be analyzed and debugged
based on the elementary knowledge. Also, you don't need a complicated
framework for it. The only thing missing from select.epoll() is timers,
but timers are not all that hard to implement (especially if you had an
a balanced tree implementation at your disposal).

Still, even the select.epoll() method requires callback implementations
of the different protocols and databases.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Javier
El sábado, 1 de agosto de 2015, 19:19:00 (UTC+2), Marko Rauhamaa  escribió:
> Javier :
> 
> > Asyncio is a crazy headache! I realized that I can't use asyncio tcp
> > servers with pickle! Asyncio is good as a concept but bad in real
> > life.
> >
> > I think python's non blocking I/O is far from being something useful
> > for developers till non-async code can invoke async code
> > transparently. Duplicating all code/libs when you realize that
> > something not fits asyncio is not a solution and even less a pythonic
> > solution.
> 
> After all these decades, we are still struggling to find the naturally
> flowing paradigm for asynchronous programming. Different
> approaches/libraries/frameworks don't usually mix well or at all.
> 
> First, I believe it has been a grave mistake to write a ton of utility
> libraries that block. They make it easy to put together a prototype, but
> before long you realize the mess they have led you to and the only way
> out is a complete rewrite or a number of complicated adapters that drain
> performance, hurt quality and don't really add true value.
> 
> Could asyncio be the basis of a de-facto Python way of doing
> asynchronous programming? Maybe. GvR definitely has that intention.
> However, I'm afraid the paradigm is quite unnatural. Essentially, it is
> thread programming where blocking calls are replaced with funny syntax.
> Most developers are familiar with multithreading, but they often are not
> actively aware what functions are blocking. Reading from a socket is
> blocking. Writing to a socket is blocking as well. Is file I/O blocking?
> Is database access blocking? Is socket.getaddrinfo() blocking?
> 
> A function may be nonblocking in one release of a package but might then
> become blocking in the next release.
> 
> I'm an advocate of the "callback hell" together with clearly expressed
> finite state machines. They are super easy to understand. They lead to
> very complicated code but the complications can be analyzed and debugged
> based on the elementary knowledge. Also, you don't need a complicated
> framework for it. The only thing missing from select.epoll() is timers,
> but timers are not all that hard to implement (especially if you had an
> a balanced tree implementation at your disposal).
> 
> Still, even the select.epoll() method requires callback implementations
> of the different protocols and databases.
> 
> 
> Marko

I agree with you, Marko, I came from callbacks too. So, if GvR wants the yield 
from become de-facto, does it mean that all python libraries will evolve to 
become asyncio friendly libs? or that I have to write my own library so I can 
use existing libraries like pickle? I think "callback hell" is "peccata minuta" 
compared with "yield from hell".



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Javier
El sábado, 1 de agosto de 2015, 18:45:17 (UTC+2), Mark Lawrence  escribió:
> On 01/08/2015 17:07, Javier wrote:
> >
> > Asyncio is a crazy headache! I realized that I can't use asyncio tcp 
> > servers with pickle! Asyncio is good as a concept but bad in real life.
> >
> > I think python's non blocking I/O is far from being something useful for 
> > developers till non-async code can invoke async code transparently. 
> > Duplicating all code/libs when you realize that something not fits asyncio 
> > is not a solution and even less a pythonic solution.
> >
> 
> I'll keep my eyes open for your solution on pypi as clearly you know 
> better than the Python core developers.  Fully documented and tested of 
> course.
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Don't be rascal, friend. Nobody thinks that self is better than core 
developers, and personaly I don't think I am better than anybody, but, I have 
my own opinion.
The fact that the core team is better at python coding and compilers than me 
does not mean that her implementation fits my needs/opinion.

I dont like the current event loop implementation (plus yield from): 
- It forces me to use beta libraries for doing something that another 
production ready library already does, 
- I can't use one of the most awesome python features: yielding between 
generators and coroutines
- As you said, I'm not as smart as they are but I thought python is for 
everybody, not only for them. Should I ask them how can I use pickle with 
streamreader? I think it would be better if it would become trivial.


I read PEPs. I don't imagine a good users community if all of us would have to 
read the pythons source code to understand how to use new features or rewrite a 
new implementation proposal to be allowed to tell our opinion, as you claims, 

I would like that all the code would run on event loop, but till then I just 
believe that event loop should be a native feature, not a python hack. I 
believe that we should be able to call asyncio functions without doing "yield 
from" through all the stack. I believe that It's possible an implementation 
that allows generators for processing data streams and that allows to mix 
classic code with loop code.

And finally I claim a place for not super-level pythoners that want to talk 
about features improvement without being asked for a reference implementation, 
each of us have our own role.

:)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Marko Rauhamaa
Javier :

> I agree with you, Marko, I came from callbacks too. So, if GvR wants
> the yield from become de-facto, does it mean that all python libraries
> will evolve to become asyncio friendly libs? or that I have to write
> my own library so I can use existing libraries like pickle? I think
> "callback hell" is "peccata minuta" compared with "yield from hell".

I guess GvR expects Twisted, Tornado et al jump on the asyncio
bandwagon.

Myself, I would like the lowest-level I/O transactions to be broken into
their atomic, nonblocking primitives:

request   optional: update(s), cancellation
response  optional: preliminary response(s)

Those primitives can be then used to put together asyncio coroutines or
blocking functions for multithreading. Or they can be used as-is in
classical callback programming.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I'm a newbie and I'm stumped...

2015-08-01 Thread Terry Reedy

On 7/30/2015 9:22 PM, Dwight GoldWinde wrote:

Please help.

I am running Python 3.4 on my Mac mini, OS X 10.10.2, using Coderunner 2
as my editor.

Here’s the code:
#!/usr/bin/env python3
word = (input('Enter a word ‘))


The outer parentheses are not needed.
Ditto to the other comments, especially about not using html and the 
unicode quote that causes SyntaxError.


--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Marko Rauhamaa
Javier :

> El sábado, 1 de agosto de 2015, 18:45:17 (UTC+2), Mark Lawrence  escribió:
>> clearly you know better than the Python core developers
>
> Nobody thinks that self is better than core developers, and personaly
> I don't think I am better than anybody, but, I have my own opinion.

It is odd how an engineering forum like this one so often judges ideas
based on the pedigree of the participants rather than objective
technical arguments.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Mark Lawrence

On 01/08/2015 19:38, Marko Rauhamaa wrote:

Javier :


El sábado, 1 de agosto de 2015, 18:45:17 (UTC+2), Mark Lawrence  escribió:

clearly you know better than the Python core developers


Nobody thinks that self is better than core developers, and personaly
I don't think I am better than anybody, but, I have my own opinion.


It is odd how an engineering forum like this one so often judges ideas
based on the pedigree of the participants rather than objective
technical arguments.


Marko



What I find odd is that the bleating and whinging comes long after the 
PEP process has finished and the code is already in production. 
Wouldn't it be easier for everybody all around to sort this out right at 
the start of the process?


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: GvR Europython keynote described on lwn.net

2015-08-01 Thread Rick Johnson
On Saturday, August 1, 2015 at 12:45:45 AM UTC-5, Steven D'Aprano wrote:

> > Yep, even the BDFL is actively developing in 2.7! He's no fool.
> 
> Of course not. Dropbox pay him to work on their systems,
> and he wants to keep his job.

Thanks for confirming my point that Python3 is not worth
developing with for at least the next five years.

> Are you aware that Dropbox are heavily pushing for static
> type hints in Python 3 as a prerequisite for them porting
> their masses of Python 2 code to Python 3? 

Well then, i hope they are ready to wait at least 10 years
before adopting Python3, because it will take that long to
work out all the kinks! Of course, with the cloud service
wars heating up, no one can be sure how long any of them
will survive. Web technology is moving much faster than 
Python.

> That's one of the motives for the masses of effort put
> into PEP 484, and its support PEPs, 482 and 483:

I do find it flattering that many of my ideas regarding
Python have been implemented: (1) It was me who recommended
"optional type checking" way back around 2008 (Heck, you
even agreed that it would be a good idea, but at the time, a
moratorium was preventing new features) (2) The fresher look
of Python.org is a result of my suggestions (3) The
interactive online console was my idea to compete with the
Ruby equivalent (4) I have pestered tutorial owners to
upgrade their tutorials to py3 compatibility, and many did!
(5) and last but not least, my courage to face down the
trolls has given courage to the shadow lurkers, who now
participate in open discussions on this list, and some have
even moved over to more dangerous grounds like Python-ideas.
All in all, my presence here has resulted in a fundamental
transformation of this group, and this language.

> As I understand it, Dropbox are paying Guido to work on
> static type hinting for Python, with the emphasis on
> proving program correctness, not speed, specifically
> because they want a big positive gain for moving to Python
> 3.

Well it's true that reducing bugs should always be
preferable to speed, but once the error potentials are
reduced, Dropbox will no doubt pivot to performance
enhancements -- this is the nature of our universe.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Javier
El sábado, 1 de agosto de 2015, 20:46:49 (UTC+2), Mark Lawrence  escribió:
> On 01/08/2015 19:38, Marko Rauhamaa wrote:
> > Javier :
> >
> >> El sábado, 1 de agosto de 2015, 18:45:17 (UTC+2), Mark Lawrence  escribió:
> >>> clearly you know better than the Python core developers
> >>
> >> Nobody thinks that self is better than core developers, and personaly
> >> I don't think I am better than anybody, but, I have my own opinion.
> >
> > It is odd how an engineering forum like this one so often judges ideas
> > based on the pedigree of the participants rather than objective
> > technical arguments.
> >
> >
> > Marko
> >
> 
> What I find odd is that the bleating and whinging comes long after the 
> PEP process has finished and the code is already in production. 
> Wouldn't it be easier for everybody all around to sort this out right at 
> the start of the process?
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence


I think so too, Mark, but I talk about it when I have used it. I came from 
blocking IO development. But isn't this a live language?

Well! let's forget all this and let's work with python 3.4 :)


My intention now is to use the asyncio.StreamReader passed as argument to the 
asyncio.start_server callback to read objects serialized with pickle. The 
problems are that pickle cant read from it (because dont yield from the full 
stack) and that I don't know the exact length of each serialized object, so I 
can't extract data manually.

Knows anybody the steps to follow?

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Marko Rauhamaa
Mark Lawrence :

> On 01/08/2015 19:38, Marko Rauhamaa wrote:
>> It is odd how an engineering forum like this one so often judges
>> ideas based on the pedigree of the participants rather than objective
>> technical arguments.
>
> What I find odd is that the bleating and whinging comes long after the
> PEP process has finished and the code is already in production.
> Wouldn't it be easier for everybody all around to sort this out right
> at the start of the process?

Err...

 * You are free to say you don't like something, even aspects of Python.

 * Criticism can be well-founded even if the critic wasn't around when
   the developers put the spec together.

 * Most Python users (as in 99.999% of them) aren't Python developers.
   That's as it should be.

 * Even if critics had been around and voiced their criticism, asyncio
   probably would have been introduced.

 * Even if somebody doesn't like an idea, somebody else might love it.

Are you happy with asyncio, Mark?


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Marko Rauhamaa
Javier :

> My intention now is to use the asyncio.StreamReader passed as argument
> to the asyncio.start_server callback to read objects serialized with
> pickle. The problems are that pickle cant read from it (because dont
> yield from the full stack) and that I don't know the exact length of
> each serialized object, so I can't extract data manually.
>
> Knows anybody the steps to follow?

You probably need to frame your pickled encoding. A simple thing would
be to use struct.pack/unpack to encode the length of the pickle encoding
in front of the pickle encoding. When decoding, you first read out the
length, then the pickle encoding, and finally you unpickle the payload.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Mark Lawrence

On 01/08/2015 20:09, Marko Rauhamaa wrote:

Mark Lawrence :


On 01/08/2015 19:38, Marko Rauhamaa wrote:

It is odd how an engineering forum like this one so often judges
ideas based on the pedigree of the participants rather than objective
technical arguments.


What I find odd is that the bleating and whinging comes long after the
PEP process has finished and the code is already in production.
Wouldn't it be easier for everybody all around to sort this out right
at the start of the process?


Err...

  * You are free to say you don't like something, even aspects of Python.

  * Criticism can be well-founded even if the critic wasn't around when
the developers put the spec together.

  * Most Python users (as in 99.999% of them) aren't Python developers.
That's as it should be.

  * Even if critics had been around and voiced their criticism, asyncio
probably would have been introduced.

  * Even if somebody doesn't like an idea, somebody else might love it.

Are you happy with asyncio, Mark?


Marko



Yes.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Mark Lawrence

On 01/08/2015 20:07, Javier wrote:

El sábado, 1 de agosto de 2015, 20:46:49 (UTC+2), Mark Lawrence  escribió:

Well! let's forget all this and let's work with python 3.4 :)



Please keep up, 3.5 is in beta and the current default will be 3.6 :)

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Which Python do I need for the below?

2015-08-01 Thread Emile van Sebille

On 8/1/2015 10:09 AM, Rustom Mody wrote:

On Saturday, August 1, 2015 at 10:07:37 PM UTC+5:30, Emile van Sebille wrote:



Seeing that you have no responses yet I'm guessing most potential
responders along with me are not opening attachments.


Most recipients are not receiving at all!
[I only see Emile's response. Evidently GG is deleting mails that have 
attachments]


Yet another side effect of the koolaid.  :(

Emile


--
https://mail.python.org/mailman/listinfo/python-list


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

2015-08-01 Thread Lukas Barth
Hi!

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 minimum element, 
find its index, then use mylist[:index] + mylist[index:], i.e. the minimum 
element will always be at the beginning.

But say I have [0,1,0,2,0,3]. I can in fact guarantee that no *pair* will 
appear 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 for a (seemingly?) simple problem. Is there 
a nice, pythonic way to do this?

Thanks for enlightening me!

Lukas
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-08-01 Thread Emile van Sebille

On 8/1/2015 1:34 PM, Lukas Barth wrote:

Hi!

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 minimum element, 
find its index, then use mylist[:index] + mylist[index:], i.e. the minimum 
element will always be at the beginning.

But say I have [0,1,0,2,0,3]. I can in fact guarantee that no *pair* will 
appear 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 for a (seemingly?) simple problem. Is there 
a nice, pythonic way to do this?


Well, I have not understood the problem for such a seemingly simple one.  :)

Is the problem to determine if one list of circular numbers 'matches' 
another one despite rotation status?  If so, I'd do something like:


def matchcircularlists(L1,L2):
#return True if L1 is a rotation variant of L2
return "".join(map(str,L1)) in "".join(map(str,L2+L2))

Emile




--
https://mail.python.org/mailman/listinfo/python-list


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

2015-08-01 Thread Marko Rauhamaa
Lukas Barth :

> 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 minimum
> element, find its index, then use mylist[:index] + mylist[index:], i.e.
> the minimum element will always be at the beginning.
>
> But say I have [0,1,0,2,0,3]. I can in fact guarantee that no *pair*
> will appear 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 for a (seemingly?) simple problem.
> Is there a nice, pythonic way to do this?

How about:


def circularly_equal(l1, l2):
length = len(l1)
if length != len(l2):
return False
twice = l1 + l1
for i in range(length):
if twice[i:i + length] == l2:
return True
return False



Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


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 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
> for i in range(length):
> if twice[i:i + length] == l2:
> return True
> return False
> 

Nice idea! But I actually really need those "canonic rotations", since I'm 
hashing them somewhere..

Lukas

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I'm a newbie and I'm stumped...

2015-08-01 Thread Paulo da Silva
On 31-07-2015 02:22, Dwight GoldWinde wrote:
> Please help.
> 
> I am running Python 3.4 on my Mac mini, OS X 10.10.2, using Coderunner 2
> as my editor.
> 
> Here’s the code:
> #!/usr/bin/env python3
> word = (input('Enter a word ‘))

As is here, this code should raise a syntax error message like
SyntaxError: EOL while scanning string literal

On the right side of *Enter a word* you have to use the same single
quote "'" as that on the left side.
Besides this, the code must work assigning your string input to variable
"word".
The outer "()" are unnecessary but cause no hurt.


-- 
https://mail.python.org/mailman/listinfo/python-list


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 10:51:03 PM UTC+2, Emile van Sebille wrote:
> Is the problem to determine if one list of circular numbers 'matches' 
> another one despite rotation status?  If so, I'd do something like:

Well.. no. I actually really need this "canonical" rotation, since I'm hashing 
this, returning it to other parts of the software, etc..

But thanks!

Lukas
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-08-01 Thread Lukas Barth
Perhaps I should clarify a bit:

- I definitely need a "canonical rotation" - just a comparison result is not 
enough

- 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.
-- 
https://mail.python.org/mailman/listinfo/python-list


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:12 PM, Lukas Barth wrote:

On Saturday, August 1, 2015 at 10:51:03 PM UTC+2, Emile van Sebille wrote:

Is the problem to determine if one list of circular numbers 'matches'
another one despite rotation status?  If so, I'd do something like:


Well.. no. I actually really need this "canonical" rotation, since I'm hashing 
this, returning it to other parts of the software, etc..


Then I'm not sure that I understand what exactly the problem is.  Can 
you state it in terms of what you start with and what you expect to get?


The only clue I see is "Now I want to rotate these to a well defined 
status, so that I can can compare them."  Which is where I understood 
you to want to compare them.


You might check at http://www.catb.org/esr/faqs/smart-questions.html

Emile


--
https://mail.python.org/mailman/listinfo/python-list


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 
specialized math related articles.


Sorry,



--
https://mail.python.org/mailman/listinfo/python-list


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 concatenated hashes of each
of the 5 rotations, or maybe a Bloom filter on those hashes.  Then to do
a lookup, hash your target list and see if it appears in the table.

If the lists are very large that doesn't sound so great due to storage
requirements..
-- 
https://mail.python.org/mailman/listinfo/python-list


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 smallest element 
was just an idea by me, any rotation that can easily produced will do.


That's a fine way to start, but more work than is needed.

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 len(list2). If that 
element equals elem0, _then_ compare the list at that point as you suggested.


Is there an aspect of this which doesn't work?

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


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, regardless of what the input rotation was.

Example:

[0,1,2,3,4] => [0,1,2,3,4]
[2,3,4,0,1] => [0,1,2,3,4]
[3,4,0,1,2] => [0,1,2,3,4]
...

It doesn't have to be "[0,1,2,3,4]", it can just as well be [2,3,4,1,0], as 
long as it's always the same.

Did that make it clearer?

Thanks a lot,

Lukas
-- 
https://mail.python.org/mailman/listinfo/python-list


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 due to storage
> requirements..

Also, that still doesn't compute that one "canonical ordering"...

Thanks,

Lukas
-- 
https://mail.python.org/mailman/listinfo/python-list


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 way so that it will produce 
> the same output every time, regardless of what the input rotation was.
>
> Example:
>
> [0,1,2,3,4] => [0,1,2,3,4]
> [2,3,4,0,1] => [0,1,2,3,4]
> [3,4,0,1,2] => [0,1,2,3,4]
> ...
>
> It doesn't have to be "[0,1,2,3,4]", it can just as well be [2,3,4,1,0], as 
> long as it's always the same.
>
> Did that make it clearer?
>
> Thanks a lot,
>
> Lukas

I've been following along.  The early suggestion to double one list
and see if the second list is in the double list seems to prove they
are the same -- one is just rotated to a different starting point.  I
don't understand the term 'canonical' in this example, but what is it
that the solution given doesn't provide for you?

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


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 len(list2). If 
> that 
> element equals elem0, _then_ compare the list at that point as you suggested.
>
> Is there an aspect of this which doesn't work?

The problem is: When I compute a hash over list1 (in its canonical form), I do 
not yet know list2 (or list3, or listN...) against which they will be compared 
later..
 
Lukas
-- 
https://mail.python.org/mailman/listinfo/python-list


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 than what you
already have but the latter is an easier problem: Find the minimum element.
Compute the hash of the rotated sequence for each occurrence of the least
common element. Add those hashes together or multiply them or some similar
operation. That's your hash that will compare equal for any rotation of a
given sequence.

--
Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


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 know of a solution to the former that is better than what you
already have but the latter is an easier problem: Find the minimum element.
Compute the hash of the rotated sequence for each occurrence of the least
common element. Add those hashes together or multiply them or some similar
operation. That's your hash that will compare equal for any rotation of a
given sequence.



I said "least common" but meant "minimum". A potential improvement would be
to use the minimum element of the least common elements instead of just the
minimum element. Presumably in most cases there would be at least some
unique elements so if you take the minimum of those then you would only
need to compute 1 sequence hash. Maybe this is unnecessary though.

--
Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Chris Angelico
On Sun, Aug 2, 2015 at 5:33 AM, Mark Lawrence  wrote:
> Please keep up, 3.5 is in beta and the current default will be 3.6 :)

Not sure what you mean by "default", but I've been running 3.6.0a0 for
a while now :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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.

> I don't know of a solution to the former that is better than what you already 
> have but the latter is an easier problem: Find the minimum element. Compute 
> the hash of the rotated sequence for each occurrence of the least common 
> element. Add those hashes together or multiply them or some similar 
> operation. That's your hash that will compare equal for any rotation of a 
> given sequence.

Yes, that sounds like an idea if I decide to just go with the hash. Thanks!

Lukas
-- 
https://mail.python.org/mailman/listinfo/python-list


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 these lists in a way so that it will produce 
> the same output every time, regardless of what the input rotation was.
> 
> Example:
> 
> [0,1,2,3,4] => [0,1,2,3,4]
> [2,3,4,0,1] => [0,1,2,3,4]
> [3,4,0,1,2] => [0,1,2,3,4]
> ...
> 
> It doesn't have to be "[0,1,2,3,4]", it can just as well be [2,3,4,1,0], as 
> long as it's always the same.
> 
> Did that make it clearer?
> 

Is this "canoncal rotation" different than sorting. I think you mean it to be, 
but these examples all look like sorting to me.

I think the collections.deque object has a rotate method, and rotating through 
the possibilities looking for matches may work, or take any deque, rotate so 
the minimum value is at the first place in the deque, and then compare.

Or am I not understanding what you mean?

Josh

-- 
https://mail.python.org/mailman/listinfo/python-list


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

2015-08-01 Thread wolfram.hinderer--- via Python-list
Am Samstag, 1. August 2015 22:34:44 UTC+2 schrieb Lukas Barth:
> Hi!
> 
> 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 minimum element, 
> find its index, then use mylist[:index] + mylist[index:], i.e. the minimum 
> element will always be at the beginning.
> 
> But say I have [0,1,0,2,0,3]. I can in fact guarantee that no *pair* will 
> appear 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 for a (seemingly?) simple problem. Is 
> there a nice, pythonic way to do this?

It's not that much code (unless I misunderstood your question):

def f(A):
i = min(range(len(A)-1), key=lambda i: A[i:i+2])
if [A[-1], A[0]] < A[i:i+2]:
i = len(A) - 1
return A[i:] + A[:i]

Examples:

f([0,2,0,1,0,3,0])
Out[23]: [0, 0, 2, 0, 1, 0, 3]

f([2,3,4,0,1])
Out[24]: [0, 1, 2, 3, 4]


Wolfram
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Javier
El sábado, 1 de agosto de 2015, 21:15:07 (UTC+2), Marko Rauhamaa  escribió:
> Javier :
> 
> > My intention now is to use the asyncio.StreamReader passed as argument
> > to the asyncio.start_server callback to read objects serialized with
> > pickle. The problems are that pickle cant read from it (because dont
> > yield from the full stack) and that I don't know the exact length of
> > each serialized object, so I can't extract data manually.
> >
> > Knows anybody the steps to follow?
> 
> You probably need to frame your pickled encoding. A simple thing would
> be to use struct.pack/unpack to encode the length of the pickle encoding
> in front of the pickle encoding. When decoding, you first read out the
> length, then the pickle encoding, and finally you unpickle the payload.
> 
> 
> Marko


Great! it works! I could not find a way to send an integer with fixed length, 
struct.pack/unpack does the job perfectly.

Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


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.  Then walk the second list from 0 to len(list2). If that
element equals elem0, _then_ compare the list at that point as you suggested.

Is there an aspect of this which doesn't work?


The problem is: When I compute a hash over list1 (in its canonical form), I do 
not yet know list2 (or list3, or listN...) against which they will be compared 
later..


Are you collating on the hash before doing anything? I think I may have missed 
part of your problem specification. I thought you had a list and needed to 
recognise other lists which were rotations of it, and possibly return them pre 
or post rotation.


If you're hashing the first list I'm presuming you're using that to allocate it 
to a bucket (even notionally) to avoid wasting time comparing it against wildly 
different lists, just compare against likely matches? Or what?


If that is the case, choose a hash function that: is affected by the list 
length and is independent of the list item ordering. That is easy to arrange 
and is guarrenteed that a rotated version of the list will have the same hash.


Trivial hash function: sum(list1)+len(list1)

It is simple and will work. It has downsides that might be a problem in other 
contexts, but since I don't know what you're using the hash for then I can 
address that.


Remember, hash functions are arbitrary - they just have to obey particular 
constraints dictated by your needs.


Comments?

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


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 hash function on a list of that element type.
That should give the same hash value for any rotation of the list.
It generalizes in the obvious way to other lengths.
-- 
https://mail.python.org/mailman/listinfo/python-list


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 this works though.
-- 
https://mail.python.org/mailman/listinfo/python-list


__main__ vs official module name: distinct module instances

2015-08-01 Thread Cameron Simpson

Hi All,

Maybe this should be over in python-ideas, since there is a proposal down the 
bottom of this message. But first the background...


I've just wasted a silly amount of time debugging an issue that really I know 
about, but had forgotten.


I have a number of modules which include a main() function, and down the bottom 
this code:


 if __name__ == '__main__':
   sys.exit(main(sys.argv))

so that I have a convenient command line tool if I invoke the module directly.  
I typically have tiny shell wrappers like this:


 #!/bin/sh
 exec python -m cs.app.maildb -- ${1+"$@"}

In short, invoke this module as a main program, passing in the command line 
arguments. Very useful.


My problem?

When invoked this way, the module cs.app.maildb that is being executed is 
actually the module named "__main__". If some other piece of code imports 
"cs.app.maildb" they get a _different_ instance of the module. In the same 
program! And how did it cause me trouble? I am monkey patching my module for 
debug purposes, and that monkey patcher imports the module by name. So I was 
monkey patching cs.app.maildb, and _not_ patching __main__. And thus not seeing 
any effect from the patch.


I realise that having __name__ == '__main__' at all almost implies this effect.  
I am not sure it needs to.


The Proposal:

What are the implications of modifying the python invocation:

 python -m cs.app.maildb

to effectively do this (Python pseudo code):

 M = importlib.import("cs.app.maildb")
 M.__name__ = '__main__'
 sys.modules['__main__'] = M

i.e. import the module by name, but bind it to _both_ "cs.app.maildb" and 
"__main__" in sys.modules. And of course hack .__name__ to support the standard 
boilerplate.


This would save some confusion when the module is invoked from the python 
command line and also imported by the code; it is not intuitive that those two 
things give you distinct module instances.


Aside from the module's .__name__ being '__main__' even when accessed by the 
code as cs.app.maildb, are there other implications to such a change that would 
break real world code?


Cheers,
Cameron Simpson 

The reasonable man adapts himself to the world; the unreasonable one persists
in trying to adapt the world to himself.  Therefore all progress depends
on the unreasonable man.- George Bernard Shaw
--
https://mail.python.org/mailman/listinfo/python-list


Re: __main__ vs official module name: distinct module instances

2015-08-01 Thread Chris Angelico
On Sun, Aug 2, 2015 at 1:53 PM, Cameron Simpson  wrote:
> What are the implications of modifying the python invocation:
>
>  python -m cs.app.maildb
>
> to effectively do this (Python pseudo code):
>
>  M = importlib.import("cs.app.maildb")
>  M.__name__ = '__main__'
>  sys.modules['__main__'] = M
>
> i.e. import the module by name, but bind it to _both_ "cs.app.maildb" and
> "__main__" in sys.modules. And of course hack .__name__ to support the
> standard boilerplate.
>
> This would save some confusion when the module is invoked from the python
> command line and also imported by the code; it is not intuitive that those
> two things give you distinct module instances.
>
> Aside from the module's .__name__ being '__main__' even when accessed by the
> code as cs.app.maildb, are there other implications to such a change that
> would break real world code?

That's the one implication that comes to mind. It breaks the invariant
that "import X; X.__name__" should be the string form of X. But does
anything ever actually depend on that, or do things depend on the
weaker requirement that X.__name__ should be something which you can
import to get back a reference to X?

I'd support this proposal. I'm not seeing any glaring problems, and it
does have the potential to prevent bizarre problems. It would still
want to be a non-recommended course of action, though, as the change
won't (presumably) be backported - so any code that assumes that
importing its main file gives the same module as __main__ will
silently do the wrong thing on Python 2.7.

Toss it out onto -ideas and see what bounces back!

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: My code won't work if I double click the saved file

2015-08-01 Thread Rustom Mody
On Saturday, August 1, 2015 at 9:28:56 PM UTC+5:30, Ben Iannitelli wrote:
> Everyone else: sorry if I messed up with this post somehow, it's my first 
> time writing back to anyone on the newsletter.

Its fine
Thanks for trying to help

[Just try to (hard)break your lines at around 72 columns/chars as some people 
use last millenium mail-clients]
-- 
https://mail.python.org/mailman/listinfo/python-list


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
>> for i in range(length):
>> if twice[i:i + length] == l2:
>> return True
>> return False
>> 
>
> Nice idea! But I actually really need those "canonic rotations", since
> I'm hashing them somewhere..

First, lists can't be used as dict keys, but that minor point is easy to
overcome.

Secondly, a hash doesn't need to be unique, it's enough for it to be
discerning. So you could, for example, choose:

   sum([ hash(x) for x in L ]) + hash(sum(L))

That doesn't discern any permutations, but depending on your application
might be good enough.

That way, you use the "pretty good" hash function together with the
circular equality test and you won't be needing any canonical
representation for the key.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list