Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Terry Hancock
On Tuesday 05 July 2005 03:43 pm, Tom Anderson wrote:
> I understand that the backslash is popular in some ivory-tower functional 
> languages. Currently, a backslash can be used for explicit line joining, 
> and is illegal elsewhere on a line outside a string literal, so i think 
> it's available for this. It would be utterly unpythonic to use puntuation 
> instead of a keyword, and it would make no sense to novices, but it would 
> scare the crap out of C programmers, which has to be worth something.

With list comprehensions and generators becoming so integral, I'm
not sure about "unpythonic".  And a syntax just occured to me --
what about this:

[y*x for x,y]

?

(that is:

[ for ]

It's just like the beginning of a list comprehension or generator, but
without the iterator.  That implies that one must be given, and
the result is therefore a callable object.

Wouldn't do anything more or less than present day "lambda", but
gets rid of the weird keyword, and integrates nicely with list comps
and generators.  It's currently a syntax error, and it requires no 
special delimiter -- it's really just an extension of list comp syntax.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Raymond Hettinger
[EMAIL PROTECTED] wrote:
> I've been reading the beloved Paul Graham's "Hackers and Painters".
> He claims he developed a web app at light speed using Lisp and lots
> of macros.
>
> It got me curious if Lisp
> is inherently faster to develop complex apps in.


With Lisp or Forth, a master programmer has unlimited power and
expressiveness.  With Python, even a regular guy can reach for the
stars.


Raymond

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


Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Raymond Hettinger
[EMAIL PROTECTED] wrote:
> The problem is that questions like 'What lang is fastest to develop
> in?'
> are hard to answer definitively.

FWIW, Google's answer to that question is C++, Java, and Python.  For
any given problem, any of the three are acceptable.  Each programmer or
engineering team gets to decide based on his or her language
expertise.*



Raymond


* Source: Greg Stein's keynote address at PyCon 2005.

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


Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Fuzzyman
So Lisp is for really good programmers, and Python is for mediocre
programmers ?

Best Regards,

Fuzzy
http://www.voidspace.org.uk/python

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


Re: f*cking re module

2005-07-06 Thread Raymond Hettinger
> There's really not a single good re tutorial or documentation
>I could found!

With * being a greedy operator, your post's subject line matches,
"firetrucking" which, of course, has nothing to do with regular
expressions, or python.org's re how-to guide, or Amazon's 18 books on
the subject, or the hundreds of available on-line tutorials.

http://www.amk.ca/python/howto/regex/
http://www.amazon.com/exec/obidos/search-handle-form/102-9115182-7050550
http://www.google.com/search?q=regular+expression+tutorial


Raymond

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


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Steven D'Aprano
I said I'd drop the discussion about lambda, but this 
isn't really the same discussion even if it is part of 
the same thread. That's my excuse, and I'm sticking to it.

Terry Hancock wrote:
> On Tuesday 05 July 2005 03:43 pm, Tom Anderson wrote:
> 
>>I understand that the backslash is popular in some ivory-tower functional 
>>languages. Currently, a backslash can be used for explicit line joining, 
>>and is illegal elsewhere on a line outside a string literal, so i think 
>>it's available for this. It would be utterly unpythonic to use puntuation 
>>instead of a keyword, and it would make no sense to novices, but it would 
>>scare the crap out of C programmers, which has to be worth something.
> 
> 
> With list comprehensions and generators becoming so integral, I'm
> not sure about "unpythonic".  And a syntax just occured to me --
> what about this:
> 
> [y*x for x,y]
> 
> ?
> 
> (that is:
> 
> [ for ]
> 
> It's just like the beginning of a list comprehension or generator, but
> without the iterator.  That implies that one must be given, and
> the result is therefore a callable object.

That is a very long chain of implication:

"It looks like a list comprehension... but there is no 
iterator... so we have to supply an iterator... so it 
takes an argument... so it is a callable object... oh 
and by the way, it can take any arguments, not just 
iterators."

It is also far too easy to make a mistake, eg to write 
something like newlist = [y*x for x,y] when you 
actually wanted the list comp [y*x for x,y in L].

This would create an anonymous function where you 
expected to create a list. It is hard to think of a 
usage case where you didn't discover the error 
reasonably soon, but it would be better for leaving the 
iterator out of a list comp to remain a syntax error, 
rather than produce an unexpected, but legal, object.

Besides, I think Guido should be very cautious about 
introducing new features that use punctuation, instead 
of keywords. We don't want to become perl do we? :-)



-- 
Steven.

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


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Antoon Pardon
Op 2005-07-01, Mike Meyer schreef <[EMAIL PROTECTED]>:
> "iK" <[EMAIL PROTECTED]> writes:
>
>> Seems like he wants python programmers to solve their problems all in the 
>> same way. While that is great for corporate slaves it is terrible for the 
>> creative programmer.
>
> No, he wants Python to be Pythonic. TMTOWTDI is not Pythonic.

If Guido should change his mind on this, then it will be pythonic.
I don't think a concept that has so little meaning has any real
value.

>> Python is quickly becoming the visual basic of the 21 century. If you want 
>> to have fun while getting some work done you need to look elsewhere. It's a 
>> shame... 
>
> If you'd rather spend your time figuring out which of multiple ways to
> do things is the best for the job at hand than producing code, there's
> a language that makes TMTOWTDI a way of life.

There are always many ways to do things, and depending on circumstances
the best way to do something may differ every time.

So if python no longer allows multiple ways to do things, it won't help
the programmer. The programmer will now face the question if python
is still the right language to do the job.

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


Create datetime instance using a tuple.

2005-07-06 Thread Negroup
Hi, all.
I would like to know if it is possible to create a datetime instance
using a tuple instead of single values.

I mean:
>>> from datetime import datetime
>>> t = (1, 2, 3)
>>> dt = datetime(t)
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: function takes at least 3 arguments (1 given)

(class datetime(year, month, day[, hour[, minute[, second[,
microsecond[, tzinfo])

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


Re: TEST

2005-07-06 Thread listmaster
Dear ITtoolbox Groups Subscriber,

Your message has NOT been distributed to the ITtoolbox BusinessObjects-L 
discussion group. Please continue reading for further details and instructions.

On Wednesday, May 26, 2004, ITtoolbox launched nine new discussion topics, each 
focusing on specific Business Objects products.  There is no longer one 
ITtoolbox BusinessObjects-L address. As a current group member, you are 
automatically subscribed to the new topics and can begin to send and receive 
messages immediately. Instead of addressing messages to [EMAIL PROTECTED], you 
must now send messages to one or more of the appropriate ITtoolbox Business 
Objects discussion topics below. 

Analytic Applications - [EMAIL PROTECTED]
Connectivity - [EMAIL PROTECTED]
Data Integration - [EMAIL PROTECTED]
Development - [EMAIL PROTECTED]
Installations and Upgrades - [EMAIL PROTECTED]
Performance Management and Security [EMAIL PROTECTED]
Reporting and Analysis - [EMAIL PROTECTED]
General Business Objects Issues - [EMAIL PROTECTED]

ITtoolbox also hosts the BusinessObjects-Crystal-L discussion group. Unlike the 
eight discussion topics listed above, you are not automatically subscribed to 
this group. To begin sending and receiving messages from the ITtoolbox 
BusinessObjects-Crystal-L discussion group, you can subscribe by visiting 
http://BI.ITtoolbox.com/groups/groups.asp?v=BUSINESSOBJECTS-CRYSTAL-L.



Please read the FAQs below for more information.

1) Why am I receiving messages from different e-mail addresses?

There is no longer one BusinessObjects-L e-mail address.  Instead, each 
Business Objects area of discussion has its own e-mail address. You will 
receive messages from each address corresponding to the new ITtoolbox Business 
Objects discussion topics.

2) How do I send a message to the new ITtoolbox Business Objects discussion 
topics?

>From the list above, choose the most relevant topic based on the subject of 
>your message. For example, if your message is relevant to Reporting, it should 
>be addressed to [EMAIL PROTECTED] 

3) What if I want my message to go to more than one topic?

Simply address your message to as many ITtoolbox Business Objects discussion 
topics as are relevant to the subject of your message. ITtoolbox will make sure 
each user only gets your message one time, even if they are subscribed to 
multiple groups.

4) What if I do not want to receive messages from all the ITtoolbox Business 
Objects discussion topics?

You may, at any point, choose to unsubscribe from specific ITtoolbox Business 
Objects discussion topics. To unsubscribe, please sign in to your ITtoolbox 
User ID with your e-mail address at http://My.ITtoolbox.com/My_Groups.asp. If 
you have never signed in before, you may request a password by visiting 
http://My.ITtoolbox.com/ForgotPassword.asp. You must individually unsubscribe 
from each topic.

5) Why did you add individual Business Objects discussion topics? I thought the 
ITtoolbox BusinessObjects-L discussion group worked just fine.

ITtoolbox received feedback from many group members requesting the opportunity 
to conduct more specialized discussion about particular Business Objects 
applications. Since such clear areas exist, we felt they warranted their own 
discussion topics. The creation of these new topics will improve the overall 
quality of discussion by enabling you to receive focused, high quality 
solutions with less turnaround time than ever before. 

6) What if I still have questions?

If you still have questions, please contact [EMAIL PROTECTED]

Thank you for your understanding.

Sincerely,

List Administrator
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: threads and sleep?

2005-07-06 Thread Alex Stapleton
Is SYS V shared memory a totalyl stupid way of doing distributed locks
between processes then?

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of
Jonathan Ellis
Sent: 06 July 2005 05:45
To: python-list@python.org
Subject: Re: threads and sleep?


Peter Hansen wrote:
> Jeffrey Maitland wrote:
> > I was hoping that python would allow for the cpu threading such in
> > Java etc.. but I guess not. (from the answers,and other findings) I
> > guess I will have to write this part of the code in something such as
> > java or c or something that allows for it then I can either wrap it in
> > python or avoid python for this part of the app.
>
> Or investigate the use of Irmen's Pyro package and how it could let you
> almost transparently move your code to a *multi-process* architecture

Unless you're doing anything that would require distributed locking.
Many if not most such projects do, which is why almost everyone prefers
to use threads on an SMP machine instead of splitting it across
multiple smaller boxes.

-Jonathan

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

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


Re: f*cking re module

2005-07-06 Thread Simon Brunning
On 6 Jul 2005 01:01:34 -0700, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> With * being a greedy operator, your post's subject line matches,
> "firetrucking"

Nope:

>>> print re.match('f*cking', 'firetrucking')
None

The OP was clearly showing his lack of regex nouce here. Clearly he
wanted 'f.*cking':

>>> print re.match('f.*cking', 'firetrucking')
<_sre.SRE_Match object at 0x01196058>

;-)

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


How to disable rangeselect in wxGrid

2005-07-06 Thread [EMAIL PROTECTED]
Hi !

I have a little problem with wxGrid.
In Delphi I can set in grids how I want to select cells.
I can select only individual cells, or ranges.

In my program I don't wanna use ranges. But I don't find any
methods or properties what can set this option.

The range selection mode is disturb the users.
Usually the ranges are used to select more cells, and do any operations 
with them.
But in my program the user can select only one(!) cell, and this cell 
set the
actual day, and actual person.
If many cells are selected, the user (and I too) cannot determine, which 
day/person
is the actual.

So if possible, I want to "protect users from this effect".

Is anyone can help me ?

Thanx for it: ft


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


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


Re: Python exception hook simple example needed

2005-07-06 Thread [EMAIL PROTECTED]
Hi !

