SciPy Core (Numeric replacement) version 0.6.1 released

2005-11-13 Thread Travis Oliphant
Background:

Numeric  is an add-on Python module that has seen widespread adoption.  
It enables Python to be used as a Scientific Computing Environment 
similar to MATLAB or IDL.  Numeric was originally written nearly 10 
years ago, and while still performing admirably, needed much updating to 
take advantage of the new features in Python and to remove old warts.

SciPy Core 0.6.1

SciPy Core is a new system which builds on the code-base of Numeric, but 
implements features (such as advanced index-selection, and user-settable 
error modes).  There are over 25 major new feature enhancements.  The 
LICENSE is still a BSD style License---the same as old Numeric.  More 
information can be found at the web-site: http://numeric.scipy.org

PA HREF=http://numeric.scipy.org;SciPy Core 0.6.1/A - Replacement 
for Numeric Python. (12-Nov-05)
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


ANN: FormEncode 0.3

2005-11-13 Thread Ian Bicking
I'm pleased to announce FormEncode 0.3.

What is it?
---

FormEncode is a package for form validation and conversion.  It also
includes modules for parsing, filling, and extracting metadata from HTML
forms.  It features robust conversion both of incoming and outgoing
data, attention paid to helpful error messages, and a wide variety of
pre-build validators.  It also supports composition of validators, and
validating structured data, including nested and repeating form elements.

FormEncode is being used in several projects, including Subway,
TurboGears, and SQLObject.

Where is it?


Website and docs:
  http://formencode.org
Download:
  http://cheeseshop.python.org/pypi/FormEncode

What has changed?
-

From the news file:

* Allow errors to be inserted automatically into a form when using
  ``formencode.htmlfill``, when a ``form:error`` tag isn't found for
  an error.

* Added ``if_key_missing`` attribute to ``schema.Schema``, which will
  fill in any keys that are missing and pass them to the validator.

* ``FancyValidator`` has changed, adding ``if_invalid_python`` and
  ``validate_python`` options (which also apply to all subclasses).
  Also ``if_empty`` only applies to ``to_python`` conversions.

* ``FancyValidator`` now has a ``strip`` option, which if true and if
  input is a string, will strip whitespace from the string.

* Allow chained validators to validate otherwise-invalid forms, if
  they define a ``validate_partial`` method.  The credit card
  validator does this.

* Handle ``FieldStorage`` input (from file uploads); added a
  ``formencode.fieldstorage`` module to wrap those instances in
  something a bit nicer.  Added
  ``validators.FieldStorageUploadConverter`` to make this conversion.

* Added ``StringBoolean`` converter, which converts strings like
  ``true`` to Python booleans.

Bugfixes


* A couple fixes to ``DateConverter``, ``FieldsMatch``,
  ``StringBoolean``, ``CreditCardValidator``.

* Added missing ``Validator.assert_string`` method.

* ``formencode.htmlfill_schemabuilder`` handles checkboxes better.

* Be a little more careful about how ``Invalid`` exceptions are
  created (catch some errors sooner).

* Improved handling of non-string input in ``htmlfill``.

Experiments
~~~

* Some experimental work in ``formencode.formgen``.  Experimental, I
  say!

* Added an experimental ``formencode.context`` module for
  dynamically-scoped variables.


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

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


SciPy 0.4.3 released (built against 0.6.1 of scipy_core)

2005-11-13 Thread Travis Oliphant
Background:

Full scipy builds on top of scipy_core to provide many more tools for 
computational science and engineering.  Included are tools for 
optimization, integration (including ode solvers), signal processing, 
sparse matrices, complete FFTs, complete linear algebra, statistical 
functions, input and output routines, interpolation, integration, and 
many special functions.

SciPy 0.4.3

This version is the first release to build on top of the new scipy_core 
(v 0.6.1).  The code is relatively stable, but there may be some 
lingering bugs from the transition from Numeric.  Please report any 
errors you find.  The LICENSE is a BSD style License---the same as 
scipy_core.  More information can be found (some of which is dated) at  
http://www.scipy.org.  The sourceforge site where it can be downloaded 
is http://sourceforge.net/projects/scipy.

PA HREF=http://www.scipy.org;SciPy (full) 0.4.3/A - Extension 
modules for scipy_core (12-Nov-05)
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: Problem with __str__ if baseclass is list

2005-11-13 Thread Serge Orlov
Edward C. Jones wrote:
 #! /usr/bin/env python

 class A(list):
  def __init__(self, alist, n):
  list.__init__(self, alist)
  self.n = n

  def __str__(self):
  return 'AS(%s, %i)' % (list.__str__(self), self.n)

  def __repr__(self):
  return 'AR(%s, %i)' % (list.__repr__(self), self.n)

 a = A(['x', 'y'], 7)

 print 1, a
 print 2, repr(a)
 print 3, list.__str__(a)
 print 4, list.__repr__(a)

 
 The output is:

 1 AS(AR(['x', 'y'], 7), 7)
 2 AR(['x', 'y'], 7)
 3 AR(['x', 'y'], 7)
 4 ['x', 'y']

 Why is list.__str__(a) == AR(['x', 'y'], 7)?

Because it's coded like this:
def __str__(self):
return repr(self)

That implies str(x) == repr(x), since you don't want that, don't call
list.__str__


 Note: The problem goes away if list.__str__(a) is replaced with
 list.__repr__(self).
 

That's right. You *cannot* call list.__str__ because it contradicts
design of class A

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


Re: something wrong in wx

2005-11-13 Thread Tim Roberts
Robert [EMAIL PROTECTED] wrote:

something wrong in wx

I doubt it.

I wrote program training na Artificial Neural Network. It work well in
console mode, but when I try to add GUI there is an error:
FANN Error 10: Error reading info from train data file zapis.txt, line: 2

How are you launching the GUI version?  Are you double-clicking on an icon
somewhere?  Are you sure the application is starting in the correct
directory -- the one that contains zapis.txt?

Perhaps you should try hard-code the full path, or at least doing an
os.chdir().
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.chown()

2005-11-13 Thread Tim Roberts
James Colannino [EMAIL PROTECTED] wrote:

Hey everyone.  I tried to use os.chown() in the following manner:

os.chown('filename', 'username', 'groupname')

I got an error, and when I googled for this function I realized that I 
must pass the numerical uid and gid.  My question is, is there a way for 
me to change ownership based on the name instead of the number?  Perhaps 
there's a function that will let me lookup the uid from the username, 
and the gid from the groupname?

One way is:
  os.system( 'chown username:groupname filename')

Are you doing this as root?  The chown function is usually restricted to
root.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inheritence Problem

2005-11-13 Thread Serge Orlov
[EMAIL PROTECTED] wrote:
 Hello.  I'm trying to mod an open source app called TinyERP and inherit
 from a parent object, and in essence change how _column is defined.  I
 found sample code of:

Looks like Spot the differences puzzle to me. Hint: look at the
underscore characters.


 class custom_product(osv.osv):
   __inherits__ = product.product
   __name__ = product.product
  _columns  = {
 'color' : fields.many2one('color','Color'),
 'size': fields.many2one('size','Size'),
  }
 custom_product()


...

  class product_uom_categ(osv.osv):
   _name = 'product.uom.categ'
   _description = 'Product uom categ'
   _columns = {
   'name': fields.char('Name', size=64, required=True),
   }
 product_uom_categ()

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


Re: Proposal for adding symbols within Python

2005-11-13 Thread Pierre Barbier de Reuille
Ben Finney a écrit :
 Pierre Barbier de Reuille [EMAIL PROTECTED] wrote:
 
This proposal suggests to add symbols into Python.
 
 
 I still don't think symbol is particularly descriptive as a name;
 there are too many other things already in the language that might
 also be called a symbol.

Well, that's the name in many languages. Then, probably all the things
already in the language that might be called symbol may be implemented
using the symbols in this proposal ... or maybe I don't see what you
mean here ?

 
[...]
First, I think it would be best to have a syntax to represent
symbols.
 
 
 I disagree. Namespaces would be fine, and would also make clear which
 values were related to each other; e.g. for your state of an object
 use case, it's useful to have all the states in one namespace,
 separate from unrelated states of other classes of objects.
 
 
Adding some special char before the name is probably a good way to
achieve that : $open, $close, ... are $ymbols.
 
 
 Counterproposal:
 
 FileState = SomeTypeDefiningStates( 'open', 'closed' )
 
 thefile.state = FileState.open
 if thefile.state == FileState.closed:
 print File is closed
 
 So all that's needed here is the type SomeTypeDefiningStates, not a
 new syntax.

The problem, IMHO, is that way you need to declare symbols
beforehands, that's what I was trying to avoid by requiring a new syntax.

One possible way to implement symbols is simply with integers
resolved as much as possible at compile time.
 
 
 I believe all your requirements and motivations could be met with an
 Enum type in the language. Here's an implementation using a sequence
 of integers for the underlying values:
 
 First Class Enums in Python
 URL:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413486
 
 An enumerated type would also allow values from that type to be
 compared with cmp() if their sequence was considered important. e.g.
 for object state, the normal sequence of states could be represented
 in the enumeration, and individual states compared to see if they are
 later that each other. If sequence was not considered important, of
 course, this feature would not get in the way.
 

Well, I don't think enumarated objects ARE symbols. I can see two
problems :
 1 - in the implementation, trying to compare values from different
groups raises an error instead of simply returning False (easy to fix ...)
 2 - You have to declare these enumerable variables, which is not
pythonic IMO (impossible to fix ... needs complete redesign)

In the end, I really think symbols and enum are of different use, one of
the interest un symbols being to let the compiler does what he wants
(i.e. probably what is the most efficient).

Thanks for your reply,

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


Re: the button of cancel

2005-11-13 Thread Fredrik Lundh
Ben Bush wrote:

 When I click the button of cancel,
 I got the follwoing message. I want to see Goodbye on the console screen.
 What to do?

 KeyboardInterrupt: operation cancelled

 num = input( Enter a number between 1 and 100:  )
 while num  1 or num  100:
print Oops, your input value (, num, ) is out of range.
num = input( Be sure to enter a value between 1 and 100:  )

you need to catch the exception, and print the message you want.

try:
... your code ...
except KeyboardInterrupt:
print Goodbye!

see chapter 8.3 in the tutorial for more info:

http://docs.python.org/tut/node10.html

/F 



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


Re: Proposal for adding symbols within Python

2005-11-13 Thread Pierre Barbier de Reuille
Mike Meyer a écrit :
 Pierre Barbier de Reuille [EMAIL PROTECTED] writes:
 
Please, note that I am entirely open for every points on this proposal
(which I do not dare yet to call PEP).

Abstract


[...]
 
 
Symbols are objects whose representation within the code is more
important than their actual value. Two symbols needs only to be
equally-comparable. Also, symbols need to be hashable to use as keys of
dictionary (symbols are immutable objects).
 
 
 The values returned by object() meet this criteria. You could write
 LISPs gensym as:
 
   gensym = object
 
 As you've indicated, there are a number of ways to get such
 objects. If all you want is symbols, all that really needs to happen
 is that one of those ways be blessed by including an implementation in
 the distribution.

Well, I may rewrite the proposal, but one good thing to have is the
hability to go from symbol to string and the opposite (as written below)
and that is not really allowed by this implementation of symbols.

 
 
In LISP : Symbols are introduced by '. 'open is a symbol.
 
 
 No, they're not. '(a b c) is *not* a symbol, it's a list. Symbols in
 LISP are just names. open is a symbol, but it's normally evaluated.
 The ' is syntax that keeps the next expression from being evaluated,
 so that 'open gets you the symbol rather than it's value. Since
 you're trying to introduce syntax, I think it's important to get
 existing practice in other languages right.

You're right ! I was a bit quick here ... ' is a way to stop
evaluation and you may also write (quote open) for 'open.

 
 
Proposal


First, I think it would be best to have a syntax to represent symbols.
 
 
 That's half the proposal.
 
 
Adding some special char before the name is probably a good way to
achieve that : $open, $close, ... are $ymbols.
 
 
 $ has bad associations for me - and for others that came from an
 earlier P-language. Also, I feel that using a magic character to
 introduce type information doesn't feel very Pythonic.
 
 While you don't make it clear, it seems obvious that you intend that
 if $open occurs twice in the same scope, it should refer to the same
 symbol. So you're using the syntax for a dual purpose. $name checks to
 see if the symbol name exists, and references that if so. If not, it
 creates a new symbol and with that name. Having something that looks
 like a variables that instantiates upon reference instead of raising
 an exception seems like a bad idea.
 

Well, that's why symbols are absolutely not variables. One good model
(IMO) is LISP symbols. Symbols are *values* and equality is not
depending on the way you obtained the symbol :

