How to annotate an IntEnum value

2019-09-03 Thread Eko palypse
Suppose the following

from enum import IntEnum

class ENDOFLINE(IntEnum):
CRLF = 0
CR = 1
LF = 2


def get_eol() -> ??:
return ENDOFLINE.CRLF 

def set_eol(eol_value) -> None:
pass


How should the return value from get_eol be annotated? As ENDOFLINE?
The same question for set_eol function, is it assumed to see the following 
declaration?

def set_eol(value: ENDOFLINE) -> None:
pass

I've tried to see what pep484 suggests but either I haven't understood it
or it doesn't go into detail in such a case.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Append some stuff into a file with only the last appended line reserved.

2019-09-03 Thread Hongyi Zhao
On Tue, 03 Sep 2019 08:29:31 +1000, Cameron Simpson wrote:

> Please describe this in more detail. Present a little pycurl output and
> then explain what portion of it should land in the log file.

See the following code from here: 
http://pycurl.io/docs/latest/callbacks.html#xferinfofunction


## Callback function invoked when download/upload has progress
def progress(download_t, download_d, upload_t, upload_d):
print "Total to download", download_t
print "Total downloaded", download_d
print "Total to upload", upload_t
print "Total uploaded", upload_d

c = pycurl.Curl()
c.setopt(c.URL, "http://slashdot.org/";)
c.setopt(c.NOPROGRESS, False)
c.setopt(c.XFERINFOFUNCTION, progress)
c.perform()



If I want to print these info ( or write them into log ) only when some 
specific events occur, say:

pycurl.ABORTED_BY_CALLBACK
pycurl.OPERTATION_TIMEOUT

How to do it?


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


Re: Proper way to pass Queue to process when using multiprocessing.imap()?

2019-09-03 Thread Israel Brewster
> 
> On Sep 3, 2019, at 9:27 AM, Rob Gaddi  
> wrote:
> 
> On 9/3/19 10:17 AM, Israel Brewster wrote:
>> When using pool.imap to apply a function over a list of values, what is the 
>> proper way to pass additional arguments to the function, specifically in my 
>> case a Queue that the process can use to communicate back to the main thread 
>> (for the purpose of reporting progress)? I have seen suggestions of using 
>> starmap, but this doesn’t appear to have a “lazy” variant, which I have 
>> found to be very beneficial in my use case. The Queue is the same one for 
>> all processes, if that makes a difference.
>> I could just make the Queue global, but I have always been told not too. 
>> Perhaps this is an exception?
>>  ---
>> Israel Brewster
>> Software Engineer
>> Alaska Volcano Observatory
>> Geophysical Institute - UAF
>> 2156 Koyukuk Drive
>> Fairbanks AK 99775-7320
>> Work: 907-474-5172
>> cell:  907-328-9145
> 
> The first rule is to never use global variables.  The second is to never put 
> too much stock in sweeping generalizations.  So long as you can keep that 
> Queue's usage pattern fairly well constrained, go ahead and make it global.
> 
> One thing to think about that might make this all easier though; have you 
> looked at the concurrent.futures module?  I find it does a fantastic job of 
> handling this sort of parallelization in a straightforward way.

I’ve only briefly looked at it in other situations. I’ll go ahead and take 
another look for this one. Thanks for the suggestion!

---
Israel Brewster
Software Engineer
Alaska Volcano Observatory 
Geophysical Institute - UAF 
2156 Koyukuk Drive 
Fairbanks AK 99775-7320
Work: 907-474-5172
cell:  907-328-9145

> 
> -- 
> Rob Gaddi, Highland Technology -- www.highlandtechnology.com
> Email address domain is currently out of order.  See above to fix.
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Proper way to pass Queue to process when using multiprocessing.imap()?