I think I found an example:

import sys

def info(type, value, tb):
   if hasattr(sys, 'ps1') or not sys.stderr.isatty():
  # we are in interactive mode or we don't have a tty-like
  # device, so we call the default hook
  print "yyy"
  sys.__excepthook__(type, value, tb)
   else:
  import traceback, pdb
  # we are NOT in interactive mode, print the exception...
  print "xxx"
  traceback.print_exception(type, value, tb)
  # ...then start the debugger in post-mortem mode.
  pdb.pm()

sys.excepthook = info

But I don't know it is working or not

Thanx: ft

>
> Tárgy:
> Re: Python exception hook simple example needed
> Feladó:
> Benji York <[EMAIL PROTECTED]>
> Dátum:
> Tue, 05 Jul 2005 10:34:23 -0400
> Címzett:
> python-list@python.org
>
> Címzett:
> python-list@python.org
>
>
> [EMAIL PROTECTED] wrote:
>
>> If anyone has an idea, how to I catch exceptions globally, please 
>> write me.
>
>
> I believe there is an example of this in the demo that comes with 
> wxPython (don't have an install handy to check).
> -- 
> Benji York
>
>

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


Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Michele Simionato
Fuzzyman:
> So Lisp is for really good programmers, and Python is for
> mediocre programmers ?


Python is *also* for mediocre programmers. I see this as a
strength, not as a weakness.

  Michele Simionato

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


Re: Create datetime instance using a tuple.

2005-07-06 Thread Qiangning Hong
On 6 Jul 2005 02:01:55 -0700, Negroup <[EMAIL PROTECTED]> wrote:
> Hi, all.
> I would like to know if it is possible to create a datetime instance
> using a tuple instead of single values.
> 
> I mean:
> >>> from datetime import datetime
> >>> t = (1, 2, 3)
> >>> dt = datetime(t)
> Traceback (most recent call last):
>   File "", line 1, in ?
> TypeError: function takes at least 3 arguments (1 given)
> 
> (class datetime(year, month, day[, hour[, minute[, second[,
> microsecond[, tzinfo])

Use:
dt = datetime(*t)

-- 
Qiangning Hong
Get Firefox! 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: precision problems in base conversion of rational numbers

2005-07-06 Thread Raymond Hettinger
[Terry Hancock]
> > Needless to say, the conventional floating point numbers in Python
> > are actually stored as *binary*, which is why there is a "decimal"
> > module (which is new).
> >
> > If you're going to be converting between bases anyway, it probably
> > makes little difference whether you are using the decimal module
> > or not, of course.  You'll have the same problems the conventional
> > float numbers do.

Not really.  floats won't do because they may not have sufficient
precision to differentiate rational values falling close the split
between representable values in a given base.  The decimal module
offers arbitrarily large precision for making sure the error-term is
small enough to not make a difference.



[Brian van den Broek]
> Thanks. mensanator provided the actual formula for my case. I had a
> "magic number" in my code by which I multiplied my desired level of
> "number of places in the representation" to obtain the value for
> decimal.getcontext.prec.
>
> mensanator wrote:
>
> > The value you want for x is log(17)/log(10) =
> > 1.2304489213782739285401698943283
>
> where x was my "magic number". I've not had a chance to think it
> through yet, but I feel confident that given the formula, I'll be able
> to work out *why* that is the formula I need.

That "formula" just gives a starting point estimate.  The required
decimal precision may be much higher.  If the rational falls very close
to the half-way point between two representable numbers, the
calculation needs to be retried with increased precision until the
split-point is definitive (when the error-term becomes less than the
distance to the next representable value).

For a simple example, convert both 10247448370872321 and
10247448370872319 from base ten to 4 digits of hex.  The calculations
need to be carried out to 15 places of hex (or 17 places of decimal)
just to determine whether the fourth hex digit is a 7 or 8:

>>> hex(10247448370872321)
'0x246801L'
>>> hex(10247448370872319)
'0x2467ffL'

For an example of using decimal with iteratively increasing precision,
see the dsum() recipe at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/393090 .


Raymond

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


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Antoon Pardon
Op 2005-07-02, Mike Meyer schreef <[EMAIL PROTECTED]>:
> "Sean McIlroy" <[EMAIL PROTECTED]> writes:
>
>> Peter Hansen wrote:
>> 
>>> Sean, what gave you the impression this would change?
>> if that's the case then list comprehensions and/or "first class
>> functions" are likely to be the next target.
>
> The existence of list comprehensions are the reason that these
> functions are going away, so they aren't likely to be next. It's all
> part of "There should be one-- and preferably only one --obvious way
> to do it."

IMO people concentrate too much on the "and preferably only one" part
of this.

If you really want at least one obvious way to do things then,
there also will be a lot of things that have more than one
obvious way. Trying to eliminate all those mulitiple obvious ways,
which seems to be one of the goals here, will result in removing
the one obvious way for doing other things.

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


Using Ghostscript DLL via ctypes in Py2.3/Win

2005-07-06 Thread Adam Twardoch
I've written a simple commanline wrapper for calling GhostScript from 
Python. It uses os.system under Windows and os.popen under unixes. The call 
looks basically like this:

gs -q -dNODISPLAY -dNOPAUSE -dSAFER ps2ai.ps infile.eps >outfile.ai

I'd prefer to use the GhostScript DLL API* and call it using ctypes under 
Windows. This way, I could package just the DLL with my application and the 
user would not necessarily need to install the full GhostScript. However, I 
don't really know how to handle ctypes very well.

Has anyone perhaps written something like that already and cares to share a 
code snippet?

Regards,
Adam

*) http://www.cs.wisc.edu/~ghost/doc/cvs/API.htm


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


Re: Dr. Dobb's Python-URL! - weekly Python news and links (Jul 5)

2005-07-06 Thread Fuzzyman
Simon Brunning wrote:
[snip..]
>
> The online Python Journal is posted at pythonjournal.cognizor.com.
> [EMAIL PROTECTED] and [EMAIL PROTECTED]
> welcome submission of material that helps people's understanding
> of Python use, and offer Web presentation of your work.
>

Does the 'pythonjournal' still deserve it's place in these posts ? It
doesn't *seem* to have been updated for some years.

Regards,

Fuzzy
http://www.voidspace.org.uk/python

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


Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Andrew Durdin
On 6 Jul 2005 00:30:34 -0700, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> 
> With Lisp or Forth, a master programmer has unlimited power and
> expressiveness.  With Python, even a regular guy can reach for the
> stars.

+1 QOTW
-- 
http://mail.python.org/mailman/listinfo/python-list


frozenset question

2005-07-06 Thread Will McGugan
Hi,

Are there any benefits in using a frozenset over a set, other than it 
being immutable?


Will McGugan
-- 
http://www.willmcgugan.com
"".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in 
"jvyy*jvyyzpthtna^pbz")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: frozenset question

2005-07-06 Thread Qiangning Hong
On 7/6/05, Will McGugan <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> Are there any benefits in using a frozenset over a set, other than it
> being immutable?

A frozenset can be used as a key of a dict:

.>> s1 = set([1])
.>> s2 = frozenset([2])
.>> {s1: 1}
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: set objects are unhashable
.>> {s2:1}
{frozenset([2]): 1}

-- 
Qiangning Hong
Get Firefox! 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: f*cking re module

2005-07-06 Thread Jorgen Grahn
On 5 Jul 2005 08:04:21 -0700, jwaixs <[EMAIL PROTECTED]> wrote:
...
> The python re module is, in my opinion, a non beginner user friendly
> module. And it's not meant for beginning python programmers. I don't
> have any experience with perl or related script/programming languages
> like python. (I prefer to do things in c) So the re module is
> completely new for me.

Actually, REs are a useful tool even in C, for example for validating input
before parsing it with custom code, so you can forget about some of the
error checking in the parsing code.

... although you have to be on a Unix system to be reasonably sure that they
are available, and even then you're looking at a much less powerful RE
language than the ones in Python and Perl.

That's another problem with REs -- there are many slightly different RE
languages, and sometimes you cannot even be sure which one you're working
with.

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: frozenset question

2005-07-06 Thread Will McGugan
Qiangning Hong wrote:
> On 7/6/05, Will McGugan <[EMAIL PROTECTED]> wrote:
> 
>>Hi,
>>
>>Are there any benefits in using a frozenset over a set, other than it
>>being immutable?
> 
> 
> A frozenset can be used as a key of a dict:

Thanks, but I meant to imply that.

I was wondering if frozenset was faster or more efficient in some way. 
Thinking back to the dark ages of C++, you could optimize things that 
you knew to be constant.


Will

-- 
http://www.willmcgugan.com
"".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in 
"jvyy*jvyyzpthtna^pbz")
-- 
http://mail.python.org/mailman/listinfo/python-list


Help with wx.PaintDC

2005-07-06 Thread flamesrock
wxGlade has made this tooo easy for me so far. But right now I'm
very confused about something:
self.bmp = wx.Bitmap('sample.bmp')
dc = wx.PaintDC(self.notebook_region_overview)
dc.DrawBitmap(self.bmp,0,0,False)

self.notebook_region_overview is basically a wx.Panel, located on the
right side of a splitterWindow.

Anyways, this code *should* draw sample.bmp inside the right wx.Panel
(self.notebook_region_overview), but doesn't.

I would be grateful if anyone could correct me. There isn't much
information about drawing images to wx.Panels online.

-thanks

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


Re: How do you program in Python?

2005-07-06 Thread Jorgen Grahn
On Sun, 03 Jul 2005 17:35:16 +0100, anthonyberet <[EMAIL PROTECTED]> wrote:
...
> What I would really like is something like an old-style BASIC 
> interpreter, in which I could list, modify and test-run sections of 

I use no IDE, just emacs for editing my sources, and a terminal window or
two. And CVS for version control.

Often I run Python interactively to try out small "one-liners". For example,
I don't try to remember the slicing syntax, or what 'list("foo")' means, or
if range(0) is legal, etc -- I just try it out interactively.

If I get stuck or if the problem is non-trivial, or if I'm writing a
standalone module, I use module unittest so I have something easily runnable
at all times. This unittest code doesn't even have to be true unit tests --
it can be any speculative code I want, driven by the unittest framework.

Between these two (interactive tinkering and unittest-based code) I feel
little need for IDEs or 'environments for experimentation'.

Others will feel differently, of course.

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter grid layout

2005-07-06 Thread Richard Lewis
Hi there,

I've got a tree control in Tkinter (using the ESRF Tree module) but I
can't get it to layout how I want it.

I'd like to have it so that it streches north/south (anchored to the top
and bottom), is of a fixed width and is anchored to the left hand side.
Here's my code (its derived from one of the examples from the ESRF web
site):

class MainWindow(Frame):
  def __init__(self, master):
Frame.__init__(self, master)
self.document = # new DOM document
self.create_site_list()
  
  def create_site_list(self):
self.list_model = ListModel(self.document)
# ListModel class returns the DOM outline as a simple Python data
structure

self.site_list = Tree.Tree(master=self,\
root_id="root",\
root_label="Site",\
get_contents_callback=self.get_list_item,\
 # get_list_item uses the list_model to build list nodes
width=300)

self.site_list.grid(row=0, column=0, sticky=N+SW)

self.grid_rowconfigure(0, weight=1)

vsb = Scrollbar(self, orient=VERTICAL)
vsb.grid(row=0, column=1, sticky=NS)
self.site_list.configure(yscrollcommand=vsb.set)
vsb.configure(command=self.site_list.yview)

hsb = Scrollbar(self, orient=HORIZONTAL)
hsb.grid(row=1, column=0, sticky=EW+S)
self.site_list.configure(xscrollcommand=hsb.set)
hsb.configure(command=self.site_list.xview)

self.site_list.focus_set()


This code makes it centred in the east/west direction and a constant
height anchored to the top. I guess its the sticky values I need to play
with (?) but I can't find the right combination. I've given the code
with the ones that seem logically correct (to me!)

I expect this is probably quite trivial for someone who knows what
they're doing.

Any ideas?

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


Re: Outlook COM: how to create a MailItem from a .msg file

2005-07-06 Thread Guy Lateur
Ok, we didn't have the IMAP service running; we do now (no SSL).

Connecting to the server is not a problem anymore, but logging in is. It 
works with the administrator account, but not with my personal account. We 
have restricted access to all machines in 10.0.0.0/255.255.255.0, which 
includes my machine.

My password is empty (yeah, I know..). Could that be the problem? I'm using 
this: pw = ''

Thanks,
g 


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


Re: System Independent Wallpaper Changer

2005-07-06 Thread Toby Dickenson
On Wednesday 06 July 2005 01:12, Terrance N. Phillip wrote:

> I've done some searching, and can't seem to find a programatic way of 
> getting *** that to happen.

http://www.google.com/search?q=setwallpaper+dcop

I hope this helps

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


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Daniel Schüle
Full Acknowledge

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


Re: frozenset question

2005-07-06 Thread Steven D'Aprano
On Wed, 06 Jul 2005 11:30:14 +0100, Will McGugan wrote:
 
> I was wondering if frozenset was faster or more efficient in some way. 
> 
> Thinking back to the dark ages of C++, you could optimize things that
> you knew to be constant.

Why would you want to?

py> import sets
py> import time
py> bigset = sets.Set(range(50))
py> bigimmutableset = sets.ImmutableSet(range(50))
py> assert len(bigset) == len(bigimmutableset)
py> 
py> def tester(S, L):
... """Test if items from L are in S, and time the process."""
... t = time.time()
... for i in range(100):
... for item in L:
... item in S
... return time.time() - t  # time returned is for 100 loops
...
py>

Time some successful tests:

py> tester(bigset, range(100, 500))
0.11539506912231445
py> tester(bigimmutableset, range(100, 500))
0.12014198303222656

Practically no difference when doing 100*400 checks of whether an integer
is in the set. But let's try again, just in case:

py> tester(bigset, range(100, 500))
0.10998892784118652
py> tester(bigimmutableset, range(100, 500))
0.4096641540527

The difference is insignificant. How about unsuccessful checks?

py> tester(bigset, range(-100, -500, -1))
0.12070298194885254
py> tester(bigset, range(-100, -500, -1))
0.11681413650512695
py> tester(bigimmutableset, range(-100, -500, -1))
0.11313891410827637
py> tester(bigimmutableset, range(-100, -500, -1))
0.11315703392028809

There is no significant speed difference between immutable and mutable
sets, at least for queries. Regardless of whether it is successful or
unsuccessful, mutable or immutable, it takes about 0.025 second to do
each test of item in set. Why would you need to optimize that?

If you tell us what you are trying to do, and under what circumstances it
is too slow, we'll see if we can suggest some ways to optimize it.

But if you are just trying to optimize for the sake of optimization,
that's a terrible idea. Get your program working first. Then when it
works, measure how fast it runs. If, and ONLY if, it is too slow, 
identify the parts of the program that make it too slow. That means
profiling and timing. Then optimize those parts, and nothing else.

Otherwise, you will be like the car designer trying to speed up his sports
cars by making the seatbelts aerodynamic.


-- 
Steven.


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


Re: threads and sleep?

2005-07-06 Thread Peter Hansen
Jonathan Ellis wrote:
> Peter Hansen wrote:
>>Or investigate the use of Irmen's Pyro package and how it could let you
>>almost transparently move your code to a *multi-process* architecture
> 
> Unless you're doing anything that would require distributed locking.
> Many if not most such projects do, which is why almost everyone prefers
> to use threads on an SMP machine instead of splitting it across
> multiple smaller boxes.

I can't address the issue of whether or not "most" such projects require 
distributed locking, because I'm not familiar with more than half of 
such projects, as you appear to be. 

On the other hand, I am (somewhat) familiar with Jeffrey's stated 
problem area (two postings of his earlier in the thread) and it really 
doesn't sound like he needs such a thing.  Would you normally expect to 
need distributed locking for a simple system where you had long-running 
computations and wanted to improve performance by using multiple CPUs?

Of course, only he can tell for sure.

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


Re: adding a character to the last string element of a list

2005-07-06 Thread Peter Hansen
Philippe C. Martin wrote:
> I guess my slicing was wrong, l[-1] worked

Note that that's _not_ a slice, however, but a reference to the last 
element in the list.

You'd have to subclass list to be able to do something with 
"reference-slices".  Probably returning a special object from 
__getslice__ which itself has references back to the original list and 
implements any changes back in the original instead of in itself.  I 
haven't tried to imagine if this is even feasible.

Anything "indexing" with : in it is a slice, so a copy, while anything 
with only a single index as you have in l[-1] is just a reference to one 
element in the list.

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


Re: Using Ghostscript DLL via ctypes in Py2.3/Win

2005-07-06 Thread Peter Hansen
Adam Twardoch wrote:
> I'd prefer to use the GhostScript DLL API* and call it using ctypes under 
> Windows. 
> Has anyone perhaps written something like that already and cares to share a 
> code snippet?

There is a ctypes mailing list where you might have more success getting 
a reply (though I suspect most people there read this forum as well).

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


Re: VBR mp3 length

2005-07-06 Thread Lucas Raab
No One wrote:
> Hello all,
> If this isn't the correct newsgroup, please redirect me.
> 
> I'm trying to extract the song length from variable bit rate mp3's.
> Does anyone know of a library or bit of code that will do this?  I've
> tried pymad, but it seems to grab the bitrate of the first frame and
> then apply that to the the file length to come up with a total length.
> Needless to say, if the bitrate of the first frame isn't close to the
> overall average, it's wildly off.
> 
> Thanks,
> -Steve

Take a look at http://pymedia.org.

-- 
--
Lucas Raab
lvraab"@"earthlink.net
dotpyFE"@"gmail.com
AIM:Phoenix11890
MSN:dotpyfe "@" gmail.com
IRC:lvraab
ICQ:324767918
Yahoo:  Phoenix11890
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: threads and sleep?

2005-07-06 Thread Peter Hansen
Grant Edwards wrote:
> On 2005-07-05, Grant Edwards <[EMAIL PROTECTED]> wrote:
>>Or is the Python interpreter actually doing the context
>>switches itself?
> 
> Upon further thought, that just can't be the case.  There has
> to be multiple instances of the intepreter because the
> interpreter can make C system calls that block (thus blocking
> that instance of the interpreter). Other Python threads within
> the program continue to run, so there must be multiple Python
> intepreters.

Maybe you should consider and explain what you mean by "multiple 
interpreters"?  As I understand the concept, and based on my several 
years' old reading of the virtual machine code, I wouldn't say there are 
multiple interpreters.

There's a reason the GIL is the *global* interpreter lock...

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


Re: Python exception hook simple example needed

2005-07-06 Thread Fuzzyman
Wax has a brilliant prebuilt dialog/handler. It's a wrapper over
wxPython - so you still use wxPython objects, it's jsut all a lot
easier.

http://zephyrfalcon.org/labs

Best Regards,

Fuzzy
http://www.voidspace.org.uk/python

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


Re: Good starterbook for learning Python?

2005-07-06 Thread Fuzzyman
A book that will stay useful as a referene *after* you've used it to
learn is 'Programming Python'.

Best Regards,

Fuzzy
http://www.voidspace.org.uk/python

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


Re: How do you program in Python?

2005-07-06 Thread Sybren Stuvel
Jorgen Grahn enlightened us with:
> I use no IDE, just emacs for editing my sources, and a terminal
> window or two. And CVS for version control.

Almost the same here, except that I use VIM and Subversion instead of
Emacs and CVS.

> If I get stuck or if the problem is non-trivial, or if I'm writing a
> standalone module, I use module unittest so I have something easily
> runnable at all times. This unittest code doesn't even have to be
> true unit tests -- it can be any speculative code I want, driven by
> the unittest framework.

Same here. I really love unittest!

> Between these two (interactive tinkering and unittest-based code) I
> feel little need for IDEs or 'environments for experimentation'.

I'm usually annoyed by IDEs because, for instance, they don't use VIM
as an editor. Since I'm hooked to that, all IDEs I've used so far have
failed to impress me.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Fuzzyman
Fair enough ;-)

