ANN: Austin -- CPython frame stack sampler 0.7.0

2019-07-30 Thread Gabriele
I am delighted to announce the release 0.7.0 of Austin. If you haven't 
heard of Austin before, it is a frame stack sampler for CPython. It can 
be used to obtain statistical profiling data out of a running Python 
application without a single line of instrumentation. This means that you 
can start profiling a Python application straightaway, even while it's 
running on a production environment, with minimal impact on performance.

The simplest way of using Austin is by piping its output to FlameGraph 
for a quick and detailed representation of the collected samples. The 
latest release introduces a memory profiling mode which allows you to 
profile memory usage.

Austin is a pure C application that has no other dependencies other than 
the C standard library. Its source code is hosted on GitHub at

https://github.com/P403n1x87/austin

The README contains installation and usage details, as well as some 
examples of Austin in action. Details on how to contribute to Austin's 
development can be found at the bottom of the page.

I hope that you can find Austin useful!

All the best,
Gabriele
-- 
https://mail.python.org/mailman/listinfo/python-list


[ANN] Austin -- CPython frame stack sampler v1.0.0 is now available

2019-10-20 Thread Gabriele
I am delighted to announce the release 1.0.0 of Austin. If you haven't 
heard of Austin before, it is a frame stack sampler for CPython. It can 
be used to obtain statistical profiling data out of a running Python 
application without a single line of instrumentation. This means that you 
can start profiling a Python application straightaway, even while it's 
running on a production environment, with minimal impact on performance.

The simplest way of using Austin is by piping its output to FlameGraph 
for a quick and detailed representation of the collected samples. The 
latest release introduces a memory profiling mode which allows you to 
profile memory usage.

Austin is a pure C application that has no other dependencies other than 
the C standard library. Its source code is hosted on GitHub at

https://github.com/P403n1x87/austin

The README contains installation and usage details, as well as some 
examples of Austin in action. Details on how to contribute to Austin's 
development can be found at the bottom of the page.

All the best,
Gabriele


What's New
==

- Added support for multi-process Python applications.
- Added support for Python 3.8.

Bugfixes


- Fixed support for WSL on Windows.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [ANN] Austin -- CPython frame stack sampler v1.0.0 is now available

2019-10-21 Thread Gabriele
Austin computes the deltas of resident memory between samples. That's
because resident memory is the closest to the actual space occupied in
physical memory.

I hope this answers your question!

Best,
G

On Mon, 21 Oct 2019, 22:37 Barry,  wrote:

>
>
> > On 20 Oct 2019, at 23:12, Gabriele  wrote:
> >
> > The
> > latest release introduces a memory profiling mode which allows you to
> > profile memory usage.
>
> I am curious how do you determine used memory for Python
> Program?
> What is you definition of “memory”?
>
> The reason I am asking is that I have looked into this for a production
> server app and found only approximations.
>
> Barry
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


[ANN] Austin -- Python frame stack sampler for CPython v1.0.1 is now available

2020-06-21 Thread Gabriele
I am delighted to announce the release 1.0.1 of Austin. If you haven't
heard of Austin before, it is a frame stack sampler for CPython. It can
be used to obtain statistical profiling data out of a running Python
application without a single line of instrumentation. This means that you
can start profiling a Python application straightaway, even while it's
running on a production environment, with minimal impact on performance.

The simplest way of using Austin is by piping its output to FlameGraph
for a quick and detailed representation of the collected samples. The
latest release introduces a memory profiling mode which allows you to
profile memory usage.

Austin is a pure C application that has no other dependencies other than
the C standard library. Its source code is hosted on GitHub at

https://github.com/P403n1x87/austin

The README contains installation and usage details, as well as some
examples of Austin in action. Details on how to contribute to Austin's
development can be found at the bottom of the page.

Austin v1.0.1 is also the first version of Austin to be available from 
Homebrew
for easy installation on MacOS. These are the other places where Austin 
can be
downloaded

Linux:
- Snap Store
- Debian repositories

Windows:
- Chocolatey

Furthermore, you can stay up-to-date with the project's development by
following Austin on Twitter (https://twitter.com/AustinSampler).

All the best,
Gabriele


Bugfixes


- Fixed Python 3.8 support on MacOS.
-- 
https://mail.python.org/mailman/listinfo/python-list


[ANN] Austin -- CPython frame stack sampler v2.0.0 is now available

2020-10-13 Thread Gabriele
I am delighted to announce the release 2.0.0 of Austin. If you haven't 
heard of Austin before, it is an open source frame stack sampler for 
CPython, distributed under the GPLv3 license. It can be used to obtain 
statistical profiling data out of a running Python application without a 
single line of instrumentation. This means that you can start profiling a 
Python application straightaway, even while it's running on a production 
environment, with minimal impact on performance.

The simplest way of using Austin is by piping its output to FlameGraph 
for a quick and detailed representation of the collected samples. The 
latest release introduces a memory profiling mode which allows you to 
profile memory usage.

Austin is a pure C application that has no other dependencies other than 
the C standard library. Its source code is hosted on GitHub at

https://github.com/P403n1x87/austin

The README contains installation and usage details, as well as some 
examples of Austin in action. Details on how to contribute to Austin's 
development can be found at the bottom of the page.

Austin can be installed easily on the following platforms and from the 
following sources:

Linux:
- Snap Store
- Debian repositories

macOS:
- Homebrew

Windows:
- Chocolatey
- Scoop

Austin is also simple to compile from sources as it only depends on the 
standard C library, if you don't have access to the above listed sources.

Besides support for Python 3.9, this new release of Austin brings a 
considerable performance enhancement that allows it to sample up to 8 
times faster than previous versions. But please do read on until the end 
to find out about some new tools that take advantage of all the key 
features of Austin.

Due to increasing popularity, the sample Python applications that were 
included in the main repository have been moved to dedicated projects on 
GitHub. The TUI can now be found at

https://github.com/P403n1x87/austin-tui

while Austin Web is now available from

https://github.com/P403n1x87/austin-web

They can both be installed easily from PyPI, but in order to use them the 
Austin binary needs to be on the PATH environment variable. These 
projects now rely on the austin-python Python package that provides a 
Python wrapper around Austin. If you are considering making your own 
profiling tool based on Austin, this package can spare you from writing 
boilerplate code, so it's worth having a look at it at

https://github.com/P403n1x87/austin-python

The documentation is hosted on RTD at

https://austin-python.readthedocs.io/en/latest/

Finally, I am happy to announce the release of pytest-austin, a plugin 
for pytest that allows you to set up performance regression testing by 
simply decorating your existing pytest test suite. The plugin launches 
Austin to profile your test runs, meaning that no further instrumentation 
is required. For more details, check out the project on GitHub

https://github.com/P403n1x87/pytest-austin

Like the other Austin tools, pytest-austin can be installed easily from 
PyPI.

You can stay up-to-date with the project's development by following 
Austin on Twitter (https://twitter.com/AustinSampler).

All the best,
Gabriele 


https://github.com/P403n1x87/austin";>Austin 2.0.0 -
frame stack sampler for CPython. (13-Oct-20)
-- 
https://mail.python.org/mailman/listinfo/python-list


getting columns attributes in declarative style with sqlalchemy

2011-10-28 Thread Gabriele
Hi,

   I'm tryed to write my first application using SqlAlchemy. I'm using
declarative style. I need to get the attributes of the columns of my
table. This is an example of my very simple model-class:

class Country(base):
__tablename__ = "bookings_countries"

id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
canceled = sqlalchemy.Column(sqlalchemy.Boolean, nullable=False,
default=False)
description = sqlalchemy.Column(Description)

def __init__(self, canceled, description):
self.canceled = canceled
self.description = description

def __repr__(self):
return "" % (self.description)

I want to populate a wx grid using the name of the fields as labels of
the columns.

I found three different solutions of my problem, but none satisfeid
me:

a) using column_descriptions in query object.

col = (model.Country.canceled, model.Country.description)
q =
self.parent.session.query(*col).order_by(model.Country.description)
l = [column["name"] for column in q.column_descriptions]

in this way, l contains exactly what I need, but I don't like because
I must execute an useless query only for having informations about the
structure of my table. Ok, it's not so big problem, but IMO is not a
very good solution

b) reflecting the table
c) using inspector lib from sqlachemy.engine

I don't like because I have to use directly the name of the table in
the database...

It sounds me better and logical to use my class Country... but I can't
find the simple way for doing that... maybe it's very simple, but...

Someone can help me?

Thanks

Gabriele




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


Re: getting columns attributes in declarative style with sqlalchemy

2011-11-02 Thread Gabriele

Il 01/11/2011 19.37, [email protected] ha scritto:

Sorry for the repost, if it does in fact repost.

I'm no SQLAlchemy expert, but I have used the Table and Column attribute 
objects from the model object to solve a similar problem in the past.  You can 
use the following syntax to do it:

[col.name for col in Country.__table__.columns._all_cols]


Thank you very much! This is exactly what I was looking for! Thanks!
Gabriele
--
http://mail.python.org/mailman/listinfo/python-list


ANN: emacs-for-python 0.2.1 released

2011-04-02 Thread Gabriele Lanaro
I'm pleased to announce the 0.2.1 release of emacs-for-python

*What is emacs-for-python?*

It's a collection of emacs extensions and settings to quickly setup the
editor for python development.

*Main features included:*

   - snippets
   - pymacs
   - ropemacs
   - auto-completion
   - on the fly synntax checking (flymake)
   - auto-pairing

For a complete list and instructions consult the README file:
https://github.com/gabrielelanaro/emacs-for-python

I've paid attention to the documentation. Read about using emacs efficiently
(tips, workflows, snippets...) in the wiki of the github project page:

https://github.com/gabrielelanaro/emacs-for-python/wiki

*Further Info about the release:*
http://pygabriel.blogspot.com/2011/04/emacs-for-python-021-release.html
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] Austin -- CPython frame stack sampler v2.1.1 is now available

2021-01-12 Thread Gabriele Tornetta
I am delighted to announce the release 2.1.1 of Austin. If you haven't
heard of Austin before, it is an open-source frame stack sampler for
CPython, distributed under the GPLv3 license. It can be used to obtain
statistical profiling data out of a running Python application without a
single line of instrumentation. This means that you can start profiling a
Python application straight away, even while it's running on a production
environment, with minimal impact on performance.

The simplest way of using Austin is by piping its output to FlameGraph or 
uploading it to speedscope.app for a quick and detailed representation of the 
collected samples.

Austin is a pure C application that has no other dependencies other than
the C standard library. Its source code is hosted on GitHub at

https://github.com/P403n1x87/austin

The README contains installation and usage details, as well as some
examples of Austin in action. Details on how to contribute to Austin's
development can be found at the bottom of the page.

Austin can be installed easily on the following platforms and from the
following sources:

Linux:
- Snap Store
- Debian repositories
- Conda Forge

macOS:
- Homebrew
- Conda Forge

Windows:
- Chocolatey
- Scoop

