Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'think,': 0.07; '"__main__":': 0.09; '__name__': 0.09; 'main()': 0.09; 'pointers': 0.09; 'received:209.85.219': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; '###': 0.16; '0.1)': 0.16; 'ideal.': 0.16; 'left,': 0.16; 'main():': 0.16; 'pointers.': 0.16; '{0}': 0.16; 'wrote:': 0.18; '<': 0.19; 'thu,': 0.19; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'math': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'define': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'message- id:@mail.gmail.com': 0.30; 'file': 0.32; 'alone': 0.33; 'received:209.85': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; 'received:209': 0.37; 'step': 0.37; 'skip:& 10': 0.38; 'pm,': 0.38; 'skip:& 20': 0.39; 'sure': 0.39; 'skip:u 10': 0.60; 'skip:\xc2 10': 0.60; 'save': 0.62; 'to:addr:gmail.com': 0.65; '8bit%:100': 0.72; 'power': 0.76; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=5YXc2uT3i1u2XamfsOxZpaifFWEWhFAeCB2x0H0oW38=; b=Oyu3Y+Q9Bz/QYWXGqcJIJDMSkxyWtCkS4mE3UZ1+eoTRMRpjcqJa4k4h2HeHneZV+v AMGIz2GhmuznFKfp2OkjrkaX4+nIjRxKI69NcqrofBfQyaFJGcq7RsMIyfNqPsFDVrUr ol5JZoXvM9TuRCTvqyQy7jneoOeHRxANy8sEcA+N+OQxnR0mdyMZC6HWPbM7XjLtTpu3 Su7WLby7AAuniTZL/G8fYk3XU8Lm69BzabcvgmeOyzGusKCBunmRrKLHn9Alb4gjxLQl rraGRcYjRGBrUOb89BSgNA353CB1XPCuHcasvq4ObOwmkWFVw+L9B6SJ+Qc8CmS37cUj Yu0w== MIME-Version: 1.0 X-Received: by 10.182.96.135 with SMTP id ds7mr5010693obb.45.1366308892921; Thu, 18 Apr 2013 11:14:52 -0700 (PDT) In-Reply-To: References: <51702AB6.30609@gmail.com> Date: Thu, 18 Apr 2013 14:14:52 -0400 Subject: Re: equivalent to C pointer From: David Robinow To: abdelkader belahcene Content-Type: multipart/alternative; boundary=047d7b2e4d5e38f0ea04daa69451 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 86 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366308903 news.xs4all.nl 2223 [2001:888:2000:d::a6]:34693 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43849 --047d7b2e4d5e38f0ea04daa69451 Content-Type: text/plain; charset=UTF-8 On Thu, Apr 18, 2013 at 1:50 PM, abdelkader belahcene wrote: > Thanks for answer, > but with C we can compile the trapeze function and put it in librairy, > If we try to save the trapeze alone in package to import it later, I > think, I am not sure > it will be refused because F1 and sin are not define !!! this is the > power of the C pointers !!! > the link is dynamic > You don't need C pointers. The design below is demonstrative, not ideal. # file MyFuncs.py def F1(x): return x*x def Trapeze(f, left, right, step): X0 = left Z = 0.0 while (X0 < right): X1 = X0 + step Y1 = f(X1) Y0 = f(X0) Z += (Y1 + Y0) * step * 0.5 X0 = X1 return Z # file UseMyFuncs.py import math import MyFuncs def main(): y = MyFuncs.Trapeze(math.sin, -2.5, 3.2, 0.1) print("Value for sin is:{0} ".format(y)) y = MyFuncs.Trapeze(MyFuncs.F1, 0, 3, 0.1) print("Value for F1 is {0} ".format(y)) if __name__ == "__main__": main() ### #python3 UseMyFuncs.py ### --047d7b2e4d5e38f0ea04daa69451 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Thu, Apr 18, 2013 at 1:50 PM, abdelkader bela= hcene <abelahcene@gmail.com> wrote:
Thanks for answer,=C2=A0
but with = C=C2=A0 we can compile the trapeze function and put it in librairy,=C2=A0 <= br>
If we try to save the trapeze alone in=C2=A0 package to import it = later,=C2=A0 I think, I am not sure
it will be refused because F1 and sin are not define !!!=C2=A0=C2=A0= =C2=A0=C2=A0 this is the power of the C pointers !!!
the link is d= ynamic
You don't need C pointers.=C2= =A0 The design below is demonstrative, not ideal.

# file=C2=A0 MyFuncs.py
def F1(x):
=C2=A0=C2=A0=C2=A0 return x*x<= br>
def Trapeze(f, left, right, step):
=C2=A0=C2=A0=C2=A0 X0 =3D left=
=C2=A0=C2=A0=C2=A0 Z =3D 0.0
=C2=A0=C2=A0=C2=A0 while (X0 < right= ):
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 X1 =3D X0 + step
=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Y1 =3D f(X1)
=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 Y0 =3D f(X0)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Z +=3D (Y1 + Y0) * step * 0.5=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 X0 =3D X1
=C2=A0=C2=A0=C2=A0= return Z



# file UseMyFuncs.py
import math
import MyFu= ncs

def main():
=C2=A0=C2=A0=C2=A0 y =3D MyFuncs.Trapeze(math.sin= , -2.5, 3.2, 0.1)
=C2=A0=C2=A0=C2=A0 print("Value for sin is:{0} &q= uot;.format(y))
=C2=A0=C2=A0=C2=A0 y =3D MyFuncs.Trapeze(MyFuncs.F1, 0, 3, 0.1)
=C2=A0= =C2=A0=C2=A0 print("Value for F1 is {0} ".format(y))

if __= name__ =3D=3D "__main__":
=C2=A0=C2=A0=C2=A0 main()

###=
#python3 UseMyFuncs.py
###

--047d7b2e4d5e38f0ea04daa69451--