I'd like to discover the power of Lisp, but I have a limited amount of
time to sink into programming... so maybe I'm better off putting my
energies and imagination into Python.

*A language is a medium of expression.* - Paul Graham

All the best.

Fuzzy
http://www.voidspace.org.uk/python

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


Dr. Dobb's Python-URL! - weekly Python news and links (Jul 5)

2005-07-06 Thread Simon Brunning
QOTW: "That's what I love in that news group. Someone comes with a stupid
and arrogant question, and someone else answers in a calm and reasonable
way." - Gustavo Niemeyer

"After 25 years doing this, I've become something of a Luddite as far as
fancy IDEs and non-standard features go... and a huge believer in strict
decoupling between my tools, to the point of ignoring things that bundle
them together in ways that are, in my opinion, too tight." - Peter Hansen


Ralf Grosse-Kunstleve floats a proposal to reduce the amount of code
requires to set instance fields from arguments in __init__ methods:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/7346ad00a14e821a

The Python Software Foundation Summer of Code projects have been selected:
http://www.amk.ca/diary/archives/003975.html

A discussion about the long-term plan to remove map, filter, reduce
and lambda starts out bad-tempered then ... improves little:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/ceef909ebd10b65a

There's a new wxPython tutorial at Dev Shed:
http://www.devshed.com/c/a/Python/A-Look-at-wxPython/

Peter Hansen wants to determine the wall-clock elapsed time taken by
a process on a managed host in a reliable, cross-platform way:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/cd1222d713730b67

Par Nicolas Lehuen uses Python to compare Microsoft Word documents
stored in a Subversion repository (!):

http://www.lehuen.com/nicolas/index.php/2005/06/30/60-comparing-microsoft-word-documents-stored-in-a-subversion-repository

Terry Hancock explains what ZOPE actually is:

http://groups-beta.google.com/group/comp.lang.python/msg/174d4101e0e419e8



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Cetus collects Python hyperlinks.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://aspn.activestate.com/ASPN/Cookbook/Python

Among several Python-oriented RSS/RDF feeds available are
http://www.python.org/channews.rdf
http://bootleg-rss.g-blog.net/pytho

Re: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code

2005-07-06 Thread NickC
Ralf,

I'd be very interested to hear your opinion on the 'namespace' module,
which looks at addressing some of these issues (the Record object, in
particular).  The URL is http://namespace.python-hosting.com, and any
comments should be directed to the [EMAIL PROTECTED]
discussion list.

Regards,
Nick.

--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.blogspot.com

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


Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Antoon Pardon
Op 2005-07-06, Michele Simionato schreef <[EMAIL PROTECTED]>:
> Fuzzyman:
>> So Lisp is for really good programmers, and Python is for
>> mediocre programmers ?
>
>
> Python is *also* for mediocre programmers. I see this as a
> strength, not as a weakness.

