Re: genetic algorithms package for python ?

2006-09-01 Thread placid

Thomas Samson wrote:
> Xiao Jianfeng <[EMAIL PROTECTED]> writes:
>
> > Hi all,
> >
> > I am looking for a genetic algorithms package for Python.
> >
> > I have googled the web before posting and found some links. The link
> > of  pygene(http://www.freenet.org.nz/python/pygene) cannot be opened.
>
> Strange, works for me...
>
> >
> > I also tried the recipe on ASPN, but it is too simple for my
> > application, and the ga model in SciPy, which is in testing in the
> > "sandbox".
> >
> > Are there any more genetic algorithms packages for Python ?
> >
>
> I am not (at all!) an specialist in genetic algorithms, but here are
> some links :
>
> http://pygp.sourceforge.net/
> http://packages.qa.debian.org/g/genetic.html
> and of course,
> http://www.freenet.org.nz/python/pygene/


GP: Genetic Programming
(http://en.wikipedia.org/wiki/Genetic_Programming)

this is different to Genetic Algorithms
(http://en.wikipedia.org/wiki/Genetic_algorithms)

Cheers

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


pysqlite - simple problem

2006-09-01 Thread rdrink
I am just getting into pysqlite (with a fair amount of Python and MySQL
experience behind me) and have coded a simple test case to try to get
the hang of things...
yet have run into a 'stock simple' problem...

I can create a database 'test.db', add a table 'foo' (which BTW I
repeatedly DROP on each run) with one INTGER column 'id', and can
insert data into with:
cur.execute("INSERT INTO foo (id) VALUES (200)")
con.commit()
(and fetch back out)
all with no problem. But...

If I try to expand this to:
num = 200
cur.execute("INSERT INTO foo (id) VALUES (?)", num)
I get the error...
Traceback (most recent call last):
  File "/home/rdrink/Programming/Python/Inner_Square/sqlite_test.py",
line 46, in ?
cur.execute("INSERT INTO foo (id) VALUES (?)", num)
  File "/usr/lib/python2.4/site-packages/sqlite/main.py", line 255, in
execute
self.rs = self.con.db.execute(SQL % parms)
TypeError: not all arguments converted during string formatting
... which obviously points to a 'typing' problem.
?? but where ??
>From all the docs I have read Python 'int' and sqlite INTEGER should
pass back and forth seemlessly...
And I have even tried to reduce things to simply:
cur.execute("INSERT INTO foo (id) VALUES (?)", 200)
but still raise the same error.

So this has to be something stupidly simple... but for the life of me I
can't see it.

Advice, suggestions, pointers for the noob?

rd

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


ANN: GMPY binaries for Windows 2.5

2006-09-01 Thread casevh
GMPY binaries for Python 2.5 are available at
http://home.comcast.net/~casevh/

Notes

They have not been extensively tested.

This is based on the CVS version of gmpy and includes a patch (not yet
in CVS) from Alex Martelli that resolves a bug with divm(). Please
consider this an "unofficial" release. The patch and the source code
snapshot I used are also available on the website.

GMP 4.2.1 is used.

There are three versions available: one that should work on any
processor, one compiled for Pentium 4 processor, and one compiled for
AMD Athlon (32-bit).

If there is demand, I'll create updated binaries for earlier version of
Python.

Enjoy,

casevh

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


Re: Tkinter listbox question

2006-09-01 Thread Hendrik van Rooyen

 <[EMAIL PROTECTED]> Wrote:


| Hi,
| I need help about Tkinter listbox widget.I want,when somebody click on
| any item(file)  in Listbox,then in new Label widget text must be
| selected item from server.
| 
| my program (wrong example):
| 
| import ftputil
| import Tkinter
| root=Tkinter.Tk()
| ftp=ftputil.FTPHost('some imaginary server')
| 
| def LabelWidget(event):
| a=Tkinter.Label(root,text=)  # Text must be only name and file
| format,example: sun.gif
| a.grid()
| 
| 
| 
| b=Tkinter.Listbox(root)
| b.insert(Tkinter.END,ftp._dir(''))
| b.place()
| c=Tkinter.Button(root,text='PRINT THIS FILE IN NEW LABEL WIDGET')
| c.bind('',LabelWidget)
| c.grid()
| root.mainloop()
| 
| 
| THANKS!!!


idx = b.curselection()# - tells you which one was clicked
StringValue = b.get(idx) # - returns the text

HTH - Hendrik

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


Re: HTTPS Login

2006-09-01 Thread Gerold Penz
Tom Grove schrieb:
> I am trying to login to a secure website and I am having some difficulty 
> understanding the process.

Hi Tom!

This code should do what you want:
http://www.python-forum.de/post-18148.html#18148

Regards,
Gerold
:-)

-- 

Gerold Penz - bcom - Programmierung
 [EMAIL PROTECTED] | http://gerold.bcom.at | http://sw3.at
Ehrliche, herzliche Begeisterung ist einer der
 wirksamsten Erfolgsfaktoren. Dale Carnegie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pysqlite - simple problem

2006-09-01 Thread Gerold Penz
rdrink schrieb:
> num = 200
> cur.execute("INSERT INTO foo (id) VALUES (?)", num)

Hi!

``num`` must be an iterable object (tuple, list, ...).

   num = (200,)
   cur.execute("INSERT INTO foo (id) VALUES (?)", num)

Regards,
Gerold
:-)

-- 

Gerold Penz - bcom - Programmierung
 [EMAIL PROTECTED] | http://gerold.bcom.at | http://sw3.at
Ehrliche, herzliche Begeisterung ist einer der
 wirksamsten Erfolgsfaktoren. Dale Carnegie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pysqlite - simple problem

2006-09-01 Thread Fredrik Lundh
"rdrink" <[EMAIL PROTECTED]> wrote:

>I am just getting into pysqlite (with a fair amount of Python and MySQL
> experience behind me) and have coded a simple test case to try to get
> the hang of things...
>
> yet have run into a 'stock simple' problem...

what does

import sqlite
print sqlite.paramstyle
print sqlite.version

print on your machine ?

(afaik, version 1 of the python bindings use paramstyle=pyformat, version
2 uses qmark.  maybe you have a version 1 library ?)

 



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


Re: pysqlite - simple problem

2006-09-01 Thread John Machin
rdrink wrote:
> I am just getting into pysqlite (with a fair amount of Python and MySQL
> experience behind me) and have coded a simple test case to try to get
> the hang of things...
> yet have run into a 'stock simple' problem...
>
> I can create a database 'test.db', add a table 'foo' (which BTW I
> repeatedly DROP on each run) with one INTGER column 'id', and can
> insert data into with:
> cur.execute("INSERT INTO foo (id) VALUES (200)")
> con.commit()
> (and fetch back out)
> all with no problem. But...
>
> If I try to expand this to:
> num = 200
> cur.execute("INSERT INTO foo (id) VALUES (?)", num)
> I get the error...
> Traceback (most recent call last):
>   File "/home/rdrink/Programming/Python/Inner_Square/sqlite_test.py",
> line 46, in ?
> cur.execute("INSERT INTO foo (id) VALUES (?)", num)
>   File "/usr/lib/python2.4/site-packages/sqlite/main.py", line 255, in
> execute
> self.rs = self.con.db.execute(SQL % parms)
> TypeError: not all arguments converted during string formatting
> ... which obviously points to a 'typing' problem.
> ?? but where ??
> >From all the docs I have read Python 'int' and sqlite INTEGER should
> pass back and forth seemlessly...
> And I have even tried to reduce things to simply:
> cur.execute("INSERT INTO foo (id) VALUES (?)", 200)
> but still raise the same error.
>
> So this has to be something stupidly simple... but for the life of me I
> can't see it.

With the '?' paramstyle, the 2nd arg to cursor.execute() should be a
*sequence* (typically a tuple) of the values that you are inserting.

Tty this:
cur.execute("INSERT INTO foo (id) VALUES (?)", (num, ))

This is standard Python DBAPI stuff - you would probably get a similar
response from other gadgets e.g. mySQLdb -- IOW it's not specific to
pysqlite.

> Advice, suggestions, pointers for the noob?

General advice: Read the docs -- both the gadget-specific docs and the
Python DBAPI spec (found at http://www.python.org/dev/peps/pep-0249/).

HTH,
John

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


Re: AttributeError: 'Attributes' object has no attribute 'saveFile'

2006-09-01 Thread crystalattice

[EMAIL PROTECTED] wrote:
> Hi
>
> Sounds like you've got a wizard-type interface thing happening.
> I haven't used wxGlade but I have done similar things in GTK several
> times.
>
> Try putting all the windows in a notebook widget with hidden tabs.
> Put the 'Next Page' button and the filename outside the notebook.  This
> makes the filename always available and the 'Next Page' button would
> just switch pages in the notebook widget.
>
> Hope this is helpful
>
> Cheers
> Tim
Sounds simple enough.  Of course, we all know the difference between
theory and practice.  I think I rember seeing a wizard-type interface
in the wxGlade tutorial.  I'll take a look at that to.  Thanks for the
tip.

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


Re: Subclassing Tkinter Buttons

2006-09-01 Thread Rob Wolfe

Bob Greschke wrote:
> I don't use classes much (mainly because I'm stupid), but I'd like to make a
> subclass of the regular Tkinter Button widget that simply adds spaces to the
> passed "text=" when the program is running on Windows (Linux, Solaris, Mac
> add a little space between the button text and the right and left edges of a
> button, Windows does not and it looks bad/can be hard to read).  Below is
> some pseudo code.  What should the guts of the BButton class be?  I can't
> work out how all of the arguments that would be passed to a regular Button
> call get handled.  *args and **kw confuse me and I can't seem to find simple
> enough examples in my mountain of books.

So watch this:


import Tkinter as Tk
import sys

class MyButton(Tk.Button):
system = sys.platform[:3]# 1

def __init__(self, master=None, **kw):   # 2 3
if self.system == "win":
kw["padx"] = kw.get("padx", 0) + 5   # 4
# alternative solution
# if "text" in kw and self.system == "win":
# kw["text"] = " " + kw["text"] + " "

Tk.Button.__init__(self, master, **kw)   # 5


1. system is a class attribute, so is shared by the class and all
instances of the class
2. __init__ is called immediately after an instance of the class
is created
3. kw is a dictionary of button options for example:
{"text": "Hello", "padx": 2}
4. change value of element "padx" or add this element to dictionary kw
5. call parent __init__ method to create button

HTH,
Rob

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


Re: Timeline for Python?

2006-09-01 Thread crystalattice
I'd write for 2.4, even though 2.5 should be coming out "shortly".
There aren't many significant changes to the whole language between 2.4
and 2.5.  Probably the best thing is write for 2.4 and have a sidenote
stating where 2.5 operates differently.

The Python 3 timeline is almost a moving target right now; personally,
I don't think it will be out before next winter.  Maybe a beta but I
doubt the full version.

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


Parsing form input in a BaseHTTPServer

2006-09-01 Thread Ron Garret
I'm write a web server using BaseHTTPServer.  It can't be a CGI because 
it has to do some weird server-push stuff as database updates come in.  
But I still need to process form inputs as if it were a CGI.  But the 
cgi module only works in a CGI environment.  Is there something with the 
equivalent functionality of cgi.FieldStorage for parsing form input in a 
non-CGI environment such as a BaseHTTPServer?  I looked at the cgi 
module code but it looked like it was pretty heavily intertwingled with 
the CGI environment variables.

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


Re: Python style: to check or not to check args and data members

2006-09-01 Thread Joel Hedlund
 > Short answer: Use Traits. Don't invent your own mini-Traits.

Thanks for a quick and informative answer! I'll be sure to read up on the 
subject. (And also: thanks Bruno for your contributions!)

 > Types are very frequently exactly the wrong thing you want to check for.

I see what you mean. Allowing several data types may generate unwanted side 
effects (integer division when expecting real division, for example).

I understand that Traits can do value checking which is superior to what I 
presented, and that they can help me move validation away from functional 
code, which is always desirable. But there is still the problem of setting 
an approprate level of validation.

Should I validate data members only? This is quite easily done using Traits 
or some other technique and keeps validation bloat localized in the code. 
This is in line with the DRY principle and makes for smooth extensibility, 
but the tracebacks will be less useful.

Or should I go the whole way and validate at every turn (all data members, 
every arg in every method, ...)? This makes for very secure code and very 
useful tracebacks, but does not feel very DRY to me... Are the benefits 
worth the costs? Do I build myself a fortress of unmaintainability this way? 
Will people laugh at my modules?

Or taken to the other extreme: Should I simply duck-type everything, and 
only focus my validation efforts to external data (from users, external 
applications and other forces of evil). This solution makes for extremely 
clean code, but the thought of potential silent data corruption makes me 
more than a little queasy.

What level do you go for?

Thanks!
/Joel

Robert Kern wrote:
> Joel Hedlund wrote:
>> Hi!
>>
>> The question of type checking/enforcing has bothered me for a while, and 
>> since this newsgroup has a wealth of competence subscribed to it, I 
>> figured this would be a great way of learning from the experts. I feel 
>> there's a tradeoff between clear, easily readdable and extensible code 
>> on one side, and safe code providing early errors and useful tracebacks 
>> on the other. I want both! How do you guys do it? What's the pythonic 
>> way? Are there any docs that I should read? All pointers and opinions 
>> are appreciated!
> 
> Short answer: Use Traits. Don't invent your own mini-Traits.
> 
> (Disclosure: I work for Enthought.)
> 
>http://code.enthought.com/traits/
> 
> Unfortunately, I think the standalone tarball on that page, uh, doesn't stand 
> alone right now. We're cleaning up the interdependencies over the next two 
> weeks. Right now, your best bet is to get the whole enthought package:
> 
>http://code.enthought.com/ets/
> 
> Talk to us on enthought-dev if you need any help.
> 
>https://mail.enthought.com/mailman/listinfo/enthought-dev
> 
> 
> Now back to Traits itself:
> 
> Traits does quite a bit more than "type-checking," and I think that is its 
> least-useful feature that it provides for Python users. Types are very 
> frequently exactly the wrong thing you want to check for. They allow inputs 
> that 
> you would like to be invalid and disallow inputs that would have worked just 
> fine if you had relied on duck-typing. In general terms, Traits does 
> value-checking; it's just that some of the traits definitions check values by 
> validating their types.
> 
> You have to be careful with type-checking, because it can introduce fragility 
> without enhancing safety. But sometimes you are working with other code that 
> necessarily has type requirements (like extension code), and moving the 
> requirements forward a bit helps build usable interfaces.
> 
> Your examples would look like this with Traits:
> 
> 
> from enthought.traits.api import HasTraits, Int, method
> 
> class MyClass(HasTraits):
>  """My example class.
>  """
> 
>  int_member = Int(0, desc="I am an integer")
> 
>  method(None, Int)
>  def process_data(self, data):
>   """Do some data processing.
>   """
> 
>   self.int_member += 1
> 
> 
> a = MyClass(int_member=9)
> a = MyClass(int_member='moo')
> """
> Traceback (most recent call last):
>File "", line 1, in ?
>File "/Users/kern/svn/enthought-lib/enthought/traits/trait_handlers.py", 
> line 
> 172, in error
>  raise TraitError, ( object, name, self.info(), value )
> enthought.traits.trait_errors.TraitError: The 'int_member' trait of a MyClass 
> instance must be a value of type 'int', but a value of moo was specified.
> """
> 
> # and similar errors for
> # a.int_member = 'moo'
> # a.process_data('moo')
> 
> 
> The method() function predates 2.4 and has not yet been converted to a 
> decorator. We don't actually use it much.
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re.compile() doesn't work under Windows?

2006-09-01 Thread ddtl
Thanks everybody for pointing out the problem.
And indeed, the script was named differently on Linux.

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


Re: ANN: GMPY binaries for Windows 2.5

2006-09-01 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, casevh wrote:

Interesting subject line.  I think I still have a set of "Win 3.11 for
workgroups" disks lying around somewhere, but where do I get Windows 2.5? ;-)

SCNR,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pysqlite - simple problem

2006-09-01 Thread Fredrik Lundh
John Machin wrote:
>> So this has to be something stupidly simple... but for the life of me I
>> can't see it.
>
> With the '?' paramstyle, the 2nd arg to cursor.execute() should be a
> *sequence* (typically a tuple) of the values that you are inserting.
>
> Tty this:
> cur.execute("INSERT INTO foo (id) VALUES (?)", (num, ))
>
> This is standard Python DBAPI stuff - you would probably get a similar
> response from other gadgets e.g. mySQLdb -- IOW it's not specific to
> pysqlite.

that mistake gives an entirely different error message, at least under 2.2.0
(which is the version shipped with 2.5):

>>> import sqlite3
>>> db = sqlite3.connect("foo.db")
>>> cur = db.cursor()
>>> cur.execute("CREATE TABLE foo (id INTEGER)")

>>> cur.execute("INSERT INTO foo (id) VALUES (?)", 200)
Traceback (most recent call last):
  File "", line 1, in 
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current
statement uses 1, and there are -1 supplied.
>>> cur.execute("INSERT INTO foo (id) VALUES (?)", [200])


(not sure "-1 arguments supplied" is any less confusing, though)

 



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


Re: GC and security

2006-09-01 Thread Fredrik Lundh
Dennis Lee Bieber wrote:

> This is after they'd made an 11x14 enlargement of the "stolen"
> print, cleaned it up with a marker, reduced to life size, and etched
> onto printed circuit board to form a mold for making a latex "skin".
> Which, BTW, also fooled the lock.

http://www.diva-portal.org/liu/abstract.xsql?dbid=2397

Sandström, Marie: Liveness Detection in Fingerprint Recognition Systems

"Nine different systems were tested at the CeBIT trade fair in Germany and
all were deceived. Three other different systems were put up against more
extensive tests with three different subjects. All systems were circumvented
with all subjects' artificial fingerprints, but with varying results."

 



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

Re: Python style: to check or not to check args and data members

2006-09-01 Thread Joel Hedlund
Bruno >> Your email address seem to be wrong. I tried to reply to you 
directly in order to avoid thread bloat but my mail bounced.

Thanks for the quick reply though. I've skimmed through some docs on your 
suggestions and I'll be sure to read up on them properly later. But as I 
said to Robert Kern in this thread, this does not really seem resolve the
problem of setting an approprate level of validation.

How do you do it? Please reply to the group if you can find the time.

Cheers!
/Joel Hedlund

Bruno Desthuilliers wrote:
> Joel Hedlund a écrit :
>> Hi!
>>
>> The question of type checking/enforcing has bothered me for a while, 
> (snip)
>> I've also whipped up some examples in order to put the above questions 
>> in context and for your amusement. :-)
> (snip)
>> These are the attached modules:
>>
>> * nocheck_module.py:
>>   As the above example, but with docs. No type checking.
>>
>> * property_module.py
>>   Type checking of data members using properties.
>>
>> * methodcheck_module.py
>>   Type checking of args within methods.
>>
>> * decorator_module.py
>>   Type checking of args using method decorators.
>>
>> * maximum_security_module.py
>>   Decorator and property type checking.
> 
> You forgot two other possible solutions (that can be mixed):
> - using custom descriptors
> - using FormEncode
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