Austin is also simple to compile from sources as it only depends on the
standard C library, if you don't have access to the above-listed repositories.

This new release of Austin brings enhanced support for many Python binary 
distributions across all the supported platforms, as well as a bugfix for the 
line number reporting. If you rely on Austin 2, upgrading to the latest version 
is strongly recommended.

Let me also remind you of some of the other existing Python tools powered by 
Austin, which have also seen new releases in the past few days, and that are 
easily available from PyPI:

https://github.com/P403n1x87/austin-tui
https://github.com/P403n1x87/austin-web
https://github.com/P403n1x87/pytest-austin

These tools are built using the austin-python library, which is also available 
from PyPI, with source code hosted at

https://github.com/P403n1x87/austin-python

For anyone wishing to build their own Austin-powered tools, the austin-python 
documentation is hosted on RTD at

https://austin-python.readthedocs.io/en/latest/

You can stay up-to-date with the project's development by following
Austin on Twitter (https://twitter.com/AustinSampler).

All the best,
Gabriele

https://github.com/P403n1x87/austin";>Austin 2.1.1 -
frame stack sampler for CPython. (12-Jan-21)
-- 
https://mail.python.org/mailman/listinfo/python-list


[ANN] Austin -- CPython frame stack sampler v3.0.0 is now available

2021-07-02 Thread Gabriele Tornetta
I am delighted to announce the release 3.0.0 of Austin. If you haven't heard of 
Austin before, it is an open-source frame stack sampler for CPython, 
distributed under the GPLv3 license. It can be used to obtain statistical 
profiling data out of a running Python application without a single line of 
instrumentation. This means that you can start profiling a Python application 
straight away, even while it's running in a production environment, with 
minimal impact on performance.

The best way to leverage Austin is to use the new extension for VS Code, which 
brings interactive flame graphs straight into the text editor to allow you to 
quickly jump to the source code with a simple click. You can find the extension 
on the Visual Studio Marketplace and install it directly from VS Code:

https://marketplace.visualstudio.com/items?itemName=p403n1x87.austin-vscode

To see how to make the best of Austin with VS Code to find and fix performance 
issues, check out this blog post, which shows you the editor extension in 
action on a real Python project:

https://p403n1x87.github.io/how-to-bust-python-performance-issues.html

The latest release comes with many improvements, including a re-worked 
sleepless mode that now gives an estimate of CPU time, initial support for 
Python 3.10, better support for Python-based binaries like gunicorn, uWSGI, 
etc. on all supported platforms.

Austin is a pure C application that has no dependencies other than the C 
standard library. Its source code is hosted on GitHub at

https://github.com/P403n1x87/austin

The README contains installation and usage details, as well as some examples of 
Austin in action. Details on how to contribute to Austin's development can be 
found at the bottom of the page.

Austin can be installed easily on the following platforms and from the 
following sources:

Linux:
- Snap Store
- Debian repositories

macOS:
- Homebrew

Windows:
- Chocolatey
- Scoop

An Austin image, based on Ubuntu 20.04, is also available from Docker Hub:

https://hub.docker.com/r/p403n1x87/austin

Austin is also simple to compile from sources as it only depends on the 
standard C library if you don't have access to the above-listed sources.


You can stay up-to-date with the project's development by following Austin on 
Twitter (https://twitter.com/AustinSampler).

All the best,
Gabriele
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Continuations Based Web Framework - Seaside.

2005-01-02 Thread gabriele renzi
Mike Thompson ha scritto:
'Seaside' is a Smalltalk framework for what might be called "Modal Web 
Development" or "Synchronous Web Programming", or even "Continuation 
Based Web Apps".

http://www.beta4.com/seaside2/
Very sexy it looks too.  And it seems to be generating a lot of interest 
- Ruby and Java variants have already sprung up:

 http://rubyforge.org/projects/borges/
 http://lakeshore.sourceforge.net/
actually, there are also implementations in Scheme, Common Lisp 
(UnCommonWeb) and Cocoon-FLOW has similar concepts.
 And somewhere (I think on the portland pattern repository) I recall 
reading that Viaweb (aka "the first web app") was written in CPS. Also 
notice that the Wee project in ruby is more advanced that Borges.

I googled for the python spin-off but didn't find one. Closest I found 
was Imposter (http://csoki.ki.iif.hu/~vitezg/impostor/) which looks like 
an earlier, partially failed attempt to do what Seaside now seems to be 
delivering.
I think "independent" more than earlier, it seem many people are 
reinventing this from time to time.
Anyway, I just wanted to point out that IIRC something on this lines 
appeared recently in the nevow svn tree, maybe you can take a look.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Cookbook 2nd ed Credits (was Re: The Industry choice)

2005-01-05 Thread gabriele renzi
Jacek Generowicz ha scritto:
[EMAIL PROTECTED] (Alex Martelli) writes:

...but each still gets ONE free copy...!-)

Who gets Luther Blissett's copy ? :-)
And are all the Luther Blissetts the same Luther Blisset ?
no, some of them are Wu Ming
http://www.wumingfoundation.com/
(from http://www.lutherblissett.net/indexes/bibliography_it.html)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python evolution: Unease

2005-01-06 Thread gabriele renzi
Alex Martelli ha scritto:

But Alex is right; Envisage does hold a lot of promise.

The very concept of an architecture based on a spare skeleton and
copious plugins is intrinsically excellent, and I think that by now
eclipse has proven it's also practically viable for real-world powerful
IDEs/platforms/frameworks.
I think this had been demonstrated from emacs long before :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: a new Perl/Python a day

2005-01-10 Thread gabriele renzi
Bob Smith ha scritto:
Scott Bryce wrote:
Xah Lee wrote:
frustrated constantly by its inanities and incompetences.)

I don't see what this has to do with Perl.

You're joking, right?
please consider that the message you all are asking are crossposted to 
comp.lang.perl.misc and comp.lang.python, avoid the crossgroup flames :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Which kid's beginners programming - Python or Forth?

2005-06-29 Thread gabriele renzi
BORT ha scritto:
> All,
> 
> The Forth-Python pull was heading to a conclusion just like "Tastes
> Great" vs. "Less Filling" or Ford-Chevy.  However, friendly folks at
> comp.lang.forth pointed me to Amazon.com and _Mindstorms: Children,
> Computers, and Powerful Ideas_
> by Seymour Papert.  The book is by Logo's inventor and, according to
> the reviews, addresses the larger goal I most want to achieve.


I thought you were limiting the choice to python/forth.
Logo is a nice dialect of lisp, so I think you're making a good choice ;)

But I'd consider Squeak. It is the best educational-but-not-only 
environment I've seen (which does not mean there are not better, but 
I've seen quite a bit of them)

Squeak not only has programming at the hand but it also provide you with 
a complete educational system, with music, painting, animations etc. And 
there is nothing that could get a kid involved like making a rabbit explode.


> I now want to read the book.  Period.  However, my kids both love Legos
> which uses a Logo implementation for their robotics toys.  I could
> probably capture both the 10 yr old AND the 7 yr old if we can spring
> for the $200 Lego Mindstorm set.  Sort of blows away my specification
> of "free," but...
> 
> In my earlier browsing, I eliminated Logo early on, thinking we would
> hit its capability ceiling too quickly and then backtrack in order to
> make a transition to a "REAL" language.
> 
> uh... I've been browsing on Logo tonight and, even without the Lego
> robots, I may go that route.  Shoot, I thought Logo was just moving
> hokey sprites in increasingly complex patterns until I saw the book
> list at:
> 
> http://el.media.mit.edu/logo-foundation/products/books.html
> 
> Hmm...  When all is said and done, maybe the choice is kind of like
> physical exercise.  I can spend weeks choosing the most effective work
> out and diet combination.  But, until I cut back on biggie size grease
> brugers with double shakes and get off of the couch every now and then,
> the choice of workout is moot.  In fact, one I use is better than the
> "best" that I don't use.
> 
> Gentle folk of comp.lang.python, I heartily thank you all for your
> input.  I think I'm taking the boys through the door marked "Logo."  We
> may be back this way, though.  We will likely need MORE in the nebulous
> future.  I am impressed with the outpouring of support here!
> 
> Thanks to all!
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: python-constraint 1.0

2005-07-07 Thread gabriele renzi
Gustavo Niemeyer ha scritto:
> 
> Overview
> 
> 
> **python-constraint** [1]_ is a Python module offering solvers for
> Constraint Solving Problems (CSPs) over finite domains in simple
> and pure Python. CSP is class of problems which may be represented
> in terms of variables (`a`, `b`, ...), domains (`a in [1, 2, 3]`, ...),
> and constraints (`a < b`, ...).

This sound cool, but have you noticed logilab.constraint? Care to contrast?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Optional Static Typing

2004-12-25 Thread gabriele renzi
Mike Meyer ha scritto:
"John Roth" <[EMAIL PROTECTED]> writes:

<[EMAIL PROTECTED]> wrote in message
This may sound a bit
cynical, but most real uber-programmers have either
Lisp or Smalltalk in their backgrounds, and
frequently both one. Neither of those languages
have static typing, and they simply don't need it.

LISP has type declarations. Everybody I know doing production work in
LISP uses them. It's the only way to get reasonable performance out of
LISP compiled code.
I also think some smalltalk allow you to tag stuff with type hints for 
performance.

Which raises what, to me, is the central question. If we have optional
static typing, can I get a performance enhancement out of it? If not,
why bother?
for documentation and 'crash early' purposes, I'd say.
Btw, why don't we rip out the approach of CL and some schemes that offer 
optional typing ? (not that I understand how those work, anyway)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Complementary language?

2004-12-26 Thread gabriele renzi
Robin Becker ha scritto:
Alex Martelli wrote:
.
If you're looking for SERIOUS multiparadigmaticity, I think Oz may be
best --  (the book's
authors critique the vagueness of the "paradigm" concept, and prefer
"model", but that's much the same thing).

according to the language shootout at
http://shootout.alioth.debian.org/benchmark.php?test=all&lang=all&sort=cpu
Mozart/Oz comes last in cpu score. I suspect that may be due to 
unfamilarity or poor implementation of the test codes. Everybody 'knows' 
that benchamrks are always wrong, but which score moves this language to 
the top in your opinion?

He's talking of just "multiparadigmaticality", not efficiency.
The mozart/Oz platform have a stronger point on stuff like 
constraint/logic/declarative concurren/etc programming, more than most 
of the CL frameworks (not that this is hard in CL, it's just not as 
central as in Oz).  Btw, I think AliceML (which just hit 1.0) would be 
better than Oz, if accompaniying with python, just to have a 
dynamic/static contrast :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Complementary language?

2004-12-26 Thread gabriele renzi
Alex Martelli ha scritto:

Nolo contendere (not having looked much into Alice yet), but are there
stand-alone didactical materials for Alice as there are for Oz?  
> It
> seemed to me that the available materials for Alice basically take SML
> somewhat for granted, while Oz does come with tutorials which make no
> analogous assumptions.  If you're recommending Alice as the second
> language for somebody whose first and only language so far is Python,
> what URLs and/or books would you point them to, for self-stufy?
>
>
> Alex
probably not, AFAIK, and that's something I did'nt think of, thanks for 
pointing out.
Anyway, the Alice homepage references some ml tutorials for that subset 
of the language and documentation for the specific extensions.
Probably a unified tutorial would be much better, anyway, I agree.
--
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous function objects?

2005-04-28 Thread gabriele renzi
Uwe Mayer ha scritto:
Friday 29 April 2005 00:06 am Paul Rubin wrote:
Closest you can come is:
  f = lambda: sys.stdout.write("hello world\n")
 
Ah. :))
Why does the "print" statement return a syntax error here?
 ^

this is the reason :)
You can't have statements into an expression
--
http://mail.python.org/mailman/listinfo/python-list