But sometimes I get the impression people want it to evolve
so it is only for mediocre programmers.

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


Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-06 Thread George Sakkis
"Terry Reedy" <[EMAIL PROTECTED]> wrote:

> "George Sakkis" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Still it's hard to explain why four specific python keywords - def,
> > del, exec and elif - were chosen to be abbreviated,
>
> Precedence in other languages and CS usage?

What precedence ? I don't know of another language that uses def or del
at least; even C++ which compared to python is much more terse uses
"delete" instead of del. And in any case, curly braces for grouping
statements is much more prevalent in other languages and CS usage but
(fortunately) python chose indentation.

> > So, who would object the full-word versions for python 3K ?
> > def -> define
> > del -> delete
> > exec -> execute
>
> These three I might prefer to keep.
>
> > elif -> else if
>
> This one I dislike and would prefer to write out.  I never liked it in
> whatever else language I first encountered it and still don't.

In contrast to the first three changes which would be straightforward,
changing "elif" to "else if" would add (a little?) complexity to the
parser by allowing "else" to be followed either by a colon (the only
choice now) or "if", though I don't think this would be a decisive
factor. 

George

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


Re: frozenset question

2005-07-06 Thread Will McGugan
Steven D'Aprano wrote:

> There is no significant speed difference between immutable and mutable
> sets, at least for queries. Regardless of whether it is successful or
> unsuccessful, mutable or immutable, it takes about 0.025 second to do
> each test of item in set. Why would you need to optimize that?
> 
> If you tell us what you are trying to do, and under what circumstances it
> is too slow, we'll see if we can suggest some ways to optimize it.
> 
> But if you are just trying to optimize for the sake of optimization,
> that's a terrible idea. Get your program working first. Then when it
> works, measure how fast it runs. If, and ONLY if, it is too slow, 
> identify the parts of the program that make it too slow. That means
> profiling and timing. Then optimize those parts, and nothing else.
> 
> Otherwise, you will be like the car designer trying to speed up his sports
> cars by making the seatbelts aerodynamic.

No need for the 'premature optimization is the root of all evil' speech. 
I'm not trying to optimize anything - just enquiring about the nature of 
frozenset. If typing 'frozenset' over 'set' gave me a saving in time or 
memory (even if tiny) I would favour immutable sets, where appropriate.

Thanks for the info.

Will

-- 
http://www.willmcgugan.com
"".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in 
"jvyy*jvyyzpthtna^pbz")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread steve . morin
map, filter, reduce and lambda
Lisp constructs, bring flexibility to the language and is why I started
programming in python to begin with. Removing these constructs will be
a shame and one step closer to the death of some of the basic features
that make python great.

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


Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Larry Bates
You don't say how long it took to develop the "macros" but
you should see what kind of website an experienced Zope/Plone
programmer can whip up in a few minutes.

Acceleration in programming has always been about the "Standard
Library" (not only Python's standard library but also your
standard library).  I'm talking about stable, debugged,
documented macros, functions and classes that the programmer can
use to quickly do very complex tasks.  I discovered this well
over 30 years ago and taught many young programmers and
University students this very important "trick".  As you write
software you will eventually come across common routines that
are used in almost every software package (logging, reading
from CSV files, date/time manipulation, ...).  If you have lots
of these to choose from in your library, you will produce code
10-100 times faster than those that start over every time AND
the code will be MANY times more reliable because you are
utilizing stable code that has been debugged over a long period
of time.  You will also be producing code that is more
"maintainable".  Discovered a bug in a library routine? Fix it
and then it is fixed in 100's (or 1000's) of existing programs
that use it.

-Larry Bates

[EMAIL PROTECTED] wrote:
> I've been reading the beloved Paul Graham's "Hackers and Painters".
> He claims he developed a web app at light speed using Lisp and lots
> of macros.
> 
> It got me curious if Lisp
> is inherently faster to develop complex apps in.  It would seem if you
> could create your own language in Lisp using macros that that would be
> quite an advantage
> 
> I realize that Python has operator overloading and OOP so I'm not sure.
> 
> Any ideas?  Any *evidence* one way or another?
> 
> thanks!
> 
> Chris
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Tom Anderson
On Wed, 5 Jul 2005, George Sakkis wrote:

> "Steven D'Aprano" <[EMAIL PROTECTED]> wrote:
>
>> On Tue, 05 Jul 2005 09:46:41 -0500, Terry Hancock wrote:
> [snip]
>
>> Def would be short for ... defend? defile? defer? defame? default? deflect?
>>
>> There's always *something* to learn. Why def instead of define? Because 
>> "easy to write" beats "instantly obvious to a beginner", if the word is 
>> used all the time and is easy to memorize.
>
> Still it's hard to explain why four specific python keywords - def,
> del, exec and elif - were chosen to be abbreviated, while all the rest
> are full words (http://docs.python.org/ref/keywords.html). "Ease of
> typing" is a joke for an excuse;

For exec and probably del, yes, but def and elif are two of the most 
frequently used keywords in the language, so i think it's reasonable to 
keep them short.

> So, who would object the full-word versions for python 3K ?
>
> def -> define

I'd keep this short - it's one of the most commonly-used keywords. It's 
particularly commonly used if you break your programs down into lots of 
little functions; since this is, IMHO, something we want to encourage 
people to do, we should strive to minimise boilerplate.

> del -> delete

How about just getting rid of del? Removal from collections could be done 
with a method call, and i'm not convinced that deleting variables is 
something we really need to be able to do (most other languages manage 
without it).

> exec -> execute

This should be a function somewhere, maybe a builtin, maybe not - it 
absolutely should not be a keyword. What that function should be called, i 
don't know!

> elif -> else if

I'm not sure about splitting it into two words; there's currently a very 
simple relationship between flow control keywords, meanings, and blocks of 
code, which would be broken if we moved to using "else if". I don't know 
that this relationship is actually important, though.

tom

-- 
Don't believe his lies.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: frozenset question

2005-07-06 Thread Michael Hudson
Will McGugan <[EMAIL PROTECTED]> writes:

> Qiangning Hong wrote:
> > On 7/6/05, Will McGugan <[EMAIL PROTECTED]> wrote:
> > 
> >>Hi,
> >>
> >>Are there any benefits in using a frozenset over a set, other than it
> >>being immutable?
> > A frozenset can be used as a key of a dict:
> 
> Thanks, but I meant to imply that.
> 
> I was wondering if frozenset was faster or more efficient in some
> way.

No, the 'usable as a dict key' is the main motivation for frozenset's
existence.

Cheers,
mwh

-- 
  The bottom tier is what a certain class of wanker would call
  "business objects" ...  -- Greg Ward, 9 Dec 1999
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Zachery Bir
Larry Bates <[EMAIL PROTECTED]> writes:

> You don't say how long it took to develop the "macros" but
> you should see what kind of website an experienced Zope/Plone
> programmer can whip up in a few minutes.

Zope/Plone (as frameworks) represent exactly the kinds of DSLs people
have been building with Lisp for decades. Shoulders of giants, and all
that. Lisp has web app frameworks as well: Uncommon Web and BKNR, to
name two.

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


Re: System Independent Wallpaper Changer

2005-07-06 Thread Terrance N. Phillip
Toby Dickenson wrote:
> On Wednesday 06 July 2005 01:12, Terrance N. Phillip wrote:
> 
> 
>>I've done some searching, and can't seem to find a programatic way of 
>>getting *** that to happen.
> 
> 
> http://www.google.com/search?q=setwallpaper+dcop
> 
> I hope this helps
> 

That helps very much, thank-you! And sorry to previous posters: yes, 
indeed, I changed naming conventions part way through--you got an 
intermediate version.

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


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Tom Anderson
On Wed, 6 Jul 2005, Terry Hancock wrote:

> On Tuesday 05 July 2005 03:43 pm, Tom Anderson wrote:
>
>> I understand that the backslash is popular in some ivory-tower 
>> functional languages. Currently, a backslash can be used for explicit 
>> line joining, and is illegal elsewhere on a line outside a string 
>> literal, so i think it's available for this. It would be utterly 
>> unpythonic to use puntuation instead of a keyword, and it would make no 
>> sense to novices, but it would scare the crap out of C programmers, 
>> which has to be worth something.
>
> With list comprehensions and generators becoming so integral, I'm
> not sure about "unpythonic".

I'm going to resist the temptation to argue that list comps are themselves 
unpythonic :).

Hang on, where's the punctuation in either of those? They *are* done with 
keywords! A generator is just a function with "yield" instead of "return", 
list comprehensions are just list literals where the explicit sequence of 
items is replaced with code producing them, using the keywords "for", "in" 
and "if", and a generator expression is a list comp *without any 
punctuation!*

> And a syntax just occured to me -- what about this:
>
> [y*x for x,y]
>
> ?

Terrible. Square brackets mean a list, and a lambda is not anything like a 
list.

I see where you're coming from, though; a lambda is a lot like the first 
half of a list comp that's broken off and is roaming free. I can't think 
of a good syntax for it, though.

tom

-- 
find porn apricot
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: math.nroot [was Re: A brief question.]

2005-07-06 Thread Jeff Epler
On Tue, Jul 05, 2005 at 09:49:33PM +0100, Tom Anderson wrote:
> Are there any uses for NaN that aren't met by exceptions?

Sure.  If you can naturally calculate two things at once, but one might
turn out to be a NaN under current rules.

x, y = calculate_two_things()
if isnan(x):
perform_next_step_with_only_y(y)
else:
perform_next_step_with_both(x, y)

Under your scheme, you'd have to write
try:
x, y = calculate_two_things()
except NaNException:
y = calculate_one_thing()
perform_next_step_with_only_y(y)
else:
perform_next_step_with_both(x, y)
and at the very least duplicate the code for calculating 'y', possibly
re-doing a lot of work at runtime too.

Jeff


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

Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Tom Anderson
On Tue, 5 Jul 2005, Mike Meyer wrote:

> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
>
>>> Well, his Viaweb company was founded in about '95, right? So he 
>>> probably just used Lisp because Python wasn't as well known yet. ;-)
>>
>> That is what I thought too.  It makes sense but I wasn't sure.  Still 
>> ain't. The problem is that questions like 'What lang is fastest to 
>> develop in?' are hard to answer definitively.
>
> True. You might start by asking which lets you write the fewest LOC, as 
> studies during the 70s showed that programmers tended to write the same 
> number of LOC/day, regardless of the language chosen.
>
> The problem with the LOC measurement is that the most productive days 
> are the ones where you refactor and eliminate a thousand LOC. That sort 
> of throws the whole thing off.

As in:

http://www.folklore.org/StoryView.py?project=Macintosh&story=Negative_2000_Lines_Of_Code.txt

Perhaps the real question, then, is which language allows you to delete 
lines of code most quickly.

tom

-- 
find porn apricot
-- 
http://mail.python.org/mailman/listinfo/python-list


Use cases for del

2005-07-06 Thread Peter Hansen
Tom Anderson wrote:
> How about just getting rid of del? Removal from collections could be 
> done with a method call, and i'm not convinced that deleting variables 
> is something we really need to be able to do (most other languages 
> manage without it).

Arguing the case for del: how would I, in doing automated testing, 
ensure that I've returned everything to a "clean" starting point in all 
cases if I can't delete variables?  Sometimes a global is the simplest 
way to do something... how do I delete a global if not with "del"?

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


Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Peter Hansen
Tom Anderson wrote:
> Perhaps the real question, then, is which language allows you to delete 
> lines of code most quickly.

No, then the question becomes "which language allows you to quickly 
write very many lines of code which then have to be deleted".

Of course, writing those lines manually would be silly if you could 
automate the process.  After all, the lines of code aren't required, so 
they don't really have to do anything, do they?

So naturally Assembly would be the proper way to get maximum performance 
out of your automatic code writing program.

Therefore Assembly is clearly the fastest development language.

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


Re: Good starterbook for learning Python?

2005-07-06 Thread Lennart
Op 6 Jul 2005 06:02:15 -0700 schreef Fuzzyman:

> A book that will stay useful as a referene *after* you've used it to
> learn is 'Programming Python'.
> 
> Best Regards,
> 
> Fuzzy
> http://www.voidspace.org.uk/python

A thanks! 

I've downloaded the book "dive into python". It costs me near 23 euro to
print it by the copyshop (yes, i prefer paper - you can write on paper, you
know :-)

Programming Python will I sell as a book that i read secondly, and use as a
reference. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread François Pinard
[Tom Anderson]

> > del -> delete

> How about just getting rid of del? [...] i'm not convinced that
> deleting variables is something we really need to be able to do

While surely not in every program, I still use `del' often.  Compare:

x = None
del x

when the goal is to cut the reference being held in x.  Both statements
do it, yet the intent is expressed more legibly by the second.

> (most other languages manage without it).

Hardly an excuse against some good ideas Python has on its own! :-)

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best options for oracle/python?

2005-07-06 Thread Paul Boddie
Mark Harrison <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> Any recommendations for Oracle bindings for the
> DB-API 2.0 specification?  This is for Oracle 10g
> if that makes any difference.
> 
> Also, any other Oracle related goodies that might
> be useful?

You might want to check out the database topic guide for Python...

http://www.python.org/topics/database/modules.html

...as well as the DB-SIG resources and mailing list:

http://www.python.org/sigs/db-sig/
http://mail.python.org/pipermail/db-sig/

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


Re: best options for oracle/python?

2005-07-06 Thread Grig Gheorghiu
Use cx_Oracle: 

Grig

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


Re: Use cases for del

2005-07-06 Thread Jp Calderone
On Wed, 06 Jul 2005 09:45:56 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote:
>Tom Anderson wrote:
>> How about just getting rid of del? Removal from collections could be
>> done with a method call, and i'm not convinced that deleting variables
>> is something we really need to be able to do (most other languages
>> manage without it).
>
>Arguing the case for del: how would I, in doing automated testing,
>ensure that I've returned everything to a "clean" starting point in all
>cases if I can't delete variables?  Sometimes a global is the simplest
>way to do something... how do I delete a global if not with "del"?
>

Unless you are actually relying on the global name not being defined, 
"someGlobal = None" would seem to do just fine.

Relying on the global name not being defined seems like an edge case.

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


Re: Tkinter grid layout

2005-07-06 Thread Richard Lewis

On Wed, 06 Jul 2005 11:44:55 +0100, "Richard Lewis"
<[EMAIL PROTECTED]> said:
> Hi there,
> 
> I've got a tree control in Tkinter (using the ESRF Tree module) but I
> can't get it to layout how I want it.
> 
> I'd like to have it so that it streches north/south (anchored to the top
> and bottom), is of a fixed width and is anchored to the left hand side.
> Here's my code (its derived from one of the examples from the ESRF web
> site):
> 
OK, I've changed it so that the Tree and scroll bars are in a single
Frame and added another Frame on the right hand side to put the rest of
my stuff in. (Though I believe this is against the principles of grid
layout management?)

class MainWindow(Frame):
  def __init__(self, master):
Frame.__init__(self, master)
self.document = # new DOM document
self.create_ui()

  def create_ui(self):
self.master.protocol("WM_DELETE_WINDOW", self.app_quit)

self.pack(fill="both")
self.master.geometry("%dx%d%+d%+d" % (800, 600, 100, 100))
self.master.title("Site Editor")

self.create_menu()

self.create_site_list()

self.rhs_frame = Frame(master=self, background="#FF")
self.rhs_frame.grid(row=0, column=1, sticky=E+W+N+S)
self.grid_columnconfigure(1, weight=1)
self.grid_rowconfigure(0, weight=1)

label = Label(master=self.rhs_frame, text="FOO")
label.grid(row=0, column=0)

  def create_site_list(self):
self.list_model = ListModel(self.document)

self.site_list_frame = Frame(master=self, width=300,
background="#00FF00")
self.site_list_frame.grid(row=0, column=0, sticky=E+W+N+S)

self.site_list = Tree.Tree(master=self.site_list_frame,\
  root_id="root",\
  root_label="Site",\
  get_contents_callback=self.get_list_item,\
  width=300,height=600)

self.site_list.grid(row=0, column=0, sticky=E+W+N+S)

self.site_list_frame.grid_columnconfigure(0, weight=1)
self.site_list_frame.grid_rowconfigure(0, weight=1)

vsb = Scrollbar(self.site_list_frame, orient=VERTICAL)
vsb.grid(row=0, column=1, sticky=NS)
self.site_list.configure(yscrollcommand=vsb.set)
vsb.configure(command=self.site_list.yview)

hsb = Scrollbar(self.site_list_frame, orient=HORIZONTAL)
hsb.grid(row=1, column=0, sticky=EW)
self.site_list.configure(xscrollcommand=hsb.set)
hsb.configure(command=self.site_list.xview)

self.site_list.focus_set()


I noticed that I had a pack() call in my create_ui() function which I
must have pasted in from some example code a while ago. I tried taking
this out (having read that you shouldn't mix pack and grid) but, of
course, then there was no layout (or something) and I just got a blank
window. So I tried using pack(fill="both"). It now fills horizontally
correctly, but it still doesn't anchor with the bottom. I'm not setting
any height for the Tree (if I do then it still doesn't anchor with the
bottom) because I don't want it to have a particular height, just to
fill the window.

Am I heading in the right direction?

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


Re: Use cases for del

2005-07-06 Thread Daniel Dittmar
Peter Hansen wrote:
> Arguing the case for del: how would I, in doing automated testing, 
> ensure that I've returned everything to a "clean" starting point in all 
> cases if I can't delete variables?  Sometimes a global is the simplest 
> way to do something... how do I delete a global if not with "del"?

globals ().__delitem__ (varname)

except that the method would probably be called delete.

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


Re: frozenset question

2005-07-06 Thread Raymond Hettinger
Will McGugan wrote:
> Are there any benefits in using a frozenset over a set, other than it
> being immutable?

No.  The underlying implementation is identical with set.  The only
difference is the addition of a hash method and absence of mutating
methods.  Everything else is the same.


Raymond

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


Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread François Pinard
[Raymond Hettinger]

> [EMAIL PROTECTED] wrote:
>
> > It got me curious if Lisp is inherently faster to develop complex
> > apps in.

> With Lisp or Forth, a master programmer has unlimited power and
> expressiveness.  With Python, even a regular guy can reach for the
> stars.

A few years ago, I much hesitated between Scheme and Python as my next
day-to-day programming language.

My feeling at the time was that Scheme is a very fast language to write
into, and in which one can implement new concepts cleanly and compactly.
Maybe Python is a bit slower to write, but this is compensated by the
fact Python is more legible when it comes to later maintenance, or when
many people have to share work on a big set of sources.

There is some heaviness and complexity in Python internals, Scheme are
purer and simpler by comparison.  On its bright side, Python has a nice
and comprehensive library, and an interesting community of users.  These
probably make most of the difference.

-- 
François Pinard   http://pinard.progiciels-bpi.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: More On - deepcopy, Tkinter

2005-07-06 Thread phil
Thanks, I used some of your methods and believe it is now
working.

I also did a lot of experiments, which I've needed to do,
investigating when references vs values are passed and
returned.  Not as obvious as I thought.

Duncan Booth wrote:

> phil wrote:
> 
> 
>> 
>>
>>>The deepcopy protocol does allow you to specify how complicated
>>>objects should be copied. Try defining __deepcopy__() in your objects
>>>to just copy the reference to the Canvas object instead of the object
>>>itself. 
>>>
>> 
>>I can't figure out from the docs what __deepcopy__ is or how it
>>
>>works.
>>I have about 25 classes of drawn objects. for instance
>>class linefromslope  creates an instance of class line.
>>One of my "ugly solutions" involves a  class prop: within each class,
>>put properties like slope and midpoint within the self.prop instance
>>and making a copy of that.
>>Would __deepcopy__ facilitate this?
>>Or am I assuming too much: is __deepcopy__ just a method
>>I invent to do what I want?
>>
>>
> 
> The docs say:
> 
> 
>>In order for a class to define its own copy implementation, it can
>>define special methods __copy__() and __deepcopy__(). The former is
>>called to implement the shallow copy operation; no additional
>>arguments are passed. The latter is called to implement the deep copy
>>operation; it is passed one argument, the memo dictionary. If the
>>__deepcopy__() implementation needs to make a deep copy of a
>>component, it should call the deepcopy() function with the component
>>as first argument and the memo dictionary as second argument. 
>>
> 
> __deepcopy__ is a method which overrides the default way to make a deepcopy 
> of an object.
> 
> So, if you have a class with attributes a, b, and c, and you want to ensure 
> that deepcopy copies a and b, but doesn't copy c, I guess you could do 
> something like:
> 
> 
class MyClass:

>_dontcopy = ('c',) # Tuple of attributes which must not be copied
> 
>def __deepcopy__(self, memo):
>   clone = copy.copy(self) # Make a shallow copy
>   for name, value in vars(self).iteritems():
>   if name not in self._dontcopy:
>   setattr(clone, name, copy.deepcopy(value, memo))
>   return clone
> 
> 
class Copyable(object):

>   def __new__(cls, *args):
>   print "created new copyable"
>   return object.__new__(cls, *args)
> 
>   
> 
m = MyClass()
m.a = Copyable()

> created new copyable
> 
m.b = Copyable()

> created new copyable
> 
m.c = Copyable()

> created new copyable
> 
clone = copy.deepcopy(m)

> created new copyable
> created new copyable
> 
m.a is clone.a

> False
> 
m.c is clone.c

> True
> 
> 
> As you can see, the deepcopy only creates deep copies of 2 of the 3 
> attributes, 'c' is simply copied across as a shallow copy.
> 
> and if you subclass MyClass you can modify the _dontcopy value to add 
> additional attributes which must not be copied.
> 



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


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Tom Anderson wrote:

>> del -> delete
> 
> 
> How about just getting rid of del? Removal from collections could be 
> done with a method call, and i'm not convinced that deleting variables 
> is something we really need to be able to do (most other languages 
> manage without it).

Since this is a Python 3k item...  What would be the consequence of 
making None the default value of an undefined name?  And then assigning 
a name to None as a way to delete it?

Some benefits
=

*No more NamesError exceptions!

 print value
 >> None

 value = 25
 print value
 >> 25

 value = None#same as 'del value'


*No initialization needed for a while loop!

 While not something:
 if :
 something = True


*Test if name exists without using a try-except!

 if something == None:
 something = value


*And of course one less keyword!


Any drawbacks?


Cheers,
Ron

PS...  not much sleep last night, so this may not be well thought out.

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


Re: threads and sleep?

2005-07-06 Thread Grant Edwards
On 2005-07-06, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Tue, 05 Jul 2005 16:01:23 -, Grant Edwards <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>> Or is the Python interpreter actually doing the context
>> switches itself?
>
> It would seem to be close to doing that, if it has that internal
> "quantum" of releasing the GIL every 100 bytecodes...

Right, but I think that's just _allowing_ a context switch
rather than performing one.  The other interpreters are blocked
waiting for the GIL and releasing it lets one of them run.
Though the effect is pretty much the same, it's quite different
than having a single interpreter that does the scheduling and
context switching itself within a single OS process/thread.

> At the least, the GIL release/reacquire would be similar to
> having a C-language program doing sleep() to let other tasks
> run. I'll admit that I don't know if creating a Python thread
> also creates a new interpreter from scratch (after all,
> Windows doesn't have a fork() operation).

If I were doing it, I don't think I'd use fork() and create a
second address space. I'd use a "lightweight" thread.  All of
the interpreter instances would share a single address space.
I know that Win32 has threads.

> It may be that the GIL toggle is part of a thread state
> save/restore operation, and could thereby be looked on as a
> high-level context switch with the OS-level context switch
> basically selecting from the threads blocked on the GIL.

Right -- I think that's what's hapenning.  I really ought to go
look at the CPython source code instead of just sputing
conjecture.

> {I'm going to louse up the message tracking here by pasting part of your
> follow-up into one response}
>
> 2> Upon further thought, that just can't be the case.  There has
> 2> to be multiple instances of the intepreter because the
> 2> interpreter can make C system calls that block (thus blocking
> 2> that instance of the interpreter). Other Python threads within
> 2> the program continue to run, so there must be multiple Python
> 2> intepreters.
>
>   From the documentation: 
>
> """
> The lock is also released and reacquired around potentially blocking I/O
> operations like reading or writing a file, so that other threads can run
> while the thread that requests the I/O is waiting for the I/O operation
> to complete. 
> """

I know. I've worked on modules that release the GIL and call
blocking operations.  My point is that when an interpreter
calls a blocking operation, the interpreter itself blocks.  It
stops running.  It goes to sleep.  But, other Python threads
keep running, so there must be other interpreters running those
threads.

> Otherwise, I'd say convert the number cruncher to a compiled
> module that can be started as a Python thread, drop into the
> compiled code, give up the GIL, and crunch away -- only
> acquiring the GIL when it has results to give back.

Unfortunately that means you've got to debug a number cruncher
that's written in C.

-- 
Grant Edwards   grante Yow!  I'm shaving!! I'M
  at   SHAVING!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: threads and sleep?

2005-07-06 Thread Grant Edwards
On 2005-07-06, Alex Stapleton <[EMAIL PROTECTED]> wrote:

> Is SYS V shared memory a totalyl stupid way of doing distributed locks
> between processes then?

Sys V semaphores would seem to be a more logical choice.

-- 
Grant Edwards   grante Yow!  I'm pretending I'm
  at   pulling in a TROUT! Am I
   visi.comdoing it correctly??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Dan Sommers
On Wed, 06 Jul 2005 14:33:47 GMT,
Ron Adam <[EMAIL PROTECTED]> wrote:

> Since this is a Python 3k item...  What would be the consequence of
> making None the default value of an undefined name?  And then assigning
> a name to None as a way to delete it?

[ ... ]

> Any drawbacks?

Lots more hard-to-find errors from code like this:

filehandle = open( 'somefile' )
do_something_with_an_open_file( file_handle )
filehandle.close( )

Regards,
Dan

-- 
Dan Sommers

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


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Steven Bethard
Terry Hancock wrote:
> And a syntax just occured to me -- what about this:
> 
> [y*x for x,y]
> 
> ?
> 
> (that is:
> 
> [ for ]

If you haven't already, see:

http://wiki.python.org/moin/AlternateLambdaSyntax

for other similar proposals.

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


Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-06 Thread Steven Bethard
Ron Adam wrote:
> Yes, I think a different key word would help.  My current favorite 
> alternative is to put it in parentheses similar to list comprehensions 
> and use "let".
> 
> (let x,y return x+y)

If you haven't already, see:

http://wiki.python.org/moin/AlternateLambdaSyntax

for other similar proposals.

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


Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Rocco Moretti
Raymond Hettinger wrote:
> [EMAIL PROTECTED] wrote:
> 
>>The problem is that questions like 'What lang is fastest to develop
>>in?'
>>are hard to answer definitively.
> 
> 
> FWIW, Google's answer to that question is C++, Java, and Python.  For
> any given problem, any of the three are acceptable.  Each programmer or
> engineering team gets to decide based on his or her language
> expertise.*

Actually, Google's answer to that question is something called "ILOG 
CPLEX", followed by Visual Basic, English as a second language, PHP, and 
"Holt Software Associates". ;-)

http://www.google.com/search?hl=en&q=What+language+is+fastest+to+develop+in%3F&btnG=Google+Search

Given this finding, I'm not sure I should put much weight into Google 
search results anymore ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: threads and sleep?

2005-07-06 Thread Grant Edwards
On 2005-07-06, Peter Hansen <[EMAIL PROTECTED]> wrote:

>>>Or is the Python interpreter actually doing the context
>>>switches itself?
>> 
>> Upon further thought, that just can't be the case.  There has
>> to be multiple instances of the intepreter because the
>> interpreter can make C system calls that block (thus blocking
>> that instance of the interpreter). Other Python threads within
>> the program continue to run, so there must be multiple Python
>> intepreters.
>
> Maybe you should consider and explain what you mean by
> "multiple interpreters"?

That in a multi-theraded Python program, the code that
impliments the Python VM is executing "simultaneously" in
multiple contexts: one for each thread (and possibly one master
thread).

I was responding to somebody who said that there were two issue
with using multiple CPUs:

  1) the interpreter (singular) only ran on one CPU.

  2) the GIL.  

My point was that 1) couldn't be true.  There must be multiple
instances of the interpreter since in a multi-threaded Python
program, the interpeter blocks when making libc calls like
read() write() recv() send(), and yet other Python threads
continue to run.  If there _were_ only a single interpeter, and
it ran only on a single CPU, then the GIL wouldn't be needed.
  
> As I understand the concept, and based on my several years'
> old reading of the virtual machine code, I wouldn't say there
> are multiple interpreters.
>
> There's a reason the GIL is the *global* interpreter lock...

Exactly.

-- 
Grant Edwards   grante Yow!  I've been WRITING
  at   to SOPHIA LOREN every 45
   visi.comMINUTES since JANUARY 1ST!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Use cases for del

2005-07-06 Thread Duncan Booth
Peter Hansen wrote:

> Tom Anderson wrote:
>> How about just getting rid of del? Removal from collections could be 
>> done with a method call, and i'm not convinced that deleting variables 
>> is something we really need to be able to do (most other languages 
>> manage without it).
> 
> Arguing the case for del: how would I, in doing automated testing, 
> ensure that I've returned everything to a "clean" starting point in all 
> cases if I can't delete variables?  Sometimes a global is the simplest 
> way to do something... how do I delete a global if not with "del"?
> 
I generally find that unit tests force me to structure the code in a 
cleaner manner, e.g. to not use globals as much, but if you do need to 
delete a global you do it in exactly the same way as you delete anything: 
use the "del" statement:

>>> x = 3
>>> def f():
global x
del x


>>> x
3
>>> f()
>>> x

Traceback (most recent call last):
  File "", line 1, in -toplevel-
x
NameError: name 'x' is not defined
>>> 

Where I have used 'del' in a unit test it has been to delete local 
variables rather than globals. Specifically I wanted to ensure that some 
data structures were being torn down properly, so the test went something 
like this:

setup: creates a weakref dictionary.

teardown: asserts that the weakref dictionary is empty.

then each test does:

  try:
create something
add it to the weakref dictionary
then test it
  finally:
use del to remove local variables
force a garbage collection

Without the del, when a test fails you get two failures, because the 
traceback information keeps the variables alive.
-- 
http://mail.python.org/mailman/listinfo/python-list


Deleting variables [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-06 Thread Steven D'Aprano
On Wed, 06 Jul 2005 14:28:55 +0100, Tom Anderson wrote:

>> del -> delete
> 
> How about just getting rid of del? Removal from collections could be done 
> with a method call, 

Which would be called object.del() I presume. And that opens a big
can of worms.

Suppose we have a list L = [4, 3, 2, 1, 0], what should L.del(1) do?

It looks like it should result in L becoming [4, 3, 2, 0]. An easy mistake
to make, if you forget that the argument is (presumably) an index.
You could make it clear by insisting on L.del[1] but that requires a big
change in Python's syntax.

What should L.del() do, with no arguments? Raise an error? 

Now, you have something like this:

class thing:
pass
obj = thing()
obj.alpha = [4, 3, 2, 1, 0]
obj.beta = 5

Python's object model suggests that obj.alpha.del() should call
alpha's del method, in the same way that obj.alpha.append() would call
alpha's append method.

So how do you delete obj.alpha? obj.del("alpha") might work. But what if
obj itself is a mapping, with a key "alpha" as well as an attribute alpha.
Which one should obj.del("alpha") delete?

Now, if you said that L.del() should raise an exception earlier, what
about obj.beta.del()?


Presumably every object automatically has a del method, so you
don't have to program a del method yourself. obj.del is a method object.
So it has a del method. (Yes, sometimes you want to delete methods.
Functions are first class objects in Python.) Which has a del method.
Which has a del method. 

What should obj.del.del.del.del.del.del.del.del.del() do?


> and i'm not convinced that deleting variables is 
> something we really need to be able to do (most other languages manage 
> without it).

Most other languages don't have namespaces that can get polluted, or
on-the-fly creation of variables. Most other languages don't consider
variables to be simply attributes of a module object. And most other
languages don't allow you to run interactive sessions where it is easy to
mistakenly make variables you don't want.

py> x = 1
py> u = x+2  # oops, typo, meant y not u
py> del u  # prevent confusion in the programmer's mind

It is also useful sometimes to delete a module object from the top level
namespace before re-importing it, rather than merely reloading it. That
requires being able to delete a variable.

In summary: del being a keyword works. del() being an object method is
unclear, confusing and complicated.


-- 
Steven.


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


Re: Lisp development with macros faster than Python development?..

2005-07-06 Thread Dan Sommers
On Wed, 06 Jul 2005 08:27:55 -0500,
Larry Bates <[EMAIL PROTECTED]> wrote:

[ reusable, stable, debugged, and documented libraries are a Good
Thing ]

Absolutely.

Two related stories from my days working as a software engineer for a
large telecomm company.  Both stories begin with the annual ritual of
management telling us that code reuse was the silver bullet of software
development.

1.  We replied that we needed about 5 calendar years to design, develop,
debug, and document sufficient libraries to pay for the effort.  Then
management would tell us that 5 years is too long, and the project(s)
would be scrapped.  I worked there for 12 years, and was still watching
new hires argue over linked list code and build tools when I left.

2.  Right after that (and often in the same speech), management would
also tell us that they would be measuring our productivity by (a) LOC
written rather than LOC reused, and (b) the number of new ideas and code
we submitted for patent.  There is no better example of a Mixed Message.

(Not to mention that we did all or most of our coding in C and C++, and
every department and every project had its own method(s) of determining
what a Line Of Code looked like, but that's even farther off-topic)

Regards,
Dan

-- 
Dan Sommers

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


Re: threads and sleep?

2005-07-06 Thread Jeffrey Maitland
Thanks for the info.

I was doing some more diggging and I came across  a module/class 
called POSH which should allow me to do what I want.  My question now
is, has anyone here used this and if so what it as easy to implement
as what I am reading it is? (I have to wait for the sys admin to
install the module on that server, but I have made a modified
implemted the syntax into a copy of the code to test it as soon as the
admin installs it.)

Once again thanks for the information that you all have shared.

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


Re: Favorite non-python language trick?

2005-07-06 Thread Edvard Majakari

(sorry, my NUA had lost the original article)
>
>> I'm curious -- what is everyone's favorite trick from a non-python
>> language? And -- why isn't it in Python?

Ability to tag some methods 'deprecated' as in Java (from 1.5
onwards?). However, Python interpreter doesn't have to do it: pydoc and
similar tools could detect, say, '@deprecated' in method comment string and
warn user about it.

Currently I just document deprecated methods, and if I feel like it, I also
add

def some_method_which_is_badly_named_or_just_plain_wrong(..)
"""docstring

This method is now deprecated. Use frob() instead.
"""

sys.stderr.write('warning: method 
some_method_which_is_badly_named_or_just_plain_wrong is now deprecated')


-- 
# Edvard Majakari   Software Engineer
# PGP PUBLIC KEY available  Soli Deo Gloria!
You shouldn't verb verbs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Use cases for del

2005-07-06 Thread Steven D'Aprano
On Wed, 06 Jul 2005 10:00:02 -0400, Jp Calderone wrote:

> On Wed, 06 Jul 2005 09:45:56 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote:
>>Tom Anderson wrote:
>>> How about just getting rid of del? Removal from collections could be
>>> done with a method call, and i'm not convinced that deleting variables
>>> is something we really need to be able to do (most other languages
>>> manage without it).
>>
>>Arguing the case for del: how would I, in doing automated testing,
>>ensure that I've returned everything to a "clean" starting point in all
>>cases if I can't delete variables?  Sometimes a global is the simplest
>>way to do something... how do I delete a global if not with "del"?
>>
> 
> Unless you are actually relying on the global name not being defined, 
> "someGlobal = None" would seem to do just fine.
> 
> Relying on the global name not being defined seems like an edge case.

Er, there is a lot of difference between a name not existing and it being
set to None.

$ cat mymodule1.py

# define some temporary names
a, b, c, d, e, f = 1, 2, 3, 4, 5, 6
# do some work
result = a+b+c+d*e**f
# delete the temp variables
del a
del b
del c
del d
del e
del f

$ cat mymodule2.py

# define some temporary names
a, b, c, d, e, f = 1, 2, 3, 4, 5, 6
# do some work
result = a+b+c+d*e**f
# delete the temp variables
a = None
b = None
c = None
d = None
e = None
f = None

Now import them into Python:

py> import mymodule1, mymodule2
py> dir(mymodule1)
['__file__', '__name__', result]
py> dir(mymodule2)
['__file__', '__name__', result, a, b, c, d, e, f]

Or worse, do this:

py> a = 1
py> from mymodule2 import *
py> a + 1
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

It is bad enough that from module import * can over-write your variables
with the modules' variables, but for it to do so with DELETED variables is
unforgivable.



-- 
Steven.

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


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Dan Sommers wrote:

> On Wed, 06 Jul 2005 14:33:47 GMT,
> Ron Adam <[EMAIL PROTECTED]> wrote:
> 
> 
>>Since this is a Python 3k item...  What would be the consequence of
>>making None the default value of an undefined name?  And then assigning
>>a name to None as a way to delete it?
> 
> 
> [ ... ]
> 
> 
>>Any drawbacks?
> 
> 
> Lots more hard-to-find errors from code like this:
> 
> filehandle = open( 'somefile' )
> do_something_with_an_open_file( file_handle )
> filehandle.close( )
> 
> Regards,
> Dan


If do_something_with_an_open_file() is not defined. Then you will get:

 TypeError: 'NoneType' object is not callable


If "file_handle" (vs "filehandle") is None.  Then you will still get an 
error as soon as you tried to use the invalid file handle.

 AttributeError: 'NoneType' object has no attribute 'read'


If the error was filehundle.close()  you will get:

 AttributeError: 'NoneType' object has no attribute 'close'


I don't think any of those would be hard to find.


Cheers,
Ron



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


Re: Favorite non-python language trick?

2005-07-06 Thread Thomas Heller
Edvard Majakari <[EMAIL PROTECTED]> writes:

> (sorry, my NUA had lost the original article)
>>
>>> I'm curious -- what is everyone's favorite trick from a non-python
>>> language? And -- why isn't it in Python?
>
> Ability to tag some methods 'deprecated' as in Java (from 1.5
> onwards?). However, Python interpreter doesn't have to do it: pydoc and
> similar tools could detect, say, '@deprecated' in method comment string and
> warn user about it.

I don't see what's wrong with this code, and if one wanted, one could
also implement a decorator which calls warnings.warn when the function
is called:

def c_buffer(init, size=None):
"deprecated, use create_string_buffer instead"
import warnings
warnings.warn("c_buffer is deprecated, use create_string_buffer instead",
  DeprecationWarning, stacklevel=2)
return create_string_buffer(init, size)

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


Re: Favorite non-python language trick?

2005-07-06 Thread Edvard Majakari
Thomas Heller <[EMAIL PROTECTED]> writes:

> I don't see what's wrong with this code, and if one wanted, one could
> also implement a decorator which calls warnings.warn when the function
> is called:
>
> def c_buffer(init, size=None):
> "deprecated, use create_string_buffer instead"
> import warnings
> warnings.warn("c_buffer is deprecated, use create_string_buffer instead",
>   DeprecationWarning, stacklevel=2)
> return create_string_buffer(init, size)

Well, nothing's wrong there, and the same could be done with Java
before. However, having a consistent deprecated string everywhere allows
easier eg. automatic finding of such methods from documentation. 

Decorators also help here, but that requires version 2.3 or newer (which
usually isn't a problem, but can be)

Hey! I hadn't realized category parameter nor stacklevel in warnings module
(just used a few times, never read the doc because I didn't need to). Neat,
thanks.

-- 
# Edvard Majakari   Software Engineer
# PGP PUBLIC KEY available  Soli Deo Gloria!

$_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n";
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter grid layout

2005-07-06 Thread Eric Brunel
On Wed, 06 Jul 2005 11:44:55 +0100, Richard Lewis <[EMAIL PROTECTED]> wrote:

> Hi there,
>
> I've got a tree control in Tkinter (using the ESRF Tree module) but I
> can't get it to layout how I want it.
>
> I'd like to have it so that it streches north/south (anchored to the top
> and bottom), is of a fixed width and is anchored to the left hand side.
> Here's my code (its derived from one of the examples from the ESRF web
> site):
>
> class MainWindow(Frame):
[snip code]

First of all, it is not a good idea to make your so-called window inherit from 
Frame: a Frame is not a window in tk, but a generic container. Creating a Frame 
without a container window will automatically initialize the tk toolkit, 
creating a default window which will become the default parent for widgets 
where you don't specify one. According to the well-known "explicit is better 
than implicit" principle, if a MainWindow instance are actually the main window 
for your application, you'd really better inherit from the Tkinter class for 
the main window, which is Tk. Doing it this way has a lot of advantages over 
what you do; for example, if you later have to create a menu bar for your 
application, you will be able to do it in the MainWindow class. If you inherit 
from Frame, you won't get any access to the actual window, so you won't be able 
to create a menu in it.

This may seems to be unrelated to your problem, but it's not: by creating a 
Frame, you introduce one more unneeded container. So, in some code you don't 
show here, you have to insert the MainWindow instance into its parent window 
via a call to its pack or grid method. Since the code you show seems to be 
correct, I guess the problem is in this call to pack or grid, which probably 
does not tell the Frame how to behave when its parent window is resized, 
causing it to get the default behaviour, which is "do nothing at all".

To be sure this actually is the problem, try to replace the line:
Frame.__init__(self, master)
in MainWindow.__init__ by:
Frame.__init__(self, master, bg='blue', bd=2)
This way, a blue border will appear around the frame, allowing you to see how 
it grows.
Then run your application, and resize the window. You should see that the frame 
does not grow when the window grows, explaining why your tree deos not grow (in 
fact, it would grow if its container did; but its container doesn't...)

So you should either make your MainWindow class inherit from Tk, which 
eliminates the unneeded container and the problems it may cause, or make sure 
the pack or grid on your MainWindow instance actually tells the container to 
grow with its container. With pack, it's quite easy: just do 
myWindow.pack(fill=BOTH, expand=1). With grid, it's a bit more complicated, 
since you will have to configure the grid on the container.

But basically, my advice would be:
- Never make your windows inherit from Frame; make them inherit from Tk for the 
main window or from Toplevel for all other ones
- When you have resize problems, always check the whole widget hierarchy from 
the actual window down to the widget showing the problem. The cause is very 
often not on the widget itself, but on one of its containers.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in 
'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


latex/bibtex python paper?

2005-07-06 Thread schwehr
Hi All,

Does anyone have a good template that I might use for writing a python
paper in latex/bibtex?  I've got the paper mostly done, but am having
issues with the references.  I am definitely not an expert at
latex/bibtex.  Right now, I have references defined like this:

@article{imp,
  title = {imp -- Access the import internals},
  journal = "http://www.python.org/doc/current/lib/module-imp.html";,
  author = {Python Software Foundation},
  year = {2005}
}

When I cite these, I get something like this (Foundation[2005]).  Is
anyone willing to offer up a tarball of a complete paper with sty and
bst that would make for a nice python paper?

Thanks!
-kurt
http://schwehr.org/software/segy-py

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


Re: Favorite non-python language trick?

2005-07-06 Thread Simon Brunning
On 7/6/05, Edvard Majakari <[EMAIL PROTECTED]> wrote:
> Ability to tag some methods 'deprecated' as in Java (from 1.5
> onwards?). However, Python interpreter doesn't have to do it: pydoc and
> similar tools could detect, say, '@deprecated' in method comment string and
> warn user about it.

http://wiki.python.org/moin/PythonDecoratorLibrary?#head-de01988728ccdec415708f10928cc6feb022e7bb

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


Re: adding a character to the last string element of a list

2005-07-06 Thread Philippe C. Martin
Thanks,

Philippe


Peter Hansen wrote:

> Philippe C. Martin wrote:
>> I guess my slicing was wrong, l[-1] worked
> 
> Note that that's _not_ a slice, however, but a reference to the last
> element in the list.
> 
> You'd have to subclass list to be able to do something with
> "reference-slices".  Probably returning a special object from
> __getslice__ which itself has references back to the original list and
> implements any changes back in the original instead of in itself.  I
> haven't tried to imagine if this is even feasible.
> 
> Anything "indexing" with : in it is a slice, so a copy, while anything
> with only a single index as you have in l[-1] is just a reference to one
> element in the list.
> 
> -Peter

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


Re: frozenset question

2005-07-06 Thread Steven D'Aprano
On Wed, 06 Jul 2005 14:25:30 +0100, Will McGugan wrote:

>> But if you are just trying to optimize for the sake of optimization,
>> that's a terrible idea. Get your program working first. Then when it
>> works, measure how fast it runs. If, and ONLY if, it is too slow, 
>> identify the parts of the program that make it too slow. That means
>> profiling and timing. Then optimize those parts, and nothing else.
>> 
>> Otherwise, you will be like the car designer trying to speed up his sports
>> cars by making the seatbelts aerodynamic.
> 
> No need for the 'premature optimization is the root of all evil' speech. 
> I'm not trying to optimize anything - just enquiring about the nature of 
> frozenset. If typing 'frozenset' over 'set' gave me a saving in time or 
> memory (even if tiny) I would favour immutable sets, where appropriate.

Well, obviously the "premature optimization" speech just went in one ear
and out the other. "Saving in time or memory" is what optimization is
about. What did you think optimization means?

set and frozenset have different functionality (one is mutable, the other
is not) and use cases (you use one where you need to dynamically add and
remove items from a set, and the other where you need to use a set as a
key in a dictionary). In most cases, they aren't interchangable. While
you're spending time worrying about shaving a thousandth of a millisecond
off a program that takes five seconds to run, I'll get on with development
using the right object for the functionality needed.



-- 
Steven.

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


Re: Create datetime instance using a tuple.

2005-07-06 Thread Dan Bishop
Qiangning Hong wrote:
> On 6 Jul 2005 02:01:55 -0700, Negroup <[EMAIL PROTECTED]> wrote:
> > Hi, all.
> > I would like to know if it is possible to create a datetime instance
> > using a tuple instead of single values.
> >
> > I mean:
> > >>> from datetime import datetime
> > >>> t = (1, 2, 3)
> > >>> dt = datetime(t)
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> > TypeError: function takes at least 3 arguments (1 given)
> >
> > (class datetime(year, month, day[, hour[, minute[, second[,
> > microsecond[, tzinfo])
>
> Use:
> dt = datetime(*t)

It's better to write:

dt = datetime(*t[:6])

This gives you compatibility with the (year, month, day, hour, minute,
second, weekday, julian_day, dst) tuples returned by time.gmtime,
time.localtime, and time.strptime.

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


Conditionally implementing __iter__ in new style classes

2005-07-06 Thread Thomas Heller
I'm trying to implement __iter__ on an abstract base class while I don't
know whether subclasses support that or not.
Hope that makes sense, if not, this code should be clearer:

class Base:
def __getattr__(self, name):
if name == "__iter__" and hasattr(self, "Iterator"):
return self.Iterator
raise AttributeError, name

class Concrete(Base):
def Iterator(self):
yield 1
yield 2
yield 3

The idea is that if a subclass of Base defines an 'Iterator' method,
instances are iterable.  They are not iterable otherwise.

The above gives the expected behaviour: iter(Base()) raises a
"TypeError: iteration over non-sequence", and iter(Concrete()) returns a
generator.

If, however, I make Base a newstyle class, this will not work any
longer.  __getattr__ is never called for "__iter__" (neither is
__getattribute__, btw).  Probably this has to do with data descriptors
and non-data descriptors, but I'm too tired at the moment to think
further about this.

Is there any way I could make the above code work with new style
classes?

Thanks,

Thomas

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


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Devan L
> Here's a couple of examples from my own code:
>
> # from a Banzhaf Power Index calculator
> # adds things that aren't numbers
> return reduce(operator.add,
> (VoteDistributionTable({0: 1, v: 1}) for v in electoral_votes))

return sum([VoteDistributionTable({0:1, v:1} for v in
electoral_votes],VoteDistributionTable({}))
Any time you use operator.add, you can probably use
sum(sequence,initialvalue)

> # from a custom numeric class
> # converts a tuple of digits into a number
> mantissa = sign * reduce(lambda a, b: 10 * a + b, mantissa)

I'll admit I can't figure out a way to replace reduce without writing
some ugly code here, but I doubt these sorts of things appear often.

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


Re: Conditionally implementing __iter__ in new style classes

2005-07-06 Thread Thomas Heller
Thomas Heller <[EMAIL PROTECTED]> writes:

> I'm trying to implement __iter__ on an abstract base class while I don't
> know whether subclasses support that or not.
> Hope that makes sense, if not, this code should be clearer:
>
> class Base:
> def __getattr__(self, name):
> if name == "__iter__" and hasattr(self, "Iterator"):
> return self.Iterator
> raise AttributeError, name
>
> class Concrete(Base):
> def Iterator(self):
> yield 1
> yield 2
> yield 3
>
> The idea is that if a subclass of Base defines an 'Iterator' method,
> instances are iterable.  They are not iterable otherwise.
>
> The above gives the expected behaviour: iter(Base()) raises a
> "TypeError: iteration over non-sequence", and iter(Concrete()) returns a
> generator.
>
> If, however, I make Base a newstyle class, this will not work any
> longer.  __getattr__ is never called for "__iter__" (neither is
> __getattribute__, btw).  Probably this has to do with data descriptors
> and non-data descriptors, but I'm too tired at the moment to think
> further about this.
>
> Is there any way I could make the above code work with new style
> classes?

I forgot to mention this: The Base class also implements a __getitem__
method which should be used for iteration if the .Iterator method in the
subclass is not available.  So it seems impossible to raise an exception
in the __iter__ method if .Iterator is not found - __iter__ MUST return
an iterator if present.

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


Re: Conditionally implementing __iter__ in new style classes

2005-07-06 Thread harold fellermann
> I'm trying to implement __iter__ on an abstract base class while I 
> don't
> know whether subclasses support that or not.
> Hope that makes sense, if not, this code should be clearer:
>
> class Base:
> def __getattr__(self, name):
> if name == "__iter__" and hasattr(self, "Iterator"):
> return self.Iterator
> raise AttributeError, name
>
> class Concrete(Base):
> def Iterator(self):
> yield 1
> yield 2
> yield 3

I don't know how to achieve it, but why don't you simply use

class Base:
pass

class Concrete(Base):
def __iter__(self) :
yield 1
yield 2
yield 3


What is the advantage to have a baseclass that essentially does
some method renaming __iter__ ==> Iterator?

- harold -

--
Always remember that you are unique;
just like everyone else.
--

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


Re: Use cases for del

2005-07-06 Thread Ron Adam
Steven D'Aprano wrote:
> On Wed, 06 Jul 2005 10:00:02 -0400, Jp Calderone wrote:
> 
> 
>>On Wed, 06 Jul 2005 09:45:56 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote:
>>
>>>Tom Anderson wrote:
>>>
How about just getting rid of del? Removal from collections could be
done with a method call, and i'm not convinced that deleting variables
is something we really need to be able to do (most other languages
manage without it).
>>>
>>>Arguing the case for del: how would I, in doing automated testing,
>>>ensure that I've returned everything to a "clean" starting point in all
>>>cases if I can't delete variables?  Sometimes a global is the simplest
>>>way to do something... how do I delete a global if not with "del"?
>>>
>>
>>Unless you are actually relying on the global name not being defined, 
>>"someGlobal = None" would seem to do just fine.
>>
>>Relying on the global name not being defined seems like an edge case.
> 
> 
> Er, there is a lot of difference between a name not existing and it being
> set to None.

Yes, they are not currently the same thing.


But what if assigning a name to None actually unbound it's name?


And accessing an undefined name returned None instead of a NameError?


Using an undefined name in most places will still generate some sort of 
an None type error.

I think the biggest drawback to this second suggestion is that we would 
have to test for None in places where it would matter, but that's 
probably a good thing and enables checking if a variable exists without 
using a try-except.


$ cat mymodule2.py

# define some temporary names
a, b, c, d, e, f = 1, 2, 3, 4, 5, 6
# do some work
result = a+b+c+d*e**f
# delete the temp variables
a = b = c = d = e = f = None# possibly unbind names

This would work if None unbound names.


> It is bad enough that from module import * can over-write your variables
> with the modules' variables, but for it to do so with DELETED variables is
> unforgivable.

Yes, I agree using None as an alternative to delete currently is 
unacceptable.

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


Re: How do you program in Python?

2005-07-06 Thread Dan
On 7/6/2005 5:38 AM, Jorgen Grahn wrote:
> On Sun, 03 Jul 2005 17:35:16 +0100, anthonyberet <[EMAIL PROTECTED]> wrote:
> ...
> 
>>What I would really like is something like an old-style BASIC 
>>interpreter, in which I could list, modify and test-run sections of 
> 

You probably want to check out Wing IDE 2.0.  There is a free trial.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conditionally implementing __iter__ in new style classes

2005-07-06 Thread infidel
I'm not sure I understand why you would want to.  Just don't define
__iter__ on your newstyle class and you'll get the expected behavior.

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


Re: Programmers Contest: Fit pictures on a page

2005-07-06 Thread tassach
Don wrote:
> Chung Leong wrote:
>
> > Isn't that an NP-complete problem or am I crazy?
>
> It is NP complete. Its known as the "cutting stock problem" (aka "Knapsack
> problem"). Here's a Wikipedia page that describes it:
>
> http://en.wikipedia.org/wiki/Cutting_stock_problem
>
> There are commerical applications available that "solve" the problem in 2D
> for use in the woodworking industry (among others). This is generally done
> to minimize waste when cutting down panels (plywood, etc) into smaller
> pieces for cabinets, etc.
>
> -Don

For photos, it's a lot simpler, assuming you only want make standard
size prints (IE: 8x10, 5x7, 4x6, 2.5x3.5).  There are a very limited
number of combinations of the standard print sizes which will fit on an
8.5x11 sheet of paper.  This could probably be solved pretty easily
with just a lookup table.

Also, you have to remember that paper cost is only part of the equation
when printing photos -- you also have to consider ink costs.  In the
stock cutting problem, it's assumed that the cutting cost is
insignificant.  Given the insane cartidge costs for inkjet printers,
wasting a little paper -- even expensive paper -- is likely to be a
more economical than wasting ink.

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


Re: Conditionally implementing __iter__ in new style classes

2005-07-06 Thread infidel
Why not define an Iterator method in your Base class that does the
iteration using __getitem__, and any subclass that wants to do
something else just defines its own Iterator method?  For that matter,
you could just use the __iter__ methods of Base and Concrete instead of
a separate method.

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


Re: Tkinter grid layout

2005-07-06 Thread Richard Lewis

On Wed, 06 Jul 2005 17:36:01 +0200, "Eric Brunel"
<[EMAIL PROTECTED]> said:
> On Wed, 06 Jul 2005 11:44:55 +0100, Richard Lewis
> <[EMAIL PROTECTED]> wrote:
> 
> > Hi there,
> >
> > I've got a tree control in Tkinter (using the ESRF Tree module) but I
> > can't get it to layout how I want it.
> >
> > I'd like to have it so that it streches north/south (anchored to the top
> > and bottom), is of a fixed width and is anchored to the left hand side.
> > Here's my code (its derived from one of the examples from the ESRF web
> > site):
> >
> > class MainWindow(Frame):
> [snip code]
> 
> First of all, it is not a good idea to make your so-called window inherit
> from Frame: a Frame is not a window in tk, but a generic container.
> []
> But basically, my advice would be:
> - Never make your windows inherit from Frame; make them inherit from Tk
> for the main window or from Toplevel for all other ones
> - When you have resize problems, always check the whole widget hierarchy
> from the actual window down to the widget showing the problem. The cause
> is very often not on the widget itself, but on one of its containers.
> 
And very sound advice it turns out to be! I've changed my MainWindow
class to inherit from Tk and now all the layout works fine.

Thanks very much for your help!

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


Re: Conditionally implementing __iter__ in new style classes

2005-07-06 Thread infidel
Something like this:

>>> class Base(object):
... def __getitem__(self, key):
... return key
... def __iter__(self):
... yield self[1]
... yield self['foo']
... yield self[3.0]
...
>>> class ConcreteIterable(Base):
... def __iter__(self):
... yield True
... yield 'Blue'
... yield 'Foo'
...
>>> class ConcreteNotIterable(Base):
... pass
...
>>> [x for x in Base()]
[1, 'foo', 3.0]
>>> [x for x in ConcreteIterable()]
[True, 'Blue', 'Foo']
>>> [x for x in ConcreteNotIterable()]
[1, 'foo', 3.0]
>>>

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


  1   2   3   >