Re: function problem

2012-01-09 Thread Chris Rebert
On Mon, Jan 9, 2012 at 7:35 PM, contro opinion wrote: > code1: > > def FirstDeco(func): >    print 'haha' >    y=func() >    return y >    print  y Since there's a `return` right before it, the latter `print` here will *never* be executed. Cheers, Chris -- http://mail.python.org/mailman/listinf

function problem

2012-01-09 Thread contro opinion
code1: def FirstDeco(func): print 'haha' y=func() return y print y @FirstDeco def test(): print 'asdf' return 7 result : haha asdf code2: def FirstDeco(func): print 'haha' y=func() #return y print y @FirstDeco def test(): print 'asdf' return 7 result : h

Re: Call CFUNCTYPE, class Structure, ctype, dll and Callback function problem

2010-07-31 Thread legard_new
On Jul 31, 10:22 pm, "Mark Tolonen" wrote: > "legard_new" wrote in message > > news:70faf0b4-fead-49ac-bf18-e182fd63b...@j8g2000yqd.googlegroups.com... > > > > > > > Hello, > > > I have a problem with calling Callback function with Python. I have a > > DLL file. > > > Below is a description in do

Re: Call CFUNCTYPE, class Structure, ctype, dll and Callback function problem

2010-07-31 Thread Mark Tolonen
"legard_new" wrote in message news:70faf0b4-fead-49ac-bf18-e182fd63b...@j8g2000yqd.googlegroups.com... Hello, I have a problem with calling Callback function with Python. I have a DLL file. Below is a description in documentation. FUNCTION Callback Arguments: Callback ID integer read-only, i

Call CFUNCTYPE, class Structure, ctype, dll and Callback function problem

2010-07-31 Thread legard_new
Hello, I have a problem with calling Callback function with Python. I have a DLL file. Below is a description in documentation. FUNCTION Callback Arguments: Callback ID integer read-only, immediate value CBackProc address read-only, immediate value

Re: time function problem

2008-11-28 Thread MRAB
willie wrote: My code: from time import time def leibniz(terms): acc = 0.0 num = 4.0 # numerator value remains constant in the series den = 1 count = 0 start_time = 0.0 for aterm in range(terms): nextterm = num/den * (-1)**aterm # (-1) allows fractions to alter

Re: time function problem

2008-11-27 Thread Steven D'Aprano
On Thu, 27 Nov 2008 11:17:04 -0800, willie wrote: > My code: > > from time import time > def leibniz(terms): > > > acc = 0.0 > num = 4.0 # numerator value remains constant in the series den = 1 > count = 0 > start_time = 0.0 This line is wrong. You're starting your timer at the

Re: time function problem

2008-11-27 Thread Diez B. Roggisch
willie wrote: > My code: > > from time import time > def leibniz(terms): > > > acc = 0.0 > num = 4.0 # numerator value remains constant in the series > den = 1 > count = 0 > start_time = 0.0 > for aterm in range(terms): > nextterm = num/den * (-1)**aterm # (-1)

time function problem

2008-11-27 Thread willie
My code: from time import time def leibniz(terms): acc = 0.0 num = 4.0 # numerator value remains constant in the series den = 1 count = 0 start_time = 0.0 for aterm in range(terms): nextterm = num/den * (-1)**aterm # (-1) allows fractions to alternate

Re: ord function problem from newbie

2008-03-17 Thread 7stud
[EMAIL PROTECTED] wrote: > I convert all to lowercase, > > import string > > small = string.lower(name) > print "Here is the calculated value:" > > print small > for ch in small: > v = ord(ch)-96 > print v > I don't know if you are using an

Re: ord function problem from newbie

2008-03-17 Thread Paul Rubin
[EMAIL PROTECTED] writes: > for ch in small: > v = ord(ch)-96 > print v total = 0 for ch in small: # the += below updates the value of total by adding (ord(ch) - 96) total += (ord(ch) - 96) print "ch:", ch, "total so far:", total -- http://mail.python

Re: ord function problem from newbie

2008-03-17 Thread Steven Clark
print sum([ord(ch)-96 for ch in small]) On Mon, Mar 17, 2008 at 11:28 PM, <[EMAIL PROTECTED]> wrote: > I'm trying to convert a name into a numerical value that is not > consistent with ANSCII values. In my case, I convert all to lowercase, > then try to sum the value of the letters entered by t

ord function problem from newbie

2008-03-17 Thread David . J . Anderson66
I'm trying to convert a name into a numerical value that is not consistent with ANSCII values. In my case, I convert all to lowercase, then try to sum the value of the letters entered by the user, can't get it to add them. Here is what I have. By the way, the values I need to use is: a=1, b=2, c=3,

Re: Using Timing function problem.....

2007-01-25 Thread Jona
Thanks so much! that did it! you can tell I'm new with python.. lol... thanks again.. Jonathan -- http://mail.python.org/mailman/listinfo/python-list

Re: Using Timing function problem.....