(eq (quote opened) 'opened)

 
On the range of symbols, I think they should be local to name space
(this point should be discussed as I see advantages and drawbacks for
both local and global symbols).
 
 
 Agreed. Having one type that has different scoping rules than
 everything else is definitely a bad idea.
 
 
There should be a way to go from strings to symbols and the other way
around. For that purpose, I propose:


assert symbol(opened) == $opened
assert str($opened) == opened
 
 
 So the heart of your proposal seems to be twofold: The addition of
 symbol as a type, and the syntax that has the lookup/create behavior
 I described above.
 

Indeed !

 
Implementation
==

One possible way to implement symbols is simply with integers resolved
as much as possible at compile time.
 
 
 What exactly are you proposing be resolved at compile time? How is
 this better than using object, as illustratd above?
 
 Suggested changes:
 
 Provide a solid definition for the proposed builtin type symbol.
 Something like:
 
   symbol objects support two operations: is and equality
   comparison. Two symbol objects compare equal if and only if
   they are the same object, and symbol objects never compare
   equal to any other type of object. The result of other
   operations on a symbol object is undefined, and should raise
   a TypeError exception.
 
   symbol([value]) - creates a symbol object. Two distinct
   calls to symbol will return two different symbol objects
   unless the values passed to them as arguments are equal, in
   which case they return the same symbol object. If symbol is
   called without an argument, it returns a unique symbol.

Good definition to me !

 
 I left the type of the value argument unspecified on purpose. Strings
 are the obvious type, but I think it should be as unrestricted as
 possible. The test on value is equality, not identity, because two
 strings can be equal without being the same string, and we want that
 case to give us the same symbol. I also added gensym-like behavior,
 because it seemed useful. You could do without equality comparison,
 but it seems like a nice thing to have.
 Now propose a new syntax that means symbol, ala {} meaning dict
 and [] meaning list. 

Re: elementtree.ElemenTree barfs on my Safari Cookies file

2005-11-13 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 Safari stores its cookies in XML format.  Looking to try and add support for
 it to cookielib I started by first trying to parse it with Fredrik Lundh's
 elementtree package.  It complained about an invalid token.  Looking at the
 spot it indicated in the file, I found a non-ASCII, but (as far as I can
 tell) perfectly valid utf-8 string.

xml.dom.minidom gives the same error, so it's not a problem with
elementtree in itself.

the problematic tag contains:

'[EMAIL PROTECTED]'

which decodes to

'[EMAIL PROTECTED]'

which contains chr(1), which is an invalid XML character (at least
in XML 1.0).

that apple's tools are able to generate bogus XML is a known problem; for
a discussion and some workarounds, see the Status of XML 1.1 processing
in Python over at the xml-sig mailing list:

http://aspn.activestate.com/ASPN/Mail/Message/xml-sig/2792071

/F 



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


Re: how to think like a computer scientist

2005-11-13 Thread Brian van den Broek
john boy said unto the world upon 2005-11-11 22:25:
 Question for the following program: sec 5.5
  
 def factorial (n):
if n == 0:
   return 1
else:
   recurse = factorial (n-1)
   result = n * recurse
   return result
  
 How come whenever I state the function with n given a value it prints no 
 results in the interpreter for EX:

snip


  
 So instead I have to give a print command to make the result appear in the 
 interpreter 
 for EX:

snip

 Is this correctshould I have to give a print command??


Hey,

I assume you mean when you run it as a script; when I run it as the 
interactive prompt, I get output:

IDLE 1.1.2
  def factorial (n):
if n == 0:
  return 1
 else:
recurse = factorial (n-1)
result = n * recurse
return result

  factorial(3)
6

In general, it would be bad if the interpreter decided to print 
everything you asked it to compute. The function returns the result of 
the factorial(n) call, and it is up to your code to decide what to do 
with it. If the only use is to print it, then

print factorial(3)

might be what you want. But it is also possible you'd want to store 
the result for further computation, and would find the print an 
unwanted 'feature'. So,

important_for_later = factorial(some_num)

Best,

Brian vdB

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


Re: Proposal for adding symbols within Python

2005-11-13 Thread Mike Meyer
Pierre Barbier de Reuille [EMAIL PROTECTED] writes:
In LISP : Symbols are introduced by '. 'open is a symbol.
 No, they're not. '(a b c) is *not* a symbol, it's a list. Symbols in
 LISP are just names. open is a symbol, but it's normally evaluated.
 The ' is syntax that keeps the next expression from being evaluated,
 so that 'open gets you the symbol rather than it's value. Since
 you're trying to introduce syntax, I think it's important to get
 existing practice in other languages right.
 You're right ! I was a bit quick here ... ' is a way to stop
 evaluation and you may also write (quote open) for 'open.

Yup. Also notice that if you eval the symbol, you get any value that
happens to be bound to it. This is irrelevant for your purposes. But
the properties you're looking for are - in LISP, anyway -
implementation details of how it handles names.

 While you don't make it clear, it seems obvious that you intend that
 if $open occurs twice in the same scope, it should refer to the same
 symbol. So you're using the syntax for a dual purpose. $name checks to
 see if the symbol name exists, and references that if so. If not, it
 creates a new symbol and with that name. Having something that looks
 like a variables that instantiates upon reference instead of raising
 an exception seems like a bad idea.

 Well, that's why symbols are absolutely not variables.

If they aren't variables, they probably shouldn't *look* like
variables.

 Provide a solid definition for the proposed builtin type symbol.
 Something like:
 
   symbol objects support two operations: is and equality
   comparison. Two symbol objects compare equal if and only if
   they are the same object, and symbol objects never compare
   equal to any other type of object. The result of other
   operations on a symbol object is undefined, and should raise
   a TypeError exception.
 
   symbol([value]) - creates a symbol object. Two distinct
   calls to symbol will return two different symbol objects
   unless the values passed to them as arguments are equal, in
   which case they return the same symbol object. If symbol is
   called without an argument, it returns a unique symbol.

 Good definition to me !

Note that this definition doesn't capture the name-space semantics you
asked for - symbol(value) is defined to return the same symbol
everywhere it's called, so long as value is equal. This is probably a
good thing. Using the ability to have non-strings for value means you
can get this behavior by passing in something that's unique to the
namespace as part of value. Said something probably depends on the the
flavor of the namespace in question. This allows you to tailor the
namespace choice to your needs.

Also, since I'm allowing non-strings for value, just invoking str on
the symbol isn't really sufficient. Let's add an attribute 'value',
such that symbol(stuff).value is identical to stuff. I you want,
define symbol.__str__ as str(symbol.value) so that str(symbol(foo))
returns foo.

 Well, maybe we should find some other way to express symbols. The only
 thing I wanted was a way easy to write, avoiding the need to declare
 symbols, and allowing the specification of the scope of the symbol. My
 prefered syntax would be something like :
 'opened, `opened or `opened`
 However, none are usable in current Python.

Well, symbol('opened') solves the declaration issue, but it's not as
easy as you'd like.

 Personally, I think that the LISP quote mechanism would be a better
 addition as a new syntax, as it would handle needs that have caused a
 number of different proposals to be raised.  It would require that
 symbol know about the internals of the implementation so that ?name
 and symbol(name) return the same object, and possibly exposing said
 object to the programmer. And this is why the distinction about how
 LISP acts is important.
 Maybe, although I may say I cannot see clearly how LISP quote mechanism
 translates into Python.

It compiles the quoted expression and returns a code object.  I'd love
to recycle backquotes so that `expr` means
compile(expr, 'quoted-expr', 'eval'), but that won't happen anytime soon.

Hmm. You know, $symbol$ doesn't seem nearly as bad as $symbol. It
tickles TeX, not P***. I could live with that.

Like I said, the tricky part of doing this is getting `symbol` to have
the semantics you want. If you compile the same string twice, you get
two different code objects, though they compare equal, and the
variable names in co_names are the same strings. Maybe equality is
sufficient, and you don't need identity.

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


Want to perform unattended installation of SW using python

2005-11-13 Thread 28tommy
Hi,

I'm trying to automate an installation of some SW that is installed on
Windows (you know - 'Start' == 'Next' == 'Next' == 'Finish' kind of
installation). Is ther any way to perform that using python?

Thank you.

tommy

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


Re: tutorial example?????

2005-11-13 Thread Brian van den Broek
john boy said unto the world upon 2005-11-12 19:43:
 OK...I have the following program
  
 i = 1
 while i = 6:
 print 2 * i,'   ',
 i = i + 1
 print
  
 this is supposed to give you a new blank line after the program runs 
 instead it just gives:
 2   4   6   8   10   12
 
  
 instead of:
 2   4   6   8   10   12
  
 
  
 to get the above return I have to type in print twice,this can't be 
 right?..ANY SUGGESTIONS?
  
 i = 1while i = 6:
 print 2 * i,'   ',
 i = i + 1
 print
 print


IDLE 1.1.2
  def as_excepted():
print The trailing comma makes the next print be ,
print on the same line as this one


  as_excepted()
The trailing comma makes the next print be  on the same line as this one
 


Try putting a string behind the print statement that appears not to be 
doing anything, and you will see that it is. The first print is needed 
to clear out of the looped print's comma.

If you don't like the repetition, you could:


  def one_way():
for i in range(3):
print i,
print '\n'   # Explicitly request newline


  one_way()
0 1 2

 

Best,

Brian vdB

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


Re: Proposal for adding symbols within Python

2005-11-13 Thread Pierre Barbier de Reuille
Mike Meyer a écrit :
 Pierre Barbier de Reuille [EMAIL PROTECTED] writes:
 
While you don't make it clear, it seems obvious that you intend that
if $open occurs twice in the same scope, it should refer to the same
symbol. So you're using the syntax for a dual purpose. $name checks to
see if the symbol name exists, and references that if so. If not, it
creates a new symbol and with that name. Having something that looks
like a variables that instantiates upon reference instead of raising
an exception seems like a bad idea.

Well, that's why symbols are absolutely not variables.
 
 
 If they aren't variables, they probably shouldn't *look* like
 variables.

Yes, that's why we should find some way to express that.

Provide a solid definition for the proposed builtin type symbol.
Something like:

  symbol objects support two operations: is and equality
  comparison. Two symbol objects compare equal if and only if
  they are the same object, and symbol objects never compare
  equal to any other type of object. The result of other
  operations on a symbol object is undefined, and should raise
  a TypeError exception.

  symbol([value]) - creates a symbol object. Two distinct
  calls to symbol will return two different symbol objects
  unless the values passed to them as arguments are equal, in
  which case they return the same symbol object. If symbol is
  called without an argument, it returns a unique symbol.

Good definition to me !
 
 
 Note that this definition doesn't capture the name-space semantics you
 asked for - symbol(value) is defined to return the same symbol
 everywhere it's called, so long as value is equal. This is probably a
 good thing. Using the ability to have non-strings for value means you
 can get this behavior by passing in something that's unique to the
 namespace as part of value. Said something probably depends on the the
 flavor of the namespace in question. This allows you to tailor the
 namespace choice to your needs.

Very interesting ... that way we could get global AND local symbols ...
I like it !

 
 Also, since I'm allowing non-strings for value, just invoking str on
 the symbol isn't really sufficient. Let's add an attribute 'value',
 such that symbol(stuff).value is identical to stuff. I you want,
 define symbol.__str__ as str(symbol.value) so that str(symbol(foo))
 returns foo.
 
 
Well, maybe we should find some other way to express symbols. The only
thing I wanted was a way easy to write, avoiding the need to declare
symbols, and allowing the specification of the scope of the symbol. My
prefered syntax would be something like :
'opened, `opened or `opened`
However, none are usable in current Python.
 
 
 Well, symbol('opened') solves the declaration issue, but it's not as
 easy as you'd like.
 
 
Personally, I think that the LISP quote mechanism would be a better
addition as a new syntax, as it would handle needs that have caused a
number of different proposals to be raised.  It would require that
symbol know about the internals of the implementation so that ?name
and symbol(name) return the same object, and possibly exposing said
object to the programmer. And this is why the distinction about how
LISP acts is important.

Maybe, although I may say I cannot see clearly how LISP quote mechanism
translates into Python.
 
 
 It compiles the quoted expression and returns a code object.  I'd love
 to recycle backquotes so that `expr` means
 compile(expr, 'quoted-expr', 'eval'), but that won't happen anytime soon.
 
 Hmm. You know, $symbol$ doesn't seem nearly as bad as $symbol. It
 tickles TeX, not P***. I could live with that.

Yep, I like this $symbol$ notation ! It could me equivalent to :

symbol( symbol )

And $object.symbol$ could translate into :

symbol( (object, symbol) )

 
 Like I said, the tricky part of doing this is getting `symbol` to have
 the semantics you want. If you compile the same string twice, you get
 two different code objects, though they compare equal, and the
 variable names in co_names are the same strings. Maybe equality is
 sufficient, and you don't need identity.
 
  mike

Yep, that's something I always found strange but I think this is for
optimization reasons. However, with symbols the problem is quite
different and we can take some time to ensure there are never two same
objects with different ids ... then, we can also garanty only the use of
== and not of is ...

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


Re: Proposal for adding symbols within Python

2005-11-13 Thread Steven D'Aprano
On Sun, 13 Nov 2005 10:11:04 +0100, Pierre Barbier de Reuille wrote:

 The problem, IMHO, is that way you need to declare symbols
 beforehands, that's what I was trying to avoid by requiring a new syntax.

???

If you don't declare your symbols, how will you get the ones that you want?

I don't understand why it is a problem to declare them first, and if it is
a problem, what your solution would be.

[snip]

 Well, I don't think enumarated objects ARE symbols. I can see two
 problems :
  1 - in the implementation, trying to compare values from different
 groups raises an error instead of simply returning False (easy to fix ...)

As you say, that's easy to fix.

  2 - You have to declare these enumerable variables, which is not
 pythonic IMO (impossible to fix ... needs complete redesign)

Are you suggesting that the Python language designers should somehow
predict every possible symbol that anyone in the world might ever need,
and build them into the language as predefined things?

If that is not what you mean, can you explain please, because I'm confused.



-- 
Steven.

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


Re: Want to perform unattended installation of SW using python

2005-11-13 Thread aum
On Sun, 13 Nov 2005 02:57:04 -0800, 28tommy wrote:

 Hi,
 
 I'm trying to automate an installation of some SW that is installed on
 Windows (you know - 'Start' == 'Next' == 'Next' == 'Finish' kind of
 installation). Is ther any way to perform that using python?

Quick answer is yes, very much so. What /can't/ you do in python? :)

I presume that by 'start - next - next' you're referring to
'installation wizards'. You can write those in python, using any of the
available GUI programming libraries, such as Tkinter, wxPython, PyFLTK,
FoxPY, PyQt or whatever appeals. PyFLTK and wxPython have Wizard widgets
built in, and quite likely PyQt does as well.

-- 
Cheers
aum


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


Re: JAPH

2005-11-13 Thread Michael
Szabolcs Nagy wrote:

 charset, modulo, japh =  .JPacehknorstuy, 17, 
 s =
 69859911049503515105680510599913390885187193231927247909305172858127641629
 for n in xrange(2,):
 if s%n==0:
 japh += charset[(n - 1) % modulo]
 s /= n
 if s==1:
 break
 print japh

More pythonic:

print Just another Python hacker.

:-)


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


