Cannot step through asynchronous iterator manually

2016-01-30 Thread Frank Millman
Hi all To loop though an iterator one usually uses a higher-level construct such as a 'for' loop. However, if you want to step through it manually you can do so with next(iter). I expected the same functionality with the new 'asynchronous iterator' in Python 3.5, but I cannot find it. I ca

Re: Mimick tac with python.

2016-01-30 Thread Peter Otten
Christian Gollwitzer wrote: > Am 30.01.16 um 05:58 schrieb Random832: >> On Fri, Jan 29, 2016, at 23:46, Hongyi Zhao wrote: >>> awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file >>> perl -e 'print reverse<>' input_file >> >> Well, both of those read the whole file into memory - tac is som

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Chris Angelico
On Sat, Jan 30, 2016 at 7:22 PM, Frank Millman wrote: > We had a recent discussion about the best way to do this, and ChrisA > suggested the following, which I liked - > >cur.execute('SELECT ...) >try: >row = next(cur) >except StopIteration: ># row does not exist >e

Re: psss...I want to move from Perl to Python

2016-01-30 Thread Larry Hudson via Python-list
On 01/28/2016 04:01 PM, Fillmore wrote: I learned myself Perl as a scripting language over two decades ago. All through this time, I would revert to it from time to time whenever I needed some text manipulation and data analysis script. My problem? maybe I am stupid, but each time I have to g

Re: Mimick tac with python.

2016-01-30 Thread Christian Gollwitzer
Am 30.01.16 um 08:56 schrieb Jussi Piitulainen: Christian Gollwitzer writes: Am 30.01.16 um 05:58 schrieb Random832: On Fri, Jan 29, 2016, at 23:46, Hongyi Zhao wrote: awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file perl -e 'print reverse<>' input_file Well, both of those read th

Re: Mimick tac with python.

2016-01-30 Thread Jussi Piitulainen
Christian Gollwitzer writes: > Am 30.01.16 um 05:58 schrieb Random832: >> On Fri, Jan 29, 2016, at 23:46, Hongyi Zhao wrote: >>> awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file >>> perl -e 'print reverse<>' input_file >> >> Well, both of those read the whole file into memory - tac is so

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Ian Kelly
On Jan 29, 2016 11:04 PM, "Frank Millman" wrote: > > Hi all > > To loop though an iterator one usually uses a higher-level construct such as a 'for' loop. However, if you want to step through it manually you can do so with next(iter). > > I expected the same functionality with the new 'asynchronou

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Chris Angelico
On Sat, Jan 30, 2016 at 7:02 PM, Ian Kelly wrote: > On Jan 29, 2016 11:04 PM, "Frank Millman" wrote: >> >> Hi all >> >> To loop though an iterator one usually uses a higher-level construct such > as a 'for' loop. However, if you want to step through it manually you can > do so with next(iter). >>

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Frank Millman
"Ian Kelly" wrote in message news:CALwzid=ssdsm8hdan+orj54a_jeu9wc8103iqgkaah8mrj-...@mail.gmail.com... On Jan 29, 2016 11:04 PM, "Frank Millman" wrote: > > Hi all > > To loop though an iterator one usually uses a higher-level construct > such as a 'for' loop. However, if you want to step t

Re: psss...I want to move from Perl to Python

2016-01-30 Thread Steven D'Aprano
On Sat, 30 Jan 2016 09:47 am, Ben Finney wrote: > Steven D'Aprano writes: > >> You should have started with the official tutorial: >> >> https://docs.python.org/2/tutorial/ > > And these days the default recommendation should be to start with the > official tutorial for the current stable versi

Re: Mimick tac with python.

2016-01-30 Thread Terry Reedy
On 1/30/2016 1:03 AM, Christian Gollwitzer wrote: Am 30.01.16 um 05:58 schrieb Random832: On Fri, Jan 29, 2016, at 23:46, Hongyi Zhao wrote: awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file perl -e 'print reverse<>' input_file Well, both of those read the whole file into memory - ta

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Maxime S
2016-01-30 11:51 GMT+01:00 Frank Millman : > "Chris Angelico" wrote in message > news:CAPTjJmoAmVNTCKq7QYaDRNQ67Gcg9TxSXYXCrY==s9djjna...@mail.gmail.com... > > >> On Sat, Jan 30, 2016 at 7:22 PM, Frank Millman >> wrote: >> > We had a recent discussion about the best way to do this, and ChrisA >>

Re: Python Scraps, Napkins & Nuggets

2016-01-30 Thread Sayth Renshaw
On Friday, 29 January 2016 17:32:58 UTC+11, Sayth Renshaw wrote: > Hi > > This may seem an odd request, however i thought i would ask do you have any > diagrams, scribbles, presentations you have done when coaching someone at > work that just seems to work for others consistently? > > In coach

Re: The computer that mastered Go

2016-01-30 Thread Ian Kelly
On Fri, Jan 29, 2016 at 1:38 PM, mm0fmf via Python-list wrote: > On 29/01/2016 19:46, Seymore4Head wrote: >> >> https://www.youtube.com/watch?v=g-dKXOlsf98 >> > > Is it written in Python? Given the game, and the fact that it's Google, I would be very disappointed if it's not written in Go. -- ht

[RELEASE] ‘python-daemon’ version 2.1.1 released

2016-01-30 Thread Ben Finney
Howdy all, I am pleased to announce the release of version 2.1.1 of the ‘python-daemon’ library. The current release is always available at https://pypi.python.org/pypi/python-daemon/>. Significant changes since the previous version == Version 2.1.0

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Kevin Conway
To address the original question, I don't believe a next() equivalent for async iterables has been added to the standard library yet. Here's an implementation from one of my projects that I use to manually get the next value: https://bpaste.net/show/e4bd209fc067. It exposes the same interface as th

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Frank Millman
"Maxime S" wrote in message news:CAGqiJR8yUdd1u7j0YHS-He_v4uUT-ui=PpiX=n_G=ntt8zn...@mail.gmail.com... I might be a bit off-topic, but why don't you simply use cursor.rowcount? I just tried that on sqlite3 and pyodbc, and they both return -1. I think that it only works with insert/update/

Re: psss...I want to move from Perl to Python

2016-01-30 Thread Sven R. Kunze
On 29.01.2016 23:49, Ben Finney wrote: "Sven R. Kunze" writes: On 29.01.2016 01:01, Fillmore wrote: How was the Python 2.7 vs Python 3.X solved? which version should I go for? Python 3 is the new and better one. More importantly: Python 2 will never improve; Python 3 is the only one that is

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Frank Millman
"Chris Angelico" wrote in message news:CAPTjJmoAmVNTCKq7QYaDRNQ67Gcg9TxSXYXCrY==s9djjna...@mail.gmail.com... On Sat, Jan 30, 2016 at 7:22 PM, Frank Millman wrote: > We had a recent discussion about the best way to do this, and ChrisA > suggested the following, which I liked - > >cur.execut

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Kevin Conway
> Any particular reason not to use the classic sentinel object model? None that I can remember. I would use the sentinel pattern if I were writing it again today. > Also curious is that you raise a new StopAsyncIteration from the original one, rather than just reraising the original. I assume the

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Chris Angelico
On Sat, Jan 30, 2016 at 11:35 PM, Kevin Conway wrote: > To address the original question, I don't believe a next() equivalent for > async iterables has been added to the standard library yet. Here's an > implementation from one of my projects that I use to manually get the next > value: https://bp

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Oscar Benjamin
On 30 January 2016 at 08:22, Frank Millman wrote: > There are times when I want to execute a SELECT statement, and test for > three possibilities - >- if no rows are returned, the object does not exist >- if one row is returned, the object does exist >- if more that one row is returned

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Frank Millman
"Oscar Benjamin" wrote in message news:cahvvxxsa0yq4voyy6qycgxxvpl5zzgm8muui+1vmezd8crg...@mail.gmail.com... The simplest thing would just be to call list(cur) but I realise that you don't want to consume more than 2 rows from the database so just use islice: rows = list(islice(cur, 2)) # p

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Oscar Benjamin
On 30 January 2016 at 13:45, Frank Millman wrote: > "Oscar Benjamin" wrote in message > news:cahvvxxsa0yq4voyy6qycgxxvpl5zzgm8muui+1vmezd8crg...@mail.gmail.com... >> >> >> The simplest thing would just be to call list(cur) but I realise that > > you don't want to consume more than 2 rows from the

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Oscar Benjamin
On 30 January 2016 at 16:42, Ian Kelly wrote: >> AFAICT there's no generator-function-style syntax for writing an async >> iterator so you'd have to make a class with the appropriate methods if >> you wanted to be able to loop over aslice with async for. > > Before you go any further with this, be

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Ian Kelly
On Jan 30, 2016 7:13 AM, "Oscar Benjamin" wrote: > > I haven't used PEP 492 yet but what about: > > async def aslice(asynciterator, end): > if end == 0: > return [] >items = [] >async for item in asynciterator: >items.append(item) >if len(items) == end: >

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Michael Torrie
On 01/30/2016 01:22 AM, Frank Millman wrote: > There are times when I want to execute a SELECT statement, and test for > three possibilities - > - if no rows are returned, the object does not exist > - if one row is returned, the object does exist > - if more that one row is returned,

Re: Python Unit test

2016-01-30 Thread 4ndre4
On 27/01/2016 04:57, toluagbo...@gmail.com wrote: [...] Here is what the python code looks like and I am to make a Unittest for it Just a few ideas: first of all, you have to make your code more modular, for it to be unit-testable. There are a few areas in your code that need testing: - com

Re: show instant data on webpage

2016-01-30 Thread mustang
So, the python plotting packages mentioned can create files that hold your graphs. As to whether you want to display them on the web or send them around as attachments to your coworkers, or build some local application to display them is your choice Sorry for my confusion :D I'm still not sur

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Chris Angelico
On Sun, Jan 31, 2016 at 6:42 AM, Michael Torrie wrote: > On 01/30/2016 01:22 AM, Frank Millman wrote: >> There are times when I want to execute a SELECT statement, and test for >> three possibilities - >> - if no rows are returned, the object does not exist >> - if one row is returned, the

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Michael Torrie
On 01/30/2016 02:19 PM, Chris Angelico wrote: > Efficiency. That's a fine way of counting actual rows in an actual > table. However, it's massive overkill to perform an additional > pre-query for something that's fundamentally an assertion (this is a > single-row-fetch API like "select into", and i

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Chris Angelico
On Sun, Jan 31, 2016 at 8:52 AM, Michael Torrie wrote: > On 01/30/2016 02:19 PM, Chris Angelico wrote: >> Efficiency. That's a fine way of counting actual rows in an actual >> table. However, it's massive overkill to perform an additional >> pre-query for something that's fundamentally an assertio

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Michael Torrie
On 01/30/2016 02:57 PM, Michael Torrie wrote: > SELECT count(some_id_field),field1,field2,field3 FROM wherever WHERE > conditions > > If the first column (or whatever you decide to alias it as) contains a > count, and the rest of the information is still there. If count is 1, > then the row is wh

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Chris Angelico
On Sun, Jan 31, 2016 at 8:57 AM, Michael Torrie wrote: > On 01/30/2016 02:19 PM, Chris Angelico wrote: >> where the ... is the full original query. In other words, the whole >> query has to be run twice - once to assert that there's exactly one >> result, and then a second time to get that result.

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Michael Torrie
On 01/30/2016 03:06 PM, Chris Angelico wrote: > That actually violates the SQL spec. Some servers will accept it, > others won't. (You're not supposed to mix column functions and > non-column functions.) Are you sure? Wikipedia is not always the most accurate place, but they have several clear e

