[ANN] pysqlite 2.0.alpha3

2005-04-23 Thread Gerhard Haering
===
pysqlite 2.0.alpha3
===

I'm glad to announce pysqlite 2.0.alpha3, which will be the last alpha
release.  Documentation and more testing will be what I'm concentrating
on in the beta test phase, so here's the explanation of the new features
within the change log.

Download it from Sourceforge:
http://sourceforge.net/project/showfiles.php?group_id=54058

Changes since 2.0.alpha2


- Fixed various memory leaks and refcount problems.

- Connection, Cursor and row factories.

o Connection factory: Subclass pysqlite2.dbapi2.Connection and
provide the parameter to pysqlite2.dbapi2.connect to use that class
instead.

o Cursor factory: Subclass pysqlite2.dbapi2.Cursor and provide the
parameter to the cursor() method of the Connection class so that
cursors of your class are created.

o Row factory: set the row_factory attribute in your cursor to a
callable that accepts a tuple and returns the real row object.

Combine the three for maximimal power and convenience like in the
following example, where we transparently use the db_row module from
http://opensource.theopalgroup.com/ to be able to access columns by
name instead of by index. A fast alternative to PgResultSet in
pysqlite 1.x.

from pysqlite2 import dbapi2 as sqlite
import db_row

class DbRowConnection(sqlite.Connection):
def __init__(self, *args, **kwargs):
sqlite.Connection.__init__(self, *args, **kwargs)

def cursor(self):
return DbRowCursor(self)

class DbRowCursor(sqlite.Cursor):
def execute(self, *args, **kwargs):
sqlite.Cursor.execute(self, *args, **kwargs)
if self.description:
self.row_factory = db_row.IMetaRow(self.description) 

con = sqlite.connect(:memory:) #, factory=DbRowConnection)
cur = con.cursor(factory=DbRowCursor)
cur.execute(create table test(i integer))
cur.execute(select 4+5 as foo)
for row in cur:
print , row
print row[foo]
print cur.fetchone()[foo]

- The first parameter to .execute() and .executemany() can now also be a
  Unicode string:

  cur.execute(uinsert into person(name) values ('Häring'))

- The conversion in SQLite types mode for TEXT is now unicode, not UTF-8
  encoded bytestrings.

  i. e. if the column type is TEXT, then you get back unicode objects now.

- Implemented user functions and aggregates.

Where a number of parameters is expected, -1 means variable number
of arguments.

The functions and aggregates must return values of the type NoneType, int,
float, str, unicode or buffer (BLOB).

Example code:

def f(*args):
return sum(args)

class Sum:
def __init__(self):
self.sum = 0

def step(self, x):
self.sum += int(x)

def finalize(self):
return self.sum


con = sqlite.connect(:memory:)

# Syntax: function name, number of parameters, callable
con.create_function(myfunc, -1, f)

# Syntax: aggregate name, number of parameters, aggregate class
con.create_aggregate(myaggr, 1, Sum)

- Added MANIFEST.in file, so that bdist_rpm and sdist will work.

- Release GIL during SQLite calls.

- After a cursor.executemany, cursor.rowcount now delivers the sum of all
  changes, not only the changes in the last call to the prepared statement.


- Implemented checks that the SQLite objects are used from the same
  thread they were created in. Otherwise raise a ProgrammingError.

  If you're 100% sure that you want to use the same connection object in
  multiple threads, because you use proper locking, you can turn the
  check of by using the parameter ''check_same_thread=0''.

- Allow for parameters to be dictionaries, too. Then, the name-based
  binding in SQLite 3 is used:

cur.execute(select name from test where name=:name, {name: foo})


- Improved error handling.

- Allow for explicit transaction start:

 con = sqlite.connect(:memory:, no_implicit_begin=True)
...
 con.begin()
...
 con.rollback()
...
 con.commit()

- Implemented cursor.lastrowid

- Avoid code duplication: handle execute() and executemany() internally
  in the same function.



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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


ANN: Vampire 1.6, an extension module for mod_python.

2005-04-23 Thread grahamd
Vampire 1.6 is now available.

   http://www.dscpl.com.au/projects/vampire

   http://www.dscpl.com.au/downloads/vampire-1.6-20050422.tar.gz

Vampire is an extension module for mod_python, which provides a more
flexible dispatch mechanism for basic content handlers, as well as an
alternative implementation of the mod_python.publisher module. A range
of other useful features are also provided which make using mod_python
a much more pleasant experience.

For a quick overview of the features that Vampire provides check out:

  http://www.dscpl.com.au/projects/vampire/articles/vampire-001.html

For a full list of changes in this new version check out:

  http://www.dscpl.com.au/projects/vampire/changes.html

A couple of bugs have been fixed in this version, along with some new
features and improvements. The supplied example of how to use
mod_python/Vampire with Cheetah templates has also been improved.

Problems fixed include a bug in the module import mechanism which was
causing thread lockups when import modules were doing sub imports and
the system was heavily loaded with requests against the
same resource. Plus changes to allow Digest or other forms of
authentication to be carried out by Apache and not have Vampire get in
the way by throwing back a bad request error due to not knowing
anything about that specific authentication type.

Most significant new feature is a way of overriding login
authentication and access hooks so that an alternate mechanism to Basic
authentication can be used. This allows for example a session based
mechanism using a web form for login to be easily used.

Enjoy.

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


ANN: Urwid 0.8.7

2005-04-23 Thread Ian Ward
Announcing Urwid 0.8.7
--

Urwid home page:
  http://excess.org/urwid/

Tarball:
  http://excess.org/urwid/urwid-0.8.7.tar.gz
or:
  https://excess.org/urwid/urwid-0.8.7.tar.gz


Summary:


This release adds a number of new widget classes as well as feature
enhancements for existing widget classes.  It also comes with a new 
example program similar to the dialog(1) command.


New in this release:


  - New widget classes: Button, RadioButton, CheckBox.
  
  - New layout widget classes: Padding, GridFlow.

  - New dialog.py example program that behaves like dialog(1) command.

  - Pile widgets now support selectable items, focus changing with up and
down keys and setting the cursor position.
  
  - Frame widgets now support selectable items in the header and footer.

  - Columns widgets now support fixed width and relative width columns, a
minimum width for all columns, selectable items within columns containing
flow widgets (already supported for box widgets), focus changing with
left and right keys and setting the cursor position.

  - Filler widgets may now wrap box widgets and have more alignment options.

  - Updated tour.py example program to show new widget types and features.

  - Avoid hogging cpu on gradual window resize and fix for slow resize 
with cygwin's broken curses implementation.

  - Fixed minor CJK problem and curs_set crash under MacOSX and Cygwin.

  - Fixed crash when deleting cells in calc.py example program.


About Urwid
===

Urwid is a curses-based UI library for Python. It features fluid 
interface resizing, CJK support, multiple text layouts, simple 
attribute markup, powerful scrolling list boxes, flexible edit boxes
and HTML screen shots.


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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


BayPIGgies: May *THIRD* Thursday at Google (May 19)

2005-04-23 Thread Aahz
Pre-announcement:

Our May meeting will be the *THIRD* Thursday, May 19.  We will *NOT* be
meeting the *SECOND* Thursday.  This will be our first meeting at Google,
with Alex Martelli's presention on design patterns.  More details later!
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code -- 
not in reams of trivial code that bores the reader to death.  --GvR
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Open Source Training Course Dates Database

2005-04-23 Thread Mark Pratt
Hi,
opensourcexperts.com now features a Database for finding Open Source  
related course dates.
Here are some views for those interested in Python, Zope, Plone related  
training.

Here is the current listing of all Python Training Course dates in 2005:
http://www.opensourcexperts.com/Training/list.html? 
Filter_CatID=7Filter_month=0

Here is the current listing of all Zope Training Course dates in 2005:
http://www.opensourcexperts.com/Training/list.html? 
Filter_CatID=1Filter_month=0

Here is the current listing of all Plone Training Course dates in 2005:
http://www.opensourcexperts.com/Training/list.html? 
Filter_CatID=2Filter_month=0

Are you doing Open Source related training in 2005? Please list course  
dates in the database.
It's free.

Cheers,
Mark
--
http://mail.python.org/mailman/listinfo/python-announce-list
   Support the Python Software Foundation:
   http://www.python.org/psf/donations.html


Frog 1.4 (web log aka blogging server)

2005-04-23 Thread Irmen de Jong
I've released a new version of Frog, a web log
aka blogging server written in 100% python.
Get version 1.4 from http://snakelets.sourceforge.net/frog/index.html
(note: storage file format has been changed since v1.3)
Some of the more interesting features are:
- multi user
- no database needed (uses files for storage)
- no web server needed (it runs in Snakelets,
   which has its own web server)
- splitted articles (read more...)
- email notification when comment is added
- formatting similar to 'bbcode', supports images and other files
- anti-spam measures: puzzles, auto-updating link blacklist,
  anti-indexing hyperlinks in comments (rel=nofollow)
- outputs lean xhtml+css pages
- fully unicode compatible
- web-based file manager, available as separate module
Have fun :)
--Irmen
PS You can see Frog in action here:
http://www.razorvine.net/snake/frog/user/irmen/
--
http://mail.python.org/mailman/listinfo/python-announce-list
   Support the Python Software Foundation:
   http://www.python.org/psf/donations.html


Re: trying to read from dying disk

2005-04-23 Thread Mike Meyer
[EMAIL PROTECTED] writes:

 I have a python file that is trying to read raw data from a raw
 partition on a dying dist, eg

   f = file('/dev/sda')
   f.seek(SOMEWHERE)
   s = f.read(SOMEBYTES)

 On some blocks, the read succeeds, on others it fails and an IOError is
 thrown, and on others it appears to hang indefinitely and will not
 respond to any attempt to kill it with 'kill -9 PID', etc.

 Is there anyway to do a timeout read on this kind of file, or even to
 kill the process once it hangs?

 linux kernel 2.6.10
 python 2.4.1

Don't do this in Python. Dealing with flaky hardware is a maintenance
problem, and applications should report the error, and either exit or
proceed as best as possible after the error.

Use the dd command to extract as much good data as you can from the
failing disk.

Ok, if you *really* want to do this in Python, the answer is - you
need to provide more information. For instance, *where* does the
process hang? It's possible you've hung the process in an
uninterruptible state in the kernel. If so, you're screwed. You need
to find out where the process hangs (kernel, libc, python, etc.), and
if in the kernel what it's waiting on. In the latter case, you need to
ask on a Linux list.

mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Overiding error message when using a python program

2005-04-23 Thread Brian van den Broek
Sion Arrowsmith said unto the world upon 2005-04-22 13:00:
Brian van den Broek  [EMAIL PROTECTED] wrote:
you've not included the part of your code which acts on the 
user's input.

I think you'll find the answer to the question of where the code
that acts on the user's input lies here:

(And your prompt_user function should use raw_input and 
return the user input for processing by other functions. raw_input is 
safer; input executes arbitrary code.)

