help

ramanand.gudimanchi at siritech.com ramanand.gudimanchi at siritech.com
Tue May 14 23:32:50 EDT 2002


                                                                                                  
                    python-list-request@                                                          
                    python.org                  To:     python-list at python.org                    
                    Sent by:                    cc:                                               
                    python-list-admin at py        Subject:     Python-list digest, Vol 1 #10937 -   
                    thon.org                    13 msgs                                           
                                                                                                  
                                                                                                  
                    05/15/02 08:50 AM                                                             
                    Please respond to                                                             
                    python-list                                                                   
                                                                                                  
                                                                                                  








Send Python-list mailing list submissions to
           python-list at python.org

To subscribe or unsubscribe via the World Wide Web, visit
           http://mail.python.org/mailman/listinfo/python-list
or, via email, send a message with subject or body 'help' to
           python-list-request at python.org

You can reach the person managing the list at
           python-list-admin at python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Python-list digest..."

Today's Topics:

   1. Re: File write/read question (Fernando =?ISO-8859-1?Q?P=E9rez?=)
   2. Re: File write/read question (Chris Liechti)
   3. Re: How to setting system time (Peter Hansen)
   4. Re: how to upgrade correctly to 2.2.1??? (Philip Swartzleonard)
   5. Re: how to write function that returns function (Bengt Richter)
   6. Re: Multi-precision packages: gmpy vs mxNumber (Gerhard
=?iso-8859-15?Q?H=E4ring?=)
   7. Re: OT: Crazy Programming (Greg Ewing)
   8. Re: generated comprehensions (Greg Ewing)
   9. Re: how to write function that returns function (Steve Holden)
  10. Re: Multibyte Character Surport for Python (Greg Ewing)
  11. Re: Oberon in Python, ala Pyrex but instant compile? (Greg Ewing)
  12. Attachmate Extra! and Python (Terje Johan Abrahamsen)
  13. Re: Problem using VC6sp5 to compile extensions - PyObject_HEAD_INIT
(Richard Jones)
Message: 1
Path:
news.baymountain.net!uunet!ash.uu.net!news-out.visi.com!hermes.visi.com!newsfeed1.earthlink.net!newsfeed.earthlink.net!news-hog.berkeley.edu!ucberkeley!news.colorado.edu!not-for-mail

From: Fernando =?ISO-8859-1?Q?P=E9rez?= <fperez528 at yahoo.com>
Newsgroups: comp.lang.python
Subject: Re: File write/read question
Date: Tue, 14 May 2002 18:48:17 -0600
Organization: University of Colorado, Boulder
Lines: 17
Message-ID: <absbdk$rfd$1 at peabody.colorado.edu>
References: <78bc9697.0205130907.4288e607 at posting.google.com>
NNTP-Posting-Host: 128.138.249.175
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7Bit
NNTP-Posting-Date: 15 May 2002 00:51:00 GMT
User-Agent: KNode/0.7.1
Xref: news.baymountain.net comp.lang.python:163557
To: python-list at python.org
Sender: python-list-admin at python.org
Precedence: bulk
List-Help: <mailto:python-list-request at python.org?subject=help>
List-Post: <mailto:python-list at python.org>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=subscribe>
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>

Nathan Hellmers wrote:

> test2 = open("test.txt", "r")
> a = test2.readline()
> int(a)
> print a + a
>

Change to:

test2 = open("test.txt", "r")
a = int(test2.readline().strip())
print a + a

and you should be fine.

f.
Message: 2
Newsgroups: comp.lang.python
Subject: Re: File write/read question
From: Chris Liechti <cliechti at gmx.net>
References: <78bc9697.0205130907.4288e607 at posting.google.com>
<9diE8.1438$Ec.126265 at newsread2.prod.itd.earthlink.net>
Message-ID: <Xns920F20B6DC4FBcliechtigmxnet at 62.2.16.82>
User-Agent: Xnews/5.03.24
NNTP-Posting-Host: 217.162.158.112
Date: 15 May 2002 03:11:07 +0200
Lines: 42
Path:
news.baymountain.net!uunet!ash.uu.net!priapus.visi.com!news-out.visi.com!hermes.visi.com!newspump.sol.net!news.mailgate.org!news-zh.switch.ch!news.swissonline.ch!not-for-mail

