ANN: uuid-0.1 Released

2006-03-27 Thread Jürgen Urner


uuid is a python module to generate RFC 4122 compatible UUIDs

Somehow this module was missing in python, so I took over the
struggle with the C sources and all those quirky bits and bytes.
Most of them should now be in place to form one of these handy
128 bit identifiers.

The module is capable of producing time, random, sha1 and md5
based uuids.


For details see:
http://home.arcor.de/jurner/python/

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

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


[ANN] Firedrop 0.2.0 - The Python Blog Client

2006-03-27 Thread Fuzzyman
It has finally happened, the release of `Firedrop 0.2.0
http://www.voidspace.org.uk/python/firedrop2/`_.

The impatient can download the new release here :

`Firedrop 0.2.0 (1.3mb)
http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=firedrop2-0.2.0.zip`_

.. note::

The first time you run version 0.2.0 it will convert your weblog
config file to the new format.

**Firedrop2** is the Python blog client with a host of features. These
include :

* RSS feed generation
* Categories
* Automatic archive generation
* A powerful set of plugins, including spell checker and emailer
* Entries can be made in text, HTML, ReST, textile, sextile or markdown
markup
* HTML templating system and macros for all sorts of tricks
* Built in FTP capability for uploading your blog to a server
* Because it's written in Python, it is easy to extend Firedrop or
create new plugins for it

This new release has been made possible by the hard work of `Stewart
Midwinter http://www.midtoad.org`_.

The changes and new features include :

* Firedrop will now start up by opening a default site.
* You can set the default site using the GUI.
* Main file name changed to ``firedrop.pyw``
* `ConfigObj http://www.voidspace.org.uk/python/configobj.html`_ is
now used to edit all the config files.
* Full support for all style elements (e.g. underline, bold) in four
  major markup formats: ReST, Sextile, Textile, Markdown (plus HTML).
* New entries are created in a separate dialog that takes care of the
markup.
* Links are available to websites for the markup styles.
* You can reset the app to a null site, and/or delete all entries.
* You can force a full build of your site, or just update your site.
* You can now create sites serving Article Collections or Items Lists
(e.g. FAQs)
  in addition to Weblogs.
* Firedrop2 now runs on Mac OS X and Linux in addition to Windows.
* You can view logfile contents using the GUI.
* Documentation has been updated to reflect these changes.

There is a roadmap for future releases on the `Firedrop2 Trac Site
http://firedrop2.python-hosting.com`_.

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

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


PyPy Tokyo sprint 23/4 - 29/4

2006-03-27 Thread Anders Chrigström
Tokyo PyPy Sprint: 23rd - 29th April 2006


The next PyPy sprint is scheduled to take place 23rd- 29th April 2006
(Sunday-Saturday) in Akihabara, Tokyo, Japan. We will together with
FSIJ (Free Software Initiative of Japan) aim to promote Python and
PyPy.  We therefor invite Japanese hackers knowledgeable in Python to
join our sprint!  We'll give newcomer-friendly introductions. To learn
more about the new Python-in-Python implementation look here:

 http://codespeak.net/pypy

For this sprint we are particularly interested in meeting and coding on
PyPy together
with interested Japanese Python hackers. Please register your interest
at [EMAIL PROTECTED]
as soon as possible and we will help with any questions regarding
getting started, pointing
to relevant documentation etc.

The PyPy team is curious and interested in the experience of hacking
code for embedded devices
and would love to discuss and get feedback on optimisation efforts and
the current state of PyPy.

Goals and topics of the sprint
--

Possible suggestions for topics are:

   - Work on gensqueak (our Squeak backend) or possibly other backends.

   - Implementing Python 2.5 features in PyPy.

   - Progress further on an 'rctypes' module aiming at letting us use a
ctypes
 implementation of an extension module from the compiled pypy-c.

   - Writing ctypes implementations of modules to be used by the above
 tool.

   - Experimenting and improving performance of our garbage collectors.

   - Experiment with PyPy flexibility or other aspects of the
implementation.

   - Possibly experiment with writing modules translatable for use both
 in PyPy and CPython.

   - Whatever participants want to do with PyPy or particular areas
 of PyPy (please send suggestions to the mailing list before to
allow us to plan
 and give feedback)


Location  Accomodation


The sprint will be held at National Institute of AIST
  (National Institute of Advanced Industrial Science and Technology,
  http://www.aist.go.jp/index_en.html), Akihahabara (the technical gadget
district in Tokyo). Yutaka Niibe is our contact person there,
helping with arranging facilities. Niibe is the chairman of FSIJ and
they have
invited us to sprint in Tokyo and we are very grateful for the help and
interest
we have recieved so far.

The facilities we are sprinting in are located here:

 http://www.gtrc.aist.go.jp/en/access/index.html#Akihabara


The actual address is:
Akihabara Dai Bldg , 1-18-13 Sotokanda, Chiyoda-ku, Tokyo 101-0021 Japan
Phone: +81-3-5298-4729

Hotel areas - we are recommended to book hotels in Ueno and Asakusa (old
town),
from those areas there are only two metro stops to Akihabara. Please
note that
hotelrooms in Tokyo are often very small.

 http://www.wh-rsv.com/english/akihabara/index.html  (nearest
hotel to sprint location)
 http://www.greenhotel.co.jp/ochanomizu_e.html
 http://www.ohgai.co.jp/index-e.html (Ueno)
 http://www.toyoko-inn.com/e_hotel/00012/index.html (Asakusa)
 http://www.hotelnewkanda.com/   (second nearest, but no english
page)

Here is a url for booking hotels with not too unreasonable rates (see map):
http://japan-hotelguide.com/hotels/Japan/Tokyo/index.htm

For more general tourist information about travelling to Japan and Tokyo
- please see:
http://www.jnto.go.jp/eng/
http://www.japantravelinfo.com/  (really useful information regarding
airfares, hotels, currency, phones etc etc)

Comments on the weather: In end April it is ca 20 degrees Celsius.


Exact times
---

The public PyPy sprint is held Sunday 23rd - Saturday 29th April 2006.
Hours will be from 10:00 until people have had enough.  It's a good idea
to arrive a day before the sprint starts and leave a day later.
Sometimes people
cannot stay for the whole sprint - you are welcome even if you can only stay
for a day or a few days.

Sunday: Starting at 10:00. This day is focused on getting to know PyPy
enought to
start to participate. We will hold a PyPy tutorial and an architectural
overview.
Planning meeting for the work to be done during the week and grouping of
developers (pairs
or groups mixing new participants with core developers).

Dinner in the evening (Yutaka will arrange a place for us to go to).

Monday-Tuesday: Starting at 10:00 with status meetings. Possible regrouping
depending on the interest and progress of the various teams.

Wednesday: Breakday (coding is allowed although we recommend taking a
break).

Thursday-Saturday: Starting at 10:00 with status meetings. Possible
regrouping
depending on the interest and progress of the various teams. Ending on
Saturday with
a Closure session - summing of the work and planning work to be done
until the next sprint.


Network, Food, currency


We will have access to WiFi at AIST - please make sure you have wlan
capabilities.


COM object pointer cast

2006-03-27 Thread Axel Bock
Hi,

I am fooling around with the Python-COM bridge, and I have a little
question with that.

In the component I am using is a method which will return an Entry
object - basically. In truth it returns some object which inherits from
entry, and I know which one, but - as said - the method will only
return the IEntry interface pointer. Now I would like to cast that one
to the one I need :) . Is there an easy way to do it, or do I have to
use the QueryInterface-method to get what I want?


Greetings  thanks in advance, 

Axel.

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


Re: (not really) randon ideas

2006-03-27 Thread Tim Roberts
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

regarding the constants, this is more for the vm (and type safety).
actually enums, constants and symbols can prolly be implemented more or
less the same.

Ewww.  For some reason, there's just something about the vulgar construct
prolly that really irks me, even more than sth for something or
proggie for program.

You're only saving two keystrokes over the correct word, probably, and
because it's split between the hands, probably is probably faster to
type.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HIRING: PHP Developer

2006-03-27 Thread HiringDivision
I apologize.  Google groups has restricted our contact email.  To reach
us, please send your quote to hiringdivision @ gmail.com.

Thank you.

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


Re: sending emails to a list of recipients

2006-03-27 Thread Tim Roberts
Gerard Flanagan [EMAIL PROTECTED] wrote:

Kun wrote:

 i have the following code:

 --
 import smtplib
...
 msg['Subject'] = 'Purchase Confirmation'
 msg ['From'] = From
 msg['To'] = emails

 s = smtplib.SMTP('.xxx.xxx.edu')
 s.login('x','')
 s.sendmail(msg['From'], msg['To'], msg.as_string())
 s.close()
 --

 it works if msg['To'] = '[EMAIL PROTECTED]'

 however, i'm trying to attach a list of emails named 'emails' to msg['To']

 emails is in the following format: ['[EMAIL PROTECTED]', '[EMAIL PROTECTED]',
 '[EMAIL PROTECTED]']

 anyone have an idea how i can modify this script to work with sending a
 list? note this is a snippet of a larger code, 'emails' is as a string
 defined earlier.

What did you try?  You should just be able to pass the list:

   s.sendmail( msg['From'], emails, msg.as_string() )
Or, if you must,
   msg['To'] = emails
   s.sendmail( msg['From'], msg['To'], msg.as_string() )

It needs to be a list or tuple of individual addresses, e-mail only, with
no nicknames.  If you tried that, what did you see?

maybe try :  msg['To'] = ', '.join( emails )

taken from:

http://docs.python.org/lib/node597.html

No, you misread the example.  It uses that in the headers of the message.
That won't work for the second parameter of SMTP.sendmail.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Override default signal handler in interactive shell

2006-03-27 Thread pkassianidis
Hello everybody,