Quite so  :-[   I think I must have typed the two parts which you 
quote with different hands, because obviously my brain didn't manage 
to see them both at once.

Thanks for pointing that out.
Best,
Brian vdB
--
http://mail.python.org/mailman/listinfo/python-list


Spamming nut won't go away

2005-04-23 Thread Johnny Gentile
There is no God. OK, Ron, discuss.
Ron wrote:
 Reports to [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED],
 [EMAIL PROTECTED], [EMAIL PROTECTED]
 
 And do not feed the troll!

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


Re: Confusing: Canvas image working in function but not in class

2005-04-23 Thread Mudcat
I will answer my own question in case anyone else ever has this
problem.

I knew the problem (although some say it's not) existed with the
namespace of pictures, that if you didn't save the pictures in
persistent memory they would disappear as soon as the function that
called them was exited. So a while ago I went through this and fixed it
by saving all my pictures and widgets that held them as class objects.

However, apparently I was causing the same thing to happen by not
saving the class instance as an object of the class that called it. So
this fixed it:

def uts5100(self):
self.sys5100 = UTS5100( self.master )

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


Re: Python licence again

2005-04-23 Thread Robert Kern
John Machin wrote:
On Fri, 22 Apr 2005 17:26:19 -0700, Robert Kern [EMAIL PROTECTED]
wrote:

While you can, sort of, and people have already pointed out the 
appropriate web page to you, I ask that you *don't* use the PSF License. 
The PSF License uses proper nouns that you will have to change[1].

and don't forget the pronouns  ... 

Seen in a too-hasty copy-paste-edit of the BSD licence:
IN NO EVENT SHALL person's name suppressed OR ITS CONTRIBUTORS BE
LIABLE ...
Yes, I think I've been guilty of that from time to time, too.
--
Robert Kern
[EMAIL PROTECTED]
In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die.
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


Python Imaging Library and PyGTK - color image path?

2005-04-23 Thread Jeremy Bowers
I have an image in the Python Image Library. I'm trying to get it into
PyGTK in color. Is there any way to do this cross-platform, preferably
without writing to anything to the disk?

PIL apparently can't write XPMs. GTK will only take XPMs, that I can see.
Therein lies the rub. I can ship over monochrome bitmaps via XBM, but I'd
rather be able to ship over full color.

(Use case, in case it matters: I am trying to embed a graphic into a text
widget. This is going fine. Because I want the text widget to be able use
different size text, and no one image can look right with everything from
8pt to 40pt text (all reasonable possibilities), I load a large image in
from the disk and scale it down as needed; the images are designed to
scale well and later I can make multiple source images if that is
desirable. But I can't figure out how to get the scaled image into GTK.
This surprises me.)

If there's an easy Google search, it has eluded me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python classes/file structure

2005-04-23 Thread Terry Hancock
On Thursday 21 April 2005 08:48 am, codecraig wrote:
 widget = gui.MyCustomWidget.MyCustomWidge()
 
 ...seems weird, how should I structure this?  Is it not common to have
 one class in a .py?

No, it isn't really. Usually, there will be several related classes in a single
module.  Only if the classes get really large would I bother to separate
them out into separate files.  One class per module is perlthink. ;-)

Someone has already mentioned using __init__.py to control how your
classes are assembled into the package namespace.

You should also be aware that:

from gui.MyCustomWidget import MyCustomWidget

is a pretty common idiom too.

Cheers,
Terry


--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: grouping subsequences with BIO tags

2005-04-23 Thread Steven Bethard
Michael Spencer wrote:
Steven Bethard wrote:
Bengt Richter wrote:
On Thu, 21 Apr 2005 15:37:03 -0600, Steven Bethard 
[EMAIL PROTECTED] wrote:

I have a list of strings that looks something like:
   ['O', 'B_X', 'B_Y', 'I_Y', 'O', 'B_X', 'I_X', 'B_X']
[snip]
With error checks on predecessor relationship,
I think I'd do the whole thing in a generator,
I'm curious why you (Bengt or Steve) think the generator is an advantage 
here. As Steve stated, the data already exists in lists of strings.

The direct list-building solution I posted is simpler, and quite a bit 
faster.
Aren't they basically just the same solution, with your stack.append 
replaced by a yield (and with a little additional error checking)?  As 
far as I'm concerned, either solution is great and writes the code that 
I couldn't. ;)

If you're still interested, in the real problem, the data doesn't exist 
as a list of strings; it exists as a list of objects for which there is 
a Python wrapper to a C API that retrieves the string.  I don't know 
exactly what happens in the wrapping, but it's possible that I can 
conserve some memory by using the generator function.  But I'd have to 
profile it to know for sure.

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


Re: a=[ lambda t: t**n for n in range(4) ]

2005-04-23 Thread Terry Hancock
On Friday 22 April 2005 06:44 pm, Scott David Daniels wrote:
 Terry Hancock wrote:
  On Friday 22 April 2005 05:18 pm, [EMAIL PROTECTED] wrote:
  
  Perhaps you don't know how to call such functions?  E.g.:
  a=[ lambda t: t**n for n in range(4) ]
 a[2](3)
  27
 
 Didn't you notice this was a funny value?

Nope. Wasn't paying attention. ;-)

Just copied the code from the OP.

 Perhaps you mean:
   a = [lambda t, n=n: t**n for n in range(4)]

This is of course what he should've written, and/or what I
should've corrected it to, thank you. 

Cheers,
Terry


--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


rudeness was: Python licence again

2005-04-23 Thread Michael . Coll-Barth
Laszlo,

 Is it something like 'center' or 'color' for Americans and 'centre' or
'colour' for British people?

Yes, exactly.  

 (Sorry to be offtopic)

No need to apologize.  I started to read the postings on this list and was
dismayed at the depth of rudeness on here.  I thought that pythonistas might
be a little more patient/tolerant.  I guess I was wrong.  I understood
exactly what you wanted to say, I just didn't have an answer.  I did find it
amusing that the person who incorrectly corrected you, was in fact,
incorrect.  

I wonder, how many others out there find that the documentation and
references materials seem to be written for someone that already knows the
answer, but are indecipherable, at times, for those that don't know the
answer.

thanks,
Michael
___
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

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


Re: a=[ lambda t: t**n for n in range(4) ]

2005-04-23 Thread Terry Hancock
On Friday 22 April 2005 05:18 pm, [EMAIL PROTECTED] wrote:
 Thanx for your replies.
 
 I'm looking for array of functions.
 Something like a=[ sin(x) , cos(x) ]

You had a list of lambda functions in your first post and in the
subject line still. How is that not what you wanted?

If you want an *answer*, you need to ask a *question*. 

Perhaps you don't know how to call such functions?  E.g.:

a=[ lambda t: t**n for n in range(4) ]

 a[2](3)
27

If you want to see *names* for the functions, you have two
choices: either used named functions, 

def unity(t): return 1
def identity(t): return t
def square(t): return t**2
def cube(t): return t**3
a = [unity, identity, square, cube]

 a
[function unity at 0x401e609c, function identity at 0x401e6b54,
function square at 0x401e6b8c, function cube at 0x401e6ca4]

or replace the list with a dictionary, e.g.:

a = dict([('t**%d' % n, lambda t: t**n) for n in range(4)])

 a
{'t**0': function lambda at 0x401e6bc4, 't**1': function lambda at 
0x401e6bfc, 
't**2': function lambda at 0x401e6c34, 't**3': function lambda at 
0x401e6c6c}
 a.keys()
['t**0', 't**1', 't**2', 't**3']
 a['t**3'](4)
64



--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Python callbacks PyGILState_Release()

2005-04-23 Thread Randall Hopper
 What is the correct way to propagate exceptions from Python callbacks?

 When I do this:

 Python - C++ - Python Callback

(example attached) an exception raised in the callback doesn't make it back
across C++ to Python.

 It appears that PyGILState_Release() at the bottom of the callback
wrapper is resetting the error state (as I can set a global based on
PyErr_Occurred() there, and can catch that up in the exception handler in
Python).

 This obviously isn't correct.  What should I be doing?

Thanks,

Randall


--
void callback_wrapper( void *user_data )
{
  // Acquire interpreter lock
  PyGILState_STATE gstate = PyGILState_Ensure();
  ...
  // Call Python
  pyresult = PyEval_CallObject( pyfunc, pyargs );
  ...
  /*** At this point, PyErr_Occurred() is true   **/
  /** But it's not true when we return through C++ to Python  **/

  // Free interpreter lock
  PyGILState_Release(gstate);
}

void registerCallback( PyObject *pyfunc )
{
  ...
  // Ensure threads inited, so we can use Ensure/Release in callbacks
  PyEval_InitThreads();

  // Ref pyfunc
  Py_INCREF( pyfunc );

  // Call underlying C++ method, registering the above C++ callback
  realRegisterCallback( callback_wrapper, pyfunc );
}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: grouping subsequences with BIO tags

2005-04-23 Thread Michael Spencer
Steven Bethard wrote:
Bengt Richter wrote:
On Thu, 21 Apr 2005 15:37:03 -0600, Steven Bethard 
[EMAIL PROTECTED] wrote:

I have a list of strings that looks something like:
   ['O', 'B_X', 'B_Y', 'I_Y', 'O', 'B_X', 'I_X', 'B_X']
[snip]
With error checks on predecessor relationship,
I think I'd do the whole thing in a generator,
I'm curious why you (Bengt or Steve) think the generator is an advantage here. 
As Steve stated, the data already exists in lists of strings.

The direct list-building solution I posted is simpler, and quite a bit faster.
L = ['O', 'B_X', 'B_Y', 'I_Y', 'O', 'B_X', 'I_X', 'B_X']
def timethem(lst, funcs = (get_runsSB, get_runsMS, get_runsBR)):
for func in funcs:
print shell.timefunc(func, lst)
  timethem(L)
 get_runsSB(...)  7877 iterations, 63.48usec per call
 get_runsMS(...)  31081 iterations, 16.09usec per call
 get_runsBR(...)  16114 iterations, 31.03usec per call
Michael
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Imaging Library and PyGTK - color image path?

2005-04-23 Thread Jeremy Bowers
On Fri, 22 Apr 2005 22:43:13 -0400, Jeremy Bowers wrote:
 (Use case, in case it matters: I am trying to embed a graphic into a text
 widget. This is going fine. Because I want the text widget to be able use
 different size text, and no one image can look right with everything from
 8pt to 40pt text (all reasonable possibilities), I load a large image in
 from the disk and scale it down as needed; the images are designed to
 scale well and later I can make multiple source images if that is
 desirable. But I can't figure out how to get the scaled image into GTK.
 This surprises me.)

As usual, posting for help after poking around for a long while guarantees
you'll figure it out in the next few minutes. You need to create GDK
pixbufs, which can be resized and scaled and stuff.

There is definitely some room for confusion here with GTK Images, GDK
Images, GTK pixbufs, and GDK pixbufs
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular Expressions - Python vs Perl

2005-04-23 Thread Ilpo Nyyssönen
Fredrik Lundh [EMAIL PROTECTED] writes:

 so you picked the wrong file format for the task, and the slowest
 tool you could find for that file format, and instead of fixing
 that, you decided that the regular expression engine was to blame
 for the bad performance. hmm.

What would you recommend instead?

I have searched alternatives, but somehow I still find XML the best
there is. It is a standard format with standard programming API.

I don't want to lose my calendar data. XML as a standard format makes
it easier to convert later to some other format. As a textual format
it is also readable as raw also and this eases debugging.

And my point is that the regular expression compilation can be a
problem in python. The current regular expression engine is just
unusable slow in short lived programs with a bit bigger amount of
regexps. And fixing it should not be that hard: an easy improvement
would be to add some kind of storing mechanism for the compiled
regexps. Are there any reasons not to do this?

 Nowdays I use libxml2-python as the XML parser and so the problem is
 not so acute anymore. (That is just harder to get in running for
 python compiled from source outside the rpm system and it is not so
 easy to use via DOM interface.)

 python has shipped with a fast XML parser since 2.1, or so.

With what features? validation? I really want a validating parser with
a DOM interface. (Or something better than DOM, must be object
oriented.)

I don't want to make my programs ugly (read: use some more low level
interface) and error prone (read: no validation) to make them fast. 

-- 
Ilpo Nyyssönen # biny # /* :-) */
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: internet explorer/firefox plugin/toolbar

