Class Methods help

2009-05-31 Thread bdsatish
Hi, I have a question regarding the difference b/w "class methods" and "object methods". Consider for example: class MyClass: x = 10 Now I can access MyClass.x -- I want a similar thing for functions. I tried class MyClass: def some_func(x): return x+2 When I call MyClass

restructured text in python

2008-04-24 Thread bdsatish
Hi all, I have a python prog: #!/usr/bin/env """ Author: BDS Version: 1.0 """ def Hello(): """ Prints a Hello World to the screen""" print "Hello, World" if __name__ == "__main__": Hello() I want to use ReSt (reStructuredText) in my docstrings or comments. Any example of how

Re: Java or C++?

2008-04-14 Thread bdsatish
On Apr 14, 12:21 pm, Bob Martin <[EMAIL PROTECTED]> wrote: > in 342367 20080414 074410 [EMAIL PROTECTED] wrote: > > >Hello, I was hoping to get some opinions on a subject. I've been > >programming Python for almost two years now. Recently I learned Perl, > >but frankly I'm not very comfortable with

Re: Rounding a number to nearest even

2008-04-11 Thread bdsatish
On Apr 11, 5:33 pm, bdsatish <[EMAIL PROTECTED]> wrote: > HI Gerard, > > I think you've taken it to the best possible implementation. Thanks ! > On Apr 11, 5:14 pm, Gerard Flanagan <[EMAIL PROTECTED]> wrote: > > > In fact you c

Re: Rounding a number to nearest even

2008-04-11 Thread bdsatish
HI Gerard, I think you've taken it to the best possible implementation. Thanks ! On Apr 11, 5:14 pm, Gerard Flanagan <[EMAIL PROTECTED]> wrote: > In fact you can avoid the call to the builtin round: > > > def myround(x): > n = int(x) > if ab

Re: Rounding a number to nearest even

2008-04-11 Thread bdsatish
On Apr 11, 4:37 pm, Scott David Daniels <[EMAIL PROTECTED]> wrote: > bdsatish wrote: > > The built-in function round( ) will always "round up", that is 1.5 is > def rounded(v): > rounded = round(v) > if divmod(v, 1)[1] == .5 and divmod(round

Re: Rounding a number to nearest even

2008-04-11 Thread bdsatish
On Apr 11, 4:24 pm, [EMAIL PROTECTED] wrote: > On Apr 11, 1:19 pm, [EMAIL PROTECTED] wrote: > > > couldn't you just do. > > > #untested > > new_round(n): > > answer = round(n) > > # is answer now odd > > if answer % 2: > > return answer - 1 > > else: > > return answer > > Whoops, th

Re: Rounding a number to nearest even

2008-04-11 Thread bdsatish
On Apr 11, 4:19 pm, [EMAIL PROTECTED] wrote: > couldn't you just do. > > #untested > new_round(n): > answer = round(n) > # is answer now odd > if answer % 2: > return answer - 1 > else: > return answer It fails for negative numbers: For -2.5 it gives -4.0 as answer whereas I expect

Re: Rounding a number to nearest even

2008-04-11 Thread bdsatish
On Apr 11, 3:27 pm, [EMAIL PROTECTED] wrote: > On 11 avr, 12:14, bdsatish <[EMAIL PROTECTED]> wrote: > > > The built-in function round( ) will always "round up", that is 1.5 is > > rounded to 2.0 and 2.5 is rounded to 3.0. > > > If I want to round to t

Rounding a number to nearest even

2008-04-11 Thread bdsatish
The built-in function round( ) will always "round up", that is 1.5 is rounded to 2.0 and 2.5 is rounded to 3.0. If I want to round to the nearest even, that is my_round(1.5) = 2# As expected my_round(2.5) = 2# Not 3, which is an odd num I'm interested in rounding numbers of the f

Integer dicision

2008-04-10 Thread bdsatish
How does (a/b) work when both 'a' and 'b' are pure integers ? >> (9/2) 4 >> (-9/2) -5 Why is it -5 ? I expect it to be -4 ? Because, in C/C++, 9/2 is 4 and so negative of it, (-9/2) is -4. What should I do to get C-like behavior ? -- http://mail.python.org/mailman/listinfo/python-list