Xref: news.baymountain.net comp.lang.python:163558
To: python-list at python.org
Sender: python-list-admin at python.org
Precedence: bulk
List-Help: <mailto:python-list-request at python.org?subject=help>
List-Post: <mailto:python-list at python.org>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=subscribe>
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>

"Howard Roth" <hr at tngi.com> wrote in
news:9diE8.1438$Ec.126265 at newsread2.prod.itd.earthlink.net:
> One way to do the conversion is to use 'eval(a)'
> So 'print eval(a) + eval(a)" will give you two.
> Or you can assign 'x = eval(a)' and 'print x + x'

this executes arbitrary python code found in the file...
good enough for a quick hack but not suitable for production code due to
security risks.

> "Nathan Hellmers" <nhellmers at yahoo.com> wrote in message
> news:78bc9697.0205130907.4288e607 at posting.google.com...
...
>> test2 = open("test.txt", "r")
>> a = test2.readline()
>> int(a)
>> print a + a
>> ----------------
>>
>> That successfully reads the number 1 from the file and assigns the
>> variable "a" to it, but the printout is 1 1 (on two lines) rather than
>> 2.  Using type I can see that "a" was not converted to an integer.  I

well it was, but you throwed away the result...

"a = int(a)" would do what you want

>> can also see that "a" actually equals "a\n".  If I slice off the \n
>> with "a = a[0:1]", I still can't convert it to an integer.

if you want to get rid of whitespaces use strip(), lstrip(), rstrip()
these methods cut away whitspace on both or one side:
i.e. "a = a.rstrip()"

if the conversion with int() would have failed above, you would have get an

exception. so the newline doesn't even matter in this case.

chris

--
Chris <cliechti at gmx.net>

Message: 3
Message-ID: <3CE1B934.2055D8B8 at engcorp.com>
Date: Tue, 14 May 2002 21:26:12 -0400
From: Peter Hansen <peter at engcorp.com>
MIME-Version: 1.0
Newsgroups: comp.lang.python
Subject: Re: How to setting system time
References: <3ce1353a$0$230$626a54ce at news.free.fr>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: fortress.engcorp.com
Lines: 7
Path:
news.baymountain.net!uunet!ash.uu.net!news-out.visi.com!hermes.visi.com!newspump.sol.net!news-xfer.siscom.net!feed1.newsreader.com!netnews.com!xfer02.netnews.com!newsfeed1.cidera.com!Cidera!news.sentex.net!not-for-mail

Xref: news.baymountain.net comp.lang.python:163559
To: python-list at python.org
Sender: python-list-admin at python.org
Precedence: bulk
List-Help: <mailto:python-list-request at python.org?subject=help>
List-Post: <mailto:python-list at python.org>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=subscribe>
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>

dag4004 wrote:
>
> Hello,
>
> Does some one know how to set the system time in Python ?

Use os.system() and a call to the OS...
Message: 4
Path:
news.baymountain.net!uunet!ash.uu.net!priapus.visi.com!news-out.visi.com!hermes.visi.com!newspeer.monmouth.com!uni-erlangen.de!fu-berlin.de!uni-berlin.de!adsl-63-192-42-251.dsl.snfc21.pacbell.NET!not-for-mail

From: Philip Swartzleonard <starx at pacbell.net>
Newsgroups: comp.lang.python
Subject: Re: how to upgrade correctly to 2.2.1???
Date: 15 May 2002 01:26:15 GMT
Organization: Ruby Dragon Outpost o_o
Lines: 21
Message-ID: <Xns920EBBB616038RASXnewsDFE1 at 130.133.1.4>
References: <abrp50$kj35u$1 at ID-75083.news.dfncis.de>
NNTP-Posting-Host: adsl-63-192-42-251.dsl.snfc21.pacbell.net
(63.192.42.251)
User-Agent: Xnews/L5
Xref: news.baymountain.net comp.lang.python:163560
To: python-list at python.org
Sender: python-list-admin at python.org
Precedence: bulk
List-Help: <mailto:python-list-request at python.org?subject=help>
List-Post: <mailto:python-list at python.org>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=subscribe>
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>

Markus Jais || Tue 14 May 2002 12:43:36p:

> hello
>
> I have 2.2 installed and now I want to install 2.2.1
>
> make uninstall in the 2.2 dicrectory does not work
> so I typed
> sudo rm -rf /usr/local/bin/pydoc
> sudo rm -rf /usr/local/binpython*
> sudo rm -rf /usr/local/lib/python2.2/
>
> does this remove all the python 2.2 stuff??

