Thursday, April 1, 2010

comp.lang.python - 25 new messages in 7 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* C-style static variables in Python? - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/ce1a7abe2f3816b9?hl=en
* How to run python without python - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/ceb4fa8fa68ba68e?hl=en
* off topic but please forgive me me and answer - 12 messages, 6 authors
http://groups.google.com/group/comp.lang.python/t/0d4f564a49022b74?hl=en
* Good Intermediate Tutorials - 4 messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/c7f81b9a51eafff8?hl=en
* Browser-based MMOG web framework - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/8f5f484fa05996fe?hl=en
* (a==b) ? 'Yes' : 'No' - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/b985d5727945d2b4?hl=en
* Developement Question? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/44ac4387b21d6c29?hl=en

==============================================================================
TOPIC: C-style static variables in Python?
http://groups.google.com/group/comp.lang.python/t/ce1a7abe2f3816b9?hl=en
==============================================================================

== 1 of 3 ==
Date: Thurs, Apr 1 2010 4:48 pm
From: Steve Holden


Terry Reedy wrote:
> On 4/1/2010 6:34 PM, kj wrote:
>>
>>
>> When coding C I have often found static local variables useful for
>> doing once-only run-time initializations. For example:
>>
>> int foo(int x, int y, int z) {
>>
>> static int first_time = TRUE;
>> static Mongo *mongo;
>> if (first_time) {
>> mongo = heavy_lifting_at_runtime();
>> first_time = FALSE;
>> }
>>
>> return frobnicate(mongo, x, y, z);
>
> Global var or class or closure such as below (obviously untested ;=):
>
> make_foo()
> mongo = heavy_lifting_at_runtime();
> def _(x,y,z):
> return frobnicate(mongo, x, y, z)
> return _
> foo = make_foo

I suspect you mean

foo = make_foo()

> del make_foo # to make sure it is *never* called again ;
>
> Now you only have foo with a hard-to-access private object and no
> first_time checks when you call it.
>
> Terry Jan Reedy
>
I don't think I'd ever want to use such an obscure technique in a
program. You might want to consider using functools.wraps to make sure
that the foo function looks right.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/

== 2 of 3 ==
Date: Thurs, Apr 1 2010 6:37 pm
From: "Alf P. Steinbach"


* kj:
> When coding C I have often found static local variables useful for
> doing once-only run-time initializations. For example:
>
> int foo(int x, int y, int z) {
>
> static int first_time = TRUE;
> static Mongo *mongo;
> if (first_time) {
> mongo = heavy_lifting_at_runtime();
> first_time = FALSE;
> }
>
> return frobnicate(mongo, x, y, z);
> }
>
> In this case, the static variable mongo is initialized only once
> (at most).
>
> What I like most about this is that it obviates the need for a
> global variable to hold the persistent value (I avoid globals like
> the plague, especially in Python). It also nicely encapsulates
> the logic that determines whether initialization is required.

In C++ you just write

int foo( int x, int y, int z )
{
static Mongo* const mongo = heavy_lifting_at_runtime();
return frobnicate( mongo, x, y, z );
}

> The best way I've found to achieve a similar effect in (procedural)
> Python defines the function as a closure. For example, here's a
> function that keeps track of (and prints out) how many times it
> has been called:
>
>>>> def make_spam():
> ... counter = [0]
> ... def _():
> ... counter[0] += 1
> ... print counter[0]
> ... return _
> ...
>>>> spam = make_spam()
>>>> spam()
> 1
>>>> spam()
> 2
>>>> spam()
> 3
>
> (Too bad that one can't stick the whole def inside parentheses and
> call the function right there, like one can do with JavaScript.)

Off the cuff, Py3:

class Spam:
def __init__( self ):
self._counter = 0

def __call__( self ):
self._counter += 1
print( counter )

spam = Spam()
spam()
spam()
spam()


[snip]
> I'm sure that there are many other ways to skin this cat, especially
> if one starts definining fancy callable classes and whatnot.

As I see it it's the closure that's fancy, and the class that's simple and direct.


> But
> is there a better *simple* way to achieve C-style static locals in
> Python that does not require a lot of extra machinery?

If you often need this functionality you might consider a general decorator that
supplies the function with a self argument, e.g. like this:


<example>
#Py3

class Object: pass

def static_initialization( init_func ):
def self_aware( f ):
def wrapped( *args, **kwargs ):
return f( f, *args, **kwargs )
init_func( f )
return wrapped
o = Object()
o.body = self_aware
return o


# Example usage:

@static_initialization
def spam( self ):
self.counter = 0

@spam.body
def spam( self ):
self.counter += 1
print( self.counter )

spam()
spam()
spam()
</example>


But as mentioned, a class is (at least IMHO) simpler and more direct.

Cheers & hth.,

- Alf (department of disingenious solutions)


== 3 of 3 ==
Date: Thurs, Apr 1 2010 8:32 pm
From: Paul Rubin


kj <no.email@please.post> writes:
> When coding C I have often found static local variables useful for
> doing once-only run-time initializations. For example:
>
> int foo(int x, int y, int z) {
> static int first_time = TRUE;
> static Mongo *mongo;
> if (first_time) { ...


Here are some cheesy ways.

1. Put an attribute onto the function name:

def foo(x, y, z):
if foo.first_time:
foo.mongo = heavy_lifting_at_runtime()
foo.first_time = False
...
foo.first_time = True

2. Use a mutable keyword parameter:

def foo(x, y, z, wrapped_mongo=[]):
if len(wrapped_mongo) == 0:
wrapped_mongo.append(heavy_lifting_at_runtime())
mongo = wrapped_mongo[0]
...

3. Streamline the first method a little:

def foo(x, y, z):
if len(foo.wrapped_mongo == 0):
foo.wrapped_mongo.append(heavy_lifting_at_runtime())
mongo = foo.wrapped_mongo[0]
...
foo.wrapped_mongo = []

All of these of course don't give as good encapsulation as one might
like.

==============================================================================
TOPIC: How to run python without python
http://groups.google.com/group/comp.lang.python/t/ceb4fa8fa68ba68e?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Apr 1 2010 4:54 pm
From: Chris Rebert


On Thu, Apr 1, 2010 at 4:46 PM, Krister Svanlund
<krister.svanlund@gmail.com> wrote:
> On Fri, Apr 2, 2010 at 1:36 AM, Spencer <Infotechsys@fairpoint.net> wrote:
>> Is there a way to developing a script on linux and give it
>> to someone on microsoft, so that they could run it on microsoft
>> without installing python?
>
> Short answer: No.

Long answer:
No indeed. But if he were to have a Windows computer, he could
generate a standalone executable from a Python program using one of
the following tools:
py2exe: http://www.py2exe.org/
PyInstaller: http://www.pyinstaller.org/

But one can't generate such a standalone executable for a different
operating system from that which one's computer runs.

Cheers,
Chris
--
http://blog.rebertia.com

==============================================================================
TOPIC: off topic but please forgive me me and answer
http://groups.google.com/group/comp.lang.python/t/0d4f564a49022b74?hl=en
==============================================================================

== 1 of 12 ==
Date: Thurs, Apr 1 2010 4:55 pm
From: David Robinow


On Thu, Apr 1, 2010 at 7:34 PM, Patrick Maupin <pmaupin@gmail.com> wrote:
> On Apr 1, 4:42 pm, Tim Chase <python.l...@tim.thechases.com> wrote:
>> superpollo wrote:
>> > how much is one half times one half?
>>
>> Uh, did you try it at the python prompt?  If not, here's the answer:
>>
>>   0.1b * 0.1b = 0.01b
>>
>> Now all you need is to find the recent thread that converts
>> binary floats to decimal floats ;-)
>>
>> -tkc
>
> I thought it was 0b0.1 * 0b0.1 == 0b0.01
>
> Otherwise, you might get it confused with hexadecimal floats :D
Well, my python says:

$ python -c "print 1/2 * 1/2"
0

But that's not what I learned in grade school.
(Maybe I should upgrade to 3.1?)


== 2 of 12 ==
Date: Thurs, Apr 1 2010 5:49 pm
From: Tim Chase


David Robinow wrote:
> $ python -c "print 1/2 * 1/2"
> 0
>
> But that's not what I learned in grade school.
> (Maybe I should upgrade to 3.1?)

That's because you need to promote one of them to a float so you
get a floating-point result:

>>> 1/2 * 1/2
0
>>> 1/2 * 1/2.0
0.0

Oh...wait ;-)

-tkc

== 3 of 12 ==
Date: Thurs, Apr 1 2010 7:01 pm
From: Patrick Maupin


On Apr 1, 7:49 pm, Tim Chase <python.l...@tim.thechases.com> wrote:
> David Robinow wrote:
> > $ python -c "print 1/2 * 1/2"
> > 0
>
> >  But that's not what I learned in grade school.
> > (Maybe I should upgrade to 3.1?)
>
> That's because you need to promote one of them to a float so you
> get a floating-point result:
>
>    >>> 1/2 * 1/2
>    0
>    >>> 1/2 * 1/2.0
>    0.0
>
> Oh...wait ;-)
>
> -tkc

