Path: csiph.com!usenet.pasdenom.info!news.etla.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.002 X-Spam-Evidence: '*H*': 1.00; '*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; 'cheers': 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; 'task': 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; 'does': 0.39; '\xa0\xa0\xa0': 0.39; 'sure': 0.39; 'skip:u 10': 0.60; 'save': 0.62; 'to:addr:gmail.com': 0.65; 'power': 0.76; 'lot,': 0.93; '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=X6ZPzMrScmkgSMJoAvXv9fp6xq30owL62f+m2mda54Y=; b=vNmmj+GF6yaexYZjGeMBgSWJiDz5vduIgeIZDcJZ1gCeXX8oiGYExZWRiWD6Vrem1x GxWhAvVUS2Rh2lRI2Klrwn7TV1dyqXDyFc/CURpyWd1Yz+xcPxv9fGX3mO5K5ffS7U4z JqOB+GCvb9qdE3umkNdWm5xOARPCB2Up9qEYgHjaXq4Rh3dS9QlqKdjbLjJgB0RCSXMh MTvTw4XEcceWoZuMPcmRaa75FA/K/nCadodiC/D8asg8Tc5HTRbYapNKGUMGNjRaEXjc ab0lNij93g4lT6/X9QY3LPweYqaJfQodt+AL6Epd+nOqwVHkwIIgKDT2o0uyg5yL7e8k FgGg== MIME-Version: 1.0 X-Received: by 10.60.19.101 with SMTP id d5mr6025211oee.115.1366314898878; Thu, 18 Apr 2013 12:54:58 -0700 (PDT) In-Reply-To: References: <51702AB6.30609@gmail.com> Date: Thu, 18 Apr 2013 20:54:58 +0100 Subject: Re: equivalent to C pointer From: abdelkader belahcene To: David Robinow Content-Type: multipart/alternative; boundary=e89a8fb1ff1833453d04daa7fa95 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: 110 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366314902 news.xs4all.nl 2187 [2001:888:2000:d::a6]:60022 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43857 --e89a8fb1ff1833453d04daa7fa95 Content-Type: text/plain; charset=ISO-8859-1 Thanks a lot, I think this does the task cheers On Thu, Apr 18, 2013 at 7:14 PM, David Robinow wrote: > On Thu, Apr 18, 2013 at 1:50 PM, abdelkader belahcene < > abelahcene@gmail.com> 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 > ### > > --e89a8fb1ff1833453d04daa7fa95 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thanks a lot, I think this does the task

cheers


On Thu, Apr 18, 2013 at 7:14 PM, David Robinow <drobinow@gmail.com> wrote:
On Thu, Apr 18, 2013 at 1:50 PM, abdelkader belahcene &l= t;abelahcene@gmai= l.com> wrote:
Thanks for answer,=A0
but with C= =A0 we can compile the trapeze function and put it in librairy,=A0
If we try to save the trapeze alone in=A0 package to import it later,=A0 = I think, I am not sure
it will be refused because F1 and sin are not define !!!=A0=A0=A0=A0 = this is the power of the C pointers !!!
the link is dynamic
You don't need C pointers.=A0 The des= ign below is demonstrative, not ideal.

# file=A0 MyFuncs.py

def F1(x):
=A0=A0=A0 retur= n x*x

def Trapeze(f, left, right, step):
=A0=A0=A0 X0 =3D left=A0=A0=A0 Z =3D 0.0
=A0=A0=A0 while (X0 < right):
=A0=A0=A0=A0=A0=A0=A0 X1 =3D X0 + step
=A0=A0=A0=A0=A0=A0=A0 Y1 =3D f(X1)
=A0=A0=A0=A0=A0=A0=A0 Y0 =3D f(= X0)

=A0=A0=A0=A0=A0=A0=A0 Z +=3D (Y1 + Y0) * step * 0.5
=A0=A0=A0=A0=A0=A0=A0 X0 =3D X1
=A0=A0=A0 return Z



# file UseMyFuncs.py
import math
import MyFuncs

def main()= :
=A0=A0=A0 y =3D MyFuncs.Trapeze(math.sin, -2.5, 3.2, 0.1)

=A0=A0=A0 print("Value for sin is:{0} ".format(y))
=A0=A0=A0 y =3D MyFuncs.Trapeze(MyFuncs.F1, 0, 3, 0.1)
=A0=A0=A0 print("Value for F1 is {0} ".format(y))

if __na= me__ =3D=3D "__main__":
=A0=A0=A0 main()

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


--e89a8fb1ff1833453d04daa7fa95--