Re: Sudoku solver

2015-03-30 Thread Christian Gollwitzer

Am 30.03.15 um 08:50 schrieb Ian Kelly:

On Sun, Mar 29, 2015 at 12:03 PM, Marko Rauhamaa  wrote:

Be careful with the benchmark comparisons. Ian's example can be solved
with the identical algorithm in eight different ways (four corners, left
or right). I ran the example with my recent Python solver and got these
times in the eight cases:

 884   s
   2.5 s
  13   s
 499   s
   5.9 s
 128   s
1360   s
  36   s


That sounds to me like either a transcription error was made to the
puzzle at some point, or there's something wrong with your solver. The
whole point of that example was that it was a puzzle with the minimum
number of clues to specify a unique solution.


I think Marko meant, that if he creates symmetrically equivalent puzzles 
by rotating / mirroring the grid, he gets vastly different execution 
times, but ends up with the same solution. This is not surprising. The 
brute force algorithm branches into different solutions first, then, 
because it fills the grid always in the same order. To compare different 
solvers, it would indeed make sense to average over all symmetric 
solutions to make sure that no solver wins the competition by sheer 
luck, i.e. choosing the right path immediately.


Christian

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


Re: Sudoku solver

2015-03-30 Thread Ian Kelly
On Mon, Mar 30, 2015 at 1:13 AM, Christian Gollwitzer  wrote:
> Am 30.03.15 um 08:50 schrieb Ian Kelly:
>>
>> On Sun, Mar 29, 2015 at 12:03 PM, Marko Rauhamaa  wrote:
>>>
>>> Be careful with the benchmark comparisons. Ian's example can be solved
>>> with the identical algorithm in eight different ways (four corners, left
>>> or right). I ran the example with my recent Python solver and got these
>>> times in the eight cases:
>>>
>>>  884   s
>>>2.5 s
>>>   13   s
>>>  499   s
>>>5.9 s
>>>  128   s
>>> 1360   s
>>>   36   s
>>
>>
>> That sounds to me like either a transcription error was made to the
>> puzzle at some point, or there's something wrong with your solver. The
>> whole point of that example was that it was a puzzle with the minimum
>> number of clues to specify a unique solution.
>
> I think Marko meant, that if he creates symmetrically equivalent puzzles by
> rotating / mirroring the grid, he gets vastly different execution times, but
> ends up with the same solution.

That makes sense, but it is true for all puzzles that there are eight
possible orientations (since it's impossible for a puzzle solution to
be symmetric), and the wording made it sound like he was describing a
property specific to the puzzle that I posted.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cgi parse_qs still exists?

2015-03-30 Thread Mark Lawrence

On 30/03/2015 07:48, dieter wrote:

Mark Lawrence  writes:


This has been marked for deprecation since at least 2.6 but is still
in the 3.5 code base.  Does anybody know if this is by accident or
design? If the former I'll happily raise an issue to get it removed
unless somebody beats me to it.


I am using "cgi.parse_qs" - and I find it very helpful.

Thus, I would be sad if it went away -- unless the library would
provide an alternative.



From https://docs.python.org/3/library/cgi.html "This function is 
deprecated in this module. Use urllib.parse.parse_qs() instead. It is 
maintained here only for backward compatibility."


--
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: Sudoku solver

2015-03-30 Thread Dave Angel

On 03/30/2015 03:29 AM, Ian Kelly wrote:

On Mon, Mar 30, 2015 at 1:13 AM, Christian Gollwitzer  wrote:

Am 30.03.15 um 08:50 schrieb Ian Kelly:


On Sun, Mar 29, 2015 at 12:03 PM, Marko Rauhamaa  wrote:


Be careful with the benchmark comparisons. Ian's example can be solved
with the identical algorithm in eight different ways (four corners, left
or right). I ran the example with my recent Python solver and got these
times in the eight cases:

  884   s
2.5 s
   13   s
  499   s
5.9 s
  128   s
 1360   s
   36   s



That sounds to me like either a transcription error was made to the
puzzle at some point, or there's something wrong with your solver. The
whole point of that example was that it was a puzzle with the minimum
number of clues to specify a unique solution.


I think Marko meant, that if he creates symmetrically equivalent puzzles by
rotating / mirroring the grid, he gets vastly different execution times, but
ends up with the same solution.


That makes sense, but it is true for all puzzles that there are eight
possible orientations (since it's impossible for a puzzle solution to
be symmetric), and the wording made it sound like he was describing a
property specific to the puzzle that I posted.



But for some puzzles, the 8 timings may be much closer.  Or maybe even 
further apart.


Incidentally, there are many other variants of the same puzzle that 
might matter, beyond those 8.


The digits can all be crypto'ed   Like replace all 4 with 8, etc. 
Probably won't matter for any realistic algorithm.


The columns can be reordered, in at least some ways.  For example, if 
the first and second columns are swapped, it's a new puzzle, equivalent. 
 Likewise certain rows.


The relationship between row, column and box can be rearranged.  Some of 
these are already covered by the rotations proposed earlier, where for a 
90 degree rotate, row becomes column and column becomes row.  But in a 
similar way each box could become a column, and so on.


All of these rearrangeements will change the order that an algorithm 
might choose to examine things, and thus affect timings (but not the 
solution).


When I made my own solver years ago, I considered the puzzle to have 9 
columns, 9 rows, and 9 boxes.  So these 27 lists of 9 could be analyzed. 
 I just came up with a fast way to map those 243 cells back and forth 
with the original 81.  At that point, it no longer mattered which things 
were rows and which were columns or boxes.



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


Re: TCP sockets python timeout public IP adresss

2015-03-30 Thread bobbdeep
On Sunday, March 29, 2015 at 2:27:59 PM UTC+5:30, bobbdeep wrote:
> I am trying to communicate between a server and client using TCP sockets. 
> 
> Server code:
> 
> import socket
> import sys
> 
> # Create a TCP/IP socket
> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> # Bind the socket to the port
> server_address = ('my-server-ipadress', 1999)
> print >>sys.stderr, 'starting up on %s port %s' % server_address
> sock.bind(server_address)
> sock.listen(1)
>  try:
> print >>sys.stderr, 'connection from', client_address
> 
> # Receive the data in small chunks and retransmit it
> while True:
> data = connection.recv(16)
> print >>sys.stderr, 'received "%s"' % data
> if data:
> print >>sys.stderr, 'sending data back to the client'
> connection.sendall(data)
> else:
> print >>sys.stderr, 'no more data from', client_address
> break
> 
> finally:
> # Clean up the connection
> connection.close()
> 
> Client code:
> 
> from socket import *
> 
> clientsocket = socket(AF_INET,SOCK_STREAM)
> 
> clientsocket.connect(("my-server-ip-address",1999))
> 
> recv = clientsocket.recv(1024)
> 
> print(recv)
> 
> It is working fine on a local connection. The problem I am facing is when I 
> run the client code on my laptop (using my home wifi network)and try to 
> communicate with the remote server, it is not able connect to the server. 
> What could be the problem ? Any changes in the code required, or do I need to 
> disable firewall on my laptop ?
> 
> The error I get is, error: [Errno 10060] A connection attempt failed because 
> the connected party did not properly respond after a period of time, or 
> established connection failed because connected host has failed to respond

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


