Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43843

Re: equivalent to C pointer

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 <ckaynor@zindagigames.com>
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; '&lt;': 0.19; 'thu,': 0.19; 'example': 0.22; 'email addr:gmail.com&gt;': 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 <CAF3f0sQ_rsdKwaEOCmFHEeEwpVUaNUo-pOYgoqYA_F-k0CftcA@mail.gmail.com>
References <CAF3f0sQ_rsdKwaEOCmFHEeEwpVUaNUo-pOYgoqYA_F-k0CftcA@mail.gmail.com>
From Chris Kaynor <ckaynor@zindagigames.com>
Date Thu, 18 Apr 2013 10:25:58 -0700
Subject Re: equivalent to C pointer
To "python-list@python.org" <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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.782.1366305989.3114.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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 <abelahcene@gmail.com
> 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 <stdio.h>
> #include <math.h>
>
> 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
>
>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: equivalent to C pointer Chris Kaynor <ckaynor@zindagigames.com> - 2013-04-18 10:25 -0700

csiph-web