a new object definition

2006-09-01 Thread Sylvain Ferriol
hello everybody,

i want to talk with you about a question i have in mind and i do not
find a answer. it 's simple:
why do we not have a beatiful syntax for object definition as we have
for class definition ?

we can define a class in python in 2 ways:
  1. by using the metaclass constructor
my_class = MyMetaClass()
  2. by using the classic definition syntax:
class my_class(object):
   __metaclass__ = MyMetaClass

if i want to instanciate an object, i only have one way to define it:
  my_obj = my_class()

why not a better syntax like class syntax ?

example:
>> instance my_obj:
>>   __class__ = my_class


with this syntax, we are coherent between objects and classes.
why do we have a specific syntax for the class object definition and not
for objects of different type?

so if i want to define a new class object (my_class for example) with a
new object syntax:
>> instance my_class:
>>   __class__ = object
>>   __metaclass__ = MyMetaClass
>>   

thanks

Sylvain Ferriol
Ingénieur de recherche
Laboratoire TIMC/IMAG
http://www-timc.imag.fr/

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


Re: pysqlite - simple problem

2006-09-01 Thread John Machin

Fredrik Lundh wrote:
> John Machin wrote:
> >> So this has to be something stupidly simple... but for the life of me I
> >> can't see it.
> >
> > With the '?' paramstyle, the 2nd arg to cursor.execute() should be a
> > *sequence* (typically a tuple) of the values that you are inserting.
> >
> > Tty this:
> > cur.execute("INSERT INTO foo (id) VALUES (?)", (num, ))
> >
> > This is standard Python DBAPI stuff - you would probably get a similar
> > response from other gadgets e.g. mySQLdb -- IOW it's not specific to
> > pysqlite.
>
> that mistake gives an entirely different error message, at least under 2.2.0
> (which is the version shipped with 2.5):
>

You're right. I didn't spot that the OP may be using an antique:

File "/usr/lib/python2.4/site-packages/sqlite/main.py"

So the advice has to be augmented:
1. Update to latest pysqlite2 (which BTW is a later version that that
shipped with Python 2.5, just to add some confusion)
2. Pass values as a sequence

Cheers,
John

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


Classes referencing each other

2006-09-01 Thread Manuel Bleichner
Hello list,

I have searched for some time now, but no result...
I'm having the following problem:

In a module I have a huge number of classes of the form:

class A(object):
   connected_to = [B, C]
   

class B(object)
   connected_to = [C]
   

class C(object)
   connected_to = [A]
   

As you see, classes A and B reference classes that
are not yet defined when the class is being defined.
It will raise a NameError: 'B'.

I know i could solve this by leaving out the definition
of 'connected_to' in A and attach it to the class later on by
A.connected_to = [B, C]
but I would like to avoid this, because in the module
there are about 50 classes that have to be altered from time
to time and it's just incredibly ugly if I have to look for
the attribute definitions in more than one place.

Also, I would like to avoid eval(), because the references
have to be followed very often and that would cause more
CPU load and make the program code uglier :)

If anyone of you knows a neat way to solve this, I'd be
very grateful.

Greetings,
Manuel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SQLObject or SQLAlchemy?

2006-09-01 Thread Bruno Desthuilliers
Jorge Vargas wrote:
> On 8/31/06, John Salerno <[EMAIL PROTECTED]> wrote:
>> Are there any major differences between these two? It seems they can
>> both be used with TurboGears, and SQLAlchemy with Django. I'm just
>> wondering what everyone's preference is, and why, and if there are even
>> more choices for ORM.
>>
> they use two approach to the same problem.

I do not agree here. SLQObject tries to use a RDBMS for object
persistance, while SQLAlchemy's main goal is to provide a better
integration of RDBMS into Python - ORM features being just an optional
facility.

> SO tries to tide each object to a table while
> SA lets you do the mapping.
> 
> so each one has it's pros and cons.
> 
> for example SA wins at using an existing db
> but SO wins at not worring about the db structure

Not worrying about the db structure ? Heck, why using a RDBMS then - if
what you want is object persistance, ZODB works just fine.

SQLAlchemy clearly exposes the RDBMS schema (you can either define the
schema in Python or use reflection), and gives you access to the full
power of SQL DBMS without having to do the embed-SQL-as-strings dance.

(snip)

> In my experience SO is great for new projects
>  and if you don't want to
> mess/optimize with the actual SQL queries (which is great for an ORM
> because IMO that is the main goal of ORMing)

Disagreement here too. Even for relatively simple new projects,
SQLObject can be far too limited to take advantage of relational
paradigm. Try managing valued many-to-many associations with SQLObject -
which is a pretty simple and common requirement, and certainly not
"messing with the db".

SQLObject, while being a much better piece of software than what I could
come with by myself (been here, done that...), is IMVHO a wrong
solution. I mean, a RDBMS is not a persistence engine, it's a data
management tool. If you don't need a relational model, or if it doesn't
match your app's needs, then why use one when we have great OODBMS in
Python ?

My 2 cents...
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Strange string encoding behaviour with pymssql

2006-09-01 Thread Fabrizio Cornelli
Hello,  I'm using pymssql to extract data from a legacy table with a non-ascii encoded name. The strange thing is that I can make my query from the idle's console, but it doesn't work from python. (I'm working in a windows environment)
The error shows that there's a problem related to the encoding, I've tried to excplicit it in a -*- coding: latin-1 -*- fashion, but it seems it's not enough. Converting with unicode(query,encode) trying all the known encoding formats dowsn't work as well.
I tried something like: mssql.query("select id_attività from prodotti") and I have an error in the form:pymssql.DatabaseError: internal error: SQL Server message 207, severity 16, state 3, line 1:
Il nome di colonna 'id_attivitÓ' non è valido.As you can see 'id_attività' has been wrongly converted in 'id_attivitÓ' .Why, I wonder, idle's console and pythonwin can manage correctly the string and python.exe
 does not?Is it a problem related to pymssql and this is not the right place where to post it, or is there someone that could show me a solution?Thanks in advance for any hint.-- Fabrizio Zeno Cornelli
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: a new object definition

