String to unicode - duplicating by function the effect of u prefix

2009-06-18 Thread CiTro
I'm looking for a way to convert a string to it's unicode "brother".

This means:

stringOne = "\u0026"
stringTwo = u"\u0026"

print unicode(stringOne) == stringTwo

The result is false. What function should I use, to duplicate the
effect of the "u" prefix ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python tutorial

2009-06-18 Thread Steven D'Aprano
On Thu, 18 Jun 2009 15:58:37 +1000, steve wrote:

> "Steven D'Aprano"  wrote in
> message news:pan.2009.06.18.01.42...@remove.this.cybersource.com.au...
>> On Thu, 18 Jun 2009 10:36:01 +1000, steve wrote:
>>
>>> 1) Windows does not make a distinction between text and binary files.
>>
>> Of course it does.
...
> Ok, Python makes a distinction between text and binary files.

Microsoft have reported a bug where cmd.exe fails to recognise EOF in a 
text file:

http://support.microsoft.com/kb/156258

The behaviour of reading past the \0x1A character is considered a bug, 
which says that cmd.exe at least (and by extension Windows apps in 
general) are expected to stop reading at \0x1A for text files.


Technically, the Windows file systems record the length of text files and 
so an explicit EOF character is redundant, nevertheless, the behaviour of 
stopping the read at \0x1A is expected. Whether you want to claim it is 
"Windows" or "the Windows shell" or something else is a fine distinction 
that makes little difference in practice.

Anyway, here's Raymond Chen of Microsoft explaining more:

http://blogs.msdn.com/oldnewthing/archive/2004/03/16/90448.aspx



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


Re: fastest native python database?

2009-06-18 Thread Pierre Quentel
On 18 juin, 05:28, per  wrote:
> hi all,
>
> i'm looking for a native python package to run a very simple data
> base. i was originally using cpickle with dictionaries for my problem,
> but i was making dictionaries out of very large text files (around
> 1000MB in size) and pickling was simply too slow.
>
> i am not looking for fancy SQL operations, just very simple data base
> operations (doesn't have to be SQL style) and my preference is for a
> module that just needs python and doesn't require me to run a separate
> data base like Sybase or MySQL.
>
> does anyone have any recommendations? the only candidates i've seen
> are snaklesql and buzhug... any thoughts/benchmarks on these?
>
> any info on this would be greatly appreciated. thank you

Hi,

buzhug syntax doesn't use SQL statements, but a more Pythonic syntax :

from buzhug import Base
db = Base('foo').create(('name',str),('age',int))
db.insert('john',33)
# simple queries
print db(name='john')
# complex queries
print [ rec.name for rec in db if age > 30 ]
# update
rec.update(age=34)

I made a few speed comparisons with Gadfly, KirbyBase (another pure-
Python DB, not maintained anymore) and SQLite. You can find the
results on the buzhug home page : http://buzhug.sourceforge.net

The conclusion is that buzhug is much faster than the other pure-
Python db engines, and (only) 3 times slower than SQLite

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


Re: String to unicode - duplicating by function the effect of u prefix

2009-06-18 Thread Peter Otten
CiTro wrote:

> I'm looking for a way to convert a string to it's unicode "brother".
> 
> This means:
> 
> stringOne = "\u0026"
> stringTwo = u"\u0026"
> 
> print unicode(stringOne) == stringTwo
> 
> The result is false. What function should I use, to duplicate the
> effect of the "u" prefix ?

"\u..." has a special meaning only in unicode, not string literals:

>>> s = "\u0026"
>>> len(s)
6
>>> s.decode("unicode-escape")
u'&'
>>> _ == u"\u0026"
True

Peter

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


Re: TypeError: int argument required

2009-06-18 Thread Lawrence D'Oliveiro
In message , Rhodri 
James wrote:

> On Wed, 17 Jun 2009 12:07:15 +0100, Lawrence D'Oliveiro
>  wrote:
> 
> [snip example code]
> 
>> You haven't managed to get rid of the backslashes.
> 
> [snip other example code]
> 
>> Now you've lost track of the original point of the discussion, which is
>> about using alternate quotes to avoid backslashes.
> 
> Ah, selective amnesia, how useful you are.  The original point of the
> discussion was in fact about using alternative quotes to avoid alternate
> backslashes (or at least excessive ones).

No mention of avoiding "alternate backslashes (or at least excessive ones)". 
Here's what I said, in message :

> In message , Rhodri
> James wrote:
> 
>> On Sun, 14 Jun 2009 10:43:30 +0100, Lawrence D'Oliveiro
>>  wrote:
>> 
>>> In message , Rhodri
>>> James wrote:
>>>
 2.  That output string has severe "leaning toothpick" syndrome.  Python
 accepts both single and double quotes to help avoid creating something
 so unreadable: use them.
>>>
>>> Backslashes are more scalable.
>> 
>> That doesn't excuse sprinkling several million backslashes through
>> literal constants when there's a more readable alternative.
> 
> Perl allows just about any printable character as a quote. I tried
> alternative quotes for many years, and decided making that choice was a
> waste of brain cells.
> 
> So no, using alternative quotes does not make things more readable.

Now compare that with Lie Ryan's examples which, instead of using 
backslashes, instead used alternative quotes plus backslashes in one 
example, and in the other example, alternative quotes, alternatives to 
literal quotes, and backslashes. As opposed to my original routine, which 
managed three levels of quoting using just backslashes. Do you begin to 
understand what I mean by "scalable"?

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


Re: fastest native python database?

2009-06-18 Thread Lawrence D'Oliveiro
In message <07ac7d7a-48e1-45e5-a21c-
f2c259c75...@j12g2000vbl.googlegroups.com>, per wrote:

> i'm looking for a native python package to run a very simple data
> base.

Use Python mapping objects. Most real-world databases will fit in memory 
anyway.

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


Re: Regarding Python is scripting language or not

2009-06-18 Thread Arnaud Delobelle
Christian Heimes  writes:

> Terry Reedy wrote:
>> If you mean 'be an instance of a class', which I think is the most
>> natural reading, then Python *is* object-oriented and, if I understand
>> what I have read correctly (so that ints are just (unboxed) ints and not
>> members of an int class), Java *is not*!
>
> A friend of mine calls Java and C++ class centric programming languanges. ;)

It's unfair on C++ given that one can write perfectly good C++ programs
without classes, just as in Python.

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


Re: python tutorial

2009-06-18 Thread steve

"Steven D'Aprano"  wrote in message 
news:pan.2009.06.18.07.05...@remove.this.cybersource.com.au...
> On Thu, 18 Jun 2009 15:58:37 +1000, steve wrote:
>
>> "Steven D'Aprano"  wrote in
>> message news:pan.2009.06.18.01.42...@remove.this.cybersource.com.au...
>>> On Thu, 18 Jun 2009 10:36:01 +1000, steve wrote:
>>>
 1) Windows does not make a distinction between text and binary files.
>>>
>>> Of course it does.
> ...
>> Ok, Python makes a distinction between text and binary files.
>
> Microsoft have reported a bug where cmd.exe fails to recognise EOF in a
> text file:
>
> http://support.microsoft.com/kb/156258
>
> The behaviour of reading past the \0x1A character is considered a bug,
> which says that cmd.exe at least (and by extension Windows apps in
> general) are expected to stop reading at \0x1A for text files.
>
>
> Technically, the Windows file systems record the length of text files and
> so an explicit EOF character is redundant, nevertheless, the behaviour of
> stopping the read at \0x1A is expected. Whether you want to claim it is
> "Windows" or "the Windows shell" or something else is a fine distinction
> that makes little difference in practice.
>
> Anyway, here's Raymond Chen of Microsoft explaining more:
>
> http://blogs.msdn.com/oldnewthing/archive/2004/03/16/90448.aspx
>
>
>
> -- 
> Steven

If you're pleased to be learning something about Windows, then
I'm pleased for you.

The reason that I didn't give a full discussion about the history of
DOS and Microsoft C was that I didn't think it was relevant to a
Python newsgroup.

My Bad. I didn't think anyone would care about the behaviour of
copy vs xcopy in DOS 6-.

I'd like to see the Tutorial corrected so that it gives some useful
information about the behaviour of Python.  As part of that, I'd like
to see it corrected so that it doesn't include patently false information,
but only because the patently false information about Windows
obscures the message about Python.

Believe me, I really don't care what myths you believe about
Windows, or why you believe them.  I've got a full and interesting
life of my own.

I'm only interested in getting the Python tutorial corrected so that it
gives some sensible information to someone who hasn't already had
the advantage of learning what the popular myths represent to the
Python community.

So far I've been pointed to a discussion of C, a discussion of DOS,
and a discussion of Windows NT 4.
Great. Glad to see that you know how to use the Internet.

I'll give you that if you already have a meaning to assign to those
meaningless words, you know more Python than I do.

And I'll give you that if you already have a meaning to assign to
those meaningless words, you know more Visual C than I do.

Is that all there is? You're going to leave the tutorial because
you can mount an obscure justification and it makes sense to
someone who already knows what it means?
Tell me it isn't so :~(



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


Re: How can I enumerate (list) serial ports?

2009-06-18 Thread Jason
On Jun 18, 2:20 pm, Tim Golden  wrote:
> but I imagine that, behind the scenes, it's doing some sort
> of conditional imports according to platform.

I have, and yes indeed it does.

> I imagine you'd
> have to do something similar to get a list of port names.

That's what I thought, although I might just defer to the user knowing
what to type in (since they would have to identify the port allocated
to the device in the first place).

> On Windows, WMI can give you what you want. Look at the
> Win32_SerialPort class. Hopefully, someone else can help
> for other platforms.

Thanks for this pointer :)

Cheers,
Jason
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic way to overwrite a file

2009-06-18 Thread Tim Wintle
On Wed, 2009-06-17 at 14:26 -0400, Cameron Pulsford wrote:
> This is only supposed to handle text files, so when would reading it
> all into memory become too much for most computers? I'm guessing there
> aren't many source files of too great a size.

I often use python with server log files - 1Tb of plain-text wouldn't
seem too much to me, but it wouldn't fit into ram on many computers ;-)

For source files I wouldn't think it would be a problem - but I agree
with Jean-Michel, I can imagine running an app like yours over hundreds
of source files at once. It wouldn't be nice if I decided to kill the
program half way through and found it had died half way through
processing a file and lost my code!


Tim Wintle

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


Re: python tutorial

2009-06-18 Thread Ben Finney
"steve"  writes:

> So far I've been pointed to a discussion of C, a discussion of DOS,
> and a discussion of Windows NT 4. Great. Glad to see that you know how
> to use the Internet.

Says the person who doesn't want to attach an identity to his messages.
(Yes, that's ad hominem if used to dismiss your argument; but it's *you*
that is raising “know how to use the internet”, so at that point you
become fair game, IMO.)

> Is that all there is? You're going to leave the tutorial because you
> can mount an obscure justification and it makes sense to someone who
> already knows what it means? Tell me it isn't so :~(

Who is “you”? Someone who knows how to use the internet surely can tell
that comp.lang.python isn't the place to come expecting *changes* in the
Python tutorial.

You started out asking how to *interpret* it, which is fine for this
forum; but discussing it here isn't going to lead automatically to any
*midification* to a document developed within the core of Python.