2005-04-23 Thread Marcus Goldfish
 does anyone have any ideas as to how to go about creating a plugin/toolbar
 for both/either the IE/Firefox browsers?
For IE, checkout Browser Helper Objects (BHOs).  Sample python code
can be found at:

http://aspn.activestate.com/ASPN/Mail/Message/ctypes-users/2263094

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


A SOAPpy question... (Method Parameters)

2005-04-23 Thread [EMAIL PROTECTED]
I'm having difficulty sending out correctly named method parameters to
a php soap server that I am running using SOAPpy. Idealy I would like
to send XML that looks like this (which I cribbed from another client
that works just fine)


SOAP-ENV:Body
ns1:login xmlns:ns1=http://testuri.org;
user_auth
user_name xsi:type=xsd:string
   hpottash
/user_name

password xsi:type=xsd:string
  775fd0ac8dcdba0f307e8a2a474f9dce
/password
version xsi:type=xsd:string
 .01
/version
/user_auth
application_name xsi:type=xsd:string
SoapTest
/application_name
/ns1:login
/SOAP-ENV:Body


The closest I can come with SOAPpy is by running the following 
remote = SOAPpy.SOAPProxy(http://192.168.0.200/;,
http://testuri.org;)
remote.login({user_auth: {'user_name': 'theusername', 'password':
'thepassword', version : .01}, application_name:SoapTest});

Which generates XML that looks like this:
SOAP-ENV:Body
ns1:login xmlns:ns1=http://testuri.org; SOAP-ENC:root=1
   v1
application_name xsi:type=xsd:string
  SoapTest
/application_name
user_auth
password xsi:type=xsd:string
  thepassword
/password
user_name xsi:type=xsd:string
   theusername
/user_name
version xsi:type=xsd:string
 .01
/version
/user_auth
/v1
/ns1:login
/SOAP-ENV:Body

I believe that the Server is unable to parse this correctly because of
the v1 tag, but I don't know how to specify what the names of the
parameters that are passed to the method should be.

Any help would be deeply appreciated. 
-Harry

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


WHERE tiny pylibpcap example code that just uses next()???...

2005-04-23 Thread [EMAIL PROTECTED]
I'm trying to learn pylibpcap and would //really// love to see a
**simple**
example that just works.


Can someone *please* send me any little app that just
captures packets with next() command and prints bytes received??


If it only works on loopback interface that is fine.


Thanks in advance.


Chris

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


Re: figuring out # of bytes

2005-04-23 Thread Jaime Wyant
On 22 Apr 2005 13:28:57 -0700, codecraig [EMAIL PROTECTED] wrote:
 i want to the number of bytes in a string...
 
 is, len(x) accurate?
 
 so, x = hi
 len(x) == 2 so that means two bytes?
 
 thanks

No, that means that the string is two bytes in length.  The number of
bytes is dependent on the encoding.  It seems like there was a thread
on this subject recently.

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


Re: Python licence again

2005-04-23 Thread Grant Edwards
On 2005-04-22, Will McGugan [EMAIL PROTECTED] wrote:

 How *do* you pronounce it?  Thurrow seems to match
 how I say the word, along with everyone else I've
 ever met (until now?).

 I would pronounce it like 'thurra', since I'm Scottish. It always makes 
 me cringe when Americans pronounce 'Edinburgh' as 'edin-burrow' rather 
 then 'edin-burra'.

The city in Pennsylvania is spelled Edinboro, so there are a
few people over here with a decent excuse.

And it could be worse, we could call it edun-burg.

-- 
Grant Edwards   grante Yow!  I feel like I'm
  at   in a Toilet Bowl with a
   visi.comthumbtack in my forehead!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a=[ lambda t: t**n for n in range(4) ]

2005-04-23 Thread El Pitonero
Bengt Richter wrote:
 I still don't know what you are asking for, but here is a toy,
 ...
 But why not spend some time with the tutorials, so have a few more
cards in your deck
 before you try to play for real? ;-)

Communication problem.

All he wanted is automatic evaluation a la spreadsheet application.
Just like in Microsoft Excel. That's all.

There are many ways for implementing the requested feature. Here are
two:

(1) Push model: use event listeners. Register dependent quantities as
event listeners of independent quantities. When an independent quantity
is modified, fire off the event and update the dependent quantities.
Excel uses the push model.

(2) Pull model: lazy evaluation. Have some flag on whether an
independent quantity has been changed. When evaluating a dependent
quantity, survey its independent quantities recursively, and update the
cached copies whereever necessary.

Of course, combination of the two approaches is possible.

For Python, metaclasses and/or decorators and/or properties may help.

But functional languages are a more natural territory.

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


Re: Frog 1.4 (web log aka blogging server)

2005-04-23 Thread limodou
great!

How about change the bbcode like editor to FCKeditor? I think
FCKeditor is much better, or make it as an optional editor which the
user could select it himself.

2005/4/23, Irmen de Jong [EMAIL PROTECTED]:
 I've released a new version of Frog, a web log
 aka blogging server written in 100% python.
 
 Get version 1.4 from http://snakelets.sourceforge.net/frog/index.html
 
 (note: storage file format has been changed since v1.3)
 
 Some of the more interesting features are:
 
 - multi user
 - no database needed (uses files for storage)
 - no web server needed (it runs in Snakelets,
 which has its own web server)
 - splitted articles (read more...)
 - email notification when comment is added
 - formatting similar to 'bbcode', supports images and other files
 - anti-spam measures: puzzles, auto-updating link blacklist,
anti-indexing hyperlinks in comments (rel=nofollow)
 - outputs lean xhtml+css pages
 - fully unicode compatible
 - web-based file manager, available as separate module
 
 Have fun :)
 
 --Irmen
 
 PS You can see Frog in action here:
  http://www.razorvine.net/snake/frog/user/irmen/
 --
 http://mail.python.org/mailman/listinfo/python-announce-list
 
 Support the Python Software Foundation:
 http://www.python.org/psf/donations.html
 


-- 
I like python! 
My Donews Blog: http://www.donews.net/limodou
New Google Maillist: http://groups-beta.google.com/group/python-cn
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python logos

2005-04-23 Thread Terry Hancock
On Friday 22 April 2005 01:12 pm, Adomas wrote:
 this question has nothing to do with Python syntax,
 or libraries, however...
 
 I'm looking for the so well-known python logo -- not
 the boring Python Powered, but the image of small
 snake. However, the only such I could found was 32x32
 or alike (windows icon size.)
 
 Does anybody know where could I find a better-resolution
 image, or yet better SVG/EPS?

AFAIK, there is no such logo which is official.  
Especially since the original author (GvR) did not mean a 
snake at all. But there are several different unofficial 
versions which can be found.  I'd try using Google's image 
search.

You might try restricting it to the list archives, I'm not 
sure whether Google will chase the links, but some people
did post their own artwork for this just late last year or 
thereabouts, if I remember.

Good luck,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: Python licence again

2005-04-23 Thread Robert Kern
Laszlo Zsolt Nagy wrote:
 Hi All!
I know there has been a post about Python licencing but I have different 
questions. I tried to Google for Python Licence and Python Licencing 
but I could not find the answer.
Is there a place where I can ready about Python licencing? (A FAQ 
maybe?) I really need to know the details of the licence, but not in the 
lawyer's language. Just simple questions:

- How put a software under the Python licence?
While you can, sort of, and people have already pointed out the 
appropriate web page to you, I ask that you *don't* use the PSF License. 
The PSF License uses proper nouns that you will have to change[1]. When 
you are done, it will no longer be the PSF License. It is my opinion 
that this kind of variant proliferation is a nuisance.

Instead, you could use other well-accepted licenses that are broadly 
similar to the PSF License.

http://www.opensource.org/licenses/bsd-license.php
http://www.opensource.org/licenses/mit-license.php
http://www.opensource.org/licenses/afl-2.1.php
[1] For example: 1. This LICENSE AGREEMENT is between the Python 
Software Foundation (PSF), and the Individual or Organization 
(Licensee) accessing and otherwise using this software (Python) in 
source or binary form and its associated documentation.

You are neither the PSF nor is your software Python.
--
Robert Kern
[EMAIL PROTECTED]
In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die.
  -- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list


BayPIGgies: May *THIRD* Thursday at Google (May 19)

2005-04-23 Thread Aahz
Pre-announcement:

Our May meeting will be the *THIRD* Thursday, May 19.  We will *NOT* be
meeting the *SECOND* Thursday.  This will be our first meeting at Google,
with Alex Martelli's presention on design patterns.  More details later!
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code -- 
not in reams of trivial code that bores the reader to death.  --GvR
-- 
http://mail.python.org/mailman/listinfo/python-list


internet explorer/firefox plugin/toolbar

2005-04-23 Thread bruce
hi...

this probably isn't the correct mailing list, but we're giving it a shot!!

does anyone have any ideas as to how to go about creating a plugin/toolbar
for both/either the IE/Firefox browsers?

We're curious as to how to do this, and what languages/technologies you'd
use to do this.. could it be done in python???

searching google didn't really turn up anything for the IE side of things...

any comments/assistance/etc would be useful...

thanks

bruce
[EMAIL PROTECTED]


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


Re: a=[ lambda t: t**n for n in range(4) ]

2005-04-23 Thread Bill Mill
On 22 Apr 2005 14:41:45 -0700, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 I was thinking about something like the following;
 
  a=[ t**n for n in range(4) ]
 Traceback (most recent call last):
  File stdin, line 1, in ?
 NameError: name 't' is not defined
 
 
 or
 
  a=[ lambda t: t**n for n in range(4) ]
  t=2
  a
 [function lambda at 0x403dcc6c, function lambda at 0x403dcca4,
 function lambda at 0x403dccdc, function lambda at 0x403dcd14]
  t=3
  a
 [function lambda at 0x403dcc6c, function lambda at 0x403dcca4,
 function lambda at 0x403dccdc, function lambda at 0x403dcd14]
 
 

Well, everybody else took away your lambda (greedy people!) but I'm
here to say that it doesn't *have* to go away. I didn't think this
would be possible, but it is:

 t = 2
 [(lambda n: t**n)(n) for n in range(4)]
[1, 2, 4, 8]
 t = 3
 [(lambda n: t**n)(n) for n in range(4)]
[1, 3, 9, 27]

I just thought that was kinda neat. If you wanted to obfuscate some
python, this would be an awesome trick - hide the value of t somewhere
early in the function then pull a variation of this out later.

Peace
Bill Mill
bill.mill at gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python licence again

2005-04-23 Thread John Machin
On Fri, 22 Apr 2005 17:26:19 -0700, Robert Kern [EMAIL PROTECTED]
wrote:


While you can, sort of, and people have already pointed out the 
appropriate web page to you, I ask that you *don't* use the PSF License. 
The PSF License uses proper nouns that you will have to change[1].

and don't forget the pronouns  ... 

Seen in a too-hasty copy-paste-edit of the BSD licence:

IN NO EVENT SHALL person's name suppressed OR ITS CONTRIBUTORS BE
LIABLE ...



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


Re: Dictionary question.

2005-04-23 Thread bserviss
A simple way to get individual values for the distribution is:

d = {}
for i in range( 0, 1000):
j = random.randrange( 0, 100)
if d.has_key(j):
d[j] += 1
else:
 d[j] = 1

keys = d.keys()
keys.sort()
for key in keys:
print key, :, * * d[key]

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


Re: a=[ lambda t: t**n for n in range(4) ]

2005-04-23 Thread mehmetmutigozel

Thanx.

It just popped in my mind.

in 3d programming there are transformation matrices like
a=[[cos(x),sin(x),0],[-sin(x),cos(x),0],[0,0,1]]
it is a 3x3 matrix. never changes during program.

it can be defined like
 def transmat(x):