Hmmm, I think I'm starting to see why we need math.fsum() to take care
of those rounding errors...


== 4 of 12 ==
Date: Thurs, Apr 1 2010 7:38 pm
From: Steven D'Aprano


On Thu, 01 Apr 2010 19:55:27 -0400, David Robinow wrote:

>>> superpollo wrote:
>>> > how much is one half times one half?
[...]
> Well, my python says:
>
> $ python -c "print 1/2 * 1/2"
> 0
>
> But that's not what I learned in grade school.
> (Maybe I should upgrade to 3.1?)

Python 2.x defaults to integer division, a design error which has been
rectified in 3.x.

One can do any of these:

[steve@sylar ~]$ python3.1 -c "print(1/2 * 1/2)"
0.25
[steve@sylar ~]$ python2.6 -c "from __future__ import division; print 1/2
* 1/2"
0.25
[steve@sylar ~]$ python2.6 -Q new -c "print 1/2 * 1/2"
0.25
[steve@sylar ~]$ python2.6 -c "print 0.5 * 0.5"
0.25


and probably many others as well.

--
Steven


== 5 of 12 ==
Date: Thurs, Apr 1 2010 7:44 pm
From: Steven D'Aprano


On Thu, 01 Apr 2010 19:49:43 -0500, Tim Chase wrote:

> David Robinow wrote:
>> $ python -c "print 1/2 * 1/2"
>> 0
>>
>> But that's not what I learned in grade school.
>> (Maybe I should upgrade to 3.1?)
>
> That's because you need to promote one of them to a float so you get a
> floating-point result:
>
> >>> 1/2 * 1/2
> 0
> >>> 1/2 * 1/2.0
> 0.0
>
> Oh...wait ;-)

Tim, I'm sure you know the answer to this, but for the benefit of the
Original Poster, the problem is that you need to promote *both* divisions
to floating point. Otherwise one of them will give int 0, which gives 0.0
when multiplied by 0.5.

>>> 1.0/2 * 1/2.0
0.25


If you want an exact result when multiplying arbitrary fractions, you
need to avoid floats and decimals and use Fractions:

>>> Fraction(1, 2)**2
Fraction(1, 4)

--
Steven


== 6 of 12 ==
Date: Thurs, Apr 1 2010 7:50 pm
From: Lie Ryan


On 04/02/10 13:01, Patrick Maupin wrote:
> On Apr 1, 7:49 pm, Tim Chase <python.l...@tim.thechases.com> wrote:
>> David Robinow wrote:
>>> $ python -c "print 1/2 * 1/2"
>>> 0
>>
>>> But that's not what I learned in grade school.
>>> (Maybe I should upgrade to 3.1?)
>>
>> That's because you need to promote one of them to a float so you
>> get a floating-point result:
>>
>> >>> 1/2 * 1/2
>> 0
>> >>> 1/2 * 1/2.0
>> 0.0
>>
>> Oh...wait ;-)
>>
>> -tkc
>
> Hmmm, I think I'm starting to see why we need math.fsum() to take care
> of those rounding errors...

hmm?

>>> import math
>>> math.fsum([1/2, 1/2])
0.0

