HOW do you stop a print???

2005-11-13 Thread john boy


ok...I am running the following program:
 
def printMultiples (n):
 i = 1
 while i <= 6:
 print n*i,   ' \t ',
 i = i + 1
i = 1
while i <= 6:
 printMultiples(i)
 i = i + 1
 
this is supposed to return a simple multiplication table, but for some reason it does not want to stop printing after 6 columns...instead it prints from left to right for a total of 10 columns...I need some sort of a "stop print" after the first 6 columns and then continue to fill in those columns...Can anybody solve this problem?...
-thanks-
		 Yahoo! FareChase - Search multiple travel sites in one click.

 

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

Re: Abstract Base Classes

2005-11-13 Thread Steven D'Aprano
Ben Finney wrote:
> Ben Finney <[EMAIL PROTECTED]> wrote:
> 
>>I want my modules to (sometimes) define an abstract base exception
>>class, that all other exceptions in that module inherit from.
> 
> 
> [re-posting with the implementation properly foo-ified]

Isn't the proper Python idiom to use Monty Python 
concepts, e.g. spam, vikings, parrots, after dinner 
mints (wafer thin or otherwise), gumby, etc.?

As well as being Pythonic, it annoys the Lisp, Perl and 
C developers even more than ... sarcasm.

*wink*

> Not a whole lot of feedback on this, so here's the implementation I
> decided upon.

[snip]

Seems good to me.


-- 
Steven.

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


modifying small chunks from long string

2005-11-13 Thread MackS
Hello everyone

I am faced with the following problem. For the first time I've asked
myself "might this actually be easier to code in C rather than in
python?", and I am not looking at device drivers. : )

This program is meant to process relatively long strings (10-20 MB) by
selectively modifying small chunks one at a time. Eg, it locates
approx. 1000-2000 characters and modifies them. Currently I was doing
this using a string object but it is getting very slow: although I only
modify a tiny bit of the string at a time, a new entire string gets
created whenever I "merge" it with the rest. Eg,

shortstr = longstr[beg:end]

# edit shortstr...

longstr = longstr[:beg] + shortstr + longstr[end:] # new huge string is
created!!

Can I get over this performance problem without reimplementing the
whole thing using a barebones list object? I though I was being "smart"
by avoiding editing the long list, but then it struck me that I am
creating a second object of the same size when I put the modified
shorter string in place...

Thanks for any help,

Mack

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


Re: PySizer 0.1

2005-11-13 Thread Claudio Grondi
A small hint about the Web-site:
At least to me, the links to the documentation as e.g.

http://pysizer.8325.org/doc/auto/home/nick/sizer-trunk/doc/auto/scanner.html
are broken (no big thing, because the distro has it anyway).

Claudio

"Nick Smallbone" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
> 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


Dictionary of tuples from query question

2005-11-13 Thread David Pratt
Hi.  I am interested in having results from a db query in the following form.

{1: (value0, value1, value2,), 2: (value0, value1, value2,), 3: (value0, value1, value2,)}

so I generate a dictionary of tuples (field values) dynamically so if I queried a table with five fields I would have five fields in my tuple and if I had 20 fields in my query, I would have 20 fields in my tuple, etc.

Note that the dict starts at 1 and not zero.  From the code below, the structure I have currently is:

{1: {0:value0, 1:value1, 2:value2}, 2: {0:value0, 1:value1, 2:value2}, 3: {0:value0, 1:value1, 2:value2}}

My code so far. I guess my problem is how to generate a tuple dynamically when it is immutable?

Many thanks
David

cursor = db.cursor()
cursor.execute("""
SELECT * FROM countries;
""")
rows = cursor.fetchall()

vdict = {}
for row in range(len(rows)):
col_dict = {}
for col in range(len(rows[row])):
value = rows[row][col]
col_dict[col] = value
vdict[row + 1] = col_dict
print vdict



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

Re: Abstract Base Classes

2005-11-13 Thread Ben Finney
Ben Finney <[EMAIL PROTECTED]> wrote:
> I want my modules to (sometimes) define an abstract base exception
> class, that all other exceptions in that module inherit from.

[re-posting with the implementation properly foo-ified]

Not a whole lot of feedback on this, so here's the implementation I
decided upon.

class FooException(Exception):
""" Base class for all exceptions in this module """
def __init__(self):
if self.__class__ is FooException:
raise NotImplementedError, \
"%s is an abstract class for subclassing" % self.__class__

