Re: linux console command line history

2010-07-21 Thread kak...@gmail.com
On Jul 21, 9:03 am, Michele Simionato 
wrote:
> On Jul 20, 11:38 pm, "kak...@gmail.com"  wrote:
>
> > Hi to all,
> > I 'm writing a linux console app with sockets. It's basically a client
> > app that fires commands in a server.
> > For example:
> > $log user 55
> > $sessions list
> > $server list etc.
> > What i want is, after entering some commands, to press the up arrow
> > key and see the previous commands that i have executed.
> > Any hints? Any examples?
>
> > Antonis
>
> You may find interesting to look at the source code for plac (http://
> micheles.googlecode.com/hg/plac/doc/plac_adv.html). The readline
> support (including command history and autocompletion) is implemented
> in the ReadlineInput class 
> (seehttp://code.google.com/p/micheles/source/browse/plac/plac_ext.py).
> If you just want command history you can use rlwrap (http://
> freshmeat.net/projects/rlwrap).

That's great! thank you so much Michele!

Antonis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to treat the first or last item differently

2010-07-21 Thread Peter Otten
Terry Reedy wrote:

> It makes sense to separate last detection from item processing so last
> detection can be put in a library module and reused.

Here's an extension of your idea that puts the detection of both the first 
and the last item into a generator:

def mark_first(items):
items = iter(items)
yield True, next(items)
for item in items:
yield False, item

def mark_last(items):
items = iter(items)
prev = next(items)
for cur in items:
yield False, prev
prev = cur
yield True, prev

def mark_ends(items):
return ((head, tail, item) for head, (tail, item)
in mark_first(mark_last(items)))

for items in "", "a", "ab", "abc":
print list(items), "-->", list(mark_ends(items))

for first, last, item in mark_ends("abc"):
if first:
print "first",
if last:
print "last",
print item

It may not be the most efficient approach, but it looks clean.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exposing buffer interface for non-extension types?

2010-07-21 Thread Stefan Behnel

Ken Watford, 21.07.2010 03:04:
>>> Currently, I can expose the NumPy array interface (using either
>>> __array_interface__ or __array_struct__) for any class, extension or
>>> otherwise. But I can't find any reference to python-side interfacing
>>> for PEP 3118. SWIG makes an extension module for your wrapped code,
>>> but not extension *types*, so the classes it produces are pure-python
>>> with methods added in from the extension module.
>>
>> Try using Cython instead, it has native support for the buffer protocol.
>
> I've used Cython before, and I generally like it. But its purpose is
> slightly different than SWIG's, and does not particularly meet my
> current project's needs.

[...]
As a part of SWIG-wrapping a larger C++ project, I'm producing some
wrappings for Blitz++ arrays.


Right, support for C++ templates in Cython isn't as good yet as it could 
be, although there has been some work in that direction. Contributions are 
welcome.


However, note that you can write the tiny bit of plain C++ glue code 
necessary to access the Blitz++ arrays, and then use Cython to wrap that 
and to implement the buffer interface and all the other wrapper code. C++ 
support by itself is pretty good in Cython 0.13. (to be released soon, get 
it from here: http://hg.cython.org/cython-closures )


Stefan

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


source install of python2.7 and rpm install of cx_Oracle collision

2010-07-21 Thread Jim Qiu
Hi all,

 I make installed python 2.7 from source, and also installed the RPM version
of cx_Oracle for python 2.7.

 But  ldd tells me :
#ldd cx_Oracle.so
  libpython2.7.so.1.0 => not found

I find out that only libpython2.7.a generated when I install python2.7, who
can tell me what I need to do ?  I want a libpython2.7.so.1.0 generated when


I install python.

I am not familiar with GCC and .so .a stuff.

Best regards,

Jim
-- 
http://mail.python.org/mailman/listinfo/python-list


SQLalchemy+py2exe+pymssql error

2010-07-21 Thread Massi
Hi everyone, I'm trying to build an executable with py2exe. My script
uses SQLalchemy and pymssql with python 2.6. Here is my setup file:

from distutils.core import setup
import py2exe

manifest = """



myProgram











"""


setup(name="MyProg",
  windows=[{"script": "MyProg.py",
  "other_resources": [(24,1,manifest)]}],
  options={"py2exe": {"includes":[ "sqlalchemy.dialects.mssql",
"pymssql", "_mssql"]}}
)

The executable is successfully built up, but when I run the program I
get the following error message:

Exception in thread Thread-3:
Traceback (most recent call last):
  File "threading.pyc", line 532, in __bootstrap_inner
  File "threading.pyc", line 484, in run
  File "MyProg.py", line 166, in DatabaseSetup
  File "sqlalchemy\engine\__init__.pyc", line 241, in create_engine
  File "sqlalchemy\engine\strategies.pyc", line 60, in create
  File "sqlalchemy\dialects\mssql\pymssql.pyc", line 61, in dbapi
  File "pymssql.pyc", line 12, in 
  File "pymssql.pyc", line 10, in __load
  File "_mssql.pxd", line 10, in init pymssql (pymssql.c:7364)
  File "_mssql.pyc", line 12, in 
  File "_mssql.pyc", line 10, in __load
  File "_mssql.pyx", line 36, in init _mssql (_mssql.c:14941)
ImportError: No module named uuid

Can anyone point  me out what I am doing wrong? Thanks you in advance!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exposing buffer interface for non-extension types?

2010-07-21 Thread Antoine Pitrou
On Tue, 20 Jul 2010 18:09:22 -0400
Ken Watford  wrote:
> Is there any way to expose the PEP 3118 buffer interface for objects
> that aren't extension types?
> 
> Currently, I can expose the NumPy array interface (using either
> __array_interface__ or __array_struct__) for any class, extension or
> otherwise. But I can't find any reference to python-side interfacing
> for PEP 3118.

There is none, but feel free to make a proposal on python-ideas if you
think there's an use case for it.

Regards

Antoine.


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


Re: source install of python2.7 and rpm install of cx_Oracle collision

2010-07-21 Thread Daniel Fetchinson
>  I make installed python 2.7 from source, and also installed the RPM version
> of cx_Oracle for python 2.7.
>
>  But  ldd tells me :
> #ldd cx_Oracle.so
>   libpython2.7.so.1.0 => not found
>
> I find out that only libpython2.7.a generated when I install python2.7, who
> can tell me what I need to do ?  I want a libpython2.7.so.1.0 generated when
>
>
> I install python.
>
> I am not familiar with GCC and .so .a stuff.

In this case I'd recommend removing the source install of python 2.7,
install it from rpm, followed by installing cx_Oracle from rpm.

HTH,
Daniel



-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Sorting a list created from a parsed xml message

2010-07-21 Thread kak...@gmail.com
Hi pythonistas,
>From the subject of my message it's clear that i get an xml message
from a socket, i parse it and the result is a list like the one that
follows:
ID_Col
4 Serverak  ip  OFFLINE

29  Server  and2ip  OFFLINE

5 Proxy l34e ip OFFLINE

6 Proxy barcip  ONLINE

41Proxy proxy-2 ip  ONLINE

53Serverserver-4ip  ONLINE

52Serverserver-3ip  ONLINE


What i want is to print this list sorted by ID_Col?
Any Suggestions?

Antonis K.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting a list created from a parsed xml message

2010-07-21 Thread Stefan Behnel

kak...@gmail.com, 21.07.2010 14:36:

From the subject of my message it's clear that i get an xml message
from a socket,


Not at all, but now that you say it...



i parse it and the result is a list like the one that
follows:
ID_Col
4 Serverak  ip  OFFLINE

29  Server  and2ip  OFFLINE

5 Proxy l34e ip OFFLINE

6 Proxy barcip  ONLINE

41Proxy proxy-2 ip  ONLINE

53Serverserver-4ip  ONLINE

52Serverserver-3ip  ONLINE


Doesn't look like a Python list to me...



What i want is to print this list sorted by ID_Col?
Any Suggestions?


Assuming that the above is supposed to represent a list of tuples, you can 
use the .sort() method on the list and pass operator.itemgetter(0) as 'key' 
argument (see the sort() method and the operator module).


Stefan

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


Re: Sorting a list created from a parsed xml message

2010-07-21 Thread kak...@gmail.com
On Jul 21, 8:58 am, Stefan Behnel  wrote:
> kak...@gmail.com, 21.07.2010 14:36:
>
> > From the subject of my message it's clear that i get an xml message
> > from a socket,
>
> Not at all, but now that you say it...
>
>
>
> > i parse it and the result is a list like the one that
> > follows:
> > ID_Col
> > 4    Server        ak              ip      OFFLINE
>
> > 29      Server     and2    ip      OFFLINE
>
> > 5    Proxy         l34e         ip OFFLINE
>
> > 6            Proxy         barc            ip      ONLINE
>
> > 41           Proxy         proxy-2         ip      ONLINE
>
> > 53           Server        server-4        ip      ONLINE
>
> > 52           Server        server-3        ip      ONLINE
>
> Doesn't look like a Python list to me...
>
> > What i want is to print this list sorted by ID_Col?
> > Any Suggestions?
>
> Assuming that the above is supposed to represent a list of tuples, you can
> use the .sort() method on the list and pass operator.itemgetter(0) as 'key'
> argument (see the sort() method and the operator module).
>
> Stefan

No it is not a Python list at all. This the way i print the parsed
items 'like a list'.
But i want them to be sorted.
-- 
http://mail.python.org/mailman/listinfo/python-list


detect endianness of a binary with python

2010-07-21 Thread Holger brunck
Hi all,
I use python 2.5 and I am looking for a possibility to determine a file type.
Especially the endianness of a file is needed for me. Is there a way to detect
this easily in python? Something like the "file" utility for linux would be very
helpfull.

Any help is appreciated.

Best regards
Holger Brunck

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


An ODBC interface for Python 3?

2010-07-21 Thread Neil Cerutti
A quick web search yielded no current support for the ODBC
interface for Python 3.

I'd like to get a simple "tracer bullet" up and running ASAP. I
need to connect to an MSSQL database from Windows XP/2000, using
an ODBC interface.

Is this a case where I'll need to go back to Python 2.6?

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting a list created from a parsed xml message

2010-07-21 Thread kak...@gmail.com
On Jul 21, 9:04 am, "kak...@gmail.com"  wrote:
> On Jul 21, 8:58 am, Stefan Behnel  wrote:
>
>
>
> > kak...@gmail.com, 21.07.2010 14:36:
>
> > > From the subject of my message it's clear that i get an xml message
> > > from a socket,
>
> > Not at all, but now that you say it...
>
> > > i parse it and the result is a list like the one that
> > > follows:
> > > ID_Col
> > > 4    Server        ak              ip      OFFLINE
>
> > > 29      Server     and2    ip      OFFLINE
>
> > > 5    Proxy         l34e         ip OFFLINE
>
> > > 6            Proxy         barc            ip      ONLINE
>
> > > 41           Proxy         proxy-2         ip      ONLINE
>
> > > 53           Server        server-4        ip      ONLINE
>
> > > 52           Server        server-3        ip      ONLINE
>
> > Doesn't look like a Python list to me...
>
> > > What i want is to print this list sorted by ID_Col?
> > > Any Suggestions?
>
> > Assuming that the above is supposed to represent a list of tuples, you can
> > use the .sort() method on the list and pass operator.itemgetter(0) as 'key'
> > argument (see the sort() method and the operator module).
>
> > Stefan
>
> No it is not a Python list at all. This the way i print the parsed
> items 'like a list'.
> But i want them to be sorted.

Well i did this:

SortedServers = []

for session in sessions:
for IP in session.getElementsByTagName("ipAddress"):
 for iphn in session.getElementsByTagName("hostName"):
  tempTuple = session.getAttribute("id"),
session.getAttribute("type"), iphn.childNodes[0].data,
IP.childNodes[0].data, session.getAttribute("status")

  SortedServers.append(tempTuple)

Sorted = sorted(SortedServers, key=lambda id: SortedServers[0])
for item in Sorted:
 print item

but the list is still unsorted and with u' in front of each item

(u'4', u'Server', u'aika74', u'ip', u'OFFLINE')
(u'29', u'Server', u'ando', u'ip2', u'OFFLINE')

How do i remove the u'

Antonis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting a list created from a parsed xml message

2010-07-21 Thread Stefan Behnel

kak...@gmail.com, 21.07.2010 15:38:

On Jul 21, 9:04 am, "kak...@gmail.com"  wrote:

On Jul 21, 8:58 am, Stefan Behnel  wrote:




kak...@gmail.com, 21.07.2010 14:36:



 From the subject of my message it's clear that i get an xml message
from a socket,



Not at all, but now that you say it...



i parse it and the result is a list like the one that
follows:
ID_Col
4Serverak  ip  OFFLINE



29  Server and2ip  OFFLINE



5Proxy l34e ip OFFLINE



6Proxy barcip  ONLINE



41   Proxy proxy-2 ip  ONLINE



53   Serverserver-4ip  ONLINE



52   Serverserver-3ip  ONLINE



Doesn't look like a Python list to me...



What i want is to print this list sorted by ID_Col?
Any Suggestions?



Assuming that the above is supposed to represent a list of tuples, you can
use the .sort() method on the list and pass operator.itemgetter(0) as 'key'
argument (see the sort() method and the operator module).



Stefan


No it is not a Python list at all. This the way i print the parsed
items 'like a list'.
But i want them to be sorted.


Well i did this:

SortedServers = []

for session in sessions:
 for IP in session.getElementsByTagName("ipAddress"):
  for iphn in session.getElementsByTagName("hostName"):
   tempTuple = session.getAttribute("id"),
session.getAttribute("type"), iphn.childNodes[0].data,
IP.childNodes[0].data, session.getAttribute("status")

   SortedServers.append(tempTuple)

Sorted = sorted(SortedServers, key=lambda id: SortedServers[0])
for item in Sorted:
  print item

but the list is still unsorted and with u' in front of each item

(u'4', u'Server', u'aika74', u'ip', u'OFFLINE')
(u'29', u'Server', u'ando', u'ip2', u'OFFLINE')


It seems you want to sort the list numerically. In that case, use 
int(SortedServers[0]) as the key. Sorting by string values will sort the 
list lexicographically.




How do i remove the u'


You should read the Python tutorial, specifically the sections about 
strings. Then, read the sections on lists and sequences.


In short: Don't care about the "u'" prefix, that's just fine.

Stefan

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


Re: An ODBC interface for Python 3?

2010-07-21 Thread Tim Golden

On 21/07/2010 2:15 PM, Neil Cerutti wrote:

A quick web search yielded no current support for the ODBC
interface for Python 3.

I'd like to get a simple "tracer bullet" up and running ASAP. I
need to connect to an MSSQL database from Windows XP/2000, using
an ODBC interface.

Is this a case where I'll need to go back to Python 2.6?



pyodbc has a branch which supports Py3k. I've installed it and
it worked ok. Can't get hold of the web at the moment, but I'm
sure you'll be able to find it.

TJG
--
http://mail.python.org/mailman/listinfo/python-list


Re: An ODBC interface for Python 3?

2010-07-21 Thread Neil Cerutti
On 2010-07-21, Tim Golden  wrote:
> On 21/07/2010 2:15 PM, Neil Cerutti wrote:
>> A quick web search yielded no current support for the ODBC
>> interface for Python 3.
>>
>> I'd like to get a simple "tracer bullet" up and running ASAP. I
>> need to connect to an MSSQL database from Windows XP/2000, using
>> an ODBC interface.
>>
>> Is this a case where I'll need to go back to Python 2.6?
>
> pyodbc has a branch which supports Py3k. I've installed it and
> it worked ok. Can't get hold of the web at the moment, but I'm
> sure you'll be able to find it.

Thanks, Tim.

I did see that support for pyodbc for Python 3 was really close
to being released.

There's odbc support using pywin32's odbc module as well, which
should be more than sufficient. My web search skillz apparently
were not up to snuff this morning.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: detect endianness of a binary with python

2010-07-21 Thread Grant Edwards
On 2010-07-21, Holger brunck  wrote:

> I use python 2.5 and I am looking for a possibility to determine a
> file type. Especially the endianness of a file is needed for me. Is
> there a way to detect this easily in python?

Only if you already know what's going to be in the file.

> Something like the "file" utility for linux would be very helpfull.
>
> Any help is appreciated.

You're going to have to describe in detail what's in the file before
anybody can help.

-- 
Grant Edwards   grant.b.edwardsYow! A shapely CATHOLIC
  at   SCHOOLGIRL is FIDGETING
  gmail.cominside my costume..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: detect endianness of a binary with python

2010-07-21 Thread Michael Torrie
On 07/21/2010 08:02 AM, Grant Edwards wrote:
> On 2010-07-21, Holger brunck  wrote:
> 
>> I use python 2.5 and I am looking for a possibility to determine a
>> file type. Especially the endianness of a file is needed for me. Is
>> there a way to detect this easily in python?
> 
> Only if you already know what's going to be in the file.
> 
>> Something like the "file" utility for linux would be very helpfull.
>>
>> Any help is appreciated.
> 
> You're going to have to describe in detail what's in the file before
> anybody can help.

There is a python module called "magic" that uses the same engine as
file to determine a file type.  It's part of the "find" source code:

http://www.darwinsys.com/file/

On Fedora I can just yum install python-magic to get it.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: blist 1.2.0

2010-07-21 Thread Daniel Stutzbach
The blist package contains several container types to supplement those
built-in to Python.  These types closely mirror the built-in types' methods,
so the learning curve is close to zero.  The package includes:

- blist: a list type with O(log n) insertions, deletes, and slices and other
performance enhancements
- btuple: a tuple type with O(log) slices
- sorteddict: a dict type that efficiently keeps keys in sorted order
- sortedlist: a list type that efficiently keeps the items sorted order
- sortedset: an indexable set type that efficiently keeps the items sorted
order
- weaksortedlist, weaksortedset: weak reference versions of sortedlist and
sortedset

What's new?
---

- blist.sort() is now *substantially* faster than list.sort() when using int
or float keys (O(n) vs. O(n log n))
- The sortedset, sortedlist, and sorteddict types have been revamped for
better compatibility with the standard library's types.
- Comprehensive reference documentation is now available at
http://stutzbachenterprises.com/blist/
- Numerous other speed improvements

Links
-

- blist vs. list performance comparison:
http://stutzbachenterprises.com/performance-blist
- Documentation: http://stutzbachenterprises.com/blist/
- Download: http://pypi.python.org/pypi/blist/
- Source repository: http://github.com/DanielStutzbach/blist
- Issue tracker: http://github.com/DanielStutzbach/blist/issues
--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC 
-- 
http://mail.python.org/mailman/listinfo/python-list


Multiline regex

2010-07-21 Thread Brandon Harris
I'm trying to read in and parse an ascii type file that contains 
information that can span several lines.

Example:

createNode animCurveTU -n "test:master_globalSmooth";
   setAttr ".tan" 9;
   setAttr -s 4 ".ktv[0:3]"  101 0 163 0 169 0 201 0;
   setAttr -s 4 ".kit[3]"  10;
   setAttr -s 4 ".kot[3]"  10;
createNode animCurveTU -n "test:master_res";
   setAttr ".tan" 9;
   setAttr ".ktv[0]"  103 0;
   setAttr ".kot[0]"  5;
createNode animCurveTU -n "test:master_faceRig";
   setAttr ".tan" 9;
   setAttr ".ktv[0]"  103 0;
   setAttr ".kot[0]"  5;

I'm wanting to grab the information out in chunks, so

createNode animCurveTU -n "test:master_faceRig";
   setAttr ".tan" 9;
   setAttr ".ktv[0]"  103 0;
   setAttr ".kot[0]"  5;

would be what my regex would grab.
I'm currently only able to grab out the first line and part of the 
second line, but no more.

regex is as follows

my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*")

I've run several variations of this, but none return me all of the 
expected information.


Is there something special that needs to be done to have the regexp grab 
any number of the setAttr lines without specification?


Brandon L. Harris


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


Re: Multiline regex

2010-07-21 Thread Rodrick Brown
Slurp the entire file into a string and pick out the fields you need.

Sent from my iPhone 4.

On Jul 21, 2010, at 10:42 AM, Brandon Harris  wrote:

> I'm trying to read in and parse an ascii type file that contains information 
> that can span several lines.
> Example:
> 
> createNode animCurveTU -n "test:master_globalSmooth";
>   setAttr ".tan" 9;
>   setAttr -s 4 ".ktv[0:3]"  101 0 163 0 169 0 201 0;
>   setAttr -s 4 ".kit[3]"  10;
>   setAttr -s 4 ".kot[3]"  10;
> createNode animCurveTU -n "test:master_res";
>   setAttr ".tan" 9;
>   setAttr ".ktv[0]"  103 0;
>   setAttr ".kot[0]"  5;
> createNode animCurveTU -n "test:master_faceRig";
>   setAttr ".tan" 9;
>   setAttr ".ktv[0]"  103 0;
>   setAttr ".kot[0]"  5;
> 
> I'm wanting to grab the information out in chunks, so
> 
> createNode animCurveTU -n "test:master_faceRig";
>   setAttr ".tan" 9;
>   setAttr ".ktv[0]"  103 0;
>   setAttr ".kot[0]"  5;
> 
> would be what my regex would grab.
> I'm currently only able to grab out the first line and part of the second 
> line, but no more.
> regex is as follows
> 
> my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*")
> 
> I've run several variations of this, but none return me all of the expected 
> information.
> 
> Is there something special that needs to be done to have the regexp grab any 
> number of the setAttr lines without specification?
> 
> Brandon L. Harris
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex

2010-07-21 Thread Brandon Harris

what do you mean by slurp the entire file?
I'm trying to use regular expressions because line by line parsing will 
be too slow. And example file would have somewhere in the realm of 6 
million lines of code.


Brandon L. Harris

Rodrick Brown wrote:

Slurp the entire file into a string and pick out the fields you need.

Sent from my iPhone 4.

On Jul 21, 2010, at 10:42 AM, Brandon Harris  wrote:

  

I'm trying to read in and parse an ascii type file that contains information 
that can span several lines.
Example:

createNode animCurveTU -n "test:master_globalSmooth";
  setAttr ".tan" 9;
  setAttr -s 4 ".ktv[0:3]"  101 0 163 0 169 0 201 0;
  setAttr -s 4 ".kit[3]"  10;
  setAttr -s 4 ".kot[3]"  10;
createNode animCurveTU -n "test:master_res";
  setAttr ".tan" 9;
  setAttr ".ktv[0]"  103 0;
  setAttr ".kot[0]"  5;
createNode animCurveTU -n "test:master_faceRig";
  setAttr ".tan" 9;
  setAttr ".ktv[0]"  103 0;
  setAttr ".kot[0]"  5;

I'm wanting to grab the information out in chunks, so

createNode animCurveTU -n "test:master_faceRig";
  setAttr ".tan" 9;
  setAttr ".ktv[0]"  103 0;
  setAttr ".kot[0]"  5;

would be what my regex would grab.
I'm currently only able to grab out the first line and part of the second line, 
but no more.
regex is as follows

my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*")

I've run several variations of this, but none return me all of the expected 
information.

Is there something special that needs to be done to have the regexp grab any 
number of the setAttr lines without specification?

Brandon L. Harris


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



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


Re: Multiline regex

2010-07-21 Thread Eknath Venkataramani
On Wed, Jul 21, 2010 at 8:12 PM, Brandon Harris
wrote:

> I'm trying to read in and parse an ascii type file that contains
> information that can span several lines.
>
Do you have to use only regex? If not, I'd certainly suggest 'pyparsing'.
It's a  pleasure to use and very easy on the eye too, if you know what I
mean.

>  I'm wanting to grab the information out in chunks, so
>

-- 
Eknath Venkataramani
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex

2010-07-21 Thread Brandon Harris
At the moment I'm trying to stick with built in python modules to create 
tools for a much larger pipeline on multiple OSes.


Brandon L. Harris


Eknath Venkataramani wrote:



On Wed, Jul 21, 2010 at 8:12 PM, Brandon Harris 
mailto:brandon.har...@reelfx.com>> wrote:


I'm trying to read in and parse an ascii type file that contains
information that can span several lines.

Do you have to use only regex? If not, I'd certainly suggest 
'pyparsing'. It's a  pleasure to use and very easy on the eye too, if 
you know what I mean.


 I'm wanting to grab the information out in chunks, so


--
Eknath Venkataramani


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


RE: Multiline regex

2010-07-21 Thread Andreas Tawn
> I'm trying to read in and parse an ascii type file that contains
> information that can span several lines.
> Example:
> 
> createNode animCurveTU -n "test:master_globalSmooth";
> setAttr ".tan" 9;
> setAttr -s 4 ".ktv[0:3]"  101 0 163 0 169 0 201 0;
> setAttr -s 4 ".kit[3]"  10;
> setAttr -s 4 ".kot[3]"  10;
> createNode animCurveTU -n "test:master_res";
> setAttr ".tan" 9;
> setAttr ".ktv[0]"  103 0;
> setAttr ".kot[0]"  5;
> createNode animCurveTU -n "test:master_faceRig";
> setAttr ".tan" 9;
> setAttr ".ktv[0]"  103 0;
> setAttr ".kot[0]"  5;
> 
> I'm wanting to grab the information out in chunks, so
> 
> createNode animCurveTU -n "test:master_faceRig";
> setAttr ".tan" 9;
> setAttr ".ktv[0]"  103 0;
> setAttr ".kot[0]"  5;
> 
> would be what my regex would grab.
> I'm currently only able to grab out the first line and part of the
> second line, but no more.
> regex is as follows
> 
> my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*")
> 
> I've run several variations of this, but none return me all of the
> expected information.
> 
> Is there something special that needs to be done to have the regexp
> grab
> any number of the setAttr lines without specification?
> 
> Brandon L. Harris

Aren't you making life too complicated for yourself?

blocks = []
for line in yourFile:
if line.startswith("createNode"):
if currentBlock:
blocks.append(currentBlock)
currentBlock = [line]
else:
currentBlock.append(line)
blocks.append(currentBlock)

Cheers,

Drea
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex

2010-07-21 Thread Peter Otten
Brandon Harris wrote:

> I'm trying to read in and parse an ascii type file that contains
> information that can span several lines.
> Example:
> 
> createNode animCurveTU -n "test:master_globalSmooth";
> setAttr ".tan" 9;
> setAttr -s 4 ".ktv[0:3]"  101 0 163 0 169 0 201 0;
> setAttr -s 4 ".kit[3]"  10;
> setAttr -s 4 ".kot[3]"  10;
> createNode animCurveTU -n "test:master_res";
> setAttr ".tan" 9;
> setAttr ".ktv[0]"  103 0;
> setAttr ".kot[0]"  5;
> createNode animCurveTU -n "test:master_faceRig";
> setAttr ".tan" 9;
> setAttr ".ktv[0]"  103 0;
> setAttr ".kot[0]"  5;
> 
> I'm wanting to grab the information out in chunks, so
> 
> createNode animCurveTU -n "test:master_faceRig";
> setAttr ".tan" 9;
> setAttr ".ktv[0]"  103 0;
> setAttr ".kot[0]"  5;
> 
> would be what my regex would grab.
> I'm currently only able to grab out the first line and part of the
> second line, but no more.
> regex is as follows
> 
> my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*")
> 
> I've run several variations of this, but none return me all of the
> expected information.
> 
> Is there something special that needs to be done to have the regexp grab
> any number of the setAttr lines without specification?

Groups are marked with parens (...) not brackets [...].

>>> text = """\
... createNode animCurveTU -n "test:master_globalSmooth";
... setAttr ".tan" 9;
... setAttr -s 4 ".ktv[0:3]"  101 0 163 0 169 0 201 0;
... setAttr -s 4 ".kit[3]"  10;
... setAttr -s 4 ".kot[3]"  10;
... createNode animCurveTU -n "test:master_res";
... setAttr ".tan" 9;
... setAttr ".ktv[0]"  103 0;
... setAttr ".kot[0]"  5;
... createNode animCurveTU -n "test:master_faceRig";
... setAttr ".tan" 9;
... setAttr ".ktv[0]"  103 0;
... setAttr ".kot[0]"  5;
... """
>>> for m in re.compile("(createNode 
>>> animCurve.*\n(\s*setAttr.*\n)*)").finditer(text):
... print m.group(1)
... print "-" * 40
...
createNode animCurveTU -n "test:master_globalSmooth";
setAttr ".tan" 9;
setAttr -s 4 ".ktv[0:3]"  101 0 163 0 169 0 201 0;
setAttr -s 4 ".kit[3]"  10;
setAttr -s 4 ".kot[3]"  10;


createNode animCurveTU -n "test:master_res";
setAttr ".tan" 9;
setAttr ".ktv[0]"  103 0;
setAttr ".kot[0]"  5;


createNode animCurveTU -n "test:master_faceRig";
setAttr ".tan" 9;
setAttr ".ktv[0]"  103 0;
setAttr ".kot[0]"  5;



Peter

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


Re: Accumulate function in python

2010-07-21 Thread John Nagle

On 7/19/2010 9:56 AM, dhruvbird wrote:

On Jul 19, 9:12 pm, Brian Victor  wrote:

dhruvbird wrote:



Having offered this, I don't recall ever seeing reduce used in real
python code, and explicit iteration is almost always preferred.


Yes, even I have noticed that reduce is a tad under-used function.


Yes, I had a use case for it once, but it wasn't worth the trouble.
"map" is often useful, but "reduce", not so much.

Python isn't really a functional language.  There's no bias toward
functional solutions, lambdas aren't very general, and the performance
isn't any better.  Nor is any concurrency provided by "map" or "reduce".
So there's no win in trying to develop cute one-liners.

John Nagle
--
http://mail.python.org/mailman/listinfo/python-list


Re: detect endianness of a binary with python

2010-07-21 Thread Holger brunck

>> Something like the "file" utility for linux would be very helpfull.
>>
>> Any help is appreciated.

>You're going to have to describe in detail what's in the file before
>anybody can help.

We are creating inside our buildsystem for an embedded system  a cram filesystem
image. Later on inside our build process we have to check the endianness,
because it could be Little Endian or big endian (arm or ppc).

The output of the "file" tool is for a little endian cramfs image:
: Linux Compressed ROM File System data, little endian size 1875968
version #2 sorted_dirs CRC 0x8721dfc0, edition 0, 462 blocks, 10 files

It would be possible to execute
ret = os.system("file  | grep "little endian")
and evaluate the return code.
But I don't like to evaluate a piped system command. If there is an way without
using the os.system command this would be great.

Best regards
Holger

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


Re: ANN: blist 1.2.0

2010-07-21 Thread Antoine Pitrou
On Wed, 21 Jul 2010 09:47:08 -0500
Daniel Stutzbach  wrote:
> 
> What's new?
> ---
> 
> - blist.sort() is now *substantially* faster than list.sort() when using int
> or float keys (O(n) vs. O(n log n))

Are you using some kind of radix sort?
Could it be contributed back into the standard list type?

Regards

Antoine.


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


Re: RE: Multiline regex

2010-07-21 Thread Brandon Harris
I could make it that simple, but that is also incredibly slow and on a 
file with several million lines, it takes somewhere in the league of 
half an hour to grab all the data. I need this to grab data from many 
many file and return the data quickly.


Brandon L. Harris


Andreas Tawn wrote:

I'm trying to read in and parse an ascii type file that contains
information that can span several lines.
Example:

createNode animCurveTU -n "test:master_globalSmooth";
setAttr ".tan" 9;
setAttr -s 4 ".ktv[0:3]"  101 0 163 0 169 0 201 0;
setAttr -s 4 ".kit[3]"  10;
setAttr -s 4 ".kot[3]"  10;
createNode animCurveTU -n "test:master_res";
setAttr ".tan" 9;
setAttr ".ktv[0]"  103 0;
setAttr ".kot[0]"  5;
createNode animCurveTU -n "test:master_faceRig";
setAttr ".tan" 9;
setAttr ".ktv[0]"  103 0;
setAttr ".kot[0]"  5;

I'm wanting to grab the information out in chunks, so

createNode animCurveTU -n "test:master_faceRig";
setAttr ".tan" 9;
setAttr ".ktv[0]"  103 0;
setAttr ".kot[0]"  5;

would be what my regex would grab.
I'm currently only able to grab out the first line and part of the
second line, but no more.
regex is as follows

my_regexp =e.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*")

I've run several variations of this, but none return me all of the
expected information.

Is there something special that needs to be done to have the regexp
grab
any number of the setAttr lines without specification?

Brandon L. Harris



Aren't you making life too complicated for yourself?

blocks =]
for line in yourFile:
if line.startswith("createNode"):
if currentBlock:
blocks.append(currentBlock)
currentBlock =line]
else:
currentBlock.append(line)
blocks.append(currentBlock)

Cheers,

Drea

  


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


RE: RE: Multiline regex

2010-07-21 Thread Andreas Tawn
> I could make it that simple, but that is also incredibly slow and on a
> file with several million lines, it takes somewhere in the league of
> half an hour to grab all the data. I need this to grab data from many
> many file and return the data quickly.
> 
> Brandon L. Harris

That's surprising.

I just made a file with 13 million lines of your data (447Mb) and read it with 
my code. It took a little over 36 seconds. There must be something different in 
your set up or the real data you've got.

Cheers,

Drea
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex

2010-07-21 Thread Brandon Harris
Could it be that there isn't just that type of data in the file? there 
are many different types, that is just one that I'm trying to grab.


Brandon L. Harris


Andreas Tawn wrote:

I could make it that simple, but that is also incredibly slow and on a
file with several million lines, it takes somewhere in the league of
half an hour to grab all the data. I need this to grab data from many
many file and return the data quickly.

Brandon L. Harris



That's surprising.

I just made a file with 13 million lines of your data (447Mb) and read it with 
my code. It took a little over 36 seconds. There must be something different in 
your set up or the real data you've got.

Cheers,

Drea
  


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


Re: ANN: blist 1.2.0

2010-07-21 Thread Daniel Stutzbach
On Wed, Jul 21, 2010 at 10:32 AM, Antoine Pitrou wrote:

> Are you using some kind of radix sort?
> Could it be contributed back into the standard list type?


Yes and yes.  I have a few mostly-complete patches on the tracker that I
need to polish off, as well as several easy-to-fix bugs that I need to take
care of.  After that I plan to work on porting my sort optimizations back to
the standard list type.

Here's a performance comparison of sorting with blist versus 3.1's list:
http://stutzbachenterprises.com/performance-blist/sort-random-list
--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC 
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Multiline regex

2010-07-21 Thread Andreas Tawn
>>> I could make it that simple, but that is also incredibly slow and on
>>> a file with several million lines, it takes somewhere in the league of
>>> half an hour to grab all the data. I need this to grab data from
>>> many many file and return the data quickly.
>>>
>>> Brandon L. Harris
>>>
>> That's surprising.
>>
>> I just made a file with 13 million lines of your data (447Mb) and
>> read it with my code. It took a little over 36 seconds. There must be
>> something different in your set up or the real data you've got.
>>
>> Cheers,
>>
>> Drea
>>
> Could it be that there isn't just that type of data in the file? there
> are many different types, that is just one that I'm trying to grab.
> 
> Brandon L. Harris

I don't see why it would make such a difference.

If your data looks like...


\t
\t
\t

Just change this line...

if line.startswith("createNode"):

to...

if not line.startswith("\t"):

and it won't care what sort of data the file contains.

Processing that data after you've collected it will still take a while, but 
that's the same whichever method you use to read it.

Cheers,

Drea

p.s. Just noticed I hadn't pre-declared the currentBlock list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex

2010-07-21 Thread Jeremy Sanders
Brandon Harris wrote:

> I'm trying to read in and parse an ascii type file that contains
> information that can span several lines.
> Example:

What about something like this (you need re.MULTILINE):

In [16]: re.findall('^([^ ].*\n([ ].*\n)+)', a, re.MULTILINE)
Out[16]: 
[('createNode animCurveTU -n "test:master_globalSmooth";\nsetAttr ".tan" 
9;\nsetAttr -s 4 ".ktv[0:3]"  101 0 163 0 169 0 201 0;\nsetAttr -s 4 
".kit[3]"  10;\nsetAttr -s 4 ".kot[3]"  10;\n',
  'setAttr -s 4 ".kot[3]"  10;\n'),
 ('createNode animCurveTU -n "test:master_res";\nsetAttr ".tan" 9;\n
setAttr ".ktv[0]"  103 0;\nsetAttr ".kot[0]"  5;\n',
  'setAttr ".kot[0]"  5;\n'),
 ('createNode animCurveTU -n "test:master_faceRig";\nsetAttr ".tan" 9;\n
setAttr ".ktv[0]"  103 0;\n',
  'setAttr ".ktv[0]"  103 0;\n')]

If you blocks start without a space and subsequent lines with a space.

Jeremy


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


Re: convert time to UTC seconds since epoch

2010-07-21 Thread Steve Allen
On Jul 20, 6:57 pm, Chris Rebert  wrote:
[regarding trust of POSIX vis a vis leap seconds]
> I'm not saying they necessarily should, but they're standardized and
> the `time` module is based on POSIX/Unix-ish assumptions; not
> following POSIX would be inconsistent and problematic.
> Breaking standards is bad, M'Kay?

Standards are good.  When it comes to leap seconds there can be no
current implementation which satisfies everyone because of this
http://www.ucolick.org/~sla/leapsecs/epochtime.html
Until the delegates to ITU-R SG7 produce a better recommendation there
is going to be chaotic disregard of the standard where folks with
different needs choose different practical implementations.
-- 
http://mail.python.org/mailman/listinfo/python-list


Inconsistency in the format docstring (2.7).

2010-07-21 Thread jmfauth
Small inconsistency in the format.__doc__

>>> sys.version
2.7 (r27:82525, Jul  4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)]
>>> ''.format.__doc__
S.format(*args, **kwargs) -> unicode