it doesn't appear to take care of those rounding errors, not in this
case at least.


== 7 of 12 ==
Date: Thurs, Apr 1 2010 7:58 pm
From: Patrick Maupin


On Apr 1, 9:50 pm, Lie Ryan <lie.1...@gmail.com> wrote:
> On 04/02/10 13:01, Patrick Maupin wrote:
>
>
>
> > On Apr 1, 7:49 pm, Tim Chase <python.l...@tim.thechases.com> wrote:
> >> David Robinow wrote:
> >>> $ python -c "print 1/2 * 1/2"
> >>> 0
>
> >>>  But that's not what I learned in grade school.
> >>> (Maybe I should upgrade to 3.1?)
>
> >> That's because you need to promote one of them to a float so you
> >> get a floating-point result:
>
> >>    >>> 1/2 * 1/2
> >>    0
> >>    >>> 1/2 * 1/2.0
> >>    0.0
>
> >> Oh...wait ;-)
>
> >> -tkc
>
> > Hmmm, I think I'm starting to see why we need math.fsum() to take care
> > of those rounding errors...
>
> hmm?
>
> >>> import math
> >>> math.fsum([1/2, 1/2])
>
> 0.0
>
> it doesn't appear to take care of those rounding errors, not in this
> case at least.

you're right! I mis-read the problem. What we REALLY need is a good
math.fmul() ;-)


== 8 of 12 ==
Date: Thurs, Apr 1 2010 8:08 pm
From: David Robinow


On Thu, Apr 1, 2010 at 10:44 PM, Steven D'Aprano
<steve@remove-this-cybersource.com.au> wrote:
> On Thu, 01 Apr 2010 19:49:43 -0500, Tim Chase wrote:
>
>> David Robinow wrote:
>>> $ python -c "print 1/2 * 1/2"
>>> 0
>>>
>>>  But that's not what I learned in grade school.
>>> (Maybe I should upgrade to 3.1?)
>>
>> That's because you need to promote one of them to a float so you get a
>> floating-point result:
>>
>>    >>> 1/2 * 1/2
>>    0
>>    >>> 1/2 * 1/2.0
>>    0.0
>>
>> Oh...wait ;-)
>
> Tim, I'm sure you know the answer to this, but for the benefit of the
> Original Poster, the problem is that you need to promote *both* divisions
> to floating point. Otherwise one of them will give int 0, which gives 0.0
> when multiplied by 0.5.
>
>>>> 1.0/2 * 1/2.0
> 0.25
>
>
> If you want an exact result when multiplying arbitrary fractions, you
> need to avoid floats and decimals and use Fractions:
>
>>>> Fraction(1, 2)**2
> Fraction(1, 4)

I should have known he wouldn't get it.


== 9 of 12 ==
Date: Thurs, Apr 1 2010 8:34 pm
From: Tim Chase


Steven D'Aprano wrote:
>> That's because you need to promote one of them to a float so you get a
>> floating-point result:
>>
>> >>> 1/2 * 1/2
>> 0
>> >>> 1/2 * 1/2.0
>> 0.0
>>
>> Oh...wait ;-)
>
> Tim, I'm sure you know the answer to this, but for the benefit of the
> Original Poster, the problem is that you need to promote *both* divisions
> to floating point. Otherwise one of them will give int 0, which gives 0.0
> when multiplied by 0.5.
>
>>>> 1.0/2 * 1/2.0
> 0.25

You can get away with just promoting one of them...you just have
to promote the _correct_ one (one involved in the first division)
so that its promotion-of-subresult-to-float carries into all
subsequent operations/operators:

>>> 1/2 * 1/2 # (((1/2)*1)/2)==(((0)*1)/2) in 2.x
0
>>> 1/2 * 1/2.0 # (((1/2)*1)/2.0)==(((0)*1)/2.0) in 2.x
0.0
>>> 1/2 * 1.0/2 # (((1/2)*1.0)/2)==(((0)*1.0)/2) in 2.x
0.0
>>> 1/2.0 * 1/2 # (((1/2.0)*1)/2)
0.25
>>> 1.0/2 * 1/2 # (((1.0/2)*1)/2)
0.25