I have written a python script which executes some functions and then
returns to the python interactive shell prompt (In other words I use
the command
#!/usr/bin/python -i  in the script's header.
In this script I register my own handler for the SIGINT and SIGTERM
handlers but when I press Control-C the default handler is invoked and
the message KeyboardInterrupt is displayed. If I don't allow the
script to return control to the interactive shell, by putting for
example an endless loop, then  my handler works fine. Does anyone know,
how I can make it work in the first case also? Thank you very much.

 Best Regards

Panos

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


Re: sending emails to a list of recipients [update]

2006-03-27 Thread Tim Roberts
Kun [EMAIL PROTECTED] wrote:

Kun wrote:
 i have the following code:
 
 --
 import smtplib
 
 from email.MIMEText import MIMEText
 fp = open('confirmation.txt', 'rb')
 msg = MIMEText(fp.read())
 
  From = '[EMAIL PROTECTED]'
 
 msg['Subject'] = 'Purchase Confirmation'
 msg ['From'] = From
 msg['To'] = emails
 
 s = smtplib.SMTP('.xxx.xxx.edu')
 s.login('x','')
 s.sendmail(msg['From'], msg['To'], msg.as_string())
 s.close()
 --

this is my error msg of leaving the code in its current state... (brave 
yourself)

Traceback (most recent call last):
   File /Tutorial/IMAP/scannermailer.py, line 41, in -toplevel-
 s.sendmail(msg['From'], msg['To'], msg.as_string())
   File 
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/email/Message.py,
 
line 129, in as_string
 g.flatten(self, unixfrom=unixfrom)
...
   File 
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/email/quopriMIME.py,
 
line 79, in _max_append
 L.append(s.lstrip())
AttributeError: 'list' object has no attribute 'lstrip'

OK, I see what's going on now.  The problem is that SMTP.sendmail and
email.MIMEText need two different things.

email.MIMEText sets up the To: header for the body of the e-mail.  It is
ONLY used for displaying a result to the human being at the other end, and
like all e-mail headers, must be a single string.  (Note that it does not
actually have to have anything to do with the people who actually receive
the message.)

SMTP.sendmail, on the other hand, sets up the envelope of the message for
the SMTP protocol.  It needs a Python list of strings, each of which has a
single address.

So, what you need to do is COMBINE the two replies you received.  Set
msg['To'] to a single string, but pass the raw list to sendmail:

msg['To'] = ', '.join( emails )

s.sendmail( msg['From'], emails, msg.as_string() )
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HIRING: PHP Developer

2006-03-27 Thread Simon
I apologize.  Google groups has restricted our contact email.  To reach
 us, please send your quote to hiringdivision @ gmail.com.

 Thank you.

Apologize to whom?  Who/What are you replying to?

Please note that we don't all use Google groups format your replies 
properly.

Simon

-- 
http://urlkick.com/
Free URL redirection service. Turns a long URL into a much shorter one. 


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


Re: __slots__

2006-03-27 Thread Antoon Pardon
Op 2006-03-25, John J. Lee schreef [EMAIL PROTECTED]:
 [EMAIL PROTECTED] (Alex Martelli) writes:
 [...]
 you should be using pychecker or pylint
 [...]

 I'm curious, as somebody who doesn't regularly use these tools: How do
 they fit into your workflow?  Do you run them every few hours, every
 day, every time you run functional tests, every release, every so
 often, on gut feeling about when it's likely to catch problems...?

 How do you cope with spurious warnings?  Does it involve tweaking code
 to quell warnings?  Keeping suppression lists?  Maintaining special
 invocations of pychecker / pylint per-project?  Do they cope well with
 other people's code who do not use these tools?

IMO they don't cope well unless you adapt to what they expect.

I just tested the two.

pylint gave me countless warnings because I use two space to indent
instead of four. It also didn't like that I used uppercase letters
in my identifiers. That there was no space after a comma or
around an operator was a problem too.

That I use the same name for the index variable of for loops in
different scopes is also warned about.


Pychecker also warns about these shadowed variable. Pychecker
goes even so far to warn you that a local variable in an imported
module is shadowing a global variable of yours. Like the following
line:

/usr/lib/python2.3/random.py:247: Local variable (i) shadows global
defined on line 43 in file demo1a.py

So it seems pychecker thinks I shouldn't use something like

for i in lst:
  ...

in my code at the global level because some module in the standard
library has a function with a local i.

Pychecker also froze on my system.


I don't recommend the use of these tools.

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


XMLRPCServer issues

2006-03-27 Thread looping
Hi,

I had some issues with XMLRPCServer and I try to validate my
workaround.

My first try was this (somewhat self explaining code):

from DocXMLRPCServer import DocXMLRPCServer
from cx_Oracle import connect

def get_task_list(user):
sql = 
select   ISS.ISS_ISSUE_NUMBER
   , ISS.ISS_DESCRIPTION
   , ISS.C_PC_ISS_STATUS
   , ISS.ISS_IN_WORK
   , ISS.PC_ISSUES_ID
   , DES.GCDTEXT1
from ...
   where ...

con = connect('DEVELOP/[EMAIL PROTECTED]')
cur = con.cursor()
cur.execute(sql, USE_NAME = user.upper())
result = cur.fetchall()
cur.close()
con.close()
return result

server = DocXMLRPCServer((localhost, 8000))
server.register_function(get_task_list)
server.serve_forever()


But I had 2 errors with this code:
-PC_ISSUES_ID column could be an integer of 12 digits but the XML
generator only allow 2L**31-1 long integer, so I had an
Overflowexception: long int exceeds XML-RPC.
-Text columns (like ISS_DESCRIPTION) could contains non ascii char.
(éàç) but the server doesn't allow to specify the encoding to use
for the XML, so parser error on non-ascii char. on the client side
(ExpatError: not well-formed (invalid token)).

My working code with workarounds for these issues is:

from DocXMLRPCServer import DocXMLRPCServer
from cx_Oracle import connect

#increase MAXINT constant to allow 12 digits integer for PC_ISSUES_ID
#(long int exceeds XML-RPC exception)
import xmlrpclib
xmlrpclib.MAXINT = 

def get_task_list(user):
sql = 
select   ISS.ISS_ISSUE_NUMBER
   , ISS.ISS_DESCRIPTION
   , ISS.C_PC_ISS_STATUS
   , ISS.ISS_IN_WORK
   , ISS.PC_ISSUES_ID
   , DES.GCDTEXT1
from ...
   where ...

con = connect('DEVELOP/[EMAIL PROTECTED]')
cur = con.cursor()
cur.execute(sql, USE_NAME = user.upper())
result = cur.fetchall()
cur.close()
con.close()
#convert string column to unicode (XML generator does not use
# encoding so string must be UTF8 or unicode)
result = [list(row) for row in result]
for row in result:
for count, x in enumerate(row):
if isinstance(x, str):
row[count] = x.decode('cp1252')
return result

server = DocXMLRPCServer((localhost, 8000))
server.register_function(get_task_list)
server.serve_forever()


But it seems to me not very clean, especially the MAXINT hack.
Has anyone a better solution ?

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


Re: Menu For The Command Line?

2006-03-27 Thread Phoe6
Michael Sperlle wrote:
 When I bring up the command line interface, it looks like: [EMAIL PROTECTED]

 Then I type in some command, and it works!

 But there are lots of commands to type in, and I find it more and more
 difficult to remember them.

This question is not for comp.lang.python.
However, for your difficultly google for bash_complete and find some
help there.

-- 
Senthil
http://puggy.symonds.net/~senthil

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


Re: __slots__

2006-03-27 Thread Georg Brandl
Antoon Pardon wrote:
 Op 2006-03-25, John J. Lee schreef [EMAIL PROTECTED]:
 [EMAIL PROTECTED] (Alex Martelli) writes:
 [...]
 you should be using pychecker or pylint
 [...]

 I'm curious, as somebody who doesn't regularly use these tools: How do
 they fit into your workflow?  Do you run them every few hours, every
 day, every time you run functional tests, every release, every so
 often, on gut feeling about when it's likely to catch problems...?

 How do you cope with spurious warnings?  Does it involve tweaking code
 to quell warnings?  Keeping suppression lists?  Maintaining special
 invocations of pychecker / pylint per-project?  Do they cope well with
 other people's code who do not use these tools?
 
 IMO they don't cope well unless you adapt to what they expect.
 
 I just tested the two.
 
 pylint gave me countless warnings because I use two space to indent
 instead of four. It also didn't like that I used uppercase letters
 in my identifiers. That there was no space after a comma or
 around an operator was a problem too.

Pylint knows different types of issues, these are code style issues
and can be
 - turned off
 - configured to what you like.
They help getting your coding style consistent and default to PEP8 style.

 That I use the same name for the index variable of for loops in
 different scopes is also warned about.

Well, everything that _could_ be problematic _or_ confuse a reader is
warned about. Pretty good in my eyes.

 Pychecker also warns about these shadowed variable. Pychecker
 goes even so far to warn you that a local variable in an imported
 module is shadowing a global variable of yours. Like the following
 line:
 
 /usr/lib/python2.3/random.py:247: Local variable (i) shadows global
 defined on line 43 in file demo1a.py

That's odd. How are the two modules related?

 So it seems pychecker thinks I shouldn't use something like
 
 for i in lst:
   ...
 
 in my code at the global level because some module in the standard
 library has a function with a local i.
 
 Pychecker also froze on my system.

Pychecker imports the modules. Thus these things can happen when a
module expects not to be imported as-is.

 I don't recommend the use of these tools.

Well, then I don't recommend anyone reading your code wink

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


Re: Python multithreading problem

2006-03-27 Thread abhinav
thanks guys.I solved the problem by moving self.stdmutex.acquire()
before if c5:

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


python -U problem for 2.4.3c1 on Windows 2000 (was Does -U option really exist?)

2006-03-27 Thread Petr Prikryl
I did observe the problem when using the -U
option on Windows 2000. Seems like some infinite 
recursion in cp1250.py -- see below.

I did not try it with earlier versions of Python.

Can this be reproduced on your computer? 

Thanks for your time and experience,
  pepr

P.S. Thanks, Martin, for the hint.

Martin v. Löwis wrote
 Petr Prikryl wrote:
  Martin v. Löwis wrote
   As for dropping the u prefix on string literals:
   Just try the -U option of the interpreter some time,
   which makes all string literals Unicode. If you manage
   to get the standard library working this way, you
   won't need a per-file decision anymore: just start
   your program with 'python -U'.
 
  I have failed to find the -U option in Python 2.4.2.
 
[...]
 $ python2.4 -U
 Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
 [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
 Type help, copyright, credits or license for more information.
 
  type()
 type 'unicode'
  ^D
[...]

On Windows machine

C:\python -U
'import site' failed; use -v for traceback
Python 2.4.3c1 (#68, Mar 23 2006, 10:19:27) [MSC v.1310 32 bit (Intel)] on win32

Type help, copyright, credits or license for more information.
 type('')
type 'unicode'
 ^Z

See the 'import site' failure. I do use the sitecustomize.py
(C:\Python24\Lib\site-packages\sitecustomize.py). It contains
-
import sys
sys.setdefaultencoding('cp1250')
-

I did remove the sitecustomize.pyc before the command.
When trying the python -U -v 2xxx.log, I get the 
following (shortened):

# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# C:\Python24\lib\site.pyc matches C:\Python24\lib\site.py
import site # precompiled from C:\Python24\lib\site.pyc
# C:\Python24\lib\os.pyc matches C:\Python24\lib\os.py
import os # precompiled from C:\Python24\lib\os.pyc
import nt # builtin
# C:\Python24\lib\ntpath.pyc matches C:\Python24\lib\ntpath.py
import ntpath # precompiled from C:\Python24\lib\ntpath.pyc
# C:\Python24\lib\stat.pyc matches C:\Python24\lib\stat.py
import stat # precompiled from C:\Python24\lib\stat.pyc
# C:\Python24\lib\UserDict.pyc matches C:\Python24\lib\UserDict.py
import UserDict # precompiled from C:\Python24\lib\UserDict.pyc
# C:\Python24\lib\copy_reg.pyc matches C:\Python24\lib\copy_reg.py
import copy_reg # precompiled from C:\Python24\lib\copy_reg.pyc
# C:\Python24\lib\types.pyc matches C:\Python24\lib\types.py
import types # precompiled from C:\Python24\lib\types.pyc
# C:\Python24\lib\locale.pyc matches C:\Python24\lib\locale.py
import locale # precompiled from C:\Python24\lib\locale.pyc
import _locale # builtin
# C:\Python24\lib\codecs.pyc matches C:\Python24\lib\codecs.py
import codecs # precompiled from C:\Python24\lib\codecs.pyc
import _codecs # builtin
import encodings # directory C:\Python24\lib\encodings
# C:\Python24\lib\encodings\__init__.pyc matches 
C:\Python24\lib\encodings\__init__.py
import encodings # precompiled from C:\Python24\lib\encodings\__init__.pyc
# C:\Python24\lib\encodings\aliases.pyc matches 
C:\Python24\lib\encodings\aliases.py
import encodings.aliases # precompiled from 
C:\Python24\lib\encodings\aliases.pyc
# C:\Python24\lib\encodings\cp1250.pyc matches 
C:\Python24\lib\encodings\cp1250.py
import encodings.cp1250 # precompiled from C:\Python24\lib\encodings\cp1250.pyc
import sitecustomize # from C:\Python24\lib\site-packages\sitecustomize.py
# wrote C:\Python24\lib\site-packages\sitecustomize.pyc
'import site' failed; traceback:
Traceback (most recent call last):
  File C:\Python24\lib\site.py, line 397, in ?
main()
  File C:\Python24\lib\site.py, line 394, in main
if hasattr(sys, setdefaultencoding):
  File C:\Python24\lib\encodings\cp1250.py, line 18, in encode
return codecs.charmap_encode(input,errors,encoding_map)
  File C:\Python24\lib\encodings\cp1250.py, line 18, in encode
return codecs.charmap_encode(input,errors,encoding_map)
  File C:\Python24\lib\encodings\cp1250.py, line 18, in encode
return codecs.charmap_encode(input,errors,encoding_map)
[...snip...]
  File C:\Python24\lib\encodings\cp1250.py, line 18, in encode
return codecs.charmap_encode(input,errors,encoding_map)
  File C:\Python24\lib\encodings\cp1250.py, line 18, in encode
return codecs.charmap_encode(input,errors,encoding_map)
RuntimeError: maximum recursion depth exceeded
# C:\Python24\lib\warnings.pyc matches C:\Python24\lib\warnings.py
import warnings # precompiled from C:\Python24\lib\warnings.pyc
# C:\Python24\lib\linecache.pyc matches C:\Python24\lib\linecache.py
import linecache # precompiled from C:\Python24\lib\linecache.pyc
Python 2.4.3c1 (#68, Mar 23 2006, 10:19:27) [MSC v.1310 32 bit (Intel)] on win32
Type help, copyright, credits or license for more information.
 
# clear __builtin__._
# clear sys.path
# clear sys.argv
# clear sys.ps1
# clear sys.ps2
# clear sys.exitfunc
# clear sys.exc_type
# clear sys.exc_value
# clear 

Difference between 'is' and '=='

2006-03-27 Thread mwql
Hey guys, this maybe a stupid question, but I can't seem to find the
result anywhere online. When is the right time to use 'is' and when
should we use '=='? 

Thanks alot~

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


Re: datetime iso8601 string input

2006-03-27 Thread Rubic
 Could [RFC 3339] be a candidate for a default consumption
 format for date-time strings?

+1

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


Re: Difference between 'is' and '=='

2006-03-27 Thread Rene Pijlman
mwql:
Hey guys, this maybe a stupid question, but I can't seem to find the
result anywhere online. When is the right time to use 'is' and when
should we use '=='? 

http://docs.python.org/ref/comparisons.html

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between 'is' and '=='

2006-03-27 Thread Max M
mwql wrote:

 Hey guys, this maybe a stupid question, but I can't seem to find the
 result anywhere online. When is the right time to use 'is' and when
 should we use '=='? 

is is like id(obj1) == id(obj2)

  100+1 == 101
True

  100+1 is 101
False

They don't have the same id. (Think of id as memory adresses.)

-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

Phone:  +45 66 11 84 94
Mobile: +45 29 93 42 96
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __slots__

2006-03-27 Thread Antoon Pardon
Op 2006-03-27, Georg Brandl schreef [EMAIL PROTECTED]:
 Antoon Pardon wrote:
 Op 2006-03-25, John J. Lee schreef [EMAIL PROTECTED]:
 [EMAIL PROTECTED] (Alex Martelli) writes:
 [...]
 you should be using pychecker or pylint
 [...]

 I'm curious, as somebody who doesn't regularly use these tools: How do
 they fit into your workflow?  Do you run them every few hours, every
 day, every time you run functional tests, every release, every so
 often, on gut feeling about when it's likely to catch problems...?

 How do you cope with spurious warnings?  Does it involve tweaking code
 to quell warnings?  Keeping suppression lists?  Maintaining special
 invocations of pychecker / pylint per-project?  Do they cope well with
 other people's code who do not use these tools?
 
 IMO they don't cope well unless you adapt to what they expect.
 
 I just tested the two.
 
 pylint gave me countless warnings because I use two space to indent
 instead of four. It also didn't like that I used uppercase letters
 in my identifiers. That there was no space after a comma or
 around an operator was a problem too.

 Pylint knows different types of issues, these are code style issues
 and can be
  - turned off
  - configured to what you like.
 They help getting your coding style consistent and default to PEP8 style.

I have been on their website in the documentation section and found
nothing that could easily help me here.

 That I use the same name for the index variable of for loops in
 different scopes is also warned about.

 Well, everything that _could_ be problematic _or_ confuse a reader is
 warned about. Pretty good in my eyes.

No it isn't. If most of these line are in fact not problematic
or confusing at all then people will in general no longer
take notice of those kind of lines.

If I use a specific variable like i only as an index in for
loops, there is no reason to think this is problematic or confusing
even if those loops are in different scopes. And all those lines
reporting something that is not a problem will detract from the
few lines that may be a real problem.

 Pychecker also warns about these shadowed variable. Pychecker
 goes even so far to warn you that a local variable in an imported
 module is shadowing a global variable of yours. Like the following
 line:
 
 /usr/lib/python2.3/random.py:247: Local variable (i) shadows global
 defined on line 43 in file demo1a.py

 That's odd. How are the two modules related?

the program demo1a.py contains the following line:

  from random import Random, randint, sample


 So it seems pychecker thinks I shouldn't use something like
 
 for i in lst:
   ...
 
 in my code at the global level because some module in the standard
 library has a function with a local i.
 
 Pychecker also froze on my system.

 Pychecker imports the modules. Thus these things can happen when a
 module expects not to be imported as-is.

I still find it unacceptable.

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


Re: XMLRPCServer issues

2006-03-27 Thread Brian Quinlan
1. Is there on option to get cx_Oracle to return string data as unicode 
rather than strings objects? XML-RPC aside, dealing with unicode objects 
might be better than dealing with encoded strings.

2. You might want to transmit integers as strings rather than use the 
XML-RPC integer type (which is limited to numbers between -2147483648 
and 2147483647).

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


Re: Difference between 'is' and '=='

2006-03-27 Thread Fuzzyman

mwql wrote:
 Hey guys, this maybe a stupid question, but I can't seem to find the
 result anywhere online. When is the right time to use 'is' and when
 should we use '=='?

 Thanks alot~

'==' is the equality operator. It is used to test if two objects are
'equal'.

'is' is the identity operator, it is used to test if two
names/references point to the same object.

a = {'a': 3}
b = {'a': 3}
a == b
True
a is b
False
c = a
a is c
True

The two dictionaries a and b are equal, but are separate objects.
(Under the hood, Python uses 'id' to determine identity).

When you bind another name 'c' to point to dictionary a, they *are* the
same object - so a *is* c.

One place the 'is' operator is commonly used is when testing for None.
You only ever have one instance of 'None', so

a is None

is quicker than

a == None

(It only needs to check identity not value.)

I hope that helps.

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Properties

2006-03-27 Thread Ronny Mandal
Is there a way of checking whether the call to a set-function is
called from within the class, e.g. the __init__() contra
object.set()?


Thanks.

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


Re: New development windows, IronPython or PythonWin

2006-03-27 Thread Dan
Thanks to all, my main concern about anything Microsoft picks up and
runs with is that they vear off just slightly from the standard and
freeze everyone else out like they have done with their browser,
javascript etc.. etc... etc... So for now I will try to use Python /
PythonWin with the COM support. Dan

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


Re: New development windows, IronPython or PythonWin

2006-03-27 Thread Fuzzyman

Dan wrote:
 Thanks to all, my main concern about anything Microsoft picks up and
 runs with is that they vear off just slightly from the standard and
 freeze everyone else out like they have done with their browser,
 javascript etc.. etc... etc... So for now I will try to use Python /
 PythonWin with the COM support. Dan

I shouldn't think that Jim Hugunin will divert from the standard. In
fact he's even been asking on Python-Dev whether they should replicate
the bugs in Python 2.4 or stick with the documented behaviour !

Jim is in charge of the project and was the lead developer behind
Jython - so he literally knows Python inside out.

Anyway - PythoNWin and COM may well be the right approach for your
problem anyway. :-)

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: PIL image size reduction script

2006-03-27 Thread Philippe Martin
nikie wrote:

 Philippe Martin wrote:
 Hi,

 Thanks to the NG, I got the script hereunder working.

 1) I am not certain that the call to convert does much (checking the doc)
 
 I think you only need it if your source image comes in a format that
 can't be stored into a jpeg file (e.g. 8-bit paletted). You'll need
 that if you're converting from GIF files, for example. It shouldn't
 hurt otherwise.

OK 

 
 2) Can this be improved as far as the final image size in (X,Y) ?
 
 I'm not sure if I get you: You tell the image object it's new
 (X,Y)-size in the resize method, don't you?

Yes, I keep reducing the (X,Y) size as long as the file is too large (in
bytes)

 
 For instance, passing a large .jpg with a target byte size of 7000, I get
 final (X,Y) results around (213, 174) ... but might want to strech it a
 bit while keeping the byte size.
 
 If I got you right, you want to compress the image to a certain file
 size. Maybe you should try optimizing the additional save parameters
 for the jpeg encoder.
 (http://www.pythonware.com/library/pil/handbook/formats.htm). Try
 reducing the quality parameter.
   l_image.save(l_tmp_file_name, quality=25)
 

That might be it !!!

Thanks,

Philippe




 Hope this helps.
 
 Niki

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


Re: PIL image size reduction script

2006-03-27 Thread Philippe Martin
PS: where can I find those extra parameters in the doc (ex: quality) ... I
must be blind.

Philippe



nikie wrote:

 Philippe Martin wrote:
 Hi,

 Thanks to the NG, I got the script hereunder working.

 1) I am not certain that the call to convert does much (checking the doc)
 
 I think you only need it if your source image comes in a format that
 can't be stored into a jpeg file (e.g. 8-bit paletted). You'll need
 that if you're converting from GIF files, for example. It shouldn't
 hurt otherwise.
 
 2) Can this be improved as far as the final image size in (X,Y) ?
 
 I'm not sure if I get you: You tell the image object it's new
 (X,Y)-size in the resize method, don't you?
 
 For instance, passing a large .jpg with a target byte size of 7000, I get
 final (X,Y) results around (213, 174) ... but might want to strech it a
 bit while keeping the byte size.
 
 If I got you right, you want to compress the image to a certain file
 size. Maybe you should try optimizing the additional save parameters
 for the jpeg encoder.
 (http://www.pythonware.com/library/pil/handbook/formats.htm). Try
 reducing the quality parameter.
   l_image.save(l_tmp_file_name, quality=25)
 
 Hope this helps.
 
 Niki

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


Re: Difference between 'is' and '=='

2006-03-27 Thread Joel Hedlund
 is is like id(obj1) == id(obj2)
snip
 (Think of id as memory adresses.)

Which means that is comparisons in general will be faster than == 
comparisons. According to PEP8 (python programming style guidelines) you should 
use 'is' when comparing to singletons like None. I take this to also include 
constants and such. That allows us to take short cuts through known terrain, 
such as in the massive_computations function below:

--
import time

class LotsOfData(object):
 def __init__(self, *data):
 self.data = data
 def __eq__(self, o):
 time.sleep(2) # time consuming computations...
 return self.data == o.data

KNOWN_DATA = LotsOfData(1,2)
same_data = KNOWN_DATA
equal_data = LotsOfData(1,2)
other_data = LotsOfData(2,3)

def massive_computations(data = KNOWN_DATA):
 if data is KNOWN_DATA:
 return very quick answer
 elif data == KNOWN_DATA:
 return quick answer
 else:
 time.sleep(10) # time consuming computations...
 return slow answer

print Here we go!
print massive_computations()
print massive_computations(same_data)
print massive_computations(equal_data)
print massive_computations(other_data)
print Done.
--

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


Re: Difference between 'is' and '=='

2006-03-27 Thread Roy Smith
In article [EMAIL PROTECTED],
 Joel Hedlund [EMAIL PROTECTED] wrote:

 Which means that is comparisons in general will be faster than == 
 comparisons.

I thought that == automatically compared identify before trying to compare 
the values.  Or am I thinking of some special case, like strings?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For loop and list comprehension similarity

2006-03-27 Thread s . lipnevich
I think I like generator comprehension in this case better than either
list comprehension or a filter because both of the latter create a new
full result list before the loop even begins. At least I suppose they
do. Also, I think Mitja's suggestion if not test: continue and
Terry's filter function are more readable than comprehensions.
It's not a contest though :-), all these variants are great, thank you
all!
Do you think this discussion is a proof that the following principle
got violated, or do you think that loop with condition is not such an
atomic thing to be subject to this: There should be one -- and
preferably only one -- obvious way to do it.
Cheers,

Sergey.

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


Re: Difference between 'is' and '=='

2006-03-27 Thread Peter Hansen
Roy Smith wrote:
 In article [EMAIL PROTECTED],
  Joel Hedlund [EMAIL PROTECTED] wrote:
Which means that is comparisons in general will be faster than == 
comparisons.
 
 I thought that == automatically compared identify before trying to compare 
 the values.  Or am I thinking of some special case, like strings?

You must be thinking of a special case:

  class A:
...   def __cmp__(self, other): return 1
...
  a = A()
  a is a
True
  a == a
False


-Peter

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


Re: Properties

2006-03-27 Thread bruno at modulix
Ronny Mandal wrote:
 Is there a way of checking whether the call to a set-function is
 called from within the class, e.g. the __init__() contra
 object.set()?

import inspect
help(inspect.stack)


-- 
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: Difference between 'is' and '=='

2006-03-27 Thread Clemens Hepper
Roy Smith wrote:
 In article [EMAIL PROTECTED],
  Joel Hedlund [EMAIL PROTECTED] wrote:
 
 Which means that is comparisons in general will be faster than == 
 comparisons.
 
 I thought that == automatically compared identify before trying to compare 
 the values.  Or am I thinking of some special case, like strings?

Even for strings there is a performance difference:

 timeit.Timer('a'=='a').timeit()
0.26859784126281738
 timeit.Timer('a' is 'a').timeit()
0.21730494499206543

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


Re: PIL image size reduction script

2006-03-27 Thread nikie
Philippe Martin wrote:
 PS: where can I find those extra parameters in the doc (ex: quality) ... I
 must be blind.
In the http://www.pythonware.com/library/pil/handbook/formats.htm page.
Look in the JPEG section. Different file formats support different
options.

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


Re: What's the best way to learn perl for a python programmer?

2006-03-27 Thread Mirco Wahab
Hello vj

 I'll try and do as much as possible in pexpect but am sure I'll have do
 some significant perl. Any suggestions on what is the best way to get
 upto speed on perl?

Perl is (imho) much more complex and
somehow more powerful than Python
(if you can handle it) - it has more
development iterations behind it plus
a large contibuting community - and
their bear's den (CPAN) -- which
will probably save your project some-
times from debris falling around you.

BUT! There is no problem in using
a subset of Perl (called Baby-Perl)
that allows you translating your
Perl Scripts to Python by omitting $$
and { }, replace 'sub'  by 'def'
(plus some minor modifications).

There is a nice comparison on Python
and Perl available on the Web, which gave
me a good laugh for more than 30 seconds ;-))