-- 
 \  “Whatever you do will be insignificant, but it is very |
  `\important that you do it.” —Mahatma Gandhi |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regarding Python is scripting language or not

2009-06-18 Thread Bruno Desthuilliers

Asun Friere a écrit :
(snip)


OTOH the whole notion of defining OO by the use of classes
automatically excludes from consideration prototype-based OO languages
(eg. Self) which arguably offer a purer approach to OO than class
centric languages.


FWIW, there's no notion of "class" in the minimal (and only commonly 
agreed AFAIK) definitions of OO:


1/ an object id defined by an id, a state and a behaviour
2/ objects communicate by sending messages to each others
--
http://mail.python.org/mailman/listinfo/python-list


please help...writing set to a file

2009-06-18 Thread yadin
Good day every one!

I got this python program that returns me a set like this..
Set ([‘A\n’, B\n’, ‘C\n’, ‘D\n’, ‘E\n’, ‘F\n’, ‘G\n’ ])
And a list pp = [‘100\n’ ‘200\n’ ‘300\n’ ‘400\n’]
I was reading this from a file….
How can I transform this to something that looks like this
Column1 Column 2

  100  A
   200 B
   300 C
400D
 E
 F
 G
And then write this to a file???
thank you for taking your time!!!

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


Re: fastest native python database?

2009-06-18 Thread pdpi
On Jun 18, 8:09 am, Pierre Quentel  wrote:
> On 18 juin, 05:28, per  wrote:
>
>
>
>
>
> > hi all,
>
> > i'm looking for a native python package to run a very simple data
> > base. i was originally using cpickle with dictionaries for my problem,
> > but i was making dictionaries out of very large text files (around
> > 1000MB in size) and pickling was simply too slow.
>
> > i am not looking for fancy SQL operations, just very simple data base
> > operations (doesn't have to be SQL style) and my preference is for a
> > module that just needs python and doesn't require me to run a separate
> > data base like Sybase or MySQL.
>
> > does anyone have any recommendations? the only candidates i've seen
> > are snaklesql and buzhug... any thoughts/benchmarks on these?
>
> > any info on this would be greatly appreciated. thank you
>
> Hi,
>
> buzhug syntax doesn't use SQL statements, but a more Pythonic syntax :
>
> from buzhug import Base
> db = Base('foo').create(('name',str),('age',int))
> db.insert('john',33)
> # simple queries
> print db(name='john')
> # complex queries
> print [ rec.name for rec in db if age > 30 ]
> # update
> rec.update(age=34)
>
> I made a few speed comparisons with Gadfly, KirbyBase (another pure-
> Python DB, not maintained anymore) and SQLite. You can find the
> results on the buzhug home page :http://buzhug.sourceforge.net
>
> The conclusion is that buzhug is much faster than the other pure-
> Python db engines, and (only) 3 times slower than SQLite
>
> - Pierre

Which means that, at this point in time, since both gadfly and sqlite
use approximately the same API, sqlite takes the lead as a core
package (post-2.5 anyway)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: please help...writing set to a file

2009-06-18 Thread Benjamin Kaplan
On Thu, Jun 18, 2009 at 5:24 AM, yadin  wrote:

> Good day every one!
>
> I got this python program that returns me a set like this..
> Set ([‘A\n’, B\n’, ‘C\n’, ‘D\n’, ‘E\n’, ‘F\n’, ‘G\n’ ])
> And a list pp = [‘100\n’ ‘200\n’ ‘300\n’ ‘400\n’]
> I was reading this from a file….
> How can I transform this to something that looks like this
> Column1 Column 2
>
>  100  A
>   200 B
>   300 C
>400D
> E
> F
> G
> And then write this to a file???
> thank you for taking your time!!!
>

I don't think you can. A set doesn't maintain order so you couldn't count on
it being returned in a particular order.


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


Re: please help...writing set to a file

2009-06-18 Thread Dave Angel

yadin wrote:

Good day every one!

I got this python program that returns me a set like this..
Set ([‘A\n’, B\n’, ‘C\n’, ‘D\n’, ‘E\n’, ‘F\n’, ‘G\n’ ])
And a list pp =‘100\n’ ‘200\n’ ‘300\n’ ‘400\n’]
I was reading this from a file….
How can I transform this to something that looks like this
Column1 Column 2

  100  A
   200 B
   300 C
400D
 E
 F
 G
And then write this to a file???
thank you for taking your time!!!


  
Since a set has no order, it cannot be done. There's no association 
between 100 and A that can be independently determined from just the set 
and the list.


Just how was the original assignment worded, anyway? And what version of 
Python are you using for it?


After you solve that problem (perhaps by returning a list in both 
cases), then the real question might be one of formatting.



Since the columns in your example don't line up in any meaningful way, 
perhaps you just want to slap a few spaces before and between the 
elements. You'll need to do a strip() on the pp items, to get rid of the 
newline. Then something like:

line = " " + ppitem.strip() + " " + otheritem

Loop through the lists and send the lines to the file. Don't forget to 
close it at the end.



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


Packing a ctypes struct containing bitfields.

2009-06-18 Thread Karthik
Hello Everybody,

I'm trying to create a packed structure in ctypes (with one 64-bit
element that is bitfielded to 48 bits),
unsuccessfully:

===
from ctypes import *

class foo (Structure):
_pack_ = 1
_fields_ = [
("bar",c_ulonglong, 48),
]

print("sizeof(foo) = %d" % sizeof(foo))
===
I'm expecting that this should print 6 - however, on my box, it prints
8.

The following piece of C code, when compiled and run, prints 6, which
is correct.
===
struct foo {
unsigned long long bar: 48;
};

printf("sizeof(foo) = %d", sizeof(foo));
===

So... what am I doing wrong?

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


pyserial question

2009-06-18 Thread Piter_
Hi all.
I try to control  some equipment from python trough  comport.
I have not succeeded in pyserial. But if I use this terminal:
http://hw-server.com/files/priloha/termv19b.zip
http://hw-server.com/software/termv19b.html
It works with following settings.
Boud rate: 9600
Data bids: 8
Parity: none
stop bids: 1
Handshaking: RST on TX

I cant find out how to set "Handshaking RST on TX" in pyserial.
Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UDP queue size

2009-06-18 Thread Nick Craig-Wood
Martin P. Hellwig  wrote:
>  Scott David Daniels wrote:
> > 找尋自己的一片天 wrote:
> >> I got a problem about UDP.
> >>
> >> How do I get the UDP buffer size?
> >>
> >> When the server had some delay in handling incoming UDP, it will lost
> >> some package. I wonder it's because the system buffer size, is there any
> >> ways to find the exactly size of the buffer?
> > 
> > UDP is defined as "best effort then give up," so _everything_ that
> > handles a UDP packet is allowed to drop it; that means switchers,
> > routers, ..., anything along the path to the target application.
> > So, you cannot expect to do any better than a conservative guess,
> > perhaps augmented by dynamic scaling.
> 
>  I would like to add, that you are most likely to lose packages because
>  they are to big, I can not remember for sure if UDP had a fixed limit
>  above what the MTU does, but you might want to look at that
>  direction too.

UDP messages can be up to 64k.  However they will be fragmented to the
MTU which is 1500 bytes for most ethernet traffic.

The means that the chance of losing a bigger UDP message is much
higher because you only need to lose one of the fragments to lose the
message.

Most people who use UDP try to keep the total message size below 1500
bytes (1480 data without the header IIRC) for that reason.
wireshark/tcpdump will quickly show you whether you are fragmenting
your UDP messages.

Another thing to bear in mind with UDP is that you can easily exceed
the packets / second that switches / routers can bear if you send lots
of small messages.  Switches / routers will start dumping packets if
you do that since.  Some switches just crash in my experience too ;-)

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CAD file format specifications?

2009-06-18 Thread Anthra Norell

norseman wrote:

Anthra Norell wrote:

Andres Acosta wrote:
HI there Anthara have you checked out www.Blender.org, It is open 
source and accepts a lot of your formats. for import and export.

Anrdres
Anthra Norell wrote:

Hi,
  Anyone working with CAD who knows about numeric data entry? I 
have 3d coordinates of a construction site on a slope (borders, 
setbacks and isometric elevation lines). Someone made me aware of 
Google's Sketch Up. It looks very attractive for the purpose of 
architectural planning, especially suited to create visual 
impressions. Doodling seems easy. But I have to start with modeling 
the terrain and the envelope and the only way to do that seems to 
be in one of several CAD file formats (skp, dwg, dxf, 3ds, ddf and 
dem). So I need to cast my numbers into one of these formats. Any 
suggestions?


Thanks

Frederic





Andres,

 Thanks for the tip. I wasn't aware of Blender. The web page looks 
promising. I downloaded it and am going to have a look at it.


Frederic


===
Frederic;
Could you be a little more specific about your data's current 
format and the format that seems to best suit your needs?


Tabular source data and dxf output files for use in CAD are quite 
simple to write.  But this assumes dxf suits your display program's 
needs.


I think, for display purposes, Microsoft Word still accepts dxf files. 
I run unix mostly and I don't keep up with Window$. ;(



I suggest you Google for CAD (Computer Aided Drafting) programs. There 
are free ones out there.  Most will take the DXF format.  If the 
contours are pre-traced you can polyline them to make the contours 
look correct. If the 3D points are X-section or random you will need a 
contour generating program  and so it goes.


Let's start here - what is your area of expertise, how much math in 
your background, why are you attempting this exercise?


In order to communicate properly I need to know.  I can tailor my 
comments to suit.






Steve Turner
Licensed Land Surveyor CA 5197 (inactive)
1st order Photogrammetric Compiler (2D depctions from 3D photo sets)
in short  Map Maker, Master Grade
norse...@hughes.net


Steve,
Thank you  for your support. In a nutshell: I have a patch of 
constructible land and have the coordinates of its borders and a few 
other parameters. The patch is on a slope, so I had a surveyor do the 
isometric elevation lines. That's a lot more coordinates. The 
coordinates are plain text. Plain text is a breeze to convert into 
Python sequences. So I made a bitmap of the ground plan with the 
elevation lines as a template to play around doing architecture. A 
ground plan is 2d and as such is rather ill-suited to conceptualize the 
vertical dimension. Then someone made me aware of Google Sketch Up. It 
looks sort of like MS Paint in three dimensions: intuitive for doodling. 
Before I waste time doodling a flying or a subterranean house I want to 
make a three-dimensional template of the terrain and the constructible 
volume. The way to import numeric data, for what I see, is as one of the 
following CAD-file formats: skp, dwg, dxf, 3ds, ddf or dem. So I need to 
convert my coordinates into one of them, preferably the 
conversion-friendliest, but I don't have the specifications of any one.
I had a look at Blender. It looks impressive too. It might be an 
alternative to Sketch Up. I'll worry about that later. My immediate need 
is a file conversion utility. A cursory inspection of Blender's menu 
tabs and the various help options didn't turn up a file-conversion 
utility. So, my question is: How do I convert a bunch of 
three-dimensional coordinates defining lines into a file format Sketch 
Up can read (skp, dwg, dxf, 3ds, ddf or dem)?


Frederic


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


Default namespace and attributes with ElementTree 1.3

2009-06-18 Thread Racinet Georges

Hi there,

I've got a problem with the way ElementTree 1.3a3-20070912 handles  
attributes
with the default namespace feature (please feel free to redirect me if  
this isn't the

proper place to discuss such matters).

>>> from elementtree import ElementTree as ET
>>> e = ET.fromstring('')
>>> ET.tostring(e)
''

Notice that the 'id' attribute does not belong to the "foo" namespace.
If I got the XML 1.0 specification right, this is perfectly normal
(Quoting http://www.w3.org/TR/REC-xml-names/#defaulting) :

"Default namespace declarations do not apply directly to attribute  
names;
the interpretation of unprefixed attributes is determined by the  
element on

which they appear.
(...)
The namespace name for an unprefixed attribute name always has no  
value."


Now, trying to serialize this back with the default_namespace feature  
of ET 1.3,

I get an error, as predicted by the online documentation

>>> t = ET.ElementTree(e)
>>> t.write(sys.stdout, default_namespace='foo')
Traceback (...)
ValueError: cannot use non-qualified names with default_namespace option

Since this is a parse/serialize round-trip, I think that this  
behaviour isn't right, and that
unprefixed attributes should go through. Actually, shouldn't  
attributes even be outside

of the scope of the default namespace feature ?

Is there hope for future improvements about this  ?
I saw some FIXME comment in the source. The svn head version (rev 528)
seems to be identical in that respect, by the way.

Removing in ElementTree.py the part where the ValueError is been raised
seems to solve the issue at first sight :
>>> t.write(sys.stdout, default_namespace='foo')


but this lets also unprefixed elements go through, which is unwanted:
>>> e = ET.fromstring('')
>>> t = ET.ElementTree(e)
>>> t.write(sys.stdout, default_namespace='foo')


I wouldn't care in my application, whose output is xhtml, though.

Regards,
--
Georges Racinet, http://www.racinet.fr
Zope/CPS/Plone expertise, assistance & development
GPG: 0x4862FFF7









PGP.sig
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python tutorial

2009-06-18 Thread D'Arcy J.M. Cain
On 18 Jun 2009 07:05:20 GMT
Steven D'Aprano  wrote:
> Technically, the Windows file systems record the length of text files and 
> so an explicit EOF character is redundant, nevertheless, the behaviour of 
> stopping the read at \0x1A is expected. Whether you want to claim it is 

I really loved CP/M in its day but isn't it time we let go?

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-18 Thread Piet van Oostrum
> Charles Yeomans  (CY) wrote:

>CY> Memory management may be an "implementation detail", but it is
>CY> unfortunately one that illustrates the so-called law of leaky
>CY> abstractions.  So I think that one has to write code that follows the
>CY> memory management scheme of whatever language one uses.   For code  written
>CY> for CPython only, as mine is, RAII is an appropriate idiom and  not kludgy
>CY> at all.  Under your assumptions, its use would be wrong, of  course.

I dare to say that, even in CPython it is doomed to disappear, but we
don't know yet on what timescale.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python tutorial

2009-06-18 Thread Peter Bell

> "Steven D'Aprano" 
writes

>http://support.microsoft.com/kb/156258

That says that Windows NT 3.5 and NT 4 couldn't make
a distinction between text and binary files.  I don't think
that advances your case.

If they had changed the Windows behaviour, yes, but
Windows 7 seems to be compatible with NT 3.5 rather
than with DOS.

Peter Bell. 


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


Re: generator expression works in shell, NameError in script

2009-06-18 Thread guthrie
On Jun 17, 6:38 pm, Steven Samuel Cole 
wrote:
> Still don't really understand why my initial code didn't work, though...

Your code certainly looks reasonable, and looks to me like it "should"
work. The comment of partial namespace is interesting, but
unconvincing (to me) - but I am not a Python expert! It would
certainly seem that within that code block it is in the local
namespace, not removed from that scope to be in another.

Seems that it should either be a bug, or else is a design error in the
language!

Just as in the above noted "WTF" - non-intuitive language constructs
that surprise users are poor design.


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


Re: Regarding Python is scripting language or not

2009-06-18 Thread Jochen Schulz
Terry Reedy:
> Jochen Schulz wrote:
>> 
>> If, by "object-oriented" you mean "everything has to be put into
>> classes", then Python is not object-oriented.
> 
> That depends on what you mean by 'put into classes' (and 'everything').

:) What I meant was that in Python you can write code without defining
your own classes at all. I had Java in mind where you cannot write a
program without using the keyword 'class'. But I think we agree here.

J.
-- 
In idle moments I remember former lovers with sentimental tenderness.
[Agree]   [Disagree]
 


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


Re: please help...writing set to a file

2009-06-18 Thread Alan G Isaac
On 6/18/2009 5:24 AM yadin apparently wrote:
> I got this python program that returns me a set like this..
> Set ([‘A\n’, B\n’, ‘C\n’, ‘D\n’, ‘E\n’, ‘F\n’, ‘G\n’ ])
> And a list pp = [‘100\n’ ‘200\n’ ‘300\n’ ‘400\n’]
> I was reading this from a file….
> How can I transform this to something that looks like this
> Column1 Column 2
> 
>   100  A
>200 B
>300 C
> 400D
>E
>F
>  G
> And then write this to a file???


http://docs.python.org/library/functions.html#sorted

http://docs.python.org/library/itertools.html#itertools.izip_longest

http://docs.python.org/library/stdtypes.html#str.format

http://docs.python.org/library/functions.html#open

hth,
Alan Isaac
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-18 Thread Rhodri James
On Thu, 18 Jun 2009 08:29:53 +0100, Lawrence D'Oliveiro  
 wrote:



Now compare that with Lie Ryan's examples which, instead of using
backslashes, instead used alternative quotes plus backslashes in one
example, and in the other example, alternative quotes, alternatives to
literal quotes, and backslashes. As opposed to my original routine, which
managed three levels of quoting using just backslashes. Do you begin to
understand what I mean by "scalable"?


I do, and I still disagree.  More importantly, Lie Ryan's examples were
much more readable, which is what I was complaining about.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: Packing a ctypes struct containing bitfields.

2009-06-18 Thread Nick Craig-Wood
Karthik  wrote:
>  Hello Everybody,
> 
>  I'm trying to create a packed structure in ctypes (with one 64-bit
>  element that is bitfielded to 48 bits),
>  unsuccessfully:
> 
> ===
>  from ctypes import *
> 
>  class foo (Structure):
>  _pack_ = 1
>  _fields_ = [
>  ("bar",c_ulonglong, 48),
>  ]
> 
>  print("sizeof(foo) = %d" % sizeof(foo))
> ===
>  I'm expecting that this should print 6 - however, on my box, it prints
>  8.
> 
>  The following piece of C code, when compiled and run, prints 6, which
>  is correct.
> ===
>  struct foo {
>  unsigned long long bar: 48;
>  };
> 
>  printf("sizeof(foo) = %d", sizeof(foo));
> ===
> 
>  So... what am I doing wrong?

I compiled and ran the above with gcc on my linux box - it prints 8
unless I add __attribute__((__packed__)) to the struct.

I'm not sure that using bitfields like that is a portable at all
between compilers let alone architectures.

I'd probably do

from ctypes import *

class foo (Structure):
_pack_ = 1
_fields_ = [
("bar0",c_uint32),
("bar1",c_uint16),
]
def set_bar(self, bar):
self.bar0 = bar & 0x
self.bar1 = (bar >> 32) & 0x
def get_bar(self):
return (self.bar1 << 32) + self.bar0
bar = property(get_bar, set_bar)

print "sizeof(foo) = %d" % sizeof(foo)
f = foo()
print f.bar
f.bar = 123456789012345
print f.bar

Which prints

sizeof(foo) = 6
0
123456789012345

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


command-line one-liners a la Perl?

2009-06-18 Thread kj



I'm a recovering Perl addict, and I'm jonesin' badly for command-line
one-liners, like

  % perl -lne '@f=split "\t";print join "\t",@f[3,1] if $f[2]=~/frobozz/i' 
in.txt

How can I get my fix with Python?

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


Re: generator expression works in shell, NameError in script

2009-06-18 Thread nn
On Jun 18, 8:38 am, guthrie  wrote:
> On Jun 17, 6:38 pm, Steven Samuel Cole 
> wrote:
>
> > Still don't really understand why my initial code didn't work, though...
>
> Your code certainly looks reasonable, and looks to me like it "should"
> work. The comment of partial namespace is interesting, but
> unconvincing (to me) - but I am not a Python expert! It would
> certainly seem that within that code block it is in the local
> namespace, not removed from that scope to be in another.
>
> Seems that it should either be a bug, or else is a design error in the
> language!
>
> Just as in the above noted "WTF" - non-intuitive language constructs
> that surprise users are poor design.

This is certainly an odd one. This code works fine under 2.6 but fails
in Python 3.1.

>>> class x:
... lst=[2]
... gen=[lst.index(e) for e in lst]
...
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 3, in x
  File "", line 3, in 
NameError: global name 'lst' is not defined
>>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: command-line one-liners a la Perl?

2009-06-18 Thread MRAB

kj wrote:



I'm a recovering Perl addict, and I'm jonesin' badly for command-line
one-liners, like

  % perl -lne '@f=split "\t";print join "\t",@f[3,1] if $f[2]=~/frobozz/i' 
in.txt

How can I get my fix with Python?


python -c "print 'Hello world!'"

Although you need to remember that Python makes much more use of
whitespace, which limits the usefulness of the command line.
--
http://mail.python.org/mailman/listinfo/python-list


pyserial. How to set Handshaking to "RST on TX".

2009-06-18 Thread Piter_
Hi all I try to drive some equipment trough serial port.
So far I could do it with some windows com port terminal if handhaking
set to "RTS on  TX".
http://hw-server.com/software/termv19b.html
But I cant find out how to set it in pyserial.
Thanks in advance for any hint.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: command-line one-liners a la Perl?

2009-06-18 Thread unayok
On Jun 18, 9:36 am, kj  wrote:
> I'm a recovering Perl addict, and I'm jonesin' badly for command-line
> one-liners, like
>
>   % perl -lne '@f=split "\t";print join "\t",@f[3,1] if $f[2]=~/frobozz/i' 
> in.txt
>
> How can I get my fix with Python?
>
> kynn

I'd encourage you to learn the ways of Python which ordinarily don't
encourage cramming lots of code into a single line.

However... if you are insistent on seeing how much rope Python can
give you
to hang yourself... ;)

$ python -c 'print "\n".join( "\t".join( ( data[3], data[1] ) ) for
data in ( lambda fn : ( line.strip().split("\t") for line in file( fn,
"r" ) ) )( "in.txt" ) if data[2].lower().find( "frobozz" ) > -1 )'

(untested) should do something similar to your perl statement (display
the
fourth and second fields from tab-delimited lines containing "frobozz"
in
any case-mixture in the third field for lines read from the "in.txt"
file).

Note that the frobozz search is not a regex search in this example.
Requiring
regex would make things more complicated.

Probably could be cleaned up a bit.

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


Re: Regarding Python is scripting language or not

2009-06-18 Thread Aaron Brady
On Jun 18, 6:07 am, Jochen Schulz  wrote:
> Terry Reedy:
>
> > Jochen Schulz wrote:
>
> >> If, by "object-oriented" you mean "everything has to be put into
> >> classes", then Python is not object-oriented.
>
> > That depends on what you mean by 'put into classes' (and 'everything').
>
> :) What I meant was that in Python you can write code without defining
> your own classes at all. I had Java in mind where you cannot write a
> program without using the keyword 'class'. But I think we agree here.

Numbers have infinite precision.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Announcing www.python-excel.org

2009-06-18 Thread Chris Withers

Hi All,

Google unfortunately has a knack of presenting prospective Python users 
who need to work with Excel files with information that is now really 
rather out of date.


To try and help with this, I've setup a small website at:

http://www.python-excel.org

...to try and list the latest recommended ways of working with Excel 
files in Python.


If you work with excel files in Python, then please take a look and let 
me know what you think.


cheers,

Chris

PS: If anyone reading this has a python-related blog, it might help 
Google if you could post a short entry about this new site.


--
Simplistix - Content Management, Zope & Python Consulting
   - http://www.simplistix.co.uk


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


Re: Newbie queue question

2009-06-18 Thread Piet van Oostrum
> Jure Erznožnik  (JE) wrote:

>JE> Hi,
>JE> I'm pretty new to Python (2.6) and I've run into a problem I just
>JE> can't seem to solve.
>JE> I'm using dbfpy to access DBF tables as part of a little test project.
>JE> I've programmed two separate functions, one that reads the DBF in main
>JE> thread and the other which reads the DBF asynchronously in a separate
>JE> thread.
>JE> Here's the code:

>JE> def demo_01():
>JE> '''DBF read speed only'''

>JE> dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1)
>JE> for i1 in xrange(len(dbf1)):
>JE> rec = dbf1[i1]
>JE> dbf1.close()

>JE> def demo_03():
>JE> '''DBF read speed into a FIFO queue'''

>JE> class mt(threading.Thread):

>JE> q = Queue.Queue(64)
>JE> def run(self):
>JE> dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1)
>JE> for i1 in xrange(len(dbf1)):
>JE> self.q.put(dbf1[i1])
>JE> dbf1.close()
>JE> del dbf1
>JE> self.q.join()

>JE> t = mt()
>JE> t.start()
>JE> while t.isAlive():
>JE> try:
>JE> rec = t.q.get(False, 0.2)
>JE> t.q.task_done();
>JE> except:
>JE> pass

>JE> del t


>JE> However I'm having serious issues with the second method. It seems
>JE> that as soon as I start accessing the queue from both threads, the
>JE> reading speed effectively halves.

>JE> I have tried the following:
>JE> 1. using deque instead of queue (same speed)
>JE> 2. reading 10 records at a time and inserting them in a separate loop
>JE> (hoped the congestion would help)
>JE> 3. Increasing queue size to infinite and waiting 10 seconds in main
>JE> thread before I started reading - this one yielded full reading speed,
>JE> but the waiting took away all the threading benefits

>JE> I'm sure I'm doing something very wrong here, I just can't figure out
>JE> what.

For a start the thread switching and the queue administration just take
time, that you can avoid if you do everything sequentially.
Threading can have an advantage if there is the possiblilty of overlap.
But there is none in your example, so it's just overhead. If your
processing would do something substantially and if the reading of the
file would be I/O bound for example. You don't say how big the file is,
and it also may be in your O.S. cache so then reading it would
essentially be CPU bound.

And then there is this code:

 while t.isAlive():
 try:
 rec = t.q.get(False, 0.2)
 t.q.task_done(); 
except:
pass

t.q.get(False, 0.2) means do a non-blocking get, so that when there is
nothing in the queue it returns immediately and then takes the exception
path which also is substantial overhead. Whether this will happen or not
depends on the timing which depends on the scheduling of the O.S. For
example when the O.S. schedules the main task first it will be busy wait
looping quite a lot before the first item arrives in the queue. If the
file is small it will probably put then all the items in the queue and
there will be no more busy wait looping. But busy wait looping just
consumes CPU time.

By the way, the second parameter (0.2) which is supposed to be the
timeout period is just ignored if the first parameter is false. You
might be better off giving True as the first parameter to get.

I dislike any form of busy wait loop. It would be better to just use a
normal get(), but that conflicts with your end detection. while
t.isAlive() is not a particularly good way to detect that the processing
is finished I think because of timing issues. After the last
t.q.task_done() [which doesn't need a semicolon, by the way] it takes
some time before the self.q.join() will be processed and the thread
finishes. In the mean time while t.isAlive() is constantly being tested,
also wasting CPU time.

IMHO a better way is to put a sentinel object in the queue:

def run(self):
 dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1)
 for i1 in xrange(len(dbf1)):
 self.q.put(dbf1[i1])
 self.q.put(None)
 dbf1.close()
 del dbf1
 self.q.join()

while True:
rec = t.q.get()
t.q.task_done()
if rec is None: break

And then you probably can also get rid of the self.q.join() and
t.q.task_done()

-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Tutorial on working with Excel files in Python (without COM and cross platform!) at EuroPython 2009

2009-06-18 Thread Chris Withers

Hi All,

Too many people in the Python community *still* think the only way to 
work with Excel files in Python is using COM on Windows.


To try and correct this, I'm giving a tutorial at this year's EuroPython 
conference in Birmingham, UK on Monday, 29th June that will cover 
working with Excel files in Python using the pure-python libraries xlrd, 
xlwt and xlutils.


I'll be looking to cover:

- Reading Excel Files

  Including extracting all the data types, formatting and working with
  large files.

- Writing Excel Files

  Including formatting, many of the useful frilly extras and writing
  large excel files.

- Modifying and Filtering Excel Files

  A run through of taking existing Excel files and modifying them in
  various ways.

- Workshop for your problems

  I'm hoping anyone who attends will get a lot out of this! If you're
  planning on attending and have a particular problem you'd like to work
  on in this part of the tutorial, please drop me an email and I'll try
  and make sure I come prepared!

All you need for the tutorial is a working knowledge of Excel and
Python, with a laptop as an added benefit, and to be at EuroPython this 
year:


http://www.europython.eu/

I look forward to seeing you all there!

Chris

--
Simplistix - Content Management, Zope & Python Consulting
   - http://www.simplistix.co.uk


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


Re: fastest native python database?

2009-06-18 Thread J Kenneth King
per  writes:

> hi all,
>
> i'm looking for a native python package to run a very simple data
> base. i was originally using cpickle with dictionaries for my problem,
> but i was making dictionaries out of very large text files (around
> 1000MB in size) and pickling was simply too slow.
>
> i am not looking for fancy SQL operations, just very simple data base
> operations (doesn't have to be SQL style) and my preference is for a
> module that just needs python and doesn't require me to run a separate
> data base like Sybase or MySQL.
>
> does anyone have any recommendations? the only candidates i've seen
> are snaklesql and buzhug... any thoughts/benchmarks on these?
>
> any info on this would be greatly appreciated. thank you

berkeley db is pretty fast. locking and such nice features are
included. the module you'd be looking at is bsddb i believe.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: logging.fileConfig limitations?

2009-06-18 Thread Vinay Sajip
On Jun 17, 9:05 pm, Mani Ghasemlou  wrote:
> Hi all,
>
> C:\Documents and Settings\ßéäöÜ2\Local Settings\Application 
> Data\MyApp\MyApp.log
>
> Now it turns out that the logging module can't find "C:/Documents and
> Settings/ßéäöÜ2/Local Settings/Application Data/MyApp/MyApp.log"
> specified in the "args" section, and rightfully so because this is an
> encoded string. *There does not seem to be a way for me to specify the
> encoding of the string so that the logging module resolves the proper
> unicode path.* This is my key problem!
>
> Is there some way to accomplish what I want?
>

No need to poke about in the source. Here's my script:

#-- log_ufn.py --
import logging.config

logging.config.fileConfig("log_ufn.ini")
logging.error("Holy Cow, Batman!")

and here's my configuration file, adapted from yours:

#-- log_ufn.ini --
[formatters]
keys: normal

[handlers]
keys: rotatingfile

[loggers]
keys: root

[formatter_normal]
format: %(asctime)s %(levelname)s %(module)s: %(message)s

[logger_root]
level: DEBUG
handlers: rotatingfile

[handler_rotatingfile]
class: handlers.RotatingFileHandler
formatter: normal
args: (u"C:/Temp/\u00DF\u00E9\u00E4\u00F6\u00DC2/MyApp.log", "a",
2*1024*1024, 5, None)

Note that I specified a Unicode filename, with Unicode escapes for
ßéäöÜ2.

After I run the script (using ActivePython 2.5.2.2), I get the
following output:

# -- Contents of C:\temp\ßéäöÜ2\MyApp.log --
2009-06-18 17:07:30,493 ERROR log_ufn: Holy Cow, Batman!

Which seems to be what one would expect.
-- 
http://mail.python.org/mailman/listinfo/python-list


A question on scope...

2009-06-18 Thread Wells Oliver
In writing out python classes, it seems the 'self' is optional, meaning that
inside a class method, "self.foo = bar" has the same effect as "foo = bar".
Is this right? If so, it seems a little odd- what's the rationale?

Or am I mistaken?

-- 
Wells Oliver
we...@submute.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exotic Logics

2009-06-18 Thread Michael Torrie
William Clifford wrote:
> I've read one can do all of the 16 binary operations with clever uses
> of NAND or NOR.

That is correct.  In fact semiconductor logic is done using these two
principle gates.  See  http://en.wikipedia.org/wiki/NAND_logic .  Quite
interesting really.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A question on scope...

2009-06-18 Thread MRAB

Wells Oliver wrote:
In writing out python classes, it seems the 'self' is optional, meaning 
that inside a class method, "self.foo = bar" has the same effect as "foo 
= bar". Is this right? If so, it seems a little odd- what's the rationale?


Or am I mistaken?


Inside a function or method "foo = bar" would make "foo" local by
default. In an instance method an attribute "foo" of the instance needs
a reference to the instance itself, by convention "self", therefore
"self.foo". In a class method a reference to the class itself is by
convention "cls", therefore "cls.foo".
--
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: int argument required

2009-06-18 Thread Lie Ryan
Rhodri James wrote:
> On Thu, 18 Jun 2009 08:29:53 +0100, Lawrence D'Oliveiro
>  wrote:
> 
>> Now compare that with Lie Ryan's examples which, instead of using
>> backslashes, instead used alternative quotes plus backslashes in one
>> example, and in the other example, alternative quotes, alternatives to
>> literal quotes, and backslashes. As opposed to my original routine, which
>> managed three levels of quoting using just backslashes. Do you begin to
>> understand what I mean by "scalable"?
> 
> I do, and I still disagree.  More importantly, Lie Ryan's examples were
> much more readable, which is what I was complaining about.

I still remember when I started programming, I wrote in QBASIC without
indentations. I honestly saw no reason to indent because I still can see
the program flow as clearly as the bottom of a bucket of crystalline
water. No decisions to be made, everything is consistently justified left.

I still remember asking a friend, "Why is your code jagged like that?"
and him looking at me a bit confused at the question.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tutorial on working with Excel files in Python (without COM and cross platform!) at EuroPython 2009

2009-06-18 Thread Mike Driscoll
On Jun 18, 10:38 am, Chris Withers  wrote:
> Hi All,
>
> Too many people in the Python community *still* think the only way to
> work with Excel files in Python is using COM on Windows.
>
> To try and correct this, I'm giving a tutorial at this year's EuroPython
> conference in Birmingham, UK on Monday, 29th June that will cover
> working with Excel files in Python using the pure-python libraries xlrd,
> xlwt and xlutils.
>
> I'll be looking to cover:
>
> - Reading Excel Files
>
>    Including extracting all the data types, formatting and working with
>    large files.
>
> - Writing Excel Files
>
>    Including formatting, many of the useful frilly extras and writing
>    large excel files.
>
> - Modifying and Filtering Excel Files
>
>    A run through of taking existing Excel files and modifying them in
>    various ways.
>
> - Workshop for your problems
>
>    I'm hoping anyone who attends will get a lot out of this! If you're
>    planning on attending and have a particular problem you'd like to work
>    on in this part of the tutorial, please drop me an email and I'll try
>    and make sure I come prepared!
>
> All you need for the tutorial is a working knowledge of Excel and
> Python, with a laptop as an added benefit, and to be at EuroPython this
> year:
>
> http://www.europython.eu/
>
> I look forward to seeing you all there!
>
> Chris
>
> --
> Simplistix - Content Management, Zope & Python Consulting
>             -http://www.simplistix.co.uk


As I recall, these utilities don't allow the programmer to access
Excel's formulas. Is that still an issue?

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


Re: Measuring Fractal Dimension ?

2009-06-18 Thread David C . Ullrich
On Wed, 17 Jun 2009 14:50:28 +1200, Lawrence D'Oliveiro
 wrote:

>In message <7x63ew3uo9@ruckus.brouhaha.com>,  wrote:
>
>> Lawrence D'Oliveiro  writes:
>>
>>> I don't think any countable set, even a countably-infinite set, can have
>>> a fractal dimension. It's got to be uncountably infinite, and therefore
>>> uncomputable.
>> 
>> I think the idea is you assume uniform continuity of the set (as
>> expressed by a parametrized curve).  That should let you approximate
>> the fractal dimension.
>
>Fractals are, by definition, not uniform in that sense.

I won't ask where I can find this definition. That Koch thing is a
closed curve in R^2. That means _by definition_ that it is a
continuous function from [0,1] to R^2 (with the same value
at the endpoints). And any continuous fu

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


Re: Measuring Fractal Dimension ?

2009-06-18 Thread David C . Ullrich
On Wed, 17 Jun 2009 14:50:28 +1200, Lawrence D'Oliveiro
 wrote:

>In message <7x63ew3uo9@ruckus.brouhaha.com>,  wrote:
>
>> Lawrence D'Oliveiro  writes:
>>
>>> I don't think any countable set, even a countably-infinite set, can have
>>> a fractal dimension. It's got to be uncountably infinite, and therefore
>>> uncomputable.
>> 
>> I think the idea is you assume uniform continuity of the set (as
>> expressed by a parametrized curve).  That should let you approximate
>> the fractal dimension.
>
>Fractals are, by definition, not uniform in that sense.

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


Re: Measuring Fractal Dimension ?

2009-06-18 Thread David C . Ullrich
On Wed, 17 Jun 2009 14:50:28 +1200, Lawrence D'Oliveiro
 wrote:

>In message <7x63ew3uo9@ruckus.brouhaha.com>,  wrote:
>
>> Lawrence D'Oliveiro  writes:
>>
>>> I don't think any countable set, even a countably-infinite set, can have
>>> a fractal dimension. It's got to be uncountably infinite, and therefore
>>> uncomputable.
>> 
>> I think the idea is you assume uniform continuity of the set (as
>> expressed by a parametrized curve).  That should let you approximate
>> the fractal dimension.
>
>Fractals are, by definition, not uniform in that sense.

Sorry if I've already posted half of this - having troubles hitting
the toushpad on this little machine by accident.

The fractal in question is a curve in R^2. By definition that
means it is a continuous function from [a,b] to R^2 (with
the same value at the two endpoints). Hence it's
uniformly continuous.

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


Re: Measuring Fractal Dimension ?

2009-06-18 Thread David C . Ullrich
On Wed, 17 Jun 2009 07:35:35 +0200, Jaime Fernandez del Rio
 wrote:

>On Wed, Jun 17, 2009 at 4:50 AM, Lawrence
>D'Oliveiro wrote:
>> In message <7x63ew3uo9@ruckus.brouhaha.com>,  wrote:
>>
>>> Lawrence D'Oliveiro  writes:
>>>
 I don't think any countable set, even a countably-infinite set, can have
 a fractal dimension. It's got to be uncountably infinite, and therefore
 uncomputable.
>>>
>>> I think the idea is you assume uniform continuity of the set (as
>>> expressed by a parametrized curve).  That should let you approximate
>>> the fractal dimension.
>>
>> Fractals are, by definition, not uniform in that sense.
>
>I had my doubts on this statement being true, so I've gone to my copy
>of Gerald Edgar's "Measure, Topology and Fractal Geometry" and
>Proposition 2.4.10 on page 69 states: "The sequence (gk), in the
>dragon construction of the Koch curve converges uniformly." And
>uniform continuity is a very well defined concept, so there really
>shouldn't be an interpretation issue here either. Would not stick my
>head out for it, but I am pretty sure that a continuous sequence of
>curves that converges to a continuous curve, will do so uniformly.

Nope. Not that I see the relvance here - the g_k _do_
converge uniformly.

>Jaime

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


Re: Measuring Fractal Dimension ?

2009-06-18 Thread David C . Ullrich
On Wed, 17 Jun 2009 07:37:32 -0400, Charles Yeomans
 wrote:

>
>On Jun 17, 2009, at 2:04 AM, Paul Rubin wrote:
>
>> Jaime Fernandez del Rio  writes:
>>> I am pretty sure that a continuous sequence of
>>> curves that converges to a continuous curve, will do so uniformly.
>>
>> I think a typical example of a curve that's continuous but not
>> uniformly continuous is
>>
>>   f(t) = sin(1/t), defined when t > 0
>>
>> It is continuous at every t>0 but wiggles violently as you get closer
>> to t=0.  You wouldn't be able to approximate it by sampling a finite
>> number of points.  A sequence like
>>
>>   g_n(t) = sin((1+1/n)/ t)for n=1,2,...
>>
>> obviously converges to f, but not uniformly.  On a closed interval,
>> any continuous function is uniformly continuous.
>
>Isn't (-?, ?) closed?

What is your version of the definition of "closed"?

>Charles Yeomans

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


Re: Measuring Fractal Dimension ?

2009-06-18 Thread David C . Ullrich
On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson
 wrote:

>On Jun 17, 3:46 pm, Paul Rubin  wrote:
>> Mark Dickinson  writes:
>> > It looks as though you're treating (a portion of?) the Koch curve as
>> > the graph of a function f from R -> R and claiming that f is
>> > uniformly continuous.  But the Koch curve isn't such a graph (it
>> > fails the 'vertical line test',
>>
>> I think you treat it as a function f: R -> R**2 with the usual
>> distance metric on R**2.
>
>Right.  Or rather, you treat it as the image of such a function,
>if you're being careful to distinguish the curve (a subset
>of R^2) from its parametrization (a continuous function
>R -> R**2).  It's the parametrization that's uniformly
>continuous, not the curve,

Again, it doesn't really matter, but since you use the phrase
"if you're being careful": In fact what you say is exactly
backwards - if you're being careful that subset of the plane
is _not_ a curve (it's sometimes called the "trace" of the curve".

>and since any curve can be
>parametrized in many different ways any proof of uniform
>continuity should specify exactly which parametrization is
>in use.

Any _closed_ curve must have [a,b] as its parameter 
interval, and hence is uniformly continuous since any
continuous function on [a,b] is uniformly continuous.

>Mark

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


Re: Measuring Fractal Dimension ?

2009-06-18 Thread Charles Yeomans


On Jun 18, 2009, at 2:19 PM, David C. Ullrich wrote:


On Wed, 17 Jun 2009 07:37:32 -0400, Charles Yeomans
 wrote:



On Jun 17, 2009, at 2:04 AM, Paul Rubin wrote:


Jaime Fernandez del Rio  writes:

I am pretty sure that a continuous sequence of
curves that converges to a continuous curve, will do so uniformly.


I think a typical example of a curve that's continuous but not
uniformly continuous is

 f(t) = sin(1/t), defined when t > 0

It is continuous at every t>0 but wiggles violently as you get  
closer

to t=0.  You wouldn't be able to approximate it by sampling a finite
number of points.  A sequence like

 g_n(t) = sin((1+1/n)/ t)for n=1,2,...

obviously converges to f, but not uniformly.  On a closed interval,
any continuous function is uniformly continuous.


Isn't (-?, ?) closed?


What is your version of the definition of "closed"?




My version of a closed interval is one that contains its limit points.

Charles Yeomans

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


Re: walking a directory with very many files

2009-06-18 Thread Lie Ryan
Mike Kazantsev wrote:
> On Wed, 17 Jun 2009 03:42:02 GMT
> Lie Ryan  wrote:
> 
>> Mike Kazantsev wrote:
>>> In fact, on modern filesystems it doesn't matter whether you
>>> accessing /path/f9e95ea4926a4 with million files in /path
>>> or /path/f/9/e/95ea with only hundred of them in each path. Former
>>> case (all-in-one-path) would even outperform the latter with ext3
>>> or reiserfs by a small margin.
>>> Sadly, that's not the case with filesystems like FreeBSD ufs2 (at
>>> least in sixth branch), so it's better to play safe and create
>>> subdirs if the app might be run on different machines than keeping
>>> everything in one path.
>> It might not matter for the filesystem, but the file explorer (and ls)
>> would still suffer. Subfolder structure would be much better, and much
>> easier to navigate manually when you need to.
> 
> It's an insane idea to navigate any structure with hash-based names
> and hundreds of thousands files *manually*: "What do we have here?
> Hashies?" ;)
> 

Like... when you're trying to debug a code that generates an error with
a specific file...

Yeah, it might be possible to just mv the file from outside, but not
being able to enter a directory just because you've got too many files
in it is kind of silly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python tutorial

2009-06-18 Thread Robert Kern

On 2009-06-18 00:57, steve wrote:

"Robert Kern"  wrote in message
news:mailman.1728.1245289092.8015.python-l...@python.org...

On 2009-06-17 19:36, steve wrote:

"Carl Banks"   wrote in message
news:2f6271b1-5ffa-4cec-81f8->>0276ad647...@p5g2000pre.googlegroups.com...
On Jun 15, 7:56 pm, "steve"   wrote:

I was just looking at the python tutorial, and I noticed these lines:

http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-...

"Windows makes a distinction between text and binary files;
"the end-of-line characters in text files are automatically altered
"slightly when data is read or written.

I don't see any obvious way to at docs.python.org to get that
corrected:
Is
there some standard procedure?

What's wrong with it?


Carl Banks

1) Windows does not make a distinction between text and binary files.

2) end-of-line characters in text files are not automatically altered by
Windows.

The Windows implementation of the C standard makes the distinction. E.g.
using stdio to write out "foo\nbar\n" in a file opened in text mode will
result in "foo\r\nbar\r\n" in the file. Reading such a file in text mode
will result in "foo\nbar\n" in memory. Reading such a file in binary mode
will result in "foo\r\nbar\r\n". In your bug report, you point out several
proprietary APIs that do not make such a distinction, but that does not
remove the implementations of the standard APIs that do make such a
distinction.

   http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx

Perhaps it's a bit dodgy to blame "Windows" per se rather than its C
runtime, but I think it's a reasonable statement on the whole.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma
  that is made terrible by our own mad attempt to interpret it as though it
had
  an underlying truth."
   -- Umberto Eco




Which is where I came in: I was looking for simple file IO in the tutorial.
The tutorial tells me something false about Windows, rather than something
true about Python.


I don't think it's false. I think it's a fair statement given the Windows 
implementation of the C standard library. Such things are frequently considered 
to be part of the OS. This isn't just some random API; it's the implementation 
of the C standard.



I'm looking at a statement that is clearly false (for anyone who knows
anything about Windows file systems and Windows file io), which leaves the
Python behaviour completely undefined (for anyone who knows nothing about
Python).

I understand that many of you don't really have any understanding of
Windows, much less any background with Windows, and I'm here to help.  That
part was simple.

The next part is where I can't help: What is the behaviour of Python?


The full technical description is where it belongs, in the reference manual 
rather than a tutorial:


  http://docs.python.org/library/functions.html#open


I'm sure you don't think that tutorial is only for readers who can guess
that they have to extrapolate from the behaviour of the Visual C library in
order to work out what Python does.


All a tutorial level documentation needs to know is what is described: when a 
file is opened in text mode, the actual bytes written to a file for a newline 
may be different depending on the platform. The reason that it does not explain 
the precise behavior on each and every platform is because it *is* undefined. 
Python 2.x does whatever the C standard library implementation for stdio does. 
It mentions Windows as a particularly common example of a difference between 
text mode and binary mode.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


ERROR: how to use a text file in a module?

2009-06-18 Thread Moni GV
Hi,

Help with a "No such file ..." error. I have the next folder structure:
---Network contains:
    --packets.py
    --Temp contains:
   -test.py

Well, within packets.py I do this:
from Temp.test import *

Within test.py I do this:
f = open ("topo.txt", "r")

The error is:
No such file "topo.txt"

However, when I execute test.py, without using neither packets.py nor the 
folder structure, there is no error, because topo.txt exists.

I'm sure I'm doing something wrong with the "import" staff or "path" maybe, but 
have no idea...please help!!!

Thanks in advance!

**
Mónica Guerrero
M.Sc. Student
Rey Juan Carlos University
Madrid




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


Re: python tutorial

2009-06-18 Thread Lie Ryan
Ben Finney wrote:
> You started out asking how to *interpret* it, which is fine for this
> forum; but discussing it here isn't going to lead automatically to any
> *midification* to a document developed within the core of Python.
> 

I definitely want to see how python doc be midified, last time I checked
MIDI cannot play spoken words, don't know whether there is
text-to-speech sound font though ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python tutorial

2009-06-18 Thread Ethan Furman

steve wrote:
"Robert Kern"  wrote in message 
news:mailman.1728.1245289092.8015.python-l...@python.org...



On 2009-06-17 19:36, steve wrote:


"Carl Banks"  wrote in message
news:2f6271b1-5ffa-4cec-81f8->>0276ad647...@p5g2000pre.googlegroups.com...
On Jun 15, 7:56 pm, "steve"  wrote:


I was just looking at the python tutorial, and I noticed these lines:

http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-...

"Windows makes a distinction between text and binary files;
"the end-of-line characters in text files are automatically altered
"slightly when data is read or written.

I don't see any obvious way to at docs.python.org to get that 
corrected:

Is
there some standard procedure?


What's wrong with it?


Carl Banks


1) Windows does not make a distinction between text and binary files.

2) end-of-line characters in text files are not automatically altered by
Windows.


The Windows implementation of the C standard makes the distinction. E.g. 
using stdio to write out "foo\nbar\n" in a file opened in text mode will 
result in "foo\r\nbar\r\n" in the file. Reading such a file in text mode 
will result in "foo\nbar\n" in memory. Reading such a file in binary mode 
will result in "foo\r\nbar\r\n". In your bug report, you point out several 
proprietary APIs that do not make such a distinction, but that does not 
remove the implementations of the standard APIs that do make such a 
distinction.


 http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx

Perhaps it's a bit dodgy to blame "Windows" per se rather than its C 
runtime, but I think it's a reasonable statement on the whole.


--
Robert Kern




Which is where I came in: I was looking for simple file IO in the tutorial. 
The tutorial tells me something false about Windows, rather than something 
true about Python.


I'm looking at a statement that is clearly false (for anyone who knows 
anything about Windows file systems and Windows file io), which leaves the 
Python behaviour completely undefined (for anyone who knows nothing about 
Python).


I understand that many of you don't really have any understanding of 
Windows, much less any background with Windows, and I'm here to help.  That 
part was simple.


I will freely admit to having no idea of just how many pythonastis have 
good Windows experience/background, but how about you give us the 
benefit of the doubt and tell us exactly which languages/routines you 
play with *in windows* that fail to make a distinction between text and 
binary?



The next part is where I can't help: What is the behaviour of Python?

I'm sure you don't think that tutorial is only for readers who can guess 
that they have to extrapolate from the behaviour of the Visual C library in 
order to work out what Python does.



Steve 

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


Re: Regarding Python is scripting language or not

2009-06-18 Thread Terry Reedy

Jochen Schulz wrote:

Terry Reedy:

Jochen Schulz wrote:

If, by "object-oriented" you mean "everything has to be put into
classes", then Python is not object-oriented.

That depends on what you mean by 'put into classes' (and 'everything').


:) What I meant was that in Python you can write code without defining
your own classes at all. I had Java in mind where you cannot write a
program without using the keyword 'class'. But I think we agree here.


Yes, I amplified your basic point ;-)

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


Help: Group based synchronize decorator

2009-06-18 Thread Vishal Shetye
I want to synchronize calls using rw locks per 'group' and my implementation is 
similar to
http://code.activestate.com/recipes/465057/
except that I have my own Lock implementation.

All my synchronized functions take 'whatGroup' as param. My lock considers 
'group' while deciding on granting locks through acquire.

What I could come up with is:
- decorator knows(assumes) first param to decorated functions is always 
'whatGroup'
- decorator passes this 'whatGroup' argument to my lock which is used in 
acquire logic.

Is it ok to make such assumptions in decorator?
Any suggestions/alternatives?

thanks
vishal
DISCLAIMER
==
This e-mail may contain privileged and confidential information which is the 
property of Persistent Systems Ltd. It is intended only for the use of the 
individual or entity to which it is addressed. If you are not the intended 
recipient, you are not authorized to read, retain, copy, print, distribute or 
use this message. If you have received this communication in error, please 
notify the sender and delete all copies of this message. Persistent Systems 
Ltd. does not accept any liability for virus infected mails.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python tutorial

2009-06-18 Thread Piet van Oostrum
> "Peter Bell"  (PB) wrote:

>>> "Steven D'Aprano" 
>PB> writes

>>> http://support.microsoft.com/kb/156258

>PB> That says that Windows NT 3.5 and NT 4 couldn't make
>PB> a distinction between text and binary files.  I don't think
>PB> that advances your case.

And that was a bug apparently (euphemistically called a `problem').