2006-09-01 Thread Michele Simionato
Sylvain Ferriol wrote:
> hello everybody,
>
> i want to talk with you about a question i have in mind and i do not
> find a answer. it 's simple:
> why do we not have a beatiful syntax for object definition as we have
> for class definition ?

See http://www.python.org/dev/peps/pep-0359  (already rejected by
Guido).

   Michele Simionato

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


Re: Pros/Cons of Turbogears/Rails?

2006-09-01 Thread Paul Boddie
fuzzylollipop wrote:
> Paul Boddie wrote:
> >
> > In various open source circles, the mere usage of 1.0 may indicate some
> > kind of stability, but not necessarily maturity, or at least the desire
> > of the developers to persuade users that the code is ready for them to
> > use.
>
> nope in GENERAL usage, 1.x means that the developer is designating a
> version that is feature complete and stable.

Please note the distinction between "stable" and "mature" - these are
not quite the same thing. Django, Rails and Turbogears may be at or
approaching 1.0, meaning that their developers regard them as being
stable (ie. no showstopping bugs), but that's not the same as being
mature. Moreover, the developers of all those frameworks will most
likely not stop at 1.0 but start working towards 2.0, possibly creating
quite a different product.

> I never ever mentioned comparing version numbers between differing packages.

No, but there are important psychological factors at work when choosing
and interpreting version numbers: do you go for ABC 0.9, XYZ 1.2 or PQR
7.1? What about the newly announced XYZ 2.0 - is that a safer choice
than its 1.x predecessor?

> MY POINT was the developers of Rails JUST RECENTLY decided that it was
> ready for general consumption compared to all the PREVIOUS Rails
> releases.

That judgement call may be true, but they haven't exactly been reticent
about getting people to download and use it before now.

> And NONE of these frameworks has been used to power anything along the
> scale of what I work with on a daily basis.

I can believe that. Do you have any success stories to share?

> And speaking from experience, autogenerated "Active Object Pattern"
> frameworks dont' scale. And Rails is no exception. It didn't work 10
> years ago when all the ORM vendors were selling ridiculously price
> "point and click" database application builders, what makes people
> think it will now?

My feeling was that any object-relational mapper that (supposedly in
this case) dictates how you're supposed to design your database
automatically rules itself out over a vast territory of existing and
new applications. Having seen the EJB army march themselves into a
swamp, my feeling is that most such mappers seem to be an increasingly
complicated excuse not to learn SQL.

Paul

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


Re: a new object definition

2006-09-01 Thread Bruno Desthuilliers
Sylvain Ferriol wrote:
> hello everybody,
> 
> i want to talk with you about a question i have in mind and i do not
> find a answer. it 's simple:
> why do we not have a beatiful syntax for object definition as we have
> for class definition ?

Python's classes are objects too - instances of their metaclass.

> we can define a class in python in 2 ways:
>  1. by using the metaclass constructor
>my_class = MyMetaClass()
>  2. by using the classic definition syntax:
>class my_class(object):
>   __metaclass__ = MyMetaClass
> 
> if i want to instanciate an object, i only have one way to define it:
>  my_obj = my_class()
>
> why not a better syntax like class syntax ?
>
> example:
>>> instance my_obj:
>>>   __class__ = my_class

I fail to see how it's "better", nor what would be the use case. But
anyway I think it could be possible by using the metaclass as class and
the class as instance. Just make sure the metaclass wraps all methods
into classmethods and you should be done.

> 
> with this syntax, we are coherent between objects and classes.
> why do we have a specific syntax for the class object definition and not
> for objects of different type?
> 
> so if i want to define a new class object (my_class for example) with a
> new object syntax:
>>> instance my_class:
>>>   __class__ = object
>>>   __metaclass__ = MyMetaClass
>>>   
> 
> thanks
> 
> Sylvain Ferriol
> Ingénieur de recherche
> Laboratoire TIMC/IMAG
> http://www-timc.imag.fr/
> 


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Classes referencing each other

2006-09-01 Thread Duncan Booth
"Manuel Bleichner" <[EMAIL PROTECTED]> wrote:

> If anyone of you knows a neat way to solve this, I'd be
> very grateful.

You could use a function:

class A(object):
   @staticmethod
   def connected_to(): return [B, C]
   

class B(object)
   @staticmethod
   def connected_to(): return [C]
   

class C(object)
   @staticmethod
   def connected_to(): return [A]
   

for cls in globals().values():
if (type(cls) is type and 
hasattr(cls, 'connected_to') and
callable(cls.connected_to)):
cls.connected_to = cls.connected_to()

or just store the names of the classes and do a similar fixup once they are 
all defined:

class A(object):
   connected_to = ['B', 'C']
   

for cls in globals().values():
if (type(cls) is type and 
hasattr(cls, 'connected_to')):
cls.connected_to = [globals()[c] for c in cls.connected_to ]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Broadcast server

2006-09-01 Thread swell
Yes but before going deeper ( too deep ) i would like to play with a
toy python example. Basically what i want to study first is a socket or
socket+select server and 5 clients that get time updated from the
server.

Don't really know how to keep hot connections without blocking the
server ? If someone can show me a quick and dirty example of the
client/server i'll apprciate it a lot.

Thx
Manu

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


Re: Python style: to check or not to check args and data members

2006-09-01 Thread Bruno Desthuilliers
Joel Hedlund wrote:
>> Short answer: Use Traits. Don't invent your own mini-Traits.
> 
> Thanks for a quick and informative answer! I'll be sure to read up on
> the subject. (And also: thanks Bruno for your contributions!)
> 
>> Types are very frequently exactly the wrong thing you want to check for.
> 
> I see what you mean. Allowing several data types may generate unwanted
> side effects (integer division when expecting real division, for example).
> 
> I understand that Traits can do value checking which is superior to what
> I presented, and that they can help me move validation away from
> functional code, which is always desirable. But there is still the
> problem of setting an approprate level of validation.
> 
> Should I validate data members only? This is quite easily done using
> Traits or some other technique and keeps validation bloat localized in
> the code. This is in line with the DRY principle and makes for smooth
> extensibility, but the tracebacks will be less useful.
> 
> Or should I go the whole way and validate at every turn (all data
> members, every arg in every method, ...)? This makes for very secure

...and inflexible...

> code and very useful tracebacks, but does not feel very DRY to me... Are
> the benefits worth the costs? Do I build myself a fortress of
> unmaintainability this way? Will people laugh at my modules?

I'm not sure that trying to fight against the language is a sound
approach, whatever the language. If dynamic typing gives you the creep,
then use a statically typed language - possibly with type-inference to
keep as much genericity as possible.

> Or taken to the other extreme: Should I simply duck-type everything, and
> only focus my validation efforts to external data (from users, external
> applications and other forces of evil). 

IMHO and according to my experience : 99% yes (there are few corner
cases where it makes sens to ensure args correctness - which may or not
imply type-checking). Packages like FormEncode are great for data
conversion/validation. Once you have trusted data, the only possible
problem is within your code.

> This solution makes for
> extremely clean code, but the thought of potential silent data
> corruption makes me more than a little queasy.

I've rarely encoutered "silent" data corruption with Python - FWIW, I
once had such a problem, but with a lower-level statically typed
language (integer overflow), and I was a very newbie programmer by that
time. Usually, one *very quickly* notices when something goes wrong. Now
if you're really serious, unit tests is the way to go - they can check
for much more than just types.

My 2 cents.
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Jython: PyException toString() is empty

2006-09-01 Thread axel
Hello,

I have the problem to get informations about script errors. And I have
found that I get a PySyntaxError if the script is wrong and if I use
for instance an unknown name I get PyException. But I don't get any
information, not even a string.
How can I get detailed informations about the error?

Thanks, axel

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


Re: Python style: to check or not to check args and data members

2006-09-01 Thread Bruno Desthuilliers
Joel Hedlund wrote:


> Bruno >> Your email address seem to be wrong. 

let's say "disguised" !-)

> I tried to reply to you
> directly in order to avoid thread bloat but my mail bounced.

I don't think it's a good idea anyway - this thread is on topic here and
may be of interest to others too IMHO.

And while we're at it : please avoid top-posting.



> Thanks for the quick reply though. I've skimmed through some docs on
> your suggestions and I'll be sure to read up on them properly later. But
> as I said to Robert Kern in this thread, this does not really seem
> resolve the
> problem of setting an approprate level of validation.

The "appropriate" level of validation depends on the context. There's
just no one-size-fits-all solution here. The only guideline I could come
with is too be paranoïd about what comes from the outside world and
mostly confident about what comes from other parts of the application.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python loops