[RELEASED] Python 3.5.0a3 is now available

2015-03-30 Thread Larry Hastings



On behalf of the Python development community and the Python 3.5 release 
team, I'm thrilled to announce the availability of Python 3.5.0a3.   
Python 3.5.0a3 is the third alpha release of Python 3.5, which will be 
the next major release of Python.  Python 3.5 is still under heavy 
development, and is far from complete.


This is a preview release, and its use is not recommended for production 
settings.


Two important notes for Windows users about Python 3.5.0a3:

 * If you have previously installed Python 3.5.0a1, you may need to
   manually uninstall it before installing Python 3.5.0a3 (issue23612).
 * If installing Python 3.5.0a3 as a non-privileged user, you may need
   to escalate to administrator privileges to install an update to your
   C runtime libraries.


You can find Python 3.5.0a3 here:

   https://www.python.org/downloads/release/python-350a3/

Happy hacking,


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


Communicating with multiple clients using one TCP socket pyt

2015-03-30 Thread bobbdeep
I am using TCP sockets to communicate between my server and clients. The server 
code and socket code are as below:

server:

from socket import *

HOST = 'xx.xx.xx.xx'
PORT = 1999
serversocket = socket(AF_INET,SOCK_STREAM)
serversocket.bind((HOST,PORT))
print 'bind success'
serversocket.listen(5)
print 'listening'
while True:
(clientsocket, address) = serversocket.accept()
print ("Got client request from",address)
#clientsocket.send('True')
data = clientsocket.recv(1024)
print data
clientsocket.send('True')
clientsocket.close()


client:

import socket
import sys

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Connect the socket to the port on the server given by the caller
server_address = ('xx.xx.xx.xx', 1999)
print >>sys.stderr, 'connecting to %s port %s' % server_address
sock.connect(server_address)

try:

message = 'This is the message.  It will be repeated.'
print >>sys.stderr, 'sending' 
for x in range (0,1):
  name=raw_input ('what is ur name')
  print type(name)
  sock.send(name)
  print sock.recv(1024)

finally:
sock.close()


I am able to communicate with the server from client and able to send and 
receive data. But the problem I am facing is that I am not able to send and 
receive data continuously from the server. I have to restart my client code on 
my laptop to send and receive data again from the server. The way the above 
client code is working is that when I give a keyboard input, then the socket 
sends data to server and server responds back. But in the client code, in the 
for loop if I do two iterations, for the second iteration the data I enter from 
keyboard is not reaching server. I need to restart my client code to send data 
again. How do I fix this ?

Also, when once client is connected to the server, the other cannot connect to 
the server. Any ideas on how to do this ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-30 Thread Ian Kelly
On Mon, Mar 30, 2015 at 2:16 AM, Dave Angel  wrote:
> The relationship between row, column and box can be rearranged.  Some of
> these are already covered by the rotations proposed earlier, where for a 90
> degree rotate, row becomes column and column becomes row.  But in a similar
> way each box could become a column, and so on.

I don't think this one is valid. The intersection of a row and a
column is one cell. The intersection of a row and a box is three
cells. If you swap a column with a box, you're changing the
relationships between the squares and the result will not be
isomorphic to the original.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sudoku solver

2015-03-30 Thread Chris Angelico
On Mon, Mar 30, 2015 at 7:57 PM, Ian Kelly  wrote:
> On Mon, Mar 30, 2015 at 2:16 AM, Dave Angel  wrote:
>> The relationship between row, column and box can be rearranged.  Some of
>> these are already covered by the rotations proposed earlier, where for a 90
>> degree rotate, row becomes column and column becomes row.  But in a similar
>> way each box could become a column, and so on.
>
> I don't think this one is valid. The intersection of a row and a
> column is one cell. The intersection of a row and a box is three
> cells. If you swap a column with a box, you're changing the
> relationships between the squares and the result will not be
> isomorphic to the original.

But if you swap *every* column with *every* box?

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


Re: Sudoku solver

2015-03-30 Thread Marko Rauhamaa
Ian Kelly :

> On Mon, Mar 30, 2015 at 1:13 AM, Christian Gollwitzer 
> wrote:
>> Am 30.03.15 um 08:50 schrieb Ian Kelly:
>>>
>>> On Sun, Mar 29, 2015 at 12:03 PM, Marko Rauhamaa 
>>> wrote:

 Be careful with the benchmark comparisons. Ian's example can be
 solved with the identical algorithm in eight different ways (four
 corners, left or right). I ran the example with my recent Python
 solver and got these times in the eight cases:

  884   s
2.5 s
   13   s
  499   s
5.9 s
  128   s
 1360   s
   36   s
>>>
>>>
>>> That sounds to me like either a transcription error was made to the
>>> puzzle at some point, or there's something wrong with your solver.
>>> The whole point of that example was that it was a puzzle with the
>>> minimum number of clues to specify a unique solution.
>>
>> I think Marko meant, that if he creates symmetrically equivalent
>> puzzles by rotating / mirroring the grid, he gets vastly different
>> execution times, but ends up with the same solution.
>
> That makes sense, but it is true for all puzzles that there are eight
> possible orientations (since it's impossible for a puzzle solution to
> be symmetric), and the wording made it sound like he was describing a
> property specific to the puzzle that I posted.

Thing is, if you are not careful in your comparisons, you might easily
get a good-looking time from one implementation and a lousy time from
another implementation because of a different traversal order.

That is why brute-force sudoku might not be as good for benchmark
testing as BertC was hoping.


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


Re: Sudoku solver

2015-03-30 Thread Marko Rauhamaa
mr.smit...@gmail.com:

> You say "neater implementation"
> I'll send you to the code-golf site:
> http://codegolf.stackexchange.com/a/446/38632 this is brute force.
> There are some really good implementations in other languages that
> arent brute force.

It ain't neater if it don't fit in your posting like mine did.


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


Re: Python 3 lack of support for fcgi/wsgi.

2015-03-30 Thread Mark Lawrence

On 30/03/2015 02:22, Ben Finney wrote:

Paul Rubin  writes:


He reported hitting more snags than some of us might expect purely
from the Python 3 propaganda ("oh, just run the 2to3 utility and it
does everything for you").


Propaganda?

Are you referring to the official guidelines for migrating from Python 2
to Python 3? The official guide at
https://docs.python.org/3/howto/pyporting.html> doesn't support
that assertion.

The ‘2to3’ program is presented as a tool to assist. I don't know of
anything official saying “it does everything for you”. Even when it was
first introduced it was only ever presented as a *start* to the porting
effort.



Not much of a tool if the 47 outstanding issues on the bug tracker are 
anything to go by.


--
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: Sudoku solver

2015-03-30 Thread BartC

On 29/03/2015 08:57, Christian Gollwitzer wrote:

Am 29.03.15 um 05:06 schrieb Steven D'Aprano:


[OT: Competing with compiled C code]


I'm not one of those people who think that C is by definition the fastest
language conceivable. (People who believe this sometimes make an
exception
for hand-crafted assembly, which is ironic since these days the best C
optimizing compilers can generate faster, tighter code than human
assembly
programmers.)




Defeating a C compiler is possible in (rare) cases, I wouldn't really
count the examples you've posted, since they don't actually compute
anything useful. However, for instance the Intel C compiler is able to
replace a loop like this:

for (int i=0; i

I have an interpreter for my language which has an implementation in C, 
and one in my own static language. That latter can also optionally make 
use of a byte-code dispatcher written in assembly (which tries to deal 
with each byte-code if it can, if not it passes it on to high-level code).


This combination of HLL+ASM can be up to double the speed of the 
C/gcc/O3 version (and which has to use gcc extensions), when executing 
benchmarks. On real programs, it can still be up to 40-50% faster (ie. 
the C version takes 40-50% longer to execute).


(My own static language by itself is 30% slower than C/gcc/O3 at the 
minute, when used for the interpreter, but I'm working on it... For 
small, tight benchmarks though it is still totally outclassed by gcc.)



Just look at the contrived PyPy benchmarks, for a very tuned selected
sample you can be almost twice as fast as C - for a random algorithm
like the Sudoku solver, not specifically tuned, C is 30x faster. It
still boils down to the classic rules: static unboxed types and static
or preallocated memory makes your code fast. In many cases, though,
programming in Python can free programmer time, which can lead in turn
to better algorithms that outperform the wisdom of the C compiler.


I'm quite impressed with PyPy. While its implementation seems (to me) 
fantastically complicated compared with the very simple concept of a 
byte-code interpreter, it seems to do the job. For simple integer 
benchmarks, it can be double the speed of my HLL+ASM interpreter running 
the same algorithm (but not in Python).


However I believe that CPython could be a bit faster than it is, even 
with all the dynamic stuff that is what's supposed to keep it slow.


(If Python wasn't so huge, and if I understood it a lot more than I do, 
I'd be tempted to have a go myself. For example, I could change the 
syntax of my interpreted language so that it looks like Python. Then I 
can take a simple benchmark in this 'Python', and run it with both 
CPython and my interpreter, and mine is likely to be faster. Yet, it 
still uses a byte-code dispatch loop, and it is still dynamically typed.


So what extra stuff is going on in CPython?)

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


Re: Strategy/ Advice for How to Best Attack this Problem?

2015-03-30 Thread Saran A
On Sunday, March 29, 2015 at 10:04:45 PM UTC-4, Chris Angelico wrote:
> On Mon, Mar 30, 2015 at 12:08 PM, Paul Rubin  wrote:
> > Saran Ahluwalia  writes:
> >> cross-platform...
> >> * Monitors a folder for files that are dropped throughout the day
> >
> > I don't see a cross-platform way to do that other than by waking up and
> > scanning the folder every so often (once a minute, say).  The Linux way
> > is with inotify and there's a Python module for it (search terms: python
> > inotify).  There might be comparable but non-identical interfaces for
> > other platforms.
> 
> All too often, "cross-platform" means probing for one option, then
> another, then another, and using whichever one you can. On Windows,
> there's FindFirstChangeNotification and ReadDirectoryChanges, which
> Tim Golden wrote about, and which I coded up into a teleporter for
> getting files out of a VM automatically:
> 
> http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html
> https://github.com/Rosuav/shed/blob/master/senddir.py
> 
> ChrisA

@Dave, Chris, Paul and Dennis: Thank you for resources and the notes regarding 
what I should keep in mind. I have an initial commit: 
https://github.com/ahlusar1989/IntroToPython/blob/master/Project1WG_with_assumptions_and_comments.py

I welcome your thoughts on this
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 lack of support for fcgi/wsgi.

2015-03-30 Thread Denis McMahon
On Sun, 29 Mar 2015 11:57:54 -0700, John Nagle wrote:

> The Python 2 module "fcgi" is gone in Python 3.

Was this part of the python standard library, or was it a third party 
library? I can only find cgi documentation  in the python 2 core documentation, not fcgi 
documentation. Documentation for cgi is also present in the python 3 core 
documentation: 

Perhaps the issue is that your python 2 web application was built using 
3rd party implementations of cgi interfaces which have not kept up with 
the development of python 3. The only core module I can find in python 
that appears relevant is the cgi module, and that exists both in python 2 
and python 3.

> The Python 3 documentation at
> 
> https://docs.python.org/3/howto/webservers.html

That appears to be a copy of the Python 2 Howto. It should probably make 
that clearer! It contains the following caveat:

"See also: While this HOWTO tries to give an overview of Python in the 
web, it cannot always be as up to date as desired. Web development in 
Python is rapidly moving forward, so the wiki page on Web Programming 
 may be more in sync with 
recent development."

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Communicating with multiple clients using one TCP socket pyt

2015-03-30 Thread sohcahtoa82
On Monday, March 30, 2015 at 1:44:17 AM UTC-7, bobbdeep wrote:
> I am using TCP sockets to communicate between my server and clients. The 
> server code and socket code are as below:
> 
> server:
> 
> from socket import *
> 
> HOST = 'xx.xx.xx.xx'
> PORT = 1999
> serversocket = socket(AF_INET,SOCK_STREAM)
> serversocket.bind((HOST,PORT))
> print 'bind success'
> serversocket.listen(5)
> print 'listening'
> while True:
> (clientsocket, address) = serversocket.accept()
> print ("Got client request from",address)
> #clientsocket.send('True')
> data = clientsocket.recv(1024)
> print data
> clientsocket.send('True')
> clientsocket.close()
> 
> 
> client:
> 
> import socket
> import sys
> 
> # Create a TCP/IP socket
> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> 
> # Connect the socket to the port on the server given by the caller
> server_address = ('xx.xx.xx.xx', 1999)
> print >>sys.stderr, 'connecting to %s port %s' % server_address
> sock.connect(server_address)
> 
> try:
> 
> message = 'This is the message.  It will be repeated.'
> print >>sys.stderr, 'sending' 
> for x in range (0,1):
>   name=raw_input ('what is ur name')
>   print type(name)
>   sock.send(name)
>   print sock.recv(1024)
> 
> finally:
> sock.close()
> 
> 
> I am able to communicate with the server from client and able to send and 
> receive data. But the problem I am facing is that I am not able to send and 
> receive data continuously from the server. I have to restart my client code 
> on my laptop to send and receive data again from the server. The way the 
> above client code is working is that when I give a keyboard input, then the 
> socket sends data to server and server responds back. But in the client code, 
> in the for loop if I do two iterations, for the second iteration the data I 
> enter from keyboard is not reaching server. I need to restart my client code 
> to send data again. How do I fix this ?
> 
> Also, when once client is connected to the server, the other cannot connect 
> to the server. Any ideas on how to do this ?

You have a bug here:

for x in range(0, 1):

range(0, 1) returns simply [0].  It is only going to loop once.  If you want it 
to loop twice, just use range(2).

Also, your server is immediately closing the connection after the first packet 
of data.

data = clientsocket.recv(1024) 
print data 
clientsocket.send('True') 
clientsocket.close() 

Your server receives the first send from the client, prints it, sends back a 
'True', then closes the connection.
-- 
https://mail.python.org/mailman/listinfo/python-list


Setuptools Confusion

2015-03-30 Thread Rob Gaddi
I'm having two issues trying to make setuptools do what I want to package 
up an application.  Well, actually I'm having many issues, but I'll start 
with the two that are foremost right now.

First, I've got documentation in RestructuredText format that I want to 
cook down to HTML to include in with the application.  I've got a 
make_docs.py that I can run to do that.  I want to make sure that 
make_docs is run prior to building the sdist package so that the docs in 
the package are always up to date.  I have no idea how to do that.

Secondly, I'm using QSettings to manage my application data, and would 
like to create an .INI file (complete with comments and whatnot) in the 
correct system-dependent location.  Once again, I've got a function 
already written that does this.  I tried the only thing I could find on 
StackOverflow, which was to overwrite the install method with:

from setuptools.command.install import install as _install

# Post-install hook
class post_install(_install):
def run(self):
_install.run(self)
from V120B.configuration import writeini
writeini()

setup(
...
# Use the post-install hook to provide the default .INI file.
cmdclass={
'install' : post_install
},
)

But I don't see the file getting created.  Also, does this mean I'd also 
have to hook develop separately?

I feel like both my questions come down to the same root; how do I hook 
setuptools to do additional tasks at appropriate times?  Is it really as 
complicated as all this, or is there something trivial and stupid that 
I'm just missing?

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 lack of support for fcgi/wsgi.

2015-03-30 Thread Denis McMahon
On Mon, 30 Mar 2015 15:47:23 +1100, Chris Angelico wrote:

> On Mon, Mar 30, 2015 at 3:35 PM, Paul Rubin 
> wrote:
>> 2b. John, thank you for describing your experience and making the
>> community's picture of the current overall state of Python 3 more
>> accurate.  It was apparently a bit too rosy before, and we should avoid
>> fostering unrealistic expectations in the future.

> Not without some evidence of where this "a bit too rosy" picture came
> from. So far, we've had rebuttals of vaguenesses, which pretty much
> amount to FUD.

I went and looked earlier - the HOWTO on the Python 3 documentation site 
 appears to be almost 
a straight copy of the HOWTO from the Python 2 documentation. 

As such, it should either be updated to ensure that any external 
libraries and modules are Python 3 compatible, have a suitable caveat 
inserted, or be removed.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strategy/ Advice for How to Best Attack this Problem?

2015-03-30 Thread Dave Angel

On 03/30/2015 12:45 PM, Saran A wrote:

On Sunday, March 29, 2015 at 10:04:45 PM UTC-4, Chris Angelico wrote:

On Mon, Mar 30, 2015 at 12:08 PM, Paul Rubin  wrote:

Saran Ahluwalia  writes:

cross-platform...
* Monitors a folder for files that are dropped throughout the day


I don't see a cross-platform way to do that other than by waking up and
scanning the folder every so often (once a minute, say).  The Linux way
is with inotify and there's a Python module for it (search terms: python
inotify).  There might be comparable but non-identical interfaces for
other platforms.


