Re: Question

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 9:39 AM, Ben Morales wrote: > I am trying to download Python but I have windows 10 and I do not see a 64 > bit download for my operating system. Do you have a 64 bit for windows? What page are you looking at? https://www.python.org/downloads/release/python-351/ has download

Re: Question on keyword arguments

2016-02-18 Thread Tim Chase
On 2016-02-18 10:57, grsm...@atlanticbb.net wrote: > Tim, the 'crazy-other-result format' is the > result returned by the database, nothing > I can do about that :) then, much like converting byte-strings to unicode strings as early as possible and converting them back to byte-strings as late as p

Re: Question on keyword arguments

2016-02-18 Thread grsmith
ython-list@python.org Subject: Re: Question on keyword arguments On Fri, Feb 19, 2016 at 2:39 AM, Dan Strohl wrote: So, define a return object like: from collections import UserList class TestResponse(UserList): def __str__(self): return '\0xfe%s' % '\0xfe'.join(self.da

Re: Question on keyword arguments

2016-02-18 Thread Chris Angelico
On Fri, Feb 19, 2016 at 2:39 AM, Dan Strohl wrote: > So, define a return object like: > > from collections import UserList > class TestResponse(UserList): > def __str__(self): > return '\0xfe%s' % '\0xfe'.join(self.data) > > ...and return that object. Out of interest, why UserList rat

RE: Question on keyword arguments

2016-02-18 Thread Dan Strohl
ably minor performance tuning.) Dan Strohl > -Original Message- > From: Python-list [mailto:python-list-bounces+d.strohl=f5@python.org] On > Behalf Of Peter Otten > Sent: Thursday, February 18, 2016 6:37 AM > To: python-list@python.org > Subject: Re: Question on keyword argum

Re: Question on keyword arguments

2016-02-18 Thread Tim Chase
On 2016-02-18 09:00, grsm...@atlanticbb.net wrote: > Would this be the correct way to return > a list as a default result. > > Also, would the list be the preferable result (to a python > programmer) ? > > def test(command, return_type='LIST'): > """ Go to database and return data""" > if

Re: Question on keyword arguments

2016-02-18 Thread Peter Otten
grsm...@atlanticbb.net wrote: > Would this be the correct way to return > a list as a default result. If it does what you want it to do it is "correct" as in "complies with specification". > Also, would the list be the preferable result (to a python programmer) ? A list as a return value is O

Re: Question about official API

2016-02-05 Thread Frank Millman
"Frank Millman" wrote in message news:n91ndn$sc1$1...@ger.gmane.org... Thanks for the link, Lutz. Unfortunately I may have asked the wrong question. In my specific case, how do I know if it is safe to use the attribute 'unfinished_tasks' in the class queue.Queue? It could be that it is in

Re: Question about official API

2016-02-05 Thread Frank Millman
"Lutz Horn" wrote in message news:blu178-w1837247af25e5755af69eb9e...@phx.gbl... Hi, > What is the rule for knowing if something is part of the official API? Look into https://docs.python.org/3/library/ Thanks for the link, Lutz. Unfortunately I may have asked the wrong question. In my

Re: Question about official API

2016-02-05 Thread Ben Finney
"Frank Millman" writes: > What is the rule for knowing if something is part of the official API? Part of what official API? Different libraries will have different rules about what is the official API. Some may not have official rules. For Python standard library modules, the official API is i

RE: Question about official API

2016-02-05 Thread Lutz Horn
Hi, > What is the rule for knowing if something is part of the official API? Look into https://docs.python.org/3/library/ Lutz -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about asyncio and blocking operations

2016-01-29 Thread Frank Millman
"Frank Millman" wrote in message news:n8et0d$hem$1...@ger.gmane.org... I have read the other messages, and I can see that there are some clever ideas there. However, having found something that seems to work and that I feel comfortable with, I plan to run with this for the time being. A quic

Re: Question about asyncio and blocking operations

2016-01-29 Thread Maxime Steisel
Le 28 janv. 2016 22:52, "Ian Kelly" a écrit : > > On Thu, Jan 28, 2016 at 2:23 PM, Maxime S wrote: > > > > 2016-01-28 17:53 GMT+01:00 Ian Kelly : > >> > >> On Thu, Jan 28, 2016 at 9:40 AM, Frank Millman wrote: > >> > >> > The caller requests some data from the database like this. > >> > > >> >

Re: Question about asyncio and blocking operations

2016-01-28 Thread Frank Millman
"Ian Kelly" wrote in message news:calwzidn6nft_o0cfhw1itwja81+mw3schuecadvcen3ix6z...@mail.gmail.com... As I commented in my previous message, asyncio.Queue is not thread-safe, so it's very important that the put calls here be done on the event loop thread using event_loop.call_soon_threadsafe.

Re: Question about asyncio and blocking operations