2006-09-01 Thread stdazi
`range' is especially useful for iterating over long sequences ;-)

for i in range(0,100) :
OverflowError: range() result has too many items



Sybren Stuvel wrote:
> [EMAIL PROTECTED] enlightened us with:
> > I thought the xrange was preferred?  for x in xrange(length):
>
> True. It doesn't create the entire list, like range does. range(1000)
> creates a 1000-element list. xrange(1000) just iterates through the
> appropirate values.
>
> > The information contained in this message and any attachment may be
> > proprietary, confidential, and privileged or subject to the work
> > product doctrine and thus protected from disclosure.  If the reader
> > of this message is not the intended recipient, or an employee or
> > agent responsible for delivering this message to the intended
> > recipient, you are hereby notified that any dissemination,
> > distribution or copying of this communication is strictly
> > prohibited.  If you have received this communication in error,
> > please notify me immediately by replying to this message and
> > deleting it and all copies and backups thereof.  Thank you.
>
> And how are we supposed to interpret this? Copying this communication
> may be prohibited, but both email and usenet messages are copied all
> the time. Without that, both systems fail miserably.
>
> Sybren
> --
> The problem with the world is stupidity. Not saying there should be a
> capital punishment for stupidity, but why don't we just take the
> safety labels off of everything and let the problem solve itself?
>  Frank Zappa

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


Re: Classes referencing each other

2006-09-01 Thread Georg Brandl
Manuel Bleichner wrote:
> Hello list,
> 
> I have searched for some time now, but no result...
> I'm having the following problem:
> 
> In a module I have a huge number of classes of the form:
> 
> class A(object):
>connected_to = [B, C]
>
> 
> class B(object)
>connected_to = [C]
>
> 
> class C(object)
>connected_to = [A]
>
> 
> As you see, classes A and B reference classes that
> are not yet defined when the class is being defined.
> It will raise a NameError: 'B'.
> 
> I know i could solve this by leaving out the definition
> of 'connected_to' in A and attach it to the class later on by
> A.connected_to = [B, C]
> but I would like to avoid this, because in the module
> there are about 50 classes that have to be altered from time
> to time and it's just incredibly ugly if I have to look for
> the attribute definitions in more than one place.

You could move all connections to a central location after the
class definitions, such as

class A: pass
class B: pass
class C: pass

connections = {A: (B, C), B: (C,), C: (A,)}

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


Re: Python style: to check or not to check args and data members

2006-09-01 Thread Joel Hedlund
> And while we're at it : please avoid top-posting.

Yes, that was sloppy. Sorry.

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


Re: Classes referencing each other

2006-09-01 Thread Manuel Bleichner
Thanks for your answer :)

> You could use a function:
>
> class A(object):
>@staticmethod
>def connected_to(): return [B, C]
>

I already thought about such a solution, but since
my code has to be compatible with python 2.3, i would
have to use the connected_to = staticmethod(connected_to)
syntax, which bloats the code and makes it quite unreadable.


> or just store the names of the classes and do a similar fixup once they  
> are
> all defined:
>
> class A(object):
>connected_to = ['B', 'C']
>
>
> for cls in globals().values():
> if (type(cls) is type and
> hasattr(cls, 'connected_to')):
> cls.connected_to = [globals()[c] for c in cls.connected_to ]

This solution seems good to me. It won't work for me as it is,
because the structure of the classes is actually a bit more
complex, but it pushed me in the right direction.

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


Re: python loops

2006-09-01 Thread bearophileHUGS
Kay Schluehr:
> I hate ii ;)

It's not nice looking, I agree. A more explicit name is often better.
But I think ii is better than i because you can find it in the code
 (with the Find command of the editor or grep) more easily than i.

Bye,
bearophile

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


Re: Classes referencing each other

2006-09-01 Thread Manuel Bleichner
Thanks for the answer.

> You could move all connections to a central location after the
> class definitions, such as
>
> class A: pass
> class B: pass
> class C: pass
>
> connections = {A: (B, C), B: (C,), C: (A,)}


I think I simplified my classes a bit too much :)
Actually there are multiple types of connections between
the classes. for example:

class A(CableConnected, WLANConnected):
   name = 'I am class A'
   cable_connections = [B, C]
   wlan_connections = [D]

class B(CableConnected, RadioConnected):
   name = 'I am class B'
   cable_connections = [C, A]
   radio_connections = [F]
...

And because not all classes have the same types of connections,
it would become extremely unreadable to try to define them
at a central place. Also it seperates attributes from each other;
'name' is defined in the class, the connections somewhere else.

Greetings,
Manuel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python loops

2006-09-01 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I thought the xrange was preferred?  for x in xrange(length):

preferred by premature optimization freaks, perhaps.  in practice, if the
range is reasonably small and you're going to loop over all the integers,
it doesn't really matter.

(the range form creates a list and N integers up front; the xrange form
creates an iterator object up front and N integers while you're looping.
what's faster depends on what Python version you're using, and some-
times also on the phase of the moon)

in Python 3.0, xrange() will disappear, and range() will return an iterator
instead.

 



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


Re: Classes referencing each other

2006-09-01 Thread John Machin
Manuel Bleichner wrote:
> Hello list,
>
> I have searched for some time now, but no result...
> I'm having the following problem:
>
> In a module I have a huge number of classes of the form:
>
> class A(object):
>connected_to = [B, C]
>
>
> class B(object)
>connected_to = [C]
>
>
> class C(object)
>connected_to = [A]
>
>
> As you see, classes A and B reference classes that
> are not yet defined when the class is being defined.
> It will raise a NameError: 'B'.
>
> I know i could solve this by leaving out the definition
> of 'connected_to' in A and attach it to the class later on by
> A.connected_to = [B, C]
> but I would like to avoid this, because in the module
> there are about 50 classes that have to be altered from time
> to time and it's just incredibly ugly if I have to look for
> the attribute definitions in more than one place.

So why can't you do it all in one place by
A.connected_to = [B, C]
B.connected_to = [C]
C.connected_to = [A]
?

or by a tabular method:

connections = (
(A, [B, C]),
(B, [C]),
(C, [A]),
)
for cls_from, targets in connections:
# maybe insert some checking code in here ...
# is X.connected_to = [X] allowed?
# is Y.connected_to = [] allowed?
cls_from.connected_to = targets

>
> Also, I would like to avoid eval(), because the references
> have to be followed very often and that would cause more
> CPU load and make the program code uglier :)

Avoiding eval() does always seem to be a good thing :-)

BTW, care to tell us what the connections mean? Applications of
connected instances of the one class are of course very common, but 50
classes connected in a cyclic fashion is rather new to me ...

Cheers,
John

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


Re: raw audio in windows

2006-09-01 Thread Ben Sizer
Putty wrote:
> Hi.  I've written a small python script that was primarily meant for
> use in a unix-compatible environment.  It writes a bunch of raw audio
> to a file and then sends the file to /dev/audio and the system plays
> the audio.  Very simple.
>
> Is there a simple way I could edit the script (which just uses the
> system call to do this) to run under windows?
>
> This is the code that would have to change:
> os.system("cat audioBuf > /dev/audio")

Not really. You'll have to convert it to .wav and then pass it to a
helper app.



-- 
Ben Sizer

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


Re: raw audio in windows

2006-09-01 Thread Fredrik Lundh
Ben Sizer wrote:

> Not really. You'll have to convert it to .wav and then pass it to a
> helper app.
>
> 

>>> import winsound
>>> help(winsound)
Help on module winsound:

NAME
winsound

FILE
c:\python24\dlls\winsound.pyd

DESCRIPTION
PlaySound(sound, flags) - play a sound
SND_FILENAME - sound is a wav file name
SND_ALIAS - sound is a registry sound association name
SND_LOOP - Play the sound repeatedly; must also specify SND_ASYNC
SND_MEMORY - sound is a memory image of a wav file
SND_PURGE - stop all instances of the specified sound
SND_ASYNC - PlaySound returns immediately
SND_NODEFAULT - Do not play a default beep if the sound can not be found
SND_NOSTOP - Do not interrupt any sounds currently playing
SND_NOWAIT - Return immediately if the sound driver is busy

Beep(frequency, duration) - Make a beep through the PC speaker.

FUNCTIONS
Beep(...)
Beep(frequency, duration) - a wrapper around the Windows Beep API

The frequency argument specifies frequency, in hertz, of the sound.
This parameter must be in the range 37 through 32,767.
The duration argument specifies the number of milliseconds.
On WinNT and 2000, the platform Beep API is used directly.  Else funky
code doing direct port manipulation is used; it's unknown whether that
will work on all systems.

MessageBeep(...)
MessageBeep(x) - call Windows MessageBeep(x). x defaults to MB_OK.

PlaySound(...)
PlaySound(sound, flags) - a wrapper around the Windows PlaySound API

The sound argument can be a filename, data, or None.
For flag values, ored together, see module documentation.

DATA
MB_ICONASTERISK = 64L
MB_ICONEXCLAMATION = 48L
MB_ICONHAND = 16L
MB_ICONQUESTION = 32L
MB_OK = 0L
SND_ALIAS = 65536L
SND_APPLICATION = 128L
SND_ASYNC = 1L
SND_FILENAME = 131072L
SND_LOOP = 8L
SND_MEMORY = 4L
SND_NODEFAULT = 2L
SND_NOSTOP = 16L
SND_NOWAIT = 8192L
SND_PURGE = 64L

 



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


Re: Python style: to check or not to check args and data members

2006-09-01 Thread Joel Hedlund
> I'm not sure that trying to fight against the language is a sound
> approach, whatever the language. 

That's the very reason I posted in the first place. I feel like I'm fighting 
the language, and since python at least to me seems to be so well thought 
out in all other aspects, the most obvious conclusion must be that I'm 
thinking about this the wrong way. And that's why I need your input!

>> > Or taken to the other extreme: Should I simply duck-type everything, and
>> > only focus my validation efforts to external data (from users, external
>> > applications and other forces of evil). 
> 
> IMHO and according to my experience : 99% yes (there are few corner
> cases where it makes sens to ensure args correctness - which may or not
> imply type-checking). Packages like FormEncode are great for data
> conversion/validation. Once you have trusted data, the only possible
> problem is within your code.

That approach is quite in line with the "blame yourself" methodology, which 
seems to work in most other circumstances. Sort of like, developers who feed 
bad data into my code have only themselves to blame! I can dig that. :-)

Hmmm... So. I should build grimly paranoid parsers for external data, use 
duck-typed interfaces everywhere on the inside, and simply callously 
disregard developers who are disinclined to read documentation? I could do that.

 > if you're really serious, unit tests is the way to go - they can check
 > for much more than just types.

Yes, I'm very much serious indeed. But I haven't done any unit testing. I'll 
have to check into that. Thanks!

> My 2 cents.

Thankfully recieved and collecting interest as we speak.

Cheers!
/Joel
-- 
http://mail.python.org/mailman/listinfo/python-list


Adding sender name to email

2006-09-01 Thread gillespie . amanda
How do I add a Sender name to the emails sent by the following script:

def createhtmlmail (html, text, subject):
"""Create a mime-message that will render HTML in popular
   MUAs, text in better ones"""
import MimeWriter
import mimetools
import cStringIO

out = cStringIO.StringIO() # output buffer for our message
htmlin = cStringIO.StringIO(html)
txtin = cStringIO.StringIO(text)

writer = MimeWriter.MimeWriter(out)
# set up some basic headers... we put subject here
# because smtplib.sendmail expects it to be in the
# message body
#
writer.addheader("Subject", subject)
writer.addheader("MIME-Version", "1.0")
#
# start the multipart section of the message
# multipart/alternative seems to work better
# on some MUAs than multipart/mixed
#
writer.startmultipartbody("alternative")
writer.flushheaders()
#
# the plain text section
#
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
pout = subpart.startbody("text/plain", [("charset", 'us-ascii')])
mimetools.encode(txtin, pout, 'quoted-printable')
txtin.close()
#
# start the html subpart of the message
#
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
#
# returns us a file-ish object we can write to
#
pout = subpart.startbody("text/html", [("charset", 'us-ascii')])
mimetools.encode(htmlin, pout, 'quoted-printable')
htmlin.close()
#
# Now that we're done, close our writer and
# return the message body
#
writer.lastpart()
msg = out.getvalue()
out.close()
return msg

if __name__=="__main__":
import smtplib
from time import *

f = open("mssg.html", 'r')
html = f.read()
f.close()
f = open("mssg.txt", 'r')
text = f.read()
f.close()
subject = "subject)"

f = open("temp.txt", 'r')
RECIPIENTS = []
for line in f:
RECIPIENTS.append(line.strip())
f.close()
for i in RECIPIENTS:
if len(i) == 0:
RECIPIENTS.remove(i)
print "Number of recipients: ", len(RECIPIENTS)

SENDER = '[EMAIL PROTECTED]'
print "Generating message..."
mssg = createhtmlmail(html, text, subject)
print "Opening session"
session = smtplib.SMTP("localhost")
print "Sending email"
offset = 0
blocksize = 20 # to send emails in blocks of 20, so I don't
bomb out my server
while offset*blocksize < len(RECIPIENTS):
print "Sending message ", offset*blocksize, " - ",
(offset+1)*blocksize, "of ", len(RECIPIENTS), "..."
smtpresult =
session.sendmail(SENDER,RECIPIENTS[offset*blocksize:(offset+1)*blocksize],mssg)
sleep(30)
offset += 1
##  smtpresult = session.sendmail(SENDER, RECIPIENTS, mssg)

if smtpresult:
errstr = ""
for recip in smtpresult.keys():
errstr = """Could not delivery mail to: %s
Server said: %s
%s
%s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)
raise smtplib.SMTPException, errstr
session.quit()

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


Jython: single step / pause / debug ...

2006-09-01 Thread axel
Hello,

I want to integrate Jython into my java application. But I want to
control the script execution. How can be realized this? I have used
TraceFunction and the script stops alway in traceCall().
But (1) I have never seen what I have to return there, (2) only this
function is called - also if there is an error in the script and (3)
what I have to do to pause/stop the script?

Thanks, Axel

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


Question about ftplib

2006-09-01 Thread alper soyler
I am trying to get '.pep' files from the ftp.genome.jp/pub/kegg/genomes/??? directories (???=directory names) with the below script. However, after downloading 121 files (I have to download 300 more), it gave me the time out error message:Traceback (most recent call last):  File "ftp1.0.py", line 18, in ?    for filename in ftp.nlst():  File "/usr/lib/python2.4/ftplib.py", line 448, in nlst    self.retrlines(cmd, files.append)  File "/usr/lib/python2.4/ftplib.py", line 396, in retrlines    conn = self.transfercmd(cmd)  File "/usr/lib/python2.4/ftplib.py", line 345, in transfercmd    return self.ntransfercmd(cmd,
 rest)[0]  File "/usr/lib/python2.4/ftplib.py", line 324, in ntransfercmd    conn.connect(sa)  File "", line 1, in connectsocket.error: (110, 'Connection timed out')How can I continue from the last download or  is there any way to arrange the time? Script:from ftplib import FTP
def handleDownload(block):
    file.write(block)
    print ".", ftp = FTP('ftp.genome.jp')
print ftp.login()
 directory = '/pub/kegg/genomes'ftp.cwd(directory)k=0for direct in ftp.nlst():    curdir = '%s/%s' % (directory, direct)    ftp.cwd(curdir)    for filename in ftp.nlst():        if not filename.endswith('.pep'):
 continue        file = open(filename, 'wb')        ftp.retrbinary('RETR %s/%s' % (curdir, filename), handleDownload)        file.close()    k=k+1    print ftp.close()- Original Message From: [EMAIL PROTECTED]To: python-list@python.orgSent: Friday, September 1, 2006 1:00:05 PMSubject: Python-list Digest, Vol 36, Issue 10Send Python-list mailing list submissions topython-list@python.orgTo subscribe or unsubscribe via the World Wide Web, visithttp://mail.python.org/mailman/listinfo/python-listor, via email, send a message with subject or body
 'help' to[EMAIL PROTECTED]You can reach the person managing the list at[EMAIL PROTECTED]When replying, please edit your Subject line so it is more specificthan "Re: Contents of Python-list digest..."Today's Topics:   1. Re: python loops (stdazi)   2. Re: Classes referencing each other (Georg Brandl)   3. Re: Python style: to check or not to check args and data  members (Joel Hedlund)   4. Re: Classes referencing each other (Manuel Bleichner)   5. Re: python loops ([EMAIL PROTECTED])From: "stdazi" <[EMAIL PROTECTED]>Precedence: listMIME-Version: 1.0To: python-list@python.orgReferences:
 <[EMAIL PROTECTED]><[EMAIL PROTECTED]><[EMAIL PROTECTED]>In-Reply-To: <[EMAIL PROTECTED]>Date: 1 Sep 2006 02:34:48 -0700Message-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset="iso-8859-1"Subject: Re: python loopsMessage: 1`range' is especially useful for iterating over long sequences ;-)for i in range(0,100) :OverflowError: range() result has too many itemsSybren Stuvel wrote:> [EMAIL PROTECTED] enlightened us with:> > I thought the xrange was preferred?  for x in xrange(length):>> True. It doesn't create the entire list, like range does.
 range(1000)> creates a 1000-element list. xrange(1000) just iterates through the> appropirate values.>> > The information contained in this message and any attachment may be> > proprietary, confidential, and privileged or subject to the work> > product doctrine and thus protected from disclosure.  If the reader> > of this message is not the intended recipient, or an employee or> > agent responsible for delivering this message to the intended> > recipient, you are hereby notified that any dissemination,> > distribution or copying of this communication is strictly> > prohibited.  If you have received this communication in error,> > please notify me immediately by replying to this message and> > deleting it and all copies and backups thereof.  Thank you.>> And how are we supposed to interpret this? Copying this
 communication> may be prohibited, but both email and usenet messages are copied all> the time. Without that, both systems fail miserably.>> Sybren> --> The problem with the world is stupidity. Not saying there should be a> capital punishment for stupidity, but why don't we just take the> safety labels off of everything and let the problem solve itself?>  Frank ZappaContent-Transfer-Encoding: 7bitFrom: Georg Brandl <[EMAIL PROTECTED]>Precedence: listMIME-Version: 1.0To: python-list@python.orgReferences: <[EMAIL PROTECTED]>In-Reply-To:
 <[EMAIL PROTECTED]>Date: Fri, 01 Sep 2006 11:50:42 +0200Message-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset=ISO-8859-15; format=flowedSubject: Re: Classes referencing each otherMessage: 2Manuel Bleichner wrote:> Hello list,> > I have searched for some time now, but no result...> I'm having the following problem:> > In a module I have a huge number of classes of the form:> > class A(object):>connected_to = [B, C]>> > class B(object)>connected_to = [C]>> > class C(object)>connected_to = [A]>> > As you see,
 classes A and B reference classes that> are not yet defined when the class i

