Fredericksburg, VA ZPUG Meeting: January 11, 7:30-9:00 PM

2006-01-06 Thread Benji York
Please join us January 11, 7:30-9:00 PM, for the seventh meeting of
the Fredericksburg, VA Zope and Python User Group (ZPUG). Squid and
Zope! Python and Zope roundtable! Free food!

 * Andrew Sawyers will discuss using the open source cache server
Squid with Zope, including a discussion of the O'Reilly book about
Squid (this talk was moved from our November meeting).

 * We will have a Python and Zope roundtable for questions and
ideas about Zope or Python.  Have a question you want to ask a Zope
core developer or a Python core developer or a community Zope or
Python user?  Come by!

 * We will serve delicious food and soft drinks.

We've had a nice group for all the meetings. Please come and bring
friends!

We also are now members of the O'Reilly and Apress user group
programs, which gives us nice book discounts (prices better than
Amazon's, for instance) and the possibility of free review copies.
Ask me about details at the meeting if you are interested.


General ZPUG information

When: second Wednesday of every month, 7:30-9:00.

Where: Zope Corporation offices. 513 Prince Edward Street;
Fredericksburg, VA 22408 (tinyurl for map is http://tinyurl.com/duoab).

Parking: Zope Corporation parking lot; entrance on Prince Edward Street.

Topics: As desired (and offered) by participants, within the
constraints of having to do with Python or Zope.

Contact: Gary Poster ([EMAIL PROTECTED])
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


ANN: Leo 4.4a5 released

2006-01-06 Thread Edward K. Ream
Leo 4.4 alpha 5 is now available at:

http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106

This release completes the last major features of Leo 4.4:

- User-specified key-binding modes.

- Support for multiple key-bindings for individual minibuffer commands.

This will be the last alpha version of Leo 4.4. Beta 1 is coming in about a 
week. You should be able to use this version safely; there are no known 
serious bugs.

To learn about Leo, see: http://webpages.charter.net/edreamleo/intro.html

The highlights of Leo 4.4:
--
- An Emacs-like mini-buffer: you can now execute any command by typing its 
long name. Support for tab completion.

- A tabbed log pane. The Find and Spell Check commands now use tabs instead 
of dialogs, making those commands much easier to use. Plugins or scripts can 
easily create new tabs. The Completion tab shows possible typing 
completions.

- Support for most commands in the Emacs Cmds menu, including cursor and 
screen movement, basic character, word and paragraph manipulation, and 
commands to manipulate buffers, the kill ring, regions and rectangles.

- Per-pane key bindings. You can bind shortcuts to multiple commands 
depending on which of Leo's panes presently has focus. For example, you can 
use arrow keys to move nodes in the outline pane, while retaining their 
defaults in Leo's body pane.

- User-specified key-binding modes. This feature makes it possible to 
emulate all aspects of Emacs and Vim as far as key bindings are concerned.

- Leo recovers from crashes much more reliably than in any previous version.

- @command nodes create minibuffer commands. You can bind key shortcuts to 
@button and @command nodes.

- Leo handles key events and updates the screen immediately rather than 
queuing them for idle time.

- Leo updates the screen immediately rather than waiting for idle time. This 
improves response.

Links:
--
Leo:  http://webpages.charter.net/edreamleo/front.html
Home: http://sourceforge.net/projects/leo/
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
CVS:  http://sourceforge.net/cvs/?group_id=3458
Quotes:   http://webpages.charter.net/edreamleo/testimonials.html


Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html


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

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


Re: itertools.izip brokeness

2006-01-06 Thread Paul Rubin
Paul Rubin http://[EMAIL PROTECTED] writes:
# quit if only discardables are left
dropwhile(lambda i,t: (not isinstance(i, Discardable)) and len(t)),
   izip(t, iterables)).next()

Ehh, that should say dropwhile(lambda (t,i): ...)  to use tuple
unpacking and get the args in the right order.  I'm sleepy and forgot
what I was doing.  Of course I'm still not sure it's right.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Xah's Edu Corner: the bug-reporting attitude

2006-01-06 Thread rurpy

Tim Roberts [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

 Xah Lee (1) is a write-only poster who pontificates but never reads
 replies, and (2) cares not a whit that the rest of us believe him to be a
 moron.

I find him offensive, and a pontificator as you said, but I
don't think he is a moron.  He has complained about
Python's docs, and that being an interest of mine too,
I visited his website and thought a lot of his criticism's
were spot on.  Unfortunately I didn't think his proposed
solutions were very good but that's not surprising, it
is a lot easier to recognize problems than to fix them.

 In a sense, I envy him.  I hold a number of strong and somewhat
 controversial opinions that I hesitate to expose in public, for fear of
 being laughed at and labeled as a nutcase.  Xah Lee has absolutely no such
 fears.

It is easier to do from an anonymous account, although
some people here have said they ignore posts from
posters without a real identity.  But my opinion is that
c.l.p is not very receptive to unorthodoxy unless you
are a member of the club (in which case you know
better than to be unorthodox).

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


Re: Python function with **kwargs Question

2006-01-06 Thread Eric McGraw
You could call it like this:
 foo(**{a-special-keyword:5})
but that might defeat the purpose of keyword arguments.

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


Re: Xah's Edu Corner: the bug-reporting attitude

2006-01-06 Thread rurpy

Tim Roberts [EMAIL PROTECTED] wrote:

 Xah Lee (1) is a write-only poster who pontificates but never reads
 replies, and (2) cares not a whit that the rest of us believe him to be a
 moron.

I find him offensive, and a pontificator as you said, but I
don't think he is a moron.  He has complained about
Python's docs, and that being an interest of mine too,
I visited his website and thought a lot of his criticism's
were spot on.  Unfortunately I didn't think his proposed
solutions were very good but that's not surprising, it
is a lot easier to recognize problems than to fix them.

 In a sense, I envy him.  I hold a number of strong and somewhat
 controversial opinions that I hesitate to expose in public, for fear of
 being laughed at and labeled as a nutcase.  Xah Lee has absolutely no such
 fears.

It is easier to do from an anonymous account, although
some people here have said they ignore posts from
posters without a real identity.  But my opinion is that
c.l.p is not very receptive to unorthodoxy unless you
are a member of the club (in which case you know
better than to be unorthodox).

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


Path and Unicode woes

2006-01-06 Thread André
I'm attempting to override a wxHtmlWindow method in order to
pre-process the file before displaying it. I'm using a unicode version
of wxPython.  I don't think my problem are wxPython-specific, but
rather a unicode mis-understanding.   Consider the following:

.def OnLinkClicked(self, linkinfo):
.#adapted from the wxPython demo
.target_file = linkinfo.GetHref()
.current = self.GetOpenedPage()
.path = os.path.dirname(current)
.print path = , path
.print current = , current
.print target_file = , target_file
.filename = os.path.join(path, target_file)
.print filename = , filename
.filename = filename.replace('\\','/')
.print filename: , filename+'\n'
.self.LoadFile(filename)

The first time I *click* on a link, I get the following:


path =  E:/Copy of rurple0.9.0.1b/rurple0.9.0.1/html/en
current =  E:/Copy of rurple0.9.0.1b/rurple0.9.0.1/html/en/rur.htm.html
target_file =  intro/browser.htm
filename =  E:/Copy of
rurple0.9.0.1b/rurple0.9.0.1/html/en\intro/browser.htm
filename:  E:/Copy of
rurple0.9.0.1b/rurple0.9.0.1/html/en/intro/browser.htm

... and everything is just fine (the expected file opens in the browser
window).  The second time I *click* on a link, I get the following
(note the replacement of E: by /E%3A):

path =  /E%3A/Copy of rurple0.9.0.1b/rurple0.9.0.1/html/en/intro
current =  /E%3A/Copy of
rurple0.9.0.1b/rurple0.9.0.1/html/en/intro/browser.htm.html
target_file =  explore.htm
filename =  /E%3A/Copy of
rurple0.9.0.1b/rurple0.9.0.1/html/en/intro\explore.htm
filename:  /E%3A/Copy of
rurple0.9.0.1b/rurple0.9.0.1/html/en/intro/explore.htm

Traceback (most recent call last):
  File E:\Copy of rurple0.9.0.1b\rurple0.9.0.1\rur_py\browser.py,
line 77, in OnLinkClicked
self.LoadFile(filename)
  File E:\Copy of rurple0.9.0.1b\rurple0.9.0.1\rur_py\browser.py,
line 54, in LoadFile
data = open(filename, 'r').read()
IOError: [Errno 2] No such file or directory: u'/E%3A/Copy of
rurple0.9.0.1b/rurple0.9.0.1/html/en/intro/explore.htm'

Any help or pointers would be appreciated...

André

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


C regex equiv to Python implementation?

2006-01-06 Thread techiepundit
I've been writing code in Python to prototype part of an application.
I've used the re regular expression pattern matcher. Now I have to take
what I've written and recode it in C to fit in an existing C app.

Anyway, is there a way to use the re regular expression evaluator in C?
Is it written in C?

Or does anyone know of a similar one that does search and match in
close to the same fashion with begin and end values returned?

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


Inheritance problem?

2006-01-06 Thread KraftDiner
I have a class

class MyClass(MyBaseClass)
   def __init__(self)
  super(self.__class__, self).__init__()
  self.type = MyClassType
  return self

It has a few methods...
I have another class and the only difference is the __init__ method..

I tried this:
class MySpecialClass(MyClass)
   def __init__(self)
  super(self.__class__, self).__init__()
  self.type = MySpecialClassType   # This is the only line
that's different between the two classes.
  return self

At runtime I get an error:
RuntimeError: maximum recursion depth exceeded
What have I done wrong?

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


Re: Microsoft IronPython?

2006-01-06 Thread rurpy

EP [EMAIL PROTECTED] wrote:
 Luis M. González wrote:

 Will Microsoft hurt Python?
 
 
 I think it is naive to ignore the fact that Microsoft could hurt Python,
 though there may be nothing anyone can do.

 How?
 
 - create a more prevalent version of Python that is less Pythonic or
 undermines some of the principles of the language, basically usurping
 Python as we conceive it in the process;
 - create an incompatible version, so that Python portability is
 dependent upon the programmer porting his code to two separate versions
 (JavaScript comes to mind);
 - create a poor implementation of Python so that programmers try the MS
 version first, find it lacking, and decide Python is a poor language...
 tarnishing the reputation of the language and its adoption...
...
Wasn't it often said that Microsoft's strategy for dealing with
standards
(and perhaps rival open source software?) was embrace, extend,
extinguish?

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


please help the newbie!

2006-01-06 Thread dpickles
In my Python research, I have found a nice little voice recognition
script on the internet that does exactly what I need, and the demo
recognizes phrases with pretty much 100%accuracy.
The script can be found here:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/93025

What I want to do is make this code into a module, so I can use it in
other programs. For example:

import voicerecognition as vr
vr.StartRecognition([one, two, three])
result = vr.GetRecognized()
if result == one:
 print You said: one
else:
 print You did not say 'one'.


Any help would be appreciated. I have tried this, but IDLE keeps
freezing whenever I try to use the module with a test script.
As I said, I am a newbie and do not know very much about classes,
instances, and all those __funky__ modules.

Can anybody give me some tips on turning this into a module???
Thank you!

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


Re: Xah's Edu Corner: the bug-reporting attitude

2006-01-06 Thread rurpy

Tim Roberts [EMAIL PROTECTED] wrote:

 Xah Lee (1) is a write-only poster who pontificates but never reads
 replies, and (2) cares not a whit that the rest of us believe him to be a
 moron.

I find him offensive, and a pontificator as you said,
but I don't think he is a moron.  He has complained about
Python's docs, and that being an interest of mine too,
I visited his website and thought a lot of his criticism's
were spot on.  Unfortunately I didn't think his proposed
solutions were very good but that's not surprising, it
is a lot easier to recognize problems than to fix them.

 In a sense, I envy him.  I hold a number of strong and somewhat
 controversial opinions that I hesitate to expose in public, for fear of
 being laughed at and labeled as a nutcase.  Xah Lee has absolutely no such
 fears.

It is easier to do from an anonymous account, although
some people here have said they ignore posts from
posters without a real identity.  But my opinion is that
c.l.p is not very receptive to unorthodoxy unless you
are a member of the club (in which case you know
better than to be unorthodox).

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


Removing Duplicate entries in a file...

2006-01-06 Thread sri2097
Hi all, I'm storing number of dictionary values into a file using the
'cPickle' module and then am retrieving it. The following is the code
for it  -

# Code for storing the values in the file
import cPickle

book = {raw_input(Name: ): [int(raw_input(Phone: )),
raw_input(Address: )] }
file_object = file(database, 'w+')
cPickle.dump(book, file_object)
file_object.close()

# Code for retrieving values and modifiing them.
tobe_modified_name = raw_input(Enter name to be modified: )
file_object = file(database)

while file_object.tell() != EOFError:
try:
stored_dict = cPickle.load(file_object)
if stored_dict.has_key(tobe_modified_name):
print (Entry found !)
# I want to modify the values retrieved from the file and
then put it back to the file   without duplicate entry.
file_object = file(database, 'a+')
except EOFError:
break
file_object.close()


Now, my problem is after finding the entry in the file, I want to make
changes to the 'values' under the searched 'key' and then insert it
back to the file. But in doing so I'm having duplicate entries for the
same key. I want to remove the previous key and value entry in the file
and key the latest one.  How to solve this problem ?

I actually thought of 2 ways -

1) In Java there is something called 'file_pointer' concept where in
after you find the entry you are looking for you move all the entries
below this entry. Then you get the searched entry at the bottom of the
file. After this truncate the file by a certain bytes to remove the old
entry. Can we do this in Python using the file.truncate([size]) method
?

2) Although this is a really crappy way but nevertheless I'll put it
across. First after finding the entry you are looking for in the file,
make a copy of this file without the entry found in the previous file.
Make the changes to the 'values' under this key and insert this into
the second file what you have created. Before exiting delete the first
file.