2019-09-03 Thread Israel Brewster
> 
> On Sep 3, 2019, at 10:49 AM, Peter Otten <__pete...@web.de> wrote:
> 
> Israel Brewster wrote:
> 
>> When using pool.imap to apply a function over a list of values, what is
>> the proper way to pass additional arguments to the function, specifically
>> in my case a Queue that the process can use to communicate back to the
>> main thread (for the purpose of reporting progress)? I have seen
>> suggestions of using starmap, but this doesn’t appear to have a “lazy”
>> variant, which I have found to be very beneficial in my use case. The
>> Queue is the same one for all processes, if that makes a difference.
>> 
>> I could just make the Queue global, but I have always been told not too.
>> Perhaps this is an exception?
> 
> How about wrapping the function into another function that takes only one 
> argument? A concise way is to do that with functools.partial():
> 
> def f(value, queue): ...
> 
> pool.imap(partial(f, queue=...), values)

That looks like exactly what I was looking for. I’ll give it a shot. Thanks!

---
Israel Brewster
Software Engineer
Alaska Volcano Observatory 
Geophysical Institute - UAF 
2156 Koyukuk Drive 
Fairbanks AK 99775-7320
Work: 907-474-5172
cell:  907-328-9145

> 
> 
> 
>> 
>> ---
>> Israel Brewster
>> Software Engineer
>> Alaska Volcano Observatory
>> Geophysical Institute - UAF
>> 2156 Koyukuk Drive
>> Fairbanks AK 99775-7320
>> Work: 907-474-5172
>> cell:  907-328-9145
>> 
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Proper way to pass Queue to process when using multiprocessing.imap()?

2019-09-03 Thread Peter Otten
Israel Brewster wrote:

> When using pool.imap to apply a function over a list of values, what is
> the proper way to pass additional arguments to the function, specifically
> in my case a Queue that the process can use to communicate back to the
> main thread (for the purpose of reporting progress)? I have seen
> suggestions of using starmap, but this doesn’t appear to have a “lazy”
> variant, which I have found to be very beneficial in my use case. The
> Queue is the same one for all processes, if that makes a difference.
> 
> I could just make the Queue global, but I have always been told not too.
> Perhaps this is an exception?

How about wrapping the function into another function that takes only one 
argument? A concise way is to do that with functools.partial():

def f(value, queue): ...

pool.imap(partial(f, queue=...), values)



>  
> ---
> Israel Brewster
> Software Engineer
> Alaska Volcano Observatory
> Geophysical Institute - UAF
> 2156 Koyukuk Drive
> Fairbanks AK 99775-7320
> Work: 907-474-5172
> cell:  907-328-9145
> 


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


Re: Help needed urgently for running some code!!!!

2019-09-03 Thread Joel Goldstick
On Tue, Sep 3, 2019 at 1:38 PM Dennis Lee Bieber  wrote:
>
> On Mon, 2 Sep 2019 08:05:14 -0700 (PDT), Spencer Du
>  declaimed the following:
>
> >Hi
> >
> >I want to execute
> >
> >"from devicesEmbedded import *": in GUI.py after all code in GUI.py is run. 
> >Also how do I make the devicesEmbedded.py reload and run when a txt file is 
> >created in the name of "list_of_devices.txt" in the GUI.py python program.
> >
> Reload is one of the least effective features. Especially when you 
> have
> bound names locally within modules. "... import *" binds names locally.
> Reloading a changed module creates a new module entry in Python's run-time,
> but any local names still refer to the old module contents.
>
> Please consider reading the documentation:
> https://docs.python.org/3/library/importlib.html
>
> """
>  importlib.reload(module)
>
> Reload a previously imported module. The argument must be a module
> object, so it must have been successfully imported before. This is useful
> if you have edited the module source file using an external editor and want
> to try out the new version without leaving the Python interpreter. The
> return value is the module object (which can be different if re-importing
> causes a different object to be placed in sys.modules).
>
> When reload() is executed:
>
> Python module’s code is recompiled and the module-level code
> re-executed, defining a new set of objects which are bound to names in the
> module’s dictionary by reusing the loader which originally loaded the
> module. The init function of extension modules is not called a second time.
>
> As with all other objects in Python the old objects are only
> reclaimed after their reference counts drop to zero.
>
> The names in the module namespace are updated to point to any new
> or changed objects.
>
> Other references to the old objects (such as names external to the
> module) are not rebound to refer to the new objects and must be updated in
> each namespace where they occur if that is desired.
> """
>
> NOTE the last paragraph. This means you should NOT be using "... import *"
> syntax for anything you might want to have reloaded. Instead use "import
> modulename" and everywhere you access something in that module use the long
> form "modulename.something". This way, when it is reloaded, "modulename"
> will reference the new contents.
>
>
> As for detecting file changes... You will have to periodically check
> the time-stamp (modification time) of the file, and if it changes, reread
> the file.
>
>
>
>
>
> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Spencer, for the past month (almost) you have been sending "urgent"
requests for people here to write code for you.  You've already
decided what needs to be done, but you haven't really explained what
you want to do.  You don't respond to other's responses for further
clarification, or with your progress.  You basically repeat the same
urgent request.  Please don't do this.  There are many python experts
here who will help you, but getting someone to write your code for you
when you can't really explain what your goal is will get you nowhere,
especially since you claim this is for your job.

To me, its an odd thing to want to do imports depending on a file's
contents.  But maybe its a good idea.  However, you can just import
all of the modules you might expect to need, and ignore if they aren't
present with a suitable try/except block.   Try explaining the bigger
picture of what you are trying to do, and maybe you can gain some
incite into a better way of proceeding.  I'm afraid it looks like you
have been cutting and pasting without understanding what your code's
design is all about.  I could be totally wrong.  good luck

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Proper way to pass Queue to process when using multiprocessing.imap()?

2019-09-03 Thread Rob Gaddi

On 9/3/19 10:17 AM, Israel Brewster wrote:

When using pool.imap to apply a function over a list of values, what is the 
proper way to pass additional arguments to the function, specifically in my 
case a Queue that the process can use to communicate back to the main thread 
(for the purpose of reporting progress)? I have seen suggestions of using 
starmap, but this doesn’t appear to have a “lazy” variant, which I have found 
to be very beneficial in my use case. The Queue is the same one for all 
processes, if that makes a difference.

I could just make the Queue global, but I have always been told not too. 
Perhaps this is an exception?
  
---

Israel Brewster
Software Engineer
Alaska Volcano Observatory
Geophysical Institute - UAF
2156 Koyukuk Drive
Fairbanks AK 99775-7320
Work: 907-474-5172
cell:  907-328-9145



The first rule is to never use global variables.  The second is to never put too 
much stock in sweeping generalizations.  So long as you can keep that Queue's 
usage pattern fairly well constrained, go ahead and make it global.


One thing to think about that might make this all easier though; have you looked 
at the concurrent.futures module?  I find it does a fantastic job of handling 
this sort of parallelization in a straightforward way.


--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
--
https://mail.python.org/mailman/listinfo/python-list


Proper way to pass Queue to process when using multiprocessing.imap()?

2019-09-03 Thread Israel Brewster
When using pool.imap to apply a function over a list of values, what is the 
proper way to pass additional arguments to the function, specifically in my 
case a Queue that the process can use to communicate back to the main thread 
(for the purpose of reporting progress)? I have seen suggestions of using 
starmap, but this doesn’t appear to have a “lazy” variant, which I have found 
to be very beneficial in my use case. The Queue is the same one for all 
processes, if that makes a difference.

I could just make the Queue global, but I have always been told not too. 
Perhaps this is an exception?
 
---
Israel Brewster
Software Engineer
Alaska Volcano Observatory 
Geophysical Institute - UAF 
2156 Koyukuk Drive 
Fairbanks AK 99775-7320
Work: 907-474-5172
cell:  907-328-9145

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


Re: TypeError: loadtxt() got an unexpected keyword argument 'max_rows'

2019-09-03 Thread MRAB

On 2019-09-03 17:29, Terry Reedy wrote:

On 9/3/2019 12:02 PM, alberto wrote:

Hi,
I produce a script to elaborate data

but command line $ python3.4 PlotnhvsvdBTP1.py

I have this error

Traceback (most recent call last):
File "PlotnhvsvdBTP1.py", line 31, in 
UCvol = np.loadtxt(outputtransfile,skiprows=26,max_rows=1,usecols=[1])
TypeError: loadtxt() got an unexpected keyword argument 'max_rows'

How could fix it?


Don't do what the message says is the wrong thing to do.  Really.

In particular, don't pass 'max_rows=1'.  To find out what *to* do, read
the doc for the loadtxt function.  From 'skiprows' and 'usecols', with
no underscore, I suspect you should pass 'maxrows=1'.


No, the documentation says "max_rows".

Apparently, consistency, like the argument, is optional. :-)
--
https://mail.python.org/mailman/listinfo/python-list


Re: TypeError: loadtxt() got an unexpected keyword argument 'max_rows'

2019-09-03 Thread MRAB

On 2019-09-03 17:02, alberto wrote:

Hi,
I produce a script to elaborate data

but command line $ python3.4 PlotnhvsvdBTP1.py

I have this error

Traceback (most recent call last):
File "PlotnhvsvdBTP1.py", line 31, in 
UCvol = np.loadtxt(outputtransfile,skiprows=26,max_rows=1,usecols=[1])
TypeError: loadtxt() got an unexpected keyword argument 'max_rows'

How could fix it?

I attacched my files

https://drive.google.com/file/d/1PgOcuEMFsaAuKTsbU0i0gwg04mDCJJoK/view?usp=sharing
https://drive.google.com/file/d/13E7vcGQtrOS1lw9RupGThGQ2vSGRfTFG/view?usp=sharing
https://drive.google.com/file/d/1Z6GKYtHthAyPO3wFHUFK10QweRpclu29/view?usp=sharing


The "max_rows" keyword argument is new in numpy version 1.16.0.

Which version do you have?

Try:

import numpy
print(numpy.__version__)
to find out.
--
https://mail.python.org/mailman/listinfo/python-list


Re: TypeError: loadtxt() got an unexpected keyword argument 'max_rows'

2019-09-03 Thread Terry Reedy

On 9/3/2019 12:02 PM, alberto wrote:

Hi,
I produce a script to elaborate data

but command line $ python3.4 PlotnhvsvdBTP1.py

I have this error

Traceback (most recent call last):
File "PlotnhvsvdBTP1.py", line 31, in 
UCvol = np.loadtxt(outputtransfile,skiprows=26,max_rows=1,usecols=[1])
TypeError: loadtxt() got an unexpected keyword argument 'max_rows'

How could fix it?


Don't do what the message says is the wrong thing to do.  Really.

In particular, don't pass 'max_rows=1'.  To find out what *to* do, read 
the doc for the loadtxt function.  From 'skiprows' and 'usecols', with 
no underscore, I suspect you should pass 'maxrows=1'.


--
Terry Jan Reedy

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


Re: TypeError: loadtxt() got an unexpected keyword argument 'max_rows'

2019-09-03 Thread Rhodri James

On 03/09/2019 17:02, alberto wrote:

I have this error

Traceback (most recent call last):
File "PlotnhvsvdBTP1.py", line 31, in 
UCvol = np.loadtxt(outputtransfile,skiprows=26,max_rows=1,usecols=[1])
TypeError: loadtxt() got an unexpected keyword argument 'max_rows'

How could fix it?


A quick google search suggests that you aren't using a recent enough 
version of numpy.  The "max_rows" keyword argument was added to 
loadtxt() in version 1.16.0; you must be using an older version than 
that.  Your options are to upgrade the version of numpy you have (don't 
ask me how, I've never used it) or delete the "max_rows=1" and accept 
the inefficiency.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: TypeError: loadtxt() got an unexpected keyword argument 'max_rows'

2019-09-03 Thread Joel Goldstick
On Tue, Sep 3, 2019 at 12:06 PM alberto  wrote:
>
> Hi,
> I produce a script to elaborate data
>
> but command line $ python3.4 PlotnhvsvdBTP1.py
>
> I have this error
>
> Traceback (most recent call last):
> File "PlotnhvsvdBTP1.py", line 31, in 
> UCvol = np.loadtxt(outputtransfile,skiprows=26,max_rows=1,usecols=[1])
> TypeError: loadtxt() got an unexpected keyword argument 'max_rows'
>
> How could fix it?
>
> I attacched my files
>
> https://drive.google.com/file/d/1PgOcuEMFsaAuKTsbU0i0gwg04mDCJJoK/view?usp=sharing
> https://drive.google.com/file/d/13E7vcGQtrOS1lw9RupGThGQ2vSGRfTFG/view?usp=sharing
> https://drive.google.com/file/d/1Z6GKYtHthAyPO3wFHUFK10QweRpclu29/view?usp=sharing
>
> regard
>
> Alberto

Please don't attach files.  Cut and paste code as text into email body
along with copy and pasted traceback.

That said I found this:.. versionadded:: 1.14.0
max_rows : int, optional

Check your version of loadtxt()?
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


TypeError: loadtxt() got an unexpected keyword argument 'max_rows'

2019-09-03 Thread alberto
Hi, 
I produce a script to elaborate data 

but command line $ python3.4 PlotnhvsvdBTP1.py 

I have this error 

Traceback (most recent call last):
File "PlotnhvsvdBTP1.py", line 31, in 
UCvol = np.loadtxt(outputtransfile,skiprows=26,max_rows=1,usecols=[1])
TypeError: loadtxt() got an unexpected keyword argument 'max_rows'

How could fix it?

I attacched my files

https://drive.google.com/file/d/1PgOcuEMFsaAuKTsbU0i0gwg04mDCJJoK/view?usp=sharing
https://drive.google.com/file/d/13E7vcGQtrOS1lw9RupGThGQ2vSGRfTFG/view?usp=sharing
https://drive.google.com/file/d/1Z6GKYtHthAyPO3wFHUFK10QweRpclu29/view?usp=sharing

regard

Alberto
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Execute complex shell commands within python and obtain the output.

2019-09-03 Thread Hongyi Zhao
On Tue, 03 Sep 2019 17:27:59 +1000, Cameron Simpson wrote:

> It was merely that it is hardwired in your code (and you need to wire in
> something). Just keep in mind that _if_ this script runs in a non-utf8
> environment the decoding may be wrong. Unlikely to actually happen
> though.

Thanks, fixed with the following:

import subprocess,locale

a=locale.getdefaultlocale()
cmd=...
ps=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE) 
output =ps.communicate()[0].decode(a[1])

Regards


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


Re: problem occurring in operating python , after typing only 5-6 programs only is causing problem it has stoped working

2019-09-03 Thread Calvin Spealman
You will need to provide more information:

What version of Python are running?

What sort of error message you receiving (paste the entire error)?

What code are you attempting to run which causes this problem (paste the
failing code)?

On Sun, Sep 1, 2019 at 3:01 PM best web site 
wrote:

>
>
> Sent from Mail for Windows 10
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 

CALVIN SPEALMAN

SENIOR QUALITY ENGINEER

cspea...@redhat.com  M: +1.336.210.5107
[image: https://red.ht/sig] 
TRIED. TESTED. TRUSTED. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed to run some code!!!!

2019-09-03 Thread Calvin Spealman
It sounds like you have module-level behavior you don't want to happen
during normal import-time. If that is the case, move that behavior into a
class or function you can invoke at the correct time, rather than trying to
do your imports at strange times.

On Mon, Sep 2, 2019 at 11:50 AM Spencer Du  wrote:

> Hi
>
> How can I execute "from devicesEmbedded import *" after this:
> "print("Device added to list")" in GUI.py because currently if I have the
> import added at the top of GUI.py file it always executes first before the
> GUI.py file is executed. I want the devicesEmbedded.py to execute after
> GUI.py has executed first.
>
> Thanks
> Spencer
>
> GUI.py
>
> import logging
> from datetime import timedelta
> import time
> from thespian.actors import *
> from transitions import Machine
> import paho.mqtt.client as mqtt
> import importlib
> import os
> import os.path
> import sys
> from PyQt5.QtWidgets import *
> from PyQt5.QtCore import *
> from PyQt5 import QtWidgets, uic
> from mqtt import *
> # from devicesEmbedded import *
> import json
>
> class MainWindow(QtWidgets.QMainWindow):
> def __init__(self,parent = None):
> QMainWindow.__init__(self)
> super(MainWindow, self).__init__(parent)
> self.mdi = QMdiArea()
> self.setCentralWidget(self.mdi)
>
> self.setMinimumSize(QSize(800, 600))
> self.setWindowTitle("PyQt button example -
> pythonprogramminglanguage.com")
>
> pybutton = QPushButton('Add device', self)
>
> pybutton.clicked.connect(self.importbutton)
>
> pybutton.move(100, 400)
> pybutton.resize(150, 32)
>
> self.textbox = QLineEdit(self)
> self.textbox.move(100,350)
> self.textbox.resize(100, 32)
>
> self.fileName_UI = ""
>
> def importbutton(self):
> self.fileName_UI = self.textbox.text()
> self.loadGUI()
>
> def getGUIFilename(self):
> return self.fileName_UI
>
> def loadGUI(self):
> print("Searching file", self.fileName_UI)
> try:
> module = __import__(self.fileName_UI)
> my_class = getattr(module, "SubWindow")
>
> sub = QMdiSubWindow()
>
> sub.setWidget(my_class())
> sub.setWindowTitle("New GUI:  " + self.fileName_UI)
> self.mdi.addSubWindow(sub)
> sub.show()
>
> print("creating new instance " + self.fileName_UI)
> client = device("Device")
> client.run()
>
> client.loop_start()  # start the loop
> # device_message = self.fileName_UI
> time.sleep(2)
> print("Subscribing to topic",
> "microscope/light_sheet_microscope/UI")
> client.subscribe("microscope/light_sheet_microscope/UI")
> print("Publishing message to topic",
> "microscope/light_sheet_microscope/UI/list_of_devices")
>
> client.publish("microscope/light_sheet_microscope/UI/list_of_devices",
> json.dumps({"type": "device", "payload":{"name": self.fileName_UI, "cmd":
> "adding device"}}, indent=2))
> time.sleep(1)  # wait
> client.loop_stop()  # stop the loop
> print("Device added" + "\n")
>
> client.run()
> client.loop_start()
> time.sleep(2)
> print("Subscribing to topic",
> "microscope/light_sheet_microscope/UI/list_of_devices")
>
> client.subscribe("microscope/light_sheet_microscope/UI/list_of_devices")
> print("Publishing message to topic",
> "microscope/light_sheet_microscope/UI/list_of_devices")
>
> client.publish("microscope/light_sheet_microscope/UI/list_of_devices",
> self.fileName_UI + " added to device list")
> time.sleep(1)
> client.loop_stop()
>
> listofdevices = []
> listofdevices.append(self.fileName_UI)
> with open("list_of_devices.txt", "a+") as myfile:
> for item in listofdevices:
> myfile.write(item + ",")
>
>
> print(item)
> print(listofdevices)
> print("Device added to list")
> except:
> print("creating new instance " + self.fileName_UI)
> client = device("Device")
> client.run()
>
> client.loop_start()  # start the loop
> device_message = self.fileName_UI
> time.sleep(2)
> print("Subscribing to topic",
> "microscope/light_sheet_microscope/UI")
> client.subscribe("microscope/light_sheet_microscope/UI")
> print("Publishing message to topic",
> "microscope/light_sheet_microscope/UI")
> client.publish("microscope/light_sheet_microscope/UI",
> json.dumps({"type": "device", "payload":{"name": self.fileName_UI}},
> indent=2))
> time.sleep(2)  # wait
> client.loop_stop()  # stop the loop
> print(device_message + ".py " + "file doesn't exist")
> print("Device not a

Re: if STREAM.isatty():

2019-09-03 Thread Rhodri James

On 30/08/2019 12:05, Hongyi Zhao wrote:

On Fri, 30 Aug 2019 18:42:51 +1000, Chris Angelico wrote:


There is no magic here. It is simply asking a question, and then making
a decision based on the answer.


What's your mean by saying this?  Sorry for my poor English.


"No 'magic'" (魔法 if Google is to be trusted :-) means here that there is 
nothing complicated and strange going on in the background. 
"STREAM.isatty()" just asks a question -- is this a tty? -- and the 
answer will always be the same for the same STREAM.  Either it is a tty 
or it isn't, it will not change from one to the other.  It's exactly 
like "STRING.isnumeric()"; for the same string it will always give the 
same answer.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: a,b = 2,3 and [a,b] = [2,3]

2019-09-03 Thread Serhiy Storchaka

03.09.19 11:02, Chris Angelico пише:

On Tue, Sep 3, 2019 at 5:53 PM Serhiy Storchaka  wrote:


02.09.19 12:24, Chris Angelico пише:

But the curious difference happens in 3.7. I don't know what changed
to cause this, but from there on, the list gets built and then
unpacked.


This was a side effect of moving the optimization for `x in [a, b]` from
the peepholer to the AST optimizer.



Ah ha. Thank you.

Is it worth trying to reinstate that? On the one hand, there's no
reason to build the list, and this technically is a (performance)
regression. On the other hand, it's not code people actually write,
since you can do the same thing with a tuple and it IS optimized.


I tried this.

Adding such optimization on the AST level will add around 30 lines of 
code, but will allow to optimize more complex cases like `[a, b] = [c, 
d] = [1, 2]` or `[a, *b] = [*c, d] = [1, 2]`.


Reintroducing it in the peepholer needs less changes, but will optimize 
only narrow set of special cases.


In any case the benefit looks too small. It may even be that the 
original optimization was not intended, but a side effect of the 
optimization for `x in [a, b]`.


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


Re: a,b = 2,3 and [a,b] = [2,3]

2019-09-03 Thread Chris Angelico
On Tue, Sep 3, 2019 at 5:53 PM Serhiy Storchaka  wrote:
>
> 02.09.19 12:24, Chris Angelico пише:
> > But the curious difference happens in 3.7. I don't know what changed
> > to cause this, but from there on, the list gets built and then
> > unpacked.
>
> This was a side effect of moving the optimization for `x in [a, b]` from
> the peepholer to the AST optimizer.
>

Ah ha. Thank you.

Is it worth trying to reinstate that? On the one hand, there's no
reason to build the list, and this technically is a (performance)
regression. On the other hand, it's not code people actually write,
since you can do the same thing with a tuple and it IS optimized.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: a,b = 2,3 and [a,b] = [2,3]

2019-09-03 Thread Serhiy Storchaka

02.09.19 12:24, Chris Angelico пише:

But the curious difference happens in 3.7. I don't know what changed
to cause this, but from there on, the list gets built and then
unpacked.


This was a side effect of moving the optimization for `x in [a, b]` from 
the peepholer to the AST optimizer.


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


Re: Execute complex shell commands within python and obtain the output.

2019-09-03 Thread Cameron Simpson

On 03Sep2019 03:59, Hongyi Zhao  wrote:

On Tue, 03 Sep 2019 08:24:17 +1000, Cameron Simpson wrote:

Finally, the .decode('utf8') assumes your locale is UTF8 based. It
probably is, but if it isn't then you may get mojibake.


Nowadays, most of the os use utf8 as the default locale.  Am I wrong?


You are not wrong. So it is pretty safe to do what you did.

It was merely that it is hardwired in your code (and you need to wire in 
something). Just keep in mind that _if_ this script runs in a non-utf8 
environment the decoding may be wrong. Unlikely to actually happen 
though.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list