>>> type('{}'.format(999))

>>> type('{}'.format('abcé'))

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


Re: detect endianness of a binary with python

2010-07-21 Thread Thomas Jollans
On 07/21/2010 05:29 PM, Holger brunck wrote:
> 
>>> Something like the "file" utility for linux would be very helpfull.
>>>
>>> Any help is appreciated.
> 
>> You're going to have to describe in detail what's in the file before
>> anybody can help.
> 
> We are creating inside our buildsystem for an embedded system  a cram 
> filesystem
> image. Later on inside our build process we have to check the endianness,
> because it could be Little Endian or big endian (arm or ppc).
> 
> The output of the "file" tool is for a little endian cramfs image:
> : Linux Compressed ROM File System data, little endian size 1875968
> version #2 sorted_dirs CRC 0x8721dfc0, edition 0, 462 blocks, 10 files
> 
> It would be possible to execute
> ret = os.system("file  | grep "little endian")
> and evaluate the return code.
> But I don't like to evaluate a piped system command. If there is an way 
> without
> using the os.system command this would be great.

Files don't, as such, have a detectable endianess. 0x23 0x41 could mean
either 0x4123 or 0x2341 - there's no way of knowing.

The "file" utility also doensn't really know about endianess (well,
maybe it does swap bytes here and there, but that's an implementation
detail) - it just knows about file types. It knows what a little-endian
cramfs image looks like, and what a big-endian cramfs image looks like.
And as they're different, it can tell them apart.

