wxPython: Terminal Output -> Scrollable Panel?

2005-07-02 Thread flamesrock
First, I'm very new to gui programming, so please go lightly on me :)

Ok, so far I've settled on wxPython, and what I'd like to do as a first
leap is *convert* a text program into a gui program. It would have a
few buttons as function controls and one main scrollable panel that
acts like a terminal window.

I want to make it so that clicking on a button that performs an
operation will output it to the scrollable wxpython terminal panel, and
(if possible) save that output as text (or maybe into a logfile).

Anyone know how to do this? Like a log window? I've seen something like
this in a program called 'nicotine' but have no idea how to implement
it myself.

-thanks

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


Re: pexpect question....

2005-07-02 Thread Ganesan Rajagopal
> "[EMAIL PROTECTED]" == [EMAIL PROTECTED] com <[EMAIL PROTECTED]> writes:

> Hi,
> I am using pexpect to spawn an interactive program and wait for
> particular string in its output. It works fine but once I get this
> required information, I really don't care about the child process
> anymore. I would effectively want to "detach" from it. 

How about just calling close(), i.e. without wait=1? No need to spawn a new
thread. 

Ganesan

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

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


Re: It seems that ZipFile().write() can only write files, how can empty directories be put into it?

2005-07-02 Thread could ildg
Thank you.

On 7/1/05, Jeff Epler <[EMAIL PROTECTED]> wrote:
> This has been discussed before.  One thread I found was
> http://mail.python.org/pipermail/python-list/2003-June/170526.html
> The advice in that message might work for you.
> 
> Jeff
> 
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shelve in a ZipFile?

2005-07-02 Thread Andreas Kostyrka
Am Freitag, den 01.07.2005, 10:53 -0700 schrieb Scott David Daniels:
> Terry Hancock wrote:
> > I only just recently had a look at the shelve module
> > That would be handy if, for example, I wanted to couple
> > (and compress into the bargain) by putting my two
> > shelf files into a single zip archive.
> 
> You are, however, fooling yourself if you think a shelve
> solution can be made to gracefully interact with a zip-
> compressed version.  In order to zip the shelve data, it
> must all be seen in a pass, so every update would necessarily
> rewrite the entire shelve storage.  much better to extract the
> entire shelve file, operate on it, and re-compress it.
> 
> Even if uncompressed, the zip archive format is not going to
> happily allow you to change the size of any of the "files" it
> stores.

It's even worse: shelve is basically a class that wraps a dictionary. It
provides a dictionary string -> pickable object based on a dictioary
string -> string. bsddb, gdbm etc. probably access files via lowlevel
calls that are not interceptable. 

One way to achieve your goals would be to add compression and/or a key
prefix (which would allow multiple dictionaries or at least key spaces
in one file)

Andreas


> 
> --Scott David Daniels
> [EMAIL PROTECTED]


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: No Subject

2005-07-02 Thread Andreas Kostyrka
Am Freitag, den 01.07.2005, 18:55 +0200 schrieb Harry George: 
> Tom Anderson <[EMAIL PROTECTED]> writes:
> 
> > On Fri, 1 Jul 2005, Adriaan Renting wrote:
> > 
> > > I'm not a very experienced Python programmer yet, so I might be
> > > mistaken, but there are a few things that would make me prefer C++
> > > over Python for large (over 500.000 LOC) projects.
> 
> Strictly in terms of software engineering and language design, Python
> may well be better suited to large projects than C++ or Java.  Code
> re-use, original coding and prototyping, unittests, and peer reviews
> are a lot easier with Python than with C++ or Java.
> 
> The problem is that large projects tend to have portions which are
> performance sensitive.  So a project might be 100K LOC of C with 200K
> LOC of Python.

In my personal opinion, one can often do lowlevel performance code in a
Python-ese way by using Pyrex. And it gets the additional benefit, that
you pay the "higher line count per feature" that C forces on the
developer only for the part that does this lowlevel manipulation.

> They serve the same purpose but are not 1:1 with a file.  I personally
> can't think of a situation where I'd want 2 or more namespaces in a
> physical file, or 2 or more files per namespace.  Therefore I don't
> see any advantage in the C++ approach.

In some ways namespaces are even less flexible as Python modules.

> Templates address (I hesitate to say "solve") static typing by adding
> back the polymorphism that static typing eliminates.
> 
> Python avoids the fix-on-a-fix by doing dynamic strong typing in the
> first place.

Actually C++ templates are a fix. They are one way to avoid the type
system in C++. A template that takes a class argument takes any class
that has all needed "features and methods". Just as in Python. So it's a
crazy kind of compile-time late-binding. And guess, this static typing
in C++ is so sucessful, that many people consider modern C++ to be a
generics oriented language, and not an OO language.

> 
> > 
> > Not that this is necessarily a good thing. I have to say that my Java
> > roots do lead me to think that strong typing is a plus for big
> > projects, since it's a way of defining and enforcing interfaces
> > between bits of code written by different people (or by one person at
> > different times!). Optional static typing in python would be nice for
> > this.
> > 
> 
> Java has nothing on Modula-3.  Talk about strong static typing... It
Well, Java got a VM. And multiple interface "inheritance". And a huge
"standard" library. 

M3 OTOH does have partial type revealing, which allows for more levels
than private, protected and public.
And even more important, M3 has the concept of safe and unsafe
modules/interfaces. Safety in M3-like sense is one of the more important
things in Python. If something goes wrong, in Python you usually just
have to read a traceback. In C/C++ you'll get a core file if you are
lucky. (Or just corrupted data) And if you are even luckier, the stack
in the core file uncorrupted, and you get a sensible backtrace.

In Python OTOH hand, when the traceback is not enough, one can always
work with settrace and other introspection tools.

IMHO languages like Python (or even Java) are a much better approach for
90% of the commercial development. There is just no rational explanation
why an application developer should have to deal with memory allocation
and freeing, dangling pointers, corrupted heaps, and all the other
benefits that C/C++ provide. ;)

> used to take me 3 days to get the first compile to run on a new
> project.
> 
> Yet after years of Modula-3 (and repeatedly seeing strong static typing
> pay off) I found python quite comfortable.  Somehow the problems
> strong static typing addresses aren't a problem.

Yes and no. The problem is that static typing addresses certain
problems, and provides a 90-98% solution. But that makes the remaining
bugs much nastier, because nobody expects them in a "static type
checked" program. Especially the type system of C++ is not powerful
enough to express certain things. On the other hand it provides for
really obscure features. How many C++ developers do know that casting
can change the pointer value? (Hint: Multiple inheritence)

So static typing gives in practice:

a) more lines of code (because variables have to type declared)

b) catches most errors of type errors.

c) forces one sometimes to hack around the type system. (AFAIK void *
hasn't been removed from C++, nor all that ugly casts ;) )

d) makes it harder to find type errors when you get them, because nobody
expects them anymore.

> 
> > > - data hiding
> > 
> > Surely you can hide data in python?
> > 
> 
> You can't genuinely hide data in Python.  The best you can do is the
> "_" idiom.  
> 
> The question is why was data hiding invented in the first place.  It
> prevents attempts to get at the underlying mechanisms instead of
> sticking with the external API.  There are two reasons for this:

Actua

What are the other options against Zope?

2005-07-02 Thread godwin
Hi all,
  I wanna thank Martin for helping out with my ignorance concerning
execution of stored procedure with python. Now i have decided to write
a web app that googles into my companies proprietary database. I need
to know whether zope is good for that job. But even the introduction to
zope in the zope book was intimidating. Are there any simple options?
If so plz tell me how i can obtain it and study it. I should say that i
am new to web programming.
Thank you

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


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

2005-07-02 Thread Ralf W. Grosse-Kunstleve
**
This posting is also available in HTML format:
  http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html
**

Hi fellow Python coders,

I often find myself writing::

class grouping:

def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
# real code, finally

This becomes a serious nuisance in complex applications with long
argument lists, especially if long variable names are essential for
managing the complexity. Therefore I propose that Python includes
built-in support for reducing the ``self.x=x`` clutter. Below are
arguments for the following approach (*please* don't get too agitated
about the syntax right here, it really is a secondary consideration)::

class grouping:

def __init__(self, .x, .y, .z):
# real code right here

Emulation using existing syntax::

def __init__(self, x, y, z):
self.x = x
del x
self.y = y
del y
self.z = z
del z


Is it really that important?


For applications of non-trivial size, yes. Here is a real-world example
(one of many in that source tree):

   
http://cvs.sourceforge.net/viewcvs.py/cctbx/cctbx/cctbx/geometry_restraints/manager.py?view=markup

Fragment from this file::

class manager:

  def __init__(self,
crystal_symmetry=None,
model_indices=None,
conformer_indices=None,
site_symmetry_table=None,
bond_params_table=None,
shell_sym_tables=None,
nonbonded_params=None,
nonbonded_types=None,
nonbonded_function=None,
nonbonded_distance_cutoff=None,
nonbonded_buffer=1,
angle_proxies=None,
dihedral_proxies=None,
chirality_proxies=None,
planarity_proxies=None,
plain_pairs_radius=None):
self.crystal_symmetry = crystal_symmetry
self.model_indices = model_indices
self.conformer_indices = conformer_indices
self.site_symmetry_table = site_symmetry_table
self.bond_params_table = bond_params_table
self.shell_sym_tables = shell_sym_tables
self.nonbonded_params = nonbonded_params
self.nonbonded_types = nonbonded_types
self.nonbonded_function = nonbonded_function
self.nonbonded_distance_cutoff = nonbonded_distance_cutoff
self.nonbonded_buffer = nonbonded_buffer
self.angle_proxies = angle_proxies
self.dihedral_proxies = dihedral_proxies
self.chirality_proxies = chirality_proxies
self.planarity_proxies = planarity_proxies
self.plain_pairs_radius = plain_pairs_radius
# real code, finally

Not exactly what you want to see in a high-level language.


Is there a way out with Python as-is?
-

Yes. If you take the time to look at the file in the CVS you'll find
that I was cheating a bit. To reduce the terrible clutter above, I am
actually using a simple trick::

adopt_init_args(self, locals())

For completeness, the implementation of ``adopt_init_args()`` is here:

   
http://cvs.sourceforge.net/viewcvs.py/cctbx/scitbx/scitbx/python_utils/misc.py?view=markup

While this obviously goes a long way, it has several disadvantages:

  - The solution doesn't come with Python -> everybody has to reinvent.

  - People are reluctant to use the trick since scripts become
dependent on a non-standard feature.

  - It is difficult to remember which ``import`` to use for
``adopt_init_args`` (since everybody has a local version/variety).

  - The ``adopt_init_args(self, locals())`` incantation is hard to
remember and difficult to explain to new-comers.

  - Inside the ``__init__()`` method, the same object has two names,
e.g. ``x`` and ``self.x``. This lead to subtle bugs a few times
when I accidentally assigned to ``x`` instead of ``self.x`` or vice
versa in the wrong place (the bugs are typically introduced while
refactoring).

  - In some cases the ``adopt_init_args()`` overhead was found to
introduce a significant performance penalty (in particular the
enhanced version discussed below).

  - Remember where Python comes from: it goes back to a teaching
language, enabling mere mortals to embrace programming.
``adopt_init_args(self, locals())`` definitely doesn't live up
to this heritage.


Minimal proposal


My minimal proposal is to add an enhanced version of ``adopt_init_args()``
as a standard Python built-in function (actual name secondary!)::

class grouping:

def __init__(self, x, y, z):
adopt_init_args()
# real code

Here is a reference implementation:

   
http://cvs.sourcefor

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

2005-07-02 Thread John Roth
"Robert Kern" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

>
> map and filter are being removed *because of* list comprehensions. Did you 
> even read Guido's articles about this issue? Your understanding of why 
> these changes are planned is incorrect; consequently your projection based 
> on that understanding is not on firm footing.

May I most respectfully point out that you've got it backwards.
Part of the justification for list comprehensions was that they could
be used to replace map and filter.

The jihad against the functional constructs has been going on for a
long time, and list comprehensions are only one piece of it.

John Roth

> -- 
> Robert Kern
> [EMAIL PROTECTED]
>
> "In the fields of hell where the grass grows high
>  Are the graves of dreams allowed to die."
>   -- Richard Harter
> 

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


Re: Accepted Summer of Code proposals

2005-07-02 Thread Reinhold Birkenfeld
A.M. Kuchling wrote:
> For anyone who's interested: the Python wiki now contains a list of the
> PSF-mentored proposals that were accepted for Google's Summer of Code:
>   http://wiki.python.org/moin/SummerOfCode

Is it right that two Wax proposals were accepted?

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


Re: Python, mysql, floating point values question