...   dummy=[[0,0,0],[0,0,0],[0,0,0]]
...   dummy[0][0]=cos(x)
...   ~~
...   return dummy

a=transmat(1.0)

it is usual way for this.

i wonder if there is an automatic way to make that without calling a
function.

an automatic way that depends on changing the value of x. as each time
x=something used the whole matrix changes automaticly.

or maybe i am just dreaming. :)

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


Re: c-extension crashes unexpected

2005-04-23 Thread Markus Wintermann
John Machin schrieb:

 ...

 Some suggestions:
 
 1. Try Pyrex. You get to write in a higher-level language and it does
 all the boring ugly error-prone stuff for you -- this includes
 reference counting as well! Look at the C code that Pyrex generates,
 to see what Pyrex is saving you from.
 2. If you still insist on DIY, look at some of the Python source code
 in the Modules and Objects directories to see how it is done.
 3. Examine carefully the book or whatever you have been learning from.
 If it doesn't cover topics like always checking for errors, throw it
 in the garbage bin (and tell the world via this newsgroup). If it does
 cover such topics but you've been ignoring it, well then, it's up to
 you what you do next :-)
 
 HTH,
 John

many thanks.

it works now, but i´ll try to do the whole thing with pyrex.
because i´m not so familiar with error handling.
i tried to write this with some tutorials and there is always written
something like:
i know it´s no nice style to have no errorhandling but for excercise
purpose that´s not necessary.
and i never know what to add.
luckily now the good pyrex will do this for me,
if i get it to work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trying to read from dying disk

2005-04-23 Thread Ivan Van Laningham
Hi All--

[EMAIL PROTECTED] wrote:
 
 I'm currently attempting something with
 
   http://www.python.org/doc/current/lib/node368.html
 
 but it seems the read operation is ignoring these signals just as it is
 ignoring my signals from the kill command -- perhaps unsurprisingly.
 
 Perhaps there is no hope.
 


Basically, if you are waiting for a hardware interrupt that never comes,
you are doomed.  You can escape by rebooting; in dire cases the only way
out is to power down.  One of the prime sources of zombie processes on
unix systems is users trying to interrupt (with ^C) a process that is
waiting for a hardware interrupt.

Metta,
Ivan
--
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python licence again

2005-04-23 Thread has
John J. Lee wrote:
 Yes.  ISTR that licence is a British English spelling, though my
 British brain has been thoroughly contaminated by US spellings and
 usage by now.

Oh, it only gets worse: a couple years on the illiterate intarweb and
even basics like its and it's become a major struggle. ;p

 (Or are they like practice and practise, which (can)
 mean subtly different things in British English

Yep, we aim to confuse:

licence, practice = noun
license, practise = verb

/grammar geek

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


Re: __init__.py question

2005-04-23 Thread Terry Hancock
On Friday 22 April 2005 07:19 am, codecraig wrote:
 Ok,  I have the following directory structure
 
 C:\pycode
-- blah.py
-- mynewdir
   -- __init__.py
   -- abc.py
 
 [[ C:\pycode\mynewdir\abc.py ]]
 
 def doFoo():
 print hi
 
 def doBar():
 print bye
 
 [[ C:\pycode\mynewdir\__init__.py ]]
 
 from mynewdir import *

This didn't work, did it?  There is no module
mynewdir.py nor a package mynewdir in
the mynewdir directory, and I don't think import
will search up to find the container.

I suspect you meant that __init__.py says:

from abc import *

 [[ C:\pycode\blah.py ]]
 
 
 
 what do i import in blah.py so that I can accesss, 
abc.doFoo() ?

Assuming the above, and that you want to access
it as you have written it, that would be:

from mynewdir import abc

Note that in order to use this form, you don't have
to have *anything* in mynewdir/__init__.py --- it can
be an empty file, as long as it exists.

You only need to use an import in __init__.py if you
want it to automatically run when you import the
package.

E.g. if you did:

import mynewdir

You could access your function as:

mynewdir.abc.doFoo

(which requires the import statement in __init__.py).

Cheers,
Terry


--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: a=[ lambda t: t**n for n in range(4) ]

2005-04-23 Thread Bengt Richter
On 22 Apr 2005 15:18:53 -0700, [EMAIL PROTECTED] wrote:

Thanx for your replies.

I'm looking for array of functions.
Something like a=[ sin(x) , cos(x) ]

 x=0.0
 a
[0, 1]
 x=1.0
 a
...

of course it can be made by
 def cratearray(x):
...   
...   return a
a=createarray(1.0)

but this isn't what i am asking for. something automized.

I still don't know what you are asking for, but here is a toy,
whose code you will be able to improve on later, but at least
provides concrete behavior that you can comment on, and maybe
explain what you are really asking for.

  class FunArray(object):
 ... def __init__(self, *funs):
 ... self.__dict__['_funs'] = funs
 ... self.__dict__['_names'] = []
 ... vars
 ... def __getattribute__(self, attr):
 ... if attr.startswith('_') or hasattr(type(self), attr):
 ... return object.__getattribute__(self, attr)
 ... v = vars(self).get(attr)
 ... if v is None: return ['%r is not set'%attr]
 ... return [f(v) for f in self._funs]
 ... def __setattr__(self, attr, v):
 ... if attr.startswith('_'): raise AttributeError, attr
 ... else:
 ... if attr in self._names: self._names.remove(attr)
 ... self._names.append(attr)
 ... self.__dict__[attr] = v
 ... def __repr__(self):
 ... last = self._names and self._names[-1] or '??'
 ... d= vars(self)
 ... return 'FunArray names: %s\n  %r = %s'% (
 ... ', '.join(['%s=%r'%(k, d[k]) for k in self._names]),
 ... last, repr(getattr(self, last)))
 ...
  from math import sin, cos, pi
  a = FunArray(sin, cos)
  a.x = 0.0
  a
 FunArray names: x=0.0
   'x' = [0.0, 1.0]
  a.x
 [0.0, 1.0]
  a.y = 1.0
  a.y
 [0.8414709848078965, 0.54030230586813977]
  a
 FunArray names: x=0.0, y=1.0
   'y' = [0.8414709848078965, 0.54030230586813977]
  a.z = pi/3
  a
 FunArray names: x=0.0, y=1.0, z=1.0471975511965976
   'z' = [0.8660254037844386, 0.50011]
  a.x = pi/6
  a
 FunArray names: y=1.0, z=1.0471975511965976, x=0.52359877559829882
   'x' = [0.49994, 0.86602540378443871]


If you just want an interactive calculator that acts according to your taste,
you can program one to prompt and read (use raw_input, not input BTW) what you
type in and calculate and print whatever form of result you'd like. See the cmd
module for one way not to reinvent some wheels.

But why not spend some time with the tutorials, so have a few more cards in 
your deck
before you try to play for real? ;-)

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


Re: Semi-newbie, rolling my own __deepcopy__

2005-04-23 Thread [EMAIL PROTECTED]
Michael Spencer wrote:
 [EMAIL PROTECTED] wrote:
  I'm back...
 [wondering why copy.deepcopy barfs on array instances]
 

 http://www.python.org/doc/2.3.3/lib/module-copy.html
 deepcopy:
 ...
 This version does not copy types like module, class, function,
method, stack
 trace, stack frame, file, socket, window, *array*, or any similar
types.
 ...

*smacks forehead*

Duh.  Right in the docs.  Too many late nights in front of the screeen.
 Thanks, Michael...

--
Rainforest laid low.
Wake up and smell the ozone,
Says man with chainsaw.
John J. Ladasky Jr., Ph.D.

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


Re: Run Unix shell command $ parse command line arguments in python

2005-04-23 Thread Terry Hancock
On Friday 22 April 2005 01:39 am, [EMAIL PROTECTED] wrote:
  I am a newbie to python. I have a makefile which i can compile in
 UNIX/LINUX, But i
 I am planning to write a python script which actually does what my
 MAKEFILE does. The make file is
[...]
 I want to write a python script to replace this Makefile.
 I Have tried using getopt/optparse for parsing command line options
 How to Run  Unix shell command from python.

Read the documentation on the os and popen2 modules under
generic operating system services in the Python Standard Library
Manual (go to http://www.python.org if you haven't already got this
manual on hand).

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: How to run Python in Windows w/o popping a DOS box?

2005-04-23 Thread pyguy2
I think of it like the ''.join semantics. The object knows best how
to
handle join (even if it looks wierd to some people). In the #! case,
the program knows best how to start itself.

This I don't understand ;-)

With  ','.join(['a','b','c'])You rely on what wants to join the
sequence to handle the issue of joining rather than have the sequence
understand joining. I think of it as the object knows best.

I think of  #! as the program knowing best how to startup, rather
than having to rely on something else to deal with it. I also like the
text based simplicity and explictness. Just like text based etc files
on unix versus the registry in windows. And, if you want you can add
more power like use env variables in #!.
It can be as simple or as powerful as you need, you can use whatever
means you want to manage the #! line: text editors, other programs,
etc.  It is data-centric, just like http, sql, file I/O rather than
verb-centric (learn another whole set of methods to figure out how to
change startup).

hopefully I am making sense,

john

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


Re: a=[ lambda t: t**n for n in range(4) ]

2005-04-23 Thread Mage
Scott David Daniels wrote:



 See, the body of your anonymous function just looks for the current
 value of n when it is _invoked_, not when it is _defined_.

The lambda functions was an unclear part of the tutorial I read.
Should I use them? Are they pythonic?
As far I see they are good only for type less a bit.

   Mage


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


Decorator pattern for new-style classes ?