Er, I haven't done this in linux yet, but in windows you can just happily
install 2.2.1 directly over 2.2 and everything works fine. It's been my
experience that *nix handles this kind of upgrading far better than here,
so... you shoudln't i think need to RM anything...

--
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com
Message: 5
Path:
news.baymountain.net!uunet!ash.uu.net!dca.uu.net!news.alt.net!oz.net!usenet
From: bokr at oz.net (Bengt Richter)
Newsgroups: comp.lang.python
Subject: Re: how to write function that returns function
Date: 15 May 2002 01:37:23 GMT
Organization: -
Lines: 110
Message-ID: <abse4j$1r8$0 at 216.39.172.122>
References: <4f52f844.0205141503.40000c50 at posting.google.com>
NNTP-Posting-Host: 216.39.172.122
Xref: news.baymountain.net comp.lang.python:163561
To: python-list at python.org
Sender: python-list-admin at python.org
Precedence: bulk
List-Help: <mailto:python-list-request at python.org?subject=help>
List-Post: <mailto:python-list at python.org>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=subscribe>
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>

On 14 May 2002 16:03:25 -0700, spam at bugbear.com (Paul Graham) wrote:

>I am not a Python expert, and I'm hoping someone
>can tell me how in Python to write a function
>of one argument x that returns a function of one
>argument y that returns x+y.
>
>Here, in Scheme, is what I want to write:
>
>(define foo (x) (lambda (y) (+ x y)))
>
With nested scopes (default in 2.2, import nested_scopes from __future__ in
2.1),
you can do this:

 >>> def foo(x): return lambda y: x+y
 ...
 >>> f = foo(7)
 >>> f(3)
 10
 >>> import dis                             <-- handy disassembler for
seeing what functions do etc.
 >>> dis.dis(f)
           0 SET_LINENO               1
           3 LOAD_DEREF               0 (x) <-- this loads the 7 from the
closure
           6 LOAD_FAST                0 (y) <-- this loads the argument to
the function
           9 BINARY_ADD
          10 RETURN_VALUE
 >>> f.func_closure
 (<cell at 0x008430C0: int object at 0x00795910>,)
 >>> hex(id(7))
 '0x795910'

Doing it as above captures x in a closure. I used a
small int 7 knowing the same instance would be used,
and we could recognize it in the closure by its id.

>I found on the web a page that says I could define
>this as follows:
>
>def addn(x):
>  return lambda y,z=y: x+z
>
I don't think that's quite right. The idea is to capture x in
a way that works like the closure, and a dummy default value is
the mechanism, so I think it should be:

 >>> def foo(x): return lambda y,z=x: y+z
 ...
 >>> f = foo(7)
 >>> f(3)
 10
 >>> dis.dis(f)
           0 SET_LINENO               1
           3 LOAD_FAST                0 (y) <-- this loads the first
function arg
           6 LOAD_FAST                1 (z) <-- this simulates the closure
effect
           9 BINARY_ADD                         \_ unless you pass a second
arg
          10 RETURN_VALUE
 >>> f.func_closure          <-- there isn't any (None)
 >>> f.func_defaults
 (7,)
 >>> f(3,5)       <-- the second arg overrides, so it's not a proper
solution
 8