class FooBarTypeError(TypeError, FooException):
""" Raised when the foo gets a bad bar """

class FooDontDoThatError(AssertionError, FooException):
""" Raised when the foo is asked to do the wrong thing """


This allows the exceptions for the module to behave similarly to their
leftmost base exception; but because they all inherit from the
abstract base class exception for the module, it also allows for this
idiom:

import foo

try:
foo.do_stuff(bar)
except FooException, e:
special_error_handler(e)


Any more comment on this technique? Any other significant use cases
for abstract base classes?

-- 
 \ "For man, as for flower and beast and bird, the supreme triumph |
  `\   is to be most vividly, most perfectly alive"  -- D.H. Lawrence. |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Abstract Base Classes

2005-11-13 Thread Ben Finney
Ben Finney <[EMAIL PROTECTED]> wrote:
> I want my modules to (sometimes) define an abstract base exception
> class, that all other exceptions in that module inherit from.

Not a whole lot of feedback on this, so here's the implementation I
decided upon.

class FooException(Exception):
""" Base class for all exceptions in this module """
def __init__(self):
if self.__class__ is EnumException:
raise NotImplementedError, \
"%s is an abstract class for subclassing" % self.__class__

class FooBarTypeError(TypeError, FooException):
""" Raised when the foo gets a bad bar """

class FooDontDoThatError(AssertionError, FooException):
""" Raised when the foo is asked to do the wrong thing """


This allows the exceptions for the module to behave similarly to their
leftmost base exception; but because they all inherit from the
abstract base class exception for the module, it also allows for this
idiom:

import foo

try:
foo.do_stuff(bar)
except FooException, e:
special_error_handler(e)


Any more comment on this technique? Any other significant use cases
for abstract base classes?

-- 
 \ "For man, as for flower and beast and bird, the supreme triumph |
  `\   is to be most vividly, most perfectly alive"  -- D.H. Lawrence. |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting dominoes

2005-11-13 Thread Yu-Xi Lim
DaveM wrote:
> Essentially, I'm trying to sort 12 dominoes. Each domino has two different
> numbers and there are two of every number. Identical dominoes are possible,
> but doubles are not.
> 
> The problem is to place the dominoes in a line, side to side, so that two
> columns (or rows, depending how you orientate them) are formed, with each
> number appearing once in each column(row).
> 
> I thought this would be the easy part of the program I'm writing, but so far
> some initial states have defeated every attempt I've made, short of
> re-shuffling the dominoes after an arbitrary number of attempts.
> 
> I'm sure I'll work out an effective algorithm eventually, but I suspect I'm
> re-inventing the wheel, so any hints on the best way to tackle this would be
> appreciated!
> 
> DaveM 

Assuming your dominoes are expressed as a list of tuples, e.g. [ (1, 2), 
(3, 2), (3, 1) ].

The pseudo-code would probably be as follows:

1) create a corresponding list of dominoes with each domino reversed
2) concatenate your original list of dominoes with the list of flipped 
dominoes
3) sort the new concatenated list
4) take every other element in the sorted list, e.g. using [::2]

I hadn't actually thought about it enough to verify if it works all the 
time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting dominoes

2005-11-13 Thread jepler
So if you have the dominoes (1 2), (3 2) and (3 1) you must arrange them as
1|2|3
2|3|1
?  If so, then it seems to me your algorithm is this:
1. pick an arbitrary domino to be first, and an arbitrary side to be the "top"
2a. until the dominoes are exhausted, pick the other domino with the same digit
   as the "bottom" of the last domino picked, and put that digit on the top.
2b. If there is no domino with the same digit, then pick an arbitrary domino as
   in step 1

Jeff


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

Re: Copyright [was Re: Python Obfuscation]

2005-11-13 Thread David T
I realize that this thread skirts with being OT, but there are  
serious implications for Pythonistas and Open Source software types.

I didn't mean to suggest that T.E. moved to California. I did,  
however, misspeak (mis-type?) when I said Edison formed a studio in  
California. His was in NJ, according to Google and other officious  
oracles.

A few different accounts of Edison's relationship to the film industry:

http://www.filmsite.org/pre20sintro2.html
http://www.cobbles.com/simpp_archive/edison_trust.htm

FYI, as a newbie to _this_ list, I had some difficulties with my  
first post to this thread earlier today.