2005-04-23 Thread George Sakkis
Searching the archives for something related to the title, I found a
few relevant threads (e.g. http://tinyurl.com/avyg6 or
http://tinyurl.com/b5b6v); however they don't seem to give a
satisfactory answer, so here it goes again: What's the equivalent
new-style Delegate class ?

class Delegate:
def __init__(self, principal):
self._principal = principal

def __getattr__(self,name):
return getattr(self._principal,name)

# overriden methods follow here

This delegates both normal and __special__ methods; unfortunately for
new style classes __getattr__ is not called for missing special
methods. The workarounds I saw or can think of are so ugly that I
prefer to to use an old-style class after a long time :-/

George

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


Re: Python Imaging Library and PyGTK - color image path?

2005-04-23 Thread Fredrik Lundh
Jeremy Bowers wrote:
I have an image in the Python Image Library. I'm trying to get it into
PyGTK in color. Is there any way to do this cross-platform, preferably
without writing to anything to the disk?
PIL apparently can't write XPMs. GTK will only take XPMs, that I can see.
Therein lies the rub. I can ship over monochrome bitmaps via XBM, but I'd
rather be able to ship over full color.
the first two google hits for PyGTK PIL are
   http://www.daa.com.au/pipermail/pygtk/2005-April/009988.html
which provides a StringIO-based solution, and
   http://www.daa.com.au/pipermail/pygtk/2003-February/004393.html
which discusses draw_rgb_image and friends, and says that if you can convert
your PIL image to a  pixel data string or buffer object, you could use them to
display the image.  here's some code that seems to do exactly that:
   http://www.mail-archive.com/pygtk@daa.com.au/msg07167.html
(but maybe this is some kind of stupid a bitmap isn't a pixmap isn't an image
thing?  if so, I suggest getting a modern windowing system ;-)
/F
--
http://mail.python.org/mailman/listinfo/python-list


Re: In defense of Visual Basic (was Re: Why Python does *SLICING* theway it does??)

2005-04-23 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:
Sub print_matrix(xmat() As Double)
Debug.Print UBound(xmat, 1), UBound(xmat, 2)
'do stuff with xmat
End Sub
It is trivial to allocate and pass multidimensional arrays in VBA, but
C requires expertise with pointers. The subroutine print_matrix can
query the dimensions of xmat, so they don't need to be passed as
separate arguments, as in C. The fact that is tricky to do simple
things is a sign of the poor design of C
Sounds more like poor C skills on your part.   Here's a snippet from the 
Python
Imaging Library which takes a 2D array (im) and creates another one (imOut).
Imaging
ImagingRankFilter(Imaging im, int size, int rank)
{
   Imaging imOut = NULL;
   int x, y;
   int i, margin, size2;
   /* check image characteristics */
   if (!im || im-bands != 1 || im-type == IMAGING_TYPE_SPECIAL)
   return (Imaging) ImagingError_ModeError();
   /* check size of rank filter */
   if (!(size  1))
   return (Imaging) ImagingError_ValueError(bad filter size);
   size2 = size * size;
   margin = (size-1) / 2;
   if (rank  0 || rank = size2)
   return (Imaging) ImagingError_ValueError(bad rank value);
   /* create output image */
   imOut = ImagingNew(im-mode, im-xsize - 2*margin, im-ysize - 2*margin);
   if (!imOut)
   return NULL;
   ... actual algorithm goes here ...
   return imOut;
}
The im input object carries multidimensional data, as well as all other 
properties
needed to describe the contents.  There are no separate arguments for the image
dimensions, nor any tricky pointer manipulations.  A Python version of this 
wouldn't
be much different.
/F
--
http://mail.python.org/mailman/listinfo/python-list


tracing function calls

2005-04-23 Thread Stormbringer
Greetings,

I've been wondering if there is a mechanism similar to trace/untrace
found in lisp, for example call trace(function-name) and whenever this
function is called it will show its parameters to stdout 

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


Re: tracing function calls

2005-04-23 Thread Fredrik Lundh
Stormbringer wrote:
I've been wondering if there is a mechanism similar to trace/untrace
found in lisp, for example call trace(function-name) and whenever this
function is called it will show its parameters to stdout 
def trace(func):
   def tracer(*args, **kwargs):
   print func.__name__, args, kwargs
   result = func(*args, **kwargs)
   print func.__name__, return, result
   return result
   return tracer
def myfunc(a, b, c):
   return a + b + c
myfunc = trace(myfunc)
myfunc(1, 2, 3)
(tweak as necessary)
/F
--
http://mail.python.org/mailman/listinfo/python-list


Question Regarding PIL and PhotoImage classes

2005-04-23 Thread Harlin Seritt
Why is that I can only get the PhotoImage class to show up when I write
a straight procedural script (no object orientation) but not when I try
to use object-orientation?

These two scripts in theory should produce the same results but they
don't. Is there any reason why?

---Procedural---

root = Tk()
im = Image.open('image.gif')
photo = ImageTk.PhotoImage(im)

label = Label(image=photo)
label.pack()
root.mainloop()

---Object-Oriented---

from Tkinter import *
import Image, ImageTk

class App:

def __init__(self, master):
im = Image.open('dellserver.gif')
photo = ImageTk.PhotoImage(im)

label = Label(master, image=photo)
label.pack()


if __name__ == '__main__':
root = Tk()
app = App(root)
root.mainloop()

---END of CODE---

Thanks,

Harlin Seritt

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


embedding python onto a fox-board

2005-04-23 Thread Floris van Manen
Is there anyone who already ported python onto a acme-systems linux 
fox-board?
http://www.acmesystems.it/



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


Re: a=[ lambda t: t**n for n in range(4) ]

2005-04-23 Thread tiissa
[EMAIL PROTECTED] wrote:
i wonder if there is an automatic way to make that without calling a
function.
You mean without _explicitely_ calling a function.
May I inquire why you need to write f instead of f(x)?
an automatic way that depends on changing the value of x. as each time
x=something used the whole matrix changes automaticly.
As pointed out by El Pitonero property can be your friend:
  class A(object):
 ... def get_v(self):
 ... return [1,x]
 ... v=property(get_v)
 ...
  a=A()
  x=0
  a.v
 [1, 0]
  x=2
  a.v
 [1, 2]
 
However, you will calculate your matrix each time you will access it 
(and I find it ugly to use a global variable this way).

You can however build it the other way round:
  class B(object):
 ... def __init__(self):
 ... self.v=[1,0]
 ... self.x=0
 ... def calc_v(self):
 ... self.v[1]=self.__x
 ... def set_x(self,x):
 ... self.__x=x
 ... self.calc_v()
 ... def get_x(self):
 ... return self.__x
 ... x=property(get_x, set_x)
 ...
  b=B()
  b.v
 [1, 0]
  b.x=2
  b.v
 [1, 2]
 
This time, calculations only occur when you change the value of x.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question Regarding PIL and PhotoImage classes

2005-04-23 Thread Fredrik Lundh
Harlin Seritt wrote:
Why is that I can only get the PhotoImage class to show up when I write
a straight procedural script (no object orientation) but not when I try
to use object-orientation?
These two scripts in theory should produce the same results but they
don't. Is there any reason why?
in the second example, the photo variable is garbage-collected when the
method returns.
see the note on this page for more info:
   http://effbot.org/zone/tkinter-photoimage.htm
/F
--
http://mail.python.org/mailman/listinfo/python-list


Re: tracing function calls

2005-04-23 Thread Stormbringer
Thank you Fredrik !
With a little tweaking for the right indentation it should prove useful
:)

Fredrik Lundh wrote:
 Stormbringer wrote:

  I've been wondering if there is a mechanism similar to
trace/untrace
  found in lisp, for example call trace(function-name) and whenever
this
  function is called it will show its parameters to stdout 

 def trace(func):
 def tracer(*args, **kwargs):
 print func.__name__, args, kwargs
 result = func(*args, **kwargs)
 print func.__name__, return, result
 return result
 return tracer

 def myfunc(a, b, c):
 return a + b + c

 myfunc = trace(myfunc)
 
 myfunc(1, 2, 3)
 
 (tweak as necessary)
 
 /F

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


Python or PHP?

2005-04-23 Thread Lad
Is anyone capable of providing Python advantages over PHP if there are
any?
Cheers,
L.

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


Re: Python or PHP?

2005-04-23 Thread Leif B. Kristensen
Lad skrev:

 Is anyone capable of providing Python advantages over PHP if there are
 any?

Much more compact and yet much more readable code, making it easier to
maintain and extend your programs.
-- 
Leif Biberg Kristensen
http://solumslekt.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-23 Thread Leif K-Brooks
Lad wrote:
Is anyone capable of providing Python advantages over PHP if there are
any?
Python is a programming language in more ways than simple Turing 
completeness. PHP isn't.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python callbacks PyGILState_Release()

2005-04-23 Thread Thomas Heller
Randall Hopper [EMAIL PROTECTED] writes:

  What is the correct way to propagate exceptions from Python callbacks?

  When I do this:

  Python - C++ - Python Callback

 (example attached) an exception raised in the callback doesn't make it back
 across C++ to Python.

  It appears that PyGILState_Release() at the bottom of the callback
 wrapper is resetting the error state (as I can set a global based on
 PyErr_Occurred() there, and can catch that up in the exception handler in
 Python).

  This obviously isn't correct.  What should I be doing?

 Thanks,

 Randall


 --
 void callback_wrapper( void *user_data )
 {
   // Acquire interpreter lock
   PyGILState_STATE gstate = PyGILState_Ensure();
   ...
   // Call Python
   pyresult = PyEval_CallObject( pyfunc, pyargs );
   ...
   /*** At this point, PyErr_Occurred() is true   **/
   /** But it's not true when we return through C++ to Python  **/

if (pyresult == NULL)
PyErr_Print();

   // Free interpreter lock
   PyGILState_Release(gstate);
 }

PyErr_Print() will do the 'right' thing´s.

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


XML file parsing with SAX

2005-04-23 Thread Willem Ligtenberg
I decided to use SAX to parse my xml file.
But the parser crashes on:
  File /usr/lib/python2.3/site-packages/_xmlplus/sax/handler.py, line 38, in 
fatalError
raise exception
xml.sax._exceptions.SAXParseException: NCBI_Entrezgene.dtd:8:0: error in 
processing external entity reference

This is caused by:
!DOCTYPE Entrezgene-Set PUBLIC -//NCBI//NCBI Entrezgene/EN
NCBI_Entrezgene.dtd

If I remove it, it parses normally.
I've created my parser like this:
import sys
from xml.sax import make_parser
from handler import EntrezGeneHandler

fopen = open(mouse2.xml, r)
ch = EntrezGeneHandler()
saxparser = make_parser()
saxparser.setContentHandler(ch)
saxparser.parse(fopen)

And the handler is:
from xml.sax import ContentHandler

class EntrezGeneHandler(ContentHandler):

A handler to deal with EntrezGene in XML


def startElement(self, name, attrs):
print Start element:, name

So it doesn't do much yet. And still it crashes...
How can I tell the parser not to look at the DOCTYPE declaration.
On a website:
http://www.devarticles.com/c/a/XML/Parsing-XML-with-SAX-and-Python/1/
it states that the SAX parsers are not validating, so this error shouldn't
even occur?

Cheers,

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


Re: PDF Printing support from Python

2005-04-23 Thread Diez B. Roggisch
 You're use of the word driver is one with which I'm not
 familiar.  But I don't really do windows so it's probably a
 Widnowism.

It could be that he means that creating PDFs on windows is done using a fake
printer that will produce the pdf when being printed to - and that fake
printer is implemented as a driver.

And traditionally in printing one often speaks of printer drivers - even if
they are mere filters that can't be considered drivers in the kernel driver
way.
-- 
Regards,

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


Re: Python or PHP?

2005-04-23 Thread Mage
Lad wrote:

Is anyone capable of providing Python advantages over PHP if there are
any?
  

I am also new to python but I use php for 4 years. I can tell:

- python is more *pythonic* than php
- python has its own perfume
http://www.1976.com.tw/image/trussardi_python_uomo.jpg  and it's nice.
php doesn't have any smell
- writing python programs you feel much better

check this: http://wiki.w4py.org/pythonvsphp.html

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


Re: Python callbacks PyGILState_Release()

2005-04-23 Thread Randall Hopper
Thomas Heller:
 |  Python - C++ - Python Callback
 |
 | (example attached) an exception raised in the callback doesn't make it back
 | across C++ to Python.
...
 | void callback_wrapper( void *user_data )
 | {
 |   // Acquire interpreter lock
 |   PyGILState_STATE gstate = PyGILState_Ensure();
 |   ...
 |   // Call Python
 |   pyresult = PyEval_CallObject( pyfunc, pyargs );
 |   ...
 |
 |if (pyresult == NULL)
 |PyErr_Print();
 |
 |   // Free interpreter lock
 |   PyGILState_Release(gstate);
 | }
 |
 |PyErr_Print() will do the 'right' thing?s.

Thanks for the reply.  However, this won't:

   a) Stop the main Python script, and
   b) Print the full stack trace (including Python and C++ SWIG wrapper)

Is there a clean way to save the full exception state in the callback
before the PyGILState_Release(), and restore it when we return across the
C++ wrapper?

If I knew what the proper save and restore exception state code bits
were, I could easily implement this with exception typemaps in SWIG.

Thanks,

Randall

P.S. Perhaps PyGILState_Release should take an argument instructing it to
exclude exception state when resetting the interpreter state back to its
original state.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PDF Printing support from Python

2005-04-23 Thread Grant Edwards
On 2005-04-23, Diez B. Roggisch [EMAIL PROTECTED] wrote:

 You're use of the word driver is one with which I'm not
 familiar.  But I don't really do windows so it's probably a
 Widnowism.

 It could be that he means that creating PDFs on windows is
 done using a fake printer that will produce the pdf when being
 printed to - and that fake printer is implemented as a driver.

 And traditionally in printing one often speaks of printer
 drivers - even if they are mere filters that can't be
 considered drivers in the kernel driver way.