Re: a new object definition

2006-09-01 Thread Sylvain Ferriol
Michele Simionato a écrit :
> Sylvain Ferriol wrote:
> 
>>hello everybody,
>>
>>i want to talk with you about a question i have in mind and i do not
>>find a answer. it 's simple:
>>why do we not have a beatiful syntax for object definition as we have
>>for class definition ?
> 
> 
> See http://www.python.org/dev/peps/pep-0359  (already rejected by
> Guido).
> 
i do not understand the withdrawal note, what do "different level" mean ?
do you have an example or is it python core implemantation problem ?
>Michele Simionato
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Classes referencing each other

2006-09-01 Thread Manuel Bleichner
Hi, thanks for your answer, too :)

Your solution won't do it, because of reasons I explained
in the answer to Georg Brandl.

> BTW, care to tell us what the connections mean? Applications of
> connected instances of the one class are of course very common, but 50
> classes connected in a cyclic fashion is rather new to me ...

Okay, I didn't want to do this, because some of you would
think I'm crazy, but what the heck :D

I'm programming a browsergame which is split in multiple parts.
There is a core which is running all the time and a cgi client connecting
to it. The core maintains all classes and keeps the game running, while
the client only requests data from it.
The core of course needs to hold all the definitions for the game
(e.g. units, buildings, resources, research) - these are written as
classes.

class EMCenter(Building, Researcher, Constructor, OnLand):
   maxhitpoints = 1000
   researchspeed = 70
   constructspeed = 50
   research_costs = [SmallEM, Weapons, Shields]
   resource_costs = [Iron: 500, Granite: 300, Silicon: 150]
   possible_research = [MediumEM, EMWeapons, EmShockwave]
   possible_constructs = [Razor, Lancer, Stinger]# these are  
all units

Now when a certain unit should be built, it must be checked if
the requirements are matched.
=> check research_costs and resource_costs
After building it, an instance of the class will be created.
The new object can itself build (=> Constructor) and research
(=> Researcher) the items provided in possible_constructs and
possible_research.

The problem occured when i wanted to define a unit that can
construct a building which itself is able to construct that
unit.

Absolutely overkill for a browsergame, I know, but I like the concept =)


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


Threads and Progress Bar

2006-09-01 Thread Ritesh Raj Sarraf
Hi,

I have a small application, written in Python, that uses threads.
The application uses function foo() to download files from the web. As it reads
data from the web server, it runs a progress bar by calling an install of a
progress bar class.

When using threads, I get the problem that the progress bar gets over-written by
the download progress of files from other threads.

I believe my change has to go into the progress bar class to make it thread
aware.

Are they any docs/suggestions on how to implement progress bars along with
threads ?

Thanks,
Ritesh
-- 
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
"Necessity is the mother of invention."
"Stealing logic from one person is plagiarism, stealing from many is research."
"The great are those who achieve the impossible, the petty are those who
cannot - rrs"

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


Re: Adding sender name to email

2006-09-01 Thread Tim Williams
On 1 Sep 2006 03:26:12 -0700, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> How do I add a Sender name to the emails sent by the following script:
>

>
> writer = MimeWriter.MimeWriter(out)
> # set up some basic headers... we put subject here
> # because smtplib.sendmail expects it to be in the
> # message body
> #
> writer.addheader("Subject", subject)
> writer.addheader("MIME-Version", "1.0")
> #

add the line

writer.addheader("From", a_sender_address)

and you should also have

writer.addheader("To", some_recipient_address(es)_as_a_string)

The smtp sender & recipients do not relate to the sender & recipients
in the email itself,  Often they are the same, but they don't have to
be.

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


Django website

2006-09-01 Thread Antal Rutz
hi,

is there something wrong with django's website (djangoproject.com)
or I have problems?
It looks ugly, the css files can't be found, I even cannot download
the source from there.
Do you know anything about them?
Any mirror I can get the tarball from?

Thanks

-- 


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


Re: Adding sender name to email

2006-09-01 Thread Tim Williams
On 01/09/06, Tim Williams <[EMAIL PROTECTED]> wrote:
> On 1 Sep 2006 03:26:12 -0700, [EMAIL PROTECTED]
> <[EMAIL PROTECTED]> wrote:
> > How do I add a Sender name to the emails sent by the following script:
> >
> add the line
>
> writer.addheader("From", a_sender_address)
>
> and you should also have
>
> writer.addheader("To", some_recipient_address(es)_as_a_string)
>
> The smtp sender & recipients do not relate to the sender & recipients
> in the email itself,  Often they are the same, but they don't have to
> be.
>

as an afterthought,  you should also add date & msg-id headers, or
your emails may fall foul of spam-filters.


-- 

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


Re: Django website

2006-09-01 Thread Richie Hindle

[Antal]
> is there something wrong with django's website (djangoproject.com)
> or I have problems?
> It looks ugly, the css files can't be found, I even cannot download
> the source from there.

It's broken for me too, so it's not a problem at your end.

-- 
Richie Hindle
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pros/Cons of Turbogears/Rails?

2006-09-01 Thread paron

[EMAIL PROTECTED] wrote:

> I was initially leaning towards Rails due to maturity,
> but the most recent version of TurboGears seem to have
> fixed a lot of the "ad hoc" feeling I got from previous
> versions. But I'm still very much up in the air.
>
> Thanks,
> Ken

I've found that familiarity with Windows in the Ruby/Rails community is
less than in the Python/TG community. Ruby/Rails seems to have been
mainly *nix until fairly recently.

Sometimes the Windows version of a module or tutorial will lag
significantly. (ldap comes to mind.) Sometimes Windows-oriented
questions get pretty short shrift along the lines of: "Perish the
thought!" or "Why would you?" instead of serious treatment.

It's not a deal-breaker and neither community is perfect in this
respect. I now work mostly with Ruby/Rails, but I did Python/CherryPy
for quite a while, and that's my impression.

Ron

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


Re: a new object definition

2006-09-01 Thread Michele Simionato
Sylvain Ferriol wrote:
> Michele Simionato a écrit :
> >
> > See http://www.python.org/dev/peps/pep-0359  (already rejected by
> > Guido).
> >
> i do not understand the withdrawal note, what do "different level" mean ?
> do you have an example or is it python core implemantation problem ?

I asked Guido in person at EuroPython. He said the syntax didn't look
"right" to him. It is as simple as that.

  Michele Simionato

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


Re: Python style: to check or not to check args and data members

2006-09-01 Thread Bruno Desthuilliers
Joel Hedlund wrote:
>> I'm not sure that trying to fight against the language is a sound
>> approach, whatever the language. 
> 
> That's the very reason I posted in the first place. I feel like I'm
> fighting the language, and since python at least to me seems to be so
> well thought out in all other aspects, the most obvious conclusion must
> be that I'm thinking about this the wrong way. And that's why I need
> your input!

The first thing I tried to do when I discovered Python (coming from
statically typed langages) was to try to forcefit it into static typing.
Then I realized that there was a whole lot of non-trivial Python apps
and libs that did just work, which made me think about the real
usefulness of static typing. Which is mainly optimisation hints for the
machine. As you probably noticed, declarative static typing imposes much
boilerplate and somewhat arbitrary restrictions, and I still wait for a
proof that it leads to more robust programs - FWIW, MVHO is that it
usually leads to more complex - hence potentially less robust - code.

>>> > Or taken to the other extreme: Should I simply duck-type
>>> everything, and
>>> > only focus my validation efforts to external data (from users,
>>> external
>>> > applications and other forces of evil). 
>
>> IMHO and according to my experience : 99% yes (there are few corner
>> cases where it makes sens to ensure args correctness - which may or not
>> imply type-checking). Packages like FormEncode are great for data
>> conversion/validation. Once you have trusted data, the only possible
>> problem is within your code.
> 
> That approach is quite in line with the "blame yourself" methodology,
> which seems to work in most other circumstances. Sort of like,
> developers who feed bad data into my code have only themselves to blame!

As long as your code is correctly documented, yes. All attempts to write
idiot-proof librairy code as failed so far AFAICT, so just let idiots
suffer from their idiocy and focus on providing good tools to normal
programmers. My own philosophie of course...

> I can dig that. :-)
> 
> Hmmm... So. I should build grimly paranoid parsers for external data,

Most of the time, you'll find they already exists. FormEncode is not
just for html forms - it's a general, powerful and flexible (but alas
very badly documented) bidirectional data converter/validator.

> use duck-typed interfaces everywhere on the inside,

Talking about interfaces, you may want to have a look at PyProtocols
(PEAK) and Zope3 Interfaces.

> and simply callously
> disregard developers who are disinclined to read documentation? 