If you're only interested in a couple of file types, it shouldn't be too
difficult to read the first few bytes/words with the struct module and
apply your own heuristics. Open the files in question in a hex editor
and try to figure out how to tell them apart!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: detect endianness of a binary with python

2010-07-21 Thread MRAB

Thomas Jollans wrote:

On 07/21/2010 05:29 PM, Holger brunck wrote:

Something like the "file" utility for linux would be very helpfull.

Any help is appreciated.

You're going to have to describe in detail what's in the file before
anybody can help.

We are creating inside our buildsystem for an embedded system  a cram filesystem
image. Later on inside our build process we have to check the endianness,
because it could be Little Endian or big endian (arm or ppc).

The output of the "file" tool is for a little endian cramfs image:
: Linux Compressed ROM File System data, little endian size 1875968
version #2 sorted_dirs CRC 0x8721dfc0, edition 0, 462 blocks, 10 files

It would be possible to execute
ret = os.system("file  | grep "little endian")
and evaluate the return code.
But I don't like to evaluate a piped system command. If there is an way without
using the os.system command this would be great.


Files don't, as such, have a detectable endianess. 0x23 0x41 could mean
either 0x4123 or 0x2341 - there's no way of knowing.

The "file" utility also doensn't really know about endianess (well,
maybe it does swap bytes here and there, but that's an implementation
detail) - it just knows about file types. It knows what a little-endian
cramfs image looks like, and what a big-endian cramfs image looks like.
And as they're different, it can tell them apart.