Thread specific singleton

2006-06-09 Thread Gabriele Farina
Hi,

I'm tring to implement a Singleton object that should be specific for 
every thread who create it, not global.
I tried a solution that seems to work, but I have a very poor knowledge 
of concurrent programming, so I'd like someone to help me find some 
problems in my implementation.

Here is the code:

-

import thread

class ThreadLock(object):

 locks = {}

 def __new__(cls):
 id = thread.get_ident()
 try:
 lock = cls.locks[id]
 except KeyError:
 lock = thread.allocate_lock()
 cls.locks[id] = lock

 return lock

 @classmethod
 def clear(cls, id=None):
 """ Clear the lock associated with a given id.

 If the id is None, thread.get_ident() is used.
 """

 if id is None:
 id = thread.get_ident()
 try:
 del cls.locks[id]
 except KeyError:
 pass

class ThreadedSingleton(object):

 pool = {}

 def __new__(cls, *args, **kw):
 lock = ThreadLock()
 lock.acquire()

 id = thread.get_ident()
 try:
 obj = cls.pool[id]
 except KeyError:
 obj = object.__new__(cls, *args, **kw)
 if hasattr(obj, '__init_singleton__'):
 obj.__init_singleton__(*args, **kw)
 cls.pool[id] = obj

 lock.release()

 return obj

 def __del__(self):
 id = thread.get_ident()
 ThreadLock.clear(id)
 try:
 del cls.pool[id]
 except KeyError:
 pass

if __name__ == '__main__':

 import time
 import random

 class Specific(ThreadedSingleton):

 def __init_singleton__(self):
 print "Init singleton"
 self.a = None

 def test(a):
 s = Specific()
 s.a = a
 print "%d: %s" %(thread.get_ident(), Specific().a)
 time.sleep(1)
 print "%d: %s" %(thread.get_ident(), Specific().a)
 time.sleep(random.randint(1, 5))
 print "%d: %s" %(thread.get_ident(), Specific().a)
 time.sleep(2)
 print "%d: %s" %(thread.get_ident(), Specific().a)

 for x in range(4):
 thread.start_new_thread(test, (x, ))

 time.sleep(10)

-

using the thread module should be fine even if threads are created 
trought the threading module, right ?

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


Re: Getting access to the process table from python?

2010-01-13 Thread John Gabriele
On Jan 13, 1:41 pm, Roy Smith  wrote:
> I need to get information about what processes are running on a box.
> Right now, I'm interested in Solaris and Linux, but eventually
> probably other systems too.  I need to know things like the pid,
> command line, CPU time, when the process started running, and owner.
>
> Has anybody written a module to do this?  I know I can run ps and
> parse the output, or troll /proc directly, but if somebody's already
> written all that, I'd rather not reinvent the wheel.

You might visit the Cheeseshop and search for "process table" there.
Searching there, I see one good hit that looks like what you're after.

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


ctypes: nested structures and pointers

2010-01-18 Thread Gabriele Modena
Hi all,
I am trying to learn ctypes and I  am facing some problems In wrapping
two nested structs.

<--- begin C code >
struct dev_callbacks;// Prototype the callback struct

typedef struct {
  const struct dev_callbacks* pdc;
  char acName[DEVICE_NAME_LENGTH];
  chip_type ct;
  dev_spec ds;
  bool bActive;
  bool bCrc;
  bool bPar;
  uint8_t ui8TxBits;
} dev_info;

struct dev_callbacks {
  const char* acDriver;
  dev_info* (*connect)(const uint32_t uiIndex);
  bool (*transceive)(const dev_spec ds, const byte_t* pbtTx, const
uint32_t uiTxLen, byte_t* pbtRx, uint32_t* puiRxLen);
  void (*disconnect)(dev_info* pdi);
};

< End C code >

I have two problems with this code:

 1. what is the correct (pythonic) way to capture the prototype
definition of dev_callbacks and the relation between that structure
and dev_info?

 2. is it correct to wrap "connect", "transceive" and "disconnect" in
separate structures and reference them within  pyDEV_CALLBACKS?

The (stub) code I wrote for now looks like this:

class pyDEV_CALLBACKS(Structure):
_fields_ = [("acDriver", c_char_p), ("connect", c_void_p),
("transceive", c_bool), ("disconnect", c_void_p) ]


class pyDEV_INFO(Structure):
_fields_ = [ ("pdc", POINTER(pyDEV_CALLBACKS)), ("ct", c_ubyte),
("ds", c_void_p), ("acName", c_char * 256), ("bActive",
c_bool), ("bCrc", c_bool), ("bPar", c_bool), ("ui8TxBits", c_ubyte) ]


Passing the data structures to wrapper functions seem to work (the
data is initialized), but the result is not what expected (I presume
the  problems are related to memory alignment due to wrong
declarations),

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


Re: ctypes: nested structures and pointers

2010-01-18 Thread Gabriele Modena
On Mon, Jan 18, 2010 at 10:33 AM, Gabriele Modena
 wrote:
>  1. what is the correct (pythonic) way to capture the prototype
> definition of dev_callbacks and the relation between that structure
> and dev_info?
>
>  2. is it correct to wrap "connect", "transceive" and "disconnect" in
> separate structures and reference them within  pyDEV_CALLBACKS?

Solved.
The answer was in the doc:
http://docs.python.org/library/ctypes.html#structured-data-types
(_fields_ & _pack_).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Few early questions on Class

2010-03-03 Thread John Gabriele
Hi Subhabrata,

s/_init_/__init__/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Working group for Python CPAN-equivalence?

2010-03-03 Thread John Gabriele
On Mar 3, 7:45 am, Olof Bjarnason  wrote:
> Hi everybody!
>
> The "Where is CPAN for Python?" question keeps popping up, with
> answers ranging from "There is no CPAN for Python" and "We already
> have CPAN for Python" (confusing).
>
> I'm wondering - is there any work being done identifying ..
>
> (1) what is so good with CPAN?
> (2) how can it be brought to the Python world?
>
> Is there a working group/initiative for this? Web page? Discussion group?

Hi Olof,

Discussions about that often take place on the distutils-sig and
catalog-sig MLs.

People are currently working on making the Cheeseshop even better and
the situation is improving. Have a look at [Tarek's blog](http://
tarekziade.wordpress.com/) for more info.

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


Re: cpan for python?