As long as you provide a usable documentation, misuse of your code is
not your problem anymore (unless of course you're the one misusing it !-).

> I could
> do that.
> 
>> if you're really serious, unit tests is the way to go - they can check
>> for much more than just types.
> 
> Yes, I'm very much serious indeed. But I haven't done any unit testing.

Then you probably want to read the relevant chapter in DiveIntoPython.

HTH
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Django website

2006-09-01 Thread Bruno Desthuilliers
Antal Rutz wrote:
> hi,
> 
> is there something wrong with django's website (djangoproject.com)

Obviously, yes.

> or I have problems?

I don't think so.

I warned them on the google group, I think things should be fixed soon.


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Question about import and namespace

2006-09-01 Thread jdemoor
Hi,

I'm new to Python and have the following problem :
I have an application started by a main.py file, which does a ' from
module_1 import * '.
main.py is responsible from the creation of an object which is then
used in module_1.
What is the best way to make that object visible in the module_1
namespace ?
I guess that if I do an ' import module_1 ', I can make the object
visible with ' module_1.myObject = myObject ', but that won't work with
the from ... import * statement.

Thanks in advance for your help.

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


Re: Question about import and namespace

2006-09-01 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, jdemoor wrote:

> I have an application started by a main.py file, which does a ' from
> module_1 import * '.
> main.py is responsible from the creation of an object which is then
> used in module_1.
> What is the best way to make that object visible in the module_1
> namespace ?
> I guess that if I do an ' import module_1 ', I can make the object
> visible with ' module_1.myObject = myObject ', but that won't work with
> the from ... import * statement.

Give the object as argument to functions in `module_1` is a clean solution.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about import and namespace

2006-09-01 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> I'm new to Python and have the following problem :
> I have an application started by a main.py file, which does a ' from
> module_1 import * '.
> main.py is responsible from the creation of an object which is then
> used in module_1.
> What is the best way to make that object visible in the module_1
> namespace ?
> I guess that if I do an ' import module_1 ', I can make the object
> visible with ' module_1.myObject = myObject ', but that won't work with
> the from ... import * statement.

You can do both

from module import * 
import module

as these kinds of import are not mutually exclusive.
But I recommend that you restructure your modules to avoid cyclic
dependencies.

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


dictionaries - returning a key from a value

2006-09-01 Thread Michael Malinowski








Appologies if this is a somewhat simple question, but
currently I can return a value from a dictionary using its key by doing :

 

 dDictionary.get( key )

 

However, I am curious to know if its possible to get the key
from giving a value (basically the opposite of what I did above, instead of
getting a value from a key, I want the key from a value). Is there a way of
doing this? Or would I need to cycle all the keys until I hit a value match
(which seems somewhat cumbersome). 

 

Cheers

Mike. 






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

How to make an announcement (was Re: ANN: GMPY binaries for Windows 2.5)

2006-09-01 Thread beliavsky
[EMAIL PROTECTED] wrote:
> GMPY binaries for Python 2.5 are available at
> http://home.comcast.net/~casevh/

"The General Multiprecision PYthon project (GMPY) focuses on
Python-usable modules providing multiprecision arithmetic functionality
to Python programmers."

A sign of Python's health is that there are so many open-source
projects that it is difficult to keep track of all of them. I think
announcements should contain at least one sentence describing what the
project is about. One can Google this, of course, but it saves the
reader time if this information is provided in the message.

>
> Notes
> 
> They have not been extensively tested.
>
> This is based on the CVS version of gmpy and includes a patch (not yet
> in CVS) from Alex Martelli that resolves a bug with divm(). Please
> consider this an "unofficial" release. The patch and the source code
> snapshot I used are also available on the website.
>
> GMP 4.2.1 is used.
>
> There are three versions available: one that should work on any
> processor, one compiled for Pentium 4 processor, and one compiled for
> AMD Athlon (32-bit).
>
> If there is demand, I'll create updated binaries for earlier version of
> Python.
> 
> Enjoy,
> 
> casevh

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


Re: introspection

2006-09-01 Thread rick
Fredrik Lundh wrote:
> brad tilley wrote:
> 
>> How do I import a module and then ask it to show me its methods or 
>> other aspects about itself during execution? I'd like to do something 
>> such as this:
>>
>> import win32api
> 
> dir(win32api)
> help(win32api)
> 
> and also
> 
> import inspect
> help(inspect)
> 
> 
> 

Great info guys! Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dictionaries - returning a key from a value

2006-09-01 Thread Avell Diroll
Michael Malinowski wrote:
(snip)
> However, I am curious to know if its possible to get the key from giving
> a value (basically the opposite of what I did above, instead of getting
> a value from a key, I want the key from a value). Is there a way of
> doing this? Or would I need to cycle all the keys until I hit a value
> match (which seems somewhat cumbersome).
(snip)

I believe you need to cycle through the entire dict (but that's what a
dict. would do ... wouldn't it?) ... but it is really quickly
done using list comprehension (in Ipython shell here):

In [30]: sampledict={'the Holy Grail':'1975', 'Life of Brian':'1979',
'Party Political Broadcast':'1974','Mr. Neutron':'1974',
'Hamlet':'1974', 'Light Entertainment War':'1974'}

In [31]: sampledict Out[31]:
{'Hamlet': '1974',
 'Life of Brian': '1979',
 'Light Entertainment War': '1974',
 'Mr. Neutron': '1974',
 'Party Political Broadcast': '1974',
 'the Holy Grail': '1975'}

In [32]: sampledict.get('the Holy Grail') Out[32]: '1975'

In [33]: sampledict['Mr. Neutron'] Out[33]: '1974'

In [34]: keys = [key for key in sampledict if sampledict[key] == '1974']
In [35]: keys
Out[35]:
['Mr. Neutron',
 'Hamlet',
 'Party Political Broadcast',
 'Light Entertainment War']




HIH

Avell

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


Help with autotools

2006-09-01 Thread Jonh Wendell
Hi all! I need help with autotools stuff..

My directory structure:

project_name
  src
main.py
others.py
  data
ui.glade
images.png
  po
translations.po

I'd like to do something like that:

The files in "src" should be installed at: $prefix/lib/project_name
The files in "data" should be installed at: $prefix/share/project_name

At $prefix/bin should be create a slink:
 $prefix/bin/project_name -> $prefix/lib/project_name/main.py

The listen (http://listengnome.free.fr/) does this, but it doesn't use
autotools...

Can anyone help me?
I've tried a lot to make this work, but with no success...

Thanks,
-- 
Jonh Wendell Santana
Analista de Sistemas

http://www.bani.com.br
MSN: [EMAIL PROTECTED]
GTalk/Jabber: [EMAIL PROTECTED]
Linux User #114432

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


Re: Egg problem (~/.python-eggs)

2006-09-01 Thread paul kölle
Mike Orr wrote:
[... snipp ...]

> Can I make it use a different eggs directory?  Any other idea how to
> install a program using eggs on a server?

I had a similar issue with tracd on gentoo. My solution was setting
PYTHON_EGG_CACHE=/tmp/.egg_cache in /etc/conf.d/tracd and exporting that
var in /etc/init.d/tracd before calling start-stop-daemon, e.g.

export PYTHON_EGG_CACHE=${PYTHON_EGG_CACHE}
start-stop-daemon --start 


cheers
 Paul

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


ANN: GMPY binaries for Python 2.5

2006-09-01 Thread casevh
Marc 'BlackJack' Rintsch wrote:

> Interesting subject line.  I think I still have a set of "Win 3.11 for
> workgroups" disks lying around somewhere, but where do I get Windows 2.5? ;-)
>
> SCNR,
>   Marc 'BlackJack' Rintsch

I've changed the subject line to read "Python 2.5" instead of "Windows
2.5".

Wasn't Windows 2.5 the result of running Windows 3.11 on a 386sx
processor? ;-)

Thanks for stirring up old memories. I wonder where my 3.11 disks are?

casevh

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


Re: a new object definition

2006-09-01 Thread Sylvain Ferriol
Michele Simionato a écrit :
> Sylvain Ferriol wrote:
> 
>>Michele Simionato a écrit :
>>
>>>See http://www.python.org/dev/peps/pep-0359  (already rejected by
>>>Guido).
>>>
>>
>>i do not understand the withdrawal note, what do "different level" mean ?
>>do you have an example or is it python core implemantation problem ?
> 
> 
> I asked Guido in person at EuroPython. He said the syntax didn't look
> "right" to him. It is as simple as that.
> 
note that we can not use the "make syntax" for a function definition 
because the block is not executed until the function call, while the 
block for a class is executed before the class instanciation
>   Michele Simionato
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


OO on python real life tutorial?

2006-09-01 Thread filippo
Hello,

I coded my +10k lines app using Perl/Tk. It is something like a hotel
software manager, it has a bunch of windows to manage the arrivals,
bills etc etc. I want to port this on Python/WxPython but I'd like to
get benefit of python, not just doing a row by row raw porting.

My problem is that I cannot figure out how OO could be useful in my
case. Is there a OO tutorial out there to help me?

Thanks,

Filippo

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


Re: Question about import and namespace

2006-09-01 Thread jdemoor
Thanks for the replies.

> You can do both
>
> from module import *
> import module
>
> as these kinds of import are not mutually exclusive.

Would this run the code in 'module' twice, or just make the objects in
it accessible by several names ?

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


Re: OO on python real life tutorial?

2006-09-01 Thread Fredrik Lundh
"filippo" wrote:

> I coded my +10k lines app using Perl/Tk. It is something like a hotel
> software manager, it has a bunch of windows to manage the arrivals,
> bills etc etc. I want to port this on Python/WxPython but I'd like to
> get benefit of python, not just doing a row by row raw porting.
>
> My problem is that I cannot figure out how OO could be useful in my
> case. Is there a OO tutorial out there to help me?

How many do you need ? ;-)

Here's Jay Parlar's proposed class intro for the python tutorial:

http://pytut.infogami.com/node11-baseline.html

I haven't seen them myself, but the related ShowMeDo videos might be
helpful:


http://showmedo.com/videos/series?name=IntroductionToPythonObjectsUsingIPython_JerolH

See also chapters 12-16 in "How to Think Like a Computer Scientist":

http://www.ibiblio.org/obp/thinkCSpy/

 



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


Re: Question about import and namespace

2006-09-01 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> Thanks for the replies.
> 
>> You can do both
>>
>> from module import *
>> import module
>>
>> as these kinds of import are not mutually exclusive.
> 
> Would this run the code in 'module' twice, or just make the objects in
> it accessible by several names ?

The latter. But why don't you try it yourself by putting a 

print "importing module" # you will see that once

statement in the module? 

There is one notable exception, the application's main module:

$ cat main.py
import main
print "importing main as", __name__
$ python main.py
importing main as main
importing main as __main__

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


Re: Question about import and namespace

2006-09-01 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, jdemoor wrote:

>> from module import *
>> import module
>>
>> as these kinds of import are not mutually exclusive.
> 
> Would this run the code in 'module' twice, or just make the objects in
> it accessible by several names ?

The code at module level is only executed at first import.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dictionaries - returning a key from a value

2006-09-01 Thread bearophileHUGS
Avell Diroll:

keys = [key for key in sampledict if sampledict[key] == '1974']

Or better, given:

sampledict = {'the Holy Grail':1975, 'Life of Brian':1979,
  'Party Political Broadcast':1974,'Mr. Neutron':1974,
  'Hamlet':1974, 'Light Entertainment War':1974}

keys = [key for key,year in sampledict.iteritems() if year == 1974]
print keys

Another solution is a two-way (bidirectional) dict:
http://cheeseshop.python.org/pypi/two_way_dict/0.2

Bye,
bearophile

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


working with ldap files

2006-09-01 Thread flit
Hello All,

I am struggling with some ldap files.

I am using the csv module to work with this files (I exported the ldap
to a csv file).
I have this string on a field
CN=pointhairedpeoplethatsux,OU=Groups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com;CN=pointhairedboss,OU=Groups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com
this string is all the groups one user has membership.
So what I am trying to do.
read this string
and extract only the CNs

like

pointhairdepeoplethatsux,pointhairedboss

Or think in negative way
remove the OU=** and DC= **

Any ideas?

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


Tkinter listbox and ftputil

2006-09-01 Thread vedran_dekovic
Hi,
Again I need help about tkinter listbox.


example:

In listbox must write (imaginary file in server):

['-rw-r--r--   1 [EMAIL PROTECTED] vedran.byethost12.com
3506 Jun 25 14:40 file.gif']


and then when somebody click on file in listbox,then in new Entry
widget must
write just filenameexample:   'file.gif'  , not other file
informations






   THANKS!

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


Re: dictionaries - returning a key from a value

2006-09-01 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> keys = [key for key in sampledict if sampledict[key] == '1974']
>
> Or better, given:
>
> sampledict = {'the Holy Grail':1975, 'Life of Brian':1979,
>  'Party Political Broadcast':1974,'Mr. Neutron':1974,
>  'Hamlet':1974, 'Light Entertainment War':1974}
>
> keys = [key for key,year in sampledict.iteritems() if year == 1974]

better in what sense?

timeit -s "from test import sampledict" "keys = [key for key in sampledict if 
sampledict[key] == 
1974]"
10 loops, best of 3: 2.27 usec per loop

timeit -s "from test import sampledict" "keys = [key for key,year in 
sampledict.iteritems() if year 
== 1974]"
10 loops, best of 3: 2.56 usec per loop

 



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


Re: dictionaries - returning a key from a value

2006-09-01 Thread bearophileHUGS
Fredrik Lundh:
> better in what sense?

With better I may mean faster, or needing less memory, or requiring a
shorter code, or other things. It depends on many things, related to
the program I am creating.

Thank you for the timings, you are right, as most times. Sometimes I am
wrong, but I try to suggest correct things and I usually try to be
helpful, as you do too, and I am learning still.
I have done timings for other things, but not for this one :-)
I have assumed that the version using iteritems (I think that in Py3.0
items will become iteritems) is the faster in that situation (but your
test shows that I was wrong).