All too often, "cross-platform" means probing for one option, then
another, then another, and using whichever one you can. On Windows,
there's FindFirstChangeNotification and ReadDirectoryChanges, which
Tim Golden wrote about, and which I coded up into a teleporter for
getting files out of a VM automatically:

http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html
https://github.com/Rosuav/shed/blob/master/senddir.py

ChrisA


@Dave, Chris, Paul and Dennis: Thank you for resources and the notes regarding 
what I should keep in mind. I have an initial commit: 
https://github.com/ahlusar1989/IntroToPython/blob/master/Project1WG_with_assumptions_and_comments.py

I welcome your thoughts on this



It's missing a number of your requirements.  But it's a start.

If it were my file, I'd have a TODO comment at the bottom stating known 
changes that are needed.  In it, I'd mention:


1) your present code is assuming all filenames come directly from the 
commandline.  No searching of a directory.


2) your present code does not move any files to success or failure 
directories


3) your present code doesn't calculate or write to a text file any 
statistics.


4) your present code runs once through the names, and terminates.  It 
doesn't "monitor" anything.


5) your present code doesn't check for zero-length files

I'd also wonder why you bother checking whether the 
os.path.getsize(file) function returns the same value as the os.SEEK_END 
and ftell() code does.  Is it that you don't trust the library?  Or that 
you have to run on Windows, where the line-ending logic can change the 
apparent file size?