>PB> If they had changed the Windows behaviour, yes, but
>PB> Windows 7 seems to be compatible with NT 3.5 rather
>PB> than with DOS.

If that is true then they may still be `researching this problem'. :=(
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python tutorial

2009-06-18 Thread Terry Reedy




1) Windows does not make a distinction between text and binary files.


'Windows', in its broad sense of Windoes system, includes the standards 
and protocols mandated by its maker, Microsoft Corporation, and 
implemented in its C compiler, which it uses to compile the software 
that other interact with. I am pretty sure that WixXP Notepad *still* 
requires \r\n in text files, even though Wordpad does not. Don't know 
about Haste (la Vista) and the upcoming Win7.


It is a common metaphor in English to ascribe agency to products and 
blame them for the sins (or virtues) of their maker.


'Unix' and 'Linux' are also used in the double meaning of OS core and OS 
 system that includes core, languages tools, and standard utilities.


2) end-of-line characters in text files are not automatically 
altered by

Windows.


The Windows implementation of the C standard makes the distinction. 
E.g. using stdio to write out "foo\nbar\n" in a file opened in text 
mode will result in "foo\r\nbar\r\n" in the file. Reading such a file 
in text mode will result in "foo\nbar\n" in memory. Reading such a 
file in binary mode will result in "foo\r\nbar\r\n". In your bug 
report, you point out several proprietary APIs that do not make such 
a distinction, but that does not remove the implementations of the 
standard APIs that do make such a distinction.


 http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx

Perhaps it's a bit dodgy to blame "Windows" per se rather than its C 
runtime, but I think it's a reasonable statement on the whole.


I agree. There are much worse sins in the docs to be fixed.

Hmmm.  "Bill Gates, his successors, and minions, still require, after 28 
years, that we jump through artificial hoops, confuse ourselves, and 
waste effort, by differentiating text and binary files and fiddling with 
line endings."


More accurate, perhaps, but probably less wise than the current text.

Terry Jan Reedy

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


Re: Once again, comparison wxpython with PyQt

2009-06-18 Thread Sebastian Wiesner


> On Jun 18, 3:49 pm, "Diez B. Roggisch"  wrote:
>> Hans Müller wrote:
>> > Here we have to select between wxPython and PyQt for a medium size
>> > project. In this project several hundred dialogs are to be created.
>> > This work will be done by a program generator which has to re-written.
>>
>> > The question now is which framework should we use.
>> > As far as I could found is PyQt with the Qt Framework the superior
>> > choice. Most articles I found (not all) results to PyQt.
>> > But Qt is expensive ~ 3400€ per Developer and OS.
>>
>> No, it's not. It is LGPL by now.
>>
>> You will have to pay licensing for *PyQT*. I'm not sure, but I *think*
>> it's about 500€. However, it is much less than Qt used to be.
>>
>> Diez
> 
> Not quite. You only have to pay for the commercial license -- you can
> use PyQT as GPL as well.
FWIW, PyQt4 license conditions do not enforce GPL 2 for derived work, but 
also permit a bunch of other free software licenses (e.g. MIT/X11, BSD, 
Apache, etc.)

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)

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


Re: Once again, comparison wxpython with PyQt

2009-06-18 Thread Mike Driscoll
On Jun 18, 8:35 am, Hans Müller  wrote:
> Here we have to select between wxPython and PyQt for a medium size project.
> In this project several hundred dialogs are to be created. This work will be 
> done by a
> program generator which has to re-written.
>
> The question now is which framework should we use.
> As far as I could found is PyQt with the Qt Framework the superior choice.
> Most articles I found (not all) results to PyQt.
> But Qt is expensive ~ 3400€ per Developer and OS.
> Since these articles are more or less old, it would be nice to hear your 
> current opinions.
>
> Condensed, I found this pros / cons:
>
> Pros for Qt:
>         - best framwork, well designed


"Best" in who's opinion?

>         - nice GUI builders
>         - faster execution

How was the execution speed measured?


> Cons:
>         - epensive

The others have answered this...

>
> Pros for wxPython:
>         - cheap
>         - big community
> Cons:
>         - more layers on top of OS
>         - more bugs (still valid ?)
>         - slower
>

Again, how was the slowness measured?


> Can someone tell me about his experiences with one or both frameworks ?
>
> Thanks a lot,
>
> Greetings
> Hans


I've been using wxPython for almost three years. I can attest to there
being a good solid community behind wx that is very friendly. The
wxPython framework is built on top of C++ wxWidgets code, but as far
as I know, pyQT is built on top of the QT framework. So I'm not sure
where this idea of "more layers" for wx comes from.

I haven't messed with QT to know if it is faster or not. Hopefully
someone else can weigh in on that. I also don't know which has more
bugs. For what I've done though, I've never had a bug to deal with.
I've created a fairly involved timesheet for my company that's a
little unwieldy at the moment. I also have quite a few smaller
applications in wxPython. I like it quite a bit. All the widgets I've
ever needed are already implemented and when they aren't there, it
always seems that one of the other developers releases one.

I would recommend trying to create something small in each toolkit
(like a minimal calculator) and see which one makes the most sense to
you.

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


Re: Perl's @foo[3,7,1,-1] ?

2009-06-18 Thread Hyuga
On Jun 13, 6:22 pm, Brian Quinlan  wrote:
> MRAB wrote:
> > Brian Quinlan wrote:
> >> kj wrote:
> >>> In  Nick Craig-Wood
> >>>  writes:
>
>  However I can't think of the last time I wanted to do this - array
>  elements having individual purposes are usually a sign that you should
>  be using a different data structure.
>
> >>> In the case I was working with, was a stand-in for the value returned
> >>> by some_match.groups().  The match comes from a standard regexp
> >>> defined elsewhere and that captures more groups than I need.  (This
> >>> regexp is applied to every line of a log file.)
>
> >>> kj
>
> >> The common idiom for this sort of thing is:
>
> >> _, _, _, val1, _, _, _, val2, ..., val3 = some_match.groups()
>
> > Alternatively:
>
> >     val1, val2, val3 = some_match.group(4, 8, something)
>
> Actually, now that I think about it, naming the groups seems like it
> would make this code a lot less brittle.

I was about to suggest that too, but it sounds like the OP has little
or no control, in this case, over the RE itself.  Another thing I
would suggest is using the (?:) syntax--it allows creating a syntactic
group that isn't returned in the list of match groups.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Measuring Fractal Dimension ?

2009-06-18 Thread Arnaud Delobelle
David C. Ullrich  writes:

> On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson
>  wrote:
>
>>On Jun 17, 3:46 pm, Paul Rubin  wrote:
>>> Mark Dickinson  writes:
>>> > It looks as though you're treating (a portion of?) the Koch curve as
>>> > the graph of a function f from R -> R and claiming that f is
>>> > uniformly continuous.  But the Koch curve isn't such a graph (it
>>> > fails the 'vertical line test',
>>>
>>> I think you treat it as a function f: R -> R**2 with the usual
>>> distance metric on R**2.
>>
>>Right.  Or rather, you treat it as the image of such a function,
>>if you're being careful to distinguish the curve (a subset
>>of R^2) from its parametrization (a continuous function
>>R -> R**2).  It's the parametrization that's uniformly
>>continuous, not the curve,
>
> Again, it doesn't really matter, but since you use the phrase
> "if you're being careful": In fact what you say is exactly
> backwards - if you're being careful that subset of the plane
> is _not_ a curve (it's sometimes called the "trace" of the curve".

I think it is quite common to refer to call 'curve' the image of its
parametrization.  Anyway there is a representation theorem somewhere
that I believe says for subsets of R^2 something like:

A subset of R^2 is the image of a continuous function [0,1] -> R^2
iff it is compact, connected and locally connected.

(I might be a bit -or a lot- wrong here, I'm not a practising
mathematician) Which means that there is no need to find a
parametrization of a plane curve to know that it is a curve.

To add to this, the usual definition of the Koch curve is not as a
function [0,1] -> R^2, and I wonder how hard it is to find such a
function for it.  It doesn't seem that easy at all to me - but I've
never looked into fractals.

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


Re: Newbie queue question

2009-06-18 Thread Jure Erznožnik
Thanks for the suggestions.
I've been looking at the source code of threading support objects and
I saw that non-blocking requests in queues use events, while blocking
requests just use InterlockedExchange.
So plain old put/get is much faster and I've managed to confirm this
today with further testing.

Sorry about the semicolon, just can't seem to shake it with my pascal
& C++ background :)

Currently, I've managed to get the code to this stage:

class mt(threading.Thread):

q = Queue.Queue()
def run(self):
dbf1 = Dbf('D:\\python\\testdbf\\promet.dbf', readOnly=1)
for i1 in xrange(len(dbf1)):
self.q.put(dbf1[i1])
dbf1.close()
del dbf1
self.q.put(None)

t = mt()
t.start()
time.sleep(22)
rec = 1
while rec <> None:
rec = t.q.get()

del t

Note the time.sleep(22). It takes about 22 seconds to read the DBF
with the 200K records (71MB). It's entirely in cache, yes.

So, If I put this sleep in there, the whole procedure finishes in 22
seconds with 100% CPU (core) usage. Almost as fast as the single
threaded procedure. There is very little overhead.
When I remove the sleep, the procedure finishes in 30 seconds with
~80% CPU (core) usage.
So the threading overhead only happens when I actually cause thread
interaction.

This never happened to me before. Usually (C, Pascal) there was some
threading overhead, but I could always measure it in tenths of a
percent. In this case it's 50% and I'm pretty sure InterlockedExchange
is the fastest thing there can be.

My example currently really is a dummy one. It doesn't do much, only
the reading thread is implemented, but that will change with time.
Reading the data source is one task, I will proceed with calculations
and with a rendering engine, both of which will be pretty CPU
intensive as well.

I'd like to at least make the reading part behave like I want it to
before I proceed. It's clear to me I don't understand Python's
threading concepts yet.

I'd still appreciate further advice on what to do to make this sample
work with less overhead.
-- 
http://mail.python.org/mailman/listinfo/python-list


Generator functions subclass generator?

2009-06-18 Thread Terry Reedy
An iterator class is a class with an __iter__ method that returns self 
and a __next__ method that on each call returns one not-yet-returned 
item of the actual or virtual collection it represents and raises 
StopIteration when there are no more items to return.  'Generator' (3.1 
name) is one of several built-in iterator classes.


A generator function is a function with keyword 'yield' in its body. Its 
presence results in four special behaviors.
1. When the generator function is called, it returns a generator 
instance inst instead of executing its body code.

2. When inst.__next__ is called, the body *is* executed.
3. When any yield is reached, an object is returned (yielded), but 
execution of the body code is only suspended, not terminated.

4. The next call resume execution at the point of suspension.

I believe any non-recursive generator functions can be written as an 
actual iterator class, though perhaps with more difficulty. (I suspect 
the same is true of recursive generators but I have never tried one.) 
The greater ease of writing gfs is one reason we have them.


I find the first two bits of magic easier with the following simile:
a generator function is like a virtual subclass of generator.

In other words,

def gf(params):
  body

acts somewhat like the following hypothetical code

class gf(generator):
  # inherited __new__ method stores the args
  # __iter__ is also inherited
  def __next__():
params =  # added
body

'yield' in the body of __next__ would still have special effects 3 and 4.

I am planning to use this in my book.  Does anyone else, particularly 
Python beginners, find it helpful?


Terry Jan Reedy


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


xlutils 1.3.2 released!

2009-06-18 Thread Chris Withers

Hi All,

I'm pleased to announce a new release of xlutils. This is a small
collection of utilities that make use of both xlrd and xlwt to process
Microsoft Excel files.

The list of utilities included in this release are:

xlutils.copy
  Tools for copying xlrd.Book objects to xlwt.Workbook objects.

xlutils.display
  Utility functions for displaying information about xlrd-related
  objects in a user-friendly and safe fashion.

xlutils.filter
  A mini framework for splitting and filtering Excel files into new
  Excel files.

xlutils.margins
  Tools for finding how much of an Excel file contains useful data.

xlutils.save
  Tools for serializing xlrd.Book objects back to Excel files.

xlutils.styles
  Tools for working with formatting information expressed in styles.

A full list of changes since the last release can be found here:

http://www.simplistix.co.uk/software/python/xlutils/changes

To find out more, please read here:

http://www.simplistix.co.uk/software/python/xlutils

In case you're not aware, xlrd and xlwt are two excellent pure-python
libraries for reading and writing Excel files. They run on any platform
and, likely, any implementation of Python without the need for horrific
things like binding to Excel via COM and so needing a Windows machine.

If you use any of xlrd, xlwt or xlutils, the following google group will
be of use:

http://groups.google.com.au/group/python-excel

Hope some of this is of interest, I'd love to hear from anyone who ends
up using it!

cheers,

Chris

--
Simplistix - Content Management, Zope & Python Consulting
   - http://www.simplistix.co.uk


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


Re: ERROR: how to use a text file in a module?

2009-06-18 Thread Rhodri James

On Thu, 18 Jun 2009 19:57:46 +0100, Moni GV  wrote:


Help with a "No such file ..." error. I have the next folder structure:
---Network contains:
    --packets.py
    --Temp contains:
   -test.py

Well, within packets.py I do this:
from Temp.test import *


Wildcarded imports like this aren't often a good idea.  It has
nothing to do with your problem, I just thought I'd mention it.


Within test.py I do this:
f = open ("topo.txt", "r")

The error is:
No such file "topo.txt"

However, when I execute test.py, without using neither packets.py nor  
the folder structure, there is no error, because topo.txt exists.


Where does topo.txt exist?  In the Temp directory?

I'll take a wild stab in the dark, and suggest that the way you ran
your program the first time (to get the error) was approximately
like this (depending on your operating system):

cd Network
python packets.py

Am I right?  And for the second time (when it worked) was:

cd Network/Temp
python test.py

roughly what you did?  Assuming that I'm right, notice that
you are in different directories each time.  Python will look
for a file called "topo.txt" in the *current* directory (i.e.
where you "cd"ed to) each time, *not* in the same directory
as test.py.

(If you double-clicked on the files, I think that's equivalent
to the situations I outlined above.  I certainly wouldn't want
to trust where the current directory was in that case!)

To fix this, you either need to be consistent about how you
run your program and change the filename appropriately (i.e.
writing 'open("Temp/topo.txt", "r")' instead), or you need to
fix where 'topo.txt' is supposed to be relative to your home
directory or the filesystem root and change the filename to
match it (as in 'open("/usr/local/lalala/topo.txt", "r")' or
'open("~/Network/Test/topo.txt", "r")', or the equivalent on
Windows).

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: python tutorial

2009-06-18 Thread Aahz
In article ,
D'Arcy J.M. Cain  wrote:
>
>I really loved CP/M in its day but isn't it time we let go?

+1 QOTW
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


TestFixtures 1.6.0 released!

2009-06-18 Thread Chris Withers

Hi All,

I'm pleased to announce the first advertised release of TestFixtures. 
This is a collection of helpers and mock objects that are useful when 
writing unit tests or doc tests.


The modules currently included are:

*Comparison*

This class lets you instantiate placeholders that can be used to 
compared expected results with actual results where objects in the 
actual results do not support useful comparison. The comparision can be 
based just on the type of the object or on a partial set of the object's 
attributes, both of which are particularly handy when comparing 
sequences returned from tested code.


*compare*

A replacement for assertEquals and the failUnless(x() is True) pattern. 
Gives more useful differences when the arguments aren't the same, 
particularly for sequences and long strings.


*diff*

This function will compare two strings and give a unified diff of their 
comparison. Handy as a third parameter to unittest.TestCase.assertEquals.


*generator*

This function will return a generator that yields the arguments it was 
called with when the generator is iterated over.


*LogCapture*

This helper allows you to capture log messages for specified loggers in 
doctests.


*log_capture*

This decorator allows you to capture log messages for specified loggers 
for the duration of unittest methods.


*replace*

This decorator enables you to replace objects such as classes and 
functions for the duration of a unittest method. The replacements are 
removed regardless of what happens during the test.


*Replacer*

This helper enables you to replace objects such as classes and functions 
from within doctests and then restore the originals once testing is 
completed.


*should_raise*

This is a better version of assertRaises that lets you check the 
exception raised is not only of the correct type but also has the 
correct parameters.


*TempDirectory*

This helper will create a temporary directory for you using mkdtemp and 
provides a handy class method for cleaning all of these up.


*tempdir*

This decorator will create a temporary directory for the duration of the 
unit test and clear it up no matter the outcome of the test.


*test_date*

This is a handy class factory that returns datetime.date replacements 
that have a today method that gives repeatable, specifiable, testable dates.


*test_datetime*

This is a handy class factory that returns datetime.datetime 
replacements that have a now method that gives repeatable, specifiable, 
testable datetimes.


*test_time*

This is a handy replacement for time.time that gives repeatable, 
specifiable, testable times.


*wrap*

This is a generic decorator for wrapping method and function calls with 
a try-finally and having code executed before the try and as part of the 
finally.


To find out more, please read here:

http://pypi.python.org/pypi/testfixtures

cheers,

Chris

--
Simplistix - Content Management, Zope & Python Consulting
   - http://www.simplistix.co.uk



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


Allocating memory to pass back via ctypes callback function

2009-06-18 Thread Scott
Hi,

I'm using python ctypes to interact with the C API of a commercial-off-
the-shelf application.  I need to implement callback functions which
will be called by the application.  The callbacks take as a parameter
a char** parameter for which the callback function will allocate
memory and set the value of the underlying char*.  The hitch is that I
need to allocate the memory with the vendor's own memory allocation
function because the caller will free the memory with the
corresponding vendor free function.  The problem is that I can't quite
work out how to set the address of the incoming POINTER(c_char_p)
parameter to the location provided by the memory allocation function.

def my_callback(pointer_c_char_p):

py_string = get_string_to_pass_back()

address = VENDOR_malloc( len(py_string)*sizeof(c_char) )

#  how to set pointer_c_char_p.contents to memory location
address?

#  would this be the correct next thing to do?
pointer_c_char_p.contents = c_char_p(py_string)
# 

return 0

Thanks,

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


Re: AT&T Usenet Netnews Service Shutting Down

2009-06-18 Thread Jive Dadson

newsmas...@bellsouth.net wrote:

Please note that on or around July 15, 2009, AT&T will no longer be
offering access to the Usenet Netnews service.  If you wish to continue
reading Usenet newsgroups, access is available through third-party vendors.

http://support.att.net/usenet


Distribution: AT&T SouthEast Newsgroups Servers



Ah ha.  I think I may have figured out how to work around it.  I need to 
use my EasyNews server to post the message, (with "SSL"), rather than 
the  ATT server.  I think.  Maybe.  Does anyone know if it's possible to 
have Thunderbird use different outgoing servers for different accounts?


I know this is not a Python question.  Please forgive me.  The main 
reason I'm sending these messages is just to see if they go through.

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


Re: Measuring Fractal Dimension ?

2009-06-18 Thread Mark Dickinson
On Jun 18, 7:26 pm, David C. Ullrich  wrote:
> On Wed, 17 Jun 2009 08:18:52 -0700 (PDT), Mark Dickinson
> >Right.  Or rather, you treat it as the image of such a function,
> >if you're being careful to distinguish the curve (a subset
> >of R^2) from its parametrization (a continuous function
> >R -> R**2).  It's the parametrization that's uniformly
> >continuous, not the curve,
>
> Again, it doesn't really matter, but since you use the phrase
> "if you're being careful": In fact what you say is exactly
> backwards - if you're being careful that subset of the plane
> is _not_ a curve (it's sometimes called the "trace" of the curve".

Darn.  So I've been getting it wrong all this time.  Oh well,
at least I'm not alone:

"Definition 1. A simple closed curve J, also called a
Jordan curve, is the image of a continuous one-to-one
function from R/Z to R2. [...]"

- Tom Hales, in 'Jordan's Proof of the Jordan Curve Theorem'.

"We say that Gamma is a curve if it is the image in
the plane or in space of an interval [a, b] of real
numbers of a continuous function gamma."

- Claude Tricot, 'Curves and Fractal Dimension' (Springer, 1995).

Perhaps your definition of curve isn't as universal or
'official' as you seem to think it is?

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


Re: Exotic Logics

2009-06-18 Thread Dave Angel

Michael Torrie wrote:

William Clifford wrote:
  

I've read one can do all of the 16 binary operations with clever uses
of NAND or NOR.



That is correct.  In fact semiconductor logic is done using these two
principle gates.  See  http://en.wikipedia.org/wiki/NAND_logic .  Quite
interesting really.

  

Not "is done"  but  "could be" done.

As your reference correctly points out,  "However, contrary to popular 
belief, modern integrated circuits 
 are not constructed 
exclusively from a single type of gate"



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


Re: question about a command like 'goto ' in Python's bytecode orit's just a compiler optimization?

2009-06-18 Thread JanC
Hendrik van Rooyen wrote:

> It is my opinion that it is not possible to make a useful machine,
> virtual or real, which executes instructions sequentially, if the
> instruction set does not contain a conditional jump of some sort.
>
> I have tried doing it using conditional calls, and it fails on
> the equivalent of the first if ..., elif ...  you try to write.

I'm 99.99% sure you can implement that by using a decision subroutine that
returns subroutine pointers (and maybe parameter pointers), but it certainly
won't be efficient on current CPU designs...


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


Re: python tutorial

2009-06-18 Thread Carl Banks
On Jun 17, 5:36 pm, "steve"  wrote:
> >"Carl Banks"  wrote in message
> >news:2f6271b1-5ffa-4cec-81f8->>0276ad647__begin_mask_n#9g02mg7!__...__end_mask_i?a63jfad$...@p5g2000pre.googlegroups.com...
> >On Jun 15, 7:56 pm, "steve"  wrote:
> >> I was just looking at the python tutorial, and I noticed these lines:
>
> >>http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-...
>
> >> "Windows makes a distinction between text and binary files;
> >> "the end-of-line characters in text files are automatically altered
> >> "slightly when data is read or written.
>
> >> I don't see any obvious way to at docs.python.org to get that corrected:
> >> Is
> >> there some standard procedure?
>
> >What's wrong with it?
>
> >Carl Banks
>
> 1) Windows does not make a distinction between text and binary files.
>
> 2) end-of-line characters in text files are not automatically altered by
> Windows.

I agree with Robert Kern, it isn't necessary to distinguish between
Windows OS and a particular Windows runtime library for the purposes
of a tutorial.

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


Re: Measuring Fractal Dimension ?

2009-06-18 Thread Paul Rubin
David C. Ullrich  writes:
> >> obviously converges to f, but not uniformly.  On a closed interval,
> >> any continuous function is uniformly continuous.
> >
> >Isn't (-?, ?) closed?
> 
> What is your version of the definition of "closed"?

I think the whole line is closed, but I hadn't realized anyone
considered the whole line to be an "interval".  Apparently they do.
So that the proper statement specifies compactness (= closed and
bounded) rather than just "closed".
-- 
http://mail.python.org/mailman/listinfo/python-list


Is this pylint error message valid or silly?

2009-06-18 Thread Matthew Wilson
Here's the code that I'm feeding to pylint:

$ cat f.py
from datetime import datetime

def f(c="today"):

if c == "today":
c = datetime.today()

return c.date()


And here's what pylint says:

$ pylint -e f.py
No config file found, using default configuration
* Module f
E: 10:f: Instance of 'str' has no 'date' member (but some types could
not be inferred)

Is this a valid error message?  Is the code above bad?  If so, what is
the right way?

I changed from using a string as the default to None, and then pylint
didn't mind:


$ cat f.py 
from datetime import datetime

def f(c=None):

if c is None:
c = datetime.today()

return c.date()

$ pylint -e f.py 
No config file found, using default configuration

I don't see any difference between using a string vs None.  Both are
immutable.  I find the string much more informative, since I can write
out what I want.

Looking for comments.

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


Re: Packing a ctypes struct containing bitfields.

2009-06-18 Thread Karthik
On Jun 18, 6:29 pm, Nick Craig-Wood  wrote:
> Karthik  wrote:
> >  Hello Everybody,
>
> >  I'm trying to create a packed structure in ctypes (with one 64-bit
> >  element that is bitfielded to 48 bits),
> >  unsuccessfully:
>
> > ===
> >  from ctypes import *
>
> >  class foo (Structure):
> >      _pack_ = 1
> >      _fields_ = [
> >          ("bar",    c_ulonglong, 48),
> >      ]
>
> >  print("sizeof(foo) = %d" % sizeof(foo))
> > ===
> >  I'm expecting that this should print 6 - however, on my box, it prints
> >  8.
>
> >  The following piece of C code, when compiled and run, prints 6, which
> >  is correct.
> > ===
> >  struct foo {
> >      unsigned long long bar: 48;
> >  };
>
> >  printf("sizeof(foo) = %d", sizeof(foo));
> > ===
>
> >  So... what am I doing wrong?
>
> I compiled and ran the above with gcc on my linux box - it prints 8
> unless I add __attribute__((__packed__)) to the struct.
>
> I'm not sure that using bitfields like that is a portable at all
> between compilers let alone architectures.
>
> I'd probably do
>
> from ctypes import *
>
> class foo (Structure):
>     _pack_ = 1
>     _fields_ = [
>         ("bar0",    c_uint32),
>         ("bar1",    c_uint16),
>     ]
>     def set_bar(self, bar):
>         self.bar0 = bar & 0x
>         self.bar1 = (bar >> 32) & 0x
>     def get_bar(self):
>         return (self.bar1 << 32) + self.bar0
>     bar = property(get_bar, set_bar)
>
> print "sizeof(foo) = %d" % sizeof(foo)
> f = foo()
> print f.bar
> f.bar = 123456789012345
> print f.bar
>
> Which prints
>
> sizeof(foo) = 6
> 0
> 123456789012345
>
> --
> Nick Craig-Wood  --http://www.craig-wood.com/nick

Oops, sorry about the missing __attribute__((packed)) - that was an
error of
omission.

Thank you, Nick :)

I'm looking at some C code that's using bitfields in structs, and I'm
writing
python code that "imports" these structs and messes around with them -
unfortunately,
I'm not at liberty to change the C code to not use bitfields.

Your solution works fine, so that's what I'm going to use.

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


Re: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux

2009-06-18 Thread Fabio Zadrozny
> yes, the same problem even on an empty program. every file has the same
> problem.
>
> for example, if I new a file and input the following:
> import os
> os.
> after I input '.', it will pop up the window, and i can select the function
> of os module or continue input. but after that, no action can be taken for
> this file unless I switch to other files and then switch back.

If it's in pydev, there's probably some problem in your interpreter
configuration (when you do os. it'll spawn a shell to gather the
completions -- but that should be pretty quick unless you have some
firewall that's preventing the communication or the spawn didn't go
well -- check your error log to see if you have any errors... In linux
I've seen some problems when connecting to 127.0.0.1 while having ipv6
enabled or in a network card misconfiguration that could cause
problems too).

Cheers,

Fabio


>
> On Thu, Jun 18, 2009 at 10:57 AM, Tyler Laing  wrote:
>>
>> Do you experience the same problem even on an empty program file or is it
>> limited to just one file?
>>
>> -Tyler
>>
>> On Wed, Jun 17, 2009 at 7:47 PM, Wei, James  wrote:
>>>
>>> On Jun 18, 10:45 am, "Wei, James"  wrote:
>>> > When I am editing python program with SPE, I found that SPE will
>>> > freeze when it is doing auto-completion. The behavior is very strange
>>> > that I can not edit the file again. If I switch to another file and
>>> > then switch back, I can edit it again.
>>> >
>>> > So I switch to eclipse+pydev, but I found the same thing happen. So I
>>> > think it is not the problem of SPE or eclipse or pydev.
>>> >
>>> > If I disable auto-completion function in SPE or Eclipse+PyDev, it will
>>> > not freeze any longer.
>>> >
>>> > Anybody can give me some hints?
>>> >
>>> > I am using Ubuntu 8.10 and updated to latest. All packages is
>>> > installed through package manager.
>>>
>>> the only thing I googled related with it is
>>>
>>>
>>> http://www.nabble.com/-pydev---Users--jython-2.5b1-Froze-eclipse-on-autocomplete-td21394274.html
>>>
>>> but I think they are different.
>>>
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>>
>> --
>> Visit my blog at http://oddco.ca/zeroth/zblog
>
>
>
> --
> Best wishes to you.
>
> Yours sincerely
>
> Xiaohai Wei
> wist...@ustc.edu
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tutorial on working with Excel files in Python (without COM and cross platform!) at EuroPython 2009

2009-06-18 Thread John Machin
Mike Driscoll  gmail.com> writes:

> On Jun 18, 10:38 am, Chris Withers  wrote:

> > working with Excel files in Python using the pure-python libraries xlrd,
> > xlwt and xlutils.

> As I recall, these utilities don't allow the programmer to access
> Excel's formulas. Is that still an issue?

xlwt supports creating XLS files with a large chunk of the Excel formula
functionality. Support in xlrd for decompiling formulas exists only in a crude
form sufficient to support debugging of xlwt formula enhancements. Whether this
is an issue or not and for whom is difficult to detect -- certainly there have
been no demands for refund of purchase price :-). Some recent enhancements have
been initiated as patches supplied by programmers personally. Patches
(preferably pre-discussed) are welcome, as would be any advice on how to get the
big end of town to send patent lawyers[1], gun coders and money. 

[1] No kidding: http://www.google.com/patents/about?id=QMwnEBAJ




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


Re: Once again, comparison wxpython with PyQt

2009-06-18 Thread Jive Dadson
Qt has far better documentation, and it has Qt Designer.  The 
documentation is a big deal.  I wrote a little project in wxPython, and 
I spent 90% of my time just trying to find the names of member functions 
and then to figure out what they do.


Why not use Qt C++?  I like Python a lot.  Heck, I even embedded it in a
robot controller that might have wrangled some of the wafers that went 
into your computer chips.  But I think I would go with C++ for a medium 
size GUI project.


Hans Müller wrote:

Here we have to select between wxPython and PyQt for a medium size project.
In this project several hundred dialogs are to be created. This work 
will be done by a

program generator which has to re-written.

The question now is which framework should we use.
As far as I could found is PyQt with the Qt Framework the superior choice.
Most articles I found (not all) results to PyQt.
But Qt is expensive ~ 3400€ per Developer and OS.
Since these articles are more or less old, it would be nice to hear your 
current opinions.


Condensed, I found this pros / cons:

Pros for Qt:
- best framwork, well designed
- nice GUI builders
- faster execution
Cons:
- epensive

Pros for wxPython:
- cheap
- big community
Cons:
- more layers on top of OS
- more bugs (still valid ?)
- slower




Can someone tell me about his experiences with one or both frameworks ?

Thanks a lot,

Greetings
Hans

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


Calling subprocess with arguments

2009-06-18 Thread Tyler Laing
I've been trying any variation I can think of to do this properly, but
here's my problem:

I want to execute this command string: vlc -I rc

This allows vlc to be controlled via  a remote interface instead of the
normal gui interface.

Now, say, I try this from subprocess:

>>>p=subprocess.Popen('vlc -I rc test.avi'.split(' '), shell=False,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

But I don't get the remote interface. I get the normal gui interface. So how
do I do it? I've tried passing ['vlc', '-I', 'rc'], I've tried ['-I', 'rc']
with executable set to 'vlc'. I've had shell=True, I've had shell=False.
I've tried all these combinations.

What am I doing wrong?

-- 
Visit my blog at http://oddco.ca/zeroth/zblog
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: generator expression works in shell, NameError in script

2009-06-18 Thread ryles
On Jun 18, 9:56 am, nn  wrote:
> On Jun 18, 8:38 am, guthrie  wrote:
>
>
>
> > On Jun 17, 6:38 pm, Steven Samuel Cole 
> > wrote:
>
> > > Still don't really understand why my initial code didn't work, though...
>
> > Your code certainly looks reasonable, and looks to me like it "should"
> > work. The comment of partial namespace is interesting, but
> > unconvincing (to me) - but I am not a Python expert! It would
> > certainly seem that within that code block it is in the local
> > namespace, not removed from that scope to be in another.
>
> > Seems that it should either be a bug, or else is a design error in the
> > language!
>
> > Just as in the above noted "WTF" - non-intuitive language constructs
> > that surprise users are poor design.
>
> This is certainly an odd one. This code works fine under 2.6 but fails
> in Python 3.1.
>
> >>> class x:
>
> ...     lst=[2]
> ...     gen=[lst.index(e) for e in lst]
> ...
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 3, in x
>   File "", line 3, in 
> NameError: global name 'lst' is not defined
>
>
>
>

I believe it works in 2.x because unlike generator expressions, list
comprehensions do not create a new scope. However, in 3.0 list
comprehensions are actually treated as list().

http://docs.python.org/reference/expressions.html
http://www.python.org/dev/peps/pep-0289
-- 
http://mail.python.org/mailman/listinfo/python-list


KeyboardInterrupt eats my error and then won't be caught

2009-06-18 Thread Philip Semanchuk

Hi all,
I need help understanding how Python deals with Ctrl-C.

A user has reported a bug in my posix_ipc module. When a Python app is  
waiting to acquire an IPC semaphore and the user hits Ctrl-C, my code  
should return a custom error indicating that the semaphore wait was  
interrupted by a signal.


However, the caller never sees the error I set. Instead they get a  
KeyboardInterrupt that refuses to be caught by try/except. Here's a  
sample program that demonstrates the problem when run from the command  
line:


# ---
import posix_ipc

sem = posix_ipc.Semaphore(None, posix_ipc.O_CREX)

try:
   sem.acquire()   # User hits Ctrl + C while this is waiting
except:
   print "* I caught it!"

sem.close()
sem.unlink()
# ---

I expected that code to raise a posix_ipc.Error with the text, "The  
wait was interrupted by a signal" which would then be trapped by the  
except statement which would print the "I caught it!" message.


Instead a KeyboardInterrupt error is propagated up to the interpreter  
and the process is killed as if the try/except wasn't there at all.


I have verified that the C function sem_wait() returns -1 (failure),  
that errno is set to EINTR and that my detects that properly. So far,  
so good. PyErr_Occurred() returns NULL at that point. So my code calls  
PyErr_SetString() to set a custom error for the caller and returns  
NULL. It's apparently at some point after that that the  
KeyboardInterrupt error is being set.


If I substitute my sysv_ipc module for posix_ipc (very similar to  
posix_ipc but uses Sys V semaphores instead of POSIX), I get the same  
behavior.


I see this w/Python 2.5 under OS X and also w/Python 2.5 under Ubuntu  
8.0.4.


If anyone wants to look at my C code, the relevant case statement is  
on line 555 of posix_ipc_module.c.


http://semanchuk.com/philip/posix_ipc/
http://semanchuk.com/philip/sysv_ipc/


Any suggestions would be appreciated.

Thanks
Philip


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


Re: GUI(eclipse+pydev/SPE) freeze when doing python auto-completion under Linux

2009-06-18 Thread Wei, Xiaohai
Thanks for your reply.

where is the error log? I can not find it at /var/log

I have a virtual network card to bridge kvm virtual machine. will it cause
problem?

as you said configuration of interpretor, how should I configure the
interpretor?

Thanks

James

On Fri, Jun 19, 2009 at 9:32 AM, Fabio Zadrozny  wrote:

> > yes, the same problem even on an empty program. every file has the same
> > problem.
> >
> > for example, if I new a file and input the following:
> > import os
> > os.
> > after I input '.', it will pop up the window, and i can select the
> function
> > of os module or continue input. but after that, no action can be taken
> for
> > this file unless I switch to other files and then switch back.
>
> If it's in pydev, there's probably some problem in your interpreter
> configuration (when you do os. it'll spawn a shell to gather the
> completions -- but that should be pretty quick unless you have some
> firewall that's preventing the communication or the spawn didn't go
> well -- check your error log to see if you have any errors... In linux
> I've seen some problems when connecting to 127.0.0.1 while having ipv6
> enabled or in a network card misconfiguration that could cause
> problems too).
>
> Cheers,
>
> Fabio
>
>
> >
> > On Thu, Jun 18, 2009 at 10:57 AM, Tyler Laing 
> wrote:
> >>
> >> Do you experience the same problem even on an empty program file or is
> it
> >> limited to just one file?
> >>
> >> -Tyler
> >>
> >> On Wed, Jun 17, 2009 at 7:47 PM, Wei, James  wrote:
> >>>
> >>> On Jun 18, 10:45 am, "Wei, James"  wrote:
> >>> > When I am editing python program with SPE, I found that SPE will
> >>> > freeze when it is doing auto-completion. The behavior is very strange
> >>> > that I can not edit the file again. If I switch to another file and
> >>> > then switch back, I can edit it again.
> >>> >
> >>> > So I switch to eclipse+pydev, but I found the same thing happen. So I
> >>> > think it is not the problem of SPE or eclipse or pydev.
> >>> >
> >>> > If I disable auto-completion function in SPE or Eclipse+PyDev, it
> will
> >>> > not freeze any longer.
> >>> >
> >>> > Anybody can give me some hints?
> >>> >
> >>> > I am using Ubuntu 8.10 and updated to latest. All packages is
> >>> > installed through package manager.
> >>>
> >>> the only thing I googled related with it is
> >>>
> >>>
> >>>
> http://www.nabble.com/-pydev---Users--jython-2.5b1-Froze-eclipse-on-autocomplete-td21394274.html
> >>>
> >>> but I think they are different.
> >>>
> >>> --
> >>> http://mail.python.org/mailman/listinfo/python-list
> >>
> >>
> >>
> >> --
> >> Visit my blog at http://oddco.ca/zeroth/zblog
> >
> >
> >
> > --
> > Best wishes to you.
> >
> > Yours sincerely
> >
> > Xiaohai Wei
> > wist...@ustc.edu
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
> >
>



-- 
Best wishes to you.

Yours sincerely

Xiaohai Wei
wist...@ustc.edu
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: generator expression works in shell, NameError in script

2009-06-18 Thread greg

ssc wrote:


class SignupForm(Form):

titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',]
title_choices   = [(0, '')] + list((titles.index(t)+1, t) for t in
titles)

Does the generator expression have its own little namespace or so ?


Yes. The generator expression is a function, with its
own local namespace. Since the class scope is not visible
from inside functions declared within it, the behaviour
you're seeing results.

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


Re: generator expression works in shell, NameError in script

2009-06-18 Thread greg

nn wrote:


This is certainly an odd one. This code works fine under 2.6 but fails
in Python 3.1.


class x:


... lst=[2]
... gen=[lst.index(e) for e in lst]


In 3.x it was decided that the loop variables in a list
comprehension should be local, and not leak into the
surrounding scope. This was implemented by making the
list comprehension into a nested function.

Unfortunately this leads to the same unintuitive
behaviour as a genexp when used in a class scope.

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


Re: Is this pylint error message valid or silly?

2009-06-18 Thread Ben Finney
Matthew Wilson  writes:

> Here's the code that I'm feeding to pylint:
> 
> $ cat f.py
> from datetime import datetime
> 
> def f(c="today"):
> 
> if c == "today":
> c = datetime.today()
> 
> return c.date()
> 
> 
> And here's what pylint says:
> 
> $ pylint -e f.py
> No config file found, using default configuration
> * Module f
> E: 10:f: Instance of 'str' has no 'date' member (but some types could
> not be inferred)
> 
> Is this a valid error message?

Yes. Mentally run through your code and ask “what happens if the
condition for the ‘if’ statement is false?”

> Is the code above bad? If so, what is the right way?

Yes, it's bad:

* The function name ‘f’ is completely unhelpful. Consider a reader of
  the function who has no access to the inside of your head: Your
  function should be named, preferably, as a verb phrase, to say what
  the function *does* when it is called.

* The parameter name ‘c’ is completely undescriptive. Again, consider a
  reader ignorant of your thinking: You should name parameters so they
  help the reader know what the parameter is supposed to be and how it
  will be interpreted.

* You're re-binding the parameter name ‘c’ to something different within
  the function: it starts out bound to the input string, but by the time
  the function ends you're expecting it to be bound to a datetime
  object. Instead, you should be binding a *different* name to the
  datetime object you create inside the function, and using that for the
  return statement.

-- 
 \“Read not to contradict and confute, nor to believe and take |
  `\  for granted … but to weigh and consider.” —Francis Bacon |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Packing a ctypes struct containing bitfields.