Re: Want to perform unattended installation of SW using python

2005-11-13 Thread 28tommy
Hi,

first of all- thanks for the quick answer.
You presumed correctly, but unfortunately, I Don't have control of the
preparation process of the package, so I get it as is. I just need to
answer it's questions on each screen of the wizard...

10x again
tommy

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


Re: Want to perform unattended installation of SW using python

2005-11-13 Thread Martin v. Löwis
28tommy wrote:
 I'm trying to automate an installation of some SW that is installed on
 Windows (you know - 'Start' == 'Next' == 'Next' == 'Finish' kind of
 installation). Is ther any way to perform that using python?

While that is possible in Python, it is very tedious to do: you 
essentially have to generate mouse clicks for the application, using
the Win32 API.

Most packaging tools provide some support for unattended installation,
so I would rather research what options to pass to the installer to
make it non-interactive.

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


Re: Proposal for adding symbols within Python

2005-11-13 Thread Pierre Barbier de Reuille
Steven D'Aprano a écrit :
 On Sun, 13 Nov 2005 10:11:04 +0100, Pierre Barbier de Reuille wrote:
 
 
The problem, IMHO, is that way you need to declare symbols
beforehands, that's what I was trying to avoid by requiring a new syntax.
 
 
 ???
 
 If you don't declare your symbols, how will you get the ones that you want?
 
 I don't understand why it is a problem to declare them first, and if it is
 a problem, what your solution would be.
 

Well, just as Python do not need variable declaration, you can just
*use* them ... in dynamic languages using symbols, they just get created
when used (i.e. have a look at LISP or Ruby).

 [snip]
 
 
Well, I don't think enumarated objects ARE symbols. I can see two
problems :
 1 - in the implementation, trying to compare values from different
groups raises an error instead of simply returning False (easy to fix ...)
 
 
 As you say, that's easy to fix.
 
 
 2 - You have to declare these enumerable variables, which is not
pythonic IMO (impossible to fix ... needs complete redesign)
 
 
 Are you suggesting that the Python language designers should somehow
 predict every possible symbol that anyone in the world might ever need,
 and build them into the language as predefined things?
 
 If that is not what you mean, can you explain please, because I'm confused.
 

Well, the best I can propose is for you to read the discussion with Mike
Meyer.
He pointer out the flaws in my proposal and we're trying to precise things.

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


Re: Want to perform unattended installation of SW using python

2005-11-13 Thread Claudio Grondi
Use AutoIt3 for it and be happy:
  http://www.autoitscript.com/autoit3/.
And if you need Python to be involved in this process, just write out the
AutoIt script from Python and then run the AutoIt script from Python, what
makes you twice that happy.
If you want, you can reinvent the wheel using Python ctypes and the
Win32 API, but what for, if AutoIt is already there and has done it
all in an excellent way?

Claudio

28tommy [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
 Hi,

 first of all- thanks for the quick answer.
 You presumed correctly, but unfortunately, I Don't have control of the
 preparation process of the package, so I get it as is. I just need to
 answer it's questions on each screen of the wizard...

 10x again
 tommy



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


about python ide

2005-11-13 Thread 赵光
i am use python2.4.2 on my gentoo linux system
i want to find some ide of python
but i am using gtk2.8,wxPython has some bug on it.i cant emerge it correctly.
i want some ide use pygtk or other lib of python gui except wxpython(wxWidgets)

thx
--
/**
* Love in Gentoo-Linux  C and Python
* Look at my blog
* http://poorc.wordpress.com
**/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a built-in method for transforming (1,None,Hello!) to 1,None,Hello!?

2005-11-13 Thread Amaury
Hello,

Daniel Crespo wrote:
 Is there a built-in method for transforming (1,None,Hello!) to
 1,None,Hello!?

As others answered before, the two syntaxes build the same object, so 
there is no need to convert.

Except if you already have the tuple stored in a variable, and want to 
call a function with the tree arguments:
   args = (1,None,Hello!)

   func(args)  # equivalent to   func((1,None,Hello!))
   func(*args) # equivalent to   func(1,None,Hello!)

Note the '*' on the second call, it will flatten the args, and 3 
arguments are passed to the function.

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


Python and Lotus Notes

2005-11-13 Thread bisj
I would like to interact with Lotus Notes. I wrote following:
 from win32com.client.dynamic import Dispatch
 ln=Dispatch('Lotus.Notessession')

then, following exception come out:
Traceback (most recent call last):
  File interactive input, line 1, in ?
  File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line
98, in Dispatch
IDispatch, userName =
_GetGoodDispatchAndUserName(IDispatch,userName,clsctx)
  File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line
91, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line
79, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
pythoncom.IID_IDispatch)
com_error: (-2147221005, 'Invalid class string', None, None)

I searched google, above code lines should be ok, but really don't know
how the exception come out. Could this be resolved? Thanks.

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


Re: Multikey Dict?

2005-11-13 Thread Scott David Daniels
David Rasmussen wrote:
 If I have a collection of dicts like:
 
 john = {'id': 1, 'name': John Cleese, 'year': 1939}
 graham = {'id': 2, 'name': Graham Chapman, 'year': 1941}
If these are all like that, I prefer:
 john = dict(id=1, name=John Cleese, year=1939}
 graham = dict{id-2, name=Graham Chapman, year=1941}

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


Re: How to avoid f.close (no parens) bug?

2005-11-13 Thread Peter
o wrote:
 plez send me
  
 

First off, please explain what you are talking about better next time.

Second, What on earth are you talking about?

f is a file object, correct?

Are you trying to close a file by typing f.close or is the file closing 
when you type f.close?

If you are trying to close a file with f.close without parenthasies, 
then i _realy_ hope that this did not work, as f.close is nothing but a 
class method and should be treated like one except when called.

You may want to check out the Python tutorial at python.org 
http://docs.python.org/tut/tut.html

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


Re: about python ide

2005-11-13 Thread Diez B. Roggisch
赵光 wrote:
 i am use python2.4.2 on my gentoo linux system
 i want to find some ide of python
 but i am using gtk2.8,wxPython has some bug on it.i cant emerge it correctly.
 i want some ide use pygtk or other lib of python gui except 
 wxpython(wxWidgets)

Take astab at eric3. Uses Qt + PyQt


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

Re: help make it faster please

2005-11-13 Thread Sybren Stuvel
Bengt Richter enlightened us with:
 I meant somestring.split() just like that -- without a splitter
 argument.  My suspicion remains ;-)

Mine too ;-)

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


Re: Proposal for adding symbols within Python

2005-11-13 Thread Ben Finney
Steven D'Aprano [EMAIL PROTECTED] wrote:
 On Sun, 13 Nov 2005 10:11:04 +0100, Pierre Barbier de Reuille wrote:
  The problem, IMHO, is that way you need to declare symbols
  beforehands, that's what I was trying to avoid by requiring a new
  syntax.
 
 If you don't declare your symbols, how will you get the ones that
 you want?
 [...]
 Are you suggesting that the Python language designers should somehow
 predict every possible symbol that anyone in the world might ever
 need, and build them into the language as predefined things?

I believe Pierre is looking for a syntax that will save him from
assigning values to names; that Python will simply assign arbitrary
unique values for these special names. My understanding of the
intended use is that their only purpose is to compare differently to
other objects of the same type, so the actual values don't matter.

What I still don't understand is why this justifies additional syntax
baggage in the language, rather than an explicit assignment earlier in
the code.