I notice you're not specifying a file mode on the open.  So in Python 3, 
your sizes are going to be specified in unicode characters after 
decoding.  Is that what the spec says?  It's probably safer to 
explicitly specify the mode (and the file encoding if you're in text).


I see you call strip() before comparing the length.  Could there ever be 
leading or trailing whitespace that's significant?  Is that the actual 
specification of line size?


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


Re: Setuptools Confusion

2015-03-30 Thread Ben Finney
Rob Gaddi  writes:

> I'm having two issues trying to make setuptools do what I want to package 
> up an application.

Those questions are on-topic here. It's worth noting, though, that you
may get better discussion of this by asking in the Distutils forum
https://www.python.org/community/sigs/current/distutils-sig/>.

> I feel like both my questions come down to the same root; how do I hook 
> setuptools to do additional tasks at appropriate times?

In short, you need to extend the ‘distutils.command’ classes and specify
your custom classes as commands. The Distutils documentation describes
this https://docs.python.org/3/distutils/extending.html>.

Note, though, that this is an advanced topic and not to be undertaken
lightly; it isn't very well understood.

> Is it really as complicated as all this, or is there something trivial
> and stupid that I'm just missing?

It's more complicated than you thought :-(

The Python Packaging Authority https://www.pypa.io/> has greatly
improved the situation in recent years, with the Python Packaging User
Guide https://packaging.python.org/> among other works.

The bad news is that, though better than ten years ago, Python package
distribution is still surprisingly baroque and difficult to navigate.

-- 
 \   “I never forget a face, but in your case I'll be glad to make |
  `\  an exception.” —Groucho Marx |
_o__)  |
Ben Finney

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


Hypothesis 1.0: A production quality property-based testing library for Python

2015-03-30 Thread David MacIver
Hypothesis is a Python library for turning unit tests into generative tests,
covering a far wider range of cases than you can manually. Rather than just
testing for the things you already know about, Hypothesis goes out and
actively hunts for bugs in your code. It usually finds them, and when it
does it gives you simple and easy to read examples to demonstrate.

Hypothesis is based on Quickcheck (
https://wiki.haskell.org/Introduction_to_QuickCheck2) but is designed to
have a naturally Pythonic API and integrate well with Python testing
libraries.

It's easy to use, extremely solid, and probably more devious than you
are at finding
edge cases.

The 1.0 release of Hypothesis has a stable and well documented public API.
It's more than ready for you to use and it's easy to get started.

Full documentation is available at
http://hypothesis.readthedocs.org/en/latest/, or if you prefer you can skip
straight to the quick start guide:
http://hypothesis.readthedocs.org/en/latest/quickstart.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 lack of support for fcgi/wsgi.

2015-03-30 Thread John Nagle
On 3/29/2015 7:11 PM, John Nagle wrote:
> Meanwhile, I've found two more variants on "flup"
> 
>   https://pypi.python.org/pypi/flipflop
>   https://pypi.python.org/pypi/flup6
> 
> All of these are descended from the original "flup" code base.
> 
> PyPi also has
> 
>   fcgi-python (Python 2.6, Windows only.)
>   fcgiapp (circa 2005)
>   superfcgi (circa 2009)
> 
> Those can probably be ignored.
> 
> One of the "flup" variants may do the job, but since there
> are so many, and no single version has won out, testing is
> necessary.  "flipflop" looks promising, simply because the
> author took all the code out that you don't need on a server.

   "flipflop" works well with Apache.  It does log
"WARNING: SCRIPT_NAME does not match REQUEST_URI" for any URL
renamed using mod_rename with Apache, but other than that,
it seems to do the job.  The warning message was copied
over from "flup", and there's an issue for it for one of the
"flup" variants.  So I referenced that issue for "flipflop":

https://github.com/Kozea/flipflop/issues

That's part of the problem of having all those forks - now
each bug has to be fixed in each fork.

After all this, the production system is now running entirely
on Python 3.

John Nagle

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


Re: Hypothesis 1.0: A production quality property-based testing library for Python

2015-03-30 Thread Terry Reedy

On 3/30/2015 2:44 PM, David MacIver wrote:

Hypothesis is a Python library for turningunit tests into generative
tests, covering a far wider range of cases thanyou can manually. Rather
than just testing for thethings you already know about, Hypothesis goes
out and actively hunts forbugs in your code.It usually finds them, and
when it does it gives you simple and easy to read examples to demonstrate.


Iteresting.  Some years ago, Vickor Stinner wrote a fuzzing module 
(fusil?).  I believe he found some bugs in the stdlib with it.


https://www.python.org/dev/peps/pep-0484/
proposes the addition of a 'typing' module for defining types beyond the 
builtins and ABCs, such as List(int), Union(tuple, list).  If and when 
it is accepted and added (maybe 3.5, maybe later), you should consider 
having Hypothesis accept the notations that it can work with.



Full documentation is available at
http://hypothesis.readthedocs.org/en/latest/, or if you prefer you can
skip straight to the quick start guide:
http://hypothesis.readthedocs.org/en/latest/quickstart.html



--
Terry Jan Reedy

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


Re: Hypothesis 1.0: A production quality property-based testing library for Python

2015-03-30 Thread David MacIver
On 30 March 2015 at 22:37, Terry Reedy  wrote:

> On 3/30/2015 2:44 PM, David MacIver wrote:
>
>> Hypothesis is a Python library for turningunit tests into generative
>> tests, covering a far wider range of cases thanyou can manually. Rather
>> than just testing for thethings you already know about, Hypothesis goes
>> out and actively hunts forbugs in your code.It usually finds them, and
>> when it does it gives you simple and easy to read examples to demonstrate.
>>
>
> Iteresting.  Some years ago, Vickor Stinner wrote a fuzzing module
> (fusil?).  I believe he found some bugs in the stdlib with it.
>

Cool. I'd somehow missed fusil, thanks. It looks interesting and I'll have
a dig through it for ideas :-)

Hypothesis and fusil are aimed at somewhat different levels. Hypothesis is
closer to being for unit testing (I mean you can use it for integration
testing and other things just as easily, but that's not strictly its
strength) whileas fusil looks better for testing whole programs.


>
> https://www.python.org/dev/peps/pep-0484/
> proposes the addition of a 'typing' module for defining types beyond the
> builtins and ABCs, such as List(int), Union(tuple, list).  If and when it
> is accepted and added (maybe 3.5, maybe later), you should consider having
> Hypothesis accept the notations that it can work with.


Yes, definitely. Having something like that as standard would be great for
Hypothesis and I intend to support it once it becomes available.

(It will force me to finally figure out how to do staged APIs, with some
versions of the API only supported on some versions of python, but I need
to do that anyway. This might involve just shipping a compatibility layer
for previous versions of Python in with Hypothesis)


>
>
>  Full documentation is available at
>> http://hypothesis.readthedocs.org/en/latest/, or if you prefer you can
>> skip straight to the quick start guide:
>> http://hypothesis.readthedocs.org/en/latest/quickstart.html
>>
>
>
> --
> Terry Jan Reedy
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Communicating with multiple clients using one TCP socket pyt

2015-03-30 Thread Ian Kelly
On Mon, Mar 30, 2015 at 2:43 AM, bobbdeep  wrote:
> Also, when once client is connected to the server, the other cannot connect 
> to the server. Any ideas on how to do this ?

While one client is connected, the server can't accept new connections
because it's tied up in a blocking call to recv, waiting for data. In
order to accept additional simultaneous connections while handling the
incoming data as it becomes ready, you'll need to multiplex your I/O
events using the select module -- see
https://docs.python.org/2/library/select.html#select.select

Also, if you don't already have a book on network programming, I
suggest getting one.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python JSON processing - extra data error

2015-03-30 Thread karthik . sharma
I have the following python program to read a set of JSON files do some 
processing on it and dump them back to the same folder. However When I run the 
below program and then try to see the output of the JSON file using

`cat file.json | python -m json.tool` 

I get the following error

`extra data: line 1 column 307 - line 1 column 852 (char 306 - 851)`

What is wrong with my program?
 
#Process 'new' events to extract more info from 'Messages'
rootDir = '/home/s_parts'
for dirName, subdirList, fileList in os.walk(rootDir):
print('Found directory: %s' % dirName)
for fname in fileList:
fname='s_parts/'+fname
with open(fname, 'r+') as f:
json_data = json.load(f)
et = json_data['Et']
ms = json_data['Ms']
if (event == 'a.b.c.d') or (event == 'e.f.g.h'):
url = re.sub('.+roxy=([^& ]*).*', r'\1', ms)
nt = re.findall(r"NT:\s*([^,)]*)",ms)[0]
bt = re.findall(r"BT:\s*([^,)]*)",ms)[0]
xt = re.findall(r"XT:\s*([^,)]*)",ms)[0]
appde = ms.split('Appde:')[1].strip().split('')[0]
version = ms.split('version:')[1].strip().split('')[0]
json_data["url"] = url
json_data["BT"] = bt
json_data["XT"] = xt
json_data["NT"] = nt
json_data["Appde"] = appde
json_data["version"] = version
else:
json_data["url"] = "null"
json_data["BT"] = "null"
json_data["XT"] = "null"
json_data["NT"] = "null"
json_data["Appde"] = "null"
json_data["version"] = "null"
   json.dump(json_data,f)

If I do a `file` command on the output file I get 
`events_parts/data_95: ASCII text, with very long lines, with no line 
terminators`


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


Image rotation issue

2015-03-30 Thread kai . peters

Last week some readers have kindly supplied ideas and code for a question I had 
asked around a form of image data compression required for specialized display 
hardware.

I was able to solve my issues for all but one:

The black & white only device (1024 (X) x 1280 (Y)) expects the compressed data 
based on portrait mode, i.e. 8 pixels combined into one bytes for 1280 rows of 
128 bytes. 

This was working well until the desire came up to be able to tilt the display 
and use it in landscape mode - now I needed to rotate the text, as Pillow does 
not seem to support drawing at angles.

No big deal - or so I thought after discovering rotate:

from PIL import Image, ImageFont, ImageDraw

white = 1
black = 0
img   = Image.new('1', (1280, 1024), white)  # start in landscape mode since we 
need to calc. based on that
draw  = ImageDraw.Draw(img)
fontname = 'FreeSansBold.ttf'

# in real life, x and y are calculated to center or align text both vertically 
and horizontally
x = 10
y = 500

dfont = ImageFont.truetype(fontname, 96)

draw.text((x, y), 'Hallo world', black, font = dfont)
draw   = ImageDraw.Draw(img)

rotimg = img.rotate(270) # rotation is counterclockwise

# i can almost make it work by resizing rotimg here, but the aspect ratio is 
then screwed
#rotimg = rotimg.resize((1024, 1280))

rotimg.show()
imagedata = list(rotimg.getdata())

But grabbing data from the rotimg does not work as it does not seem to return 
an image with swapped dimensions...

What am I missing? 
-- 
https://mail.python.org/mailman/listinfo/python-list


Error in processing JSON files in Python

2015-03-30 Thread Karthik Sharma
I have the following python program to read a set of JSON files do some 
processing on it and dump them back to the same folder. However When I run the 
below program and then try to see the output of the JSON file using

`cat file.json | python -m json.tool`

I get the following error

`extra data: line 1 column 307 - line 1 column 852 (char 306 - 851)`

What is wrong with my program?
 
#Process 'new' events to extract more info from 'Messages'
rootDir = '/home/s_parts'
for dirName, subdirList, fileList in os.walk(rootDir):
print('Found directory: %s' % dirName)
for fname in fileList:
fname='s_parts/'+fname
with open(fname, 'r+') as f:
json_data = json.load(f)
et = json_data['Et']
ms = json_data['Ms']
if (event == 'a.b.c.d') or (event == 'e.f.g.h'):
url = re.sub('.+roxy=([^& ]*).*', r'\1', ms)
nt = re.findall(r"NT:\s*([^,)]*)",ms)[0]
bt = re.findall(r"BT:\s*([^,)]*)",ms)[0]
xt = re.findall(r"XT:\s*([^,)]*)",ms)[0]
appde = ms.split('Appde:')[1].strip().split('')[0]
version = ms.split('version:')[1].strip().split('')[0]
json_data["url"] = url
json_data["BT"] = bt
json_data["XT"] = xt
json_data["NT"] = nt
json_data["Appde"] = appde
json_data["version"] = version
else:
json_data["url"] = "null"
json_data["BT"] = "null"
json_data["XT"] = "null"
json_data["NT"] = "null"
json_data["Appde"] = "null"
json_data["version"] = "null"
   json.dump(json_data,f)

If I do a `file` command on the output file I get
`s_parts/data_95: ASCII text, with very long lines, with no line terminators` 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Image rotation issue

2015-03-30 Thread Ian Kelly
On Mon, Mar 30, 2015 at 3:22 PM,   wrote:
> rotimg = img.rotate(270) # rotation is counterclockwise
>
> # i can almost make it work by resizing rotimg here, but the aspect ratio is 
> then screwed
> #rotimg = rotimg.resize((1024, 1280))
>
> rotimg.show()
> imagedata = list(rotimg.getdata())
>
> But grabbing data from the rotimg does not work as it does not seem to return 
> an image with swapped dimensions...
>
> What am I missing?

Have you tried passing the expand flag to rotate?

http://pillow.readthedocs.org/en/latest/reference/Image.html#PIL.Image.Image.rotate

I'm not sure if that will result in an image sized (1280, 1024) or
(1280, 1280). If the latter, you should be able to fix it using
Image.crop.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 lack of support for fcgi/wsgi.

2015-03-30 Thread Terry Reedy

On 3/30/2015 4:07 PM, John Nagle wrote:


After all this, the production system is now running entirely
on Python 3.


I am really glad to read this.  Aside from a bit of hyperbole, I 
appreciate the report of successes and difficulties.  I also understand 
better that 'Python 3' means something different (more) to a 
user-developer than to CPython core developers, and that the boundary 
between stdlib modules and 3-rd party modules is much less important to 
you than to us.


--
Terry Jan Reedy

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


Re: Error in processing JSON files in Python

2015-03-30 Thread MRAB

On 2015-03-30 22:27, Karthik Sharma wrote:

I have the following python program to read a set of JSON files do some 
processing on it and dump them back to the same folder. However When I run the 
below program and then try to see the output of the JSON file using

`cat file.json | python -m json.tool`

I get the following error

`extra data: line 1 column 307 - line 1 column 852 (char 306 - 851)`

What is wrong with my program?

 #Process 'new' events to extract more info from 'Messages'
 rootDir = '/home/s_parts'
 for dirName, subdirList, fileList in os.walk(rootDir):
 print('Found directory: %s' % dirName)
 for fname in fileList:
 fname='s_parts/'+fname
 with open(fname, 'r+') as f:
 json_data = json.load(f)
 et = json_data['Et']
 ms = json_data['Ms']
 if (event == 'a.b.c.d') or (event == 'e.f.g.h'):
 url = re.sub('.+roxy=([^& ]*).*', r'\1', ms)
 nt = re.findall(r"NT:\s*([^,)]*)",ms)[0]
 bt = re.findall(r"BT:\s*([^,)]*)",ms)[0]
 xt = re.findall(r"XT:\s*([^,)]*)",ms)[0]
 appde = ms.split('Appde:')[1].strip().split('')[0]
 version = ms.split('version:')[1].strip().split('')[0]
 json_data["url"] = url
 json_data["BT"] = bt
 json_data["XT"] = xt
 json_data["NT"] = nt
 json_data["Appde"] = appde
 json_data["version"] = version
 else:
 json_data["url"] = "null"
 json_data["BT"] = "null"
 json_data["XT"] = "null"
 json_data["NT"] = "null"
 json_data["Appde"] = "null"
 json_data["version"] = "null"
json.dump(json_data,f)

If I do a `file` command on the output file I get
`s_parts/data_95: ASCII text, with very long lines, with no line terminators`


open(fname, 'r+') opens the file for update, json.load(f) reads from
the file, and then json.dump(json_data,f) writes back to the file,
_appending_ to it, so the file now contains the old data followed by
the new data.

Another point: "null" is a string and will be written as such. If you
actually want a null in the JSON data, then that should be None.

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


Python 3 success story

2015-03-30 Thread Terry Reedy
Last summer, a college student, who prefers Python to Java and Racket 
(her other CS course languages), wanted to do a year-long AI research 
project using PyBrain (for the ai part), numpy (required for PyBrain), 
and pygame (for animated displays).  We both preferred 3.x.  That was 
not an issue for pygame and numpy as compiled 3.4 Windows binaries  were 
easily available.


PyBrain, however, was '2.7 only'.  So I downloaded it, read the doc for 
2to3, and ran it to do the conversion.  Running the PyBrain test suite 
did not work because it uses fragile doctests. Looking at the non-test 
code, I could see that it mostly used things that did not change in 3.x 
and a few things that should have been converted correctly.  This all 
took maybe an hour, certainly less than 2.


So I suggested going ahead and testing PyBrain by using it.  This 
appears to have worked out well. I believe the only 2-3 issue she ran 
into was a '/' that needed to become '//', that either 2to3 or I missed 
in the initial conversion. She had more problems with exception messages 
that she could not understand.  If anything, those have been improved in 
3.x (and such improvements continue).


--
Terry Jan Reedy

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


Re: Python 3 lack of support for fcgi/wsgi.

2015-03-30 Thread Ben Finney
John Nagle  writes:

> That's part of the problem of having all those forks - now
> each bug has to be fixed in each fork.

Agreed, there is too much focus on developing everything in isolation,
too little focus on getting different libraries working together.

> After all this, the production system is now running entirely
> on Python 3.

Hey, that's great! Congratulations on making it through to the
actively-developed world of Python 3 :-)

-- 
 \“When in doubt tell the truth. It will confound your enemies |
  `\   and astound your friends.” —Mark Twain, _Following the Equator_ |
_o__)  |
Ben Finney

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