http://www.adequacy.org/stories/2001.12.20.165434.32.html

(too bad - most responders didn't get the point of it)

Regards,

M.

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


Re: Advice for Python and Web Server/Services?

2006-03-27 Thread Ronald Davis
On Sunday 26 March 2006 5:00 pm, Dennis Lee Bieber wrote:

 Any possibility you need to specify an option on the socket
 connections to reuse-sockets without the normal time-out?

The problem turned out to be keep-alive. Apparently, Comcast is limiting my 
inbound connections. Apache keeps the connections alive so it works fine. The 
Python servers don't support keep-alive and are using up the available 
connections too quickly.

I'm now using Apache as a proxy to the Python server and it works well.

Thanks for the response.

 On Sun, 26 Mar 2006 14:55:12 -0500, Ron Davis [EMAIL PROTECTED]

 declaimed the following in comp.lang.python:
  I've looked in to fastcgi and mod_python but I'm not sure either is what
  I need. What I want is for my Python program to be polling the web
  services 24/7 and Apache to serve static pages by itself but call a
  function in my already running Python program for files with a certain
  extension (.xml for example).

   I think you'll first need to disconnect the two sides... The program
 doing the polling has to run completely stand-alone from your own
 web-server.  I also think you'll need to create some independent
 (file-system?) store which the polling program can write to; so your web
 server page can do the selected retrieval -- but since you don't want a
 database capable of concurrent access... The polling program needs to
 include an asynchronous or threaded scheme with a local socket so the
 web server (CGI) process can connect to it and requests the poller to
 return the data.

  Ideally, I'd like to figure out why the Python servers are having
  problems. This is a very low volume system so straight Python would be
  great if I can get it working.

   Any possibility you need to specify an option on the socket
 connections to reuse-sockets without the normal time-out?
 --

   == 
 [EMAIL PROTECTED]  | Wulfraed  Dennis Lee Bieber  KD6MOG 
[EMAIL PROTECTED] |   Bestiaria Support Staff   
   == 
 Home Page: http://www.dm.net/~wulfraed/
  Overflow Page: http://wlfraed.home.netcom.com/

-- 
Ron Davis
Custom Software Engineering
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nevow LivePage tutorial

2006-03-27 Thread Jean-Paul Calderone
On 26 Mar 2006 23:12:33 -0800, Mir Nazim [EMAIL PROTECTED] wrote:
Hello,

Can any one direct me to some tutorials for:
 1. Nevow LivePage

http://divmod.org/trac/wiki/DivmodNevow/Athena
http://divmod.org/trac/browser/trunk/Nevow/examples/athenademo

 2. Form handling in Nevow


http://divmod.org/trac/browser/trunk/Nevow/examples/formbuilder
http://forms-project.pollenation.net/cgi-bin/trac.cgi

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


Python, equivalent of set command

2006-03-27 Thread loial
In unix shell script I can do the following to get the status and
values returned by a unix command

OUTPUT=`some unix command`
STATUS=$?
if [ $STATUS -ne 0 ]
then
  exit 1
else
  set $OUTPUT
  VAL1=$1
  VAL2=$2
  VAL3=$3
fi

How can I achieve the same in python?

I know how to run it via the os.system command and return the status,
but how do I return the values too?

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


Re: Difference between 'is' and '=='

2006-03-27 Thread Dan Sommers
On Mon, 27 Mar 2006 14:52:46 +0200,
Joel Hedlund [EMAIL PROTECTED] wrote:

 ... According to PEP8 (python programming style guidelines) you should
 use 'is' when comparing to singletons like None. I take this to also
 include constants and such ...

This does *not* also mean constants and such:

Python 2.4.2 (#1, Feb 22 2006, 08:02:53) 
[GCC 4.0.1 (Apple Computer, Inc. build 5247)] on darwin
Type help, copyright, credits or license for more information.
 a = 123456789
 a == 123456789
True
 a is 123456789
False
 

Regards,
Dan

-- 
Dan Sommers
http://www.tombstonezero.net/dan/
I wish people would die in alphabetical order. -- My wife, the genealogist
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python types

2006-03-27 Thread bruno at modulix
Dennis Lee Bieber wrote:
 On Mon, 27 Mar 2006 01:34:14 +0200, Bruno Desthuilliers
 [EMAIL PROTECTED] declaimed the following in
 comp.lang.python:
 
 
Ok, so even if Python itself declares b and b2 (read: objects that names 
b and b2 are bound to) to be of the same type,  you cannot apply the 
myop() operation on b2...
 
 
  
   Try looking at class-based objects as a form of CONTAINER... 

ouch, my ears :(

 Two
 containers can be of the same type, but the contents may be different.
 
(snip)

This is mostly how OO is implemented in Python (in javascript too FWIW)
- but this is not the semantic of classes/objects in OO. The OO
translation of a type - at least according to the definition proposed by
the OP, and this is a pretty common definition - is a set of attributes
and methods. In most OO languages, this set is fixed for *all* the
instances of a class (subclassing not withstanding - and subclassing is
already a not so trivial problem in type theory).

What I wanted to point out is that, while class-based, Python in, in
this respect, closer to a prototype-based language.

In fact, since the set of attributes and methods of a given object may
change during the object's lifetime, it's type(s) may change too. So
saying that objects in Python have a perfectly defined type is perhaps
not really accurate, or at least requires further precisions (well, IMHO)

And I didn't even mention the possibility of changing the value of
anobject.__class__ at runtime !-)


-- 
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: Difference between 'is' and '=='

2006-03-27 Thread mwql
It's really strange,

if
a = 1
b = 1
a is b == True

the same thing applies for strings, but not for dict, lists or tuples
I think the 'is' operator is useful for objects only, not for primitive
types, 
I think I solved the mystery behind my bugged code =)

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


Re: PIL image size reduction script

2006-03-27 Thread Philippe Martin
Many thanks


nikie wrote:

 Philippe Martin wrote:
 PS: where can I find those extra parameters in the doc (ex: quality) ...
 I must be blind.
 In the http://www.pythonware.com/library/pil/handbook/formats.htm page.
 Look in the JPEG section. Different file formats support different
 options.

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


Re: Nevow LivePage tutorial

2006-03-27 Thread Tim Parkin
Jean-Paul Calderone wrote:

On 26 Mar 2006 23:12:33 -0800, Mir Nazim [EMAIL PROTECTED] wrote:
  


2. Form handling in Nevow




http://divmod.org/trac/browser/trunk/Nevow/examples/formbuilder
http://forms-project.pollenation.net/cgi-bin/trac.cgi

Jean-Paul
  

And http://divmod.org/trac/wiki/DivmodNevow/FormHandling

Tim Parkin

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


Re: Difference between 'is' and '=='

2006-03-27 Thread Benji York
mwql wrote:
 It's really strange,
 
 if
 a = 1
 b = 1
 a is b == True
 
 the same thing applies for strings

Not quite:

  'abc' is 'abc'
True
  'abc' is 'ab' + 'c'
False

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


Re: XMLRPCServer issues

2006-03-27 Thread looping

Brian Quinlan wrote:
 1. Is there on option to get cx_Oracle to return string data as unicode
 rather than strings objects? XML-RPC aside, dealing with unicode objects
 might be better than dealing with encoded strings.

I don't think cx_Oracle can return unicode string, so my code to
convert string is not so bad.

 2. You might want to transmit integers as strings rather than use the
 XML-RPC integer type (which is limited to numbers between -2147483648
 and 2147483647).

Is it a limit of XML-RPC RFC or a limit (probably with a good reason)
of the python xmlrpclib ?

Thanks for your answer.

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


Re: Python, equivalent of set command

2006-03-27 Thread skip

loial In unix shell script I can do the following to get the status and
loial values returned by a unix command

loial OUTPUT=`some unix command`
loial STATUS=$?
loial if [ $STATUS -ne 0 ]
loial then
loial   exit 1
loial else
loial   set $OUTPUT
loial   VAL1=$1
loial   VAL2=$2
loial   VAL3=$3
loial fi

loial How can I achieve the same in python?

I'm not much of a shell programmer, but it looks like you want something
like:

import os
pipe = os.popen(some unix command)
result = pipe.read()
status = pipe.close()
if not status:  # but see below...
val1, val2, val3 = result.split()

Read up on the os.popen function to get the details of what's in the status
variable.  I think the exit status might be in the upper eight bits, but I
don't remember off the top of my head.  That will affect the test.

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


Re: Difference between 'is' and '=='

2006-03-27 Thread Clemens Hepper
Dan Sommers wrote:
 This does *not* also mean constants and such:
 
 Python 2.4.2 (#1, Feb 22 2006, 08:02:53) 
 [GCC 4.0.1 (Apple Computer, Inc. build 5247)] on darwin
 Type help, copyright, credits or license for more information.
  a = 123456789
  a == 123456789
 True
  a is 123456789
 False

It's strange: python seem to cache constants from 0 to 99:

for x in xrange(1000):
 if not eval(%d%x) is eval(%d%x):
  print x

for me it printed 100-999.

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


Re: MVC in Python for web app dev

2006-03-27 Thread Don Taylor
[EMAIL PROTECTED] wrote:
  I'm aware that Pylons is trying to
 compete with Rails in the near future but I'm just not clear on how
 directly they are trying to compete...will Pylons have the same
 generation functions and other time saving goodies that RoR has or am I
 barking up the wrong tree?
 

Thanks for the reference to Pylon:

http://pylonshq.com/

I had not heard of it before and it looks promising.

Have you asked your questions ('the same generation functions and other 
time saving goodies') of the Pylon folks?

Don.

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


Re: Module documentation

2006-03-27 Thread msoulier
Bruno Desthuilliers wrote:
 In the python shell, typing 'help(symbol)' should get you started most
 of the time.

And honestly, it should work all of the time. If it doesn't, file a bug
report. I can't stand it when that doesn't work. Some of us don't do
all of our work with a browser handy, and a net connection. 

Mike

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


Re: For loop and list comprehension similarity

2006-03-27 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
 Do you think this discussion is a proof that the following principle
 got violated, or do you think that loop with condition is not such an
 atomic thing to be subject to this: There should be one -- and
 preferably only one -- obvious way to do it.

Mitja's suggestion was the one obvious way.  The others are all 
interesting, maybe even preferable in some cases, but I don't think most 
experienced Python programmers would be more likely to start with one of 
them than with the simple for-loop-with-explicit-test.

-Peter

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


Re: Difference between 'is' and '=='

2006-03-27 Thread Felipe Almeida Lessa
Em Seg, 2006-03-27 às 08:23 -0500, Dan Sommers escreveu:
 On Mon, 27 Mar 2006 14:52:46 +0200,
 Joel Hedlund [EMAIL PROTECTED] wrote:
 
  ... According to PEP8 (python programming style guidelines) you should
  use 'is' when comparing to singletons like None. I take this to also
  include constants and such ...
 
 This does *not* also mean constants and such:
 
 Python 2.4.2 (#1, Feb 22 2006, 08:02:53) 
 [GCC 4.0.1 (Apple Computer, Inc. build 5247)] on darwin
 Type help, copyright, credits or license for more information.
  a = 123456789
  a == 123456789
 True
  a is 123456789
 False
  

Not those kind of constants, but this one:

Python 2.4.2 (#2, Nov 20 2005, 17:04:48)
[GCC 4.0.3 2005 (prerelease) (Debian 4.0.2-4)] on linux2
Type help, copyright, credits or license for more information.
 CONST = 123456789
 a = CONST
 a == CONST
True
 a is CONST
True


-- 
Felipe.

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

Re: Difference between 'is' and '=='

2006-03-27 Thread Diez B. Roggisch
mwql wrote:

 It's really strange,
 
 if
 a = 1
 b = 1
 a is b == True
 
 the same thing applies for strings, but not for dict, lists or tuples
 I think the 'is' operator is useful for objects only, not for primitive
 types,
 I think I solved the mystery behind my bugged code =)

 The reason that is works for small numbers is that these are cached for
performance reasons. Try

 a = 100
 b = 100
 a is b
False

So - your conclusion is basically right: use is on (complex) objects, not on
numbers and strings and other built-ins. The exception from the rule is
None - that should only exist once, so

foo is not None

is considered better style than foo == None.

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


Next PyPy Sprint: Tokyo 23/4 - 29/4

2006-03-27 Thread Carl Friedrich Bolz

Tokyo PyPy Sprint: 23rd - 29th April 2006


The next PyPy sprint is scheduled to take place 23rd- 29th April 2006
(Sunday-Saturday) in Akihabara, Tokyo, Japan. We will together with
FSIJ (Free Software Initiative of Japan) aim to promote Python and
PyPy.  We therefor invite Japanese hackers knowledgeable in Python to
join our sprint!  We'll give newcomer-friendly introductions. To learn
more about the new Python-in-Python implementation look here:

  http://codespeak.net/pypy

For this sprint we are particularly interested in meeting and coding on
PyPy together
with interested Japanese Python hackers. Please register your interest
at [EMAIL PROTECTED]
as soon as possible and we will help with any questions regarding
getting started, pointing
to relevant documentation etc.

The PyPy team is curious and interested in the experience of hacking
code for embedded devices
and would love to discuss and get feedback on optimisation efforts and
the current state of PyPy.

Goals and topics of the sprint
--

Possible suggestions for topics are:

- Work on gensqueak (our Squeak backend) or possibly other backends.

- Implementing Python 2.5 features in PyPy.

- Progress further on an 'rctypes' module aiming at letting us use a
ctypes
  implementation of an extension module from the compiled pypy-c.

- Writing ctypes implementations of modules to be used by the above
  tool.

- Experimenting and improving performance of our garbage collectors.

- Experiment with PyPy flexibility or other aspects of the
implementation.

- Possibly experiment with writing modules translatable for use both
  in PyPy and CPython.

- Whatever participants want to do with PyPy or particular areas
  of PyPy (please send suggestions to the mailing list before to
allow us to plan
  and give feedback)


Location  Accomodation


The sprint will be held at National Institute of AIST
   (National Institute of Advanced Industrial Science and Technology,
   http://www.aist.go.jp/index_en.html), Akihahabara (the technical gadget
district in Tokyo). Yutaka Niibe is our contact person there,
helping with arranging facilities. Niibe is the chairman of FSIJ and
they have
invited us to sprint in Tokyo and we are very grateful for the help and
interest
we have recieved so far.

The facilities we are sprinting in are located here:

  http://www.gtrc.aist.go.jp/en/access/index.html#Akihabara


The actual address is:
Akihabara Dai Bldg , 1-18-13 Sotokanda, Chiyoda-ku, Tokyo 101-0021 Japan
Phone: +81-3-5298-4729

Hotel areas - we are recommended to book hotels in Ueno and Asakusa (old
town),
from those areas there are only two metro stops to Akihabara. Please
note that
hotelrooms in Tokyo are often very small.

  http://www.wh-rsv.com/english/akihabara/index.html  (nearest
hotel to sprint location)
  http://www.greenhotel.co.jp/ochanomizu_e.html
  http://www.ohgai.co.jp/index-e.html (Ueno)
  http://www.toyoko-inn.com/e_hotel/00012/index.html (Asakusa)
  http://www.hotelnewkanda.com/   (second nearest, but no english
page)

Here is a url for booking hotels with not too unreasonable rates (see map):
http://japan-hotelguide.com/hotels/Japan/Tokyo/index.htm

For more general tourist information about travelling to Japan and Tokyo
- please see:
http://www.jnto.go.jp/eng/
http://www.japantravelinfo.com/  (really useful information regarding
airfares, hotels, currency, phones etc etc)

Comments on the weather: In end April it is ca 20 degrees Celsius.


Exact times
---

The public PyPy sprint is held Sunday 23rd - Saturday 29th April 2006.
Hours will be from 10:00 until people have had enough.  It's a good idea
to arrive a day before the sprint starts and leave a day later.
Sometimes people
cannot stay for the whole sprint - you are welcome even if you can only stay
for a day or a few days.

Sunday: Starting at 10:00. This day is focused on getting to know PyPy
enought to
start to participate. We will hold a PyPy tutorial and an architectural
overview.
Planning meeting for the work to be done during the week and grouping of
developers (pairs
or groups mixing new participants with core developers).

Dinner in the evening (Yutaka will arrange a place for us to go to).

Monday-Tuesday: Starting at 10:00 with status meetings. Possible regrouping
depending on the interest and progress of the various teams.

Wednesday: Breakday (coding is allowed although we recommend taking a
break).

Thursday-Saturday: Starting at 10:00 with status meetings. Possible
regrouping
depending on the interest and progress of the various teams. Ending on
Saturday with
a Closure session - summing of the work and planning work to be done
until the next sprint.


Network, Food, currency


We will have access to WiFi at AIST - please make sure you have wlan

Re: determine file type

2006-03-27 Thread Steven D'Aprano
On Sun, 26 Mar 2006 19:52:32 -0700, Mark Gibson wrote:

 
 
 
 import os
 def test_file(filename, maxread=1024):
if os.path.isdir(filename):
  return 'directory'
afile = open(filename) # open as text
for achar in afile.read(maxread):
  if ord(achar)  127:
return 'binary'
return 'text'
 
 
 
 Pefect, thanks!

Not only is it not perfect, as given it isn't even correct.

 open(lots_of_nulls.bin, w).write(\0 * 1024)
 test_file(lots_of_nulls.bin)
'text'

However, with a more careful algorithm for deciding what's text and what's
not, the general approach is fine.


-- 
Steven.

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


Re: XMLRPCServer issues

2006-03-27 Thread Fredrik Lundh
looping wrote:

  2. You might want to transmit integers as strings rather than use the
  XML-RPC integer type (which is limited to numbers between -2147483648
  and 2147483647).

 Is it a limit of XML-RPC RFC or a limit (probably with a good reason)
 of the python xmlrpclib ?

the specification defines an integer field as a four-byte signed integer.

/F



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


Re: COM Client / Server creation?

2006-03-27 Thread Dan
Thanks, I am going to try to implement with Python.

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


Re: adding a new line of text in Tk

2006-03-27 Thread Fredrik Lundh
Ben Cartwright wrote:

  w =Label(root, text=Congratulations you have made it this far,just a few 
  more
  questions then i will be asking you some)
 
  The problem i have is where i have started to write some 
  textCongratulations
  you have made it this far,just a few more questions then i will be asking 
  you
  some)
  I would actually like to add some text but it puts it all on one line.I 
  would
  like to be able to tell it to start a new line.


 Just use \n in your string, e.g.:

 w = Label(root, text=Line 1\nLine 2\nLine 3)

 Or a triple-quoted string will do the trick:

 w = Label(root, text=Line 1
 Line 2
 Line 3)

