RE: Python in Games (was RE: [Stackless] Python in Games)

2005-06-14 Thread Delaney, Timothy C (Timothy)
Irmen de Jong wrote:

> Also, alledgedly the new BattleField II uses Python in a way...
> because I heard that you had to comment out a certain line
> in a certain .py file to remove the time limit of the demo :-)

Silly silly people - they should have at least had the launcher and that
part in Pyrex ;)

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


RE: Python in Games (was RE: [Stackless] Python in Games)

2005-06-14 Thread Delaney, Timothy C (Timothy)
Dave LeCompte (really) wrote:

>> Who is using Python in games
>> 
>> Python has been used in a number of games, including
>> 
>>* ToonTown - http://www.toontown.com/
>>* EveOnline - http://www.eve-online.com/
>>* Blade of Darkness - http://www.codemastersusa.com/blade/

Add to that:

- `The Temple of Elemental Evil`__
- `Vampire: The Masquerade: Bloodlines`__

.. __: http://www.troikagames.com/toee.htm
.. __: http://www.vampirebloodlines.com/

Moved to python-list because it's gone beyond Stackless :)

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


RE: Controlling a generator the pythonic way

2005-06-13 Thread Delaney, Timothy C (Timothy)
FWIW, PEP 342 is now titled "Coroutines via Enhanced Iterators" :)

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


RE: Controlling a generator the pythonic way

2005-06-13 Thread Delaney, Timothy C (Timothy)
Steve Holden wrote:

> Sigh indeed. But if you allow next() calls to take arguments you are
> effectively arguing for the introduction of full coroutines into the
> language, and I suspect there would be pretty limited support for
> that. 

You mean `PEP 342`_ which I posted earlier and is considered pretty
non-controversial?

I think I may suggest that the name of the PEP be changed to "Coroutines
using advanced iterators".

.. _`PEP 342`: http://www.python.org/peps/pep-0342.html

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


RE: Controlling a generator the pythonic way

2005-06-12 Thread Delaney, Timothy C (Timothy)
Thomas Lotze wrote:

> call. The picture might fit better (IMO) if it didn't look so much
> like working around the fact that the next() call can't take
> parameters for some technical reason. 

You might want to take a look at PEP 342
. Doesn't help you now, but it
will in the future.

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


RE: For review: PEP 343: Anonymous Block Redux and GeneratorEnhancements

2005-06-05 Thread Delaney, Timothy C (Timothy)
Nicolas Fleury wrote:

> def getFirstLine(filename):
>  with opening(filename) as file
>  return file.readline()

Your tastes definitely disagree with the majority of Python programmers
then, including Guido. Scoping is defined in Python by indentation.

If you want the above sort of thing, you're going to have to write a new
PEP, and I'd be very surprised to see it accepted. But there's nothing
stopping you from doing so.

> def getFirstLine(filename):
>  with opening(filename) as file:
>  return file.readline()

This is beautiful and explicit. What else could you want?

The syntax:

with EXPR1 as VAR1, EXPR2 as VAR2:
...

was discussed on python-dev. It wasn't explicitly rejected, but the
feeling seemed to be that it was an unnecessary complication as far as
PEP 343 is concerned. There's nothing stopping another PEP proposing
this as an extension to PEP 343, and there's nothing stopping that being
in Python 2.5 if it's accepted.

PEP 343 was originally PEP 340 (and several other things) and was quite
complicated at one point (it originally contained PEP 342 as well). The
PEP in its current state represents 2 months of discussion, complication
and (finally) simplification. Its semantics are clear and unambiguous.
And (as Guido states) it will obsolete 4(?) other PEPs.

Be sure to read the referenced PEPs (and the ones referenced from them)
- they contain a lot of history. Also read PEP 346 for a competing PEP
to PEPs 340 and 343 that gradually converged to PEP 343 - most
importantly, it contains the rejected options (that seem to have been
lost from PEPs 340 and 343).

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


RE: Is Python suitable for a huge, enterprise size app?

2005-05-18 Thread Delaney, Timothy C (Timothy)
Ivan Van Laningham wrote:

> What you're going to run into are two major stumbling blocks.  One,
> Python's got no credibility with management types unless the
> credibility's already there.  "Python?  Never heard of it.  Tell me
> about it.  ...   Oh, it's interpreted, is it?  Interesting."  You can
> see Python going down the sewer pipes, right on their faces.  Two,
> security.  "This python sounds pretty interesting.  Tell me about the
> security.  How can we prevent people from stealing our source code,
> which we just spent millions developing?  ...  Hmm, trust the
> developers out there not to peek?  Oh, sure, let's use it."  (True,
> there are ways around the second, but you're going to have to talk
> _very_ fast and have ALL the answers before the management type gets
> to his/her office and shuts the door in your face and on your idea.)

