Re: waiting for file lock?

2006-04-11 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

>i need to go into a directory to grab some files and do some
>processing.
>The thing is, i need to wait till the process that generates the files
>in that directory to finish
>before i can grab the files. eg if file A is being generated and has
>not finished, my python script will not go into the directory.
>how can i check that file A has actually finished?

I wrote a similar system that watches for new files arriving in an 
"uploads" directory, whether copied there via FTP or using a GUI desktop 
script. My heuristic was to only process files whose last-modified 
date/time was at least 5 minutes in the past. My assumption was that it 
was unlikely that 5 minutes would go by between more information being 
added to a file.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I reduce the number of queries to my PostgreSQL database?

2006-04-11 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "SR" <[EMAIL PROTECTED]> wrote:

>The script works fine, if a little slow. I think that's because if I
>have 50 books in my database, my script performs 51 database queries (1
>for all book names; then 1 for each book)

If your database is that small, why bother with sophisticated 
relational-database queries at all? Why not just load everything into 
memory, and use sets and dicts and things to put it all together?

This is feasible for databases with up to thousands or even tens of 
thousands of records in them, on today's machines.
-- 
http://mail.python.org/mailman/listinfo/python-list


using regex to remove $ sign

2006-04-11 Thread Kun
i have an html/cgi input that takes in values to a mysql database, 
however, if i stick in $20 instead of 20, it crashes the program because 
of the extra $ sign.  I was wondering if anyone has a quick regular 
expression in python to remove the $-sign if it is present in the input.
-- 
http://mail.python.org/mailman/listinfo/python-list


modifying html input date for mysql, reg ex or string interpolation?

2006-04-11 Thread Kun
I have an html form that takes dates and inserts them into a mysql file. 
  Currently, users have to type in dates in the -mm-dd format.  As 
of now, this process works with the sql.  However, I would like to make 
this process easier by:

1) providing drop down menus for year, month, and date respectively.


in a failed attempt, i tried made 3 drop down lists (dateyear, 
datemonth, dateday) respectively and then used string interpolation to 
tie them together into a -mm-dd string called 'date'.  I then tried 
to use this 'date' string in my original sql query and it no longer worked.

Is this because the new 'date' value is a string instead of an int?  How 
can I go about solving this problem and making the new 'date' string 
work with my old sql query?


Attached is my code:


#!/usr/bin/env python

import cgi
print "Content-type: text/html"
print

form = cgi.FieldStorage()
print form.keys()


#gets value for each input
price = form["price"]
price = price.value
purchasetype = form["purchasetype"]
purchasetype = purchasetype.value
date = form["date"]
date = date.value
comment = form["comment"]
comment = comment.value


dateyear = form["dateyear"]
dateyear = dateyear.value
datemonth = form["datemonth"]
datemonth = datemonth.value
dateday = form["dateday"]
dateday = dateday.value


#string interpolation for date
date = "%d-%d-%d" % (dateyear, datemonth, dateday)
print ""



for x in form.keys():
print "%s=%s" % (x, form[x].value) + ""


# make connection to MySQL
import MySQLdb
import re
import urllib
import sys

try:
connection = MySQLdb.connect(host="localhost", user="", 
passwd="", db ="")

except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit (1)

#take data and put it into table that you have created.
cursor = connection.cursor()
mysqlstatement = ""
mysqlstatement = "INSERT INTO dir (date, purchasetype, price, comment) 
VALUES ('"+ date +"','"+ purchasetype +"','"+ price +"','"+ comment +"' )"
print mysqlstatement
cursor.execute (mysqlstatement)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: writing captcha image file

2006-04-11 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I get this msg:
> Traceback (most recent call last):
>   File "/usr/local/apache/cgi-bin/newuser.cgi", line 61, in ?
> cstatus = im.save(file_name,'JPEG')
>   File "/usr/local/lib/python2.4/PIL/Image.py", line 1299, in save
> fp = __builtin__.open(fp, "wb")
> IOError: [Errno 13] Permission denied:
> '/usr/local/apache/htdocs/captcha/t13uum15a2jgfj2sqg.jpg'

that means exactly what it says: the user account that your CGI script
is running under is not allowed to write to that directory.

this is a Unix/Apache configuration issue, not really a Python issue.  see
this apache FAQ entry for some additional info:

http://httpd.apache.org/docs/2.2/faq/error.html#error.permissiondenied





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


Re: Python 3.0 or Python 3000?

2006-04-11 Thread Sergei Organov
Dennis Lee Bieber <[EMAIL PROTECTED]> writes:

> On Tue, 11 Apr 2006 09:40:50 +0400, Sergei Organov <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>> 
>> Anyway, it's unfair to speak of one of the most wonderful pieces of
>> software ever written in such a tone.
>>
>   I refer to the documents I was creating as "rudimentary stuff" --
> IE, I made use of very little of the real power available to me... It
> was: Use a Macintosh (I'm talking original with the tall narrow display)
> or LaTeX on a VAX to produce transparencies for presentations...

I did misunderstood you and I'm sorry about it. Probably I just got up
too early today. Sorry once again.

-- Sergei.

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


[Off topic] Re: Backing Up VMWare

2006-04-11 Thread Franck Pommereau
> Hello - has anyone written a Python script to backup VMWare servers?
> If so, I'd appreciate any pointers as to how to go about doing so.

Nothing to do with Python, but... Under Linux, VMware disks are
mountable using the script vmware-mount.pl, see:

  http://www.vmware.com/support/reference/linux/loopback_linux.html

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


Re: using vim as a python class/module/function etc.. browser

2006-04-11 Thread Daniel Nogradi
> >>Of course, modern versions of Exuberant Ctags also support Python, too.
> >
> > I apt-installed this package but the man page is rather intimidating so
> > I thought I might as well make sure I was going in the right direction.
>
> You will probably want to read the vim documentation on how to use ctags
> from
> vim. That will tell you all you need to know without extraneous cruft.
>
> > Just need to verify that the stable version (sarge) is modern enough..
>
> It ought to be. It has supported Python for years and years.

For browsing source code I found the folding feature of vim very
useful. It collapses the body of function and class definitions into
one line so you can have a general overview of definitions in the
code. It is available from version 6 up and I recently wrote a vim
plugin specifically for folding python source code. You can find it
here: http://www.vim.org/scripts/script.php?script_id=1494

There is also an excellent vim plugin by Yegappan Lakshmanan for
working with 'tags' files using ctags. It displays all your function
and class definitions (from multiple files if you wish) in a narrow
vertical window where you can easily jump to the file containing a
chosen definition. This script is here:
http://www.vim.org/scripts/script.php?script_id=273

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


Re: Calling Web Services from Python

2006-04-11 Thread Ivan Zuzak
m.banaouas wrote:
> Can you tell us more about SOAPpy bug ?
> Is it about authentication ?
> 
> Ivan Zuzak a écrit :
> 
>> ...
>> I need a package/tool that generates web service proxies that will do 
>> all the low-level HTTP work. (Someting like the WSDL.EXE tool in .NET 
>> Framework) The ZSI and SOAPy packages [1] that i found (should) have 
>> those functionalities but either have a bug (SOAPy) or either do not 
>> work for arbitrary web services (ZSI). ...

SOAPy : http://soapy.sourceforge.net/
SOAPPy : http://pywebsvcs.sourceforge.net/

The bugged one is SOAPy (parsing errors and something else). I just
downloaded and tried SOAPPy and that one crashes too. I get an "Index
out of range" error while parsing the wsdl ( in XMLSchema.py ). The
traceback is a bit long, so I wont list the whole thing here.

Bellow this message is the wsdl of the service for which im trying to
get a proxy. If anyone manages to get a proxy out of it - please let me
know :).

Thank you for your help,
Ivan

 WSDL START 


http://www.ris.fer.hr/overlay/addressing";
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/";
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/";
xmlns:s="http://www.w3.org/2001/XMLSchema";
xmlns:s3="http://www.ris.fer.hr/OpenCollectives/CoopetitionServices/MailBox/MessageStatistics";
 

xmlns:s2="http://www.ris.fer.hr/OpenCollectives/CoopetitionServices/XmlDoc";
xmlns:s4="http://ris.zemris.fer.hr/remotingSchema";
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/";
xmlns:tns="http://www.ris.fer.hr/OpenCollectives/CoopetitionServices/MailBox"; 

xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/";
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/";
targetNamespace="http://www.ris.fer.hr/OpenCollectives/CoopetitionServices/MailBox";
 

xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";>
   
 http://www.ris.fer.hr/OpenCollectives/CoopetitionServices/MailBox";>
   http://www.ris.fer.hr/overlay/addressing"; />
   http://www.ris.fer.hr/OpenCollectives/CoopetitionServices/XmlDoc"; 

/>
   
 
   
 
 
   
 
   
   
 
   
 
   
 
   
   
   
 
   
 xmlns
   
 
   
   
 
   
 
   
 
   
   
 
   
 
   
 
   
   
 
   
 
 
   
 
   
   
 
   
 
   
 
   
   
 
   
 
 
 
   
 
   
   
 
   
 
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
 
   
 
   
 
   
 
   
 
   
 
 http://www.ris.fer.hr/overlay/addressing";>
   
   
 
   
 xmlns
   
 
 
   
   
   
   
   
   
   
 
   
   
 
   
 
   
   
 
   
 xmlns
   
 
 
   
 
   
   
 
   
 
   
   
 
   
 
   
 
   
   
   
 
   
 xmlns
   
 
   
   
   
 
   
 
 http://www.ris.fer.hr/OpenCollectives/CoopetitionServices/XmlDoc";>
   
   
 
   
 
 
   
 
 http://www.ris.fer.hr/OpenCollectives/CoopetitionServices/MailBox/MessageStatistics";>
   
   
 
   
 
   
 
 http://ris.zemris.fer.hr/remotingSchema";>
   
   
 
   
 
 
 
   
   
 
   
 
 
 
   
   
 
   
 
 
 
   
   
 
 
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
   
   
 
 
   
   
 
 
   
   
 
 
   
   
 
 
   
   
 
 
   
   
 
   
   
 http://schemas.xmlsoap.org/soap/http";
style="document" />
 
   http://www.ris.fer.hr/OpenCollectives/Coope

Re: can't pass command-line arguments

2006-04-11 Thread Duncan Booth
Lawrence D'Oliveiro wrote:

> In article <[EMAIL PROTECTED]>,
>  Duncan Booth <[EMAIL PROTECTED]> wrote:
> 
>>Windows variants such as NT/2000/XP are not based on MS-DOS in any way.
> 
> Then why are Windows system files still restricted to 8.3 names? Doesn't 
> that restriction derive from a core MS-DOS-based kernel?