Are there any more ways to solve my problem ? Any criticisms are
welcome

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


Re: Encoding sniffer?

2006-01-06 Thread Andreas Jung

Thanks!

--On 5. Januar 2006 18:21:39 -0600 [EMAIL PROTECTED] wrote:


http://orca.mojam.com/~skip/python/






pgpyF17uM2CTT.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How run web software *locally* easily?

2006-01-06 Thread Paul Rubin
[EMAIL PROTECTED] [EMAIL PROTECTED] writes:
 Is there some easy way to somehow perhaps embed a minimal web server in
 a Python tar ball

Yes, sure, see any of the HTTP server classes in the stdlib.
Just listen on a localhost socket and pop a browser to point to that socket.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C regex equiv to Python implementation?

2006-01-06 Thread Ganesan Rajagopal
 techiepundit  [EMAIL PROTECTED] writes:

 I've been writing code in Python to prototype part of an application.
 I've used the re regular expression pattern matcher. Now I have to take
 what I've written and recode it in C to fit in an existing C app.

What platform? Linux includes a regex(7) implementation in the C
library. However, it doesn't support many of the extensions that Python
regexes support. Try http://www.pcre.org/. There are pre-build binaries for
Windows also. 

Ganesan

-- 
Ganesan Rajagopal (rganesan at debian.org) | GPG Key: 1024D/5D8C12EA
Web: http://employees.org/~rganesan| http://rganesan.blogspot.com


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


Re: How to Retrieve Data from an HTTPS://URL

2006-01-06 Thread Fuzzyman
It certainly *should* work - have you tried with urllib2 ? I assume the
page works when fetched with a browser ?

You don't have any proxy settings do you (Python can pick up on these
automatically) ?

What error are you getting (or what value in data) ?

All the best,

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

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


Working Firedrop2 anywhere?

2006-01-06 Thread Steve Holden
I've been trying to install Firedrop2, but the currently available 
source doesn't appear to be usable. For the whole sad story, or to see 
whether I did something wrong, see

   http://holdenweb.blogspot.com/2006/01/open-source-frustrations.html

Does anyone know where a working copy might be located? I can't be 
Googling hard enough!

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Microsoft IronPython?

2006-01-06 Thread Max M
EP wrote:
 Luis M. González wrote:
 
 Will Microsoft hurt Python?
  
 I think it is naive to ignore the fact that Microsoft could hurt Python, 
 though there may be nothing anyone can do.
 
 How?
 
 - create a more prevalent version of Python that is less Pythonic or 
 undermines some of the principles of the language, basically usurping 


First of they would need to make Python a strategic platform for 
corporations, so that it was used practically everywhere on Windows.

Then it would have the powerbase to change the lanuage and make an 
incompatible version that they could control.

As far as I can see C## has that role for them. So I don't see how 
Python should be in any danger.


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: csv format to DBase III format

2006-01-06 Thread William

Peter Otten wrote:
 [EMAIL PROTECTED] wrote:

  I need to transfer csv format file to DBase III format file.
  How do i do it in Python language?

 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362715

 Peter

Hi,

I create a dbf file, it can be opened by Excel but it cannot be opened
by Access. Where
is the error in my script. My script is as follows:

#!/opt/bin/python2.3

import struct, datetime,itertools,time


def dbfwriter(f, fieldnames, fieldspecs, records):

 Return a string suitable for writing directly to a binary dbf
file.

File f should be open for writing in a binary mode.

Fieldnames should be no longer than ten characters and not include
\x00.
Fieldspecs are in the form (type, size, deci) where
type is one of:
C for ascii character data
M for ascii character memo data (real memo fields not
supported)
D for datetime objects
N for ints or decimal objects
L for logical values 'T', 'F', or '?'
size is the field width
deci is the number of decimal places in the provided decimal
object
Records can be an iterable over the records (sequences of field
values).


# header info
ver = 3
now = datetime.datetime.now()
yr, mon, day = now.year-1900, now.month, now.day
numrec = len(records)
numfields = len(fieldspecs)
lenheader = numfields * 32 + 33
#   lenrecord = sum(field[1] for field in fieldspecs) + 1
num = 0
for field in fieldspecs :
 num = num + int(field[1])

lenrecord = num + 1

hdr = struct.pack('LHH20x', ver, yr, mon, day, numrec,
lenheader, lenrecord)
f.write(hdr)

# field specs
for name, (typ, size, deci) in itertools.izip(fieldnames,
fieldspecs):
#   name = name.ljust(11, '\x00')
name = name.ljust(11)
fld = struct.pack('11sc4xBB14x', name, typ, size, deci)
f.write(fld)

# terminator
f.write('\r')

# records
for record in records:
f.write(' ')# deletion flag
for (typ, size, deci), value in itertools.izip(fieldspecs,
record):
if typ == N:
#   value = str(value).rjust(size, ' ')
value = str(value).rjust(size)
elif typ == 'D':
#   value = value.strftime('%Y%m%d')
value = value
elif typ == 'L':
value = str(value)[0].upper()
else:
#   value = str(value)[:size].ljust(size, ' ')
value = str(value)[:size].ljust(size)
assert len(value) == size
f.write(value)

# End of file
f.write('\x1A')
f.close()


# ---
# Example calls
if __name__ == '__main__':

import sys, csv
from cStringIO import StringIO
#   from operator import itemgetter


# Create a new DBF
#   f = StringIO()

f = open('test.dbf','w')
fieldnames = ['CUSTOMER_ID','EMPLOY_ID','ORDER_DATE','ORDER_AMT']
fieldspecs = [('C',11,0),('C',11,0),('D',8,0),('N',12,2)]
records = [['MORNS','555','19950626','17.40'],\
['SAWYH','777','19950629','97.30'],\
['WALNG','555','19950522','173.40']]


dbfwriter(f, fieldnames, fieldspecs, records)

Thanks,

William

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


Re: Python function with **kwargs Question

2006-01-06 Thread Duncan Booth
Eric McGraw wrote:

 You could call it like this:
 foo(**{a-special-keyword:5})
 but that might defeat the purpose of keyword arguments.
 
Don't forget you can mix ordinary keyword arguments with the ** call, so 
only the weird arguments actually need to be passed that way.

 def f(**args):
print args


 f(a=1, **{'x-y':3})
{'a': 1, 'x-y': 3}
 

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


Re: Is 'everything' a refrence or isn't it?

2006-01-06 Thread Ernst Noch
Mike Meyer wrote:
 Steven D'Aprano [EMAIL PROTECTED] writes:
 
Thinking about Python's behaviour (it always passes references to
objects) will invoke misleading frames in many programmers' minds. The
word reference is misleading and should be avoided, because what the
average non-Python programmer understands by the word is different from
what the experienced Pythonista understands by it.
 
 
 Yes, but it's not misleading because reference doesn't mean what
 they think it means. reference means the same thing in Python as it
 does in C and similar languages. It's misleading because variables
 and assignment in Python don't do the things they do in C. Some of
 the places that this shows up is when you're dealing with call by
 reference, or with references in a list.


Maybe next time showing something like the following trivial snippet 
might help demonstrate that the core of the matter doesn't is not the 
way python treats parameters?

 def func(param, what):
if what:
param['foo'] = 'changed'
else:
temp = param['foo'] # temp is _not_ a reference!
temp = 'changed'

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


Re: itertools.izip brokeness

2006-01-06 Thread Bengt Richter
On 5 Jan 2006 14:34:39 -0800, [EMAIL PROTECTED] wrote:


Bengt Richter wrote:
 On 5 Jan 2006 15:48:26 GMT, Antoon Pardon [EMAIL PROTECTED] wrote:

 On 2006-01-04, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  But here is my real question...
  Why isn't something like this in itertools, or why shouldn't
  it go into itertools?
 
 