2005-07-02 Thread qwweeeit
Hi Christopher,
if you have to make calculations or comparing operations, the only
"safe" method is to save and use only integer values.
Of course there must be a preventive agreement on the precision you
want to have (2, 3 4 ...  decimals).
The sw part is straigthforward:
- to save in the database you must multiply every float by
10**(precision)
- to use the "integers" and, for example, display them as float, you
must of course make the opposit operation (dividing).

There are drawbacks:
- the queries (from the point of view of the user) are much more
complicate
- the integer takes generally more place than the corresponding float
- the integer divide needs particular attention.

If the disk space occupied by the database is a concern, you can
evaluate the possibility to save the floats as string representation
as, for example, "1.5632"
(coming out from "%.4f" % 1.5631).

Sorry if the above considerations are not at the same level of those of
the experts, but I definitely am not an "expert". I encountered the
same problems many years ago (when the size of disks was at maximum 200
Mb).
Bye.

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


Re: Which kid's beginners programming - Python or Forth?

2005-07-02 Thread TZOTZIOY
On Tue, 28 Jun 2005 12:58:21 -0700, rumours say that Dave Benjamin
<[EMAIL PROTECTED]> might have written:

>BORT wrote:
>> I am toying with the idea of teaching my ten year old a little about
>> programming.  I started my search with something like "best FREE
>> programming language for kids."  After MUCH clicking and high-level
>> scanning, I am looking at Python and Forth.  Both have advocates that
>> say each is a great approach to learning computers.

>Kids your backwards talking like if forth love will they then.

I have a nephew that would love Forth only for that.

The perfect language for many kids I know would be Python with boolean
operators reversed.  Oh, and 'print' should be 'do_NOT_print'.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Boss wants me to program

2005-07-02 Thread TZOTZIOY
On Wed, 29 Jun 2005 07:11:43 -0500, rumours say that phil
<[EMAIL PROTECTED]> might have written:

>I wonder what percentage of the tools you refer to are
>Eclipse and not Java per se.  ?? I don't know.

>The really big bucks of IBM sent Eclipse through the roof.

The project name is pretty offensive too, since it's related to the term
"Sun" and not the term "Java".

If one has heard of the differences between Sun and IBM about Java, and
knowing that Eclipse started as an IBM project, then the reasoning for
choosing the name "Eclipse" becomes more obvious...
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accepted Summer of Code proposals

2005-07-02 Thread Peter Hansen
Reinhold Birkenfeld wrote:
> A.M. Kuchling wrote:
> 
>>For anyone who's interested: the Python wiki now contains a list of the
>>PSF-mentored proposals that were accepted for Google's Summer of Code:
>>  http://wiki.python.org/moin/SummerOfCode
> 
> 
> Is it right that two Wax proposals were accepted?

"Right" can mean either "correct" or "proper".  Which did you mean?

If you meant the first, then the above link clearly shows that there 
were in fact two different Wax proposals (from different people) accepted.

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


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

2005-07-02 Thread Gregory K. Johnson
On Sat, Jul 02, 2005 at 03:04:09AM -0700, Ralf W. Grosse-Kunstleve wrote:
[...]
> Minimal proposal
> 
> 
> My minimal proposal is to add an enhanced version of ``adopt_init_args()``
> as a standard Python built-in function (actual name secondary!)::
> 
> class grouping:
> 
> def __init__(self, x, y, z):
> adopt_init_args()
> # real code
[...]
> Enhanced syntax proposal
> 
> 
> The exclusion problem suggests these alternatives::
> 
>   class grouping:
> 
>   def __init__(self, self.keep_this, self.and_this, but_not_this,
> self.but_this_again):
>   # real code right here
[...]
> A shorter alternative (my personal favorite since minimally redundant)::
> 
>   class grouping:
> 
>   def __init__(self, .keep_this, .and_this, but_not_this, 
> .but_this_again):
>   # real code right here
[...]
> P.S.: If you reply to this message, please clearly separate
> naming/syntax issues from the core issue of providing built-in support
> designed to reduce clutter.

I share many of the qualms of those who responded to your earlier post.
(Is this really a problem? Can't a good editor save you the typing?
Explicit is better than implicit, and all that.)

But it also occurs to me to ask: Is a function-definition syntax
extension really appropriate when it's only likely usefulness is for the
particular function called __init__()? That seems more un-Pythonic to me
than straightforward, idiomatic, but somewhat verbose boilerplate.

An adoptargs([excluded=None]) builtin or similar seems much more viable.
(Although even there I don't feel any pressing need: I'm content with
"self.x = x".)

-- 
Gregory K. Johnson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython: Terminal Output -> Scrollable Panel?

2005-07-02 Thread Peter Hansen
flamesrock wrote:
> I want to make it so that clicking on a button that performs an
> operation will output it to the scrollable wxpython terminal panel, and
> (if possible) save that output as text (or maybe into a logfile).

The example code includes something called "PyCrust" which does pretty 
much this.  (The logging part is fairly trivial, so I won't mention it.) 
  I'm sure you could look in the source to learn more.  You can start by 
running the demo, and finding that particular one, playing with it a 
bit, and then seeing how the demo code invokes PyCrust.  Then find the 
source for PyCrust in the wxPython folder (under your lib/site-packages 
folder in c:\python24) and start reading.

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


Re: What are the other options against Zope?

2005-07-02 Thread Peter Hansen
godwin wrote:
>   I wanna thank Martin for helping out with my ignorance concerning
> execution of stored procedure with python. Now i have decided to write
> a web app that googles into my companies proprietary database. 

Just checking... do you really mean "googles", or is that in your mind a 
synonym for "search"?

> I need
> to know whether zope is good for that job.

For which part of it?  The web part, or the searching part?  It's not 
likely sufficient for the searching part, since it doesn't include 
database interfaces other than to its own ZODB.  What proprietary 
database is involved?

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


Re: When someone from Britain speaks, Americans hear a "British accent"...

2005-07-02 Thread Stephen Kellett
In message <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] writes
>T can be silent in England too ..
>
>frui'
>cricke'

Both of those words (fruit and cricket) have the letter T sounded.

Stephen (Nationality: English).
-- 
Stephen Kellett
Object Media Limitedhttp://www.objmedia.demon.co.uk/software.html
Computer Consultancy, Software Development
Windows C++, Java, Assembler, Performance Analysis, Troubleshooting
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bad Math

2005-07-02 Thread Patrick Rutkowski
On 7/2/05, Brian van den Broek <[EMAIL PROTECTED]> wrote:
> Patrick Rutkowski said unto the world upon 02/07/2005 00:12:
> > That's... annoying, to say the least. And my number 4/5 was a rational
> > number too; I can understand how when doing 1/3 things can get funky.
> > Really though... 4/5 = 0.8 right on the nose, whats up?
> >
> > I read that 
> > http://www.python.org/doc/faq/general.html#why-are-floating-point-calculations-so-inaccurate
> > I'd like to find out more, is there anyway for this issue to be
> > circumvented? That "is within a reasonable limit check" seams like way
> > too much just to get a proper result from something simple like 4/5.
> >
> >
> 
> Hi Patrick,
> 
> my quick piece of code became something I thought might someday be
> useful. So, I expanded it with tests, and sanity checks, etc. It
> doesnt' yet have the full functionality I'd like (see docstrings), but
> I won't get to fixing it anytime real soon.
> 
> So, in case you are interested, it is attached. It allows you to
> compute the value of a rational[*] as expressed in any base, 1 < base
> < 37, to arbitrary precision.
> 
> [*] Any n/m, -3 < n/m < 3. Subject to some restrictions, a greater
> range. (These are the limits on functionality mentioned above.)
> 
> It is in need of some re-organization, and I'm no skilled programmer,
> so certainly don't take it as an ideal model :-)
> 
> It also got me to look into decimal for the first time :-)
> 
> Anyway, attached.
> 
> Best,
> 
> Brian vdB
> 
> 
> 
> 
> #! /usr/bin/env python
> #
> # rationalconverter.py
> # Copyright 2005 Brian van den Broek
> # [EMAIL PROTECTED]
> #
> # Version 0.1
> # 02-Jul-2005  05:29:20
> #
> # Released under the GPL
> # (If you would prefer some other licence, feel free to write and ask: we
> # will most probably be able to work something out -- I picked the GPL
> # because safe and well-known, not out of a deep ideological commitment.)
> 
> ##
> #
> # rationalconverter.py -- functions to convert rationals to other bases
> # Copyright (C) 2005 Brian van den Broek
> #
> # This program is free software; you can redistribute it and/or modify
> # it under the terms of the GNU General Public License as published by
> # the Free Software Foundation; either version 2 of the License, or
> # (at your option) any later version.
> #
> # This program is distributed in the hope that it will be useful,
> # but WITHOUT ANY WARRANTY; without even the implied warranty of
> # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> # GNU General Public License for more details.
> #
> # You can view the GNU General Public License at:
> # .
> #
> # Alternatively, you can obtain a copy by writing to:
> # The Free Software Foundation, Inc.
> # 59 Temple Place - Suite 330
> # Boston, MA 02111-1307
> # USA
> #
> ##
> 
> 
> import math, string
> from decimal import Decimal
> 
> # values is the set of 36 'digits' for use in representing the converted 
> value.
> values = string.digits + string.uppercase
> 
> def float_to_base_n(numerator, denominator, base, precision):
> '''_> string expressing target in base to desired precision
> 
> numerator and denominator must be integral values, denominator must also 
> be
> non-zero.
> base must be an integral value greater than 1 and less than 37.
> precision must be an integeral value greater than 0.
> 
> The function returns a string representing numerator/denominator in base
> to the desired level of precision.
> 
> NB Temporary limitations:
> Presently, it can handle neither numerator/denominator values greater
> than 10, nor combinations of numerator, denominator, and base values
> such that numerator/denominator > base. (The original code was written
> just to deal with decimal fractions in [0, 1] and thus cannot cope 
> with
> these cases.) Future plan. Patches welcomed.
> 
> >>> float_to_base_n(4, 5, 3, 20)
> '0.210121012101210121012'
> '''
> 
> error, msg = _sanity_check_for_float_to_base_n(numerator, denominator,
>base, precision)
> if error:
> raise error, msg
> 
> base = Decimal(base)
> precision = Decimal(precision)
> target = Decimal(numerator) / Decimal(denominator)
> 
> start = target.to_integral()
> 
> # Must be a better way, but this ensures that start is the integral 
> portion
> # of numerator/denominator. FIXME
> if target > 0:
> if start > target:
> start = start - 1
> residue = target - start
> else:
> if start < target:
> start = start + 1
> residue = target + start
> 
> start = int(start)
> expression = [st

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

2005-07-02 Thread Roy Smith
"Ralf W. Grosse-Kunstleve" <[EMAIL PROTECTED]> wrote:
>   class grouping:
> 
>   def __init__(self, .keep_this, .and_this, but_not_this, 
> .but_this_again):
>   # real code right here

I'm really torn about this.  On the one hand, my first thought was "you 
shouldn't be writing constructors with arguments lists so long that this is 
a problem", but you showed a reasonable counter-example to that argument.  
I'm a big fan of DRY (Don't Repeat Yourself), sometimes expressed as "Once 
And Only Once", and your proposal lets you do that.

It also has the nice feature that it doesn't break any existing code; the 
suggested syntax is not currently legal Python.

What happens if I do:

def __init__ (self, .x, .y, .z):
   x = 0

what does the assignment x do?  Does it automatically get promoted to an 
assignment to self.x?  Does it generate an error?

The big question in my mind is not "Is this useful" (since it clearly is), 
but "Does the utility justify the cost?".  In other words, will it be used 
frequently enough to compensate for the added complexity to the language?  
I'm not convinced of that.

There have been some proposals floating around to implement a "with" 
keyword which would create implicit namespaces.  That's sort of what you're 
proposing here.  I'm not convinced either is a good idea, but if they were 
to be adopted, I'd certainly want to see the them done in a uniform, 
logically consistent way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MD5 problem

2005-07-02 Thread TZOTZIOY
On Mon, 13 Jun 2005 14:00:33 +0200, rumours say that fargo
<[EMAIL PROTECTED]> might have written:

>If I use the md5 module with .txt files, it'ok.
>
>The Problem comes from the .msg files. I get the same signature for 
>every .msg file I try to hash with the md5 algorithm. I think some 
>character are strange for python, and makes it stop before the end of 
>the .msg file.

FYI: the character that was strange for Windows (not Python) was
chr(26), or Ctrl-Z, or end-of-file, which is special for files opened as
text instead of binary.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-07-02 Thread TZOTZIOY
On Fri, 01 Jul 2005 23:45:57 +1000, rumours say that John Machin
<[EMAIL PROTECTED]> might have written:

>Simon Brunning wrote:
>> On 7/1/05, Peter Maas <[EMAIL PROTECTED]> wrote:
>> 
>>>Simon Brunning schrieb:
>>>
Sibylle Koczian needs to sort part of a list. His first attempt made
the natural mistake - sorting a *copy* of part of the list:

[Peter]
>>>I think it was _her_ first attempt.

[Simon]
>> Ooops! Sorry, Sibylle.

[John]
>Obviously haven't spent enough time watching Fawlty Towers :-)

Then surely it should have been "its" first attempt?  Aren't piranhas
neutral?
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python choice of database

2005-07-02 Thread TZOTZIOY
On 20 Jun 2005 11:43:28 -0700, rumours say that "Oren Tirosh"
<[EMAIL PROTECTED]> might have written:

>For very short keys and record (e.g. email addresses) you can use
>symbolic links instead of files. The advantage is that you have a
>single system call (readlink) to retrieve the contents of a link. No
>need to open, read and close.

readlink also does open, read and close too.  And why go through
indirection?  Why not make indexes into subdirectories, say, and
hard-link the records under different filenames?

>This works only on posix systems, of course.

There aren't any non-posix-conformant --or, at least, any
non-self-described-as-posix-conformant :-)-- operating systems in wide
use today.

Hint: win32file.CreateHardLink
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python choice of database

2005-07-02 Thread TZOTZIOY
On Tue, 21 Jun 2005 17:00:17 +0300, rumours say that Konstantin
Veretennicov <[EMAIL PROTECTED]> might have written:

>On 6/21/05, Charles Krug <[EMAIL PROTECTED]> wrote:
>> 
>> Related question:
>> 
>> What if I need to create/modify MS-Access or SQL Server dbs?
>
>You could use ADO + adodbapi for both.
>http://adodbapi.sourceforge.net/

Or pywin32/ctypes and COM (btw, I prefer DAO to ADO, but that is a
personal choice).
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python choice of database

2005-07-02 Thread TZOTZIOY
On Mon, 20 Jun 2005 23:42:21 -0800, rumours say that "EP"
<[EMAIL PROTECTED]> might have written:

>I tried this for one application under the Windows OS and it worked fine...
>
>until my records (text - maybe 50KB average) unexpectedly blossomed into the 
>10,000-1,000,000 ranges.  If I or someone else (who innocently doesn't know 
>better) opens up one of the directories with ~150,000 files in it, the 
>machine's personality gets a little ugly (it seems buggy but is just very 
>busy; no crashing).  Under 10,000 files per directory seems to work just fine, 
>though.

Although I am not a pro-Windows person, I have to say here directories
containing more than 1 files is not a problem for NTFS (at least
NTFS of Win2000 and WinXP based on my experience) since AFAIK
directories are stored in B-tree format; the problem is if one tries to
*view* the directory contents using Explorer.  Command-line dir had no
problem on a directory with >15000 files.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Better console for Windows?

2005-07-02 Thread TZOTZIOY
On Sat, 02 Jul 2005 03:55:43 GMT, rumours say that [EMAIL PROTECTED] (Bengt
Richter) might have written:

>Alt-spacebar, e, l, (uparrow/downarrow)*, Esc
> (lower case L)--^   ^--does the scrolling. Esc ends the 
> scrolling mode.

Damn! it says Scroll in there in the system menu, doesn't it?  Talk
about blindness...

>Seems to work for cmd.exe on NT4

XP too.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Boss wants me to program

2005-07-02 Thread Riccardo Galli
On Tue, 28 Jun 2005 12:57:36 -0700, xeys_00 wrote:

> The other alternative
> is to install console mode linux on it and hope that the ncurses library
> can be used by python. 

Hi, for curses module and linux, I made a library which give you
various widgets (combobox, buttons,checkbox,menubar,...).
It's hard to find googling so I let you know it here.

curses-extra is its name
http://www.sideralis.net/index.php?action=4&pjid=20

Bye,
Riccardo

-- 
Riccardo Galli
Sideralis Programs
http://www.sideralis.net
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-07-02 Thread Andrew Koenig
"Ralf W. Grosse-Kunstleve" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

>class grouping:
>
>def __init__(self, .x, .y, .z):
># real code right here

> Emulation using existing syntax::

>def __init__(self, x, y, z):
>self.x = x
>del x
>self.y = y
>del y
>self.z = z
>del z

I think this is a bad idea, for a subtle reason.

In Python, unlike many other languages, the names of formal parameters are 
part of a function's interface. For example:

def f(x, y):
return x-y

Now f(3, 4) is -1 and f(y=3,x=4) is 1.

The names of instance variables are generally not part of a class' 
interface--they are part of its implementation.

This proposed feature, whenever used, would tie a class' implementation to 
the interface of every method that uses the feature.  As far as I can see, 
it is impossible to use the feature without constraining the implementation 
in this way.

For this reason, I would much rather have the mapping between parameter 
names and instance variables be explicit.


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


Re: web programming with mod_python

2005-07-02 Thread Ray Cote
At 7:17 PM -0300 7/1/05, Rodrigo Dominguez wrote:
>My question is: is there some kind of framework that works with mod_python?

You could take a look at Myghty:



-- 

Raymond Cote
Appropriate Solutions, Inc.
PO Box 458 ~ Peterborough, NH 03458-0458
Phone: 603.924.6079 ~ Fax: 603.924.8668
rgacote(at)AppropriateSolutions.com
www.AppropriateSolutions.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modules for inclusion in standard library?

2005-07-02 Thread Colin J. Williams
Steven Bethard wrote:
> Fredrik Johansson wrote:
> 
>> On 6/27/05, Reinhold Birkenfeld 
>> <[EMAIL PROTECTED]> wrote:
>>
>>> Do you have any other good and valued Python modules that you would 
>>> think are
>>> bug-free, mature (that includes a long release distance) and useful 
>>> enough to
>>> be granted a place in the stdlib?
>>
>>
>> First of all, numeric/numarray, obviously!
> 
> 
> There has been recent discussion about this.  Check the python-dev list 
> archives I think.  It's unlikely that all of numeric/numarray could go 
> into the Python stdlib because there still is disagreement between the 
> two camps as to the module architecture.  However, there does seem to be 
> some agreement at the level of the basic array object, so it may be 
> possible that at least the array object itself might join the stdlib in 
> the not too distant future.  I suspect there's more detailed discussion 
> of this in the numeric/numarray lists.

There was a flurry of exchanges about three months ago but it soon died.

One thing which needs to be sorted out is the silent truncation of 
complex values:
http://sourceforge.net/tracker/index.php?func=detail&aid=1216688&group_id=1369&atid=450446

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


Re: Re:

2005-07-02 Thread Tom Anderson
On Fri, 1 Jul 2005, Andreas Kostyrka wrote:

> Am Freitag, den 01.07.2005, 08:25 -0700 schrieb George Sakkis:
>
>>> Again, how? Is there a way to force that an external user of my lib can
>>> not use my internal data/methods/classes, unless he uses odd compiler
>>> hacks?
>>
>> I never understood how mainstream OO languages expect the designer of a 
>> class to know in advance that an attribute should be hidden or 
>> unnecessary to its subclasses by being declared "private" instead of 
>> "protected".
>
> The problem is, that the classic private/protected/public visibility
> tags try to solve multiple problems.
>
> Private: Ok, that's all that's really only for the implementation.
> public: Well, that's all for my "customers". Hmm. What if I've got two
> kinds of customers? Say a customer like in bank customer, and second
> customer that plays the role of the bank employee? oops.

C++ has 'friend' for that:

http://www.cplusplus.com/doc/tutorial/tut4-3.html

tom

-- 
REMOVE AND DESTROY
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-07-02 Thread Tom Anderson
On Fri, 1 Jul 2005, Ivan Van Laningham wrote:

> Personally, I find that Lisp & its derivatives put your head in a very 
> weird place.  Even weirder than PostScript/Forth/RPN, when you come 
> right down to it.

+1 QOTW!

tom

-- 
REMOVE AND DESTROY
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: map vs. list-comprehension

2005-07-02 Thread Tom Anderson
On Fri, 1 Jul 2005, Sion Arrowsmith wrote:

> Tom Anderson  <[EMAIL PROTECTED]> wrote:
>> On Thu, 30 Jun 2005, Roy Smith wrote:
>>
>>> Even some of the relatively recent library enhancements have been kind 
>>> of complicated.  The logging module, for example, seems way over the 
>>> top.
>>
>> Exactly the same thing happened with Java.
>
> I was under the impression that Python's logging module (like unittest) 
> was based on a common Java one, and it's complexity could be blamed on 
> that.

That would explain it. Who was responsible for this crime? I say we shoot 
them and burn the bodies.

>> if you look at the libraries that were in 1.1, they're very clean and 
>> simple (perhaps with the exception of AWT). 1.2 added a load of stuff 
>> that was much less well-designed (with the notable exception of the 
>> collections stuff, which is beautiful)
>
> There are very many adjectives I could (and have) used to describe the 
> Collection framework. "Beautiful" is not among them. I think the closest 
> I could manage is "baroque".

Oh, i don't think it's really that bad. For java.

tom

-- 
REMOVE AND DESTROY
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modules for inclusion in standard library?

2005-07-02 Thread Tom Anderson
On Fri, 1 Jul 2005, Scott David Daniels wrote:

> Daniel Dittmar wrote:
>> Rocco Moretti wrote:
>>
> Except that (please correct me if I'm wrong) there is somewhat of a 
> policy for not including interface code for third party programs 
> which are not part of the operating system. (I.e. the modules in the 
> standard libary should all be usable for anyone with a default OS + 
> Python install.)
>> 
>> There seems to be a great reluctance by the Python developers to add 
>> modules of the expat kind, as this means responsibilities for 
>> additional source modules. There's also the problem with incompatible 
>> licenses, integrating a second configure, deciding when to update to 
>> the latest version of the library etc.
>
> If you haven't noticed, the Python code has a substantial body of unit
> tests.  Arranging the tests to be easily runnable for all developers
> is going to be tough for "third party programs."

The tests for interface modules would have to use mock objects on the back 
end. This is pretty standard practice, isn't it?

> Making the interfaces work for differing versions of the 3PPs as the 
> third parties themselves change their interfaces (see fun with Tcl/Tk 
> versions for example), and building testbeds to test to all of those 
> differing versions, would cause a nightmare that would make a knight of 
> Ni scream.

But given that at a number of such modules have in fact been written, 
along with tests, why not add them to the standard distribution?

tom

-- 
REMOVE AND DESTROY
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modules for inclusion in standard library?

2005-07-02 Thread Colin J. Williams
Gregory Piñero wrote:
> While that policy does make sense, I think a database program falls
> somewhere in between an OS and an everyday third party program.  For
> web developers, the database might as well be the OS.  I use the
> database to store everything in my web app.  That way I can just worry
> about 1 place to access information and not have to fool with files
> and other OS issues.
> 
> So I humbly suggest the policy should be :
> 
> Python will not include interface code for third party programs which
> are not part of an operating system or database system.
> 
> ...
Isn't this where the discussion should start?  There should be some 
general policy guiding the types of modules which should be in the 
standard library.  Clearly, size is a factor as the msi version of 
Python 2.4 is now 10 MB.

if there were some sort of package manager which took account of 
dependencies would that reduce the need to expand the standard library?

Colin W.
> But I have no experience in designing world class programming
> langauges so forgive me if I am too bold.
> 
> -Greg
> 
> 
> On 6/29/05, Rocco Moretti <[EMAIL PROTECTED]> wrote:
> 
>>Paul Rubin wrote:
>>
>>>Gregory Piñero <[EMAIL PROTECTED] > writes:
>>>
>>>
I'd like to see some database API's to the most common databases
included.
>>>
>>>Yes, certainly, this is a serious deficiency with Python.
>>
>>Except that (please correct me if I'm wrong) there is somewhat of a
>>policy for not including interface code for third party programs which
>>are not part of the operating system. (I.e. the modules in the standard
>>libary should all be usable for anyone with a default OS + Python install..)
>>
>>A notable exception is the dbm modules, but I seem to recall hearing
>>that the official position is that it was a mistake. (Now only kept for
>>backward compatability.)
>>--
>>http://mail.python.org/mailman/listinfo/python-list 
>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modules for inclusion in standard library?

2005-07-02 Thread Colin J. Williams
Rocco Moretti wrote:
> Paul Rubin wrote:
> 
>> Rocco Moretti <[EMAIL PROTECTED]> writes:
>>
>>> Except that (please correct me if I'm wrong) there is somewhat of a
>>> policy for not including interface code for third party programs which
>>> are not part of the operating system. (I.e. the modules in the
>>> standard libary should all be usable for anyone with a default OS +
>>> Python install.)
>>
>>
>>
>> I've never heard of Python having such a policy and I don't understand
>> how such a stupid policy could be considered compatible with a
>> proclaimed "batteries included" philosophy.  Why would Python
>> advocates want to make Python deliberately uncompetitive with PHP,
>> Java, and other languages that do include database modules?
> 
> 
> Well, since there seems to be an outpouring of disgust at my statement, 
> and no official confirmation/rejection, it's probably a figment of my 
> prematurely failing mind.
> 
> However, if there was such a policy, it would not be unequivocally 
> "stupid." First off, there is a bit of flexibility in what is considered 
> part of the OS. E.g, Linux may properly refer to just the kernel, but 
> rarely is just the kernel installed. Various utilities and programs 
> might be considered part of the OS because they are ubiquitously 
> installed, or are included with the Python distribution itself (as Tk is 
> with windows Python).
> 
> For those programs which aren't ubiquitously installed, or even for ones 
> that are, but require significant configuration, it is reasonable to 
> expect that if someone has the ability and goes to the effort of 
> locating, obtaining, installing, and configuring a third party program, 
> they can just as easily obtain and install the python module, especially 
> as it's usually as easy as "python setup.py install".
> 
> At any rate, I'm not advocating such a policy, I'm just saying it can 
> make a bit of sense if you look at it from a certain angle.
I agree.  It makes sense to develop a policy first.

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


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

2005-07-02 Thread Robert Kern
John Roth wrote:
> "Robert Kern" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> 
>>map and filter are being removed *because of* list comprehensions. Did you 
>>even read Guido's articles about this issue? Your understanding of why 
>>these changes are planned is incorrect; consequently your projection based 
>>on that understanding is not on firm footing.
> 
> May I most respectfully point out that you've got it backwards.
> Part of the justification for list comprehensions was that they could
> be used to replace map and filter.

That is essentially what I said. List comprehensions were made to 
replace map and filter. Now that they are here, Guido wants to remove 
map and filter to keep OOWTDI.

My response was incomplete, not incorrect.

-- 
Robert Kern
[EMAIL PROTECTED]

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

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


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

2005-07-02 Thread Roy Smith
"Andrew Koenig" <[EMAIL PROTECTED]> wrote:
> In Python, unlike many other languages, the names of formal parameters are 
> part of a function's interface. For example:
> 
> def f(x, y):
> return x-y
> 
> Now f(3, 4) is -1 and f(y=3,x=4) is 1.
> 
> The names of instance variables are generally not part of a class' 
> interface--they are part of its implementation.
> 
> This proposed feature, whenever used, would tie a class' implementation to 
> the interface of every method that uses the feature.  As far as I can see, 
> it is impossible to use the feature without constraining the implementation 
> in this way.

While I suppose that's true from a theoretical point of view, as a 
practical matter, I don't see it being much of a big deal.  I don't think 
I've ever written an __init__ method which saved its parameters and used 
different names for the parameter and the corresponding instance variable.  
Doing so would just be confusing (at least for the kind of code I write).

Also, it doesn't really tie it in any hard and fast way.  Right now, I 
would write:

def __init__ (self, x, y, z):
   self.x = x
   self.y = y
   self.z = z
   blah

under the new proposal, I would write:

def __init__ (self, .x, .y, .z):
   blah

If at some time in the future, if I decided I need to change the name of 
the instance variable without changing the exposed interface, it would be 
easy enough to do:

def __init__ (self, .x, .y, z):
   self.zeta = z
   blah

I'm still not convinced we need this, but the exposed interface issue 
doesn't worry me much.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What are the other options against Zope?

2005-07-02 Thread Florian Lindner
Peter Hansen wrote:

> godwin wrote:
>>   I wanna thank Martin for helping out with my ignorance concerning
>> execution of stored procedure with python. Now i have decided to write
>> a web app that googles into my companies proprietary database.
> 
> Just checking... do you really mean "googles", or is that in your mind a
> synonym for "search"?
> 
>> I need
>> to know whether zope is good for that job.
> 
> For which part of it?  The web part, or the searching part?  It's not
> likely sufficient for the searching part, since it doesn't include
> database interfaces other than to its own ZODB.  What proprietary
> database is involved?

That's not correct. Zope2 includes DB interfaces to MySQL, PostGre, ODBC and
many others.
For Zope3 IIRC there are not yet so many interfaces.

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


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

2005-07-02 Thread Jamey Cribbs
Tom Anderson wrote:
> So, if you're a pythonista who loves map and lambda, and disagrees with 
> Guido, what's your background? Functional or not?

I have no functional language background.  Until recently, I had no use 
for programming "expression to be evaluated later" or "deferred 
expressions" or whatever else they are being called.

Where I came to see the awesomeness of "deferred expressions" was a few 
months ago when I started a major rewrite of KirbyBase for Ruby.  I 
wanted to make the Ruby version of KirbyBase take advantage of the 
strengths of the language.  Another Ruby programmer, Hal Fulton, was 
helping me by constantly pushing me to make KirbyBase more Ruby-ish. 
One thing he kept pushing was to be able to specify select querys using 
Ruby's "deferred expression" mechanism, code blocks (before anyone 
starts yelling, I know that Ruby code blocks are *much* more than just 
"deferred expressions"; I'm just using that descriptor here for the sake 
of this discussion).

Code blocks allow you to wrap up any Ruby code and pass it to a method 
and have it executed within that method.  It is more powerful than 
lambda, because you can have multiple statements in the code block and 
you can do assignment within the code block.  This allowed me to rewrite 
KirbyBase so that you can do a select like this:

plane_tbl.select { |r| r.country == 'USA' and r.speed > 350 }

Now, this is cool, but you can do this using lambda in Python.  Where 
Ruby code blocks really shine is that you can also do this:

plane_tbl.update {|r| r.name == 'P-51'}.set {|r|
 r.speed = 405
 r.range = 1210
}

I have one code block that I pass to the update method which says 
"Select all planes with name equal to P-51".  Then, I pass a code block 
to the set method which assigns new values to the speed and range fields 
for those records (i.e. P-51) that were selected in the update method. 
This is something you can't do with lambda.

Now, I think I can duplicate the same functionality of Ruby code blocks 
by using Python functions, but it is not going to be as pretty.

So, even though lambda is not as powerful as Ruby code blocks, I was 
still bummed to read that it is going away, because it is better than 
nothing.

Hopefully, Guido will reconsider or, even better, give us something even 
more powerful.

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


Re: Re:

2005-07-02 Thread Andreas Kostyrka
Am Samstag, den 02.07.2005, 15:11 +0100 schrieb Tom Anderson:
> On Fri, 1 Jul 2005, Andreas Kostyrka wrote:
> 
> > Am Freitag, den 01.07.2005, 08:25 -0700 schrieb George Sakkis:
> >
> >>> Again, how? Is there a way to force that an external user of my lib can
> >>> not use my internal data/methods/classes, unless he uses odd compiler
> >>> hacks?
> >>
> >> I never understood how mainstream OO languages expect the designer of a 
> >> class to know in advance that an attribute should be hidden or 
> >> unnecessary to its subclasses by being declared "private" instead of 
> >> "protected".
> >
> > The problem is, that the classic private/protected/public visibility
> > tags try to solve multiple problems.
> >
> > Private: Ok, that's all that's really only for the implementation.
> > public: Well, that's all for my "customers". Hmm. What if I've got two
> > kinds of customers? Say a customer like in bank customer, and second
> > customer that plays the role of the bank employee? oops.
> 
> C++ has 'friend' for that:
> 
> http://www.cplusplus.com/doc/tutorial/tut4-3.html

Well, than you have to know who your friend is, don't you? And my friend
comes on "private" term, doesn't he? *g*

Andreas



signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: What are the other options against Zope?

2005-07-02 Thread phil
Peter Hansen wrote:

> godwin wrote:
> 
>>  I wanna thank Martin for helping out with my ignorance concerning
>>execution of stored procedure with python. Now i have decided to write
>>a web app that googles into my companies proprietary database. 
>>
> 
> Just checking... do you really mean "googles", or is that in your mind a 
> synonym for "search"?
> 
> 
>>I need
>>to know whether zope is good for that job.
>>
> 
> For which part of it?  The web part, or the searching part?  It's not 
> likely sufficient for the searching part, since it doesn't include 
> database interfaces other than to its own ZODB.  What proprietary 
> database is involved?
> 
> -Peter
> 

I think the guy might like to know what Zope is.
I went to an IBM all day once, can't even remember the
name of their "web services".  At smoke breaks would
compare notes with other attendees.  I'm not sure we
ever understood, but we all agreed the problem
was "undefined terms" which I call organic buzz words.

Zope is like that to me.  I ask what is it and the answer
sounds like "Oh, it's oierbv for the zxcvioupo of 7cvn^djh'.

Now understand, I know what very well what Python, Apache, PhP,
MySQL, IE and javascript do.  I just don't know what Zope
does.

And if the answer is going contain phrases like "brings together"
or "sits on top of", don't bother. :-)


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


Re: Which kid's beginners programming - Python or Forth?

2005-07-02 Thread André
Scanning quickly through the various response, I noticed that at least
one person suggested rur-ple  (rur-ple.sf.net), hence Python.  I would
second that ;-) ... but then, I am biased as the author of rur-ple!

rur-ple is intended to be a complete learning environment for learning
programming and Python for complete beginners.  At the core of it are a
set of lessons (about 40 so far).  Before the end of the summer,
rur-ple should include a complete tutorial on writing games using
Python (and pygames).  My goal is for rur-ple to be usable by 10 years
old (with guidance) and young adults (by themselves) to learn about
programming.

Check it out ... and let me know what appeals to you (if anything) and
what doesn't.

It's free :-)

André

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


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

2005-07-02 Thread Mike Meyer
Jamey Cribbs <[EMAIL PROTECTED]> writes:
> Code blocks allow you to wrap up any Ruby code and pass it to a method
> and have it executed within that method.  It is more powerful than
> lambda, because you can have multiple statements in the code block and
> you can do assignment within the code block.

Just FYI, the inability to have statements - even multiple statements
- in a lambda is what people are talking about when they talk about
the limitations of lambda. It's a common thing for someone with a
background that includes a proper lambda to trip over when they first
start programming in Python. It's not that uncommon for newcommers to
trip over it with "print".

   http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Splitting string into dictionary

2005-07-02 Thread Christopher Subich
Robert Kern wrote:
> David Pratt wrote:
> 
>> I have string text with language text records that looks like this:
>>
>> 'en' | 'the brown cow' | 'fr' | 'la vache brun'

> translations = [x.strip(" '") for x in line.split('|')]
> d = dict(zip(translations[::2], translations[1::2]))

One caevat is that this assumes that the proto-list doesn't have any '|' 
inside the actual text.
-- 
http://mail.python.org/mailman/listinfo/python-list


email link and foreign accent

2005-07-02 Thread Vittorio
Hi,

I have one problem ( I am a python beginner) in a cgi:

print"""mailto:%s";>""" %(campovalore.encode('iso-8859-1'))
print campovalore.encode('iso-8859-1')
print ""


campovalore is an email address  with special (italian) characters.

>From IE6 everything is fine and the link launches my predefined (in 
Windows) email client with the correct string in the mailto field.

But from Firefox and the same email client I have an incorrect mailto field 
every time there is a special character in the string.

Any suggestion is welcome,

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


What's wrong with this code?

2005-07-02 Thread Nathan Pinno

  Hi all,

  What's wrong with the following code? It says there is name error, that
random is not defined. How do I fix it?

  # Plays the guessing game higher or lower.
  # Originally written by Josh Cogliati, improved first by Quique, then by
Nathan Pinno.
  print "Higher or Lower"
  print
  number = random.choice(range(100))
  guess = 0
  while guess != number:
  guess = input("Guess a number: ")
  if guess > number:
  print "Too high"
  guess = input("Guess a number: ")
  elif guess < number:
  print "Too low"
  guess = input("Guess a number: ")
  print "Just right"

  Thanks.
  Nathan Pinno
  http://www.npinnowebsite.ca/



-- 



 Posted via UsenetRevolution.com - Revolutionary Usenet
** HIGH RETENTION ** Specializing in Large Binaries Downloads **
 http://www.UsenetRevolution.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's wrong with this code?

2005-07-02 Thread Sébastien Boisgérault


Nathan Pinno a écrit :
> Hi all,
>
>   What's wrong with the following code? It says there is name error, that
> random is not defined. How do I fix it?

Add "import random" at the top of your file

Cheers,

SB

>   # Plays the guessing game higher or lower.
>   # Originally written by Josh Cogliati, improved first by Quique, then by
> Nathan Pinno.
>   print "Higher or Lower"
>   print
>   number = random.choice(range(100))
>   guess = 0
>   while guess != number:
>   guess = input("Guess a number: ")
>   if guess > number:
>   print "Too high"
>   guess = input("Guess a number: ")
>   elif guess < number:
>   print "Too low"
>   guess = input("Guess a number: ")
>   print "Just right"
>
>   Thanks.
>   Nathan Pinno
>   http://www.npinnowebsite.ca/
>
>
>
> --
>
>
> 
>  Posted via UsenetRevolution.com - Revolutionary Usenet
> ** HIGH RETENTION ** Specializing in Large Binaries Downloads **
>  http://www.UsenetRevolution.com

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


Re: What's wrong with this code?

2005-07-02 Thread Robert Kern
Nathan Pinno wrote:
>   Hi all,
> 
>   What's wrong with the following code? It says there is name error, that
> random is not defined. How do I fix it?

You need to import random.

-- 
Robert Kern
[EMAIL PROTECTED]

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

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


A brief question.

2005-07-02 Thread Nathan Pinno




  Hi all,
   
  Brief question for anyone who knows the answer, because I don't. Is there 
  anyway to make Python calculate square roots?
   
  Thanks,
  Nathan Pinnohttp://www.npinnowebsite.ca/

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

Re: Favorite non-python language trick?

2005-07-02 Thread Bernhard Herzog
Scott David Daniels <[EMAIL PROTECTED]> writes:

> Rocco Moretti wrote:
>> Joseph Garvin wrote:
>>
>> I'm not aware of a language that allows it, but recently I've found
>> myself wanting the ability to transparently replace objects
>> I mainly look for it in the "object replaces self" form, but I guess
>> you could also have it for arbitrary objects, e.g. to wrap a logging
>> object around a function, even if you don't have access to all
>> references of that function.
>> Why isn't it in Python? It's completely counter to the conventional
>> object semantics.
>
> Actually this is the old (and terrifying) Smalltalk message 'becomes:'.
> There is a concrete reason it is not in python: objects are represented
> as pointers to their data structures, do not have identical sizes, and
> therefore cannot be copied into each others data space. 

That limitation applies only some of the time, e.g. when you inherit
from built-in types.  But for ordinary classes it can be done:

>>> class A(object):
... def __init__(self, x):
... self.x = x
... 
>>> class B(object):
... def __init__(self, y):
... self.y = y
... 
>>> a = A(1)
>>> b = B(2)
>>> vars(a)
{'x': 1}
>>> vars(b)
{'y': 2}
>>> a.__class__, b.__class__ = b.__class__, a.__class__
>>> a.__dict__, b.__dict__ = b.__dict__, a.__dict__
>>> vars(a)
{'y': 2}
>>> isinstance(a, B)
True


   Bernhard

-- 
Intevation GmbH http://intevation.de/
Skencil   http://skencil.org/
Thuban  http://thuban.intevation.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-07-02 Thread Walter Brunswick
Why not just update the local dictionary?

class Grouping:
def __init__(self,x,y,z):
self.__dict__.update(locals()) 


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


Re: A brief question.

2005-07-02 Thread Robert Kern
Nathan Pinno wrote:
> 
> Hi all,
>  
> Brief question for anyone who knows the answer, because I don't. Is
> there anyway to make Python calculate square roots?

http://docs.python.org/

There is a search facility.

-- 
Robert Kern
[EMAIL PROTECTED]

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

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


Re: email link and foreign accent

2005-07-02 Thread Peter Hansen
Vittorio wrote:
> print"""mailto:%s";>""" %(campovalore.encode('iso-8859-1'))
> print campovalore.encode('iso-8859-1')
> print ""
> 
> campovalore is an email address  with special (italian) characters.
> [snip]
> Any suggestion is welcome,

It might help if you showed us the output of "repr(x)" where x is the 
output of the campovalore.encode('iso-8859-1') part above.

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


Re: Inheriting from object

2005-07-02 Thread Bengt Richter
On Thu, 30 Jun 2005 08:54:31 -0700, Scott David Daniels <[EMAIL PROTECTED]> 
wrote:

>Sion Arrowsmith wrote:
>> ... And if you were to do so, surely:
>> class foo(object):
>> def __init__(self, *args, **kwargs):
>>  super(foo, self).__init__(self)
>> 
>> would be the preferred way to go?
>> 
>Or, perhaps:
> class foo(object):
> def __init__(self, *args, **kwargs):
> super(foo, self).__init__(self, *args, **kwargs)
> ...
>
Doesn't super(foo, self).__init__ return a bound method, so you don't
need to pass self again? I.e.,
  super(foo, self).__init__(*args, **kwargs)

BTW, there's something about referring to type(self) by its not
always dependably bound (though usually global) name that bothers me.

I wonder if the above common use of super could be implemented as a property of 
object,
so you'd normally inherit it and be able to write
self.super.__init__(*args, **kwargs)  # (maybe spell it 
self.__super__.__init__(...) I suppose)

