list index()

2007-08-29 Thread zzbbaadd
What's with the index() function of lists throwing an exception on not
found? Let's hope this is rectified in Python 3. If nothing else, add
a function that doesn't throw an exception. There are a million
situations where you can have an item not be in a list and it is not
an exception situation.

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


Re: self extracting zipefile (windows) and (standard module) zipefile

2007-08-29 Thread Werner
On 30 Aug., 06:26, Scott David Daniels <[EMAIL PROTECTED]> wrote:
> Grant Edwards wrote:
>
> ...
>
> > Another option is to search through the file from the beginning
> > looking for whatever signature matches the beginning of a
> > "normal" zip file.  The self-extracting zipfiles that I've
> > dissected are just an executable image concatenated with a
> > "normal" zipfile.  If you just start searching from the
> > beginning of the file, it's simple to find the actual zip data
> > and copy it into a separate file which then can be unzipped
> > like any other plain zipfile.
>
> Actually, the zip format is defined from the _end_ rather than
> the _beginning_ of the file.  Some random file with a zip file
> concatenated on the end will have the same contents as the zip
> file.  You can even point Python itself at such files and get
> data via:
>  import zipfile
>  zf = zipfile.ZipFile('something.exe')
>  ...
>
> -Scott David Daniels
> [EMAIL PROTECTED]

I hoped, this would work, but I got ":
File is not a zip file"...
WinZip and 7-ZIP may handle this file, so I take the command line
version of 7-Zip (but I'd prefered a Python only version)

Thanks
Werner

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


Re: self extracting zipefile (windows) and (standard module) zipefile

2007-08-29 Thread Werner
On 29 Aug., 15:23, [EMAIL PROTECTED] wrote:
> On Aug 29, 6:53 am, Werner <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Hi,
>
> > I try to read (and extract) some "self extracting" zipefiles on a
> > Windows system. The standard module zipefile seems not to be able to
> > handle this.
>
> > >>> fName = r"C:\tmp\mySelfExtratingFile.exe"
> > >>> import zipfile
> > >>> zipefile.is_zipfile(fName))
>
> > False
>
> > Is there a wrapper or has some one experience with other libaries to
> > extract those files?
>
> > Thanks in advance
> > Werner
>
> Since it's an executable, why not just use the subprocess module?
>
> I did find this set of scripts, but I don't know if they will 
> help:http://www.example-code.com/python/zip.asp
>
> I did find how to extract via the command line, which you could use in
> conjunction with the subprocess 
> module:http://help.globalscape.com/help/cutezip2/Creating_and_extracting_arc...
>
> Mike- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

thank you for answer. I found, that WinZip aund 7-ZIP may handle my
files (I'm not shure, if it's really zip...) So, I thing I try the 7-
zip command line tool (but I'd prefered a Python buildin version)

Werner

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


Re: status of Programming by Contract (PEP 316)?

2007-08-29 Thread Russ

> I disagree. IMO automatic testing is thousands of times better than
> design by contract and Python has already all the support you need
> (unittest, doctest, py.test, nose, ...)

In theory, anything you can verify with "design by contract" you can
also verify with unittest and the rest. However, "design by contract"
has a major practical advantage: if you have real (or simulated)
inputs available, you don't need to write a test driver or generate
test inputs for each class or function.

All you need to do is to run your program with the real (or simulated)
inputs, all the internal data that gets passed around between classes
and functions gets generated as usual, and everything gets tested
automatically. In other words, you are spared the potentially
considerable effort of generating and storing samples of all the
internal data that gets passed around internally.

You may want to do unit tests also, of course. Separate unit tests
will give you more control and allow you to test individual classes
and functions using a wider variety of inputs. But if your design by
contract is comprehensive (i.e., passing it guarantees correct
functioning of your code), then your unit tests can simply make use of
the tests already available in the design by contract. So you've done
no extra work in setting up the design by contract anyway.

Another significant advantage of "design by contract" is that the
tests are all right there in your source code, where they are much
less likely to get lost or ignored by subsequent programmers who need
to maintain the code.  Relying on separate units tests is a bit like
relying on extended "comments" or design documents that are separate
from the code. Yes, those are certainly useful, but they do not
eliminate the need for comments in the code.

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


We need PIGs :)

2007-08-29 Thread Martin Marcher
Hello,

having worked quite a bit with python in the last months (some Java
before, and some C++ before that) I was very impressed by an idea the
Java people had.

Explanation: the JSRs define how to implement certain services and or
features in Java so that they can be reused. I haven't found such a
thing for python yet.

Say I have the problem of authentication. Now I can implement
authentication against a text file with a "key : value" format.

However someone may find it more suitable to implement a
authentication backend for exactly this app that can use postgres.

Who else can use the authentication for my program created by a third
party in his or her own app/package/module? To my knowledge noone as
there's nothing you could at least theoretically keep to.