I'd rather be explicit in *real* code that I'd write and
explicitly float'ify constants or float() integer variables. The
OP's question was both OT and pretty basic middle-school math
that google would have nicely answered[1] so IMHO warranted a bit
of fun. :)

-tkc

[1]
http://www.google.com/search?q=1%2F2+*+1%2F2

== 10 of 12 ==
Date: Thurs, Apr 1 2010 9:52 pm
From: Dennis Lee Bieber


On Thu, 01 Apr 2010 22:44:51 +0200, superpollo <utente@esempio.net>
declaimed the following in gmane.comp.python.general:

> how much is one half times one half?

import math
print math.exp((math.log(1) - math.log(2))
+ (math.log(1) - math.log(2)))
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

== 11 of 12 ==
Date: Thurs, Apr 1 2010 10:25 pm
From: Patrick Maupin


On Apr 1, 11:52 pm, Dennis Lee Bieber <wlfr...@ix.netcom.com> wrote:
> On Thu, 01 Apr 2010 22:44:51 +0200, superpollo <ute...@esempio.net>
> declaimed the following in gmane.comp.python.general:
>
> > how much is one half times one half?
>
> import math
> print math.exp((math.log(1) - math.log(2))
>                                  + (math.log(1) - math.log(2)))

That's all well and good, but base 'e' is kind of complicated. Some
of us were using base 10, and others took Tim's lead and were using
base 2:

>>> print math.exp(((math.log(1)/math.log(2) - math.log(2)/math.log(2)) + (math.log(1)/math.log(2) - math.log(2)/math.log(2)))*math.log(2))
0.25


== 12 of 12 ==
Date: Thurs, Apr 1 2010 10:40 pm
From: Steven D'Aprano


On Thu, 01 Apr 2010 22:34:46 -0500, Tim Chase wrote:

>> Tim, I'm sure you know the answer to this, but for the benefit of the
>> Original Poster, the problem is that you need to promote *both*
>> divisions to floating point. Otherwise one of them will give int 0,
>> which gives 0.0 when multiplied by 0.5.
>>
>>>>> 1.0/2 * 1/2.0
>> 0.25
>
> You can get away with just promoting one of them...you just have to
> promote the _correct_ one

Doh!

Of course you do. I knew that!

--
Steven

==============================================================================
TOPIC: Good Intermediate Tutorials
http://groups.google.com/group/comp.lang.python/t/c7f81b9a51eafff8?hl=en
==============================================================================

== 1 of 4 ==
Date: Thurs, Apr 1 2010 5:25 pm
From: Abethebabe


I've recently finished reading A Byte Of Python and have the basics of
Python down. I want to continue practice but I'm unsure what I can do.
So I started looking for tutorials to open my mind a little, but
everything I come across are beginner tutorials that cover the same
topics...over and over.

Can anyone point me to good Intermediate tutorials, that don't make
use of libraries and such (so I can get really comfortable with the
core language.) Maybe even the source code of some simple Python
applications, so I can observe and learn the code myself.

Really appreciative of any help!


== 2 of 4 ==
Date: Thurs, Apr 1 2010 6:27 pm
From: rantingrick


On Apr 1, 7:25 pm, Abethebabe <abrahamalra...@gmail.com> wrote:
> I've recently finished reading A Byte Of Python and have the basics of
> Python down. I want to continue practice but I'm unsure what I can do.
> So I started looking for tutorials to open my mind a little, but
> everything I come across are beginner tutorials that cover the same
> topics...over and over.
>
> Can anyone point me to good Intermediate tutorials, that don't make
> use of libraries and such (so I can get really comfortable with the
> core language.) Maybe even the source code of some simple Python
> applications, so I can observe and learn the code myself.
>
> Really appreciative of any help!


Try "Dive into Python", great tut!
http://diveintopython.org/


== 3 of 4 ==
Date: Thurs, Apr 1 2010 9:06 pm
From: Lie Ryan


On 04/02/10 11:25, Abethebabe wrote:
> I've recently finished reading A Byte Of Python and have the basics of
> Python down. I want to continue practice but I'm unsure what I can do.
> So I started looking for tutorials to open my mind a little, but
> everything I come across are beginner tutorials that cover the same
> topics...over and over.

