Translating some Java to Python

Arnaud Delobelle arnodel at googlemail.com
Sun May 20 16:34:48 EDT 2007


On May 20, 9:24 pm, Daniel Gee <zef... at gmail.com> wrote:
> A while ago I wrote a class in Java for all kinds of dice rolling
> methods, as many sides as you want, as many dice as you want, only
> count values above or below some number in the total, things like
> that. Now I'm writing a project in Python that needs to be able to
> make use of that kind of a class.
>
> The Java version has static methods for common roll styles (XdY and XdY
> +Z) for classes that just want a result but don't want to bother
> keeping an object around for later.
>
> So the question is, assuming that I wanted to keep the static method
> behavior (which I'm not really sure I do), how does one format the
> method header on a 'static' method in Python? Is it just something
> like:
>
> class Foo:
>   def statAdd(self,a):
>     return a+5
>
> or do you drop the 'self' bit and just use a 1 variable parameter list?

Do you really want your dice rolling functions to be methods?  It
seems to me that you would be better off grouping them as functions in
a module rather than as methods in a class.  A java class full of
static methods translates to a python module populated with functions
in general.

--
Arnaud




More information about the Python-list mailing list