I think it's the latter.  I believe he wants to know how to
print a PDF file without using any external programs (or
drivers) like Acrobat Reader or ghostscript that understand
PDF.  AFAIK, the only way to do what he wants would be for him
to write a PDF engine in Python that renders PDF into whatever
raw format is understood by his printer.

-- 
Grant Edwards   grante Yow!  I'LL get it!! It's
  at   probably a FEW of my
   visi.comITALIAN GIRL-FRIENDS!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a=[ lambda t: t**n for n in range(4) ]

2005-04-23 Thread Harald Massa
Mage [EMAIL PROTECTED] wrote in news:mailman.2339.1114242211.1799.python-

 The lambda functions was an unclear part of the tutorial I read.
 Should I use them? Are they pythonic?
 As far I see they are good only for type less a bit.

And to obfusicate code. lambda is evil, do not play with it.

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


Re: a=[ lambda t: t**n for n in range(4) ]

2005-04-23 Thread Scott David Daniels
Mage wrote:
Scott David Daniels wrote:
See, the body of your anonymous function just looks for the current
value of n when it is _invoked_, not when it is _defined_.
The lambda functions was an unclear part of the tutorial I read.
Should I use them? Are they pythonic?
As far I see they are good only for type less a bit.
As for most python features which are not dead obvious, you should
only use them where they they make the code clearer than it would be
without the use of that feature.  In this case, I was responding to
a particular use of lambda which, in fact, had a flaw that made the
code do something different from what it looked like it was doing.
I felt the distinction was clearer in the lambda form than it would
have been with def-style function definitions.  One of the reasons
the distinction came out was that there was no confusing naming of
what this function means, only program structure.  In a real program
that is a hindrance.  In the case of pointing out a flaw, it makes
differences between two versions of some code more obvious.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Caching compiled regexps across sessions (was Re: Regular Expressions - Python vs Perl)

2005-04-23 Thread Ville Vainio
 Ilpo == Ilpo Nyyssnen iny writes:

 so you picked the wrong file format for the task, and the slowest

Ilpo What would you recommend instead?

Ilpo I have searched alternatives, but somehow I still find XML
Ilpo the best there is. It is a standard format with standard
Ilpo programming API.

Ilpo I don't want to lose my calendar data. XML as a standard
Ilpo format makes it easier to convert later to some other
Ilpo format. As a textual format it is also readable as raw also
Ilpo and this eases debugging.

Use pickle, perhaps, for optimal speed and code non-ugliness. You can
always use xml as import/export format, perhaps even dumping the db to
xml at the end of each day.

Ilpo And my point is that the regular expression compilation can
Ilpo be a problem in python. The current regular expression
Ilpo engine is just unusable slow in short lived programs with a
Ilpo bit bigger amount of regexps. And fixing it should not be
Ilpo that hard: an easy improvement would be to add some kind of
Ilpo storing mechanism for the compiled regexps. Are there any
Ilpo reasons not to do this?

It should start life as a third-party module (perhaps written by you,
who knows :-). If it is deemed useful and clean enough, it could be
integrated w/ python proper. This is clearly something that should not
be in the python core, because the regexps themselves aren't there
either.

 python has shipped with a fast XML parser since 2.1, or so.

Ilpo With what features? validation? I really want a validating
Ilpo parser with a DOM interface. (Or something better than DOM,
Ilpo must be object oriented.)

Check out (coincidentally) Fredrik's elementtree:

http://effbot.org/zone/element-index.htm

Ilpo I don't want to make my programs ugly (read: use some more
Ilpo low level interface) and error prone (read: no validation)
Ilpo to make them fast.

Why don't you use external validation on the created xml? Validating
it every time sounds like way too much like Javaic BD to be fun
anymore. Pickle should serve you well, and would probably remove about
half of your code. Do the simplest thing that could possibly work
and all that.

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Frog 1.4 (web log aka blogging server)

2005-04-23 Thread Irmen de Jong
limodou wrote:
great!
How about change the bbcode like editor to FCKeditor? I think
FCKeditor is much better, or make it as an optional editor which the
user could select it himself.
Isn't that pretty heavyweight for a blog?
I mean; Frog is not a CMS with which you write HTML pages...
Then again, it shouldn't be very hard to switch de default
formatting engine for another one, the code is already
somewhat prepared for this.
I'd say, give it a shot :)   Patches are gladly accepted.
(I'll put this as a nice-to-have on the list)
--Irmen

2005/4/23, Irmen de Jong [EMAIL PROTECTED]:
I've released a new version of Frog, a web log
aka blogging server written in 100% python.
[...]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-23 Thread Ville Vainio
 Leif == Leif K-Brooks [EMAIL PROTECTED] writes:

Leif Lad wrote:
 Is anyone capable of providing Python advantages over PHP if there are
 any?

Leif Python is a programming language in more ways than simple Turing
Leif completeness. PHP isn't.

+1 QOTW.

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-23 Thread Diez B. Roggisch
 php doesn't have any smell

au contraire! I've seen many code smells in PHP.

http://c2.com/cgi/wiki?CodeSmell

--  
Regards,

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


Re: Trouble Installing TTX/FontTools (asks for .NET Framework Packages)

2005-04-23 Thread Jesper Olsen

weston wrote:
 This problem may be addressed here:

 http://sourceforge.net/mailarchive/message.php?msg_id=1702374

 Apparently setup.py tries to compile a c file, which of course
doesn't
 work if there's no compiler.

In fact it does not work even if there is a compiler - seems distutils
has been broken in python2.4 (it works in python2.3).

Jesper

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


Re: Python or PHP?

2005-04-23 Thread Tim Tyler
Mage [EMAIL PROTECTED] wrote or quoted:

 check this: http://wiki.w4py.org/pythonvsphp.html

Good - but it hardly mentions the issue of security - which seems
like a bit of a problem for PHP at the moment.
-- 
__
 |im |yler  http://timtyler.org/  [EMAIL PROTECTED]  Remove lock to reply.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python licence again

2005-04-23 Thread Tim Tyler
fuzzylollipop [EMAIL PROTECTED] wrote or quoted:

 try spelling license correctly next time and heading the google
 suggestions that probably looked like didn't you mean : Python License

How do you spell license correctly?
-- 
__
 |im |yler  http://timtyler.org/  [EMAIL PROTECTED]  Remove lock to reply.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a=[ lambda t: t**n for n in range(4) ]

2005-04-23 Thread Bengt Richter
On 22 Apr 2005 20:45:55 -0700, El Pitonero [EMAIL PROTECTED] wrote:

Bengt Richter wrote:
 I still don't know what you are asking for, but here is a toy,
 ...
 But why not spend some time with the tutorials, so have a few more
cards in your deck
 before you try to play for real? ;-)

Communication problem.
Indeed.


All he wanted is automatic evaluation a la spreadsheet application.
Just like in Microsoft Excel. That's all.

There are many ways for implementing the requested feature. Here are
two:

(1) Push model: use event listeners. Register dependent quantities as
event listeners of independent quantities. When an independent quantity
is modified, fire off the event and update the dependent quantities.
Excel uses the push model.
This is essentially what I was demonstrating with the namespace of FunArray,
showing object attribute namespace access as perhaps _the_ 'listening hook
of Python -- which properties and overriding base class methods with
subclass methods etc. etc. all depend on.

FunArray 'listens' for named spreadsheet cell assignments to its namespace,
and it listens for a repr access to the spreadsheet as a whole, presenting
its status in terms of cell names and the formula value of the last cell 
entered.

Not conventional, but I wanted to stay as close to the OP's proposed
example interactive log (if that was what it was, which apparently it wasn't ;-)

This does also demonstrate that if you want to listen for apparent
assignments to bare names, AFAIK there is no way without byte code hackery
or using a trace hook, or just doing your own eval-print loop,
which is why I suggested the cmd module as a start.

of course, you could mess with displayhook to get what the OP originally
appeared to be asking for. E.g., this toy produces an interactive log
much like the OP specified:

  class DH(object):
 ... def __init__(self):
 ... import math
 ... self.env = vars(math)
 ... self.env.update(vars(__builtins__))
 ... def evalstrex(self, s):
 ... for name in compile(s,'','eval').co_names:
 ... if type(self.env[name]) == str:
 ... self.env[name] = self.evalstrex(self.env[name])
 ... return eval(s, self.env)
 ... def __call__(self, o):
 ... if type(o)==str:
 ... self.env.update(globals())
 ... o = self.evalstrex(o)
 ... sys.__displayhook__(o)
 ...
  import sys
  sys.displayhook = DH()

Other than the quotes around the formula,

  a = '[sin(x), cos(x)]'
  x=0.0
  a
 [0.0, 1.0]
  x=1.0
  a
 [0.8414709848078965, 0.54030230586813977]

looks a lot like

 
 I'm looking for array of functions.
 Something like a=[ sin(x) , cos(x) ]

  x=0.0
  a
 [0, 1]
  x=1.0
  a
 ...

 of course it can be made by
  def cratearray(x):
 ...   
 ...   return a
 a=createarray(1.0)

 but this isn't what i am asking for. something automized.


Of course, this is not what the OP _really_ wanted ;-)

But it's kind of fun. Anything you type in quotes is evaluated
using available global bindings plus the ones in the math module
and __builtins__, and it's recursive, so if a name in the quoted
formula refers to another string (which must be a valid expression),
that is evaluated, and so on. This is pull based on interactive
display trigger ;-)

  x='pi/6'
  a
 [0.49994, 0.86602540378443871]

  x='pi/6'
  a
 [0.49994, 0.86602540378443871]
  x = 'pi/y'
  y=6
  a
 [0.49994, 0.86602540378443871]
  y=3
  a
 [0.8660254037844386, 0.50011]

The display hook passes through non-strings, so you can box a string formula to 
see it:

  [a]
 ['[sin(x), cos(x)]']
  [x]
 ['pi/y']
  [y]
 [3]


You could specify your spread sheet:

  a1,a2,a3=100,200,'sum([a1,a2])'
  a1,a2,a3
 (100, 200, 'sum([a1,a2])')
  a1
 100
  a2
 200
  a3
 300

;-)


(2) Pull model: lazy evaluation. Have some flag on whether an
independent quantity has been changed. When evaluating a dependent
quantity, survey its independent quantities recursively, and update the
cached copies whereever necessary.

Of course, combination of the two approaches is possible.

For Python, metaclasses and/or decorators and/or properties may help.

But functional languages are a more natural territory.


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


Re: XML parsing per record