In programming, if you've gone past the beginner level, the only text
you ever need is the reference manual.

If you want to broaden your mind, you may want to learn other languages
that have distinctly different paradigms than the ones you already know.
Then when you get back to python, you will be able to see new angles to
attack a problem from.

> Can anyone point me to good Intermediate tutorials, that don't make
> use of libraries and such (so I can get really comfortable with the
> core language.) Maybe even the source code of some simple Python
> applications, so I can observe and learn the code myself.
>
> Really appreciative of any help!

Strengthen your math, specifically discrete math; many problems are just
different manifestations of a few classes of problem. You can leverage
developing completely new methods and new ideas by abstracting your
problem to find out the the class of problem your problem belongs to.
(contrived analogy: a head chef need to determine whether the remaining
ingredients will suffice for the day; a bricklayer need to determine the
number of bricks he need to buy for a span of wall; those problems has a
common solution: counting and number division).

In short, read a book about math and/or problem solving.
Recommendations: The Art of Computer Programming by D.E. Knuth,
Algorithm Design Manual by S.S. Skiena.

Frequent the mailing list. Only by then you will learn to write
"idiomatic python"; a book can be compiled about common python idioms
but they will more-or-less be the author's perspective of the idioms
instead of actual python's idioms. I found that, in python at least,
avoiding use of library often forces you to write non-idiomatic python
because many libraries are written specifically because it is difficult
to write the equivalent efficient code with idiomatic python.

In short, don't avoid the library if you want to learn idiomatic python.
(if you want to learn about the algorithms though, avoiding libraries is
a fine restriction)


== 4 of 4 ==
Date: Thurs, Apr 1 2010 9:57 pm
From: Dennis Lee Bieber


On Thu, 1 Apr 2010 17:25:14 -0700 (PDT), Abethebabe
<abrahamalrajhi@gmail.com> declaimed the following in
gmane.comp.python.general:

>
> Can anyone point me to good Intermediate tutorials, that don't make
> use of libraries and such (so I can get really comfortable with the
> core language.) Maybe even the source code of some simple Python
> applications, so I can observe and learn the code myself.
>
The reference manual for the "core language" is only some 80 pages,
last time I printed it.

If you want to see Python as coded by others -- read the source for
the standard libraries (granted, the most optimized eventually devolve
into calling compiled DLLs (Windows as PYDs)/shared object libraries (so
on Linux)).
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/


==============================================================================
TOPIC: Browser-based MMOG web framework
http://groups.google.com/group/comp.lang.python/t/8f5f484fa05996fe?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Apr 1 2010 6:14 pm
From: Steve


Hi, I could use some advice on my project.

It's a browser-based MMOG: "The High Seas" (working title)

Basically it is a trading game set in 1600s or 1700s ... inspirations:
Patrician 3, Mine Things, Space Rangers 2, ...

Travel between cities takes several days: game updates trading ship
positions every 10 minutes. Apart from that it handles player input
to buy/sell goods, if their ship is in port.

I want the game logic and world state data storage on a webserver,
with players connecting via web browser. Also, I want to make an
"admin mode" client for me to keep track of the world and add changes
to game world stuff.

I want to use Python but I haven't ever used it in a web context.

http://wiki.python.org/moin/WebFrameworks lists several different
options for Python Web Frameworks: Django, Grok, Pylons, TurboGears,
web2py, Zope. I've heard of Django and Grok...that's about my level
of knowledge here.

My question: can any of these frameworks help me with what I'm trying
to do?


== 2 of 2 ==
Date: Thurs, Apr 1 2010 7:59 pm
From: exarkun@twistedmatrix.com