-- 
 \  Smoking cures weight problems. Eventually.  -- Steven Wright |
  `\   |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


want some python ide

2005-11-13 Thread [EMAIL PROTECTED]
i want some python ide use pygtk
eric3 is good for me ,but i like gtk,so i want some pygtk ide look like
eric3
wing is a good python ide,but i can not download it
some other python ide(must use pygtk)
thx

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


Re: how to think like a computer scientist

2005-11-13 Thread Colin J. Williams
Brian van den Broek wrote:
 john boy said unto the world upon 2005-11-11 22:25:
 
 Question for the following program: sec 5.5
  
 def factorial (n):
if n == 0:
   return 1
else:
   recurse = factorial (n-1)
   result = n * recurse
   return result
  
 How come whenever I state the function with n given a value it 
 prints no results in the interpreter for EX:
 
 
 snip
 
 
  
 So instead I have to give a print command to make the result appear 
 in the interpreter for EX:
 
 
 snip
 
 Is this correctshould I have to give a print command??
 
 
 
 Hey,
 
 I assume you mean when you run it as a script; when I run it as the 
 interactive prompt, I get output:
 
 IDLE 1.1.2
   def factorial (n):
 if n == 0:
   return 1
 else:
 recurse = factorial (n-1)
 result = n * recurse
 return result
 
   factorial(3)
 6
 
 In general, it would be bad if the interpreter decided to print 
 everything you asked it to compute. The function returns the result of 
 the factorial(n) call, and it is up to your code to decide what to do 
 with it. If the only use is to print it, then
 
 print factorial(3)
 
 might be what you want. But it is also possible you'd want to store the 
 result for further computation, and would find the print an unwanted 
 'feature'. So,
 
 important_for_later = factorial(some_num)
 
 Best,
 
 Brian vdB
 
Looks OK to me, prints 120.
Could be a little simpler:
def factorial (n):
if n == 0:
   return 1
else:
   return n * factorial (n-1)
print factorial(5)

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


Re: How to avoid f.close (no parens) bug?

2005-11-13 Thread Carsten Haese
On Thu, 2 Nov 2006 23:56:22 +0200, o wrote 
 plez send me 
  

Please tell us what bug you're talking about:

A) Python closed the file but you expected it not to.
B) Python didn't close the file but you expected it to.
C) Python didn't warn you when you wrote f.close instead of f.close().
D) Something else. Please elaborate by giving us a code example, a description
of what you expected to happen, and a description of what happened instead.

Best regards,

Carsten Haese.

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


Re: want some python ide

2005-11-13 Thread 赵光
wingide is good for me
but i cant down load it
i download from
http://wingware.com/pub/wingide-personal/2.0.4/wingide-personal-2.0.4-1-i386-linux.tar.gz
but it stop at 7%
who can help me
thx

--
/**
* Love in Gentoo-Linux  C and Python
* Look at my blog
* http://poorc.wordpress.com
**/
-- 
http://mail.python.org/mailman/listinfo/python-list


ANNOUNCE: twill v0.7.4, Web testing language.

2005-11-13 Thread C. Titus Brown
ANNOUNCING twill v0.7.4.

twill is a simple Web scripting language built on top of Python and
John J. Lee's 'mechanize'.  It's designed for automated testing of Web
sites, but it should prove useful for anybody who needs to interact
with Web sites (especially those using logins and cookies) on the
command line or via a script.

twill can also now be used for stress-testing and benchmarking of
complex sites via the twill-fork script.

twill is a reimplementation of Cory Dodt's PBP.

A twill script looks like this:

   # go to the /. login page
   go http://slashdot.org/login.pl

   # fill in the form
   fv 1 unickname test
   fv 1 upasswd test
   submit

   # ok, there's no such account ;). show error HTML.
   show

---

This is the fifth public release of twill, version 0.7.4.

(Tagline: many bugs fixed, nose-based unit tests now work.)

Download directly here:

 http://darcs.idyll.org/~t/projects/twill-0.7.4.tar.gz

Documentation is online at

 http://www.idyll.org/~t/www-tools/twill.html

---

Miscellaneous details:

twill is implemented in Python and uses pyparsing and mechanize.  In
addition to the existing simple command language, twill can easily be
extended with Python.  twill also provides a fairly simple and
well-documented wrapper around mechanize.

twill scripts can be recorded with maxq, although scripts may require
some hand tweaking at the moment.  See the twill documentation for
more information.

twill does not understand JavaScript, I'm sorry to say.

---

Notable bug fixes and features:

   * better error handling  display;

   * many, many browsing bugs fixed;

   * new 'url', 'exit', 'showlinks', 'title', 'config' and 'agent' commands;

   * 'nose' unit tests and unit-test support infrastructure; c.f.

  http://www.idyll.org/~t/www-tools/twill.html#unit-testing

Thanks go to Tommi Virtanen, James Cameron, sureshvv, William Volkman,
and Mike Rovner for patches and bug reports.
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANNOUNCE] gmpy 1.1 beta released

2005-11-13 Thread Alex Martelli
See http://gmpy.sourceforge.net/ for details.
 
What is it: a wrapper for the GMP 4 library (http://swox.com/gmp/), to
provide multi-precision arithmetic for Python.  Multi-precision floats,
and unbounded-precision rationals, are not present in stock Python;
multi-precision integers ('long') are, but gmpy's version of
multi-precision integers is faster for some operations, and provides
lots of nifty pre-packaged additional functions.

Minor changes and bug-fixes since the latest 1.0 alpha: support for the
latest versions of GMP and Python, particularly on the Mac (whose gmp 4
is pickier...).  Windows binary releases are now installer-exe's,
support Python 2.3 and 2.4, and (thanks to enhancements in the
underlying GMP) are faster than the previous Windows binary releases of
gmpy (so is the source release, on any platform, if you build it with
the latest and greatest GMP).

This release has no known bugs (the scan0/scan1 bug that used to be
present in Windows binary releases, as predicted, has disappeared
without needing any changes to gmpy, thanks to bug fixes in GMP; the
divm function's bugs, that were gmpy's responsibility, are now fixed).


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


Re: Proposal for adding symbols within Python

2005-11-13 Thread Steven D'Aprano
On Sun, 13 Nov 2005 12:33:48 +0100, Pierre Barbier de Reuille wrote:

 Steven D'Aprano a écrit :
 On Sun, 13 Nov 2005 10:11:04 +0100, Pierre Barbier de Reuille wrote:
 
 
The problem, IMHO, is that way you need to declare symbols
beforehands, that's what I was trying to avoid by requiring a new syntax.
 
 
 ???
 
 If you don't declare your symbols, how will you get the ones that you want?
 
 I don't understand why it is a problem to declare them first, and if it is
 a problem, what your solution would be.
 
 
 Well, just as Python do not need variable declaration, you can just
 *use* them ... in dynamic languages using symbols, they just get created
 when used (i.e. have a look at LISP or Ruby).

If you want to be technical, Python doesn't have variables. It has names
and objects.

If I want a name x to be bound to an object 1, I have to define it
(actually bind the name to the object):

x = 1

If I want a symbol $x$ (horrible syntax!!!) with a value 1, why shouldn't
I define it using:

$x$ = 1

instead of expecting Python to somehow magically know that I wanted it?
What if somebody else wanted the symbol $x$ to have the value 2 instead?


 [snip]
 
 
Well, I don't think enumarated objects ARE symbols. I can see two
problems :
 1 - in the implementation, trying to compare values from different
groups raises an error instead of simply returning False (easy to fix ...)
 
 
 As you say, that's easy to fix.
 
 
 2 - You have to declare these enumerable variables, which is not
pythonic IMO (impossible to fix ... needs complete redesign)
 
 
 Are you suggesting that the Python language designers should somehow
 predict every possible symbol that anyone in the world might ever need,
 and build them into the language as predefined things?
 
 If that is not what you mean, can you explain please, because I'm confused.
 
 
 Well, the best I can propose is for you to read the discussion with Mike
 Meyer.
 He pointer out the flaws in my proposal and we're trying to precise things.

I've read the discussion, and I am no wiser.

You haven't explained why enums are not suitable to be used for symbols.
You gave two problems, one of which was easy to fix, as you said
yourself, and the other reason was that you don't want to define enums as
symbols. 

If you don't want to define something manually, that can only mean that
you expect them to be predefined. Or am I misunderstanding something?



-- 
Steven.

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


Re: Proposal for adding symbols within Python

2005-11-13 Thread Pierre Barbier de Reuille
Ben Finney a écrit :
 Pierre Barbier de Reuille [EMAIL PROTECTED] wrote:
 
Mike Meyer a écrit :

Hmm. You know, $symbol$ doesn't seem nearly as bad as $symbol. It
tickles TeX, not P***. I could live with that.

Yep, I like this $symbol$ notation !
 
 
 Gets a big -1 here.
 
 I've yet to see a convincing argument against simply assigning values
 to names, then using those names.
 

I can see three interests :
1 - ensure values are unique (i.e. a bit like using instances of object)
2 - values are meaningful (i.e. with introspection on the values you get
a human-readable value, unlike with instances of object)
3 - getting an *easy* access to those two properties

1 and 2 require a new type, 3 a new syntax (IMO).

Here's a try for the symbol class :

class symbol(object):
  def __init__(self, value):
self._value = value
  def _get_value(self):
return self._value
  value = property(_get_value)
  def __eq__(self, other):
return self.value == other.value
  def __str__(self):
return str(self.value)
  def __repr__(self):
return symbol(%s) % (repr(self.value),)

One thing to do would be to return the same object for symbols with the
same value (when possible ...).

For example, if we limit symbol to hashable types, we can implement
something which can be tested with is instead of ==:

class symbol(object):
  _cache = {}
  def __new__(cls, value):
if value in symbol._cache:
  return symbol._cache[value]
self = object.__new__(cls)
self._value = value
symbol._cache[value] = self
return self
  def _get_value(self):
return self._value
  value = property(_get_value)
  def __eq__(self, other):
return self.value == other.value
  def __str__(self):
return str(self.value)
  def __repr__(self):
return symbol(%s) % (repr(self.value),)

Then, as I suggested, you can do something like :

a = symbol((file, opened))

But it's less readable than $file.opened$ (or something similar).

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

Re: Proposal for adding symbols within Python

2005-11-13 Thread Björn Lindström
Ben Finney [EMAIL PROTECTED] writes:

 I've yet to see a convincing argument against simply assigning values
 to names, then using those names.

The problem with that is that you can't pass around the names of objects
that are used for other things. Obviously they make enums unnecessary,
but only people damaged by non-dynamic languages could think that's the
main point. ;-)

Being able to do that precludes the need for converting going back and
forth between strings and method names when you need to do things like
keeping a list of function names, even when you need to be able to
change what those function names point to.

Python doesn't really need to introduce a new type to do this. It's
already there, as what we usually just call names. Probably this
discussion would benefit from talking about names rather than symbols,
as that seems to confuse some people.

So, Python already has symbols. What we need is a way to refer to these
symbols explicitly. I would suggest to do it like in Lisp:

quote(spam)

Of course, this would preferably be implemented so that it doesn't just
work on simple names:

quote(spam(eggs))

I syntactic sugar, like ' in Lisp, could be introduced later, but I
don't think that would be strictly necessary.

-- 
Björn Lindström [EMAIL PROTECTED]
Student of computational linguistics, Uppsala University, Sweden
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Proposal for adding symbols within Python

2005-11-13 Thread Steven D'Aprano
On Mon, 14 Nov 2005 00:48:46 +1100, Ben Finney wrote:

 Steven D'Aprano [EMAIL PROTECTED] wrote:
 On Sun, 13 Nov 2005 10:11:04 +0100, Pierre Barbier de Reuille wrote:
  The problem, IMHO, is that way you need to declare symbols
  beforehands, that's what I was trying to avoid by requiring a new
  syntax.
 
 If you don't declare your symbols, how will you get the ones that
 you want?
 [...]
 Are you suggesting that the Python language designers should somehow
 predict every possible symbol that anyone in the world might ever
 need, and build them into the language as predefined things?
 
 I believe Pierre is looking for a syntax that will save him from
 assigning values to names; that Python will simply assign arbitrary
 unique values for these special names. My understanding of the
 intended use is that their only purpose is to compare differently to
 other objects of the same type, so the actual values don't matter.

Unless I've misunderstood something, it would be easy to modify the recipe
given here to do something like that:

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

The example code does this:

Days = Enum('Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su')
print Days.Mo, Days.Tu
# etc.


 What I still don't understand is why this justifies additional syntax
 baggage in the language, rather than an explicit assignment earlier in
 the code.

The only advantage would be if you want to do something like this:

MO, TU, WE, TH, FR, SA, SU = Symbols()

and have it magically work. I can see the advantage of that, and you don't
even need new syntax, just a magic function that somehow knows how many
names are on the left hand side of the assignment.

This is a poor substitute:

MO, TU, WE, TH, FR, SA, SU = range(7)

Firstly, if you change the number of symbol names, you have to manually
adjust the argument to range. Secondly, your symbols are actually ints,
and so will compare the same way ints compare.


I don't know enough about the Python internals to tell: is there any
feasible way for there to be a magic function like Symbol above that knew
how many names were waiting for it to be supplied? If there is no way to
do this from Python itself, it is possible to patch the compiler to do so?



-- 
Steven.

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


Re: Proposal for adding symbols within Python

2005-11-13 Thread Pierre Barbier de Reuille
Steven D'Aprano a écrit :
 On Sun, 13 Nov 2005 12:33:48 +0100, Pierre Barbier de Reuille wrote:
 
 
Steven D'Aprano a écrit :
[...]
 
 
 If you want to be technical, Python doesn't have variables. It has names
 and objects.
 
 If I want a name x to be bound to an object 1, I have to define it
 (actually bind the name to the object):
 
 x = 1
 
 If I want a symbol $x$ (horrible syntax!!!) with a value 1, why shouldn't
 I define it using:
 
 $x$ = 1
 
 instead of expecting Python to somehow magically know that I wanted it?
 What if somebody else wanted the symbol $x$ to have the value 2 instead?
 

Well, as stated, I don't care about the actual value of symbols. They
*are* values. A trivial implementation of symbols are strings :

$x$ = x

However, that won't fit because of the scope, because it would be great
to use is instead of == (even if not necessary), and as said Mike,
you might want something else than a string. That's why `x` would be a
good wawy to write that.

 
 
[snip]
 
 
 I've read the discussion, and I am no wiser.
 
 You haven't explained why enums are not suitable to be used for symbols.
 You gave two problems, one of which was easy to fix, as you said
 yourself, and the other reason was that you don't want to define enums as
 symbols. 
 
 If you don't want to define something manually, that can only mean that
 you expect them to be predefined. Or am I misunderstanding something?
 

Well, I suspect Python will know them, exactly as it know without
defining it that foo is the string with chars f, o, o, that 3 is the
number 3, that [1,2] is the list with 1 and 2, ... However, to get
quicker, symbols could be created at compile-time when possible (like
variables). The fact is, symbols allow compilation optimisations that
you cannot get with regular types, because the language is completely
free about their representations. Then, to the programmer it is a good
way to have a meaningful value without caring about how to represent it
in the computer. That way, while debugging, if I ask the value of
file.state I will get something I can read instead of some meaningless
integer or other anonymous object.

So I gain in readability of my code and in debugging capacity.

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


Re: Proposal for adding symbols within Python

2005-11-13 Thread Pierre Barbier de Reuille
Björn Lindström a écrit :
 Ben Finney [EMAIL PROTECTED] writes:
 
 
I've yet to see a convincing argument against simply assigning values
to names, then using those names.
 
 
 The problem with that is that you can't pass around the names of objects
 that are used for other things. Obviously they make enums unnecessary,
 but only people damaged by non-dynamic languages could think that's the
 main point. ;-)
 
 Being able to do that precludes the need for converting going back and
 forth between strings and method names when you need to do things like
 keeping a list of function names, even when you need to be able to
 change what those function names point to.
 
 Python doesn't really need to introduce a new type to do this. It's
 already there, as what we usually just call names. Probably this
 discussion would benefit from talking about names rather than symbols,
 as that seems to confuse some people.
 
 So, Python already has symbols. What we need is a way to refer to these
 symbols explicitly. I would suggest to do it like in Lisp:
 
 quote(spam)
 
 Of course, this would preferably be implemented so that it doesn't just
 work on simple names:
 
 quote(spam(eggs))
 
 I syntactic sugar, like ' in Lisp, could be introduced later, but I
 don't think that would be strictly necessary.
 

Well, if this already exists in Python's internals, then, it would be
great just to expose them. Now, just being able to write :

 quote(spam)
quote(spam)

requires a new syntax so that spam is not resolved *before* calling the
quote method.

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

Re: elementtree.ElemenTree barfs on my Safari Cookies file

2005-11-13 Thread skip

Fredrik that apple's tools are able to generate bogus XML is a known
Fredrik problem; for a discussion and some workarounds, see the Status
Fredrik of XML 1.1 processing in Python over at the xml-sig mailing
Fredrik list:

Fredrik http://aspn.activestate.com/ASPN/Mail/Message/xml-sig/2792071

Thanks much.  Your SgmlopXMLTreeBuilder module came to the rescue.

Skip

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


Re: want some python ide

2005-11-13 Thread D H
[EMAIL PROTECTED] wrote:
 i want some python ide use pygtk
 eric3 is good for me ,but i like gtk,so i want some pygtk ide look like
 eric3
 wing is a good python ide,but i can not download it
 some other python ide(must use pygtk)
 thx
 

You can just use a text editor like jedit with gazpacho or glade
http://gazpacho.sicem.biz/
They are not as easy to use at QT Designer though for building interfaces.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to avoid f.close (no parens) bug?

2005-11-13 Thread D H
Carsten Haese wrote:
 On Thu, 2 Nov 2006 23:56:22 +0200, o wrote 
 
plez send me 
 
 
 
 Please tell us what bug you're talking about:
 
 A) Python closed the file but you expected it not to.
 B) Python didn't close the file but you expected it to.
 C) Python didn't warn you when you wrote f.close instead of f.close().
 D) Something else. Please elaborate by giving us a code example, a description
 of what you expected to happen, and a description of what happened instead.

It is certainly B  C.  It is a common issue.  There is no way to avoid 
it unless you learn how to avoid it.  Other than that, PyChecker may 
help find this kind of error.  Over a year ago Guido said he wanted to 
include pychecker with python but it still hasn't happened, so you can 
download it from here: http://pychecker.sourceforge.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: about python ide

2005-11-13 Thread D H
?? wrote:
 i am use python2.4.2 on my gentoo linux system
 i want to find some ide of python
 but i am using gtk2.8,wxPython has some bug on it.i cant emerge it correctly.
 i want some ide use pygtk or other lib of python gui except 
 wxpython(wxWidgets)

Try Gazpacho or Glade for designing your user interfaces:
http://gazpacho.sicem.biz/
and here is an IDE called Pida: http://pida.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterator addition

2005-11-13 Thread Reinhold Birkenfeld
[EMAIL PROTECTED] wrote:
 Tom Anderson:
 And we're halfway to looking like perl already! Perhaps a more pythonic
 thing would be to define a then operator:
 all_lines = file1 then file2 then file3
 
 Or a chain one:
 all_lines = file1 chain file2 chain file3

That's certainly not better than the chain() function. Introducing new operators
for just one application is not pythonic.

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


splitting Tkinter gui into several files

2005-11-13 Thread jarhead
My Tkinter app's gui file grew to the point that i wanted to split it
into several files: menus.py, mainFrame,py, buttons.py, etc. Of
course, when i moved the menu code into its own file, then did import
menus in the main gui file, it died because of references in the
menus file to stuff in the main gui file. What's the right way, or the
cleanest way, to split up my main gui file into its several conceptual
component files?

tia,
Eric

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


SnakeCard goes open source

2005-11-13 Thread Philippe C. Martin
Dear all,

I have decided to focus my activities on development and support.

I will release SnakeCard's produt line source code under the GPL licence
this week (www.snakecard.com) ... I need to fix the site.

It includes:
SCF: SnakeCard Framework (software=Python)
SCFB: SnaleCard Framework Bundle (software=Python, applets BasicCard T=1,
JavaCard T=0)
SCALS: (software: Python (core), VB6 (GUI), C++ (GINA DLL), applets
BasicCard T=1, JavaCard T=0)
SC PCSC Server(software=Python)

Best regards,


Philippe


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


Re: SnakeCard goes open source

2005-11-13 Thread Philippe C. Martin
I forgot

SC-School-ID and SC-Corporate-ID: software = Python, GUI = wxWidget, Applets
JavaCard and BasicCard.

Regards,

Philippe


Philippe C. Martin wrote:

 Dear all,
 
 I have decided to focus my activities on development and support.
 
 I will release SnakeCard's produt line source code under the GPL licence
 this week (www.snakecard.com) ... I need to fix the site.
 
 It includes:
 SCF: SnakeCard Framework (software=Python)
 SCFB: SnaleCard Framework Bundle (software=Python, applets BasicCard T=1,
 JavaCard T=0)
 SCALS: (software: Python (core), VB6 (GUI), C++ (GINA DLL), applets
 BasicCard T=1, JavaCard T=0)
 SC PCSC Server(software=Python)
 
 Best regards,
 
 
 Philippe

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


[no subject]

2005-11-13 Thread David T

 Thomas Edison (I think it was him) once said it took 999 failures to
 make 1 success.  That makes SourceForge 10 times more successful.


 The world is filled with
 millions of wanna-be poets, writers and creators whose sum total
 contribution to the artistic wealth of the world is negative.



 I'm not just using hyperbole. By poisoning the well with their  
 garbage,
 they just make it that little bit harder for genuinely talented  
 artists to
 be heard.


 Whose opinion?  Yours, or the market's?



Just my $0.02:

Individuals, and perhaps groups of individuals are the creators of  
works.

Walt Disney was a creator. Disney Inc. is not the creator, but has  
managed to twist copyright laws to maintain control of Walt's mouse.
Tom Edison moved to California so _he_ could skirt copyright laws of  
the works _he_ was stealing. (See episode 7 of From the Earth to the  
Moon miniseries, re Georges Méliès' 1902 silent film «Le Voyage dans  
la lune»)
Edwin Howard Armstrong invented FM radio (and even got the patent),  
but RCA won the war. The giant corporation was able to twist  
regulations to drive Edwin to a despairing death.

Today, Anne A. Mator might create a new character for Disney Inc.,  
but the copyright belongs to Disney Inc., not Anne.
Professor Suchn Such of Abig University might write a book, but The  
Regents of Abig University get the copyright.
Annin Ventor might build a better widget for Transnational Megacorp,  
but Annin will probably never see a dime of profit or recognition.


Why? IMHO, most inventors, writers and artists have too much to do  
and too little spare money to pay lobbyists to have laws written for  
them. Giant corporations do have the money to get laws written for  
them. Still, I've never seen a creative corporation or a creative  
law. The best corporations and governments can do is foster an  
environment where creativity flourishes and is justly rewarded.

Thus, I must express my gratitude to all of those programmers who  
write open-source code (even if it doesn't go anywhere), and even  
shareware, and other works which are made available and open at no or  
reasonable cost. The Python community most of all.

A free and open marketplace of ideas and products is quite capable of  
separating the triticale from the chaff.

It makes all of us more productive!

--David

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


Re:Copyright [was Re: Python Obfuscation]

2005-11-13 Thread David T

 Thomas Edison (I think it was him) once said it took 999 failures to
 make 1 success.  That makes SourceForge 10 times more successful.



 The world is filled with
 millions of wanna-be poets, writers and creators whose sum total
 contribution to the artistic wealth of the world is negative.





 I'm not just using hyperbole. By poisoning the well with their  
 garbage,
 they just make it that little bit harder for genuinely talented  
 artists to
 be heard.



 Whose opinion?  Yours, or the market's?




Just my $0.02:

Individuals, and perhaps groups of individuals are the creators of  
works.

Walt Disney was a creator. Disney Inc. is not the creator, but has  
managed to twist copyright laws to maintain control of Walt's mouse.
Tom Edison moved to California so _he_ could skirt copyright laws of  
the works _he_ was stealing. (See episode 7 of From the Earth to the  
Moon miniseries, re Georges Méliès' 1902 silent film «Le Voyage dans  
la lune»)
Edwin Howard Armstrong invented FM radio (and even got the patent),  
but RCA won the war. The giant corporation was able to twist  
regulations to drive Edwin to a despairing death.

Today, Anne A. Mator might create a new character for Disney Inc.,  
but the copyright belongs to Disney Inc., not Anne.
Professor Suchn Such of Abig University might write a book, but The  
Regents of Abig University get the copyright.
Annin Ventor might build a better widget for Transnational Megacorp,  
but Annin will probably never see a dime of profit or recognition.


Why? IMHO, most inventors, writers and artists have too much to do  
and too little spare money to pay lobbyists to have laws written for  
them. Giant corporations do have the money to get laws written for  
them. Still, I've never seen a creative corporation or a creative  
law. The best corporations and governments can do is foster an  
environment where creativity flourishes and is justly rewarded.

Thus, I must express my gratitude to all of those programmers who  
write open-source code (even if it doesn't go anywhere), and even  
shareware, and other works which are made available and open at no or  
reasonable cost. The Python community most of all.

A free and open marketplace of ideas and products is quite capable of  
separating the triticale from the chaff.

It makes all of us more productive!

--David


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


Re: IE Temporary Internet Files Python

2005-11-13 Thread John J. Lee
James Hu [EMAIL PROTECTED] writes:

 Maybe the reason is ..\Content.IE5\index.dat can't be deleted! 
[...]

IIRC, it can/could be from linux (with Win NT 4 installed on a VFAT
partition), so I guess it is/was a normal file to that extent.


John

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


Re: Iterator addition

2005-11-13 Thread Tom Anderson
On Sun, 13 Nov 2005, Reinhold Birkenfeld wrote:

 [EMAIL PROTECTED] wrote:

 Tom Anderson:

 And we're halfway to looking like perl already! Perhaps a more 
 pythonic thing would be to define a then operator:

 all_lines = file1 then file2 then file3

 Or a chain one:

 all_lines = file1 chain file2 chain file3

This may just be NIH syndrome, but i like that much less - 'then' makes 
for something that reads much more naturally to me. 'and' would be even 
better, but it's taken; 'andthen' is a bit unwieldy.

Besides, chain file2 is going to confuse people coming from a BASIC 
background :).

 That's certainly not better than the chain() function. Introducing new 
 operators for just one application is not pythonic.

True, but would this be for just one application With python moving 
towards embracing a lazy functional style, with generators and genexps, 
maybe chaining iterators is a generally useful operation that should be 
supported at the language level. I'm not seriously suggesting doing this, 
but i don't think it's completely out of the question.

tom

-- 
limited to concepts that are meta, generic, abstract and philosophical --
IEEE SUO WG
-- 
http://mail.python.org/mailman/listinfo/python-list


D foreach

2005-11-13 Thread bearophileHUGS
The Digital Mars D compiler is a kind of improved c++, it contains a
foreach statement:
http://www.digitalmars.com/d/statement.html#foreach

Usage example:
foreach(int i, inout int p; v1) p = i;

Is equal to Python:
for i in xrange(len(v)): v[i] = i

That is: v1 = range(len(v1))
(Some people use something like this in Python to scan a list of lists,
so p become a reference to a list, that can be modified in place, but
it's not much explicit way of doing things.)


Another example:
foreach(int i, int p; v2) v1[i] = p;

Is equal to Python:
for i,p in enumerate(v2): v1[i] = p

So the variable p contains (scans) the elements of the given iterable
object, but if you assign p with a value, that value becomes copied
inside the mutable iterable too. Those are little examples, but I think
it can be quite useful in more complex code.

Bye,
bearophile

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


py2exe, pyparallel

2005-11-13 Thread garyr
I'm using py2exe to create a standalone program that uses pyparallel.
When I run the created program an error occurs and a message directs me
to
the log file which contains:

Traceback (most recent call last):
  File fg.py, line 30, in ?
import dds2
  File dds2.pyc, line 24, in ?
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR
  File parallel\__init__.pyc, line 13, in ?
  File parallel\parallelwin32.pyc, line 59, in ?
  File ctypes\__init__.pyc, line 407, in __getattr__
  File ctypes\__init__.pyc, line 319, in __init__
WindowsError: [Errno 1157] One of the library files needed to run this
application cannot be found

My setup.py is:
from distutils.core import setup
import py2exe
setup(windows = [fg.py])

Line 59 in parallelwin32.py is:  _pyparallel = ctypes.windll.simpleio.

I'm using PythonWin 2.3.2 on Win98SE. I have ctypes 0.9.6, py2exe 0.6.3
and pyparallel 0.2 installed.

I posted a similar message to the py2exe mailing list but apparently
that list is inactive. Any suggestions appreciated.

Thanks,
Gary Richardson

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


Re: Confusion about __call__ and attribute lookup

2005-11-13 Thread John J. Lee
Kent Johnson [EMAIL PROTECTED] writes:

 Leif K-Brooks wrote:
  New-style classes look up special methods on the class, not on the instance:
 
 For my future reference, is this documented somewhere in the standard docs?

Maybe somewhere in here :-(

http://www.python.org/doc/newstyle.html


John

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


Re: Pywin32: How to import data into Excel?

2005-11-13 Thread Norbert
Simon Brunning wrote:
 On 08/11/05, Dmytro Lesnyak [EMAIL PROTECTED] wrote:
  I need to import some big data into Excel from my Python script. I have TXT
  file (~7,5 Mb).

 Have you considered converting your text data to CSV format? Excel
 opens CSV files happily enough, and you could always automate
 save-as-workbook and any formatting you need afterwards.

But there are thorny issues with different locales and number formats.
Excel is also just too clever in recognising dates

All the best

Norbert

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


Re: help make it faster please

2005-11-13 Thread Ron Adam


Fredrik Lundh wrote:
 Lonnie Princehouse wrote:
 
 
[a-z0-9_] means match a single character from the set {a through z,
0 through 9, underscore}.
 
 
 \w should be a bit faster; it's equivalent to [a-zA-Z0-9_] (unless you
 specify otherwise using the locale or unicode flags), but is handled more
 efficiently by the RE engine.
 
 (you can use \w in sets too, so you can do e.g. [EMAIL PROTECTED])
 
 /F

The \w does make a small difference, but not as much as I expected. 
Surprisingly a standard Python word iterator works just as well, and is 
easier to understand than the re version.

Which one is faster depends on the average word length and number of 
ignored characters.

Cheers,
Ron




Character count: 10
Word count: 16477
Average word size: 6.06906597075
word_counter: 0.06820057 (best of 3)
count_words: 0.07333837 (best of 3)


#

import string
import re
import time
import random


# Create a really ugly n length string to test with.
n = 10
random.seed(1)
lines = ''.join([ random.choice(string.ascii_letters * 2
   + '[EMAIL PROTECTED]*()#/' + '\n' * 6) for x in 
range(n) ])
print 'Character count:', n
print 'Word count:', len(lines.split())
print 'Average word size:', float(n)/len(lines.split())



letters = string.lowercase + string.digits + '_@'

def word_iter(text, letters=letters):
 ltrs=letters.lower()
 wd = ''
 for c in text + ' ':
 if c in ltrs:
 wd += c
 elif wd != '':
 yield wd
 wd = ''

def word_counter(text):
 txt = text.lower()
 countDict={}
 for wd in word_iter(txt):
 if wd in countDict:
 countDict[wd] += 1
 else:
 countDict[wd] = 1
 return countDict




word_finder = re.compile('[EMAIL PROTECTED]', re.I)

def count_words(string, word_finder = word_finder):
 # avoid global lookups
 countDict = {}
 for match in word_finder.finditer(string.lower()):
 word = match.group(0)
 countDict[word] = countDict.get(word,0) + 1
 return countDict



foos = [word_counter, count_words]
r1 = r2 = None
for foo in foos:
 best_time = 0
 for n in range(3):
 t = time.clock()
 for line in lines.splitlines():
 countDict = foo(line)
 tt = time.clock()-t
 if tt  best_time: best_time = tt

 r1 = r2
 r2 = countDict
 if r1 != None:
 # change to 1 if assert fails to find problem
 if 0:
 for k in r1.keys():
 if r1[k] != r2[k]:
 print k,r1[k],r2[k]
 assert r1 == r2

 print '%s: %.8f (best of %d)' \
   % (foo.__name__, best_time, n+1)

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


Python Book

2005-11-13 Thread David Rasmussen
What is the best book for Python newbies (seasoned programmer in other 
languages)?

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


Re: Rename files with numbers

2005-11-13 Thread Florian Diesch
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Ok, so the function simplifyed without loops:

 def renamer(folder, band):
   archive = #file to transform
   rest = archive[3:]
   print band +  -,rest.capitalize()


 obs: the file names came this way(with spaces or apostrophes) from the
 cd i imported.

Maybe you want to take a look at Jack
http://www.home.unix-ag.org/arne/jack/, a IMHO very nice CD ripper
written in Python.


   Florian
-- 
Einen Troll zu füttern ist das gleiche als würde man einen Haufen
Hundescheisse sehen, absichtlich reinsteigen und sich dann beschweren.
(Christian Schneider in [EMAIL PROTECTED])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help make it faster please

2005-11-13 Thread Fredrik Lundh
Ron Adam wrote:

 The \w does make a small difference, but not as much as I expected.

that's probably because your benchmark has a lot of dubious overhead:

 word_finder = re.compile('[EMAIL PROTECTED]', re.I)

no need to force case-insensitive search here; \w looks for both lower-
and uppercase characters.

  for match in word_finder.finditer(string.lower()):

since you're using a case-insensitive RE, that lower() call is not necessary.

  word = match.group(0)

and findall() is of course faster than finditer() + m.group().

  t = time.clock()
  for line in lines.splitlines():
  countDict = foo(line)
  tt = time.clock()-t

and if you want performance, why are you creating a new dictionary for
each line in the sample?

here's a more optimized RE word finder:

word_finder_2 = re.compile('[EMAIL PROTECTED]').findall

def count_words_2(string, word_finder=word_finder_2):
 # avoid global lookups
 countDict = {}
 for word in word_finder(string):
 countDict[word] = countDict.get(word,0) + 1
 return countDict

with your original test on a slow machine, I get

count_words: 0.29868684 (best of 3)
count_words_2: 0.17244873 (best of 3)

if I call the function once, on the entire sample string, I get

count_words: 0.23096036 (best of 3)
count_words_2: 0.11690620 (best of 3)

/F



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


Error

2005-11-13 Thread danger
hi everybody, i have a problem with py2exe that gives me this error:

ImportError: could not import pango
ImportError: could not import pango
Traceback (most recent call last):
  File acqua.py, line 40, in ?
  File gtk\__init__.pyc, line 113, in ?
AttributeError: 'module' object has no attribute 'Font'

does anybody knows how to solve it?

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


Re: Python Book

2005-11-13 Thread Bruno Desthuilliers
David Rasmussen a écrit :
 What is the best book for Python newbies (seasoned programmer in other 
 languages)?

I don't know if it's the best, but a DiveIntoPython/PythonCookbook 
combo may be a good choice.

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


Re: Copyright [was Re: Python obfuscation]

2005-11-13 Thread The Eternal Squire
As far as I know, only one country ever claimed to have that, so your
we only applies to citizens of that country, and not to everyone who
may be reading the letter - and the status of the person you quoted
but did not attribute is unclear.

It applies to not only the US, which explicitly has We The People in
our
Constitution, but to all other countries who model on republican
systems:  Japan, Germany, France, South Korea, Taiwan, and more.

Further, recent evidence is that this is no longer true in that
country, assuming it ever was.

Wow, how Machiaviellian.

Copyright by itself does not pay
the rent, put food on the table or put people through college. It's
strong enough to be do that *if* the public values what you create
enough and *if* you work hard enough at marketing it and *if* you
produce enough. Those are some mighty big ifs.

Yes, profitable innovation is 1 percent inspiration plus 99 percent
persperation.

Maybe the people you're talking about above are the rich corporations
with the congresscritters in their pockets. But that's hardly the
majority.

It sometimes works that way, unfortunately.  But at least we can vote
the
bastards out when we hear of such things.

You apparently think that taking the opportunity for the creator to be
rewarded for their efforts is ok if you deride other people who do
that very thing.

And in what way is piracy a form of creation?

So what's the difference between the RIAA and a
pirate who publicly points out that what the RIAA is up to?

The difference is that the RIAA does not copy software without the
copyright holder's consent.

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


Re: Confusion about __call__ and attribute lookup

2005-11-13 Thread Serge Orlov
Kent Johnson wrote:
 Leif K-Brooks wrote:
  New-style classes look up special methods on the class, not on the instance:

 For my future reference, is this documented somewhere in the standard docs?


Looks like it's the most detailed explanation on the net:

http://mail.python.org/pipermail/python-dev/2003-May/035732.html

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


Re: Copyright [was Re: Python Obfuscation]

2005-11-13 Thread Erik Max Francis
David T wrote:

 Individuals, and perhaps groups of individuals are the creators of  
 works.

When someone pays you to create a work, then they own the copyright, not 
you.  It's called work for hire.

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
San Jose, CA, USA  37 20 N 121 53 W  AIM erikmaxfrancis
   There is no fate that cannot be surmounted by scorn.
   -- Albert Camus
-- 
http://mail.python.org/mailman/listinfo/python-list


strip not working on strings?

2005-11-13 Thread dan . j . weber
I'm using Python 2.3.5 and when I type the following in the interactive
prompt I see that strip() is not working as advertised:

s = 'p p:p'
s.strip(' :')
'p p:p'

Is this just me or does it not work? I want to get rid of all ' ' and
':' in the string. I've checked the doc and from what I can tell this
is what strip() is supposed to do. Thanks for any help.

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


Re: Copyright [was Re: Python obfuscation]

2005-11-13 Thread Erik Max Francis
Mike Meyer wrote:

 Further, recent evidence is that this is no longer true in that
 country, assuming it ever was.

Oh, please.  Take the political crap elsewhere.

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
San Jose, CA, USA  37 20 N 121 53 W  AIM erikmaxfrancis
   There is no fate that cannot be surmounted by scorn.
   -- Albert Camus
-- 
http://mail.python.org/mailman/listinfo/python-list


open source and pure python

2005-11-13 Thread Ben Bush
Is there any package written in pure python code?
I know lots of packages borrow the functions from other languages such as C or FORTRAN. So it is still black box to me because I do not know these languages.
Ben
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: strip not working on strings?

2005-11-13 Thread marduk
On Sun, 2005-11-13 at 13:16 -0800, [EMAIL PROTECTED] wrote:
 I'm using Python 2.3.5 and when I type the following in the interactive
 prompt I see that strip() is not working as advertised:
 
 s = 'p p:p'
 s.strip(' :')
 'p p:p'
 
 Is this just me or does it not work? I want to get rid of all ' ' and
 ':' in the string. I've checked the doc and from what I can tell this
 is what strip() is supposed to do. Thanks for any help.
 

According to my docs it says Return a copy of the string with the
leading and trailing characters removed.  There are no leading or
trailing spaces or colons in 'p p:p'.

What your probably looking for is the .replace() method.

-m

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


Re: strip not working on strings?

2005-11-13 Thread Pierre Quentel
[EMAIL PROTECTED] a écrit :
 I'm using Python 2.3.5 and when I type the following in the interactive
 prompt I see that strip() is not working as advertised:
 
 
s = 'p p:p'
s.strip(' :')
 
 'p p:p'
 
 Is this just me or does it not work? I want to get rid of all ' ' and
 ':' in the string. I've checked the doc and from what I can tell this
 is what strip() is supposed to do. Thanks for any help.
 

strip(chars) returns a copy of the string with leading and trailing 
characters removed, that is, at the beginning and at the end of the string

You can use this to remove the specified characters :

for char in chars:
 s.replace(char,'')

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


Re: strip not working on strings?

2005-11-13 Thread Eric Jacoboni
In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] wrote:

 I'm using Python 2.3.5 and when I type the following in the interactive
 prompt I see that strip() is not working as advertised:
 
 s = 'p p:p'
 s.strip(' :')
 'p p:p'
 
 Is this just me or does it not work? I want to get rid of all ' ' and
 ':' in the string. I've checked the doc and from what I can tell this
 is what strip() is supposed to do.

In /my/ docs, s.strip return a copy of s where all /leading/ and 
/heading/  spaces are removed. s.strip(x) does the same but removing 
chars of x.

So, what you're asking for by s.strip(' :') is remove heading or 
leading space or ':' chars, /not/ remove heading or leading space or 
':' chars.

If you want to get rid of ' ' and ':' anywhere in s, i think that 
string.maketrans and s.translate will do the job:

 import string
 s = 'p p:p'
 ident = string.maketrans('', '')
 s.translate(ident,' :')
'ppp'

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


Re: Iterator addition

2005-11-13 Thread Bengt Richter
On Sun, 13 Nov 2005 17:31:32 +0100, Reinhold Birkenfeld [EMAIL PROTECTED] 
wrote:

[EMAIL PROTECTED] wrote:
 Tom Anderson:
 And we're halfway to looking like perl already! Perhaps a more pythonic
 thing would be to define a then operator:
 all_lines = file1 then file2 then file3
 
 Or a chain one:
 all_lines = file1 chain file2 chain file3

That's certainly not better than the chain() function. Introducing new 
operators
for just one application is not pythonic.
Agreed. But here's a thought:

What if
expr1 expr2

were as legal as
expr1, expr2

and had well defined meaning? The meaning I have in mind is
that expr1 and expr2 (etc if more) should be evaluated just as
they are for building a tuple. Then, instead of taking the values
on the stack and building the tuple, the whole sequence is evaluated
by looking for three possible methods on the objects. First, a __unaryop__
method is sought. If present, that is sufficient to evaluate
expr1 expr2
as
expr1.__unaryop__(expr2)

Now that effectively becomes the first element replacing the first two
elements of the sequence. If it is the only element, that is the value
of the whole. If there are more elements, we start as if with a new sequence,
so
expr1 expr2 expr2

is equivalent to
(expr1 expr2 expr3)

is equivalent to
((expr1 expr2) expr3)

so we evaluate
(expr1 expr2).__unaryop__(expr3)

if that __unaryop__ exists. If not, we look for a postfix unary op method on 
expr3
and if present, we get

expr3.__pfunaryop__((expr1 expr2))

as the value of the whole. Or to write it out fully,

expr3.__pfunaryop__(expr1.__unaryop__(expr2))

Now if expr1 had no op method, we would look for __pfunaryop__ on expr2
and if found the value would obviously be
expr2.__pfunaryop__(expr1)

If there is no __pfunaryop__ on expr2, we look for a __binaryop__ method,
(BTW meaning unary ops are given precedence). If we have expr2.__binaryop__,
then we need an expr3, or it is an error. If present, we get a value for

expr1 expr2 expr3

that is

expr2.__binaryop__(expr1, expr3)

Now if e.g. a bare-name expression MINUS is bound to an object that has
both a __unaryop__ and a __binaryop__ method, parens can as usual control
the evaluation. E.g.,

 MINUS a MINUS b
evaluates to
 MINUS.__binaryop__(MINUS.__unaryop__(a), b)
whereas
 MINUS (a MINUS b)
evaluates to
 MINUS.__unaryop__(MINUS.__binaryop__(a, b))

Presumably the byte codes for the above would look something like
(faked!! minor revision of tuple-building code ;-)

  dis.dis(compile('MINUS a MINUS b','','eval'))
   0   0 LOAD_NAME0 (MINUS)
   3 LOAD_NAME1 (a)
   6 LOAD_NAME0 (MINUS)
   9 LOAD_NAME2 (b)
  12 EVAL_EXPR_SEQ4
  15 RETURN_VALUE
  dis.dis(compile('MINUS (a MINUS b)','','eval'))
   0   0 LOAD_NAME0 (MINUS)
   3 LOAD_NAME1 (a)
   6 LOAD_NAME0 (MINUS)
   9 LOAD_NAME2 (b)
  12 EVAL_EXPR_SEQ3
  15 EVAL_EXPR_SEQ2
  18 RETURN_VALUE

I think this might have some interesting possibilities ;-)

I'm sure there can be some interesting ambiguities in the
syntax of adjacent blank-separated expressions, but nothing
parens couldn't overcome, IWT. Built-in operators with
symbols such as +, -, *, / etc. would of course not be
treated as as objects in the above sense. I.e.,
even if expr1 had a __unaryop__ method,
expr1 - expr2
could not become
expr1.__unaryop__(-expr2)
unless you forced the issue with
expr1 (-expr2)

Ok, this should be fun ;-)

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


need drvmcdb.sys

2005-11-13 Thread james HU
Anybody has this file in ..\system32\drivers\drvmcdb.sys in your computer? please send it to me. You will save my life!  thanks a lot!James
		 Yahoo! FareChase - Search multiple travel sites in one click.

 

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

Re: strip not working on strings?

2005-11-13 Thread Eric Jacoboni
In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] wrote:

 I'm using Python 2.3.5 and when I type the following in the interactive
 prompt I see that strip() is not working as advertised:
 
 s = 'p p:p'
 s.strip(' :')
 'p p:p'
 
 Is this just me or does it not work? I want to get rid of all ' ' and
 ':' in the string. I've checked the doc and from what I can tell this
 is what strip() is supposed to do.

In /my/ docs, s.strip return a copy of s where all /leading/ and 
/heading/  spaces are removed. s.strip(x) does the same but removing 
chars of x.

So, what you're asking for by s.strip(' :') is remove heading or 
leading space or ':' chars, /not/ remove or leading or 
':' chars.

If you want to get rid of ' ' and ':' anywhere in s, i think that 
string.maketrans and s.translate will do the job:

 import string
 s = 'p p:p'
 ident = string.maketrans('', '')
 s.translate(ident,' :')
'ppp'

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


Re: strip not working on strings?

2005-11-13 Thread Eric Jacoboni
In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] wrote:

 I'm using Python 2.3.5 and when I type the following in the interactive
 prompt I see that strip() is not working as advertised:
 
 s = 'p p:p'
 s.strip(' :')
 'p p:p'
 
 Is this just me or does it not work? I want to get rid of all ' ' and
 ':' in the string. I've checked the doc and from what I can tell this
 is what strip() is supposed to do.

In /my/ docs, s.strip return a copy of s where all /leading/ and 
/heading/  spaces are removed. s.strip(x) does the same but removing 
chars of x.

So, what you're asking for by s.strip(' :') is remove heading or 
leading space or ':' chars, /not/ remove space or 
':' chars.

If you want to get rid of ' ' and ':' anywhere in s, i think that 
string.maketrans and s.translate will do the job:

 import string
 s = 'p p:p'
 ident = string.maketrans('', '')
 s.translate(ident,' :')
'ppp'

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


Re: something wrong in wx

2005-11-13 Thread Robert Tomasik
Dnia Sun, 13 Nov 2005 08:29:49 +, Tim Roberts napisał(a):

I wrote program training na Artificial Neural Network. It work well in
console mode, but when I try to add GUI there is an error:
FANN Error 10: Error reading info from train data file zapis.txt, line: 2
 
 How are you launching the GUI version?  Are you double-clicking on an icon
 somewhere?  

I launch the Gui version with terminal.
# python Training.py

Are you sure the application is starting in the correct
 directory -- the one that contains zapis.txt?

Yes i'm sure. 

 Perhaps you should try hard-code the full path, or at least doing an
 os.chdir().
it still doesn't work.

Thanks. 

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


Re: Python Book

2005-11-13 Thread Stuart McGraw
David Beasley's Essential Python (New Riders).  It's a little dated
now (covers only up to version 2.2) but lucid, consise, well organized.
It restricts itself to Python's syntax and semantics and does not waste
time explaining basic programming concepts.

I made several attempts to learn Python but found the Python docs
pretty poor, and the tutorial books I looked at were incredibly ponderous 
and slow.  It wasn't until I got Beasley's book that I could actual find 
info effectively enough to start actually writing Python code.  I still most
often refer to it in preference to the Python docs.

David Rasmussen [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 What is the best book for Python newbies (seasoned programmer in other 
 languages)?
 
 /David
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Copyright

2005-11-13 Thread Mike Meyer
The Eternal Squire [EMAIL PROTECTED] writes:
Further, recent evidence is that this is no longer true in that
country, assuming it ever was.
 Wow, how Machiaviellian.

Just an observation on the state of the US. It's been a long while
since the people running the country did so for the people.

Copyright by itself does not pay
the rent, put food on the table or put people through college. It's
strong enough to be do that *if* the public values what you create
enough and *if* you work hard enough at marketing it and *if* you
produce enough. Those are some mighty big ifs.
 Yes, profitable innovation is 1 percent inspiration plus 99 percent
 persperation.

The critical thing is that copyright isn't a vital part of the
formula. Lots of people make a good living creating intellectual
property without needing copyright on said property to provide the
income.

The whole claim that copyright benefits the creator is a
misdirection. Look at the number of creators who make a living off of
sale of copyrighted materials vs the number of people between the
creator and the consumer making a living off their work. Tell me who
owns the big, fancy offices - the creators, or the middlemen. Tell me
who's lobbying congress to create laws that protect and extend
copyright. Finally, notice the difference between what you pay for a
mass-market work - dollars - and what the creator gets - pennies, and
tell me who gets the difference. Yes, copyright benefits the creator,
but the primary beneficiaries are the people who arrange to put hard
media in the hands of the public - the publishers.

During the bulk of the twentieth century, this arrangement was
reasonable - the middlemen were putting up the money, and taking all
the financial risks. In some cases, they even took on the risk for the
creator themselves, paying the creator an advance against royalties,
so that if the product failed in the market, the creator got paid, and
they took the hit for it.

Given all that, the *real* question isn't How will the creator get
paid?, it's How will the creator get published? The last few
decades have given us a *lot* of answers to that: put it on their web
site, which can be had for free; put it in a podcat; blog it; put it
in a torrent; and so on. How they make money off of it after that is
still being explored, but people are doing it. Yes, the creator
doesn't sell as many copies this way. On the other hand, they get a
much larger percentage of the price of the product.

Publishers are in danger of becoming irrelevant. That's why they're
making all the noise, and doing everything they can to limit the
publics rights. They're distracting people from the real issue - their
bottom line - by claiming it's for the good of the creator, while
they try and make sure their business model - the one where they get
the bulk of the profits - stays in place. *These* are the people whose
side you are arguing, not the creator.

Maybe the people you're talking about above are the rich corporations
with the congresscritters in their pockets. But that's hardly the
majority.
 It sometimes works that way, unfortunately.  But at least we can vote
 the
 bastards out when we hear of such things.

It's been working that way regulary since the 1920s, and the same
bastards are still running the country.

You apparently think that taking the opportunity for the creator to be
rewarded for their efforts is ok if you deride other people who do
that very thing.
 And in what way is piracy a form of creation?

That's a complete non-sequitor.

So what's the difference between the RIAA and a
pirate who publicly points out that what the RIAA is up to?
 The difference is that the RIAA does not copy software without the
 copyright holder's consent.

Actually, they do. More accurately, the companies that form the RIAA
do. That's the point.

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


Re: Copyright [was Re: Python Obfuscation]

2005-11-13 Thread Bruno Desthuilliers
Erik Max Francis a écrit :
 David T wrote:
 
 Individuals, and perhaps groups of individuals are the creators of  
 works.
 
 
 When someone pays you to create a work, then they own the copyright, 

Depends on the country's laws and the exact agreement.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: open source and pure python

2005-11-13 Thread Robert Kern
Ben Bush wrote:
 Is there any package written in pure python code?

Quite a lot. Browse through the Package Index.

http://cheeseshop.python.org/pypi

-- 
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: Copyright

2005-11-13 Thread Mike Meyer
Erik Max Francis [EMAIL PROTECTED] writes:
 Mike Meyer wrote:
 Further, recent evidence is that this is no longer true in that
 country, assuming it ever was.
 Oh, please.  Take the political crap elsewhere.

It's got as much right to be here as the copyright crap. And I'm
trying to keep it to the minimum required to refute the political crap
I'm answering.

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


Re: something wrong in wx

2005-11-13 Thread [EMAIL PROTECTED]
Don't know if this will help or not because it seems like a strange
error if this is the problem.  I've always had to run my wxPython apps
with pythonw, otherwise it will give you an error saying it needs the
GUI interpreter or something like that.  However, this could be an
operating system specific codition.  If that doesn't fix anything all I
can say is check and recheck your path.

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


Re: Copyright [was Re: Python Obfuscation]

2005-11-13 Thread Steven D'Aprano
On Sun, 13 Nov 2005 13:16:43 -0800, Erik Max Francis wrote:

 David T wrote:
 
 Individuals, and perhaps groups of individuals are the creators of  
 works.
 
 When someone pays you to create a work, then they own the copyright, not 
 you.  It's called work for hire.

That is *not* generally true, although it is true in certain industries,
such as newspapers.

Book publishers, for instance, do not generally own the copyright even if
they ask you to write a book. Until the 1978 Copyright Act, neither did
record labels: the creative musician owned the copyright.

See http://www.cdbaby.net/articles/courtney_love.html for details of how
the major record labels, through their enforcement arm the RIAA, stole
rights from the creative artists that they claim to represent.


-- 
Steven.

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


ANN: PySizer 0.1

2005-11-13 Thread Nick Smallbone
I'd like to announce the first release of PySizer, a memory usage
profiler for Python code.
PySizer was written as part of Google's Summer of Code.

The source, documentation and so on are at http://pysizer.8325.org.
The current release is at
http://pysizer.8325.org/dist/sizer-0.1.tar.gz.
The code is kept in a Subversion repository at
http://codespeak.net/svn/user/nick8325/sizer.

The idea is to take a snapshot of memory use at some time, and then
use the functions of the profiler to find information about it.

Features

* You can make a snapshot of all reachable objects at a given time,
  organised as a tree (well, a graph, since there are cycles).

* For any given object, you can find out how much space it takes up,
  what objects it references and so on.

  With a patched version of Python, you can also find out what stack of
  function calls created an object, and what objects were created by
  each stack of calls.

* You can collect objects into groups. For example, you can group each
  object according to the module it appears to come from. Then you can
  treat each module as a single object.

* You can filter objects, find the amount of space used by instances of
  each type, find objects which appeared from one snapshot to the next,
  find the biggest objects/types/groups, and so on.

Requirements

See http://pysizer.8325.org/INSTALL.
The main one is Python 2.4 - I will port it to 2.3 soon.

Bugs, suggestions, comments, problems, anything else

You can contact me at [EMAIL PROTECTED] I would love to know if
you find a use for it, too.

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


Re: Copyright [was Re: Python Obfuscation]

2005-11-13 Thread Erik Max Francis
Bruno Desthuilliers wrote:

 Depends on the country's laws and the exact agreement.

Work for hire is part of the Berne convention.

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
San Jose, CA, USA  37 20 N 121 53 W  AIM erikmaxfrancis
   Life is painting a picture, not doing a sum.
   -- Oliver Wendell Holmes, Jr.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Copyright [was Re: Python Obfuscation]

2005-11-13 Thread Erik Max Francis
Steven D'Aprano wrote:

 That is *not* generally true, although it is true in certain industries,
 such as newspapers.

It is true in many industries, including the software industry.  My 
point was that the creator of a work and the copyright holder and not 
necessarily one and the same.  Often, in fact, they are not.

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
San Jose, CA, USA  37 20 N 121 53 W  AIM erikmaxfrancis
   Life is painting a picture, not doing a sum.
   -- Oliver Wendell Holmes, Jr.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Copyright

2005-11-13 Thread Robert Kern
Mike Meyer wrote:
 Erik Max Francis [EMAIL PROTECTED] writes:
 
Mike Meyer wrote:

Further, recent evidence is that this is no longer true in that
country, assuming it ever was.

Oh, please.  Take the political crap elsewhere.
 
 It's got as much right to be here as the copyright crap. And I'm
 trying to keep it to the minimum required to refute the political crap
 I'm answering.

Off-topic responses are just as off-topic as the off-topic posts they
are responding to. Take 'em off-list. Use http://conversate.org/ for a
relatively convenient way to do so.

-- 
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 for adding symbols within Python

2005-11-13 Thread Michael
Ben Finney wrote:
...
 I've yet to see a convincing argument against simply assigning values
 to names, then using those names.

I don't like any syntax I've seen so far, but I can understand the problem.
If you have a name, you can redefine a name, therefore the value a name
refers to is mutable. As a result if you have 2 symbols represented by
names and values, you may have two symbols with different names but the
same value. Hence the two symbols are no longer unique)

Conversely consider NAME to be a symbol. I can't modify NAME. It always
means the same as NAME and NAME, but is never the same as FRED.
What's tricky is I can't have namespaceOne.NAME [1] and
namespaceTwo.NAME as different NAMEs even though logically there's no
reason I couldn't treat NAME differently inside each.

   [1] Supposing for a moment that I could have a string as a name in a
   namespace. (Rather than a string used as a key in that namespace)

However it might be useful to note that these two values (or symbols) are
actually different, even if you remove their namespaces.

To me, the use of a symbol implies a desire for a constant, and then to only
use that constant rather than the value. In certain situations it's the
fact that constant A is not the same as constant B that's important (eg
modelling state machines).

Often you can use strings for that sort of thing, but unfortunately even
python's strings can't be used as symbols that are always the same thing
in all ways. For example, we can force the id of identical strings to be
different:
 s = h*1
 x = h*1
 id(s), id(x)
(135049832, 135059864)

As a result I can see that *IF* you really want this kind of symbol, rather
than the various other kinds people have discussed in the thread, that some
special syntax (like u'hello' for unicode 'hello') could be useful.

However, I'd be more interested in some real world usecases where this would
be beneficial, and then seeing what sort of syntax would be nice/useful
(Especially since I can think of some uses where it would be nice).

On the original syntax proposal, I'm firmly in the -1 camp - to me having
done lots of perl in the past $foo looks very firmly like a mutable, rather
than an immutable.

The reason I'm more interested in seeing usecases, is because I'd rather see
where the existing approaches people use/define symbols has caused the OP
problems to the extent he feels the language needs to change to fix these
real world problems.


Michael.

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


Re: Proposal for adding symbols within Python

2005-11-13 Thread Ben Finney
Steven D'Aprano [EMAIL PROTECTED] wrote:
 On Mon, 14 Nov 2005 00:48:46 +1100, Ben Finney wrote:
  I believe Pierre is looking for a syntax that will save him from
  assigning values to names; that Python will simply assign
  arbitrary unique values for these special names.
 
  What I still don't understand is why this justifies additional
  syntax baggage in the language, rather than an explicit assignment
  earlier in the code.
 
 The only advantage would be if you want to do something like this:
 
 MO, TU, WE, TH, FR, SA, SU = Symbols()

I believe that's exactly what Pierre doesn't want to do. He wants to
simply use names (marked special in some way) and have Python
automatically determine a unique value for each name, with nary an
assignment in sight.

To me, that's a net loss. It makes names more complicated, it loses
explicit is better than implicit, and it loses the checks Python
could do against using a name that hasn't been assigned a value
(caused by e.g. a misspelled name).

-- 
 \  Why should I care about posterity? What's posterity ever done |
  `\ for me?  -- Groucho Marx |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Book