2009-06-18 Thread Lawrence D'Oliveiro
In message , Karthik wrote:

> from ctypes import *

Don't do that.

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


Re: walking a directory with very many files

2009-06-18 Thread Lawrence D'Oliveiro
In message <20090618081423.2e035...@coercion>, Mike Kazantsev wrote:

> On Thu, 18 Jun 2009 10:33:49 +1200
> Lawrence D'Oliveiro  wrote:
> 
>> In message <20090617214535.10866...@coercion>, Mike Kazantsev wrote:
>> 
>>> On Wed, 17 Jun 2009 23:04:37 +1200
>>> Lawrence D'Oliveiro  wrote:
>>> 
 In message <20090617142431.2b25f...@malediction>, Mike Kazantsev
 wrote:
 
> On Wed, 17 Jun 2009 17:53:33 +1200
> Lawrence D'Oliveiro  wrote:
> 
>>> Why not use hex representation of md5/sha1-hashed id as a path,
>>> arranging them like /path/f/9/e/95ea4926a4 ?
>>> 
>>> That way, you won't have to deal with many-files-in-path problem
>>> ...
>> 
>> Why is that a problem?
> 
> So you can os.listdir them?
 
 Why should you have a problem os.listdir'ing lots of files?
>>> 
>>> I shouldn't, and I don't ;)
>> 
>> Then why did you suggest that there was a problem being able to
>> os.listdir them?
> 
> I didn't, OP did ...

Then why did you reply to my question "Why is that a problem?" with "So that 
you can os.listdir them?", if you didn't think there was a problem (see 
above)?

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


Re: walking a directory with very many files

2009-06-18 Thread Lawrence D'Oliveiro
In message , Ethan 
Furman wrote:

> Lawrence D'Oliveiro wrote:
>> In message <20090617214535.10866...@coercion>, Mike Kazantsev wrote:
>> 
>> 
>>>On Wed, 17 Jun 2009 23:04:37 +1200
>>>Lawrence D'Oliveiro  wrote:
>>>
>>>
In message <20090617142431.2b25f...@malediction>, Mike Kazantsev wrote:


>On Wed, 17 Jun 2009 17:53:33 +1200
>Lawrence D'Oliveiro  wrote:
>
>
>>>Why not use hex representation of md5/sha1-hashed id as a path,
>>>arranging them like /path/f/9/e/95ea4926a4 ?
>>>
>>>That way, you won't have to deal with many-files-in-path problem ...
>>
>>Why is that a problem?
>
>So you can os.listdir them?

Why should you have a problem os.listdir'ing lots of files?
>>>
>>>I shouldn't, and I don't ;)
>> 
>> Then why did you suggest that there was a problem being able to
>> os.listdir them?
> 
> He didn't ...

He replied to my question "Why is that a problem?" with "So you can 
os.listdir them?". Why reply with an explanation of why it's a problem if 
you don't think it's a problem?


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


Re: walking a directory with very many files

2009-06-18 Thread Lawrence D'Oliveiro
In message <%zv_l.19493$y61.5...@news-server.bigpond.net.au>, Lie Ryan 
wrote:

> Yeah, it might be possible to just mv the file from outside, but not
> being able to enter a directory just because you've got too many files
> in it is kind of silly.

Sounds like a problem with your file/directory-manipulation tools.

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


Re: AT&T Usenet Netnews Service Shutting Down

2009-06-18 Thread Terry Reedy

Jive Dadson wrote:

newsmas...@bellsouth.net wrote:

Please note that on or around July 15, 2009, AT&T will no longer be
offering access to the Usenet Netnews service.  If you wish to continue
reading Usenet newsgroups, access is available through third-party 
vendors.


news.gmane.org (free) mirrors python-list as gmane.comp.python.general
I prefer it to c.l.p because python-list filters out most spam.

Ah ha.  I think I may have figured out how to work around it.  I need to 
use my EasyNews server to post the message, (with "SSL"), rather than 
the  ATT server.  I think.  Maybe.  Does anyone know if it's possible to 
have Thunderbird use different outgoing servers for different accounts?