My idea was to define "Python Implementation Guidelines" (PIGs) that
specify a problem formalize it enough so that implementations are
interchangeable (in this example create a module that has an
"authenticate(username, password)" method so that one could easily
take that module for any given app and then authenticate against
postgres, and also against my plaintext file (which was the original -
quite useless - implementation).

Does that sound like a good idea or would that be over formalization?

Personally I think that would be great as I could search the PIGs at
(hopefully) python.org find out the number and search at koders.com or
code.google.com for python code that has "PIG: XXX" in the metadata
docstring or wherever - maybe even a __pig__ = XXX variable.

any input is welcome (also point me to the place where that can be
found if it already exists)
martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python molecular viewer

2007-08-29 Thread Scott David Daniels
Andy Cheesman wrote:
> Dear People,
> 
> I was wondering if people could recommend a simple molecular viewing
> package written in python. I'm working in Theoretical chemistry and I'm
> not after an all-singing dancing molecular rendering package(pymol does
> that rather well) but a program which reads XYZ files and displays
> simple structures which can be rotated in 3D

You could use VPython if you know how to convert XYZ files to ball and
stick locations to cartesian coordinates.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: self extracting zipefile (windows) and (standard module) zipefile

2007-08-29 Thread Scott David Daniels
Grant Edwards wrote:
...
> Another option is to search through the file from the beginning
> looking for whatever signature matches the beginning of a
> "normal" zip file.  The self-extracting zipfiles that I've
> dissected are just an executable image concatenated with a
> "normal" zipfile.  If you just start searching from the
> beginning of the file, it's simple to find the actual zip data
> and copy it into a separate file which then can be unzipped
> like any other plain zipfile.

Actually, the zip format is defined from the _end_ rather than
the _beginning_ of the file.  Some random file with a zip file
concatenated on the end will have the same contents as the zip
file.  You can even point Python itself at such files and get
data via:
 import zipfile
 zf = zipfile.ZipFile('something.exe')
 ...

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


Re: Python molecular viewer

2007-08-29 Thread Greg Couch
Andy Cheesman <[EMAIL PROTECTED]> writes:

>Dear People,

>I was wondering if people could recommend a simple molecular viewing
>package written in python. I'm working in Theoretical chemistry and I'm
>not after an all-singing dancing molecular rendering package(pymol does
>that rather well) but a program which reads XYZ files and displays
>simple structures which can be rotated in 3D

>Thanks

>Andy

Check out http://www.cgl.ucsf.edu/chimera/.  Unlike PyMol, all of the
molecular data is accesible from Python.  It still might be too much
of an all-singing dancing molecular rendering package for you though.

Greg Couch
UCSF Computer Graphics Lab
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Jython 2.2 on Ubuntu

2007-08-29 Thread smalltalk
On Aug 29, 10:50 pm, Neil Wallace <[EMAIL PROTECTED]>
wrote:
> Thanks Tim,
>
> I subscribed to the Jython group hosted by sourceforge, and they are a
> great bunch of guys/gals.
>
> Here's what I did to fix my problem.
>
> 1. removed Jython 2.1 (using Synaptic)jytho
> 2. added the following lines (as root) to /etc/profile
>  # set PATH for Jython
>  PATH=$PATH:/home/neil/jython2.2
>  export PATH
>
> I had to restart X, that's it solved!!
>
> Neil
>
>
>
> Tim Couper wrote:
> > you need to ensure that the correct jython executable is in a directory
> > which is on your on your path.
>
> > I've just successfully test-subscribed to
> >https://lists.sourceforge.net/lists/listinfo/jython-users. Maybe you
> > could try again.
>
> > Tim
>
> > Dr Tim Couper
> > CTO, SciVisum Ltd
>
> >www.scivisum.com
>
> > Neil Wallace wrote:
> >> Hi all,
>
> >> I am a novice Python/Jython programmer, and Ubuntu user.
>
> >> Ubuntu still only supports only version 2.1 of Jython. I have used the
> >> GUI installer of Jython 2.2, and installed it to the default
> >> /root/jython2.2 directory. The install went without issues.
>
> >> However, typing jython --version
> >> in a teminal still gives me    Jython 2.1 on java (JIT: null)
>
> >> What else do I need to do?
>
> >> regards
> >> Neil.
>
> >> p.s. I posted this to the jython group hosted by sourceforge, but it
> >> bounced. :-(- Hide quoted text -
>
> - Show quoted text -

you can use eclipse + pydev
it is very easy to setup jython or python

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


Re: status of Programming by Contract (PEP 316)?

2007-08-29 Thread Michele Simionato
On Aug 30, 1:17 am, Dan Stromberg - Datallegro
<[EMAIL PROTECTED]> wrote:
> IMO, putting Programming by Contract into python as part of the language
> itself, or as a simple module, is a little bit like a company or
> department coming up with a mission statement.  It's easy to say that it's
> meaningless, and some will ignore it, but it still kind of sets the tone
> for how things "should be done".

I disagree. IMO automatic testing is thousands of times better than
design by contract and Python has already all the support you need
(unittest, doctest, py.test, nose, ...)


 Michele Simionato

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


Re: Is LOAD_GLOBAL really that slow?

2007-08-29 Thread Carsten Haese
On Wed, 2007-08-29 at 19:23 -0600, Adam Olsen wrote:
> It seems a common opinion that global access is much slower than local
> variable access.  However, my benchmarks show a relatively small
> difference:
> 
> ./python -m timeit -r 10 -v -s 'x = [None] * 1
> def foo():
>   for i in x:
> list; list; list; list; list; list; list; list; list; list' 'foo()'
> 10 loops -> 0.0989 secs100 loops -> 0.991 secs
> raw times: 0.999 0.985 0.987 0.985 0.985 0.982 0.982 0.982 0.981 0.985
> 100 loops, best of 10: 9.81 msec per loop
> 
> ./python -m timeit -r 10 -v -s 'x = [None] * 1
> def foo():
>   mylist = list
>   for i in x:
> mylist; mylist; mylist; mylist; mylist; mylist; mylist; mylist;
> mylist; mylist' 'foo()'
> 10 loops -> 0.0617 secs
> 100 loops -> 0.61 secs
> raw times: 0.603 0.582 0.582 0.583 0.581 0.583 0.58 0.583 0.584 0.582
> 100 loops, best of 10: 5.8 msec per loop
> 
> So global access is about 70% slower than local variable access.  To
> put that in perspective, two local variable accesses will take longer
> than a single global variable access.
> 
> This is a very extreme benchmark though.  In practice, other overheads
> will probably drop the difference to a few percent at most.  Not that
> important in my book.

Your comparison is flawed, because the function call and the inner for
loop cause a measurement offset that makes the locals advantage seems
smaller than it is. In the interest of comparing the times for just the
local lookup versus just the global lookup, I think the following
timings are more appropriate:

$ python2.5 -mtimeit -r10 -s"y=42" -s"def f(x): pass" "f(42)"
100 loops, best of 10: 0.3 usec per loop
$ python2.5 -mtimeit -r10 -s"y=42" -s"def f(x): x" "f(42)"
100 loops, best of 10: 0.331 usec per loop
$ python2.5 -mtimeit -r 10 -s"y=42" -s"def f(x): y" "f(42)"
100 loops, best of 10: 0.363 usec per loop

There is no loop overhead here, and after subtracting the function call
overhead, I get 31 nanoseconds per local lookup and 63 nanoseconds per
global lookup, so local lookups are just about twice as fast as global
lookups.

True, whether this difference is significant does depend on how many
name lookups your code makes and how much else it's doing, but if you're
doing a lot of number crunching and not a lot of I/O, the difference
might be significant. Also, even if using local names is only slightly
faster than using globals, it's still not slower, and the resulting code
is still more readable and more maintainable. Using locals is a win-win
scenario.

Hope this helps,

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: IDE for Python

2007-08-29 Thread Eric S. Johansson
Ben Finney wrote:
> Stefan Behnel <[EMAIL PROTECTED]> writes:

> "Neither"? Emacs is both editor *and* IDE.

I think of it more as feature full but somehow unsatisfying.  For example, for 
those of us PRDs ( Politely Referred to as Disabled) who are trying to program 
by voice could use an enumeration of all symbols visible from a cursor on 
outward through method, class, and file scope, etc.  then we can take we can 
speak symbols and make them pronounceable as well as synthesize a grammar so 
that one can refer to symbols in the object hierarchy by absolute paths as well 
as individual symbols.

it's just an idea at this stage but it could be fun to see how well it would 
work in real life

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


RE: How to use os.putenv() ?

2007-08-29 Thread Ryan Ginstrom
> On Behalf Of [EMAIL PROTECTED]
> What am I doing wrong?  How do I change the value of an 
> environment variable?

You'll have to go through the Windows registry. Please have a look at the
following recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/55993

I also have my own routines based on that for getting and setting the path:

##

import _winreg as winreg
import win32gui
import win32con

REG_KEY_PATH = r'SYSTEM\CurrentControlSet\Control\Session
Manager\Environment'

def set_path(pathval):
"""Set the PATH environment variable"""

try:
reg = winreg.ConnectRegistry(None,
 win32con.HKEY_LOCAL_MACHINE)
key = winreg.OpenKey(reg,
 REG_KEY_PATH,
 0,
 win32con.KEY_ALL_ACCESS)

winreg.SetValueEx(key,
  'path',
  0,
  win32con.REG_EXPAND_SZ,
  pathval)

win32gui.SendMessage(win32con.HWND_BROADCAST,
 win32con.WM_SETTINGCHANGE,
 0,
 'Environment')

finally:
winreg.CloseKey(key)
winreg.CloseKey(reg)

def get_path():
"""Get the PATH environment variable"""
try:
reg = winreg.ConnectRegistry(None,
 win32con.HKEY_LOCAL_MACHINE)
key = winreg.OpenKey(reg,
 REG_KEY_PATH,
 0,
 win32con.KEY_ALL_ACCESS)

return winreg.QueryValueEx(key,
   'path')[0]

finally:
winreg.CloseKey(key)
winreg.CloseKey(reg)

##

Regards,
Ryan Ginstrom

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


Re: How to use os.putenv() ?

2007-08-29 Thread Graham Dumpleton
On Aug 30, 11:21 am, [EMAIL PROTECTED] wrote:
> >>> import os
>
> >>> os.environ['PATH']
>
> 'C:\\WINNT\\system32;C:\\WINNT;C:\\WINNT\\System32\\Wbem;%C:\\WINNT%\
> \system32;%C:\\WINNT%;%C:\\WINNT%\\System32\\Wbem'
>
> >>> os.putenv('PATH', 'C:\\WINNT\\system32')
>
> >>> os.environ['PATH']
>
> 'C:\\WINNT\\system32;C:\\WINNT;C:\\WINNT\\System32\\Wbem;%C:\\WINNT%\
> \system32;%C:\\WINNT%;%C:\\WINNT%\\System32\\Wbem'
>
>
>
> What am I doing wrong?  How do I change the value of an environment
> variable?

What you are missing is that os.environ is only populated from the
global process environment at process startup.

If you update os.environ the changes will be pushed into the global
process environment as well. But if you use os.putenv() instead,
bypassing os.environ, the changes will not show in os.environ.

To confirm that the global process environment is being updated, use
os.getenv().

Graham

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


Re: replacing xml elements with other elements using lxml

2007-08-29 Thread Ultrus
Ah! I figured it out. I forgot that the tree is treated like a list.
The solution was to replace the  element with the first 
child, then use Python's insert(i,x) function to insert elements after
the first one.

lxml rocks!

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


RE: Pythonwin Install COM exceptions on Windows Vista Ultimate

2007-08-29 Thread Sandipan News
How do I deactivate UAC and Router?

I did run as Administrator and installed both Python and Pythonwin into
c:\Python25\

This is the error I got ...

Here is the log at the end of the install:

Copied pythoncom25.dll to C:\Outils\Python\pythoncom25.dll
Copied pywintypes25.dll to C:\Outils\Python\pywintypes25.dll
You do not have the permissions to install COM objects.
The sample COM objects were not registered.
-> Software\Python\PythonCore\2.5\Help[None]=None
-> Software\Python\PythonCore\2.5\Help\Pythonwin
Reference[None]='C:\\Outils\\Python\\Lib\\site-packages\\PyWin32.chm'
Creating directory C:\Outils\Python\Lib\site-packages\win32com\gen_py
Shortcut for Pythonwin created
Shortcut to documentation created
The pywin32 extensions were successfully installed.

Thanks.

Sandipan

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Méta-MCI (MVP)
Sent: Wednesday, August 29, 2007 9:19 AM
To: python-list@python.org
Subject: Re: Pythonwin Install COM exceptions on Windows Vista Ultimate

Hi!

Perso, on Vista, I :
  - deactive UAC
  - deactive firewall (I have a rooter)
  - run all like Administrator
  - install all in other DIR than "Program Files"

Result :  no problem.


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


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


RE: Pythonwin Install COM exceptions on Windows Vista Ultimate

2007-08-29 Thread Sandipan News
Here is the log at the end of the install:

Copied pythoncom25.dll to C:\Outils\Python\pythoncom25.dll
Copied pywintypes25.dll to C:\Outils\Python\pywintypes25.dll
You do not have the permissions to install COM objects.
The sample COM objects were not registered.
-> Software\Python\PythonCore\2.5\Help[None]=None
-> Software\Python\PythonCore\2.5\Help\Pythonwin
Reference[None]='C:\\Outils\\Python\\Lib\\site-packages\\PyWin32.chm'
Creating directory C:\Outils\Python\Lib\site-packages\win32com\gen_py
Shortcut for Pythonwin created
Shortcut to documentation created
The pywin32 extensions were successfully installed.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Wednesday, August 29, 2007 9:25 AM
To: python-list@python.org
Subject: Re: Pythonwin Install COM exceptions on Windows Vista Ultimate

On Aug 28, 8:20 pm, "Sandipan News" <[EMAIL PROTECTED]> wrote:
> What do I do? Can't do without Python!
> Any experience, advice, hope is welcome.
> Thanks.
> Sandipan

You need to post the error traceback along with some more information
so the community can help.

Mike

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


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


How to use os.putenv() ?

2007-08-29 Thread google
>>>
>>> import os
>>>
>>> os.environ['PATH']
'C:\\WINNT\\system32;C:\\WINNT;C:\\WINNT\\System32\\Wbem;%C:\\WINNT%\
\system32;%C:\\WINNT%;%C:\\WINNT%\\System32\\Wbem'
>>>
>>> os.putenv('PATH', 'C:\\WINNT\\system32')
>>>
>>> os.environ['PATH']
'C:\\WINNT\\system32;C:\\WINNT;C:\\WINNT\\System32\\Wbem;%C:\\WINNT%\
\system32;%C:\\WINNT%;%C:\\WINNT%\\System32\\Wbem'
>>>

What am I doing wrong?  How do I change the value of an environment
variable?

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


Is LOAD_GLOBAL really that slow?

2007-08-29 Thread Adam Olsen
It seems a common opinion that global access is much slower than local
variable access.  However, my benchmarks show a relatively small
difference:

./python -m timeit -r 10 -v -s 'x = [None] * 1
def foo():
  for i in x:
list; list; list; list; list; list; list; list; list; list' 'foo()'
10 loops -> 0.0989 secs100 loops -> 0.991 secs
raw times: 0.999 0.985 0.987 0.985 0.985 0.982 0.982 0.982 0.981 0.985
100 loops, best of 10: 9.81 msec per loop

./python -m timeit -r 10 -v -s 'x = [None] * 1
def foo():
  mylist = list
  for i in x:
mylist; mylist; mylist; mylist; mylist; mylist; mylist; mylist;
mylist; mylist' 'foo()'
10 loops -> 0.0617 secs
100 loops -> 0.61 secs
raw times: 0.603 0.582 0.582 0.583 0.581 0.583 0.58 0.583 0.584 0.582
100 loops, best of 10: 5.8 msec per loop

So global access is about 70% slower than local variable access.  To
put that in perspective, two local variable accesses will take longer
than a single global variable access.

This is a very extreme benchmark though.  In practice, other overheads
will probably drop the difference to a few percent at most.  Not that
important in my book.

So my question: does somebody have a globals benchmark that shows a
really significant slowdown vs local variables?

-- 
Adam Olsen, aka Rhamphoryncus
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: copying files

2007-08-29 Thread Carsten Haese
On Wed, 2007-08-29 at 17:03 -0400, Brian McCann wrote:
> what do the + signs do?

Start here: http://docs.python.org/tut/

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: Haskell like (c:cs) syntax

2007-08-29 Thread Carl Banks
On Tue, 28 Aug 2007 17:30:47 -0500, Erik Jones wrote:
> On Aug 28, 2007, at 5:12 PM, Chris Mellon wrote:
>> When working with lists, Python has a slice syntax (which is rather
>> more powerful than Haskells limited head->tail linked list syntax) that
>> you can use to chop a sequence up into various parts.
> 
> That is extremely arguable (in fact, Haskell's list semantics are
> extremely powerful as they are not limited to just head/tail).

Apples and oranges, really.  Pattern matching can do an awful lot of cool 
things, but arbitrary slicing isn't one of the more pleasant ones.  (At 
least not without a good set of slice-matching patterns handy, which I 
don't know if Haskell has.)


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


Re: status of Programming by Contract (PEP 316)?

2007-08-29 Thread Russ

> But it's always a good idea to make your software "correct and as
> reliable as possible", isn't it? The problem is the external constraints
> on the project. As the old saying goes: "Cheap, fast, reliable: choose
> any two".

If you are suggesting that "programming by contract" is not
appropriate for every application, you will get no argument from me.
All I am suggesting is that having the option to use it when you need
it is very desirable, and it can possibly enhance the versatility of
Python by making Python more suitable for *some* mission-critical
applications.

I once read a book on something called SPARK Ada, which also supports
programming by contract. I was pleasantly surprised to discover
yesterday that support for the such methods is also available for
Python. However, the support would obviously be a bit stronger if it
were in the core Python distribution.

What I really like about the implementation I cited above is that the
invariants and the pre and post-conditions can all be put right in the
doc string at the beginning of each class or function. You can think
of it as a detailed specification of the intent (or of some of the
requirements or constraints) of the class or function -- which can be
*automatically* checked during testing. It can also be used for
explicit type checking.

It's like having some of your most critical unit tests built right
into your code. It may make your code very verbose, but it will also
be very complete.



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


Re: IDE for Python

2007-08-29 Thread Ben Finney
Stefan Behnel <[EMAIL PROTECTED]> writes:

> Eric CHAO wrote:
> > I think many python developers don't need such an IDE actually. Just
> > like Ruby guys, they use a powerful editor, for example, Textmate,
> > instead of all-in-one IDE. It's quick and direct.
> 
> True. However, some use neither an editor nor an IDE but Emacs.

"Neither"? Emacs is both editor *and* IDE.

-- 
 \"Some people, when confronted with a problem, think 'I know, |
  `\   I'll use regular expressions'. Now they have two problems."  -- |
_o__)Jamie Zawinski, in alt.religion.emacs |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: status of Programming by Contract (PEP 316)?

2007-08-29 Thread Dan Stromberg - Datallegro
On Tue, 28 Aug 2007 23:45:28 -0700, Russ wrote:

> On Aug 28, 10:58 pm, Michele Simionato <[EMAIL PROTECTED]>
> wrote:
> 
>> Why do you think that would ad a strong positive capability?
>> To me at least it seems a big fat lot of over-engineering, not
>> needed in 99% of programs. In the remaining 1%, it would still not
>> be needed since Python provides out of the box very powerful
>> metaprogramming capabilities so that you can implement
>> yourself the checks you need, if you really need them.
> 
> I get the strong impression you don't really understand what
> programming by contract is.
> 
> I have not yet personally used it, but I am interested in anything
> that can help to make my programs more reliable. If you are
> programming something that doesn't really need to be correct, than you
> probably don't need it. But if you really need (or want) your software
> to be correct and reliable as possible, I think you you should be
> interested in it. You might want to read this:
> 
> http://archive.eiffel.com/doc/manuals/technology/contract/ariane/page.html

I agree with Chris - there's no need to be condescending.

However, I agree with you that this is a valuable addition to a language.

It's not that Eiffel, by having preconditions and postconditions, is doing
anything that cannot be done in python already.

It's more that by making these things a formal part of the language, or at
least a module that facilitates them, one gives a sort of stamp of
approval to adding a ton of assertions about how your code is supposed to
work /when/working/in/that/language, which makes debugging a relative
snap.  Isn't that something people should want for python?  Sturdy code
and easy debugging?

I've been trying to write my python code with tons of "unnecessary" if
statements that check out my assumptions, and I'm finding more or less
what the Eiffel people claim: I'm investing a little bit of upfront time,
and getting a huge payoff in the backend as my code starts to debug
itself.  But I likely never would've started taking my error checking to
such extremes if I hadn't been curious about Eiffel for a while.

Throwing in tons of error and assumption checking mostly eliminates silly
tracing from procedure to function to procedure to function, trying to
find the ultimate root cause of a problem.  Usually, the root cause is
identified in an error on stderr or similar.

Keep in mind that debugging usually takes far longer than the initial
coding.  Programming by contract seems to balance that out, relatively
speaking.

Granted, we could just say "You should check for these things anyway", or
"You should know what you're doing", but...  Isn't that kind of what
assembler programmers used to say to Lisp, FORTRAN and COBOL programmers? 

And what about the case where you've written a piece of code, and
someone else has written another, and the two pieces of code need to
interact?  Odds are pretty good that if this code has much substance,
there'll be opportunity for subtly different assumptions about what should
be happening in each (yes, "well abstracted" code will be
misassumption-resistant, but even the best OOP programmers will run afoul
of this /sometimes/). Perhaps both these programmers "Know what they're
doing", but they don't necessarily know what the other is doing!

IMO, putting Programming by Contract into python as part of the language
itself, or as a simple module, is a little bit like a company or
department coming up with a mission statement.  It's easy to say that it's
meaningless, and some will ignore it, but it still kind of sets the tone
for how things "should be done".


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


Re: replacing xml elements with other elements using lxml

2007-08-29 Thread Ultrus
Stefan,
I'm honored by your response.

You are correct about the bad xml. I attempted to shorten the xml for
this example as there are other tags unrelated to this issue in the
mix. Based on your feedback, I was able to make following fully
functional code using some different techniques:

from lxml import etree
from StringIO import StringIO
import random

sourceXml = "\
\
 Stefan's fortune cookie:\
 \
  \
   \
\
 You will always know love.\
\
\
 You will spend it all in one place.\
\
   \
  \
  \
   Your life comes with a lifetime warrenty.\
  \
 \
 The end.\
"

parser = etree.XMLParser(ns_clean=True, recover=True,
remove_blank_text=True, remove_comments=True)
tree = etree.parse(StringIO(sourceXml), parser)
xml = tree.getroot()

def reduceRandoms(xml):
for elem in xml:
if elem.tag == "random":
elem.getparent().replace(elem, random.choice(elem)[0])
reduceRandoms(xml)

reduceRandoms(xml)
for elem in xml:
print elem.tag, ":", elem.text




One challenge that I face now is that I can only replace a parent
element with a single element. This isn't a problem if an 
element only has 1  element, or just 1  element
(this works above). However, if  elements have more than one
child element such as a  element, followed by a 
element (like children of ), only the first element is used.

Any thoughts on how to replace+append after the replaced element, or
clear+append multiple elements to the cleared position?

Thanks again :)

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


Re: re compiled object result caching?

2007-08-29 Thread Steve Holden
Dan Stromberg - Datallegro wrote:
> On Wed, 29 Aug 2007 17:45:36 -0400, Steve Holden wrote:
> 
>> Dan wrote:
>>> foo_re = re.compile(r"foo(bar)")
>>> # . . .
>>> if foo_re.search(line):
>>> foo_re.last_result().group(1)
>>>
>> If you wanted to implement this I don't really see why a method call is 
>> necessary. It would surely only need to be a simple attribute?
>>
>> Of course you then introduce the possibility that someone will reference 
>> if before using the RE in a search, plus it still requires separate 
>> storage if you want the ability to use the same RE for two different 
>> matches and compare the match results.
> 
> I've long felt that publicly accessible attributes probably should be
> syntactic sugared to look like accessor methods, a bit like how __add__
> ends up being + - so that if your attribute ever needs to become methods
> (say, it started out life as a unidimensional thing, but later needs to
> be a flattening of 3 dimensions or something), you won't necessarily need
> to change depenent code.
> 
> But are methods a lot more expensive in python than referencing other
> kinds of attributes?
> 
Well, given that they are procedure calls, yes. There's also other magic 
over and above that.

The property() function is a way of making what appear to be attribute 
accesses become method calls. Your intuition is taking you the wrong 
way: if you need an accessor method then just turn the normal attribute 
into a property. Given that mechanism, your wish to use accessor methods 
is definitely anti-pythonic.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: re compiled object result caching?

2007-08-29 Thread Marc 'BlackJack' Rintsch
On Wed, 29 Aug 2007 21:54:50 +, Dan Stromberg - Datallegro wrote:

> I've long felt that publicly accessible attributes probably should be
> syntactic sugared to look like accessor methods, a bit like how __add__
> ends up being + - so that if your attribute ever needs to become methods
> (say, it started out life as a unidimensional thing, but later needs to
> be a flattening of 3 dimensions or something), you won't necessarily need
> to change depenent code.

Maybe you should read about the `property()` function.

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


Re: cgi

2007-08-29 Thread Fabio Z Tessitore
Il Wed, 29 Aug 2007 23:11:53 +0200, Gigs_ ha scritto:

> Gigs_ wrote:
>> Fabio Z Tessitore wrote:
>>> Are you sure your script is in the right dir?
>>>
>>> On my home computer, php script will work in /var/www but my python
>>> script need an other dir to work properly (i don't remember which now
>>> ;-))
>>>
>>> bye
>>>
>> i think that it is in right dir because other script in same dir work.
>> dir is: cgi-bin
> 
> 
> sorry...
> 
> 
> 
> for waisting your time,
> somehow in html page in form i forgot to put right script addr
> 
> 
> 
> thx anyway
> 
> 
> work now

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


Re: Haskell like (c:cs) syntax

2007-08-29 Thread Erik Max Francis
Marco Mariani wrote:
> Ricardo Aráoz ha scritto:
> 
>> L = ['one', 'two', 'three', 'four', 'five']
>>
>> print L[0]# This would be 'head'
>> print L[1:]   # This would be 'tail'
>>
>> Caution : L[0] and L[1:] are COPIES of the head and tail of the list.
> 
> This might surprise people who see L[1:] = [], since changing a copy is 
> not supposed to change the original.

That's because slicing and assigning is not the same thing as slicing 
alone.  Slicing and assigning mutates the sequence.  Slicing alone 
returns a copy.

 >>> L = ['one', 'two', 'three', 'four', 'five']
 >>> x = L[1:] # grab a slice
 >>> x[:] = [] # mutate it
 >>> x
[]
 >>> L # original list is unchanged
['one', 'two', 'three', 'four', 'five']

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
   Eternity is very long, especially near the end.
-- Woody Allen
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re compiled object result caching?

2007-08-29 Thread Dan Stromberg - Datallegro
On Wed, 29 Aug 2007 17:45:36 -0400, Steve Holden wrote:

> Dan wrote:
>> foo_re = re.compile(r"foo(bar)")
>> # . . .
>> if foo_re.search(line):
>> foo_re.last_result().group(1)
>> 
> If you wanted to implement this I don't really see why a method call is 
> necessary. It would surely only need to be a simple attribute?
> 
> Of course you then introduce the possibility that someone will reference 
> if before using the RE in a search, plus it still requires separate 
> storage if you want the ability to use the same RE for two different 
> matches and compare the match results.

I've long felt that publicly accessible attributes probably should be
syntactic sugared to look like accessor methods, a bit like how __add__
ends up being + - so that if your attribute ever needs to become methods
(say, it started out life as a unidimensional thing, but later needs to
be a flattening of 3 dimensions or something), you won't necessarily need
to change depenent code.

But are methods a lot more expensive in python than referencing other
kinds of attributes?

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


Re: re compiled object result caching?

2007-08-29 Thread Steve Holden
Dan wrote:
> I find myself often using regular expressions in the following
> pattern:
> 
> foo_re = re.compile(r"foo(bar)")
> # . . .
> re_result = foo_re.search(line)
> if re_result:
> bar = re_result.group(1)
> # . . .
> 
> But, I keep thinking this is awkward, and I would kind of like to have
> the re object to cache its result; along the lines of:
> 
> foo_re = re.compile(r"foo(bar)")
> # . . .
> if foo_re.search(line):
> foo_re.last_result().group(1)
> 
If you wanted to implement this I don't really see why a method call is 
necessary. It would surely only need to be a simple attribute?

Of course you then introduce the possibility that someone will reference 
if before using the RE in a search, plus it still requires separate 
storage if you want the ability to use the same RE for two different 
matches and compare the match results.

> I realize I could do this with a wrapper object (I'm not sure if I can
> subclass the re object..), but I was wondering what the community
> thought of this. Good idea? Bad? Would it be difficult to add to the
> standard re module? The only real downside I can think of is thread
> safety. The other practical benefit I can think of is situations like
> the following:
> 
> if unlikely_condition and foo_re.search(line):
># . . .
> 
> With the current implementation I think you would either have to do
> the search even if unlikely_condition is False, or you would have to
> do an annoying nested if. Is there another way to achieve this that
> I'm not thinking of?
> 
I see absolutely no reason why you can't create your own module with a 
compile function that produces an extended_RE object by compiling the RE 
passed as an argument and saving the compiled result. It can then 
delegate most method calls to the compiled RE, but extend certain of its 
methods to provide the behavior that you want.

Personally I think it's anti-Pythonic to abhor

matchobj = pat.match(...)

You throw some clarity out just for the sake of making the "no match" 
case a teeny bit faster and a minute amount more readable. But others' 
opinions may differ.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Re: copying files

2007-08-29 Thread Ricardo Aráoz
Brian McCann wrote:
>  
>  
>  
> Hi Ricardo,
> 
> what do the + signs do?
>  

Add the different strings. You had 'm' and 'TEST_HOME' inside a string,
so they would be taken as characters and not variables.

>>> TEST_HOME = "/v01/test_home"
>>> m = "./lib"
>>> "cp -r " + m + " " + TEST_HOME
'cp -r ./lib /v01/test_home'   <- This is what you want.
>>> "cp -r m TEST_HOME"
'cp -r m TEST_HOME'<- This is NOT what you want.

> 
> 
> 
> From: Ricardo Aráoz [mailto:[EMAIL PROTECTED]
> Sent: Wed 8/29/2007 2:51 PM
> To: Brian McCann
> Cc: python-list@python.org
> Subject: Re: copying files
> 
> 
> 
> Brian McCann wrote:
>> Hi,
>>
>> with the code below I set a variable TEST_HOME to a path and the
>> variable m to a path
>> in my current dir.
>> I have a symbolic link setting m>lib
>> when I run the script I get no errors and the lib dir with its 20 files
>> does not get copied to /v01/test_home
>> any help would be greatly appreciated
>>
>> --Brian
>>
>> #!/usr/bin/python
>> import string
>> import os
>> import sys
>> import errno
>> import shutil
>> import tarfile
>>
>> TEST_HOME = "/v01/test_home"
>> m = "./lib"
>> os.system("cp -r m TEST_HOME")
>> #os.system("tar -cvf viziant-ingestion.tar /v01/")
>>
> 
> Sorry, meant : os.system("cp -r " + m + " " + TEST_HOME)
> 
> 
> 
> 

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


Re: status of Programming by Contract (PEP 316)?

2007-08-29 Thread Steve Holden
Chris Mellon wrote:
> On 8/29/07, Russ <[EMAIL PROTECTED]> wrote:
[...]
>> If you are
>> programming something that doesn't really need to be correct, than you
>> probably don't need it. But if you really need (or want) your software
>> to be correct and reliable as possible, I think you you should be
>> interested in it. You might want to read this:
>>
> 
> You don't want your software to KILL BABIES, do you? If you don't want
> your programs to KILL BABIES then you should use our technique, so you
> don't KILL BABIES.
> 
> There are ways to make correct programs besides DBC. It may not even
> help in the general case - just as with unit testing and type proving,
> you're going to be limited by what you don't think to assert or
> document or test, and I've seen no evidence that DBC is any better
> than anything else at preventing unwritten assumptions.

Personally I have found the best strategy to be KWYD: know what you're 
doing. Your assertion that success of DBC relies on the competence of 
the practitioner is indeed true, just as it is for all other 
methodologies. The number of programmers who *don't* know what they are 
doing and yet manage to find well-paid employment in mission-critical 
system implementation is truly staggering.

If I can blow my own trumpet briefly, two customers (each using over 25 
kLOC I have delivered over the years) ran for two years while I was away 
in the UK without having to make a single support call. One of the 
systems was actually locked in a cupboard all that time (though I have 
since advised that client to at least apply OS patches to bring it up to 
date).

This was achieved by defensive programming, understanding the user 
requirements and just generally knowing what I was doing. Nevertheless I 
would hesitate to write code for such demanding areas as real-time 
rocket flight control, because I just don't think I'm that good. Very 
few people are, and learning as you go can be disastrously expensive 
when military and space projects are involved.

But it's always a good idea to make your software "correct and as 
reliable as possible", isn't it? The problem is the external constraints 
on the project. As the old saying goes: "Cheap, fast, reliable: choose 
any two".

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Thread issue

2007-08-29 Thread James Matthews
Hi

I have a program that downloads webpages. The webpages are stored in a list
and i make each has it's own thread that downloads it. Sometimes the threads
exit (because urlopen() throws an exception) Now the question is how can i
recover from this thread failing


Example Code
from urllib import urlopen
import threading

threaded_object = []
urls= [url1,url2]
for i in urls:
   do_thread = threading.Thread(target=urlopen,args=(url,))
threaded_object.append(do_thread)
 for i in threaded_object:
i.start()
for i in threaded_object:
i.join()

Thanks
James



-- 
http://www.goldwatches.com/
http://www.jewelerslounge.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: cgi

2007-08-29 Thread Gigs_
Gigs_ wrote:
> Fabio Z Tessitore wrote:
>> Are you sure your script is in the right dir?
>>
>> On my home computer, php script will work in /var/www but my python 
>> script need an other dir to work properly (i don't remember which now 
>> ;-))
>>
>> bye
>>
> i think that it is in right dir because other script in same dir work.
> dir is: cgi-bin


sorry...



for waisting your time,
somehow in html page in form i forgot to put right script addr



thx anyway


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


Re: Short, crazy example: list-derived class, with __iadd__

2007-08-29 Thread Marshall T. Vandegrift
Moon <[EMAIL PROTECTED]> writes:

> class Vec(list):
> def __init__(self):
> list.__init__(self, [0.0, 0.0])
>
> def __iadd__(self, other):
> assert isinstance(other, Vec)
> self[0] += other[0]
> self[1] += other[1]
> print "right now, v is: ", self, " as you'd expect"
  return self
>
>
> v = Vec()
> w = Vec()
> w[0] = 1.0
> w[1] = 2.0
> print "v starts:", v
>
> print "(w is:", w, " which is fine)"
>
> v += w
>
> print "(w still is:", w
>
  print "after iadd, v: ", v

>
> # - running it: 

v starts: [0.0, 0.0]
(w is: [1.0, 2.0]  which is fine)
right now, v is:  [1.0, 2.0]  as you'd expect
(w still is: [1.0, 2.0]
after iadd, v:  [1.0, 2.0]

-Marshall

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


Re: cgi

2007-08-29 Thread Gigs_
Fabio Z Tessitore wrote:
> Are you sure your script is in the right dir?
> 
> On my home computer, php script will work in /var/www but my python 
> script need an other dir to work properly (i don't remember which now ;-))
> 
> bye
> 
i think that it is in right dir because other script in same dir work.
dir is: cgi-bin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Short, crazy example: list-derived class, with __iadd__ <- nevermind, me == idiot

2007-08-29 Thread Moon
__iadd__ is supposed to /return/ something, most likely self. 

My bad. 

On Wed, 29 Aug 2007 20:49:59 +, Moon wrote:

> class Vec(list):
> def __init__(self):
> list.__init__(self, [0.0, 0.0])
> 
> def __iadd__(self, other):
> assert isinstance(other, Vec)
> self[0] += other[0]
> self[1] += other[1]
> print "right now, v is: ", self, " as you'd expect"
> 
> 
> v = Vec()
> w = Vec()
> w[0] = 1.0
> w[1] = 2.0
> print "v starts:", v
> 
> print "(w is:", w, " which is fine)"
> 
> v += w
> 
> print "(w still is:", w
> 
> print "after iadd, v: ", v, " <-- becomes None! What the hey?"
> 
> 
> # - running it:
> 
> py> python badvec.py
> v starts: [0.0, 0.0]
> (w is: [1.0, 2.0]  which is fine)
> right now, v is:  [1.0, 2.0]
> (w still is: [1.0, 2.0]
> later, v is:  None  <-- becomes None! What the hey?
> 
> py> python -V
> Python 2.5.1
> 
> -- Any explanation from a guru?
> 
> Thanks much...

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


RE: copying files

2007-08-29 Thread Brian McCann
 
 
 
Hi Ricardo,

what do the + signs do?
 



From: Ricardo Aráoz [mailto:[EMAIL PROTECTED]
Sent: Wed 8/29/2007 2:51 PM
To: Brian McCann
Cc: python-list@python.org
Subject: Re: copying files



Brian McCann wrote:
> Hi,
> 
> with the code below I set a variable TEST_HOME to a path and the
> variable m to a path
> in my current dir.
> I have a symbolic link setting m>lib
> when I run the script I get no errors and the lib dir with its 20 files
> does not get copied to /v01/test_home
> any help would be greatly appreciated
> 
> --Brian
>
> #!/usr/bin/python
> import string
> import os
> import sys
> import errno
> import shutil
> import tarfile
> 
> TEST_HOME = "/v01/test_home"
> m = "./lib"
> os.system("cp -r m TEST_HOME")
> #os.system("tar -cvf viziant-ingestion.tar /v01/")
> 

Sorry, meant : os.system("cp -r " + m + " " + TEST_HOME)




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

Re: Haskell like (c:cs) syntax

2007-08-29 Thread Stefan Niemann
Thanks for all the good answers.

In fact the `Extended Iterable Unpacking' is exactly what I was looking for. 
Ok, my main aspect of writing

head, *tail = seq

instead of

head, tail = seq[0], seq[1:]

is the syntactic sugar. As mentioned in the PEP this may also be faster when 
iterables are involved.

Stefan

"Matimus" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
>> Is there a pattern matching construct in Python like (head : tail), 
>> meaning
>> 'head' matches the first element of a list and 'tail' matches the rest? I
>> could not find this in the Python documentation.
>
> Not really, but you could do something like this:
>
> [code]
> def foo(head, *tail):
>#do stuff with head and tail
>
> foo(*seq)
> [/code]
>
> Also, Python 3.0 will have `Extended Iterable Unpacking'
> http://www.python.org/dev/peps/pep-3132/
>
> This isn't quite the same as Haskell's type matching, but would enable
> similar behavior in some cases.
>
> example:
> [code]
> head, *tail = seq
> [/code]
>
> Which would assign the first element of seq to head, and the remainder
> to tail.
>
> Matt
> 


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


Short, crazy example: list-derived class, with __iadd__

2007-08-29 Thread Moon
class Vec(list):
def __init__(self):
list.__init__(self, [0.0, 0.0])

def __iadd__(self, other):
assert isinstance(other, Vec)
self[0] += other[0]
self[1] += other[1]
print "right now, v is: ", self, " as you'd expect"


v = Vec()
w = Vec()
w[0] = 1.0
w[1] = 2.0
print "v starts:", v

print "(w is:", w, " which is fine)"

v += w

print "(w still is:", w

print "after iadd, v: ", v, " <-- becomes None! What the hey?"


# - running it: 

py> python badvec.py
v starts: [0.0, 0.0]
(w is: [1.0, 2.0]  which is fine)
right now, v is:  [1.0, 2.0]
(w still is: [1.0, 2.0]
later, v is:  None  <-- becomes None! What the hey?

py> python -V
Python 2.5.1

-- Any explanation from a guru?  

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


Re: cgi

2007-08-29 Thread Fabio Z Tessitore
Are you sure your script is in the right dir?

On my home computer, php script will work in /var/www but my python 
script need an other dir to work properly (i don't remember which now ;-))

bye

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


Re: Accessing docstrings at runtime?

2007-08-29 Thread Kenneth Love
On 08/29/07, Chris Mellon <[EMAIL PROTECTED]> wrote:
> On 8/29/07, Kenneth Love <[EMAIL PROTECTED]> wrote:
>> How do I print the docstring for a class property?
>>
>> [[[ SNIP EXAMPLE ]]]
>>
>> What am I doing wrong?
>>
>
> You're looking at an instance, not at the class. y.x is going through
> the descriptor lookup and is returning the string, so the __doc__ is
> the the __doc__ of the string object, as you see.
>
> If you want to look at the property directly, look it up in the class 
> object:
>
> C.x.__doc__

That worked.  Thanks!

Kenneth 


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


Re: Unzip: Memory Error

2007-08-29 Thread David Bolen
mcl <[EMAIL PROTECTED]> writes:

> I am trying to unzip an 18mb zip containing just a single 200mb file
> and I get a Memory Error.  When I run the code on a smaller file 1mb
> zip, 11mb file, it works fine.
(...)
> def unzip_file_into_dir(file, dir):
>   #os.mkdir(dir, 0777)
>   zfobj = zipfile.ZipFile(file)
>   for name in zfobj.namelist():
>   if name.endswith('/'):
>   os.mkdir(os.path.join(dir, name))
>   else:
>   outfile = open(os.path.join(dir, name), 'wb')
>   outfile.write(zfobj.read(name))
>   outfile.close()

The "zfobj.read(name)" call is reading the entire file out of the zip
into a string in memory.  It sounds like it's exceeding the resources
you have available (whether overall or because the Apache runtime
environment has stricter limits).

You may want to peek at a recent message from me in the "Unable to
read large files from zip" thread, as the suggestion there may also be
suitable for your purposes.

http://groups.google.com/group/comp.lang.python/msg/de04105c170fc805?dmode=source
-- David
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a multi-tier client/server application

2007-08-29 Thread David Bolen
Jeff <[EMAIL PROTECTED]> writes:

> reasons, not the least of which is that I've been working almost
> entirely on web apps for the past few years, and I am getting mighty
> sick of it.  A lot of that is due to the language (PHP, which I have
> since grown to hate) I had to use.  I've worked on a site for my self
> in Python (using Pylons, actually--which is excellent) which was
> vastly easier and more fun.  But I'd really like to try something
> different.

To contribute a data point against your original question - I've a similar
(structurally, not functionality) system I completed recently.

Without trying to get too mired in the thick client v. web application
debate, there were a handful of points that decided me in favor of the
thick client:

* Needed to automate QuickTime viewer for video previews and extraction
  of selected frames to serve as thumbnails on web approval page.
* Needed to control transfers to server of multiple very large files
  (hundreds of MBs to GBs at a shot)

But assuming a thick client, in terms of your original question of
components to use, here's what I've got.  My primary networking component
is Twisted.

The pieces are:

Client (OS X Cocoa application):

* PyObjC based.  Twisted for networking, Twisted's PB for the primary
  management channel, with an independent direct network connections for
  bulk file transfers.  (I needed to go Mac native for clean integration of
  QuickTime UI elements including frame extraction to thumbnails)

Server:

* Twisted for networking.  PB and raw connections for clients, web server
  through twisted.web.  Genshi for web templating, with Mochikit (might
  move to JQuery) for client-side JS/AJAX.  Twisted for email transmission
  (email construction using normal Python email package).  Small UI
  front-end module (Cocoa/PyObjC).

The client accesses server-based objects through Twisted PB, which for some
of the server objects also control session change lifetime (transactions).
So at least in my case, having a stateful connection from the client worked
out well, particularly since I needed to coordinate both database changes
as well as filesystem changes through independent file uploads, each of
which can fail independently.
  
Right now a single server application contains all support for client
connections as well as the web application, but I could fracture that (so
the web server was independent for example) if needed.

For the client, I package it using py2app, and put into an normal Mac
installer, and distribute as a dmg.  If it were a Windows client, I'd
probably wrap with py2exe, then Inno Setup.  The server's web server has a
restricted URL that provides access to the DMG.  The client has a Help menu
item taking users to that URL.  Clients are versioned and accepted/rejected
by the server during initial connection - from the server side I can
"retire" old client versions, at which point users get a message at signon
with a button to take them to the download page for the latest DMG.

So right now upgrades are executed manually by the user, and I can support
older clients during any transition period.  I may provide built-in support
for automatically pulling down the new image and executing its installer,
but haven't found it a hardship yet.  I probably won't bother trying to
automate smaller levels of updates.

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


ANNOUNCE: Spiff Workflow 0.0.2

2007-08-29 Thread Samuel
Introduction

Spiff Workflow is a library implementing a framework for workflows. It is 
based on http://www.workflowpatterns.com and implemented in pure Python.
Spiff Workflow is part of the Spiff platform, which aims to produce a 
number of generic libraries generally needed in enterprise applications. 
This release SHOULD NOT BE USED IN PRODUCTION ENVIRONMENTS - it is meant 
for development only.
Spiff Workflow is free software and distributed under the GNU LGPLv2.1.


New In This Release
---
This release is a huge step forward and an essential rewrite that comes 
with many new features, bugfixes and improvements. The API is now even 
simpler to use, and support for the following workflow patterns was added 
(check the Workflow Patterns page for what they mean):

11. Implicit Termination
12. Multiple Instances without Synchronization
13. Multiple Instances with a Priori Design-Time Knowledge
14. Multiple Instances with a Priori Run-Time Knowledge
15. Multiple Instances without a Priori Run-Time Knowledge

23. Transient Trigger

28. Blocking Discriminator
29. Cancelling Discriminator
30. Structured Partial Join
31. Blocking Partial Join
32. Cancelling Partial Join
33. Generalized AND-Join

37. Acyclic Synchronizing Merge
38. General Synchronizing Merge

41. Thread Merge
42. Thread Split

Spiff Workflow now also supports persistence using Python's pickle 
module. The unit test suite was extremely improved and extended - every 
pattern now comes with a test.

The full ChangeLog is here:
http://spiff.googlecode.com/svn/trunk/libs/Workflow/ChangeLog


Dependencies
-
Python >= 2.4


Download
-
Please check out the code from SVN:
svn checkout http://spiff.googlecode.com/svn/trunk/libs/Workflow/

You can also get a tarball from the release page:
http://pypi.python.org/pypi/Spiff%20Workflow/


Links:
---
Example XML: 
http://spiff.googlecode.com/svn/trunk/libs/Workflow/tests/xml/patterns/
Spiff project page: http://code.google.com/p/spiff/
Mailing list: http://groups.google.com/group/spiff-devel
Bug tracker: http://code.google.com/p/spiff/issues/list
Documentation: http://spiff.googlecode.com/svn/trunk/libs/Workflow/README
Browse the source: http://spiff.googlecode.com/svn/trunk/libs/Workflow/

If you have any questions, please do not hesitate to ask.

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


Re: IDE for Python

2007-08-29 Thread Stefan Behnel
Eric CHAO wrote:
> I think many python developers don't need such an IDE actually. Just
> like Ruby guys, they use a powerful editor, for example, Textmate,
> instead of all-in-one IDE. It's quick and direct.

True. However, some use neither an editor nor an IDE but Emacs.

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


Re: sys.argv is munging my command line options

2007-08-29 Thread Arnau Sanchez
Chris Allen escribió:

> action key=value key=value...
> 
> Where action is a required string (ie. 'backup', 'init', 'restore',
> etc) and the program can accept one or more key value pairs.  I know
> this syntax isn't standard, but I think it works great for my program
> as each key can override an identically named field in a configuration
> file, that way the user doesn't have to have two different syntaxes to
> do the same thing.  I could do this with --key value

It's ok for a personal script, but if you expect other people to use it, 
you should consider the "Rule of Least Surprise" and follow the standard.

Anyway, using getopt or optparse, it would be "--key=value", or perhaps 
"-o key=value / --option=key=value"

> But I'm running into a problem with this which is that sys.argv splits
> my key=value options.  I need to know the option associations, and
> there's no way to know this by inspecting sys.argv.  Can I get access
> to the command line string as python saw it before it split it into
> sys.argv or is there another way?

I can't see the problem, sys.argv[1:] gives you the list of ordered 
key/value pairs... give an example of what you want and what you get.
-- 
http://mail.python.org/mailman/listinfo/python-list


re compiled object result caching?

2007-08-29 Thread Dan

I find myself often using regular expressions in the following
pattern:

foo_re = re.compile(r"foo(bar)")
# . . .
re_result = foo_re.search(line)
if re_result:
bar = re_result.group(1)
# . . .

But, I keep thinking this is awkward, and I would kind of like to have
the re object to cache its result; along the lines of:

foo_re = re.compile(r"foo(bar)")
# . . .
if foo_re.search(line):
foo_re.last_result().group(1)

I realize I could do this with a wrapper object (I'm not sure if I can
subclass the re object..), but I was wondering what the community
thought of this. Good idea? Bad? Would it be difficult to add to the
standard re module? The only real downside I can think of is thread
safety. The other practical benefit I can think of is situations like
the following:

if unlikely_condition and foo_re.search(line):
   # . . .

With the current implementation I think you would either have to do
the search even if unlikely_condition is False, or you would have to
do an annoying nested if. Is there another way to achieve this that
I'm not thinking of?

-Dan

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


Re: sys.argv is munging my command line options

2007-08-29 Thread Chris Allen
Thanks for the reply. Oops...  I forget that I was calling the program
from a shell script, the shell script was responsible for goofing up
my command line options.  Solved.  Thanks again.


On Aug 29, 12:28 pm, Ant <[EMAIL PROTECTED]> wrote:
> On Aug 29, 8:11 pm, Chris Allen <[EMAIL PROTECTED]> wrote:
> ...
>
> > But I'm running into a problem with this which is that sys.argv splits
> > my key=value options.  I need to know the option associations, and
> > there's no way to know this by inspecting sys.argv.  Can I get access
> > to the command line string as python saw it before it split it into
> > sys.argv or is there another way?  Thanks.
>
> Could you show us some example code that demonstrates this? The
> following works as expected for me on win32:
>
> # test.py
> import sys
>
> for arg in sys.argv[1:]:
> print arg
>
> >From the command prompt:
>
> C:\0>test.py action key=value key=value
> action
> key=value
> key=value
>
> --
> Ant.


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


Re: sys.argv is munging my command line options

2007-08-29 Thread Ant
On Aug 29, 8:11 pm, Chris Allen <[EMAIL PROTECTED]> wrote:
...
> But I'm running into a problem with this which is that sys.argv splits
> my key=value options.  I need to know the option associations, and
> there's no way to know this by inspecting sys.argv.  Can I get access
> to the command line string as python saw it before it split it into
> sys.argv or is there another way?  Thanks.

Could you show us some example code that demonstrates this? The
following works as expected for me on win32:

# test.py
import sys

for arg in sys.argv[1:]:
print arg

>From the command prompt:

C:\0>test.py action key=value key=value
action
key=value
key=value

--
Ant.

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


Re: cgi

2007-08-29 Thread Gigs_
Fabio Z Tessitore wrote:
> Il Wed, 29 Aug 2007 19:24:54 +0200, Gigs_ ha scritto:
> 
>> i have simple page and form that ask for name and color and cgi script
>> that print that name in another page and background in chosen color
>>
>> all the time this error pop:
>> Error response
>>
>> Error code 501.
>>
>> Message: Can only POST to CGI scripts.
>>
> 
> I think this should be your problem,
> 
> change GET with POST in the form
> 
> bye
it is post in form.
-- 
http://mail.python.org/mailman/listinfo/python-list


sys.argv is munging my command line options

2007-08-29 Thread Chris Allen
The command line syntax for my program is as follows:

action key=value key=value...

Where action is a required string (ie. 'backup', 'init', 'restore',
etc) and the program can accept one or more key value pairs.  I know
this syntax isn't standard, but I think it works great for my program
as each key can override an identically named field in a configuration
file, that way the user doesn't have to have two different syntaxes to
do the same thing.  I could do this with --key value, but key=value is
cleaner IMHO because it matches the config file syntax.

But I'm running into a problem with this which is that sys.argv splits
my key=value options.  I need to know the option associations, and
there's no way to know this by inspecting sys.argv.  Can I get access
to the command line string as python saw it before it split it into
sys.argv or is there another way?  Thanks.

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


Re: Creating a multi-tier client/server application

2007-08-29 Thread askel
On Aug 29, 1:31 pm, Jeff <[EMAIL PROTECTED]> wrote:
> Goldfish--thanks, I'll check it out.
>
> > > That, or something similar, may be what I do.  It would mean, however,
> > > developing my own method for transferring objects across the network,
>
> > Why transfering "objects" ? You only need to transfer data.
>
> I suppose I don't need to transfer objects, it just seems like it
> would make it far easier (certainly less repetition of code) to
> program the client-side app.

If you prefer to deal with RPC-like protocol, take a look at Ice by
ZeroC (http://www.zeroc.com/).

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


Unzip: Memory Error

2007-08-29 Thread mcl
I am trying to unzip an 18mb zip containing just a single 200mb file
and I get a Memory Error.  When I run the code on a smaller file 1mb
zip, 11mb file, it works fine.

I am running on a hosted Apache web server

I am using some code I found on the web somewhere.


def unzip_file_into_dir(file, dir):
#os.mkdir(dir, 0777)
zfobj = zipfile.ZipFile(file)
for name in zfobj.namelist():
if name.endswith('/'):
os.mkdir(os.path.join(dir, name))
else:
outfile = open(os.path.join(dir, name), 'wb')
outfile.write(zfobj.read(name))
outfile.close()


Error Traceback: Line 357 gives the Memory Error
I have removed paths from file references
==

MemoryError Python 2.3.4: /usr/bin/python
Wed Aug 29 19:38:22 2007

A problem occurred in a Python script. Here is the sequence of
function calls leading up to the error, in the order they occurred.

/qlunzip.py
   58
   59
   60 if __name__ == "__main__" :
   61 unzipMain()
   62
unzipMain = 

/qlunzip.py in unzipMain()
   53 destdir = getDestDir()
   54 print destdir, gv.nl
   55 unzip_file_into_dir(zips, destdir)
   56
   57
global unzip_file_into_dir = , zips = '/
pcodes.zip', destdir = '/pcodes/'

/qlunzip.py in unzip_file_into_dir(file='pcodes.zip', dir='pcodes/')
   34 else:
   35 outfile = open(os.path.join(dir, name),
'wb')
   36 outfile.write(zfobj.read(name))
   37 outfile.close()
   38
outfile = , outfile.write =
, zfobj = , zfobj.read = >, name = 'pcodes.lst'

 /usr/lib/python2.3/zipfile.py in read(self=, name='pcodes.lst')
  355 # zlib compress/decompress code by Jeremy Hylton of
CNRI
  356 dc = zlib.decompressobj(-15)
  357 bytes = dc.decompress(bytes)
  358 # need to feed in unused pad byte so that zlib won't
choke
  359 ex = dc.decompress('Z') + dc.flush()
bytes = '\xc4\x9d]\x93\xab8\x92\x86\xef7b\xff\x83\xa3/\xf6f\xba
\xa7\xe7\xa2g#vwf6\x8a\x02\xc3\xd04\x8d\r\x1e\x7f\xdclP\xb6\xcav\x1c
\xca\xd4`\xfbx...; \xb7jp\x06V{\xaf\xc3\xa5\xa7;\xdd\xd2\xaaD\x7f)c
\xc6\x9d\x0f\xf2\xff-\xc9\x92\xc3\x1d\xa4`\xe0\xb8\x06)\x188\x9cA\n
\x06\x8e\x1bPc\xf8\xf0\x1f', dc = ,
dc.decompress = 

MemoryError:
  args = ()


Any help much appreciated

Richard

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


Re: copying files

2007-08-29 Thread kyosohma
On Aug 29, 1:51 pm, Ricardo Aráoz <[EMAIL PROTECTED]> wrote:
> Brian McCann wrote:
> > Hi,
>
> > with the code below I set a variable TEST_HOME to a path and the
> > variable m to a path
> > in my current dir.
> > I have a symbolic link setting m>lib
> > when I run the script I get no errors and the lib dir with its 20 files
> > does not get copied to /v01/test_home
> > any help would be greatly appreciated
>
> > --Brian
>
> > #!/usr/bin/python
> > import string
> > import os
> > import sys
> > import errno
> > import shutil
> > import tarfile
>
> > TEST_HOME = "/v01/test_home"
> > m = "./lib"
> > os.system("cp -r m TEST_HOME")
> > #os.system("tar -cvf viziant-ingestion.tar /v01/")
>
> Sorry, meant : os.system("cp -r " + m + " " + TEST_HOME)

Did you try using the shutil module?

Mike

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

Re: cgi

2007-08-29 Thread Fabio Z Tessitore
Il Wed, 29 Aug 2007 19:24:54 +0200, Gigs_ ha scritto:

> i have simple page and form that ask for name and color and cgi script
> that print that name in another page and background in chosen color
> 
> all the time this error pop:
> Error response
> 
> Error code 501.
> 
> Message: Can only POST to CGI scripts.
> 

I think this should be your problem,

change GET with POST in the form

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


Re: copying files

2007-08-29 Thread Ricardo Aráoz
Brian McCann wrote:
> Hi,
>  
> with the code below I set a variable TEST_HOME to a path and the
> variable m to a path
> in my current dir.
> I have a symbolic link setting m>lib
> when I run the script I get no errors and the lib dir with its 20 files
> does not get copied to /v01/test_home
> any help would be greatly appreciated
>  
> --Brian
> 
> #!/usr/bin/python
> import string
> import os
> import sys
> import errno
> import shutil
> import tarfile
>  
> TEST_HOME = "/v01/test_home"
> m = "./lib"
> os.system("cp -r m TEST_HOME")
> #os.system("tar -cvf viziant-ingestion.tar /v01/")
>  

Sorry, meant : os.system("cp -r " + m + " " + TEST_HOME)


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


Re: copying files

2007-08-29 Thread Ricardo Aráoz
Brian McCann wrote:
> Hi,
>  
> with the code below I set a variable TEST_HOME to a path and the
> variable m to a path
> in my current dir.
> I have a symbolic link setting m>lib
> when I run the script I get no errors and the lib dir with its 20 files
> does not get copied to /v01/test_home
> any help would be greatly appreciated
>  
> --Brian
> 
> #!/usr/bin/python
> import string
> import os
> import sys
> import errno
> import shutil
> import tarfile
>  
> TEST_HOME = "/v01/test_home"
> m = "./lib"
> os.system("cp -r m TEST_HOME")
> #os.system("tar -cvf viziant-ingestion.tar /v01/")
>  

Maybe os.system("cp -r " + m + TEST_HOME) ?

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


Re: Accessing docstrings at runtime?

2007-08-29 Thread Bruno Desthuilliers
Chris Mellon a écrit :
> On 8/29/07, Kenneth Love <[EMAIL PROTECTED]> wrote:
> 
>>How do I print the docstring for a class property?
(snip)
> You're looking at an instance, not at the class. y.x is going through
> the descriptor lookup and is returning the string, so the __doc__ is
> the the __doc__ of the string object, as you see.
> 
> If you want to look at the property directly, look it up in the class object:
> 
> C.x.__doc__

Or type(y).x.__doc__ if you don't know the class of y.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a multi-tier client/server application

2007-08-29 Thread Bruno Desthuilliers
Jeff a écrit :
> Goldfish--thanks, I'll check it out.
> 
> 
>>>That, or something similar, may be what I do.  It would mean, however,
>>>developing my own method for transferring objects across the network,
>>
>>Why transfering "objects" ? You only need to transfer data. 
> 
> I suppose I don't need to transfer objects, it just seems like it
> would make it far easier (certainly less repetition of code) 

Why so ???

> to
> program the client-side app.


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


RE: copying files

2007-08-29 Thread Brian McCann
 
 
one thing I just noticed is that when I run the script I get a new symbolic link
created in my current dir  TEST_HOME-->lib
--Brian
 



From: [EMAIL PROTECTED] on behalf of Brian McCann
Sent: Wed 8/29/2007 2:40 PM
To: python-list@python.org
Subject: copying files 


Hi,
 
with the code below I set a variable TEST_HOME to a path and the variable m to 
a path
in my current dir. 
I have a symbolic link setting m>lib
when I run the script I get no errors and the lib dir with its 20 files does 
not get copied to /v01/test_home
any help would be greatly appreciated
 
--Brian

#!/usr/bin/python
import string
import os
import sys
import errno
import shutil
import tarfile
 
TEST_HOME = "/v01/test_home"
m = "./lib"
os.system("cp -r m TEST_HOME")


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

copying files

2007-08-29 Thread Brian McCann
Hi,
 
with the code below I set a variable TEST_HOME to a path and the variable m to 
a path
in my current dir. 
I have a symbolic link setting m>lib
when I run the script I get no errors and the lib dir with its 20 files does 
not get copied to /v01/test_home
any help would be greatly appreciated
 
--Brian

#!/usr/bin/python
import string
import os
import sys
import errno
import shutil
import tarfile
 
TEST_HOME = "/v01/test_home"
m = "./lib"
os.system("cp -r m TEST_HOME")
#os.system("tar -cvf viziant-ingestion.tar /v01/")

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

Re: Accessing docstrings at runtime?

2007-08-29 Thread Chris Mellon
On 8/29/07, Kenneth Love <[EMAIL PROTECTED]> wrote:
> How do I print the docstring for a class property?
>
> When I run the code below, I get the docstring for the string module
> and not the one I set for the property.
>
> -
> # NOTE: Found in Python docs defining built-in functions (such as
> #   property()).  FIXED: Bug in getx, setx, and delx where "__x"
> #   was misreferenced as "_x".
> class C(object):
> def __init__(self):
> self.__x = None
> def getx(self):
> return self.__x
> def setx(self, value):
> self.__x = value
> def delx(self):
> del self.__x
> x = property(getx, setx, delx, "I'm the 'x' property.")
>
> if __name__ == "__main__"
> y = C()
> y.x = 'test'
> print y.x
> print y.x.__doc__
> -
>
> I get the following output:
>
> -
> test
> str(object) -> string
>
> Return a nice string representation of the object.
> If the argument is a string, the return value is the same object.
> -
>
> What am I doing wrong?
>

You're looking at an instance, not at the class. y.x is going through
the descriptor lookup and is returning the string, so the __doc__ is
the the __doc__ of the string object, as you see.

If you want to look at the property directly, look it up in the class object:

C.x.__doc__
-- 
http://mail.python.org/mailman/listinfo/python-list


Accessing docstrings at runtime?

2007-08-29 Thread Kenneth Love
How do I print the docstring for a class property?

When I run the code below, I get the docstring for the string module
and not the one I set for the property.

-
# NOTE: Found in Python docs defining built-in functions (such as
#   property()).  FIXED: Bug in getx, setx, and delx where "__x"
#   was misreferenced as "_x".
class C(object):
def __init__(self):
self.__x = None
def getx(self):
return self.__x
def setx(self, value):
self.__x = value
def delx(self):
del self.__x
x = property(getx, setx, delx, "I'm the 'x' property.")

if __name__ == "__main__"
y = C()
y.x = 'test'
print y.x
print y.x.__doc__
-

I get the following output:

-
test
str(object) -> string

Return a nice string representation of the object.
If the argument is a string, the return value is the same object.
-

What am I doing wrong?

adTHANKSvance,
Kenneth Love

P.S. If I want a docstring and I do not want a delete function,
 do I just pass 'None' (minus quotes) for that parameter?

-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  
Kenneth Love   | Oklahoma Tax Commission
DP Programmer/Analyst  | Information Technology
(405) 522 - 5864   | http://www.tax.ok.gov/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

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


Re: general function for sorting a matrix

2007-08-29 Thread Neil Cerutti
On 2007-08-29, Xah Lee <[EMAIL PROTECTED]> wrote:
> A couple years ago, i posted a programing problem, about
> writing a function that will sort a arbitrarily dimentioned
> matrix in any possible way to sort it.
>
> Such a function, is rather typical in functional programing
> languages.  I wrote a version in 1999 in perl for practical
> purposes, since sorting a matrix (i.e. list of lists) is rather
> common. With this function, i can have a single interface to
> deal with any list (including list of lists).
>
> It is ideal, that a language's function for sort actually are
> of this generality.
> (See ?What is Expressiveness in a Computer Language?, Xah Lee, 2005.
> http://xahlee.org/perl-python/what_is_expresiveness.html
> )
>
> The advantage of such a generality, is that a programer don't
> need to write a sorting code every time she encounters a list.

The advantage of such a richly implemented language as Python, is
that a programmer don't need to write a general sorting algorithm
at all.

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


Re: Creating a multi-tier client/server application

2007-08-29 Thread Jeff
Goldfish--thanks, I'll check it out.

> > That, or something similar, may be what I do.  It would mean, however,
> > developing my own method for transferring objects across the network,
>
> Why transfering "objects" ? You only need to transfer data.

I suppose I don't need to transfer objects, it just seems like it
would make it far easier (certainly less repetition of code) to
program the client-side app.




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


cgi

2007-08-29 Thread Gigs_
i have simple page and form that ask for name and color and cgi script that 
print that name in another page and background in chosen color

all the time this error pop:
Error response

Error code 501.

Message: Can only POST to CGI scripts.

Error code explanation: 501 = Server does not support this operation.

i run it on windows xpand this is server that i use:

webdir = '.'
port   = 80

import os, sys
from BaseHTTPServer import HTTPServer
from CGIHTTPServer  import CGIHTTPRequestHandler

os.chdir(webdir)
srvraddr = ("", port)
srvrobj  = HTTPServer(srvraddr, CGIHTTPRequestHandler)
srvrobj.serve_forever()

can someone help me?



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


Re: status of Programming by Contract (PEP 316)?

2007-08-29 Thread Chris Mellon
On 8/29/07, Russ <[EMAIL PROTECTED]> wrote:
> On Aug 28, 10:58 pm, Michele Simionato <[EMAIL PROTECTED]>
> wrote:
>
> > Why do you think that would ad a strong positive capability?
> > To me at least it seems a big fat lot of over-engineering, not
> > needed in 99% of programs. In the remaining 1%, it would still not
> > be needed since Python provides out of the box very powerful
> > metaprogramming capabilities so that you can implement
> > yourself the checks you need, if you really need them.
>
> I get the strong impression you don't really understand what
> programming by contract is.
>

Don't be condescending.

> I have not yet personally used it, but I am interested in anything
> that can help to make my programs more reliable.

The entire issue of software reliability, exactly what metrics you
should use to measure it, and whether any specific technique results
in more of it are very much in debate. If you want to experiment with
these techniques, you can do so without them being in the Python core.
Python has all the support you need to play with them right now.

>If you are
> programming something that doesn't really need to be correct, than you
> probably don't need it. But if you really need (or want) your software
> to be correct and reliable as possible, I think you you should be
> interested in it. You might want to read this:
>

You don't want your software to KILL BABIES, do you? If you don't want
your programs to KILL BABIES then you should use our technique, so you
don't KILL BABIES.

There are ways to make correct programs besides DBC. It may not even
help in the general case - just as with unit testing and type proving,
you're going to be limited by what you don't think to assert or
document or test, and I've seen no evidence that DBC is any better
than anything else at preventing unwritten assumptions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Gmane's been quiet ...

2007-08-29 Thread Grant Edwards
On 2007-08-29, Robert Marshall <[EMAIL PROTECTED]> wrote:

>> Given that I have now read a reply to my post-via-gmane on gmane
>> before seeing the original post appear there I shall assume they've
>> been having some sort of issue.
>
> See http://news.gmane.org/gmane.discuss for some discussion of this...

A day's worth of e-mail messages was lost (both incoming and
outgoing apparently).

-- 
Grant Edwards   grante Yow! In Newark the
  at   laundromats are open 24
   visi.comhours a day!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: general function for sorting a matrix

2007-08-29 Thread Stefan Behnel
Xah Lee wrote:
[undermotivated blah stripped]

don't feed the troll.

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


Re: Gmane's been quiet ...

2007-08-29 Thread Robert Marshall
On Wed, 29 Aug 2007, Steve Holden wrote:

> 
> Lawrence Oluyede wrote:
>> Grant Edwards <[EMAIL PROTECTED]> wrote:
>>> Posting that were made to mailing lists via gmane?
>>
>> That, I do not know
>>
> Given that I have now read a reply to my post-via-gmane on gmane
> before seeing the original post appear there I shall assume they've
> been having some sort of issue.
> 

See http://news.gmane.org/gmane.discuss for some discussion of this...

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: replacing xml elements with other elements using lxml

2007-08-29 Thread Stefan Behnel
Ultrus wrote:
> I'm attempting to generate a random story using xml as the document,
> and lxml as the parser. I want the document to be simplified before
> processing it further, and am very close to accomplishing my goal.
> Below is what I have so far. Any ideas on how to move forward?
> 
> The goal:
> read and edit xml file, replacing random elements with randomly picked
> content from within
> 
> Completed:
> [x] read xml
> [x] access first random tag
> [x] pick random content within random item
> [o] need to replace  tag with picked contents
> 
> xml sample:
> Here is some content.
> 
>Here is some random content.
>Here is some more random content.
> 
> Here is some content.

Hmm, this is not well-formed XML, so I assume you stripped the example. The
root element is missing.


> Python code:
> from lxml import etree
> from StringIO import StringIO
> import random
> 
> theXml = "Here is some content. contents>Here is some random content. contents>Here is some more random content. contents>Here is some content."
> 
> f = StringIO(theXml)
> tree = etree.parse(f)

 ^
This would raise an exception if the above really *was* your input.


> r = tree.xpath('//random')
> 
> if len(r) > 0:
>randInt = random.randInt(0,(len(r[0]) - 1))
>randContents = r[0][randInt][0]
>#replace parent random tag with picked content here
> 
> now that I have the contents tag randomly chosen, how do I delete the
> parent  tag, and replace it to look like this:
> 
> final xml sample (goal):
> Here is some content.
> Here is some random content.
> Here is some content.

what about:

   r.getparent().replace(r, random.choice(r))

?

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


Re: general function for sorting a matrix

2007-08-29 Thread Marc 'BlackJack' Rintsch
On Wed, 29 Aug 2007 08:47:27 -0700, Xah Lee wrote:

> While reviewing this code, there's something interesting of note.
> 
> Namely, in my perl solution, the approach is drastically different
> than the python version. Instead of sorting by looping thru the
> sorting directives, it parses the directives then generate the
> complete sort code, then eval it in one shot. This is more of a pure
> functional approach.

I don't see why that is more functional.  After all you iterate in both
versions through the directives.  In Perl to build the code, in Python to
sort the list multiple times.  Here's a Python function that sorts the
list just once:

def sort_matrix(matrix, directives):
tmp = [(column - 1, str if as_string else float, 1 if ascending else -1)
   for (column, as_string, ascending) in directives]

def cmp_func(row_a, row_b):
for column, convert_func, factor in tmp:
result = cmp(convert_func(row_a[column]),
 convert_func(row_b[column])) * factor
if result:
return result
return 0

matrix.sort(cmp=cmp_func)

There's no return value as your reference implementation sorts in place
too.

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


Re: Creating a multi-tier client/server application

2007-08-29 Thread Bruno Desthuilliers
Jeff a écrit :
>> You could explore something like a custom-made GUI client app
>> communicating thru the http protocol with a web-server app. http is just
>> a protocol, and it doesn't necessarily imply using html and a browser...
>> IIRC, some GUI toolkits uses XML description files for the UI.
> 
> That, or something similar, may be what I do.  It would mean, however,
> developing my own method for transferring objects across the network,

Why transfering "objects" ? You only need to transfer data.

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


python + gcov

2007-08-29 Thread labrach
Hi
I want to profile (and analyse coverage) some  c++ code imported as a
python module
I've compiled python (2.4.2) with gcc 3.4.3 and flags=-Wall -fprofile-
arcs -ftest-coverage in order to use gcov. However, the python binary
does not generate any coverage file (such than *.gcno, gcda) during
execution.
any tips ?
or may be another method to profile c++ wrapped modules within
python ?

thanks

laurent

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


Re: What's the difference ?

2007-08-29 Thread Alexandre Badez
Thanks for all you information.

I'll continue to use 'in' instead of 'has_key' for a "faster, more
concise, & readable" code (^L^ )

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


general function for sorting a matrix

2007-08-29 Thread Xah Lee
A couple years ago, i posted a programing problem, about writing a
function that will sort a arbitrarily dimentioned matrix in any
possible way to sort it.

Such a function, is rather typical in functional programing
languages.  I wrote a version in 1999 in perl for practical purposes,
since sorting a matrix (i.e. list of lists) is rather common. With
this function, i can have a single interface to deal with any list
(including list of lists).

It is ideal, that a language's function for sort actually are of this
generality.
(See “What is Expressiveness in a Computer Language”, Xah Lee, 2005.
http://xahlee.org/perl-python/what_is_expresiveness.html
)

The advantage of such a generality, is that a programer don't need to
write a sorting code every time she encounters a list.

Anyway, so i wrote it in 1999 in perl for practical purposes, and have
used it in industrial coding often.  In 2005, while i was learning
Python, i wrote a python version as a exercise.  Today, i actually
need it again, while coding in python. So i looked at my code and
spruced up the documentation.

Here's the function spec:


Today we'll write a function that can sort a matrix in all possible
ways. Following is the specification. Take a day to see if you can
write such a function in your favorite language. Perl and Python
solutions are at the end of this page.

sort_matrix( matrix, [[n1, s1, d1], [n2, s2, d2], [n3, s3, d3], ...])
returns a sorted matrix by n1 th column, if tie, then by n2 th
column ... and so on.

The first argument is a list, whose elements are lists of equal
lengths.

s1, s2, s3... are booleans. If True, then the corresponding column are
interpreted as a string and the ordering is lexicographical.

d1, d2, d3... are booleans. If True, the sort for the corresponding
column are ascending.

Example:.

myMatrix =
 [
   [3, 99, 'a'],
   [2, 77, 'a'],
   [1, 77, 'a']
 ];

sort_matrix(myMatrix,[[3,True,True],[2,False,True]])

This means sort by 3th column, regarding it as strings, and in
ascending order. If tie, sort by 2th column, regarding it as number,
in ascending order. It returns:

[[2,77,'a'],
 [1,77,'a'],
 [3,99,'a']]



While reviewing this code, there's something interesting of note.

Namely, in my perl solution, the approach is drastically different
than the python version. Instead of sorting by looping thru the
sorting directives, it parses the directives then generate the
complete sort code, then eval it in one shot. This is more of a pure
functional approach.

I thought it is of interest.

The Perl and Python solutions are at:
General Function For Matrix Sorting
http://xahlee.org/perl-python/sort_matrix.html

It would be interesting, to see a python version using the approach
i've done in the Perl version, and a Perl version using imperative
approach without using eval().

A solution in lisp (emacs lisp, common lisp, scheme) would be
relatively trivial, similarly for Haskell and Mathematica. In fact, i
think the sort function as specified above are not very useful in
practice in these languages to various degress (depending on the
lang). Because a functional language usually have powerful,
generalized functions and constructs that solve the above in a few
trivial lines that are rather ideomatic to the language.

Nevertheless, it would be interesting to see a solution in the above
languages.

For the languages i'm personally involved, a major difficulty would be
Java. In my opinion, it would be a very difficult (if not impossible)
to construct this sort function Java, C, C++, C#.

  Xah
  [EMAIL PROTECTED]
∑ http://xahlee.org/

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

Re: encoding problems

2007-08-29 Thread Damjan
> 
> is there a way to sort this string properly (sorted()?)
> I mean first 'a' then 'à' then 'e' etc. (sorted puts accented letters at
> the end). Or should I have to provide a comparison function to sorted?

After setting the locale...

locale.strcoll()


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

Re: What's the difference ?

2007-08-29 Thread kyosohma
On Aug 29, 9:44 am, [EMAIL PROTECTED] (Alex Martelli) wrote:
> <[EMAIL PROTECTED]> wrote:
>
>...
>
> > Weird. Hetland's book, "Beginning Python" states that it's a matter of
> > taste.
>
> If your taste is for more verbose AND slower notation without any
> compensating advantage, sure.
>
> > Martelli's "Python Cookbook 2nd Ed." says to use the get()
> > method instead as you never know if a key is in the dict.  However, I
> > can't seem to find any reference to has_key in his book.
>
> .get is not a direct alternative to ``in'' (it's an alternative to an
> idiom where you key into the dict if the key is present and otherwise
> supply a default value, and it's MUCH better in that case).  has_key is
> probably not even mentioned in the Cookbook (2nd edition) since there is
> never a good need for it in the Python versions it covers (2.2 and up),
> but you can probably find traces in the 1st edition (which also covered
> Python back to 1.5.2, where has_key *was* needed); the Nutshell (2nd ed)
> mentions it briefly in a table on p. 60.
>
> > According to Chun in "Core Python Programming", has_key will be
> > obsoleted in future versions of Python, so he recommends using "in" or
> > "not in".
>
> Yes, we're removing has_key in Python 3.0 (whose first alpha will be out
> reasonably soon, but is not going to be ready for production use for
> quite a bit longer), among other redundant things that exist in 2.* only
> for legacy and backwards compatibility reasons.  This makes 3.0 simpler
> (a little closer to the "only one obvious way" ideal).
>
> But you should use ``in'' and ``not in'' anyway, even if you don't care
> about 3.* at all, because they only have advantages wrt has_key, without
> any compensating disadvantage.
>
> Alex

Martelli,

I kind of figured .get wasn't a direct alternative to "in", but I
thought the OP might be able to use it since (s)he didn't mention what
they wanted to do.

Mike

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


Re: strange list comprehension on generator

2007-08-29 Thread [EMAIL PROTECTED]
On Aug 29, 6:50 am, Roland Puntaier <[EMAIL PROTECTED]
automation.com> wrote:
> def changeOne(aa,idx):
>   aa[idx]=not aa[idx]
>   yield aa
>   for i in range(idx):
> for x in changeOne(aa,i):
>   yield x
>
> def changeOneOrder(aa):
>   yield aa
>   for i in range(len(aa)):
> for x in changeOne(aa,i):
>   yield x
>
> a=[False]*3
> og=changeOneOrder(a)
> #this does not return the way I would expect. why?
> list(og)
> #returns
> #[[False, False, True], [False, False, True], [False, False, True],
> [False, False, True], [False, False, True], [False, False, True], [False,
> False, True], [False, False, True]]


If you want the "intermediate" states of 'a' in
list(og), then you need to yield a copy of that list,
instead of the list itself:

def changeOne(aa, idx):
aa[idx] = not aa[idx]
yield aa[:] # <--- a copy
for i in range(idx):
for x in changeOne(aa, i):
yield x

def changeOneOrder(aa):
yield aa[:] # <--- a copy
for i in range(len(aa)):
for x in changeOne(aa, i):
yield x

a = [False] * 3
og = changeOneOrder(a)
print list(og)

Otherwise, as you've already noticed, you can
loop over the iterator and do something
with the "instantaneous" state of 'a'.

--
Hope this helps,
Steven


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


replacing xml elements with other elements using lxml

2007-08-29 Thread Ultrus
Hello,
I'm attempting to generate a random story using xml as the document,
and lxml as the parser. I want the document to be simplified before
processing it further, and am very close to accomplishing my goal.
Below is what I have so far. Any ideas on how to move forward?

The goal:
read and edit xml file, replacing random elements with randomly picked
content from within

Completed:
[x] read xml
[x] access first random tag
[x] pick random content within random item
[o] need to replace  tag with picked contents

xml sample:
Here is some content.

   Here is some random content.
   Here is some more random content.

Here is some content.

Python code:
from lxml import etree
from StringIO import StringIO
import random

theXml = "Here is some content.Here is some random content.Here is some more random content.Here is some content."

f = StringIO(theXml)
tree = etree.parse(f)
r = tree.xpath('//random')

if len(r) > 0:
   randInt = random.randInt(0,(len(r[0]) - 1))
   randContents = r[0][randInt][0]
   #replace parent random tag with picked content here

now that I have the contents tag randomly chosen, how do I delete the
parent  tag, and replace it to look like this:

final xml sample (goal):
Here is some content.
Here is some random content.
Here is some content.

Any idea on how to do this? So close! Thanks for the help in
advance. :)

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


Re: handling tabular data in python--newbie question

2007-08-29 Thread hyena
Thanks Bruno and Steve for the quick answer!

>What make you think such a thing ?
I am also using R and java from time to time, and think it is very covinient 
that in R tables are handled as matrixs or data frames. Thus I expect python 
has something similiar. :)

And I went for Steve's first suggestion, which is just what I want at this 
moment.

Thanks again. 


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


Re: Jython 2.2 on Ubuntu

2007-08-29 Thread Neil Wallace
Thanks Tim,

I subscribed to the Jython group hosted by sourceforge, and they are a 
great bunch of guys/gals.

Here's what I did to fix my problem.

1. removed Jython 2.1 (using Synaptic)jytho
2. added the following lines (as root) to /etc/profile
 # set PATH for Jython
 PATH=$PATH:/home/neil/jython2.2
 export PATH

I had to restart X, that's it solved!!

Neil


Tim Couper wrote:
> you need to ensure that the correct jython executable is in a directory 
> which is on your on your path.
> 
> I've just successfully test-subscribed to 
> https://lists.sourceforge.net/lists/listinfo/jython-users. Maybe you 
> could try again.
> 
> Tim
> 
> Dr Tim Couper
> CTO, SciVisum Ltd
> 
> www.scivisum.com
> 
> 
> 
> Neil Wallace wrote:
>> Hi all,
>>
>> I am a novice Python/Jython programmer, and Ubuntu user.
>>
>> Ubuntu still only supports only version 2.1 of Jython. I have used the 
>> GUI installer of Jython 2.2, and installed it to the default 
>> /root/jython2.2 directory. The install went without issues.
>>
>> However, typing jython --version
>> in a teminal still gives me    Jython 2.1 on java (JIT: null)
>>
>> What else do I need to do?
>>
>> regards
>> Neil.
>>
>> p.s. I posted this to the jython group hosted by sourceforge, but it 
>> bounced. :-(
>>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's the difference ?

2007-08-29 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:
   ...
> Weird. Hetland's book, "Beginning Python" states that it's a matter of
> taste.

If your taste is for more verbose AND slower notation without any
compensating advantage, sure.

> Martelli's "Python Cookbook 2nd Ed." says to use the get()
> method instead as you never know if a key is in the dict.  However, I
> can't seem to find any reference to has_key in his book.

.get is not a direct alternative to ``in'' (it's an alternative to an
idiom where you key into the dict if the key is present and otherwise
supply a default value, and it's MUCH better in that case).  has_key is
probably not even mentioned in the Cookbook (2nd edition) since there is
never a good need for it in the Python versions it covers (2.2 and up),
but you can probably find traces in the 1st edition (which also covered
Python back to 1.5.2, where has_key *was* needed); the Nutshell (2nd ed)
mentions it briefly in a table on p. 60.


> According to Chun in "Core Python Programming", has_key will be
> obsoleted in future versions of Python, so he recommends using "in" or
> "not in".

Yes, we're removing has_key in Python 3.0 (whose first alpha will be out
reasonably soon, but is not going to be ready for production use for
quite a bit longer), among other redundant things that exist in 2.* only
for legacy and backwards compatibility reasons.  This makes 3.0 simpler
(a little closer to the "only one obvious way" ideal).

But you should use ``in'' and ``not in'' anyway, even if you don't care
about 3.* at all, because they only have advantages wrt has_key, without
any compensating disadvantage.


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


Re: What's the difference ?

2007-08-29 Thread Alex Martelli
Alex <[EMAIL PROTECTED]> wrote:

> Hye,
> 
> I was just wondering what is the difference between
> 
> >> if my_key in mydict:
> >> ...
> 
> and
> 
> >> if mydict.has_keys(my_key):

Mis-spelled (no final s in the method name).

> >> ...
> 
> I've search a bit in the python documentation, and the only things I
> found was that they are "equivalent".

Semantically they are, but `in' is faster, more concise, & readable.


> But in this (quiet old) sample ( "http://aspn.activestate.com/ASPN/
> Cookbook/Python/Recipe/59875" ), there is difference between the two
> notation.

What that example is pointing to as "wrong way" is a NON-equivalent
approach that's extremely slow:
  if my_key in mydict.keys():

The call to keys() takes time and memory to build a list of all keys,
after which the ``in'' operator, having a list as the RHS operand, is
also quite slow (O(N), vs O(1)!).  So, never use that useless and silly
call to keys() in this context!


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


Re: strange list comprehension on generator

2007-08-29 Thread Martin v. Löwis
> #this does not return the way I would expect. why?

You yield the very same list object all the times. So
when you make a later change, all earlier results will
get changed, too (since they are the same object).
Of course, it won't affect the terminal output, so you
don't see that the older values changed in the example
that you think works as expected.

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


Re: strange list comprehension on generator

2007-08-29 Thread Bjoern Schliessmann
No greeting, no text? Pity.

Roland Puntaier wrote:

> def changeOne(aa,idx):
>   aa[idx]=not aa[idx]
>   yield aa
>   for i in range(idx):
> for x in changeOne(aa,i):
>   yield x
> 
> def changeOneOrder(aa):
>   yield aa
>   for i in range(len(aa)):
> for x in changeOne(aa,i):
>   yield x

Okay, two generator definitions.
 
> a=[False]*3
> og=changeOneOrder(a)
> #this does not return the way I would expect. why?

What do you expect? You created a generator object and bound it
to "og".

Please always state what you expect and what really happens. Fortune
telling is not one of my hobbies (and I think I'm not alone with
that).

Regards,


Björn

-- 
BOFH excuse #284:

Electrons on a bender

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


Re: Creating a multi-tier client/server application

2007-08-29 Thread Goldfish
Perhaps Spring Python can help you out (http://springpython.python-
hosting.com). It reuses technologies like Pyro for remoting, offers
database templates, has a plugable security component, an AOP solution
should the need arise, an IoC container, and has a couple of web-app
demos using CherryPy. Of course, you can use whatever web stack you
want. I just picked CherryPy to demo things.

Each component of Spring Python is optional, and you can use it
through the IoC container, or programatically. This might help you
leverage development of an enterprise app.

BTW, I have plans to implement a wxPython front end sample app. I just
haven't done it yet.

Good luck!

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


Re: Creating a multi-tier client/server application

2007-08-29 Thread Jeff
> You could explore something like a custom-made GUI client app
> communicating thru the http protocol with a web-server app. http is just
> a protocol, and it doesn't necessarily imply using html and a browser...
> IIRC, some GUI toolkits uses XML description files for the UI.

That, or something similar, may be what I do.  It would mean, however,
developing my own method for transferring objects across the network,
which, as far as I can tell, is what things like Pyro are supposed to
take care of.


> > 3) Easier to "lock down" who's using the program by only
> > installing it on certain machines.
>
> Not a very reliable security scheme IMHO !-)

You are 100% correct.  That will most certainly *not* be the only
means of security.  There will be user authentication against a
central LDAP server, SSL for all connections, and possibly IP address
based blocking as well.  I need to clarify what I meant (I didn't want
to bore everyone with the tedious details)--while this system will
mostly be used by supervisors/managers, the employees will also be
using it to sign into their shifts.  The managers want the employees
to only be able to sign in from designated machines, while at the same
time they want them to be able to look up their schedules from a web
interface, but *not* use that to sign in.  That wasn't the best point,
but I think there's something to be said of the *perceived* security
of desktop vs. web apps.

> Extreme Programming doesn't mean "no preparation", and makes heavy use
> of use cases. Of course you need to have some - hopefully accurate -
> functional specs. The point was mostly along the lines of "don't try to
> have full-featured detailed design before you start coding, because
> chances are it will be wrong".
>
> > Hopefully, the amount of planning will be somewhere in between that
> > and the bureaucratic nightmare of documenting up front what each
> > module, class and function will do.
>
> Which would be totally non-sensical. I don't believe anyone on earth
> could come up with such a thing - done right - *before* the application
> is written.

I'm not looking to layout how the GUI should look, or even how
individual parts of it should work.  What I need to do, though, is
write very detailed specs with my clients on the data that will be
used, and plan out as thoroughly as possible the architecture of the
project as far as tiers and such.  I don't have much choice in this
aspect, sadly.  But, in my experience, the more detail (and agreement
on those details) I have up front, the less painful the rest of the
process will be.

Thanks again!

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


Re: self extracting zipefile (windows) and (standard module) zipefile

2007-08-29 Thread Grant Edwards
On 2007-08-29, Hyuga <[EMAIL PROTECTED]> wrote:

>> I try to read (and extract) some "self extracting" zipefiles
>> on a Windows system. The standard module zipefile seems not to
>> be able to handle this. [...]
>
> First of all, there's really no such thing as a "self
> extracting zipefile".

Perhaps there isn't "really such a thing," but that's the
commonly used name for the type of file the OP is dealing with.

> [...] You'll have to execute it--there's no way you can
> operate on it like a normal zip file.

Executing the file is a huge, huge security risk.

Other zip tools (e.g. the "unzip" utility for Linux) seem know
how to work with self-extracting zipfiles.  Unfortunately there
are multiple slightly different zip formats along with mutlple
"self-extracting zip file" formats. Nonetheless, I've never run
across one I couldn't unzip without executing it.  On Linux,
I'd probably just try exec'ing the "unzip" program.  

Another option is to search through the file from the beginning
looking for whatever signature matches the beginning of a
"normal" zip file.  The self-extracting zipfiles that I've
dissected are just an executable image concatenated with a
"normal" zipfile.  If you just start searching from the
beginning of the file, it's simple to find the actual zip data
and copy it into a separate file which then can be unzipped
like any other plain zipfile.  I haven't done that for many
years since the normal zip tools that I use can operate on
self-extracting files.

-- 
Grant Edwards   grante Yow! NEWARK has been
  at   REZONED!!  DES MOINES has
   visi.combeen REZONED!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: non-blocking communication with imaplib

2007-08-29 Thread Igor V. Rafienko
[ Lawrence D'Oliveiro ]

[ ... ]

> According to the documentation
> , you can override
> the "read" and "readline" methods. How about replacing them with
> routines that use select.select on the socket() object to implement
> a timeout?


Sounds like a plan. I'll try that. Thank you.





ivr
-- 
<+Kaptein-Dah> igorr: for få parenteser
<+Kaptein-Dah> igorr: parenteser virker som lubrication under iterasjon
<+Kaptein-Dah> igorr: velkjent
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: status of Programming by Contract (PEP 316)?

2007-08-29 Thread Aahz
In article <[EMAIL PROTECTED]>,
Russ  <[EMAIL PROTECTED]> wrote:
>
>I just stumbled onto PEP 316: Programming by Contract for Python
>(http://www.python.org/dev/peps/pep-0316/). This would be a great
>addition to Python, but I see that it was submitted way back in 2003,
>and its status is "deferred." I did a quick search on comp.lang.python,
>but I don't seem to see much on it. Does anyone know what the real
>status is of getting this into standard Python? Thanks.

The way to get this into Python is to get people to use it as a
stand-alone module.  It's already in PyPI, so now it's time for some
marketing.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"If you don't know what your program is supposed to do, you'd better not
start writing it."  --Dijkstra
-- 
http://mail.python.org/mailman/listinfo/python-list


strange list comprehension on generator

2007-08-29 Thread Roland Puntaier
def changeOne(aa,idx):
  aa[idx]=not aa[idx]
  yield aa
  for i in range(idx):
for x in changeOne(aa,i):
  yield x

def changeOneOrder(aa):
  yield aa
  for i in range(len(aa)): 
for x in changeOne(aa,i):
  yield x

a=[False]*3
og=changeOneOrder(a)
#this does not return the way I would expect. why?
list(og)
#returns
#[[False, False, True], [False, False, True], [False, False, True], 
[False, False, True], [False, False, True], [False, False, True], [False, 
False, True], [False, False, True]]


#this works as expected
a=[False]*3
og=changeOneOrder(a)
og.next()
og.next()
...

#this works as expected
def ty():
  yield 1
  yield 2
  yield 3

tg=ty()
list(tg)

cheers, Roland

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


Re: What's the difference ?

2007-08-29 Thread Marc 'BlackJack' Rintsch
On Wed, 29 Aug 2007 13:39:27 +, Alex wrote:

> Hye,
> 
> I was just wondering what is the difference between
> 
>>> if my_key in mydict:
>>> ...
> 
> and
> 
>>> if mydict.has_keys(my_key):
>>> ...
> 
> I've search a bit in the python documentation, and the only things I
> found was that they are "equivalent".
> 
> But in this (quiet old) sample ( "http://aspn.activestate.com/ASPN/
> Cookbook/Python/Recipe/59875" ), there is difference between the two
> notation.

The comments in this recipes source code are misleading.  Difference is
not the ``in`` but that it is used on ``another_dict.keys()`` in the "bad"
example.  That is a linear search on a list with all keys instead asking
the dictionary directly like you did above.

The difference in your code above is that  ``in`` works on other types too
that implement `__contains__()`, like lists or sets for example, and that
it is a bit faster as the second example has to look up the `has_key()`
method on the object first.

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


Re: What's the difference ?

2007-08-29 Thread kyosohma
On Aug 29, 8:39 am, Alex <[EMAIL PROTECTED]> wrote:
> Hye,
>
> I was just wondering what is the difference between
>
> >> if my_key in mydict:
> >> ...
>
> and
>
> >> if mydict.has_keys(my_key):
> >> ...
>
> I've search a bit in the python documentation, and the only things I
> found was that they are "equivalent".
>
> But in this (quiet old) sample ( "http://aspn.activestate.com/ASPN/
> Cookbook/Python/Recipe/59875" ), there is difference between the two
> notation.
>
> Thanks in advance

Weird. Hetland's book, "Beginning Python" states that it's a matter of
taste. Martelli's "Python Cookbook 2nd Ed." says to use the get()
method instead as you never know if a key is in the dict.  However, I
can't seem to find any reference to has_key in his book.

According to Chun in "Core Python Programming", has_key will be
obsoleted in future versions of Python, so he recommends using "in" or
"not in".

There's your non-answer. Hope that helps.

Mike

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


Re: Pythonwin Install COM exceptions on Windows Vista Ultimate

2007-08-29 Thread Larry Bates
Sandipan News wrote:
> What do I do? Can't do without Python!
> Any experience, advice, hope is welcome.
> Thanks.
> Sandipan
> 
> 
If you are asking if you can run COM objects created in Python on Windows Vista 
Ultimate, the answer is yes.  I have several.

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


Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-29 Thread M�ta-MCI \(MVP\)
Hi! 

I've send the soft.
But, I have no news ; good news? 

@+

Michel Claveau

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


Re: Creating a multi-tier client/server application

2007-08-29 Thread Bruno Desthuilliers
Jeff a écrit :
> Thanks for the quick responses.
> 
> I was really hoping to avoid an entirely web-based app, for a few
> reasons, not the least of which is that I've been working almost
> entirely on web apps for the past few years, and I am getting mighty
> sick of it.  A lot of that is due to the language (PHP, which I have
> since grown to hate) I had to use.  I've worked on a site for my self
> in Python (using Pylons, actually--which is excellent) which was
> vastly easier and more fun.  But I'd really like to try something
> different.
> 
> Now, of course, that's not enough reason to force such a thing onto my
> clients (when I say clients, I mean the ones that are paying for this,
> but they're really within my same department, so they actually have
> working technical knowledge.)  Some reasons for them would be (in no
> particular order): 1) More responsive and user-friendly interfaces,

You could explore something like a custom-made GUI client app 
communicating thru the http protocol with a web-server app. http is just 
a protocol, and it doesn't necessarily imply using html and a browser... 
IIRC, some GUI toolkits uses XML description files for the UI.

(snip)

> 3) Easier to "lock down" who's using the program by only
> installing it on certain machines.

Not a very reliable security scheme IMHO !-)

(snip)

> Which leads me to the discussion of planning:  
(snip)

> This system will be used, often, to figure out how much people should
> be paid (and then interface directly with the University's payroll
> system), and store lovely things like SSNs, and will also have to have
> somewhat crazy business logic to track when hourly workers are
> eligible for raises, if they took enough training classes, etc.  There
> are a lot of people with a stake in this system, and I will need to
> work with them very closely on how this should work, and they sure as
> hell don't want any surprises.  My manager even wants use cases (if
> you've never had to deal with use cases, consider yourself a lucky,
> lucky person) which I am going to attempt to argue as that is even
> going *too* far.
> 
> So, long story short (too late), no Extreme Programming for me.

Extreme Programming doesn't mean "no preparation", and makes heavy use 
of use cases. Of course you need to have some - hopefully accurate - 
functional specs. The point was mostly along the lines of "don't try to 
have full-featured detailed design before you start coding, because 
chances are it will be wrong".

> Hopefully, the amount of planning will be somewhere in between that
> and the bureaucratic nightmare of documenting up front what each
> module, class and function will do.

Which would be totally non-sensical. I don't believe anyone on earth 
could come up with such a thing - done right - *before* the application 
is written.
-- 
http://mail.python.org/mailman/listinfo/python-list


What's the difference ?

2007-08-29 Thread Alex
Hye,

I was just wondering what is the difference between

>> if my_key in mydict:
>> ...

and

>> if mydict.has_keys(my_key):
>> ...

I've search a bit in the python documentation, and the only things I
found was that they are "equivalent".

But in this (quiet old) sample ( "http://aspn.activestate.com/ASPN/
Cookbook/Python/Recipe/59875" ), there is difference between the two
notation.

Thanks in advance

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


  1   2   >