Hamburg Pythoneers Monthly Meeting: Wed, Apr 11

2007-03-09 Thread Helge Stahlmann
+ Hamburg Python User Group April Meeting +

I am pleased to announce our next user group meeting:

Wednesday, April 11, 2007 at 7:00pm

Location: DDD Design GmbH, Jarrestrasse 46, 22303 Hamburg.

Session highlight: Aspect-oriented programming with AOPython

RSVP now at http://python.meetup.com/179/calendar/5549826/

If you're interested in learning more, please visit our website at
meetup.com: http://python.meetup.com/179/


Additional links:

RSS Newsfeed:
feed://www.meetup.com/rss/g/python/179/new/

Group Calendar RSS:
feed://python.meetup.com/179/calendar/rss/The+Hamburg+Python+User+Group/

iCal:
webcal://python.meetup.com/179/calendar/ical/The+Hamburg+Python+User 
+Group/


+ Hamburg Python User Group - Treffen im April +

Ich freue mich, an dieser Stelle unser nächstes Meeting ankündigen zu  
dürfen:

Mittwoch, 11. April 2007 um 19 Uhr

Veranstaltungsort: DDD Design GmbH, Jarrestrasse 46, 22303 Hamburg.

Highlight: Aspektorientierte Programmierung mit AOPython

Anmeldungen werden unter
http://python.meetup.com/179/calendar/5549826/ entgegengenommen.

Weitere Informationen finden sich auf unserer Webseite bei meetup.com:
http://python.meetup.com/179/


Weitere Links:

RSS Newsfeed:
feed://www.meetup.com/rss/g/python/179/new/

Gruppen Kalender RSS:
feed://python.meetup.com/179/calendar/rss/The+Hamburg+Python+User+Group/

iCal:
webcal://python.meetup.com/179/calendar/ical/The+Hamburg+Python+User 
+Group/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


PyWeek #4 in April!

2007-03-09 Thread Richard Jones
PyWeek #4 will run in the first week of April:

 Start: 00:00UTC Sunday 1st April
Finish: 00:00UTC Sunday 8th April
 

REGISTRATION IS OPEN

Visit the PyWeek website for more information: 

  http://pyweek.org/ 


THE PYWEEK CHALLENGE: 

- Invites all Python programmers to write a game in one week from scratch 
  either as an individual or in a team, 
- Is intended to be challenging and fun, 
- Will hopefully increase the public body of python game tools, code and 
  expertise, 
- Will let a lot of people actually finish a game, and 
- May inspire new projects (with ready made teams!) 

Entries must be developed during the challenge, and must incorporate some 
theme decided at the start of the challenge. The rules for the challenge are 
at: 

  http://media.pyweek.org/static/rules.html 


Richard 

-- 
Visit the PyWeek website:  http://pyweek.org/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: Python books?

2007-03-09 Thread wesley chun
On Mar 8, 7:06 pm, Tommy Nordgren [EMAIL PROTECTED] wrote:
 Could some kind soul please recommend a few textbooks on Python 2.5
 and it's class library?


it's not necessary to have a 2.5 book that can introduce you to the
modules of the Python Standard Library (not all modules are [or have]
classes so class library perhaps is too restrictive a term).

the most significant additions to the std library in 2.5 are:
ctypes, sqlite3, xml.etree (ElementTree), wsgiref, cProfile

altho they provide new functionality, there are plenty of existing
modules in the standard library that are worth learning.  the main
reference guides to the standard library modules and their attributes
include: Python in a Nutshell and Python Essential Reference, both in
addition to the online library reference.

my book, Core Python Programming, is revised to 2.5, but focuses on
teaching you the core part of the language, features, objects, memory
management, development, good practices, some advanced topic coverage,
and presents lots of exercises.  however, it is not an exhaustive
guide to the standard library.  to find out more about it, check out
the reviews and notes on amazon as well as the book's website (see
below).

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Core Python Programming, Prentice Hall, (c)2007,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com

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


Re: Configuration: Apache + mod_python

2007-03-09 Thread Danilo
On 8 Mrz., 22:23, [EMAIL PROTECTED] wrote:
 On Mar 9, 12:02 am, Danilo [EMAIL PROTECTED] wrote:



  On 8 Mrz., 12:18, [EMAIL PROTECTED] wrote:

   On Mar 8, 9:50 pm, Danilo [EMAIL PROTECTED] wrote:

Hi there,

is it possible to create a rewrite rule to send every server-request
to the directory /py? But only if the file does not exists on the
server.

This is my mod_python section of the apache config-file.

Location /py
SetHandler python-program
PythonHandler django.core.handlers.modpython
PythonPath ['/var/www/mydomain.com/htdocs/py'] + sys.path
SetEnv DJANGO_SETTINGS_MODULE myapp.settings
PythonDebug Off
/Location

   For the more general case of where a HTTP 404 error would otherwise be
   returned, indicating that a resource could not be found, as opposed to
   an actual physical file, you can just use:

 ErrorDocument 404 /py

   This would be simpler than using mod_rewrite. I can't remember though
   whether the handler when triggered in this case can change the
   response status to something other than 404.

   You could use mod_rewrite if you really must, but not sure how it
   would interact with virtual resources managed by some handler where no
   actual file exists. To be practical you would probably want to
   restrict the scope of mod_rewrite to specific contexts.

   Quoting an example from very good book The Definitive Guide to Apache
   mod_rewrite, you can do something similar to:

 RewriteEngine On
 # If its not here ...
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 # Look here instead ...
 RewriteRule ^/images/(.*) /pics/$1 [PT]

   In this case it is causing lookups for images to be made in two
   places, but your case wouldn't be much different.

   Graham

  The rewrite rule works, but now every request ist send to /py.
  This is my .conf:

  VirtualHost *
  DocumentRoot /var/www/mydomain.com/htdocs
  ServerName mydomain.com
  ServerAliaswww.mydomain.com

  Location /py
  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  PythonPath ['/var/www/mydomain.com/htdocs/py'] + sys.path
  SetEnv DJANGO_SETTINGS_MODULE myapp.settings
  PythonDebug Off
  /Location

  RewriteEngine On
  # If its not here...
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  # Look here instead...
  RewriteRule (.*) /py$1 [PT]

  ErrorLog /var/www/mydomain.com/logs/error.log
  CustomLog /var/www/mydomain.com/logs/access.log common
  /VirtualHost

  Any ideas what is wrong?

 I did say you would probably need to restrict the scope of the
 mod_rewrite rule to a specific context. In particular, put it inside
 of a Directory directive corresponding to the file system directory
 where your files live. Where you have it as the moment,
 REQUEST_FILENAME probably will not resolve to anything as Apache
 hasn't yet matched it to the filesystem. Thus:

   Directory /some/path/to/document/root

 RewriteEngine On
 # If its not here...
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 # Look here instead...
 RewriteRule (.*) /py$1 [PT]

   /Directory

 Graham

Thank you.

the RewriteCond just needs the absolute path:

RewriteEngine On
# If its not here...
RewriteCond /var/www/btsgroup.de/htdocs/%{REQUEST_FILENAME} !-f
RewriteCond /var/www/btsgroup.de/htdocs/%{REQUEST_FILENAME} !-d
# Look here instead...
RewriteRule (.*) /py$1 [PT]

Thanks
dan

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


Re: merits of Lisp vs Python

2007-03-09 Thread Terry Reedy

Alex Martelli [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
| later sold for mucho dinero) is an unabashed fan of Python; the XO
| (nee One Laptop Per Child, OLPC, and once known as the $100 laptop)
| uses Python as its preferred (only?-) application language, and it's
| slated to be the most widely distributed Python distro if it hits even
| half of its ambitious target-numbers...

The exciting part to me is that the somewhat inovative user inteface is 
writen in Python and intended to be hacked on by the users (kids) around 
the world.

tjr



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


Re: catching exceptions from an except: block

2007-03-09 Thread Duncan Booth
Gabriel Genellina [EMAIL PROTECTED] wrote:

 Not the *previous* exception, but the *current* one. You must be
 inside an  except clause to use a bare raise.
 
No, you don't have to be inside an except clause to use a bare raise.

A bare 'raise' will re-raise the last exception that was active in the 
current scope. That applies even outside the except clauses just so long 
as there has been an exception within the same function:

e.g.

def retry(fn, *args):
for attempt in range(3):
try:
return fn(*args)
except:
print retrying attempt, attempt+1
# If we get here we've had too many retries
raise

 import random
 def testfn():
if random.randint(0,3):
raise RuntimeError(oops)
return 42

 retry(testfn)
retrying attempt 1
retrying attempt 2
retrying attempt 3

Traceback (most recent call last):
  File pyshell#24, line 1, in module
retry(testfn)
  File pyshell#20, line 4, in retry
return fn(*args)
  File pyshell#23, line 3, in testfn
raise RuntimeError(oops)
RuntimeError: oops
 retry(testfn)
retrying attempt 1
retrying attempt 2
42
 retry(testfn)
42
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: catching exceptions from an except: block

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 04:49:59 -0300, Gerard Flanagan  
[EMAIL PROTECTED] escribió:

 Another version:

 import exceptions

As back in time as I could go (Python 1.5), exceptions were available as  
builtins...

 def onfailFalse(fn):
 def inner(*args, **kwargs):
 try:
 return fn(*args, **kwargs)
 except ABCException:
 return False
 return inner

 @onfailFalse
 def a(x):
 if x == 1:
 return 'function a succeeded'
 else:
 raise ABCException()

There is a serious flaw on this approach, the function can't return any  
false value (it would be treated as a failure).

-- 
Gabriel Genellina

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


2 new comment-like characters in Python to aid development?

2007-03-09 Thread dbhbarton
Had a thought that's grown on me. No idea if it's original or not- too
inexperienced in programming- but I guess there's no harm floating it
out there.

Python wins big on readability, and there's no doubt that context-
dependent text formatting in IDEs (keywords, strings, comments etc) is
a massive help too, therefore benefitting development and maintenance.
This idea is in a similar vein, especially for when scripts grow
large.

What if 2 new 'special' comment-like characters were added to Python?:


1. The WIP (Work In Progress) comment:

A '?' placed in the preceding whitespace of a line as a means of
quickly highlighting a line or block of code for special attention.
The interpreter simply ignores these characters, and executes the code
as if each WIP character wasn't there. The value-added comes from how
IDEs can exploit this to color the line or code block (in a
customisable fashion as with other context-dependent IDE formatting).

Thus...
?a=6 #This line gets highlighted.
?class MyClass: #This entire class gets highlighted.
def __init__(self):
self.val=3
?def MyFn(): #This entire function gets highlighted.
return 'x'
?for each in range(9): #This entire block gets highlighted.
print each

Simply delete the ? and the associated highlighting vanishes
immediately.
Indeed if the interpreter can tolerate one '?' then perhaps it can
also allow '??' and '???', letting the IDE color each differently for
some additional flexibility.

Applications...
Lets you highlight / un-highlight entire blocks with a single
keystroke: to record which part of a long script you're working on, or
which part needs development or optimization. IDEs could add
additional functionality if they chose: options to remove all wip
comments, or step through them, or even to automatically add WIP
comments (to highlight syntax errors, potentially infinite loops, or
rate-limiting code blocks, perhaps?)


2. The HALT comment:

A '!' at the start of a line, indicating the end of the script proper.
The interpreter would register this one, and ignore everything after
it, a bit like a sys.exit() call but also stopping it from picking
syntax errors after the HALT. IDEs could then 'grey out' (or 'yellow
out' or whatever) all following characters, including later HALT
comments.

Applications...
Lets you mask / unmask the tailing parts of a py script with a single
keystroke: potentially quite useful during the writing / testing phase
of coding when you might not want to run the whole thing, or as
another means of adding extensive comments to the end of a file. Could
also be rather handy in 'tutorial scripts' and the like...

E.g...
# Welcome to my Python Tutorial Script
my_string=Hello World
print my_string
! # Everything after this '!' is ignored and greyed out for now, but
when you're ready to move on to the next part of the tutorial script
just delete the '!' and run it again.
my_list=list(my_string)
print my_list
! # -- delete '!' when ready, etc etc
my_list_reversed=my_list[::-1]
print my_list_reversed


As far as I can see, neither of these would break backwards
compatibility and, like the @ decorator, if you don't like it, you
wouldn't have to use it. I don't know enough about the guts of Python
to say much about ease of implementation, but it doesn't seem like it
would be too hard.

Personally I'd use these a lot, but I'm a rank amateur so maybe I just
don't develop code properly.
That's it. Useful? Pointless? Dangerous? Stupid?


Dave.

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


Re: class attrdict

2007-03-09 Thread Hallvard B Furuseth
Alex Martelli writes:
 (...)
 class Namespace(object):
 (...)
 I might, if it weren't for the redundant if and the horribly buggy
 interference between separate instances -- which is why I wrote it,
 almost six years ago and without the bugs, as
 http://aspn.activestate.com/ASPN/Python/Cookbook/Recipe/52308 .

Nice one.  I gotta dig up the Cookbook again.

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


Re: catching exceptions from an except: block

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 05:52:35 -0300, Duncan Booth  
[EMAIL PROTECTED] escribió:

 Gabriel Genellina [EMAIL PROTECTED] wrote:

 Not the *previous* exception, but the *current* one. You must be
 inside an  except clause to use a bare raise.

 No, you don't have to be inside an except clause to use a bare raise.
 A bare 'raise' will re-raise the last exception that was active in the
 current scope. That applies even outside the except clauses just so long
 as there has been an exception within the same function:

Oh! Thanks, I didn't know that.
I tested it in the interpreter, outside any function, and the exception  
info was lost immediately, so I wrongly concluded that it lived shortly.

-- 
Gabriel Genellina

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


Re: class attrdict

2007-03-09 Thread Hallvard B Furuseth
Alex Martelli writes:
 You make a good point.  I do like being able to say foo.bar=baz rather
 than foo['bar']=baz in certain cases -- not so much to save 3 chars, but
 to avoid excessive punctuation; however, I don't really need this AND
 all of dict's power at the same time, so, I don't inherit from dict:-).