Tbird recommends not doing so (no idea why), so it *must* be possible 
;-).  Looks pretty simple.


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


Re: Is this pylint error message valid or silly?

2009-06-18 Thread Terry Reedy

Matthew Wilson wrote:

Here's the code that I'm feeding to pylint:

$ cat f.py
from datetime import datetime

def f(c="today"):


pylint infers that you intend users to pass a string. Human would guess 
the same at this point.



if c == "today":
c = datetime.today()


Now I guess that you actually intend c to be passed as a datetime 
object. You only used the string as a type annotation, not as a real 
default value. Something like 'record_date = None' is better.



return c.date()


and here you ask for the input's date, which strings do not have.



And here's what pylint says:

$ pylint -e f.py
No config file found, using default configuration
* Module f
E: 10:f: Instance of 'str' has no 'date' member (but some types could
not be inferred)

Is this a valid error message?  Is the code above bad?  If so, what is
the right way?

I changed from using a string as the default to None, and then pylint
didn't mind:


$ cat f.py 
from datetime import datetime


def f(c=None):

if c is None:
c = datetime.today()

return c.date()

$ pylint -e f.py 
No config file found, using default configuration


I don't see any difference between using a string vs None.  Both are
immutable.  I find the string much more informative, since I can write
out what I want.

Looking for comments.

Matt


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