Using unittest for benchmarking / speed improvements

2008-03-29 Thread Daniel Abel
Hi!

As everyone knows, using unittests to monitor and improve the
correctness of code is really handy. Is there a good system for using
unittests to monitor / improve the _speed_ of code?

I.e. I would like a system which every time when running a test, also
measures the time the test took, and stores it in a file
somewhere. (For example, stores date&time, svn revision, and the time
the test took) Then, the programmer can plot that in gnuplot / etc,
and see whether the speed of the code is improving or not, and also
compare different tests to each other (when comparing the speed of
different implementations).

Also, svn revisions could be labelled with svn checkin comments, so
that one can easily associate any improvement / regression with the
summary of the change.

I was thinking about something built on top of nose, and hoping
someone has already created such a thing. (After all, 'benchmark
before optimize' and similar are often repeated; such a system seems
really necessary for doing that systematically.)

I found
http://renesd.blogspot.com/2007/08/timing-and-unittests-graphing-speed.html
which talks about this idea, and
the stopwatch plugin at:
http://darcs.idyll.org/~t/projects/pinocchio/doc/#stopwatch-selecting-tests-based-on-execution-time
which can measure the time (and would be the easies to extend to store
the information I would need)
and also the profile nose plugin (included in the nose package) can
measure how time is spent _inside_ the test. (which is also handy, but
I
would only need unittest-level timing, i.e. not as granular as
profile
creates.)

So, is there such a complete framework (i.e. which can compare speed
across revisions) or do I have to hack one together myself? (And would
others be interested in it?)

Thanks in advance,
Daniel Abel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Summary of threading for experienced non-Python programmers?

2008-03-29 Thread Hrvoje Niksic
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes:

>> systems.  (In theory, file input/output should also be available as
>> asynchronous code, but async IO is low-level and not available in
>> Python.)  While threads shouldn't be considered a replacement for
>
> I suggest you tell that the twisted-guys. And the ones from the
> built-in asyncore-module.

Note that I said "*file* input/output".  Twisted and asyncore are
about asynchronous socket programming that polls over nonblocking file
descriptors such as found in socket programming, not about wrapping
aio(3) and the equivalent Windows APIs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I reconnect a disconnected socket?

2008-03-29 Thread Bryan Olson
Grant Edwards wrote:
> Laszlo Nagy wrote:
>> What about non-blocking sockets?
> 
> $ man recv
> ...
>If no messages are available at the socket, the receive
>calls wait for a message to arrive, unless the socket is
>non-blocking (see fcntl(2)), in which case the value -1
>is returned and the external variable errno set to
>EAGAIN.

As Grant showed, a successful recv() returning zero bytes
indicates the end of the data stream from the remote peer.
Other cases block or raise errors.

A few more notes:

When a socket will return zero bytes to indicate the end of the
data stream, it will select() as readable.