4) If a need does arise, it can be met by __builtins__.map() or by
   writing:  chain(iterable, repeat(None)).
 
  Yes, if youre a python guru.  I don't even understand the
  code presented in this thread that uses chain/repeat,
 
 And it wouldn't work in this case. chain(iterable, repeat(None))
 changes your iterable into an iterator that first gives you
 all elements in the iterator and when these are exhausted
 will continue giving the repeat parameter. e.g.
 
   chain([3,5,8],repeat(Bye)
 
 Will produce  3, 5 and 8 followed by an endless stream
 of Bye.
 
 But if you do this with all iterables, and you have to
 because you don't know which one is the smaller, all
 iterators will be infinite and izip will never stop.

 But you can fix that (only test is what you see ;-) :

   from itertools import repeat, chain, izip
   it = iter(lambda z=izip(chain([3,5,8],repeat(Bye)), 
 chain([11,22],repeat(Bye))):z.next(), (Bye,Bye))
   for t in it: print t
  ...
  (3, 11)
  (5, 22)
  (8, 'Bye')

 (Feel free to generalize ;-)

Which just reinforces my original point: if leaving
out a feature is justified by the existence of some
alternate method, then that method must be equally
obvious as the missing feature, or must be documented
as an idiom.  Otherwise, the justification fails.

Is the above code as obvious as
  izip([3,5,8],[11,22],sentinal='Bye')?
(where the sentinal keyword causes izip to iterate
to the longest argument.)

You are right. I was just responding with a quick fix to the
problem Antoon noted.
For a more flexible izip including the above capability, but
also abble to do the default izip with a capability of continuing iteration
in the above mode after the normal izip mode stops, see izip2.py in my other
post in this thread.

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


Re: Removing Duplicate entries in a file...

2006-01-06 Thread Fuzzyman

sri2097 wrote:
 Hi all, I'm storing number of dictionary values into a file using the
 'cPickle' module and then am retrieving it. The following is the code
 for it  -

 # Code for storing the values in the file
 import cPickle

 book = {raw_input(Name: ): [int(raw_input(Phone: )),
 raw_input(Address: )] }
 file_object = file(database, 'w+')
 cPickle.dump(book, file_object)
 file_object.close()


I may be misunderstanding you - but it seems you just want to read a
pickle, modify it, and then write it back ?

What you're doing is appending the modified pickle to the original one
- which is more complicated than what you want to achieve.

file_object = open(filename, 'rb')
stored_dict = cPickle.load(file_object)
file_object.close()

... code that modifies stored_dict

file_object = open(filename, 'wb')
cPickle.dump(stored_dict, file_object)
file_object.close()

Any reason why that shouldn't do what you want ?

All the best,

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

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


Re: itertools.izip brokeness

2006-01-06 Thread Steven D'Aprano
On Thu, 05 Jan 2006 23:52:13 -0800, Paul Rubin wrote:

 [EMAIL PROTECTED] writes:
 def izip4(*iterables, **kw):
  kw:fill. An element that will pad the shorter iterable
 kw:infinite. Number of non-terminating iterators 
 
 That's a really kludgy API.  I'm not sure what to propose instead:
 maybe some way of distinguishing which iterables are supposed to be
 iterated til exhaustion (untested):
 
 class Discardable(object): pass
 
 def izip5(*iterables, fill=None):

Doesn't work: keyword arguments must be listed before * and ** arguments.

 def izip5(*iterables, fill=None):
  File stdin, line 1
def izip5(*iterables, fill=None):
 ^
SyntaxError: invalid syntax


Personally, I don't see anything wrong with an API of

function(*iterators [, fill]):
   Perform function on one or more iterators, with an optional fill
   object.

Of course, this has to be defined in code as:

def function(*iterators, **kwargs):
if kwargs.keys() != [fill]:
raise ValueError
...

It might not be the easiest API to extend, but for a special case like
this, I think it is perfectly usable.


-- 
Steven.

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


Re: Is 'everything' a refrence or isn't it?

2006-01-06 Thread Steven D'Aprano
On Thu, 05 Jan 2006 22:18:39 -0600, Terry Hancock wrote:

 Consider this:
 
 def do_nothing(x):
 pass
 
 huge_tuple = (None,) * 1**4
 do_nothing(huge_tuple)
 
 If Python made a copy of huge_tuple before passing it to
 the function, you would notice.
 
 Which succinctly demonstrates precisely why a newbie
 *should* be told that Python passes references instead of
 values. 

I don't like Chinese food, and pizza gives me gas. Let's have a burger,
says I.

And Terry helpfully answers: Pizza gives you gas? Well there you go then,
that's precisely why we have to have Chinese food.

I have never suggested that we should tell newbies that Python is call
by value, and I deny that the only two possible choices for usefully
describing Python's behaviour is by CBV and CBR. The fact that Terry could
read this thread and still imagine that there is such a dichotomy is
worrying.


 But it should probably also be made clear that
 reference means a label assigned to an object, and not a
 variable containing a memory location (which is what a C
 pointer is).
 
 The reference is usually a simple name, but it can also be
 an container expression following list, dictionary,
 or class instance (spam, spam[0], spam['eggs'], or
 spam.ham, for example).  Not tuple or string because they
 are immutable, and so don't have assignable references.

Are you seriously suggesting that you can't include tuples in a list, or
pass them to functions? Because that's what it sounds like you're saying:
Python passes references. The reference is usually a simple name, but it
can also be a container... Not tuple or string because they are immutable.

If you don't mean to say that Python can't pass strings to functions, what
do you mean to say?

I'll tell you what I say: Python passes objects to functions or
assignments.

Does this mean that the object is copied? No, I didn't say it copies
objects. I left the nature of the passing mechanism unspoken, which is how
it should be because it is an implementation detail.

Does this mean that the object can be modified in place? Certainly not,
since that depends on the object, not on the nature of Python's high-level
behaviour. It emphasises the object oriented nature of Python, and by its
very language warns the reader not to assume that Python behaves
identically to other languages. It invites further questions, rather than
lulling the reader into jumping to false conclusions.

The emphasis is on the *object*, not the passing mechanism. In C,
everything is mutable, and whether you can change an item depends on
whether you are working with a reference to that item or a copy of the
item. That's a language issue, not a data issue -- in some languages,
you can even choose whether to pass a reference to a function or a copy
of the value.

In Python, whether or not you can change an object depends on the object,
not the language itself: it is a data issue.


-- 
Steven.

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


Re: itertools.izip brokeness

2006-01-06 Thread Paul Rubin
Steven D'Aprano [EMAIL PROTECTED] writes:
  def izip5(*iterables, fill=None):
 Doesn't work: keyword arguments must be listed before * and ** arguments.

Eh, ok, gotta use **kw.

 def function(*iterators, **kwargs):
 if kwargs.keys() != [fill]:
 raise ValueError
 ...
 
 It might not be the easiest API to extend, but for a special case like
 this, I think it is perfectly usable.

Yeah, that's what the earlier version had.  I tried to bypass it but
as you pointed out, it's a syntax error.  The code I posted also has a
deliberate syntax error (until Python 2.5), namely the use of the new
conditional expression syntax (PEP 308).  That could be worked around
of course.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How run web software *locally* easily?

2006-01-06 Thread sébastien
for example like that: python -m CGIHTTPServer

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


Re: OT: Degrees as barriers to entry [was Re: - E04 - Leadership! Google, Guido van Rossum, PSF]

2006-01-06 Thread David T

On Jan 3, 2006, at 9:54 PM, Brian van den Broek wrote:

 Steven D'Aprano said unto the world upon 03/01/06 07:33 PM:
 On Tue, 03 Jan 2006 08:27:39 -0800, Alex Martelli wrote:


 Or some even more stringent qualification, such as the state's  
 Bar exam
 for lawyers -- you may not be able to sit for that exam w/o the
 appropriate degree, but the degree by itself is not enough, you  
 still
 have to pass the exam.  It is that way for Engineers in Italy (I  
 passed
 my State Exam in the early '80s), although you only need the  
 certificate
 for some specific professional undertakings (e.g. design a ship,  
 or a
 large building, or technically supervise building operations  
 beyond a
 certain size -- not to write software or to design chips).

 Personally, I agree with the theory, first expressed by Adam  
 Smith, that
 such barriers to entry are mostly useful to grant practitioners of a
 certain profession the scarcity value that lets them charge higher
 prices, although of course they're always presented as good for
 society.  Note that in Europe in the Middle Ages you needed strict
 qualifications of that kind for just about anything -- you could not
 make hats unless you belonged to the Hatters' Guild, etc; most of  
 those
 restrictions have since been lifted, but a few groups (doctors,  
 lawyers,
 accountants, ...) have managed to keep them in place.


 Let's not confuse the medieval guild system with today's system.  
 Guilds
 were more like clubs than professional bodies: it was who you  
 knew, rather
 than what you knew, that decided whether you got in. You were  
 forbidden
 from becoming (say) a hat maker unless the other hat makers  
 allowed you to
 join the guild. There was no independent, or even semi- 
 independent, body
 who decided what qualifications were needed to make hats. It was  
 all about
 who you knew -- if your uncle's best friend was a hat maker, you  
 could be
 apprenticed to a hat maker and join the guild, otherwise there was  
 no exam
 to sit that got you in, no matter how talented you were.

 snip

 By contrast, today's professional bodies like law, medicine etc. have
 independent standards of skill that must be met. I don't wish to deny
 that knowing the right people can help smooth the procedure of  
 becoming
 a doctor, lawyer, etc., but failing to have an uncle who is a  
 lawyer is no
 barrier to becoming a lawyer, provided you can pass the bar exam.  
 That is
 very different from the guild system.

 snip

 Another major difference between today's professional bodies and  
 medieval
 guilds is that the scarcity is not entirely (or even mostly)  
 caused by
 the professional body. It is the universities controlling  
 prerequisite
 degrees that gain more from the scarcity: within reason, the fewer  
 places
 they offer for (say) law degrees, the higher fees they can charge for
 them. In my inexpert opinion, the cause of shortages of experts is  
 more
 the fault of the universities than of the professional bodies.

 So, just shy of 1 out of every 200 working-aged people in the USA were
   lawyers in 2000.

 I'm inclined to agree with the claim that law schools don't have the
 correct number of seats, but I think we might just differ on which way
 the adjustment should go :-)

snip

My professional body (The American Chemical Society, no, I'm not a  
professional programmer), takes the opinion that the more chemists  
there are in the world the better. It keeps labor costs down.

That's what happens when the professional bodies are controlled by  
large corporate interests. So, meanwhile, I sit at home and wait for  
the undersupply of scientists to correct itself. I have visions of  
starting my own manufacturing company, but it's hard to find capital.  
There are way too many dead and dying small companies around Michigan  
and way too many unemployed scientists and engineers, and lots of us  
have great ideas for companies.

Fortunately, this gives me plenty of time to learn Python and write  
code to simulate and optimize my manufacturing process!

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


error rising while connecting oracle 9i

2006-01-06 Thread python_eager
Hi
   i am connecting my database oracle 9i. While connecting i am 
getting the following error
 
connection = cx_Oracle.connect(myusername, mypassword, python)
RuntimeError: Unable to acquire Oracle environment handle
 
 
please send the solution
 
Thank you
regards
Python Eager




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


Re: Is 'everything' a refrence or isn't it?

2006-01-06 Thread bonono

Steven D'Aprano wrote:
 I'll tell you what I say: Python passes objects to functions or
 assignments.

Which in C sense, is a reference(or pointer) to some opaque table
maintain by the system, identified by id().

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


Re: Is 'everything' a refrence or isn't it?

2006-01-06 Thread Steven D'Aprano
On Fri, 06 Jan 2006 02:19:29 -0800, bonono wrote:

 
 Steven D'Aprano wrote:
 I'll tell you what I say: Python passes objects to functions or
 assignments.

 Which in C sense, is a reference(or pointer) to some opaque table
 maintain by the system, identified by id().

And that C sense is precisely why people try using C idioms in Python and
then are surprised that they don't behave as they would in C.

So how about we all agree to stop implying that Python behaves like C, and
try to teach people that Python behaves like Python?


-- 
Steven.

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


Re: How run web software *locally* easily?

2006-01-06 Thread dimitri pater
Check out this recipe using CherryPy ;-)http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442481CherryPy's server runs on localhost, also see my tutorial here:
www.serpia.org/cherrypybye,DimitriOn 5 Jan 2006 16:13:01 -0800, 
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
If grandma wanted to run some web application software (HTML files,CGI/Python scripts)*locally*, must she install a full blown Apache server with all thetrimmings??Is there some easy way to somehow perhaps embed a minimal web server in
a Python tar ballor some other clever trick to make grandma's life easier?Chris--http://mail.python.org/mailman/listinfo/python-list
-- All truth passes through three stages. First, it is ridiculed. Second, it is violently opposed. Third, it is accepted as being self-evident.
~Arthur Schopenhauer Please visit dimitri's website: www.serpia.org
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Is 'everything' a refrence or isn't it?

2006-01-06 Thread bonono

Steven D'Aprano wrote:
 On Fri, 06 Jan 2006 02:19:29 -0800, bonono wrote:

 
  Steven D'Aprano wrote:
  I'll tell you what I say: Python passes objects to functions or
  assignments.
 
  Which in C sense, is a reference(or pointer) to some opaque table
  maintain by the system, identified by id().

 And that C sense is precisely why people try using C idioms in Python and
 then are surprised that they don't behave as they would in C.

 So how about we all agree to stop implying that Python behaves like C, and
 try to teach people that Python behaves like Python?

No one implies Python behaves like C but just trying to explain as
close as possible to people speaking that language.

passed by object can just as easilly be interpreted as the function
received a seperate copy, with the caller's copy untouched.

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


Re: advice required re migrating php app to python and most likely zope

2006-01-06 Thread Ken Guest
On Thu, Jan 05, 2006 at 10:10:39PM +0100, Diez B. Roggisch wrote:
 Ken Guest schrieb:
  Hi,
  I've two relatively small web applications that are currently implemented in
  PHP and needed to be migrated to python and most likely zope afterwards as
  we're getting a third-party Zope powered CMS later this year.
  
  There isn't an immediate need for them to be developed as zope
  modules/extensions so I was wondering what the best approach might me -
  especially as they'd be deployed in the middle of a PHP driven website.
  
  Would I be best off to enable mod_python inside apache for the moment, 
  writing
  good modular reusable code that may|should need minimum tweaks for when our
  Zope CMS comes on-line or should I go the full way and design the web apps 
  for
  Zope from day zero?
 
 If you want ZOPE, the only way is to use it right from the start. There 
 is not much you can write as good modular reusable code, as ZOPE 
 imposes quite a few constraints on the way things _have_ to happen. That 
 isn't a bad thing! Its just that with ZOPE, you've got to grok what it 
 is about to use it, and much things are different from the simple 
 one-page-one-script-stuff you ususally come up with in PHP.
 

Well it'll be zope/plone to be more exact - good to know I should start off
with zope sooner rather than later, thanks Diez.

k.

-- 
Ken Guest
Mobile: +353 86 8252 141http://blogs.linux.ie/kenguest/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is 'everything' a refrence or isn't it?

2006-01-06 Thread bonono

Steven D'Aprano wrote:
 But in programming, things do work that way. If my class Book contains a
 reference to Smith's classic work, I can modify it. (Unless the language
 deliberately restricts my ability to modify certain objects, as Python
 does with immutable objects.)

 That's what programmers expect when you talk about references, especially
 if they come from a C (or Pascal) background. In Python, sometimes that's
 true, and sometimes it is not, and the only way to tell is by looking at
 the object itself, not by thinking about Python's high-level behaviour.

I believe one can restrict modification to pointer/reference parameter
passing to C function, so C programmer shouldn't have problem knowing
that reference doesn't not necessary mean you can modify it.

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


Re: Inheritance problem?

2006-01-06 Thread Simon Percivall
Don't use self.__class__, use the name of the class.

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


Re: Inheritance problem?

2006-01-06 Thread Pierre Barbier de Reuille
Well, I would even add : don't use super !
Just call the superclass method :

MyClass.__init__(self)



Simon Percivall a écrit :
 Don't use self.__class__, use the name of the class.
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Does Python allow access to some of the implementation details?

2006-01-06 Thread Claudio Grondi
Let's consider a test source code given at the very end of this posting.

The question is if Python allows somehow access to the bytes of the 
representation of a long integer or integer in computers memory?
Or does Python hide such implementation details that deep, that there is 
no way to get down to them?

The test code below shows, that extracting bits from an integer value n 
is faster when using n0x01 than when using n%2 and I suppose it is 
because %2 tries to handle the entire integer, where 0x01 processes 
only the last two bytes of it (I come to this because the speed 
difference between 0x01 and %2 operations depends on how large the 
value n is). If it were possible to 'tell' the %2 operation to operate 
only on one short of the integer number representation there will be 
probably no difference in speed. Is there a way to do this efficiently 
in Python like it is possible in C when using pointers and recasting?

As I am on Python 2.4.2 and Microsoft Windows, I am interested in 
details related to this Python version (to limit the scope of the 
question).

Claudio

Here the code:

import time

# i = 2**25964951 - 1
i = 123456789**123
lstBitsModulo = []
start = time.clock()
while i:
   i=i1
   lstBitsModulo.append(i%2)
speedModulo = time.clock()-start

# i = 2**25964951 - 1
i = 123456789**123
lstBitsBitwiseAnd = []
start = time.clock()
while i:
   i=i1
   lstBitsBitwiseAnd.append(i0x01)
speedBitwiseAnd = time.clock()-start

print
if lstBitsBitwiseAnd == lstBitsModulo :
   print 'BitwiseAnd = %f '%(speedBitwiseAnd,)
   print 'Modulo = %f '%(speedModulo,)

print # both lists are lists of long integer values
print lstBitsBitwiseAnd[0:3]
print lstBitsModulo[0:3]
-- 
http://mail.python.org/mailman/listinfo/python-list


PythonWin: logging module not showing messages from imported modules

2006-01-06 Thread rodrigostrauss
Having the following code:

 Module1.py 
import logging
def X():
  logging.error('test')