On 01:14 am, srosborne@gmail.com wrote:
>Hi, I could use some advice on my project.
>
>It's a browser-based MMOG: "The High Seas" (working title)
>
>Basically it is a trading game set in 1600s or 1700s ... inspirations:
>Patrician 3, Mine Things, Space Rangers 2, ...
>
>Travel between cities takes several days: game updates trading ship
>positions every 10 minutes. Apart from that it handles player input
>to buy/sell goods, if their ship is in port.
>
>I want the game logic and world state data storage on a webserver,
>with players connecting via web browser. Also, I want to make an
>"admin mode" client for me to keep track of the world and add changes
>to game world stuff.
>
>I want to use Python but I haven't ever used it in a web context.
>
>http://wiki.python.org/moin/WebFrameworks lists several different
>options for Python Web Frameworks: Django, Grok, Pylons, TurboGears,
>web2py, Zope. I've heard of Django and Grok...that's about my level
>of knowledge here.
>
>My question: can any of these frameworks help me with what I'm trying
>to do?

This is something that Twisted and Nevow Athena will probably be really
good at doing (a lot better than the ones you've mentioned above, I
think).

You can find an Athena introduction here (at least for now, the content
might move to another site before too long):

http://divmodsphinx.funsize.net/nevow/chattutorial/

Jean-Paul

==============================================================================
TOPIC: (a==b) ? 'Yes' : 'No'
http://groups.google.com/group/comp.lang.python/t/b985d5727945d2b4?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Apr 1 2010 7:33 pm
From: Steven D'Aprano


On Thu, 01 Apr 2010 08:27:53 -0700, Den wrote about Python's ternary
operator:

> I've been following this thread for a few days now. My thoughts are
> that, in view of a long known widely used syntax for this operator,
> python's syntax seems like change for change sake. If current
> programing paradigm provides that particular trinary operator, why
> should python's be different from the previously well known one.

Yes, I agree, we should be using the previously well known syntax:

condition -> value_if_true, value_if_false

which was introduced by BCPL in 1966.


> For instance, no reasonable language designer would, now, use post-fix
> (I know about Forth)

Do you also know about Postscript, Factor, Joy and Cat, to mention only a
few? And also the native language of Hewlett-Packard scientific
calculators, RPL.

> or allow only +=, -=, /=, etc. assignments ONLY.
> (Just as no reasonable car designer would put the accelerator pedal on
> the left.) There are conventions which should span products. Yes
> python has the trinary operator and it's not going to change, but this
> seems like a bit of petulance on the part of the designer.

Unless you have read the PEP that added the operator to the language, and
the reasons for rejecting the alternatives, you are not qualified to
guess what Guido's motives for choosing the current syntax are.

http://www.python.org/dev/peps/pep-0308/

You might not like it, but I do, and I like it far more than the ugly and
hard to understand C syntax. In English (which has existed for much
longer than C) the question mark punctuation symbol is a sentence
terminator, not a separator between clauses, so using ? as an operator
has always looked strange and disturbing to me.


--
Steven


== 2 of 2 ==
Date: Thurs, Apr 1 2010 9:16 pm
From: Steve Howell


On Mar 30, 8:40 am, gentlestone <tibor.b...@hotmail.com> wrote:
> Hi, how can I write the popular C/JAVA syntax in Python?
>
> Java example:
>     return (a==b) ? 'Yes' : 'No'
>
> ; first idea is:
>     return ('No','Yes')[bool(a==b)]
>
> Is there a more elegant/common python expression for this?

The ironic thing about the ternary operator is that it is not really
ternary; it's binary. Even just making an expression from a binary
operator inevitably leads to syntax hell.

There is a principle of programming that I would like to coin, which
is the "Tyranny of Three."

It is impossible to code for any expression that has three possible
values in any kind of elegant way. It's just impossible. Try to code
the bowling game without tearing out your teeth--three conditions:
strike, spare, or normal.

The tyranny of three is that 3 is too small for an elegant N-based
solution and too large for a simple condition.


==============================================================================
TOPIC: Developement Question?
http://groups.google.com/group/comp.lang.python/t/44ac4387b21d6c29?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Apr 1 2010 11:29 pm
From: Tim Roberts


Wayne <infotechsys@fairpoint.net> wrote:
>
>My town office uses Microsoft operating system. They have a proprietary
>accounting system that uses excel for their accounting reports.
>I would like to read these report and reproduce the report so that
>the report can be seen on the web.

If it were me, I'd just have Excel print to a PDF. No conversion, no
scripting. There are a number of open source PDF converters.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate