Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.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.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'everybody,': 0.07; '#include': 0.09; 'pointers': 0.09; 'received:209.85.219': 0.09; 'python': 0.11; '/**': 0.16; '0.1);': 0.16; '0.5;': 0.16; 'left,': 0.16; 'x1,': 0.16; 'y1,': 0.16; '<': 0.19; 'example': 0.22; 'compilation': 0.24; 'pointer': 0.24; 'defined': 0.27; 'function': 0.29; 'message-id:@mail.gmail.com': 0.30; 'received:209.85': 0.35; 'knows': 0.35; 'received:google.com': 0.35; 'method': 0.36; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'too': 0.37; 'received:209': 0.37; 'step': 0.37; 'skip:& 10': 0.38; 'to:addr :python-list': 0.38; '\xa0\xa0\xa0': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'new': 0.61; 'here': 0.66; 'use\xa0': 0.84; 'discovering': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=B6PR7Tz0YyNaOsiKjdG6by2oMFJLvf9ujBz3d9Mij6w=; b=ozD2iYuzvlU47p/bWo3zlL1HMkubgwVXx9tvb/OuG0rP0FFUwCfEweiDaSHj2w0H1A yuIaYYvvoqt7nZBxbdMqv7BYRHb2VQ64qfAJh38d0oY9tqUs6eT9msb3jAZ6l0rwelSs P29BcZAz/MW535eQIFs4mqZ1m4agGST6+eVqsOjq+EZfYinuBqcgULE8/T5HKk2yzug8 qrSFdykunUOwGyONx6stlRsjoHN/G5Z6F3+Dc39Kozvse7OmcC5UtIQXTEULYBKIYtdy jROxLbsYuHXW61/+G78vwEHFN9FLZ2IjMvIWJ4at0sE4rLDYOT+P+GPDBA+DtNiSPBml Gadg== MIME-Version: 1.0 X-Received: by 10.60.83.70 with SMTP id o6mr944583oey.81.1366304765504; Thu, 18 Apr 2013 10:06:05 -0700 (PDT) Date: Thu, 18 Apr 2013 18:06:05 +0100 Subject: equivalent to C pointer From: abdelkader belahcene To: python-list@python.org Content-Type: multipart/mixed; boundary=089e01176ceb34402804daa59e0c 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: 102 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366304774 news.xs4all.nl 2265 [2001:888:2000:d::a6]:50164 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43841 --089e01176ceb34402804daa59e0c Content-Type: multipart/alternative; boundary=089e01176ceb34402604daa59e0a --089e01176ceb34402604daa59e0a Content-Type: text/plain; charset=ISO-8859-1 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 --089e01176ceb34402604daa59e0a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
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
--089e01176ceb34402604daa59e0a-- --089e01176ceb34402804daa59e0c Content-Type: text/x-csrc; charset=US-ASCII; name="trapeze.c" Content-Disposition: attachment; filename="trapeze.c" Content-Transfer-Encoding: base64 X-Attachment-Id: f_hfoasxqr0 I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CiAKZG91YmxlIEYxIChkb3VibGUg eCl7IAoJCXJldHVybiB4Kng7IAp9CmRvdWJsZSBUcmFwZXplKGRvdWJsZSBGb25jKGRvdWJsZSAp LCAKCQkJCQkJCQlkb3VibGUgbGVmdCwgZG91YmxlIHJpZ2h0LCBkb3VibGUgc3RlcCl7CiAgZG91 YmxlIFgxLCBYMCwgWTAsIFkxLCBaID0gMDsgICAgCiAgZm9yKFgwPWxlZnQ7IFgwIDwgcmlnaHQg OyBYMCA9IFgwICsgc3RlcCkgewogICAgWDEgPSBYMCArIHN0ZXA7CiAgICBZMSA9IEZvbmMoWDEp OyAgICBZMCA9IEZvbmMoWDApOwogICAgWiAgKz0gKFkxICsgWTApICogc3RlcCAqIDAuNTsKICB9 CiAgIHJldHVybiBaOwp9CmludCAgbWFpbigpeyAKICBkb3VibGUgeTsKICB5PVRyYXBlemUoc2lu LCAtMi41LCAzLjIsIDAuMSk7CiAgcHJpbnRmKCJcblx0VmFsdWUgZm9yIHNpbiAgaXMgOiBcdCAl OC4zbGYgIiwgeSk7CiAgeT1UcmFwZXplKEYxLCAwLCAzLCAwLjEpOwogIHByaW50ZigiXG5cdFZh bHVlIGZvciBGMSBpcyA6IFx0ICU4LjNsZiAiLCB5KTsKICByZXR1cm4gMDsKfSAKLyoqCglWYWx1 ZSBmb3Igc2luICBpcyA6IAkgICAgMC4xOTcgCglWYWx1ZSBmb3IgRjEgaXMgOiAJICAgICA5LjAw NQoJKi8K --089e01176ceb34402804daa59e0c--