Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43857
| References | <CAF3f0sQ_rsdKwaEOCmFHEeEwpVUaNUo-pOYgoqYA_F-k0CftcA@mail.gmail.com> <51702AB6.30609@gmail.com> <CAF3f0sTgxWupYqKDdtqqaPBz2kCZ04404rtDBnsOkDLXAfbQpQ@mail.gmail.com> <CAF3Xjby+U2Q6XTVRk+iSW_6xCdyJuabgrWrxZ5+7wDAWqGvR8A@mail.gmail.com> |
|---|---|
| Date | 2013-04-18 20:54 +0100 |
| Subject | Re: equivalent to C pointer |
| From | abdelkader belahcene <abelahcene@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.792.1366314902.3114.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
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 <
> 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
> ###
>
>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: equivalent to C pointer abdelkader belahcene <abelahcene@gmail.com> - 2013-04-18 20:54 +0100
csiph-web