Can you give an example where the filenames are restricted to 8.3 names (as 
opposed to just happening to use names which fit within 8.3)?

A lot of the files and directories in the C:\Windows folder have non 8.3 
names, and though many of them aren't part of the core system they are 
still 'system files'. Of course .Net is where the filenames become really 
gross.

There is no MSDOS kernel in any of the the systems I mentioned.

There is an MSDOS subsystem which is loaded when required to run old 
applications: NT had 5 subsytems: Win32, Posix, OS/2, MSDOS virtual 
machine, and WOW (16 bit windows emulation). XP dropped the OS/2 and Posix 
subsystems. XP 64-bit edition also drops the MS-DOS and WOW subsystems (it 
adds a WOW64 subsystem to handle 32-bit binaries).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using regex to remove $ sign

2006-04-11 Thread Fredrik Lundh
"Kun" <[EMAIL PROTECTED]> wrote:

> i have an html/cgi input that takes in values to a mysql database,
> however, if i stick in $20 instead of 20, it crashes the program
> because of the extra $ sign.  I was wondering if anyone has a quick
> regular expression in python to remove the $-sign if it is present in
> the input.

RE?  ex-perler?  try strip+lstrip instead:

>>> text = "  $12921  "
>>> text.strip().lstrip("$")
"12921"





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


Re: [Off topic] Re: Backing Up VMWare

2006-04-11 Thread Duncan Booth
Franck Pommereau wrote:

>> Hello - has anyone written a Python script to backup VMWare servers?
>> If so, I'd appreciate any pointers as to how to go about doing so.
> 
> Nothing to do with Python, but... Under Linux, VMware disks are
> mountable using the script vmware-mount.pl, see:
> 
>   http://www.vmware.com/support/reference/linux/loopback_linux.html
> 
and for windows users DiskMount (http://www.vmware.com/download/ws/) does a 
similar job (but you cannot mount a suspended machine so you would have to 
shut it down first).

I guess though you want something which runs inside the virtual machine to 
backup just the files which have changed to a networked drive on the host 
machine or a CD/DVD drive?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About classes and OOP in Python

2006-04-11 Thread Ben Sizer
fyhuang wrote:
> It seems to me that it is difficult to use OOP to a wide extent in
> Python code because these features of the language introduce many
> inadvertant bugs. For example, if the programmer typos a variable name
> in an assignment, the assignment will probably not do what the
> programmer intended.

You'll find that if you assign to a wrongly-typed variable name, then
later attempts to access the variable you wrongly believed you typed
will raise an exception. If you assign from a wrongly-typed variable,
again an exception will be raised.

I think it's important not to wrongly confuse 'OOP' with ''data hiding'
or any other aspect you may be familiar with from Java or C++. The
primary concept behind OOP is not buzzwords such as abstraction,
encapsulation, polymorphism, etc etc, but the fact that your program
consists of objects maintaining their own state, working together to
produce the required results, as opposed to the procedural method where
the program consists of functions that operate on a separate data set.

-- 
Ben Sizer

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


Re: using regex to remove $ sign

2006-04-11 Thread bearophileHUGS
Fredrik Lundh>RE?  ex-perler?  try strip+lstrip instead:<

Or even:
>>> text = "  $12921  "
>>> text.replace("$", "")
'  12921  '

Bye,
bearophile

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


Re: About classes and OOP in Python

2006-04-11 Thread Fredrik Lundh
Ben Sizer wrote:

> I think it's important not to wrongly confuse 'OOP' with ''data hiding'
> or any other aspect you may be familiar with from Java or C++. The
> primary concept behind OOP is not buzzwords such as abstraction,
> encapsulation, polymorphism, etc etc, but the fact that your program
> consists of objects maintaining their own state, working together to
> produce the required results, as opposed to the procedural method where
> the program consists of functions that operate on a separate data set.

+1 QOTW





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


Re: Python 3.0 or Python 3000?

2006-04-11 Thread per9000
I can't wait to get my hands on version PAL9000, then we will all have
to deallocate memory *the hard way*.

/per9000

---
I'm afraid. I'm afraid, Dave. Dave, my mind is going. I can feel it.
I can feel it. My mind is going. There is no question about it.
I can feel it. I can feel it. I can feel it. I'm a ... fraid.
---

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


Re: waiting for file lock?

2006-04-11 Thread Christos Georgiou
On Tue, 11 Apr 2006 19:07:19 +1200, rumours say that Lawrence D'Oliveiro
<[EMAIL PROTECTED]> might have written:

>In article <[EMAIL PROTECTED]>,
> [EMAIL PROTECTED] wrote:
>
>>i need to go into a directory to grab some files and do some
>>processing.
>>The thing is, i need to wait till the process that generates the files
>>in that directory to finish
>>before i can grab the files. eg if file A is being generated and has
>>not finished, my python script will not go into the directory.
>>how can i check that file A has actually finished?

>I wrote a similar system that watches for new files arriving in an 
>"uploads" directory, whether copied there via FTP or using a GUI desktop 
>script. My heuristic was to only process files whose last-modified 
>date/time was at least 5 minutes in the past. My assumption was that it 
>was unlikely that 5 minutes would go by between more information being 
>added to a file.

This works (unless there are long network timeouts, when downloading...),
but another idea is to wait for the existence of a zero-byte sentinel file
that is created last, after the transfer (or process, in general) has ended.

This method is the one that has worked best for me.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this object counter code pythonic

2006-04-11 Thread bruno at modulix
[EMAIL PROTECTED] wrote:
> Fredrik is then this a valid "property"  use  case and pythonic  to
> get/set a common varibale  across objects
> 
> class E(object):
> _i = 0
> def geti(self) : return E._i
> def seti(self,val) : E._i = val
> i = property(geti,seti)
> 
> if __name__ == "__main__":
> e1 = E()
> e1.i = 100
> e2 = E()
> print e2.i
> 

Why do you want/think you need to hide the fact that i is an attribute
of class E ?

Actually, I find this use of properties very misleading:

e1.i = 42
e2.i = 1138
assert e1.i == 42, "WTF ???"


While this is perfectly obvious:

E.i = 42



-- 
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: About classes and OOP in Python

2006-04-11 Thread Michele Simionato
Roy Smith wrote:

> That being said, you can indeed have private data in Python.  Just prefix
> your variable names with two underscores (i.e. __foo), and they effectively
> become private.  Yes, you can bypass this if you really want to, but then
> again, you can bypass private in C++ too.

Wrong, _foo is a *private* name (in the sense "don't touch me!"), __foo
on the contrary is a *protected* name ("touch me, touch me, don't worry
I am protected against inheritance!").
This is a common misconception, I made the error myself in the past.

   Michele Simionato

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


Re: Decorators, Identity functions and execution...

2006-04-11 Thread Christos Georgiou
On Tue, 11 Apr 2006 15:05:22 +1200, rumours say that Lawrence D'Oliveiro
<[EMAIL PROTECTED]> might have written:

>In article <[EMAIL PROTECTED]>,
> Roy Smith <[EMAIL PROTECTED]> wrote:
>
>>One of the most basic 
>>maxims on the Internet has always been, "Be liberal in what you accept, be 
>>conservative in what you produce".

>How do you explain top-posting, then?

“Be lazy and let your news/mail client choose for you.”

Unless you meant “how do you explain top-posting *acceptance* by non
top-posters.”  That is another branch of psychology.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list

dircache.listdir() or os.listdir()

2006-04-11 Thread kai
Hello,

I use dircache.listdir(myDir) in my module repeatedly. On OS WIN 2000
listdir() will re-read the directory structure! But on AIX, listdir()
will not re-read the directory structure (see Python Library
Reference).
I work with python version 2.2.

Now my 2 questions:
Why does dircache.listdir() work different?
Can I change in my modules dircache.listdir() with os.listdir() without
problems. I want to use the re-read functionality.

Thanks for your hints, Kai.

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


Re: updated pre-PEP: The create statement

2006-04-11 Thread Michele Simionato

Steven Bethard wrote:
> Azolex wrote:
> > Steven Bethard wrote:
> >> and named, nested hierarchies like XML documents could be created
> >> like::
> >>
> >> create ETobject html:
> >> "This statement would generate an ElementTree object"
> >>
> >> create ETobject head:
> >> "generate the head"
> >> ...
> >>
> >> create ETobject body:
> >> "generate the body"
> >> ...
> >
> > I think this is is a most important eventual use-case, and would like to
> > see it better worked out - or else declared outside the scope of the
> > proposed statement. As far as I can see, this does not cut it, since xml
> > and html allow /sequencial repetition/ of tags and the results of the
> > statement suites are passed as unordered namespaces/dicts.
>
> Good point.  The code above would only work if you didn't care about the
> order of elements.  I'm half inclined to pull the example, but the
> original was due to Michele Simionato, and I haven't quite convinced
> myself yet that you couldn't hack it to have ETObject append to an
> internal list somehow to keep order.  Michele?  Did you have a plan for
> how this would work?
>
> STeVe


Honestly, I don't want the 'create' statement to be used to write XML
in Python.  I think this would be a misuse of the functionality. OTOH
I believe that the main selling point for the 'create' statements is
that it make it easy to implement declarative minilanguages, so I have
given an XML example. To solve the ordering issue one should change
the internals of Python, in such a way to pass an ordered dict to the
'create' statement instead of an usual dictionary.  I think the main
use case for 'create' would be in things like
object-relational-mappers, not in XML generation. You can pull out the
example in the official PEP, if you like.  It was just matter for
thought.

   Michele Simionato

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


Re: About classes and OOP in Python

2006-04-11 Thread bruno at modulix
fyhuang wrote:
> Hello all,
> 
> I've been wondering a lot about why Python handles classes and OOP the
> way it does. From what I understand, there is no concept of class
> encapsulation in Python, i.e. no such thing as a private variable.

Seems you're confusing encapsulation with data hiding.

> Any
> part of the code is allowed access to any variable in any class,

This is also true for Java and C++ - it just a requires a little bit
more language-specific knowledge.

Python relies a lot on conventions. One of these conventions is that any
attribute whose name begins with an underscore is implementation detail
and *should* not be accessed from client code.

> and
> even non-existant variables can be accessed:

Nope. You can dynamically *add* new attributes - either to an instance
or a class - but trying to *read* a non-existant attribute will raise an
AttributeError.

> they are simply created.
> I'm wondering what the philosophy behind this is,

Dynamism.

> and if this
> behaviour is going to change in any future release of Python.

Certainly not.

> It seems to me that it is difficult to use OOP to a wide extent in
> Python code because these features of the language introduce many
> inadvertant bugs.

Don't assume, verify. My own experience is that it's *much more* easy to
do OOP with a dynamic language.

> For example, if the programmer typos a variable name
> in an assignment, the assignment will probably not do what the
> programmer intended.

That's true for any language. I never had any serious problem with this
in 5+ years - not that I'm never making typos, but it never took me more
than a pair of minutes to spot and correct this kind of errors. OTOH,
Python's dynamism let me solved in a quick and clean way problems that
would have been a royal PITA in some less agile languages.

> Ruby does something with this that I think would be excellent as an
> inclusion in Python (with some syntax changes, of course). If private
> variables require a setter/getter pair, we can shortcut that in some
> way, i.e. (pseudocode):
> 
> class PythonClass:
>private foo = "bar"
>private var = 42
>allow_readwrite( [ foo, var ] )

A first point: in Ruby (which closely follows Smalltalk's model),
there's a definitive distinction between callable and non-callable
attributes, and this last category is *always* private.

A second point is that Python also provides you getter/setter for
attributes. The default is read/write, but you can easily make any
attribute read-only (or write-only FWIW) and add any computation.

> Or allow_read to only allow read-only access. Also there might be a
> way to implement custom getters and setters for those times you want
> to modify input or something:
> 
> class PythonClass:
>def get foo():
>return "bar"
> 
>def set var( value ):
>var = value

What you want is named "property".

> Anyways, these are just some speculatory suggestions.

Don't waste time with speculations. Read the Fine Manual instead, and
actually *use* Python.

> My main question
> is that of why Python chooses to use this type of OOP model and if it
> is planned to change.

I'm not the BDFL, but my bet is that this will *not* change.

-- 
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: About classes and OOP in Python

2006-04-11 Thread bruno at modulix
Roy Smith wrote:
(snip)

> That being said, you can indeed have private data in Python.  Just prefix 
> your variable names with two underscores (i.e. __foo), and they effectively 
> become private.  

The double-leading-underscore stuff has nothing to do with "privacy".
It's meant to protect from *accidental* overriding of implementation stuff.

(snip)

> Yes, that is is a risk.  Most people deal with that risk by doing a lot of 
> testing (which you should be doing anyway).  If you really want to, you can 
> use the __slots__ technique to prevent this particular bug from happening 
> (although the purists will tell you that this is not what __slots__ was 
> designed for).

Ok, so I must be a purist !-)

-- 
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 interpreter widget for Tkinter?

2006-04-11 Thread Alexandre Guimond
thx ian. exactly what I wanted.

best,

alex.

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


Web Service SOAP - Unknown element v1

2006-04-11 Thread Jesus . Javier . Masa . Lledo

Im trying to develope a web service that comunicates python (client) with Java (server). Everything works fine until the client calls a method that takes parameters ( for example: setName("Joe") ). Any other method that takes no parameteres works perfect ( For example: getDate() ), even the ones that return stuff from the server.

This is the client code:

>>>import SOAPpy
>>>from SOAPpy import WSDL
>>>servidor = WSDL.Proxy("http://localhost.localdomain:6060/DVDOnlineStore")
>>>print servidor.getDVD()    <--- Fine
Alice in Wonderland
>>>print servidor.setDVD("Fight Club")  <--- Crashes here (This method is suppossed to print "Fight Club" in the server console)


This is the error that appears when calling that method:


Traceback (most recent call last):
  File "", line 1, in ?
  File "dvd.py", line 16, in ?
    print servidor.setDVD("Pernambuko")
  File "/usr/lib/python2.3/site-packages/SOAPpy/Client.py", line 470, in __call__
  File "/usr/lib/python2.3/site-packages/SOAPpy/Client.py", line 492, in __r_call
  File "/usr/lib/python2.3/site-packages/SOAPpy/Client.py", line 406, in __call

SOAPpy.Types.faultType: : {'idoox-java-mapping.org.idoox.xmlrpc.MessageProcessingException': : {'stack-trace': 'org.idoox.xmlrpc.MessageProcessingException: Unknown element v1\n\tat org.idoox.wasp.wsdl.SOAPMethodInfo$RequiredElements$Invocation.notNillElement(SOAPMethodInfo.java:1033)\n\tat com.systinet.wasp.server.adaptor.JavaInvoker.fillCallParamsXml(JavaInvoker.java:1162)\n\tat com.systinet.wasp.server.adaptor.JavaInvoker.beginInvoke(JavaInvoker.java:491)\n\tat com.idoox.wasp.server.adaptor.JavaAdaptorImpl.beginInvoke(JavaAdaptorImpl.java:63)\n\tat com.idoox.wasp.server.AdaptorTemplate.javaInvocation(AdaptorTemplate.java:514)\n\tat com.idoox.wasp.server.AdaptorTemplate.doDispatch(AdaptorTemplate.java:395)\n\tat com.idoox.wasp.server.Adapto!
 rTemplate.dispatch(AdaptorTemplate.java:328)\n\tat com.idoox.wasp.server.ServiceConnector.dispatch(ServiceConnector.java:390)\n\tat com.systinet.wasp.ServiceManagerImpl.dispatchRequest(ServiceManagerImpl.java:626)\n\tat com.systinet.wasp.ServiceManagerImpl.dispatch(ServiceManagerImpl.java:461)\n\tat com.systinet.wasp.ServiceManagerImpl$DispatcherConnHandler.handlePost(ServiceManagerImpl.java:2562)\n\tat com.idoox.transport.http.server.Jetty$WaspHttpHandler.handle(Jetty.java:97)\n\tat com.mortbay.HTTP.HandlerContext.handle(HandlerContext.java:1087)\n\tat com.mortbay.HTTP.HttpServer.service(HttpServer.java:675)\n\tat com.mortbay.HTTP.HttpConnection.service(HttpConnection.java:457)\n\tat com.mortbay.HTTP.HttpConnection.handle(HttpConnection.java:317)\n\tat com.mortbay.HTTP.SocketListener.handleConnection(SocketListener.java:99)\n\tat com.mortbay.Util.ThreadedServer.handle(ThreadedServer.java:254)\n\tat com.mortbay.Util.ThreadPool$PoolThreadRunnable.run(ThreadPool.java:607)\n\t!
 at java.lang.Thread.run(Thread.java:534)\n'}}>


Could anyone tell me why is this happening
If you feel like e-mailing me, please reffer to:  [EMAIL PROTECTED]

Thank you !!!-- 
http://mail.python.org/mailman/listinfo/python-list

Re: how relevant is C today?

2006-04-11 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 Thomas Bellman <[EMAIL PROTECTED]> wrote:

>Lawrence D'Oliveiro <[EMAIL PROTECTED]> writes:
>
>> "const" is in C89/C90.
>
>Although with slightly different semantics from in C++...  For
>instance:
>
>static const int n = 5;
>double a[n];
>
>is valid C++, but not valid C.

enum
  {
n = 5,
  };
double a[n];

works in C.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using regex to remove $ sign

2006-04-11 Thread John Machin

[EMAIL PROTECTED] wrote:
> Fredrik Lundh>RE?  ex-perler?  try strip+lstrip instead:<
>
> Or even:
> >>> text = "  $12921  "
> >>> text.replace("$", "")
> '  12921  '

That's fair enough with the given input, but it would silently swallow
the "$"  in "123$5678" --  this sort of approach leads to all sorts of
disasters. The next problem after you've got rid of the $ is that
you'll find commas in it. No worries, we'll just rip out any commas
too!! So what happens is this: punter is thinking twelve dollars and 34
cents but types in 12,34 either because he's European or (more likely)
because he made a typo (comma is next to period on most folks
keyboards) then some twit programmer blindly rips out the comma and hey
presto you've got twelve hundred and 34 dollars. Think it's unlikely?
Just check out the bidding bidding on a certain large well-known online
auction system :-)

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


Re: challenging (?) metaclass problem

2006-04-11 Thread alainpoint

 Hi Peter,

I don't know if you noticed but i changed my mind and removed the post
as i realised that people seemed to have much more interest in how
relevant c code still is than in solving an interesting problem.
I only speak French and Dutch and my knowledge of Belgium's third
official language (German) is only passive. Otherwise i would have
posted on the german newsgroup (the French newsgroup does not seem to
be so interesting and there are no belgian or dutch newsgroups either).
Anyway, thank you for accepting the challenge. I'll try out your code
and get back if i have any problem.

Viele dank.

Alain

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


Re: updated pre-PEP: The create statement

2006-04-11 Thread Michele Simionato
Steven Bethard wrote:
> Azolex wrote:
> > Steven Bethard wrote:
> >> and named, nested hierarchies like XML documents could be created
> >> like::
> >>
> >> create ETobject html:
> >> "This statement would generate an ElementTree object"
> >>
> >> create ETobject head:
> >> "generate the head"
> >> ...
> >>
> >> create ETobject body:
> >> "generate the body"
> >> ...
> >
> > I think this is is a most important eventual use-case, and would like to
> > see it better worked out - or else declared outside the scope of the
> > proposed statement. As far as I can see, this does not cut it, since xml
> > and html allow /sequencial repetition/ of tags and the results of the
> > statement suites are passed as unordered namespaces/dicts.
>
> Good point.  The code above would only work if you didn't care about the
> order of elements.  I'm half inclined to pull the example, but the
> original was due to Michele Simionato, and I haven't quite convinced
> myself yet that you couldn't hack it to have ETObject append to an
> internal list somehow to keep order.  Michele?  Did you have a plan for
> how this would work?
>
> STeVe

Honestly, I don't want the 'create' statement to be used to write XML
in Python.
I think this would be a misuse of the functionality. OTOH I believe
that the main selling point for the 'create' statements is that it make
it easy to implement declarative minilanguages, so I have given an XML
example. To solve the ordering issue one
should change the internals of Python, in such a way to pass an ordered
dict
to the 'create' statement instead of an usual dictionary.
I think the main use case for 'create' would be in things like
object-relational-mappers,
not in XML generation. You can pull out the example in the official
PEP, if you like.
It was just matter for thought.

   Michele Simionato

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


Re: Web Service SOAP - Unknown element v1

2006-04-11 Thread Simon Brunning
On 4/11/06, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
>
> Im trying to develope a web service that comunicates python (client) with
> Java (server). Everything works fine until the client calls a method that
> takes parameters ( for example: setName("Joe") ). Any other method that
> takes no parameteres works perfect ( For example: getDate() ), even the ones
> that return stuff from the server.

(snip Java stack trace.)

> Could anyone tell me why is this happening

Try using keyword arguments instead of positional keywords, like so:

servidor.setDVD(title="Fight Club")

I've guessed at 'title' for the keyword here, 'cos I can't see your
WSDL to find out what the real one is.

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


dircache.listdir() or os.listdir()

2006-04-11 Thread kai
Hello,

I use dircache.listdir(myDir) in my module repeatedly. On OS WIN 2000
listdir() will re-read the directory structure! But on AIX, listdir()
will not re-read the directory structure (see Python Library
Reference).
I work with python version 2.2.

Now my 2 questions:
Why does dircache.listdir() work different?
Can I change in my modules dircache.listdir() with os.listdir() without
problems. I want to use the re-read functionality.

Thanks for your hints, Kai.

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


Re: Decorators, Identity functions and execution...

2006-04-11 Thread Ben Sizer
Lawrence D'Oliveiro wrote:
> In article <[EMAIL PROTECTED]>,
>  "Carl Banks" <[EMAIL PROTECTED]> wrote:
>
> >Always use spaces when posting, and use them in your code as well.
> >Spaces are the current recommended practice, and in the future tabs
> >might become illegal.  I'd prefer tabs myself, but it's more important
> >to respect community standards than to stick to some silly preference
> >you have.
>
> Tab stops every 4 columns. What's silly about that? Any other definition
> is silly, or at best antiquated.

Every day I come across people or programs that use tab stops every 2
or 8 columns. I am another fan of tabs every 4 columns, but
unfortunately this isn't standard, so spaces in Python it is.

-- 
Ben Sizer

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


Re: updated pre-PEP: The create statement

2006-04-11 Thread Michele Simionato
Steven Bethard wrote:
> Azolex wrote:
> > Steven Bethard wrote:
> >> and named, nested hierarchies like XML documents could be created
> >> like::
> >>
> >> create ETobject html:
> >> "This statement would generate an ElementTree object"
> >>
> >> create ETobject head:
> >> "generate the head"
> >> ...
> >>
> >> create ETobject body:
> >> "generate the body"
> >> ...
> >
> > I think this is is a most important eventual use-case, and would like to
> > see it better worked out - or else declared outside the scope of the
> > proposed statement. As far as I can see, this does not cut it, since xml
> > and html allow /sequencial repetition/ of tags and the results of the
> > statement suites are passed as unordered namespaces/dicts.
>
> Good point.  The code above would only work if you didn't care about the
> order of elements.  I'm half inclined to pull the example, but the
> original was due to Michele Simionato, and I haven't quite convinced
> myself yet that you couldn't hack it to have ETObject append to an
> internal list somehow to keep order.  Michele?  Did you have a plan for
> how this would work?

Honestly, I don't want the 'create' statement to be used to write XML
in Python.  I think this would be a misuse of the functionality. OTOH
I believe that the main selling point for the 'create' statements is
that it make it easy to implement declarative minilanguages, so I have
given an XML example. To solve the ordering issue one should change
the internals of Python, in such a way to pass an ordered dict to the
'create' statement instead of an usual dictionary.  I think the main
use case for 'create' would be in things like
object-relational-mappers, not in XML generation. You can pull out the
example in the official PEP, if you like.  It was just matter for
thought.

   Michele Simionato

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


Re: challenging (?) metaclass problem

2006-04-11 Thread alainpoint

 Hi Peter,

I don't know if you noticed but i changed my mind and removed the post
as i realised that people seemed to have much more interest in how
relevant c code still is than in solving an interesting problem.
I only speak French and Dutch and my knowledge of Belgium's third
official language (German) is only passive. Otherwise i would have
posted on the german newsgroup (the French newsgroup does not seem to
be so interesting and there are no belgian or dutch newsgroups either).
Anyway, thank you for accepting the challenge. I'll try out your code
and get back if i have any problem.

Viele dank.

Alain

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


dircache.listdir() or os.listdir()

2006-04-11 Thread kai
Hello,

I use dircache.listdir(myDir) in my module repeatedly. On OS WIN 2000
listdir() will re-read the directory structure! But on AIX, listdir()
will not re-read the directory structure (see Python Library
Reference).
I work with python version 2.2.

Now my 2 questions:
Why does dircache.listdir() work different?
Can I change in my modules dircache.listdir() with os.listdir() without
problems. I want to use the re-read functionality.

Thanks for your hints, Kai.

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


dircache.listdir() or os.listdir()

2006-04-11 Thread kai
Hello,

I use dircache.listdir(myDir) in my module repeatedly. On OS WIN 2000
listdir() will re-read the directory structure! But on AIX, listdir()
will not re-read the directory structure (see Python Library
Reference).
I work with python version 2.2.

Now my 2 questions:
Why does dircache.listdir() work different?
Can I change in my modules dircache.listdir() with os.listdir() without
problems. I want to use the re-read functionality.

Thanks for your hints, Kai.

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


Re: updated pre-PEP: The create statement

2006-04-11 Thread Michele Simionato
Steven Bethard wrote:
> Azolex wrote:
> > Steven Bethard wrote:
> >> and named, nested hierarchies like XML documents could be created
> >> like::
> >>
> >> create ETobject html:
> >> "This statement would generate an ElementTree object"
> >>
> >> create ETobject head:
> >> "generate the head"
> >> ...
> >>
> >> create ETobject body:
> >> "generate the body"
> >> ...
> >
> > I think this is is a most important eventual use-case, and would like to
> > see it better worked out - or else declared outside the scope of the
> > proposed statement. As far as I can see, this does not cut it, since xml
> > and html allow /sequencial repetition/ of tags and the results of the
> > statement suites are passed as unordered namespaces/dicts.
>
> Good point.  The code above would only work if you didn't care about the
> order of elements.  I'm half inclined to pull the example, but the
> original was due to Michele Simionato, and I haven't quite convinced
> myself yet that you couldn't hack it to have ETObject append to an
> internal list somehow to keep order.  Michele?  Did you have a plan for
> how this would work?
>
> STeVe

Honestly, I don't want the 'create' statement to be used to write XML
in Python.
I think this would be a misuse of the functionality. OTOH I believe
that the main selling point for the 'create' statements is that it make
it easy to implement declarative minilanguages, so I have given an XML
example. To solve the ordering issue one
should change the internals of Python, in such a way to pass an ordered
dict
to the 'create' statement instead of an usual dictionary.
I think the main use case for 'create' would be in things like
object-relational-mappers,
not in XML generation. You can pull out the example in the official
PEP, if you like.
It was just matter for thought.

   Michele Simionato

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


Re: updated pre-PEP: The create statement

2006-04-11 Thread Michele Simionato
Steven Bethard wrote:
> Azolex wrote:
> > Steven Bethard wrote:
> >> and named, nested hierarchies like XML documents could be created
> >> like::
> >>
> >> create ETobject html:
> >> "This statement would generate an ElementTree object"
> >>
> >> create ETobject head:
> >> "generate the head"
> >> ...
> >>
> >> create ETobject body:
> >> "generate the body"
> >> ...
> >
> > I think this is is a most important eventual use-case, and would like to
> > see it better worked out - or else declared outside the scope of the
> > proposed statement. As far as I can see, this does not cut it, since xml
> > and html allow /sequencial repetition/ of tags and the results of the
> > statement suites are passed as unordered namespaces/dicts.
>
> Good point.  The code above would only work if you didn't care about the
> order of elements.  I'm half inclined to pull the example, but the
> original was due to Michele Simionato, and I haven't quite convinced
> myself yet that you couldn't hack it to have ETObject append to an
> internal list somehow to keep order.  Michele?  Did you have a plan for
> how this would work?
>
> STeVe

Honestly, I don't want the 'create' statement to be used to write XML
in Python.
I think this would be a misuse of the functionality. OTOH I believe
that the main selling point for the 'create' statements is that it make
it easy to implement declarative minilanguages, so I have given an XML
example. To solve the ordering issue one
should change the internals of Python, in such a way to pass an ordered
dict
to the 'create' statement instead of an usual dictionary.
I think the main use case for 'create' would be in things like
object-relational-mappers,
not in XML generation. You can pull out the example in the official
PEP, if you like.
It was just matter for thought.

   Michele Simionato

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


Re: ftp putting information in a variable

2006-04-11 Thread Stefan Schwarzer
Hi Arne,

On 2006-04-08 12:44, Arne wrote:
> I am looking for a way to put ftp returns in a variable.
>
> My OS is XP and I want to get the owner of a file. So I have to
>
> connect to ftp. But I am stacked with how I can receive this
> information and put it in a variable.

you can use a library to handle that. One of them is ftputil
( http://ftputil.sschwarzer.net/ ), which I know because I'm its
author. ;-) Surely, there are alternatives. You can search the
Python package index at http://www.python.org/pypi .

With ftputil, you would do

import ftputil
host = ftputil.FTPHost(hostname, user, password)
# st_uid is used by Python's os.(l)stat, but it's a string here,
# not an integer
user = host.stat(file_or_dir).st_uid
...
host.close()

This works only if the output of the FTP LIST command contains
the user information (which is often the case).

ftputil is pure Python and should work on OS X without problems.

If you think that installing/using an additional library is
overkill, you can extract the necessary parser code from the file
ftp_stat.py or write your own parser.

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


Re: writing captcha image file

2006-04-11 Thread amaltasb
I changed the owner of the file to root using chown root newuser.cgi,
but still i m not able to   write...

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


Re: dircache.listdir() or os.listdir()

2006-04-11 Thread kai
sorry, my posting was crazy

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


Re: Web Service SOAP - Unknown element v1

2006-04-11 Thread Simon Brunning
On 4/11/06, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> I've already tried that, but the problem persists... Instead of saying 
> "Unknown element v1", it says "Unknown element title" (In my case, the 
> parameter name in the server is title).
>
> Any other suggestion?

Have a look at the SOAP messages to see what is being sent back and forth?

servidor.soapproxy.config.dumpSOAPOut = True
servidor.soapproxy.config.dumpSOAPIn = True

Look at the logs on the Java side?

Have you sucessfully invoked this service from any other clients?

FWIW, I'm using SOAPpy to talk to an Axis SOAP service (also Java),
and it works fine, so if you are using keywords, I doubt the problem
is on the Python side.

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: writing captcha image file

2006-04-11 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I changed the owner of the file to root using chown root newuser.cgi,
> but still i m not able to   write...

have you tried asking in a unix or apache forum, or do you expect
pythoneers to help you with all your computer-related problems ?





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


Re: Characters contain themselves?

2006-04-11 Thread Sion Arrowsmith
Graham  Fawcett <[EMAIL PROTECTED]> wrote:
>You could always use an "is-proper-subset-of" function, which is closer
>to the intent of your algorithm. Using Jamitzky's very clever infix
>recipe [1], you can even write it as an infix operator:
>
>#Jamitzky's infix-operator class, abbreviated
>class Infix:
> [ ... ]
>
># define our is-proper-subset operator...
>ips = Infix(lambda a, b: (a is not b) and (a in b))
>
 print 'a' |ips| 'a'
>False
 print 'a' |ips| 'abc'
>True

Unfortunately:

>>> print 'abc' |ips| 'abc'
False
>>> print 'a'+'bc' |ips| 'abc'
True

Which might not be what you want. On the other hand, it's a simple
fix:

>>> ips = Infix(lambda a, b: (a != b) and (a in b))
>>> print 'a' |ips| 'abc'
True

>>> print 'a'+'bc' |ips| 'abc'
False

>[1] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Decorators, Identity functions and execution...

2006-04-11 Thread Sybren Stuvel
Ben Sizer enlightened us with:
> Every day I come across people or programs that use tab stops every
> 2 or 8 columns. I am another fan of tabs every 4 columns, but
> unfortunately this isn't standard, so spaces in Python it is.

I don't care about how people see my tabs. I use one tab for every
indent level, so no matter how you set your tab width, my code will
look consistent.

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: updated pre-PEP: The create statement

2006-04-11 Thread Peter Hansen
Michele Simionato wrote:
> Honestly, I don't want the 'create' statement to be used to write XML
> in Python.
> I think this would be a misuse of the functionality. OTOH I believe
> that the main selling point for the 'create' statements is that it make
> it easy to implement declarative minilanguages, so I have given an XML
> example. To solve the ordering issue one
> should change the internals of Python, in such a way to pass an ordered
> dict ...

That solves "the ordering issue", but not the real issue, which is that 
XML can have *multiple* elements with the same name (even though ids 
must be unique, but that's irrelevant to the point here).  Attributes on 
an element are mappings, but elements are (nested) lists of items in 
XML, not mappings.

 > You can pull out the example in the official
> PEP, if you like.

Please do.  If this is supposed to have anything to do with namespaces, 
it has nothing to do with the type of data structures XML is capable of 
and the presence of this example would only lead some people to think 
there can't be a good use case for the whole idea if that's the best we 
can come up with to demonstrate its benefits.

-Peter

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


Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-11 Thread looping
For Python developers around.

>From Python 2.5 doc:
The list of base classes in a class definition can now be empty. As an
example, this is now legal:
  class C():
  pass

nice but why this syntax return old-style class, same as "class C:",
and not the new style "class C(object):" ?
Old-style class are somewhat deprecated and could be almost always be
replaced by new-style class, so this syntax could be a nice shortcut to
create them.

Am I wrong or is there something that I've missed ?

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


Re: How to initiate HotSync of Palm device?

2006-04-11 Thread Peter Hansen
dylpkls91 wrote:
> I know how to get the program to wait for a process to finish, but I'm
> having trouble initiating a HotSync through Python. While poking around
> the Palm Desktop and HotSync system files, I found a DLL called "HSAPI"
> with the title "HotSync API", but I'm not sure if this is what I need.
> There is no HotSync COM type library in my PythonWin COM browser.

Have you inquired in a Palm forum to learn what the correct method is 
for doing this?  Surely if there's a way to do it, using that same 
approach from Python would be the simplest thing to do.  (In other 
words, unless there's a ready-made Python module that does this, and I 
suspect you've googled for that already, then this is a Palm question 
and not really a Python one...)

-Peter

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


Re: wxStyledTextCtrl - Dead?

2006-04-11 Thread Peter Hansen
David Rasmussen wrote:
> I am trying to make a programmer's editor (and later a full IDE), and I 
> want things like syntax highlighting etc. I could of course roll my own 
> fancy editing control, but if STC could solve my problem and is flexible 
> enough, then I'll use that for now :)

There are at least two (that I know of) editors written in Python and 
based on the STC.  Going from memory, PyPE is one, and the other is ... 
  um... well, it's too early in the morning to recall but I'm sure it 
wouldn't be hard to find.  Full source is available for either and while 
rolling your own anything is fun and educational, I think both of these 
are simple enough that you'd probably prefer to stand on their authors' 
shoulders, or at least learn from the code first.

-Peter

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


Re: minidom + wxPython woes

2006-04-11 Thread grahamd
Paul Boddie wrote:
> Frank Millman wrote:
> > Fredrik Lundh wrote:
> > >
> > > no, it's not a bug in the pyexpat module -- the problem is that
> > > wxPython uses it's own incompatible version of the expat library,
> > > and loads it in a way that causes problems for any library that's
> > > tries to use its own statically linked version.
>
> [...]
>
> > Firstly, it seems from various posts to the tracker item that the same
> > problem has been reported with pygtk, Qt, and VTK.
>
> There used to be issues with Expat, PyXML and mod_python which may be
> vaguely related to this, mostly because there was some usage of Expat
> within some Apache component which conflicted with PyXML's Expat
> configuration.

FYI, the incompatibility issues that arise with pyexpat in mod_python
are well documented at:

  http://www.dscpl.com.au/articles/modpython-006.html

Graham

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


Re: Sorting a list of objects by multiple attributes

2006-04-11 Thread Kent Johnson
gry@ll.mit.edu wrote:
> For multiple keys the form is quite analogous:
> 
>L.sort(key=lambda i: (i.whatever, i.someother, i.anotherkey))
> 
> I.e., just return a tuple with the keys in order from your lambda.
> Such tuples sort nicely.  

In Python 2.5 you can do this with operator.attrgetter():

   L.sort(key=operator.attrgetter('whatever', 'someother', 'anotherkey'))

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


Re: Web Service SOAP - Unknown element v1

2006-04-11 Thread Simon Brunning
On 4/11/06, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
>
> This is the result of doing: setDVD(title="BenHur")
>
> *** Outgoing SOAP **
> 
>SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
>   xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/";
>   xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance";
>   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";
>   xmlns:xsd="http://www.w3.org/1999/XMLSchema";
> >
> 
> 
> BENHUR
> 
> 
> 
> 

Clearly it isn't. Your Python snippet uses the keyword "title",
whereas the outgoing SOAP message uses "titulo". What does the WSDL
say it needs?

Have you looked at the Java side, as I suggested?

BTW, please reply to the list rather than to me personally. Thanks.

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxStyledTextCtrl - Dead?

2006-04-11 Thread Franz Steinhaeusler
On Tue, 11 Apr 2006 06:58:28 -0400, Peter Hansen <[EMAIL PROTECTED]>
wrote:

>David Rasmussen wrote:
>> I am trying to make a programmer's editor (and later a full IDE), and I 
>> want things like syntax highlighting etc. I could of course roll my own 
>> fancy editing control, but if STC could solve my problem and is flexible 
>> enough, then I'll use that for now :)
>
>There are at least two (that I know of) editors written in Python and 
>based on the STC.  Going from memory, PyPE is one, and the other is ... 
>  um... well, it's too early in the morning to recall but I'm sure it 
>wouldn't be hard to find. 

No, it's not hard. :)
for example: Boa Constructor, DrPython, spe and newedit.


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


Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-11 Thread Georg Brandl
looping wrote:
> For Python developers around.
> 
>>From Python 2.5 doc:
> The list of base classes in a class definition can now be empty. As an
> example, this is now legal:
>   class C():
>   pass
> 
> nice but why this syntax return old-style class, same as "class C:",
> and not the new style "class C(object):" ?
> Old-style class are somewhat deprecated and could be almost always be
> replaced by new-style class, so this syntax could be a nice shortcut to
> create them.
> 
> Am I wrong or is there something that I've missed ?

class C():

is meant to be synonymous with

class C:

and therefore cannot create a new-style class.

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


RIIA in Python 2.5 alpha: "with... as"

2006-04-11 Thread Alexander Myodov
Hello,

Having heard that Python 2.5 offers some kind of RIIA concept via
PEP343, got it downloaded (Windows version) and tried. But it did not
work as expected and as wanted.
For the time since I first learned Python, the only reason why I just
could not use it was inability to localize the lifetime of some
variables inside some syntactical "blocks", especially ones in
"for"/"while"/"if" statements, but possibly in any "manually
generated" block (say, like if I would create a "{}" block in C/C++
just to separate one part of the function from another). I mean the
cases like
  for k in a1:
pass
  print "k: %s" % k
where "k" lives long after the actual need in it was lost, and even
list comprehensions:
  b1 = [l for l in a1]
  print "l: %s" % l
.

So, with 2.5, I tried to utilize "with...as" construct for this, but
unsuccessfully:
   from __future__ import with_statement
   with 5 as k:
 pass
   print k
- told me that "AttributeError: 'int' object has no attribute
'__context__'".


So, does this mean that we still don't have any kind of RIIA in
Python, any capability to localize the lifetime of variables on a
level less than a function, and this is indeed not gonna happen to
change yet?


-- 
With best regards,
 Alexander  mailto:[EMAIL PROTECTED]


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


Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-11 Thread Peter Hansen
Georg Brandl wrote:
> class C():
> 
> is meant to be synonymous with
> 
> class C:
> 
> and therefore cannot create a new-style class.

I think "looping" understands that, but is basically asking why anyone 
is bothering with a change that involves a part of the language that is 
effectively deprecated.  In other words, class(): never used to be 
valid, so why make it valid now?

-Peter

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


Re: Best Python web-hosting?

2006-04-11 Thread Simon Brunning
On 9 Apr 2006 11:31:38 -0700, Steve <[EMAIL PROTECTED]> wrote:
> http://www.python-hosting.com/
>
> I haven't used them myself, but recent research that I did made them
> look like good candidates.

Python-Hosting.com is run by Remi Delon, author of CherryPy, so you'll
be getting your support (should you need any) from someone who knows
Python, and knows what he's talking about.

And the control panel has to be seen to be believed. Setting up new
Django, TurboGears or Zope applications is a point and click
operation, taking seconds.

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compleated Begginers Guide. Now What?

2006-04-11 Thread Steve Holden
James Stroud wrote:
> Mirco Wahab wrote:
> 
>>Jay wrote:
>>Malchick, you cracked your veshchs to classes, which is
>>not that gloopy. So rabbit on them and add class methods
>>that sloosh on beeing called and do the proper veshchs
>>to the gulliwuts of their classes.
> 
> 
> Brillig!
> 
> 
But neither helpful nor sympathetic.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com

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


Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-11 Thread Georg Brandl
Peter Hansen wrote:
> Georg Brandl wrote:
>> class C():
>> 
>> is meant to be synonymous with
>> 
>> class C:
>> 
>> and therefore cannot create a new-style class.
> 
> I think "looping" understands that, but is basically asking why anyone 
> is bothering with a change that involves a part of the language that is 
> effectively deprecated.  In other words, class(): never used to be 
> valid, so why make it valid now?

I don't recall that, you'll have to search the python-dev archives.

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


Re: RIIA in Python 2.5 alpha: "with... as"

2006-04-11 Thread Duncan Booth
Alexander Myodov wrote:

> So, with 2.5, I tried to utilize "with...as" construct for this, but
> unsuccessfully:
>from __future__ import with_statement
>with 5 as k:
>  pass
>print k
> - told me that "AttributeError: 'int' object has no attribute
> '__context__'".
> 
> 
> So, does this mean that we still don't have any kind of RIIA in
> Python, any capability to localize the lifetime of variables on a
> level less than a function, and this is indeed not gonna happen to
> change yet?
> 

No, it means that Python 2.5 supports 'resource initialisation is 
acquisition', but that has nothing to do with the restricting the lifetime 
of a variable. You have to use a context manager to handle the resource, 5 
isn't a context manager. Some objects which actually need handling as a 
resource can be used as context managers, for others you might need to 
write your own.

with open('/etc/passwd', 'r') as f:
for line in f:
print line

after executing this f has been closed, but the variable f still exists.

Or try this:

>>> @contextlib.contextmanager
... def silly(n):
...print "starting to use", n
...yield n
...print "finished with", n
...
>>> with silly(5) as k:
...print "hello"
...
starting to use 5
hello
finished with 5
>>> k
5

The resource is controlled by the with statement, but the scope of the 
variable and the lifetime of the object are separate issues.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: updated pre-PEP: The create statement

2006-04-11 Thread Michele Simionato
Peter Hansen wrote:
> Michele Simionato wrote:
>  > You can pull out the example in the official
> > PEP, if you like.
>
> Please do.  If this is supposed to have anything to do with namespaces,
> it has nothing to do with the type of data structures XML is capable of
> and the presence of this example would only lead some people to think
> there can't be a good use case for the whole idea if that's the best we
> can come up with to demonstrate its benefits.

Sorry for the multiple posting (Google failed me) and yes, let's remove
the XML example.

   Michele Simionato

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


Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-11 Thread looping
Peter Hansen wrote:
> Georg Brandl wrote:
> > class C():
> >
> > is meant to be synonymous with
> >
> > class C:
> >
> > and therefore cannot create a new-style class.
>
> I think "looping" understands that, but is basically asking why anyone
> is bothering with a change that involves a part of the language that is
> effectively deprecated.  In other words, class(): never used to be
> valid, so why make it valid now?
>
> -Peter

Exact.
But I think that if we make "class C():" a synonym of "class
C(object):", it will save lot of keystrokes ;-)
So I think the idea is great but the result is not actually very
usefull.

Delphi (Pascal?) use almost the same concept:
TTest = class

is a synonym of

TTest = class(TObject)

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


Re: using regex to remove $ sign

2006-04-11 Thread Tim Chase
> i have an html/cgi input that takes in values to a mysql
> database, however, if i stick in $20 instead of 20, it
> crashes the program because of the extra $ sign.  I was
> wondering if anyone has a quick regular expression in
> python to remove the $-sign if it is present in the
> input.

While the others have provided non-regexp solutions, I 
suspect there's a deeper underlying problem here if a simple 
dollar-sign is causing the program to die.

If you find where this death happens, there's usually an 
associated escape() function that will handle all the 
troublesome characters.  My suspicion is that you're trying 
to stick this string value into a numeric field in your 
database.  Thus, you want to strip out *anything* that will 
cause a mysql assignment-to-a-numeric-field to barf.

If you really must do it with a regexp:

Just strip a dollar-sign:

result = re.sub(r'\$','',input_value)

If you want to strip any non-numerics:

result = re.sub(r'[^0-9]', '', input_value)

If you want decimal points too:

result = re.sub(r'[^0-9.]', '', input_value)

As someone else mentioned, you might want to take other 
currency conventions (namely, using commas rather than 
periods) into consideration.  Thus, I'd do it in a two-step

result = re.sub(r'[^0-9.]', '',
input_value.replace(",", "."))

This normalizes all commas to periods and then strips out 
anything that isn't a digit or a period.  This will still 
give your program grief if someone puts in something like 
"$192.168.3.14".

Thus, you might want to just pull out the dollars and 
optional cents, and use them:

r = re.compile(r'.*?(\d+)([.,]\d\d)?.*')
m = r.match(input_value)
if m:
dollars = m.group(1)
cents = m.group(2)
if not cents:
cents = cents[1:]
else:
cents = "00"
else:
raise BogusValueFromDoofusError

new_input_value = "%s.%s" % (dollars, cents)

With the above bogus IP-address/currency value, this would 
produce a valid result of "192.16" which may or may not be 
what you want.  Caveat regextor.

Feel free to monkey with the regexp to adjust for your wants.

-tim





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


Help - strange behaviour from python list

2006-04-11 Thread Sean Hammond

I've managed to create a scenario in which editing an object in a list of 
objects seems to edit every object in the list, rather than just the one. 
I'm totally stumped and wondered if anyone would be kind enough to read my 
explanation and see if they have any suggestions. I have probably stumbled 
into some typical newbie problem, but anyway:

I have two classes, Area and Agent:

class Agent:
def __init__(self,name):
self.name = name

class Area:
def __init__(self, occupants = []):
self.occupants = occupants

Now, I want to create a 'virtual environment' as a 2D list of Area 
objects, so:

environment = []
for x in range(0,10):
environment.append([])
for y in range(0,10):
new_area = Area()
environment[-1].append(new_area)

This works fine, environment is now a 10*10 2D list of Area objects, and 
the occupants member of each Area object is [].

Now, I want to add an occupants, in the form of an Agent object, to an 
area in the environment:

new_agent = Agent("Bob")
environment[4][5].occupants.append(new_agent)

This is where it goes wrong, it looks as if new_agent gets appended to the 
occupants list of EVERY Area object in environment. For example, the 
following code:

for areas_list in environment:
for area in areas_list:
print len(area.occupants)

Will print out `1` 100 times over.

I must be making some really stupid mistake, but this just doesn't look 
like the list behaviour I would expect. What's going on here?


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


Re: how relevant is C today?

2006-04-11 Thread bruno at modulix
Lawrence D'Oliveiro wrote:
> In article <[EMAIL PROTECTED]>,
>  bruno at modulix <[EMAIL PROTECTED]> wrote:
> 
> 
>>gregarican wrote:
>>
>>>Here are a few languages I recommend most programmers should at least
>>>have a peek at:
>>>
>>
>>(snip)
>>
>>>2) Lisp - Along with FORTRAN, one of the oldest programming languages
>>>still in use. Pure functional programming model 
>>
>>Err... Even if Lisp is the father of functional programming, it is
>>definitively not a 'pure' FPL.
> 
> 
> It _can_ be used as a pure functional language. An interpreter for a 
> pure-functional subset of LISP can be written

And ?

-- 
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: newbie: Need Help Moving Data from Kirbybase to Gadfly

2006-04-11 Thread dc
The addresslist table was defined and did exist, I had connection
defined incorrectly.

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


Re: Help - strange behaviour from python list

2006-04-11 Thread Schüle Daniel
Sean Hammond schrieb:
> 
> I've managed to create a scenario in which editing an object in a list 
> of objects seems to edit every object in the list, rather than just the 
> one. I'm totally stumped and wondered if anyone would be kind enough to 
> read my explanation and see if they have any suggestions. I have 
> probably stumbled into some typical newbie problem, but anyway:
> 

just a hint

 >>> def foo(val,lst=[]):
... lst.append(val)
... print lst
...
 >>>
 >>>
 >>> foo(1)
[1]
 >>> foo(2)
[1, 2]
 >>> foo(3)
[1, 2, 3]
 >>> foo(4,[0])
[0, 4]
 >>>

here list lst is created and bound once


compare with this one (which is what you really want)

 >>> def bar(val, lst=None):
... if lst is None:
... lst = []
... lst.append(val)
... print lst
...
 >>> bar(1)
[1]
 >>> bar(2)
[2]
 >>> bar(3, [0])
[0, 3]
 >>>

hth, Daniel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help - strange behaviour from python list

2006-04-11 Thread Duncan Booth
Sean Hammond wrote:

> class Area:
>   def __init__(self, occupants = []):
>self.occupants = occupants
> 
...
> I must be making some really stupid mistake, but this just doesn't
> look like the list behaviour I would expect. What's going on here?

Whenever you use the default value for occupants in the constructor you 
reuse the same list. Don't use mutable objects as default values:

def __init__(self, occupants=None):
if occupants is None:
   self.occupants = []
else:
   self.occupants = occupants
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help - strange behaviour from python list

2006-04-11 Thread Fredrik Lundh
Sean Hammond wrote:

> I've managed to create a scenario in which editing an object in a list of
> objects seems to edit every object in the list, rather than just the one.
> I'm totally stumped and wondered if anyone would be kind enough to read my
> explanation and see if they have any suggestions. I have probably stumbled
> into some typical newbie problem, but anyway:

some useful resources:

http://docs.python.org/tut/node6.html#SECTION00671
(see the paragraph that starts with "important warning")


http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects

http://docs.python.org/ref/function.html
(see the paragraph that starts with "Default parameters are evaluated when 
the
function definition is executed")

(you cannot say we didn't warn you ;-)

 



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


Re: writing captcha image file

2006-04-11 Thread Fredrik Lundh
>> I changed the owner of the file to root using chown root newuser.cgi,
>> but still i m not able to   write...
>
> have you tried asking in a unix or apache forum, or do you expect
> pythoneers to help you with all your computer-related problems ?

(are you sure your apache install runs CGI processes as root, btw?  sounds
dangerous...)

 



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


Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-11 Thread Peter Hansen
looping wrote:
> But I think that if we make "class C():" a synonym of "class
> C(object):", it will save lot of keystrokes ;-)

Saving keystrokes has only rarely influenced Python's design, 
thankfully.  If you read "import this", you'll see "explicit is better 
than implicit", and interpreting in this case one would have to say that 
  so long as both old and new-style classes exist, making "class():" 
equivalent to "class(object):" would be doing something very implicit, 
and potentially very confusing.  Leaving things just as they are would 
be a better choice.

-Peter

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


Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-11 Thread bruno at modulix
looping wrote:
> Peter Hansen wrote:
> 
>>Georg Brandl wrote:
>>
>>>class C():
>>>
>>>is meant to be synonymous with
>>>
>>>class C:
>>>
>>>and therefore cannot create a new-style class.
>>
>>I think "looping" understands that, but is basically asking why anyone
>>is bothering with a change that involves a part of the language that is
>>effectively deprecated.  In other words, class(): never used to be
>>valid, so why make it valid now?
>>
>>-Peter
> 
> 
> Exact.
> But I think that if we make "class C():" a synonym of "class
> C(object):", it will save lot of keystrokes ;-)

Since the class statement without superclass actually creates an
old-style class,  I'd expect the "class MyClass():" variant to behave
the same. Sacrifying readability and expliciteness just to save half a
dozen keystrokes is not pythonic IMHO.


-- 
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[2]: RIIA in Python 2.5 alpha: "with... as"

2006-04-11 Thread Alexander Myodov
Hello Duncan,

You wrote:
> Alexander Myodov wrote:
>> So, with 2.5, I tried to utilize "with...as" construct for this, but
>> unsuccessfully:
>> ...
>> So, does this mean that we still don't have any kind of RIIA in
>> Python, any capability to localize the lifetime of variables on a
>> level less than a function, and this is indeed not gonna happen to
>> change yet?

> No, it means that Python 2.5 supports 'resource initialisation is
> acquisition', but that has nothing to do with the restricting the lifetime
> of a variable.
Sorry, I misworded the question - RIIA is indeed present at least by
the reason that the examples from PEP pass. Agree, my problem is a bit
different, and I a bit mixed up initialization/acquisition with
lifetime blocks. So, seems that we indeed have one and still don't
have another.
Or maybe you have an idea how this can be fixed? The
simplest way I see is putting all the "controlled" variables into a
dedicated class... and do that each time for each block of variables I
need control lifetime. Is there any simpler way?

-- 
With best regards,
 Alexander  mailto:[EMAIL PROTECTED]


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


MySQLdb module generating errors

2006-04-11 Thread amaltasb
I installed MySQLdb module on bsd and when I import I get the following
error...

Traceback (most recent call last):
  File "", line 1, in ?
  File "MySQLdb/__init__.py", line 27, in ?
import _mysql
ImportError: /usr/local/lib/liblthread.so.2: Undefined symbol
"_sched_yield"

Is any module missing ??

Thanks

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


Refresh loop

2006-04-11 Thread Aleksandar Cikota
Hello,

I'm beginner in python. I want to refresh and print Scope.SiderealTime every 
second in Tkiner. I have a easy question. How to refresh this loop every 
second?

Here the code:

from Tkinter import *
import win32com.client
Scope = win32com.client.dynamic.Dispatch('ScopeSim.Telescope')
root=Tk()

Label(root, text=Scope.SiderealTime).grid(row=0, sticky=W)

root.mainloop()


Thank You!

Regards,
Aleksandar



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


Re: Re[2]: RIIA in Python 2.5 alpha: "with... as"

2006-04-11 Thread Diez B. Roggisch
>> No, it means that Python 2.5 supports 'resource initialisation is
>> acquisition', but that has nothing to do with the restricting the
>> lifetime of a variable.
> Sorry, I misworded the question - RIIA is indeed present at least by
> the reason that the examples from PEP pass. Agree, my problem is a bit
> different, and I a bit mixed up initialization/acquisition with
> lifetime blocks. So, seems that we indeed have one and still don't
> have another.
> Or maybe you have an idea how this can be fixed? The
> simplest way I see is putting all the "controlled" variables into a
> dedicated class... and do that each time for each block of variables I
> need control lifetime. Is there any simpler way?

Wouldn't a small surrounding function suffice? Something like this
(untested):


def whatever():
  def anon():
 with open('/etc/passwd', 'r') as f:
 for line in f:
 print line

Sure, not the nicest of all solutions. But if you really fear that f is
reused, it might help.

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


Re: Help - strange behaviour from python list

2006-04-11 Thread Sean Hammond

Right, thanks everyone, that's a useful lesson learned. As I suspected I 
was being tripped over by some feature of Python I was unaware of. I had 
been looking up lists in the documentation, not functions, and could find 
no explanation.

Prbolem solved!

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


Re: Characters contain themselves?

2006-04-11 Thread Graham Fawcett
Sion Arrowsmith wrote:
> Unfortunately:
> >>> print 'a'+'bc' |ips| 'abc'
> True
>
> Which might not be what you want. On the other hand, it's a simple
> fix:
> >>> ips = Infix(lambda a, b: (a != b) and (a in b))
> >>> print 'a'+'bc' |ips| 'abc'

Ah, good point.

Graham

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


Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-11 Thread bearophileHUGS
bruno at modulix>Since the class statement without superclass actually
creates an old-style class, I'd expect the "class MyClass():" variant
to behave the same.<

In Python 3.0 I really hope the

class C: pass
class C(): pass
class C(object): pass

will mean the same thing. (So in Python 2.5 the second version can be
made to mean the same thing of the third).

Bye,
bearophile

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


Re: RIIA in Python 2.5 alpha: "with... as"

2006-04-11 Thread Martin v. Löwis
Alexander Myodov wrote:
> Sorry, I misworded the question - RIIA is indeed present at least by
> the reason that the examples from PEP pass. Agree, my problem is a bit
> different, and I a bit mixed up initialization/acquisition with
> lifetime blocks. So, seems that we indeed have one and still don't
> have another.
> Or maybe you have an idea how this can be fixed? 

Why do you want to restrict the lifetime of a variable?

If you want the variable to become unassigned, just invoke the del
statement.

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


Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-11 Thread looping
bruno at modulix wrote:
> looping wrote:
> > Peter Hansen wrote:
> >
> >>Georg Brandl wrote:
> >>
> >>>class C():
> >>>
> >>>is meant to be synonymous with
> >>>
> >>>class C:
> >>>
> >>>and therefore cannot create a new-style class.
> >>
> >>I think "looping" understands that, but is basically asking why anyone
> >>is bothering with a change that involves a part of the language that is
> >>effectively deprecated.  In other words, class(): never used to be
> >>valid, so why make it valid now?
> >>
> >>-Peter
> >
> >
> > Exact.
> > But I think that if we make "class C():" a synonym of "class
> > C(object):", it will save lot of keystrokes ;-)
>
> Since the class statement without superclass actually creates an
> old-style class,  I'd expect the "class MyClass():" variant to behave
> the same. Sacrifying readability and expliciteness just to save half a
> dozen keystrokes is not pythonic IMHO.
>

I don't think readability suffer and expliciteness could sometimes be
sacrified to simplify the life of developer: ex "abcd"[0:3]  ->
"abcd"[:3].
And for newbies, the somewhat magic behavior of the "object" superclass
is not so clear even that it is very explicit.
When I write script I don't use new-style class cause is bother me to
type "(object)" when I don't need their features. But in an other hand,
I believe that new-style class are faster to instanciate (maybe I'm
wrong...).
So this new syntax is a good way to boost their uses without bother
with compatibility of existing code IMHO.

Well I stop to argue now and let Python Dev make their (very good) job.

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


Re: Saving files from post data via sys.stdin

2006-04-11 Thread ACB

"ACB" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I am rewriting an existing PERL script I wrote several months ago.  It is a 
>script that is used as the action for a form containing several type="file" 
>inputs.  The script is run unbuffered and writes the data from sys.stdin to 
>a file which is stat'ed by another script called asyncornously from 
>javascript.  In the end I am able to make a progress bar for file uploads 
>via http.
>
> Anyway, I have printed sys.stdin to a file and looked at it afterward. 
> This is what is looks like
> -126591649570
> Content-Disposition: form-data; name="userid"
>
> myUserid
> -126591649570
> Content-Disposition: form-data; name="ulimage"; filename="bc12.jpg"
> Content-Type: image/jpeg
>
> binary data of jpeg
> -126591649570
> Content-Disposition: form-data; name="ulimage"; filename=""
> Content-Type: image/jpeg
>
> -126591649570
> Content-Disposition: form-data; name="ulimage"; filename=""
> Content-Type: image/jpeg
>
>
> -126591649570
> Content-Disposition: form-data; name="sessionid"
>
> mySessionid
>
> Normally, I use cgi.FieldStorage() and access the values via calls like
> form = cgi.FieldStorage()
> sessionid = form["sessionid"].value
>
> What is the best method for accessing the various variables and their 
> respective values so I can save the files one at a time?  Is there some 
> class that can take this input and make it easier to deal with?  I need to 
> save each of the ulimage values as individual images and gain access to 
> the values of sessionid and userid.
>
> Thanks
> Amy
>
>

Any further help is appreciated.   : )


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


Re: waiting for file lock?

2006-04-11 Thread Larry Bates
[EMAIL PROTECTED] wrote:
> hi
> i need to go into a directory to grab some files and do some
> processing.
> The thing is, i need to wait till the process that generates the files
> in that directory to finish
> before i can grab the files. eg if file A is being generated and has
> not finished, my python script will not go into the directory.
> how can i check that file A has actually finished?  thanks
> 
I don't know if you have control of the program that is writing the
file.  If you do, change it so that it writes the files with some
temporary name and renames them when it is done.  Since rename is
basically atomic, the file won't show up as a candidate to be
processed until it is actually completed.

Something like:

Process A -> writes files into directory with .tmp extensions.
Process B -> scans directory but never processes anything with
 .tmp extensions
Process A -> renames file.tmp to file when it is finished so
 that process B picks it up on its next scan.


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


Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-11 Thread Georg Brandl
looping wrote:
> Peter Hansen wrote:
>> Georg Brandl wrote:
>> > class C():
>> >
>> > is meant to be synonymous with
>> >
>> > class C:
>> >
>> > and therefore cannot create a new-style class.
>>
>> I think "looping" understands that, but is basically asking why anyone
>> is bothering with a change that involves a part of the language that is
>> effectively deprecated.  In other words, class(): never used to be
>> valid, so why make it valid now?
>>
>> -Peter
> 
> Exact.
> But I think that if we make "class C():" a synonym of "class
> C(object):", it will save lot of keystrokes ;-)

If you have many classes in a module, putting

__metaclass__ = type

at the top can save you these keystrokes.

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


Re: Best Python web-hosting?

2006-04-11 Thread walterbyrd
I emailed them, they say they have mod_python.

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


Re: Best Python web-hosting?

2006-04-11 Thread walterbyrd
I emailed them, they say they have mod_python.

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


Re: Re[2]: RIIA in Python 2.5 alpha: "with... as"

2006-04-11 Thread Duncan Booth
Alexander Myodov wrote:

> Or maybe you have an idea how this can be fixed? The
> simplest way I see is putting all the "controlled" variables into a
> dedicated class... and do that each time for each block of variables I
> need control lifetime. Is there any simpler way?

I wouldn't use the word "fixed", but I suppose if you must you could do 
something like:

>>> import contextlib
>>> @contextlib.contextmanager
def controlled(**kw):
class Bunch: pass
obj = Bunch()
obj.__dict__.update(kw)
yield obj
obj.__dict__ = {}


>>> with controlled(a=5, b=[1, 2, 3]) as k:
print k.a, k.b, dir(k)


5 [1, 2, 3] ['__doc__', '__module__', 'a', 'b']
>>> print dir(k)
['__doc__', '__module__']

So the lifetime of the variable is still not limited, but the lifetime of 
its attributes is. I still don't see what that buys you though.
-- 
http://mail.python.org/mailman/listinfo/python-list


setting up mod_python handlers on a server?

2006-04-11 Thread John Salerno
I get this internal error message when I try to access a PSP page:

"Invalid command 'PythonHandler', perhaps mis-spelled or defined by a 
module not included in the server configuration"

So it seems that mod_python is not fully configured yet to handled PSP 
pages. When I check the installed Apache handlers, there is an entry 
called "mod_python .psp" where the first term is the handler and the 
second is the extension. I also tried adding "PythonHandler" as it 
appears in the htaccess file, but nothing is working. Sometimes the HTML 
is displayed, and other times I get a 500 Internal Server Error page.

I had assumed when a server has mod_python installed, you can start 
using PSP functionality automatically, but I guess there's more work to 
do to set it up. Can anyone tell me what else I might need to do? Add 
another handler, perhaps?

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


Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-11 Thread Felipe Almeida Lessa
Em Ter, 2006-04-11 às 06:49 -0700, looping escreveu:
> But in an other hand,
> I believe that new-style class are faster to instanciate (maybe I'm
> wrong...).

$ python2.4 -m timeit -s 'class x: pass' 'x()'
100 loops, best of 3: 0.435 usec per loop
$ python2.4 -m timeit -s 'class x(object): pass' 'x()'
100 loops, best of 3: 0.316 usec per loop

-- 
Felipe.

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

Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-11 Thread Aahz
In article <[EMAIL PROTECTED]>,
 <[EMAIL PROTECTED]> wrote:
>
>In Python 3.0 I really hope the
>
>class C: pass
>class C(): pass
>class C(object): pass
>
>will mean the same thing. 

The BDFL made that one of the very first Pronouncements of 3.0.  ;-)

>(So in Python 2.5 the second version can be made to mean the same thing
>of the third).

Can, yes.  But should it?  The whole point of adding the () option to
classes was to ease the learning process for newbies who don't
understand why classes have a different syntax from functions.  Having

class C(): pass

behave differently from

class C: pass

would be of no benefit for that purpose.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"LL YR VWL R BLNG T S"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unboundlocalerror with cgi module

2006-04-11 Thread bruno at modulix
David Bear wrote:
> I'm attempting to use the cgi module with code like this:
> 
> import cgi
> fo = cgi.FieldStorage()
> # form field names are in the form if 'name:part'
> keys = fo.keys()
> for i in keys:
> try:
> item,value=i.split(':')
> except NameError, UnboundLocalError:
> print "exception..."
> item,value=(None,None)
> return(item,value)
> 
> However, the except block does not seem to catch the exception

Which one ?-)

> and an
> unboundlocalerror is thrown anyway. What am I missing?

Err...

1/ the correct try/except syntax is:
try:
  whatever_that_may_raise()
except (ExceptionClass1, ExceptionClassN):
  handle_the_exception()

What you code would actually do (if it raised a NameError, which will
not be the case, cf next point) is to *bind* the exception object to the
name 'UnboundLocalError'.

2/ the line:
  item,value=i.split(':')
*won't* raise NameError nor UnboundLocalError


3/ if fo.keys() returns a non-empty list, your code (that I assume is
the body of a function) will return the result of the split() for the
*last* item in the list (after having uselessly split'ed each and every
key...)

4/ else (ie : fo.keys() returns an empty list), *then* you'll get an
UnboundLocalError (once again, assuming this code is the body of a
function - but else you'd get a SyntaxError, since the return statement
is not allowed outside a function body), *but* this exception will be
raised when the 'return' statement is executed - not in the loop.


A corrected version of your code could be:

def extract_last_key(field_storage):
  # form field names are in the form if 'name:part'
  keys = field_storage.keys()
  if keys:
return keys[-1].split(':', 1)
  else:
return (None, None)

import cgi
fo = cgi.FieldStorage()
name, part = extract_last_key(fo)

I doubt this is actually what you *really* want, but this is at least
what your code effectively try to do.

FWIW, trying things at random until it seems to work is the worst way to
program (some call this 'programming by accident').


-- 
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: how relevant is C today?

2006-04-11 Thread gregarican
bruno wrote:

> Err...

> And ?

It's the snide, curt replies such as your recent ones in this thread
that reinforce the generalization that the Python community can be
rude.

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


the mysql for python cann't be install from the source! Help!!

2006-04-11 Thread boyeestudio
I install the mysqldb module for python,I use:
python setup.py build
 
but it tell me "cann't find include file my_conf.h'
I search the mysql directory but gain none of it!
Please help me with it!
Thanks a lot!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-11 Thread bruno at modulix
[EMAIL PROTECTED] wrote:
> bruno at modulix>Since the class statement without superclass actually
> creates an old-style class, I'd expect the "class MyClass():" variant
> to behave the same.<
> 
> In Python 3.0 I really hope the
>
> class C: pass
> class C(): pass
> class C(object): pass
> 
> will mean the same thing. 

Yes, but this is for 3.0. Actually we're still at 2.5.


-- 
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: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-11 Thread bruno at modulix
looping wrote:
> bruno at modulix wrote:
> 
>>looping wrote:
>>
>>>Peter Hansen wrote:
>>>
>>>
Georg Brandl wrote:


>class C():
>
>is meant to be synonymous with
>
>class C:
>
>and therefore cannot create a new-style class.

I think "looping" understands that, but is basically asking why anyone
is bothering with a change that involves a part of the language that is
effectively deprecated.  In other words, class(): never used to be
valid, so why make it valid now?

-Peter
>>>
>>>
>>>Exact.
>>>But I think that if we make "class C():" a synonym of "class
>>>C(object):", it will save lot of keystrokes ;-)
>>
>>Since the class statement without superclass actually creates an
>>old-style class,  I'd expect the "class MyClass():" variant to behave
>>the same. Sacrifying readability and expliciteness just to save half a
>>dozen keystrokes is not pythonic IMHO.
>>
> 
> 
> I don't think readability suffer 

It does. The statement "class X():" imply there's no superclass, so it
definitiveley should behave the same as "class X:".

> and expliciteness could sometimes be
> sacrified to simplify the life of developer: ex "abcd"[0:3]  ->
> "abcd"[:3].

Here there's no ambiguity.

> And for newbies, the somewhat magic behavior of the "object" superclass
> is not so clear even that it is very explicit.

There's no magic involved here. And I really doubt that having
inconsistant behaviour for "class X():" wrt/ "class X:" will help here.

> When I write script I don't use new-style class 

You should.

> cause is bother me to
> type "(object)" when I don't need their features.

Please repeat this 101 times each morning:
"thou shall not use old-style classes for they are deprecated".

(snip)

> So this new syntax is a good way to boost their uses without bother
> with compatibility of existing code IMHO.

It's mostly a good way to add inconsistency and confusion to a situation
that's already confusing enough for newbies.


-- 
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


Override on terminal

2006-04-11 Thread fivestars
Hi there.

I'm computer science student at the end of my degree. I'm new about
python.

I've a question for all of you.

Do you know how to write, from python code, on a unix(linux) terminal
on specified coordinates?
And also: is it possible to override, from python code, something on a
unix(linux) terminal?

I would have a suggestion that won't use files.

I hope that i've been clear.

Thanks,

  Mattia

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


Re: setting up mod_python handlers on a server?

2006-04-11 Thread Gerard Flanagan

John Salerno wrote:
> I get this internal error message when I try to access a PSP page:
>
> "Invalid command 'PythonHandler', perhaps mis-spelled or defined by a
> module not included in the server configuration"
>
> So it seems that mod_python is not fully configured yet to handled PSP
> pages. When I check the installed Apache handlers, there is an entry
> called "mod_python .psp" where the first term is the handler and the
> second is the extension. I also tried adding "PythonHandler" as it
> appears in the htaccess file, but nothing is working. Sometimes the HTML
> is displayed, and other times I get a 500 Internal Server Error page.
>
> I had assumed when a server has mod_python installed, you can start
> using PSP functionality automatically, but I guess there's more work to
> do to set it up. Can anyone tell me what else I might need to do? Add
> another handler, perhaps?
>
> Thanks.

I'm just learning apache and mod_python myself so no expertise, but do
you have an 'AddHandler' or a 'SetHandler' before 'PythonHandler'?

I have this:

SetHandler mod_python
PythonPath "sys.path"
PythonHandler mod_python.publisher
PythonDebug On

and I think what you want is:

AddHandler mod_python .psp
PythonHandler mod_python.psp

Gerard

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


Re: Creating an event loop

2006-04-11 Thread Michele Simionato
Fabian Steiner wrote:
> Hello!
>
> I am currently wondering how to write something like an "event loop".
> For example, if I want to write a function that checks whether a file
> was added or removed in a directory I would think of a "while 1: ..."
> construct that checks the mtime of the directory. Is this the right way
> to achieve the exepected result or are there any better ways?

Well, if you feel like cheating, you could use the Tkinter mainloop:

import os
from Tkinter import Tk
root = None # invisible tk window

DELTA_T = 1 # 10 seconds

def checkdir(path='.'):
print os.listdir(path) # do whatever check you wish
root.after(DELTA_T, checkdir)

if __name__ == '__main__':
root = Tk()
root.withdraw()
checkdir()
try:
root.mainloop()
except KeyboardInterrupt:
pass

The advantage is that you can every easily schedule recurring and
non-recurring events.

Michele Simionato

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


Re: [fcntl]how to lock a file

2006-04-11 Thread marcello
Carl J. Van Arsdall wrote:
 > [...]
 >
 > If you end up having problems working with the python fcntl module let
 > me know your configuration I'd be interested to see if anyone else had
 > similar problems to me.


Python 2.2.3 (#1, Aug  8 2003, 08:44:02)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-13)] on linux2
kernel 2.4.21-4.0.1.ELsmp
glibc-2.3.2-95.6



What else can i add?

best regards
Marcello

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


  1   2   3   >