2010-03-03 Thread John Gabriele
On Mar 2, 11:58 pm, John Bokma  wrote:
> Lie Ryan  writes:
> > On 03/03/2010 09:47 AM, TomF wrote:
>
> [..]
>
> >> There
> >> is also a program called cpan, distributed with Perl.  It is used for
> >> searching, downloading, installing and testing modules from the CPAN
> >> repository.  It's far more extensive than setuptools.  AFAIK the python
> >> community has developed nothing like it.
>
> > python have easy_install
>
> How easy is it to /remove/ something? ;-) (Last time I checked I read
> something like "manually remove the .egg"...
>

Have a look at [pip](http://cheeseshop.python.org/pypi/pip). It should
support uninstalling packages.

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


Re: Working group for Python CPAN-equivalence?

2010-03-04 Thread John Gabriele
On Mar 3, 9:11 pm, John Bokma  wrote:
> Philip Semanchuk  writes:
>
> > In other words, if I was a Perl user under Ubuntu would I use
> > the pkg manager to add a Perl module, or CPAN, or would both work?
>
> Both would work, but I would make very sure to use a separate
> installation directory for modules installed via CPAN.

What's worked best for me is: use *only* the apt system to install
modules into your system Perl (`/usr/bin/perl`) and use *only* cpan/
cpanp/cpanm to install modules into *your own* Perl (for example, you
may have installed into `/opt`).

> AFAIK there are also programs that pack CPAN modules/bundles into
> something the package manager can use to install.

Right. If you really want to install a module for which there's no
Debian package, and you don't want to install your own Perl, this is a
good route to take.

Incidentally, this is the same way I recommend handling the situation
with Python: Use only aptitude to install packages for your system
Python, and use only pip to install packages into your own Python
(which you built and installed elsewhere, ex., `/opt/py-2.6.4`).

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


Re: Working group for Python CPAN-equivalence?

2010-03-04 Thread John Gabriele
On Mar 3, 5:30 pm, Ben Finney  wrote:
>
> Terry Reedy  writes:
>
> > On 3/3/2010 12:05 PM, John Nagle wrote:
>
> > > CPAN enforces standard organization on packages. PyPi does not.
>
> This is, I think, something we don't need as much in Python; there is a
> fundamental difference between Perl's deeply nested namespace hierarchy
> and Python's inherently flat hierarchy.

What do you think that difference is? Both use nested namespaces. My
understanding is that if 2 different dists contain like-named
packages, and if a user installs both of them, they all just go to the
same place in the user's site-packages dir.

One difference I see is that the CPAN has a *lot* of dist's which
constitute a very large number of modules. Keeping them organized by a
semi-agreed-upon hierarchy of packages seems like a great
organizational tool.

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


Problems with relative imports and pep 366

2010-05-31 Thread Gabriele Lanaro
I've yet asked this question on SO, I'll copy the contents:

I have a "canonical file structure" like that (I'm giving sensible names
to ease the reading):

mainpack/

  __main__.py
  __init__.py 

  - helpers/
 __init__.py
 path.py

  - network/
 __init__.py
 clientlib.py
 server.py

  - gui/
 __init__.py
 mainwindow.py
 controllers.py

In this structure, for example modules contained in each package may
want to access the helpers utilities through relative imports in
something like:

# network/clientlib.py
from ..helpers.path import create_dir

The program is runned "as a script" using the __main__.py file in this
way:

python mainpack/

Trying to follow the PEP 366 I've put in __main__.py these lines:

___package___ = "mainpack"
from .network.clientlib import helloclient 

But when running:

$ python mainpack 
Traceback (most recent call last):
  File "/usr/lib/python2.6/runpy.py", line 122, in _run_module_as_main
"__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.6/runpy.py", line 34, in _run_code
exec code in run_globals
  File "path/mainpack/__main__.py", line 2, in 
from .network.clientlib import helloclient
SystemError: Parent module 'mainpack' not loaded, cannot perform relative import

What's wrong? What is the correct way to handle and effectively use
relative imports?

I've tried also to add the current directory to the PYTHONPATH, nothing
changes.

link:
http://stackoverflow.com/questions/2943847/nightmare-with-relative-imports-how-does-pep-366-work


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


Re: Vote to Add Python Package "pubsub" to the Python Standard Library

2010-06-02 Thread Gabriele Lanaro
I definitvely vote for adding such a package to the stdlib (or at least a
symilar publish/subscrive and observer implementation). It's useful in a
wide range of programs.


2010/6/2 Carl Banks 

> On May 26, 4:26 am, Tom  wrote:
> > I vote for adding the Python package "pubsub" to the Python standard
> > library.  It has recently been added to wxpython (replacing the old
> > wx.lib.pubsub package), but it has application to non-gui programs as
> > well.
>
>
> Well, I can definitely see a case for adding something like this to
> the standard library.  If there is a standard publish-subscribe
> implementation, then different third-party packages can use it in a
> consistent way together.  It can open whole paradigms of package
> integration.
>
> However, I'm not sure this particular library is the one to use, and I
> would not be in favor of throwing the first publish-subscribe
> implentation that comes by into the standard library, at least not
> without a whole lot of vetting first.  (They did that with optparse
> and the Python community has been paying for it ever since.)
>
> I think it has a pretty good chance of being accepted, too.  The
> publish-subscribe pattern, if you will, seems to have been implemented
> separately in many places.  The logging module in the standard library
> uses something like this.  Qt's signal/slot mechanism is another
> variation.  I'm sure there's lots more.  I've noticed that pointing
> out lots of independetnly crafted examples in the wild, and especially
> in the standard library, works quite well.
>
>
> Carl Banks
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Replace in large text file ?

2010-06-05 Thread Gabriele Lanaro
A module designed to do this is fileinput:

http://docs.python.org/library/fileinput.html

The approach is the same as the other except that it's in the standard
library.

2010/6/5 Paul Rubin 

> Steve  writes:
> > Remove all comma's
> > Replace all @ with comma's
> > Save as a new file.
>
> The simplest way is just copy the file one character at a time, making
> replacements to commas and @'s as stated.  That will be a bit slow
> (especially in Python) but if you only have to do it once, just wait it
> out.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUIs - A Modest Proposal

2010-06-06 Thread Gabriele Lanaro
I'd really like to s/tkinter/WxWidgets/g, the multiplatformness is (almost)
the same but wx looks infinitely better. IMHO a good intention is to best
the API of wx.
Anyway, GUI programmers usually choose the toolkit (often 3rd party) more
appropriate for the situation, wether it is or not in the standard library,
to cite again Java, python interface looks generally better than Java ones
because of this "freedom" of choicing the appropriate GUI.

Personally If I'll have to develop a windows GUI I will use IronPython
(choosing a different python implementation!).

My 2 cents

2010/6/6 Michael Torrie 

> On 06/05/2010 08:22 PM, ant wrote:
> > WxPython and PyGtk are both powerful, but quirky in different ways.
> > PyQt is tied to one platform. And there are dozens more.
>
> In what way is PyQt (or the new PySide bindings) tied to one platform?
> PyQt is "native" on Win32, Mac, and Linux.  Would your universal GUI be
> any less quirky?
>
> > I ask the group; should we try to create a new GUI for Python, with
> > the following properties?:
> > 
> > - Comprehensive, for complicated things - Cross-platform
> Most GUI toolkits currently are, to some degree or another.  Qt is the
> most comprehensive cross-platform toolkit that I know of.  You can
> pretty much do any application operation using its API.
>
> > - Looks good (to be defined)
> Does that mean it looks native?  Should it be native?  Does not the
> Tkinter gui look "good?"
>
> I can think of at least the following reasons why a new universal GUI
> for Python will have acceptance issues:
>  - stuck with the lowest common denominator of functionality on each
> platform if you thunk to native widgets (a la wxWidgets)
>  - often look and feel is not quite native even when using native themes
> (GTK on windows, for example)
>  - if you take the Java Swing approach, you'll look out of place
> everywhere, which is kind of where tkinter is now.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Syntax problem - cannot solve it by myself

2010-06-08 Thread Gabriele Lanaro
The print function you're trying to use is for python 3 version only, If you
want to keep reading the book, install python 3, else take a book that
covers python 2.x syntax

2010/6/8 Deadly Dirk 

> I am a total beginner with Python. I am reading a book ("The Quick Python
> Book", 2nd edition, by Vernon Ceder) which tells me that print function
> takes end="" argument not to print newline character. I tried and here is
> what happens:
>
> >>> print(x)
> abc
> >>> print(x,end="")
>  File "", line 1
>print(x,end="")
>   ^
> SyntaxError: invalid syntax
> >>>
>
> What does the error message mean? I am using Python 2.6.5 on Ubuntu 9.10.
>
>
> --
> The missionaries go forth to Christianize the savages -
> as if the savages weren't dangerous enough already.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Python distributing localization files

2010-06-17 Thread Gabriele Lanaro
Hi, I want to localize my application (a pygtk gui app), what's the best way
to distribute and install localization files?
I'm currently using `distribute` to package it.

Any suggestion?
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN]: Emacs For Python 0.1, collection of emacs extensions for python development

2010-07-01 Thread Gabriele Lanaro
Emacs For Python 0.1

Emacs for python  (epy) is  a collection of emacs extensions for python
development, yet ready and configured for you.
It includes also tweaks to commonly used extension to provide extra
functionality and fast bug correction. There are also sane configuration
that helps you getting started pretty fast.

Some of the most important extensions configured and included in the
distribution are:

   - ido prompts
   - autocompletion + rope (if you have pymacs)
   - snippets, simplified and standard-compliant
   - automatic error/warning/info highlighting with flymake (powered by
   pyflakes)
   - custom keybindings
   - much more (really)

I remaind you for further information to the home page:
http://gabrielelanaro.github.com/emacs-for-python/

You'll find additional information on the github page (readme and wiki):
http://github.com/gabrielelanaro/emacs-for-python

Thank you for the attention!

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


[ANN] Emacs For Python 0.1, collection of emacs extensions for python development

2010-07-02 Thread Gabriele Lanaro
Emacs For Python 0.1

Emacs for python  (epy) is  a collection of emacs extensions for python
development, yet ready and configured for you.
It includes also tweaks to commonly used extension to provide extra
functionality and fast bug correction. There are also sane configuration
that helps you getting started pretty fast.

Some of the most important extensions configured and included in the
distribution are:

   - ido prompts
   - autocompletion + rope (if you have pymacs)
   - snippets, simplified and standard-compliant
   - automatic error/warning/info highlighting with flymake (powered by
   pyflakes)
   - custom keybindings
   - much more (really)

I remaind you for further information to the home page:
http://gabrielelanaro.github.com/emacs-for-python/

You'll find additional information on the github page (readme and wiki):
http://github.com/gabrielelanaro/emacs-for-python

Thank you for the attention!

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


Re: Speed-up for loops

2010-09-04 Thread Gabriele Lanaro
Maybe for the simple sum you can just use the sum builtin:
python -m timeit -s  'sum((10,)*1)'
1000 loops, best of 3: 0.0985 usec per loop

About the loop in general it's a good practice to use list comprehension and
generator expressions

2010/9/2 Michael Kreim 

> Hi,
>
> I was comparing the speed of a simple loop program between Matlab and
> Python.
>
> My Codes:
> $ cat addition.py
> imax = 10
> a = 0
> for i in xrange(imax):
>a = a + 10
> print a
>
> $ cat addition.m
> imax = 1e9;
> a = 0;
> for i=0:imax-1
>a = a + 10;
> end
> disp(a);
> exit;
>
> The results look like this:
> $ /usr/bin/time --verbose python addition.py
> 100
>Command being timed: "python addition.py"
>User time (seconds): 107.30
>System time (seconds): 0.08
>Percent of CPU this job got: 97%
>Elapsed (wall clock) time (h:mm:ss or m:ss): 1:50.09
>[...]
>
> $ /usr/bin/time --verbose matlab -nodesktop -nosplash -r "addition"
> [...]
>1.e+10
>Command being timed: "matlab -nodesktop -nosplash -r addition"
>User time (seconds): 7.65
>System time (seconds): 0.18
>Percent of CPU this job got: 94%
>Elapsed (wall clock) time (h:mm:ss or m:ss): 0:08.25
>[...]
>
> Unfortunately my Python Code was much slower and I do not understand why.
>
> Are there any ways to speed up the for/xrange loop?
> Or do I have to live with the fact that Matlab beats Python in this
> example?
>
> Thanks a lot for your answers.
>
> With best regards,
>
> Michael
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Adding methods to an object

2005-10-13 Thread Gabriele *darkbard* Farina
Hi, there is a way to add methods to an object dynamically? I need to
do something like this. I remember python allowed this ...

class A(object):
 def do(s, m):
  print m

 @staticmethod
 def init(obj):
  obj.do = A.do

class Test(object):
 pass

o = Test()
A.init(o)

o.do(10)

Now it gives me an error ... unbound method ...

tnx, gabriele

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


cgi, reusing html. common problem?

2005-09-01 Thread John M. Gabriele
I'm putting together a small site using Python and cgi.

(I'm pretty new to this, but I've worked a little with
JSP/servlets/Java before.)

Almost all pages on the site will share some common (and
static) html, however, they'll also have dynamic aspects.
I'm guessing that the common way to build sites like this
is to have every page (which contains active content) be
generated by a cgi script, but also have some text files
hanging around containing incomplete html fragments which
you read and paste-in as-needed (I'm thinking:
header.html.txt, footer.html.txt, and so on).

Is that how it's usually done? If not, what *is* the
usual way of handling this?

Thanks,
---John

-- 
--- if contacting via email, remove zees ---


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


Re: cgi, reusing html. common problem?

2005-09-01 Thread John M. Gabriele
On Thu, 01 Sep 2005 09:20:51 +0200, Diez B. Roggisch wrote:

> John M. Gabriele wrote:
>> I'm putting together a small site using Python and cgi.
>> 
>> (I'm pretty new to this, but I've worked a little with
>> JSP/servlets/Java before.)
>> 
>> Almost all pages on the site will share some common (and
>> static) html, however, they'll also have dynamic aspects.
>> I'm guessing that the common way to build sites like this
>> is to have every page (which contains active content) be
>> generated by a cgi script, but also have some text files
>> hanging around containing incomplete html fragments which
>> you read and paste-in as-needed (I'm thinking:
>> header.html.txt, footer.html.txt, and so on).
>> 
>> Is that how it's usually done? If not, what *is* the
>> usual way of handling this?
> 
> The basic idea is correct - but there are sooo many other people that 
> had the same problem, and thus they creted web-framworks like e.g. 
> CherryPy or Django or... and then there is ZOPE. Search this group for 
> webframeworks, and you might get more answers than you wanted :)
> 
> Diez


Thanks Diez. Glad to hear I'm on the right track. :)

>From poking around, it looks to me like these Python web
frameworks are to Python as JSP is to Java.

I really don't want to use a "templating language" (a la
JSP) -- I was hoping to just stick with straight Python
and then also html + css. Though I've heard good things
about CherryPy.