2005-04-23 Thread Kent Johnson
Willem Ligtenberg wrote:
Is there an easy way, to couple data together. Because I have discoverd an
irritating feature in the xml file.
Sometimes this is a database reference:
Dbtag
Dbtag_dbUCSC/Dbtag_db
Dbtag_tag
Object-id
Object-id_str1234/Object-id_str
/Object-id
/Dbtag_tag
/Dbtag
And sometimes:
Dbtag
Dbtag_dbUCSC/Dbtag_db
Dbtag_tag
Object-id
Object-id_id1234/Object-id_id
/Object-id
/Dbtag_tag
/Dbtag
So I get a list database names and two! lists of ID's
And those two are in no way related. Is there an easy way to create a
dictionary like this DBname -- ID
If not, I still might need to revert to SAX... :(
None of your requirements sound particularly difficult to implement. If you would post a complete 
example of the data you want to parse and the data you would like to end up it would be easier to 
help you. The sample data you posted originally does not have many of the fields you want to extract 
and your example of what you want to end up with is not too clear either.

If you are having trouble with ElementTree I expect you will be completely lost with SAX, 
ElementTree is much easier to work with and cElementTree is very fast.

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


Re: Python or PHP?

2005-04-23 Thread Mage
Tim Tyler wrote:

Mage [EMAIL PROTECTED] wrote or quoted:

  

check this: http://wiki.w4py.org/pythonvsphp.html



Good - but it hardly mentions the issue of security - which seems
like a bit of a problem for PHP at the moment.
  

I don't think so. Bad programmers are able to write bad programs in any
language. Maybe there are more bad php programmers than python
programmers and the 70% of the dynamic world wide web is copied from
user comments in the php.net/manual. However one of the worst cases is
the sql injection attack. And sql injections must be handled neither by
php nor by python but by the programmer.

I think a website or even a large portal is a well constructed database
with triggers and stored procedures and some echo, if, foreach and
while in the php code.

To me the advantage of python seems to come out when you deal with xml,
file handling or when you have to write a native server application for
your website. But I am so new here, others may say other things.

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


func_code vs. string problem

2005-04-23 Thread Filip Dreger
Each function has a func_code property that is suposed to contain the 
pure bytecode of the function. All the context (including reference to 
relevant namespaces) is stored in different fields of the function 
object. Since 'exec' is able to execute any string or bytecode in the 
current scope, it would seem possible to execute code of any function 
in any namespace. But no matter how I tried, I could not do it. There 
must be something I am missing.
Here's what I do:(if anyone wants to help, I placed the source 
under http://www.bajobongo.net/foo.py - tested on Python 2.4.1)

1. I declare a function. In the next steps I will try to run its code 
from inside a class:

def myfunction():
   print abc
   self.test()

2. I declare a class foo, with two methods. The first one tries to 
reach some local variables from a string passed to exec. The other one 
tries to do the same from inside a bytecode (from myfunction). IMHE 
this should make no difference to 'exec' - [spoiler: it does].

class foo:
   def test(self):
  print ABC
   def checkfunction(self):
  abc=10
  exec myfunction.func_code
   def checkstring(self):
  abc=10
  exec print abc;self.test()

3. I test the both methods. Sadly, the 'checkfunction' fails to find 
the correct namespace (id does not see 'abc' nor 'self'). Adding 
things like:
exec myfunction.func_code in globals(),locals() does not help.

i=foo()
i.checkstring()
i.checkfunction()  # this throws exception; why???

4. I try to find some help here, and hope to also gain better 
undesrtanding of how Python works :-)

Thanks for any suggestions,
regards,
Filip Dreger 


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


Re: Python or PHP?

2005-04-23 Thread Kirk Job Sluder
Lad [EMAIL PROTECTED] writes:

 Is anyone capable of providing Python advantages over PHP if there are
 any?
 Cheers,
 L.

PHP is strongly wedded to providing web-based content, while Python can
be used to build a large number of different types of applications.  

-- 
Kirk Job-Sluder
The square-jawed homunculi of Tommy Hilfinger ads make every day an
existential holocaust.  --Scary Go Round
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble Installing TTX/FontTools (asks for .NET FrameworkPackages)

2005-04-23 Thread Fredrik Lundh
Jesper Olsen wrote:

  Apparently setup.py tries to compile a c file, which of course
 doesn't
  work if there's no compiler.

 In fact it does not work even if there is a compiler - seems distutils
 has been broken in python2.4 (it works in python2.3).

distutils works just fine in 2.4.

but the standard Windows distribution of Python 2.4 is compiled with
a newer compiler.  if you don't have a compatible compiler on your
machine (or if the compiler isn't properly installed), setup won't be able
to build extensions for 2.4.

/F



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


Re: How to run Python in Windows w/o popping a DOS box?

2005-04-23 Thread Bengt Richter
On 22 Apr 2005 21:16:04 -0700, [EMAIL PROTECTED] wrote:

I think of it like the ''.join semantics. The object knows best how
to
handle join (even if it looks wierd to some people). In the #! case,
the program knows best how to start itself.

This I don't understand ;-)

With  ','.join(['a','b','c'])You rely on what wants to join the
sequence to handle the issue of joining rather than have the sequence
understand joining. I think of it as the object knows best.

I think of  #! as the program knowing best how to startup, rather
than having to rely on something else to deal with it. I also like the
My point was that the program -- whether script or executable --
_is_ depending on something else, i.e., whatever is launching it
in an appropriate environment, and my real point was that the launcher
looks at the beginning of the file contents to check what to do, rather
than looking at separate file metadata. I am objecting to embeddeding
metadata in data. The convention of using a first #! line in scripts
as metadata and passing the whole script to whatever interpreter
means that the interpreters have to know to ignore the first line
--usually meaning the '#' is a comment line start. Or else it has
to be told with a command line option like python's -x to ignore
extraneous metadata. Carrying metadata in file names and extensions
is not better, just different, and brings a bag of problems, like
having no identifier for the data per se, just its various containers.

text based simplicity and explictness. Just like text based etc files
on unix versus the registry in windows. And, if you want you can add
more power like use env variables in #!.
It can be as simple or as powerful as you need, you can use whatever
means you want to manage the #! line: text editors, other programs,
etc.  It is data-centric, just like http, sql, file I/O rather than
verb-centric (learn another whole set of methods to figure out how to
change startup).
I don't disagree about the usefulness of various text data, I just
want to distinguish data from metadata and container identifiers
from data identifiers.

hopefully I am making sense,

I think we were just looking a different aspects of the elephant ;-)

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


Re: Python or PHP?

2005-04-23 Thread Simon John
I've been a PHP and Perl programmer (amongst others) for 10 years or
more now, and a Python coder for 3 or so.

I have come to hate PHP now, it's pseudo-OOP is awful, it's dog slow at
handling XML, it's so easy to use that most of the programmers I've had
contact with are very sloppy and do things like extract($_GET); or put
database usernames and passwords in index.php. I also have to agree
that php.net/manual seems to be the main reference that coders use -
which is not good if the comments are wrong!

Python seems to force you to write better code, maybe because of the
indentation, exception handling, proper OOP etc. Plus it's not so tied
into web stuff, in fact most of my Python programming is for the
desktop.

I still love Perl, it's a bit of an art form, as there's more than one
way to do it, whereas Python usually only allows one way to do it,
which may or may not be a better mantra

I've come to allocate PHP the same standing as ASP, VB or Java - the
language is OK, but the programmers are usually crap.

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


Does numarray search for blas and lapack during installation?

2005-04-23 Thread Edward C. Jones
I have a PC with Debian sid installed. I install all my Python stuff in 
/usr/local. I just installed numarray 1.3.1. Blaslite and lapacklite 
were compiled. Did the installation process search for blas and lapack?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Imaging Library and PyGTK - color image path?

2005-04-23 Thread Jeremy Bowers
On Sat, 23 Apr 2005 10:20:29 +0200, Fredrik Lundh wrote:
 which discusses draw_rgb_image and friends, and says that if you can
 convert your PIL image to a  pixel data string or buffer object, you could
 use them to display the image.  here's some code that seems to do exactly
 that:
 
 http://www.mail-archive.com/pygtk@daa.com.au/msg07167.html
 
 (but maybe this is some kind of stupid a bitmap isn't a pixmap isn't an
 image thing?  if so, I suggest getting a modern windowing system ;-)

A varient; I was missing the gdk.pixbuf because I assumed that because
there was a gtk.pixbuf that I knew about, that I had all relevant data.
Were that the only pixbuf, that would be an atrocity. (Particularly odd
for GTK, the *Gimp* windowing toolkit.)

(It of course figures that was the google search; I think I tried
everything but that; python imaging library pygtk isn't anywhere near
as helpful, for instance.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: grouping subsequences with BIO tags

2005-04-23 Thread Bengt Richter
On Fri, 22 Apr 2005 16:01:42 -0700, Michael Spencer [EMAIL PROTECTED] wrote:

Steven Bethard wrote:
 Bengt Richter wrote:
 
 On Thu, 21 Apr 2005 15:37:03 -0600, Steven Bethard 
 [EMAIL PROTECTED] wrote:

 I have a list of strings that looks something like:
['O', 'B_X', 'B_Y', 'I_Y', 'O', 'B_X', 'I_X', 'B_X']

[snip]

 With error checks on predecessor relationship,
 I think I'd do the whole thing in a generator,

I'm curious why you (Bengt or Steve) think the generator is an advantage here. 
As Steve stated, the data already exists in lists of strings.

I hadn't seen your post[1], which I think is a nice crisp and clever solution 
;-)

I just wrote what I thought was a straightforward solution, anticipating that
the imput list might be some huge bioinfo thing, and you might want to iterate
through the sublists one at a time and not want to build the whole list of
lists as represented by your stack.

[1] I don't know why stuff arrives almost instantly sometimes, and sometimes 
quite
delayed and out of order, but it is a bit embarrassing to post a me-too without
relevant comment, or being able to decide whether to play open source leapfrog.
In this case, I don't see a lily pad on the other side of your code, other than
the memory aspect ;-)


The direct list-building solution I posted is simpler, and quite a bit faster.

L = ['O', 'B_X', 'B_Y', 'I_Y', 'O', 'B_X', 'I_X', 'B_X']

def timethem(lst, funcs = (get_runsSB, get_runsMS, get_runsBR)):
 for func in funcs:
 print shell.timefunc(func, lst)

   timethem(L)
  get_runsSB(...)  7877 iterations, 63.48usec per call
  get_runsMS(...)  31081 iterations, 16.09usec per call
  get_runsBR(...)  16114 iterations, 31.03usec per call


Michael


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


Re: gui developing

2005-04-23 Thread Phil Thompson
On Friday 22 April 2005 9:26 pm, John J. Lee wrote:
 R. C. James Harlow [EMAIL PROTECTED] writes:
  On Friday 22 April 2005 20:07, Grant Edwards wrote:
   I've never tried Qt.
 
  Qt, in my opinion, is as excellent as python in the consistency stakes,
  has the best documentation bar none, an excellent set of python bindings,
  the best free layout tool, and an active and helpful community.

 Qt's technical superiority is unchallenged (pretty much).

  The killer, of course, is that there's no free windows port, so if you're
  doing free software that you want to run on linux then you're stuffed.

 Soon to change: Qt 4 for Windows (and the corresponding PyQt) will be
 available under the GPL.  Dunno when Qt 4 is scheduled for though.  I
 wonder if BlackAdder will carry on with roughly similar price and
 licensing with Qt 4?

Qt 4 is scheduled for the end of Q2. The plan is that PyQt will follow fairly 
soon after, but there will be a number of releases with classes being added 
at each release. It will be some afterwards that the support matches that of 
Qt 3.

 Also, somebody outside Trolltech was also doing a port of Qt 3 GPL to
 Windows which apparently got quite a long way.  Whether that effort
 continues, and whether PyQt will support that 'unofficial' port, I
 don't know (not sure TT are hugely happy about the port, so perhaps
 PyQt's author - Phil Thompson - respecting the people at TT as I'm
 sure he does, won't support it).

With something like that you adopt a wait and see attitude to see if it 
gains any momentum.

 Poor old Phil Thompson is fated to answer the same licensing questions
 forever, though - an activity I suspect he dislikes even more than GUI
 application programming wink

But at least it means I can stop adding the phrase but it depends of which 
platform you are using to every sentence I utter.

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


Re: Python or PHP?

2005-04-23 Thread Fredrik Lundh
Mage wrote:

 I don't think so. Bad programmers are able to write bad programs in any
 language.

in PHP, good programmers are able to write bad programs without
even noticing.