>but I don't think this is exactly the same thing,
>because it returns a function that takes a second
>optional argument.  That is a substantial difference.
>If the Scheme function is inadvertently called
>(e.g. in someone else's code) with two arguments, it
>would signal an error, whereas the code above would
>quietly give the wrong answer.
>
right

>I would appreciate it if someone could tell me the
>standard way to write this so that it returns a
>function of exactly one argument.
>
See above, but BTW, you don't have to use lambda at all:

 >>> def foo(x):
 ...     def forget_this_name(y):
 ...         return x+y
 ...     return forget_this_name
 ...
 >>> f = foo(7)
 >>> f(3)
 10
 >>> dis.dis(f)
           0 SET_LINENO               2

           3 SET_LINENO               3
           6 LOAD_DEREF               0 (x)  <-- this loads the 7 from the
closure
           9 LOAD_FAST                0 (y)  <-- this loads the function
arg
          12 BINARY_ADD
          13 RETURN_VALUE
          14 LOAD_CONST               0 (None) <--this is dead boilerplate
code you don't get with lambda
          17 RETURN_VALUE
 >>> f.func_closure
 (<cell at 0x008430C0: int object at 0x00795910>,)  <-- proper closure this
time. Note hex location
 >>> f.func_defaults                                <-- no defaults
 >>> f(3,5)                                         <-- strictly one arg,
so this fails
 Traceback (most recent call last):
   File "<stdin>", line 1, in ?
 TypeError: forget_this_name() takes exactly 1 argument (2 given)
 >>> hex(id(7))
 '0x795910'                                         <--hex location of 7

HTH

Regards,
Bengt Richter
Message: 6
Path:
news.baymountain.net!uunet!ash.uu.net!prodigy.com!skynet.be!skynet.be!fu-berlin.de!uni-berlin.de!pd9eb7ce1.dip.t-dialin.NET!not-for-mail

From: Gerhard =?iso-8859-15?Q?H=E4ring?= <gerhard at bigfoot.de>
Newsgroups: comp.lang.python
Subject: Re: Multi-precision packages: gmpy vs mxNumber
Date: 15 May 2002 01:49:44 GMT
Organization: People's Front of Judea
Lines: 15
Message-ID: <slrnae3flo.as7.gerhard at lilith.my-fqdn.de>
References: <absabp$qj4$1 at peabody.colorado.edu>
NNTP-Posting-Host: pd9eb7ce1.dip.t-dialin.net (217.235.124.225)
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-15
Content-Transfer-Encoding: 8bit
User-Agent: slrn/0.9.7.4 (Linux)
Cache-Post-Path: gargamel.hqd-internal!unknown at lilith.hqd-internal
Xref: news.baymountain.net comp.lang.python:163562
To: python-list at python.org
Sender: python-list-admin at python.org
Precedence: bulk
List-Help: <mailto:python-list-request at python.org?subject=help>
List-Post: <mailto:python-list at python.org>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=subscribe>
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>

Fernando Pérez wrote in comp.lang.python:
> Do any of the experts have any advice on the pros and cons of these two
GMP
> wrappers? [...]

While we're at it, is there any Python extension for fixed point
arithmetic available? pyPgSQL has a fixed point type implemented in
Python, which should eventually be replaced by a C type. It would be
great if I could borrow code somewhere.

Gerhard
--
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9  3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple
('zS^BED\nX_FOY\x0b')))
Message: 7
Path:
news.baymountain.net!uunet!ash.uu.net!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsfeed01.tsnz.net!canterbury.ac.nz!not-for-mail

From: Greg Ewing <greg at cosc.canterbury.ac.nz>
Newsgroups: comp.lang.python
Subject: Re: OT: Crazy Programming
Date: Wed, 15 May 2002 14:16:34 +1200
Organization: Computer Science Dept, University of Canterbury
Lines: 29
Message-ID: <3CE1C502.BF27501D at cosc.canterbury.ac.nz>
References: <mailman.1021198403.21335.python-list at python.org>
<87offlnq3k.fsf at mathdogs.com>
<chris-55B5FD.02324413052002 at corp.supernews.com>
<abnqdd$8bf$1 at slb0.atl.mindspring.net>
<23891c90.0205130956.6f0436a0 at posting.google.com>
<ht91eus6861nu2am7164l8ui9925rmu5sn at 4ax.com>
<3d06fae9.0205140451.5ec335b1 at posting.google.com>
NNTP-Posting-Host: oma.cosc.canterbury.ac.nz
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Date: Wed, 15 May 2002 02:16:43 +0000 (UTC)
Xref: news.baymountain.net comp.lang.python:163563
To: python-list at python.org
Sender: python-list-admin at python.org
Precedence: bulk
List-Help: <mailto:python-list-request at python.org?subject=help>
List-Post: <mailto:python-list at python.org>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=subscribe>
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>

jmdeschamps wrote:
>
> But programming is not building bridges or buildings; in its very
> essence, its the realm of whatever is within the outer limits of human
> creativity, whatever that is!

Indeed. I don't think the problem is a lack of engineering
principles, it's that we're pushing the boundaries all the
time.