Looks like mod_python also comes with it's own solution too:
http://www.onlamp.com/pub/a/python/2004/02/26/python_server_pages.html



-- 
--- if contacting via email, remove zees ---


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


Re: cgi, reusing html. common problem?

2005-09-01 Thread John M. Gabriele
On Thu, 01 Sep 2005 13:12:14 +0100, Fuzzyman wrote:

> On Thu, 01 Sep 2005 03:10:07 -0400, "John M. Gabriele"
> <[EMAIL PROTECTED]> wrote:
> 
>>I'm putting together a small site using Python and cgi.
>>
>>(I'm pretty new to this, but I've worked a little with
>>JSP/servlets/Java before.)
>>
>>Almost all pages on the site will share some common (and
>>static) html, however, they'll also have dynamic aspects.
>>I'm guessing that the common way to build sites like this
>>is to have every page (which contains active content) be
>>generated by a cgi script, but also have some text files
>>hanging around containing incomplete html fragments which
>>you read and paste-in as-needed (I'm thinking:
>>header.html.txt, footer.html.txt, and so on).
>>
>>Is that how it's usually done? If not, what *is* the
>>usual way of handling this?
>>
> 
> Having a template and inserting dynamic values into it is very common.
> 
> You'll have more luck looking for  'python templating systems'.
> 
> I use a module called 'embedded code' - which is part of firedrop by
> Hans Nowak. See http://www.voidspace.org.uk/python/firedrop2/
> 
> Popular templating engines include Cheetah and TAL.
> 
> You can also roll your own basic one using the string method
> ``replace``. 


Thanks for the reply Fuzzy.

I'm going to try rolling my own. I found this *great* article:
http://www.devshed.com/index2.php?option=content&task=view&id=198&pop=1&page=0&hide_js=1

and it shows pretty much exactly what I think I want: separate
html files containing fragments of a complete page, then some
python code to read in the html fragment, and replace your
generated code with some placeholder.


> 
> I'm pretty sure their is an entry on the Python.org WIKI about
> templating.

Whoops. I ended up hitting this page first:
http://wiki.python.org/moin/CgiScripts
and now I'm sticking with it. :)

I like CGI. I want to keep things as simple as possible. :)

---John


> 
> All the best,
> 
> Fuzzy
> http://www.voidspace.org.uk/python
> 
> 
>>Thanks,
>>---John

-- 
--- if contacting via email, remove zees ---


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


Re: cgi, reusing html. common problem?

2005-09-01 Thread John M. Gabriele
On Thu, 01 Sep 2005 19:10:14 +0200, Walter Dörwald wrote:

> John M. Gabriele wrote:
> 
>> I'm putting together a small site using Python and cgi.
>> 
>> (I'm pretty new to this, but I've worked a little with
>> JSP/servlets/Java before.)
>> 
>> Almost all pages on the site will share some common (and
>> static) html, however, they'll also have dynamic aspects.
>> I'm guessing that the common way to build sites like this
>> is to have every page (which contains active content) be
>> generated by a cgi script, but also have some text files
>> hanging around containing incomplete html fragments which
>> you read and paste-in as-needed (I'm thinking:
>> header.html.txt, footer.html.txt, and so on).
>> 
>> Is that how it's usually done? If not, what *is* the
>> usual way of handling this?
> 
> I don't know if it's the *usual* way, but you could give XIST a try 
> (http://www.livinglogic.de/Python/xist). It was developed for exactly 
> this purpose: You implement reusable HTML fragments in Python and you 
> can use any kind of embedded dynamic language (PHP and JSP are supported 
> out of the box).
> 
> Bye,
> Walter Dörwald

Thanks Walt. :) Though, it seems simpler to me to just stick with some
plain vanilla static html, and pull that in to my cgi scripts as
necessary.

---John

-- 
--- if contacting via email, remove zees ---


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


Re: cgi, reusing html. common problem?

2005-09-01 Thread John M. Gabriele
On Thu, 01 Sep 2005 20:57:56 -0500, Steve Holden wrote:

> John M. Gabriele wrote:
>> [snip]
>> 
>> Is that how it's usually done? If not, what *is* the
>> usual way of handling this?
>> 
> There are a million ways to solve this particular problem, despite 
> Python's "TSBOAPOOOWTDI" (see "import this") philosophy (because the 
> philosophy is addressing primitive programming rather than application 
> frameworks).

Yes. :)

> You could do something as simple as writing a module "webPage" that 
> defines a function page(path, content) that does something along the 
> lines of:
> 
> def page(path, content):
>  return """\
> 
> If you want titles, add another argument
> 
> 
>  the path given as an argument - I'm just ignoring it in this example>
> %s
> 
> 
> """ % content

Ah yes, I see. If the content is completely static, you
can use a text file (html fragment) and just read it and
paste it in, but for fragments that are *mostly* static,
I really like that idea to use a module as you suggest.


> [snip]
> 
> Hope this gives you a few ideas. This problem has been considered by 
> many people, but clearly no outstanding solution has yet been devised, 
> otherwise we'd all be using it.
> 
> regards
>   Steve

Thanks Steve!

---John

-- 
--- if contacting via email, remove zees ---


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


Is Python as capable as Perl for sysadmin work?

2005-02-07 Thread John M. Gabriele
I recently posted this sort of question to the c.l.p.m but
didn't get much of a response. I know a little Perl and a
little Python, but master neither at the moment.

I see that Python is a general purpose OO programming language
that finds use among some system administrators, but my guess
is that Perl is still more common in that area than Python.

For sysadmin-related tasks, is Python as useful as Perl, or
does it get clumsy when often dealing with the stuff admins
deal with on a regular basis?

At some point during some dingy job in the back boiler room
of Unix, would you find yourself saying, "geez, I'd wish I
started this with Perl -- Python just isn't cutting it." ?

Thanks,
---J

-- 
--- if replying via email, remove zees ---


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


Re: Is Python as capable as Perl for sysadmin work?

2005-02-07 Thread John M. Gabriele
On Mon, 07 Feb 2005 20:13:30 -0800, beliavsky wrote:

> 
> [snip]
> 
> I'm a Windows user, not a Unix sysadmin, but I've noticed that
> Cameron Laird has written several articles on Python for system
> administration in Unix Review and Sys Admin magazine, for example
> http://www.unixreview.com/documents/s=9083/sam0401d/ . Reading his
> articles may help you decide if Python is a good fit for your work.

Great series of articles. Thanks for the link. :)

-- 
--- if replying via email, remove zees ---


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


Re: Is Python as capable as Perl for sysadmin work?

2005-02-08 Thread John M. Gabriele
Aahz wrote:
[snip]
Anyway.  Have you ever noticed how shell scripts keep getting longer?
Yup.
Ever notice how it gets harder to figure out what the heck any given
script's doing?
Yup.
 Well, that's where Python helps you out compared to
Perl.  Python can be a bit clumsier than Perl for dirt-simple tasks, but
you'll find that Python scales much better than Perl.
Check. Thanks Aahz. :)
--
-- remove zees if contacting via email --
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python as capable as Perl for sysadmin work?

2005-02-08 Thread John M. Gabriele
Nick Vargish wrote:
"John M. Gabriele" <[EMAIL PROTECTED]> writes:

At some point during some dingy job in the back boiler room
of Unix, would you find yourself saying, "geez, I'd wish I
started this with Perl -- Python just isn't cutting it." ?

Sometimes I have to write a quick script in Perl because Python isn't
ubiquitous enough around here, and I often find myself thinking I
the opposite... "Perl just isn't cutting it."
And I spent several years putting food on the table with Perl, so it's
not like I'm a noob with Perl.
Nick
Thanks Nick (and everyone else) for the replies. Much appreciated.
--
--- remove zees if replying via email ---
--
http://mail.python.org/mailman/listinfo/python-list


difference between class methods and instance methods

2005-02-16 Thread John M. Gabriele
I've done some C++ and Java in the past, and have recently learned
a fair amount of Python. One thing I still really don't get though
is the difference between class methods and instance methods. I
guess I'll try to narrow it down to a few specific questions, but
any further input offered on the subject is greatly appreciated:

1. Are all of my class's methods supposed to take 'self' as their
first arg?

2. Am I then supposed to call them with MyClass.foo() or instead:

bar = MyClass()
bar.foo()
?

3. Is "bound method" a synonym for instance method?

4. Is "unbound method" a synonym for class method?

And if anyone's *really* daring:
Where do the so-called "static methods" fit into all this?
By the name of them, it sounds like the same thing as class
methods...

Much thanks,
---J

-- 
--- if replying via email, remove zees ---


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


Like overloading __init__(), but how?

2005-02-23 Thread John M. Gabriele
I know that Python doesn't do method overloading like
C++ and Java do, but how am I supposed to do something
like this:

- incorrect 
#!/usr/bin/python

class Point3d:
  pass

class Vector3d:
  """A vector in three-dimensional cartesian space."""

  def __init__( self ):
"""Create a Vector3d with some reasonable default value."""
x, y, z = 0.0, 0.0, 0.0


  def __init__( self, x_from, y_from, z_from,
  x_to,   y_to,   z_to ):
"""Create a Vector3d from x-y-z coords."""
# ...
pass


  def __init__( self, point_from, point_to ):
"""Create a Vector3d from two Point3d objects."""
# ...
pass
  

  def __init__( self, same_as_this_vec ):
"""Create a Vector3d from a copy of another one."""
# ...
pass

p = Point3d()
p2 = Point3d()
# v = Vector3d( p2, p ) -- Nope. Only the last __init__() counts.
 
-- /incorrect ---

Thanks.

-- 
--- if replying via email, remove zees ---


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


Re: Like overloading __init__(), but how?

2005-02-23 Thread John M. Gabriele
On Wed, 23 Feb 2005 21:32:52 -0700, Steven Bethard wrote:

> [snip]
> Another possibility is to play around with *args:
> 
> class Vector3d(object):
>  def __init__(self, *args):
>  if not args:
>  # constructor with no arguments
>  elif len(args) == 6:
>  # constructor with xyz coords
>  elif len(args) == 2:
>  # constructor with points
>  elif len(args) == 1:
>  # copy constructor
>  else:
>  raise TypeError('expected 0, 1, 2 or 6 args, got %i' %
>  len(args))
> 
> But this can get really ugly really quick.
> 
> HTH,
> 
> STeVe

Thanks STeVe. I think, for now, I'll probably stick with
the easier but less elegant way of checking *args. I guess
I could compare args[0].__class__.__name__  against 'Point3d',
'Vector3d', or just 'float'.