It follows at the end of this post.
On Nov 13, 2005, at 7:28 PM, Alex Martelli wrote:

> David T <[EMAIL PROTECTED]> wrote:
>...
>> Tom Edison moved to California so _he_ could skirt copyright laws of
>
> I'm not aware of any move to California for either the better-known
> Thomas Alva Edison, or his lesser-known and less successful son of the
> same name.  Could you clarify?  The movie industry was born in
> California to skirt around some of Edison's (and others') patents, but
> that's a whole 'nother story, of course.
>
>
> Alex
> -- 
> http://mail.python.org/mailman/listinfo/python-list


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: py2exe, pyparallel

2005-11-13 Thread garyr

Chris Mellon wrote:
> On 13 Nov 2005 10:03:52 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > 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
> >
>
> This *looks* like all that's happening is that ctypes is unable to
> load the dll simpleio.dll , which is not a standard windows library
> and therefore needs to be somewhere LoadLibrary can find it.
>
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
Thanks for you reply.
Yes, copying simpleio.dll to my dist directory corrected the problem.
The
program now runs but I get an error message when it terminates that
directs
me to the log file where I find the message:

C:\MY DOCUMENTS\PYTHON\DDS\DIST\library.zip\dds2.py:96: FutureWarning:
x

Sorting dominoes

2005-11-13 Thread DaveM
Essentially, I'm trying to sort 12 dominoes. Each domino has two different
numbers and there are two of every number. Identical dominoes are possible,
but doubles are not.

The problem is to place the dominoes in a line, side to side, so that two
columns (or rows, depending how you orientate them) are formed, with each
number appearing once in each column(row).

I thought this would be the easy part of the program I'm writing, but so far
some initial states have defeated every attempt I've made, short of
re-shuffling the dominoes after an arbitrary number of attempts.

I'm sure I'll work out an effective algorithm eventually, but I suspect I'm
re-inventing the wheel, so any hints on the best way to tackle this would be
appreciated!

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


Trouble with "freeze.py" importing 3rd Party Modules

2005-11-13 Thread Michael Williams
Can anyone explain why "freeze.py" will make binaries with the std  
modules fine, however, when using 3rd party modules (Pexpect in  
particular) it requires the target system to actually have it installed?

Thanks in advance,
Mike
-- 
http://mail.python.org/mailman/listinfo/python-list


gmpy/decimal interoperation

2005-11-13 Thread Alex Martelli
As things stand now (gmpy 1.01), an instance d of decimal.Decimal cannot
transparently become an instance of any of gmpy.{mpz, mpq, mpf}, nor
vice versa (the conversions are all possible, but a bit laborious, e.g.
by explicitly going through string-forms).

I'm thinking about possible ways to fix this, in whole or in part, but,
before I spend more time on this, I was wondering if there's anybody
else who'd be interested -- if so, maybe we can discuss which
conversions should happen implicitly (e.g., if you try to sum a Decimal
and an mpz, maybe the latter should implicitly become a Decimal, just
like an int would, so that the result is a Decimal) and which ones
should only happen on explicit request (e.g., gmpy.mpf(d) should produce
an mpf instance, just as calling gmpy.mpf on an int instance would).


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


Re: Hash map with multiple keys per value ?

2005-11-13 Thread Bengt Richter
On Fri, 11 Nov 2005 22:55:53 +, Chris Stiles <[EMAIL PROTECTED]> wrote:

>Hi --
>
>I'm working on something that includes the concept of multiple aliases for a
>particular object, where a lookup for any of the aliases has to return all the
>others.  The hack way of doing this was to have a dictionary where each 
>entry consisted of a list of all the aliases - with multiple references to the
>same list from the various dictionary entries corresponding to each alias.
>
>Is there an easier and cleaner way of doing this ?  Is there example code
>floating around that I might have a look at ?
>
[OT about on-T missing post]
I see my post on google
http://groups.google.com/group/comp.lang.python/msg/7d6056940048f1b6
but I haven't seen it yet on my newsreader. Is it not showing for anyone
else either? I am wondering what's happening. Usually it's only a matter
of minutes, not a day and counting ;-/

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


gmpy 1.01 binaries for the mac