This seems to require one hash access, plus the iteration:
... for key in sampledict if sampledict[key] ...

This seems to require just the iteration plus the key,year tuple
creation:
... for key,year in sampledict.iteritems() if year ...

I have assumed that the hash access + an interation is slower, but
maybe the tuple object creation is slow(er) too. As usual to know
what's better in a given Python version you have to test it.

Bye,
bear hugs,
bearophile

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


Re: Question about import and namespace

2006-09-01 Thread jdemoor
Ok, thanks again. That was helpful.

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


Re: Python style: to check or not to check args and data members

2006-09-01 Thread Joel Hedlund
> I still wait for a
> proof that it leads to more robust programs - FWIW, MVHO is that it
> usually leads to more complex - hence potentially less robust - code.

MVHO? I assume you are not talking about Miami Valley Housing Opportunities 
here, but bloat probably leads to bugs, yes.

> Talking about interfaces, you may want to have a look at PyProtocols
> (PEAK) and Zope3 Interfaces.

Ooh. Neat.

> As long as you provide a usable documentation, misuse of your code is
> not your problem anymore (unless of course you're the one misusing it !-).

But hey, then I'm still just letting idiots suffer from their idiocy, and 
since that's part of our greater plan anyway I guess that's ok :-D

> Then you probably want to read the relevant chapter in DiveIntoPython.

You are completely correct. Thanks for the tip.

Thanks for your help! It's been real useful. Now I'll sleep better at night.

Cheers!
/Joel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: working with ldap files

2006-09-01 Thread Tim Chase
> I have this string on a field
> CN=pointhairedpeoplethatsux,OU=Groups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com;CN=pointhairedboss,OU=Groups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com
> this string is all the groups one user has membership.
> So what I am trying to do.
> read this string
> and extract only the CNs
> 
> like
> 
> pointhairdepeoplethatsux,pointhairedboss

 >>> s = 
"CN=pointhairedpeoplethatsux,OU=Groups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com;CN=pointhairedboss,OU=Groups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com"
 >>> pieces = sum([p.split(';') for p in s.split(',')], [])
 >>> pieces
['CN=pointhairedpeoplethatsux', 'OU=Groups', 'OU=Hatepeople', 
'OU=HR', 'DC=fabrika', 'DC=com', 'CN=pointhairedboss', 
'OU=Groups', 'OU=Hatepeople', 'OU=HR', 'DC=fabrika', 'DC=com']
 >>> pieces = sum([p.split(';') for p in s.split(',')], [])
 >>> cns = [piece[3:] for piece in pieces if piece.startswith('CN=')]
 >>> cns
['pointhairedpeoplethatsux', 'pointhairedboss']


The process basically splits on commas, then splits each of those 
pieces on semi-colons, then flattens the list-of-lists into a 
single list of all the pieces (the flattening is done by abusing 
sum() so there may be better, more elegant ways of doing that). 
Once you have the flattened list of pieces, you can then just 
check for the ones that start with "CN=" and extract the bits of 
them that you need.

-tkc




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


Re: working with ldap files (2nd answer)

2006-09-01 Thread Tim Chase
>> I have this string on a field
>> CN=pointhairedpeoplethatsux,OU=Groups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com;CN=pointhairedboss,OU=Groups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com
>> this string is all the groups one user has membership.
>> So what I am trying to do.
>> read this string
>> and extract only the CNs
>>
>> like
>>
>> pointhairdepeoplethatsux,pointhairedboss
> 
>  >>> s = 
> "CN=pointhairedpeoplethatsux,OU=Groups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com;CN=pointhairedboss,OU=Groups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com"

Or, if you're a regexp junkie...

 >>> import re
 >>> r = re.compile('CN=([^;,]*)')
 >>> r.findall(s)
['pointhairedpeoplethatsux', 'pointhairedboss']

I'll leave timing comparisons as an exercise to the reader... ;)

Both of these solutions make the assumption that neither a comma 
nor a semicolon are permissible in a CN.

-tkc



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


os.name under Win32

2006-09-01 Thread Igor Kravtchenko
Hi!

We have an application using Python that is intended to work both under 
Win32 and Linux.
Since some parts of the code need to be different depending whether we 
are under Win32
or Linux, we use the traditional:

if os.name == "posix":
  some Linux code
else:
  some Win32 code

However, we have noticed that under some circumstances, in some cases, 
in some
computers under Windows XP Family that the "posix" code was executed causing
of course a crash.

My question is whether that is supposed to be totally impossible.
Under Win32, we are indeed supposed to have os.name = "nt".  Is that value
hardcoded in Win32 binaries distribution themself?  Can it potentially 
change?

The purpose of this thread would be to have confirmed that under Win32,
os.name cannot never, ever be equal to "posix", whatever happens and so,
that we must have done some other mistakes elsewhere.

Thanks for any enlighting,

Igor.

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


Re: os.name under Win32

2006-09-01 Thread Fredrik Lundh
Igor Kravtchenko wrote:

> We have an application using Python that is intended to work both under 
> Win32 and Linux.
> Since some parts of the code need to be different depending whether we 
> are under Win32
> or Linux, we use the traditional:
> 
> if os.name == "posix":
>   some Linux code
> else:
>   some Win32 code

the usual thing to test for is sys.platform, not os.name.

if sys.platform == "win32":
some win32 code (or win64 code)
else:
some linux code

> However, we have noticed that under some circumstances, in some cases, 
> in some computers under Windows XP Family that the "posix" code was
 > executed causing of course a crash.

sounds weird.  have you checked your code so you don't assign to os.name 
somewhere, by accident?



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


Re: SQLObject or SQLAlchemy?

2006-09-01 Thread lazaridis_com
John Salerno wrote:
> Are there any major differences between these two? It seems they can
> both be used with TurboGears, and SQLAlchemy with Django. I'm just
> wondering what everyone's preference is, and why, and if there are even
> more choices for ORM.
>
> Thanks.

You can review the Persit Case, which will shortly evaluate the stated
ORM's:

http://case.lazaridis.com/wiki/Persist

It is possibly of importance to remember some requirements which should
be relevant for an persistency mechanism targetting an OO language:

Requirements

* Uses standard OO Terminology on the API side
  o free of SQL/Relational terminology for ORM Tools
* Transparency (minimal or no difference to standard objects of the
language)
  o Inheritance
* Includes Automated Schema Evolution Support
  o Development Schema Evolution (focusing on simplicity and
conveniency etc.)
  o Production Schema Evolution (focusing on integrity,
stability etc.)
* Support Standard ODBMS API's
* Support of Standards within the language-domain (e.g. Python)

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


Re: Duck typing alows true polymorfisim

2006-09-01 Thread Isaac Gouy
The Ghost In The Machine wrote:
> In comp.lang.java.advocacy, Tor Iver Wilhelmsen
> <[EMAIL PROTECTED]>
>  wrote
> on 31 Aug 2006 18:31:15 +0200
> <[EMAIL PROTECTED]>:
> > The Ghost In The Machine <[EMAIL PROTECTED]> writes:
> >
> >> Also, one language is very conspicuous by its absence: C#.
> >
> > He does not date any of the updates, so it's unclear how recently it
> > has been updated (a lot of the web is stale, like a rotting tree in a
> > forest.)
>
> Aye; my webpage has a similar problem. :-)
>
> >
> >> AmigaBasic -- Microsoft-sponsored Amiga variant
> >
> > Well, at the time Microsoft were the makers of the de-facto BASIC
> > implementations - M-BASIC for CP/M, the various variants in VC-20 and
> > C-64 and later derivates of those, and many other home computers.
> > "Sponsored" should probably be "created" instead - I assume they were
> > paid for the job.
>
> OK, "created" then. :-)
>
>
> >
> >> Also, Java now has templates. (The implementation is pretty gross
> >> and has some quirks, IMO, but it's better than nothing.) C++ has a
> >> typing system ("type_of" or some such; I'd have to look) which
> >> yields little more than the mangled type name and static inheritance
> >> testing capabilities. Of course C++ doesn't have dynamic inheritance
> >> anyway.
> >
> > There's the virtual stuff, and you could conceivably implement dynamic
> > inheritance via the bare-bones C layer - like function pointers. The
> > type information in C++ (RTTI) is optional.
>
> Oh yeah, that's true.  Still not all that dynamic, though, unless
> one recompiles.
>
> >
> >> Dynamic type creation. I don't know if Java has this or not. One can
> >> of course attempt bytecode synthesis -- I think that's what BCEL
> >> uses -- but that's a bit of a hack.
> >
> > Groovy could possibly be used for that; also IIRC Java 6 adds some
> > features for that. I seem to recall security implications being one
> > reason this ability wasn't included from the start.
>
> Not familiar with Groovy; I'll have to look into that.
> It's amazing what's out there; one of the problems with
> Free Open Source Software (FOSS) is that there's multiple
> choices for the obvious stuff. :-)
>
> >
> >> Dynamic method creation. Java does *not* have this. AIUI
> >> Smalltalk-80 does; one can take an existing class and add methods
> >> thereto.
> >
> > Yes, but that's because a Smalltalk program lives inside a big binary
> > "image" that is mutable. Woe unto you if that big binary file gets
> > corrupted.
>
> Indeed.
>
> I for one would want Smalltalk to have the ability to
> transcript certain messages but would have to look.
> (One might call that an edit audit trail.)

The comments "Woe unto you if that big binary file gets corrupted" are
plain wrong.

For at least 25 years (and perhaps back to Smalltalk-72?) Smalltalk
implementations have comprised an image file, a sources file, and a
change log. The change log records changes to objects, as Smalltalk
statements that can be replayed to reproduce those changes - and as
Smalltalk classes and methods are just objects, that means code changes
are recorded in the change log and can be reproduced even if the image
file is somehow corrupted.

By the late '80s, commercial Smalltalk development had adopted tightly
integrated, fine grained, multi-user version control - everytime a
method was compiled a new edition of the method was recorded in the
version control system, which really helps continuous integration
across the team.

>
> >
> >> Dynamic method deletion. I for one might only want this in the
> >> context of a "sandbox" but if one can create methods, one should be
> >> able to delete them as well if only because of undo.
> >
> > The problem with deleting a method is whether the runtime can handle
> > it: Smalltalk has doesNotUnderstand:#aMessage, Java has
> > NoSuchMetohdError - what does C++ do? A zeroed virtual method would
> > cause a pure virtual method call error, which I guess C++ programmers
> > are trained to take into account.
>
> I'd frankly have to look.  My thinking is that it's a message followed
> by an exit().
>
> > Also, if class A has a method and
> > you delet it in subclass B, it breaks the Liskov Substitution
> > Principle, there B should be able to function where an A is wanted.
>
> Heh...an interesting name; I'm not familiar with that
> issue.  Of course it's important for B to be an A in
> many cases, though AFAICT usually what happens is that
> A declares a method virtual with an implementation and B
> munges it.
>
> >
> >> Dynamic method rename. This could lead to much madness but this
> >> might be useful during sandboxing.
> >
> > A method's name and its "address" are distinct, but for dynamic method
> > dispatch, what about any other code that doesn't know the new name but
> > assumes the method is called the same?
>
> What indeed?  Much madness.
>
> >
> >> Dynamic inheritance. For those languages that support inheritance
> >> one might liken it to changing what the langua

Re: a new object definition

2006-09-01 Thread Steven Bethard
Sylvain Ferriol wrote:
> hello everybody,
> 
> i want to talk with you about a question i have in mind and i do not
> find a answer. it 's simple:
> why do we not have a beatiful syntax for object definition as we have
> for class definition ?
> 
> we can define a class in python in 2 ways:
>  1. by using the metaclass constructor
>my_class = MyMetaClass()
>  2. by using the classic definition syntax:
>class my_class(object):
>   __metaclass__ = MyMetaClass
> 
> if i want to instanciate an object, i only have one way to define it:
>  my_obj = my_class()
> 
> why not a better syntax like class syntax ?
> 
> example:
>>> instance my_obj:
>>>   __class__ = my_class

Michele Simionato already pointed you to `PEP 359`_.  One of the reasons 
that I withdrew it was that people seemed to feel that you could get 
most of what you want now by defining appropriate metaclasses.  In your 
case, for example, the appropriate metaclass and its usage might look like::

 >>> def instance(name, bases, dict):
 ... cls = dict.pop('__class__')
 ... dict.pop('__metaclass__')
 ... dict.pop('__module__') # silently added by class statement
 ... return cls(**dict)
 ...
 >>> class C(object):
 ... def __init__(self, a, b):
 ... self.a = a
 ... self.b = b
 ...
 >>> class c:
 ... __metaclass__ = instance
 ... __class__ = C
 ... a = 'foo'
 ... b = 'bar'
 ...
 >>> c.a, c.b
 ('foo', 'bar')

Sure, it's misleading to use a class statement when you're not actually 
creating a class, but I guess people felt that wanting to do this was 
uncommon enough that they weren't worried about it.

.. _PEP 359: http://www.python.org/dev/peps/pep-0359/

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


Problem loading true-type font with PIL

2006-09-01 Thread Christian Stapfer
After switching from Python 2.3 to 2.4 (Enought),
PIL throws an exception that did not occur formerly
(under Python 2.3) when executing

ImageFont.truetype(font, size)

where font = "C:/Windows/Fonts/comic.TTF".

Here is the traceback that results:

Traceback (most recent call last):
  File "Gen\gen.py", line 808, in ?
mylabeler = labeler.Labeler(szNavigFont, iNavigFontSize)
  File "E:\Homepage\Gen\labeler.py", line 11, in __init__
self._font = ImageFont.truetype(font, size)
  File "C:\Python24\lib\site-packages\PIL\ImageFont.py", line 202, in 
truetype
return FreeTypeFont(filename, size, index, encoding)
  File "C:\Python24\lib\site-packages\PIL\ImageFont.py", line 120, in 
__init__
import _imagingft
ImportError: No module named _imagingft

A module seems to be missing: do I have to install something
in addition to PIL in order to be able to load true-type fonts?

Could someone (more knowledgeable than myself as regards PIL
and this true-type font loading business) please point me
in the right direction?

Many thanks in advance,
Christian Stapfer

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


Re: Problem loading true-type font with PIL

2006-09-01 Thread Christian Stapfer
Christian Stapfer" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> After switching from Python 2.3 to 2.4 (Enought),
  ^
I mean: Python Enthought Edition--Python 2.4.3 for Windows,
sorry for that.

I see in the documentation for PIL that an additional
module is needed: but I don't see where I can get
it from. I'd expected that the Python Enthought Edition
--Python 2.4.3 for *Windows* would include that module

Regards,
Christian STapfer

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


Newbie question involving buffered input

2006-09-01 Thread Caolan

I am executing 
the code below on a Windows XP system and if I enter > 2 characters it 
buffers the input and the call to sys.stdin.flush does not flush the input, it 
remains buffered.
 
What am I doing wrong here?
 
Thanks,
 
Caolan
 
    
try:    
gooberselectX = sys.stdin.read(2)    
except IOError, 
e:    print 
'error reading from stdin device'    
except KeyboardInterrupt, 
e:    print 
'you cannot break. please use the \'q\' key to 
exit'    
else:    
try:    
sys.stdin.flush()    
except IOError, 
e:    
print 'error flushing buffered input'-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python style: to check or not to check args and data members

2006-09-01 Thread Bruno Desthuilliers
Joel Hedlund wrote:
>> I still wait for a
>> proof that it leads to more robust programs - FWIW, MVHO is that it
>> usually leads to more complex - hence potentially less robust - code.
> 
> MVHO? I assume you are not talking about Miami Valley Housing
> Opportunities here, 

Nope --> My Very Humble Opinion

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SQLObject or SQLAlchemy?

2006-09-01 Thread Bruno Desthuilliers
lazaridis_com wrote:
> John Salerno wrote:
>> Are there any major differences between these two? It seems they can
>> both be used with TurboGears, and SQLAlchemy with Django. I'm just
>> wondering what everyone's preference is, and why, and if there are even
>> more choices for ORM.
>>
>> Thanks.
> 
> You can review the Persit Case, which will shortly evaluate the stated
> ORM's:
> 
> http://case.lazaridis.com/wiki/Persist
> 
> It is possibly of importance to remember some requirements which should
> be relevant for an persistency mechanism targetting an OO language:

RDBMS are not "persistency mechanism", they are data management tools.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Strange import behavior

2006-09-01 Thread unexpected
Hey guys,

I'm having problems importing a file into my python app. Everytime I
try to define the object specified by this file, i.e,

test = Test(),

It raises an ImportError exception: ImportError: cannot import name
Test.

I've declared it as:

from test import Test (and I've also tried from test import *)

As luck would have it, if I try creating a newfile (say test2) and then
declare the same class as:

from test2 import Test()

It works fine! I tried doing this with the first couple of files, but
then another error crops up for another file giving me this
ImportError...so I'd end up having to re-copy a bunch of files over
again.

I feel like there may be some sort of dependency screw up or
whatever..Is there a command that's like "Python, chill, let's start
from scratch and build this thing"?

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


Re: Newbie question involving buffered input

2006-09-01 Thread Jean-Paul Calderone
On Fri, 1 Sep 2006 09:31:11 -0700, Caolan <[EMAIL PROTECTED]> wrote:
>I am executing the code below on a Windows XP system and if I enter > 2 
>characters it buffers the input and the call to sys.stdin.flush does not flush 
>the input, it remains buffered.

You cannot flush input.  The flush method only relates to output.  The
*other* side of the file has to flush *its* output in order for you to
see it as input.

On Linux, the termios module provides a way to tell the system not to do
any buffering on a file descriptor.  pywin32 may expose equivalent
functionality for Windows.

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


used to work at ungerer lab?

2006-09-01 Thread lind
I am looking for an old friend, used to work at a path lab in Pretoria,
dabbled in Scientology and rock climbing?  I know this is not
friendster.com, but I really have to get into contact with him.

Hendrik van Rooyen wrote:
> <[EMAIL PROTECTED]> Wrote:
>
>
> | Hi,
> | I need help about Tkinter listbox widget.I want,when somebody click on
> | any item(file)  in Listbox,then in new Label widget text must be
> | selected item from server.
> |
> | my program (wrong example):
> |
> | import ftputil
> | import Tkinter
> | root=Tkinter.Tk()
> | ftp=ftputil.FTPHost('some imaginary server')
> |
> | def LabelWidget(event):
> | a=Tkinter.Label(root,text=)  # Text must be only name and file
> | format,example: sun.gif
> | a.grid()
> |
> |
> |
> | b=Tkinter.Listbox(root)
> | b.insert(Tkinter.END,ftp._dir(''))
> | b.place()
> | c=Tkinter.Button(root,text='PRINT THIS FILE IN NEW LABEL WIDGET')
> | c.bind('',LabelWidget)
> | c.grid()
> | root.mainloop()
> |
> |
> | THANKS!!!
>
>
> idx = b.curselection()# - tells you which one was clicked
> StringValue = b.get(idx) # - returns the text
> 
> HTH - Hendrik

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


Re: SQLObject or SQLAlchemy?

2006-09-01 Thread lazaridis_com

Ο/Η Bruno Desthuilliers έγραψε:
> lazaridis_com wrote:
> > John Salerno wrote:
> >> Are there any major differences between these two? It seems they can
> >> both be used with TurboGears, and SQLAlchemy with Django. I'm just
> >> wondering what everyone's preference is, and why, and if there are even
> >> more choices for ORM.
> >>
> >> Thanks.
> >
> > You can review the Persit Case, which will shortly evaluate the stated
> > ORM's:
> >
> > http://case.lazaridis.com/wiki/Persist
> >
> > It is possibly of importance to remember some requirements which should
> > be relevant for an persistency mechanism targetting an OO language:
>
> RDBMS are not "persistency mechanism", they are data management tools.

possibly.

but this is not relevant, as the "Persist" case does not deal with
RDBMS.

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

Re: used to work at ungerer lab?

2006-09-01 Thread lind
Yes, and Du Buisson's and a variety of others. Liked spiders and spent
time at the WNNR?
lind wrote:
> I am looking for an old friend, used to work at a path lab in Pretoria,
> dabbled in Scientology and rock climbing?  I know this is not
> friendster.com, but I really have to get into contact with him.
>
> Hendrik van Rooyen wrote:
> > <[EMAIL PROTECTED]> Wrote:
> >
> >
> > | Hi,
> > | I need help about Tkinter listbox widget.I want,when somebody click on
> > | any item(file)  in Listbox,then in new Label widget text must be
> > | selected item from server.
> > |
> > | my program (wrong example):
> > |
> > | import ftputil
> > | import Tkinter
> > | root=Tkinter.Tk()
> > | ftp=ftputil.FTPHost('some imaginary server')
> > |
> > | def LabelWidget(event):
> > | a=Tkinter.Label(root,text=)  # Text must be only name and file
> > | format,example: sun.gif
> > | a.grid()
> > |
> > |
> > |
> > | b=Tkinter.Listbox(root)
> > | b.insert(Tkinter.END,ftp._dir(''))
> > | b.place()
> > | c=Tkinter.Button(root,text='PRINT THIS FILE IN NEW LABEL WIDGET')
> > | c.bind('',LabelWidget)
> > | c.grid()
> > | root.mainloop()
> > |
> > |
> > | THANKS!!!
> >
> >
> > idx = b.curselection()# - tells you which one was clicked
> > StringValue = b.get(idx) # - returns the text
> > 
> > HTH - Hendrik

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


Re: Strange import behavior

2006-09-01 Thread Fredrik Lundh
unexpected wrote:

> I'm having problems importing a file into my python app. Everytime I
> try to define the object specified by this file, i.e,
> 
> test = Test(),
> 
> It raises an ImportError exception: ImportError: cannot import name
> Test.
> 
> I've declared it as:
> 
> from test import Test (and I've also tried from test import *)
> 
> As luck would have it, if I try creating a newfile (say test2) and then
> declare the same class as:
> 
> from test2 import Test()
> 
> It works fine!

your code samples make very little sense, and the last one isn't even 
valid Python syntax.

maybe you could post a complete self-contained example (including the 
file names, and what's in what file), instead of typing from memory ?



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


Re: OO on python real life tutorial?

2006-09-01 Thread Claudio Grondi
filippo wrote:
> Hello,
> 
> I coded my +10k lines app using Perl/Tk. It is something like a hotel
> software manager, it has a bunch of windows to manage the arrivals,
> bills etc etc. I want to port this on Python/WxPython but I'd like to
> get benefit of python, not just doing a row by row raw porting.
> 
> My problem is that I cannot figure out how OO could be useful in my
> case. 
Be warned, that I am a bit biased here and my opinion is probably not 
mainstream, but I think OO won't be useful in your case, so there is no 
reason to learn about it.
A row by row porting will be ok, but if I were you, I would use probably 
Python/Tk for it in order to avoid programming in wxPython if not really 
necessary (wxPython has its strengths with growing project sizes, but 
yours is still far below the threshold).
Consider it that way: if you cannot figure out how OO could be useful, 
just be more self-confident and accept the enlightenment, that it 
probably or even for sure can't.

Claudio Grondi
Is there a OO tutorial out there to help me?
> 
> Thanks,
> 
> Filippo
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: raw audio in windows

2006-09-01 Thread Jay
I'm afraid I can't do that.  Don't take it personally.  I would send it
to you, but at this time, I'm developing this app with a friend and I
don't know his feelings about the program's distribution or licensing.
I can't send it around until I speak to him about it.

Sorry.


spiffy wrote:
> On 31 Aug 2006 21:34:13 -0700, "Putty" <[EMAIL PROTECTED]> wrote:
>
> >Hi.  I've written a small python script that was primarily meant for
> >use in a unix-compatible environment.  It writes a bunch of raw audio
> >to a file and then sends the file to /dev/audio and the system plays
> >the audio.  Very simple.
> >
> >Is there a simple way I could edit the script (which just uses the
> >system call to do this) to run under windows?
> >
> >This is the code that would have to change:
> >os.system("cat audioBuf > /dev/audio")
>
>
> hey, that sounds like some stuff i've been working on...
> is there any possibility that you could send me that script so I could
> take a look at it and learn?
> i'm new to python and programming in general. i'm working on some
> algorithmic composition stuff and also trying to write some synths
> here's my email...
> [EMAIL PROTECTED]

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


Re: OO on python real life tutorial?

2006-09-01 Thread filippo
thanks Fredrik and Claudio,

probably structured coding paradigm is what I need. Claudio, could you
explain better your sentence below?

Claudio Grondi ha scritto:
> Python/Tk for it in order to avoid programming in wxPython if not really
> necessary (wxPython has its strengths with growing project sizes, but
> yours is still far below the threshold).

I want to switch to wxpython because I don't like Tk too much. It is
difficult sometimes to have full control of the widgets (i.e. focus
sequence). Why do you think wxwidget is not suitable for low-medium
size projects? Could you give me some practical examples of this?

Thanks and best regards,

Filippo

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


  1   2   >