If buildings were built like computer programs, every
building would be unique, not quite like any other
building ever built before, and using experimental
new materials and building techniques. And before
we'd got all the bugs out of one building, we'd be
charging ahead with the next one. Under those
conditions, I don't think the building industry would
have much of a reputation for reliability in their
products!

When we *do* settle down to work on something
properly, we seem to do a pretty good job --
unix, gcc, etc...

--
Greg Ewing, Computer Science Dept, University of Canterbury,
Christchurch, New Zealand
To get my email address, please visit my web page:
http://www.cosc.canterbury.ac.nz/~greg
Message: 8
Path:
news.baymountain.net!uunet!ash.uu.net!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsfeed01.tsnz.net!canterbury.ac.nz!not-for-mail

From: Greg Ewing <greg at cosc.canterbury.ac.nz>
Newsgroups: comp.lang.python
Subject: Re: generated comprehensions
Date: Wed, 15 May 2002 14:27:03 +1200
Organization: Computer Science Dept, University of Canterbury
Lines: 29
Message-ID: <3CE1C777.9110C4D7 at cosc.canterbury.ac.nz>
References: <4c877253.0205132231.6d286d0b at posting.google.com>
NNTP-Posting-Host: oma.cosc.canterbury.ac.nz
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Date: Wed, 15 May 2002 02:27:12 +0000 (UTC)
Xref: news.baymountain.net comp.lang.python:163564
To: python-list at python.org
Sender: python-list-admin at python.org
Precedence: bulk
List-Help: <mailto:python-list-request at python.org?subject=help>
List-Post: <mailto:python-list at python.org>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=subscribe>
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>

Garth T Kidd wrote:
>
>     def printOdds(upto):
>         for odd in [num for num in xrange(upto) if num%2]:
>             print odd
>
> ... works fine if upto is 5, but just sits there chewing up memory if
> upto is 10**9, at which point you abandon comprehensions and do it
> properly:

I don't think I would have used a comprehension there in
the first place, because building a list isn't needed.
i.e. I would have "done it properly" the first time,
particularly since the comprehension only saves 2 lines
of code.