Didn't realize this topic came up recently. Sorry for the
duplication.

---J

-- 
--- if replying via email, remove zees ---


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


Extracting Font Outline informations

2005-04-04 Thread Gabriele *Darkbard* Farina
Hi,
there is a Python library that makes me able to extract outline 
informations from font files? I'd like to manage TrueType and FreeType 
fonts ...

I searched for som wrappers, but I didn't find anything ...
bye
--
http://mail.python.org/mailman/listinfo/python-list


OOP: method overriding works in mysterious ways?

2006-01-02 Thread John M. Gabriele
Consider the following:

#!/usr/bin/python

#-
class Grand_parent( object ):

 def speak( self ):
 print 'Grand_parent.speak()'
 self.advise()

 def advise( self ):
 print 'Grand_parent.advise()'
 self.critique()

 def critique( self ):
 print 'Grand_parent.critique()'


#-
class Parent( Grand_parent ):

 def speak( self ):
 print '\tParent.speak()'
 self.advise()

 def advise( self ):
 print '\tParent.advise()'
 self.critique()

 # ATM, the Parent is at a loss for words, and has no critique.


#-
class Child( Parent ):

 def speak( self ):
 print '\t\tChild.speak()'
 self.advise()

 # Currently, the Child has no really useful advice to give.

 def critique( self ):
 print '\t\tChild.critique()'


#-
print 'speak() calls advise(), then advise() calls critique().'
print

people = [ Grand_parent(), Parent(), Child() ]
for person in people:
 person.speak()
 print




The output is:

speak() calls advise(), then advise() calls critique().

Grand_parent.speak()
Grand_parent.advise()
Grand_parent.critique()

 Parent.speak()
 Parent.advise()
Grand_parent.critique()

 Child.speak()
 Parent.advise()
 Child.critique()


What's going on here with that last "Child.critique()"? The
Parent called self.critique(), and since it *had* no critique()
method, it should've deferred to it's parent's critique()
method, right? But instead, somehow Child.critique() got called.
Why?

---J

-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OOP: method overriding works in mysterious ways?

2006-01-02 Thread John M. Gabriele
Scott David Daniels wrote:
> Dustan wrote:
> 
>>  From my experience, the methods are passed
>> down, not referred to from the parent. That is, Parent does have its
>> own critique method, not a reference to Grand_parent.critique(). 
> 
> This is typical of static binding as (for example) seen in C++.  If you
> think of dynamically bound systems like Smalltalk, Ruby, and Python, the
> more unusual case is wanting to go up the hierarchy (where you use super
> to get the behavior you are apparently expecting).  Think of Python's
> method dispatch as always being "virtual".

Ah. Not only that, but the other ingredient (I think) is to keep in mind 
that you're always calling instance methods via the self object -- and 
that self object is always the same object regardless of how far up the 
inheritance tree you go with those method calls, right?

> --Scott David Daniels
> [EMAIL PROTECTED]

---J
-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OOP: method overriding works in mysterious ways?

2006-01-02 Thread John M. Gabriele
Dustan wrote:
> [snip] That is, Parent does have its
> own critique method, not a reference to Grand_parent.critique().

Interesting. "It has its own" critique method? Hm. Not quite sure what 
that means exactly...

Anyhow, I wasn't suggesting that Parent had a reference to 
Grand_parent.critique(), only that Python would search *up* the tree 
looking for the method it's looking to call.

Thanks!

> So
> when Child calls self.advise, it is calling its inherrited copy. Then,
> since the inherited Child.advise() from Parent.advise() calls
> self.critique, it calls it's own overriden critique method.
> 
> I hope this makes sense.
> 


-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OOP: method overriding works in mysterious ways?

2006-01-02 Thread John M. Gabriele
André wrote:
> John M. Gabriele wrote:
> 
> Since Child has no advice() method, it inherits the one for Parent.
> Thus, Child can be thought of as being defined as follows:
> 
> . class Child( Parent ):
> .
> .  def speak( self ):
> .  print '\t\tChild.speak()'
> .  self.advise()
> .
> .  def advise( self ):   # inherited from Parent
> .  print '\tParent.advise()'
> .  self.critique()
> .
> .  def critique( self ):
> .  print '\t\tChild.critique()'
> .

That's a very interesting way to look at it... But I thought
that the Python interpreter takes care of walking up the
inheritance tree looking for the instance methods, rather
than what you've written above...

> Note that "self" refer to the *instance* created, not the *class*.

Thanks. Right -- the self object always refers to the object that
you originally used to call the instance method (here, speak()).

> 
> Now, does the output make sense?
> 
> André
> 

Bearing in mind what self is referring to, then yes,
the output does make sense. Thanks. :)

---J

-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


instance attributes not inherited?

2006-01-15 Thread John M. Gabriele
The following short program fails:


--- code 
#!/usr/bin/python

class Parent( object ):
 def __init__( self ):
 self.x = 9
 print "Inside Parent.__init__()"


class Child( Parent ):
 def __init__( self ):
 print "Inside Child.__init__()"


p1 = Parent()
p2 = Parent()
c1 = Child()
foo = [p1,p2,c1]

for i in foo:
 print "x =", i.x
- /code --



yielding the following output:

 output --
Inside Parent.__init__()
Inside Parent.__init__()
Inside Child.__init__()
x = 9
x = 9
x =
Traceback (most recent call last):
   File "./foo.py", line 21, in ?
 print "x =", i.x
AttributeError: 'Child' object has no attribute 'x'
 /output -


Why isn't the instance attribute x getting inherited?

My experience with OOP has been with C++ and (more
recently) Java. If I create an instance of a Child object,
I expect it to *be* a Parent object (just as, if I subclass
a Car class to create a VW class, I expect all VW's to *be*
Cars).

That is to say, if there's something a Parent can do, shouldn't
the Child be able to do it too? Consider a similar program:

--- code 
#!/usr/bin/python


class Parent( object ):
 def __init__( self ):
 self.x = 9
 print "Inside Parent.__init__()"

 def wash_dishes( self ):
 print "Just washed", self.x, "dishes."


class Child( Parent ):
 def __init__( self ):
 print "Inside Child.__init__()"


p1 = Parent()
p2 = Parent()
c1 = Child()
foo = [p1,p2,c1]

for i in foo:
 i.wash_dishes()
--- /code ---

But that fails with:

--- output --
Inside Parent.__init__()
Inside Parent.__init__()
Inside Child.__init__()
Just washed 9 dishes.
Just washed 9 dishes.
Just washed
Traceback (most recent call last):
   File "./foo.py", line 24, in ?
 i.wash_dishes()
   File "./foo.py", line 10, in wash_dishes
 print "Just washed", self.x, "dishes."
AttributeError: 'Child' object has no attribute 'x'
--- /output -

Why isn't this inherited method call working right?
Is this a problem with Python's notion of how OO works?

Thanks,
---J

-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: instance attributes not inherited?

2006-01-15 Thread John M. Gabriele
David Hirschfield wrote:
> Nothing's wrong with python's oop inheritance, you just need to know 
> that the parent class' __init__ is not automatically called from a 
> subclass' __init__. Just change your code to do that step, and you'll be 
> fine:
> 
> class Parent( object ):
> def __init__( self ):
> self.x = 9
> 
> 
> class Child( Parent ):
> def __init__( self ):
> super(Child,self).__init__()
>print "Inside Child.__init__()"
> 
> -David
> 

How does it help that Parent.__init__ gets called? That call simply
would create a temporary Parent object, right? I don't see how it
should help (even though it *does* indeed work).

Why do we need to pass self along in that call to super()? Shouldn't
the class name be enough for super() to find the right superclass object?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: instance attributes not inherited?

2006-01-15 Thread John M. Gabriele
John M. Gabriele wrote:
> David Hirschfield wrote:
> 
>> Nothing's wrong with python's oop inheritance, you just need to know 
>> that the parent class' __init__ is not automatically called from a 
>> subclass' __init__. Just change your code to do that step, and you'll 
>> be fine:
>>
>> class Parent( object ):
>> def __init__( self ):
>> self.x = 9
>>
>>
>> class Child( Parent ):
>> def __init__( self ):
>> super(Child,self).__init__()
>>print "Inside Child.__init__()"
>>
>> -David
>>
> 
> How does it help that Parent.__init__ gets called? That call simply
> would create a temporary Parent object, right? I don't see how it
> should help (even though it *does* indeed work).

Sorry -- that question I wrote looks a little incomplete: what I meant
to ask was, how does it help this code to work:

 code 
#!/usr/bin/python

class Parent( object ):
 def __init__( self ):
 self.x = 9
 print "Inside Parent.__init__()"

 def wash_dishes( self ):
 print "Inside Parent.wash_dishes(), washing", self.x, "dishes."


class Child( Parent ):
 def __init__( self ):
 super( Child, self ).__init__()
 print "Inside Child.__init__()"


c = Child()
c.wash_dishes()
 /code 

since the x instance attribute created during the
super( Child, self ).__init__() call is just part of what looks to be
a temporary Parent instance.




-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: instance attributes not inherited?

2006-01-15 Thread John M. Gabriele
Dan Sommers wrote:
> [snip]
> 
>>How does it help that Parent.__init__ gets called? That call simply
>>would create a temporary Parent object, right? I don't see how it
>>should help (even though it *does* indeed work).
> 
> 
> The __init__ method is an *initializer*, *not* a constructor.  By the
> time __init__ runs, the object has already been constructed; __init__
> just does extra initialization.
> 
> Regards,
> Dan
> 

Right. Thanks for the clarification. :)

-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: instance attributes not inherited?

2006-01-15 Thread John M. Gabriele
Dennis Lee Bieber wrote:
> On Sun, 15 Jan 2006 20:50:59 -0500, "John M. Gabriele"
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
> 
> 
>>Sorry -- that question I wrote looks a little incomplete: what I meant
>>to ask was, how does it help this code to work:
>>
>> code 
>>#!/usr/bin/python
>>
>>class Parent( object ):
>> def __init__( self ):
>> self.x = 9
>> print "Inside Parent.__init__()"
>>
>> def wash_dishes( self ):
>> print "Inside Parent.wash_dishes(), washing", self.x, "dishes."
>>
>>
>>class Child( Parent ):
>> def __init__( self ):
>> super( Child, self ).__init__()
>> print "Inside Child.__init__()"
>>
>>
>>c = Child()
>>c.wash_dishes()
>> /code 
>>
>>since the x instance attribute created during the
>>super( Child, self ).__init__() call is just part of what looks to be
>>a temporary Parent instance.

(Whoops. I see now thanks to Dan Sommers' comment that there's
no temp Parent instance, unless the call to super() is creating
one...)

> 
>   Because you passed the CHILD INSTANCE (self) to the method of the
> super... so "self.x" is "child-instance.x"

Huh? But it sounds by the name of it that super() is supposed to
return something like the superclass (i.e. Parent). You mean, that
super( Child, self ).__init__() call inside Child.__init__() leads
to Parent.__init__() getting called but with the 'self' reference
inside there referring to the Child object we named 'c' instead of
some Parent  {confused}