2005-11-13 Thread Alex Martelli
I've added to gmpy.sf.net two binary packages of gmpy for Mac OS X 10.4,
one for the Python 2.3.5 that comes with the system and one for Bob
Ippolito's build of 2.4.1.  They still need GMP to be previously
installed (I'm told the one that comes with fink works; I installed my
own from sources, from the GMP's site at swox.com), and they're .tar.gz
packages requiring unpacking with tar xzf from the Terminal -- so, not
very Mackish -- but they may still help if you don't want to install
Apple's free and powerful XCode (which IS currently an 800+ MB download,
after all) and still want to play with gmpy's functionality on your
Mac's Python, I hope.

Let me know if there's interest in me eventually doing a better job of
Mac packaging... while I have a hard time getting ahold of Windows
machines, and particularly suitable development systems for them, I _am_
rather full of Macs (& dev systems for them;-)...


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


Re: Iterator addition

2005-11-13 Thread Bengt Richter
On Sun, 13 Nov 2005 17:28:59 -0600, [EMAIL PROTECTED] wrote:
[...]
>
>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.
>
Oops ;-) Ok. Parens to control evaluation order in expression sequences could 
use the illegal
attribute trailer syntax expr1 .(expr2) so that would be

  expr .(-expr)

And the previous MINUS thing would become

 MINUS .(a MINUS b)

Not as pretty, but I guess workable when actually needed.

Anyway, to give an idea of possibilities, matrix ops could
be written nicely to operate on lists and lists of lists
(or duck-equiv objects) as an alternative to having e.g.
a matrix class with __POW__(-1) and __MUL__ defined,
and where you might use a matrix class and write

a41 = m44**-1 * m41

you could operate on duck-lists writing something like

a41 = m44 INV MM m41

where (sketching still ;-)

class INV(MatrixOps):
"""postfix matrix inverse operator"""
@classmethod
def __pfunaryop__(cls, m):
 # mx inverse here
 return cls.inverse(m)

class MM(MatrixOps):
"""binary matrix multiply operator"""
@classmethod
def __binaryop__(cls, left, right):
 # mx product here
 return cls.product(left, right)

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


Re: Copyright [was Re: Python Obfuscation]

2005-11-13 Thread Alex Martelli
David T <[EMAIL PROTECTED]> wrote:
   ...
> Tom Edison moved to California so _he_ could skirt copyright laws of

I'm not aware of any move to California for either the better-known
Thomas Alva Edison, or his lesser-known and less successful son of the
same name.  Could you clarify?  The movie industry was born in
California to skirt around some of Edison's (and others') patents, but
that's a whole 'nother story, of course.


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


Re: py2exe, pyparallel

2005-11-13 Thread Chris Mellon
On 13 Nov 2005 10:03:52 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> 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
>

This *looks* like all that's happening is that ctypes is unable to
load the dll simpleio.dll , which is not a standard windows library
and therefore needs to be somewhere LoadLibrary can find it.

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


Re: Python Book

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

I like Learning Python. Python in a Nutshell is good if you want something 
brief.

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


Re: Confusion about __call__ and attribute lookup

2005-11-13 Thread Kent Johnson
John J. Lee wrote:
> 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

I have never found it there. I think something like the writeup Serge 
referenced should be in the language reference. I just sent the suggestion to 
[EMAIL PROTECTED]

Thanks to both of you,
Kent
-- 
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 "NAME"s 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


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

Wow, a lot bigger difference than on my machine.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]:
  

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: 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: 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: 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: 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 "NAME"s 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: 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: 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 [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


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


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

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.

  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: 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 [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: 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.

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


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


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


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


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


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


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: the button of cancel

2005-11-13 Thread Ben Bush

On 11/13/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
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.htmlThanks, now the code works. I wonder when i put the number between 1 and 100, I get the message of 'Your number is in the range' but i still see the input box. How to remove it?
num = input( "Enter a number between 1 and 100: " )try:    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: ' )
    num=input('Your number is in the range')except KeyboardInterrupt:    print 'Goodbye!'
-- 
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)





-- 
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
, 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


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: 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]")
> 
> 

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


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


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


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


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


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


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


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


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


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


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


[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


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


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


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: 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:
> 
> 
> 
> 
> 
>>  
>> So instead I have to give a "print" command to make the result appear 
>> in the interpreter for EX:
> 
> 
> 
> 
>> 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


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

2005-11-13 Thread Ben Finney
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.

-- 
 \ "Yesterday I parked my car in a tow-away zone. When I came back |
  `\   the entire area was missing."  -- Steven Wright |
_o__)  |
Ben Finney
-- 
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


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


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 "", 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: 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


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


  1   2   >