starting some Python script from C#

2006-05-27 Thread tatamata
Hello.

How can I run some Python script within C# program?

Thanks,

Zlatko 


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


Re: Looking for triangulator/interpolator

2006-05-27 Thread Travis E. Oliphant
Grant Edwards wrote:
> On 2006-05-27, Travis E. Oliphant <[EMAIL PROTECTED]> wrote:
> 
>>> I need to interpolate an irregularly spaced set of sampled
>>> points: Given a set of x,y,z points, I need to interpolate z
>>> values for a much finer x,y grid.
>> How many x,y,z points do you have?
> 
> I've got about 700 data points.  They're arranged irregularly
> along arcs arranged in sort of truncated fan-shape.
> 
>> Did you try the fitpack function bisplrep in scipy?
> 
> Not recently.  I spent a month or so wrestling with bisplrep a
> while back, but was unable to get stable results (either with
> real world data or with the example from the tutorial):
> 
> http://www.visi.com/~grante/scipy/interpolate.html
> http://www.scipy.net/pipermail/scipy-user/2004-December/003921.html
> 
> I switched to a trianguation scheme shortly after that posting,
> and haven't tired bisplrep since then.
> 

Not that you made a bad choice.  I do wonder, how much of your 
difficulty was with the interface to the underlying fitpack routines. 
The interface is pretty involved as there are lots of parameter choices 
to the underlying routine.  It's very possible the interface is broken 
in some strange way.

Given how many people want to do interpolation.  I'm surprised nobody 
has looked into fixing up the fitpack routines that do it.  I suppose 
it's possible that the underlying fitpack routines are faulty in 2-d.

Your examples will help in that study.

Pearu made some nice class-based interfaces to fitpack in 2003.  They 
are in SciPy, but, it appears that people aren't making much use of 
them.  Did you try them?

They are in fitpack2.py

There are new wrappers for it


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


Re: Speed up this code?

2006-05-27 Thread Frank Millman

Gregory Petrosyan wrote:
> # Paul Rubin's version
> [EMAIL PROTECTED]:~$ python -mtimeit "import test2" "test2.primes(1000)"
> 100 loops, best of 3: 14.3 msec per loop
>
> # version from the Cookbook
> [EMAIL PROTECTED]:~$ python -mtimeit "import test1" "test1.primes(1000)"
> 1000 loops, best of 3: 528 usec per loop

You are quite right, Gregory, my timings are way off.

I have figured out my mistake. Paul's function is a generator. Unlike a
normal function, when you call a generator function, it does not
actually run the entire function, it simply returns a generator object.
It only runs when you iterate over it until it is exhausted. I was
effectively measuring how long it took to *create* the generator, not
iterate over it.

Thanks for correcting me.

Frank

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


matplotlib and numpy installation

2006-05-27 Thread cesco
Hi,

I wanted to install python, numpy and matplotlib on Linux Ubuntu.
I installed python with the following commands
./configure --enable-unicode=ucs4
make
make install
and then I installed numpy running
python setup.py install
Finally I came to matplotlib, that for the installation requires the
commands
python setup.py build
python setup.py install
but when I run the first (python setup.py build) I got the following
output that I copied partially below. What am I doing wrong? Can anyone
help?
I had previously another version of python located in usr/bin while the
current is in usr/local/bin. I guess I could remove the previous by the
deleting the relative folder and now if I run the command 'which
python' it actually says 'usr/local/bin/python' so I hope I done it
correctly. If not, how can I uninstall any previous version of python?
Do you think that somehow the error I get is caused by an unclean
removal of that previous version?

Thanks and regards
Francesco

Here follows the output:
---

GTK requires pygtk
TKAgg requires TkInter
GTKAgg requires pygtk
running build
running build_py
running build_ext
building 'matplotlib.backends._ns_backend_agg' extension
gcc options: '-pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
-Wstrict-prot\
otypes -fPIC'
compile options:
'-I/usr/local/lib/python2.4/site-packages/numpy/core/include -\
I/usr/include -I. -Isrc -Iswig -Iagg23/include -I. -I/usr/include -I.
-I/usr/lo\
cal/lib/python2.4/site-packages/numpy/core/include/freetype2
-I/usr/include/fre\
etype2 -I./freetype2 -Isrc/freetype2 -Iswig/freetype2
-Iagg23/include/freetype2\
 -I./freetype2 -I/usr/include/freetype2 -I./freetype2
-I/usr/local/include/pyth\
on2.4 -c'
extra options: '-DSCIPY=1'
gcc: src/_image.cpp
src/_image.cpp:5:17: png.h: No such file or directory
In file included from /usr/local/include/python2.4/Python.h:8,
 from src/_image.cpp:7:
/usr/local/include/python2.4/pyconfig.h:835:1: warning:
"_POSIX_C_SOURCE" redef\
ined
In file included from
/usr/include/c++/3.3/i486-linux/bits/os_defines.h:39,
 from
/usr/include/c++/3.3/i486-linux/bits/c++config.h:35,
 from /usr/include/c++/3.3/iostream:44,
 from src/_image.cpp:1:
/usr/include/features.h:131:1: warning: this is the location of the
previous de\
finition
src/_image.cpp: In member function `Py::Object Image::write_png(const
   Py::Tuple&)':
src/_image.cpp:626: error: `png_structp' undeclared (first use this
function)
src/_image.cpp:626: error: (Each undeclared identifier is reported only
once
   for each function it appears in.)
src/_image.cpp:626: error: parse error before `;' token
src/_image.cpp:627: error: `png_infop' undeclared (first use this
function)
src/_image.cpp:628: error: aggregate `png_color_8_struct sig_bit' has
   incomplete type and cannot be defined
src/_image.cpp:629: error: `png_uint_32' undeclared (first use this
function)
src/_image.cpp:629: error: parse error before `=' token
src/_image.cpp:632: error: `png_bytep' undeclared (first use this
function)
src/_image.cpp:632: error: `row_pointers' undeclared (first use this
function)
src/_image.cpp:632: error: parse error before `[' token
src/_image.cpp:634: error: `row' undeclared (first use this function)
src/_image.cpp:645: error: `png_ptr' undeclared (first use this
function)
src/_image.cpp:645: error: `PNG_LIBPNG_VER_STRING' undeclared (first
use this
   function)
src/_image.cpp:645: error: `png_create_write_struct' undeclared (first
use this\

   function)
src/_image.cpp:653: error: `info_ptr' undeclared (first use this
function)
src/_image.cpp:653: error: `png_create_info_struct' undeclared (first
use this
   function)
src/_image.cpp:657: error: `png_destroy_write_struct' undeclared (first
use
   this function)
src/_image.cpp:662: error: `setjmp' undeclared (first use this
function)
src/_image.cpp:670: error: `png_init_io' undeclared (first use this
function)
src/_image.cpp:673: error: `PNG_COLOR_TYPE_RGB_ALPHA' undeclared (first
use
   this function)
src/_image.cpp:673: error: `PNG_INTERLACE_NONE' undeclared (first use
this
   function)
src/_image.cpp:674: error: `PNG_COMPRESSION_TYPE_BASE' undeclared
(first use
   this function)
...

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


Re: chop() and empty() functions

2006-05-27 Thread bearophileHUGS
Jeremy L. Moles>It's just an iterative way to say, "Okay, give me some
default behavior for everything, and I'll come back around later and
set the explicit handlers later."<

There's some correlation with the Null Object pattern:
http://www.cs.oberlin.edu/~jwalker/nullObjPattern/

Bye,
bearophile

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


Re: monkeypatching NamedTemporaryFile

2006-05-27 Thread craighse888
Maybe that should be the default behaviour.  Presumably the file has
been deleted by some other process?

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


Re: chop() and empty() functions

2006-05-27 Thread John Machin
On 27/05/2006 7:10 AM, Jeremy L. Moles wrote:
> On Sat, 2006-05-27 at 06:22 +1000, John Machin wrote:
>> On 27/05/2006 2:54 AM, Jeremy L. Moles wrote:
>>
>> ["chop" snipped]
>>
>>> Furthermore, what do people think about the idea of adding a truly
>>> empty, no-op global lambda somewhere in Python? I use them a lot
>> What is the use case? Why write something like """empty(foo, 42, 
>> cmd="xyzzy")""" when you could merely write "pass" or nothing at all?
> 
> Well, in a lot of the libraries I use, there is often a need for a
> callback of some sort. Sure, I--and most other people--often define an
> empty, no-op function of some sort when you want to at least have
> "something" there, but I thought it might be kinda' neat to be able to
> have a builtin called empty() or noop() that returned a (possibly
> optimized?) function that just did nothing. :) It probably is a dumb
> idea, hehe... the chop() was the big one I thought people might comment
> on.
> 
> For example, I often do stuff like this for handling "input events" in
> soya:
> 
>   evhandlers = [emptyfunc for i in range(MAX_NUM_EVENTS)]
> 
>   evhandlers[EVENT_NUMBER] = self.my_handler_function
> 
> ...and then in the actual input loop I'll come along and say...
> 
>   evhandlers[ev](*args)
> 
> In this way I don't have to test the value of any event and behave
> accordingly--I just send it on it's way. 
> 
> It's just an iterative way to say, "Okay, give me some default behavior
> for everything, and I'll come back around later and set the explicit
> handlers later."

If you intend to set explicit handlers later, wouldn't it be better for 
the default event handler to raise an exception, just in case your 
intention is waylaid or sidetracked?