Re: Image rotation issue

2015-03-30 Thread Chris Angelico
On Tue, Mar 31, 2015 at 8:22 AM,   wrote:
> rotimg = img.rotate(270) # rotation is counterclockwise

Unless the 90 and 270 cases are documented as being handled specially,
I'd look for a dedicated function for doing those changes. A quick
perusal of the docs showed up this:

http://pillow.readthedocs.org/en/latest/reference/Image.html#PIL.Image.Image.transpose

Is that any better, or is that doing the exact same thing as rotate()?

By the way:

> The black & white only device (1024 (X) x 1280 (Y)) expects the compressed 
> data based on portrait mode, i.e. 8 pixels combined into one bytes for 1280 
> rows of 128 bytes.
>

This sounds to me like the fax standard. I wonder, can you make use of
a TIFF library to do some of your work for you?

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


Re: Python 3 success story

2015-03-30 Thread Mario Figueiredo
On Mon, 30 Mar 2015 19:28:16 -0400, Terry Reedy 
wrote:

>
>So I suggested going ahead and testing PyBrain by using it.  This 
>appears to have worked out well. I believe the only 2-3 issue she ran 
>into was a '/' that needed to become '//', that either 2to3 or I missed 
>in the initial conversion. She had more problems with exception messages 
>that she could not understand.  If anything, those have been improved in 
>3.x (and such improvements continue).