Wait a second. I can replace that super() call with simply

 Parent.__init__( self )

and everything still works... and it looks to me that, indeed,
I'm passing self in (which refers to the Child object), and that
self gets used in that __init__() method of Parent's... Wow. I'd
never seen/understood that before! We're using superclass initializers
on subclasses that weren't around when the superclass was written!

I'm having a hard time finding the documentation to the super() function.
I checked the language reference ( http://docs.python.org/ref/ref.html )
but didn't find it. Can someone please point me to the relevant docs on
super?

help( super ) doesn't give much info at all, except that super is actually
a class, and calling it the way we are here returns a "bound super object",
but I don't yet see what that means (though I know what bound methods are).

Thanks,
---J

-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: web crawling.

2006-01-19 Thread John M. Gabriele
Alex Martelli wrote:
> S Borg <[EMAIL PROTECTED]> wrote:
> 
> 
>> Hello,
>>
>> I have been writing very simple Python programs that parse HTML and
>>such, mainly just to get
>>a better feel for the language. Here is my question: If I parsed an
>>HTML page into all of the image
>>files listed on that page, how could I request all of those images and
>>download them into some specified folder? I am sure this is quite easy,
>>but I am stuck.
> 
> 
> There's a good crawler in the Demo directory of the Python source
> distribution, so download and unpack said sources and look there.
> 
> 
> Alex

Hm. Looks like that's:

 Python-2.4.2/Tools/webchecker

See 'pydoc ./webchecker.py' for more info.

---J


-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to generate graphics dynamically on the web using Python CGI script?

2006-01-21 Thread John M. Gabriele
Luiz Geron wrote:
> I don't have experience on this, but I think that you can make the
> script return the image "contents" directly to the img tag, without
> passing it to a img file, so you can use something like this:
> 
> 
> 
> wich saves some processing and I/O.
> 

I like this method.

You have 2 cgi scripts: one that creates your html with that img
tag in it, and a 2nd one to generate the image file on the fly when
the browser asks for it.

For generating the plot, I tried pychart http://home.gna.org/pychart/
and it was pretty nice.

If using pychart, your script that emits image contents might look
like this:

 code 
#!/usr/bin/python

# Not using cgi module at this point, since this script
# isn't very smart yet. :)

import sys
sys.argv.append( '--format=png' )

print "Content-type: image/png"
print

from pychart import *
theme.get_options()
theme.scale_factor = 3
theme.reinitialize()

import random
data = []
for i in range(10):
 data.append( (i, random.random()* 3.0) )

xaxis = axis.X( format="/hL%d",  label="time" )
yaxis = axis.Y(  label="synaptic activity" )

ar = area.T( x_axis=xaxis, y_axis=yaxis, y_range=(0,None), size=(120,110) )
plot = line_plot.T( label="cortex data", data=data, ycol=1, 
tick_mark=tick_mark.star )
ar.add_plot( plot )
ar.draw()
- /code 

Try the script out -- it'll work as-is once you've installed pychart.

You can add logic to it to generate your plot depending on what
you pass in, encoded in the URL request. Just import the cgi
module for getting those parameters.

---J

-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


restricted environment

2006-07-19 Thread Gabriele *darkbard* Farina
Hi,

I saw the rexec module is deprecated. I need to develop a python
application able to run custom python code based on a configuration
file that tells the path of the script that have to be executed. Those
scripts can be runned simultaneously trought threading module, but the
MUST not have any way to change the base application nor the other
scripts behaviour.

There is a way to reach this point without using rexec? There is a way
to start a python interpreter from python to run the scripts?

My final goal is to develop a simple fastcgi script that, based on
configuration files, is able to host different applications without
need to copy the script for any application and with any risk that the
scripts will ifluence in any way each other.

Any help?

Gabriele

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


Re: restricted environment

2006-07-19 Thread Gabriele *darkbard* Farina
Using a separate interpreter could be a solution, but restarting any
time the interpreter give me too much overhead and the application will
work as slow as a CGI app even if it runs using FastCGI.

Can't I put the interpreter to the starting state any time it finishes
a script execution without restarting it ?

The first attempt to reach my goal was to override the __import__
function to limit it working on modules that can be used and on custom
import directories that can be accessed. Then I executed the scripts
using exec. There is any security problem related to this solution ?

The other problem is about limiting accessible resources ...

Gabriele

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


Re: restricted environment

2006-07-20 Thread Gabriele *darkbard* Farina

Paul Rubin wrote:
> "Gabriele *darkbard* Farina" <[EMAIL PROTECTED]> writes:
> > Using a separate interpreter could be a solution, but restarting any
> > time the interpreter give me too much overhead and the application will
> > work as slow as a CGI app even if it runs using FastCGI.
>
> How many users are you talking about?  Can you have a separate FastCGI
> server for each one, running continuously?

I could be the last solution, but I'd like to understand if a can use
only one FastCGI server to handle all the scripts that need to run.
This is just to speed up a bit the system, making it possible to share
resources among applications.

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


Re: restricted environment

2006-07-20 Thread Gabriele *darkbard* Farina

faulkner wrote:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496746
> When you think of modifying the interpreter, think of the compiler
> module.

This seems a good solutions. Does it works correctly and safely ?

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


Question about the "new" module

2006-12-29 Thread Gabriele *darkbard* Farina
Hi,

I'm using Python 2.5 to develop a simple MVC framework based on
mod_python. To load my controllers, I create new modules using the
"new" module like this:

# 
my_module = new.module("random_name")
my_module.__file__ = module_path

exec open(module_path, "r") in my_module.__dict__

then I initialize the class defined inside the module and call a method
of this class based on the HTTP request.

All works fine but the imports. If my module contains something like
this:

import something

class MyController(Controller):
def index(self):
something.do_something()

when MyController.index is called an exception is raised "NoneType
object has not attribute do_something". Why does it happen ? I have to
load the module in different ways (but I'd like to force the reload
every time the module is loaded) ?

Gabriele

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


Re: VB to Python migration

2006-01-28 Thread John M. Gabriele
Josh wrote:
> We have a program written in VB6 (over 100,000 lines of code and 230 UI 
> screens) that we want to get out of VB and into a better language.  The
> program is over 10 years old and has already been ported from VB3 to 
> VB6, a job which took over two years. We would like to port it to 
> Python, but we need to continue to offer upgrades and fixes to the 
> current VB6 version. Does anybody know of ways we could go about 
> rewriting this, one screen at a time, in Python, and calling the screens 
> from the existing program?

Dunno what you mean by "calling the screens" from the existing
program. (?)

Is your VB6 progam object-based? If so, it sounds like you might
have your work cut out for you in duplicating the classes in Python
(I've never used VB6 and don't even know if it's an OO language.).

I'd look into how you can start with unit tests + your classes
right from the start. And, it goes without saying to use version
control from the start (svn or, if you're adventurous, maybe bzr
(i.e. Bazaar-NG)).

> We are also looking for a graphics toolkit to use.

You might take a peek at Python + PyGTK + Glade:
http://pygtk.org/ . Dunno the state of GTK on Windows,
but I've heard it's workable. No idea about Glade on
Windows.

Here's an article from 2001:
http://www.linuxjournal.com/article/4702
but if you look around there should be some newer tutorials
around.

> [snip]
> 
> Any answers/suggestions/pointers are greatly appreciated.

As Steven suggested, I'd examine whether or not your app
might work as a web app. That completely frees you from Windows
altogether. Just make sure it runs alright with Firefox/Opera/
Safari. :)

---J

> Thanks,
> 
> Josh Isted


-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Server side newbie

2006-01-29 Thread John M. Gabriele
swisscheese wrote:
> I have a simple python desktop app with several edit controls and a
> couple of buttons. It just does some math. What's the simplest way to
> make it a server-side app so visitors to my site can run the app via
> their browser?
> 

The *simplest* way is to make it into a CGI script.

What you'll probably want is to make the CGI script
produce some html with a form in it. The form action
is the CGI script itself. This way, after you hit the
submit button, you get the same page back again (with
your math answer written in the page somewhere), with
the same fields and submit button waiting for you to
use the script again.

Use the cgi module to access the data that gets
submitted by the form.

To run your script, you'll need to install a web server.
On Debian it's:

 apt-get install apache2

Then you put your CGI script into /usr/lib/cgi-bin/foo.py
and point your browser to

 http://localhost/cgi-bin/foo.py

---J


-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fairly large webapp: from Java to Python. experiences?

2006-02-03 Thread John M. Gabriele
[EMAIL PROTECTED] wrote:
> To replace a large framework you will probably need a framework.

Well, I'm sure not all web frameworks are created equal, however,
CherryPy does bill itself as a "web framework".

> Take a
> look at http://www.djangoproject.com or http://www.turbogears.org. They
> both use some of the tools you mention but operate on a higher level.

Django looks interesting to me. Would like to try out mod_python.
Taking a look...

> I find Python fairly easy to maintain. Unfortunatly, I do not find it
> easy to take a bunch of Java code and move it to Python.

Well, I figured it might be better to use the previous webapp
as a *model* to learn from, rather than to directly translate
code from Java to Python.

> But once it is
> there, Python is a good choice for web apps. Java is slow

Slow? They're both dynamic languages, but Java is statically
typed (with less work to do at runtime). For long-running processes,
I'd guess that Java bytecode executes faster than Python bytecode.

> and has a big
> footprint.

Yes.

> Python is reasonably nimble and good design choices pay off.
> Plus, you must write many more lines of Java to do what you can in
> Python.

Yup. The main issue with the current Java webapp seems to be
that it takes a long time to make changes/additions.

> I do not know the code you are not working with, but a lot of
> large Java apps can be poorly written.

I've found that good documentation is *most* critical. At least
if the docs are good, but the code needs work, you have some
direction as to how to fix the code. If there's no docs, you
spend hours wondering why things are done the way they're done.

Currently having a look at the Django docs. :)

Thanks Brian!
---J
-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cannot install scipy

2006-02-03 Thread John M. Gabriele
nitro wrote:
> Hi,
> 
> I am using a Debian system. I installed NumPy and everything works
> well. When I try to install SciPy, I get the following error. Any help
> would be appreciated.
> 
> ===
> [EMAIL PROTECTED]:~/scipy/scipy-0.4.4$ python setup.py install
> import core -> failed:
> /usr/lib/python2.3/site-packages/numpy/core/multiarray.so: undefined
> symbol: PyOS_ascii_strtod
> import random -> failed: 'module' object has no attribute 'dtype'
> import lib -> failed:
> /usr/lib/python2.3/site-packages/numpy/core/multiarray.so: undefined
> symbol: PyOS_ascii_strtod
> Fatal Python error: can't initialize module lapack_lite
> Aborted
> [EMAIL PROTECTED]:~/scipy/scipy-0.4.4$
> ===
> 
> nitro
> 

Why not just "apt-get install python-scipy"?

That's one of the best parts of running Debian. :)

---J

-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python's library support

2006-02-03 Thread John M. Gabriele
Sean wrote:
> I am a newbie in python, and I have a feeling that python provides less
> library support than perl www.cpan.org  This seems a big discussion
> topic.
> 
> I want to know if there is extensive algorithm library support in
> python. I know there is a pretty neat module in perl to implement graph
> theory. Is there a graph theory module in python?
> 
> Thanks,
> 

You might have a look around at the cheese shop:

http://cheeseshop.python.org/pypi

---J

-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fairly large webapp: from Java to Python. experiences?

2006-02-04 Thread John M. Gabriele
Shalabh Chaturvedi wrote:
> [EMAIL PROTECTED] wrote:
> 
> A class-to-class and method-to-method rewrite will give some but likely 
> not the full benefit of moving to Python. A redesign might be necessary 
> - making it more 'Pythonic' in the process. In my experience, many cruft 
> classes that exist in a Java design simply disappear when ported to 
> Python. See also http://dirtsimple.org/2004/12/python-is-not-java.html
> 
> Cheers,
> Shalabh
> 

Great link Shalabh. Thanks. :) Googling around, I'd also come across
that one.

---J

-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: editor for Python on Linux

2006-02-22 Thread John M. Gabriele
Mladen Adamovic wrote:
> Hi!
> 
> I wonder which editor or IDE you can recommend me for writing Python 
> programs. I tried with jEdit but it isn't perfect.
> 

NEdit

-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new wooden door step - fixing and finishing

2006-02-22 Thread John M. Gabriele
Jeffrey Schwab wrote:
> jkn wrote:
> 
> 
>> I was wondering about treating it
>> wilth liberal amounts of Teak Oil or similar...
> 
> 
> Some people, when confronted with a problem, think "I know, I’ll use 
> Teak Oil."  Now they have two problems.


Quit it! You're making me laugh too much and it's gonna
wake up the kids! :D

-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyFltk-1.1

2006-02-22 Thread John M. Gabriele
{fixed top-posting}

george williams wrote:

 > > This is to announce the first official release of pyFltk-1.1,
 > > the Python bindings for the cross platform GUI toolkit fltk-1.1
 >
> By god this sounds interesting I wish I 
> knew what you are talking about

fltk (pronounced "full-tick" as in "Cap'n, we're doing warp 9
and the engines are going full tick!" but not as in, "boy,
I just checked the dog found one very full tick") is a C++
GUI toolkit. You would use fltk for writing a GUI desktop
application. It's like GTK+ or Qt, but much smaller and lighter.

pyFltk is a Python binding to fltk. That is, so you can use
fltk from Python instead of from C++.

---J

-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: automatic html generation for documentation?

2006-02-26 Thread John M. Gabriele
Lonnie Princehouse wrote:
> I plan on writing some documentation that will consist of blocks of
> commentary with interspersed snippets of syntax-colored Python code and
> the occaisional image.
> 
> Does anyone know of a package that will take a high level description
> of what I just described and auto-generate clean-looking web pages,
> including syntax coloring?   I'm already using epydoc for API reference
> generation; what I'm looking for here is just something to help out
> with the narrative so I don't have to spend lots of time fiddling with
> HTML.
> 

The Python wiki http://wiki.python.org/moin/FrontPage uses moinmoin
and their pages contain syntax highlighted (highlit? ;) ) Python code.

Of course, there's always source-highlight
http://www.gnu.org/software/src-highlite/source-highlight.html
which you may be able to work into your current solution with
a little glue.

In fact, come to think of it, if your editor is up to snuff, you
could simply paste the code into your html doc, select that code
in the editor, then filter it through source-highlight in-place.
I use NEdit and I think that could do it easily.

---J
-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for a simpe plotting module

2006-02-26 Thread John M. Gabriele
Henrique Ferreiro wrote:
> 
> O Sáb, 25-02-2006 ás 15:01 -0800, MARK LEEDS escribiu:
> 
>>i'm pretty much a python beginner so can anyone recommend a plooting
>>package in python ( simple foating  numbers 
>>that makes lines or dots with a yaxis and an an xaxis. i don't need
>>fancy drawings ) that is a built in module 
>>in python ?  i am using python 2.4 in linux if that matters. thanks.
>>
>>
>>
>>-- 
>>http://mail.python.org/mailman/listinfo/python-list
> 
> matplotlib is an excellent library which uses the syntax of matlab
> plots.
> 
> http://matplotlib.sourceforge.net


You might also have a look at PyChart:
http://wiki.python.org/moin/PyChart


-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python Indentation Problems

2006-02-28 Thread John M. Gabriele
Renato wrote:
> If you use vi (vim, I hope), then place something like this in your
> .vimrc
> 
> set ts=4
> set sw=4
> set expandtab
> set ai

Or, more verbose:

set tabstop=4
set shiftwidth=4

set autoindent

> There are a lot more tricks for python in vim (and plugins, and
> helpers, and so on), but this is the starting point: tabstops of 4
> places, autoconverted in spaces. Also, when shifting text with < or >
> it moves 4 spaces.
> 

Also possibly useful:

set shiftround

---John


-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C++ OpenGL rendering, wxPython GUI?

2006-02-28 Thread John M. Gabriele
[EMAIL PROTECTED] wrote:
> [snip]  Now I'm
> looking to build a GUI in python with the rendering engine as an
> integrated window. I will most likely use wxPython for the GUI and I
> know it has support for adding an OpenGL canvas.
> 
> 

You might look into PyFLTK (which I think was just recently
mentioned on the announce list):

http://pyfltk.sourceforge.net/

I haven't used it. Just something to maybe look into. I think
fltk does indeed have support for OpenGL. And I hear it's a
fast and light toolkit. ;)

---John


-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suggestions for documentation generation?

2006-03-01 Thread John M. Gabriele
kpd wrote:
> Hello,
> 
> I have written a C++ library that I've then wrapped with Pyrex.
> Any suggestions to the best-in-class tool to create documentation for
> the libraries?
> 
> I would love to document things in one spot (could be the code) and
> generate html and PDF from there.
> 
> Doxygen (www.doxygen.org) looks to be about the best so far. 
> 
> Thanks,
> 

I've heard that some folks use pythondoc:
http://starship.python.net/crew/danilo/pythondoc/
http://effbot.org/zone/pythondoc.htm

There's also HappyDoc http://happydoc.sourceforge.net/
and EpyDoc http://epydoc.sourceforge.net/ .

-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suggestions for documentation generation?

2006-03-02 Thread John M. Gabriele
Michael Ekstrand wrote:
> 
> 
> Doxygen has recently added support for Python, [snip]

Didn't know that. Thanks for the heads-up. :)

-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Write a GUI for a python script?

2006-03-02 Thread John M. Gabriele
Glurt Wuntal wrote:
> I am a newbie with Python. It's a great language, but I would like to be
> able to present a simple gui menu for some of my scripts; something better
> than using 'raw_input' prompts.
> 
> Any recommendations for a program that will allow me to create the gui
> screens? Something useable in Linux.
> 
> thanks.
> 

There are Python bindings to most GUI toolkits (GTK+, Qt, fltk, wxWindows,
and Tk come to mind). You could use any of them. They're all usable in
GNU/Linux.

-- Tk is a mature, small, and simple toolkit. The Python binding
to Tk is called Tkinter.

-- GTK+ is what most Gnome apps use. The Python binding is PyGTK.
http://www.pygtk.org/

-- Qt is what most KDE apps use. The Python binding is called PyQt.

-- wxWindows is a lot like MS Windows MFC if I recall correctly.
The Python binding to wxWindows is called wxPython.
http://www.wxpython.org/

-- For a terminal-based text-mode character-cell display program, you
could use ncurses. http://www.amk.ca/python/howto/curses/
http://gnosis.cx/publish/programming/charming_python_6.html


---John
-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Write a GUI for a python script?

2006-03-02 Thread John M. Gabriele
John M. Gabriele wrote:
> 
> There are Python bindings to most GUI toolkits (GTK+, Qt, fltk, wxWindows,
> and Tk come to mind).

Whoops. Forgot fltk with the pyFLTK Python binding. fltk
is a fast, light, toolkit that's written in C++ but (again,
IIRC) feels more like C-with-classes (which isn't a bad thing).

---John
-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list


zipimport

2005-05-04 Thread Gabriele *Darkbard* Farina
Hi,

I have a zip file structured like this:

mymodule.zip\
   module1.py
   submodule\
submodule1.py

I tried to load submodule.submodule1 using this pice of code:

import zipimport

z = zipimport.zipimporter("mymodule.zip")
z.load_module("submodule.submodule1")

but it does not work (load_module raises an exception)

why?

tnx, bye
-- 
http://mail.python.org/mailman/listinfo/python-list


compiling python code

2005-05-26 Thread Gabriele *Darkbard* Farina
Hi,

I have a python file inside a zip file. I'd like to compile it and add 
the resulting .pyc file into the zip. I tryed reading the source and 
compiling it using compile(), but I don't know how to write .pyc file. 
Can someone give me some help?

bye,
gabriele
-- 
http://mail.python.org/mailman/listinfo/python-list


Python C API question

2006-04-24 Thread Gabriele *darkbard* Farina
Hi,

I'm a newbie in python extension development, and I'd like to ask you a
simple question. I have to implement a simple estension that parses a
source file and returns an xml.dom.minidom.Document instance. I'd like
to know how can I import and then manage xml.dom.minidom.* objects
using Python C API.

thanks,
Gabriele

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


Re: Python C API question

2006-04-24 Thread Gabriele *darkbard* Farina
It seems to be what I need. Thank you!

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


Unicode digit to unicode string

2006-05-16 Thread Gabriele *darkbard* Farina
Hi, I have a unicode digit stored into a variable ('0020' for example)
and I'd like to retrieve the corrisponding unicode character based on
the current encoding. How can i do that ?

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


Re: Unicode digit to unicode string

2006-05-16 Thread Gabriele *darkbard* Farina
thank you, bye

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


Re: Basic python help

2006-03-13 Thread John M. Gabriele
(Please don't top-post -- fixed)

Kevin Feng wrote:

> 
> 
> On 3/14/06 2:12 AM, in article [EMAIL PROTECTED],
> "Gregor Horvath" <[EMAIL PROTECTED]> wrote:
> 
> 
>>Kevin Feng schrieb:
>>
>>
>>>More information about this error may be available in the server error log.
>>>
>>>
>>>
>>>Any suggestions?  Much thanks.
>>>
>>
>>What does the error log of the webserver say?
>>
>>--
>>Greg
> 

 > No idea, I do not have permission to access the error log.
 >
 >

In your cgi script, try putting "import cgitb; cgitb.enable()"
on the next line right after "import cgi".

Also try changing your POST to GET.

---John
-- 
(remove zeez if demunging email address)
-- 
http://mail.python.org/mailman/listinfo/python-list