2007-01-24 Thread Gabriel Genellina
At Thursday 25/1/2007 01:26, kevin wrote: Hi... I'm having a few problems here... I want to input in my function different values and then time each one to see how long it took to run the function... so right now it doesn't like the "i" inside my function fibonacci(i) but if I put a constant it

Using Timing function problem.....

2007-01-24 Thread kevin
Hi... I'm having a few problems here... I want to input in my function different values and then time each one to see how long it took to run the function... so right now it doesn't like the "i" inside my function fibonacci(i) but if I put a constant it's fine any idea on how to approach this?

Re: __init__ function problem

2006-11-07 Thread Colin J. Williams
Carl Banks wrote: > kelin,[EMAIL PROTECTED] wrote: >> It says the __init__ is called immediately after an instance of the >> class is created. What dose "immediately" mean? >> And what is difference between the init method and the constructor in >> Java? > > For all intents and purposes, __init__

Re: __init__ function problem

2006-11-07 Thread kelin,[EMAIL PROTECTED]
Hi, I've read all of this. And I am clear about it. Thanks all. Best Regards! Gabriel Genellina wrote: > At Tuesday 7/11/2006 21:47, Jia Lu wrote: > > > > In Python, the real constructor is called __new__, > > > > Carl Banks > > > >But the code below won't invoke __new__: > > Is this a question, o

Re: __init__ function problem

2006-11-07 Thread Gabriel Genellina
At Tuesday 7/11/2006 21:47, Jia Lu wrote: > In Python, the real constructor is called __new__, > > Carl Banks But the code below won't invoke __new__: Is this a question, or just for making things more and more confusing to beginners? class Test: def __new__(self, value): prin

Re: __init__ function problem

2006-11-07 Thread Jia Lu
> In Python, the real constructor is called __new__, > > Carl Banks But the code below won't invoke __new__: [CODE] class Test: def __new__(self, value): print "__new__",value def __init__(self,value): print "__init__",value x = Test("testing") [/CODE] -- http://mail.p

Re: __init__ function problem

2006-11-07 Thread Carl Banks
kelin,[EMAIL PROTECTED] wrote: > It says the __init__ is called immediately after an instance of the > class is created. What dose "immediately" mean? > And what is difference between the init method and the constructor in > Java? For all intents and purposes, __init__ is a constructor. It isn't

Re: __init__ function problem

2006-11-07 Thread babui
Steven D'Aprano ha escrit: > Once the __new__ method creates the instance and returns, before anything > else happens, the instance's __init__ method is called. This only happens when the object created by __new__ isinstance of the class invoked in the creation statement, that is: s=MagicStr("l

Re: __init__ function problem

2006-11-07 Thread Steven D'Aprano
On Tue, 07 Nov 2006 05:26:07 -0800, kelin,[EMAIL PROTECTED] wrote: > Hi, > > Today I read the following sentences, but I can not understand what > does the __init__ method of a class do? Play around with this class and see if it helps: class MagicStr(str): """Subclass of str with leadi

Re: __init__ function problem

2006-11-07 Thread Duncan Booth
"kelin,[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Today I read the following sentences, but I can not understand what > does the __init__ method of a class do? > __init__ is called immediately after an instance of the class is > created. It would be tempting but incorrect to call this the > c

__init__ function problem

2006-11-07 Thread kelin,[EMAIL PROTECTED]
Hi, Today I read the following sentences, but I can not understand what does the __init__ method of a class do? __init__ is called immediately after an instance of the class is created. It would be tempting but incorrect to call this the constructor of the class. It's tempting, because it looks li

Re: append function problem?

2006-04-28 Thread bruno at modulix
[EMAIL PROTECTED] wrote: > hello, recently i tried to use list.append() function in seemingly > logical ways, What seems logical and how it really works may not be the same... As a general rule, for builtin types, destructive methods returns None. I personnaly find it a wart, but what, it's the B

Re: append function problem?

2006-04-27 Thread *binarystar*
# Try This seed = [2, 3, 4, 5] next = [7] seed1 = seed + next [EMAIL PROTECTED] wrote: > hello, recently i tried to use list.append() function in seemingly > logical ways, however, i cannot get it to work, here is the test code: > seed = [2, 3, 4, 5] next = 7 seed1 = seed.append(

Re: append function problem?

2006-04-27 Thread vbgunz
seed = [1,2,3] seed.append(4) print seed # [1,2,3,4] many of the list methods are in place methods on a mutable object. In other words, doing the following results in None. seed = [1,2,3] seed = seed.append(4) print seed # None you also just wiped out your list... The append method like many o

Re: append function problem?

2006-04-27 Thread John Machin
On 28/04/2006 1:49 PM, [EMAIL PROTECTED] wrote: > hello, recently i tried to use list.append() function in seemingly > logical ways, however, i cannot get it to work, here is the test code: > seed = [2, 3, 4, 5] next = 7 seed1 = seed.append(next) seed1 print(str(seed1)) >

Re: append function problem?

2006-04-27 Thread Murali
A typo here? seed v/s seed1. Instead of "print(seed.append(5))", try "seed.append(5)" followed by "print seed" -- "print(seed)" also works. The append method does not return the appended value (like many C functions). - Murali -- http://mail.python.org/mailman/listinfo/python-list

append function problem?

2006-04-27 Thread randomtalk
hello, recently i tried to use list.append() function in seemingly logical ways, however, i cannot get it to work, here is the test code: >>> seed = [2, 3, 4, 5] >>> next = 7 >>> seed1 = seed.append(next) >>> seed1 >>> print(str(seed1)) None >>> def test(lst): ... print(str(lst)) ... >>> test(

Re: round function problem

2005-09-06 Thread Bengt Richter
On Tue, 06 Sep 2005 09:27:48 +0200, mg <[EMAIL PROTECTED]> wrote: >Hi everybody... > >We try to white scripts with Pyrhon 2.4 for an acoustic simulation and >we wrote these follow lines : > > >c = 340 340 is an integer, which is different from 340. >i =j=k= 1 >sum_ = 23 also an integer >table = [

Re: round function problem

2005-09-06 Thread Magnus Lycka
mg wrote: > The problem is simple. The function 'round' allow to obtain the value > with the specified number of digits after the ",". Then, when the > variable 'freq' is printed, there is no problem; but when freq is set in > the table and the table printed, all the digits are come back. > > I

Re: round function problem

2005-09-06 Thread Gregory Bond
mg wrote: > Is it a bug or a control behavour ? I don't understand ?!?!?!?!... It's a case of applying different float-to-text rounding in different situations, on a variable that (even after round()) is not representable in binary floatingpoint. "print var" does one sort of string conversion

Re: round function problem

2005-09-06 Thread Fredrik Lundh
"mg" wrote: > We try to white scripts with Pyrhon 2.4 for an acoustic simulation and > we wrote these follow lines : > > > c = 340 > i =j=k= 1 > sum_ = 23 > table = [] > freq = round((c/2*(sum_)**0.5),2) > print freq > table.append([freq,(i,j,k)]) > print i,j,k,' freq',freq > for item in table: p

round function problem

2005-09-06 Thread mg
Hi everybody... We try to white scripts with Pyrhon 2.4 for an acoustic simulation and we wrote these follow lines : c = 340 i =j=k= 1 sum_ = 23 table = [] freq = round((c/2*(sum_)**0.5),2) print freq table.append([freq,(i,j,k)]) print i,j,k,' freq',freq for item in table: print item The prob

Re: class-call a function in a function -problem

2005-08-16 Thread Bengt Richter
On Tue, 16 Aug 2005 18:46:30 +0200, "wierus" <[EMAIL PROTECTED]> wrote: >Hello, i have a problem. I write my first class in python so i'm not a >experience user. I want to call a function in another function, i tried to >do it in many ways, but i always failed:( >I supposed it's sth very simple b

Re: class-call a function in a function -problem

2005-08-16 Thread Elmo Mäntynen
On Tue, 16 Aug 2005 18:45:51 +0200, wierus wrote: > Hello, i have a problem. I write my first class in python so i'm not a > experience user. I want to call a function in another function, i tried to > do it in many ways, but i always failed:( > I supposed it's sth very simple but i can't figu

Re: class-call a function in a function -problem

2005-08-16 Thread Steven Bethard
Larry Bates wrote: > def __init__(self, x=1, y=2) [snip] > self.x=x > self.y=y > self.a=0 > return > > def l(self): [snip] > self.a=self.x+self.y > print "In ludzik.l a=',self.a > return > > def ala(self): [snip] > self.l

Re: class-call a function in a function -problem

2005-08-16 Thread Steven Bethard
wierus wrote: > class ludzik: > x=1 > y=2 > l=0 > def l(self): > ludzik.l=ludzik.x+ludzik.y > print ludzik.l > > def ala(self): > print ludzik.x > print ludzik.y > ludzik.l() Methods defined in a class expect an instance of that class as the first argument. When you write: l

Re: class-call a function in a function -problem

2005-08-16 Thread Larry Bates
Try something like: class ludzik: # # Define an __init__ method that gets called when # you instantiate the class. Notice also that I've # allowed you to set x, and y parameters if you like. # If you don't pass them they default to 1 and 2 as # in your example. #

class-call a function in a function -problem

2005-08-16 Thread wierus
Hello, i have a problem. I write my first class in python so i'm not a experience user. I want to call a function in another function, i tried to do it in many ways, but i always failed:( I supposed it's sth very simple but i can't figure what it is: == class lud

class-call a function in a function -problem

2005-08-16 Thread wierus
Hello, i have a problem. I write my first class in python so i'm not a experience user. I want to call a function in another function, i tried to do it in many ways, but i always failed:( I supposed it's sth very simple but i can't figure what it is: == class ludzik