If you're only interested in a couple of file types, it shouldn't be too
difficult to read the first few bytes/words with the struct module and
apply your own heuristics. Open the files in question in a hex editor
and try to figure out how to tell them apart!


If you have control over the file format then you could ensure that
there's a double-byte value such as 0xFF00 at a certain offset. That
will tell you the endianness of the file.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pydev 1.6.0 Released

2010-07-21 Thread Дамјан Георгиевски
> Pydev 1.6.0 has been released
> 
> Details on Pydev: http://pydev.org
> Details on its development: http://pydev.blogspot.com

The supposed feature to start a console in which the contents of the 
current editor window are automatically "exec"ed /available still 
doesn't work for me.

I'm talking about this:
http://www.pydev.org/manual_adv_interactive_console.html

Pressing Ctrl-Alt-Enter, a interactive console opens but my class 
defined in the editor window is not available.




-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Perfection is achieved, not when there is nothing more to add, but
when there is nothing left to take away. - Antoine de Saint-Exupéry

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


Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of NANO

2010-07-21 Thread nanothermite911fbibustards
Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX
MAILER ??? Where are the 4 blackboxes, where are the 5 dancing
israelis and what is the status of FORENSIC evidence and trace of NANO
THERMITE in WTC dust ?


The FAT per DIEM FBI bustards use our TAX PAYER MONEY and INCOMPETENCE
is UNACCEPTABLE.