> 
> This same design is probably used in other areas too... that's why I
> brought up the "truly empty noop" thing; it would give me fuzzy feeling
> to know that in those cases where empty() is defined, nothing is
> happening (although, this could currently be the case in Python, I'm not
> sure--I don't know a lot about Python internals).

It would give you a fuzzy feeling to know that nothing is happening -- 
instead of *what* happening? What do you dread?

If, when you do evhandlers[ev](*args), evhandlers[ev] can't be evaluated 
to a callable object (for one of several possible reasons), Python will 
raise the appropriate exception. It won't "do nothing". Python will not 
assume that you meant to supply a no-op function. Python refuses to 
guess what you had in mind. This is part of the language philosophy, and 
is not implementat(ion|er)-dependant.

I suggest that you fire up a Python interactive prompt, and type

import this

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


CMFBoard

2006-05-27 Thread maria
Hi everybody!

I use CMFBoard 2.2.1 as a discussion board on my website.
I want to open the forum to all users, anonymous and registred users!
But my problem is, that whenever an ano user posts a topic, the
overview doesn't display the message correctly. Instead of a table
containing topic-title, short description, last reply, user.. there
is only some text shown, like this:

 {'last_reply_created': '2006-05-27 09:36', 'msgIcon': ' ',
'Title': 'test', 'actions': {'reply':
'http://forumfolder.2006-05-27.1751137831/public/0002/forum_reply_form',
'delete':
'http://forumfolder.2006-05-27.1751137831/public/0002/forum_message_delete_form'},
'topic': , 'last_user': 'Anonymous
User', 'topicIcon': u'', 'Description': '', 'creator': 'admin',
'replyCount': 1, 'msg': ,
'review_state': 'published', 'topicId': '0002', 'last_reply_title': '',
'topicDesc': u'', 'pages_links': [], 'view_mode': 'flat',
'last_reply_topic': 0, 'anonymous': 1, 'last_user_isanon': 1, 'icon':
'http:///fcTopic_icon.gif"; alt="Normal topic "
title="Normal topic " longdesc="" height="11" width="17" />', 'hits':
1, 'created': '2006-05-27 09:35', 'url':
'http:///forumfolder.2006-05-27.1751137831/public/0002',
'sticky_flag': 1, 'last_reply_link':
'http://forumfolder.2006-05-27.1751137831/public/0002/0002'}


I would be very happy, if anyone can help me!!
Best regards,
Maria

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


Re: matplotlib and numpy installation

2006-05-27 Thread Travis E. Oliphant
cesco wrote:
> Hi,
> 
> I wanted to install python, numpy and matplotlib on Linux Ubuntu.
> I installed python with the following commands
> ./configure --enable-unicode=ucs4
> [snip]
> running build_ext
> building 'matplotlib.backends._ns_backend_agg' extension
> gcc options: '-pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
> -Wstrict-prot\
> otypes -fPIC'
> compile options:
> '-I/usr/local/lib/python2.4/site-packages/numpy/core/include -\
> I/usr/include -I. -Isrc -Iswig -Iagg23/include -I. -I/usr/include -I.
> -I/usr/lo\
> cal/lib/python2.4/site-packages/numpy/core/include/freetype2
> -I/usr/include/fre\
> etype2 -I./freetype2 -Isrc/freetype2 -Iswig/freetype2
> -Iagg23/include/freetype2\
>  -I./freetype2 -I/usr/include/freetype2 -I./freetype2
> -I/usr/local/include/pyth\
> on2.4 -c'
> extra options: '-DSCIPY=1'
> gcc: src/_image.cpp
> src/_image.cpp:5:17: png.h: No such file or directory

This is the source of the remaining errors

On my system the "png.h" file comes from a libpng3-devel rpm

Perhaps you need to use apt-get to obtain the development package for png.

-Travis



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


Re: Running External Commands + Seeing when they are Finished

2006-05-27 Thread andychambers2002
from os import *

for cmd in ['adaware', 'spybot']:
system(cmd)

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


Re: Pyrex installation on windows XP: step-by-step guide

2006-05-27 Thread greg
Jim Lewis wrote:
> Thanks but now another problem :-(
> Examples in books show importing a global so why does below give:
> AttributeError: 'module' object has no attribute 'globalvar'
> 
> primes.pyx:
> from run import globalvar
> def prime(int kmax):
>   result = [run.globalvar]
> ...
> 
> run.py:
> from primes import prime
> globalvar = 999
> while True:
>   print prime (10)

The first thing run does is import primes, which
immediately imports run and tries to access the
name globalvar in it, before it has been defined.

There are ways of fixing that, but for various
reasons it's usually a bad idea for subsidiary
modules to try to import things from the main
module of a program. It would be better to move
globalvar into a third module.

Even better again would probably be not to use
a global at all, but pass it in as a parameter
to the prime() function.

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


Pyrex speed

2006-05-27 Thread Jim Lewis
Has anyone found a good link on exactly how to speed up code using
pyrex? I found various info but the focus is usually not on code
speedup.

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


Re: CMFBoard

2006-05-27 Thread Bruno Desthuilliers
maria a écrit :
> Hi everybody!
> 
> I use CMFBoard 2.2.1  as a discussion board on my website.
> I want to open the forum to all users, anonymous and registred users!
> But my problem is, that whenever an ano user posts a topic, the
> overview doesn't display the message correctly. Instead of a table
> containing topic-title, short description, last reply, user.. there
> is only some text shown, like this:
> 
>  {'last_reply_created': '2006-05-27 09:36', 'msgIcon': ' ',
> 'Title': 'test', 'actions': {'reply':
> 'http://forumfolder.2006-05-27.1751137831/public/0002/forum_reply_form',
> 'delete':
(snip)

Please repost this on Zope's mailing list - that's where you'll get the 
best answers. FWIW, your problem is likely a CMF configuration problem 
and has nothing to do with the Python language.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Method Delegation To Subinstances

2006-05-27 Thread Steve Holden
Cloudthunder wrote:
> In the example:
> 
> class Boo:
> def __init__(self, parent):
> self.parent = parent
> print self.parent.testme
> def run():
> print "Yaho!"
> 
> class Foo:
> testme = "I love you!"
> def __init__(self):
> test = Boo(self)
> 
> A = Foo()
> 
> 
> How can I set up method delegation so that I can do the following:
> 
> A.run()
> 
> and have this call refer to the run() method within the boo instance? 
> Also, what if I have tons of functions like run() within the boo 
> instance and I want all them to be directly accessible as if they were 
> part of their parent (the Foo instance)?  
> 
The usual way is to provide a __getattr__ method, since this is invoked 
after the usual mechanisms have failed to produce a sought attribute.

class Boo:
 def run(self):
 print "Yaho!"
 def identify(self):
print repr(self)

class Foo:
 testme = "I love you!"
 def __init__(self):
 self.test = Boo()
 def __getattr__(self, attname):
 return getattr(self.test, attname)

A = Foo()
B = Boo()

B.run()
B.identify()
A.run()
A.identify()

[EMAIL PROTECTED] ~/Projects/Python
$ python test49.py
Yaho!
<__main__.Boo instance at 0x186c002c>
Yaho!
<__main__.Boo instance at 0x186b9d4c>

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Python - Web Display Technology

2006-05-27 Thread Steve Holden
Edward Elliott wrote:
> [EMAIL PROTECTED] wrote:
> 
> 
>>Flash also behaves consistently cross-browser, cross/platform -- and 
>>features cannot be disabled by the user.
> 
>^^
> And that's a good thing?  Maybe for Macromedia, not for us.  This smells
> like astroturf.
> 
> 
> 
>>Flash can load and play external MP3 audio.
>>Flash can render text...
>>Flash can load/parse/serialize/send XML.
>>Flash can access you webcam, allowing you to create your own video
>>chat/IM app.
>>Flash can programatically-build vector shapes, gradients, and fills.
> 
> 
> It dices!  It splices!  Flash can heat your coffee, walk your dog, and
> change your baby!  It's the stupendous, miraculous, fantabulous app you
> can't live without!
> 
>  
> 
>>Flash can #animate# stuff!!!
>>
>>Flash is like a 2 MB download that works in almost *every* browser out
>>there.  ...it's pretty phenomenal that all those features could have
>>been crammed into it.(like: a built-in interpreter for a
>>late-version-EcmaScript-compliant scripting language -- that, in many
>>ways, is far more capable than what is available w/ JavaScript in most
>>browsers!)
>>
>>*** This feature can be used for a web-based CMS!  It would blow-away
>>anything (non-Java) now available for managing and uploading assets.
>>- Show quoted text -
> 
> 
> Ugh, definitely astroturf.
> 
The most telling thing of all is that most of the web sites with a Flash 
intro find it necessary to provide a "bypass intro" button. People 
quickly tire of this stuff. It's just, well, flashy :-)

Unfortunately it's difficult to get someone who's in love with a 
proprietary technology to admit that open standards are preferable.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Pyrex speed

2006-05-27 Thread Diez B. Roggisch
Jim Lewis schrieb:
> Has anyone found a good link on exactly how to speed up code using
> pyrex? I found various info but the focus is usually not on code
> speedup.

The code speedup comes through the usage of C by pyrex itself, and using 
it to put a thin layer over C-functions available/coded for that purpose.

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


Re: Pyrex speed

2006-05-27 Thread Jim Lewis
I'm not planning to write C functions. My understanding is that by
using cdefs in the python code one can gain substantial speed. I'm
trying to find a description of how to modify python code in more
detail so it runs fast under pyrex.

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


Re: getattr for modules not classes

2006-05-27 Thread Piet van Oostrum
> Heiko Wundram <[EMAIL PROTECTED]> (HW) schreef:

>HW> from x import test as x
>HW> print x.one
>HW> print x.two
>HW> print x.three

Or replace test by x in x.py :=)
-- 
Piet van Oostrum <[EMAIL PROTECTED]>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: starting some Python script from C#

2006-05-27 Thread Gerard Flanagan
tatamata wrote:
> Hello.
>
> How can I run some Python script within C# program?
>

-
ProcessStartInfo startInfo;
Process process;
string directory;
string pyArgs;
string script;

startInfo = new ProcessStartInfo("python");
startInfo.WorkingDirectory = directory;
startInfo.Arguments = script + " " + pyArgs;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;

process = new Process();
process.StartInfo = startInfo;
process.Start();

string s;
while ((s = process.StandardOutput.ReadLine()) != null)
{
//do something with s
}
-

HTH

Gerard

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


Re: Pyrex speed

2006-05-27 Thread Simon Percivall
You can gain substantial speed-ups in very certain cases, but the main
point of Pyrex is ease of wrapping, not of speeding-up.

Depending on what you're doing, rewriting in Pyrex or even in C, using
the Python/C API directly, might not gain you much.

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


Re: Pyrex speed

2006-05-27 Thread Jim Lewis
> main point of Pyrex is ease of wrapping, not of speeding-up.

Supposedly the primes example is 50 times faster.

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


Re: Pyrex speed

2006-05-27 Thread Jarek Zgoda
Jim Lewis napisal:

>>main point of Pyrex is ease of wrapping, not of speeding-up.
> 
> Supposedly the primes example is 50 times faster.

How often you perform primes calculations in your programs? In my >10
years of professional career in writing business software I never had an
opportunity to do any more sophisticated math than simple adding,
multiplying, subtracting and dividing.

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to clear up a List in python?

2006-05-27 Thread Martin v. Löwis
Duncan Smith wrote:
> chris brat wrote:
>> Doesnt this do what the original poster is try accomplish?
>>
> 
> Not what the OP asked for, no.  Clearing a list implies that list1
> should still be bound to the same list (which might be important if
> there are other names bound to the same list).  If it wasn't important
> that it be bound to the same list then I would probably go with
> linnorm's approach (which isn't really 'clearing' the list).

Sure. However, the OP still might have been happy with just discarding
the old list and creating a new one. Although he explicitly said "clear
the list", he might have meant "make it so that the variable refers to
an empty list", to which clearing the list is only one possible
solution.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


TreeCtrl to TreeListCtrl

2006-05-27 Thread sendhil kumar
Hi all,
whwn working with xml connectvity to python, i have a
sash window, in which first window has a Tree Control
that has 'n' parent fields preceded by + sign and on
leftdown  all the childs got from external xml file.

when the particular parent field is selected and
dragged, it must get posted to the other sash window
which should in TreeList Control, bcoz iam displaying
numerous xml attributes of the parent and following
'n' number of childs from xml.

Now, iam facing a problem in implementing with
TreeListCtrl, but it works fne with ListCtrl...

any suggestions, would be of great value...

cheers and thanx in advance...
SendhilKumar B.Tech


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pyrex speed

2006-05-27 Thread Jim Lewis
> I never had an opportunity to do any more sophisticated math than simple 
> adding,
multiplying, subtracting and dividing.

Neither is the primes example doing anything more sophisticated than
basic arithmetic but it's 50 times faster.

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


Re: Looking for triangulator/interpolator

2006-05-27 Thread Grant Edwards
On 2006-05-27, Travis E. Oliphant <[EMAIL PROTECTED]> wrote:

> Not that you made a bad choice.  I do wonder, how much of your
> difficulty was with the interface to the underlying fitpack
> routines.

I've no idea.  I had never done anything with splines before,
so it's quite possible I just wasn't doing things right.  I
never got it to work at all for non-gridded data (which is what
I needed).  Since it wasn't stable even for gridded data, I
more or less gave up.

> The interface is pretty involved as there are lots of
> parameter choices to the underlying routine.  It's very
> possible the interface is broken in some strange way.

I took a look at underlying Fortran code, but that made my
dizzy.

> Given how many people want to do interpolation.  I'm surprised
> nobody has looked into fixing up the fitpack routines that do
> it.  I suppose it's possible that the underlying fitpack
> routines are faulty in 2-d.
>
> Your examples will help in that study.
>
> Pearu made some nice class-based interfaces to fitpack in
> 2003.  They are in SciPy, but, it appears that people aren't
> making much use of them.  Did you try them?

Not that I remember.  

For that particular application, the interpolation had to be
done in real time, so a triangulation scheme turned out to be a
lot faster [with some constraints on the input data to make the
triangle search O(sqrt(N))].

-- 
Grant Edwards   grante Yow!  Are the STEWED PRUNES
  at   still in the HAIR DRYER?
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: access serial port in python

2006-05-27 Thread Grant Edwards
On 2006-05-27, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> i can use the polling method to check for data on the serial port using
> pyserial...but i need to use the interrupt driven method .am workin
> on a windows platform 

I don't think there is any way to so interrupt driven I/O under
Windows.  You can do asynchronous I/O under Windows using the
normal Win32 FileIO API.

-- 
Grant Edwards   grante Yow!  Is it 1974? What's
  at   for SUPPER? Can I spend my
   visi.comCOLLEGE FUND in one wild
   afternoon??
-- 
http://mail.python.org/mailman/listinfo/python-list


Using a package like PyInstaller

2006-05-27 Thread LittlePython
Is it possible when using packages like PyInstaller to create an .exe for
distribution that parts of the package can bleed out and be left on a system
when the .exe is executed?

Thx


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


Re: "Learning Python" 2nd ed. p479 error?

2006-05-27 Thread AbrahamLincolnIllinois
Thanks for your help, guys.  I'm convinced it is a bug, not a
misunderstanding.  I submitted it to the errata page at O'Reilly.


   Regards, 

   Abraham

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


Re: Pyrex speed

2006-05-27 Thread Graham Breed
Jim Lewis \/\/|20+3:
> I'm not planning to write C functions. My understanding is that by
> using cdefs in the python code one can gain substantial speed. I'm
> trying to find a description of how to modify python code in more
> detail so it runs fast under pyrex.

I've used pyrex to speed up my code.  It worked.  While it isn't
intended as a tutorial on pyrex you can have a look at it here:

http://www.microtonal.co.uk/temper.html

The trick is to write C functions using pyrex.  That's not much easier
than writing C functions in C.  But I still found it convenient enough
to be worth doing that way.  Some tips:

- declare functions with cdef

- declare the type of every variable you use

- don't use Python builtins, or other libraries

The point of these rules is that generated C code using Python
variables will still be slow.  You want Pyrex to write C code using C
variables only.  To check this is happening you can look at the
automatically generated source code to make sure there are no reference
counting functions where there shouldn't be.

The usual rule for C optimization applies -- rewrite the code that
you're spending most time in.  But if that innermost function's being
called from a loop it can be worth changing the loop as well so that
you pass in and out C variables.

HTH,

 Graham

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


Re: Pyrex speed

2006-05-27 Thread Gonzalo Monzón
Hi Jim,

It depends a lot on what you're doing. You will get speed up from Pyrex 
or wrapping C code if you understand how does it work internally, and to 
speed up you application via coding *only* Pyrex parts (I mean don't 
using it for wrapping C but implementing in Pyrex), it limits a lot the 
things that you can expect to get faster -'cause on some kind of things 
you can even get better performance coding that in straight Python than 
in Pyrex and converted to C & compiled, I thought you should know how 
Python works in the C side to understand it fully-.

I attach some examples of different code where C is a lot faster, or 
just a little bit faster (and I compare with C counterparts, not Pyrex 
ones -Pyrex is only used for wrapping in these examples-). So you can 
get an idea of why depends a lot on what you're doing.  If you plan only 
using cdefs to speed-up Python code, you're very limited in the things 
that could be speed-up. Try to do some experiments and examine the C 
generated code by Pyrex, and you will see why it is -you will see how 
Pyrex does Python C api function calls for conversion from Python 
objects to C type values every time you use that var, and that's not a 
great gain, even in some kind of operations can be worse as Python does 
a better job than generated C code by Pyrex for some operations or value 
conversions (i.e. when doing operations on some kind of iterable objects 
I remember to read on some paper that Pyrex does not traslate to the 
faster C approach)

Some days ago I posted some timing results for a function coded in 
Python, or coded in C and wrapped by Pyrex. C approach was more than 80 
times faster. And I attach below another one, where C isn't much a gain 
(1 time faster).

Example A:
This code is more than 80 times faster than a "easy" Python 
implementation. For every call, it does some bitwise operations and does 
an array lookup for every string character from argument. Its a lot 
faster because in Python approach a list lookup is done and it is a lot 
faster to do a C array lookup -thought that in these C loops no Python 
type value conversions are needed, if it where the case, C approach 
would not be so faster than python. I don't know how would perform an 
array based Python code, but I expect it to be a lot faster than using a 
list, so Python code can be speed up a lot if you know how to do it.

// C code:
int CRC16Table[256]; // Filled elsewhere
int CalcCRC16(char *str)
{
int crc;
   
for(crc = 0x; *str != 0; str++) {
crc = CRC16Table [(( crc >> 8 ) & 255 )] ^ ( crc << 8 ) ^ *str;
}
   
return crc;
}

# Python code
gCRC16Table = [] # Filled elsewhere
def CalcCRC16(astr):
crc = 0xL
for c in astr:
crc = gCRC16Table[((crc >> 8) & 255)] ^ ((crc & 0xFF) << 8) 
^ ord(c)
return crc

-
Example B:
If we do compare the functions below, Python approach is only a bit 
slowly than C implementation. I know both aren't the faster approaches 
for every language, but that's a different issue. C here is only about 1 
time faster:

// C code. gTS type is struct { int m, int s }
gTS gTS_diff(gTS t0, gTS t1) {
gTS retval;

retval.s = (t1.s-t0.s);
if ((t0.m>t1.m)) {
retval.m = (t1.m-t0.m);

while((retval.m<0)) {
retval.s = (retval.s-1);
retval.m = (m+1000);
}
} else {
retval.m = (t1.m-t0.m);
}

while((retval.m>999)) {
retval.m = (retval.m-1000);
retval.s = (retval.s+1);
}
return retval;
}

# Python code (t0 and t1 are tuples)
def gts_diff(t0,t1):
s = t1[0] - t0[0]
if (t0[1] > t1[1]):
m = t1[1] - t0[1]
   
while m < 0:
s = s - 1
m = m + 1000
else:
m = t1[1] - t0[1]
   
while m > 999:
m = m - 1000
s = s + 1  
return s, m


I encourage you to google for some Pyrex papers on the net, they explain 
the "to do"'s and the "not to do"'s with Pyrex. Sorry but I don't have 
the urls.

Regards,
Gonzalo

Jim Lewis escribió:

>>I never had an opportunity to do any more sophisticated math than simple 
>>adding,
>>
>>
>multiplying, subtracting and dividing.
>
>Neither is the primes example doing anything more sophisticated than
>basic arithmetic but it's 50 times faster.
>
>  
>

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


Re: starting some Python script from C#

2006-05-27 Thread tatamata
thanks.

"Gerard Flanagan" <[EMAIL PROTECTED]> je napisao u poruci interesnoj 
grupi:[EMAIL PROTECTED]
> tatamata wrote:
>> Hello.
>>
>> How can I run some Python script within C# program?
>>
>
> -
>ProcessStartInfo startInfo;
>Process process;
>string directory;
>string pyArgs;
>string script;
>
>startInfo = new ProcessStartInfo("python");
>startInfo.WorkingDirectory = directory;
>startInfo.Arguments = script + " " + pyArgs;
>startInfo.UseShellExecute = false;
>startInfo.CreateNoWindow = true;
>startInfo.RedirectStandardOutput = true;
>startInfo.RedirectStandardError = true;
>
>process = new Process();
>process.StartInfo = startInfo;
>process.Start();
>
>string s;
>while ((s = process.StandardOutput.ReadLine()) != null)
>{
>//do something with s
>}
> -
>
> HTH
>
> Gerard
> 


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


dynamic type changing

2006-05-27 Thread andychambers2002
I'm working on a "TempFile" class that stores the data in memory until
it gets larger than a specified threshold (as per PEP 42).  Whilst
trying to implement it, I've come across some strange behaviour.  Can
anyone explain this?

The test case at the bottom starts a TempFile at size 50 and prints its
type.  It then increases the size to the threshold at which point
"self" is changed to being a TemporaryFile.  It seems that the next
call correctly uses the write() method of TemporaryFile (since we don't
see "changing type" in the output).  However, type(tmp) still equals
TempFile.  Not only that, tmp can still access the method dummy() that
exists only in TempFile.

#!/usr/bin/env python
from StringIO import StringIO
import tempfile

class TempFile(StringIO, object):
"""A temporary file implementation that uses memory unless
   either capacity is breached or fileno is requested, at which
   point a real temporary file will be created and the relevant
   details returned
"""
def __init__(self, buffer, capacity):
"""Creates a TempFile object containing the specified buffer.
If capacity is specified, we use a real temporary file once the

file gets larger than that size.  Otherwise, the data is stored

in memory.
"""
self.capacity = capacity
if len(buffer) > capacity:
self = tempfile.TemporaryFile()
self.write(buffer)
else:
super(TempFile, self).__init__(buffer)

def dummy(self):
pass

def write(self, str):
self.seek(0, 2)  # find end of file
if((self.tell() + len(str)) >= self.capacity):
print "changing type"
flo = tempfile.TemporaryFile()
flo.write(self.getvalue())
self = flo
print type(self)
else:
super(TempFile, self).write(str)


print "testing tempfile:"
tmp = TempFile("", 100)
ten_chars = "1234567890"
tmp.write(ten_chars * 5)
tmp.dummy()
print "tmp < 100: " + str(type(tmp))
tmp.write(ten_chars * 5)
tmp.dummy()
print "tmp == 100: " + str(type(tmp))
tmp.write("the last straw")
tmp.dummy()
print "tmp > 100: " + str(type(tmp))

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


HTTPS client certificates (was Re: Twill question) (fwd)

2006-05-27 Thread John J Lee
Just forwarding this in case anybody here can shed light on this -- 
urllib's support for SSL client certificates didn't work for me, and I'm 
wondering if it works for anybody else...


John

-- Forwarded message --
Date: Sat, 27 May 2006 14:33:03 + (UTC)
From: John J Lee <[EMAIL PROTECTED]>
To: Wayne Wang <[EMAIL PROTECTED]>, twill@lists.idyll.org
Subject: HTTPS client certificates (was Re: Twill question)

On Fri, 26 May 2006, Wayne Wang wrote:
[...wants https client auth...]

OK, I added the necessary boilerplate to mechanize (haven't committed yet), but 
the basic support for this that comes with Python didn't work for me on a local 
test server I set up, so I couldn't get it working with mechanize either.

Wayne, and anybody else who uses client certificates and is inclined to help 
out: could you try running this script, after replacing HTTPS_URL with a URL on 
the secure site you're trying to access, and KEY_FILE and CERT_FILE with the 
full filenames where you keep those?

I'm afraid you have to convert the p12 file into separate PEM-format key and 
cert files using e.g. OpenSSL:

openssl pkcs12 -clcerts -nokeys -in cert.p12 -out cert.pem
openssl pkcs12 -nocerts -in cert.p12 -out key.pem


HTTPS_URL = "https://example.com:443/restricted/foo.html";
KEY_FILE = r"c:\blah\blah\key.pem"
CERT_FILE = r"c:\blah\blah\cert.pem"

import urllib
urllib.URLopener(key_file=KEY_FILE,
   cert_file=CERT_FILE,
  ) 
r = urllib.urlopen()
print r.read()


John

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


Re: Running External Commands + Seeing when they are Finished

2006-05-27 Thread Tommy B
The problem is with that (which is what I'm doing already) is that one
app is in a window and one app is on the command line. Thus, you end up
with both apps running at the same time. Are there any modules that
have functions for checking when windows are opened or closed?

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


Re: John Bokma harassment

2006-05-27 Thread Dražen Gemić
I can't see the way how Xah Lee could be on topic in 
comp.lang.java.programmer. He is not a programmer,
and does not write about neither programming nor
Java.

He should stick to philosophy and advocacy groups.

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


Re: HTTPS client certificates (was Re: Twill question) (fwd)

2006-05-27 Thread John J Lee
Oops, spot the deliberate misteka ;-)  should have been:

opener = urllib.FancyURLopener(key_file=KEY_FILE,
cert_file=CERT_FILE,
)
r = opener.open()
print r.read()


... which *does* work for me.  Sorry for the noise everybody.


John

On Sat, 27 May 2006, John J Lee wrote:

> Just forwarding this in case anybody here can shed light on this -- urllib's 
> support for SSL client certificates didn't work for me, and I'm wondering if 
> it works for anybody else...
>
>
> John
>
> -- Forwarded message --
> Date: Sat, 27 May 2006 14:33:03 + (UTC)
> From: John J Lee <[EMAIL PROTECTED]>
> To: Wayne Wang <[EMAIL PROTECTED]>, twill@lists.idyll.org
> Subject: HTTPS client certificates (was Re: Twill question)
>
> On Fri, 26 May 2006, Wayne Wang wrote:
> [...wants https client auth...]
>
> OK, I added the necessary boilerplate to mechanize (haven't committed yet), 
> but the basic support for this that comes with Python didn't work for me on a 
> local test server I set up, so I couldn't get it working with mechanize 
> either.
>
> Wayne, and anybody else who uses client certificates and is inclined to help 
> out: could you try running this script, after replacing HTTPS_URL with a URL 
> on the secure site you're trying to access, and KEY_FILE and CERT_FILE with 
> the full filenames where you keep those?
>
> I'm afraid you have to convert the p12 file into separate PEM-format key and 
> cert files using e.g. OpenSSL:
>
> openssl pkcs12 -clcerts -nokeys -in cert.p12 -out cert.pem
> openssl pkcs12 -nocerts -in cert.p12 -out key.pem
>
>
> HTTPS_URL = "https://example.com:443/restricted/foo.html";
> KEY_FILE = r"c:\blah\blah\key.pem"
> CERT_FILE = r"c:\blah\blah\cert.pem"
>
> import urllib
> urllib.URLopener(key_file=KEY_FILE,
>   cert_file=CERT_FILE,
> ) 
> r = urllib.urlopen()
> print r.read()
>
>
> John
>

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


Re: monkeypatching NamedTemporaryFile

2006-05-27 Thread Jason Lunz
[EMAIL PROTECTED] said:
> Maybe that should be the default behaviour.  Presumably the file has
> been deleted by some other process?

The use case is that a NamedTemporaryFile was used to securely create
and populate a file, which is then atomically (on posix) os.rename()d to
its final location.

If any error occurs prior to the rename, NamedTemporaryFile takes care
of deleting the tempfile on the error path. But in the success case,
NamedTemporaryFile causes an unsightly "ignored exception" message on
stderr when it fails to unlink the now-nonexistent tempfile.

Jason

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


Re: PIL problem with biprocessor hardware

2006-05-27 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> oops. lost my train of thought. I was gonna say, I wonder if some of
> these image manipulation routines are using multiple threads?

PIL doesn't use threading by itself, and I know of quite a few PIL-based 
systems running on multi-processor hardware (not to mention multi-core
and hyper-threading systems).

if the posted snippet is all there is, I'd blame it on the hardware ;-)



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


Re: dynamic type changing

2006-05-27 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> I'm working on a "TempFile" class that stores the data in memory until
> it gets larger than a specified threshold (as per PEP 42).  Whilst
> trying to implement it, I've come across some strange behaviour.  Can
> anyone explain this?
> 
> The test case at the bottom starts a TempFile at size 50 and prints its
> type.  It then increases the size to the threshold at which point
> "self" is changed to being a TemporaryFile.

Changed how ?-)

>  It seems that the next
> call correctly uses the write() method of TemporaryFile (since we don't
> see "changing type" in the output).  However, type(tmp) still equals
> TempFile.  Not only that, tmp can still access the method dummy() that
> exists only in TempFile.
> 
> #!/usr/bin/env python
> from StringIO import StringIO
> import tempfile
> 
> class TempFile(StringIO, object):
> """A temporary file implementation that uses memory unless
>either capacity is breached or fileno is requested, at which
>point a real temporary file will be created and the relevant
>details returned
> """
> def __init__(self, buffer, capacity):
> """Creates a TempFile object containing the specified buffer.
> If capacity is specified, we use a real temporary file once the
> 
> file gets larger than that size.  Otherwise, the data is stored
> 
> in memory.
> """
> self.capacity = capacity
> if len(buffer) > capacity:
> self = tempfile.TemporaryFile()

assigning to 'self' in a method doesn't impact the object itself - it 
only rebinds the *local* name 'self' for the rest of the block.

If you want to change the class of an object, you must assign to 
self.__class__ - but, while perfectly legal (and in fact the simplest 
possible implementation of the state pattern in Python), it may be 
somewhat risky.

(snip)
>  def write(self, str):
> self.seek(0, 2)  # find end of file
> if((self.tell() + len(str)) >= self.capacity):
> print "changing type"
> flo = tempfile.TemporaryFile()
> flo.write(self.getvalue())
> self = flo
> print type(self)

Same comment here.

(snip)

Now for a practical solution : what you want is the strategy pattern.


from StringIO import StringIO
from tempfile import TemporaryFile
import sys

class TempFile(object):
 """A temporary file implementation that uses memory unless
either capacity is breached or fileno is requested, at which
point a real temporary file will be created and the relevant
details returned
 """

 _strategies = (StringIO, TemporaryFile)

 def __init__(self, buffer, capacity):
 """Creates a TempFile object containing the specified buffer.

 If capacity is specified, we use a real temporary file once the
 file gets larger than that size.  Otherwise, the data is stored
 in memory.
 """
 self.capacity = capacity
 self._delegate = self._strategies[len(buffer) > self.capacity]()
 self.write(buffer)

 def write(self, value):
 print >> sys.stderr, \
  "about to write %d more characters" % len(value)
 if isinstance(self._delegate, self._strategies[0]):
 len_value = len(value)
 if len_value >= self.capacity:
 needs_new_strategy = True
 else:
 self.seek(0, 2)  # find end of file
 needs_new_strategy = \
   self.tell() + len_value >= self.capacity

 if needs_new_strategy:
 print >> sys.stderr, "changing strategy"
 new_delegate = self._strategies[1]()
 new_delegate.write(self.getvalue())
 self._delegate = new_delegate

 self._delegate.write(value)


 def __getattr__(self, name):
 # Takes care of automatic delegation,
 # customize this according to your needs.
 # Hint : this will only be called if normal lookup
 # failed, so to control access to any _delegate's method,
 # just implement a method with same name
 try:
 return getattr(self._delegate, name)
 except AttributeError:
 # hide the delegation
 e = "object '%s' has no attribute '%s'" \
 % (self.__class__.__name__, name)
 raise AttributeError(e)


if __name__ == "__main__":
 print "testing tempfile:"
 tmp = TempFile("", 100)
 ten_chars = "1234567890"
 tmp.write(ten_chars * 5)
 print "tmp < 100: ", tmp._delegate.__class__.__name__
 tmp.write(ten_chars * 5)
 print "tmp == 100: " , tmp._delegate.__class__.__name__
 tmp.write("the last straw")
 print "tmp > 100: " , tmp._delegate.__class__.__name__
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: groupby

2006-05-27 Thread Paul McGuire
"Paul McGuire" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> So here's how to save the values from the iterators while iterating over
the
> groupby:
>
> >>> m = [(x,list(y)) for x,y in groupby([1, 1, 1, 2, 2, 3])]
> >>> m
> [(1, [1, 1, 1]), (2, [2, 2]), (3, [3])]
>
> -- Paul
>
>

Playing some more with groupby.  Here's a one-liner to tally a list of
integers into a histogram:

# create data set, random selection of numbers from 1-10
dataValueRange = range(1,11)
data = [random.choice(dataValueRange) for i in xrange(10)]
print data

# tally values into histogram:
# (from the inside out:
# - sort data into ascending order, so groupby will see all like values
together
# - call groupby, return iterator of (value,valueItemIterator) tuples
# - tally groupby results into a dict of (value, valueFrequency) tuples
# - expand dict into histogram list, filling in zeroes for any keys that
didn't get a value
hist = [ (k1,dict((k,len(list(g))) for k,g in
itertools.groupby(sorted(data))).get(k1,0)) for k1 in dataValueRange ]

print hist

Gives:
[9, 6, 8, 3, 2, 3, 10, 7, 6, 2]
[(1, 0), (2, 2), (3, 2), (4, 0), (5, 0), (6, 2), (7, 1), (8, 1), (9, 1),
(10, 1)]

Change the generation of the original data list to 10,000 values, and you
get something like:
[(1, 995), (2, 986), (3, 941), (4, 998), (5, 978), (6, 1007), (7, 997), (8,
1033), (9, 1038), (10, 1027)]

If you know there wont be any zero frequency values (or don't care about
them), you can skip the fill-in-the-zeros step, with one of these
expressions:
histAsList = [ (k,len(list(g))) for k,g in itertools.groupby(sorted(data)) ]
histAsDict = dict((k,len(list(g))) for k,g in
itertools.groupby(sorted(data)))

-- Paul


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


Serializing / Unserializing datetime

2006-05-27 Thread Brendan
Hi All

I can't find the "Python Way" of writing a datetime instance to a
string so that it can be easily parsed back again.  time.strptime is
apparantly not supported on some platforms, and time.time <==>
datetime.utcfromtimestamp will cause problems come 2038.  Unfortunately
there don't seem to be "fromstring" equivalents for datetime.ctime or
datetime.isoformat.

Ideally the serialized datetime should be human readable, and
potentially parseable from other languages.  Any suggestions?

  Brendan
--
Brendan Simons

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


How to control color of contour lines?

2006-05-27 Thread Grant Edwards
How do I get contour lines drawn in just one color (e.g. black)?

Multicolored contour lines on top of a pm3d surface can be very
hard to look at...

-- 
Grant Edwards   grante Yow!  Is it 1974? What's
  at   for SUPPER? Can I spend my
   visi.comCOLLEGE FUND in one wild
   afternoon??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to control color of contour lines?

2006-05-27 Thread Grant Edwards
On 2006-05-27, Grant Edwards <[EMAIL PROTECTED]> wrote:
> How do I get contour lines drawn in just one color (e.g. black)?
>
> Multicolored contour lines on top of a pm3d surface can be very
> hard to look at...

Of course I found it right after I posted the question:

 "unset clabel"

-- 
Grant Edwards   grante Yow!  It was a JOKE!! Get
  at   it?? I was receiving
   visi.commessages from DAVID
   LETTERMAN!! YOW!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Array? Please help.

2006-05-27 Thread Dr. Pastor
I need a row of 127 bytes that I will use as a
circular buffer. Into the bytes (at unspecified times)
a mark (0http://mail.python.org/mailman/listinfo/python-list


CLAIM YOUR TWO FREE UNIVERSAL STUDIOS TICKETS!

2006-05-27 Thread Toyagaines



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

Re: Array? Please help.

2006-05-27 Thread Diez B. Roggisch
Dr. Pastor schrieb:
> I need a row of 127 bytes that I will use as a
> circular buffer. Into the bytes (at unspecified times)
> a mark (0 After some time the "buffer" will contain the last 127 marks.
> (A pointer will point to the next byte to write to.)
> What would be the Pythonic way to do the above?
> Thanks for any guidance.

Use a list, use append and slicing on it:


max_size = 10
buffer = []

for i in xrange(100):
 buffer.append(i)
 buffer[:] = buffer[-max_size:]
 print buffer


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


Re: Python - Web Display Technology

2006-05-27 Thread Marco Carvalho
We don't need any proprietary junk to make a nice-look website:
http://www.csszengarden.com

You can navigate in this site with any kind of browser, even graphical
or text-based, like lynx.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to control color of contour lines?

2006-05-27 Thread Grant Edwards
On 2006-05-27, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2006-05-27, Grant Edwards <[EMAIL PROTECTED]> wrote:
>> How do I get contour lines drawn in just one color (e.g. black)?
>>
>> Multicolored contour lines on top of a pm3d surface can be very
>> hard to look at...
>
> Of course I found it right after I posted the question:
>
>  "unset clabel"

And then I realized I posted it to the wrong group.

I shouldn't be workign on a Saturday

-- 
Grant Edwards   grante Yow!  My FAVORITE group
  at   is "QUESTION MARK & THE
   visi.comMYSTERIANS"...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Go "help" the perl list instead Fredrik Lundh

2006-05-27 Thread Bruno Desthuilliers
D H a écrit :
> Fredrik Lundh wrote:
> 
>> vbgunz wrote:
>>
 I have new a list , when it hava large number of values, I wonna to
 delete all the values in it,how to do?
>>>
>>>
>>> something like this will probably help.
>>>
>>> x = [1,2,3,4,5,6,7,8,9]
>>> y = x
>>>
>>> list([x.pop() for z in xrange(len(x))])
>>>
>>> print x, y  # [] []
>>
>>
>> if you don't know how to do things, you don't need to post.
>>
>> if you know why this is about the dumbest way to do what you're doing, 
>> and you're posted this on purpose, you really need to grow up.
>>
>> 
> 
> 
> He already posted before your post that he made a mistake.

Not the same one. Or there are missing posts on my provider's usenet 
service.

> You obviously ignored that and invented some argument that he
> posted with malicious intentions. 

Fredrik may have been a bit harsh, but the fact is that vbgunz's 
solution for clearing a list *is* the dumbest possible - and it should 
be obvious for anyone past CS101. Now since a lot of Python newbies read 
this newsgroup, uncorrected bad answers are far worse than no answer at all.

> That better describes most of
> your thousands of annoying posts.

Fredrik - aka the effbot - is a Python expert, and a major contributor 
here. He's known to be usually very helpful, even for questions that are 
in the Fine Manual or in the FAQs. I'm afraid you can say so. You may 
not like the way he corrected vbgunz - and I'll wholefully agree on this 
- but this last sentence is total bullshit.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a package like PyInstaller

2006-05-27 Thread James Stroud
LittlePython wrote:
> Is it possible when using packages like PyInstaller to create an .exe for
> distribution that parts of the package can bleed out and be left on a system
> when the .exe is executed?
> 
> Thx
> 
> 

Look at innosetup.

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Software Needs Philosophers

2006-05-27 Thread Bruno Desthuilliers
John D Salt a écrit :
> <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]:
> 
> [Snips]
> 
>>Wrong. We live in a paradise of ideas and possibilities well beyond the
>>wildest dreams of only 20 years ago.
> 
> 
> What exciting new ideas exist in software that are both important and 
> cannot be traced back to 1986 or earlier?
>
Make it 1958 FWIW. Yes, the year Lisp was born...

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


Re: Software Needs Philosophers

2006-05-27 Thread Bruno Desthuilliers
John A. Bailo a écrit :
> John D Salt wrote:
> 
>> <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]:
>>
>> [Snips]
>>
>>> Wrong. We live in a paradise of ideas and possibilities well beyond the
>>> wildest dreams of only 20 years ago.
>>
>>
>>
>> What exciting new ideas exist in software that are both important and 
>> cannot be traced back to 1986 or earlier?
> 
> 
> What exciting new ideas exist in software that are both important and 
> cannot be traced back to Doug Engbart's 1968 presentation at Xerox Parc?
> 
Those that can be traced back to 1958 when someone invented Lisp ?-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Software Needs Philosophers

2006-05-27 Thread Bruno Desthuilliers
Paul Rubin a écrit :
> John D Salt  writes:
> 
>>What exciting new ideas exist in software that are both important and 
>>cannot be traced back to 1986 or earlier?
> 
> 
> Automated spamming tools?  ;-)
keyboard !
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Array? Please help.

2006-05-27 Thread George Sakkis
Diez B. Roggisch wrote:
> Dr. Pastor schrieb:
> > I need a row of 127 bytes that I will use as a
> > circular buffer. Into the bytes (at unspecified times)
> > a mark (0 > After some time the "buffer" will contain the last 127 marks.
> > (A pointer will point to the next byte to write to.)
> > What would be the Pythonic way to do the above?
> > Thanks for any guidance.
>
> Use a list, use append and slicing on it:
>
>
> max_size = 10
> buffer = []
>
> for i in xrange(100):
>  buffer.append(i)
>  buffer[:] = buffer[-max_size:]
>  print buffer
> 
> 
> Diez

You're not serious about this, are you ?

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


(mostly-)POSIX regular expressions

2006-05-27 Thread Sébastien Boisgérault
Hi,

I'm searching for a POSIX 1003.2 compatible regular expression engine.
The Python binding "pregex" by Neal Becker may do the job, but I did
not manage to download it as the original link
ftp://ftp.ctd.comsat.com/pub/
seems dead.

Does any old-timer () have a copy of this package ?

Cheers,

SB

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


Re: Array? Please help.

2006-05-27 Thread Scott David Daniels
Dr. Pastor wrote:
> I need a row of 127 bytes that I will use as a
> circular buffer. Into the bytes (at unspecified times)
> a mark (0 After some time the "buffer" will contain the last 127 marks.

Sounds a lot like homework.

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


Re: iterator? way of generating all possible combinations?

2006-05-27 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> Terry Reedy wrote:
>
>>
>> Are the dice identical or distinguishable (marked).  In other words, 
>> with 2
>> dice, is 1,2 the same as 2,1 or different?  Note that in most dice 
>> games,
>> such as craps, the dice are not distinguished, but probability 
>> calculations
>> must treast them as if they were to get the elementary events.
>>
> they are distinct.  This isn't necessarily about simulating a game.  So
> yes the dice are marked and I want to track those different
> possibilties.

Then your dice problem is equivalent to generating all n-digit base-d 
numbers, which is also the n-fold cartesian product of a set with itself. 
Sequential generation amounts to a 'plus-1' operation.

tjr



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


Re: Using a package like PyInstaller

2006-05-27 Thread LittlePython
Thx for the tip.

I am referring more to the use of PyInstaller or py2exe. Packages that
create exe files that basically have your py script and a small py
interpreter all rolled up into one. This way py does not need to be
installed on a system to execute a py script. I am being advised that python
is installed onto systems (windows) it should not be on. I am new to python
and these types of packages and am not too sure how dumb a question this
really is.. but can these packages bleed out files, dll, exe ect. to systems
they are run on?

"James Stroud" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> LittlePython wrote:
> > Is it possible when using packages like PyInstaller to create an .exe
for
> > distribution that parts of the package can bleed out and be left on a
system
> > when the .exe is executed?
> >
> > Thx
> >
> >
>
> Look at innosetup.
>
> -- 
> James Stroud
> UCLA-DOE Institute for Genomics and Proteomics
> Box 951570
> Los Angeles, CA 90095
>
> http://www.jamesstroud.com/


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


Re: Using a package like PyInstaller

2006-05-27 Thread James Stroud
LittlePython wrote:
> Thx for the tip.
> 
> I am referring more to the use of PyInstaller or py2exe. Packages that
> create exe files that basically have your py script and a small py
> interpreter all rolled up into one. This way py does not need to be
> installed on a system to execute a py script. I am being advised that python
> is installed onto systems (windows) it should not be on. I am new to python
> and these types of packages and am not too sure how dumb a question this
> really is.. but can these packages bleed out files, dll, exe ect. to systems
> they are run on?

They don't have to "bleed" anything. Everything, including the python 
interpreter, and 3rd party libraries can be included in a single 
executable. Here is an example script for pyinstaller that rolls 
evertyhing into one file (this is what I use to roll up my passerby 
program at passerby.souceforge.net):


setenv TEMP temp

set pythonexe='c:/Python23-Enthought/python'
set pbydir='z:/Code/pby/current/'

rm *.pyc

rm -rf ./temp/ ./passerby/
mkdir temp

$pythonexe Configure.py
$pythonexe Makespec.py --onefile --tk --noconsole  \
--icon $pbydir/../icons/passerby.ico \
   $pbydir/passerby.py passerby/passerby.spec
$pythonexe Build.py passerby/passerby.spec


You can control installation with innosetup.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANNOUNCE]: typecheck 0.3.5 released

2006-05-27 Thread Collin Winter
Hello all,

I have released version 0.3.5 of my typecheck module, a Python module
providing run-time typechecking facilities for function parameters and
return values, as well as generator yield values.

The main workhorses of this module, the functions accepts, returns and yields,
are used as function/method decorators. These operate on a function
arguments, function return values and generator yield values,
respectively.

A number of utility classes are provided to assist in building more complex
signatures, for example, by creating boolean expressions based on classes
and/or types.

It is possible to incorporate typechecking facilities into user-defined
classes. A mixin class, UnorderedIteratorMixin, is provided to allow easy
typechecking of iterators. Numerous examples are provided as to how to
integrate your own container classes into typecheck.

Where to get it:
#

typecheck is available from the project's website at

http://oakwinter.com/code/typecheck/

and from the Python Package Index at

http://cheeseshop.python.org/pypi/typecheck

Both source tarballs and Python Eggs for Python versions 2.4 and 2.5
are available.

Release Notes


This is a bug-fix release:

+ After fixing an issue with the test suite, typecheck is now
compatible with Python 2.5

+ Compatibility issues:
- Typeclass instances are no longer callable. This means that
"Number() is not Number" is True. This was done to fix a bug
with typeclasses.

+ Bug fixes:
- Add an __all__ list to typecheck/__init__.py
- Instances with __call__ methods can now be used as
functions (ie, in conjunction with Function)
- Unicode can now be used to specify type variables
- Rename all message() methods on the internal _TC_* extensions
to error_message() (Python 2.5's exceptions already have
message attribute)
- Add repr() and str() support to Typeclass instances
- Fix a bug related to typecheck_args()'s checking of the number of
arguments passed to the typechecked function
- Fix SF #1495358; typeclasses can now actually be used.


As always, feedback welcome!

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


Re: Serializing / Unserializing datetime

2006-05-27 Thread John Machin
On 28/05/2006 3:37 AM, Brendan wrote:
> Hi All
> 
> I can't find the "Python Way" of writing a datetime instance to a
> string so that it can be easily parsed back again.  time.strptime is
> apparantly not supported on some platforms, and time.time <==>
> datetime.utcfromtimestamp will cause problems come 2038.  Unfortunately
> there don't seem to be "fromstring" equivalents for datetime.ctime or
> datetime.isoformat.
> 
> Ideally the serialized datetime should be human readable, and
> potentially parseable from other languages.  Any suggestions?
> 
>

It's not that hard to DIY; the simple code at the end of this posting 
(1) handles fractions of a second [which you may or may not want] 
without burdening the network or the readers' eyeballs with excess 
trailing zeroes (2) doesn't handle TZs [which you may or may not want].

Some further validation on input strings may be a good idea, if you need 
to eat other software's strings as well as yours. E.g. check that where 
the '-' characters should be that you find nothing stranger than '.' or 
'/'; certainly not digits.

HTH,
John

8<---
import datetime

def datetime_from_str(s):
 # -MM-DD HH:MM:SS.TTT
 # 01234567890123456789012
 year = int(s[0:4])
 month = int(s[5:7])
 day = int(s[8:10])
 hour = int(s[11:13])
 minute = int(s[14:16])
 microseconds = int(float(s[17:]) * 100.0)
 second, microsecond = divmod(microseconds, 100)
 return datetime.datetime(year, month, day, hour, minute, second, 
microsecond)

def datetime_as_str(dtm):
 part1 = dtm.strftime("%Y-%m-%d %H:%M:%S")
 micros = dtm.microsecond
 if not micros:
 return part1
 part2 = (".%06d" % micros).rstrip('0')
 return part1 + part2

if __name__ == "__main__":
 tests = [
 '1999-12-31 23:59:59.99',
 '1999-12-31 23:59:59.',
 '1999-12-31 23:59:59.999',
 '1999-12-31 23:59:59',
 '2000-01-01 00:00:00.000',
 '2000-01-01 00:00:00',
 '2000-01-01 00:00:00.01',
 '2000-01-01 00:00:00.001',
 ]
 for test in tests:
 dtm = datetime_from_str(test)
 print "input str: ", repr(test)
 print "datetime:  ", repr(dtm)
 round_trip = datetime_as_str(dtm)
 print "output str:", repr(round_trip), ["not same", 
""][round_trip == test]
 print
8<---

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


Re: Using a package like PyInstaller

2006-05-27 Thread LittlePython
That is very close to what I have being doing, however I was unable to
enclose a bmp or another file for that matter in the exe. I used both DATA
and BINARY key words with no luck. I checked what was in the package and
there were there. I guess for some reason it could not locate then when
executed. I used snap 274 if I remember correctly.

I am not too sure I am explaining my question correctly though. I have not
problem creating and distributing my python/wxpython scripts in exe
(stand-a-lone) except for what I have described above. I am worrying that
when the py script is run I am leaving behind files. That the components of
my stand-alone exe is somehow coming out of the exe (PyInstaller) and being
installed.

My setup exe is not what's is bothering me although I do like the your
suggestion and have just been tinkering with it. It is cool  stuff and much
better then what I have been using.

Thx

"James Stroud" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> LittlePython wrote:
> > Thx for the tip.
> >
> > I am referring more to the use of PyInstaller or py2exe. Packages that
> > create exe files that basically have your py script and a small py
> > interpreter all rolled up into one. This way py does not need to be
> > installed on a system to execute a py script. I am being advised that
python
> > is installed onto systems (windows) it should not be on. I am new to
python
> > and these types of packages and am not too sure how dumb a question this
> > really is.. but can these packages bleed out files, dll, exe ect. to
systems
> > they are run on?
>
> They don't have to "bleed" anything. Everything, including the python
> interpreter, and 3rd party libraries can be included in a single
> executable. Here is an example script for pyinstaller that rolls
> evertyhing into one file (this is what I use to roll up my passerby
> program at passerby.souceforge.net):
>
>
> setenv TEMP temp
>
> set pythonexe='c:/Python23-Enthought/python'
> set pbydir='z:/Code/pby/current/'
>
> rm *.pyc
>
> rm -rf ./temp/ ./passerby/
> mkdir temp
>
> $pythonexe Configure.py
> $pythonexe Makespec.py --onefile --tk --noconsole  \
> --icon $pbydir/../icons/passerby.ico \
>$pbydir/passerby.py passerby/passerby.spec
> $pythonexe Build.py passerby/passerby.spec
>
>
> You can control installation with innosetup.
>
> James
>
> -- 
> James Stroud
> UCLA-DOE Institute for Genomics and Proteomics
> Box 951570
> Los Angeles, CA 90095
>
> http://www.jamesstroud.com/


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


Re: Pyrex speed

2006-05-27 Thread John Machin
On 28/05/2006 12:10 AM, Gonzalo Monzón wrote:

[good advice snipped]

> 
> Example A:
> This code is more than 80 times faster than a "easy" Python 
> implementation. For every call, it does some bitwise operations and does 
> an array lookup for every string character from argument. Its a lot 
> faster because in Python approach a list lookup is done and it is a lot 
> faster to do a C array lookup -thought that in these C loops no Python 
> type value conversions are needed, if it where the case, C approach 
> would not be so faster than python. I don't know how would perform an 
> array based Python code, but I expect it to be a lot faster than using a 
> list, so Python code can be speed up a lot if you know how to do it.
> 
> // C code:
> int CRC16Table[256]; // Filled elsewhere
> int CalcCRC16(char *str)
> {
>int crc;
>  for(crc = 0x; *str != 0; str++) {
>crc = CRC16Table [(( crc >> 8 ) & 255 )] ^ ( crc << 8 ) ^ *str;

Gonzalo, just in case there are any C compilers out there which need to 
be told:

 >  for(crc = 0x; *str != 0;) {
 >crc = CRC16Table [(( crc >> 8 ) & 255 )] ^ ( crc << 8 ) ^ *str++;


>}
>  return crc;
> }
> 
> # Python code
> gCRC16Table = [] # Filled elsewhere
> def CalcCRC16(astr):
>crc = 0xL

Having that L on the end (plus the fact that you are pointlessly 
maintaining "crc" as an *unsigned* 32-bit quantity) will be slowing the 
calculation down -- Python will be doing it in long integers. You are 
calculating a *sixteen bit* CRC! The whole algorithm can be written 
simply so as to not need more than 16-bit registers, and not to pollute 
high-order bits in 17-or-more-bit registers.

>for c in astr:
>crc = gCRC16Table[((crc >> 8) & 255)] ^ ((crc & 0xFF) << 8) ^ 
> ord(c)

Note that *both* the C and Python routines still produce a 32-bit result 
with 16 bits of high-order rubbish -- I got the impression from the 
previous thread that you were going to fix that.

This Python routine never strays outside 16 bits, so avoiding your "& 
255" and a final "& 0x" (which you don't have).

def CalcCRC16(astr):
 crc = 0x
 for c in astr:
 crc = gCRC16Table[crc >> 8] ^ ((crc & 0xFF) << 8) ^ ord(c)
 return crc

==
To the OP:

I'd just like to point out that C code and Pyrex code can gain 
signicantly (as the above example does) by not having to use ord() and 
chr().

As Gonzalo says, read the generated C code. Look for other cases of 
using Python built-ins that could be much faster with a minor bit of 
effort in Pyrex e.g. "max(a, b)" -> "(a) > (b) ? (a) : (b) " or if you 
don't like that, a cdef function to get the max of 2 ints will be *way* 
faster than calling Python's max()
-- 
http://mail.python.org/mailman/listinfo/python-list


run time linked attributes

2006-05-27 Thread michael . murr
I've read a few posts about how to have attributes that are "linked" at
run time.  I've created a (simple) Python metaclass that accomplishes
this with some behind-the-scenes __init__ redirection.  I'm posting the
code at the end in case anyone is interested.

Problem background:
Object a (an instance of class A) has an attribute that points to
object b (which is an instance of class B).  So A's __init__ might look
something like this:
__init__(self):
   self.b = B(arg1, arg2, arg3)

The catch is, that instances of B() need to reference other attributes
of A.  The traditional way to do this is pass the instance of A as a
parameter to B.  So B's __init__ might look something like:
__init__(self, creator, arg1, arg2, arg3):
   self.creator = creator;

naturally, A's __init__ would now look something like:
__init__(self):
   self.b = B(self, arg1, arg2, arg3)

Essentially this creates two links:
a = A();
a.b --> b
a.b.creator -> a

To hide the passing of the reference to the parent/creator, the
metaclass below adds a method MakeLinkedAttribute.

To hide the handling of the reference to the parent/creator, the
metaclass below redirects B's __init__ when the class object is
created, inserting a call to Meta__init__, which handles the processing
of the parent/creator element.  The original __init__ is then called.
See the module's docstring for an example...

I'm curious to hear feedback about the code, especially any dangers
that can occur from redirecting/hijacking __init__.

Cheers!

LinkedAttribute.py:
""" Metaclass for making linked attributes

The LinkedAttribute class allows you to (at run time) have objects
that have references back to the object that created them.

Any class that has LinkedAttribute as it's metaclass will have a
MakedLinkedAttribute() method to make linked attributes.

To accomplish this hackery, we use the metaclass to hijack the
__init__
method, replacing it with our own.  The new __init__ method (defined
as
Meta__init__) sets up the _creator attribute (if it was passed in) and
then
calls the original __init__ function.  The original __init__ function
gets
renamed to _old__init__.  The reason for including the
class name
in the first part of the redefinition is so that sub classes that call
super(...).__init__ won't enter an infinite loop.


The restriction to using this metaclass is that the classes that you
call
MakeLinkedAttribute on must also have LinkedAttribute as a metaclass.

If you use this metaclass, make sure to give credit where credit is
due :)
(e.g. in a comment or docstring)

There are other ways of solving the same problem (including passing
the
parent to __init__ explicitly).


The software is provided AS IS, use this software at your own risk.
There
is no warranty.  By using this software you agree to hold the
author(s)
harmless of any damage whether direct, incidental, consequently and
otherwise.  In no event shall the author(s) of this code be liable for
any
damages whatsoever incurred by this code.

(c) 2006 Michael Murr [mmurr at code-x d0t net]


e.g.:
-

from LinkedAttribute import LinkedAttribute

class a(object):
def __init__(self):
self.linked_b = self.MakeLinkedAttribute(b, "this is a 
linked b")
self.plain_b = b("this is a plain b")

__metaclass__ = LinkedAttribute

class b(object):
def __init__(self, text):
self.text = text
if hasattr(self, "_creator"):
print "I have a creator!"
else:
print "I am a standalone!"

__metaclass__ = LinkedAttribute

if __name__ == "__main__":
objectA = a()
objectB = b("created directly")

print objectA.linked_b.text
print objectA.plain_b.text
print objectB.text



yields:
---

I have a creator!
I am a standalone!
I am a standalone!
this is a linked b
this is a plain b
created directly

"""

class LinkedAttribute(type):
def __new__(klass, klassName, klassBases, klassDict):
# Method to make a new linked child
def MakeLinkedAttribute(self, childClass, *args, **kwds):
return(childClass(_creator=self, *args, **kwds))
# MakeLinkedAttribute(self, childClass, *args, **kwds):

# Run time hijacking of __init__ so we can make
# a _creator BEFORE the original __init__ is called
#
# We use klassName + "_hijacked__init__" so sub classes
# who call super(...).__ini

Re: linking errors with debug build of Python2.4.3

2006-05-27 Thread [EMAIL PROTECTED]
Martin Wiechert wrote:
> Hi list,
>
> I've created a fresh build of Python 2.4.3 using the following configuration
>
> $ ./configure --with-pydebug --prefix=/usr/local/debug --enable-shared
> --with-fpectl --with-signal-module
>
> What did I do wrong?

Try with just:  ./configure --with-pydebug --prefix=/usr/local/debug

I think the problem is --enable-shared.  I'm not sure what you are
doing, but you probably don't need the other options.  The signal
module should always be built, I've never even seen the
--with-signal-module option. :-)

n

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


Re: Pyrex speed

2006-05-27 Thread Gonzalo Monzón
Hi John,

John Machin escribió:

>On 28/05/2006 12:10 AM, Gonzalo Monzón wrote:
>
>[good advice snipped]
>
>  
>
>>Example A:
>>This code is more than 80 times faster than a "easy" Python 
>>implementation. For every call, it does some bitwise operations and does 
>>an array lookup for every string character from argument. Its a lot 
>>faster because in Python approach a list lookup is done and it is a lot 
>>faster to do a C array lookup -thought that in these C loops no Python 
>>type value conversions are needed, if it where the case, C approach 
>>would not be so faster than python. I don't know how would perform an 
>>array based Python code, but I expect it to be a lot faster than using a 
>>list, so Python code can be speed up a lot if you know how to do it.
>>
>>// C code:
>>int CRC16Table[256]; // Filled elsewhere
>>int CalcCRC16(char *str)
>>{
>>   int crc;
>> for(crc = 0x; *str != 0; str++) {
>>   crc = CRC16Table [(( crc >> 8 ) & 255 )] ^ ( crc << 8 ) ^ *str;
>>
>>
>
>Gonzalo, just in case there are any C compilers out there which need to 
>be told:
>
> >  for(crc = 0x; *str != 0;) {
> >crc = CRC16Table [(( crc >> 8 ) & 255 )] ^ ( crc << 8 ) ^ *str++;
>  
>
Thank you for the advise! I didn't know you couldn't advance pointer in 
the for in some compilers...

>
>  
>
>>   }
>> return crc;
>>}
>>
>># Python code
>>gCRC16Table = [] # Filled elsewhere
>>def CalcCRC16(astr):
>>   crc = 0xL
>>
>>
>
>Having that L on the end (plus the fact that you are pointlessly 
>maintaining "crc" as an *unsigned* 32-bit quantity) will be slowing the 
>calculation down -- Python will be doing it in long integers. You are 
>calculating a *sixteen bit* CRC! The whole algorithm can be written 
>simply so as to not need more than 16-bit registers, and not to pollute 
>high-order bits in 17-or-more-bit registers.
>
>  
>
Yes I know but I plan to post a quick example for Jim, and got the first 
one file from several versions... :-) The issue was about Jim 
understanding how some code can be speed-up a lot and some other not and 
how that's not a trivial question.

>>   for c in astr:
>>   crc = gCRC16Table[((crc >> 8) & 255)] ^ ((crc & 0xFF) << 8) ^ 
>>ord(c)
>>
>>
>
>Note that *both* the C and Python routines still produce a 32-bit result 
>with 16 bits of high-order rubbish -- I got the impression from the 
>previous thread that you were going to fix that.
>  
>
Yes of course! I plan to spend some time on this issue, the last week I 
had not much time to work on this, but  thought it worth the pain to 
setup a compiling environment -ms.evc++ obviously-, and got succesfuly 
compiled Python and some of these own custom Pyrex extensions for the 
PocketPC, easily, only adding the C files to makefile, as Pyrex glue 
code compiles well on ARM, so I have to make some timings and decide 
what version to use for the code that won't be likely to be changed in 
long time. I still have to test the last improved Python array based 
approach and make some timings on the PDA.

>This Python routine never strays outside 16 bits, so avoiding your "& 
>255" and a final "& 0x" (which you don't have).
>
>def CalcCRC16(astr):
> crc = 0x
> for c in astr:
> crc = gCRC16Table[crc >> 8] ^ ((crc & 0xFF) << 8) ^ ord(c)
> return crc
>  
>
Thank you again for your thoughts John! :-)

Regards,
Gonzalo

>==
>To the OP:
>
>I'd just like to point out that C code and Pyrex code can gain 
>signicantly (as the above example does) by not having to use ord() and 
>chr().
>
>As Gonzalo says, read the generated C code. Look for other cases of 
>using Python built-ins that could be much faster with a minor bit of 
>effort in Pyrex e.g. "max(a, b)" -> "(a) > (b) ? (a) : (b) " or if you 
>don't like that, a cdef function to get the max of 2 ints will be *way* 
>faster than calling Python's max()
>  
>

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


Re: Looking for triangulator/interpolator

2006-05-27 Thread Travis E. Oliphant
Grant Edwards wrote:
> On 2006-05-27, Travis E. Oliphant <[EMAIL PROTECTED]> wrote:
> 
>> Not that you made a bad choice.  I do wonder, how much of your
>> difficulty was with the interface to the underlying fitpack
>> routines.
> 
> I've no idea.  I had never done anything with splines before,
> so it's quite possible I just wasn't doing things right.  I
> never got it to work at all for non-gridded data (which is what
> I needed).  Since it wasn't stable even for gridded data, I
> more or less gave up.
> 
>> The interface is pretty involved as there are lots of
>> parameter choices to the underlying routine.  It's very
>> possible the interface is broken in some strange way.
> 
> I took a look at underlying Fortran code, but that made my
> dizzy.

Just to finish this thread, I should mention I spent some time yesterday 
looking into the details of the underlying surfit fucntion used by 
bisplrep.  It appears to have difficulties when s=0 is used.  It seems 
to be geared toward smoothing applications where you are trying to fit 
"noisy" scattered data to a smooth function.There are many warnings 
about choosing s to be too low.

Thus, trying to use bisplrep for interpolation (instead of data 
smoothing) is probably going to be difficult with bisplrep.

We still need a good N-d re-gridding algorithm in SciPy.

-Travis


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


Best way to check that a process is running on a Unix system?

2006-05-27 Thread Arthur Pemberton
Hello list,

What is the best way to check that a process is running (or better yet
number of instances) based on the name of the process? Would have to
work on a unix/linux system.

Thank you.

-- 
To be updated...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to check that a process is running on a Unix system?

2006-05-27 Thread BJörn Lindqvist
> What is the best way to check that a process is running (or better yet
> number of instances) based on the name of the process? Would have to
> work on a unix/linux system.

Use "ps -C proc_name". Then either read the nr of lines in the output
(for the number of instances) or read the return value. 0 if the
process is running. Or read the /proc/*/status files and check if your
process is in any of them.

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a package like PyInstaller

2006-05-27 Thread James Stroud
LittlePython wrote:
> That is very close to what I have being doing, however I was unable to
> enclose a bmp or another file for that matter in the exe. I used both DATA
> and BINARY key words with no luck. I checked what was in the package and
> there were there. I guess for some reason it could not locate then when
> executed. I used snap 274 if I remember correctly.

You can include files with innosetup under the [FILES] section. The docs 
show how. You can then code absolute paths to these resources in your 
code according to the results of 'sys.platform'. If you use the 
"--onedir" option, then you may want to look here:

http://pyinstaller.hpcf.upr.edu/docs/Manual_v1.1.html#accessing-data-files


> I am worrying that
> when the py script is run I am leaving behind files. That the components of
> my stand-alone exe is somehow coming out of the exe (PyInstaller) and being
> installed.

Im 99.999% confident that this will not happen from the .exe file 
generated by pyinstaller (unless you specify--see link above).

However, innosetup will put files in the 'Program Files' directory or 
wherever you specify. This would be similar to just about every other 
application out there for windows.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: send an email with picture/rich text format in the body

2006-05-27 Thread anya
Acctualy there is a solution:
see  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473810
(thanks darrin massena for sharing)

and , if you will set all the neccessary parametrs, it won't be
recognized as a
spam, 
thanks

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