you can also use the wraplength option to set a max width for
the label widget:

w = Label(
root, text=long paragraph...,
wraplength=150, justify=LEFT
)

also see:

http://effbot.org/tkinterbook/label.htm

/F



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


Re: XMLRPCServer issues

2006-03-27 Thread looping

Fredrik Lundh wrote:
 looping wrote:

   2. You might want to transmit integers as strings rather than use the
   XML-RPC integer type (which is limited to numbers between -2147483648
   and 2147483647).
 
  Is it a limit of XML-RPC RFC or a limit (probably with a good reason)
  of the python xmlrpclib ?

 the specification defines an integer field as a four-byte signed integer.

 /F

OK, I will remove my MAXINT hack and convert value to string.

Thanks everybody for your fast answers, nice group with nice (and
brillant) people.
See you later for my next question.

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


Re: access mbx files?

2006-03-27 Thread David Isaac
Donn Cave, [EMAIL PROTECTED]
 I suppose it isn't supported by the mailbox module basically because
 it isn't all that commonly encountered.  It may be more common on mail
 servers, but there it's email net protocol data, POP or IMAP.  If
 Mahogany has been using this format for `local' folders (i.e., via
 filesystem), I think that may have been kind of poor judgement on the
 part of its developers.

I cannot judge that, although I think I recall the choice was made
for reasons of speed.  What do you see as the downsides?
Just that it is uncommon (and thus questions like my original
questions arise)?

Thanks,
Alan Isaac


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


DELETE an image

2006-03-27 Thread ChengGong
hi guys,

could u tell me how to delete images ( files) from a folder by using
dtml tags in zope?
Because I upload images there and test whether it is meet size
requirment and then upload it to the folder it supposed to be.

Pls help me, thanks.

Cheng

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

tkinter+matplotlib

2006-03-27 Thread Giacomo Boffi
i have coded some progs that use the Pmw.Blt.Graph widgets, embedded
in a simple Tkinter GUI

,
| from Tkinter import *
| import Pmw
| ...
| frame=Frame(root)
| ...
| graph=Pmw.Blt.Graph(frame,...)
| graph.line_create(...)
| graph.pack(...)
`