I.e., self.__super__ would effectively return the equivalent of
super(type(self), self)

(I think Michele Simionato may have posted some idea like this early on that
I didn't really follow, but maybe my subconscious snagged and garbled ;-)

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


Re: What are the other options against Zope?

2005-07-02 Thread Peter Hansen
Florian Lindner wrote:
> Peter Hansen wrote:
>>[Zope] doesn't include
>>database interfaces other than to its own ZODB.  
> 
> That's not correct. Zope2 includes DB interfaces to MySQL, PostGre, ODBC and
> many others.

It actually *includes* them?  I thought those were all add-in modules, 
not ones that Zope actually installs.  (I admit it's been a couple of 
years since I was current with the state of Zope... and my memory sucks. 
:-( )

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


Re: Inheriting from object

2005-07-02 Thread Peter Hansen
Bengt Richter wrote:
> BTW, there's something about referring to type(self) by its not
> always dependably bound (though usually global) name that bothers me.
> 
> I wonder if the above common use of super could be implemented as a property 
> of object,
> so you'd normally inherit it and be able to write
> self.super.__init__(*args, **kwargs)  # (maybe spell it 
> self.__super__.__init__(...) I suppose)
> 
> I.e., self.__super__ would effectively return the equivalent of
> super(type(self), self)

This doesn't work: type(self) is always the type of the instantiated 
(child) class, not the type of the class at whatever level of the class 
hierarchy the __init__() calls currently have reached.

In other words, with these definitions:

class A(object):
   def __init__(self):
  super(type(self), self).__init__()  # does not do what you want

class B(A):
   def __init__(self):
  super(type(self), self).__init__()# works okay here

if you do "b = B()", the first __init__ will work (i.e. B's __init__ 
will find and call A.__init__), but the next one won't (i.e. A.__init__ 
will now try calling A.__init__ recursively, giving you an eventual 
stack overflow).

-correcting-bengt-richter-on-such-arcana-is-always-dangerously y'rs,
  Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2005-07-02 Thread Ron Adam
Ralf W. Grosse-Kunstleve wrote:

> class grouping:
> 
> def __init__(self, .x, .y, .z):
> # real code right here

The way this would work seems a bit inconsistent to me.  Args normally 
create local variables that receive references to the objects passed to 
them.

In this case, a function/method is *creating* non local names in a scope 
outside it's own name space to receive it's arguments.  I don't think 
that's a good idea.

A better approach is to have a copy_var_to(dest, *var_list) function 
that can do it.  You should be able to copy only selected arguments, and 
not all of them.

 copy_var_to(self,x,z)

Not exactly straight forward to do as it runs into the getting an 
objects name problem.


> Emulation using existing syntax::
> 
> def __init__(self, x, y, z):
> self.x = x
> del x
> self.y = y
> del y
> self.z = z
> del z

The 'del's aren't needed as the references will be unbound as soon as 
__init__ is finished.  That's one of the reasons you need to do self.x=x 
, the other is to share the objects with other methods.



> Is there a way out with Python as-is?
> -

With argument lists that long it might be better to use a single 
dictionary to keep them in.

  class manager:
  def __init__(self, **args):
  defaults = {
'crystal_symmetry':None,
'model_indices':None,
'conformer_indices':None,
'site_symmetry_table':None,
'bond_params_table':None,
'shell_sym_tables':None,
'nonbonded_params':None,
'nonbonded_types':None,
'nonbonded_function':None,
'nonbonded_distance_cutoff':None,
'nonbonded_buffer':1,
'angle_proxies':None,
'dihedral_proxies':None,
'chirality_proxies':None,
'planarity_proxies':None,
'plain_pairs_radius':None }
  defaults.update(args)
  self.data = defaults

  # real code

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


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

2005-07-02 Thread Roy Smith
In article <[EMAIL PROTECTED]>,
 "Walter Brunswick" <[EMAIL PROTECTED]> wrote:

> Why not just update the local dictionary?
> 
> class Grouping:
> def __init__(self,x,y,z):
> self.__dict__.update(locals()) 

That's pretty clever.  The only minor annoyance is that it creates a 
self.self.  If that bothers you, you can fix it with:

def __init__ (self, x, y, z):
vars = locals()
del vars["self"]
self.__dict__.update(vars)

or, perhaps:

def __init__ (self, x, y, z):
self.__dict__.update(locals())
del self.self

It doesn't give you all the flexibility of the original proposal (i.e. 
name-by-name selectivity of what gets imported into self), but it does 
solve the OP's OP (Original Poster's Original Problem).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bad Math

2005-07-02 Thread Brian van den Broek
Patrick Rutkowski said unto the world upon 02/07/2005 09:25:
> On 7/2/05, Brian van den Broek <[EMAIL PROTECTED]> wrote:
> 
>>Patrick Rutkowski said unto the world upon 02/07/2005 00:12:
>>
>>>That's... annoying, to say the least. And my number 4/5 was a rational
>>>number too; I can understand how when doing 1/3 things can get funky.
>>>Really though... 4/5 = 0.8 right on the nose, whats up?
>>>
>>>I read that 
>>>http://www.python.org/doc/faq/general.html#why-are-floating-point-calculations-so-inaccurate
>>>I'd like to find out more, is there anyway for this issue to be
>>>circumvented? That "is within a reasonable limit check" seams like way
>>>too much just to get a proper result from something simple like 4/5.
>>>
>>>
>>
>>Hi Patrick,
>>
>>my quick piece of code became something I thought might someday be
>>useful. So, I expanded it with tests, and sanity checks, etc. It
>>doesnt' yet have the full functionality I'd like (see docstrings), but
>>I won't get to fixing it anytime real soon.
>>
>>So, in case you are interested, it is attached. It allows you to
>>compute the value of a rational[*] as expressed in any base, 1 < base
>>< 37, to arbitrary precision.




> I just got up and read your mail. However, I'm going away for the day
> so I didn't have time to look over your code. Thanks for the advice
> and explanations, they really helped. I understand the problem now...
> /me waves fist a base 2 fractions. If your code can fix it, then
> that's pretty great! What was that "import decimal" idea you proposed?
> Does it contain some functions that can sanely work with floating
> points? I'm not a new programmer, but my main arena is the simple side
> of Java, so I'm not really too far along yet.
> 
> Hoping Python will be fun,
> Patrick Rutkowski
> 
> P.S. I responded to the list this time.


Hi all,