There is a good answer to both of these ... Pyrex (second time I've
recommended it today :)

http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/

I recently had a situation here at work where a utility written in
Python needed to start going out to customers. The simplest solution was
to use Pyrex to create extension modules from the Python files. With
very minimal changes and an appropriate build script, everything worked.

The disadvantages are that for the Pyrex files you are limited to a
subset of Python features - in particular, things like list
comprehensions, generators, etc don't work. OTOH, it's very easy to put
that type of thing in a Python module and call it from a Pyrex module. A
mixture of Python and Pyrex is about the best of both worlds (esp. if
you add psyco to the mix).

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


RE: speeding up Python script

2005-05-18 Thread Delaney, Timothy C (Timothy)
James Carroll wrote:

> It looks like your algorithm really does iterate over all values for
> six variables and do lots of math.. then you can't do any better than
> implementing the inner loop in C.

Or Pyrex ...
http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/

For this type of situation, Pyrex is pretty much perfect. You can write
your algorithm in Python, get it right, then optimise it with static
typing, C variables, etc as required. You don't even need to change your
test suite because you build a Python extension module.

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


RE: The world is really unstable these days......

2005-05-15 Thread Delaney, Timothy C (Timothy)
Peter Hansen wrote:

> Lucas Raab wrote:
>> 
> [...]
>> Y'know, I really do love these random word spam messages. They're
>> quite entertaining to read.
> 
> Although, when posting in reply to them it apparently helps those who
> read this through the mailing list, and who have Bayesian filtering of
> spam happening, if you would snip the entire content.
> 
> Otherwise it can confuse the spam blockers since they have your name
> generally associated with useful messages (I presume ;-) )  instead of
> with spam.  You're messin' with their statistics, man!  ;-)

Absolutely. Another example of where these things can mess with
Spambayes is people replying to XL and correcting his horrendous
troll-posts. It makes it really hard for Spambayes to determine that
*anything* coming from XL is spam.

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


RE: Property,how to use it?

2005-05-15 Thread Delaney, Timothy C (Timothy)
[EMAIL PROTECTED] wrote:

> What is the "property" mean in the python? Who can explain it
> for me? I don't know how to use it.

http://www.catb.org/~esr/faqs/smart-questions.html

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


RE: Need a little parse help

2005-05-11 Thread Delaney, Timothy C (Timothy)
Fredrik Lundh wrote:

> that's probably because finalizers *are* called when Python exits.

D'oh! Old semantics? I'm sure I remember this used to not work at some
point, and not just in Jython.

My apologies to anyone who I led astray. Still ... better to be too
careful ;) I've been trying to find the declared semantics (without
looking at the source for now) but it's proving elusive ...

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


RE: Need a little parse help

2005-05-10 Thread Delaney, Timothy C (Timothy)
Peter Hansen wrote:

> In my opinion, if the code fits on one screen and just reads stuff
> from one file and, maybe, writes to another, you can safely and with
^^
> clean conscience ignore Mike's advice (but remember it for later!).

Remember, finalisers are not called when Python exits. So if you don't
explicitly close the file you are *writing* to, it may not be flushed
before being closed (by the OS because the process no longer exists).

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


RE: bad argument type for built-in operation

2005-05-10 Thread Delaney, Timothy C (Timothy)
Florian Lindner wrote:

> Traceback (most recent call last):
>   File "visualizer.py", line 8, in ?
> main()
>   File "visualizer.py", line 5, in main
> g = GraphCreator(f)
>   File "/home/florian/visualizer/GraphCreator.py", line 13, in
> __init__ self.conf = ConfigReader(config)
>   File "/home/florian/visualizer/ConfigReader.py", line 53, in
> __init__ graph.sourceReader = CSVReader(filename, firstline,
>   delimiter) File "/home/florian/visualizer/ConfigReader.py", line
> 13, in __init__ self.reader = csv.reader(f, delimiter=Adelimiter)
> TypeError: bad argument type for built-in operation
> 
> f ist file object, Adelimiter is ",".
> 
> What is wrong there?

Lack of code. I'd start looking very carefully as to whether `f` really
is a file object.

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


RE: Ask for a tool to protect my .pyc file :)

2005-05-08 Thread Delaney, Timothy C (Timothy)
Lily Kakm wrote:

> when I distribute my software, I will give the users .pyc file (maybe
> I can use py2exe, but I think there's no essential different),
> because I don't like them to know my source code.

Leaving aside all other arguments of whether or not you should allow
your users to see your source code ...

The simplest method to compile python is to use Pyrex:
http://www.google.com.au/search?q=pyrex&btnI

It's almost-compatible syntax-wise with Python 2.2 (no augmented
assignment, no nesting classes, and classmethods don't appear to work -
probably static methods too).

Then you just have a single script which calls your first main module,
and everything else is in a shared library (.so, .pyd).

It's quite nice to be able to have identical source, copy the source
tree, rename files appropriately and be able to build using Pyrex (with
an appropriate setup.py).

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


RE: problem in the compiler ?

2005-05-04 Thread Delaney, Timothy C (Timothy)
Glauco Silva wrote:

> I´m sorry, I feel I didn't comunicate very well .
> The program I am writing is a part of a big project, so it would be
> no use to post it here as it involves many other things and concepts.

We wouldn't want the whole thing - that would be useless. What you need to do 
is trim it down to the smallest piece of code that causes the problem. Normally 
doing this reveals the actual problem, and you don't need to go to the 
newsgroup.

> But i solve my problem and don´t have bug. My code was wrong.

Excellent. You should now post your solution to the newsgroup.

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


RE: problem in the compiler ?

2005-05-03 Thread Delaney, Timothy C (Timothy)
Glauco Silva wrote:

> My code is like this:
> 
> MyClass()
> 
> class MyClass:
>  def __init__(self):
>  btn = RadioButton(command=self.Function)
>  def Function(self):
>  print "Enter in the function"
> 
> When a do this, the function 'Function' is call. And i don´t want
> this. What´s wrong ?

Are you absolutely sure this is the exact code? As it is this will not work - 
it will fail with a NameError.

You need to post a working piece of code that exhibits the behaviour, and 
include the exact error message (if any).

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


RE: problem in the compiler ?

2005-05-02 Thread Delaney, Timothy C (Timothy)
Glauco Silva wrote:

> when i creat a RadioButton and put a command = self.Function , this
> function is called in the creation of RadioButton. It´s right this or
> it´s wrong ? 

http://www.catb.org/~esr/faqs/smart-questions.html

I'm pretty sure I can guess exactly what the problem is. I suspect your code 
looks somewhat like:

btn = RadioButton(command=self.Function())

Follow the instructions in the above link and you should be able to work out 
why this is wrong.

If I've failed to read your mind correctly, the above link should also teach 
you how to make it easier for me to do so.

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


RE: Compiling extensions

2005-04-06 Thread Delaney, Timothy C (Timothy)
ake wrote:

> I would like to compile extensions usig distutils. is there a way to
> set which compiler to use ?
> 
> I am using windows and VC++ 7.1 comp.

python setup.py --help
python setup.py build --help

However, if you're using an installed version of VC++ 7.1 you shouldn't
need to set the compiler.

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


RE: the bugs that try men's souls

2005-04-06 Thread Delaney, Timothy C (Timothy)
Jordan Rastrick wrote:

> I had a doozy myself the other night, writing a mergesort for python's
> deque class (I can't believe it doesnt come with one!)

Post it to the Cookbook ... ;)

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


RE: string goes away

2005-03-31 Thread Delaney, Timothy C (Timothy)
Andreas Beyer wrote:

> Yeeh, I was expecting something like that. The only reason to use
> map() at all is for improving the performance.
> That is lost when using list comprehensions (as far as I know). So,
> this is *no* option for larger jobs.

Try it and see. You'll probably be pleasantly surprised.

Note that you can use `str.upper` in map ...

/usr/bin> C:/Python24/python.exe -m timeit -s "strings = ['a']*1000"
"map(str.upper, strings)"
1000 loops, best of 3: 304 usec per loop

/usr/bin> C:/Python24/python.exe -m timeit -s "strings = ['a']*1000"
"[s.upper() for s in strings]"
1000 loops, best of 3: 331 usec per loop

Pretty damn close.

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


RE: mod_python

2005-03-29 Thread Delaney, Timothy C (Timothy)
onur2029 wrote:

>I need mod_python resources,documentation or ebook.But not manual
> from modpython.org.I'm waiting for your links.

http://www.catb.org/~esr/faqs/smart-questions.html

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


RE: __getslice__ passed INT_MAX rather than sys.maxint for missingendpoint?

2005-03-28 Thread Delaney, Timothy C (Timothy)
Dave Huang wrote:

> Hi, I don't actually know Python; I'm just trying to debug a problem
> I encounted in another program, so apologies if this has been
> covered before. I did do some Google searches though, and didn't
> find anything that specifically addressed this :)
> 
> According to the documentation at
> , __getslice__
> is passed sys.maxint for a missing endpoint (foo[i:]). However, as
> far as I can tell, it's actually passing INT_MAX. I'm running Python
> 2.4 on an Alpha running NetBSD 2.0, an LP64 platform, so the two
> aren't the same. INT_MAX is 2^32-1, whereas sys.maxint is LONG_MAX:
> 2^64-1.
> 
> So, am I misunderstanding things, or is this a doc bug, or a code bug?

It sounds like a code bug to me - raise it at:
http://sourceforge.net/tracker/?group_id=5470&atid=105470

> FWIW, the problem I encountered was some code that did something like:
> def __getslice__(self, a, b):
> if b == maxint:
> b = self.length  # this never got executed, causing

I presume that's actually:

if b == sys.maxint:

Anyway, the quick fix for this is:

def __getslice__(self, a, b):
b = min(b, len(self.length))

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


RE: The Running Time of += on Char Strings ?

2005-03-28 Thread Delaney, Timothy C (Timothy)
MyHaz wrote:

> ''.join(['Thank ','you])
   ^^ Syntax error ...

Probably better as:

' '.join(['Thank', 'you'])

;)

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


RE: Help me to sort.

2005-03-23 Thread Delaney, Timothy C (Timothy)
BMS wrote:

> I'll apreciate if you can guide me how to sort in Python. I'm doing a
> list and I want to sort it in ascending or descending order. 
> 
> Please send me some examples.

Everything you need is right here:
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.python.org/doc/

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


RE: Set literals

2005-03-21 Thread Delaney, Timothy C (Timothy)
George Sakkis wrote:

> How about overloading curly braces for set literals, as in
> 
 aSet = {1,2,3}
> 
> - It is the standard mathematic set notation.
> - There is no ambiguity or backwards compatibility problem.
> - Sets and dicts are in many respects similar data structures, so why
> not share the same delimiter ? 

This was the proposed syntax (with {-} being the empty set - there's the
ambiguity). The issue may be revisited for Python 3K, but for now there
will not be syntax support for sets.

Read the section on 'Set Notation' in:
http://www.python.org/peps/pep-0218.html

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


RE: printing anomaly

2005-03-20 Thread Delaney, Timothy C (Timothy)
Paul Rubin wrote:

> What's the deal with this?
> 
> >>> print 3.2
> 3.2
> >>> print [3.2]
> [3.2002]
> >>>
> 
> Yes, I know that 3.2 isn't an exact binary fraction.  I'm wondering
> why it's converted differently depending on whether it's in a list.

`print 3.2` == `print str(3.2)`.
`print [3.2]` == `print str([3.2])`.

list.str calls repr() on all elements. Partly, this is so that:

>>> print [3.2]
>>> print ['3.2']

don't have the same output. Otherwise, how could you tell (visually) if
an element was a string or a float (or integer, or whatever)?

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


RE: code for Computer Language Shootout

2005-03-16 Thread Delaney, Timothy C (Timothy)
Jacob Lee wrote:

>>  # alias methods to avoid repeated lookup
>>  join = ''.join

I would actually do the alias here sometimes, but give it a
semantically-useful name ...

nosep_join = ''.join

...

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


RE: Conversion to string: how do `s work?

2005-03-14 Thread Delaney, Timothy C (Timothy)
Chris Lasher wrote:

> I'm working my way through _Learning_Python_ 2nd ed., and I saw
> something peculiar which is not explained anywhere in the text.
> 
> print " " + file + " size=" + `size`
> 
> The `s appear to somehow automagically convert the integer to a string
> for concatenation. How does this work? Is this just a shortcut for
> str(size)? Is it considered bad practice to use `s?

In addition to the fact that `` is repr() and generally shouldn't be
used, the above is much better written using string formatting:

print ' %s size=%u' % (file, size)

Shorter, cleaner, and more explicit.

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


RE: Best way to make a list unique?

2005-03-08 Thread Delaney, Timothy C (Timothy)
Michael Hoffman wrote:

>>> For those who don't know, these implement a hash set/map which
>>> iterates in the order that the keys were first added to the set/map.
> 
> I would love to see such a thing.

I've proposed this on python-dev, but the general feeling so far is
against it. So far the only use case is to remove duplicates without
changing order, and there are iterator-based solutions which would
normally be preferable.

It's pretty simple to roll your own, and I'll probably put together a
Cookbook recipe for it.

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


RE: Best way to make a list unique?

2005-03-08 Thread Delaney, Timothy C (Timothy)
Steven Bethard wrote:

> Sounds like a good candidate for the collections module.  Of course
> someone will need to implement it. ;)

I'll suggest it to Raymond ... ;)

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


RE: parameter name conflict. How to solve?

2005-03-08 Thread Delaney, Timothy C (Timothy)
Bo Peng wrote:

>> Is this a style guide thing?
>> 
>> Why not just:
>> 
>> def func(output_param=''):
>> output(output=output_param)
>> 
> 
> This is exactly the problem. There are a bunch of other functions that
> use output='' parameter. Changing parameter name for this single
> function may cause confusion.

So why not rename the `output` function? Or alternatively, you could
change the parameter name for everything (not recommended).

I can assure you that when someone goes to maintain this code, having a
function go through all kinds of schenanigans to support what you want
to do will be much more confusing than a different parameter name.

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


RE: Best way to make a list unique?

2005-03-08 Thread Delaney, Timothy C (Timothy)
Diez B. Roggisch wrote:

> No. But I doubt that that is what you actually want, as listA will
> lose its order afterwards. Typically, something like that gets
> written like this: 

This is actually one thing that Java 1.5 has that I'd like to see in
Python - the LinkedHashSet and LinkedHashMap. Very useful data
structures.

For those who don't know, these implement a hash set/map which iterates
in the order that the keys were first added to the set/map.

Such a data structure is fairly simple to implement, and removing
duplicates then becomes:

unique = list(linkedset(orig))

and you're guaranteed to maintain order.

Implementing these is fairly simple.

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


RE: Default function arguments, KURL::cleanPath() -- a bindings bug?

2005-03-07 Thread Delaney, Timothy C (Timothy)
Frans Englich wrote:

> Apparently, cleanPath /requires/ a boolean argument, but the C++
> function definition says:
> 
>   void cleanPath(bool cleanDirSeparator = true);

Most likely that cleanPath's default parameter hasn't been declared to
*Python*. If so, I expect this is a KURL bug. Raise a bug report with
the KURL developers.

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


RE: parameter name conflict. How to solve?

2005-03-07 Thread Delaney, Timothy C (Timothy)
Steven Bethard wrote:

>> If you ask: why do you choose these names? The answer is: they need
>> to be conformable with other functions, parameter names.

Is this a style guide thing?

>> I have a function that pretty much like:
>> 
>> def output(output=''):
>>   print output
>> 
>> and now in another function, I need to call output function, with
>> again keyword parameter output 
>> 
>> def func(output=''):
>>   output(output=output)

Why not just:

def func(output_param=''):
output(output=output_param)

?

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


RE: Why doesn't join() call str() on its arguments?

2005-02-16 Thread Delaney, Timothy C (Timothy)
John Roth wrote:

> result = "".join([str(x) for x in list])

As of 2.4, you should use a generator expression here instead (unless
you require backwards-compatibility with 2.3).

result = ''.join(str(x) for x in iterable)

Easier to read, more memory-efficient, potentially faster (depending on
performance characteristics of building large lists).

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


RE: Inheritance error in python 2.3.4???

2005-02-14 Thread Delaney, Timothy C (Timothy)
[EMAIL PROTECTED] wrote:

> I guess I could just use one underscore but that means it is
> easier for other people to get at my implementation details (which,
> coming from a C++ background really bothers me).

This is the correct solution, and getting over being bothered about it
is the correct thing to do.

Getting at private members is simple in C++ too if anyone wants to do
that.

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


RE: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-14 Thread Delaney, Timothy C (Timothy)
Stephen Kellett wrote:

> In message <[EMAIL PROTECTED]>, Ilias Lazaridis
> <[EMAIL PROTECTED]> writes
>>>  And yet there is not one company that has someone devoted full-time
>>> to  developing Python. Not even Guido.
>> 
>> Who's "Guido"?
> 
> LOL Falling off my chair!!

See, the problem is that you have to go all the way to the second FAQ in
order to find out who Guido is. Obviously it needs to be more prominent
on the Python web site.

Oh - you mean Ilias didn't actually *read* anything on the Python web
site? My bad.

Illias - I'm assuming you are not a troll (despite the contrary
evidence) and am going to direct you to a site with all the answers you
need.

http://www.catb.org/~esr/faqs/smart-questions.html

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


RE: custom classes in sets

2005-02-13 Thread Delaney, Timothy C (Timothy)
vegetax wrote:

>   def __hashcode__(s): return s.path.__hashcode__()

Try __hash__ ...

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


RE: [N00B] What's %?

2005-02-10 Thread Delaney, Timothy C (Timothy)
Harlin wrote:

> In the mode of anticipating another question... I get these all the
> time at work of all places! You'd think IT workers would know the
> answer to these...
> 
> What good is the modulus operator? What would I ever need it for?

# Print a summary every 100 rows
for i in range(1, 1001):
if i % 100 == 0:
print 'Summary: %s rows' % (i,)

There are two examples of using the modulo operator in the above - one
is using it in it's intended integer form, and the other is using it in
its overloaded string formatting form.

Note that the range is from 1 (inclusive) to 1001 (exclusive). If you
used the normal range(1000) you would get a summary on the first time
round the loop, and wouldn't get one for the last 99. Why is for you to
work out ;)

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


RE: strange behaviour with decorators.

2005-02-09 Thread Delaney, Timothy C (Timothy)
Antoon Pardon wrote:

> Ah, yes, the penny dropped. The try: except where there because
> originally there were other statements I wanted to test and I
> didn't want the raise exception by the inc(-2) stop the script.
> I completely forget to consider it would also catch the
> error I was expecting.

A very good example of why you should (almost) never use a bare except:
...

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


RE: Alternative to standard C "for"

2005-02-06 Thread Delaney, Timothy C (Timothy)
[EMAIL PROTECTED] wrote:

> 2) for i in range(A, B, STEP):
>  ...do something...

Note that the most common use of this is something like:

t = 1, 2, 3

for i in range(len(t)):
print i, t[i]

This is best accomplished as:

t = 1, 2, 3

for i, e in enumerate(t):
print i, e

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


RE: Why does super() require the class as the first argument?

2005-02-06 Thread Delaney, Timothy C (Timothy)
Nick Coghlan wrote:

> It *is* possible to eliminate the explicit class argument, but it
> takes a bit (*cough*) of work:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286195

Nick - you stole my thunder ;)

Note that my recipe uses a sys._getframe() hack, so it will never be in
Python as it is. It's also considerably slower than just using super.
But it *does* eliminate the need for specifying the current class name,
and (if you wish) the current method name.

Guido has said that eventually he wants a simpler super() call - but he
doesn't really like my proposed syntax of having it hang off self.
Personally, I like it though and if there was enough community support
I'd write it up as a PEP using the recipe as a sample implementation
which demonstrates the required semantics. However, it hasn't gained
much community support so far ;)

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


RE: Next step after pychecker

2005-02-01 Thread Delaney, Timothy C (Timothy)
huy wrote:

> do not yet have good coverage. TDD is a quite hard to practice as a
> beginner. 

It's even harder to bolt onto an existing codebase :(

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


RE: Pystone benchmark: Win vs. Linux (again)

2005-01-30 Thread Delaney, Timothy C (Timothy)
Franco Fiorese wrote:

>   * Windows XP Pro:  16566.7 pystones/second
>   * Linux (kernel 2.6.9 NPTL): 12346.2 pystones/second

First of all, realise that pystone is not meant to be a general-purpose
benchmarking program. It test a specific, *small* subset of the
functionality available in Python. It's also not meant to be able to
compare across machines, etc. It's highly susceptible to cache effects
and various other things.

If you include parrotbench you will get a better view of things, but
it's also not designed for comparisons across machines.

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


RE: Which is faster?

2005-01-26 Thread Delaney, Timothy C (Timothy)
Aggelos I. Orfanakos wrote:

> Any idea which of the following is faster?
> 
> 'a/b/c/'[:-1]
> 
> or
> 
> 'a/b/c/'.rstrip('/')
> 
> Thanks in advance.
> 
> P.S. I could time it but I thought of trying my luck here first, in
> case someone knows already, and of course the reason.

First, it almost certainly doesn't matter. Use the one that is
self-documenting.

Secondly, time it yourself. It's incredibly easy. There's a module
written especially for doing this - and surprise surprise, it's called
"timeit.py" and it's in the /Lib directory.

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


RE: On benchmarks, heaps, priority queues

2005-01-26 Thread Delaney, Timothy C (Timothy)
[EMAIL PROTECTED] wrote:

> PQPython23 - the Lib implementation
> PQ0 - my insertion sort based variant
> PQueue - my "heap" based variant
> (like PQPython23, but different).

First of all, you should be running these benchmarks using Python 2.4.
heapq is considerably faster there ... (Raymond Hettinger rewrote it all
in C).

http://www.python.org/2.4/highlights.html

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


RE: Distutils: blurring the file==module borders

2005-01-24 Thread Delaney, Timothy C (Timothy)
Frans Englich wrote:

> in ./foo/ I have an __init__.py and a handful of files named
> ClassA.py, ClassB.py, ClassC.py and so forth.
>
> import foo.ClassA
> 
> var = foo.ClassA.ClassA()
> 
> while I want to do var = foo.ClassA()
> 
> In other words, the result I want can be achieved by putting all code
> in __init__.py. The problem is that I would find it horrible to have
> all code in one file.

# __init__.py

from foo.ClassA import ClassA

That brings the class 'ClassA' into the namespace of module 'foo'
(replacing module 'ClassA' as a side effect - if you don't want that,
change some names).

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


RE: fefinining % of c'm'y and k

2005-01-16 Thread Delaney, Timothy C (Timothy)
[EMAIL PROTECTED] wrote:

> hello
> i need a program (and pleas shoe me the modol in the softwar) that :
> if i have a scaned photo
> i want to define out of each poligon color ,as it seems in the photo,
> the cmyk
> in % (percets) of the color/
> 4 exampl from poligon color orang defin the cmyk in %
> like that: (example)
> c: 30%
> m:56%
> y:78%
> k: 10%

This site will assist you greatly.
http://www.catb.org/~esr/faqs/smart-questions.html

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


RE: generator expressions: performance anomaly?

2005-01-16 Thread Delaney, Timothy C (Timothy)
Raymond Hettinger wrote:

> Check out the current source.  The time machine beat you to it.

Nick's other suggestion - that genexps propagate __len__ - might still
be interesting. Of course, it would only be applicable for unconditional
genexps(i.e. no if clause).

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


RE: sorted (WAS: lambda)

2005-01-13 Thread Delaney, Timothy C (Timothy)
Terry Reedy wrote:

> No, not same difference.  A list method would only operate on lists,
> as is true of all list methods.  Being a function lets it work for
> any iterable, as is true of any function of iterable.  Big
> difference.  And consistent. One could argue though that it should
> have been put into itermethods module instead of builtins.

Definitely not. iter*tools* is primarily for functions that take
iterators and *return* iterators i.e. don't use memory proportional to
the length of the iterator.

OK - so there are one or two exceptions, but their presense there has
been strongly justified (and nowhere else seems appropriate - for
example, itertools.tee).

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


RE: shutil.move has a mind of its own

2005-01-10 Thread Delaney, Timothy C (Timothy)
Daniel Bickett wrote:

> shutil.move( "C:\omg.txt" , "C:\folder\subdir" )
  ^  ^^ ^
The problem is that backslash is the escape character. In particular,
'\f' is a form feed.

>>> '\o'
'\\o'
>>> '\f'
'\x0c'
>>> '\s'
'\\s'

Notice how for '\o' and '\s' it doubles-up the backslash - this is
because '\o' and '\s' are not valid escapes, and so it treats the
backslash as just a backslash. But '\f' is a valid escape.

You have a couple of options:

1. Use double-backslashes (to escape the backslash):
   shutil.move("C:\\omg.txt", "C:\\folder\\subdir")

2. Use forward slashes (they work on Windows for the most part):
   shutil.move("C:/omg.txt", "C:/folder/subdir")

3. Build your paths using os.path.join (untested):
   shutil.move(os.path.join("C:", "omg.txt"), os.path.join("C:",
"folder", "subdir"))

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


RE: interpreter Py_Initialize/Py_Finalize mem leak?

2005-01-09 Thread Delaney, Timothy C (Timothy)
Roman Suzi wrote:

> In pure curiosity I tried to compile loop.c from Demo/embed
> and started it with 'print 2+2'. It seems, that both 2.3 and 2.4
> pythons have memory leaks in Py_Initialize/Py_Finalize calls.
> (That is, interpreter doesn't clean up well after itself).

What's your evidence for this (i.e. what are the symptoms)?

If you have a repeatable test case, please raise a bug report on
SourceForge.

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


RE: Developing Commercial Applications in Python

2005-01-03 Thread Delaney, Timothy C (Timothy)
Christophe Cavalaria wrote:

> [EMAIL PROTECTED] wrote:
> 
>> Hello All,
>> I am trying to convince my client to use Python in his new product.
>> He is worried about the license issues. Can somebody there to point
>> me any good commercial applications developed using python ?. The
>> licence clearly says Python can be used for commercial applications.
>> Is there any other implications like that of GPL to make the source
>> open ? Thanks for any help. eeykay

> Troika games use Python in their games. It seems you can even get the
> source .py files for Vampires: Bloodlines :)

Absolutely - it's a slightly modified version of 2.1.2. Troika also used
Python for the Temple of Elemental Evil.

I even compiled psyco to work with Bloodlines and modified the .py
source to call it - worked perfectly well, but didn't give me any
significant performance improvement :( I'm CPU limited, so I thought it
was worth a try.

I'm wondering if I can hack Python 2.4 into Bloodlines ... the biggest
problem is that Bloodlines used .vpk files for packaging, and I believe
the major modifications to 2.1 are to allow these to be read. I've
already extracted all of these though ...

Anyway, back to the original question:
http://www.python.org/doc/faq/general.html#are-there-copyright-restricti
ons-on-the-use-of-python

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


RE: [ANN] [Hack] Import binary extensions from zipfiles, windows only

2004-12-16 Thread Delaney, Timothy C (Timothy)
Thomas Heller wrote:

> zipextimporter.py contains the ZipExtImporter class which allows to
> load Python binary extension modules contained in a zip.archive,
> without unpacking them to the file system.

I take it this was what you were talking about the other day when you
mentioned single-file applications produced by py2exe ...

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


RE: Python compiler method

2004-12-15 Thread Delaney, Timothy C (Timothy)
Lady_Valerie wrote:

> hello guys! i just want to ask favor, coz i want to know how python
> compiler method could be done? im really clueless of this programming
> language hope anyone coule help me with this topic... im just focusing
> only on the compiler of the python.thanks a lot!!!

This should get you some of the way:
http://www.catb.org/~esr/faqs/smart-questions.html

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


RE: need some help quickly

2004-12-14 Thread Delaney, Timothy C (Timothy)
Allan Irvine wrote:

> Hope you can help - any thoughts welcome

Here is the best place you can get help for your problem:
http://www.catb.org/~esr/faqs/smart-questions.html

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


RE: [dictionary] how to get key by item

2004-12-14 Thread Delaney, Timothy C (Timothy)
Roy Smith wrote:

>> >>> forward = {10 : 50, 2 : 12, 4 : 43}
>> >>> reverse = dict([(v,k) for (k,v) in forward.iteritems()])
>> >>> print forward {10: 50, 4: 43, 2: 12}
>> >>> print reverse
>> {50: 10, 43: 4, 12: 2}
> 
> BTW, does Python really build the intermediate list and throw it away
> after using it to initialize the dictionary, or is it smart enough to
> know that it doesn't really need to build the whole list in memory?

Python will do what you tell it. In the above case, it will build a
list.

Using Python 2.4, the above can be rewritten as a generator expression:

>>> forward = {10 : 50, 2 : 12, 4 : 43}
>>> reverse = dict((v,k) for (k,v) in forward.iteritems())
>>> print forward {10: 50, 4: 43, 2: 12}
>>> print reverse
{50: 10, 43: 4, 12: 2}

which does not build an intermediate list. Note that all I've done is
remove the [ and ] - that's because a genexp must be surrounded by
parentheses, but *any* parentheses will do - for example, the
parentheses surrounding the parameters in a function call.

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


RE: byte code generated under linux ==> bad magic number under windows

2004-12-06 Thread Delaney, Timothy C (Timothy)
Philippe C. Martin wrote:

> I understand from my reading that a .pyc generated by python anywhere
> should run anywhere else - is that true ?
> 
> If I generate 'compile.all' a pyc with python 2.3.3 under Linux, I
^
> get a 'bad magic number' trying to execute it under windows (2.4).
   ^^^
> are the pyc plateform dependant ? and if so must I generate one
> version for each version of Linux, windows .. ?

.pyc files are not platform dependent, but they are *version* dependent
- specifically, major version (i.e. 2.3, 2.4).

Between major versions, the bytecode can change. There were in fact some
significant changes between 2.3 and 2.4.

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


RE: How is Python designed?

2004-12-02 Thread Delaney, Timothy C (Timothy)
Roy Smith wrote:

> As far as I can tell, the process works like this:
> 
> Guido has an idea for something he wants to do and announces it.
> 
> Everybody beats him up about it.
> 
> He goes ahead and does it anyway.
> 
> It's a strange process, but it seems to work.

It's not quite that straightforward. For example, sometimes we beat
someone else up as well.

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


RE: decorators ?

2004-12-02 Thread Delaney, Timothy C (Timothy)
Michael Hudson wrote:

> Skip Montanaro <[EMAIL PROTECTED]> writes:
> 
>> Jacek> Anything you can do with decorators, you could do before
>> (with Jacek> the exception of rebinding the __name__ of
>> functions). 
>> 
>> And while that feature was added because we realized it would be
>> nice if the decorated function could have the same name as the
>> original function, it seems like that change could stand on its own
>> merits. 
> 
> Indeed.  I'd been meaning to do it for at least a year...

Ah - looking for any old excuse to get it in huh? 

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