Re: lxml and xpath(?)

2016-10-27 Thread Pete Forman
Peter Otten <__pete...@web.de> writes: > root = etree.fromstring(s) > for server in root.xpath("./server"): > servername = server.xpath("./name/text()")[0] When working with lxml I prefer to use this Python idiom. servername, = server.xpath("./name/text()") That enforces a single result

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread Terry Reedy
On 10/27/2016 1:49 AM, Marko Rauhamaa wrote: Terry Reedy : On 10/26/2016 8:33 AM, Marko Rauhamaa wrote: Maybe there should be some way to get the raw events from the PTY. PTY? Must be Linux-specific. Most beginners are not on Linux. A PTY is an emulated console (https://en.wikipedia.org/

Re: lxml and xpath(?)

2016-10-27 Thread Peter Otten
Pete Forman wrote: > Peter Otten <__pete...@web.de> writes: > >> root = etree.fromstring(s) >> for server in root.xpath("./server"): >> servername = server.xpath("./name/text()")[0] > > When working with lxml I prefer to use this Python idiom. > > servername, = server.xpath("./name/text

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread D'Arcy Cain
On 2016-10-27 03:05 AM, Terry Reedy wrote: When I used unix in the 1980s, the full screen ran csh until one started another full screen application. MSDOS was the same. Every contemporary photo of modern Linux or Mac I have seen has a desktop with windows just like Windows. Do people on Linux s

Re: Reversing \N{...} notation?

2016-10-27 Thread Serhiy Storchaka
On 26.10.16 23:47, Peter Otten wrote: def mynamereplace(exc): return u"".join( "\\N{%s}" % unicodedata.name(c) for c in exc.object[exc.start:exc.end] ), exc.end codecs.register_error("namereplace", mynamereplace) Not all characters has standard na

Re: Iteration, while loop, and for loop

2016-10-27 Thread Veek M
Elizabeth Weiss wrote: > words=["hello", "world", "spam", "eggs"] > counter=0 > max_index=len(words)-1 > > while counter<=max_index: > word=words[counter] > print(word + "!") > counter=counter + 1 while 0 < 10: get 0'th element do something with element increment 0 to 1 (repeat) words[0

AsyncSSH and timeout

2016-10-27 Thread mantaselprj
Good day, I'm trying to run multiple SSH clients using AsyncSSH lib. This is an example from manual, which works fine: http://pastebin.com/zh4zymeQ The problem is, it is not possible to directly set connect timeout in run_client() function. However, the manual says: "asyncio calls can be wrappe

AsyncSSH and timeout

2016-10-27 Thread Standard User
Good day, I'm trying to run multiple SSH clients using AsyncSSH lib. This is an example from manual, which works fine: http://pastebin.com/zh4zymeQ The problem is, it is not possible to directly set connect timeout in run_client() function. However, the manual says: "asyncio calls can be wrapped

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread Terry Reedy
On 10/26/2016 9:12 PM, BartC wrote: On 27/10/2016 00:30, Terry Reedy wrote: Bart, you appear to have been fortunate enough to be spoiled by learning programming on microcomputers, where the terminal and computer are combined into one unit, so that the computer, and potentially the programmer,

Re: How to use two threads (GUI and backend)

2016-10-27 Thread pozz
Il 26/10/2016 16:18, jmp ha scritto: On 10/26/2016 02:45 PM, pozz wrote: Il 26/10/2016 13:16, jmp ha scritto: [...] I suggest you write a GUI that make synchronouscalls to a remote application, if possible. If the remote app is in python, you have access to remote protocols already written

Re: How to use two threads (GUI and backend)

2016-10-27 Thread Demosthenes Koptsis
Here is an example about threads and PyQT https://www.youtube.com/watch?v=ivcxZSHL7jM&index=2 On 10/27/2016 01:22 PM, pozz wrote: Il 26/10/2016 16:18, jmp ha scritto: On 10/26/2016 02:45 PM, pozz wrote: Il 26/10/2016 13:16, jmp ha scritto: [...] I suggest you write a GUI that make synchron

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread BartC
On 27/10/2016 07:51, Steven D'Aprano wrote: On Thursday 27 October 2016 12:12, BartC wrote: I don't understand the argument that a language shouldn't have a basic keyboard API because some computers it could run on might not have a keyboards. That's not the argument. The argument is that Pyth

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread Marko Rauhamaa
Terry Reedy : > Do people on Linux still commonly use full-screen, no window text > editors like the one I had? I occasionally switch on one of the alternate VTs, which are not running any GUI. However, I constantly use -- in fact, as I type, I'm using -- a program running in a PTY environment. I

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread Marko Rauhamaa
BartC : > "There's a room in your house with no door to it; how do I get in?" > > "There's no need for a door because no one ever uses that room! But > you can get in through the chimney - if you /have/ to." +1 > On Linux you can't assume any such resources except some apparently > 1970s-style t

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread BartC
On 27/10/2016 11:07, Terry Reedy wrote: On 10/26/2016 9:12 PM, BartC wrote: On 27/10/2016 00:30, Terry Reedy wrote: So how does your tkinter example work in such a server? Without X-windows available, there would be no point, and it will not work. I presume including the X window subsystem

Re: How to use two threads (GUI and backend)

2016-10-27 Thread jmp
On 10/27/2016 12:22 PM, pozz wrote: Anyway I don't like this approach, because the main (and single) thread should check in_waiting every X milliseconds. If X is too high, I could wait for the answer even if it is already ready in the input buffer. If X is too low, the application consumes a lot

Re: How to use two threads (GUI and backend)

2016-10-27 Thread Chris Angelico
On Thu, Oct 27, 2016 at 10:33 PM, jmp wrote: > On 10/27/2016 12:22 PM, pozz wrote: >> >> Anyway I don't like this approach, because the main (and single) thread >> should check in_waiting every X milliseconds. >> If X is too high, I could wait for the answer even if it is already >> ready in the i

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread Steve D'Aprano
On Thu, 27 Oct 2016 09:42 pm, BartC wrote: > On 27/10/2016 07:51, Steven D'Aprano wrote: >> On Thursday 27 October 2016 12:12, BartC wrote: >> >>> I don't >>> understand the argument that a language shouldn't have a basic keyboard >>> API because some computers it could run on might not have a key

Re: How to use two threads (GUI and backend)

2016-10-27 Thread pozz
Il 27/10/2016 13:33, jmp ha scritto: On 10/27/2016 12:22 PM, pozz wrote: Anyway I don't like this approach, because the main (and single) thread should check in_waiting every X milliseconds. If X is too high, I could wait for the answer even if it is already ready in the input buffer. If X is to

Re: How to use two threads (GUI and backend)

2016-10-27 Thread Chris Angelico
On Thu, Oct 27, 2016 at 10:56 PM, pozz wrote: > Yes of course, but when the backend thread calls the *blocking* function > pyserial.read(), it *doesn't* consume CPU clocks (at least, I hope). > The low-level implementation of pyserial.read() should move the thread in a > "suspend" or "waiting" sta

Re: How to use two threads (GUI and backend)

2016-10-27 Thread jmp
On 10/27/2016 01:43 PM, Chris Angelico wrote: Blocked threads don't consume CPU time. Why would they? ChrisA Agreed. My point being that a blocked thread achieve nothing, except parallelism, i.e. other threads can be processed. To be more specific, if you compute factorial(51354) in a thre

Re: How to use two threads (GUI and backend)

2016-10-27 Thread Chris Angelico
On Thu, Oct 27, 2016 at 11:33 PM, jmp wrote: > On 10/27/2016 01:43 PM, Chris Angelico wrote: >> >> Blocked threads don't consume CPU time. Why would they? >> >> ChrisA >> > > Agreed. My point being that a blocked thread achieve nothing, except > parallelism, i.e. other threads can be processed. >

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread BartC
[repost as original disappeared] On 27/10/2016 12:41, Steve D'Aprano wrote: On Thu, 27 Oct 2016 09:42 pm, BartC wrote: I don't need one character at a time. I want to pause everything else, ask the user a question, and wait for them to enter an entire line. And no, I don't want to reinvent th

Re: How to use two threads (GUI and backend)

2016-10-27 Thread jmp
On 10/27/2016 02:55 PM, Chris Angelico wrote: On Thu, Oct 27, 2016 at 11:33 PM, jmp wrote: On 10/27/2016 01:43 PM, Chris Angelico wrote: Blocked threads don't consume CPU time. Why would they? ChrisA Agreed. My point being that a blocked thread achieve nothing, except parallelism, i.e. ot

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread Marko Rauhamaa
BartC : > If you're executing a billion instructions per second you don't want > to keep stopping every N instructions to ask the user for any special > requests, or to press Enter to continue. In mobile computing, such wakeups drain the battery. Marko -- https://mail.python.org/mailman/listinf

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread Grant Edwards
On 2016-10-27, Marko Rauhamaa wrote: > Grant Edwards : >> I've offered a few times to extend the Linux pty driver to support the >> same set of ioctl calls that a tty does (so that it could be used in >> place of a tty generally), but I've never gotten any response. > > Ah, Linux kernel politics a

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread Grant Edwards
On 2016-10-27, Terry Reedy wrote: > When I used unix in the 1980s, the full screen ran csh until one started > another full screen application. MSDOS was the same. Every contemporary > photo of modern Linux or Mac I have seen has a desktop with windows just > like Windows. Do people on Linux

Re: How to use two threads (GUI and backend)

2016-10-27 Thread D'Arcy Cain
On 2016-10-27 07:33 AM, jmp wrote: On 10/27/2016 12:22 PM, pozz wrote: (blocking) thread. The blocking function read returns *immediately* when all the bytes are received. And I think during blocking time, the thread isn't consuming CPU clocks. Threads do consume CPU clocks. Sometimes they

Windows switch between python 2 and 3

2016-10-27 Thread Daiyue Weng
Hi, I installed Python 2.7 and Python 3.5 64 bit versions on Win 10. Under C:\Python35 C:\Python27 Both have been set in environment variable Path. When I type python in cmd, it only gives me python 2.7, I am wondering how to switch between 2 and 3 in command prompt. cheers -- https://mail.py

Re: multiprocess passing arguments double asterisks

2016-10-27 Thread ricemom
On Wednesday, October 26, 2016 at 5:31:18 PM UTC-5, MRAB wrote: > On 2016-10-26 21:44, pic8...@gmail.com wrote: > > On Monday, October 24, 2016 at 12:39:47 PM UTC-5, Thomas Nyberg wrote: > >> On 10/24/2016 12:45 PM, pic8...@gmail.com wrote: > >> > Thanks for the reply. > >> > > >> > The code snippe

Re: Windows switch between python 2 and 3

2016-10-27 Thread Peter Otten
Daiyue Weng wrote: > Hi, I installed Python 2.7 and Python 3.5 64 bit versions on Win 10. Under > > C:\Python35 > > C:\Python27 > > Both have been set in environment variable Path. > > When I type python in cmd, it only gives me python 2.7, I am wondering how > to switch between 2 and 3 in com

Re: Windows switch between python 2 and 3

2016-10-27 Thread Veek M
Daiyue Weng wrote: > Hi, I installed Python 2.7 and Python 3.5 64 bit versions on Win 10. > Under > > C:\Python35 > > C:\Python27 > > Both have been set in environment variable Path. > > When I type python in cmd, it only gives me python 2.7, I am wondering > how to switch between 2 and 3 in c

Re: Windows switch between python 2 and 3

2016-10-27 Thread Steve D'Aprano
On Fri, 28 Oct 2016 02:11 am, Daiyue Weng wrote: > Hi, I installed Python 2.7 and Python 3.5 64 bit versions on Win 10. Under > > C:\Python35 > > C:\Python27 > > Both have been set in environment variable Path. > > When I type python in cmd, it only gives me python 2.7, I am wondering how > to

Re: Windows switch between python 2 and 3

2016-10-27 Thread Zachary Ware
On Thu, Oct 27, 2016 at 10:11 AM, Daiyue Weng wrote: > Hi, I installed Python 2.7 and Python 3.5 64 bit versions on Win 10. Under > > C:\Python35 > > C:\Python27 > > Both have been set in environment variable Path. > > When I type python in cmd, it only gives me python 2.7, I am wondering how > to

Re: problem using pickle

2016-10-27 Thread Veek M
Rustom Mody wrote: > On Saturday, July 2, 2016 at 9:17:01 AM UTC+5:30, Veek. M wrote: >> object is a keyword and you're using it as an identifier > > keyword and builtin are different > In this case though the advice remains the same > In general maybe not... > Just sayin' np - feel free to corre

Re: problem using pickle

2016-10-27 Thread Veek M
Ben Finney wrote: > "Veek. M" writes: > >> class Foo(object): >> pass >> >> object is a keyword and you're using it as an identifier > > Python does not have ‘object’ as a keyword. ‘and’ is a keyword. > > Here's the difference:: > > >>> object > > >>> object = "Lorem ipsum" >

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread Steve D'Aprano
On Fri, 28 Oct 2016 12:13 am, BartC wrote: > [repost as original disappeared] > On 27/10/2016 12:41, Steve D'Aprano wrote: >> On Thu, 27 Oct 2016 09:42 pm, BartC wrote: > >> I don't need one character at a time. I want to pause everything else, >> ask the user a question, and wait for them to ent

Re: Windows switch between python 2 and 3

2016-10-27 Thread Daiyue Weng
python windows launcher seems like the best option here. thanks On 27 October 2016 at 16:49, Zachary Ware wrote: > On Thu, Oct 27, 2016 at 10:11 AM, Daiyue Weng > wrote: > > Hi, I installed Python 2.7 and Python 3.5 64 bit versions on Win 10. > Under > > > > C:\Python35 > > > > C:\Python27 > >

[PyQT] After MessageBox app quits...why?

2016-10-27 Thread Demosthenes Koptsis
Hello, i have a PyQT systray app with a menu and two actions. Action1 is Exit and action2 display a MessageBox with Hello World message. When i click OK to MessageBox app quits...why? http://pastebin.com/bVA49k1C -- https://mail.python.org/mailman/listinfo/python-list

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread BartC
On 27/10/2016 17:13, Steve D'Aprano wrote: On Fri, 28 Oct 2016 12:13 am, BartC wrote: Doubtless your solution would be some large sledgehammer to crack this particular nut. *shrug* Python's a pretty high-level language. Not every low-level feature needs to be part of the Python language. Th

Re: Windows switch between python 2 and 3

2016-10-27 Thread eryk sun
On Thu, Oct 27, 2016 at 3:41 PM, Steve D'Aprano wrote: > On Fri, 28 Oct 2016 02:11 am, Daiyue Weng wrote: > >> Hi, I installed Python 2.7 and Python 3.5 64 bit versions on Win 10. Under >> >> C:\Python35 >> >> C:\Python27 >> >> Both have been set in environment variable Path. >> >> When I type pyt

How to execute "gksudo umount VirtualDVD"

2016-10-27 Thread Demosthenes Koptsis
I want to execute the command "gksudo umount VirtualDVD" My code is this but it fails: def umount(self): '''unmounts VirtualDVD''' cmd ='gksudo umount VirtualDVD' proc = subprocess.Popen(str(cmd),shell=True,stdout=subprocess.PIPE).stdout.read() print proc It pops up the gksudo dialog,

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread Gregory Ewing
BartC wrote: "There's a room in your house with no door to it; how do I get in?" "There's no need for a door because no one ever uses that room! But you can get in through the chimney - if you /have/ to." It's not like that. The room *does* have a door, it's just that it's in different places

Re: How to execute "gksudo umount VirtualDVD"

2016-10-27 Thread Ian Kelly
On Thu, Oct 27, 2016 at 3:30 PM, Demosthenes Koptsis wrote: > I want to execute the command "gksudo umount VirtualDVD" > > My code is this but it fails: > > def umount(self): > '''unmounts VirtualDVD''' cmd ='gksudo umount VirtualDVD' proc = > subprocess.Popen(str(cmd),shell=True,stdout=subpro

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread BartC
On 27/10/2016 19:09, BartC wrote: On 27/10/2016 17:13, Steve D'Aprano wrote: On Fri, 28 Oct 2016 12:13 am, BartC wrote: print "Enter 3 numbers: " readln a,b,c How is the interpreter supposed to know that a, b, c are numbers? What sort of numbers? 16-bit integers, 80-bit floats, Bignum

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread Chris Angelico
On Fri, Oct 28, 2016 at 9:02 AM, BartC wrote: > > I notice that when it comes to reading command-line arguments, then Python's > sys.argv presents them as a list, not one long string. > > And the list is just a series of strings, so needing to know whether any > parameter was a number or whatever

Installing Python on Windows 7

2016-10-27 Thread Karen Hermann
I just downloaded Python 3.5.2 for Windows, which I installed on a Windows 7 laptop. Disclaimer up front, I am a former lapsed programmer that has been away from it and all things Windows since Windows XP. :)I’m back to being a bit of a newbie again. It’s a relatively clean laptop, just

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread BartC
On 27/10/2016 23:31, Chris Angelico wrote: On Fri, Oct 28, 2016 at 9:02 AM, BartC wrote: I notice that when it comes to reading command-line arguments, then Python's sys.argv presents them as a list, not one long string. And the list is just a series of strings, so needing to know whether any

Re: Installing Python on Windows 7

2016-10-27 Thread eryk sun
On Thu, Oct 27, 2016 at 10:10 PM, Karen Hermann wrote: > > Can you help please, is there something wrong with my system / setup, should > I be > downloading a different Python version? The system is missing the new C runtime. Enable Windows Update and install the recommended updates. -- https:/

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread Chris Angelico
On Fri, Oct 28, 2016 at 10:45 AM, BartC wrote: > On 27/10/2016 23:31, Chris Angelico wrote: >> >> When >> you exec to a process, you provide multiple arguments, not a single >> combined string. > > > Really, there could be dozens of arguments? Windows' CreateProcess() (if > that's the same thing)

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread BartC
On 28/10/2016 01:08, Chris Angelico wrote: On Fri, Oct 28, 2016 at 10:45 AM, BartC wrote: On 27/10/2016 23:31, Chris Angelico wrote: When you exec to a process, you provide multiple arguments, not a single combined string. Really, there could be dozens of arguments? Windows' CreateProcess(

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread Michael Torrie
On 10/27/2016 04:07 AM, Terry Reedy wrote: > As I and others have said, those keyboard functions are not available on > text terminals. I predict that keyboard functions that so not work on > all systems will never become built-ins. But some are available with an > import. Sure you can't get

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread Michael L Torrie
On 10/27/2016 11:05 PM, Michael Torrie wrote: > On 10/27/2016 04:07 AM, Terry Reedy wrote: >> As I and others have said, those keyboard functions are not available on >> text terminals. I predict that keyboard functions that so not work on >> all systems will never become built-ins. But some ar

Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-27 Thread Christian Gollwitzer
Am 28.10.16 um 07:05 schrieb Michael Torrie: On 10/27/2016 04:07 AM, Terry Reedy wrote: As I and others have said, those keyboard functions are not available on text terminals. I predict that keyboard functions that so not work on all systems will never become built-ins. But some are available