:-(

Patrick had originally posted with the "why is Python getting the math 
wrong?" floating point issue. I'd responded to him with the FAQ link. 
He wrote back privately (top of quoting above). I replied privately 
and explained that the "better" behaviour of 4/5.0 as compared to 
1/3.0 is a product of base 10 representation. To substantiate this, I 
coded up something (incomplete) to represent rationals in arbitrary 
bases, for base 1< base < 37, and sent it privately.

Patrick then replied to the message with that code to the list :-( I'd 
not intended it to be posted publicly, not out of any code hoarding 
impulse, but from thinking it isn't good enough to put forth to the 
world. (I'm only a hobbyist.) But, since the decision to put it out 
there was taken for me, if anyone read the code, I'd appreciate 
comments. (The code is in the msg to which this is a reply -- it is 
long enough I didn't want to post it twice.)

Thanks, and best to all,

Brian vdB

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


Re: Inheriting from object

2005-07-02 Thread Scott David Daniels
Bengt Richter wrote:
> On Thu, 30 Jun 2005 08:54:31 -0700, Scott David Daniels <[EMAIL PROTECTED]> 
> wrote:
>>Or, perhaps:
>>class foo(object):
>>def __init__(self, *args, **kwargs):
>>super(foo, self).__init__(self, *args, **kwargs)
>>...
>>
> 
> Doesn't super(foo, self).__init__ return a bound method, so you don't
> need to pass self again? I.e.,
>   super(foo, self).__init__(*args, **kwargs)

Yes, of course (a silly cut-o / paste-o).

> BTW, there's something about referring to type(self) by its not
> always dependably bound (though usually global) name that bothers me.
> 
> I wonder if the above common use of super could be implemented as a property 
> of object,
> so you'd normally inherit it and be able to write
> self.super.__init__(*args, **kwargs)  # (maybe spell it 
> self.__super__.__init__(...) I suppose)
> 
> I.e., self.__super__ would effectively return the equivalent of
> super(type(self), self)

The problem with this is:

 class A(object):
 def __init__(self, *args, **kwargs):
 print 'Set A(*%r, **%r)' % (args, kwargs)
 class B(A):
 def __init__(self, *args, **kwargs):
 print 'Set B(*%r, **%r)' % (args, kwargs)
 super(B, self).__init__(*args, **kwargs)
 class C(B):
 def __init__(self, *args, **kwargs):
 print 'Set C(*%r, **%r)' % (args, kwargs)
 super(C, self).__init__(*args, **kwargs)

 class D(A):
 def __init__(self, *args, **kwargs):
 print 'Set D(*%r, **%r)' % (args, kwargs)
 super(type(self), self).__init__(*args, **kwargs)
 class E(D):
 def __init__(self, *args, **kwargs):
 print 'Set E(*%r, **%r)' % (args, kwargs)
 super(type(self), self).__init__(*args, **kwargs)


You'll see the problem when you attempt to create an instance of E.
All of the others work just fine.

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


Re: Modules for inclusion in standard library?

2005-07-02 Thread Terry Reedy

"Colin J. Williams" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>Isn't this where the discussion should start?  There should be some
>general policy guiding the types of modules which should be in the
>standard library.

A couple of times, Guido has given his general policy as generally useful; 
best-of-breed, tested and accepted by the community; and backed by a 
developer who will adapt it and its doc up to stdlib standards (if 
necessary) and commit to maintainence for a few years.

Terry J. Reedy



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


Re: A brief question.

2005-07-02 Thread Terry Reedy

"Nathan Pinno" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

>Brief question for anyone who knows the answer, because I don't.
> Is there anyway to make Python calculate square roots?

Python can calculate any calculable function of the objects it has to work 
with.  So the answer depends on what you mean by 'square roots': the 
infinite decimal or a finite approximation thereof.

Terry J. Reedy



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


Re: wxPython: Terminal Output -> Scrollable Panel?

2005-07-02 Thread flamesrock
Thanks much for your response.

I  looked at PyCrust, and while its given me a few cool ideas, I may
have described the problem incorrectly. What I really need is not
something that takes input, but merely redirects the 'print' statements
to something like a terminal window.

Is this even possible without entering the function calls directly into
a pycrust like terminal? Maybe I'm trying to do the wrong thing.

Thanks

Peter Hansen wrote:
> flamesrock wrote:
> > I want to make it so that clicking on a button that performs an
> > operation will output it to the scrollable wxpython terminal panel, and
> > (if possible) save that output as text (or maybe into a logfile).
>
> The example code includes something called "PyCrust" which does pretty
> much this.  (The logging part is fairly trivial, so I won't mention it.)
>   I'm sure you could look in the source to learn more.  You can start by
> running the demo, and finding that particular one, playing with it a
> bit, and then seeing how the demo code invokes PyCrust.  Then find the
> source for PyCrust in the wxPython folder (under your lib/site-packages
> folder in c:\python24) and start reading.
> 
> -Peter

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


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

2005-07-02 Thread jcarlson
Ralf W. Grosse-Kunstleve wrote:
> A shorter alternative (my personal favorite since minimally redundant)::
>
>   class grouping:
>
>   def __init__(self, .keep_this, .and_this, but_not_this, 
> .but_this_again):
>   # real code right here

There is also the variant which I proposed on python-dev:

class grouping:
def __init__(self, _keep_this, _and_this, but_not_this, _but this
again):
InitAttrs(self, locals())
#real code goes here

Essentially you replace the '.' with '_', which doesn't require a
syntax change.  Unfortunately, both are almost invisible.  It does
offer you what you want right now (without that whole waiting a year+
for Python 2.5, PEP process, etc.).

> Enhanced __slot__ semantics proposal
> 
>
> When ``__slots__`` are used (cool feature!) the boilerplate problem
> becomes even worse::
>
>   class grouping:
>
>   __slots__ = ["keep_this", "and_this", "but_this_again"]
>
>   def __init__(self, keep_this, and_this, but_not_this, but_this_again):
>   self.keep_this = keep_this
>   self.and_this = and_this
>   self.but_this_again = but_this_again
>   # real code, finally

There is also the AutoSlots metaclass (which I have fixed) that does
this as well.

class grouping(object):
__metaclass__ = AutoSlots
def __init__(self, _keep_this, _and_this, but_not_this,
_but_this_again):
InitAttrs(self, locals())
#real code goes here

Both AutoSlots and InitAttrs use leading underscores on the __init__
method to discover which attributes are to be __slots__, and which
should be automatically assigned.

> P.S.: If you reply to this message, please clearly separate
> naming/syntax issues from the core issue of providing built-in support
> designed to reduce clutter.

Because you don't seem to have listened in python-dev, I'll say it
here.  Not everything that reduces clutter should be syntax, and not
every function, class, and module which reduces programming time should
be builtin.  Why?


1. Expanding Python syntax bloats the language.  It increases what you
need to teach to new Python users.  In my opinion, syntax additions
should really only be considered when significant gains in readability
and writability for many users are realized, that a lack of syntax
cannot offer.

2. Expanding the Python standard library bloats the distribution.
Right now, Python is a relatively light download.  But if one were to
include the top packages in everything, the distribution would quickly
bloat to 40+ megs.  This is not an option.  Generally, the requirements
of getting code into the standard library is either a demonstrated need
for the addition, or a known best-of-breed implementation for a
commonly used module, or both.

I believe your syntax change is a non-starter.  Why?  Because I've
offered code that does essentially everything you want, without a
syntax change.  If someone happens to include AutoSlots and InitAttrs
with their code, module, what have you, and it manages to make its way
into standard Python, so be it (I place the code into the public
domain).

The code for the InitAttrs and AutoSlots mechanism are available here:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/435880

 - Josiah

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


Re: wxPython: Terminal Output -> Scrollable Panel?

2005-07-02 Thread Peter Hansen
flamesrock wrote:
> I  looked at PyCrust, and while its given me a few cool ideas, I may
> have described the problem incorrectly. What I really need is not
> something that takes input, but merely redirects the 'print' statements
> to something like a terminal window.
> 
> Is this even possible without entering the function calls directly into
> a pycrust like terminal? Maybe I'm trying to do the wrong thing.

PyCrust would show you a mechanism to get lines of text into a "terminal 
window".  Actually capturing those lines of output is a different story. 
  Here's one approach, if you have control over the print statements:

class Redirector:
 def __init__(self, infoAboutTerminal):
 # store "infoAboutTerminal" in local attributes

 def write(self, text):
 '''output lines of text to terminal window'''
 # here you do whatever PyCrust does to get output to its window
 # using the info stored in the constructor

Assuming you have a PyCrust-like terminal window open somewhere,
you would create a Redirector and pass it whatever info about the 
terminal window that it might need.

terminal = Redirector(infoAboutPyCrustLikeWindow)

Then just send your prints to this location using the >> syntax sugar:

print >>terminal, 'This line of text goes to the GUI window.'
print >>terminal, 'So does all this\neven multiple lines...'

If you *don't* have the ability to change the print statements like 
this, then you can install a Redirector in place of sys.stdout, but that 
will affect all prints, including those in standard library modules and 
elsewhere.

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


Determining actual elapsed (wall-clock) time

2005-07-02 Thread Peter Hansen
I would like to determine the "actual" elapsed time of an operation 
which could take place during a time change, in a platform-independent 
manner (at least across Linux/Windows machines).

Using time.time() doesn't appear to be suitable, since time might jump 
forwards or backwards at the user's whim, if the system clock is reset, 
or when a daylight savings time change occurs.

Using time.clock() doesn't appear to be suitable on Linux, though it 
appears sufficient on Windows.  (I'm willing to assume nobody will reset 
whatever QueryPerformanceCounter() uses to return the time.clock() value 
on Windows.)

There used to be a "timing" module (according to 
http://effbot.org/librarybook/timing.htm) which would likely have worked 
(for Unix at least), but it's not in the latest Pythons.

I can deal with wraparounds if necessary.  I'm not too concerned about 
the resolution, though better than one second would be useful.

Thanks for any suggestions.

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


Re: Determining actual elapsed (wall-clock) time

2005-07-02 Thread Roy Smith
Peter Hansen <[EMAIL PROTECTED]> wrote:
> I would like to determine the "actual" elapsed time of an operation 
> which could take place during a time change, in a platform-independent 
> manner (at least across Linux/Windows machines).
> 
> Using time.time() doesn't appear to be suitable, since time might jump 
> forwards or backwards at the user's whim, if the system clock is reset, 
> or when a daylight savings time change occurs.

If you get the UTC time, daylight savings time doesn't enter the equation.  
If the system clock is reset, however, you're out of luck.  I can't think 
of any time-related API which doesn't rely on the system clock as a 
reference.  If the system clock is good, you get good time.  If the system 
clock sucks, or changes, you don't.

If you care about time, you want your system clock controlled by NTP.  
There's just no excuse not to.

Is there some reason you can't just use the system clock?  I suppose if you 
had to, you could hobble together your own NTP client which keeps network 
time independent of the system clock.  But that would be a lot of work and 
it's hard to imagine the effort would be justified.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython: Terminal Output -> Scrollable Panel?

2005-07-02 Thread flamesrock
Exactly what I'm looking for! Thanks

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


Re: Determining actual elapsed (wall-clock) time

2005-07-02 Thread Peter Hansen
Roy Smith wrote:
> Peter Hansen <[EMAIL PROTECTED]> wrote:
> If you get the UTC time, daylight savings time doesn't enter the equation.  

Of course... I didn't think of that approach.  I don't actually care 
about absolute time, so this should work fine for at least the DST case.

> If you care about time, you want your system clock controlled by NTP.  
> There's just no excuse not to.

I guess as long as the NTP client is set up to ensure the time 
adjustments are smaller than some value X, it would be acceptable.  I'll 
have to look into how to set up Windows XP to prevent users from 
changing the time on their own, assuming that's possible.

> Is there some reason you can't just use the system clock?  

I was anticipating use of the system (running on Windows in this case) 
by users who might decide to change the time, and in certain cases that 
could cripple the software.  I hadn't thought of the possibility of 
simply preventing that, though if I insist on an NTP client being 
installed, they shouldn't have a problem with that.

Thanks for correcting my thought process...

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


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

2005-07-02 Thread Mike C. Fletcher
Ralf W. Grosse-Kunstleve wrote:
...

>class grouping:
>
>def __init__(self, x, y, z):
>self.x = x
>self.y = y
>self.z = z
># real code, finally
>
>This becomes a serious nuisance in complex applications with long
>argument lists, especially if long variable names are essential for
>managing the complexity. Therefore I propose that Python includes
>built-in support for reducing the ``self.x=x`` clutter. Below are
>arguments for the following approach (*please* don't get too agitated
>about the syntax right here, it really is a secondary consideration)::
>  
>
...

This can be dealt with quite nicely if you take a step back and consider
what you're trying to do:

* define a set of properties/fields for a class, potentially with
  default values for any given property
* define an initialisation function which, given an instance of a
  class with defined properties (potentially with defaults) and a
  mapping of name:value pairs, assigns the named values to the named
  properties...

class Grouping( propertied.Propertied ):
x = FloatProperty(
   "x", """Holder for the grouping node's x coordinate""",
   defaultValue = 0,
)
y = FloatProperty(
   "y", """Holder for the grouping node's y coordinate""",
   defaultValue = 0,
)
z = FloatProperty(
   "z", """Holder for the grouping node's z coordinate""",
   defaultValue = 0,
)
def __init__( self, **args ):
   # code here to do whatever you like to args (or whatever)...
   super( Grouping, self ).__init__( **args )
   # extra code here...

where the propertied.Propertied class defines a simple init that
iterates through the defined properties pulling those which are present
in the **args of the __init__ function and assigning them to the
appropriate property.

The advantage here is that your class is now documented properly, with
the information about a given property all localised in a definition of
the property.  Your properties can also implement the observer pattern,
automatic type checking and coercion, and can provide default values
that appear when you delete current values (not just during
initialisation).  You can also do useful things like using the defined
properties of a class to auto-generate __repr__ and __str__ values.  You
can have your properties delegate to other objects, or have them delay
loading/resolving a property's value until the last possible second
(lazy loading from an object database, for instance).

The fact that it's all doable in Python 2.2+ without any need for new
syntax... well... that's cool too.

The disadvantage is that the properties tend to be unordered (unless you
explicitly order them, and that's awkward looking), and you have to pass
them to the constructor as keyword arguments.  But then, if you're
defining a class with 50 properties, you likely aren't really wanting to
pass all 50 as positional arguments anyway.

You'll find patterns like this in my own OpenGLContext (3D scenegraph
viewer) and BasicProperty packages, as well as in Traits (originally
part of a 2D graphics package), and Zope's FieldProperty (and PEAK,
though as always with PEAK, it's somewhat weird in there ;) ).  All of
those are largish systems (or used in largish systems), btw.

Just my thoughts,
Mike

-- 

  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

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


Re: Python, mysql, floating point values question

2005-07-02 Thread Terry Hancock
On Friday 01 July 2005 11:13 pm, John Machin wrote:
> x BETWEEN y AND z

Ah, even better, thank you.

>The python equivalent would be to write it out as:
> > 
> > if  a > b-epsilon and a < b+epsilon:
> > print "a~=b"
> 
> Try this:
> 
> if b-epsilon < a < b+epsilon:

This I knew, but I was trying to write the closest thing
to what the SQL code would look like, and I didn't know
about BETWEEN.

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

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


Re: When someone from Britain speaks, Americans hear a "British accent"...

2005-07-02 Thread TZOTZIOY
On 28 Jun 2005 13:24:42 -0700, rumours say that "muldoon"
<[EMAIL PROTECTED]> might have written:

>   Now, what forum would you recommend? Any help would be appreciated.

alt.usage.english?
alt.languages.english?
alt.english.usage?
uk.culture.language.english?
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When someone from Britain speaks, Americans hear a "British accent"...

2005-07-02 Thread TZOTZIOY
On Thu, 30 Jun 2005 18:29:56 +0100, rumours say that Tom Anderson
<[EMAIL PROTECTED]> might have written:

>On Thu, 30 Jun 2005, Benji York wrote:
>
>> python-needs-more-duct-tape'ly yours,
>
>You're in luck: Python 3000 will replace duck typing with duct taping.

I would bet that somewhere in the "Ingliy-spiking werld" both terms
sound exactly the same.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for everything?

2005-07-02 Thread TZOTZIOY
On Thu, 30 Jun 2005 20:55:20 -0400, rumours say that Mike Meyer
<[EMAIL PROTECTED]> might have written:

>Actually, I was thinking of pre-K&R Unix compilers.

There must be something I am missing here, cause I don't understand what
you mean; what is the earliest K&R C compiler ("Unix" compiler) you
consider as such?  Were there other Unix C compilers before K&R wrote
one?  Or are you considering as "K&R Unix compilers" those after the
publication of the white book and before C89?
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What are the other options against Zope?

2005-07-02 Thread phil

> either... It sits under... 

Well that's a relief, cause ...sits on top of
was confusing.


> A rather object-oriented system for managing and serving web
> applications and data (using object inheritance for common behavior,
> etc.) This makes Zope a toolkit, not an end application itself.


So that would make it Apache, with a Python CGI. Oh wait, Apache has
a Python CGI which can access Data bases and send objects to the client.

A web application is you deliver am html page and the user fills
in some forms, then submits the form, which is then validated
and another form is delivered. Right?  Cool idea, IBM had that in
1975 it was called CICS.

I once asked my son-in-law tech support guy what is the Windows
registry, what does it do?  He thought for a while and said
"Think of it as the soul of the machine".  So I thought about it
as the soul of the machine for a while, then I asked;
"You don't know, do you", and he said "No."





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


Re: shelve in a ZipFile?

2005-07-02 Thread Terry Hancock
On Friday 01 July 2005 04:40 pm, Andreas Kostyrka wrote:
> It's even worse: shelve is basically a class that wraps a dictionary. It
> provides a dictionary string -> pickable object based on a dictioary
> string -> string. bsddb, gdbm etc. probably access files via lowlevel
> calls that are not interceptable. 
> 
> One way to achieve your goals would be to add compression and/or a key
> prefix (which would allow multiple dictionaries or at least key spaces
> in one file)

Yeah, I'm already using a character prefix for header data in the
1st file. Right now, one of the headers tells where to find the 2nd file.

Seems to be working okay.

I'm a little bothered by the idea of lumping both into one dictionary,
though I see this could be done the same way. 

I wasn't really looking for a way to compress the data (just thought it
was a nice side benefit), but your post reminded me that I could do
it with zlib on the data *before* storing them in the shelf.  I guess if
bulk becomes an issue I'll try that.

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

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


Re: Determining actual elapsed (wall-clock) time

2005-07-02 Thread Roy Smith
Peter Hansen <[EMAIL PROTECTED]> wrote:
> I guess as long as the NTP client is set up to ensure the time 
> adjustments are smaller than some value X, it would be acceptable.

NTP is generally capable of keeping the various system clocks on a LAN 
within a few ms of each other, and within a few 10's of ms over the 
Internet from GPS, WWV, or similar international time references.

> I'll have to look into how to set up Windows XP to prevent users from 
> changing the time on their own, assuming that's possible.

On a single-user system like Windows, you pretty much have to assume the 
user can do anything.  They can turn off NTP, reset the clock, reboot the 
system, uninstall your software, whatever.

If you could check to see that NTP is running, it doesn't prove anything.  
A malicious and determined user could set up another machine as a NTP 
server to synch against, and even configure that machine to look like it 
was a stratum-1 reference (i.e. an atomic clock).

At some point, you need to decide if you trust the system administrator to 
supply you with an accurate system clock or not.  If you don't, and it's 
really important that you have an accurate time reference, you've got an 
interesting engineering problem on your hands.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for everything?

2005-07-02 Thread Roy Smith
Christos "TZOTZIOY" Georgiou <[EMAIL PROTECTED]> wrote:
> Were there other Unix C compilers before K&R wrote one? 

Considering that K&R (along with T) invented both Unix and C, I would say 
that the answer to the above has to be "No".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What are the other options against Zope?

2005-07-02 Thread Terry Hancock
On Saturday 02 July 2005 10:55 am, phil wrote:
> Zope is like that to me.  I ask what is it and the answer
> sounds like "Oh, it's oierbv for the zxcvioupo of 7cvn^djh'.
> 
> Now understand, I know what very well what Python, Apache, PhP,
> MySQL, IE and javascript do.  I just don't know what Zope
> does.

You know, that's a good question. Let's see if I can make a good
answer:

Zope is the "Z Object Publishing Environment".

It publishes a *tree* of *objects* stored in the ZODB which is
an object oriented database.  Think of it as a monstrous pickle
implementation.

Zope folders are a lot like user-defined classes in your application.
They contain things, which is why they're called "folders". But
basically, from a programming perspective, what they contain
are their "attributes" in the class/object jargon (in reality it can
be more complicated, some containers use Python container
types like dictionary or list as their internal structure).

Of course, "publishes" means "publishes to the web".

Z:

So Zope includes an *object store*, a *publisher*,
and a *web server*.   When the web server receives a request,
it asks the publisher to get it, which digs it out of the object
store.  Then it goes back the other way, back to the requester
via the web.

Usually, you run the Zope webserver behind another proxy
like Apache, but it is possible to serve a site directly from
Zope.  I never do that for production, because, Apache, being
much more completely tested is a safer bet for not crashing
or misbehaving under heavy loads.  However, the built-in
Zope webserver (I believe it was once called Medusa) is
quite convenient for development and testing.

OBJECT:

Because Zope publishes Python *objects* instead of  *files*,
they can have much richer structure (e.g. metadata) than
a site based on files stored in a filesystem.  However, a set
of files stored in a filesystem is very much like an object
database, so

1) The ZODB is sometimes called the Zope Object FileSystem,
which I find a useful idea --- especially since ZOFS has some
extra constraints beyond what ZODB requires.

2) You actually can store contents of the ZODB *as* a filesystem
with associated metadata in auxiliary files. I believe this is
how the "filesystem storage" option for ZODB works (by default,
ZODB lumps all its data into one big container file "Data.fs" --
this is the "filestorage" option).

PUBLISHING:

Zope has also been called a "web application server", because
it's relatively easy to write highly-integrated, highly-dynamic
sites with it (and overkill to use it for purely static sites).

Objects are defined in such a way that they can be represented
as web pages.  The publisher has a lot of default behaviors for
built-in types and the objects that come with Zope.

Zope "product" developers have the responsibility (and control)
over how their objects will appear when published.

ENVIRONMENT:

If you want to think of it as a "web application server", then
basically, Zope is your "operating system", and your site is
your "web application software".

Zope also provides some specialized programming language
help --- Python scripts that can be edited through the web,
and two "Templating Languages" for designing web pages that
will have dynamic content.  You can think of the templating
languages as being similar to PHP or ASP style programming.

But "Zope Zen" says that the serious code should be either
in Python scripts or in Python products (on the filesystem, 
instead of in the ZODB, like scripts).   Templates are meant
to be simple, simple, simple.  But that's a style issue.

This stuff provides the Zope "operating system" with a
"shell".  And the "Zope Management Interface", which is
what you see when you visit the /manage page at a Zope
site, is the "window system" or, perhaps more accurately,
the "file browser" of that "operating system".

So, in fact, Zope does quite a bit.  But it isn't really all
that hard to understand. It's just not been well-introduced,
because the people explaining it have a tendency to forget
that it isn't all obvious, because it seems that way to
them, now that they know it.

But that's the newbie's problem in all areas of software, ISTM.

HTH,
Terry

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

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


Re: What are the other options against Zope?

2005-07-02 Thread [EMAIL PROTECTED]
If you're looking for a leight weight web development enviroment acting
as a front end for a database take a look at http://www.cherrypy.org

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


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

2005-07-02 Thread Terry Hancock
On Saturday 02 July 2005 05:04 am, Ralf W. Grosse-Kunstleve wrote:
> I often find myself writing::
> 
> class grouping:
> 
> def __init__(self, x, y, z):
> self.x = x
> self.y = y
> self.z = z
> # real code, finally

Fortunately, you don't have to, try this:
#(1)
class grouping:
def __init__(self, *args):
parms = ('x', 'y', 'z')
arg_parms = zip(parms, args[:len(parms)])
for parm, arg in arg_parms:
setattr(self, parm, arg)

In this case, of course, this isn't any shorter, but if you have
a few dozen parameters, it can be.

Note, that it may be stylistically better to do this:
#(2)
class grouping:
def __init__(self, **kw):
for key, val in kw.items():
setattr(self, key, val)

or possibly:
#(3)
class grouping:
def __init__(self, **kw):
parms = ('x', 'y', 'z')
for key, val in kw.items():
if key in parms: setattr(self, key, val)

Because, if you are going to have dozens of arguments, it will be hard
for you to remember their order in the caller, and keyword arguments
will make it possible to set them by name.  Example (2) doesn't validate
the arguments -- allowing you to set any arbitrary collection of values
you want (can be a useful way to create a shared namespace), but (3)
does (which is probably important if your class actually does specific
things with the parameters).

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

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


Re: Running Python interpreter in Emacs

2005-07-02 Thread Rex Eastbourne
Yes, I knew that copying it to my root was a kludge. But between that
and not having it work, I chose the former. (As you might be able to
tell from my posts, I tried multiple things and was frustrated.) I
tried putting quotes around "c:\program files\python24". It still
didn't work.

I chose to install Python in Program Files. I didn't know it would
cause any problems; I just thought it was good to have all my programs
in the same place. I guess I was wrong.

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


Re: Python, mysql, floating point values question

2005-07-02 Thread Christopher Kang
Thanx all for responding.

I've been doing the epsilon comparisons, i had just hoped that to be a
temporary solution.

anyway, thanx for the responses
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determining actual elapsed (wall-clock) time

2005-07-02 Thread Peter Hansen
Roy Smith wrote:
> Peter Hansen <[EMAIL PROTECTED]> wrote:
>>I'll have to look into how to set up Windows XP to prevent users from 
>>changing the time on their own, assuming that's possible.
> 
> On a single-user system like Windows, you pretty much have to assume the 
> user can do anything.  They can turn off NTP, reset the clock, reboot the 
> system, uninstall your software, whatever.

Actually, I suspect that a non-administrator user can be restricted from 
doing several of those things under XP, which would simplify things.

And, in any case, I'm not remotely concerned about malicious users, just 
"fiddlers" who might think their watch time is somehow more correct than 
what the computer says...

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


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

2005-07-02 Thread John Machin
Christos TZOTZIOY Georgiou wrote:
> On Fri, 01 Jul 2005 23:45:57 +1000, rumours say that John Machin
> <[EMAIL PROTECTED]> might have written:
> 
> 
>>Simon Brunning wrote:
>>
>>>On 7/1/05, Peter Maas <[EMAIL PROTECTED]> wrote:
>>>
>>>
Simon Brunning schrieb:


>   Sibylle Koczian needs to sort part of a list. His first attempt made
>   the natural mistake - sorting a *copy* of part of the list:
> 
> 
> [Peter]
> 
I think it was _her_ first attempt.
> 
> 
> [Simon]
> 
>>>Ooops! Sorry, Sibylle.
> 
> 
> [John]
> 
>>Obviously haven't spent enough time watching Fawlty Towers :-)
> 
> 
> Then surely it should have been "its" first attempt?  Aren't piranhas
> neutral?

Neutral: no, they always seem to be active combatants.
Neuter: one would hope so, lest they procreate.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's wrong with this code?

2005-07-02 Thread Tim Roberts
"Nathan Pinno" <[EMAIL PROTECTED]> wrote:
>
>  Hi all,
>
>  What's wrong with the following code? It says there is name error, that
>random is not defined. How do I fix it?
>
>  # Plays the guessing game higher or lower.
>  # Originally written by Josh Cogliati, improved first by Quique, then by
>Nathan Pinno.
>  print "Higher or Lower"
>  print
>  number = random.choice(range(100))
>  guess = 0
>  while guess != number:
>  guess = input("Guess a number: ")
>  if guess > number:
>  print "Too high"
>  guess = input("Guess a number: ")
>  elif guess < number:
>  print "Too low"
>  guess = input("Guess a number: ")
>  print "Just right"

There is a problem with this, caused by having to repeat the same code in
multiple places.  Sa that the number is 50.  You get to the first "input"
statment, and you enter 30.  It prints "Too low", and asks you to enter
another number.  You enter 40.  The "while" expression is true, so it will
loop again, and prompt you to enter ANOTHER number, without telling you
whether it was high or low.

Better to eliminate duplicated code:

import random
print "Higher or Lower"
print
number = random.choice(range(100))
while 1:
guess = input("Guess a number: ")
if guess == number:
break
elif guess > number:
print "Too high"
else:
print "Too low"
print "Just right"
  
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determining actual elapsed (wall-clock) time

2005-07-02 Thread Peter Hansen
Roy Smith wrote:
> Peter Hansen <[EMAIL PROTECTED]> wrote:
>>Using time.time() doesn't appear to be suitable, since time might jump 
>>forwards or backwards at the user's whim, if the system clock is reset, 
>>or when a daylight savings time change occurs.
> 
> If you get the UTC time, daylight savings time doesn't enter the equation.  

Hmmm... not only that, but at least under XP the return value of 
time.time() _is_ UTC.  At least, it's entirely unaffected by the 
daylight savings time change, or (apparently) by changes in time zone.

Looks like time.time() might be sufficient.  (That might be what Roy 
intended, but I initially thought he meant time.gmtime(time.time()), 
which could have resulted in a race condition if time.time() jumped 
ahead or back separately from some internal daylight savings time flag, 
and the value was read between the two operations.)

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


Re: Determining actual elapsed (wall-clock) time

2005-07-02 Thread Tim Peters
[Peter Hansen]
> Hmmm... not only that, but at least under XP the return value of
> time.time() _is_ UTC.  At least, it's entirely unaffected by the
> daylight savings time change, or (apparently) by changes in time zone.

On all platforms, time.time() returns the number of seconds "since the
epoch".  All POSIX systems agree on when "the epoch" began, but that
doesn't really matter to your use case.  Number of seconds since the
epoch is insensitive to daylight time, time zone, leap seconds, etc. 
Users can nevertheless make it appear to jump (into the future or the
past) by changing their system clock.  If you need an absolute measure
of time immune to user whims, you need to connect to special hardware,
or to an external time source.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A brief question.

2005-07-02 Thread Tom Brown
On Saturday 02 July 2005 10:55, Nathan Pinno wrote:
>   Brief question for anyone who knows the answer, because I don't. Is
> there anyway to make Python calculate square roots?

from math import sqrt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's wrong with this code?

2005-07-02 Thread John Machin
Nathan Pinno wrote:
>   Hi all,
> 
>   What's wrong with the following code? It says there is name error, that
> random is not defined. How do I fix it?

Others have already answered that question. This posting is a 
pre-emptive strike to head off the next half-a-dozen questions.

> 
>   # Plays the guessing game higher or lower.
>   # Originally written by Josh Cogliati, improved first by Quique, then by
> Nathan Pinno.

Some of us are interested in the process by which great pieces of code 
arise, how they are meticulously honed and polished, which craftpersons 
contributed what ... is it possible for you to publish the earlier versions?

>   print "Higher or Lower"
>   print
>   number = random.choice(range(100))

"number" will refer to one of: 0, 1, .., 98, 99

>   guess = 0

so you'll get a strange result by using zero here; try -1 instead

>   while guess != number:
>   guess = input("Guess a number: ")

"guess" will refer to a string e.g. "42" which will *not* compare equal 
to the integer 42. Also you should use raw_input, not input.

so do this:

guess = int(raw_input("Guess a number: "))

>   if guess > number:
>   print "Too high"
>   guess = input("Guess a number: ")

This will cause your program to ask TWICE per trip around the loop. Lose it.

>   elif guess < number:
>   print "Too low"
>   guess = input("Guess a number: ")

... and again.

>   print "Just right"
> 

General advice:
1. Look on the Python web site (http://www.python.org) for an 
introduction to Python for non-programmers.
2. Join the Python tutor list.
3. In this news group, read a little more than the threads that you have 
  started; this guessing game was discussed in a thread started by 
somebody calling themselves ChuckDubya on 29 June!! Homework??

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


Re: A brief question.

2005-07-02 Thread Tom Anderson
On Sat, 2 Jul 2005, Tom Brown wrote:

> On Saturday 02 July 2005 10:55, Nathan Pinno wrote:
>
>> Brief question for anyone who knows the answer, because I don't. Is 
>> there anyway to make Python calculate square roots?
>
> from math import sqrt

That's one way. I'd do:

root = value ** 0.5

Does that mean we can expect Guido to drop math.sqrt in py3k? :)

tom

-- 
That's no moon!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular Expression for pattern substitution

2005-07-02 Thread James Stroud
You might want to be a little more explicit. Do you know that

this = "this"
that = "that"

or do you mean 

this = `the part before the \D*`
that = `the part after the \D*`

If you mean the former, then the previously proposed

py> import re
py> line = 'see this man with that woman holding this dog and that cat'
py> r = re.compile(r'this(\D*?)that')
py> r.sub(r'that\1this',line)

will do fine.

If you mean the latter, then you should describe the type of pattern that
this and that belong to. Also, consider how greedy your \D* is:

py> line = 'this abcd this efgh that'
py> r.sub(r'that\1this',line)
'that abcd this efgh this'

Would this be the result you expect?






James

On Friday 01 July 2005 09:39 am, Vibha Tripathi wrote:
> It'd be silly to write the code for it if it already
> exists somewhere in the Python re or sre library
> module:
>
> I need to find and replace all strings in a text file
> from a certain pattern to another pattern.
>
> so for example if I see 'this(\D*)that' anywhere in
> the file then I'd like to make is 'that(\D*)this'
> where the middle part of the strings remains
> unmodified.
>
> Any suggestions?
>
> Peace.
> Vibha
>
> PS. How do I avoid getting my email ID web-published
> for this mailing list.?
>
>
>
> 
> Yahoo! Sports
> Rekindle the Rivalries. Sign up for Fantasy Football
> http://football.fantasysports.yahoo.com

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

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


Re: Determining actual elapsed (wall-clock) time

2005-07-02 Thread John Machin
Roy Smith wrote:
> Peter Hansen <[EMAIL PROTECTED]> wrote:
> 
>>I guess as long as the NTP client is set up to ensure the time 
>>adjustments are smaller than some value X, it would be acceptable.
> 
> 
> NTP is generally capable of keeping the various system clocks on a LAN 
> within a few ms of each other, and within a few 10's of ms over the 
> Internet from GPS, WWV, or similar international time references.
> 
> 
>>I'll have to look into how to set up Windows XP to prevent users from 
>>changing the time on their own, assuming that's possible.
> 
> 
> On a single-user system like Windows, you pretty much have to assume the 
> user can do anything.  They can turn off NTP, reset the clock, reboot the 
> system, uninstall your software, whatever.
> 
> If you could check to see that NTP is running, it doesn't prove anything.  
> A malicious and determined user could set up another machine as a NTP 
> server to synch against, and even configure that machine to look like it 
> was a stratum-1 reference (i.e. an atomic clock).
> 
> At some point, you need to decide if you trust the system administrator to 
> supply you with an accurate system clock or not.  If you don't, and it's 
> really important that you have an accurate time reference, you've got an 
> interesting engineering problem on your hands.

A couple of quick thoughts: (1) stupidity is much more prevalent than 
malice in that environment.

(2) Peter, if your app has something else to measure e.g. it is 
processing zillions of rows from a database, grab the [UTC] wall time 
every N things, and apply plausibility checks to the speed N/delta(wall) 
-- if it goes negative or "too high" or "too slow", holler fer a mountie.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A brief question.

2005-07-02 Thread Fredrik Johansson
On 7/3/05, Tom Anderson <[EMAIL PROTECTED]> wrote:
> That's one way. I'd do:
> 
> root = value ** 0.5
> 
> Does that mean we can expect Guido to drop math.sqrt in py3k? :)

I'd rather like to see a well implemented math.nthroot. 64**(1/3.0)
gives 3.9996, and this error could be avoided.

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


Re: What's wrong with this code?

2005-07-02 Thread John Machin
John Machin wrote:
> Nathan Pinno wrote:

>>   guess = input("Guess a number: ")
> 
> 
> "guess" will refer to a string e.g. "42" which will *not* compare equal 
> to the integer 42. Also you should use raw_input, not input.
> 
> so do this:
> 
> guess = int(raw_input("Guess a number: "))
> 

Ahem ... I'll redo that:

You'd be better using raw_input, which *then* means you need to wrap 
int() around it, ending up with the same recommendation:

guess = int(raw_input("Guess a number: "))

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


Re: Inheriting from object

2005-07-02 Thread Steven Bethard
Bengt Richter wrote:
> I wonder if the above common use of super could be implemented as a property 
> of object,
> so you'd normally inherit it and be able to write
> self.super.__init__(*args, **kwargs)  # (maybe spell it 
> self.__super__.__init__(...) I suppose)
> 
> I.e., self.__super__ would effectively return the equivalent of
> super(type(self), self)
> 
> (I think Michele Simionato may have posted some idea like this early on that
> I didn't really follow, but maybe my subconscious snagged and garbled ;-)

Here's the link I believe you're referring to:
http://groups-beta.google.com/group/comp.lang.python/msg/0034684c138cf9f3

Probably worth reading for anyone interested in making super syntax 
"look prettier".  Basically Michele shows that the current super() 
object fails in a number of ways when you try to make it a class attribute.

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


Re: When someone from Britain speaks, Americans hear a "British accent"...

2005-07-02 Thread Darkfalz
muldoon wrote:
> Americans consider having a "British accent" a sign of sophistication
> and high intelligence. Many companies hire salespersons from Britain to
> represent their products,etc. Question: When the British hear an
> "American accent," does it sound unsophisticated and dumb?
>
> Be blunt. We Americans need to know. Should we try to change the way we
> speak? Are there certain words that sound particularly goofy? Please
> help us with your advice on this awkward matter.

I find this amusing even when they have the most cockney, ghetto
English accent, Americans still find it "sophisticated".

And yes, seppos sound like dumb fucks to the entire rest of the world.

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


Re: Favorite non-python language trick?

2005-07-02 Thread Steven D'Aprano
On Fri, 01 Jul 2005 12:24:44 -0700, Devan L wrote:

> With the exception of reduce(lambda x,y:x*y, sequence), reduce can be
> replaced with sum, and Guido wants to add a product function.

How do you replace:

reduce(lambda x,y: x*y-1/y, sequence) 

with sum?


Inquiring minds want to know.


-- 
Steven.

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


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

2005-07-02 Thread Steven D'Aprano
On Fri, 01 Jul 2005 09:13:58 -0700, mcherm wrote:

> Lambda serves a very specific purpose: declaring small, in-place
> functions which are no bigger than a single expression. I do this often
> enough that I  DO want special syntax for it. But I'll admit that I
> wish "lambda" were about 5 or 6 characters shorter 

As in an empty string? :-)

> and didn't have such an obscure name.

Lambda is no more an obscure name than "function", "decorator", "closure",
"class", or "module". The first time you come across it, you don't know
what it means. Then you learn what it means, and then you know.



-- 
Steve



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


Re: Assigning to None (was Re: Question about Python)

2005-07-02 Thread Steven D'Aprano
On Fri, 01 Jul 2005 12:59:20 -0400, François Pinard wrote:

> [Peter Hansen]
>> Mike Meyer wrote:
>> > Yes. I once grabbed an old program that did assignments to None. But
>> > that's always been a bad idea.
> 
>> What was the use case!?
> 
> People used to assign None to itself as a keyword argument in function
> headers.  The goal was to make a local copy of the reference, which was
> then accessed faster than the global thing.

Can you say "premature optimization is the root of all evil"?

I'd like to see the profiling that demonstrated that this made a
significant -- or even measurable -- speed-up in anything but the most
unusual cases.


-- 
Steven

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


  1   2   >