(every successful server attack I've seen closely the last few years
have been through PHP.  it's totally without competition in this area)

 However one of the worst cases is the sql injection attack. And sql
 injections must be handled neither by php nor by python but by the
 programmer.

sql injection?  what's your excuse for not using data binding?

/F



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


Re: PDF Printing support from Python

2005-04-23 Thread M.E.Farmer
 You're use of the word driver is one with which I'm not
 familiar.  But I don't really do windows so it's probably a
 Widnowism.
It is a windowism but not exclusively ;).
http://www.collaborium.org/onsite/romania/UTILS/Printing-HOWTO/winprinters.html

This is the first link I found that mentioned drivers, but the last
time I installed Linux-Mandrake I saw a document that went into detail
about CUPS and windows printing.
It seems that cups is available for windows( they also use the word
driver )
http://www.cups.org/windows/index.php
Ghostscript for windows available here
http://www.ghostscript.com/
http://www.cs.wisc.edu/~ghost/

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


Re: Python or PHP?

2005-04-23 Thread Mage
Fredrik Lundh wrote:


sql injection?  what's your excuse for not using data binding?
  

I am not sure I truly understand your question.
So far my own servers didn't get successful sql injection attack. I just
saw some on other sites and did one for demonstration.

Avoid them is easy with set_type($value,integer) for integer values
and correct escaping for strings.

However, php programmers usually don't initialize their variables
because they don't have to do. They even turn off warnings and errors.
Our php errorlog at my full time working company is so huge I could cry.
We have php-copypasters.
I don't know anyone IRL who uses python. So I started to learn it.

   Mage


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


Re: Python or PHP?

2005-04-23 Thread Jeremy Bowers
On Sat, 23 Apr 2005 20:13:24 +0200, Mage wrote:
 Avoid them is easy with set_type($value,integer) for integer values and
 correct escaping for strings.

Avoiding buffer overflows in C is easy, as long as you check the buffers
each time.

The *existence* of a technique to avoid problems is not in question. The
problem is when the language makes it easier to *not* do the checks than
to do the checks. Any look at the real world shows that that pattern
causes trouble, and that clearly, the mere *existence* of a way to not get
in trouble is not sufficient in the general case.

Despite the fact that all you have to do to avoid cutting your finger off
with a saw is not stick your finger in the saw, most people, even
carpentry professionals, are going to want to use finger-guards and other
safety equipment. A programmer turning down such security protection
(without another good reason, which does happen), is being like the guy
too macho to use the finger guard; stupidity induced by arrogance, not
some one no longer using training wheels. Using PHP and futzing with SQL
directly is probably not a good enough reason, as surely PHP has safer
libraries available. (If not, my opinion of PHP goes down another notch.)

Data binding with something like SQLObject makes it *easier* to be secure
than insecure; barring an out-and-out bug in SQLObject (given the nature
of the requisite bug, it is extremely unlikely to have survived this
long), a programmer must go *way* out of their way to introduce the SQL
injection attacks that so plague PHP projects.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or PHP?

2005-04-23 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2005-04-23 15:53:17 +0200:
 Lad wrote:
 
 Is anyone capable of providing Python advantages over PHP if there are
 any?
  
 I am also new to python but I use php for 4 years. I can tell:
 
 - python is more *pythonic* than php
 - python has its own perfume
 http://www.1976.com.tw/image/trussardi_python_uomo.jpg  and it's nice.
 php doesn't have any smell
 - writing python programs you feel much better

No, *you* feel better. :)
 
 check this: http://wiki.w4py.org/pythonvsphp.html

The comparison found there is biased, the author is a Python
partisan.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python modules in home dir

2005-04-23 Thread Uche Ogbuji
On Sat, 2005-04-16 at 08:12 -0600, Uche Ogbuji wrote:
 On Sat, 2005-04-09 at 14:09 -0700, dzieciou wrote:
 
  I'm new-comer in Python.
  I want to install few Python modules (4Suite, RDFLib, Twisted and Racoon)
  in my home directory, since Python installation is already installed in the
  system
  and I'm NOT its admin.
  I cannot install pyvm (portable binary python machine) - have no such big
  quota.
  Any idea how can I solve it?
 
 To install 4Suite in the home dir, use an incantation such as:
 
 ./setup.py config --prefix=$HOME/lib
 ./setup.py install
 
 Note: I expect you also installed Python in your home dir?

BTW, I expanded on this suggestion at:

http://copia.ogbuji.net/blog/2005-04-16/Installing


-- 
Uche Ogbuji   Fourthought, Inc.
http://uche.ogbuji.nethttp://fourthought.com
http://copia.ogbuji.net   http://4Suite.org
Use CSS to display XML, part 2 - 
http://www-128.ibm.com/developerworks/edu/x-dw-x-xmlcss2-i.html
XML Output with 4Suite  AMara - http://www.xml.com/pub/a/2005/04/20/py-xml.html
Use XSLT to prepare XML for import into OpenOffice Calc - 
http://www.ibm.com/developerworks/xml/library/x-oocalc/
Schema standardization for top-down semantic transparency - 
http://www-128.ibm.com/developerworks/xml/library/x-think31.html

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


python and Tile Studio

2005-04-23 Thread André Roberge
Has anyone used Python with Tile Studio to create games?
http://tilestudio.sourceforge.net/
André
--
http://mail.python.org/mailman/listinfo/python-list


Re: XML file parsing with SAX

2005-04-23 Thread Uche Ogbuji
On Sat, 2005-04-23 at 15:20 +0200, Willem Ligtenberg wrote:
 I decided to use SAX to parse my xml file.
 But the parser crashes on:
   File /usr/lib/python2.3/site-packages/_xmlplus/sax/handler.py, line 38, 
 in fatalError
 raise exception
 xml.sax._exceptions.SAXParseException: NCBI_Entrezgene.dtd:8:0: error in 
 processing external entity reference
 
 This is caused by:
 !DOCTYPE Entrezgene-Set PUBLIC -//NCBI//NCBI Entrezgene/EN
 NCBI_Entrezgene.dtd
 
 If I remove it, it parses normally.
 I've created my parser like this:
 import sys
 from xml.sax import make_parser
 from handler import EntrezGeneHandler
 
 fopen = open(mouse2.xml, r)
 ch = EntrezGeneHandler()
 saxparser = make_parser()
 saxparser.setContentHandler(ch)
 saxparser.parse(fopen)
 
 And the handler is:
 from xml.sax import ContentHandler
 
 class EntrezGeneHandler(ContentHandler):
   
   A handler to deal with EntrezGene in XML
   
   
   def startElement(self, name, attrs):
   print Start element:, name
 
 So it doesn't do much yet. And still it crashes...
 How can I tell the parser not to look at the DOCTYPE declaration.
 On a website:
 http://www.devarticles.com/c/a/XML/Parsing-XML-with-SAX-and-Python/1/
 it states that the SAX parsers are not validating, so this error shouldn't
 even occur?

Just because it's not validating doesn't mean that the parser won't try
to read the external entity.

Maybe you're looking for 


feature_external_ges
Value: http://xml.org/sax/features/external-general-entities; 
true: Include all external general (text) entities. 
false: Do not include external general entities. 
access: (parsing) read-only; (not parsing) read/write


Quote from:

http://docs.python.org/lib/module-xml.sax.handler.html

But you're on pretty shaky ground in any XML 1.x toolkit using a bogus
DTDecl in this way.  Why go through the hassle?  Why not use a catalog,
or remove the DTDecl?


-- 
Uche Ogbuji   Fourthought, Inc.
http://uche.ogbuji.nethttp://fourthought.com
http://copia.ogbuji.net   http://4Suite.org
Use CSS to display XML, part 2 - 
http://www-128.ibm.com/developerworks/edu/x-dw-x-xmlcss2-i.html
XML Output with 4Suite  AMara - http://www.xml.com/pub/a/2005/04/20/py-xml.html
Use XSLT to prepare XML for import into OpenOffice Calc - 
http://www.ibm.com/developerworks/xml/library/x-oocalc/
Schema standardization for top-down semantic transparency - 
http://www-128.ibm.com/developerworks/xml/library/x-think31.html

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


Handling lists

2005-04-23 Thread [EMAIL PROTECTED]
I have a question on python lists.
Suppose I have a 2D list
list = [[10,11,12,13,14,78,79,80,81,300,301,308]]
how do I convert it so that I arrange them into bins  .
so If i hvae a set of consecutive numbers i would like to represent
them as a range in the list with max and min val of the range alone.
I shd get something like 
list = [[10,14],[78,81],[300,308]]

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


Using Ming on Windows

2005-04-23 Thread André Roberge
I tried to install Ming
(http://sourceforge.net/projects/ming/)
on Windows to use with Python *but*
I can't [/don't know how to] use make to install it.
Does anyone know where I could find a ready-made compiled
version for Windows to just put in my site-packages directory.
Any help would be appreciated.
André
--
http://mail.python.org/mailman/listinfo/python-list


Re: Handling lists

2005-04-23 Thread Mage
[EMAIL PROTECTED] wrote:

I have a question on python lists.
Suppose I have a 2D list
list = [[10,11,12,13,14,78,79,80,81,300,301,308]]
how do I convert it so that I arrange them into bins  .
so If i hvae a set of consecutive numbers i would like to represent
them as a range in the list with max and min val of the range alone.
I shd get something like 
list = [[10,14],[78,81],[300,308]]

  

Maybe:

list = [10,11,12,13,14,78,79,80,81,300,301,308]

new_list = []
start = 0
for i in range(1,len(list) + 1):
if i == len(list) or list[i] - list[i-1]  1:
new_list.append([list[start],list[i-1]])
start = i

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


Re: Python or PHP?

2005-04-23 Thread F. Petitjean
Le Sat, 23 Apr 2005 19:11:19 +0200, Fredrik Lundh a écrit :
 in PHP, good programmers are able to write bad programs without
 even noticing.

+1 QOTW

--- 
The use of COBOL cripples the mind; its teaching should, therefore, be
regarded as a criminal offense.
Dr. E.W. Dijkstra
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does numarray search for blas and lapack during installation?

2005-04-23 Thread RickMuller
IIRC, no. But the setup.py script is fairly easy to hack to link in
your own blas/lapack libraries.

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


Bounding box on clusters in a 2D list

2005-04-23 Thread [EMAIL PROTECTED]
If I have

ex: x = [[1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0],
 [1,1,1,0,1,1,0,0,0,0,0,1,1,1,1,0,0,0],
 [1,1,1,0,1,1,1,0,1,1,0,1,1,1,0,0,0,0],
 [0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0]]
what I want is a boundingbox over the region where we find clusters of
1's.So for instance in the above list first 3 roes and colums have 1's
so the area of that box is 3x3
so my final array should have an array of approx areas of clusters of
1's like
area = [ 9,4 ]
Hope I am clear with my question.

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


Re: func_code vs. string problem

2005-04-23 Thread Filip Dreger
I came up with a simpler description of the problem.
It's all in the simple source:

# we define 'print b' in three different ways: as a string,
# a bytecode and a function
string=print b
code=compile(string,'string','exec')
def function():
print b

# now we make functions that test if it is possible to execute 'print 
b'
# in some local scope

def execstring():
b=5
exec string

def execfunction():
b=5
exec function.func_code

def execcode():
b=5
exec code

execstring()   # works
execcode() # works
execfunction() # throws name error exception...

My problem is that both 'string' and 'code' are references to code 
objects, so they _should_ behave in the same way... I am close to 
giving up...
I am trying to find a way of executing functions without creating a 
nested scope, so they can share local and global namespace (even if 
they are declared in some other module). I _could_ turn them into 
strings and pass around as compiled objects, butthis would be very 
ugly. I am sure Python has some better, cleaner way to do this.

regards,
Filip Dreger 


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


  1   2   >