In the case Laszlo asked about here -- a non-blocking socket
is not shutdown but no data is immediately readable -- on some
systems, the error is EWOULDBLOCK, which may be, but is not
generally, the same code as EAGAIN. (There may be yet other
systems that have different error conventions; I don't know.)

The Python library's 'errno' module exports the error names with
their associated numeric values.

Python's socket module does not 'return' these error codes; it
raises exceptions. A non-blocking socket, or equivalently a
socket with a timeout of zero, will raise socket.error. The
errno in the exception's (errno, string) value should be
EAGAIN or EWOULDBLOCK.  If a socket has a non-zero timeout,
and that timeout expires, the operation raises socket.timeout.


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


Re: Setting the value of one cell in QTableWidget fills everything.

2008-03-29 Thread Constantly Distracted
> Move the creation of the QTableWidgetItem() to the inner loop (and call
> it "item" rather than "items").
>
> Phil

Thanks, that works perfectly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tell ya' what:

2008-03-29 Thread castironpi
On Mar 28, 3:59 pm, [EMAIL PROTECTED] wrote:
> I want to regression a signal.  It's NN, not necessarily, sine wave.
> What kind of numbers of harmonic simultaneous sounds are we looking
> at?  How close to an A 440 can a human make?
>
> I want recognition to alert me.  As a sine wave is coming in:
>
> >>> for t in [ ( 200* sin( x*2 ), 200* cos( x*2 ) ) for x in range( 10 ) ]: 
> >>> print( *t )
>
> ...
> 0.0 200.0
> 181.859485365 -83.2293673094
> -151.360499062 -130.728724173
> -55.8830996398 192.03405733
> 197.871649325 -29.167617
> -108.804222178 -167.814305815
> -107.3145836 168.770791746
> 198.121471139 27.3474436416
> -57.58066 -191.531896065
> -150.197449354 132.063341649
>
> Did everyone take the course on computer architecture?

E.g. sum() is not an operation you do in world operations.  (i
question that 'walk' is.)  you don't ( add ) drop to puddle, you move
drop.  we've all got graphics sub-primitives but no modelling ones.
you don't want to decode sense cell inputs, do you?  i'd say in
complexity, one cell adds up to an entire input line-trail (wake).  I
would be proposing multiplexcating every CPU unit onto every input
gate: off keystrokes and camera photovoltaics.  (Light takes six -
complexity- muscles, plus squinting, while not six calory-muscles.)
So, taking outputs to be common combinations of inputs, unless you
want symbological inputs to map to anything constructive.  I think we
design architecture utility-first.  Ste p1.  Big box?  Would
calculations include utility transponders (tabulation)?  Time-scale is
discretized.  Can you be more productive continuously?  Do you need to
recognize users discretely, each an own interaction on file, due to
discrete measures (discrete times)?  It's more robotic than our
interface with dogs.  Does anyone have names for syllables?
Superlatives are always theoretical.  What can we learn from an
executed time-space translation?  Point is, sum() is not real, add is.

I think event-driven stuff.  It's non-destructive.  Are there other
tables after D.J.?  He's predictable alright.

Broadcast dropoff "sighted" (recognized).  Is that bandwidth or baud?
How quickly can you get total human decible out of a room?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding euclidean distance,better code?

2008-03-29 Thread Roel Schroeven
Steven D'Aprano schreef:
> On Fri, 28 Mar 2008 16:59:59 +0100, Robert Bossy wrote:
> 
>> Gabriel Genellina wrote:
>>> That's what I said in another paragraph. "sum of coordinates" is using
>>> a different distance definition; it's the way you measure distance in a
>>> city with square blocks. I don't know if the distance itself has a
>>> name, but
>> I think it is called Manhattan distance in reference of the walking
>> distance from one point to another in this city.
> 
> You know, there are other cities than Manhattan. Some of them even have 
> streets and blocks.

I'm not sure what your point is. The name of the distance happens to be 
Manhattan distance (or taxicab distance, rectilinear distance, L1 
distance, city block distance; see 
http://en.wikipedia.org/wiki/Manhattan_distance) so Robert has a valid 
point.


-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
   -- Isaac Asimov

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


Re: Help me on function definition

2008-03-29 Thread Roel Schroeven
aeneng schreef:
> Hello everyone,
> 
> I am just starting to use python in numerical cacluation. 
> I need you to help me to see what's wrong with the following piece of 
> codes, which computes the cross product of two vectors and returns 
> the result. u and v are two 3x1 matrix.
> 
> when I import the function, error message show like this
 import cross
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "cross.py", line 8
> ppp2=u[2]*v[0]-u[0]*v[2]
> ^
> SyntaxError: invalid syntax
> 
> WHAT IS WRONG WITH MY CODE?
> 
> I appreciate your help.
> 
> ##here is the function definition.
> ##cross.py##
> def cross(u,v)
> """input two vectors u and v in 3-D space, 
>output a cross product of vector w, in column or in row 
> accordingly."""
> ppp1,ppp2,ppp3=0.0,0.0,0.0

You forgot the : after def cross(u, v)

-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
   -- Isaac Asimov

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


Re: Summary of threading for experienced non-Python programmers?

2008-03-29 Thread Paul Rubin
Hrvoje Niksic <[EMAIL PROTECTED]> writes:
> Note that I said "*file* input/output".  Twisted and asyncore are
> about asynchronous socket programming that polls over nonblocking file
> descriptors such as found in socket programming, not about wrapping
> aio(3) and the equivalent Windows APIs.

aio is also used for sockets, while twisted and asyncore use select or
something similar.  That is asynchronous but in a different sense of
the word.  See also: http://www.kegel.com/c10k.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Summary of threading for experienced non-Python programmers?

2008-03-29 Thread Paul Rubin
Paul Rubin  writes:
> aio is also used for sockets, while twisted and asyncore use select or
> something similar.  That is asynchronous but in a different sense of
> the word.  See also: http://www.kegel.com/c10k.html

Hmm that actually says that in Linux 2.6.0#-test2 sockets weren't
supported.  I can't tell the situation from the man page on the system
I'm using right now.  I may have misremembered but I thought I talked
with someone a while back who was using aio in a high concurrency VOIP
system and that it was beating other approaches.  I don't know what
kernels were involved etc.  Anyway using this stuff in Python would be
overkill.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding euclidean distance,better code?

2008-03-29 Thread Steven D'Aprano
On Sat, 29 Mar 2008 10:11:28 +0100, Roel Schroeven wrote:

> Steven D'Aprano schreef:
>> On Fri, 28 Mar 2008 16:59:59 +0100, Robert Bossy wrote:
>> 
>>> Gabriel Genellina wrote:
 That's what I said in another paragraph. "sum of coordinates" is
 using a different distance definition; it's the way you measure
 distance in a city with square blocks. I don't know if the distance
 itself has a name, but
>>> I think it is called Manhattan distance in reference of the walking
>>> distance from one point to another in this city.
>> 
>> You know, there are other cities than Manhattan. Some of them even have
>> streets and blocks.
> 
> I'm not sure what your point is. The name 

"The" name? You go on to list four additional names, so why do you say 
that "Manhattan distance" is THE name? When I studied this at university, 
we called it the taxi metric. 


> of the distance happens to be
> Manhattan distance (or taxicab distance, rectilinear distance, L1
> distance, city block distance; see
> http://en.wikipedia.org/wiki/Manhattan_distance) so Robert has a valid
> point.

Wikipedia doesn't believe that M-D is the primary or most common name, 
and the link you give redirects to "Taxicab distance". Googlefight 
agrees: "Taxicab distance" is more than twice as common, and "rectilinear 
distance" more than five times as common.

My point was to draw attention to Robert's unconscious assumptions which 
are reflected in his choice of language. Rectilinear distance applies to 
more than "distance from one point to another in THIS city" (emphasis 
added).

It applies in parts of Rome, Sydney, London, Moscow and many other 
places. It even applies to sleepy little country towns like Bendigo and 
Mildura here in Australia. Manhattan is hardly the only place where 
cities are carved up into rectangular or square city blocks, and I doubt 
that it applies to the entirety of Manhattan. It also applies to 
supermarket isles, church pews, chess boards, pixels on a monitor and no 
doubt other places as well.

The very name is New York-centric, just as much as if the English called 
the science of acoustics "Big-Ben-onics" in reference to the peals of Big 
Ben's clock. I had thought I had pointed that out with a little gentle 
understatement.



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


Passing function objects to timeit

2008-03-29 Thread Steven D'Aprano
The timeit.Timer class times "code snippets" -- you pass it strings 
rather than function objects. That's good for what it's worth, but 
sometimes the code you want to time is too big to easily pass as a 
string, or maybe you only have access to a function object without the 
source, or for whatever reason it's not very convenient.

In this case, a good trick is to import the function by name:

timeit.Timer('spam()', 'from __main__ import spam')


But now I find myself wanting to time a function that's not defined in 
__main__. Here's a illustrative example:


def factory():
def f():
return "spam"
return f

def main():
func = factory()
return timeit.Timer('func()', 'from __main__ import func').timeit() 


But it doesn't work:

>>> main()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 3, in main
  File "/usr/lib/python2.5/timeit.py", line 161, in timeit
timing = self.inner(it, self.timer)
  File "", line 3, in inner
ImportError: cannot import name func


Moving the definition of func into __main__ is not an option. What do I 
do? Am I reduced to re-writing the timeit module to take functions 
instead of strings? (Maybe I should do that anyway.) Or is there a way to 
inject the function object into the namespace used by timeit?



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


Why prefer != over <> for Python 3.0?

2008-03-29 Thread kwitters
I don't know if this is the right place to discuss the death of <> in
Python 3.0, or if there have been any meaningful discussions posted
before (hard to search google with '<>' keyword), but why would anyone
prefer the comparison operator != over <>???

I've written an article about it to try and save this nice "is not
equal" operator, located at http://dewitters.koonsolo.com/python_neq.html

Please set it straight in 3.0, and if not, convince me with a good
reason of doing so, so that I can live with it and don't have to spend
the rest of my life in 2.x ;).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why prefer != over <> for Python 3.0?

2008-03-29 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> I don't know if this is the right place to discuss the death of <> in
> Python 3.0, or if there have been any meaningful discussions posted
> before (hard to search google with '<>' keyword), but why would anyone
> prefer the comparison operator != over <>???

I doubt anyone cares.  Python probably chose != because it's what C uses.
The scary choice is /= which can be interpreted as an assignment.  Python
lacks assignment expressions partly because of a meme that using = instead
of == by accident is a common C bug.  I'm sure it happens but at least in
my own experience (from having written plenty of buggy C code over the
years) it's not that frequent.  Using /= instead of != seems more likely,
for programmers who switch between C and languages that use /= for nonequality.
-- 
http://mail.python.org/mailman/listinfo/python-list


deleting a line from a file

2008-03-29 Thread eMko
Hello,

In Perl, using a Tie::File module I can easily and comfortably delete
a line from the middle of a text file:

  my @file;
  open(DATA, "+<:encoding(utf8):raw" , "file.txt") or return 0;
  tie @file, 'Tie::File', \*DATA or return 0;
  splice(@file, $_[0], 1);
  untie @file;
  close DATA;

(when the first argument of the function ($_[0]) is a number of the
line which should be deleted)

Is there some easy way how to delete a line from a middle of a file in
Python?

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


Re; finding euclidean distance,better code?

2008-03-29 Thread Hendrik van Rooyen
On Saturday 29 March 2008 03:09:46 Steven D'Aprano wrote:
> On Fri, 28 Mar 2008 16:59:59 +0100, Robert Bossy wrote:
> > Gabriel Genellina wrote:
> >> That's what I said in another paragraph. "sum of coordinates" is using
> >> a different distance definition; it's the way you measure distance in a
> >> city with square blocks. I don't know if the distance itself has a
> >> name, but
> >
> > I think it is called Manhattan distance in reference of the walking
> > distance from one point to another in this city.
>
> You know, there are other cities than Manhattan. Some of them even have
> streets and blocks.

Sorry about having to dispel your illusions, but -

In Printed Circuit Board Layout jargon, the 'manhattan distance' is
the sum of the distances along the orthogonal axes between
two points on the board that should be connected.

The sum of all such distances is an idealised minimum for the
total track length on a double sided board, given that it were 
possible to lay all tracks with segments connected by vias,
making strictly increasing progress in the desired direction,
by laying x direction tracks on the one, and y direction tracks 
on the other side of the board without having to "backtrack" 
- i.e. having to "dodge around" obstacles, thereby adding 
"overshooting" segments of track.

(A via is a through plated hole that connects copper traces or 
tracks on opposite sides of the board) 

So I have met the beast, but I have no concept of its origin,
other than the mind numbing regularity of the layout of the
suburb of the city after which it seems to be named -
For all I know 'manhatten' could be a native american word that
means "net".

Have you noticed that when people say "Sorry.but" they are 
not normally sorry at all?

:-)

-  Hendrik



 

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


Re: why does socket.makefile require non-blocking mode?

2008-03-29 Thread Guilherme Polo
2008/3/28, Forest <[EMAIL PROTECTED]>:
> The socket.makefile() docs say, "the socket must be in blocking mode."  I
>  don't see any explanation of why blocking mode is required, and I'm not sure
>  whether that means timeout mode is forbidden as well.  Can someone clarify
>  this?
>

Have you set your socket to be nonblocking ? Otherwise it is blocking,
it is the "normal" one. I don't know why you think timeout is
forbidden too, it is not.

>  I wanted to use file-like objects with socket timeouts, so I ended up writing
>  my own replacement for socket._fileobject.  I'd appreciate it if someone 
> could
>  either explain to my why my new class was unnecessary, or else encourage me 
> to
>  contribute it as a patch to the socket module.
>

It looks like to be unnecessary.

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


-- 
-- Guilherme H. Polo Goncalves
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why prefer != over <> for Python 3.0?

2008-03-29 Thread Steven D'Aprano
On Sat, 29 Mar 2008 04:08:16 -0700, Paul Rubin wrote:

> [EMAIL PROTECTED] writes:
>> I don't know if this is the right place to discuss the death of <> in
>> Python 3.0, or if there have been any meaningful discussions posted
>> before (hard to search google with '<>' keyword), but why would anyone
>> prefer the comparison operator != over <>???
> 
> I doubt anyone cares.  

[channeling Luke Skywalker sotto voice]
I care.


> Python probably chose != because it's what C uses.

Coming from a background in Pascal, I originally hated the look of != and 
preferred <> but I've now got used to the look of it.

When I design my own language (ha!), I'll use != for "not equal to" and 
reserve <> for "greater than or less than but not equal to" which is 
subtly different. (Think about unordered values, where x != y does not 
imply that x < y or x > y, e.g. IEEE NaNs.)

> The scary choice is /= which can be interpreted as an assignment. 

"Can be"?

>>> x = 5.0
>>> x /= 2
>>> x
2.5


Koen, I've read your blog and I'm afraid that your reasoning is specious. 
You say:

[quote]
For comparison (not assignment!), they use operators like <, >, <= 
(smaller or equals), >= (larger or equals), == (double '=' so there is no 
confusion with assignment).

All pretty clear hey? But now comes the catch, there exists an operator 
!=... but what does it mean? Well, that one is pretty easy, of course ! 
must be an operator of its own (in non-python languages meaning 'not'), 
and it resembles the fancy assignment statement, so 
a != b

must mean "assign the value 'not b' to 'a'... right?... Wrong! Somehow 
this is a comparison operator meaning "not equals"... what??? Yes, that's 
right, but hey, you learn to live with it eventually.
[end quote]

Given that <= is a comparison operator, not an assignment, why do you 
jump to the conclusion that != is an assignment? Why don't you argue that 
"x <= y" means "assign the value of xhttp://mail.python.org/mailman/listinfo/python-list


Re: deleting a line from a file

2008-03-29 Thread Steven D'Aprano
On Sat, 29 Mar 2008 04:13:10 -0700, eMko wrote:

> Is there some easy way how to delete a line from a middle of a file in
> Python?

If the file is small enough to fit into memory (say, up to a few hundred 
megabytes on most modern PCs):


lines = open('file', 'r').readlines()
del line[100]
open('file', 'w').writelines(lines)


Quick and easy for the coder, but not the safest way to do it in serious 
production code because there's no error handling there.

The only safe way to delete a line from a file (at least under common 
operating systems like Windows, Linux and Mac) is to copy the file 
(without the line you wish to delete) to a temporary file, then replace 
the original file with the new version. That's also how to do it for 
files too big to read into memory.



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


Re: Why prefer != over <> for Python 3.0?

2008-03-29 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> reserve <> for "greater than or less than but not equal to" which is 
> subtly different. (Think about unordered values, where x != y does not 
> imply that x < y or x > y, e.g. IEEE NaNs.)

Heh, good point.

> > The scary choice is /= which can be interpreted as an assignment. 
> "Can be"?

Yes, what I mean is that some languages (e.g. Ada, Haskell) use /= for
nonequality.  So if you switch between Haskell and C, you could find
yourself typing /= when you mean != and the compiler won't flag it.

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


Re: deleting a line from a file

2008-03-29 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> The only safe way to delete a line from a file (at least under common 
> operating systems like Windows, Linux and Mac) is to copy the file 
> (without the line you wish to delete) to a temporary file, then replace 
> the original file with the new version. That's also how to do it for 
> files too big to read into memory.

You could do it "in place" in all those systems afaik, either opening
the file for both reading and writing, or using something like mmap.
Basically you'd leave the file unchanged up to line N, then copy lines
downward starting from line N+1.  At the end you'd use ftrunc to
shrink the file, getting rid of the duplicate last line.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding euclidean distance,better code?

2008-03-29 Thread Roel Schroeven
Steven D'Aprano schreef:
> On Sat, 29 Mar 2008 10:11:28 +0100, Roel Schroeven wrote:
> 
>> Steven D'Aprano schreef:
>>> On Fri, 28 Mar 2008 16:59:59 +0100, Robert Bossy wrote:
>>>
 Gabriel Genellina wrote:
> That's what I said in another paragraph. "sum of coordinates" is
> using a different distance definition; it's the way you measure
> distance in a city with square blocks. I don't know if the distance
> itself has a name, but
 I think it is called Manhattan distance in reference of the walking
 distance from one point to another in this city.
>>> You know, there are other cities than Manhattan. Some of them even have
>>> streets and blocks.
>> I'm not sure what your point is. The name 
> 
> "The" name? You go on to list four additional names, so why do you say 
> that "Manhattan distance" is THE name? When I studied this at university, 
> we called it the taxi metric. 
> 
> 
>> of the distance happens to be
>> Manhattan distance (or taxicab distance, rectilinear distance, L1
>> distance, city block distance; see
>> http://en.wikipedia.org/wiki/Manhattan_distance) so Robert has a valid
>> point.
> 
> Wikipedia doesn't believe that M-D is the primary or most common name, 
> and the link you give redirects to "Taxicab distance". Googlefight 
> agrees: "Taxicab distance" is more than twice as common, and "rectilinear 
> distance" more than five times as common.
> 
> My point was to draw attention to Robert's unconscious assumptions which 
> are reflected in his choice of language. Rectilinear distance applies to 
> more than "distance from one point to another in THIS city" (emphasis 
> added).

You can hardly blame that on Robert. It's true that Manhattan distance 
is not the only name and not even the most popular one, but it's also 
true that it's a valid name, and that Robert didn't invent it, he merely 
used an existing name.

> It applies in parts of Rome, Sydney, London, Moscow and many other 
> places. It even applies to sleepy little country towns like Bendigo and 
> Mildura here in Australia. Manhattan is hardly the only place where 
> cities are carved up into rectangular or square city blocks, and I doubt 
> that it applies to the entirety of Manhattan.

No, but it's actually very close.

I just looked at the places you mention in Google Earth; while they do 
have sections with rectangular layouts, in none of them it is as 
prevalent and obvious as in Manhattan (Manhattan isn't a city of course 
like the other ones, it's only a part of New York).

Now of course it's true that there are many other places with checker 
board layouts, but I still don't think that makes Manhattan distance a 
bad name.

> The very name is New York-centric, just as much as if the English called 
> the science of acoustics "Big-Ben-onics" in reference to the peals of Big 
> Ben's clock. I had thought I had pointed that out with a little gentle 
> understatement.

I'm absolutely not USA/America/New York centric myself, but Manhattan 
simply is a good and well-known example of a checker board layout.

There are worse examples of bad names: 'French fries' for example is 
French-centric, but that's not the real problem. The real problem is 
that the name is simply wrong because fries are Belgian (which is 
disputed, but I believe it since I'm from Belgium ;) ). But I'm still 
not going the call them freedom fries or anything.

In any case, I replied because your reaction didn't feel all that gentle 
to me; to be honest, it felt rather rude. I apologize for interpreting 
the tone incorrectly.

-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
   -- Isaac Asimov

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


Re: Re; finding euclidean distance,better code?

2008-03-29 Thread Maurice LING
Hendrik van Rooyen wrote:
> On Saturday 29 March 2008 03:09:46 Steven D'Aprano wrote:
>> On Fri, 28 Mar 2008 16:59:59 +0100, Robert Bossy wrote:
>>> Gabriel Genellina wrote:
 That's what I said in another paragraph. "sum of coordinates" is using
 a different distance definition; it's the way you measure distance in a
 city with square blocks. I don't know if the distance itself has a
 name, but
>>> I think it is called Manhattan distance in reference of the walking
>>> distance from one point to another in this city.
>> You know, there are other cities than Manhattan. Some of them even have
>> streets and blocks.
> 
> Sorry about having to dispel your illusions, but -
> 
> In Printed Circuit Board Layout jargon, the 'manhattan distance' is
> the sum of the distances along the orthogonal axes between
> two points on the board that should be connected.
> 
> The sum of all such distances is an idealised minimum for the
> total track length on a double sided board, given that it were 
> possible to lay all tracks with segments connected by vias,
> making strictly increasing progress in the desired direction,
> by laying x direction tracks on the one, and y direction tracks 
> on the other side of the board without having to "backtrack" 
> - i.e. having to "dodge around" obstacles, thereby adding 
> "overshooting" segments of track.
> 
> (A via is a through plated hole that connects copper traces or 
> tracks on opposite sides of the board) 
> 
> So I have met the beast, but I have no concept of its origin,
> other than the mind numbing regularity of the layout of the
> suburb of the city after which it seems to be named -
> For all I know 'manhatten' could be a native american word that
> means "net".
> 
> Have you noticed that when people say "Sorry.but" they are 
> not normally sorry at all?
> 
> :-)
> 
> -  Hendrik
> 

Manhatten distance is also known as "taxicab distance" or "city block 
distance" - the average distance of getting from point A to point B in a 
city with roads laid out as grids.

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


Create executable from executable with py2exe

2008-03-29 Thread vedrandekovic
Hello,

Is there any example how can I create executable from executable with
py2exe.For example if I create main executable with some TextEntry
( wxpython ) and then when i write this code into this entry:

import os
print os.getcwd()
print "ok"

...to main executable convert this code into executable with py2exe.

Sorry for my english!
Regards,
Vedran
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Psyco alternative

2008-03-29 Thread king kikapu
On 28 Μαρ, 20:06, Paul Boddie <[EMAIL PROTECTED]> wrote:
> On 27 Mar, 15:19, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
>
>
> [Psyco maintenance and further development]
>
> > Nope, but I heard through the grapevine that while it won't be supported for
> > all times to come, a new version is in the making.
>
> > But ultimately, the author says that the approach is flawed, so at *some*
> > point it will be discontinued. But that could be said about nearly
> > everything, couldn't it?
>
> From what I've seen from browsing publicly accessible materials,
> there's a certain commercial interest in seeing Psyco updated
> somewhat. So, whether it gets discontinued depends on the usual
> factors of satisfying a need and there being qualified and motivated
> people to work on it.
>
> Paul

Let's hope that this isn't going to happen (psyco dicontinued). But i
do not have positive thinking after an email i got for the author last
week. Unless something has changed...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: finding euclidean distance,better code?

2008-03-29 Thread Gerard Flanagan
On Mar 29, 11:01 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Sat, 29 Mar 2008 10:11:28 +0100, Roel Schroeven wrote:
> > Steven D'Aprano schreef:
> >> On Fri, 28 Mar 2008 16:59:59 +0100, Robert Bossy wrote:
>
> >>> Gabriel Genellina wrote:
>  That's what I said in another paragraph. "sum of coordinates" is
>  using a different distance definition; it's the way you measure
>  distance in a city with square blocks. I don't know if the distance
>  itself has a name, but
> >>> I think it is called Manhattan distance in reference of the walking
> >>> distance from one point to another in this city.
>
> >> You know, there are other cities than Manhattan. Some of them even have
> >> streets and blocks.
>
> > I'm not sure what your point is. The name
>
> "The" name? You go on to list four additional names, so why do you say
> that "Manhattan distance" is THE name? When I studied this at university,
> we called it the taxi metric.
>
> > of the distance happens to be
> > Manhattan distance (or taxicab distance, rectilinear distance, L1
> > distance, city block distance; see
> >http://en.wikipedia.org/wiki/Manhattan_distance) so Robert has a valid
> > point.
>
> Wikipedia doesn't believe that M-D is the primary or most common name,
> and the link you give redirects to "Taxicab distance". Googlefight
> agrees: "Taxicab distance" is more than twice as common, and "rectilinear
> distance" more than five times as common.
>
> My point was to draw attention to Robert's unconscious assumptions which
> are reflected in his choice of language. Rectilinear distance applies to
> more than "distance from one point to another in THIS city" (emphasis
> added).
>
> It applies in parts of Rome, Sydney, London, Moscow and many other
> places. It even applies to sleepy little country towns like Bendigo and
> Mildura here in Australia. Manhattan is hardly the only place where
> cities are carved up into rectangular or square city blocks, and I doubt
[...]

a metric by any other name...

http://news.bbc.co.uk/2/hi/uk_news/northern_ireland/2595215.stm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding euclidean distance,better code?

2008-03-29 Thread Peter Otten
Steven D'Aprano wrote:

> Wikipedia doesn't believe that M-D is the primary or most common name,
> and the link you give redirects to "Taxicab distance". Googlefight
> agrees: "Taxicab distance" is more than twice as common, and "rectilinear
> distance" more than five times as common.

Could it be that there are many documents containing both taxicab and
distance that have nothing to do with the "taxicab distance"? Searching
with quotes around the search term google advertises 

about 936 results for "taxicab distance"
6930 for "rectilinear distance"
38200 for "manhattan distance"

> The very name is New York-centric, just as much as if the English called 
> the science of acoustics "Big-Ben-onics" in reference to the peals of Big 
> Ben's clock. I had thought I had pointed that out with a little gentle 
> understatement.

Whether you like a term and agree with its (alleged) bias or if it's in
common use are two different questions.

I think Robert addressed the latter while your answer implied the former.

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


Re: Summary of threading for experienced non-Python programmers?

2008-03-29 Thread Diez B. Roggisch
Hrvoje Niksic schrieb:
> "Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
> 
>>> systems.  (In theory, file input/output should also be available as
>>> asynchronous code, but async IO is low-level and not available in
>>> Python.)  While threads shouldn't be considered a replacement for
>> I suggest you tell that the twisted-guys. And the ones from the
>> built-in asyncore-module.
> 
> Note that I said "*file* input/output".  Twisted and asyncore are
> about asynchronous socket programming that polls over nonblocking file
> descriptors such as found in socket programming, not about wrapping
> aio(3) and the equivalent Windows APIs.

I admit glossing over the file-input - however this is available on 
posix-systems using the select-module. So if I were in nitpicking-mood, 
your assertion still would be false - albeit having to consider 
platoform dependencies certainly is unfortunate and could be considered 
"missing".

I'm pretty sure though that tiwsted & asynchore don't poll, but instead 
use the select-module. Which at least for unix (and AFAIK for Windows as 
well) is asynchronous - you get notified if data arrives or has been 
transmitted, and otherwise your process sleeps.


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


Re: Summary of threading for experienced non-Python programmers?

2008-03-29 Thread Diez B. Roggisch
> I appreciate the droll sense of humor, but do you mean to
> assert that asyncore.py supports asynchronous disk file I/O?

As I said in an answer to the OP, I somewhat glossed over the "file" and 
just read IO. And under Posix, python *does* support asynchronous IO 
using the select-module. If you can faciliate that using the asynchore 
module I can't say, but the question was if python as whole supported 
async IO out of the box - asyncore & twisted I mention as references of 
implementations using that.

> What that means to me is, you queue a disk read, and there's
> an event flag or something that you can wait for before you
> come back to find the data in your buffer.  (That's how I
> remember it from the old days, when it mattered a little,
> though not enough that I ever remember actually doing it,
> and 20 years later I guess the incentive is even less.)


Which is exactly what select allows you to do. You pass a set of 
file-descriptors and are notified if data arrives or has been 
successfully transmitted.

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


Re: Summary of threading for experienced non-Python programmers?

2008-03-29 Thread Diez B. Roggisch
Paul Rubin schrieb:
> Hrvoje Niksic <[EMAIL PROTECTED]> writes:
>> Note that I said "*file* input/output".  Twisted and asyncore are
>> about asynchronous socket programming that polls over nonblocking file
>> descriptors such as found in socket programming, not about wrapping
>> aio(3) and the equivalent Windows APIs.
> 
> aio is also used for sockets, while twisted and asyncore use select or
> something similar.  That is asynchronous but in a different sense of
> the word.  See also: http://www.kegel.com/c10k.html

In which sense is that different? AFAIK select lets you avoid polling 
and provides notifications (possibly with timeouts) for IO-events. So 
where exactly is the difference? I read TFA, and it does mention that 
select/poll have potential for optimization, but not something that 
disqualified them (or rather select) as being not async.

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


Re: finding euclidean distance,better code?

2008-03-29 Thread Steven D'Aprano
On Sat, 29 Mar 2008 13:06:27 +0100, Roel Schroeven wrote:

> In any case, I replied because your reaction didn't feel all that gentle
> to me; to be honest, it felt rather rude.

Are you new to Usenet? :-)

No offense taken; I hope Robert didn't take offense either, but took the 
little dig in the spirit it was intended.



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


Re: Psyco alternative

2008-03-29 Thread Luis M . González
On 27 mar, 13:14, king kikapu <[EMAIL PROTECTED]> wrote:
> > One reason attention is going to PyPy instead of Psyco...
>
> > Jean-Paul
>
> I had a look at PyPy, it, indeed, have a very long way to go so we can
> consider it an alternative.

To see how it´s going, you can check this out: http://morepypy.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


[OT] Modesty and apologies [Re: Re; finding euclidean distance,better code?]

2008-03-29 Thread Steven D'Aprano
On Sat, 29 Mar 2008 12:43:22 +0200, Hendrik van Rooyen wrote:

> Sorry about having to dispel your illusions, but -
[...]
> Have you noticed that when people say "Sorry.but" they are not
> normally sorry at all?

Heh heh heh.

Reminds me of a quote from the character Spike of "Buffy the Vampire 
Slayer":

[quote]
Yeah, I did a couple Slayers in my time. I don't like to brag. Who am I 
kidding? I love to brag! There was this one Slayer during the Boxer 
Rebellion, and...
[end quote]



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


Python and xml

2008-03-29 Thread Doran, Harold
I am a python neophyte who has used python to parse through text files using 
basic functions and no OOP experience. I have a need to process some xml files 
and from what I am now reading python is the exact tool I need to work through 
this issue.

However, as I read online docs and peruse which books to buy, I am quickly 
becoming overwhelmed with the topic and could use some guidance on how to best 
tackle my task. To frame the issue, here is what I would like to be able to do. 

I have a statistical program that outputs the data into an xml document. My 
goal is to use python to parse this document and output a .txt document or .csv 
document that organizes the results into human-readable rows and columns in a 
nicely formatted manner.

As I read online docs about xml and python, it seems the topic is very big. 
While I am more than happy to invest significant time learning this topic, it 
may be possible to narrow the scope of what I need to know and be able to do in 
order to complete my task.

Any suggestions on how I should proceed and/or fundamentals I need to learn? Is 
anyone aware of simple how to docs or other tutorials that demonstrate this 
kind of task?

Thanks,
Harold


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

Re: Help me on function definition

2008-03-29 Thread castironpi
On Mar 29, 4:18 am, Roel Schroeven <[EMAIL PROTECTED]>
wrote:
> aeneng schreef:
>
>
>
>
>
> > Hello everyone,
>
> > I am just starting to use python in numerical cacluation.
> > I need you to help me to see what's wrong with the following piece of
> > codes, which computes the cross product of two vectors and returns
> > the result. u and v are two 3x1 matrix.
>
> > when I import the function, error message show like this
>  import cross
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> >   File "cross.py", line 8
> >     ppp2=u[2]*v[0]-u[0]*v[2]
> >     ^
> > SyntaxError: invalid syntax
>
> > WHAT IS WRONG WITH MY CODE?
>
> > I appreciate your help.
>
> > ##here is the function definition.
> > ##cross.py##
> > def cross(u,v)
> >     """input two vectors u and v in 3-D space,    
> >        output a cross product of vector w, in column or in row
> > accordingly."""
> >     ppp1,ppp2,ppp3=0.0,0.0,0.0
>
> You forgot the : after def cross(u, v)

No; directional is only signed and unsigned.  

There's a laptop on my computer.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: python-ldap-2.3.4

2008-03-29 Thread Michael Ströder
Find a new release of python-ldap:

   http://python-ldap.sourceforge.net/

python-ldap provides an object-oriented API to access LDAP directory
servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for
that purpose. Additionally it contains modules for other LDAP-related
stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema).


Released 2.3.4 2008-03-29

Changes since 2.3.3:

Modules/
* Fixed seg fault when calling LDAPObject.get_option()
   (see SF#1926507, thanks to Matej)


Released 2.3.3 2008-03-26

Changes since 2.3.2:

Fixed backward-compability when building with OpenLDAP 2.3.x libs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Psyco alternative

2008-03-29 Thread king kikapu
On 29 Μαρ, 16:03, Luis M. González <[EMAIL PROTECTED]> wrote:
> On 27 mar, 13:14, king kikapu <[EMAIL PROTECTED]> wrote:
>
> > > One reason attention is going to PyPy instead of Psyco...
>
> > > Jean-Paul
>
> > I had a look at PyPy, it, indeed, have a very long way to go so we can
> > consider it an alternative.
>
> To see how it´s going, you can check this out:http://morepypy.blogspot.com/

Thanks, that is my source already!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Summary of threading for experienced non-Python programmers?

2008-03-29 Thread Paul Rubin
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
> > I appreciate the droll sense of humor, but do you mean to
> > assert that asyncore.py supports asynchronous disk file I/O?
> 
> As I said in an answer to the OP, I somewhat glossed over the "file"
> and just read IO. And under Posix, python *does* support asynchronous
> IO using the select-module. 

Select does nonblocking i/o but I think Donn is interpreting
"asynchronous i/o" as having a narrower meaning.  See:

  http://www.ibm.com/developerworks/linux/library/l-async/

for some info.  

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


Re: Summary of threading for experienced non-Python programmers?

2008-03-29 Thread Paul Rubin
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
> In which sense is that different? AFAIK select lets you avoid polling
> and provides notifications (possibly with timeouts) for IO-events. So
> where exactly is the difference? I read TFA, and it does mention that
> select/poll have potential for optimization, but not something that
> disqualified them (or rather select) as being not async.

Select blocks until the data is ready, while with AIO the i/o happens
completely in the background and your process gets an interrupt when
the i/o completes.  Also, with select based i/o, usually the kernel
reads data from the external device into a system buffer, and then you
do a read system call that copies the data from the system buffer to
your buffer.  AIO can be set up so the i/o happens directly into your
buffer, avoiding the extra copying.  You can also initiate a bunch of
different i/o events with a single system call, avoiding some context
switches.

http://www.ibm.com/developerworks/linux/library/l-async/

describes select as "asynchronous, blocking" as opposed to AIO which
is asynchronous and nonblocking.  Other descriptions I've seen reserve
"asynchronous i/o" for AIO-like schemes.  It's just a terminological
thing.

The PDP-10 operating systems even let you define your own page fault
handlers, so you could do i/o with something like mmap and not get
delayed in the cases where the page you wanted wasn't in memory.  I
guess that's even more asynchronous than AIO.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding Full Path to Process EXE

2008-03-29 Thread misceverything
On Mar 28, 4:53 pm, Tim Golden <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Hello,
>
> > I would like to write a script that would enumerate all running
> > processes and return the full path to the EXE of each running
> > process.  However, I can't seem to find any good info on how to do
> > this..any help is greatly appreciated.  Thanks.
>
> I have this strange feeling of deja vu. Try this:
>
> http://timgolden.me.uk/python/wmi_cookbook.html#running_processes
>
> (You want the .ExecutablePath or .CommandLine attributes I imagine)
>
> TJG

Thanks, Tim!  I was able to find plenty out there about enumerating
processes, but the .ExecutablePath was exactly what I needed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why prefer != over <> for Python 3.0?

2008-03-29 Thread Jeroen Ruigrok van der Werven
-On [20080329 13:01], Paul Rubin ("http://phr.cx"@NOSPAM.invalid) wrote:
>Yes, what I mean is that some languages (e.g. Ada, Haskell) use /= for
>nonequality.

/= is understandable given how it looks like a digraph for ≠ (U+2260) and I
am guessing that was the intent.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
Cum angelis et pueris, fideles inveniamur. Quis est iste Rex gloriae..?
-- 
http://mail.python.org/mailman/listinfo/python-list

Problem with sqlite

2008-03-29 Thread aiwarrior
class db:
def __init__(self): #constructor
conn = sqlite3.connect('./db.db')
conn.isolation_level = None
self.cursor = conn.cursor()
try:
self.cursor.execute("CREATE TABLE database
(album,filepath)" )
except:
pass

def add_entry( self, eone , etwo ): #Add entry to database
self.cursor.execute( "INSERT INTO database (album,filepath)
VALUES (?,?)", ( eone , etwo ) )
return 1 #TODO: exception handler

def get_mediadb( self, print_db = False ):
self.cursor.execute( 'SELECT * FROM database' )
if (print_db == True):
print self.cursor.fetchall()

def get_value( self, column ):
self.cursor.execute( "SELECT %s FROM database" % column )
for n in self.cursor:
 print n

def destructor(self):
self.cursor.close()

def walking_and_filling(db):
pass


if __name__ == "__main__":
db = db()
#walking_and_filling( db )
for root, dirs, files in os.walk( '''foo_path/''',
topdown=False ):
for name in files:
joined = os.path.join(root, name)
if (name[-3:] == 'mp3' and os.path.isfile( joined ) ):
try:
audio = MP3 (joined, ID3=EasyID3 )
print (audio['album'])
db.add_entry( joined, audio['album'] )
except:
pass
db.get_mediadb( print_db=True )


When i execute this the database doesn't get filled with anything and
the program stays running in memory for ever.
The print statement is just a Unicode string that would get to the
database if i stated it in the add_entry function as a constant
string. It's a really weird problem that i dont seem to understand why
it's working out this way.

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


Re: Why prefer != over <> for Python 3.0?

2008-03-29 Thread Lie
On Mar 29, 5:55 pm, [EMAIL PROTECTED] wrote:
> I don't know if this is the right place to discuss the death of <> in
> Python 3.0, or if there have been any meaningful discussions posted
> before (hard to search google with '<>' keyword), but why would anyone
> prefer the comparison operator != over <>???
>
> I've written an article about it to try and save this nice "is not
> equal" operator, located athttp://dewitters.koonsolo.com/python_neq.html
>
> Please set it straight in 3.0, and if not, convince me with a good
> reason of doing so, so that I can live with it and don't have to spend
> the rest of my life in 2.x ;).


All pretty clear hey? But now comes the catch, there exists an
operator !=... but what does it mean? Well, that one is pretty easy,
of course ! must be an operator of its own (in non-python languages
meaning 'not'), and it resembles the fancy assignment statement
<...snip...>

When I started to learn python I came across an operator <>. What
could it mean? Well, you don't have to think long about it. You're
only reference are the < and > operators (with meanings the same as in
mathematics or plain written language, any non programmer would
understand this). So <> must mean "smaller or larger", or not-equals,
no question about that. It couldn't possible be mistaken as an
assignment operator. You just have to love a language that uses
operators with clear and obvious meaning.


You're forcing your argument too much, both != and <> are NOT standard
mathematics operators -- the standard not-equal operator is >< -- and
I can assure you that both != and <> won't be comprehensible to non-
programmers. And I'm not sure if anyone could have mistaken != for
assignment operator because they're used in completely different
places (which is the reason why some languages can use the same
operator for = (assignment) and == (comparison)). = is always used in
a line by itself while != is always used in places where a
'condition' (a.k.a. 'expression') is required.

The problem you stated may be a problem in C/C++ (if C/C++ do have
both != and <>, fortunately they only have !=) because C/C++'s =
(assignment) is an operator and operators always return a value but in
Python = (assignment) is a statement and can't return a value so "if a
= b:" always raise an error.

Since != operator can only be used in places where a
'condition'/'expression' is required and never in a line by itself as
a statement, it could never be mistaken as an assignment (which is a
statement).

The problem just don't exist in Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: deleting a line from a file

2008-03-29 Thread Paddy
On Mar 29, 11:13 am, eMko <[EMAIL PROTECTED]> wrote:
> Hello,
>
> In Perl, using a Tie::File module I can easily and comfortably delete
> a line from the middle of a text file:
>
>   my @file;
>   open(DATA, "+<:encoding(utf8):raw" , "file.txt") or return 0;
>   tie @file, 'Tie::File', \*DATA or return 0;
>   splice(@file, $_[0], 1);
>   untie @file;
>   close DATA;
>
> (when the first argument of the function ($_[0]) is a number of the
> line which should be deleted)
>
> Is there some easy way how to delete a line from a middle of a file in
> Python?
>
> Thanks a lot
> eMko

Module fileinput has\;

Optional in-place filtering: if the keyword argument inplace=1 is
passed to input() or to the FileInput constructor, the file is moved
to a backup file and standard output is directed to the input file (if
a file of the same name as the backup file already exists, it will be
replaced silently). This makes it possible to write a filter that
rewrites its input file in place. If the keyword argument
backup='.' is also given, it specifies the extension
for the backup file, and the backup file remains around; by default,
the extension is '.bak' and it is deleted when the output file is
closed. In-place filtering is disabled when standard input is read.


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


Re: Problem with sqlite

2008-03-29 Thread Duncan Booth
aiwarrior <[EMAIL PROTECTED]> wrote:

> When i execute this the database doesn't get filled with anything and
> the program stays running in memory for ever.

That's odd, when I execute the code you posted I just get "NameError: 
global name 'sqlite3' is not defined". You should always try to post the 
complete actual code you are using, not just some random part of it.

> The print statement is just a Unicode string that would get to the
> database if i stated it in the add_entry function as a constant
> string. It's a really weird problem that i dont seem to understand why
> it's working out this way.
> 
Are you absolutely certain of that? If you use print to try to debug the 
value of an object you should usually use repr:


print repr(audio['album'])

What MP3 library are you using?

You have forced a commit after every insert. This slows down sqlite A LOT. 
I get about 400 insertions each minute with your code (just inserting fixed 
strings) but if I remove the conn.isolation_level assignment and add a 
single commit at the end I get in excessive of 2 per second. Are you 
sure you just didn't wait long enough?
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why prefer != over <> for Python 3.0?

2008-03-29 Thread Duncan Booth
Lie <[EMAIL PROTECTED]> wrote:

> You're forcing your argument too much, both != and <> are NOT standard
> mathematics operators -- the standard not-equal operator is >< -- and
> I can assure you that both != and <> won't be comprehensible to non-
> programmers.

My maths may be a bit rusty, but I always thought that the standard not-
equal operator was like an = sign but with a diagonal slash through it as 
displayed when you do:

   print u'\u2260'

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


Licensing

2008-03-29 Thread DS
I'm pretty sure this is the wrong place to ask, but I'm hoping someone 
will point me in the right direction.

I'm getting ready to publish a first open-source project written in 
python.  I am planning to use GPLas the license.  However, in my code, 
there is a function that I like from Python Cookbook.  I would like to 
use it, although I could certainly write a less elegant version that 
would do the same thing.

So, my options appear to be:
1.   Don't use it.
2.   Use it with no comment -- that doesn't seem right.
3.   Use it with remarks in the code that acknowledge the source.
4.   Provide a separate licensing page for that function
   along with the GPL for my code.

What is the appropriate course of action here?  I'm thinking #3 is 
probably ok.  How do others deal with this in an honorable way?  In the 
book, it appears that they are saying they don't really care unless 
there is some massive use.

Thanks



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


Re: Problem with sqlite

2008-03-29 Thread Gerhard Häring
Ok, I'll review your code.

aiwarrior wrote:
> class db:
> def __init__(self): #constructor
> conn = sqlite3.connect('./db.db')
> conn.isolation_level = None

Autocommit mode is mostly for newbies who forget to call commit.
Unfortunately, newbiews find enough other ways to shoot themselves in
the foot. So, in retrospect, maybe I should not have added that feature
to pysqlite ;-)

> self.cursor = conn.cursor()
> try:
> self.cursor.execute("CREATE TABLE database
> (album,filepath)" )
> except:
> pass

try: except: pass without catching *specific* exceptions is generally a
very bad idea. If you're doing something stupid, or another error
happens than the one you want to ignore, you will never know this way.

> def add_entry( self, eone , etwo ): #Add entry to database
> self.cursor.execute( "INSERT INTO database (album,filepath)
> VALUES (?,?)", ( eone , etwo ) )
> return 1 #TODO: exception handler
> 
> def get_mediadb( self, print_db = False ):
> self.cursor.execute( 'SELECT * FROM database' )
> if (print_db == True):
> print self.cursor.fetchall()

The if clause can be written as just "if print_db:".

> def get_value( self, column ):
> self.cursor.execute( "SELECT %s FROM database" % column )
> for n in self.cursor:
>  print n
> 
> def destructor(self):
> self.cursor.close()

Just FYI, Python's "destructor" method is called "__del__", not
"destructor".

> def walking_and_filling(db):
> pass
> 
> 
> if __name__ == "__main__":
> db = db()
> #walking_and_filling( db )
> for root, dirs, files in os.walk( '''foo_path/''',
> topdown=False ):
> for name in files:
> joined = os.path.join(root, name)
> if (name[-3:] == 'mp3' and os.path.isfile( joined ) ):
> try:
> audio = MP3 (joined, ID3=EasyID3 )
> print (audio['album'])
> db.add_entry( joined, audio['album'] )
> except:
> pass

Now, this try: except: pass is most probably hiding the real error That
leads to the insert failing. Because you just ignored any errors, you
will never now what exactly went wrong here.

> db.get_mediadb( print_db=True )
> 
> 
> When i execute this the database doesn't get filled with anything and
> the program stays running in memory for ever. [...]

HTH,

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


problem with logic in reading a binary file

2008-03-29 Thread [EMAIL PROTECTED]
Hello,

I am having trouble writing the code to read a binary string.  I would
like to extract the values for use in a calculation.

Any help would be great.

Here is my function that takes in a string.

def parseSequence(data, start):

group_num = data[start:start+2]
element_num = data[start+2:start+4]
vl_field = data[start+4:start+8]
length = struct.unpack('hh', vl_field)[0]
value = data[start+8:(start+8+length)]
pos = start+8+length
element = (group_num+element_num)

if element == '\xfe\xff\x00\xe0':
data = value

while start < length:
group_num = data[start:start+2]
element_num = data[start+2:start+4]
vl_field = data[start+4:start+8]
length = struct.unpack('hh', vl_field)[0]
value = data[start+8:(start+8+length)]
start = start+8+length
element = (group_num+element_num)

if element == '\xfe\xff\x00\xe0':
data = value

while start < length:
group_num = data[start:start+2]
element_num = data[start+2:start+4]
vl_field = data[start+4:start+8]
length = struct.unpack('hh', vl_field)[0]
value = data[start+8:(start+8+length)]
start = start+8+length
element = (group_num+element_num)
return element, start, value

else:
return element, start, value

else:
return  element, pos, value

And, here is a sample string (I have split up and indented for
readability).  There is an identifier (\xfe\xff\x00\xe0) followed by
the length of the nested values.


'\xfe\xff\x00\xe0\x18\x02\x00\x00 -length=536
 \n0q\x00\x02\x00\x00\x001
 \n0x\x00\x02\x00\x00\x0010
 \n0\x80\x00\x02\x00\x00\x004
 \n0\xa0\x00\x02\x00\x00\x000
 \x0c0\x04\x00\xe8\x01\x00\x00
 \xfe\xff\x00\xe0p\x00\x00\x00 -length=112
  \n0\x82\x002\x00\x00\x0042.9068704277562\\-392.3545926477\
\189.182112099444
  \n0\x84\x00\x0c\x00\x00\x008.9617062e-1
  \n0\x86\x00\x10\x00\x00\x00127.378510918301
  \x0c0\x06\x00\x02\x00\x00\x001
 \xfe\xff\x00\xe0p\x00\x00\x00 -length=112
  \n0\x82\x002\x00\x00\x0042.9068704277562\\-392.3545926477\
\189.182112099444
  \n0\x84\x00\x0c\x00\x00\x001.629998e-1
  \n0\x86\x00\x10\x00\x00\x0023.159729257873
  \x0c0\x06\x00\x02\x00\x00\x004
 \xfe\xff\x00\xe0t\x00\x00\x00  -length=116
  \n0\x82\x002\x00\x00\x0042.9068704277562\\-392.3545926477\
\189.182112099444
  \n0\x84\x00\x10\x00\x00\x001.26285318894435
  \n0\x86\x00\x10\x00\x00\x00227.690980638769
  \x0c0\x06\x00\x02\x00\x00\x003
 \xfe\xff\x00\xe0t\x00\x00\x00  -length=116
  \n0\x82\x002\x00\x00\x0042.9068704277562\\-392.3545926477\
\189.182112099444
  \n0\x84\x00\x10\x00\x00\x001.52797639111557
  \n0\x86\x00\x10\x00\x00\x00263.433384670643
  \x0c0\x06\x00\x02\x00\x00\x002 ')


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


Re: How to insert multiple rows in SQLite Dbase

2008-03-29 Thread Gerhard Häring
Gabriel Genellina wrote:
> [...]
> and execute:
> cur.executemany("insert into log (IP, EntryDate, Requestt, ErrorCode)
> values (:ip, :date, :request, :errorcode)", values)

It's probably worth mentioning that pysqlite's executemany() accepts
anything iterable for its parameter. So you don't need to build a list
beforehand to enjoy the performance boost of executemany().

The deluxe version with generators could look like this:

def parse_logfile():
logf = open(...)
for line in logf:
if ...:
  row = (value1, value2, value3)
  yield row
logf.close()

...

cur.executemany("insert into ... values (c1, c2, c3)", parse_logfile())

-- Gerhard

PS: pysqlite internally has a statement cache since verson 2.2, so
multiple execute() calls are almost as fast as executemany().
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with logic in reading a binary file

2008-03-29 Thread Gary Herron
[EMAIL PROTECTED] wrote:
> Hello,
>
> I am having trouble writing the code to read a binary string.  I would
> like to extract the values for use in a calculation.
>
> Any help would be great.
>   

Without having looked at your code an any detail, may I humbly suggest 
that you throw it all out and use the struct module:

http://docs.python.org/lib/module-struct.html

It is meant to solve this kind of problem, and it is quite easy to use.

Gary Herron

> Here is my function that takes in a string.
>
> def parseSequence(data, start):
>
> group_num = data[start:start+2]
> element_num = data[start+2:start+4]
> vl_field = data[start+4:start+8]
> length = struct.unpack('hh', vl_field)[0]
> value = data[start+8:(start+8+length)]
> pos = start+8+length
> element = (group_num+element_num)
>
> if element == '\xfe\xff\x00\xe0':
> data = value
>
> while start < length:
> group_num = data[start:start+2]
> element_num = data[start+2:start+4]
> vl_field = data[start+4:start+8]
> length = struct.unpack('hh', vl_field)[0]
> value = data[start+8:(start+8+length)]
> start = start+8+length
> element = (group_num+element_num)
>
> if element == '\xfe\xff\x00\xe0':
> data = value
>
> while start < length:
> group_num = data[start:start+2]
> element_num = data[start+2:start+4]
> vl_field = data[start+4:start+8]
> length = struct.unpack('hh', vl_field)[0]
> value = data[start+8:(start+8+length)]
> start = start+8+length
> element = (group_num+element_num)
> return element, start, value
>
> else:
> return element, start, value
>
> else:
> return  element, pos, value
>
> And, here is a sample string (I have split up and indented for
> readability).  There is an identifier (\xfe\xff\x00\xe0) followed by
> the length of the nested values.
>
>
> '\xfe\xff\x00\xe0\x18\x02\x00\x00 -length=536
>  \n0q\x00\x02\x00\x00\x001
>  \n0x\x00\x02\x00\x00\x0010
>  \n0\x80\x00\x02\x00\x00\x004
>  \n0\xa0\x00\x02\x00\x00\x000
>  \x0c0\x04\x00\xe8\x01\x00\x00
>  \xfe\xff\x00\xe0p\x00\x00\x00 -length=112
>   \n0\x82\x002\x00\x00\x0042.9068704277562\\-392.3545926477\
> \189.182112099444
>   \n0\x84\x00\x0c\x00\x00\x008.9617062e-1
>   \n0\x86\x00\x10\x00\x00\x00127.378510918301
>   \x0c0\x06\x00\x02\x00\x00\x001
>  \xfe\xff\x00\xe0p\x00\x00\x00 -length=112
>   \n0\x82\x002\x00\x00\x0042.9068704277562\\-392.3545926477\
> \189.182112099444
>   \n0\x84\x00\x0c\x00\x00\x001.629998e-1
>   \n0\x86\x00\x10\x00\x00\x0023.159729257873
>   \x0c0\x06\x00\x02\x00\x00\x004
>  \xfe\xff\x00\xe0t\x00\x00\x00  -length=116
>   \n0\x82\x002\x00\x00\x0042.9068704277562\\-392.3545926477\
> \189.182112099444
>   \n0\x84\x00\x10\x00\x00\x001.26285318894435
>   \n0\x86\x00\x10\x00\x00\x00227.690980638769
>   \x0c0\x06\x00\x02\x00\x00\x003
>  \xfe\xff\x00\xe0t\x00\x00\x00  -length=116
>   \n0\x82\x002\x00\x00\x0042.9068704277562\\-392.3545926477\
> \189.182112099444
>   \n0\x84\x00\x10\x00\x00\x001.52797639111557
>   \n0\x86\x00\x10\x00\x00\x00263.433384670643
>   \x0c0\x06\x00\x02\x00\x00\x002 ')
>
>
>   

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


Re: Why prefer != over <> for Python 3.0?

2008-03-29 Thread Lie
On Mar 30, 1:24 am, Duncan Booth <[EMAIL PROTECTED]> wrote:
> Lie <[EMAIL PROTECTED]> wrote:
> > You're forcing your argument too much, both != and <> are NOT standard
> > mathematics operators -- the standard not-equal operator is >< -- and
> > I can assure you that both != and <> won't be comprehensible to non-
> > programmers.
>
> My maths may be a bit rusty, but I always thought that the standard not-
> equal operator was like an = sign but with a diagonal slash through it as
> displayed when you do:
>
>print u'\u2260'

Ah yes, that is also used (I completely forgot about that one, my
math's aren't that sharp anymore) and I think it's used more
frequently than ><. Some books use >< while most use ≠, but my
argument was that no math book use != or <> (except in math for
programmers).
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Why prefer != over <> for Python 3.0?

2008-03-29 Thread Michael Wieher
to me it seems simple.

C uses !=

why does C use !=  because its kind of hard to type the "equal with a
slash"

so if python is supposed to be a simple and easy to use language, use the
simple and easy to understand, standard 'not-equal' operator... Idk, maybe
there's more to it but simple is as simple does, sir

2008/3/29 Lie <[EMAIL PROTECTED]>:

> On Mar 30, 1:24 am, Duncan Booth <[EMAIL PROTECTED]> wrote:
> > Lie <[EMAIL PROTECTED]> wrote:
> > > You're forcing your argument too much, both != and <> are NOT standard
> > > mathematics operators -- the standard not-equal operator is >< -- and
> > > I can assure you that both != and <> won't be comprehensible to non-
> > > programmers.
> >
> > My maths may be a bit rusty, but I always thought that the standard not-
> > equal operator was like an = sign but with a diagonal slash through it
> as
> > displayed when you do:
> >
> >print u'\u2260'
>
> Ah yes, that is also used (I completely forgot about that one, my
> math's aren't that sharp anymore) and I think it's used more
> frequently than ><. Some books use >< while most use ≠, but my
> argument was that no math book use != or <> (except in math for
> programmers).
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Why prefer != over <> for Python 3.0?

2008-03-29 Thread Carl Banks
On Mar 29, 6:55 am, [EMAIL PROTECTED] wrote:
> why would anyone

Questions that begin with the words "why would anyone" are almost
always betray an arrogance about their own beliefs and an ignorance
(or feigning ignorance) of human nature.

Wiser folks know better than to phrase this question so judgmentally.


> Please set it straight in 3.0, and if not, convince me with a good
> reason of doing so, so that I can live with it and don't have to spend
> the rest of my life in 2.x ;).

1. It's not going to change in Python 3.0.

2. It's a silly thing to care so much about that you will avoid using
a langauge because of it.


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


Problem with python

2008-03-29 Thread mac_the_scotte
Hi there.
I downloaded python a couple of days ago from the official site and
have started writing simple programs in the python gui (this being my
first attempt at programming ever). The only thing is when I write
python code in a text editor and save it as a .py file, when I double
click it all that happens is a black box flashes up on the screen, but
nothing else!?

At first I thought this was because I had only written a hello world
program, and that the box had displayed "hello world" and then closed.
But then I wrote a program requiring user input and the same thing
happened... Am I doing something wrong?

Thanks in advance for any help!

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


Re: Problem with python

2008-03-29 Thread Lie
On Mar 30, 2:57 am, [EMAIL PROTECTED] wrote:
> Hi there.
> I downloaded python a couple of days ago from the official site and
> have started writing simple programs in the python gui (this being my
> first attempt at programming ever). The only thing is when I write
> python code in a text editor and save it as a .py file, when I double
> click it all that happens is a black box flashes up on the screen, but
> nothing else!?
>
> At first I thought this was because I had only written a hello world
> program, and that the box had displayed "hello world" and then closed.
> But then I wrote a program requiring user input and the same thing
> happened... Am I doing something wrong?
>
> Thanks in advance for any help!
>
> //mac

open the program in IDLE (or any other Python IDEs). I'm guessing that
your program is printing a traceback (error) when trying to get input
that's why it immediately closes itself.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me on function definition

2008-03-29 Thread Terry Reedy

"aeneng" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| def cross(u,v)
|"""input two vectors u and v in 3-D space,
|   output a cross product of vector w, in column or in row
| accordingly."""
|ppp1,ppp2,ppp3=0.0,0.0,0.0

To add to other comments, remove above which is complete waste.



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


Re: Error message from function definition

2008-03-29 Thread Terry Reedy
Please do not post same question twice.



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


Re: Problem with sqlite

2008-03-29 Thread aiwarrior
On Mar 29, 6:41 pm, Gerhard Häring <[EMAIL PROTECTED]> wrote:
> Ok, I'll review your code.
>
> aiwarrior wrote:
> > class db:
> > def __init__(self): #constructor
> > conn = sqlite3.connect('./db.db')
> > conn.isolation_level = None
>
> Autocommit mode is mostly for newbies who forget to call commit.
> Unfortunately, newbiews find enough other ways to shoot themselves in
> the foot. So, in retrospect, maybe I should not have added that feature
> to pysqlite ;-)
>
> > self.cursor = conn.cursor()
> > try:
> > self.cursor.execute("CREATE TABLE database
> > (album,filepath)" )
> > except:
> > pass
>
> try: except: pass without catching *specific* exceptions is generally a
> very bad idea. If you're doing something stupid, or another error
> happens than the one you want to ignore, you will never know this way.
>
> > def add_entry( self, eone , etwo ): #Add entry to database
> > self.cursor.execute( "INSERT INTO database (album,filepath)
> > VALUES (?,?)", ( eone , etwo ) )
> > return 1 #TODO: exception handler
>
> > def get_mediadb( self, print_db = False ):
> > self.cursor.execute( 'SELECT * FROM database' )
> > if (print_db == True):
> > print self.cursor.fetchall()
>
> The if clause can be written as just "if print_db:".
>
> > def get_value( self, column ):
> > self.cursor.execute( "SELECT %s FROM database" % column )
> > for n in self.cursor:
> >  print n
>
> > def destructor(self):
> > self.cursor.close()
>
> Just FYI, Python's "destructor" method is called "__del__", not
> "destructor".
>
>
>
> > def walking_and_filling(db):
> > pass
>
> > if __name__ == "__main__":
> > db = db()
> > #walking_and_filling( db )
> > for root, dirs, files in os.walk( '''foo_path/''',
> > topdown=False ):
> > for name in files:
> > joined = os.path.join(root, name)
> > if (name[-3:] == 'mp3' and os.path.isfile( joined ) ):
> > try:
> > audio = MP3 (joined, ID3=EasyID3 )
> > print (audio['album'])
> > db.add_entry( joined, audio['album'] )
> > except:
> > pass
>
> Now, this try: except: pass is most probably hiding the real error That
> leads to the insert failing. Because you just ignored any errors, you
> will never now what exactly went wrong here.
>
> > db.get_mediadb( print_db=True )
>
> > When i execute this the database doesn't get filled with anything and
> > the program stays running in memory for ever. [...]
>
> HTH,
>
> -- Gerhard

I'm sorry about not saying showing the libraries. It was not on
purpose.

import os
import sqlite3
from mutagen.easyid3 import EasyID3
from mutagen.mp3 import MP3


##def tree(path):
##node = ()
##for node in os.listdir( path ):
##if( os.path.isdir( path + node )):
##tree(path+node)
##return path

class db:
def __init__(self): #constructor
conn = sqlite3.connect( './db.db' )
conn.isolation_level = None
self.cursor = conn.cursor()
try:
self.cursor.execute( "CREATE TABLE database
(album,filepath)" )
except:
pass

def add_entry( self, eone , etwo ): #Add entry to database
self.cursor.execute( "INSERT INTO database (album,filepath)
VALUES (?,?)", ( eone , etwo ) )
return 1 #TODO: exception handler

def get_mediadb( self, print_db = False ):
self.cursor.execute( 'SELECT * FROM database' )
if (print_db == True):
print self.cursor.fetchall()

def get_value( self, column ):
self.cursor.execute( "SELECT %s FROM database" % column )
for n in self.cursor:
 print n

def destructor( self ):
self.cursor.close()

def walking_and_filling( db ):
pass


if __name__ == "__main__":
db = db()
#walking_and_filling( db )
for root, dirs, files in os.walk( '''foo_path/''',
topdown=False ):
for name in files:
joined = os.path.join(root, name)
if (name[-3:] == 'mp3' and os.path.isfile( joined ) ):
try:
audio = MP3 (joined, ID3=EasyID3 )
print (audio['album'])
db.add_entry( joined, audio['album'] )
except:
pass
db.get_mediadb( print_db=True )

This is all the code. Some of that try pass code is just something i
glued to create a clean slate database file
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding Full Path to Process EXE

2008-03-29 Thread Michel Claveau - NoSpam SVP ; merci
Hi!

Warning : WMI give the "command-line" of a process only for windows > 
2000

@-salutations

Michel Claveau

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


Buffer Overflow with Python 2.5 on Vista in import site

2008-03-29 Thread Fuzzyman
A very odd error with Python 2.5 (both 2.5.1 and 2.5.2 from the
official msi installers and running on Vista under Parallels on the
Mac).

'import site' fails due to a string in sys.path that contains a huge
number of null bytes.

The error is actually in ntpath - I adjusted it to print the paths it
is working with and a string on encountering the bad path.

Because 'import site' is executed twice with the following code I
snipped the first dump and only print the one with the traceback:

C:\Users\Administrator>python -c "import site"

[snip]

'import site' failed; use -v for traceback
set(['c:\\python25\\lib\\plat-win', 'c:\\windows\\system32\
\python25.zip', 'c:\\
python25', 'c:\\python25\\lib\\lib-tk', 'c:\\users\\administrator', 'c:
\\python2
5\\dlls', 'c:\\python25\\lib', 'c:\\python25\\lib\\site-packages'])

  BAD PATH  
"C:\\Python25\\lib\\site-packages\\\x00\x05\x16\x07\x00\x02\x00\x00Mac
OS X
   \x00\x02\x00\x00\x00\t\x00\x00\x002\x00\x00\x0e
\xb0\x00\x00\x00\x02\x00\x00\x
0e\xe2\x00\x00\x01\x1e
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x
00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00AT
TR\x00\x00\x00!\x00\x00\x0e\xe2\x00\x00\x00\x98\x00\x00\x00
\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x98\x00\x00\x00
\x00\x0
0\x15com.macromates.caret\x00x\x9c\xab\xe6R\x00\x82\xe4\xfc\x9c
\xd2\xdc<\x05[\x0
5\x03k0?'3/\x15\xc2\xab\x05\x00\x8b\x99\x08\x1d
\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\

[snip a load of null bytes]

x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x1eThis resource
fork intent
ionally left blank
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0

[snip a load more null bytes]

0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0
0\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x1e
\x00\x00\x00\x00\x0
0\x00\x00\x00\x00\x1c\x00\x1e\xff\xff"
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python25\lib\site.py", line 417, in 
main()
  File "C:\Python25\lib\site.py", line 402, in main
paths_in_sys = addsitepackages(paths_in_sys)
  File "C:\Python25\lib\site.py", line 206, in addsitepackages
addsitedir(sitedir, known_paths)
  File "C:\Python25\lib\site.py", line 169, in addsitedir
addpackage(sitedir, name, known_paths)
  File "C:\Python25\lib\site.py", line 141, in addpackage
dir, dircase = makepath(sitedir, line)
  File "C:\Python25\lib\site.py", line 67, in makepath
dir = os.path.abspath(os.path.join(*paths))
  File "C:\Python25\lib\ntpath.py", line 500, in abspath
path = _getfullpathname(path)
TypeError: _getfullpathname() argument 1 must be (buffer overflow),
not str


Odd. Anyone got any clues?

Michael Foord
http://www.ironpythoninaction.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with sqlite

2008-03-29 Thread Tzury Bar Yochay
after executing insert
do conection.commit()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why prefer != over <> for Python 3.0?

2008-03-29 Thread Dan Bishop
On Mar 29, 6:08 am, Paul Rubin  wrote:
> [EMAIL PROTECTED] writes:
> > I don't know if this is the right place to discuss the death of <> in
> > Python 3.0, or if there have been any meaningful discussions posted
> > before (hard to search google with '<>' keyword), but why would anyone
> > prefer the comparison operator != over <>???
>
> I doubt anyone cares.  Python probably chose != because it's what C uses.

MOST of Python's operators are based on C's.  Consider, for example,
the bitwise operators | ^ & << >> ~ and the compound assignment
operators += -= etc.

The exceptions are ** (from Fortran), //, and the logical operators.
-- 
http://mail.python.org/mailman/listinfo/python-list


What motivates all unpaid volunteers at Pycon?

2008-03-29 Thread [EMAIL PROTECTED]
I was impressed and humbled by all the unpaid volunteers at Pycon.

I was wondering what motivated so many people to give so much to the
Python community.

(I have my guesses but I'd rather listen than assume I know.)

Any ideas?

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


regarding xml elements

2008-03-29 Thread Raj kumar
Hi,
I have an xml file in my application,
I have created an element using 
Example goes like this.

document.createElement("abc")
and i appeneded it by using append() method.
But how i can reflect this change to my xml file?
 and one more thing is i want to create element with some other parameters
like.

  

and i have m and n values as strings with me.
can anybody help me to create this element and write it to the existing xml 
file 
as a child of an existing element?

Thanks in advance..

Raj..




  Forgot the famous last words? Access your message archive online at 
http://in.messenger.yahoo.com/webmessengerpromo.php-- 
http://mail.python.org/mailman/listinfo/python-list

cProfile for python 2.4

2008-03-29 Thread David Pratt
I'd like to compile cProfile for python 2.4. Where can I get it to do 
this? I realize it is part of python 2.5. Many thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


New python forum on CodeGuru!

2008-03-29 Thread Robert Dailey
Hi,

I managed to convince the CodeGuru forum administrator to add a Python
discussion forum to the community. It's a great success for me, as I really
love CodeGuru and their forums. I really encourage everyone to use it, as it
will be a great asset to the Python community. The forum will be removed if
it doesn't generate enough traffic in the next few months, so please help
support it by generating discussion there instead of on the mailing list.
You can visit the following link to get to the forum:
http://www.codeguru.com/forum/forumdisplay.php?f=95
-- 
http://mail.python.org/mailman/listinfo/python-list

Serial port error statistics - any comparable data?

2008-03-29 Thread Hendrik van Rooyen
Hi,

I have been doing some tests on a device that
we are thinking of incorporating into a product, 
and I have seen that reception on a serial port
at 115200 baud over about six metres of RS-232
cable makes mistakes, to the order of 125 lines
with errors in them out of approximately 18.4
million lines of 65 or so chars - about one errored
line in 147000, or one error character in 95 million.

The PC that is making the errors is a 64 bit dual
core AMD machine running at 2 Gig, and I am 
running stock standard Open Suse 10.3 with 
the supplied Python 2.5.

What kind of bothers me is the nature of the errors -
I seem to get only missing characters, as if an 
interrupt was missed.  There are no munged characters
as one would expect if the errors were bit related.

Has anyone else seen anything like this, and am I worrying
needlessly?

I realise that my production protocols will easily handle
this almost non existent level of error - but if this were in
microcontroller code that I had written myself, I would
suspect that I was spending too long in some critical
section of code.

- Hendrik



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


tkinter coordinates, conversion

2008-03-29 Thread Ron Provost
Is there any way in tkinter to convert between coordinate systems?  
Specifically, I'm refering to the canvas.  I'm getting x and y's back in mouse 
events and I would like to convert them back to inches 'i', centemeters 'c', 
millimeters 'm' or points 'p'.  Which I wish to use to provided information 
back to the user.

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

Re: cProfile for python 2.4

2008-03-29 Thread ptrk
On Mar 28, 3:50 pm, David Pratt <[EMAIL PROTECTED]> wrote:
> I'd like to compile cProfile for python 2.4. Where can I get it to do
> this? I realize it is part of python 2.5. Many thanks.

can you use cProfile's predecessor, profile?

http://docs.python.org/lib/module-profile.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Serial port error statistics - any comparable data?

2008-03-29 Thread Diez B. Roggisch
Hendrik van Rooyen schrieb:
> Hi,
> 
> I have been doing some tests on a device that
> we are thinking of incorporating into a product, 
> and I have seen that reception on a serial port
> at 115200 baud over about six metres of RS-232
> cable makes mistakes, to the order of 125 lines
> with errors in them out of approximately 18.4
> million lines of 65 or so chars - about one errored
> line in 147000, or one error character in 95 million.
> 
> The PC that is making the errors is a 64 bit dual
> core AMD machine running at 2 Gig, and I am 
> running stock standard Open Suse 10.3 with 
> the supplied Python 2.5.
> 
> What kind of bothers me is the nature of the errors -
> I seem to get only missing characters, as if an 
> interrupt was missed.  There are no munged characters
> as one would expect if the errors were bit related.
> 
> Has anyone else seen anything like this, and am I worrying
> needlessly?
> 
> I realise that my production protocols will easily handle
> this almost non existent level of error - but if this were in
> microcontroller code that I had written myself, I would
> suspect that I was spending too long in some critical
> section of code.

RS232 is unfortunately as bad as a "protocol" as it can get. I've used 
it for communication with a microcontroller for just a few bytes every 
second. And it failed miserably, so I needed to implement a protocol on 
top of it.

The machine spec is totally irrelevant - what is interesting is the 
serial hardware you use. Are you by any chance using a 
serial2usb-converter? I had nothing but troubles with these.

if you have the chance, try & attach a machine with legacy rs232 port, 
and see if the errors still remain.

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


wxPython listctrl

2008-03-29 Thread Gif
I was wondering if there is a way to extract an icon from a file
(executable) and then add it in a listctrl. I also 'd like to know if
i can shorten the icon in order to fit in a listctrl item.
I've managed to get the icon from an icon file and add t as a listctrl
item but it remains 32x32.

code:
images = ['LimeWire.ico']

self.il = wx.ImageList(18, 10)
self.il.Add(wx.Bitmap(images[0]))

#This below raises an error saying that no handle was found for that
image
#self.ib = wx.IconBundle()
#self.ib.AddIconFromFile(r'LimeWire.exe', wx.BITMAP_TYPE_ANY)

self.listView1.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
self.listView1.SetItemImage(0, 0)
-- 
http://mail.python.org/mailman/listinfo/python-list


Python vs. Perl, which is better to learn?

2008-03-29 Thread linda vogele
4332951-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python and xml

2008-03-29 Thread Konstantin Veretennicov
On Sat, Mar 29, 2008 at 3:57 PM, Doran, Harold <[EMAIL PROTECTED]> wrote:

>  I am a python neophyte who has used python to parse through text files
> using basic functions and no OOP experience. I have a need to process some
> xml files and from what I am now reading python is the exact tool I need to
> work through this issue.
>
> However, as I read online docs and peruse which books to buy, I am quickly
> becoming overwhelmed with the topic and could use some guidance on how to
> best tackle my task.
>
> You can start with this basic example (requires Python 2.5):

spam.xml:

  Dinsdale (Face the Press)
  The Spanish Inquisition
  Deja vu
  The Buzz Aldrin Show
  Live From the Grill-O-Mat Snack Bar
  It's a Living
  The Attila the Hun Show
  Archaeology Today
  How to Recognize Different Parts of the
Body
  Scott of the Antarctic
  How Not to Be Seen
  Spam
  Royal Episode 13


spam.py:
from xml.etree.ElementTree import ElementTree as ET

et = ET(file='spam.xml')
for episode in et.findall('episode'):
print episode.attrib['number'] + ':', '"' + episode.text + '"'


Use standard csv module if you want to produce csv ouput (
http://docs.python.org/lib/module-csv.html).

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

Re: What motivates all unpaid volunteers at Pycon?

2008-03-29 Thread Tim Chase
> I was wondering what motivated so many people to give so much to the
> Python community.

fear, surprise, ruthless efficiency, an almost fanatical devotion 
to the BDFL, and nice red uniforms.

Oh...

-tkc



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


Re: Licensing

2008-03-29 Thread Scott David Daniels
DS wrote:
> I'm getting ready to publish a first open-source project written in 
> python.  I am planning to use GPL as the license.  However, in my code, 
> there is a function that I like from Python Cookbook
> So, my options appear to be:
> 1.   Don't use it.
> 2.   Use it with no comment -- that doesn't seem right.
> 3.   Use it with remarks in the code that acknowledge the source.
I vote for this.  If you got it of the web site, include a url.  If you
went for the book, I'd prefer crediting both, but at least give enough
so the interested reader can get back to some version of "the original."

> 4.   Provide a separate licensing page for that function
>   along with the GPL for my code.
> What is the appropriate course of action here?  I'm thinking #3 is 
> probably ok.  How do others deal with this in an honorable way?
As the author of several of those recipes, I definitely expect others
to use them.  I'd hate to slow them up by requiring them to ask
permission, but would appreciate an acknowledgment.

-Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Licensing

2008-03-29 Thread DS
Scott David Daniels wrote:
> DS wrote:
>   
>> I'm getting ready to publish a first open-source project written in 
>> python.  I am planning to use GPL as the license.  However, in my code, 
>> there is a function that I like from Python Cookbook
>> So, my options appear to be:
>> 1.   Don't use it.
>> 2.   Use it with no comment -- that doesn't seem right.
>> 3.   Use it with remarks in the code that acknowledge the source.
>> 
> I vote for this.  If you got it of the web site, include a url.  If you
> went for the book, I'd prefer crediting both, but at least give enough
> so the interested reader can get back to some version of "the original."
>
>   
>> 4.   Provide a separate licensing page for that function
>>   along with the GPL for my code.
>> What is the appropriate course of action here?  I'm thinking #3 is 
>> probably ok.  How do others deal with this in an honorable way?
>> 
> As the author of several of those recipes, I definitely expect others
> to use them.  I'd hate to slow them up by requiring them to ask
> permission, but would appreciate an acknowledgment.
>
> -Scott David Daniels
> [EMAIL PROTECTED]
>   

Thanks for your perspective. I'll do both.

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


Re: Problem with python

2008-03-29 Thread Scott David Daniels
Lie wrote:
> On Mar 30, 2:57 am, [EMAIL PROTECTED] wrote:
>> Hi there.
>> I ... started writing simple programs in the python gui...  when I write
>> python code ...[and]... double click it all that happens is a black box 
>> flashes up on the screen, but nothing else!? 
> 
> open the program in IDLE (or any other Python IDEs). I'm guessing that
> your program is printing a traceback (error) when trying to get input
> that's why it immediately closes itself.

Another possibility is to open a shell (or command window or "dos box"),
and in that window type in "python myfile.py" You'll see error messages
because the display window does not depend on the program staying alive.

By the way, a better thing to have said when you asked this would
include your OS, the python version, and the GUI system you are using.
Those details matter.  If you are doing wxPython programming, for
example, you cannot easily use IDLE for your program (GUI systems
fight for control of the display).

-Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing simplejson issues

2008-03-29 Thread Diez B. Roggisch
Gabriel Genellina schrieb:
> En Fri, 28 Mar 2008 23:23:01 -0300, <[EMAIL PROTECTED]> escribió:
> 
>> On Mar 28, 1:57 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
>> wrote:
>>> En Fri, 28 Mar 2008 16:14:07 -0300, <[EMAIL PROTECTED]> escribió:
>>>
>>> > I am trying to install the twitter python wrapper...I got that
>>> > installed just fine, but am having serious troubles getting the
>>> > simplejson package to install.  I need help diagnosing where this is
>>> > failing.  I am trying to use:
>>>
>>> >http://pypi.python.org/pypi/simplejson
>>>
>>> > and I run "python setup.py build" and then "python setup.py install",
>>> > which both seem to work just fine.
> 
> I tried to install the package but failed. Looks like the setup.py used 
> by simplejson is broken - doesn't handle well the case when the C 
> extension can't be compiled.
> When I run `python setup.py install` I got this message:
> 
> building 'simplejson._speedups' extension
> **
> WARNING: The C extension could not be compiled, speedups are not enabled.
> 
> Below is the output showing how the compilation failed:
> 
> Python was built with Visual Studio version 7.1, and extensions need to 
> be built
>  with the same version of the compiler, but it isn't installed.
> **
> 
> and later:
> removing simplejson.egg-info\native_libs.txt
> ...
> error: can't copy 'simplejson.egg-info\native_libs.txt': doesn't exist 
> or not a regular file
> 
> I suggest that you remove the simplejson-xx.egg file and delete the 
> simplejson entry in easy-install.pth (both in your site-packages directory)
> Then extract the simplejson directory from inside the original .tar.gz 
> archive into your site-packages directory (so you end up by example with 
> a .../site-packages/simplejson/decoder.py file, among others)
> That appears to be enough; import simplejson worked fine for me.
> 
> I hate those fng eggs. Ah, and I hate easy_install too.

This has nothing to do with setuptools or easy_install per se. The 
author of simplejson tried to create a library that works with or 
without a C-extension. And failed.

As your above approach fails to even *try* and compile the speedups.

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


Re: Installing simplejson issues

2008-03-29 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> I am trying to install the twitter python wrapper...I got that
> installed just fine, but am having serious troubles getting the
> simplejson package to install.  I need help diagnosing where this is
> failing.  I am trying to use:
> 
> http://pypi.python.org/pypi/simplejson
> 
> and I run "python setup.py build" and then "python setup.py install",
> which both seem to work just fine.
> 
> I tried running with easy_install, but that too is not working.  I end
> up with:
> 
> simplejson-1.8.1-py2.5-macosx-10.3-fat.egg
> 
> in my:
> 
> /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
> packages/
> 
> I am on Mac OS X 10.5.  Any help would be greatly appreciated.

Go to the turbogears file section and download an appropriate version of 
simplejson:

http://www.turbogears.org/download/filelist.html

I presume sj-1.7.4 is sufficient.

Alternatively, be gentle to your unixish OS that OS X is, and install 
XCode. Which will install the whole GCC chain, making your OS a 
respected member of OS-community - as every system should be able to 
compile C-code, in which itself has been written.

Then the install should work as well.

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


pexpect

2008-03-29 Thread Paul Lemelle

I am trying separate a script that users pexpect into
various functions within the same expect session.  The
problem is that the function does not return control
back Main.  Any insight into this issue would be
greatly appreciated.  Below is sample code of the
problem.  

Thanks, 
Paul 


import pexpect





def sshcon(user, password):

go = pexpect.spawn ('/usr/bin/ssh -l root %s '%
(user))

go.expect ('Password: ')

go.sendline (password)

go.interact()





#get node info for both clusters. 



C1_node = raw_input("Enter the ip address for node on
cluster 1: ")

C1_pass = raw_input("Enter the password for the node
on cluster 1: ")





sshcon(C1_node, C1_pass)

#The function will not run anything pass this point.  If I place the
#below code into the above funciton than everything works fine.  
chk = pexpect.spawn('ls') # veriy that you are
connected

#go to the path

chk.expect('# ')

chk.sendline('ls')



chk.interact(

#END

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


Re: pygame handoff

2008-03-29 Thread castironpi
On Mar 28, 5:09 am, [EMAIL PROTECTED] wrote:
> Can anyone do a simple pygame render of a rollercoaster in first-
> person?  I'll do the generator.  Just for fun for free.  (Ha see
> pythaagh.  He bothered to carve it.  Have a nice day.)

Does anyone want to team up on this:

http://www.pygame.org/gamelets/games/pycastersrc.zip
-- 
http://mail.python.org/mailman/listinfo/python-list


Can anyone help me?

2008-03-29 Thread castironpi
I have this.

'pycaster.py' works.  'spherecollide.py' doesn't.

C:\Documents and Settings\usr\My Documents\inbin\SphereCollide>
\programs\python2
5\python SphereCollide.py
Traceback (most recent call last):
  File "SphereCollide.py", line 39, in 
dlWorld, dlSpheres, dlFakeshadow = Objects.main()
  File "C:\Documents and Settings\usr\My Documents\inbin\SphereCollide
\Objects.p
y", line 11, in main
GL_RGBA, GL_UNSIGNED_BYTE, Data )
  File "C:\programs\Python25\Lib\site-packages\OpenGL\wrapper.py",
line 1624, in
 __call__
return self.finalise()( *args, **named )
  File "C:\programs\Python25\Lib\site-packages\OpenGL\wrapper.py",
line 924, in
wrapperCall
raise err
OpenGL.error.GLError: GLError(
err = 1281,
description = 'invalid value',
baseOperation = glTexImage2D,
pyArgs = [
GL_TEXTURE_2D,
0,
GL_RGBA,
200,
200,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
'\x80\x80\x80\xff\x80\x80\x80\xff\x80...
],
cArgs = [
GL_TEXTURE_2D,
0,
GL_RGBA,
200,
200,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
'\x80\x80\x80\xff\x80\x80\x80\xff\x80...
],
cArguments = (
GL_TEXTURE_2D,
0,
GL_RGBA,
200,
200,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
c_void_p(189956812),
)
)

C:\Documents and Settings\usr\My Documents\inbin\SphereCollide>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Change user on UNIX

2008-03-29 Thread Tim Roberts
"Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote:
>
>I'll try to describe what I'm actually trying to implement so that
>maybe it can help you understand a little better.
>The application is an asynchronous FTP server implementation.
>I decided that it would be desirable to change the current
>implementation so that every time a filesystem operation is going to
>be made I
>temporarily change the current process ID to reflect the current
>logged-in user, execute the filesystem call and then switch back to
>the original process ID.

You don't mean "process ID".  You mean user ID and group ID.  Your
fundamental concept is correct.

>Pseudo code:
>
>def STOR(filename):
> authorizer = UnixAuthorizer()
> authorizer.impersonate_user(current_logged_in_user)
> try:
> f = open(filename, 'w')
> finally:
> authorizer.terminate_impersonation()
> ...
>
>The UnixAuthorizer class is expected to provide the mechanism to
>change the current user (presumably via os.setegid()/os.seteuid()) and
>then switch back to the original one.
>Since we're talking about an asynchronous environment I tought that
>temporarily changing the process ID was the only way to do this.
>I'm sincerely not skilled enough about the UNIX world to know which
>are the security implications behind such an approach.
>Do you think it is reasonable?

Typically, an FTP server dedicates one thread/process per logged in
session.  That process changes to the logged in user's identity as soon as
it gets the username and password, and stays there forever.  There is no
need to switch back to root in between.  The principle of least privilege
says you should just stay as the unprivileged user while you can.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing simplejson issues

2008-03-29 Thread blwatson
On Mar 29, 3:48 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] schrieb:
>
>
>
> > I am trying to install the twitter python wrapper...I got that
> > installed just fine, but am having serious troubles getting the
> > simplejson package to install.  I need help diagnosing where this is
> > failing.  I am trying to use:
>
> >http://pypi.python.org/pypi/simplejson
>
> > and I run "python setup.py build" and then "python setup.py install",
> > which both seem to work just fine.
>
> > I tried running with easy_install, but that too is not working.  I end
> > up with:
>
> > simplejson-1.8.1-py2.5-macosx-10.3-fat.egg
>
> > in my:
>
> > /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
> > packages/
>
> > I am on Mac OS X 10.5.  Any help would be greatly appreciated.
>
> Go to the turbogears file section and download an appropriate version of
> simplejson:
>
> http://www.turbogears.org/download/filelist.html
>
> I presume sj-1.7.4 is sufficient.
>
> Alternatively, be gentle to your unixish OS that OS X is, and install
> XCode. Which will install the whole GCC chain, making your OS a
> respected member of OS-community - as every system should be able to
> compile C-code, in which itself has been written.
>
> Then the install should work as well.
>
> Diez

I have already installed XCode...my compiel did not break the way the
above did.

I have grabbed the .egg file for simplejson 1.7.4 for Mac OS X 10.5 at
the above link you provided - it has a simplejson dir, with the exact
files that are in my simplejson directory for 1.8.1 (except none of
my .py files have been compiled down to bytecode).

I tried to add the directory "//simplejson" to my sys.path
in the interpreter, hoping that the call to import simplejson would
work if the dir was there, even though simplejson.py did not exist is
that dir, but the encoder, decoder, jsonfilter and scanner .py files
were all there.

My problem is that the call "import simplejson" fails.  How can I make
that call work?

Thanks in advance.

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


Re: Why prefer != over <> for Python 3.0?

2008-03-29 Thread Gabriel Genellina
En Sat, 29 Mar 2008 16:24:01 -0300, Michael Wieher  
<[EMAIL PROTECTED]> escribió:

> to me it seems simple.
>
> C uses !=
>
> why does C use !=  because its kind of hard to type the "equal with a
> slash"

In C, ! by itself is the logical "not", so !(a==b) is the same as (a!=b)  
and that's rather consistent.
Python doesn't use ! for anything else; != is rather arbitrary but  
certainly much better than <> (for many objects < and > are meaningless;  
being equal or not equal has nothing to do with being less or greater)

-- 
Gabriel Genellina

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


Re: Passing function objects to timeit

2008-03-29 Thread Gabriel Genellina
En Sat, 29 Mar 2008 07:33:40 -0300, Steven D'Aprano  
<[EMAIL PROTECTED]> escribió:

> The timeit.Timer class times "code snippets" -- you pass it strings
> rather than function objects. That's good for what it's worth, but
> sometimes the code you want to time is too big to easily pass as a
> string, or maybe you only have access to a function object without the
> source, or for whatever reason it's not very convenient.
>
> In this case, a good trick is to import the function by name:
>
> timeit.Timer('spam()', 'from __main__ import spam')
>
>
> But now I find myself wanting to time a function that's not defined in
> __main__. Here's a illustrative example:
>
>
> def factory():
> def f():
> return "spam"
> return f
>
> def main():
> func = factory()
> return timeit.Timer('func()', 'from __main__ import func').timeit()

Would this help (untested)?

def main():
   return timeit.Timer('func()', 'from __main__ import factory; func =  
factory()').timeit()

Or maybe:

def main():
   global func
   func = factory()
   return timeit.Timer('func()', 'from __main__ import func').timeit()

-- 
Gabriel Genellina

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


Re: Can anyone help me?

2008-03-29 Thread Paul McGuire
On Mar 29, 6:37 pm, [EMAIL PROTECTED] wrote:


What is the collision of spheres?  Is it the melding of a sphere of
influence and cosmic sphere?  What does it mean to say that such a
collision "doesn't work"?  The sphere is the optimal solid for storing
the maximum volume in the minimum area.  A sphere can retain the most
heat, with minimum surface area for radiation or conduction,
convection of course being dependent not only on surface area but also
ambient flow of surrounding conducting fluid if such flow is laminar
with respect to Reynold's magic number not to be confused with the
numbers of a magic square, which is a two-dimensional shape is there a
determination of the collision of a sphere's projection onto a plane
with a square on that same plane.  I've had it with these MF'in
squares on this MF'in plane!

-
More than iron, more than lead, more than gold I need electricity.
I need it more than I need lamb or pork or lettuce or cucumber.
I need it for my dreams.


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


Re: Can anyone help me?

2008-03-29 Thread marek . rocki
I love Paul's response.

[EMAIL PROTECTED] napisał(a):
> 

My crystal ball broke a few days ago due to overuse, but I recall that
OpenGL likes to have power-of-two texture sizes. If that doesn't work,
please trim down your code as far as possible (so that it still
displays the error) and post it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with sqlite

2008-03-29 Thread Tim Roberts
aiwarrior <[EMAIL PROTECTED]> wrote:
>
>I'm sorry about not saying showing the libraries. It was not on
>purpose.

You didn't make any comment on the rest of Gerhard's suggestion, nor does
it appear that you took any action to correct them.

You should get out of the habit of using extra parentheses in "if" and
"print" statements.  They are not needed in Python, and they make the code
more difficult to read.

>self.cursor.execute( "CREATE TABLE database
>(album,filepath)" )

Note the order of the fields: album, then path.

>def add_entry( self, eone , etwo ): #Add entry to database
>self.cursor.execute( "INSERT INTO database (album,filepath)
>VALUES (?,?)", ( eone , etwo ) )
>return 1 #TODO: exception handler

Again note the order of the fields here: album, then path.

>def get_value( self, column ):
>self.cursor.execute( "SELECT %s FROM database" % column )
>for n in self.cursor:
> print n

I suspect you wanted "self.cursor.fetchall()" there, but since you don't
call it, it doesn't matter yet.

>db.add_entry( joined, audio['album'] )

Now note the order that you supply the fields: path first, album second.
You are inserting the fields in the wrong order here.

>This is all the code. Some of that try pass code is just something i
>glued to create a clean slate database file

And such gluing is a very bad idea, because it is apparently hiding the
real cause of your problems.  Get rid of the try/except/pass sequences
until you understand what is failing.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why prefer != over <> for Python 3.0?

2008-03-29 Thread Steven D'Aprano
On Sat, 29 Mar 2008 12:49:05 -0700, Carl Banks wrote:

>> Please set it straight in 3.0, and if not, convince me with a good
>> reason of doing so, so that I can live with it and don't have to spend
>> the rest of my life in 2.x ;).
> 
> 1. It's not going to change in Python 3.0.
> 
> 2. It's a silly thing to care so much about that you will avoid using a
> langauge because of it.


I dislike the attitude that "oh, feature X is unimportant, why should we 
care about it?". It's often -- but not always -- said by those who do 
care very much about it themselves, except they prefer the way it is 
rather then the requested feature.

If Guido had a sudden brain tumor and replaced comparison operators with 
Fortran-style operators, it wouldn't destroy Python. It would just be a 
minor wart on an otherwise good language. So why should we care about 
using == instead of .EQ.?

Why does Python use # for comments instead of Basic-style remarks? Would 
it be silly to care if Python 3 discarded # and introduced REM?

I could belabor the obvious with dozens of syntax elements which, *in 
isolation*, it would be silly to care about. But syntax defines the feel 
of the language. Perl and Java have better (or at least *larger*) 
libraries, although arguably not as many "batteries included", but the 
syntax, oh my. We use Python because it is Python and not Perl or Basic 
or Fortran or Java. If the syntax changes, so does the language.

Yes, in isolation the question of != versus <> is a tiny little thing, 
silly to drop Python merely because of it. But it's not silly to care 
about the feel of the language. Python is as good as it is because Guido 
cares very much indeed about the feel of the language, and so do many of 
we Python users.



-- 
Steven

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


Re: Installing simplejson issues

2008-03-29 Thread Gabriel Genellina
En Sat, 29 Mar 2008 19:45:09 -0300, Diez B. Roggisch <[EMAIL PROTECTED]>  
escribió:

>> I suggest that you remove the simplejson-xx.egg file and delete the
>> simplejson entry in easy-install.pth (both in your site-packages  
>> directory)
>> Then extract the simplejson directory from inside the original .tar.gz
>> archive into your site-packages directory (so you end up by example with
>> a .../site-packages/simplejson/decoder.py file, among others)
>> That appears to be enough; import simplejson worked fine for me.
>>
>> I hate those fng eggs. Ah, and I hate easy_install too.
>
> This has nothing to do with setuptools or easy_install per se. The
> author of simplejson tried to create a library that works with or
> without a C-extension. And failed.

I think that the whole approach is doomed to fail; trying to do things  
more complicated that they should be.
The pure-python part of simplejson is just a package. Copying the  
directory into site-packages is *ALL* that is required; distutils can do  
that perfectly. That's all folks!. A database or registry keeping track of  
installed product versions might be useful, too. Anything that does much  
more than that is just looking for problems; simple systems work better  
than complex ones.
In this case, there is no need to create an egg, no need to play with .pth  
files, no need to slow down the package at import time (eggs must be  
decompressed), no need to extend sys.path and slow down *all* other  
imports. I don't feel that anything is better by using eggs or  
easy_install, and at least for me, they always have given more problems  
than answers.
So, again, I hate eggs and easy_install. And I hate eggplants too.

-- 
Gabriel Genellina

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


Re: Installing simplejson issues

2008-03-29 Thread Gabriel Genellina
En Sat, 29 Mar 2008 20:54:36 -0300, <[EMAIL PROTECTED]> escribió:

> I tried to add the directory "//simplejson" to my sys.path
> in the interpreter, hoping that the call to import simplejson would
> work if the dir was there, even though simplejson.py did not exist is
> that dir, but the encoder, decoder, jsonfilter and scanner .py files
> were all there.
>
> My problem is that the call "import simplejson" fails.  How can I make
> that call work?

simplejson is a package (a directory with an __init__.py), not a module;  
don't look for simplejson.py
Its *parent* directory must be in sys.path for Python to find it. Try  
copying the simplejson directory below site-packages (which should be  
already in sys.path)

-- 
Gabriel Genellina

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


Re: Problem with sqlite

2008-03-29 Thread Carsten Haese
On Mar 29, 9:10 pm, Tim Roberts <[EMAIL PROTECTED]> wrote:
> aiwarrior <[EMAIL PROTECTED]> wrote:
> >def get_value( self, column ):
> >self.cursor.execute( "SELECT %s FROM database" % column )
> >for n in self.cursor:
> > print n
>
> I suspect you wanted "self.cursor.fetchall()" there, but since you don't
> call it, it doesn't matter yet.

sqlite3's cursor objects support the iteration protocol, so the for-
loop does work without calling fetchall().

--
Carsten Haese
http://informixdb.sourceforge.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can anyone help me?

2008-03-29 Thread castironpi
On Mar 29, 7:59 pm, [EMAIL PROTECTED] wrote:
> I love Paul's response.
>
> [EMAIL PROTECTED] napisa³(a):
>
> > 
>
> My crystal ball broke a few days ago due to overuse, but I recall that
> OpenGL likes to have power-of-two texture sizes. If that doesn't work,
> please trim down your code as far as possible (so that it still
> displays the error) and post it.

It isn't mine.  while 1: it isn't.

Try to attach files fail 1.  Can link though: any help?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why prefer != over <> for Python 3.0?

2008-03-29 Thread Aahz
In article <[EMAIL PROTECTED]>,
 <[EMAIL PROTECTED]> wrote:
>
>I don't know if this is the right place to discuss the death of <> in
>Python 3.0, or if there have been any meaningful discussions posted
>before (hard to search google with '<>' keyword), but why would anyone
>prefer the comparison operator != over <>???

Are you asking why Python 3.0 gets rid of one of them or are you asking
why != was chosen over <>?
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Passing function objects to timeit

2008-03-29 Thread Steven D'Aprano
On Sat, 29 Mar 2008 21:12:33 -0300, Gabriel Genellina wrote:

> En Sat, 29 Mar 2008 07:33:40 -0300, Steven D'Aprano
> <[EMAIL PROTECTED]> escribió:
> 
>> The timeit.Timer class times "code snippets" -- you pass it strings
>> rather than function objects. That's good for what it's worth, but
>> sometimes the code you want to time is too big to easily pass as a
>> string, or maybe you only have access to a function object without the
>> source, or for whatever reason it's not very convenient.
>>
>> In this case, a good trick is to import the function by name:
>>
>> timeit.Timer('spam()', 'from __main__ import spam')
>>
>>
>> But now I find myself wanting to time a function that's not defined in
>> __main__. Here's a illustrative example:
>>
>>
>> def factory():
>> def f():
>> return "spam"
>> return f
>>
>> def main():
>> func = factory()
>> return timeit.Timer('func()', 'from __main__ import func').timeit()
> 
> Would this help (untested)?
> 
> def main():
>return timeit.Timer('func()', 'from __main__ import factory; func =
> factory()').timeit()


Unfortunately no.

The above was just a simple illustration. Perhaps I misled you by showing 
where func() came from, but what I intended to illustrate was that func() 
could come from *anywhere*. I might not know where it came from: all I 
have is a function object.

In fact, my question is actually more general than that, because my 
example was a little unrealistic in that the function took no arguments. 
I have to deal with the function arguments as well.

The general problem is that I wish to time an arbitrary function with 
arbitrary arguments. The function and arguments are provided to me as 
Python objects, but timeit requires strings. Converting the objects to 
strings is not practical, and the objects might not exist in the __main__ 
module.

The problem is that timeit creates its own namespace to execute the code 
in (which is a good thing!). Is there a way to insert arbitrary objects 
into that namespace?


> Or maybe:
> 
> def main():
>global func
>func = factory()
>return timeit.Timer('func()', 'from __main__ import func').timeit()

I'll try playing around with that and see.


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

Re: problem with logic in reading a binary file

2008-03-29 Thread castironpi
On Mar 29, 2:11 pm, Gary Herron <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Hello,
>
> > I am having trouble writing the code to read a binary string.  I would
> > like to extract the values for use in a calculation.
>
> > Any help would be great.
>
> Without having looked at your code an any detail, may I humbly suggest
> that you throw it all out and use the struct module:
>
>    http://docs.python.org/lib/module-struct.html
>
> It is meant to solve this kind of problem, and it is quite easy to use.
>
> Gary Herron
>
>
>
> > Here is my function that takes in a string.
>
> > def parseSequence(data, start):
>
> >     group_num = data[start:start+2]
> >     element_num = data[start+2:start+4]
> >     vl_field = data[start+4:start+8]
> >     length = struct.unpack('hh', vl_field)[0]
> >     value = data[start+8:(start+8+length)]
> >     pos = start+8+length
> >     element = (group_num+element_num)
>
> >     if element == '\xfe\xff\x00\xe0':
> >         data = value
>
> >         while start < length:
> >             group_num = data[start:start+2]
> >             element_num = data[start+2:start+4]
> >             vl_field = data[start+4:start+8]
> >             length = struct.unpack('hh', vl_field)[0]
> >             value = data[start+8:(start+8+length)]
> >             start = start+8+length
> >             element = (group_num+element_num)
>
> >             if element == '\xfe\xff\x00\xe0':
> >                 data = value
>
> >                 while start < length:
> >                     group_num = data[start:start+2]
> >                     element_num = data[start+2:start+4]
> >                     vl_field = data[start+4:start+8]
> >                     length = struct.unpack('hh', vl_field)[0]
> >                     value = data[start+8:(start+8+length)]
> >                     start = start+8+length
> >                     element = (group_num+element_num)
> >                     return element, start, value
>
> >             else:
> >                 return element, start, value
>
> >     else:
> >         return  element, pos, value
>
> > And, here is a sample string (I have split up and indented for
> > readability).  There is an identifier (\xfe\xff\x00\xe0) followed by
> > the length of the nested values.
>
> > '\xfe\xff\x00\xe0\x18\x02\x00\x00     -length=536
> >      \n0q\x00\x02\x00\x00\x001
> >      \n0x\x00\x02\x00\x00\x0010
> >      \n0\x80\x00\x02\x00\x00\x004
> >      \n0\xa0\x00\x02\x00\x00\x000
> >      \x0c0\x04\x00\xe8\x01\x00\x00
> >      \xfe\xff\x00\xe0p\x00\x00\x00     -length=112
> >           \n0\x82\x002\x00\x00\x0042.9068704277562\\-392.3545926477\
> > \189.182112099444
> >           \n0\x84\x00\x0c\x00\x00\x008.9617062e-1
> >           \n0\x86\x00\x10\x00\x00\x00127.378510918301
> >           \x0c0\x06\x00\x02\x00\x00\x001
> >      \xfe\xff\x00\xe0p\x00\x00\x00     -length=112
> >           \n0\x82\x002\x00\x00\x0042.9068704277562\\-392.3545926477\
> > \189.182112099444
> >           \n0\x84\x00\x0c\x00\x00\x001.629998e-1
> >           \n0\x86\x00\x10\x00\x00\x0023.159729257873
> >           \x0c0\x06\x00\x02\x00\x00\x004
> >      \xfe\xff\x00\xe0t\x00\x00\x00      -length=116
> >           \n0\x82\x002\x00\x00\x0042.9068704277562\\-392.3545926477\
> > \189.182112099444
> >           \n0\x84\x00\x10\x00\x00\x001.26285318894435
> >           \n0\x86\x00\x10\x00\x00\x00227.690980638769
> >           \x0c0\x06\x00\x02\x00\x00\x003
> >      \xfe\xff\x00\xe0t\x00\x00\x00      -length=116
> >           \n0\x82\x002\x00\x00\x0042.9068704277562\\-392.3545926477\
> > \189.182112099444
> >           \n0\x84\x00\x10\x00\x00\x001.52797639111557
> >           \n0\x86\x00\x10\x00\x00\x00263.433384670643
> >           \x0c0\x06\x00\x02\x00\x00\x002 ')- Hide quoted text -

Binaries can come from computers as from people.  Synth sound &
graphics.  Start structuring primitive binaries:  What operation can
you run in real-time?

I would probably have to learn natural language to make any sense of
his keystrokes.  Designing interface-first, you want another person to
be pressing keys.  Can we get Simon to teach us a couple distinct
patterns?  (That's we teach it; (that means:); no words: that's
faster.)  Get a couple ring tones, customiz-ing-, and you play a
game.)

Multi-pad consolled the PC.  Can we give keystrokes its own thread?
Sadly, our first one: get spatial delay timing up to speed.  The
sturdy keys (the discretes) have whisper roger that.  Watch moving
target? over raise riggings.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Buffer Overflow with Python 2.5 on Vista in import site

2008-03-29 Thread Gabriel Genellina
En Sat, 29 Mar 2008 17:34:27 -0300, Fuzzyman <[EMAIL PROTECTED]> escribió:

> A very odd error with Python 2.5 (both 2.5.1 and 2.5.2 from the
> official msi installers and running on Vista under Parallels on the
> Mac).

It may be actually a Parallels issue - I've installed 2.5.1 on Vista (just  
once, on a real PC) and it worked fine. Anyway a better place for bug  
reports is bugs.python.org

Mmm, maybe you should check all your .pth files - looks like this strange  
path comes from one of them.

-- 
Gabriel Genellina

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


Re: What motivates all unpaid volunteers at Pycon?

2008-03-29 Thread Steve Holden
Tim Chase wrote:
>> I was wondering what motivated so many people to give so much to the
>> Python community.
> 
> fear, surprise, ruthless efficiency, an almost fanatical devotion 
> to the BDFL, and nice red uniforms.
> 
> Oh...
> 
NOT THE COMFY CHAIR! (tm)
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Can anyone help me?

2008-03-29 Thread Gabriel Genellina
En Sat, 29 Mar 2008 21:48:21 -0300, Paul McGuire <[EMAIL PROTECTED]>  
escribió:

> What is the collision of spheres?  Is it the melding of a sphere of
> influence and cosmic sphere?  What does it mean to say that such a
> collision "doesn't work"?  The sphere is the optimal solid for storing
> the maximum volume in the minimum area.  A sphere can retain the

Too much logical cohesion, even if you didn't want it... I'm sorry but you  
still can't emulate Aaron's jumping thoughts - maybe if you try harder  
next time...

-- 
Gabriel Genellina

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


  1   2   >