Re: psss...I want to move from Perl to Python

2016-01-30 Thread Gregory Ewing
Rustom Mody wrote: 1. One can use string-re's instead of compiled re's And I gather that string REs are compiled on first use and cached, so you don't lose much by using them most of the time. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Chris Angelico
On Sun, Jan 31, 2016 at 9:19 AM, Michael Torrie wrote: > On 01/30/2016 03:06 PM, Chris Angelico wrote: >> That actually violates the SQL spec. Some servers will accept it, >> others won't. (You're not supposed to mix column functions and >> non-column functions.) > > Are you sure? Wikipedia is no

Heap Implemenation

2016-01-30 Thread Sven R. Kunze
Hi again, as the topic of the old thread actually was fully discussed, I dare to open a new one. I finally managed to finish my heap implementation. You can find it at https://pypi.python.org/pypi/xheap + https://github.com/srkunze/xheap. I described my motivations and design decisions at

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Gregory Ewing
Michael Torrie wrote: I'm not sure how SQLite handles it, or even what the SQL spec says, but I know in MySQL you could do something like this: SELECT count(id) as row_count,`tablename`.* FROM `tablename` WHERE condition I don't think that's strictly valid SQL. I know of at least one SQL imple

Re: show instant data on webpage

2016-01-30 Thread Mark Lawrence
On 30/01/2016 20:50, mustang wrote: So, the python plotting packages mentioned can create files that hold your graphs. As to whether you want to display them on the web or send them around as attachments to your coworkers, or build some local application to display them is your choice Sorry

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Michael Torrie
On 01/30/2016 02:19 PM, Chris Angelico wrote: > where the ... is the full original query. In other words, the whole > query has to be run twice - once to assert that there's exactly one > result, and then a second time to get that result. The existing > algorithm ("try to fetch a row - if it fails

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Chris Angelico
On Sun, Jan 31, 2016 at 9:05 AM, Michael Torrie wrote: > On 01/30/2016 02:57 PM, Michael Torrie wrote: >> SELECT count(some_id_field),field1,field2,field3 FROM wherever WHERE >> conditions >> >> If the first column (or whatever you decide to alias it as) contains a >> count, and the rest of the in

Re: psss...I want to move from Perl to Python

2016-01-30 Thread Rick Johnson
On Friday, January 29, 2016 at 9:38:23 PM UTC-6, Rustom Mody wrote: > JustForTheRecord[1]: Rick is someone who I sometimes agree with... Thanks for reacting in a rational, cool-headed manner. Many folks, especially the new members of this group, may not understand *WHY* i react so passionately w

Heap Implementation

2016-01-30 Thread Sven R. Kunze
Hi again, as the topic of the old thread actually was fully discussed, I dare to open a new one. I finally managed to finish my heap implementation. You can find it at https://pypi.python.org/pypi/xheap + https://github.com/srkunze/xheap. I described my motivations and design decisions at

Re: Heap Implementation

2016-01-30 Thread Steven D'Aprano
On Sunday 31 January 2016 09:47, Sven R. Kunze wrote: > @all > What's the best/standardized tool in Python to perform benchmarking? timeit -- Steve -- https://mail.python.org/mailman/listinfo/python-list

Re: psss...I want to move from Perl to Python

2016-01-30 Thread Steven D'Aprano
On Sunday 31 January 2016 09:18, Gregory Ewing wrote: > Rustom Mody wrote: >> 1. One can use string-re's instead of compiled re's > > And I gather that string REs are compiled on first use and > cached, so you don't lose much by using them most of the > time. Correct. The re module keeps a cache

Re: psss...I want to move from Perl to Python

2016-01-30 Thread Rustom Mody
On Sunday, January 31, 2016 at 7:27:06 AM UTC+5:30, Steven D'Aprano wrote: > On Sunday 31 January 2016 09:18, Gregory Ewing wrote: > > > Rustom Mody wrote: > >> 1. One can use string-re's instead of compiled re's > > > > And I gather that string REs are compiled on first use and > > cached, so yo

Re: psss...I want to move from Perl to Python

2016-01-30 Thread Rustom Mody
On Sunday, January 31, 2016 at 9:18:31 AM UTC+5:30, Cameron Simpson wrote: > On 30Jan2016 19:22, rusi wrote: > >Python 3.4.3+ (default, Oct 14 2015, 16:03:50) > >[GCC 5.2.1 20151010] on linux > >Type "help", "copyright", "credits" or "license" for more information. > python.el: native completi

x=something, y=somethinelse and z=crud all likely to fail - how do i wrap them up

2016-01-30 Thread Veek. M
I'm parsing html and i'm doing: x = root.find_class(... y = root.find_class(.. z = root.find_class(.. all 3 are likely to fail so typically i'd have to stick it in a try. This is a huge pain for obvious reasons. try: except something: x = 'default_1' (repeat 3 times) Is there some other

Re: x=something, y=somethinelse and z=crud all likely to fail - how do i wrap them up

2016-01-30 Thread Chris Angelico
On Sun, Jan 31, 2016 at 3:58 PM, Veek. M wrote: > I'm parsing html and i'm doing: > > x = root.find_class(... > y = root.find_class(.. > z = root.find_class(.. > > all 3 are likely to fail so typically i'd have to stick it in a try. This is > a huge pain for obvious reasons. > > try: > > exc

Re: psss...I want to move from Perl to Python

2016-01-30 Thread MRAB
On 2016-01-31 01:56:51, "Steven D'Aprano" wrote: On Sunday 31 January 2016 09:18, Gregory Ewing wrote: Rustom Mody wrote: 1. One can use string-re's instead of compiled re's And I gather that string REs are compiled on first use and cached, so you don't lose much by using them most of

Re: psss...I want to move from Perl to Python

2016-01-30 Thread Cameron Simpson
On 30Jan2016 19:22, rusi wrote: Python 3.4.3+ (default, Oct 14 2015, 16:03:50) [GCC 5.2.1 20151010] on linux Type "help", "copyright", "credits" or "license" for more information. python.el: native completion setup loaded import re re._MAXCACHE 512 Have you ever seen a program that uses 512

Re: x=something, y=somethinelse and z=crud all likely to fail - how do i wrap them up

2016-01-30 Thread Veek. M
Chris Angelico wrote: > On Sun, Jan 31, 2016 at 3:58 PM, Veek. M wrote: >> I'm parsing html and i'm doing: >> >> x = root.find_class(... >> y = root.find_class(.. >> z = root.find_class(.. >> >> all 3 are likely to fail so typically i'd have to stick it in a try. This >> is a huge pain for obviou

Re: x=something, y=somethinelse and z=crud all likely to fail - how do i wrap them up

2016-01-30 Thread Veek. M
Veek. M wrote: > Chris Angelico wrote: > >> On Sun, Jan 31, 2016 at 3:58 PM, Veek. M wrote: >>> I'm parsing html and i'm doing: >>> >>> x = root.find_class(... >>> y = root.find_class(.. >>> z = root.find_class(.. >>> >>> all 3 are likely to fail so typically i'd have to stick it in a try. >>> T

Re: Heap Implementation

2016-01-30 Thread srinivas devaki
@Sven actually you are not sweeping at all, as i remember from my last post what i meant by sweeping is periodically deleting the elements which were marked as popped items. kudos on that __setitem__ technique, instead of using references to the items like in HeapDict, it is brilliant of you to si

Re: x=something, y=somethinelse and z=crud all likely to fail - how do i wrap them up

2016-01-30 Thread Steven D'Aprano
On Sun, 31 Jan 2016 03:58 pm, Veek. M wrote: > Is there some other nice way to wrap this stuff up? The answer to "how do I wrap this stuff up?" is nearly always: - refactor your code so you don't need to; - subclass and extend the method; - write a function; - write a delegate class. Pick whi