Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'everybody,': 0.07; '#include': 0.09; 'objects,': 0.09; 'pointers': 0.09; 'python': 0.11; 'def': 0.12; '/**': 0.16; '0.1)': 0.16; '0.1);': 0.16; '0.5;': 0.16; 'left,': 0.16; 'main():': 0.16; 'pointers,': 0.16; 'x1,': 0.16; 'y1,': 0.16; 'wrote:': 0.18; '<': 0.19; 'thu,': 0.19; 'example': 0.22; 'email addr:gmail.com>': 0.22; 'to:name :python-list@python.org': 0.22; 'compilation': 0.24; 'pointer': 0.24; 'defined': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'url:python': 0.33; 'received:209.85': 0.35; 'knows': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'method': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'too': 0.37; 'received:209': 0.37; 'step': 0.37; 'skip:& 10': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; '\xa0\xa0\xa0': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'url:mail': 0.40; 'how': 0.40; 'new': 0.61; 'here': 0.66; 'object:': 0.84; 'use\xa0': 0.84; 'discovering': 0.91; '2013': 0.98 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type:x-gm-message-state; bh=hVtdrzvdGNtD6nZCSrfC33kaX9goYB96pNWgRFdd+I8=; b=Z7vuoBosfCaTkG2eLFOXfnRFYGq7rN4KRx/1mC7SB40TwzDkIOfCm264dC62ZAsiJE vEjePeVZu9ohUbYBQfCYFm0/R/2M1DIXJJ0C69IczrCpFsR81Vgp92t/weugY24FC1tb 4k4mNyCMb6N6mQJZd8fNnqqDyo2f9HrfRRI26p3Gcn8M3Vvaoq9qA3sI9YmKHikYZ0vr H0kIaVgpkEUYVn4/mauBXbsZ4YAnmeDczPWXTVS8obGit/PmpbWAntW/1JJ1DgT7e1xj rvrlqepgiQOu+p9ESU9bSKDhylNIzD+ayWq5uYPJgeMiZoGRL3DbzBqIw4CR4FKehN2a q7wg== X-Received: by 10.49.41.34 with SMTP id c2mr12451857qel.16.1366305979916; Thu, 18 Apr 2013 10:26:19 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Chris Kaynor Date: Thu, 18 Apr 2013 10:25:58 -0700 Subject: Re: equivalent to C pointer To: "python-list@python.org" Content-Type: multipart/alternative; boundary=047d7bdca7c29685b304daa5e65a X-Gm-Message-State: ALoCoQk0Que5XjW+Zovp59HK2/q7MAAJA+PIU1h1lOTMp09Et08ohCKe7kK1d4RL7++upWrhLScN 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: 143 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366305989 news.xs4all.nl 2214 [2001:888:2000:d::a6]:35264 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43843 --047d7bdca7c29685b304daa5e65a Content-Type: text/plain; charset=ISO-8859-1 While Python does not have pointers, Python functions are objects, and they may be passed like any other object: def F1(x): return x * x def Trapeze(Fonc, left, right, step): ...code... Y1 = Fonc(X1) ...code... def main(): ...code... y = Trapeze(F1, -2.5, 3.2, 0.1) ...code... Chris On Thu, Apr 18, 2013 at 10:06 AM, abdelkader belahcene wrote: > Hi everybody, > > I am new to python and I am discovering it. > I know C well, > and want to know if python knows how to manage Pointers > like pointer to function here is a C example how to write it in python > Intergration with trapeze method > > When we write Trapeze ( at the compilation level) we don't know which > functions > Fonc to handle. Here for example we use sin and a user defined F1 > The program is attached too > > #include > #include > > double F1 (double x){ > return x*x; > } > double Trapeze(double Fonc(double ), > double left, double right, double step){ > double X1, X0, Y0, Y1, Z = 0; > for(X0=left; X0 < right ; X0 = X0 + step) { > X1 = X0 + step; > Y1 = Fonc(X1); Y0 = Fonc(X0); > Z += (Y1 + Y0) * step * 0.5; > } > return Z; > } > int main(){ > double y; > y=Trapeze(sin, -2.5, 3.2, 0.1); > printf("\n\tValue for sin is : \t %8.3lf ", y); > y=Trapeze(F1, 0, 3, 0.1); > printf("\n\tValue for F1 is : \t %8.3lf ", y); > return 0; > } > /** > Value for sin is : 0.197 > Value for F1 is : 9.005 > */ > thanks a lot > > -- > http://mail.python.org/mailman/listinfo/python-list > > --047d7bdca7c29685b304daa5e65a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
While Python does not have pointers, Python functions are = objects, and they may be passed like any other object:

d= ef F1(x):
=A0 =A0 return x * x

def Trapeze(Fonc, left, right, step):
=A0 =A0 ...code...
=A0 =A0 Y1 =3D Fonc(X1)
=A0 =A0 ...code...

def main():
=A0 =A0...co= de...
=A0 =A0y =3D Trapeze(F1, -2.5, 3.2, 0.1)
=A0 =A0...code...<= /div>


Chris


On Thu, Apr 18, 2013 at 10:06 AM, abdelk= ader belahcene <abelahcene@gmail.com> wrote:
Hi everybody,=A0
I am new to python=A0 and I am discovering it.
I know C we= ll,
and want to know if python knows how to manage Pointers
like pointer to function=A0 here is a C example how to write it in python
Intergration with trapeze method

When = we write Trapeze =A0 ( at the compilation level) we don't know which fu= nctions
Fonc=A0 to handle.=A0=A0=A0=A0=A0 Here for example we use=A0 sin and = a user defined=A0 F1
The program is attached too

=
#include <stdio.h>
#includ= e <math.h>
=A0
double F1 (double x){
=A0=A0=A0 =A0=A0=A0 return x*x;
}
d= ouble Trapeze(double Fonc(double ),
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0= =A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 double left, double right, d= ouble step){
=A0 double X1, X0, Y0, Y1, Z =3D 0;=A0=A0=A0
=A0 for(X0= =3Dleft; X0 < right ; X0 =3D X0 + step) {
=A0=A0=A0 X1 =3D X0 + step;
=A0=A0=A0 Y1 =3D Fonc(X1);=A0=A0=A0 Y0 =3D F= onc(X0);
=A0=A0=A0 Z=A0 +=3D (Y1 + Y0) * step * 0.5;
=A0 }
=A0=A0 = return Z;
}
int=A0 main(){
=A0 double y;
=A0 y=3DTrapeze(sin, = -2.5, 3.2, 0.1);
=A0 printf("\n\tValue for sin=A0 is : \t %8.3lf &q= uot;, y);
=A0 y=3DTrapeze(F1, 0, 3, 0.1);
=A0 printf("\n\tValue for F1 is : \= t %8.3lf ", y);
=A0 return 0;
}
/**
=A0=A0=A0 Value for s= in=A0 is : =A0=A0=A0 =A0=A0=A0 0.197
=A0=A0=A0 Value for F1 is : =A0=A0= =A0 =A0=A0=A0=A0 9.005
=A0=A0=A0 */
thanks a lot

--
http://mail.python.org/mailman/listinfo/python-list


--047d7bdca7c29685b304daa5e65a--