=

http://www.youtube.com/watch?v=lX18zUp6WPY

http://www.youtube.com/watch?v=XQapkVCx1HI

http://www.youtube.com/watch?v=tXJ-k-iOg0M

Hey Racist and INcompetent FBI Bustards, where is the ANTHRAX Mailer ?
Where are the 4 blackboxes ? Where are the Pentagon Videos ? Why did
you release the 5 dancing Israelis compromising the whole 911
investigation ? If the Dubai Police can catch Mossad Murderers and put
the videos and Iranian Police can why cant you put the Pentagon
Videos ? If Iran police can put the AMERICAN TERRORIST, Riggi and
puting on INTERNATIONAL MEDIA a day after catching him without
TORTURE, why cant you put the INNOCENT patsies on the MEDIA. Why did
you have to LIE about Dr Afiya Siddiqui and torture that Innocent
little mother of 3 and smashing the skull of her one child ?

http://www.youtube.com/watch?v=DhMcii8smxk
http://www.youtube.com/watch?v=0SZ2lxDJmdg

There are CRIMINAL cases against CIA CRIMINAL Bustards in Italian
courts.

FBI bustards paid a penalty of $5.8 million to Steven Hatfill, but
only because he was a white. They got away with MURDER of thousands of
Non-whites in all parts of the world.

Daily 911 news : http://911blogger.com

http://www.youtube.com/watch?v=tRfhUezbKLw

http://www.youtube.com/watch?v=x7kGZ3XPEm4

http://www.youtube.com/watch?v=lX18zUp6WPY

Conclusion : FBI bustards are RACIST and INcompetent. They could
neither catch the ANTHRAX or 911 YANK/Jew criminals nor could they
cover them up - whichever was their actual goal or task.

SLASH the SALARIES of FBI/CIA/NSA etc BUSTARDS into half all across
tbe board, esp the whites/jew on the top.

FBI Bustards failed to Catch BERNARD MADOFF even after that RACIST and
UNPATRIOTIC Act
FBI bustards failed to prevent ROMAN POLANSKY from absconding to
europe and rapes.
FBI bustards failed to prevent OKLAHOMA

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


Re: urllib2 test fails (2.7, linux)

2010-07-21 Thread guandalino
On 20 Lug, 21:24, Terry Reedy  wrote:

Hi Terry, thanks for your reply.

> > ==
> > ERROR: test_file (__main__.HandlerTests)
> > --
> > Traceback (most recent call last):
> >    File "test_urllib2.py", line 711, in test_file
> >      h.file_open, Request(url))
[cut]
> You could insert a print to find what url caused a problem.

Output:
file://localhost:80/home/redt/sandbox/2.7/lib/python2.7/test/%40test_29416_tmp
file:///file_does_not_exist.txt
file://127.0.0.1:80/home/home/redt/sandbox/2.7/lib/python2.7/test/@test_29416_tmp
file://somerandomhost.ontheinternet.com/home/home/redt/sandbox/2.7/lib/python2.7/test/@test_29416_tmp

Offending line is the the 4th.

> This is in unittest.py. It says that this test case *should* fail, but
> with a different error (urllib.error.URLError) than the one you got
> (gaierror).
>
> >    File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1269,
> > in file_open
> >      return self.open_local_file(req)
> >    File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1301,
> > in open_local_file
> >      (not port and socket.gethostbyname(host) in self.get_names()):
> > gaierror: [Errno -5] No address associated with hostname
>
> gaierror comes from socket.gethostbyname

When I print the value of the variable 'host' in urllib2.py line 1301
I get this: somerandomhost.ontheinternet.com. This is why
socket.gethostbyname(host) raises gaierror -5, there is no address
associated to somerandomhost.ontheinternet.com. Instead the values
that 'host' takes for the other urls are localhost or 127.0.0.1, both
valid for gethostbyname().

Any hint?

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


Re: ANN: blist 1.2.0

2010-07-21 Thread Terry Reedy

On 7/21/2010 12:15 PM, Daniel Stutzbach wrote:


Here's a performance comparison of sorting with blist versus 3.1's list:
http://stutzbachenterprises.com/performance-blist/sort-random-list


Question related to possible addition of radix sort to lists:

These tests use random numbers with a constant, relatively high density 
of 25%, which is favorable to radix sort. What if you do the same test 
with a constant range of, say, 10 (1 billion) or even a trillion 
or quadrillion. Or how about sorting a thousand 128bit ip6 addresses? 
Which wins for that?


list.sort is (near) linear for lists that are mostly ordered. I think 
Tim's writeup about this in in the source. For instance, if one extends 
a sorted with 1% random additions and resorts, list.sort will skip the 
sorted part, sort the additions, and merge them back in. Radix sort 
ignores pre-existing order. So either a lot of comparitive profiling 
would be needed for auto-selection of sort method, or it should be user 
selectable.


Does your radix sort meet the stability guarantee of list.sort?
If not, a separate .rsort method would be needed anyway.

--
Terry Jan Reedy

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


Re: Inconsistency in the format docstring (2.7).

2010-07-21 Thread Terry Reedy

On 7/21/2010 2:13 PM, jmfauth wrote:

Small inconsistency in the format.__doc__


sys.version

2.7 (r27:82525, Jul  4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)]

''.format.__doc__

S.format(*args, **kwargs) ->  unicode



type('{}'.format(999))



type('{}'.format('abcé'))




Thank you for reporting this. Forwarded to the tracker as
http://bugs.python.org/issue9328

--
Terry Jan Reedy


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


Re: ANN: blist 1.2.0

2010-07-21 Thread Daniel Stutzbach
On Wed, Jul 21, 2010 at 5:27 PM, Terry Reedy  wrote:

> These tests use random numbers with a constant, relatively high density of
> 25%, which is favorable to radix sort. What if you do the same test with a
> constant range of, say, 10 (1 billion) or even a trillion or
> quadrillion. Or how about sorting a thousand 128bit ip6 addresses? Which
> wins for that?
>

blist switches to radix sort only if the keys contain only floats or only
integers that fit into a C long.  If the integers get too big, it reverts to
timsort.

When using a sort key, the decorate-sort-undecorate pattern requires
touching every object once before the sort.  The check for a consistent type
is done inexpensively during the decorate phase.

Here's an example result with a density of only 1%, where the radix sort is
around 4 times as fast:


otto:~/src/blist$ python3.1 -m timeit -s 'import random' -s 'x =
[random.randrange(1*100) for i in range(1)]' 'y = list(x)'
'y.sort(key=float)'
100 loops, best of 3: 12.4 msec per loop

otto:~/src/blist$ python3.1 -m timeit -s 'from blist import blist' -s
'import random' -s 'x = [random.randrange(1*100) for i in range(1)]'
'y = blist(x)' 'y.sort(key=float)'
100 loops, best of 3: 3.4 msec per loop


And a density of 0.01%:


otto:~/src/blist$ python3.1 -m timeit -s 'import random' -s 'x =
[random.randrange(1*1) for i in range(1)]' 'y = list(x)'
'y.sort(key=float)'
100 loops, best of 3: 12 msec per loop

otto:~/src/blist$ python3.1 -m timeit -s 'from blist import blist' -s
'import random' -s 'x = [random.randrange(1*1) for i in
range(1)]' 'y = blist(x)' 'y.sort(key=float)'
100 loops, best of 3: 3.52 msec per loop


> list.sort is (near) linear for lists that are mostly ordered. I think Tim's
> writeup about this in in the source. For instance, if one extends a sorted
> with 1% random additions and resorts, list.sort will skip the sorted part,
> sort the additions, and merge them back in. Radix sort ignores pre-existing
> order. So either a lot of comparitive profiling would be needed for
> auto-selection of sort method, or it should be user selectable.
>

I've tested exactly that scenario.  For already-ordered lists, radix sort
and timsort tie.


> Does your radix sort meet the stability guarantee of list.sort?
>

Yes.
--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib2 test fails (2.7, linux)

2010-07-21 Thread Terry Reedy

On 7/21/2010 5:06 PM, guandalino wrote:

On 20 Lug, 21:24, Terry Reedy  wrote:

Hi Terry, thanks for your reply.


==
ERROR: test_file (__main__.HandlerTests)
--
Traceback (most recent call last):
File "test_urllib2.py", line 711, in test_file
  h.file_open, Request(url))

[cut]

You could insert a print to find what url caused a problem.


Output:
file://localhost:80/home/redt/sandbox/2.7/lib/python2.7/test/%40test_29416_tmp
file:///file_does_not_exist.txt
file://127.0.0.1:80/home/home/redt/sandbox/2.7/lib/python2.7/test/@test_29416_tmp
file://somerandomhost.ontheinternet.com/home/home/redt/sandbox/2.7/lib/python2.7/test/@test_29416_tmp
Offending line is the the 4th.


Ah. I did not see anything like that in 3.1 test_urllib2. Either I just 
simply missed it, or it is obscured, or it was removed because it causes 
failures;-).



This is in unittest.py. It says that this test case *should* fail, but
with a different error (urllib.error.URLError) than the one you got
(gaierror).


File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1269,
in file_open
  return self.open_local_file(req)
File "/home/redt/sandbox/2.7/lib/python2.7/urllib2.py", line 1301,
in open_local_file
  (not port and socket.gethostbyname(host) in self.get_names()):
gaierror: [Errno -5] No address associated with hostname


gaierror comes from socket.gethostbyname


When I print the value of the variable 'host' in urllib2.py line 1301
I get this: somerandomhost.ontheinternet.com. This is why
socket.gethostbyname(host) raises gaierror -5, there is no address
associated to somerandomhost.ontheinternet.com. Instead the values
that 'host' takes for the other urls are localhost or 127.0.0.1, both
valid for gethostbyname().

Any hint?


Remove the offending fake url.

If you want to investigate the history of the file, go to
http://svn.python.org/view/python/branches/release27-maint/Lib/test/test_urllib2.py?view=log

If you do not get an answer here, file a bug report. If you can, put
orsenthil,benjamin.peterson,ezio.melotti
on the nosy list, as they are recent committers to this file. Say I said 
to do so if you want. Add tjreedy also so I can see responses and learn too.


--
Terry Jan Reedy

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


Re: [ann] Hatta 1.4.0 wiki engine released

2010-07-21 Thread James Mills
On Wed, Jul 21, 2010 at 6:01 PM, Radomir Dopieralski  wrote:
> I'm proud to announce release 1.4.0 of Hatta wiki engine.

Congrats.

cheers
James

-- 
-- James Mills
--
-- "Problems are solved by method"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of

2010-07-21 Thread spudnik
thermite is not what you think, it is;
it's primary use is for dismantling steel frameworks,
piece by piece, just as they were welded --
see the report by MIT's Head Welder.

thus:
there, you've hit upon the self-same absurdity
of Newton's "theory" of corpuscles, vis-a-vu waves of light
in the non-vacuum of space (unconsciously .-)

thus quoth:
Does every dust speck have gravitons?  And if not, how do the specks
know... "which way the mass is"?

--BP's cap&trade "free-er trade nostrum" is before Senate!
http://tarpley.net/online-books/george-bush-the-unauthorized-biography/chapter-8-the-permian-basin-gang/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex

2010-07-21 Thread Steven D'Aprano
On Wed, 21 Jul 2010 10:06:14 -0500, Brandon Harris wrote:

> what do you mean by slurp the entire file? I'm trying to use regular
> expressions because line by line parsing will be too slow.  And example
> file would have somewhere in the realm of 6 million lines of code.

And you think trying to run a regex over all 6 million lines at once will 
be faster? I think you're going to be horribly, horribly disappointed.


And then on Wed, 21 Jul 2010 10:42:11 -0500, Brandon Harris wrote:

> I could make it that simple, but that is also incredibly slow and on a
> file with several million lines, it takes somewhere in the league of
> half an hour to grab all the data. I need this to grab data from many
> many file and return the data quickly.

What do you mean "grab" all the data? If all you mean is read the file, 
then 30 minutes to read ~ 100MB of data is incredibly slow and you're 
probably doing something wrong, or you're reading it over a broken link 
with very high packet loss, or something.

If you mean read the data AND parse it, then whether that is "incredibly 
slow" or "amazingly fast" depends entirely on how complicated your parser 
needs to be.

If *all* you mean is "read the file and group the lines, for later 
processing", then I would expect it to take well under a minute to group 
millions of lines. Here's a simulation I ran, using 2001000 lines of text 
based on the examples you gave. It grabs the blocks, as required, but 
does no further parsing of them.


def merge(lines):
"""Join multiple lines into a single block."""
accumulator = []
for line in lines:
if line.lower().startswith('createnode'):
if accumulator:
yield ''.join(accumulator)
accumulator = []
accumulator.append(line)
if accumulator:
yield ''.join(accumulator)


def test():
import time
t = time.time()
count = 0
f = open('/steve/test.junk')
for block in merge(f):
# do some make-work
n = sum([1 for c in block if c in '1234567890'])
count += 1
print "Processed %d blocks from 2M+ lines." % count
print "Time taken:", time.time() - t, "seconds"


And the result on a low-end PC:

>>> test()
Processed 1000 blocks from 2M+ lines.
Time taken: 17.4497909546 seconds



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: detect endianness of a binary with python

2010-07-21 Thread Grant Edwards
On 2010-07-21, Thomas Jollans  wrote:

>> It would be possible to execute ret = os.system("file  |
>> grep "little endian") and evaluate the return code. But I don't like
>> to evaluate a piped system command. If there is an way without using
>> the os.system command this would be great.
>
> Files don't, as such, have a detectable endianess. 0x23 0x41 could mean
> either 0x4123 or 0x2341 - there's no way of knowing.
>
> The "file" utility also doensn't really know about endianess (well,
> maybe it does swap bytes here and there, but that's an implementation
> detail) - it just knows about file types. It knows what a little-endian
> cramfs image looks like, and what a big-endian cramfs image looks like.
> And as they're different, it can tell them apart.
>
> If you're only interested in a couple of file types, it shouldn't be too
> difficult to read the first few bytes/words with the struct module and
> apply your own heuristics. Open the files in question in a hex editor
> and try to figure out how to tell them apart!

And by looking at the rules that "file" uses for the two file types
that matter, one should be able to figure out how to implement
something in Python.  Or one can use the Python "magic" module as
previously suggested: http://pypi.python.org/pypi/python-magic/

-- 
Grant

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


Did class inheritance from "dict" work in early Python?

2010-07-21 Thread John Nagle

   Did class inheritance from "dict" work in early Python?  Or did
that only start working when "new objects" came in?

John Nagle
--
http://mail.python.org/mailman/listinfo/python-list


Re: Did class inheritance from "dict" work in early Python?

2010-07-21 Thread Stephen Hansen
On 7/21/10 7:45 PM, John Nagle wrote:
>Did class inheritance from "dict" work in early Python?  Or did
> that only start working when "new objects" came in?

The latter, that's why UserDict (and UserList) was added.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Did class inheritance from "dict" work in early Python?

2010-07-21 Thread Steven D'Aprano
On Wed, 21 Jul 2010 19:45:24 -0700, John Nagle wrote:

> Did class inheritance from "dict" work in early Python?  Or did that
> only start working when "new objects" came in?

Only with the introduction of new-style classes and "object" in version 
2.2.

http://www.python.org/download/releases/2.2.3/descrintro/#subclassing


Before that the technique of choice was to use automatic delegation, e.g. 
see the UserDict module.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: please come and help to defend against ISLAM , bring physicists to refute their calculation on speed of light and wormholes

2010-07-21 Thread nanothermite911fbibustards
On Jul 21, 9:23 pm, nanothermite911fbibustards
 wrote:
> http://www.speed-light.info/angels_speed_of_light.htm

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


Re: Hey RACIST and INcompetent FBI/CIA Bustards where is the ANTHRAX MAILER ??? Where are the 4 blackboxes, where are the 5 dancing israelis and what is the status of FORENSIC evidence and trace of

2010-07-21 Thread nanothermite911fbibustards
On Jul 21, 4:31 pm, spudnik  wrote:
> thermite is not what you think, it is;
> it's primary use is for dismantling steel frameworks,
> piece by piece, just as they were welded --
> see the report by MIT's Head Welder.
>
> thus:
> there, you've hit upon the self-same absurdity
> of Newton's "theory" of corpuscles, vis-a-vu waves of light
> in the non-vacuum of space (unconsciously .-)
>
> thus quoth:
> Does every dust speck have gravitons?  And if not, how do the specks
> know... "which way the mass is"?
>
> --BP's cap&trade "free-er trade nostrum" is before 
> Senate!http://tarpley.net/online-books/george-bush-the-unauthorized-biograph...


Whats the qualification of you a faceless, spky bustard ? unlike
HONORABLE Professor Dr Steven Jones, who sacrificed his job and career
at BYU  - Brigham Young University . Whats your sacrifice to show your
conviction from your ODIOUS and PUTRID mouth ?
-- 
http://mail.python.org/mailman/listinfo/python-list


how to prevent the "extended call syntax" (*) from expanding a string into a list of characters

2010-07-21 Thread fulv
I get the following error:

  File "", line 1, in ?
  File "/Users/fulvio/plone/seiu_new/buildout/eggs/z3c.saconfig-0.11-
py2.4.egg/z3c/saconfig/utility.py", line 164, in __call__
_ENGINES[self._key] = engine = sqlalchemy.create_engine(
  File "/Users/fulvio/plone/seiu_new/buildout/eggs/SQLAlchemy-0.6.3-
py2.4.egg/sqlalchemy/engine/__init__.py", line 244, in create_engine
return strategy.create(*args, **kwargs)
TypeError: create() takes exactly 2 non-keyword arguments (150 given)

Basically, args and kwargs come as the return values from my
overridden function configuration():

args, kw = self.configuration()
_ENGINES[self._key] = engine =
sqlalchemy.create_engine(
*args, **kw)


This is what I'm returning from configuration():

args = (connection_string)
kwargs = {'echo' : True, 'encoding' : 'cp1252'}
return args, kwargs

In other words, args is a list containing just one string.  It seems
to me that create_engine is interpreting that as a list of 150
characters.

Any suggestions, on what I'm doing wrong?

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


Unzip File un Python 5.5

2010-07-21 Thread Girish
Hello All,

I am using Python 2.5. How do I extract all the files and directories
in a zip file?

Thanks in advance..

-Girish
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unzip File un Python 5.5

2010-07-21 Thread nopsidy
hi,

hope this helps.

http://www.google.com/search?hl=en&q=unzip+file+in+python
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to prevent the "extended call syntax" (*) from expanding a string into a list of characters

2010-07-21 Thread James Mills
On Thu, Jul 22, 2010 at 4:26 PM, fulv  wrote:
>  args = (connection_string)

Replace this with:

args = (connection_string,)

NOTE: The trailing , (comma) indicating that this _is_ a tuple.

cheers
James

-- 
-- James Mills
--
-- "Problems are solved by method"
-- 
http://mail.python.org/mailman/listinfo/python-list