> I'm sure I'll figure out a decent rule of thumb (say, "unit test with
> the biggest practical number, and get rid of comprehensions if they
> turn out to be a problem", or "don't use comprehensions with
> generators"),

The rule of thumb you want is: If you need the result as
a list, use a comprehension, otherwise don't.

--
Greg Ewing, Computer Science Dept, University of Canterbury,
Christchurch, New Zealand
To get my email address, please visit my web page:
http://www.cosc.canterbury.ac.nz/~greg
Message: 9
Path:
news.baymountain.net!uunet!ash.uu.net!news-out.visi.com!hermes.visi.com!newsfeeds-atl2!atlpnn01.usenetserver.com.POSTED!not-for-mail

From: "Steve Holden" <sholden at holdenweb.com>
Newsgroups: comp.lang.python
References: <4f52f844.0205141503.40000c50 at posting.google.com>
Subject: Re: how to write function that returns function
Lines: 73
Message-ID: <%MjE8.9266$Wh.4751 at atlpnn01.usenetserver.com>
NNTP-Posting-Date: Tue, 14 May 2002 22:32:27 EDT
Organization: WebUseNet Corp.  http://corp.webusenet.com - ReInventing the
UseNet
Date: Tue, 14 May 2002 22:28:43 -0400
Xref: news.baymountain.net comp.lang.python:163565
To: python-list at python.org
Sender: python-list-admin at python.org
Precedence: bulk
List-Help: <mailto:python-list-request at python.org?subject=help>
List-Post: <mailto:python-list at python.org>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=subscribe>
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>

"Paul Graham" <spam at bugbear.com> wrote in message
news:4f52f844.0205141503.40000c50 at posting.google.com...
> I am not a Python expert, and I'm hoping someone
> can tell me how in Python to write a function
> of one argument x that returns a function of one
> argument y that returns x+y.
>
> Here, in Scheme, is what I want to write:
>
> (define foo (x) (lambda (y) (+ x y)))
>
> I found on the web a page that says I could define
> this as follows:
>
> def addn(x):
>   return lambda y,z=y: x+z
>
> but I don't think this is exactly the same thing,
> because it returns a function that takes a second
> optional argument.  That is a substantial difference.
> If the Scheme function is inadvertently called
> (e.g. in someone else's code) with two arguments, it
> would signal an error, whereas the code above would
> quietly give the wrong answer.
>
> I would appreciate it if someone could tell me the
> standard way to write this so that it returns a
> function of exactly one argument.
>
There's no need to use lambda, and indeed I eschew it whenever it make
sense
to do so. From 2.2 on you don't need top import nested_scopes from
__future__, by the way. Since functions are fisrt-class objects, it doesn't
matter what name is associated with the declarations - they can be bound to
any variable once they are returned.

Python 2.2 (#1, Dec 31 2001, 15:21:18)
[GCC 2.95.3-5 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def adder(x):
...     def anyoldname(y):
...         return x+y
...     return anyoldname
...
>>> add3 = adder(3)
>>> add100 = adder(100)
>>> add3(12)
15
>>> add100(12)
112
>>>

Note, however, that the function name (the name bound to it in the def
statement) does get built in to its repr():

>>> add3
<function anyoldname at 0x100fffe8>
>>> add100
<function anyoldname at 0x10100278>
>>>

Hope this helps.

regards
 Steve
--
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------





Message: 10
Path:
news.baymountain.net!uunet!ash.uu.net!dca.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsfeed01.tsnz.net!canterbury.ac.nz!not-for-mail

From: Greg Ewing <greg at cosc.canterbury.ac.nz>
Newsgroups: comp.lang.python
Subject: Re: Multibyte Character Surport for Python
Date: Wed, 15 May 2002 14:35:27 +1200
Organization: Computer Science Dept, University of Canterbury
Lines: 15
Message-ID: <3CE1C96F.ED19AFF4 at cosc.canterbury.ac.nz>
References: <e786d63d.0205080421.3788a0e2 at posting.google.com>
<mailman.1020884595.5671.python-list at python.org>
<UVhC8.20845$CN3.673651 at news2.tin.it>
<83d6vzgngy.fsf at panacea.canonical.org>
<nP4E8.54617$zW3.757325 at news1.tin.it>
NNTP-Posting-Host: oma.cosc.canterbury.ac.nz
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Date: Wed, 15 May 2002 02:35:36 +0000 (UTC)
Xref: news.baymountain.net comp.lang.python:163566
To: python-list at python.org
Sender: python-list-admin at python.org
Precedence: bulk
List-Help: <mailto:python-list-request at python.org?subject=help>
List-Post: <mailto:python-list at python.org>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=subscribe>
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>

Alex Martelli wrote:
>
> we can't really count illiterates as candidate
> programmers, I think -- despite all of the "point and grunt" rhetoric).

But haven't you heard of the CP4P&G initiative (Computer
Programming for Pointers and Grunters)? And the working
subcomittee for establishing a point-and-grunt encoding
for Unicode is due to report any day now...

--
Greg Ewing, Computer Science Dept, University of Canterbury,
Christchurch, New Zealand
To get my email address, please visit my web page:
http://www.cosc.canterbury.ac.nz/~greg
Message: 11
Path:
news.baymountain.net!uunet!ash.uu.net!lore.csc.com!nntp.abs.net!feed2.news.rcn.net!rcn!news.maxwell.syr.edu!xmission!news-out.spamkiller.net!propagator2-maxim!propagator-maxim!news-in.spamkiller.net!news02.tsnz.net!newsfeed01.tsnz.net!canterbury.ac.nz!not-for-mail

From: Greg Ewing <greg at cosc.canterbury.ac.nz>
Newsgroups: comp.lang.python
Subject: Re: Oberon in Python, ala Pyrex but instant compile?
Date: Wed, 15 May 2002 14:56:43 +1200
Organization: Computer Science Dept, University of Canterbury
Lines: 19
Message-ID: <3CE1CE6B.4C39A3D1 at cosc.canterbury.ac.nz>
References: <3ce11bc3_4 at goliath.newsgroups.com>
NNTP-Posting-Host: oma.cosc.canterbury.ac.nz
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Date: Wed, 15 May 2002 02:56:54 +0000 (UTC)
Xref: news.baymountain.net comp.lang.python:163567
To: python-list at python.org
Sender: python-list-admin at python.org
Precedence: bulk
List-Help: <mailto:python-list-request at python.org?subject=help>
List-Post: <mailto:python-list at python.org>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=subscribe>
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>

Brad Clements wrote:
>
> But I wondering if this is too crazy an idea or not. Have something like
> Pyrex write Oberon code, run it through an Oberon compiler and
dynamically
> load the resulting module.

I suppose it could be done, provided you can make calls
to the Python/C API from Oberon code. I don't know
enough about current Oberon implementations to know
whether this is possible.

Anyway, feel free to hack on Pyrex to make it generate
Oberon, and let me know how you get on!

--
Greg Ewing, Computer Science Dept, University of Canterbury,
Christchurch, New Zealand
To get my email address, please visit my web page:
http://www.cosc.canterbury.ac.nz/~greg
Message: 12
Path:
news.baymountain.net!uunet!ash.uu.net!prodigy.com!newscon02.news.prodigy.com!prodigy.com!cpk-news-hub1.bbnplanet.com!news.gtei.net!fu-berlin.de!uni-berlin.de!24-148-77-209.na.21stcentury.NET!not-for-mail

From: Terje Johan Abrahamsen <terjej at mailandnews.com>
Newsgroups: comp.lang.python
Subject: Attachmate Extra! and Python
Date: Wed, 15 May 2002 10:02:29 -0500
Lines: 11
Message-ID: <8nt4eu0mc5ovohpc62iig23mglf7mln4t9 at 4ax.com>
NNTP-Posting-Host: 24-148-77-209.na.21stcentury.net (24.148.77.209)
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Xref: news.baymountain.net comp.lang.python:163568
To: python-list at python.org
Sender: python-list-admin at python.org
Precedence: bulk
List-Help: <mailto:python-list-request at python.org?subject=help>
List-Post: <mailto:python-list at python.org>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=subscribe>
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>

I am trying to make use of Win32Com and make a "bridge" between Excel
and Extra!. The documentation that comes with Extra is very sparse
regarding how to use the OLE connections. I guess they want to sell
the developer kit for 500 dollars. However, that will not work with my
budget, and besides, I just need a very small part of it. So,
therefore I am very curious if somebody has controlled Extra! thru
Python? If so, do you know about a website with some more info or some
sourcecode I can read thru to get some hints?

Thanks in advance,
Terje
Message: 13
Content-Type: text/plain;
  charset="iso-8859-1"
From: Richard Jones <rjones at ekit-inc.com>
Organization: ekit.com Inc
To: sjmachin at lexicon.net (John Machin), python-list at python.org
Subject: Re: Problem using VC6sp5 to compile extensions -
PyObject_HEAD_INIT
Date: Wed, 15 May 2002 13:19:06 +1000
References: <mailman.1021357343.26170.python-list at python.org>
<c76ff6fc.0205141241.16396022 at posting.google.com>
In-Reply-To: <c76ff6fc.0205141241.16396022 at posting.google.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Message-Id: <200205151319.06701.rjones at ekit-inc.com>
Sender: python-list-admin at python.org
Precedence: bulk
List-Help: <mailto:python-list-request at python.org?subject=help>
List-Post: <mailto:python-list at python.org>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=subscribe>
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
           <mailto:python-list-request at python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list/>

On Wed, 15 May 2002 06:41, John Machin wrote:
> Richard Jones <rjones at ekit-inc.com> wrote in message
> news:<mailman.1021357343.26170.python-list at python.org>...
>
> > I've had a bug report for the kjbuckets module:
> >
> >
http://sourceforge.net/tracker/?func=detail&atid=100662&aid=555391&group_
> >id=662
> >
> > In summary, trying to "python setup.py install" the kjbuckets module
> > distributed with the new Gadfly package results in:
> >
> > """
> > kjbucketsmodule.c(3301) : error C2099: initializer is not a constant
> > kjbucketsmodule.c(3321) : error C2099: initializer is not a constant
> > kjbucketsmodule.c(3341) : error C2099: initializer is not a constant
>
> Billy Gates don't lie, man! As the *MANUAL* points out, what you have
> is not "strictly conforming C". Please read
>
>    http://www.python.org/doc/current/ext/dnt-basics.html
>
> and the *FAQ*:
>
>    http://www.python.org/doc/FAQ.html#3.24

I have already apologised once for not performing a web search before
posting.
I had inherited the module from another programmer, and assumed that the
problem I had run into was unique, or it would already have been fixed. I
will not make that assumption again.

Thanks to all who responded.


   Richard





--
http://mail.python.org/mailman/listinfo/python-list









More information about the Python-list mailing list