Yes.  Attribute syntax looks nicer, in particular one implements a sort
of private variables collected in a dict thing (e.g. SQL field names)
but still wants some dict functionality.

Another variant I thought of would be to prefix dict methods with '_'
(except those that already start with '__') and (if implemented as a
dict subtype) also override the original names with a sorry, use
_foo error method.

(Posting a bit sporatically currently, disappearing for a week again
now.)

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


Python not processing .pth files

2007-03-09 Thread pnm
This one I do not understand -- does anyone have any suggestions?


Newly compiled untweaked Python2.5 is not processing .pth files (as
far as I can see _any_ .pth files in site-packages. Example:.

+++

[EMAIL PROTECTED]:/usr/local/lib/python2.5/site-packages$ ls setup*
-rw-r--r--  1 root staff 306K Mar  8 20:44 setuptools-0.6c3-py2.5.egg
-rw-rw-rw-  1 root staff   29 Mar  8 23:57 setuptools.pth
[EMAIL PROTECTED]:/usr/local/lib/python2.5/site-packages$ cat setuptools.pth
./setuptools-0.6c3-py2.5.egg
[EMAIL PROTECTED]:/usr/local/lib/python2.5/site-packages$ python2.5
Python 2.5 (r25:51908, Mar  8 2007, 22:34:54)
[GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
Type help, copyright, credits or license for more information.
 import setuptools
Traceback (most recent call last):
  File stdin, line 1, in module
ImportError: No module named setuptools
 import sys
 sys.path
['', '/usr/local/lib/python25.zip', '/usr/local/lib/python2.5', '/usr/
local/lib/python2.5/plat-linux2', '/usr/local/lib/python2.5/lib-tk', '/
usr/local/lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/site-
packages']


+

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


Pb with descriptor and super ...

2007-03-09 Thread Erwan Adam
Hi all,

I have a problem with the use of descriptors
and super. The file is :

# ---

class Desc(object):
 def __init__(self, class_name):
 self.class_name = class_name
 return
 def __get__(self, obj, typ):
 print Desc.__get__ : class_name is %s, obj is %s and typ is 
%s%(self.class_name, obj, typ)
 return
 pass

class A(object):
 attr = Desc(A)
 pass

class B(A):
 attr = Desc(B)
 pass

b = B()

print ---
print Getting b.attr ...
print I hope that  : class_name is B, obj is b and typ is B
b.attr
print ---
print Getting super(B, b).attr ...
print I hope that  : class_name is A, obj is b and typ is A but it is 
not the case !
super(B, b).attr
print ---

# ---

and the result is :

---
Getting b.attr ...
I hope that  : class_name is B, obj is b and typ is B
Desc.__get__ : class_name is B, obj is __main__.B object at 0xb7b1f8ec 
and typ is class '__main__.B'
---
Getting super(B, b).attr ...
I hope that  : class_name is A, obj is b and typ is A but it is not the 
case !
Desc.__get__ : class_name is A, obj is __main__.B object at 0xb7b1f8ec 
and typ is class '__main__.B'
---

I expected that when getting super(B, b).attr, typ is A, but it is not
the case ...

python used :

[EMAIL PROTECTED] /home/adam/Work/Python] python
Python 2.4.3 (#2, Sep 18 2006, 21:07:35)
[GCC 4.1.1 20060724 (prerelease) (4.1.1-3mdk)] on linux2
Type help, copyright, credits or license for more information.
 


Best regards,


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


Re: Python books?

2007-03-09 Thread Ralf Schönian
Have a look at: Core python programming from Wesley J. Chun printed by 
Prentice Hall.

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


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 06:14:46 -0300, [EMAIL PROTECTED] escribió:

 A '?' placed in the preceding whitespace of a line as a means of
 quickly highlighting a line or block of code for special attention.
 The interpreter simply ignores these characters, and executes the code
 as if each WIP character wasn't there. The value-added comes from how
 IDEs can exploit this to color the line or code block (in a
 customisable fashion as with other context-dependent IDE formatting).

This could be implemented without new syntax: just make your editor  
recognize some special comments, and apply the highlighting to the  
following block. By example,

# XXX Remove this when FuruFaifa is fixed to always provide
# XXX the names in the same order
names.sort()
names.reverse()

if names==oldnames:
...

would highlight the first 4 lines (let's say, up to the next blank line or  
dedent).

 2. The HALT comment:

 A '!' at the start of a line, indicating the end of the script proper.
 The interpreter would register this one, and ignore everything after
 it, a bit like a sys.exit() call but also stopping it from picking
 syntax errors after the HALT. IDEs could then 'grey out' (or 'yellow
 out' or whatever) all following characters, including later HALT
 comments.

You accidentally type a ! somewhere, and your module stops working - not  
so good :( and worse, hard to find.

I sometimes use '''this string marks''' to ignore whole blocks of code. It  
works fine unless the block already contains the same kind of  
triple-quoted string...

 As far as I can see, neither of these would break backwards
 compatibility and, like the @ decorator, if you don't like it, you
 wouldn't have to use it. I don't know enough about the guts of Python
 to say much about ease of implementation, but it doesn't seem like it
 would be too hard.

The main problem with new syntax is breaking compatibility with older  
versions, and I doubt it's worth the pain just for highlighting or playing  
interactively, so you don't have a great chance of them being  
implemented...

-- 
Gabriel Genellina

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


Re: Configuration: Apache + mod_python

2007-03-09 Thread Graham Dumpleton
On Mar 9, 7:09 pm, Danilo [EMAIL PROTECTED] wrote:
 On 8 Mrz., 22:23, [EMAIL PROTECTED] wrote:



  On Mar 9, 12:02 am, Danilo [EMAIL PROTECTED] wrote:

   On 8 Mrz., 12:18, [EMAIL PROTECTED] wrote:

On Mar 8, 9:50 pm, Danilo [EMAIL PROTECTED] wrote:

 Hi there,

 is it possible to create a rewrite rule to send every server-request
 to the directory /py? But only if the file does not exists on the
 server.

 This is mymod_pythonsection of the apache config-file.

 Location /py
 SetHandler python-program
 PythonHandler django.core.handlers.modpython
 PythonPath ['/var/www/mydomain.com/htdocs/py'] + sys.path
 SetEnv DJANGO_SETTINGS_MODULE myapp.settings
 PythonDebug Off
 /Location

For the more general case of where a HTTP 404 error would otherwise be
returned, indicating that a resource could not be found, as opposed to
an actual physical file, you can just use:

  ErrorDocument 404 /py

This would be simpler than using mod_rewrite. I can't remember though
whether the handler when triggered in this case can change the
response status to something other than 404.

You could use mod_rewrite if you really must, but not sure how it
would interact with virtual resources managed by some handler where no
actual file exists. To be practical you would probably want to
restrict the scope of mod_rewrite to specific contexts.

Quoting an example from very good book The Definitive Guide to Apache
mod_rewrite, you can do something similar to:

  RewriteEngine On
  # If its not here ...
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  # Look here instead ...
  RewriteRule ^/images/(.*) /pics/$1 [PT]

In this case it is causing lookups for images to be made in two
places, but your case wouldn't be much different.

Graham

   The rewrite rule works, but now every request ist send to /py.
   This is my .conf:

   VirtualHost *
   DocumentRoot /var/www/mydomain.com/htdocs
   ServerName mydomain.com
   ServerAliaswww.mydomain.com

   Location /py
   SetHandler python-program
   PythonHandler django.core.handlers.modpython
   PythonPath ['/var/www/mydomain.com/htdocs/py'] + 
   sys.path
   SetEnv DJANGO_SETTINGS_MODULE myapp.settings
   PythonDebug Off
   /Location

   RewriteEngine On
   # If its not here...
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   # Look here instead...
   RewriteRule (.*) /py$1 [PT]

   ErrorLog /var/www/mydomain.com/logs/error.log
   CustomLog /var/www/mydomain.com/logs/access.log common
   /VirtualHost

   Any ideas what is wrong?

  I did say you would probably need to restrict the scope of the
  mod_rewrite rule to a specific context. In particular, put it inside
  of a Directory directive corresponding to the file system directory
  where your files live. Where you have it as the moment,
  REQUEST_FILENAME probably will not resolve to anything as Apache
  hasn't yet matched it to the filesystem. Thus:

Directory /some/path/to/document/root

  RewriteEngine On
  # If its not here...
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  # Look here instead...
  RewriteRule (.*) /py$1 [PT]

/Directory

  Graham

 Thank you.

 the RewriteCond just needs the absolute path:

 RewriteEngine On
 # If its not here...
 RewriteCond /var/www/btsgroup.de/htdocs/%{REQUEST_FILENAME} !-f
 RewriteCond /var/www/btsgroup.de/htdocs/%{REQUEST_FILENAME} !-d
 # Look here instead...
 RewriteRule (.*) /py$1 [PT]

Doing that would probably be considered bad practice. I think the
problem was I neglected to mention you would have to change your
RewriteRule to add a slash when used in Directory directive. Ie., use:

Directory /var/www/btsgroup.de/htdocs

RewriteEngine On
# If its not here...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Look here instead...
RewriteRule (.*) /py/$1 [PT]

/Directory

Note the slash after /py.

This works for me when I test it.


Graham

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


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Nick Craig-Wood
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  What if 2 new 'special' comment-like characters were added to Python?:
 
 
  1. The WIP (Work In Progress) comment:

I use # FIXME for this purpose or /* FIXME */ in C etc.

I have an emacs macro which shows it up in bright red / yellow text so
it is easy to see and the company has a system which makes a web page
with a list of all the FIXMEs on.

FIXME is easy to grep for, language neutral and a lot of people use
something similar (eg XXX or TODO).

  2. The HALT comment:

You can so this with triple quotes.  ''' and ''' (if you normally use
  for docstrings)

Python just ignores strings that lie around.

-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: catching exceptions from an except: block

2007-03-09 Thread Gerard Flanagan
On Mar 9, 9:56 am, Gabriel Genellina [EMAIL PROTECTED] wrote:
 En Fri, 09 Mar 2007 04:49:59 -0300, Gerard Flanagan
 [EMAIL PROTECTED] escribió:

  Another version:

  import exceptions

 As back in time as I could go (Python 1.5), exceptions were available as
 builtins...


I did not know that. Thanks.

  def onfailFalse(fn):
  def inner(*args, **kwargs):
  try:
  return fn(*args, **kwargs)
  except ABCException:
  return False
  return inner

  @onfailFalse
  def a(x):
  if x == 1:
  return 'function a succeeded'
  else:
  raise ABCException()

 There is a serious flaw on this approach, the function can't return any
 false value (it would be treated as a failure).


I was teaching myself decorators more than anything, so it's not
thought out to any extent, but even so I don't think it's a serious
flaw, rather it would be programmer error to use @onfailFalse on a
function that may return False. Don't you think?

Gerard



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


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread dbhbarton
Thanks for the thoughts.

 This could be implemented without new syntax: just make your editor  
 recognize some special comments, and apply the highlighting to the  
 following block. By example,

 # XXX Remove this when FuruFaifa is fixed to always provide
 # XXX the names in the same order
 names.sort()
 names.reverse()

Yes I recognise that we can use existing comments for this purpose,
and if I was suitably gifted I guess I could try to make the IDE
recognise these 'special comments', and maybe even work out what block
they're meant to apply to. Of course I'll still argue that the WIP
character would be a more elegant, speedy and versatile alternative.


 You accidentally type a ! somewhere, and your module stops working - not  
 so good :( and worse, hard to find.

By my reckoning it would be very very easy to find. Even if the IDE
wasn't greying out everything after it. And how often do you
accidentally mistype a ! at the beginning of a line?


 I sometimes use '''this string marks''' to ignore whole blocks of code. It  
 works fine unless the block already contains the same kind of  
 triple-quoted string...

Indeed. Moreover those quotes have to be in pairs, so it's not exactly
a quick and dandy way of doing what I'd like.


 The main problem with new syntax is breaking compatibility with older  
 versions...

Agreed. But both characters are currently disallowed in the positions
concerned, and in the proposal they're optional extras. This can't
stop old scripts from working, it can only stop new scripts from
working on old installations- just like any new feature.

, and I doubt it's worth the pain just for highlighting or playing  
 interactively

Ah well there's the issue!

, so you don't have a great chance of them being  
 implemented...

Obviously I like the idea, but I never hold out much hope that people
will agree with me!

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


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Bruno Desthuilliers
Nick Craig-Wood a écrit :
 [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  What if 2 new 'special' comment-like characters were added to Python?:


  1. The WIP (Work In Progress) comment:
 
 I use # FIXME for this purpose or /* FIXME */ in C etc.
 
 I have an emacs macro which shows it up in bright red / yellow text so
 it is easy to see

ot
Care to share this macro ?
/ot
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote:

 Of course I'll still argue that the WIP character would be a more
 elegant, speedy and versatile alternative.

I don't think so. Those characters have no syntactical meaning and
would, IMHO, make the language dirty.

Regards,


Björn

-- 
BOFH excuse #73:

Daemons did it

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


Re: Pb with descriptor and super ...

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 06:25:08 -0300, Erwan Adam [EMAIL PROTECTED]  
escribió:

 I have a problem with the use of descriptors
 and super. The file is :

Descriptors for super behave a bit different than for classes. See
http://www.python.org/2.2/descrintro.html#cooperation

-- 
Gabriel Genellina

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


Re: C++ and Python

2007-03-09 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote:

 I'm considering about generating some Python Bindings for C++
 libraries. What are considered the best tools for doing something
 like this? I know that there are SWIG, SIP, Boost.Python, and
 GCC_XML.

Please excuse me for asking the following stupid question ...

I'm planning to buy a car. What is the best brand? I know that there
are Mercedes, Opel, Honda and Ford.

Regards,


Björn

P.S.: Try this googled link and look for the comparation paragraph,
in section Introduction:
 http://www.boost-consulting.com/writing/bpl.html

-- 
BOFH excuse #163:

no any key on keyboard

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


Python in a Nutshell v2.5 shortcomings (was: Python books?)

2007-03-09 Thread Bjoern Schliessmann
Alex Martelli wrote:

 I do know that the 2nd edition of Python in a Nutshell tries to do
 so, but falls quite a bit short on a number of important new
 additions to the library

Which, if I may ask?

Regards,


Björn

-- 
BOFH excuse #221:

The mainframe needs to rest.  It's getting old, you know.

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


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread BJörn Lindqvist
On 9 Mar 2007 02:31:14 -0800, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 Thanks for the thoughts.

  This could be implemented without new syntax: just make your editor
  recognize some special comments, and apply the highlighting to the
  following block. By example,
 
  # XXX Remove this when FuruFaifa is fixed to always provide
  # XXX the names in the same order
  names.sort()
  names.reverse()

 Yes I recognise that we can use existing comments for this purpose,
 and if I was suitably gifted I guess I could try to make the IDE
 recognise these 'special comments', and maybe even work out what block
 they're meant to apply to. Of course I'll still argue that the WIP
 character would be a more elegant, speedy and versatile alternative.

But you are overloading the ? character for a purpose which it totally
was not meant for. What the character means really depends on what
person you are asking. To me, it means that what precedes it is
something someone or something does not know and wants to know the
answer to. To me, it really does not mean that what follows it is work
in progress.

Even if I could intuitively tell that a question mark represents a
work in progress, that information is not very useful. Similarly to
the under construction animated gifs that were popular on the web in
the mid 90-ties, the symbol does not convey any useful information.
WHY is it a work in progress? Is there something wrong with it?

?def foobar():
do stuff

The question mark does not leave me any the wiser. Now if you replace
that question mark with a comment:

# foobar() is buggy because it throws weird exceptions when x = 42.
def foobar():
do stuff

That gives me some useful information.

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pb with descriptor and super ...

2007-03-09 Thread Erwan Adam
Erwan Adam a écrit :
 Hi all,
 
 I have a problem with the use of descriptors
 and super. The file is :
 
 # ---
 
 class Desc(object):
 def __init__(self, class_name):
 self.class_name = class_name
 return
 def __get__(self, obj, typ):
 print Desc.__get__ : class_name is %s, obj is %s and typ is 
 %s%(self.class_name, obj, typ)
 return
 pass
 
 class A(object):
 attr = Desc(A)
 pass
 
 class B(A):
 attr = Desc(B)
 pass
 
 b = B()
 
 print ---
 print Getting b.attr ...
 print I hope that  : class_name is B, obj is b and typ is B
 b.attr
 print ---
 print Getting super(B, b).attr ...
 print I hope that  : class_name is A, obj is b and typ is A but it is 
 not the case !
 super(B, b).attr
 print ---
 
 # ---
 
 and the result is :
 
 ---
 Getting b.attr ...
 I hope that  : class_name is B, obj is b and typ is B
 Desc.__get__ : class_name is B, obj is __main__.B object at 0xb7b1f8ec 
 and typ is class '__main__.B'
 ---
 Getting super(B, b).attr ...
 I hope that  : class_name is A, obj is b and typ is A but it is not the 
 case !
 Desc.__get__ : class_name is A, obj is __main__.B object at 0xb7b1f8ec 
 and typ is class '__main__.B'
 ---
 
 I expected that when getting super(B, b).attr, typ is A, but it is not
 the case ...

Moreover, on the page :

http://users.rcn.com/python/download/Descriptor.htm

the author writes :

The call super(B, obj).m() searches obj.__class__.__mro__ for the base 
class A immediately following B and then returns 
A.__dict__['m'].__get__(obj, A).

which it seems not the case ...

Is it a bug or a mis-understood ?

Regards,

  E.A.


 
 python used :
 
 [EMAIL PROTECTED] /home/adam/Work/Python] python
 Python 2.4.3 (#2, Sep 18 2006, 21:07:35)
 [GCC 4.1.1 20060724 (prerelease) (4.1.1-3mdk)] on linux2
 Type help, copyright, credits or license for more information.
  
 
 
 Best regards,
 
 
   E.A.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: catching exceptions from an except: block

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 07:30:20 -0300, Gerard Flanagan  
[EMAIL PROTECTED] escribió:

 There is a serious flaw on this approach, the function can't return any
 false value (it would be treated as a failure).

 I was teaching myself decorators more than anything, so it's not
 thought out to any extent, but even so I don't think it's a serious
 flaw, rather it would be programmer error to use @onfailFalse on a
 function that may return False. Don't you think?

I thought this was on response to the original problem, not for your own  
problem.

-- 
Gabriel Genellina

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


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread dbhbarton
Those characters have no syntactical meaning...

?
Neither does # until you give it syntactical meaning. I must be
missing what you mean.

 would, IMHO, make the language dirty.

Well I'm not a big fan of decorators so I know how you must feel. But
# FIXME + a hack doesn't seem clean to me. And commenting off the
bottom half of a long script with triple quotes is ugly and a pain and
you can't indicate multiple alternate halt points as in the 'tutorial
script' example I gave.

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


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Diez B. Roggisch
 
 Well I'm not a big fan of decorators so I know how you must feel. But
 # FIXME + a hack doesn't seem clean to me. And commenting off the
 bottom half of a long script with triple quotes is ugly and a pain and
 you can't indicate multiple alternate halt points as in the 'tutorial
 script' example I gave.

It's not a hack. Without an IDE, there won't be support for that anyway -
after all, you're about to highlight blocks and the like, how is that
supposed to work?

And besides that - you might not _like_ decorators, but they do have a
semantic. Just inserting random characters into the source code that one
has to overread doesn't make any sense, it just clutters the code.

With an proper IDE, you could make that tagging of yours bound to a simple
keystroke, and the IDE could store the tagging information separately. E.g.
eric3 offers some bookmark features, I presume something like your proposal
would be possible, too.


Diez



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


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread dbhbarton
On Mar 9, 10:59 am, BJörn Lindqvist [EMAIL PROTECTED] wrote:
 On 9 Mar 2007 02:31:14 -0800, [EMAIL PROTECTED]





 [EMAIL PROTECTED] wrote:
  Thanks for the thoughts.

   This could be implemented without new syntax: just make your editor
   recognize some special comments, and apply the highlighting to the
   following block. By example,

   # XXX Remove this when FuruFaifa is fixed to always 
   provide
   # XXX the names in the same order
   names.sort()
   names.reverse()

  Yes I recognise that we can use existing comments for this purpose,
  and if I was suitably gifted I guess I could try to make the IDE
  recognise these 'special comments', and maybe even work out what block
  they're meant to apply to. Of course I'll still argue that the WIP
  character would be a more elegant, speedy and versatile alternative.

 But you are overloading the ? character for a purpose which it totally
 was not meant for. What the character means really depends on what
 person you are asking. To me, it means that what precedes it is
 something someone or something does not know and wants to know the
 answer to. To me, it really does not mean that what follows it is work
 in progress.

 Even if I could intuitively tell that a question mark represents a
 work in progress, that information is not very useful. Similarly to
 the under construction animated gifs that were popular on the web in
 the mid 90-ties, the symbol does not convey any useful information.
 WHY is it a work in progress? Is there something wrong with it?

 ?def foobar():
 do stuff

 The question mark does not leave me any the wiser. Now if you replace
 that question mark with a comment:

 # foobar() is buggy because it throws weird exceptions when x = 42.
 def foobar():
 do stuff

 That gives me some useful information.

 --
 mvh Björn- Hide quoted text -

 - Show quoted text -

perhaps another character would be preferable. '~' perhaps. As to what
you use the WIP character for- in my mind the purpose is to allow an
extra type/level of commenting over and above #, which is inherently
flexible. I could for example choose to use ? (or ~) for blocks I'm
still writing, ?? (or ~~) for blocks that are buggy, and ??? (or ~~~)
for blocks that work but could use optimization. It's a commenting
shortcut for me as the script's developer and its advantage over #
comments are speed or insertion/removal.
Ah but I can see I'm not winning anybody over. I shall graciously
retire!

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


Re: catching exceptions from an except: block

2007-03-09 Thread Gerard Flanagan
On Mar 9, 11:57 am, Gabriel Genellina [EMAIL PROTECTED]
wrote:
 En Fri, 09 Mar 2007 07:30:20 -0300, Gerard Flanagan
 [EMAIL PROTECTED] escribió:

  There is a serious flaw on this approach, the function can't return any
  false value (it would be treated as a failure).

  I was teaching myself decorators more than anything, so it's not
  thought out to any extent, but even so I don't think it's a serious
  flaw, rather it would be programmer error to use @onfailFalse on a
  function that may return False. Don't you think?

 I thought this was on response to the original problem, not for your own
 problem.


Mea culpa.

Gerard



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


Python-friendly hosting (was Re: merits of Lisp vs Python)

2007-03-09 Thread Paul Boddie
On 9 Mar, 02:32, John Nagle [EMAIL PROTECTED] wrote:


[Dedicated server offerings]

I'm not so familiar with dedicated servers, being unlikely to buy into
that kind of hosting any time soon - I'm not running a business with
serious reliability/control/uptime constraints where I could justify
spending that kind of money. However...

  In neither case is the Python environment typically ready for serious use
 out of the box.

Well, I can't say much about the off-the-shelf, locked down solutions
with Plesk control panels, but if you just get a box with the pipes
(an empty machine in a rack), you make from that what you will. Such
a solution isn't likely to be any good for Perl, PHP or Ruby out of
the box, either. I mean, what's the operating system? Do you have to
provide that? If so, any modern GNU/Linux distribution would give you
lots of acceptable packages for Python.

  There's denial in the Python community that this is a problem, but it is.
 The Ruby on Rails people get it; they work to provide a seamless experience
 for web developers.  Which is why their market share is way up over two years
 ago.

They got a number of things right. However, the big difference as I
see it is that instead of wondering why various providers don't
support Rails, they've either gone and started their own (including
virtual private server solutions), or they've found existing, flexible
providers (such as WebFaction) who were already providing lots of
plumbing for various Python-based solutions and persuaded them to
provide support for Rails. Last time I looked, Rails deployment
situation seemed closely tied to FastCGI and a lot of other stuff that
is arguably less attractive to various hosting providers than many of
the ways you can deploy Python Web solutions.

As for the denial, I can see your point to an extent. Before the Rails
hype there were discussions about making Python solutions as
attractive to deploy as PHP solutions, but a lot of the movers and
shakers in the Python Web community seem to have the luxury of
managing their own Internet-facing infrastructure. Thus, any progress
really has to be driven by people like you with your own hosting
requirements.

Paul

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


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Robert Marshall
On Fri, 09 Mar 2007, Bruno Desthuilliers wrote:

 
 Nick Craig-Wood a écrit :
 [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  What if 2 new 'special' comment-like characters were added to
  Python?:


  1. The WIP (Work In Progress) comment:

 I use # FIXME for this purpose or /* FIXME */ in C etc.

 I have an emacs macro which shows it up in bright red / yellow text
 so it is easy to see
 
 ot
 Care to share this macro ?
 /ot

I have this

(cond (window-system
   (progn
 (font-lock-add-keywords 
'python-mode '((\\FIXME: .*$ 0 font-lock-warning-face prepend))

Robert
-- 
La grenouille songe..dans son château d'eau
Links and things http://rmstar.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pb with descriptor and super ...

2007-03-09 Thread Erwan Adam
Gabriel Genellina a écrit :
 En Fri, 09 Mar 2007 06:25:08 -0300, Erwan Adam [EMAIL PROTECTED] 
 escribió:
 
 I have a problem with the use of descriptors
 and super. The file is :
 
 Descriptors for super behave a bit different than for classes. See
 http://www.python.org/2.2/descrintro.html#cooperation
 
 --Gabriel Genellina
 

Hi Gabriel,

Thanks for your answer ... I followed the link
and tried to use the fully functional implementation of
the super() built-in class in pure Python given
on this page and the result is quite surprising :

# -

class Super(object):
 def __init__(self, type, obj=None):
 self.__type__ = type
 self.__obj__ = obj
 def __get__(self, obj, type=None):
 if self.__obj__ is None and obj is not None:
 return Super(self.__type__, obj)
 else:
 return self
 def __getattr__(self, attr):
 if isinstance(self.__obj__, self.__type__):
 starttype = self.__obj__.__class__
 else:
 starttype = self.__obj__
 mro = iter(starttype.__mro__)
 for cls in mro:
 if cls is self.__type__:
 break
 # Note: mro is an iterator, so the second loop
 # picks up where the first one left off!
 for cls in mro:
 if attr in cls.__dict__:
 x = cls.__dict__[attr]
 if hasattr(x, __get__):
 x = x.__get__(self.__obj__)
 return x
 raise AttributeError, attr

class Desc(object):
 def __init__(self, class_name):
 self.class_name = class_name
 return
 def __get__(self, obj, typ=None):
 print Desc.__get__ : class_name is %s, obj is %s and typ is 
%s%(self.class_name, obj, typ)
 return
 pass

class A(object):
 attr = Desc(A)
 pass

class B(A):
 attr = Desc(B)
 pass

b = B()

print Using built-in super
attr = super(B, b).attr
print Using python Super
attr = Super(B, b).attr

class MySuper(object):
 def __init__(self, type, obj=None):
 self.__type__ = type
 self.__obj__ = obj
 def __get__(self, obj, type=None):
 if self.__obj__ is None and obj is not None:
 return Super(self.__type__, obj)
 else:
 return self
 def __getattr__(self, attr):
 if isinstance(self.__obj__, self.__type__):
 starttype = self.__obj__.__class__
 else:
 starttype = self.__obj__
 mro = iter(starttype.__mro__)
 for cls in mro:
 if cls is self.__type__:
 break
 # Note: mro is an iterator, so the second loop
 # picks up where the first one left off!
 for cls in mro:
 if attr in cls.__dict__:
 x = cls.__dict__[attr]
 if hasattr(x, __get__):
 x = x.__get__(self.__obj__, cls)
 return x
 raise AttributeError, attr

print Using python MySuper
attr = MySuper(B, b).attr


# --

it gives :

[EMAIL PROTECTED] /home/adam/Work/Python] python super_from_guido.py
Using built-in super
Desc.__get__ : class_name is A, obj is __main__.B object at 0xb7bc302c 
and typ is class '__main__.B'
Using python Super
Desc.__get__ : class_name is A, obj is __main__.B object at 0xb7bc302c 
and typ is None
Using python MySuper
Desc.__get__ : class_name is A, obj is __main__.B object at 0xb7bc302c 
and typ is class '__main__.A'

the Super gives None for typ ... which is quite surprising !
In MySuper, I just change

 x = x.__get__(self.__obj__)

by

 x = x.__get__(self.__obj__, cls)

at the -3 :) line of the class ... and it gives the result I expected
at the beginning : obj is b and typ is A 


Best regards,

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


Re: What is the best way to upgrade python?

2007-03-09 Thread Paul Boddie
On 8 Mar, 22:13, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hi,

 i am using red hat enterprise 4. It has python 2.3 installed. What is
 the best way to upgrade to python 2.4?

By installing a version from the source packages available from
python.org.

 I think one way is to compile python 2.4 from the source, but I can't
 remove the old one since when i do 'rpm -e python', i get error like
 'failed dependencies'.

That's because various administrative programs (and perhaps others)
depend on Python 2.3 - unless Red Hat provide versions of these for
Python 2.4 (which I suppose they don't in RHEL 4), then you can't
remove Python 2.3 from your system.

Either configure the source package choosing --prefix as something
other than /usr (the default is /usr/local) and then install using
make install, or choose --prefix as /usr and do a make altinstall.
Using package management tools to build custom packages which can then
be installed via the system tools might be an even better solution,
since you can then manage what you've done and uninstall if necessary,
but I can't tell you how that's done on Red Hat (with RPMs and so on).

Paul

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


Creat a DLL File from python code, and use that DLL file in other Platform (Labview, Java .NET etc)

2007-03-09 Thread macedo . silva
Hi,

I would like to request your attention for this very specific issue:

I have several classes in Python, and now I want simply re-use it, in
other language.


The closest to solution I think I came was with this site:
http://www.py2exe.org/index.cgi/Py2exeAndCtypesComExeServer?highlight=%28%28Py2exeAndCtypesComDllServer%29%29
but I not able to solve questions related with TLB files and
__init__.py files.

So, could anyone give a tip about HOW TO CREAT a dll file from Python?

thank in advance

AMMS

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


A Pythonic Way to Measure and Improve Your Programming Skills?

2007-03-09 Thread Jeff Rush
(inspired by a thread on the psf-members list about Python certification)

Those who know me know I am no fan of the programmer certification industry 
and I agree that your typical certificate arrangement, e.g. to show HR to get 
that box checked in your candidate file, so a company can skip responsibility 
in vetting a candidate, is un-Pythonic.  However, I do think we need a good 
answer to the engineering manager or team leader who asks, how do I know this 
person knows Python?, and to the candidate who thinks, I believe I'm good at 
Python but am I as good as I think?.

The first case primarily cares about the reputation of the testing facility 
within the industry, so that if they choose wrong, they are absolved of blame. 
The latter two are often honestly looking for some guidance on bringing good 
people in-house or to step-up their programming skills.

As Python use spreads, it becomes more important for the community to provide 
benchmarks for measuring skill levels, to avoid Python being relegated to the, 
respectfully, lightweight programmer category e.g. PHP or perhaps Ruby on 
Rails (not Ruby the language).

Prior to PyCon I'd been thinking about some kind of campaign, service or 
documents, that I call So you think you know Python  My initial idea was 
for use by Python programmers, who are honest with themselves, to have a way 
to measure their knowledge.  We all run into or are programmers who think they 
are hot-stuff, especially those of us who work solo as many in our community 
do, but when put side-by-side against others, fall a bit short.  PyCon can 
have that effect, with so many smart people in a small area. ;-) But the 
objective isn't to denegrate these programmers but to provide a measuring 
stick, along with an educational roadmap, so they can make wise choices.

The rapid growth in use of Python is going to lead to a shortage in Python 
programmers, unless we manage the supply side as well.  The manager wanting to 
find and hire good Python programmers is not an adversary seeking to use 
certificates to commoditize our community, but an ally in helping us get 
industry respect and career opportunities using our favorite language.  We 
need to behind what he asks for to see what he needs.

I've been carefully watching Crunchy, about which a talk was given at PyCon, 
for writing tutorials that, with its doctests feature, could be used to 
propose tests that pass and require a candidate to write an acceptable 
program.  This week I was prototyping an rst2crunchy tool, that let's you 
write Crunchy scripts in reStructured Text, rather than HTML.  Crunchy needs 
more features, such as a user login facility and measurement facilities to 
store test submissions for review by experienced Python programmers after they 
pass.  From what I hear on the edu-sig list, André Roberge and Johannes 
Woolard are tackling these but could use more help.  Johannes in particular 
was a student for Google's Summer of Code 2006 and I believe is looking for 
sponsorship for 2007.

But perhaps Crunchy is not the ready answer in this case, so I'm looking for 
suggestions.

With regard to how a manager can know a person is good at Python, besides 
looking at their portfolio of work, we could stake out conceptual areas of the 
language or libraries about which a programmer should be conversant.  This 
might be a document, with example questions but carefully focused on what lies 
behind those questions, so an interviewer can come up with his own questions 
and avoid rote memorization.  This conceptual map could also eventually form 
the basis of advanced-placement in schools that goes beyond those terrible 
Visual BASIC test questions.  And for the Python programmer who wonders if his 
knowledge is broad enough and wants to improve him or herself, the conceptual 
map could have links/recommendations to training materials on specific topics.

Join me on the advocacy list and let's discuss this further.

You can join at:
   http://mail.python.org/mailman/listinfo/advocacy

Jeff Rush
Python Advocacy Coordinator
-- 
http://mail.python.org/mailman/listinfo/python-list


Creating a DLL file from Python Code

2007-03-09 Thread macedo . silva

Hi,

I would like to request your attention for this very specific issue:

I have several classes in Python, and now I want simply re-use it, in
other language.

The closest to solution I think I came was with this site:
http://www.py2exe.org/index.cgi/Py2exeAndCtypesComDllServer
but I not able to solve questions related with TLB files and
__init__.py files.

So, could anyone give a tip about how to creat a dll file from Python?
It is possible under any conditions?

thank in advance

macedo

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


MPI in python?

2007-03-09 Thread Joydeep Mitra

Hi guys,
I am a relatively new user of python.
I wanted to know what are the minimum requirements (modules, etc) are
required for paralleliing python programs on a multiproc linux cluster.
Is there a tutorial that explains the MPI syntax in python with examples?

Thanking in advance,
Joydeep
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: C++ and Python

2007-03-09 Thread cptnwillard
On Mar 9, 7:04 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hi Everyone,

 I'm considering about generating some Python Bindings for C++
 libraries. What are considered the best tools for doing something like
 this? I know that there are SWIG, SIP, Boost.Python, and GCC_XML.

 Thanks!

Declare the functions you want to use in Python with 'extern C', and
make them available in a dynamic library. Then use ctypes to call them
directly.

Regards,

Willard

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


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote:
 Those characters have no syntactical meaning...
 
 ?
 Neither does # until you give it syntactical meaning. I must be
 missing what you mean.

Yes, it has. It says disregard the following characters until EOL.
If you remove it, the following code will be interpreted as ...
code (and not be disregarded).

A WIP character would only be there for tagging and wouldn't
change the program logic. Thus, IMHO, it's useless as a part of the
Python language. Highlighting and tagging is task of editors/IDEs.
 
 would, IMHO, make the language dirty.
 
 Well I'm not a big fan of decorators so I know how you must feel.

Mh, not sure -- why do you have decorators in mind? I don't dislike
them.

 But # FIXME + a hack doesn't seem clean to me. 

I think it's much cleaner to have language and fixme levels
separate. fixme features can then depend fully on the editor/IDE
and don't have to be part of the source code (though they may).

 And commenting off the bottom half of a long script with triple
 quotes is ugly and a pain and you can't indicate multiple
 alternate halt points as in the 'tutorial script' example I gave.

A proper editor can comment out multiple lines easily.

A smart script can have multiple halt points user-selectable, though
this is a big matter of taste. I think that in this case some kind
of learning environment is better.

Regards,


Björn

-- 
BOFH excuse #23:

improperly oriented keyboard

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


Re: catching exceptions from an except: block

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 08:14:18 -0300, Gerard Flanagan  
[EMAIL PROTECTED] escribió:

 Mea culpa.

Ego te absolvo in nomine Patris Guidii et Filii Python et Spiritus Sancti  
Computatorium.

-- 
Gabriel Genellina

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


Re: MPI in python?

2007-03-09 Thread rishi pathak

try this

http://sourceforge.net/projects/pympi/

On 3/9/07, Joydeep Mitra [EMAIL PROTECTED] wrote:


Hi guys,
I am a relatively new user of python.
I wanted to know what are the minimum requirements (modules, etc) are
required for paralleliing python programs on a multiproc linux cluster.
Is there a tutorial that explains the MPI syntax in python with examples?

Thanking in advance,
Joydeep


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





--
Regards--
Rishi Pathak
National PARAM Supercomputing Facility
Center for Development of Advanced Computing(C-DAC)
Pune University Campus,Ganesh Khind Road
Pune-Maharastra
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: pylint: don't warn about tabs

2007-03-09 Thread Colin J. Williams
Ben Finney wrote:
 Bjoern Schliessmann [EMAIL PROTECTED] writes:
 
 Alan Isaac wrote:
 As a tab user, I want the tabs warning turned off.
 Advice: Don't.
 
 Agreed. Sticking to spaces for indentation avoids the ambiguity of
 interpretation that ASCII TAB characters are subject to. In addition,
 PEP 8 (which many people consider a strong suggestion for a style
 guide for all Python code) recommends four space characters for
 indentation.
For those who prefer say 3 or 8, pylint permits this to be specified in 
the configuration file.

Colin W.
 
 IIRC it's planned in future Python versions that TABs aren't
 supported for indentation.
 
 I've not seen such plans, can you support that?
 
 If you're thinking of this post from Guido, please note the date it
 was made:
 
 URL:http://www.artima.com/weblogs/viewpost.jsp?thread=101968
 

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


Re: Pb with descriptor and super ...

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 08:22:46 -0300, Erwan Adam [EMAIL PROTECTED]  
escribió:

 Thanks for your answer ... I followed the link
 and tried to use the fully functional implementation of
 the super() built-in class in pure Python given
 on this page and the result is quite surprising :

It appears that there is some disagreement on how the super object should  
behave.
If you want to know what it actually *does* now (not what it *should* do)  
you can look at typeobject.c, but it's a bit hard to read, and I don't  
understand it in full...
Maybe looking at the test suite is easier, in test_descr.py

-- 
Gabriel Genellina

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


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Nick Craig-Wood
Robert Marshall [EMAIL PROTECTED] wrote:
  On Fri, 09 Mar 2007, Bruno Desthuilliers wrote:
 
  
  Nick Craig-Wood a ?crit :
  [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
   What if 2 new 'special' comment-like characters were added to
   Python?:
 
 
   1. The WIP (Work In Progress) comment:
 
  I use # FIXME for this purpose or /* FIXME */ in C etc.
 
  I have an emacs macro which shows it up in bright red / yellow text
  so it is easy to see
  
  ot
  Care to share this macro ?
  /ot
 
  I have this
 
  (cond (window-system
 (progn
   (font-lock-add-keywords 
  'python-mode '((\\FIXME: .*$ 0 font-lock-warning-face 
 prepend))

This is what I use which is very similar

(font-lock-add-keywords 'python-mode
  '(
((FIXME\\):? 1 font-lock-warning-face prepend)
)
  )

-- 
Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread dbhbarton
 Yes, it has. It says disregard the following characters until EOL.
 If you remove it, the following code will be interpreted as ...
 code (and not be disregarded).

and ! would say disregard the following characters until End Of
Program. Is it really so different?


  Well I'm not a big fan of decorators so I know how you must feel.

 Mh, not sure -- why do you have decorators in mind? I don't dislike
 them.

Just because I remember reading similar aesthetic arguments against
the @ syntax- that it looked alien, messy, unpythonic and obfuscating.
I certainly agree with the latter point even if I find the former ones
a little hand-wavey for my tastes.


 I think it's much cleaner to have language and fixme levels
 separate. fixme features can then depend fully on the editor/IDE
 and don't have to be part of the source code (though they may).

That's certainly a solid ideological argument against the WIP
character. Maybe I should just change my editor!

It sounds like other Python users *do* like to do the kind of things I
suggested, but seasoned users would rather rely on macros and features
of specific editors. Unfortunately, to a newbie like myself, these
seem like obscure 'tricks' to be mastered rather than simple built-in
conveniences that any newbie can profit from.

I suppose my ideology is that Python's greatest strength is (and focus
should be) its visual simplicity and ease of learning, making
programming more accessible to the masses. But hey I'm just a fresh-
faced conscript. I guess I've got to leave the battle planning to the
five-star generals on the hill!

Thanks for all the comments and the spirit of tolerance.

dave


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


Re: C++ and Python

2007-03-09 Thread Mandus
8 Mar 2007 22:04:48 -0800 skrev [EMAIL PROTECTED]:
 Hi Everyone,

 I'm considering about generating some Python Bindings for C++
 libraries. What are considered the best tools for doing something like
 this? I know that there are SWIG, SIP, Boost.Python, and GCC_XML.

We are doing this quite extensively at work, and have found that in the
long run SWIG is the best solution. OMMV, but if you ask me, the answer
is SWIG. 

mvh,
-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Diez B. Roggisch
 It sounds like other Python users *do* like to do the kind of things I
 suggested, but seasoned users would rather rely on macros and features
 of specific editors. Unfortunately, to a newbie like myself, these
 seem like obscure 'tricks' to be mastered rather than simple built-in
 conveniences that any newbie can profit from.

But you _can't_ profit from these conveniences, at least not the ?
character. It's just garbage put in there for some others to interpret,
meaningless to the interpreter. So it _always_ boils down to
editor-support.

Now obviously _one_ scheme supported by all editors would be a great thing -
so one could argue that a well-defined PEP that suggests a certain comment
style that allows for your desired functionality would be a good thing.

Diez

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


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread dbhbarton
On 9 Mar, 14:05, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 But you _can't_ profit from these conveniences, at least not the ?
 character. It's just garbage put in there for some others to interpret,
 meaningless to the interpreter. So it _always_ boils down to
 editor-support.

I'm sorry I don't follow your logic. Meaningless to the interpreter,
yes, meaningless to the IDE or to me, no. I _can't_ profit from these
conveniences? Why ever not?

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


Re: Reading a portion of a file

2007-03-09 Thread Vulcanius
Here is the code I've come up with. Please feel free to critique it
and let me know what you would change. Also, as you can see I call
open(SERVER,'r') twice; but I want to only call it once, what would
the best way to do this be?



import re

SERVER = 192.168.1.60

# Pull all data from server file.
FILE = open(SERVER,'r')
ALLINFO = FILE.read()

# Grab a list of all sections in the server file.
SECTIONS = re.findall((?m)^\#VS:\w*:.*:, ALLINFO)

# Remove duplicates from the list.
if SECTIONS:
   SECTIONS.sort()
   LAST = SECTIONS[-1]
   for I in range(len(SECTIONS)-2, -1, -1):
   if LAST==SECTIONS[I]: del SECTIONS[I]
   else: LAST=SECTIONS[I]

# Pull data from each section and assign it a dictionary item.
# Data can be called using SECTIONDICT['section'] i.e
SECTIONDICT['df']
SECTIONDICT = {}
for SECT in SECTIONS:
PRESECTNAME1 = SECT[9:len(SECT) - 1]
PRESECTNAME2 = PRESECTNAME1.split(/)
SECTNAME = PRESECTNAME2[len(PRESECTNAME1.split(/)) - 1]
START = SECT + START
STOP = SECT +  STOP
for LINE in open(SERVER,'r'):
LINE = LINE.strip()
if START in LINE:
SECTIONLISTTEMP = []
elif STOP in LINE:
SECTIONDICT[SECTNAME] = SECTIONLISTTEMP
SECTIONLISTTEMP = []
print - * 80
print SECTION: %s % SECTNAME
print SECTIONDICT[SECTNAME]
else:
if LINE:
SECTIONLISTTEMP.append(LINE)

FILE.close()



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


Is this right? Multiple imports of same module.

2007-03-09 Thread Lou Pecora
From what I gleaned on some messages this is the way multiple imports of 
the same module work.  Say, I have 3 modules (mod1.py, mod2.py, and 
mod3.py) and in the same session they all import another module 
mymodule.py like this:

*In mod1.py

import mymodule

*In mod2.py

import mymodule

*In mod3.py

import mymodule as MM

Then mymodule is imported only once, but each module has access to it 
through the module name (mod1 and mod2) and the alias MM (mod3).  Is 
that right?

I was concerned about multiple imports and efficiency.

Thanks for any info.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 On 9 Mar, 14:05, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 But you _can't_ profit from these conveniences, at least not the ?
 character. It's just garbage put in there for some others to interpret,
 meaningless to the interpreter. So it _always_ boils down to
 editor-support.
 
 I'm sorry I don't follow your logic. Meaningless to the interpreter,
 yes, meaningless to the IDE or to me, no. I _can't_ profit from these
 conveniences? Why ever not?

Exactly, the ? is meaningless to the language itself, it's only a comment
sign - but what you want is 


1. The WIP (Work In Progress) comment:

A '?' placed in the preceding whitespace of a line as a means of
quickly highlighting a line or block of code for special attention.


Now tell me - how exactly do you highlight a text? That is solely part of
the editor you use, either it will parse the ?  - the same way it would
parse a # fixme or # wip comment - and react accordingly, or it won't.

But for python itself, it has no meaning whatsoever, and would just be a
character to overread, introducing visual clutter.

So - if you want that feature, patch your editor of choice to deal with that
comments, make them added and removed with a key stroke, whatever - be my
guest. But it has nothing to do with _python_ the language, so it doesn't
belong there.

Besides, I don't see how quick highlighting of text is something that
needs to be persisted anyway - if it is quick, hightlight it within the
editor until the file is closed. If not, it might be well worth a comment
anyway why you think it needs special attention.

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


number generator

2007-03-09 Thread cesco
I have to generate a list of N random numbers (integer) whose sum is
equal to M. If, for example, I have to generate 5 random numbers whose
sum is 50 a possible solution could be [3, 11, 7, 22, 7]. Is there a
simple pattern or function in Python to accomplish that?

Thanks and regards
Francesco

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


Re: number generator

2007-03-09 Thread Paul Rubin
cesco [EMAIL PROTECTED] writes:
 I have to generate a list of N random numbers (integer) whose sum is
 equal to M. If, for example, I have to generate 5 random numbers whose
 sum is 50 a possible solution could be [3, 11, 7, 22, 7]. Is there a
 simple pattern or function in Python to accomplish that?

Erm, yes, lots of ways, there are probably further constraints on the
problem, such as the size of the integers, how the lists are supposed
to be distributed, etc.  Can you be more specific?  Is this for an
application?  If it's a homework problem, that's fine, but it's better
in that case for respondents to suggest hints rather than full solutions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread dbhbarton
  I'm sorry I don't follow your logic. Meaningless to the interpreter,
  yes, meaningless to the IDE or to me, no. I _can't_ profit from these
  conveniences? Why ever not?

 Exactly, the ? is meaningless to the language itself, it's only a comment
 sign - ...
 ... it has nothing to do with _python_ the language, so it doesn't
 belong there.

But # is 'only a comment sign' as well, and equally meaningless to the
interpreter. But it's still part of the language, very very useful and
I profit from its existence every day.


 But for python itself, it has no meaning whatsoever, and would just be a
 character to overread, introducing visual clutter.

If you can highlight an entire block with a single character, won't
there be _less_ visual clutter than the current way of achieving the
same effect with # comments?


 So - if you want that feature, patch your editor of choice to deal with that
 comments, make them added and removed with a key stroke, whatever - be my
 guest.

Would if I could!

 Besides, I don't see how quick highlighting of text is something that
 needs to be persisted anyway - if it is quick, hightlight it within the
 editor until the file is closed. If not, it might be well worth a comment
 anyway why you think it needs special attention.

What we're talking about here is a form of 'alternate commenting
style'. With the IDE's cooperation it'd work on whole blocks at once,
it would highlight without disrupting the code concerned (at least the
way I'm envisaging it), it would be versatile (could probably be used
for as big a variety of purposes as the # comment), and yes, it'd be
persistent, which is how it would be different from any IDE-based
highlighting.

I think that'd be most useful. You don't. So far nobody else here does
either, and I've not persuaded anybody differently. Fair enough!

dave

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


Re: Creating a DLL file from Python Code

2007-03-09 Thread Laurent Pointal
[EMAIL PROTECTED] a écrit :
 Hi,
 
 I would like to request your attention for this very specific issue:
 
 I have several classes in Python, and now I want simply re-use it, in
 other language.
 
 The closest to solution I think I came was with this site:
 http://www.py2exe.org/index.cgi/Py2exeAndCtypesComDllServer
 but I not able to solve questions related with TLB files and
 __init__.py files.
 
 So, could anyone give a tip about how to creat a dll file from Python?
 It is possible under any conditions?

For inter-languages intagration maybe you can use some distributed
objects protocol like CORBA (see OmniORBpy), or - as you wrote about a
DLL - COM/DCOM (see pywin32). Or write a simple TCP or UDP layer to
communicate with your existing classes.
Note: all that need some work in the Python side to be able to work
using a client/server model.
Note2: as long as your interface dont change, you can make modifications
in both sides without problem.

A+

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


Re: number generator

2007-03-09 Thread cesco
On Mar 9, 3:51 pm, Paul Rubin http://[EMAIL PROTECTED] wrote:
 cesco [EMAIL PROTECTED] writes:
  I have to generate a list of N random numbers (integer) whose sum is
  equal to M. If, for example, I have to generate 5 random numbers whose
  sum is 50 a possible solution could be [3, 11, 7, 22, 7]. Is there a
  simple pattern or function in Python to accomplish that?

 Erm, yes, lots of ways, there are probably further constraints on the
 problem, such as the size of the integers, how the lists are supposed
 to be distributed, etc.  Can you be more specific?  Is this for an
 application?  If it's a homework problem, that's fine, but it's better
 in that case for respondents to suggest hints rather than full solutions.

Given two positive integers, N and M with N  M, I have to generate N
positive integers such that sum(N)=M. No more constraints.

Thanks again
Francesco

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


Re: Creat a DLL File from python code, and use that DLL file in other Platform (Labview, Java .NET etc)

2007-03-09 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 Hi,
 
 I would like to request your attention for this very specific issue:
 
 I have several classes in Python, and now I want simply re-use it, in
 other language.
 
 
 The closest to solution I think I came was with this site:

http://www.py2exe.org/index.cgi/Py2exeAndCtypesComExeServer?highlight=%28%28Py2exeAndCtypesComDllServer%29%29
 but I not able to solve questions related with TLB files and
 __init__.py files.
 
 So, could anyone give a tip about HOW TO CREAT a dll file from Python?

You might have success with 

http://elmer.sourceforge.net/

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


opinion needed

2007-03-09 Thread azrael
id like to hear your opinion about something.
I just started using Prolog yesterday and i have my doubts about it,
but it seems to me something like object oriented. so i wanted to ask
you how usefull prolog is. Sure this is no prolog newsgroup so my
question is: because it seems object oriented, how important is it by
understanding python and improving my python skills. because i just
started it, i may bee totaly wrong or i missunderstood.

thnx

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


Re: C++ and Python

2007-03-09 Thread hg
Mandus wrote:

 8 Mar 2007 22:04:48 -0800 skrev [EMAIL PROTECTED]:
 Hi Everyone,

 I'm considering about generating some Python Bindings for C++
 libraries. What are considered the best tools for doing something like
 this? I know that there are SWIG, SIP, Boost.Python, and GCC_XML.
 
 We are doing this quite extensively at work, and have found that in the
 long run SWIG is the best solution. OMMV, but if you ask me, the answer
 is SWIG.
 
 mvh,
 --
 Mandus - the only mandus around.

Hi,

Why do you think it is better than ctypes ?

Thanks,

hg

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


Re: number generator

2007-03-09 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], cesco wrote:

 Given two positive integers, N and M with N  M, I have to generate N
 positive integers such that sum(N)=M. No more constraints.

Break it into subproblems.  Generate a random number X from a suitable
range and you are left with one number, and the problem to generate (N-1)
random numbers that add up to (M-X).  You have to think a little bit about
the suitable range part though.

The necessary functions to draw random numbers are in the `random` module.

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


Re: Is this right? Multiple imports of same module.

2007-03-09 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Lou Pecora wrote:

 *In mod1.py
 
 import mymodule
 
 *In mod2.py
 
 import mymodule
 
 *In mod3.py
 
 import mymodule as MM
 
 Then mymodule is imported only once, but each module has access to it 
 through the module name (mod1 and mod2) and the alias MM (mod3).  Is 
 that right?

Yes, that's correct.

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


Re: number generator

2007-03-09 Thread Gerard Flanagan
On Mar 9, 4:17 pm, cesco [EMAIL PROTECTED] wrote:
 On Mar 9, 3:51 pm, Paul Rubin http://[EMAIL PROTECTED] wrote:

  cesco [EMAIL PROTECTED] writes:
   I have to generate a list of N random numbers (integer) whose sum is
   equal to M. If, for example, I have to generate 5 random numbers whose
   sum is 50 a possible solution could be [3, 11, 7, 22, 7]. Is there a
   simple pattern or function in Python to accomplish that?

  Erm, yes, lots of ways, there are probably further constraints on the
  problem, such as the size of the integers, how the lists are supposed
  to be distributed, etc.  Can you be more specific?  Is this for an
  application?  If it's a homework problem, that's fine, but it's better
  in that case for respondents to suggest hints rather than full solutions.

 Given two positive integers, N and M with N  M, I have to generate N
 positive integers such that sum(N)=M. No more constraints.

 Thanks again
 Francesco

Suppose you have a fixed telegraph pole at N and a fixed telgraph pole
at M, and you're given 5 more telegraph poles...

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


Re: C++ and Python

2007-03-09 Thread Roman Yakovenko

On 8 Mar 2007 22:04:48 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

Hi Everyone,

I'm considering about generating some Python Bindings for C++
libraries. What are considered the best tools for doing something like
this? I know that there are SWIG, SIP, Boost.Python, and GCC_XML.


If you ask me than Boost.Python and Py++(
http://language-binding.net/pyplusplus/pyplusplus.html)
is the way to go. I collected few links to articles that compare between
different tools:
http://language-binding.net/pyplusplus/comparisons/compare_to.html

Until recently there was not big library written in C++, which was exposed
to Python
using different tools. Today there are two projects, which expose same
source code
to Python. The exposed library is Ogre - a scene-oriented, flexible 3D
engine, pretty big
and complex project.

The first solution, PyOgre, uses SWIG, while the second one uses Py++.
The link I gave earlier contains links to the projects CVS's. It worse to
take a
look on them and compare.

P.S. Take all what I say with caution, because I am the author of Py++.

--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: number generator

2007-03-09 Thread Carsten Haese
On Fri, 2007-03-09 at 07:17 -0800, cesco wrote:
 On Mar 9, 3:51 pm, Paul Rubin http://[EMAIL PROTECTED] wrote:
  cesco [EMAIL PROTECTED] writes:
   I have to generate a list of N random numbers (integer) whose sum is
   equal to M. If, for example, I have to generate 5 random numbers whose
   sum is 50 a possible solution could be [3, 11, 7, 22, 7]. Is there a
   simple pattern or function in Python to accomplish that?
 
  Erm, yes, lots of ways, there are probably further constraints on the
  problem, such as the size of the integers, how the lists are supposed
  to be distributed, etc.  Can you be more specific?  Is this for an
  application?  If it's a homework problem, that's fine, but it's better
  in that case for respondents to suggest hints rather than full solutions.
 
 Given two positive integers, N and M with N  M, I have to generate N
 positive integers such that sum(N)=M. No more constraints.

Paul still had a point, since the word positive is a vital piece of
information that never appeared in your original description.

-Carsten


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


Re: Is this right? Multiple imports of same module.

2007-03-09 Thread Simon Brunning
On 3/9/07, Lou Pecora [EMAIL PROTECTED] wrote:

 *In mod1.py

 import mymodule

 *In mod2.py

 import mymodule

 *In mod3.py

 import mymodule as MM

 Then mymodule is imported only once, but each module has access to it
 through the module name (mod1 and mod2) and the alias MM (mod3).  Is
 that right?

Yup, and occasionally it's useful to do stuff like this...

 I was concerned about multiple imports and efficiency.

... but not for this reason. Subsequent imports of an already loaded
module are very quick.

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


Re: Is this right? Multiple imports of same module.

2007-03-09 Thread Bart Ogryczak
On Mar 9, 3:30 pm, Lou Pecora [EMAIL PROTECTED] wrote:
 Then mymodule is imported only once, but each module has access to it
 through the module name (mod1 and mod2) and the alias MM (mod3).  Is
 that right?

Yes, it is.

 I was concerned about multiple imports and efficiency.

If the module is already loaded, it won't be loaded again. Dictionary
of loaded modules is avaliable as sys.modules.



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


Re: opinion needed

2007-03-09 Thread Grant Edwards
On 2007-03-09, azrael [EMAIL PROTECTED] wrote:

 I just started using Prolog yesterday and i have my doubts about it,
 but it seems to me something like object oriented.

Not in my experience, but I haven't used Prolog for 10 years.

 so i wanted to ask you how usefull prolog is.

It's brilliant for doing predicate logic.  It sort of sucks for
most other things.

 Sure this is no prolog newsgroup so my question is: because it
 seems object oriented, how important is it by understanding
 python and improving my python skills.

What?

 because i just started it, i may bee totaly wrong or i
 missunderstood.

-- 
Grant Edwards   grante Yow!  Were these parsnips
  at   CORRECTLY MARINATED in
   visi.comTACO SAUCE?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

  I'm sorry I don't follow your logic. Meaningless to the interpreter,
  yes, meaningless to the IDE or to me, no. I _can't_ profit from these
  conveniences? Why ever not?

 Exactly, the ? is meaningless to the language itself, it's only a comment
 sign - ...
 ... it has nothing to do with _python_ the language, so it doesn't
 belong there.
 
 But # is 'only a comment sign' as well, and equally meaningless to the
 interpreter. But it's still part of the language, very very useful and
 I profit from its existence every day. 

A language has to have a comment mechanism, some even several.

But all of them are clear on how they work: they affect one line, or have a
bracket style like /* */ and thus demark clearly what they affect. Even
someone not fluent in the language in question will quickly grab what they
mean.

But the key-difference is that the comment in python has a meaning for the
interpreter - ignore this.

The ? has no meaning. It only has a meaning for an editor.

 But for python itself, it has no meaning whatsoever, and would just be a
 character to overread, introducing visual clutter.
 
 If you can highlight an entire block with a single character, won't
 there be _less_ visual clutter than the current way of achieving the
 same effect with # comments?

Not in my opinion - 

# fixme
def foo():
   pass

is much more clear than a rather obscure and by the occasional beholder
maybe misinterpreted

?def foo():
   pass

 Would if I could!

Well, grab eric3, it's written in python, and teach it to do so! It's an
exercise in python then :)

It already has some features like bookmarks, shouldn't be too hard to build
upon that.

 What we're talking about here is a form of 'alternate commenting
 style'. With the IDE's cooperation it'd work on whole blocks at once,
 it would highlight without disrupting the code concerned (at least the
 way I'm envisaging it), it would be versatile (could probably be used
 for as big a variety of purposes as the # comment), and yes, it'd be
 persistent, which is how it would be different from any IDE-based
 highlighting.

I think you contradict yourself here. On the one side, you want it not
disturbing to the eye, yet it should be highlighted, so it will be directly
noticed by that same eyes.

This is why I believe that your idea by itself - the visually marking of
code parts - is a good thing, but the embedding into code is not, because
it _is_ an disturbance. And with an IDE that stores such information in
e.g. project metainformation, you can even have the persistence, without
the disturbance and without altering python.

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


Re: number generator

2007-03-09 Thread Paul Rubin
Carsten Haese [EMAIL PROTECTED] writes:
  Given two positive integers, N and M with N  M, I have to generate N
  positive integers such that sum(N)=M. No more constraints.
 Paul still had a point, since the word positive is a vital piece of
 information that never appeared in your original description.

It's maybe even more complicated that way.  Does the OP want to
generate each possible partition with equal probability?  See

  http://en.wikipedia.org/wiki/Partition_number

for more info.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Bruno Desthuilliers
Nick Craig-Wood a écrit :
 Robert Marshall [EMAIL PROTECTED] wrote:
  On Fri, 09 Mar 2007, Bruno Desthuilliers wrote:

 Nick Craig-Wood a ?crit :
 [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  What if 2 new 'special' comment-like characters were added to
  Python?:


  1. The WIP (Work In Progress) comment:
 I use # FIXME for this purpose or /* FIXME */ in C etc.

 I have an emacs macro which shows it up in bright red / yellow text
 so it is easy to see
 ot
 Care to share this macro ?
 /ot
  I have this

  (cond (window-system
 (progn
   (font-lock-add-keywords 
  'python-mode '((\\FIXME: .*$ 0 font-lock-warning-face 
 prepend))
 
 This is what I use which is very similar
 
 (font-lock-add-keywords 'python-mode
   '(
 ((FIXME\\):? 1 font-lock-warning-face prepend)
 )
   )
 

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


Re: opinion needed

2007-03-09 Thread Bart Ogryczak
On Mar 9, 4:27 pm, azrael [EMAIL PROTECTED] wrote:
 id like to hear your opinion about something.
 I just started using Prolog yesterday and i have my doubts about it,
 but it seems to me something like object oriented. so i wanted to ask
 you how usefull prolog is.

It's very useful for Logic Programming classes. Better pick would be
RDFS or OWL, and a logic engine of choice. There are Python
implementations.



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


about application deployment

2007-03-09 Thread Alessandro de Manzano
Hello,

I'ld ask you all about deployment of python applications.

Sometimes (if not most times..) I would make deployment easy (easier)
for my customers (and for me too...)

What I mean, would be very useful to have a jar-like archive/single
file / multiple platform in order to deploy also complex applications
with many modules.

I know about py2exe, it's nice but it's Windows only, I would need
something multiplatform or at least available also for other platforms
(*nix, Mac maybe, ...)

My impression is that Python is a great language but a bit messy
about on field deployment...

What am I missing ? :)
What are your experiences (and solutions ?) for this issues ?

Many thanks in advance!


bye!

Ale

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


Re: opinion needed

2007-03-09 Thread Diez B. Roggisch
azrael wrote:

 id like to hear your opinion about something.
 I just started using Prolog yesterday and i have my doubts about it,
 but it seems to me something like object oriented. so i wanted to ask
 you how usefull prolog is. Sure this is no prolog newsgroup so my
 question is: because it seems object oriented, how important is it by
 understanding python and improving my python skills. because i just
 started it, i may bee totaly wrong or i missunderstood.

OO? Prolog? Last time I checked it was much more functional if anything
else, good for searching solutions in problem-spaces via backtracking.
Certainly a concept one should get ones head wrapped around, if only to
have a new perspective.

No idea how you come to the conclusion it's OO though.

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


Re: about application deployment

2007-03-09 Thread Diez B. Roggisch
Alessandro de Manzano wrote:

 Hello,
 
 I'ld ask you all about deployment of python applications.
 
 Sometimes (if not most times..) I would make deployment easy (easier)
 for my customers (and for me too...)
 
 What I mean, would be very useful to have a jar-like archive/single
 file / multiple platform in order to deploy also complex applications
 with many modules.
 
 I know about py2exe, it's nice but it's Windows only, I would need
 something multiplatform or at least available also for other platforms
 (*nix, Mac maybe, ...)
 
 My impression is that Python is a great language but a bit messy
 about on field deployment...
 
 What am I missing ? :)
 What are your experiences (and solutions ?) for this issues ?

There are the greate setuptools available, that make creating and installing
a single .egg-file (which is very close to a jar) easy as cake - provided
you've got them working.

I'm not sure if there is some equivalent as 

java -jar jar

though. Could be worth thinking about.

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


Re: number generator

2007-03-09 Thread Bjoern Schliessmann
cesco wrote:
 On Mar 9, 3:51 pm, Paul Rubin http://[EMAIL PROTECTED]
 cesco [EMAIL PROTECTED] writes:
 I have to generate a list of N random numbers (integer) whose
 sum is equal to M. If, for example, I have to generate 5 random
 numbers whose sum is 50 a possible solution could be [3, 11, 7,
 22, 7]. Is there a simple pattern or function in Python to
 accomplish that?

Isn't at least one of those numbers depending on the others?

 Given two positive integers, N and M with N  M, I have to
 generate N positive integers such that sum(N)=M. No more
 constraints.

Then why must they be random? div and mod should do it.

Regards,


Björn

-- 
BOFH excuse #220:

Someone thought The Big Red Button was a light switch.

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


Re: Is this right? Multiple imports of same module.

2007-03-09 Thread Lou Pecora
In article [EMAIL PROTECTED],
 Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:

 In [EMAIL PROTECTED], Lou Pecora wrote:
 
  *In mod1.py
  
  import mymodule
  
  *In mod2.py
  
  import mymodule
  
  *In mod3.py
  
  import mymodule as MM
  
  Then mymodule is imported only once, but each module has access to it 
  through the module name (mod1 and mod2) and the alias MM (mod3).  Is 
  that right?
 
 Yes, that's correct.
 
 Ciao,
   Marc 'BlackJack' Rintsch

Thank you.

A further confusion (if I may):

I have noticed that using from xxx import * can lead to problems when 
trying to access variables in the xxx module.

E.g.

-- File f2.py

imvar=1

def prn():
   print imvar

-- File junk.py

from f2 import *
prn()
imvar=2
prn()

-- Running junk.py gives the output:

1
1

Not what I would expect which is,

1
2

Namespaces get confusing.  I have begun to switch to using 'import f2 
as' which gives the 2nd expected result. Safer, but still a bit puzzling.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this right? Multiple imports of same module.

2007-03-09 Thread Simon Brunning
On 3/9/07, Lou Pecora [EMAIL PROTECTED] wrote:
 I have noticed that using from xxx import * can lead to problems when
 trying to access variables in the xxx module.

Don't do it, then. ;-)

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


Re: Is this right? Multiple imports of same module.

2007-03-09 Thread Lou Pecora
In article [EMAIL PROTECTED],
 Bart Ogryczak [EMAIL PROTECTED] wrote:

 On Mar 9, 3:30 pm, Lou Pecora [EMAIL PROTECTED] wrote:
  Then mymodule is imported only once, but each module has access to it
  through the module name (mod1 and mod2) and the alias MM (mod3).  Is
  that right?
 
 Yes, it is.

Praise the Lord.  :-)  I got one right in the namespaces puzzles. (But 
see my followup on using  'from XXX import *' in this thread.  I'm still 
not a namespace guru.

  I was concerned about multiple imports and efficiency.
 
 If the module is already loaded, it won't be loaded again. Dictionary
 of loaded modules is avaliable as sys.modules.

Good to know.  Thank you.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: opinion needed

2007-03-09 Thread Grant Edwards
On 2007-03-09, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 azrael wrote:

 id like to hear your opinion about something.
 I just started using Prolog yesterday and i have my doubts about it,
 but it seems to me something like object oriented. so i wanted to ask
 you how usefull prolog is. Sure this is no prolog newsgroup so my
 question is: because it seems object oriented, how important is it by
 understanding python and improving my python skills. because i just
 started it, i may bee totaly wrong or i missunderstood.

 OO? Prolog? Last time I checked it was much more functional if anything
 else, good for searching solutions in problem-spaces via backtracking.
 Certainly a concept one should get ones head wrapped around, if only to
 have a new perspective.

 No idea how you come to the conclusion it's OO though.

There apparently are OO Prolog extensions:

  http://sourceforge.net/projects/oopl/
  http://www.trinc-prolog.com/doc/pl_obj.htm
  
-- 
Grant Edwards   grante Yow!  These PRESERVES
  at   should be FORCE-FED to
   visi.comPENTAGON OFFICIALS!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: number generator

2007-03-09 Thread Steven D'Aprano
On Fri, 09 Mar 2007 06:44:01 -0800, cesco wrote:

 I have to generate a list of N random numbers (integer) whose sum is
 equal to M. If, for example, I have to generate 5 random numbers whose
 sum is 50 a possible solution could be [3, 11, 7, 22, 7]. Is there a
 simple pattern or function in Python to accomplish that?

No, you'll have to program it yourself.

You might like to Google for the coin change algorithm for some hints on
how to accomplish this. It's not the same problem, but it might give you
some ideas on how to solve it.

The way to solve this problem also depends on what you mean by random
numbers. For example, if the random numbers have to be uniformly
distributed (so that all numbers in the appropriate range are equally
likely to be picked), I think the only way to proceed is with the horribly
inefficient algorithm:

(1) Generate every possible list of N random numbers between 1 and the
maximum value allowed. If the maximum value is (say) 10, there will 10**N
such lists.

(2) Check each list's sum to see if it equals M, and eliminate it if it
doesn't.

That guarantees that the individual random numbers all have the same
probability, but the execution time will explode for large N.


If you relax the requirement that all the random numbers have the same
probability, you can use a heuristic that is biased towards picking
smaller numbers. E.g. something like this:

def make_sum(N, M):
Generate a random list of N ints that sum to M.
# WARNING: untested!

def get_sum(M):
# Returns a list of any length that sums to M.
L = []
while M  0:
n = random.randint(1, M)
L.append(n)
M -= n
return L

L = []
while len(L) != N:
L = get_sum(M)
return L


This isn't a particularly good algorithm, since it will take a LONG time
to return a solution on average, but it should give you some clues towards
solving the problem more efficiently.

Another procedure might be to do something like the following:

We want to make a list of 5 numbers adding up to 50.
The first random number between 1 and 50 might be (say) 13.
So our list will consist of [13] plus a list of 4 numbers adding up to 37.
And so on...

There's a few subtleties which I'll leave to you.

Last but not least, another possible algorithm is to start with a list of
N numbers, regardless of whether or not they add to M, and then adjust
each one up or down by some amount until they sum to the correct value.



-- 
Steven.

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


Re: about application deployment

2007-03-09 Thread Jeff McNeil

If a .egg file is in your sys.path, it would be nice to simply use 'python
-m' in my opinion. As far as I know, you can't '-m' a module that's been
imported from a zip file?



On 3/9/07, Diez B. Roggisch [EMAIL PROTECTED] wrote:


Alessandro de Manzano wrote:

 Hello,

 I'ld ask you all about deployment of python applications.

 Sometimes (if not most times..) I would make deployment easy (easier)
 for my customers (and for me too...)

 What I mean, would be very useful to have a jar-like archive/single
 file / multiple platform in order to deploy also complex applications
 with many modules.

 I know about py2exe, it's nice but it's Windows only, I would need
 something multiplatform or at least available also for other platforms
 (*nix, Mac maybe, ...)

 My impression is that Python is a great language but a bit messy
 about on field deployment...

 What am I missing ? :)
 What are your experiences (and solutions ?) for this issues ?

There are the greate setuptools available, that make creating and
installing
a single .egg-file (which is very close to a jar) easy as cake - provided
you've got them working.

I'm not sure if there is some equivalent as

java -jar jar

though. Could be worth thinking about.

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

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

Problem with new Vista and os.system

2007-03-09 Thread Arne Jamtgaard
I'm getting myself set up on a new Vista box at work, and one of my
old scripts has stopped working.

Specifically, all calls to os.system return a -1.  Whatever action I
was
asking os.system to run does not take place.

Is this a Vista thing, or perhaps just a wonky setting in my
environment.

Oh, python 2.5.

Arne

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


Problem with new Vista and os.system

2007-03-09 Thread Arne Jamtgaard
I'm getting myself set up on a new Vista box at work, and one of my
old scripts has stopped working.

Specifically, all calls to os.system return a -1.  Whatever action I
was
asking os.system to run does not take place.

Is this a Vista thing, or perhaps just a wonky setting in my
environment?
I've installed the latest python (2.5) within the past two weeks...

I've double-checked other functions for os.* and they seem to work
from
the python command line - it's just os.system.

Arne

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


Re: Is this right? Multiple imports of same module.

2007-03-09 Thread Michele Simionato
On Mar 9, 5:18 pm, Lou Pecora [EMAIL PROTECTED] wrote:
 I have noticed that using from xxx import * can lead to problems when
 trying to access variables in the xxx module.

``from xxx import *`` is intended to be used in the interactive
interpreter
only.

Michele Simionato

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


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread dbhbarton
 But all of them are clear on how they work: they affect one line, or have a
 bracket style like /* */ and thus demark clearly what they affect. Even
 someone not fluent in the language in question will quickly grab what they
 mean.

There's nothing remotely fuzzy about how wip or halt comments would
work, nor anything unclear about what they would affect. Nor are they
remotely difficult to explain. They just haven't been employed before,
to my knowledge, even though the underlying effects seem to be a
reasonably common requirement.

 But the key-difference is that the comment in python has a meaning for the
 interpreter - ignore this.

OK that is true. But it's true for the halt comment as well.


 The ? has no meaning. It only has a meaning for an editor.

So it _does_ have meaning! I'm sorry I just don't buy into this kind
of abstract programming ideology, and I never really have. I don't
care what the interpreter finds meaningful and neither, on a day to
day basis, do most users, I'm sure. It seems like the same kind of
aesthetic ideology that leads lots of programmers to feel repulsed by
Python's whitespace block delimiting. There's a more important
principle being missed by them: the human factor. The guy or gal who's
actually _using_ this stuff. BTW I don't mean to imply that you're not
thinking about human readability / useability, just that you don't
seem to be arguing from that basis.


 Not in my opinion -

;p


  Would if I could!

 Well, grab eric3, it's written in python, and teach it to do so! It's an
 exercise in python then :)

I may do that. Thanks for bringing it to my attention.


  What we're talking about here is a form of 'alternate commenting
  style'. With the IDE's cooperation it'd work on whole blocks at once,
  it would highlight without disrupting the code concerned (at least the
  way I'm envisaging it), it would be versatile (could probably be used
  for as big a variety of purposes as the # comment), and yes, it'd be
  persistent, which is how it would be different from any IDE-based
  highlighting.

 I think you contradict yourself here. On the one side, you want it not
 disturbing to the eye, yet it should be highlighted, so it will be directly
 noticed by that same eyes.

You misread me. I wasn't talking about visual disturbance but 'code
disturbance'. Let me rephrase..
..it would highlight without causing the highlighted code to be
ignored by the interpreter..


 it _is_ an disturbance. And with an IDE that stores such information in
 e.g. project metainformation, you can even have the persistence, without
 the disturbance and without altering python.

So it's fine and wonderful to add a massive chunk of code to IDEs to
introduce jargon-strewn behaviour that newbies have little hope of
comprehending yet alone taking advantage of, and which will inevitably
behave differently in any IDE that does get around to providing it?
But adding two special characters to the core language is 'messy'?

I can't argue with your aesthetic dislike of the proposed syntax, it's
just the reasoning you use to support your stance that doesn't ring
true to me! (I trust no offense is caused.)

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


Re: Creat a DLL File from python code, and use that DLL file in other Platform (Labview, Java .NET etc)

2007-03-09 Thread Larry Bates
[EMAIL PROTECTED] wrote:
 Hi,
 
 I would like to request your attention for this very specific issue:
 
 I have several classes in Python, and now I want simply re-use it, in
 other language.
 
 
 The closest to solution I think I came was with this site:
 http://www.py2exe.org/index.cgi/Py2exeAndCtypesComExeServer?highlight=%28%28Py2exeAndCtypesComDllServer%29%29
 but I not able to solve questions related with TLB files and
 __init__.py files.
 
 So, could anyone give a tip about HOW TO CREAT a dll file from Python?
 
 thank in advance
 
 AMMS
 
Do you absolutely need .DLL?  You can make a class into a COM object that
nearly every language on the planet can dispatch with ease.  Here is some
info:

http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html

Calling an existing .DLL?  Use ctypes module.

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


Re: Pb with descriptor and super ...

2007-03-09 Thread Arnaud Delobelle
On Mar 9, 11:22 am, Erwan Adam [EMAIL PROTECTED] wrote:
[snip]

 [EMAIL PROTECTED] /home/adam/Work/Python] python super_from_guido.py
 Using built-in super
 Desc.__get__ : class_name is A, obj is __main__.B object at 0xb7bc302c
 and typ is class '__main__.B'
 Using python Super
 Desc.__get__ : class_name is A, obj is __main__.B object at 0xb7bc302c
 and typ is None
 Using python MySuper
 Desc.__get__ : class_name is A, obj is __main__.B object at 0xb7bc302c
 and typ is class '__main__.A'

It seems to me that it is the built-in super which has the correct
behaviour.  When you write obj.attr, python calls  attr.__get__(obj,
type(obj)) and not attr.__get__(obj) which sets the second arg to
None. You can check this by creating a barebone descriptor that simply
prints its arguments:

class D(object):
def __get__(self, obj, objtype):
print obj, objtype

class A(object):
d=D()

A().d
__main__.A object at 0x133c5f0 class '__main__.A' # objtype is not
None!

Therefore in your case when you do super(B, b).attr then
A.__dict__['attr'].__get__(b, type(b)) is called. You can try this, it
should give the same output as builtin super.

 the Super gives None for typ ... which is quite surprising !
 In MySuper, I just change

  x = x.__get__(self.__obj__)

 by

  x = x.__get__(self.__obj__, cls)
 at the -3 :) line of the class ... and it gives the result I expected
 at the beginning : obj is b and typ is A 

Neither of these are right I think. If my explanation above is right
the correct line should be:
x = x.__get__(self.__obj__, type(self.__obj__))

HTH

--
Arnaud

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


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Diez B. Roggisch

 The ? has no meaning. It only has a meaning for an editor.
 
 So it _does_ have meaning! I'm sorry I just don't buy into this kind
 of abstract programming ideology, and I never really have. I don't
 care what the interpreter finds meaningful and neither, on a day to
 day basis, do most users, I'm sure. It seems like the same kind of
 aesthetic ideology that leads lots of programmers to feel repulsed by
 Python's whitespace block delimiting. There's a more important
 principle being missed by them: the human factor. The guy or gal who's
 actually _using_ this stuff. BTW I don't mean to imply that you're not
 thinking about human readability / useability, just that you don't
 seem to be arguing from that basis.

I certainly do. Because a comment is always a comment. If you happen to 
have a multi-line comment (in python that is) that spans more than a 
page of your current terminal, you clearly will see it as such when 
piped through less - a frequent tool for looking into code of libraries 
for example. At least for me, and I guess some other coders as well.

But a tiny ? or !, the latter one massively changing the semantics of 
the displayed code? I'm not too positive that this will be getting the 
proper attention needed when comprehending the code.

Even the multiline-comments of C are easier, because they feature an 
end-mark. Which for one _is_ easier to implement, thus even less might 
implement some syntax  hi-lighting based on it (if the terminal supports 
that, that is. I've been doing my fair share of last-minute hacking 
through malconfigured ssh-connections in vi, no syntax-highlighting 
whatsoever) - while it is much less probable that less will grow a 
full blown python parser just for the sake of hi-lighting a !-prefixed 
block of code.


FWIW, I'm totally convinced that the addition of this feature to the 
interpreter itself would be a minor operation that wouldn't cause much 
headache from a implementation POV. It's just I don't buy into its 
usefulness.

 
 What we're talking about here is a form of 'alternate commenting
 style'. With the IDE's cooperation it'd work on whole blocks at once,
 it would highlight without disrupting the code concerned (at least the
 way I'm envisaging it), it would be versatile (could probably be used
 for as big a variety of purposes as the # comment), and yes, it'd be
 persistent, which is how it would be different from any IDE-based
 highlighting.
 I think you contradict yourself here. On the one side, you want it not
 disturbing to the eye, yet it should be highlighted, so it will be directly
 noticed by that same eyes.
 
 You misread me. I wasn't talking about visual disturbance but 'code
 disturbance'. Let me rephrase..
 ..it would highlight without causing the highlighted code to be
 ignored by the interpreter..


What do you mean by code-disturbance? Programming is usually something 
that needs carefully assembled sequences of characters, with some 
seemingly minor interpunction characters becoming extremly meaningful. 
And you want to add to that the complexity of something that has _no_ 
meaning at all - for the language. To me that is a disturbance. Clearly 
a matter of taste, though.

 
 it _is_ an disturbance. And with an IDE that stores such information in
 e.g. project metainformation, you can even have the persistence, without
 the disturbance and without altering python.
 
 So it's fine and wonderful to add a massive chunk of code to IDEs to
 introduce jargon-strewn behaviour that newbies have little hope of
 comprehending yet alone taking advantage of, and which will inevitably
 behave differently in any IDE that does get around to providing it?
 But adding two special characters to the core language is 'messy'?

Adding two characters to the language from which one's only purpose is 
to support the introduction of jargon-strewn behavior that newbies have 
little hope of comprehending let alone taking advantage of, and which 
will inevitable behave differently in any IDE that does get around 
providing it.

I couldn't say it better. It is exactly my point: the ? is _nothing_ 
without an IDE, where _none_ of them is forced to interpret and 
represent it by any means. Yet still you want to add it? Sorry, I can't 
buy that.

Besides, the whole purpose of IDEs is to add massive chunks of code to 
e.g. analyze class structures, show syntactic errors even before the 
code is run and so on... so if you accept that editing code is more than 
poking with a hex editor on your hard disk image, I fail to see the 
problem of adding such chunks of code if it is feasible.

 I can't argue with your aesthetic dislike of the proposed syntax, it's
 just the reasoning you use to support your stance that doesn't ring
 true to me! (I trust no offense is caused.)

Certainly not. And I don't intend to cause offense myself!

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


Re: about application deployment

2007-03-09 Thread Larry Bates
Alessandro de Manzano wrote:
 Hello,
 
 I'ld ask you all about deployment of python applications.
 
 Sometimes (if not most times..) I would make deployment easy (easier)
 for my customers (and for me too...)
 
 What I mean, would be very useful to have a jar-like archive/single
 file / multiple platform in order to deploy also complex applications
 with many modules.
 
 I know about py2exe, it's nice but it's Windows only, I would need
 something multiplatform or at least available also for other platforms
 (*nix, Mac maybe, ...)
 
 My impression is that Python is a great language but a bit messy
 about on field deployment...
 
 What am I missing ? :)
 What are your experiences (and solutions ?) for this issues ?
 
 Many thanks in advance!
 
 
 bye!
 
 Ale
 
I think you are going to find that you need different deployment
methods for different operating systems.  When you deploy you will
no doubt have different things to do (shortcuts, registry entries,
.INI file entries, etc.) that you want to do.

On Windows my choice is py2exe to bundle and then Inno Installer
to make a setup.exe distrubution program that handles the install
and uninstall.  Others can chime in on linux, mac, etc.

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


SQLite3 trapping OperationalError

2007-03-09 Thread jim-on-linux
pyhelp,

I set up a table in SQLite3.

While running other modules I want to know if a  
table exists.

SQL has a command List Tables but I don't think 
SQLlite3 has this command.

I've tried 
   cursor.execute(select * from debtor where key
is not null )

The table debtor does not exist so I get 
OperationalError
which I want to trap with try/except or some other 
way.

However python 2.5, 
except OperationalError: 
responds with 
OperationalError is not defined.

Ideas on how to determine if a table exists would 
be welcome.

jim-on-linux


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


Re: SQLite3 trapping OperationalError

2007-03-09 Thread Jerry Hill
On 3/9/07, jim-on-linux [EMAIL PROTECTED] wrote:
 However python 2.5,
 except OperationalError:
 responds with
 OperationalError is not defined.

I believe that needs to be spelled
except sqlite3.OperationalError:
do_something()

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


Re: SQLite3 trapping OperationalError

2007-03-09 Thread jim-on-linux
On Friday 09 March 2007 13:10, Jerry Hill wrote:
 On 3/9/07, jim-on-linux [EMAIL PROTECTED] 
wrote:
  However python 2.5,
  except OperationalError:
  responds with
  OperationalError is not defined.

 I believe that needs to be spelled
 except sqlite3.OperationalError:
 do_something()

 --
 Jerry

Thanks,
 except sqlite3.OperationalError:
works for me.

jim-on-linux
-- 
http://mail.python.org/mailman/listinfo/python-list


Are Lists thread safe?

2007-03-09 Thread abcd
Are lists thread safe?  Or do I have to use a Lock when modifying the
list (adding, removing, etc)?  Can you point me to some documentation
on this?

thanks

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


Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Matthew Woodcraft
Bruno Desthuilliers  [EMAIL PROTECTED] wrote:
 Nick Craig-Wood a ecrit :
 I use # FIXME for this purpose or /* FIXME */ in C etc.

 I have an emacs macro which shows it up in bright red / yellow text
 so it is easy to see

 Thanks you both.

For what it's worth, sufficiently recent versions of emacs python-mode
have this built in.

-M-

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


Re: merits of Lisp vs Python

2007-03-09 Thread Tim Bradshaw
On 2007-03-09 07:00:06 +, [EMAIL PROTECTED] (Alex Martelli) said:

 (nee One Laptop Per Child, OLPC, and once known as the $100 laptop)
 uses Python as its preferred (only?-) application language, and it's
 slated to be the most widely distributed Python distro if it hits even
 half of its ambitious target-numbers...

But it won't get anywhere near that because it's a stupid an 
ill-conceived idea (not because of Python, note!).  The electronic 
gadget people need in the developing world is a mobile phone not a 
computer.

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


Re: Are Lists thread safe?

2007-03-09 Thread Larry Bates
abcd wrote:
 Are lists thread safe?  Or do I have to use a Lock when modifying the
 list (adding, removing, etc)?  Can you point me to some documentation
 on this?
 
 thanks
 
You really should at least try Google first:

http://effbot.org/pyfaq/what-kinds-of-global-value-mutation-are-thread-safe.htm

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


Re: Best place for a function?

2007-03-09 Thread Inyeol Lee
On Wed, Mar 07, 2007 at 05:27:04PM -0500, Sergio Correia wrote:
 I'm writing a class, where one of the methods is kinda complex. The
 method uses a function which I know for certain will not be used
 anywhere else. This function does not require anything from self, only
 the args passed by the method.
 
 Where should I put the function?

Use staticmethod. It's a normal function with class namespace.

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


Re: Are Lists thread safe?

2007-03-09 Thread Greg Copeland
On Mar 9, 1:03 pm, abcd [EMAIL PROTECTED] wrote:
 Are lists thread safe?  Or do I have to use a Lock when modifying the
 list (adding, removing, etc)?  Can you point me to some documentation
 on this?

 thanks


Yes there are still some holes which can bite you.  Adding and
removing is thread safe but don't treat the list as locked between
operations unless you specifically do your own locking.  You still
need to be on the lookout for race conditions.

Greg

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


  1   2   >