2016-01-28 Thread Ian Kelly
On Jan 28, 2016 3:07 PM, "Maxime Steisel" wrote: > > But it is a pretty strange idea to call two fetch*() method concurrently anyways. If you want to process rows concurrently and aren't concerned with processing them in order, it may be attractive to create multiple threads / coroutines, pass th

Re: Question about asyncio and blocking operations

2016-01-28 Thread Ian Kelly
On Thu, Jan 28, 2016 at 2:23 PM, Maxime S wrote: > > 2016-01-28 17:53 GMT+01:00 Ian Kelly : >> >> On Thu, Jan 28, 2016 at 9:40 AM, Frank Millman wrote: >> >> > The caller requests some data from the database like this. >> > >> >return_queue = asyncio.Queue() >> >sql = 'SELECT ...' >> >

Re: Question about asyncio and blocking operations

2016-01-28 Thread Maxime S
2016-01-28 17:53 GMT+01:00 Ian Kelly : > On Thu, Jan 28, 2016 at 9:40 AM, Frank Millman wrote: > > > The caller requests some data from the database like this. > > > >return_queue = asyncio.Queue() > >sql = 'SELECT ...' > >request_queue.put((return_queue, sql)) > > Note that since thi

Re: Question about asyncio and blocking operations

2016-01-28 Thread Frank Millman
"Ian Kelly" wrote in message news:CALwzidnGbz7kM=d7mkua2ta9-csfn9u0ohl0w-x5bbixpcw...@mail.gmail.com... On Jan 28, 2016 4:13 AM, "Frank Millman" wrote: > > I *think* I have this one covered. When the caller makes a request, it creates an instance of an asyncio.Queue, and includes it with the

Re: Question about asyncio and blocking operations

2016-01-28 Thread Ian Kelly
On Jan 28, 2016 4:13 AM, "Frank Millman" wrote: > > "Chris Angelico" wrote in message news:captjjmr162+k4lzefpxrur6wxrhxbr-_wkrclldyr7kst+k...@mail.gmail.com... >> >> >> On Thu, Jan 28, 2016 at 8:13 PM, Frank Millman wrote: >> > Run the database handler in a separate thread. Use a queue.Queue to

Re: Question about asyncio and blocking operations

2016-01-28 Thread Ian Kelly
On Thu, Jan 28, 2016 at 9:40 AM, Frank Millman wrote: > I have hit a snag. It feels like a bug in 'await q.get()', though I am sure > it is just me misunderstanding how it works. > > I can post some working code if necessary, but here is a short description. > > Here is the database handler - 'req

Re: Question about asyncio and blocking operations

2016-01-28 Thread Frank Millman
"Chris Angelico" wrote in message news:captjjmr162+k4lzefpxrur6wxrhxbr-_wkrclldyr7kst+k...@mail.gmail.com... On Thu, Jan 28, 2016 at 8:13 PM, Frank Millman wrote: > Run the database handler in a separate thread. Use a queue.Queue to send > requests to the handler. Use an asyncio.Queue to send

Re: Question about asyncio and blocking operations

2016-01-28 Thread Chris Angelico
On Thu, Jan 28, 2016 at 8:13 PM, Frank Millman wrote: > Run the database handler in a separate thread. Use a queue.Queue to send > requests to the handler. Use an asyncio.Queue to send results back to the > caller, which can call 'await q.get()'. > > I ran a quick test and it seems to work. What d

Re: Question about asyncio and blocking operations

2016-01-28 Thread Chris Angelico
On Thu, Jan 28, 2016 at 10:11 PM, Frank Millman wrote: >> >> The other risk is that the wrong result will be queried (two async >> tasks put something onto the queue - which one gets the first >> result?), which could either be coped with by simple sequencing (maybe >> this happens automatically,

Re: Question about asyncio and blocking operations

2016-01-28 Thread Frank Millman
"Ian Kelly" wrote in message news:CALwzidkr-fT6S6wH2caNaxyQvUdAw=x7xdqkqofnrrwzwnj...@mail.gmail.com... On Wed, Jan 27, 2016 at 10:14 AM, Ian Kelly wrote: > Unfortunately this doesn't actually work at present. > EventLoop.run_in_executor swallows the StopIteration exception and > just returns

Re: Question about asyncio and blocking operations

2016-01-27 Thread Frank Millman
"Ian Kelly" wrote in message news:CALwzidk-RBkB-vi6CgcEeoFHQrsoTFvqX9MqzDD=rny5boc...@mail.gmail.com... On Tue, Jan 26, 2016 at 7:15 AM, Frank Millman wrote: > > If I return the cursor, I can iterate over it, but isn't this a blocking > operation? As far as I know, the DB adaptor will only ac

Re: Question about asyncio and blocking operations

2016-01-27 Thread Frank Millman
"Ian Kelly" wrote in message news:calwzidn6tvn9w-2qnn2jyvju8nhzn499nptfjn9ohjddceb...@mail.gmail.com... On Wed, Jan 27, 2016 at 7:40 AM, Frank Millman wrote: > > Assume a slow function - > > async def slow_function(arg1, arg2): >[do stuff] > > It now looks like this - > > async def slow_f

Re: Question about asyncio and blocking operations

2016-01-27 Thread Ian Kelly
On Wed, Jan 27, 2016 at 10:14 AM, Ian Kelly wrote: > Unfortunately this doesn't actually work at present. > EventLoop.run_in_executor swallows the StopIteration exception and > just returns None, which I assume is a bug. http://bugs.python.org/issue26221 -- https://mail.python.org/mailman/listin

Re: Question about asyncio and blocking operations

2016-01-27 Thread Ian Kelly
On Wed, Jan 27, 2016 at 9:15 AM, Ian Kelly wrote: > class CursorWrapper: > > def __init__(self, cursor): > self._cursor = cursor > > async def __aiter__(self): > return self > > async def __anext__(self): > loop = asyncio.get_event_loop() > return await

Re: Question about asyncio and blocking operations

2016-01-27 Thread Ian Kelly
On Wed, Jan 27, 2016 at 7:40 AM, Frank Millman wrote: > "Ian Kelly" wrote in message > news:CALwzidk-RBkB-vi6CgcEeoFHQrsoTFvqX9MqzDD=rny5boc...@mail.gmail.com... > >> You probably want an asynchronous iterator here. If the cursor doesn't >> provide that, then you can wrap it in one. In fact, this

Re: Question about asyncio and blocking operations

2016-01-27 Thread Frank Millman
"Ian Kelly" wrote in message news:CALwzidk-RBkB-vi6CgcEeoFHQrsoTFvqX9MqzDD=rny5boc...@mail.gmail.com... On Tue, Jan 26, 2016 at 7:15 AM, Frank Millman wrote: > > If I return the cursor, I can iterate over it, but isn't this a blocking > operation? As far as I know, the DB adaptor will only ac

Re: Question about asyncio and blocking operations

2016-01-26 Thread Alberto Berti
> "Alberto" == Alberto Berti writes: Alberto> async external_coro(): # this is the calling context, which is a coro Alberto> async with transction.begin(): Alberto> o = MyObject Alberto> # maybe other stuff ops... here it is "o = MyObject

Re: Question about asyncio and blocking operations

2016-01-26 Thread Alberto Berti
> "Frank" == Frank Millman writes: Frank> Now I have another problem. I have some classes which retrieve some Frank> data from the database during their __init__() method. I find that it Frank> is not allowed to call a coroutine from __init__(), and it is not Frank> allowed to

Re: Question about asyncio and blocking operations

2016-01-26 Thread Ian Kelly
On Tue, Jan 26, 2016 at 7:15 AM, Frank Millman wrote: > I am making some progress, but I have found a snag - possibly unavoidable, > but worth a mention. > > Usually when I retrieve rows from a database I iterate over the cursor - > >def get_rows(sql, params): >cur.execute(sql, params)

Re: Question about asyncio and blocking operations

2016-01-26 Thread Frank Millman
"Frank Millman" wrote in message news:n8038j$575$1...@ger.gmane.org... I am developing a typical accounting/business application which involves a front-end allowing clients to access the system, a back-end connecting to a database, and a middle layer that glues it all together. [...] The

Re: Question about asyncio and blocking operations

2016-01-25 Thread Paul Rubin
Marko Rauhamaa writes: > Note that neither the multithreading model (which I dislike) nor the > callback hell (which I like) suffer from this problem. There are some runtimes (GHC and Erlang) where everything is nonblocking under the covers, which lets even the asyncs be swept under the rug. Simi

Re: Question about asyncio and blocking operations

2016-01-25 Thread Marko Rauhamaa
Rustom Mody : > Bah -- What a bloody mess! > And thanks for pointing this out, Ian. > Keep wondering whether my brain is atrophying, or its rocket science or... I'm afraid the asyncio idea will not fly. Adding the keywords "async" and "await" did make things much better, but the programming mode

Re: Question about asyncio and blocking operations

2016-01-25 Thread Rustom Mody
On Monday, January 25, 2016 at 9:16:13 PM UTC+5:30, Ian wrote: > On Mon, Jan 25, 2016 at 8:32 AM, Ian Kelly wrote: > > > > On Jan 25, 2016 2:04 AM, "Frank Millman" wrote: > >> > >> "Ian Kelly" wrote in message > >>> > >>> This seems to be a common misapprehension about asyncio programming. > >>>

Re: Question about asyncio and blocking operations

2016-01-25 Thread Ian Kelly
On Mon, Jan 25, 2016 at 8:32 AM, Ian Kelly wrote: > > On Jan 25, 2016 2:04 AM, "Frank Millman" wrote: >> >> "Ian Kelly" wrote in message >> news:calwzidngogpx+cpmvba8vpefuq4-bwmvs0gz3shb0owzi0b...@mail.gmail.com... >>> >>> This seems to be a common misapprehension about asyncio programming. >>>

Re: Question about asyncio and blocking operations

2016-01-25 Thread Ian Kelly
On Jan 25, 2016 2:04 AM, "Frank Millman" wrote: > > "Ian Kelly" wrote in message news:calwzidngogpx+cpmvba8vpefuq4-bwmvs0gz3shb0owzi0b...@mail.gmail.com... >> >> This seems to be a common misapprehension about asyncio programming. >> While coroutines are the focus of the library, they're based on

Re: Question about asyncio and blocking operations

2016-01-25 Thread Frank Millman
"Ian Kelly" wrote in message news:calwzidngogpx+cpmvba8vpefuq4-bwmvs0gz3shb0owzi0b...@mail.gmail.com... On Sat, Jan 23, 2016 at 7:38 AM, Frank Millman wrote: > Here is the difficulty. The recommended way to handle a blocking > operation > is to run it as task in a different thread, using run_i

Re: Question about asyncio and blocking operations

2016-01-25 Thread Frank Millman
"Ian Kelly" wrote in message news:calwzidngogpx+cpmvba8vpefuq4-bwmvs0gz3shb0owzi0b...@mail.gmail.com... On Sat, Jan 23, 2016 at 7:38 AM, Frank Millman wrote: > Here is the difficulty. The recommended way to handle a blocking > operation > is to run it as task in a different thread, using run_

Re: Question about how to do something in BeautifulSoup?

2016-01-23 Thread Cody Piersall
On Fri, Jan 22, 2016 at 8:01 AM, inhahe wrote: > Say I have the following HTML (I hope this shows up as plain text here > rather than formatting): > > "Is > today the day?" > > And I want to extract the "Is today the day?" part. There are other places > in the document with and , but this is the

Re: Question about asyncio and blocking operations

2016-01-23 Thread Frank Millman
"Frank Millman" wrote in message news:n8038j$575$1...@ger.gmane.org... So I thought I would ask here if anyone has been through a similar exercise, and if what I am going through sounds normal, or if I am doing something fundamentally wrong. Thanks for any input Just a quick note of thank

Re: Question about asyncio and blocking operations

2016-01-23 Thread Ian Kelly
On Sat, Jan 23, 2016 at 8:44 AM, Ian Kelly wrote: > This is where it would make sense to me to use callbacks instead of > subroutines. You can structure your __init__ method like this: Doh. s/subroutines/coroutines -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about asyncio and blocking operations

2016-01-23 Thread Ian Kelly
On Sat, Jan 23, 2016 at 7:38 AM, Frank Millman wrote: > Here is the difficulty. The recommended way to handle a blocking operation > is to run it as task in a different thread, using run_in_executor(). This > method is a coroutine. An implication of this is that any method that calls > it must als

Re: Question about asyncio and blocking operations

2016-01-23 Thread Chris Angelico
On Sun, Jan 24, 2016 at 1:38 AM, Frank Millman wrote: > I find I am bumping my head more that I expected, so I thought I would try > to get some feedback here to see if I have some flaw in my approach, or if > it is just in the nature of writing an asynchronous-style application. I don't have a l

Re: Question about how to do something in BeautifulSoup?

2016-01-22 Thread Mario R. Osorio
I think you'd do better using the pyparsing library On Friday, January 22, 2016 at 9:02:00 AM UTC-5, inhahe wrote: > I hope this is an appropriate mailing list for BeautifulSoup questions, > it's been a long time since I've used python-list and I don't remember if > third-party modules are on to

Re: Question about how to do something in BeautifulSoup?

2016-01-22 Thread Peter Otten
inhahe wrote: > I hope this is an appropriate mailing list for BeautifulSoup questions, > it's been a long time since I've used python-list and I don't remember if > third-party modules are on topic. I did try posting to the BeautifulSoup > mailing list on Google groups, but I've waited a day or t

Re: Question about function parameter copy

2016-01-18 Thread Random832
On Mon, Jan 18, 2016, at 13:44, Robert wrote: > cdef inline dtype_t _logsumexp(dtype_t[:] X) nogil: > . > > fwdlattice[t, j] = _logsumexp(work_buffer) + framelogprob[t, j] > > I find that [:] is about object copy, but I am not sure about its usage > here in a function parameter. W

Re: Question on pytest example code

2016-01-10 Thread Terry Reedy
On 1/10/2016 2:38 PM, Robert wrote: Hi, Below is a code snippet from pytest package. It passes pytest, i.e. there is no failure report. # content of test_sysexit.py import pytest def f(): raise SystemExit(1) def test_mytest(): with pytest.raises(SystemExit): f() I se

Re: Question about a class member

2016-01-07 Thread Robert
On Thursday, January 7, 2016 at 5:06:07 PM UTC-5, Steven D'Aprano wrote: > On Fri, 8 Jan 2016 04:23 am, Robert wrote: > > > Hi, > > > > I am using a download package. When I read its code, see below please, I > > don't know what 'sample' is: > > > > > > -- > > model = hmm.GaussianHMM(n_

Re: Question about a class member

2016-01-07 Thread Steven D'Aprano
On Fri, 8 Jan 2016 04:23 am, Robert wrote: > Hi, > > I am using a download package. When I read its code, see below please, I > don't know what 'sample' is: > > > -- > model = hmm.GaussianHMM(n_components=4, covariance_type="full") When I try running that code, I get an error: py> m

Re: Question about a class member

2016-01-07 Thread John Gordon
In Robert writes: > I am using a download package. When I read its code, see below please, I > don't know what 'sample' is: > -- > model = hmm.GaussianHMM(n_components=4, covariance_type="full") > model.startprob_ = startprob > model.transmat_ = transmat > model.means_ = means > mode

Re: Question about a class member

2016-01-07 Thread Robert
On Thursday, January 7, 2016 at 12:24:53 PM UTC-5, Robert wrote: > Hi, > > I am using a download package. When I read its code, see below please, I > don't know what 'sample' is: > > > -- > model = hmm.GaussianHMM(n_components=4, covariance_type="full") > > model.startprob_ = startprob

Re: Question about figure plot

2015-12-15 Thread Robert Kern
On 2015-12-15 02:43, Robert wrote: Hi, When I run the following code, there is no figure shown in the end. // import pymc import numpy as np n = 5*np.ones(4,dtype=int) x = np.array([-.86,-.3,-.05,.73]) alpha = pymc.Normal('alpha',mu=0,tau=.01) beta = pymc.Normal('beta',mu=0,tau=.01)

Re: Question about split method

2015-12-05 Thread Erik
On 05/12/15 20:27, Mark Lawrence wrote: On 05/12/2015 19:51, Robert wrote: On Saturday, December 5, 2015 at 2:29:28 PM UTC-5, Peter Pearson wrote: On Wed, 2 Dec 2015 14:44:30 -0600, Ian Kelly wrote: On Wed, Dec 2, 2015 at 2:37 PM, Robert wrote: [snip] ss0="1, 2, 4, 8, 16".split(", ") [sni

Re: Question about split method

2015-12-05 Thread Mark Lawrence
On 05/12/2015 19:51, Robert wrote: On Saturday, December 5, 2015 at 2:29:28 PM UTC-5, Peter Pearson wrote: On Wed, 2 Dec 2015 14:44:30 -0600, Ian Kelly wrote: On Wed, Dec 2, 2015 at 2:37 PM, Robert wrote: [snip] ss0="1, 2, 4, 8, 16".split(", ") [snip] Try help(str.split) Or if, like me,

Re: Question about split method

2015-12-05 Thread Robert
On Saturday, December 5, 2015 at 2:29:28 PM UTC-5, Peter Pearson wrote: > On Wed, 2 Dec 2015 14:44:30 -0600, Ian Kelly wrote: > > On Wed, Dec 2, 2015 at 2:37 PM, Robert wrote: > [snip] > >> ss0="1, 2, 4, 8, 16".split(", ") > [snip] > > Try help(str.split) > > Or if, like me, you can't remember t

Re: Question about split method

2015-12-05 Thread Peter Pearson
On Wed, 2 Dec 2015 14:44:30 -0600, Ian Kelly wrote: > On Wed, Dec 2, 2015 at 2:37 PM, Robert wrote: [snip] >> ss0="1, 2, 4, 8, 16".split(", ") [snip] > Try help(str.split) Or if, like me, you can't remember the magic word "str", ask: help("".split) and you know you're asking about the right "s

Re: Question about split method

2015-12-02 Thread Robert
On Wednesday, December 2, 2015 at 3:45:34 PM UTC-5, Ian wrote: > On Wed, Dec 2, 2015 at 2:37 PM, Robert wrote: > > Hi, > > > > I learn split method online. When I try to run the line with ss1 beginning, > > I don't understand why its output of ss1 and ss2. I have check the help > > about split. It

Re: Question about split method

2015-12-02 Thread Ian Kelly
On Wed, Dec 2, 2015 at 2:37 PM, Robert wrote: > Hi, > > I learn split method online. When I try to run the line with ss1 beginning, > I don't understand why its output of ss1 and ss2. I have check the help > about split. It looks like that it is a numpy method. > What is the split method parameter

Re: Question about code writing '% i, callback'

2015-12-01 Thread Ian Kelly
On Mon, Nov 30, 2015 at 7:44 PM, Dennis Lee Bieber wrote: > On Mon, 30 Nov 2015 10:55:23 -0800 (PST), fl declaimed > the following: > >>Thanks Ian. I created the class because I want to use the original example >>line >> >> UI.Button("button %s" % i, callback) >> >>Is there another way to use the

Re: Question about code writing '% i, callback'

2015-11-30 Thread fl
On Monday, November 30, 2015 at 12:02:57 PM UTC-5, Ian wrote: > On Mon, Nov 30, 2015 at 10:44 AM, fl wrote: > > I come across the following code snippet. > > > > for i in range(10): > > def callback(): > > print "clicked button", i > > UI.Button("button %s" % i, callback) > > > > T

Re: Question about code writing '% i, callback'

2015-11-30 Thread Ian Kelly
On Mon, Nov 30, 2015 at 10:36 AM, fl wrote: > Thanks for the replies. Now, I have the following code: > > > > class buibutton(): > print 'sd' > def __nonzero__(self): >return False > > def Button(self, ii, callbackk): > callbackk() > return > UI=buibutton() > >

Re: Question about code writing '% i, callback'

2015-11-30 Thread fl
On Monday, November 30, 2015 at 12:37:52 PM UTC-5, Terry Reedy wrote: > On 11/30/2015 11:44 AM, fl wrote: > > > I come across the following code snippet. > > > for i in range(10): > > def callback(): > > print "clicked button", i > > UI.Button("button %s" % i, callback) > > >

Re: Question about code writing '% i, callback'

2015-11-30 Thread fl
On Monday, November 30, 2015 at 11:44:44 AM UTC-5, fl wrote: > Hi, > > I come across the following code snippet. > > > > > > for i in range(10): > def callback(): > print "clicked button", i > UI.Button("button %s" % i, callback) > > > > > The content inside parenthesis in

Re: Question about code writing '% i, callback'

2015-11-30 Thread Terry Reedy
On 11/30/2015 11:44 AM, fl wrote: I come across the following code snippet. for i in range(10): def callback(): print "clicked button", i UI.Button("button %s" % i, callback) http://effbot.org/zone/default-values.htm Note that the above is an intentional example of com

Re: Question about code writing '% i, callback'

2015-11-30 Thread Ian Kelly
On Mon, Nov 30, 2015 at 10:44 AM, fl wrote: > I come across the following code snippet. > > for i in range(10): > def callback(): > print "clicked button", i > UI.Button("button %s" % i, callback) > > The content inside parenthesis in last line is strange to me. > > "button %s" % i

Re: Question about code writing '% i, callback'

2015-11-30 Thread Zachary Ware
On Mon, Nov 30, 2015 at 10:53 AM, Zachary Ware wrote: > On Mon, Nov 30, 2015 at 10:44 AM, fl wrote: >> The content inside parenthesis in last line is strange to me. >> >> "button %s" % i, callback > > https://docs.python.org/library/stdtypes.html#printf-style-string-formatting Sorry, should have

Re: Question about code writing '% i, callback'

2015-11-30 Thread Zachary Ware
On Mon, Nov 30, 2015 at 10:44 AM, fl wrote: > The content inside parenthesis in last line is strange to me. > > "button %s" % i, callback https://docs.python.org/library/stdtypes.html#printf-style-string-formatting -- Zach -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about output different with command dis.dis(code)

2015-11-26 Thread Steven D'Aprano
On Thu, 26 Nov 2015 08:02 pm, fl wrote: > Hi, > > I see the following from a previous post: > > > Python 1.5.2 (#1, Aug 27 2012, 09:09:18) [GCC 4.1.2 20080704 (Red Hat > 4.1.2-52)] on linux2 > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam import dis code = compile("(1

Re: Question about output different with command dis.dis(code)

2015-11-26 Thread Chris Angelico
On Thu, Nov 26, 2015 at 8:02 PM, fl wrote: > Are there something, my input or Python difference > make the output different? Anything involving the disassembly of Python code depends heavily on internal interpreter details. You just quoted something showing that ancient versions of Python did at

Re: Question about output different with command dis.dis(code)

2015-11-26 Thread Random832
fl writes: > Python 1.5.2 (#1, Aug 27 2012, 09:09:18) [GCC 4.1.2 20080704 (Red Hat > 4.1.2-52)] on linux2 The context of the post was discussing the behavior of a very old version of python. I'm not sure how you missed this. > When I run the above three line code, I get the following: Further

Re: Question about 'print' in a loop

2015-11-18 Thread dieter
fl writes: > Hi, > > From previous post, I get many helpful replies. Now I have a new question > when I run this example code: > > > - > sq=[] > for xx in range(5): > print 'here' > sq.append(lambda:xx**2) > ... > sq[2]() > Out[151]: 16 > > sq[3]() > Out[152]: 16 > / Same rea

Re: Question about 'print' in a loop

2015-11-18 Thread fl
On Wednesday, November 18, 2015 at 10:11:24 PM UTC-5, Chris Angelico wrote: > On Thu, Nov 19, 2015 at 1:55 PM, fl wrote: > > There are only one time 5 'here' printed out, but there is no 'here' print > > out in thereafter call sq[2]() etc. How to understand this phenomenon? > > Code does what cod

Re: Question about 'print' in a loop

2015-11-18 Thread Chris Angelico
On Thu, Nov 19, 2015 at 1:55 PM, fl wrote: > There are only one time 5 'here' printed out, but there is no 'here' print > out in thereafter call sq[2]() etc. How to understand this phenomenon? Code does what code should. Before you ask for comprehension of "this phenomenon", why don't you tell u

Re: Question about yield

2015-11-16 Thread Steven D'Aprano
On Sun, 15 Nov 2015 01:37 pm, fl wrote: > Hi, > I have read a couple of tutorial on yield. The following code snippet > still gives me a shock. I am told yield is a little like return. I only > see one yield in the tutorial examples. Here it has two yields. And there > are three variables followin

Re: Question about yield

2015-11-14 Thread Chris Angelico
On Sun, Nov 15, 2015 at 1:37 PM, fl wrote: > Or are there some high relevant tutorial on this? > Start here: https://docs.python.org/3/tutorial/index.html ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about math.pi is mutable

2015-11-14 Thread Antoon Pardon
Op 14-11-15 om 04:11 schreef Michael Torrie: > On 11/10/2015 03:03 AM, Antoon Pardon wrote: >> Op 10-11-15 om 00:29 schreef Ben Finney: >>> >>> Who is doing what to whom? The user of the library isn't doing anything >>> to the library author, so what is it the library author would consent >>> to? I

Re: Question about math.pi is mutable

2015-11-13 Thread Michael Torrie
On 11/10/2015 03:03 AM, Antoon Pardon wrote: > Op 10-11-15 om 00:29 schreef Ben Finney: >> >> Who is doing what to whom? The user of the library isn't doing anything >> to the library author, so what is it the library author would consent >> to? Instead, you seem to be trying to assert a *power* of

Re: Question about math.pi is mutable

2015-11-13 Thread Larry Hudson via Python-list
On 11/13/2015 01:19 AM, Denis McMahon wrote: On Fri, 13 Nov 2015 09:04:54 +1100, Steven D'Aprano wrote: On Fri, 13 Nov 2015 07:40 am, Thomas 'PointedEars' Lahn wrote: [crap I expect] And you should consider the irony, and hypocrisy, of somebody who signs his posts "PointedEars" bitching a

Re: Question about math.pi is mutable

2015-11-13 Thread Denis McMahon
On Fri, 13 Nov 2015 09:04:54 +1100, Steven D'Aprano wrote: > On Fri, 13 Nov 2015 07:40 am, Thomas 'PointedEars' Lahn wrote: > > [crap I expect] > And you should consider the irony, and hypocrisy, of somebody who signs > his posts "PointedEars" bitching about supposed "real names". TPEL has been

Re: Question about math.pi is mutable

2015-11-12 Thread Chris Angelico
On Fri, Nov 13, 2015 at 9:19 AM, BartC wrote: > (FWIW, my real first name is Bart and C is the initial of my last name. Very > dull I know.) That's a common way of signing emails. I sign most of mine "ChrisA", which (as you'll see from my headers) is constructed the same way. So did the late Dave

Re: Question about math.pi is mutable

2015-11-12 Thread BartC
On 12/11/2015 20:40, Thomas 'PointedEars' Lahn wrote: Chris Angelico wrote: […] Ben Finney […] wrote: I recommend you ignore that request; “Bartc” is fine as a name here, IMO. Given that LARTC means Linux Advanced Routing and Traffic Control, I'm guessing Bartc is all about *BSD networking?

Re: Question about math.pi is mutable

2015-11-12 Thread Steven D'Aprano
On Fri, 13 Nov 2015 07:40 am, Thomas 'PointedEars' Lahn wrote: > And on GABELNs [1] it is considered polite to post using your real name. Falsehoods programmers believe about names: http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ > You have been warned. And you

Re: Question about math.pi is mutable

2015-11-12 Thread Thomas 'PointedEars' Lahn
Chris Angelico wrote: > […] Ben Finney […] wrote: >> I recommend you ignore that request; “Bartc” is fine as a name here, >> IMO. > > Given that LARTC means Linux Advanced Routing and Traffic Control, I'm > guessing Bartc is all about *BSD networking? :) I thought LART were the Luser Attitude Re

Re: Question about math.pi is mutable

2015-11-11 Thread Steven D'Aprano
On Wed, 11 Nov 2015 07:30 pm, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Since compile, eval and exec are Python built-ins, if it doesn't >> include a byte-code compiler, it isn't Python. It's just a subset of >> Python. > > compile() can be implemented trivially, or in any other manner. It

Re: Question about math.pi is mutable

2015-11-11 Thread Marko Rauhamaa
Steven D'Aprano : > Since compile, eval and exec are Python built-ins, if it doesn't > include a byte-code compiler, it isn't Python. It's just a subset of > Python. compile() can be implemented trivially, or in any other manner. It simply needs to return a "code object." I suspect even a string

Re: Question about math.pi is mutable

2015-11-10 Thread Steven D'Aprano
On Wednesday 11 November 2015 00:26, BartC wrote: > Does the Python language specify how it is to be compiled and executed? Not in so many words, but there are limitations on what you can do based on the specified semantics of Python. But so long as you meet those semantics, you can implement t

Re: Question about math.pi is mutable

2015-11-10 Thread Steven D'Aprano
On Tue, 10 Nov 2015 11:14 pm, Ben Finney wrote: >> Python -- yes, even CPython -- has a runtime compiler. When you import >> a module, it is compiled (if needed) just before the import. Likewise, >> when you call the `compile`, `eval` or `exec` built-ins, the compiler >> operates. >> >> I'm not ca

Re: Question about math.pi is mutable

2015-11-10 Thread BartC
On 10/11/2015 11:34, Steven D'Aprano wrote: On Tue, 10 Nov 2015 05:10 pm, Ben Finney wrote: I am a Bear of Little Brain, but: Isn't anything that the *compiler* does, by definition done at *compile* time? In a manner of speaking, yes, of course. But you've missed the critical issue: when is

Re: Question about math.pi is mutable

2015-11-10 Thread Ben Finney
Laura Creighton writes: > In a message of Tue, 10 Nov 2015 17:10:09 +1100, Ben Finney writes: > >I am a Bear of Little Brain, but: Isn't anything that the *compiler* > >does, by definition done at *compile* time? > > No. > > We used to have a pretty strict defintion about what a compiler was, > a

Re: Question about math.pi is mutable

2015-11-10 Thread Steven D'Aprano
On Tue, 10 Nov 2015 05:10 pm, Ben Finney wrote: > Steven D'Aprano writes: > >> Ben, I fear that you are not paying attention to me :-) > > Possibly, though I also think there's miscommunication in this thread. > > You speak of “compile time” and “run time”. You also speak of what the > compile

Re: Question about math.pi is mutable

2015-11-10 Thread Laura Creighton
In a message of Tue, 10 Nov 2015 17:10:09 +1100, Ben Finney writes: >Steven D'Aprano writes: > >> Ben, I fear that you are not paying attention to me :-) > >Possibly, though I also think there's miscommunication in this thread. > >You speak of “compile time” and “run time”. You also speak of what

Re: Question about math.pi is mutable

2015-11-10 Thread Antoon Pardon
Op 10-11-15 om 00:29 schreef Ben Finney: > > Who is doing what to whom? The user of the library isn't doing anything > to the library author, so what is it the library author would consent > to? Instead, you seem to be trying to assert a *power* of the library > author to restrict the library user.

Re: Question about math.pi is mutable

2015-11-10 Thread Terry Reedy
On 11/9/2015 9:37 PM, Steven D'Aprano wrote: The compiler doesn't need to decide *in advance* whether the attribute might have changed. It knows whether it has changed or not *at runtime*. You are using 'compiler' when you should, to avoid confusion, use 'interpreter'. It's one thing to sa

Re: Question about math.pi is mutable

2015-11-09 Thread Ben Finney
Steven D'Aprano writes: > Ben, I fear that you are not paying attention to me :-) Possibly, though I also think there's miscommunication in this thread. You speak of “compile time” and “run time”. You also speak of what the compiler can do, at run time. I am a Bear of Little Brain, but: Isn't

Re: Question about math.pi is mutable

2015-11-09 Thread Steven D'Aprano
On Tue, 10 Nov 2015 06:45 am, Ben Finney wrote: > Steven D'Aprano writes: > >> The compiler doesn't need to decide in advance whether or not the >> module attributes have been changed. It can decide that at runtime, >> just before actually looking up the attribute. In pseudo-code: >> >> if a

Re: Question about math.pi is mutable

2015-11-09 Thread Ben Finney
Antoon Pardon writes: > Op 07-11-15 om 04:43 schreef Ben Finney: > > Python assumes the programmers using it are consenting adults. Doing > > harmful things is difficult but not forbidden. > > I find that to be contradictory. Why should you make something difficult > if you are consenting adults?

Re: Question about math.pi is mutable

2015-11-09 Thread Ben Finney
Laura Creighton writes: > In a message of Tue, 10 Nov 2015 06:45:40 +1100, Ben Finney writes: > >So the remaining space of code that is safe for the proposed > >optimisation is trivially small. Why bother with such optimisations, if > >the only code that can benefit is *already* small and simple?

<    1   2   3   4   5   6   7   8   9   10   >