2005-11-13 Thread Stuart McGraw
Stuart McGraw [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 David Beasley's Essential Python (New Riders).  It's a little dated
 now (covers only up to version 2.2) [...]

Oops, that should be Beazley, Python Essential Reference, and 
version 2.1.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multikey Dict?

2005-11-13 Thread Bengt Richter
On Sun, 13 Nov 2005 01:03:05 +0100, David Rasmussen [EMAIL PROTECTED] wrote:

If I have a collection of dicts like:

john = {'id': 1, 'name': John Cleese, 'year': 1939}
graham = {'id': 2, 'name': Graham Chapman, 'year': 1941}

Why do you use dicts for what looks like fixed-format records? Why not just 
tuples? E.g.,
 john = (1, John Cleese, 1939)
 graham = (2, Graham Chapman, 1941)


I could store all of them in a list. But for easy lookup, I might store 
all these in a dict instead, like

people = {'1': john, '2': graham}

or maybe

people = {'John Cleese': john, 'Graham Chapman': graham}

or whatever key I might choose. Now, first of all, it seems a bit 
annoying that I have to keep that redundant data in the second dict that 
ISTM you are confusing equivalent references with redundant data. The
people dict does not contain its own copy of john and graham objects,
it just refers to them, and you get to look up the reference by key name.

is already in the individual dicts within people. Secondly (and this is 
my question), it is annoying that I have to choose one of several 
unambiguous keys as a key.
Keys in the same dict have to be unambiguous, or how could you retrieve
an associated value?


I would like to be able to say:

people['1'].year

in some case and in other cases I want to say

people['John Cleese'].year

That is, sometimes I have the name at hand and would like to look up 
data based on that. Other times, I have the ID at hand and would like to 
look up data based on that instead.
No prob. So long as no one has a name like '1' or an id like 'John Cleese'
you can keep both '1':john and 'John Cleese':john  key:value associations
in the same dict. Referring to the same value with different keys is no prob.

Of course, using tuples for john and graham you can't get year as an attribute.
Recalling from above
john = (1, John Cleese, 1939)

you'd have to write
people['1'][2]
or
people['John Cleese'][2]

Or you could define some handy mnemonic constants to match the tuple, e.g.,
ID, NAME, YEAR = range(3)

and then you could write
people['1'][YEAR]
or
people['John Cleese'][YEAR]

Or you could define an object giving you the attribute access you wanted.
Not as efficient spacewise though, unless you define __slots__.

Of course, you can use dicts for john and graham if you need the ability
to add arbitrary fields. If this happens rarely, you could conceivably gain
efficiency in storage by using slots for the normal data and a single slot
initialized to None for extra data, and then create a dict for that slot
only if you need to extend with new field names.


Also, I would like if I didn't have to keep the key data both in the 
dict of dicts and in the dicts :)
IIUC I guess you don't have to.