This is good news, Terry. Have you considered requesting a fork from
the authors? And if you don't get the required attention, just fork it
yourself? Even if you don't plan to maintain it, it would be nice to
have it available for someone else to do it.

A quick look at the GitHub pages reveals the project has pretty much
stalled. Although it could be it achieved a good enough stable status,
this is a machine learning project and those tend to always require
constant work.

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


Re: Hypothesis 1.0: A production quality property-based testing library for Python

2015-03-30 Thread Terry Reedy

On 3/30/2015 4:46 PM, David MacIver wrote:

On 30 March 2015 at 22:37, Terry Reedy mailto:tjre...@udel.edu>> wrote:



https://www.python.org/dev/__peps/pep-0484/

proposes the addition of a 'typing' module for defining types beyond
the builtins and ABCs, such as List(int), Union(tuple, list).  If
and when it is accepted and added (maybe 3.5, maybe later), you
should consider having Hypothesis accept the notations that it can
work with.

Yes, definitely. Having something like that as standard would be great
for Hypothesis and I intend to support it once it becomes available.


I just posted "PEP 484: Generating test inputs from type hints" to 
python-ideas list.



(It will force me to finally figure out how to do staged APIs, with some
versions of the API only supported on some versions of python, but I
need to do that anyway. This might involve just shipping a compatibility
layer for previous versions of Python in with Hypothesis)