now i'd like to port those progs to an environment where i have no BLT

assuming that i can use matplotlib to draw the line graphs i need, how
do i place the graph widget inside my tkinter GUI?

tia,
gb
-- 
  If you grow tired of the friends you make
   Never ever turn the back on them
Say they were the best of time you ever had
The best of times with the thougthless kind-- John Cale
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python, equivalent of set command

2006-03-27 Thread Jeffrey Schwab
loial wrote:
 In unix shell script I can do the following to get the status and
 values returned by a unix command
 
 OUTPUT=`some unix command`
 STATUS=$?
 if [ $STATUS -ne 0 ]
 then
   exit 1
 else
   set $OUTPUT
   VAL1=$1
   VAL2=$2
   VAL3=$3
 fi
 
 How can I achieve the same in python?
 
 I know how to run it via the os.system command and return the status,
 but how do I return the values too?

http://docs.python.org/lib/node241.html

6.8.3.1 Replacing /bin/sh shell backquote

output=`mycmd myarg`
==
output = Popen([mycmd, myarg], stdout=PIPE).communicate()[0]

The popen object also has a 'returncode' attribute.
-- 
http://mail.python.org/mailman/listinfo/python-list


COM server / COM client

2006-03-27 Thread Dan
Does the COM server created with python have to be compiled? I have the
need to integrate database access but, I can not have any proprietary
software. Meaning no compiled programs built by me. So, if python can
do com clients and servers without compiling, Im good. But I don't know
if that is possible. The ctypes example implies that it must be
compiled using py2exe. I know the clients don't have to be compiled.
What about the server?

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