If I could just say to Python: john and graham (and ...) are all a part 
of a superdict and either their id or their name can be used as keys.

Can I do that somehow?
Sure. What API would you like for your superdict?
Defining requirements is usually the hardest part, because newbies
often imagine limitations that don't exist in Python ;-)

Others will have proposed many variants by now, I assume ;-)

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


Re: Proposal for adding symbols within Python

2005-11-13 Thread Erik Max Francis
Ben Finney wrote:

 I believe that's exactly what Pierre doesn't want to do. He wants to
 simply use names (marked special in some way) and have Python
 automatically determine a unique value for each name, with nary an
 assignment in sight.
 
 To me, that's a net loss. It makes names more complicated, it loses
 explicit is better than implicit, and it loses the checks Python
 could do against using a name that hasn't been assigned a value
 (caused by e.g. a misspelled name).

I agree.  And, when done explicitly, it's already easy enough to do this 
within the language, by just assigning it a value, even if it's an 
integer from range/xrange or a new sentinel like object().

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
San Jose, CA, USA  37 20 N 121 53 W  AIM erikmaxfrancis
   The stairs of the sky are let down for him that he may ascend thereon
   to heaven. O gods, put your arms under the king: raise him, lift him
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help make it faster please

2005-11-13 Thread Ron Adam