If I import it into PythonWin console and call X(), the error message
is not printed. If I do the same in Python console the message is
printed. Do I need to configure the logging module or it's a problem
with PythonWin?

If I call logging.error() in the PythonWin console it works like a
charm. The problem is just regarding imported modules.


Rodrigo Strauss

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


MVC programming with python (newbie) - please help

2006-01-06 Thread bwaha
I'd appreciate some experience from the gurus out there to help me
understand how to implement MVC design in python code.

Entry number 5 on the wxpython wiki at
http://wiki.wxpython.org/index.cgi/BuildingControls discusses MVC design in
building reusable controls. The author (Terrel Shumway) suggests that
instead of:

quote:

class MyCoolListControl(...):
def __init__(self,parent,id,choices):
...
def InsertItem(...):
def AppendItem(...):

where choices is a static list, do something like this

class ListDataModel:
 a minimal model interface to be used by MyCoolListControl 
def __len__(self):
 return the number of items in the list 
def __getitem__(self,index):
 return the specified item 

# consider notifications for observers (e.g. the list control)

# allow the user to define whatever mutators are appropriate


class MyCoolListControl(...):
def __init__(self,parent,id,model):
...
def [GS]etModel(self,model):
...

This allows the user (programmer) to store the data the way he thinks is
best, rather than having to copy the data into your structure whenever it
changes. It also reduces the need for kludges like [GS]etItemData for
maintaining association of the real data with its currently displayed string
representation.

endquote

The author refers to mvctree.py in wxPython as an example of MVC design.
However I'm still too green so I find that particular example too complex
and I'm not understanding the separation the author is recommending.

Can anyone explain to me further the simple example above and/or supply a
simple example of their own? At some level I feel like there's a benefit but
I'm failing to grasp it, and how to implement it. If I understand correctly
then in the future for example I could completely change how data is stored
in the class ListDataModel and not require a change in class
MyCoolListControl. Say, hypothetically, I wanted to implement ListDataModel
using a dictionary rather than, more naturally, a list, where the list
data structure is implemented as a dictionary and the list entries
correspond to dictionary keys (dictionary values are not used in this case).
Then if I understand the MVC concept, class MyCoolListControl need not
change at all. If that's true then that's really cool. But I don't get how
that works.

I think I need a little further expansion of the example or an alternative
(20-30 liner) that I can work through.

The question arises in the context of wanting to build a dialog with a tree
control that presents projects and studys as a tree and allows selection of
projects and studies as required by the user. I want to parse a file with
contents as follows:

BEGIN PROJECT mpi6_0
STUDY Cyc0302_0 cyc0302_beanoz_x1.sdy
STUDY Cyc0305_0 cyc0305_beanoz_x1.sdy
STUDY Cyc0308_0 cyc0308_beanoz_x1.sdy
STUDY Cyc0311_0 cyc0311_beanoz_x1.sdy
STUDY Cyc0314_0 cyc0314_beanoz_x1.sdy
END PROJECT
BEGIN PROJECT mpi6_1
STUDY Cyc0302_1 cyc0302_beanoz_x1.sdy
STUDY Cyc0305_1 cyc0305_beanoz_x1.sdy
STUDY Cyc0308_1 cyc0308_beanoz_x1.sdy
STUDY Cyc0311_1 cyc0311_beanoz_x1.sdy
STUDY Cyc0314_1 cyc0314_beanoz_x1.sdy
END PROJECT
...

I have wriiten a class as follows that extracts the data from the file.

import os

class ProjectFileDecoder:

parse project file to obtain project names and associated studies and
study files

def __init__(self, file):
self.projects = {}
self.parse_file(file)

def parse_file(self, file):
f = open(file, 'r')
dir = os.path.split(file)
while 1:
line = f.readline()
if 'BEGIN PROJECT' in line:
proj_name = line.strip().split('')[1]
self.projects[proj_name] = {}
elif 'STUDY' in line:
study_name = (line.strip().split(''))[1].strip()
study_file = dir[0] + '/' +
(line.strip().split(''))[2].strip()
self.projects[proj_name][study_name] = study_file
elif not len(line):
f.close()
break

def getProjectNames(self):
return self.projects.keys()

def getStudyNames(self):
return [self.projects[i].keys() for i in self.getProjectNames()]

def getStudyFiles(self):
return [self.projects[i].values() for i in self.getProjectNames()]

At some level this seems to me like the class ListDataModel above. I just
need to make a MyTreeControl class. However here GS(et) routines are
implemented in the ProjectFileDecoder class (data model?)  whereas in the
earlier advice they are in class MyCoolListControl. So I'm not understanding
how data gets from the DataModel class to the ListControl class. After all
the words I've said,  I think that's the core misunderstanding I have.

Hope someone can help clear that up for me.

Chris






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


Python based Compiler tools

2006-01-06 Thread Doru-Catalin Togea
Hi!

I have some experience with PLY. What other alternatives are there, and 
which is the best (that is most feature rich, easiest to use, ...)?

Thanks,
Catalin

-- 

  == 
  We are what we repeatedly do.  
   Excellence, therefore, is not an act  
  but a habit.   
  == 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python allow access to some of the implementation details?

2006-01-06 Thread Diez B. Roggisch
 The test code below shows, that extracting bits from an integer value n
 is faster when using n0x01 than when using n%2 and I suppose it is
 because %2 tries to handle the entire integer, where 0x01 processes
 only the last two bytes of it (I come to this because the speed
 difference between 0x01 and %2 operations depends on how large the
 value n is)

I doubt that the reason is in  handling less data. The reason is that % is
effectively a division, whereas  is a logical operation. Which have always
been _way_ faster than divisions.

Of course you are right that the bitfiddling _could_ be optimized when one
knows that only certain bytes of a number would be of interest. But I
seriously doubt that python does any optimization here. However, I don't
know for sure.

Regards,

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


ANN: Leo 4.4a5 released

2006-01-06 Thread Edward K. Ream
Leo 4.4 alpha 5 is now available at:

http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106

This release completes the last major features of Leo 4.4:

- User-specified key-binding modes.

- Support for multiple key-bindings for individual minibuffer commands.

This will be the last alpha version of Leo 4.4. Beta 1 is coming in about a 
week. You should be able to use this version safely; there are no known 
serious bugs.

To learn about Leo, see: http://webpages.charter.net/edreamleo/intro.html

The highlights of Leo 4.4:
--
- An Emacs-like mini-buffer: you can now execute any command by typing its 
long name. Support for tab completion.

- A tabbed log pane. The Find and Spell Check commands now use tabs instead 
of dialogs, making those commands much easier to use. Plugins or scripts can 
easily create new tabs. The Completion tab shows possible typing 
completions.

- Support for most commands in the Emacs Cmds menu, including cursor and 
screen movement, basic character, word and paragraph manipulation, and 
commands to manipulate buffers, the kill ring, regions and rectangles.

- Per-pane key bindings. You can bind shortcuts to multiple commands 
depending on which of Leo's panes presently has focus. For example, you can 
use arrow keys to move nodes in the outline pane, while retaining their 
defaults in Leo's body pane.

- User-specified key-binding modes. This feature makes it possible to 
emulate all aspects of Emacs and Vim as far as key bindings are concerned.

- Leo recovers from crashes much more reliably than in any previous version.

- @command nodes create minibuffer commands. You can bind key shortcuts to 
@button and @command nodes.

- Leo handles key events and updates the screen immediately rather than 
queuing them for idle time.

- Leo updates the screen immediately rather than waiting for idle time. This 
improves response.

Links:
--
Leo:  http://webpages.charter.net/edreamleo/front.html
Home: http://sourceforge.net/projects/leo/
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
CVS:  http://sourceforge.net/cvs/?group_id=3458
Quotes:   http://webpages.charter.net/edreamleo/testimonials.html

Edward K. Ream
January 6, 2006

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html



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


[FW] Microsoft embraces open-source scripting language

2006-01-06 Thread Man-wai Chang


 Original Message 
Subject: [NF] Microsoft embraces open-source scripting language
Date: Thu, 05 Jan 2006 15:37:47 -0500
From: MB Software Solutions [EMAIL PROTECTED]
Reply-To: [EMAIL PROTECTED]
Organization: MB Software Solutions, LLC
To: [EMAIL PROTECTED]

http://news.zdnet.com/2100-3513_22-6017630.html?tag=nl.e539

-- 
  .~.Might, Courage, Vision. SINCERITY. http://www.linux-sxs.org
 / v \
/( _ )\  (Ubuntu 5.10)  Linux 2.6.14.4
  ^ ^22:37:01 up 13 days 11:34 load average: 0.08 0.10 0.08
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: [FW] Microsoft embraces open-source scripting language

2006-01-06 Thread Man-wai Chang
http://dabodev.com/


-- 
   .~.Might, Courage, Vision. SINCERITY. http://www.linux-sxs.org
  / v \
/( _ )\  (Ubuntu 5.10)  Linux 2.6.14.4
   ^ ^22:38:01 up 13 days 11:35 load average: 0.10 0.09 0.08
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk
-- 
http://mail.python.org/mailman/listinfo/python-list


Fredericksburg, VA ZPUG Meeting: January 11, 7:30-9:00 PM

2006-01-06 Thread Benji York
Please join us January 11, 7:30-9:00 PM, for the seventh meeting of
the Fredericksburg, VA Zope and Python User Group (ZPUG). Squid and
Zope! Python and Zope roundtable! Free food!

 * Andrew Sawyers will discuss using the open source cache server
Squid with Zope, including a discussion of the O'Reilly book about
Squid (this talk was moved from our November meeting).

 * We will have a Python and Zope roundtable for questions and
ideas about Zope or Python.  Have a question you want to ask a Zope
core developer or a Python core developer or a community Zope or
Python user?  Come by!

 * We will serve delicious food and soft drinks.

We've had a nice group for all the meetings. Please come and bring
friends!

We also are now members of the O'Reilly and Apress user group
programs, which gives us nice book discounts (prices better than
Amazon's, for instance) and the possibility of free review copies.
Ask me about details at the meeting if you are interested.


General ZPUG information

When: second Wednesday of every month, 7:30-9:00.

Where: Zope Corporation offices. 513 Prince Edward Street;
Fredericksburg, VA 22408 (tinyurl for map is http://tinyurl.com/duoab).

Parking: Zope Corporation parking lot; entrance on Prince Edward Street.

Topics: As desired (and offered) by participants, within the
constraints of having to do with Python or Zope.

Contact: Gary Poster ([EMAIL PROTECTED])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Try Python update

2006-01-06 Thread Xavier Morel
Mike Meyer wrote:
 After spending time I should have been sleeping working on it, the try
 python site is much more functional. It now allows statements,
 including multi-line statements and expressions. You can't create code
 objects yet, so it's still more a programmable calculator than
 anything real.
 
 I've got some of the tutorial text (literally) up as well. I hope to
 make it easier to read the tutorial and interact with python at the
 same time in the near future.
 
 The url is http://www.mired.org/home/mwm/try_python/. Reports of
 problems would appreciated.
 
 If you want to try an online P{ython tool that lets you save code, try
 Devan L's at http://www.datamech.com/devan/trypython/trypython.py.
 
   mike

Mike, may I ask whether that box has been secured? And if yes how?

Since Python doesn't have any way to secure the interface built-in, i'd 
be interrested in that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] - Requesting Comments for Process Definition and Presentation

2006-01-06 Thread Xavier Morel
Ilias Lazaridis wrote:
 b) to retrieve feedback subjecting the Process Definition itself 
 (content of diagramms, clarity, terminology etc.)
 
This is a lie, and you know it.

You are merely some kind of strange troll. You've built something that 
you consider the only object model worth using within your mind and 
proceed to try bashing OO languages such as Py or Ruby because they 
don't fit your own object model and terminology.

No one in either c.l.p or c.l.r need you, no one wants your object 
model, no one wants your so-called evaluations (especially about the 
community leaders, your various comments about both Guido van Rossum and 
Yukihiro Matz Matsumoto are insulting and disrespectful), please do 
everyone a favor: create your damn own language, or head over to 
comp.lang.lisp and implement your object model in this language, Lisp is 
a meta-language and _nothing_ stops you from heading over and creating a 
new object model from scratch (that's been done countless times anyway, 
and the CLOS probably wouldn't fit your personal object model, so go ahead).

The fact is that you don't live in reality, you generate more buzzwords 
and empty acronyms than a well-trained marketroid, but guess what? that 
doesn't matter, unless you can prove that what you advocate _works_.

And you can't.

Both Ruby's object model and Py's object models work. They have flaws, 
they evolve, they grow and change, but they work, they are used in real 
world situations and they fit the needs of their respective communities. 
Ilias Lazaridis Majic Object Model doesn't. Period.

Just stop posting altogether, implement your damn blasted object model 
(or try to) in an existing language or create a new language to 
implement it and just leave us.


And stop spamming your damn worthless website too. Thank you very much.

 I can't see anything at this site what would make sense to me.
 
 you mean, you don't understand _anything_?
 
No, he means that your website just doesn't make sense. There is no 
purpose, no consistency, no way to understand what the website is 
supposed to hold, no way to find *informations* (and your colorful 
graphs with an informative level of somewhere below 0 do not count as 
information BTW).

I'll add that the color/style schemes are awfully misleading (why the 
hell are random words in bold-ocre, please go read a few books on 
interfaces and websites creation because you obviously don't have a clue 
there, Steve Krug's Don't Make Me Think would be a much required 
start), that the various categories are unclear, fuzzy and *never 
explained anywhere* and that you claiming that you can *review websites* 
(for a fee on top of that) is insulting to people with actual skills in 
the field.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or Java or maybe PHP?

2006-01-06 Thread Xavier Morel
Mike Meyer wrote:
 That doesn't sounds like hates to me. More like doesn't like the
 baggage.
 
 mike

Yet anonymous functions are nice.

Wouldn't it be possible to change the `def` statement to return a 
reference to the function, and allow omitting the function name thereby 
bypassing the default binding (current behavior)?

Something along the lines of

  # Current behavior
  def foo(*args, **kwargs):
pass
  print foo
function foo at 0x00FA37B0

  # Extended behavior
  # returns a reference to the function
  def foo(*args, **kwargs):
pass
function at 0x00FA37B0
 
  # Anonymous functions
  def (*args, **kwargs):
pass
function at 0x00FA3830
  foo = def(*args, **kwargs): pass


Note that the function wouldn't have it's own name anymore (no more 
__name__ attribute? Or a blank one?)

Since functions can already be defined inline, the only thing that'd be 
left would be to end the function's definition when the wrapper 
structure ends:

  doSomething(def (*args, **kwargs): pass, arg) # End of the function 
definition at the end of it's argument
  doSomethingElse(def (*args, **kwargs):
... # Multiline
... pass
...)

I'm not too sure about the multi line version (and it looks very ugly 
with a non-monospaced font), but:

Pros (I think):
 * Backwards-compatible (I think, since the new uses of `def` are 
currently errors)
 * Fairly obvious syntax
 * No `lambda` or `macros` baggage, the new form of def would merely 
define an anonymous function instead of a named one.
 * No new keyword, or structure, or idiom
 * Existing idioms are merely slightly extended without changing 
their current meaning

Cons:
 * May reduce readability when misused, and may be used in Very 
Stupid Ways that reduce readability a lot (but then again most construct 
may be abused in some way), e.g.:

 doSomething(arg1, arg2, arg3, def foo(a): manipulate(a)) # 
binds a function to `foo` _and_ sends it to `doSomething`
 ...
 [a few lines of code]
 ...
 foo(value) # where the hell did that foo come from?

 * Replaces lambdas with something much more powerful, which may go 
against the goal of getting rid of lambdas (unless the aforementioned 
goal is mostly because of the historical baggage of lambdas/macros)

Unsure:
 * Shows that Python is the Ultimate Language, people are not ready yet.
 * May allow for blocks-like constructs (I'm not sure of the current 
state of the closures over Python functions though, these may have to be 
extended to full closures if they aren't) and be considered by some as 
yielding to the hype (even though the structure itself is more or less 
35 years old)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: One-step multiples list generation?

2006-01-06 Thread Xavier Morel
Damien Wyart wrote:
 Thanks for these important and useful additions, they are very welcome !
 
 In writing my answer I had immutables in mind, but mutables are a bit
 more dangerous, here...
 

Not *that* much though.

The first construct can't be used, but he can use

  [copy.copy(Foo) for _ in range(20)]

And he should be ok.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Translate this to python?

2006-01-06 Thread Xavier Morel
[EMAIL PROTECTED] wrote:
 For some reason, ocassionally when  I see xrange, I think But wasn't
 that deprecated  since range is now a . . oh wait that's xreadlines.
 xrange is a  cool thing the few times where you really need it.
 
 john
 
 Not sure what i is really for, but j seems to be independent,
 so perhaps (also untested, and caveat: it's past bedtime)

 i = nPoints - 1
 for j in xrange(nPoints):
 # whatever
 i = j

 Regards,
 Bengt Richter
 
I think that xrange is also soon-to-be deprecated (xrange eats a little 
less memory and is slightly faster to _create_, but much slower to 
_iterate over_ than range)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inheritance problem?

2006-01-06 Thread Xavier Morel
Pierre Barbier de Reuille wrote:
 Well, I would even add : don't use super !
 Just call the superclass method :
 
 MyClass.__init__(self)
 
 
 
 Simon Percivall a écrit :
 Don't use self.__class__, use the name of the class.

Bad idea if you're using new-style classes with a complex inheritance 
hierarchy and multiple inheritance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [FW] Microsoft embraces open-source scripting language

2006-01-06 Thread Man-wai Chang
Sorry, left out 2 links:

IronPython 1.0 Beta 1
http://dw.com.com/redir?destUrl=http%3A%2F%2Fwww.microsoft.com%2Fdownloads%2Fdetails.aspx%3FFamilyID%3D94082D26-E689-4F7F-859B-FEC6DACF3AE8%26displaylang%3DensiteId=22oId=2100-3513-6017630ontId=3513lop=nl.ex,
which was released at the end of last week, is well integrated with
the rest of the .Net programming framework and allows all .Net libraries
to be easily accessed by Python programmers, according to Microsoft.

Microsoft's support for Python could help the software giant attract
Unix developers to the Windows platform, as it is a commonly used
scripting language on the Unix platform, according to Salim Fadhley
http://dw.com.com/redir?destUrl=http%3A%2F%2Fnews.zdnet.co.uk%2Fbusiness%2Flegal%2F0%2C39020651%2C39230999%2C00.htmsiteId=22oId=2100-3513-6017630ontId=3513lop=nl.ex,
who develops Python programs for Unix.

-- 
   .~.Might, Courage, Vision. SINCERITY. http://www.linux-sxs.org
  / v \
/( _ )\  (Ubuntu 5.10)  Linux 2.6.14.4
   ^ ^23:12:01 up 13 days 12:09 load average: 0.04 0.03 0.03
news://news.3home.net news://news.hkpcug.org news://news.newsgroup.com.hk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: inline function call

2006-01-06 Thread Xavier Morel
Peter Hansen wrote:
 Riko, any chance you could post the final code and a bit more detail on 
 exactly how much Psyco contributed to the speedup?  The former would be 
 educational for all of us, while I'm personally very curious about the 
 latter because my limited attempts to use Psyco in the past have 
 resulted in speedups on the order of only 20% or so.  (I blame my 
 particular application, not Psyco per se, but I'd be happy to see a 
 real-world case where Psyco gave a much bigger boost.)
 
 Thanks,
 -Peter
 

Someone I know created an application to compute Markus Lyapunov 
fractals (aka heavy mathematical computations) (he pretty much did it to 
learn Python).

Last time I checked, his code ran in roughly 3 minutes (179s) on my box 
(Athlon64/3000+) without psyco and 46 seconds with psyco enabled under 
Windows 2000.

Someone else got respectively 2mn34s and 13s (without and with psyco) on 
a Linux box with an Athlon XP 2600+ (same frequency as my 3200+ btw, 2GHz).

My tests show a 74% speedup, and the Linux test shows a 91% speedup.

In any case, the gain is significant because the actual code is very 
short (less than 200 lines, and the algorithm itself fits in under 50 
lines) and is called very often (from my notes, the main function is 
called 16 times during the computation of the fractal)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: - E04 - Leadership! Google, Guido van Rossum, PSF

2006-01-06 Thread Xavier Morel
Ilias Lazaridis wrote:
 I estimate that there is a unfreeze operation, too - which would lead 
 to flexibity.
 
There is none, you have to make a copy of the object via the dup 
(duplicate) method to get an unfrozen copy (note: clone yields an exact 
copy, which means that it's still frozen).

Unfreezing an object is forbidden in Ruby.

Alex Martelli wrote:
  At the other extreme, Ruby's very productive choice is to
  allow freeze and unfreeze of everything (I believe -- but you should
  double check with a Ruby expert)
I'm no ruby expert, but I'm pretty sure there is no way to unfreeze a 
frozen ruby object, you *have* to create a molten copy with the dup 
method.

Ilias Lazaridis wrote:
  Alex Martelli wrote:
  Ilias Lazaridis [EMAIL PROTECTED] wrote:
  [...] - google stuff
 
  http://lazaridis.com/case/lang/python.html#simple_variable_access
 
  this leads to a new limitation:
 
  #LIMITATION: large amount of repetitive code
  One normally does not define large numbers of identical accessors (there
  [...] - (extensive elaboration)
 
  possibly one can provide the code for something similar to the ruby
  attr_accessor:
 
  class Talker
 def sayHello
   puts Hello world
 end
 
 attr_accessor :name, :age
 
  end
 
  thus they can later be accessed this way
 
  john.age = 19
 
  print john.age
 
There is no point, these exist because a ruby attribute can *never* be 
accessed from outside the object, a Ruby attribute is always private 
while a Python attribute is always public. This means that you *have to* 
declare properties to have the ability to access an attribute of a Ruby 
object, which lead to attr_accessor, attr_reader and attr_writer as 
shortcut-declarations of basic properties.

The Pythonic equivalent of Ruby's attr_accessor is merely to do nothing, 
because what the attr_accessor does is:

attr_accessor :something
generates
def something
@something
end
def something= value
@something = value
end

but not doing it would prevent any access to the something attribute.
(attr_reader only declares the getter method, making the attribute 
read-only, and attr_writer only defines the setter, making the attribute 
write-only)

One thing that is very important is that in Ruby you *never* deal with 
member attributes from outside the object, only methods (messages to the 
object).
In Python, you deal either with methods (messages) or attributes 
(datas), but these attributes can be either real attributes (real 
unchecked data) or properties, e.g. virtual attributes (that may 
generate side-effects, sanity check on the data, or _may not map to any 
existing unique data in the object_) and unless you really try to, you 
don't have any way to distinguish a real attribute from a property 
(virtual attribute), and you don't care.

 
  thus if I make a typo, I create a new attribute?
 
Why yes of course, what were you expecting?
-- 
http://mail.python.org/mailman/listinfo/python-list


Spelling mistakes!

2006-01-06 Thread KraftDiner
I've spent hours trying to find a bug that was a simple spelling
mistake.

in an init method I declare a variable  self.someLongName

later in a different method of the class I use
self.sumLongName
Now I really meant self.someLongName.
In fact I don't want a variable called sumLongName.
Frankly how are you ever to know if this type of error is occuring?

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


Re: Spelling mistakes!

2006-01-06 Thread Heiko Wundram
KraftDiner wrote:
 Frankly how are you ever to know if this type of error is occuring?

By the traceback:

[EMAIL PROTECTED] ~ $ python
Python 2.4.2 (#1, Dec 22 2005, 17:27:39)
[GCC 4.0.2 (Gentoo 4.0.2-r2, pie-8.7.8)] on linux2
Type help, copyright, credits or license for more information.
 class x(object):
...   def __init__(self):
... self.somename = hello
...   def somemethod(self):
... print self.sumname
...
 a = x()
 a.somemethod()
Traceback (most recent call last):
  File stdin, line 1, in ?
  File stdin, line 5, in somemethod
AttributeError: 'x' object has no attribute 'sumname'


AttributeError describes just this. And please don't start the war on how
much better compiled languages are because they catch this kind of error at
compile time. They simply are not.

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


Re: Spelling mistakes!

2006-01-06 Thread Fuzzyman
VBScript allows you to specify that variable names be declared. I used
to think this was good - until I realised that Python allows you to
dynamically assign attributes in namespaces using all sorts of tricks.

(Setattr, using __dict__ etc).

It's just not possible with Python. Rarely happens to me in practise
and is easy to fix.

All the best,

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

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


Re: Spelling mistakes!

2006-01-06 Thread KraftDiner
try this:

class x(object):
   def __init__(self):
  self.someName = hello
   def someMethod(self):
  self.sumName = bye

find that bug.

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


Re: Translate this to python?

2006-01-06 Thread Heiko Wundram
Xavier Morel wrote:
 I think that xrange is also soon-to-be deprecated (xrange eats a little
 less memory and is slightly faster to _create_, but much slower to
 _iterate over_ than range)

It might be slower to iterate using xrange, but xrange certainly has its
place in Python... Try the following on your computer:

for x in range(10**10):
print x

for x in xrange(10**10):
print x

Tell me which one doesn't overflow your memory. ;-) And before you come
telling me that these constraints are articial, I've _written_ programs
that had to iterate over 2**24 (the set of 10.* IP addresses), and I most
certainly wouldn't have wanted the machines to contain 384+ MB of RAM just
to store the number objects that range creates.

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


Re: Python or Java or maybe PHP?

2006-01-06 Thread Alex Martelli
Xavier Morel [EMAIL PROTECTED] wrote:
   ...
 Wouldn't it be possible to change the `def` statement to return a 
 reference to the function, and allow omitting the function name thereby
 bypassing the default binding (current behavior)?

It's _possible_ (doesn't  introduce syntax ambiguities) though it does
introduce incompatible interactive-interpreter behavior, as you say:

   # Extended behavior
   # returns a reference to the function
   def foo(*args, **kwargs):
   pass
 function at 0x00FA37B0

This could be avoided if 'def nameetc' remained a statement like
today, and a separate expression 'defetc' returned a function object
as a result; this would have the aded plus of avoiding the totally new
(to Python) idea of statement returning a value (_expressions_ return
a value).

 Note that the function wouldn't have it's own name anymore (no more
 __name__ attribute? Or a blank one?)

Currently, a lambda has a __name__ of 'lambda'; I'd assume a similar
arrangement if 'expression def' took lambda's place.


 I'm not too sure about the multi line version (and it looks very ugly

Yeah, the multiline's the rub -- there's currently no multiline
expression, and it does look ugly.


  * May allow for blocks-like constructs (I'm not sure of the current
 state of the closures over Python functions though, these may have to be
 extended to full closures if they aren't) and be considered by some as

Python's closures are 'full', but don't allow inner functions to rebind
names in the namespace of outer functions.

I'm not sure a PEP like this has ever been proposed, but the idea of
anonymous def is not new (bar some details of your proposal): if a PEP
doesn't exist, you could write one, at least to firm up all details.


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


Re: Spelling mistakes!

2006-01-06 Thread Xavier Morel
KraftDiner wrote:
 I've spent hours trying to find a bug that was a simple spelling
 mistake.
 
 in an init method I declare a variable  self.someLongName
 
 later in a different method of the class I use
 self.sumLongName
 Now I really meant self.someLongName.
 In fact I don't want a variable called sumLongName.
 Frankly how are you ever to know if this type of error is occuring?
 

PyChecker and PyLint sound like the perfect remedy to this issue (I know 
one of them is able to warn you if you *create* an attribute outside of 
__init__, maybe both are but at least one of them is)

I just run them when I save my files, they don't take long and even 
though the default configuration is *extremely* annoying (especially 
PyLint's, it generates heaps of warnings) once configured to one's need, 
they're extremely valuable for both personal and team development.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python allow access to some of the implementation details?

2006-01-06 Thread casevh
I don't know of a way to directly access the internal structure of a
long, but you can speed up your example.

First, is the order of the commands

   i=i1
   lstBitsBitwiseAnd.append(i0x01)

what you intend? The first low order bit is discarded because you've
done the shift first. And an extra 0 is appended.

If you are trying to get the binary representation of a long, try
i.__hex__(). This will create a string with the hex representation.
Conversion from hex to binary is left as an exercise for the reader. :-)

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


Re: Spelling mistakes!

2006-01-06 Thread Jean-Paul Calderone
On 6 Jan 2006 07:57:04 -0800, KraftDiner [EMAIL PROTECTED] wrote:
try this:

class x(object):
   def __init__(self):
  self.someName = hello
   def someMethod(self):
  self.sumName = bye

find that bug.


[EMAIL PROTECTED]:~$ cat  xobj.py
class x(object):
def __init__(self):
self.someName = hello
def someMethod(self):
self.sumName = bye
[EMAIL PROTECTED]:~$ cat  test_xobj.py
from twisted.trial import unittest

import xobj

class XObjTestCase(unittest.TestCase):
def testSomeName(self):
x = xobj.x()
self.assertEquals(x.someName, hello)
x.someMethod()
self.assertEquals(x.someName, bye)
[EMAIL PROTECTED]:~$ trial test_xobj.py 
Running 1 tests.
test_xobj
  XObjTestCase
testSomeName ...   [FAIL]

=
[FAIL]: test_xobj.XObjTestCase.testSomeName

  File /home/exarkun/test_xobj.py, line 10, in testSomeName
self.assertEquals(x.someName, bye)
twisted.trial.unittest.FailTest: 'hello' != 'bye'
-
Ran 1 tests in 0.278s

FAILED (failures=1)
[EMAIL PROTECTED]:~$ 

Hope this helps,

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


Re: Spelling mistakes!

2006-01-06 Thread André
KraftDiner wrote:
 try this:

 class x(object):
def __init__(self):
   self.someName = hello
def someMethod(self):
   self.sumName = bye

 find that bug.

Write a test for each method before writing the method.

Write the code once; read it critically (at least) twice.

If you find that too difficult, use a different programming language
(one in which you have to declare every variable) and become less
productive.

A.

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


Re: Spelling mistakes!

2006-01-06 Thread Peter Hansen
KraftDiner wrote:
 try this:
 
 class x(object):
def __init__(self):
   self.someName = hello
def someMethod(self):
   self.sumName = bye
 
 find that bug.

You forgot to include unit tests for someMethod().  Those would have 
caught the bug.

The reality is that if you aren't doing unit testing, you aren't 
catching other bugs either, bugs which aren't caught by the compile-time 
tests in other languages and which aren't caught by PyChecker or PyLint 
either.  Bugs which are probably much more common than typos like the 
above, too.

Still, if you are really bothered by these things frequently, I believe 
recipes have been posted in the past which *do* allow you to avoid many 
such problems, by declaring the acceptable attribute names somewhere and 
using one of Python's many hooks to intercept and check attribute 
setting.  Check the archives or the CookBook.

-Peter

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


Re: Translate this to python?

2006-01-06 Thread Xavier Morel
Heiko Wundram wrote:
 Xavier Morel wrote:
 I think that xrange is also soon-to-be deprecated (xrange eats a little
 less memory and is slightly faster to _create_, but much slower to
 _iterate over_ than range)
 
 It might be slower to iterate using xrange, but xrange certainly has its
 place in Python... Try the following on your computer:
 
 for x in range(10**10):
 print x
 
 for x in xrange(10**10):
 print x
 
 Tell me which one doesn't overflow your memory. ;-) And before you come
 telling me that these constraints are articial, I've _written_ programs
 that had to iterate over 2**24 (the set of 10.* IP addresses), and I most
 certainly wouldn't have wanted the machines to contain 384+ MB of RAM just
 to store the number objects that range creates.
 
 --- Heiko.

While xrange does have it's place in Python, it has very few actual uses 
(yours being one of the few), and is usually more harmful than beneficial.

While the deprecation of xrange is not that soon, it is part of the 
Python 3000 PEP (http://www.python.org/peps/pep-3000.html#id38) along 
with the deprecation of most FP-facilities of Python (filter, map, reduce).

It should also be noted that reimplementing xrange when needed is 
trivial and can be done with a 5-lines generator for the minimal version 
(1 argument, 0-n range) and probably less than 10 lines for the full 
blown version equivalent to the current one (including start, end and 
step arguments)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or Java or maybe PHP?

2006-01-06 Thread Xavier Morel
Alex Martelli wrote:
 Xavier Morel [EMAIL PROTECTED] wrote:
...
 Wouldn't it be possible to change the `def` statement to return a 
 reference to the function, and allow omitting the function name thereby
 bypassing the default binding (current behavior)?
 
 It's _possible_ (doesn't  introduce syntax ambiguities) though it does
 introduce incompatible interactive-interpreter behavior, as you say:
 
   # Extended behavior
   # returns a reference to the function
   def foo(*args, **kwargs):
   pass
 function at 0x00FA37B0
 
 This could be avoided if 'def nameetc' remained a statement like
 today, and a separate expression 'defetc' returned a function object
 as a result; this would have the aded plus of avoiding the totally new
 (to Python) idea of statement returning a value (_expressions_ return
 a value).
 
True that, I didn't even consider the possibility to create an 
independent expression.

And it completely remove the possibility to generate the first con.

  * May allow for blocks-like constructs (I'm not sure of the current
 state of the closures over Python functions though, these may have to be
 extended to full closures if they aren't) and be considered by some as
 
 Python's closures are 'full', but don't allow inner functions to rebind
 names in the namespace of outer functions.
 
 I'm not sure a PEP like this has ever been proposed, but the idea of
 anonymous def is not new (bar some details of your proposal): if a PEP
 doesn't exist, you could write one, at least to firm up all details.
 
 
 Alex
Or maybe start by creating a thread on the subject of an anonymous def 
expression on this list first?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inheritance problem?

2006-01-06 Thread Pierre Barbier de Reuille
Xavier Morel a écrit :
 Pierre Barbier de Reuille wrote:
 
 Well, I would even add : don't use super !
 Just call the superclass method :

 MyClass.__init__(self)



 Simon Percivall a écrit :

 Don't use self.__class__, use the name of the class.

 Bad idea if you're using new-style classes with a complex inheritance
 hierarchy and multiple inheritance.

As a reference :

http://fuhm.org/super-harmful/

I may say this is the only place I ever saw what super *really* is
for. The behavior is far too complex and misthought. All I can say is :
don't use it ! It solves *nothing* and creates too many bugs in the long
run.
-- 
http://mail.python.org/mailman/listinfo/python-list


Copy an Object (Again?)

2006-01-06 Thread KraftDiner
I'm having trouble getting a copy of and object... (a deep copy)

I'm writing a method that creates a mirror image of an object (on
screen)
In order to do this i need to get a copy of the object and then modify
some
of its attributes.

I tried:
objs = myListOfObjects
for obj in objs:
   if obj.flag:
  newObject = copy.deepcopy(obj)
  newObject.mirror()
  myListOfObjects.append(newObject)

That doesn't seem to work.. the new object seems to disapear from
existance.
I'm wondering if its a bug in my application or if this is my shallow
understanding of the language.

TIA
B.

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


Re: Inheritance problem?

2006-01-06 Thread Xavier Morel
Pierre Barbier de Reuille wrote:
 Xavier Morel a écrit :
 Pierre Barbier de Reuille wrote:

 Well, I would even add : don't use super !
 Just call the superclass method :

 MyClass.__init__(self)



 Simon Percivall a écrit :

 Don't use self.__class__, use the name of the class.

 Bad idea if you're using new-style classes with a complex inheritance
 hierarchy and multiple inheritance.
 
 As a reference :
 
 http://fuhm.org/super-harmful/
 
 I may say this is the only place I ever saw what super *really* is
 for. The behavior is far too complex and misthought. All I can say is :
 don't use it ! It solves *nothing* and creates too many bugs in the long
 run.

My own encounter with the subject was Guido's Unifying types and 
classes in Python 2.2 (http://www.python.org/2.2.3/descrintro.html#mro 
for the part on super itself), but I'll keep your link close by.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is 'everything' a refrence or isn't it?

2006-01-06 Thread Mike Meyer
Ernst Noch [EMAIL PROTECTED] writes:
 Maybe next time showing something like the following trivial snippet
 might help demonstrate that the core of the matter doesn't is not the
 way python treats parameters?

Did you insert an extra doesn't in that? If so, then I agree about
what isn't the core of the matter.

On the other hand, the snippet doesn't help without an
explanation. Especially with misleading comments.

 def func(param, what):
   if what:
   param['foo'] = 'changed'
   else:
   temp = param['foo'] # temp is _not_ a reference!

Except temp *is* a reference. What it's not is a reference to
param['foo']. Instead, it's a reference to the same object that
param['foo'] is a reference to.

   temp = 'changed'

mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pdb.py - why is this debugger different from all other debuggers?

2006-01-06 Thread Mike Meyer
[EMAIL PROTECTED] (R. Bernstein) writes:
 Mike Meyer [EMAIL PROTECTED] writes:
 I don't use pdb a lot either - and I write a *lot* of Python. 
 Some of us may have to *read* a lot of python. (For example I know
 many people including myself who have had to deal with code written by
 consultants who wrote a *lot* of code but are no longer *maintaining*
 the code for various reasons). And one place debuggers tend to come in
 handy is in focused or problem-solving of others' code.

I also read a lot of Python. Cleaning up that which was created by
others is a common role for consultants.

 If not, rather than load the application into a debugger
 and futz with that, it's simpler to fire up the interpreter, import
 the module that is misbehaving, instantiate and experiment on the
 classes with bogus behavior. 
 If you have a good understanding of the code that may be a good thing.
 If you don't and debugging is easy (and I think someone else had
 suggested python may be in some circumstances lacking here), then
 debugging is desireable. I've noticed that different people pefer
 different things. And that's why there's race-track betting.

In my experience, a good way to gain an understanding of the code is
to play with it in the interpreter. Being able to feed arbitrary
things to methods and observe the results is invaluable. Being able to
step through the code line at a time also helps, and it's a good thing
that Python lets you do both. But if I had to choose between being
able to play with objects interactively or being able to step through
code, I'll take the interactive interpreter every time.

 If you write code that consists of
 reasonably small methods/functions, these tools work *very* well for
 chasing down bugs. 
 It would be simple-minded to assert that everyone who writes python
 code works uses your tools or writes code as easy to understand as you
 imply your code is.

Well, the tools I'm talking about here are ones that Python comes
with. It may be simple-minded to assert that everyone who writes
Python code uses the tools that come with Python, but it's not very
bright to not use the tools that come with the language.

I'm all to aware that not everyone writes code as easy to understand
as what I do. The correct solution for bad code was elucidated by
Kernighan and Plauger nearly 30 years ago: Don't fix bad
code. Rewrite it. I don't do that nearly often enough.

 Given those two tools, I find I use pdb maybe once a year. I probably
 wouldn't miss it if it vanished. 
 I guess you are in agreement with many POSIX shell (e.g bash, Bourne
 and Korn) developers.  You see, before I wrote a debugger for bash
 (http://bashdb.sourceforge.net) there just weren't any such
 things. :-) And those languages are very very old maybe 20 years or
 so.

A good debugger is a valuable thing, and I've used some incredible
debuggers, including one that actually implemented DWIM.  Stepping
through the code is one of the least valuable thing a debugger does,
but it's also the thing that makes it a debugger. Pretty much
everything else that a debugger does can be done by other tools. As
those tools improve, the value of the debugger decreases. Python has
very good other tools.


 mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is 'everything' a refrence or isn't it?

2006-01-06 Thread Ernst Noch
Mike Meyer wrote:
 Ernst Noch [EMAIL PROTECTED] writes:
 
Maybe next time showing something like the following trivial snippet
might help demonstrate that the core of the matter doesn't is not the
way python treats parameters?
 
 
 Did you insert an extra doesn't in that? If so, then I agree about
 what isn't the core of the matter.

Uhm, yes. Seems the whole message was written too hastily.

 
 On the other hand, the snippet doesn't help without an
 explanation. Especially with misleading comments.

Absolutely, it was mainly meant as an example to demonstrate in practice 
that the way python passes parameters has nothing to do with what happens.

 
 
def func(param, what):

  if what:
  param['foo'] = 'changed'
  else:
  temp = param['foo'] # temp is _not_ a reference!
 
 
 Except temp *is* a reference. What it's not is a reference to
 param['foo']. Instead, it's a reference to the same object that
 param['foo'] is a reference to.
 

Oh dear, yes. I inserted that comment as an afterthought.




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


Re: Inheritance problem?

2006-01-06 Thread Mike Meyer
Xavier Morel [EMAIL PROTECTED] writes:
 Pierre Barbier de Reuille wrote:
 Well, I would even add : don't use super !
 Just call the superclass method :
 MyClass.__init__(self)
 Simon Percivall a écrit :
 Don't use self.__class__, use the name of the class.
 Bad idea if you're using new-style classes with a complex inheritance
 hierarchy and multiple inheritance.

To quote the original code:

class MyClass(MyBaseClass)
   def __init__(self)
  super(self.__class__, self).__init__()
  self.type = MyClassType
  return self

class MySpecialClass(MyClass)
   def __init__(self)
  super(self.__class__, self).__init__()
  self.type = MySpecialClassType
  return self

The only place it uses self.__class__ is in the calls to super. Super
finds the superclass of it's first argument. If that argument is
self.__class__, then super will always return the superclass of the
class of self, *not* the superclass of the class who's code is being
run. That's why the code resuls in an infinite recursion.

And a note to the OP: __init__'s return value is ignored. You should
delete the return self from your methods.

   mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Missing libpython2.4.so during build of python 2.4.2 on AIX 5.1

2006-01-06 Thread HajoEhlers
Hi folks,
maybe somebody can help.
I am trying to build python 2.4.2 on AIX 5.1 with gcc 3.3.2

The build option for python are:
$ ./configure   \
 --enable-unicode \
 --enable-shared  \
 --with-gcc   \
 --mandir=/usr/local/man  \
 --infodir=/usr/local/info

After  make i see a libpython2.4.a in /usr/local/lib/python2.4/config
but not an libpython2.4.so .
Even the libpython2.4.a will not be installed into /usr/local/lib
From looking at the Makefile i was not not able to determine the option
which might be missing to get a shared library of python.

Any hints ?
Hajo

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


Re: Is 'everything' a refrence or isn't it?

2006-01-06 Thread Donn Cave
In article [EMAIL PROTECTED],
 Steven D'Aprano [EMAIL PROTECTED] wrote:

 I'll tell you what I say: Python passes objects to functions or
 assignments.
 
 Does this mean that the object is copied? No, I didn't say it copies
 objects. I left the nature of the passing mechanism unspoken, which is how
 it should be because it is an implementation detail.

Thus conveniently deferring the necessary explanation of how
it actually works, which will not be too hard but resists
simplistic use this word solutions.

 The emphasis is on the *object*, not the passing mechanism. In C,
 everything is mutable, and whether you can change an item depends on
 whether you are working with a reference to that item or a copy of the
 item. That's a language issue, not a data issue -- in some languages,
 you can even choose whether to pass a reference to a function or a copy
 of the value.
 
 In Python, whether or not you can change an object depends on the object,
 not the language itself: it is a data issue.

Oh, baloney.  Same in C -

   $ cc -c /tmp/t.c
   /tmp/t.c: In function 'churk':
   /tmp/t.c:4: error: assignment of read-only location

As long as you pass by pointer, it is much the same -

   void
   churk(const char *data)
   {
data[0] = 'C';  /* error - modify const object */
data = C;  /* no problem here - rebind pointer parameter */
   }

Maybe the cure for hardened C programmers who aren't
getting it is to emphasize the pointer angle - and note
that there isn't any way to write *i = 4.  Everything
is a pointer, let's say -- or maybe, Everything is a
reference would be smarter.

C programmers are used to seeing their data called
objects, too.  (Not to mention the unlucky many of
us who learned OOP via C++.)

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


Re: Copy an Object (Again?)

2006-01-06 Thread Schüle Daniel
KraftDiner wrote:
 I'm having trouble getting a copy of and object... (a deep copy)
 
 I'm writing a method that creates a mirror image of an object (on
 screen)
 In order to do this i need to get a copy of the object and then modify
 some
 of its attributes.
 
 I tried:
 objs = myListOfObjects
 for obj in objs:
if obj.flag:
   newObject = copy.deepcopy(obj)
   newObject.mirror()
   myListOfObjects.append(newObject)
 
 That doesn't seem to work.. the new object seems to disapear from
 existance.
 I'm wondering if its a bug in my application or if this is my shallow
 understanding of the language.
 
 TIA
 B.
 

I think you should provide more code, eg what attributes does your 
object have?
imagine the situation like this

  import copy
  class A:
... lst=[1, 2, 3]
...
  a=A()
  b=copy.deepcopy(a)
  a
__main__.A instance at 0x403e3c8c
  a.lst
[1, 2, 3]
  b.lst
[1, 2, 3]
  b.lst.append(4)
  b.lst
[1, 2, 3, 4]
  a.lst
[1, 2, 3, 4]

or even if you could copy instances

class X:
def __init__(self, filename = /path/file)
self.file = file(filename, w+)
def modifyByteAt(offset):
self.file.tell(offset)
self.file.write(X)

this is untested pseudocode, it should only give you an idea

hth, Daniel

ps:
question to all
what is a general approach to copy class instances?
write own method or is there some __magic__ attribute or
should one use pickle.dump?

Regards, Daniel

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


Re: Filename case-insensitivity on OS X

2006-01-06 Thread Dan Lowe

On Jan 3, 2006, at 9:50 PM, Tom Anderson wrote:

 On Tue, 3 Jan 2006, Dan Sommers wrote:

 On Tue, 03 Jan 2006 15:21:19 GMT,
 Doug Schwarz [EMAIL PROTECTED] wrote:

 Strictly speaking, it's not OS X, but the HFS file system that is  
 case
 insensitive.

 Aaah, of course. Why on earth didn't Apple move to UFS/FFS/whatever  
 with
 the switch to OS X?

 You can use other file systems, such as UNIX File System.  Use  
 Disk
 Utility to create a disk image and then erase it (again, using Disk
 Utility) and put UFS on it.  You'll find that touch foo FOO will
 create two files.

 You may also find some native Mac OS X applications failing in  
 strange
 ways.

 Oh, that's why. :(

That's one reason, but here are two more:

1. It would have broken the expected behavior from the previous 15  
years of Mac OS releases. Given Mac users' obsessive attention to  
detail regarding the consistency of their environment, this would  
*not* have gone over well at all.

2. Mac OS is designed primarily for non-technical users. A case- 
sensitive filesystem would just be confusing for the main audience.  
If I tried to explain to my mother that Dan.doc is not the same as  
DAN.DOC, she would probably tell me I was out of my mind.

Think about it - how many things used by average people are case  
sensitive? Passwords? That's about it. (And judging by most user  
passwords I have seen, they're almost all lowercase anyway.) Email  
addresses, URLs, the search box in Google, your AOL or Jabber buddy  
list: all case-insensitive.

Aside from that, what is right is a matter of opinion. I prefer  
case-insensitive filesystems, and I'm a system administrator who  
works on Solaris systems all day. Others I work with refuse to  
consider case-insensitive filesystems as anything but a bug. Who's  
right? I don't think there's one true answer...

I'm not trying to get into one of these case sensitivity religious  
wars here, just offering an opinion.

  -dan

-- 
For a list of all the ways technology has failed to improve the quality
of life, please press three.   -Alice Kahn



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


Re: PythonWin: logging module not showing messages from imported modules

2006-01-06 Thread jmdeschamps

[EMAIL PROTECTED] wrote:
 Having the following code:

  Module1.py 
 import logging
 def X():
   logging.error('test')

 If I import it into PythonWin console and call X(), the error message
 is not printed. If I do the same in Python console the message is
 printed. Do I need to configure the logging module or it's a problem
 with PythonWin?

 If I call logging.error() in the PythonWin console it works like a
 charm. The problem is just regarding imported modules.


 Rodrigo Strauss

Do you *run* module1 before attempting to call X() from the interactive
window?

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


Re: Filename case-insensitivity on OS X

2006-01-06 Thread Mark Jackson
Dan Lowe [EMAIL PROTECTED] writes:

 Think about it - how many things used by average people are case  
 sensitive? Passwords? That's about it. (And judging by most user  
 passwords I have seen, they're almost all lowercase anyway.) Email  
 addresses, URLs, the search box in Google, your AOL or Jabber buddy  
 list: all case-insensitive.

Not all URLs.  Compare, for example:

http://www.python.org/doc/Summary.html
http://www.python.org/doc/summary.html

-- 
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
Those who can make you believe absurdities
can make you commit atrocities. - Voltaire


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


Re: Copy an Object (Again?)

2006-01-06 Thread Ernst Noch
KraftDiner wrote:
 I'm having trouble getting a copy of and object... (a deep copy)
 
 I'm writing a method that creates a mirror image of an object (on
 screen)
 In order to do this i need to get a copy of the object and then modify
 some
 of its attributes.
 
 I tried:
 objs = myListOfObjects
 for obj in objs:
if obj.flag:
   newObject = copy.deepcopy(obj)
   newObject.mirror()
   myListOfObjects.append(newObject)
 
 That doesn't seem to work.. the new object seems to disapear from
 existance.
 I'm wondering if its a bug in my application or if this is my shallow
 understanding of the language.
 
 TIA
 B.
 
Another remark, are you sure that your for obj in objs doesn't get you 
into an infinite loop?
If myListOfObjects is a normal list, your assignment

objs = myListofObjects

doesn't make a copy of the list:

  MyListOfNumbers = [1,2,3,4]
  numbs = MyListOfNumbers
  MyListOfNumbers.append(5)
  numbs
[1, 2, 3, 4, 5]

If anything, that makes your alorithm hard to read, because you are 
iterating over a list while appending to it.

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


Re: Copy an Object (Again?)

2006-01-06 Thread Schüle Daniel
I was not very clear about it

 or even if you could copy instances
 
 class X:
 def __init__(self, filename = /path/file)
 self.file = file(filename, w+)
 def modifyByteAt(offset):
 self.file.tell(offset)
 self.file.write(X)
 
 this is untested pseudocode, it should only give you an idea

even when x=X() and y=copyItSomehowFrom(x)
what is supposed to be copied?
the whole file? but where?

in your case .. what is supposed to happen with the mirrored image?
should it be mirrored inplace
if I recall properly in import PIL.Image as image if you image.open
an image and want to mirror it you can create a real copy
and then save as  it into a file

my 2 cents

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


Re: Translate this to python?

2006-01-06 Thread Heiko Wundram
Xavier Morel wrote:
 While the deprecation of xrange is not that soon, it is part of the
 Python 3000 PEP (http://www.python.org/peps/pep-3000.html#id38) along
 with the deprecation of most FP-facilities of Python (filter, map,
 reduce).

I know this, and that's one of the reasons I'm a little at odds with Python
3000... There are many good things in there (such as removing the
FP-facilities which are much more clearly and cleverly implemented using
generator- and list-comprehensions), but some things are so basic (such as
xrange) I wouldn't want to have to implement them every time I need such a
beast.

Unless of course range() becomes more clever and returns an iterator in
case the amount of memory to store the needed range is too large, which
would of course mean obfuscation at other places...

I just don't know.

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


Re: Removing Duplicate entries in a file...

2006-01-06 Thread Mike Meyer
sri2097 [EMAIL PROTECTED] writes:
 Hi all, I'm storing number of dictionary values into a file using the
 'cPickle' module and then am retrieving it. The following is the code
 for it  -

 # Code for storing the values in the file
 import cPickle

 book = {raw_input(Name: ): [int(raw_input(Phone: )),
 raw_input(Address: )] }
 file_object = file(database, 'w+')
 cPickle.dump(book, file_object)
 file_object.close()

 # Code for retrieving values and modifiing them.
 tobe_modified_name = raw_input(Enter name to be modified: )
 file_object = file(database)

 while file_object.tell() != EOFError:
 try:
 stored_dict = cPickle.load(file_object)
 if stored_dict.has_key(tobe_modified_name):
 print (Entry found !)
 # I want to modify the values retrieved from the file and
 then put it back to the file   without duplicate entry.
 file_object = file(database, 'a+')
 except EOFError:
 break
 file_object.close()


 Now, my problem is after finding the entry in the file, I want to make
 changes to the 'values' under the searched 'key' and then insert it
 back to the file. But in doing so I'm having duplicate entries for the
 same key. I want to remove the previous key and value entry in the file
 and key the latest one.  How to solve this problem ?

First, file_object.tell won't return EOFError. Nothing should return
EOFError - it's an exception. It should be raised.

As you noticed, cPickle.load will raise EOFError when called on a file
that you've reached the end of. However, you want to narrow the
try clause as much as possible:

  try:
  stored_dict = cPickle.load(file_object)
  except EOFError:
  break
   
   # Work with stored dict here.

If you weren't doing a break in the except clause, you'd work with the
dictionary in an else clause.

 I actually thought of 2 ways -

 1) In Java there is something called 'file_pointer' concept where in
 after you find the entry you are looking for you move all the entries
 below this entry. Then you get the searched entry at the bottom of the
 file. After this truncate the file by a certain bytes to remove the old
 entry. Can we do this in Python using the file.truncate([size]) method
 ?

Yup, this would work. You'd have to save the value from
file_object.tell() before calling cPickle.load, so you could go back
to that point to write the next object. You'd either have to load all
the following objects into memory, or shuttle back and forth between
the read and write positions. The latter sounds really crappy to me.

 2) Although this is a really crappy way but nevertheless I'll put it
 across. First after finding the entry you are looking for in the file,
 make a copy of this file without the entry found in the previous file.
 Make the changes to the 'values' under this key and insert this into
 the second file what you have created. Before exiting delete the first
 file.

Actually, there's a good reason for doing it that way. But first,
another alternative.

Unless your file is huge (more than a few hundred megabytes), you
might consider loading the entire thing into memory. Instead of
calling cPickle.dump multiple times, put all the dictionaries in a
list, then call cPickle.dump on the list. When you want to update the
list, cPickle.load will load the entire list, so you can use Python to
work on it.

As for saving the file, best practice for updating a file is to write
it to a temporary file, and then rename the new file to the old name
after the write has successfully finished. This way, if the write
fails for some reason, your working file isn't corrupted. Doing it
this way also makes dealing with the case of the the list being to big
load into memory easy:

# Warning, untested code

while 1:
try:
stored_dict = cPickle.load(input_file)
except EOFError:
break
if stored_dict.has_key(tobe_modified_name):
   print Entry found !
   # Modify stored_dict here
cPickle.dump(stored_dict, output_file)

output_file.close()
os.unlink(database) # May not be required; depends on your os
os.rename(datebase_temp, database)


You'll probably want to handle exceptions from cPickle.dump and
output_file.close cleanly as well.

mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Microsoft IronPython?

2006-01-06 Thread Luis M. González
I think that this posted message in Jim Hugunin's weblog clearly shows
what are Microsoft intentions regarding Python and other dynamic
languages:
http://blogs.msdn.com/hugunin/archive/2006/01/05/509812.aspx

We're hiring full-time and summer interns!

We're looking for a few exceptionally talented individuals with
dynamic language experience (Python, Ruby, PHP, JavaScript, etc.) to
come join our efforts to make the Common Language Runtime (CLR) the
world's best platform for dynamic languages and dynamic scenarios.
The CLR already has a lot of dynamic support with reflection, runtime
code generation, and cross-language interaction. IronPython has shown
that the CLR can be a great platform for building dynamic languages. We
want you to help us take this support to the next level.

We have one developer (not yet posted), one program manager, one tester
and at least one summer intern positions available. If you're
interested, please send me email ([EMAIL PROTECTED]) that clearly
explains why you'd be the best choice for one of these jobs and
attach a current resume.
posted on Thursday, January 05, 2006 1:11 PM by hugunin

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


Re: Inheritance problem?

2006-01-06 Thread KraftDiner
So ok I've written a piece of code that demonstrates the problem.
Can you suggest how I change the Square class init?

class Shape(object):
def __init__(self):
print 'MyBaseClass __init__'

class Rectangle(Shape):
def __init__(self):
super(self.__class__, self).__init__()
self.type = Rectangle
print 'Rectangle'

class Square(Rectangle):
def __init__(self):
super(self.__class__, self).__init__()
self.type = Square
print 'Square'

r = Rectangle()
s = Square()

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


Converting milliseconds to human time

2006-01-06 Thread Harlin Seritt
I would like to take milliseconds and convert it to a more
human-readable format like:

4 days 20 hours 10 minutes 35 seconds

Is there something in the time module that can do this? I havent been
able to find anything that would do it.

Thanks,

Harlin Seritt

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


Re: Python or Java or maybe PHP?

2006-01-06 Thread Mike Meyer
Xavier Morel [EMAIL PROTECTED] writes:
 Mike Meyer wrote:
 That doesn't sounds like hates to me. More like doesn't like the
 baggage.
 mike
 Yet anonymous functions are nice.

 Wouldn't it be possible to change the `def` statement to return a
 reference to the function, and allow omitting the function name
 thereby bypassing the default binding (current behavior)?

[...]
   # Anonymous functions
   def (*args, **kwargs):
   pass
 function at 0x00FA3830
   foo = def(*args, **kwargs): pass

This kind of thing has been proposed a number of times, by a number of
people. Including me.

[examples elided]

 I'm not too sure about the multi line version (and it looks very ugly
 with a non-monospaced font), but:

The multi-line version is actually a killer problem. If you allow
newlines it, you get all kinds of problems with nesting, and the code
gets really ugly. If you don't allow newlines, what you have is barely
more powerfull than the existing lambda, and would tempt people to
write really ugly suites in a single line.

 Pros (I think):
  * Backwards-compatible (I think, since the new uses of `def` are
  * currently errors)
  * Fairly obvious syntax
  * No `lambda` or `macros` baggage, the new form of def would
  * merely define an anonymous function instead of a named one.
  * No new keyword, or structure, or idiom
  * Existing idioms are merely slightly extended without changing
  * their current meaning

My version was actually even more backwards compatible - I only
returned the value in the case where you were defining an anonymous
function. Not that that makes any real difference.

 Cons:
  * May reduce readability when misused, and may be used in Very
  * Stupid Ways that reduce readability a lot (but then again most
  * construct may be abused in some way), e.g.:

It's not clear that there are any useful uses that are readable. I had
examples in my proposal, and freely admitted that they were ugly. I
may even have mentioned it in the proposal.

How about some use cases with example usage? That would show us
whether or not there are uses that are both useful and not ugly. Even
if the idea is ultimately rejected, the use cases may generate
different proposals for solving them that are accepted.

  mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encoding sniffer?

2006-01-06 Thread Ralf Muschall
Diez B. Roggisch wrote:

 AFAIK iso-8859-1 has all codepoints taken - so you won't go beyond that
 in your example.