I believe Guido intends that typing.py should be available on PyPI for 
use with current versions.



Full documentation is available at
http://hypothesis.readthedocs.__org/en/latest/
you can
skip straight to the quick start guide:
http://hypothesis.readthedocs.__org/en/latest/quickstart.html


--
Terry Jan Reedy

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


Re: Hypothesis 1.0: A production quality property-based testing library for Python

2015-03-30 Thread Paul Rubin
David MacIver  writes:
> Hypothesis is based on Quickcheck
> (https://wiki.haskell.org/Introduction_to_QuickCheck2)

This is great.  Have you looked at the Erlang version of Quickcheck?  It
may have aspects more directly applicable to Python, since Erlang is
dynamically typed like Python is.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Image rotation issue

2015-03-30 Thread high5storage
On Monday, 30 March 2015 16:48:08 UTC-7, Chris Angelico  wrote:
> On Tue, Mar 31, 2015 at 8:22 AM,   wrote:
> > rotimg = img.rotate(270) # rotation is counterclockwise
> 
> Unless the 90 and 270 cases are documented as being handled specially,
> I'd look for a dedicated function for doing those changes. A quick
> perusal of the docs showed up this:
> 
> http://pillow.readthedocs.org/en/latest/reference/Image.html#PIL.Image.Image.transpose
> 
> Is that any better, or is that doing the exact same thing as rotate()?
> 
> By the way:
> 
> > The black & white only device (1024 (X) x 1280 (Y)) expects the compressed 
> > data based on portrait mode, i.e. 8 pixels combined into one bytes for 1280 
> > rows of 128 bytes.
> >
> 
> This sounds to me like the fax standard. I wonder, can you make use of
> a TIFF library to do some of your work for you?
> 
> ChrisA

According to the docs rotate & transform can both be used and should do the 
same in my case - but they are not.

rotimg = img.transpose(Image.ROTATE_270) 
print img.getbbox()
print rotimg.getbbox()

gives

(0, 0, 1280, 1024)
(0, 0, 1024, 1280)

while

rotimg = img.rotate(270, 0, 1)
print img.getbbox()
print rotimg.getbbox()

gives

(0, 0, 1280, 1024)
(1, 1, 1025, 1281)

Neither one produces good output when the compression is applied. 

Don't think it's related to fax standards - it's proprietary (E-Ink Tile)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Image rotation issue

2015-03-30 Thread Chris Angelico
On Tue, Mar 31, 2015 at 3:04 PM,   wrote:
> Neither one produces good output when the compression is applied.

Oh well, was worth a try.

> Don't think it's related to fax standards - it's proprietary (E-Ink Tile)

Doesn't need to be specifically _related_, but it's looking similar.
If you could do 90% of your work by pretending that this is a fax
you're sending, you could possibly do the other 10% by snagging a byte
stream from somewhere. But maybe not worth hunting down. Just a
thought.

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


Using csv DictWriter - add a extra field

2015-03-30 Thread Victor Hooi
Hi,

I have a dict named "connections", with items like the following:

In [18]: connections
Out[18]:
{'3424234': {'end_timestamp': datetime.datetime(2015, 3, 25, 5, 31, 30, 406000, 
tzinfo=datetime.timezone(datetime.timedelta(-1, 61200))),
  'ip_address': '10.168.8.36:52440',
  'open_timestamp': datetime.datetime(2015, 3, 25, 5, 31, 0, 383000, 
tzinfo=datetime.timezone(datetime.timedelta(-1, 61200))),
  'time_open': datetime.timedelta(0, 30, 23000)}}

In this case, the key is a connection id (e.g. "3424234"), and the value is a 
another dict, which contains things like 'end_timestamp', 'ip_address" etc.

I'm writing the output of "connections" to a CSV file using DictWriter:

fieldnames = ['connection_id', 'ip_address', 'open_timestamp', 'end_timestamp', 
'time_open']
with open('output.csv', 'w') as csvfile:
writer = DictWriter(csvfile, fieldnames)
writer.writeheader()
for connection, values in sorted(connections.items()):
if 'time_open' in values:
writer.writerow(values, {'connection_id': connection})
else:
pass
# DO SOME STUFF

The only problem is, I'd also like output the connection_id field as part of 
each CSV record.

However, connection_id in this case is the key for the parent dict.

Is there a clean way to add a extra field to DictWriter writerows, or it is the 
contents of the dict and that's it?

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


Re: Python JSON processing - extra data error

2015-03-30 Thread dieter
karthik.sha...@gmail.com writes:

> I have the following python program to read a set of JSON files do some 
> processing on it and dump them back to the same folder. However When I run 
> the below program and then try to see the output of the JSON file using
>
> `cat file.json | python -m json.tool` 
>
> I get the following error
>
> `extra data: line 1 column 307 - line 1 column 852 (char 306 - 851)`

You might have got a traceback which would tell you where precisely
the problem was detected. Looking the the code there (Python is "Open Source";
thus, you can look at code) will tell you what apparently went wrong.


"extra data" suggests to me that your JSON input may be invalid.

"1 2", for example could cause such a problem, because it contains
two integers (not a single one) without a containing container.

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


Re: Python 3 success story

2015-03-30 Thread Terry Reedy

On 3/30/2015 8:24 PM, Mario Figueiredo wrote:

On Mon, 30 Mar 2015 19:28:16 -0400, Terry Reedy 
wrote:



So I suggested going ahead and testing PyBrain by using it.  This
appears to have worked out well. I believe the only 2-3 issue she ran
into was a '/' that needed to become '//', that either 2to3 or I missed
in the initial conversion.


This is good news, Terry. Have you considered requesting a fork from
the authors?


I considered and rejected the idea at the time because a) I was more 
than busy supervising a GSOC project and b) to work on it seriously, I 
would want to ditch doctest (which was not meant for serious unit 
testing) and convert to using unittest for both 2.7 and 3.x.


> And if you don't get the required attention, just fork it

yourself? Even if you don't plan to maintain it, it would be nice to
have it available for someone else to do it.


Now that the port has been used for some months, I a) can see that 
making it available might be helpful to others, and b) would feel more 
comfortable doing so on an as is, use at your own risk, basis (and 
possibly even accept and apply patches).



A quick look at the GitHub pages reveals the project has pretty much
stalled. Although it could be it achieved a good enough stable status,
this is a machine learning project and those tend to always require
constant work.


Not knowing git and github adds a barrier, but thanks for the suggestion.

--
Terry Jan Reedy

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