Re: a problem to solve

2006-03-27 Thread Scott David Daniels
[EMAIL PROTECTED] wrote:

 And furthermore, having Python's bitwise operators
 is nice, but it's not nice enough. I need the bitwise
 functionality gmpy provides that's not available in
 Python: scan for position of least significant 1 or 0,
Cute tricks (artifact of two's complement notation):

 v  -v == isolated least significant bit of v

 math.log(v  -v, 2) == bit number of least significant bit.


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


Re: access mbx files?

2006-03-27 Thread Donn Cave
Quoth David Isaac [EMAIL PROTECTED]:
| Donn Cave, [EMAIL PROTECTED]
| I suppose it isn't supported by the mailbox module basically because
| it isn't all that commonly encountered.  It may be more common on mail
| servers, but there it's email net protocol data, POP or IMAP.  If
| Mahogany has been using this format for `local' folders (i.e., via
| filesystem), I think that may have been kind of poor judgement on the
| part of its developers.
|
| I cannot judge that, although I think I recall the choice was made
| for reasons of speed.  What do you see as the downsides?
| Just that it is uncommon (and thus questions like my original
| questions arise)?

That's one problem, it's inaccessible to a wide variety of email
software you might want to run.  Maybe worse, it's fragile.  It
has, for no particular reason, a header full of NUL bytes, which
some editors will through away.  Any change to contents without
the corresponding change to the header destroys the folder past
that point.  Etc.  And for all that, it doesn't buy you much.

Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: maximum() efficency

2006-03-27 Thread Arne Ludwig
Just for completeness: The functions in Steve's original post named
maximum calculate the minimum.

Also, timing-wise, on my machine with a random list of 20 integers
Steve's iteration version and Mitja's version are about equal, the
system built-in is equal or slightly slower, and Paul's version about
3-4x slower. If the comparison function is very complex, the mileage
may vary of course.

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


Re: COM server / COM client

2006-03-27 Thread Larry Bates
Dan wrote:
 Does the COM server created with python have to be compiled? I have the
 need to integrate database access but, I can not have any proprietary
 software. Meaning no compiled programs built by me. So, if python can
 do com clients and servers without compiling, Im good. But I don't know
 if that is possible. The ctypes example implies that it must be
 compiled using py2exe. I know the clients don't have to be compiled.
 What about the server?
 

Sounds like you are walking a fine line on the no compiled programs
written by me thing.

Py2exe doesn't REALLY compile python.  Rather it PACKAGEs it into an
.exe file with any required external routines in library.zip.  With
proper bundle option, you can put everything into the .exe file itself
(except for mscvrt71.dll).  Just makes it easier to distribute and
you don't have to install Python.  Using py2exe and Inno Setup (my
recommendation) makes it easier to distribute your program to multiple
computers.

That said, no you don't have to compile.  If you don't create .exe
by using py2exe you must have Python on the machine and must set up
any supporting libraries (like ctypes) in lib/site-packages.

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


encode short string as filename (unix/windows)

2006-03-27 Thread robert
want to encode/decode an arbitrary short 8-bit string as save filename. 
is there a good already builtin encoding to do this (without too much 
inflation) ? or re.sub expression?

or which characters are not allowed in filenames on typical OS?

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


Re: Accessing func_name from inside a function

2006-03-27 Thread Scott David Daniels
Eyal Lotem wrote:
 By the way, the real problem here is referencing by name, rather than
 using true references. Which is the result of using a textual language.
 The real solution would be to store real-references to the function and
 only present the name in a graphical interface.

There is a problem with this attitude (to which I used to subscribe).
Just as what constitutes a mathematical proof is a social agreement
among mathematicians, programmers need to be able to read programs
by other programmers.  People do not communicate in data structures.
I worked with LML, a lazy ML variant that (among other things) allowed
specification of the print form of structures.  I wound up debugging
(for a nasty 12 hours) a program which printed identically to the
correct program, but was not, in fact, the correct program.  That one
experience has convinced me that programs are defined in print, not
structures.

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


Re: encode short string as filename (unix/windows)

2006-03-27 Thread Grant Edwards
On 2006-03-27, robert [EMAIL PROTECTED] wrote:
 want to encode/decode an arbitrary short 8-bit string as save filename. 
 is there a good already builtin encoding to do this (without too much 
 inflation) ? or re.sub expression?

 or which characters are not allowed in filenames on typical OS?

Under unix, / and NULL aer not allowed.

There are other characters that are not recommended, but those
are the only two that are not allowed.

-- 
Grant Edwards   grante Yow!  .. the MYSTERIANS are
  at   in here with my CORDUROY
   visi.comSOAP DISH!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: encode short string as filename (unix/windows)

2006-03-27 Thread nikie
 want to encode/decode an arbitrary short 8-bit string as save filename.
 is there a good already builtin encoding to do this (without too much
 inflation) ? or re.sub expression?

 or which characters are not allowed in filenames on typical OS?

On Windows, / \ : * ? | are forbidden, and the name can't be
empty.

Using urlsafe_b64encode/...decode should work on any platform.

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


Re: encode short string as filename (unix/windows)

2006-03-27 Thread Diez B. Roggisch
robert wrote:

 want to encode/decode an arbitrary short 8-bit string as save filename.
 is there a good already builtin encoding to do this (without too much
 inflation) ? or re.sub expression?

Yuu could use the base64-encoder. Disadvantage is clearly that you can't
easily read your original text. Alternatively, three is that encoding that
is used by e.g. emails if you have an umlaut in a name. I _think_ it is
called puny-code, but I'm not sure how and if you can use that from within
python - google yourself :)

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


Re: maximum() efficency

2006-03-27 Thread Paul McGuire
Arne Ludwig [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Just for completeness: The functions in Steve's original post named
 maximum calculate the minimum.

 Also, timing-wise, on my machine with a random list of 20 integers
 Steve's iteration version and Mitja's version are about equal, the
 system built-in is equal or slightly slower, and Paul's version about
 3-4x slower. If the comparison function is very complex, the mileage
 may vary of course.


Arne -

The version I posted (which is not mine by the way, but I've lost the
original citation) becomes much more competitive when run with psyco.  With
your list of 200,000 integers, I believe it will outpace even the C library
built-ins.

-- Paul


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


Re: encode short string as filename (unix/windows)

2006-03-27 Thread Jean-Paul Calderone
On Mon, 27 Mar 2006 18:13:17 +0200, Diez B. Roggisch [EMAIL PROTECTED] 
wrote:
robert wrote:

 want to encode/decode an arbitrary short 8-bit string as save filename.
 is there a good already builtin encoding to do this (without too much
 inflation) ? or re.sub expression?

Yuu could use the base64-encoder. Disadvantage is clearly that you can't
easily read your original text. Alternatively, three is that encoding that
is used by e.g. emails if you have an umlaut in a name. I _think_ it is
called puny-code, but I'm not sure how and if you can use that from within
python - google yourself :)

punycode is used by dns.  A commonly used email codec is quoted-printable.  
Here's an example of each:

 u'Helló world'.encode('utf-8').encode('quopri')
'Hell=C3=B3=20world'
 u'Helló world'.encode('punycode')
'Hell world-jbb'
 

Note the extra trip through utf-8 for quoted-printable, as it is not 
implemented in Python as a character encoding, but a byte encoding, so you 
cannot (safely) apply it to a unicode string.

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

Re: COM object pointer cast

2006-03-27 Thread Simon Brunning
On 27 Mar 2006 00:19:09 -0800, Axel Bock [EMAIL PROTECTED] wrote:
 I am fooling around with the Python-COM bridge, and I have a little
 question with that.

 In the component I am using is a method which will return an Entry
 object - basically. In truth it returns some object which inherits from
 entry, and I know which one, but - as said - the method will only
 return the IEntry interface pointer. Now I would like to cast that one
 to the one I need :) . Is there an easy way to do it, or do I have to
 use the QueryInterface-method to get what I want?

There's an easy way - use win32com.client.CastTo(). See the
convert_tracks.py script on this page -
http://www.brunningonline.net/simon/blog/archives/001742.html for an
example.

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


Re: object references

2006-03-27 Thread Steven D'Aprano
On Sat, 25 Mar 2006 21:33:24 -0800, DrConti wrote:

 Dear Python developer community,
 I'm quite new to Python, so perhaps my question is well known and the
 answer too.
 
 I need a variable alias ( what in other languages you would call  a
 pointer (c) or a reference (perl))

Others have given you reasons why you can't do this, or shouldn't do this.
In general, I agree with them -- change your algorithm so you don't
need indirect references. 

But if you can't get away from it, here is another work-around that might
help:



 class ObjectClass:
Test primary Key assignment 
 
 if __name__ == __main__:
 
   ObjectClassInstantiated=ObjectClass()
   ObjectClassInstantiated.AnAttribute='First PK Elem'
   ObjectClassInstantiated.AnotherOne='Second PK Elem'
   ObjectClassInstantiated.Identifier=[]
   
 ObjectClassInstantiated.Identifier.append(ObjectClassInstantiated.AnAttribute)
   
 ObjectClassInstantiated.Identifier.append(ObjectClassInstantiated.AnotherOne)
   print ObjectClassInstantiated.Identifier
   ObjectClassInstantiated.AnAttribute='First PK Elem Changed'
   print ObjectClassInstantiated.Identifier


# helper class
class Indirect:
def __init__(self, value):
self.value = value
def mutate(self, newvalue):
self.value = newvalue
def __eq__(self, other):
return self.value == other
def __repr__(self):
return - %r % self.value

instance = ObjectClass()
instance.attribute = Indirect('First PK Elem')
instance.another_attribute = Indirect('Second PK Elem')
instance.identifier = [instance.attribute, instance.another_attribute]

print instance.identifier
instance.attribute.mutate('First PK Elem Changed')
print instance.identifier

which prints 

[- 'First PK Elem', - 'Second PK Elem']
[- 'First PK Elem Changed', - 'Second PK Elem']

as requested.


-- 
Steven.

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


Re: COM server / COM client

2006-03-27 Thread Dan
Sounds like you are walking a fine line on the no compiled programs
written by me thing.

Yeah, I hate it. I could have written a C++ server, client application
etc.. very easily. Instead, I have had to write javascript on the
client to embed in an html page to view, insert,delete etc.. SQL server
table over the intranet via ADO. But, requirements are requirements.
Besides, I am learning a lot and thats always good. We are integrators,
so our clients specifications are always vague and with an eye toward
leaving themselves outs whenever possible.

That said, no you don't have to compile.  If you don't create .exe
by using py2exe you must have Python on the machine and must set up
any supporting libraries (like ctypes) in lib/site-packages.

That won't be a problem since all of the clients will be our own pc's
so we will be installing python on each.

What about activeX controls? Will I be able to create an activeX client
control using python for embedding into a web document, again without
compiling ? I know I could use Javascript to gain access to the python
server but I don't know if it will allow me to subscribe to the events
properly. In the ADO interfaces at least you can not receive the events
fired from the server via Javascript or VBScript. Thanks, Dan

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


Re: encode short string as filename (unix/windows)

2006-03-27 Thread Steven D'Aprano
On Mon, 27 Mar 2006 08:14:07 -0800, nikie wrote:

 want to encode/decode an arbitrary short 8-bit string as save filename.
 is there a good already builtin encoding to do this (without too much
 inflation) ? or re.sub expression?

 or which characters are not allowed in filenames on typical OS?
 
 On Windows, / \ : * ? | are forbidden, and the name can't be
 empty.

Windows also has a number of reserved names that you can't use. However,
in general, it is best to ignore that and just let Windows raise an error
if it chooses. But for completeness, here is the the canonical list of
prohibited file names and characters for Windows:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/naming_a_file.asp

or http://makeashorterlink.com/?I2B853DDC



-- 
Steven.

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


Re: encode short string as filename (unix/windows)

2006-03-27 Thread robert
Jean-Paul Calderone wrote:


 punycode is used by dns.  A commonly used email codec is 
 quoted-printable.  Here's an example of each:
 
 u'Helló world'.encode('utf-8').encode('quopri')
'Hell=C3=B3=20world'
 u'Helló world'.encode('punycode')
'Hell world-jbb'

 Note the extra trip through utf-8 for quoted-printable, as it is not 
 implemented in Python as a character encoding, but a byte encoding, so 
 you cannot (safely) apply it to a unicode string.
 
 Jean-Paul
 

  u'Helló world\\/\x00'.encode('punycode')
'Hell world\\/\x00-elb'
  u'Helló world\\/\x00'.encode('utf-8').encode('quopri')
'Hell=C3=B3=20world\\/=00'
 


that doesn't remove \ /
that other base.. things similar

so finally found me reggae'ing :-(  , but this provides minimal optical 
damage for common strings ...


def encode_as_filename(s):
 def _(m): return +%02X % ord(m.group(0))
 return re.sub('[\x00/*?:|+\n]',_,s)
def decode_from_filename(s):
 def _(m): return chr(int(m.group(0)[1:],16))
 return re.sub(\\+[\dA-F]{2,2},_,s)


  newsletter.encode_as_filename('[EMAIL PROTECTED]/\\+\n\x00:+test')
'[EMAIL PROTECTED]'
  newsletter.decode_from_filename(_)
'[EMAIL PROTECTED]/\\+\n\x00:+test'
 


Robert


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

using a perl mod

2006-03-27 Thread David Bear
almost 41 million hits from google about using perl mod's in python was a
bit discouraging...So, I thought about asking humans.

There are some perl modules written to manage files, acls, etc in afs.
Rather than wrapping the c-compiled versions of afs commands in sys.popen
and parsing the output, I was hoping to use the perl mods and the perl
objects returned by these mods in python -- since I can't stand reading
perl.

The question then becomes, are there any python modules that encapsulate and
map perl objects into python object?
-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: encode short string as filename (unix/windows)

2006-03-27 Thread robert
Steven D'Aprano wrote:

 On Mon, 27 Mar 2006 08:14:07 -0800, nikie wrote:
 
 
want to encode/decode an arbitrary short 8-bit string as save filename.
is there a good already builtin encoding to do this (without too much
inflation) ? or re.sub expression?

or which characters are not allowed in filenames on typical OS?

On Windows, / \ : * ? | are forbidden, and the name can't be
empty.
 
 
 Windows also has a number of reserved names that you can't use. However,
 in general, it is best to ignore that and just let Windows raise an error
 if it chooses. But for completeness, here is the the canonical list of
 prohibited file names and characters for Windows:
 
 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/naming_a_file.asp
 
 or http://makeashorterlink.com/?I2B853DDC
 

thanks. infact to avoid COMx etc. I have also to prepend and remove a 
char like _  on encode/decode in addition to what I just posted

Robert

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


front end GUI

2006-03-27 Thread DataSmash
I'm looking for software to create a simple GUI to execute python code
for users in the office.
The GUI would need a couple text boxes for user input and some option
buttons and check boxes.
Can anyone recommend free software that doesn't require a huge learning
curve?
My python skills are probably a 3 or 4 on a scale from 1 to 10.

Thanks for your help!
R.D.

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


Where does Python look for libraries?

2006-03-27 Thread ACB
I have been trying to get the gdmodule installed and have run into an issue.
When I import gd I get the following error.

 import gd
Traceback (most recent call last):
  File stdin, line 1, in ?
  File /usr/local/lib/python2.3/site-packages/gd.py, line 10, in ?
import _gd
ImportError: /usr/local/lib/libgd.so.2: Undefined symbol libiconv_open

But, when I run
nm libiconv.so
in the directory with the iconv library I get an entry like this
00011fe0 T libiconv_open

so I know the functionality is there.  So, my question.  Does python have a 
way to add search directories for locating libraries?

Thanks. 


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


CGI redirection: let us discuss it further

2006-03-27 Thread Sullivan WxPyQtKinter
I am now programming python scripts for CGI environment. The
redirection has been discussed in this forum for over one hundred
times. I have seen most of them, but still have some questions:

1. Are there any method (in python of course) to redirect to a web page
without causing a Back button trap(ie, when user click the back
button on their web browser, they are redirect to their current page,
while their hope is probably to go back to the last page they have
seen, rather than the redirection page with a Location: url head and
blank content.)?

2. Are there any method to use relative path, rather than full absolute
URI path in Location: url? It is very essential for later transplant
work, e.g.,transplant a folder of cgi scripts from one web server to
another, with different URL.

Thank you.

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


Re: Difference between 'is' and '=='

2006-03-27 Thread filipwasilewski
Clemens Hepper wrote:
 It's strange: python seem to cache constants from 0 to 99:

That's true. The Python api doc says that Python keeps an array of
integer objects for all integers between -1 and 100. See
http://docs.python.org/api/intObjects.html.
This also seems to be true for integers from -5 to -2 on (ActiveState)
Python 2.4.2.

-- 
fw

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


Re: using a perl mod

2006-03-27 Thread Paddy
Don't know if there is a way to call perl from Python but the perl
inline python module allows you to call perl from python from within an
outer perl interpreter.

Thts what I make of the following anyway:

  http://aspn.activestate.com/ASPN/CodeDoc/Inline-Python/Python.html

- Paddy.

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


Re: using a perl mod

2006-03-27 Thread Paddy
There is also:PyPerl at:
  http://search.cpan.org/dist/pyperl/perlmodule.pod

But you need to check if it is current.

- Pad.

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


Re: Difference between 'is' and '=='

2006-03-27 Thread Donn Cave
In article [EMAIL PROTECTED],
 Diez B. Roggisch [EMAIL PROTECTED] wrote:
...
 So - your conclusion is basically right: use is on (complex) objects, not on
 numbers and strings and other built-ins. The exception from the rule is
 None - that should only exist once, so
 
 foo is not None
 
 is considered better style than foo == None.

But even better style is just `foo' or `not foo'.  Or not,
depending on what you're thinking.

The key point between `is' and `==' has already been made -
  - use `is' to compare identity
  - use `==' to compare value

It's that simple, and it's hard to add to this without
potentially layering some confusion on it.  While Python's
implementation makes the use of identity with small numbers
a slightly more complicated issue, there isn't a lot of
practical difference.  To take a common case that has already
been mentioned here, if I define some constant symbolic values
as small integers, as long as I take care that their values
are distinct, I can reasonably use identity and ignore this
technical weakness.  I can assume that no one is going to
supply randomly selected integers in this context.  Meanwhile,
the use of identity clarifies the intent.

Depending, of course, on what the intent may be, which brings
us to None, and a point about values in Python that was brought
to a fairly brilliant light some years back by someone we don't
hear from often here any more, unfortunately.

  - use `is' to compare identity
  - use `==' to compare value
  - use neither to test for `somethingness'

I'm not going to try to elucidate the theory of something and
nothing in Python, but suffice it to say that there are places
where it may be better to write

if not expr:

than

if expr is None:

or worse yet,

if expr == False:

That's what I think, anyway.

   Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: front end GUI

2006-03-27 Thread Diez B. Roggisch
DataSmash schrieb:
 I'm looking for software to create a simple GUI to execute python code
 for users in the office.
 The GUI would need a couple text boxes for user input and some option
 buttons and check boxes.
 Can anyone recommend free software that doesn't require a huge learning
 curve?
 My python skills are probably a 3 or 4 on a scale from 1 to 10.

Use the shipped tkinter.

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


pysqlite

2006-03-27 Thread abcd
anyone have v2.x of pysqlite that I could download?  the website is
down for a hardware upgrade with no date as to when it will be back.

I checked sourceforge but there are no files there to download.

thanks.

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


Re: CGI redirection: let us discuss it further

2006-03-27 Thread Sybren Stuvel
Sullivan WxPyQtKinter enlightened us with:
 1. Are there any method (in python of course) to redirect to a web
 page without causing a Back button trap(ie, when user click the
 back button on their web browser, they are redirect to their current
 page, while their hope is probably to go back to the last page they
 have seen, rather than the redirection page with a Location: url
 head and blank content.)?

I don't know if this is possible using CGI. I use CherryPy, and it has
an InternalRedirect method. Same is true for mod_python and Apache.

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: Programming challenge: wildcard exclusion in cartesian products

2006-03-27 Thread funkyj
Going in a slightly different direction ...

There has been lots of published work on how to create efficient FSMs
from regexps.  Generally these FSMs are used for pattern matching (i.e.
does string 's' match regexp 'e'?).

Is there any corresponding literature on the topic addressed by the
OP's challenge of generating the languaged defined by a regexp (or the
complement of that regexp)?

  --jfc

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


Re: pysqlite

2006-03-27 Thread abcd
Dennis Lee Bieber wrote:
 On 27 Mar 2006 10:17:21 -0800, abcd [EMAIL PROTECTED] declaimed
 the following in comp.lang.python:

  anyone have v2.x of pysqlite that I could download?  the website is
  down for a hardware upgrade with no date as to when it will be back.
 
   Source or binary (or everything)? Architecture?

I need v 2.x for windows, running python v2.4

u can email it to me, codecraig _A_T_ gmail _D_O_T_ com

thx

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


problems with looping, i suppose

2006-03-27 Thread John Salerno
Here's an exercise I was doing to guess a number from 1-100. Just for 
fun (ha ha) I decided to add some error checking too, and now when I run 
it, the DOS prompt flashes real quick and disappears. At first, I had 
just the top try/except block and not the second one, and that worked 
(as far as it would work), but after adding the second try/except, it 
has this problem. I'm sure it has something to do with the looping and 
the breaks/continues.

I'd appreciate any help on this, and also any suggestions for programs 
that let you step through code to debug it (I'm used to Visual Studio). 
I have SPE installed at home, but not here at work so I can't try it 
right now. I assume it has a debugger.

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


Re: problems with looping, i suppose

2006-03-27 Thread John Salerno
John Salerno wrote:
 Here's an exercise I was doing 

This might help:

import random

number = random.choice(range(1, 100))
tries = 0

while True:
 try:
guess = input('Enter a number between 1 and 100: ')
break
 except NameError:
print 'Invalid number\n'
continue

while True:
tries += 1
try:
if guess == number:
print 'Congratulations! You got it in', tries, 'guess(es).'
break
elif guess  number:
guess = input('Too low. Try again: ')
elif guess  number:
guess = input('Too high. Try again: ')
 except NameError:
print 'Invalid number\n'
continue

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


Re: object references

2006-03-27 Thread bruno at modulix
Steven D'Aprano wrote:
 On Sat, 25 Mar 2006 21:33:24 -0800, DrConti wrote:
 
 
Dear Python developer community,
I'm quite new to Python, so perhaps my question is well known and the
answer too.

I need a variable alias ( what in other languages you would call  a
pointer (c) or a reference (perl))
 
 
 Others have given you reasons why you can't do this, or shouldn't do this.
 In general, I agree with them -- change your algorithm so you don't
 need indirect references. 
 
 But if you can't get away from it, here is another work-around that might
 help:

(snip)

And another one, that mess less with attributes (but more with lookup
rules - use it at your own risks !-):

class CompoundAttribute(object):
  def __init__(self, *names):
self._names = names
  def __get__(self, obj, objtype):
if obj is None:
   return self
return [getattr(obj, name) for name in self._names]
  def __set__(self, obj, value):
raise TypeError, object '%s' does not support assignement % self

import types


class ObjectClass(object):
  def __getattribute__(self, name):
v = object.__getattribute__(self, name)
if not isinstance(v, types.FunctionType) \
   and hasattr(v, '__get__'):
  return v.__get__(self, self.__class__)
return v


 instance = ObjectClass()
  instance.attribute = 'First PK Elem'
  instance.another_attribute = 'Second PK Elem'
  instance.identifier = CompoundAttribute('attribute', 'another_attribute')

NB : Sorry, not tested.


-- 
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: problems with looping, i suppose

2006-03-27 Thread John Salerno
John Salerno wrote:
 Here's an exercise I was doing to guess a number from 1-100. 

Here's another question that is related:

while True:
 year = raw_input('Enter year (or other character to quit): ')

 try:
year = int(year)
 except NameError:
break

 if (year % 4 == 0) and (year % 100 != 0 or year % 400 == 0):
print year, 'is a leap year.\n'
 else:
print year, 'is not a leap year.\n'

raw_input()

This works as expected, except that if you enter any character other 
than a number, the program just quits. Why doesn't it still execute the 
raw_input function and pause? I think this is what is happening in the 
other exercise too, but I don't know why. If you break out of the loop, 
should it still pause at raw_input?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problems with looping, i suppose

2006-03-27 Thread [EMAIL PROTECTED]
Just barely looked the code answer:
check you scope on the second try block.

if that doesn't work...
I'll read it for real :)

Try PyDev plugin  with eclipse - it's served me fairly well, but I did
come from Java - so I'm an eclipse fan already.

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


Re: object references

2006-03-27 Thread Scott David Daniels
DrConti wrote:
 I need a variable alias ( what in other languages you would call  a
 pointer (c) or a reference (perl))
Or, you think you need it.

 I read some older mail articles and I found that the offcial position
 about that was that variable referencing wasn't implemented because
 it's considered bad style.
Generally, yes.  The line goes, roughly, You've decided on a solution
and are twisting your problem to fit it.


 There was also a suggestion to write a real problem where referencing
 is really needed.  I have one...:
 
 I'm trying to  generate dynamically class methods which works on
 predefined sets of object attributes.
 one of these is the set of attributes identfying uniquely the object
 (primary key).

First, this is _not_ a real problem; this is a bunch of code.  The
real problem request is to provide an actual use case, not some code
where you want to write what you want to write.

 A naïve attempt to do the job:
 
 class ObjectClass:
Test primary Key assignment 
 
 if __name__ == __main__:
 
   ObjectClassInstantiated=ObjectClass()
   ObjectClassInstantiated.AnAttribute='First PK Elem'
   ObjectClassInstantiated.AnotherOne='Second PK Elem'
   ObjectClassInstantiated.Identifier=[]
   
 ObjectClassInstantiated.Identifier.append(ObjectClassInstantiated.AnAttribute)
   
 ObjectClassInstantiated.Identifier.append(ObjectClassInstantiated.AnotherOne)
   print ObjectClassInstantiated.Identifier
   ObjectClassInstantiated.AnAttribute='First PK Elem Changed'
   print ObjectClassInstantiated.Identifier

If you insist on this kind of approach, you could use a pair of
an object, and an attribute name as a reference, and use getattr
and setattr to access the identified attribute.  _But__ I emphasize
that you are thinking about your problem from the point of view
of a solution, not from the point of view of the problem.

You'd probably like this:

 class Example(object):
  Test primary Key assignment 

 def __init__(self, one, two, other):
 self.one = one
 self.two = two
 self.other = other

 def __repr__(self):
 return '%s(%r, %r, %r)' % (
 type(self).__name__, self.one, self.two, self.other)


 if __name__ == __main__:
 eg = Example(3.1415, 3+4j, 'pi')
 ref_attr = eg, 'one'
 ref_other = eg, 'other'
 print eg, getattr(*ref_attr), getattr(*ref_other)
 eg.one = 'First PK Elem'
 print eg, getattr(*ref_attr), getattr(*ref_other)
 setattr(*ref_other + (u'Strangely',))
 print eg, getattr(*ref_attr), getattr(*ref_other)

But you might consider this:

 class Another(Example):
  Test primary Key assignment 
 key = ('one', 'two')


 def getkey(v):
 return [getattr(v, part) for part in v.key]

 if __name__ == __main__:
 eg2 = Another(3.1415, 3+4j, 'pi')
 print eg2, getkey(eg2)
 eg2.one = 'First PK Elem'
 print eg2, getkey(eg2)
 setattr(eg2, 'two', u'Strangely')
 print eg2, getkey(eg2)


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


  1   2   3   >