IIRC the range 128-159 (i.e. control codes with the high bit set)
are unused.

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


JINI service -- Python client

2006-01-06 Thread asmirnov1234567890
Hi

does anybody knows how to use JINI service from Python?

Regards,
Andrei

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


Re: Try Python update

2006-01-06 Thread Mike Meyer
Xavier Morel [EMAIL PROTECTED] writes:
 Mike Meyer wrote:
 The url is http://www.mired.org/home/mwm/try_python/. Reports of
 problems would appreciated.
 If you want to try an online P{ython tool that lets you save code,
 try
 Devan L's at http://www.datamech.com/devan/trypython/trypython.py.
 Mike, may I ask whether that box has been secured? And if yes how?

If you go to my try_python page and click the Security heading,
it'll tell you that the interpreter is run in a chrooted sandbox
inside a FreeBSD jail. You don't have access to anything in the file
system but the code needed to run the interpreter. That's all
write-protected, though I do sometimes forget to write-protect an
upgraded file. I've also removed things from the library that weren't
essential to the application.

 Since Python doesn't have any way to secure the interface built-in,
 i'd be interrested in that.

Devan apparently doesn't have as cooperative an ISP, and is working on
securing the interpreter. What he's done may be more interesting.

 mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: - E04 - Leadership! Google, Guido van Rossum, PSF

2006-01-06 Thread Mike Meyer
Xavier Morel [EMAIL PROTECTED] writes:
 Ilias Lazaridis wrote:
   thus if I make a typo, I create a new attribute?
 Why yes of course, what were you expecting?

Actually, it's not quite that way. If you make a typo reading an
attribute, you'll create an exception. There are languages where
making a typo reading an exception creates the attribute, giving it
some default value.

 mike
-- 
Mike Meyer [EMAIL PROTECTED]  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spelling mistakes!

2006-01-06 Thread skip

 try this:
 class x(object):
def __init__(self):
   self.someName = hello
def someMethod(self):
   self.sumName = bye

 find that bug.

Aside from the other responses (unittests, pychecker/pylint), you might also
consider using __slots__ for new-style classes:

class x(object):
   __slots__ = ('someName',)
   def __init__(self):
  self.someName = hello
   def someMethod(self):
  self.sumName = bye

my_x = x()
my_x.someMethod()

When run you will get this output:

Traceback (most recent call last):
  File slot.py, line 9, in module
my_x.someMethod()
  File slot.py, line 6, in someMethod
self.sumName = bye
AttributeError: 'x' object has no attribute 'sumName'

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


Re: Translate this to python?

2006-01-06 Thread Robert Kern
Heiko Wundram wrote:
 Xavier Morel wrote:
 
While the deprecation of xrange is not that soon, it is part of the
Python 3000 PEP (http://www.python.org/peps/pep-3000.html#id38) along
with the deprecation of most FP-facilities of Python (filter, map,
reduce).
 
 I know this, and that's one of the reasons I'm a little at odds with Python
 3000... There are many good things in there (such as removing the
 FP-facilities which are much more clearly and cleverly implemented using
 generator- and list-comprehensions), but some things are so basic (such as
 xrange) I wouldn't want to have to implement them every time I need such a
 beast.
 
 Unless of course range() becomes more clever and returns an iterator in
 case the amount of memory to store the needed range is too large, which
 would of course mean obfuscation at other places...

I believe range() will always return an iterator in Python 3000. See the first
item in the section Built-In Changes on http://wiki.python.org/moin/Python3.0.
xrange() will be going away because it will be utterly obsolete in every
conceivable way.

-- 
Robert Kern
[EMAIL PROTECTED]

In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die.
  -- Richard Harter

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


Re: Converting milliseconds to human time

2006-01-06 Thread Dan Bishop
Harlin Seritt wrote:
 I would like to take milliseconds and convert it to a more
 human-readable format like:

 4 days 20 hours 10 minutes 35 seconds

 Is there something in the time module that can do this? I havent been
 able to find anything that would do it.

The datetime module has something like that:

 d = datetime.timedelta(milliseconds=418235000)
 print d
4 days, 20:10:35

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


Re: Filename case-insensitivity on OS X

2006-01-06 Thread Dan Lowe

On Jan 6, 2006, at 1:13 PM, Mark Jackson wrote:

 Dan Lowe [EMAIL PROTECTED] writes:

 Think about it - how many things used by average people are case
 sensitive? Passwords? That's about it. (And judging by most user
 passwords I have seen, they're almost all lowercase anyway.) Email
 addresses, URLs, the search box in Google, your AOL or Jabber buddy
 list: all case-insensitive.

 Not all URLs.  Compare, for example:

 http://www.python.org/doc/Summary.html
 http://www.python.org/doc/summary.html

You are correct, of course. I was thinking of cases like this:

http://www.python.org
HTTP://WWW.PYTHON.ORG
hTtP://www.PyThOn.ORG

So I should have said hostnames instead of URLs. In my  
experience, most URLs that are actually typed in are like this...

http://yahoo.com
http://google.com
http://ebay.com
http://apple.com
http://amazon.com

And in that form, they are not case sensitive. They only become that  
way when you start putting more on the end. But I'd guess that 90%+  
of the time, URLs of that form are clicked on, not typed into the  
browser.

  -dan

-- 
You know you've achieved perfection in design, not when you have  
nothing more
to add, but when you have nothing more to take away.
 -Antoine de Saint-Exupery


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


Re: Inheritance problem?

2006-01-06 Thread Pierre Barbier de Reuille
KraftDiner a écrit :
 So ok I've written a piece of code that demonstrates the problem.
 Can you suggest how I change the Square class init?
 
 class Shape(object):
   def __init__(self):
   print 'MyBaseClass __init__'
 
 class Rectangle(Shape):
   def __init__(self):
   super(self.__class__, self).__init__()
   self.type = Rectangle
   print 'Rectangle'
 
 class Square(Rectangle):
   def __init__(self):
   super(self.__class__, self).__init__()
   self.type = Square
   print 'Square'
 
 r = Rectangle()
 s = Square()
 

I suggest you have a look at the link I gave before :
http://fuhm.org/super-harmful/

It gives a good explanation about what happens with super.

At least, if you *really* want to use it, change your code like that :

class Shape(object):
  def __init__(self):
super(Shape, self).__init__()
print 'Shape __init__'

class Rectangle(Shape):
  def __init__(self):
super(Rectangle, self).__init__()
self.type = Rectangle
print 'Rectangle'

class Square(Rectangle):
  def __init__(self):
super(Square, self).__init__()
self.type = Square
print Square

r = Rectangle()
s = Square()


But, once more, I would recommand to use direct method call 

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


psexec and os.popen help

2006-01-06 Thread dennis . scales
I'm trying to wrap a psexec command in a python script so I can capture
the results and generate an exception report. The problem I'm having is
that when I use x = os.popen(command) to do it, it runs, but the
content of x is empty. I know there should be output sent to it,
because when I run the command from the DOS prompt, it shows it.  I
don't have this problem when wrapping other PSTools.  Has anyone else
had this problem, or can someone try it and verify that it works, then
show me there work?  I really appreciate it. Its been a late night.
Thanks

Dennis

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


  1   2   >