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


Groups > comp.lang.python > #43847

Re: equivalent to C pointer

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Neil Cerutti <neilc@norwich.edu>
Newsgroups comp.lang.python
Subject Re: equivalent to C pointer
Date 18 Apr 2013 18:07:32 GMT
Organization Norwich University
Lines 46
Message-ID <atar34Fmv3jU2@mid.individual.net> (permalink)
References <CAF3f0sQ_rsdKwaEOCmFHEeEwpVUaNUo-pOYgoqYA_F-k0CftcA@mail.gmail.com> <51702AB6.30609@gmail.com> <mailman.783.1366307409.3114.python-list@python.org>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Trace individual.net CMwabe+gEJ+BWEwHevE8mA9MJVWyShGSgubQ/VNkgrVtnl1nhG
Cancel-Lock sha1:47D7wcGVM1lICN/p00hUF04kd1U=
User-Agent slrn/0.9.9p1/mm/ao (Win32)
Xref csiph.com comp.lang.python:43847

Show key headers only | View raw


On 2013-04-18, 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

There's no linking stage in Python. Everything you use must be
defined before you use it.

In Python you can put trapeze in a library, and it will be able
to accept any old function under the sun when you call it, as
long as that function is defined.

in trapeze.py:

  def trapeze(func, left, right, step):
      return sum((func(x) + func(x + step)) * step * 0.5
                 for x in range(left, right, step))
               
in file1.py:

  import trapeze
  
  def square(x):
      return x*x
  
  print(trapeze.trapeze(square, 0, 3, 2.5))


if file2.py:

  import trapeze
  import math
  
  print(trapeze.trapeze(math.sin, 1.3, 2.5, 1.0))

The functions square and sin are both defined before you pass
them to trapeze, so all is well. Trapeze doesn't know or care about
the signature of those functions until it actually tries to call
them. At that time, if either one isn't defined properly Python
will raise an exception.

-- 
Neil Cerutti

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


Thread

Re: equivalent to C pointer abdelkader belahcene <abelahcene@gmail.com> - 2013-04-18 18:50 +0100
  Re: equivalent to C pointer Neil Cerutti <neilc@norwich.edu> - 2013-04-18 18:07 +0000
    Re: equivalent to C pointer Tim Chase <python.list@tim.thechases.com> - 2013-04-18 13:48 -0500

csiph-web