Fredrik Lundh wrote:
 Ron Adam wrote:
 
 
The \w does make a small difference, but not as much as I expected.
 
 
 that's probably because your benchmark has a lot of dubious overhead:

I think it does what the OP described, but that may not be what he 
really needs.

Although the test to find best of n, instead was finding worse of n. 
Which explains why I was getting a larger variance than I thought I 
should have been getting.


word_finder = re.compile('[EMAIL PROTECTED]', re.I)
 
 
 no need to force case-insensitive search here; \w looks for both lower-
 and uppercase characters.

But the dictionary keys need to be either upper or lower otherwise you 
count 'The' separately from 'the'.


 for match in word_finder.finditer(string.lower()):
 
 
 since you're using a case-insensitive RE, that lower() call is not necessary.
 
 
 word = match.group(0)
 
 
 and findall() is of course faster than finditer() + m.group().

Cool,  I don't use re that often so I just used what was posted to test 
against.

 
 t = time.clock()
 for line in lines.splitlines():
 countDict = foo(line)
 tt = time.clock()-t
 
 
 and if you want performance, why are you creating a new dictionary for
 each line in the sample?

Because that's what the OP apparently wanted.  A line by line word 
count.  I originally did it to get an the over all count and then change 
it so it matched the re version that was posted.

 here's a more optimized RE word finder:
 
 word_finder_2 = re.compile('[EMAIL PROTECTED]').findall
 
 def count_words_2(string, word_finder=word_finder_2):
  # avoid global lookups
  countDict = {}
  for word in word_finder(string):
  countDict[word] = countDict.get(word,0) + 1
  return countDict
 
 with your original test on a slow machine, I get
 
 count_words: 0.29868684 (best of 3)
 count_words_2: 0.17244873 (best of 3)
 
 if I call the function once, on the entire sample string, I get
 
 count_words: 0.23096036 (best of 3)
 count_words_2: 0.11690620 (best of 3)
 
 /F

Wow, a lot bigger difference than on my machine.  curious  An athlon 
64 3000+ on winxp.  I'm not sure how much difference that would make?

This is what I get after adding the above version to it, with the 
lower(). There's not quite as big a difference as you get, but the find 
all version is still faster than both the others.

Cheers,
Ron


Character count: 10
Word count: 16477
Average word size: 6.06906597075
word_counter: 0.06245989 (best of 3)
count_words: 0.07309812 (best of 3)
count_words_2: 0.04981024 (best of 3)


And as count all words...

Character count: 10
Word count: 16477
Average word size: 6.06906597075
word_counter: 0.05325006 (best of 3)
count_words: 0.05910528 (best of 3)
count_words_2: 0.03748158 (best of 3)


They all improve, but the re find all version is clearly better.



#

import string
import re
import time
import random

# Create a really ugly n length string to test with.
# The word length are
n = 10
random.seed(1)
lines = ''.join([ random.choice(string.ascii_letters * 2
   + '[EMAIL PROTECTED]*()#/' + '\n' * 6) for x in 
range(n) ])
print 'Character count:', n
print 'Word count:', len(lines.split())
print 'Average word size:', float(n)/len(lines.split())


letters = string.lowercase + string.digits + '_@'

def word_iter(text, letters=letters):
 wd = ''
 for c in text + ' ':
 if c in letters:
 wd += c
 elif wd != '':
 yield wd
 wd = ''

def word_counter(text):
 countDict={}
 for wd in word_iter(text.lower()):
 if wd in countDict:
 countDict[wd] += 1
 else:
 countDict[wd] = 1
 return countDict


word_finder = re.compile('[EMAIL PROTECTED]', re.I).finditer

def count_words(string, word_finder=word_finder):
 # avoid global lookups
 countDict = {}
 for match in word_finder(string.lower()):
 word = match.group(0)
 countDict[word] = countDict.get(word,0) + 1
 return countDict


word_finder_2 = re.compile('[EMAIL PROTECTED]').findall

def count_words_2(string, word_finder=word_finder_2):
  # avoid global lookups
  countDict = {}
  for word in word_finder(string.lower()):
  countDict[word] = countDict.get(word,0) + 1
  return countDict


foos = [word_counter, count_words, count_words_2]
r1 = r2 = None
for foo in foos:
 best_time = 100  # too large to be useful on purpose
 for n in range(3):
 t = time.clock()
 #for line in lines.splitlines():
 countDict = foo(lines)
 tt = time.clock()-t
 best_time = min(tt, best_time)

 r1 = r2
 r2 = countDict
 if r1 != None:
 # change to 1 if assert fails to find problem
 if 0:
 for k in r1.keys():
 if r1[k] != r2[k]:
 print k,r1[k],r2[k]
 assert r1 == r2

  

Re: Iterator addition

2005-11-13 Thread jepler
On Sun, Nov 13, 2005 at 09:44:43PM +, Bengt Richter wrote:
 even if expr1 had a __unaryop__ method,
 expr1 - expr2
 could not become
 expr1.__unaryop__(-expr2)
 unless you forced the issue with
 expr1 (-expr2)

as opposed to being a function call?  I don't think you've solved the ambiguity 
problem yet.

Jeff


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

Re: which feature of python do you like most?

2005-11-13 Thread Gregory Bond
[EMAIL PROTECTED] wrote:
 which feature of python do you like most?
 

Duck typing (All I care about is that it quacks, and it doesn't have to 
derive from Duck() to do that!)

And decorating (the ability to add attributes to objects on-the-fly, not 
the @XXX stuff)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Book

2005-11-13 Thread calad . sigilon
Have you tried the tutorial on python.org? It's pretty good, even for
seasoned programmers.

Calad Sigilon

David Rasmussen wrote:
 What is the best book for Python newbies (seasoned programmer in other
 languages)?
 
 /David

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


Re: Proposal for adding symbols within Python

2005-11-13 Thread Ben Finney
Michael [EMAIL PROTECTED] wrote:
 Ben Finney wrote:
  I've yet to see a convincing argument against simply assigning
  values to names, then using those names.
 
 If you have a name, you can redefine a name, therefore the value a
 name refers to is mutable.

Since there are mutable and immutable values, it might be clearer to
say the binding of a name to a value can be changed. Yes?

In that case, I don't see why someone who wants such a binding to be
unchanging can't simply avoid changing it. Where's the case for having
Python enforce this?

 Conversely consider NAME to be a symbol. I can't modify NAME. It
 always means the same as NAME and NAME, but is never the same as
 FRED. What's tricky is I can't have namespaceOne.NAME [1] and
 namespaceTwo.NAME as different NAMEs even though logically
 there's no reason I couldn't treat NAME differently inside each.

So you want to mark such objects as being in a namespace, where they
compare the same within that namespace but not outside. Why is
separate syntax necessary for this? A data type that is informed of
its space, and refuses comparison with values from other spaces,
would suffice.

class Xenophobe(object):
def __init__(self, space, value):
self.__space = space
self.__value = value

def __str__(self):
return str(self.__value)

def __cmp__(self, other):
if not isinstance(other, Xenophobe):
raise AssertionError, \
Can only compare Xenophobes to each other
if not other.__space == self.__space:
raise AssertionError, \
Can only compare Xenophobes from the same space
return cmp(self.__value, other.__value)

With the bonus that you could pass such values around between
different names, and they'd *still* compare, or not, as you choose
when you first create them.

Replace the AssertionError with some appropriate return value, if you
want such comparisons to succeed.

 However it might be useful to note that these two values (or
 symbols) are actually different, even if you remove their
 namespaces.

The above Xenophobe implementation creates objects that know their
space forever.

 To me, the use of a symbol implies a desire for a constant, and then
 to only use that constant rather than the value. In certain
 situations it's the fact that constant A is not the same as constant
 B that's important (eg modelling state machines).

Since the actual value can't be easily accessed, the only purpose of a
Xenophobe is too be created and compared to others.

 Often you can use strings for that sort of thing, but unfortunately
 even python's strings can't be used as symbols that are always the
 same thing in all ways. For example, we can force the id of
 identical strings to be different:

Hold up -- what in your stated use case requires *identity* to be the
same? You said you just wanted to compare them to each other.

Besides, Python *does* preserve identity for short strings...

  s = h*1
  x = h*1
  id(s), id(x)
 (135049832, 135059864)

... which is sufficient for unique values, if you're not actively
fighting the system as above. If the use case is for brief, identical
values, we have those: short strings.

 As a result I can see that *IF* you really want this kind of symbol,
 rather than the various other kinds people have discussed in the
 thread, that some special syntax (like u'hello' for unicode 'hello')
 could be useful.

I can see the case for a new type. I disagree that syntax changes are
necessary.

 However, I'd be more interested in some real world usecases where
 this would be beneficial, and then seeing what sort of syntax would
 be nice/useful (Especially since I can think of some uses where it
 would be nice).

Real use cases would interest me, too, but *only* if they can't be
satisfied with a new type that knows things about its creation state,
such as Xenophobe.

 The reason I'm more interested in seeing usecases, is because I'd
 rather see where the existing approaches people use/define symbols
 has caused the OP problems to the extent he feels the language needs
 to change to fix these real world problems.

Ditto.

-- 
 \   My aunt gave me a walkie-talkie for my birthday. She says if |
  `\ I'm good, she'll give me the other one next year.  -- Steven |
_o__)   Wright |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >