From bluebox03 at gmail.com Fri Mar 1 09:39:48 2019 From: bluebox03 at gmail.com (tommy yama) Date: Fri, 1 Mar 2019 23:39:48 +0900 Subject: how to setup for localhost:8000 In-Reply-To: <20190225034616.GA20568@cskk.homeip.net> References: <20190225034616.GA20568@cskk.homeip.net> Message-ID: Here you go A port can be configurable. https://www.tutorialspoint.com/python/python_http_server.htm On Mon, Feb 25, 2019 at 12:48 PM Cameron Simpson wrote: > On 24Feb2019 19:00, 0x906 wrote: > >>> I am working on window 7 and Python 3.5 to setup a localhost:8000 > >>> but it did not get through as shown below: > >>>> python -m http.server > >>> Serving HTTP on 0.0.0.0 port 8000 ... > >>> But it did not show the results. > >>> Can someone help me how to setup the localhost? > > > >There is a chance that I missed something with the 0.0.0.0. but I am > pretty sure that the localhost IP is 127.0.0.1. > > Yeah. 0.0.0.0 is the wildcard address: the server will be listening on > all the available addresses (127.0.0.1 and also any LAN address). > > Wen-Ruey may simply be missing that it is just running a web server. To > actually see anything she/he needs to hit it with a web browser, for > example with a URL like: > > http://127.0.0.1:8000/ > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > From songbird at anthive.com Fri Mar 1 08:48:59 2019 From: songbird at anthive.com (songbird) Date: Fri, 1 Mar 2019 08:48:59 -0500 Subject: revisiting the "What am I running on?" question References: <7d52f95b-66fd-9919-da2f-25208a57ea85@potatochowder.com> <272619c5-9a99-dbb9-2f7e-939baf563a5b@tjol.eu> Message-ID: Terry Reedy wrote: > On 2/22/2019 7:55 AM, songbird wrote: >> eryk sun wrote: >> ... >>> The win-amd64 ABI is significantly different, but at the API level >>> there isn't a drastic difference between 32-bit and 64-bit Windows, so >>> there's no cognitive burden with perpetuating the Win32 name. The >>> official API name was actually changed to "Windows API" or WINAPI (or >>> WinAPI). But it would require a massive effort to change the culture. >>> There's no pressing need to expend that much time and energy over a >>> name. >> >> just adding a comment to the documentation that >> win32 also covers win64 would be a help IMO. > > Could you open an issue on the tracker suggesting a specific edit at a > specific place? i don't want to create yet another account to file a bug/issue, but the specific place in the docs is: https://docs.python.org/3/library/sys.html?highlight=sys%20platform#sys.platform songbird From matthew.thompson at nasa.gov Fri Mar 1 10:35:24 2019 From: matthew.thompson at nasa.gov (Thompson, Matt (GSFC-610.1)[SCIENCE SYSTEMS AND APPLICATIONS INC]) Date: Fri, 1 Mar 2019 10:35:24 -0500 Subject: Version numbers in Standard Library Message-ID: Dear Python List, A question. I help maintain a Python stack for users in my division here at NASA and one user asked about updating the re module to 2.4. I believe because he read the docs: https://docs.python.org/2.7/library/re.html where you see lines like "New in version 2.4" and he also did: $ python2 -c 'import re; print (re.__version__)' 2.2.1 And, well, one can think "oh, a newer version is needed". I searched on conda, etc. and can't find it and finally realized that 2.4 meant Python 2.4, not re 2.4. (The 3.7 docs have lines like "Changed in version 3.7".) My question to the pros here is what purpose do the __version__/version variables serve in the Python Standard Library? I can understand in external packages, but once in the Standard Library...? For example, in re.py, that line was last changed 18 years ago according to git blame. In tarfile.py, the version string was last changed 12 years ago. But in both, the modules were edited in 2018 so they haven't been static for a decade. Are those strings there just for historic purposes? Not a big deal, I was just wondering. Thanks, Matt -- Matt Thompson, SSAI, Sr Scientific Programmer/Analyst NASA GSFC, Global Modeling and Assimilation Office Code 610.1, 8800 Greenbelt Rd, Greenbelt, MD 20771 Phone: 301-614-6712 Fax: 301-614-6246 http://science.gsfc.nasa.gov/sed/bio/matthew.thompson From skip.montanaro at gmail.com Fri Mar 1 15:41:06 2019 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 1 Mar 2019 14:41:06 -0600 Subject: Version numbers in Standard Library In-Reply-To: References: Message-ID: The point of the "Changed in version ..." or "New in version ..." bits in the documentation is to alert readers who maintain software which needs to remain backward compatible with older versions of Python. If you maintain a package which you support for Python 3.4, 3.5, 3.6, and 3.7, you'll probably shy away from bits which weren't around for 3.4, and be careful about APIs which have changed since 3.4. Skip From python at mrabarnett.plus.com Fri Mar 1 15:41:38 2019 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 1 Mar 2019 20:41:38 +0000 Subject: Extension Module for Python 3.6 + In-Reply-To: <5b2bcbc6-e5e4-bd56-ab99-1a2eb1d57856@btinternet.com> References: <5b2bcbc6-e5e4-bd56-ab99-1a2eb1d57856@btinternet.com> Message-ID: <1aabd6e2-9459-4bee-664e-292d8f7a46b2@mrabarnett.plus.com> On 2019-03-01 01:19, Anthony Flury via Python-list wrote: > In my brave and noble quest to get to grips with the CAPI - I am trying > to write a C extension module which provides a new class > > The exact details are not important, but what is important is that > instances of my new class are imutable, and therefore from time to time, > my extension module needs to build a new instance of my extension class. > > The documentation is pretty sparse here, and suggests using PyObject_New > & PyObject_Init but gives no examples. > > An internet search suggests using PyObject_CallObject in some way - but > the examples here are call backs to Python functions. > > What is the canonical way to create New Instances of the Extension Type > from within the Extension Module - even if someone can point me to a > working example that would be great. > > Another option would be to call the extension class new and init > functions directly - is there a reason that is not allowed ? > > PS - I think I also need to use Py_BuildValue to 'encapsulate' the > initial arguments for the new instance - or could I just build a 'blank' > instance and then directly set the fields as neccessary ? > Here's an example that exports a 'make' factory function to create a new instance. Hope it helps: ----8<---- class_example.c ----8<---- #include "Python.h" #include "structmember.h" /* offsetof */ /* The MyClassObject. */ typedef struct MyClassObject { PyObject_HEAD PyObject* weakreflist; /* List of weak references. */ PyObject* value; } MyClassObject; /* The MyClass_Type. */ static PyTypeObject MyClass_Type = { PyVarObject_HEAD_INIT(NULL, 0) "class_example.MyClass", sizeof(MyClassObject) }; /* Makes an instance with the given value. */ Py_LOCAL_INLINE(PyObject*) myclass_make(PyObject* self_, PyObject* args, PyObject* kwargs) { PyObject* value; MyClassObject* instance; static char* kwlist[] = { "value", NULL }; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &value)) return NULL; instance = PyObject_New(MyClassObject, &MyClass_Type); if (!instance) return NULL; instance->value = value; Py_INCREF(instance->value); return (PyObject*)instance; } /* Deallocates a MyClassObject. */ static void myclass_dealloc(PyObject* self_) { MyClassObject* self; self = (MyClassObject*)self_; Py_DECREF(self->value); PyObject_DEL(self); } /* The documentation of a MyClassObject. */ PyDoc_STRVAR(myclass_doc, "MyClass object"); /* The methods of a MyClassObject. */ static PyMethodDef myclass_methods[] = { /* The instance methods here. */ {NULL, NULL} }; /* The members of a MyClassObject. */ static PyMemberDef myclass_members[] = { {"value", T_OBJECT, offsetof(MyClassObject, value), READONLY, "The stored value."}, {NULL} /* Sentinel */ }; PyDoc_STRVAR(myclass_make_doc, "make(value) --> MyClassObject.\n" " Makes a MyClass object."); /* The table of the module's functions. */ static PyMethodDef functions[] = { { "make", (PyCFunction)myclass_make, METH_VARARGS | METH_KEYWORDS, myclass_make_doc }, { NULL, NULL } }; /* The module definition. */ static struct PyModuleDef class_example_module = { PyModuleDef_HEAD_INIT, "class_example", NULL, -1, functions, NULL, NULL, NULL, NULL }; /* Initialises the module. */ PyMODINIT_FUNC PyInit_class_example(void) { PyObject* this_module; /* Initialise the MyClass_Type. */ MyClass_Type.tp_dealloc = myclass_dealloc; MyClass_Type.tp_flags = Py_TPFLAGS_DEFAULT; MyClass_Type.tp_doc = myclass_doc; MyClass_Type.tp_weaklistoffset = offsetof(MyClassObject, weakreflist); MyClass_Type.tp_methods = myclass_methods; MyClass_Type.tp_members = myclass_members; if (PyType_Ready(&MyClass_Type) < 0) return NULL; /* Create the module. */ this_module = PyModule_Create(&class_example_module); if (!this_module) return NULL; /* This makes MyClass visible, but won't let you create an instance. Useful * with Python's isinstance function. */ if (PyModule_AddObject(this_module, "MyClass", (PyObject*)&MyClass_Type) != 0) return NULL; return this_module; } ----8<---- test_example.py ----8<---- #!python3.7 # -*- coding: utf-8 -*- import class_example from class_example import make instance = make(0) print(instance) print(instance.value) # Cannot change the attribute: #instance.value = 1 From alan at csail.mit.edu Fri Mar 1 17:27:39 2019 From: alan at csail.mit.edu (Alan Bawden) Date: 01 Mar 2019 17:27:39 -0500 Subject: Lifetime of a local reference References: <8736oai5c7.fsf@elektro.pacujo.net> <86pnrd2a95.fsf@richard.bawden.org> <86k1hk1jhx.fsf@richard.bawden.org> Message-ID: <86ef7q1b8k.fsf@richard.bawden.org> ram at zedat.fu-berlin.de (Stefan Ram) writes: > Alan Bawden writes: > >The Java compiler has no way to know whether a variable references an > >object with a finalize() method that has side effects > > java.lang.Object#finalize() is deprecated since Java 9. And we are advised to use a "Cleaner" or a "PhantomReference" instead. So there are still non-deprecated mechanisms in Java 11 you can use to run cleanup code when an object becomes unreachable. And the language I quoted from the Java 8 spec is still there in the Java 11 spec. So the situation is unchanged with respect to the point I was making. -- Alan Bawden From greg.ewing at canterbury.ac.nz Fri Mar 1 19:32:53 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 02 Mar 2019 13:32:53 +1300 Subject: Lifetime of a local reference In-Reply-To: <86k1hk1jhx.fsf@richard.bawden.org> References: <8736oai5c7.fsf@elektro.pacujo.net> <86pnrd2a95.fsf@richard.bawden.org> <86k1hk1jhx.fsf@richard.bawden.org> Message-ID: Alan Bawden wrote: > The Java compiler has no way to know whether a variable references an > object with a finalize() method that has side effects It should be able to tell in some situations, e.g. String a = "hello"; String b = a.replace('e', 'u'); There's no way that b can reference anything other than a plain String instance at this point. Maybe Java implementations are living dangerously and making assumptions beyond this. My point is that I would expect a Python implementation to be careful enough not to get this wrong. -- Greg From arj.python at gmail.com Sun Mar 3 02:21:09 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 3 Mar 2019 11:21:09 +0400 Subject: deque as default list behaviour Message-ID: simple question; why does the normal list not exhibit a deque behaviour (left insertion)? -- Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius From rosuav at gmail.com Sun Mar 3 02:44:45 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Mar 2019 18:44:45 +1100 Subject: deque as default list behaviour In-Reply-To: References: Message-ID: On Sun, Mar 3, 2019 at 6:17 PM Abdur-Rahmaan Janhangeer wrote: > > simple question; why does the normal list not exhibit a deque behaviour > (left insertion)? Because it's a lot less efficient. If you want that behaviour, you CAN still insert into a list at position zero, but it's going to be slow on large lists; or if you want it to be efficient, the deque is available in the standard library. ChrisA From tjol at tjol.eu Sun Mar 3 04:26:39 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 3 Mar 2019 10:26:39 +0100 Subject: Version numbers in Standard Library In-Reply-To: References: Message-ID: <2179b46e-42ec-8f88-eaa9-0a01999d0282@tjol.eu> On 01/03/2019 16:35, Thompson, Matt (GSFC-610.1)[SCIENCE SYSTEMS AND APPLICATIONS INC] via Python-list wrote: > Dear Python List, > > A question. I help maintain a Python stack for users in my division here > at NASA and one user asked about updating the re module to 2.4. I > believe because he read the docs: > > https://docs.python.org/2.7/library/re.html > > where you see lines like "New in version 2.4" and he also did: > > $ python2 -c 'import re; print (re.__version__)' > 2.2.1 > > And, well, one can think "oh, a newer version is needed". I searched on > conda, etc. and can't find it and finally realized that 2.4 meant Python > 2.4, not re 2.4. (The 3.7 docs have lines like "Changed in version 3.7".) > > My question to the pros here is what purpose do the __version__/version > variables serve in the Python Standard Library?? I can understand in > external packages, but once in the Standard Library...? If a module that started life outside the standard library is included in the standard library under the same name, it is taken aboard hook, line and sinker. If it has a __version__, then that should probably stay: code that used the module before it entered the standard library might rely on it. As you quite rightly point out, these lines are then completely pointless, so there's no reason to ever change them. > > For example, in re.py, that line was last changed 18 years ago according > to git blame. In tarfile.py, the version string was last changed 12 > years ago. But in both, the modules were edited in 2018 so they haven't > been static for a decade. > > Are those strings there just for historic purposes? > > Not a big deal, I was just wondering. > > Thanks, > Matt > From arj.python at gmail.com Sun Mar 3 06:12:12 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 3 Mar 2019 15:12:12 +0400 Subject: deque as default list behaviour In-Reply-To: References: Message-ID: i can be wrong but i guess that inserting at the begining does not cause troubles as insertion at index 0 is constant (time does not scale with number of data) Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius From rosuav at gmail.com Sun Mar 3 06:34:04 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Mar 2019 22:34:04 +1100 Subject: deque as default list behaviour In-Reply-To: References: Message-ID: On Sun, Mar 3, 2019 at 10:12 PM Abdur-Rahmaan Janhangeer wrote: > > i can be wrong but i guess that inserting at the begining does not cause troubles as insertion at index 0 is constant (time does not scale with number of data) > In a deque? Correct. But the price of that is reduced efficiency in other areas. A Python list is *not* efficient for inserting at index 0, but is compact and fast for other, more common operations. If you want a deque, you know where to find it. The list is not like that though. ChrisA From rshepard at appl-ecosys.com Sun Mar 3 16:44:36 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sun, 3 Mar 2019 13:44:36 -0800 (PST) Subject: tkinter: get ttk.combobox choices from another class Message-ID: I'm using Alan D. Moore's tkinter book as a template for my application. In the views module in his book the one form has a ttk.Combobox and lists the available values in an input_args dictionary. To allow addition of new choices for this column in my application they are in a separate class. Example from my code: in my application's views module this data entry form class includes, self.inputs['Industry'] = LabelInput( OrgDataForm, "industry", input_class=ValidatedCombobox, input_var=tk.StringVar(), input_args={"values": ["", "", "", ""]} ) self.inputs['Industry'].grid(row=0, column=1) The middleware/controller is SQLAlchemy (postgres back end). The model.py contains, class Industries(Base): __tablename__ = 'industries' ind_name = Column(String, primary_key=True) How can I have the ttk.Combobox get the values from the Industries class? (If I confused you let me know and I'll try to clarify the situation.) TIA, Rich From rosuav at gmail.com Sun Mar 3 17:02:02 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Mar 2019 09:02:02 +1100 Subject: tkinter: get ttk.combobox choices from another class In-Reply-To: References: Message-ID: On Mon, Mar 4, 2019 at 8:46 AM Rich Shepard wrote: > In the views module in his book the one form has a ttk.Combobox and lists > the available values in an input_args dictionary. To allow addition of new > choices for this column in my application they are in a separate class. Specifically, from my reading of your example, you need a list of strings for the applicable values. > The middleware/controller is SQLAlchemy (postgres back end). The model.py > contains, > class Industries(Base): > __tablename__ = 'industries' > > ind_name = Column(String, primary_key=True) > > How can I have the ttk.Combobox get the values from the Industries class? > > (If I confused you let me know and I'll try to clarify the situation.) So you need to get a list of strings from SQLAlchemy. It's been a while since I did that sort of thing, but you should be able to mess with this independently of the ComboBox. I don't remember if you can specifically ask for all the values for ind_name, but worst case, you should be able to do this: names = [ind.ind_name for ind in session.query(Industries)] Then you can use that list in the ComboBox, once you've tested it. ChrisA From rshepard at appl-ecosys.com Sun Mar 3 17:33:15 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sun, 3 Mar 2019 14:33:15 -0800 (PST) Subject: tkinter: get ttk.combobox choices from another class [RESOLVED] In-Reply-To: References: Message-ID: On Mon, 4 Mar 2019, Chris Angelico wrote: > Specifically, from my reading of your example, you need a list of > strings for the applicable values. Chris, Yep. And I was not sure just how I would get these unitl I read your answer. > So you need to get a list of strings from SQLAlchemy. It's been a while > since I did that sort of thing, but you should be able to mess with this > independently of the ComboBox. I don't remember if you can specifically > ask for all the values for ind_name, but worst case, you should be able to > do this: > names = [ind.ind_name for ind in session.query(Industries)] > Then you can use that list in the ComboBox, once you've tested it. I've not before used SA, but it makes sense to run a query that returns all rows in the industries table, assigns those to a list which is passed to the combobox. I'll work out how exactly to implement this. Now that you've pointed it out to me it is quite obvious. :-) Thanks very much, Rich From rosuav at gmail.com Sun Mar 3 18:18:45 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Mar 2019 10:18:45 +1100 Subject: tkinter: get ttk.combobox choices from another class [RESOLVED] In-Reply-To: References: Message-ID: On Mon, Mar 4, 2019 at 9:34 AM Rich Shepard wrote: > > On Mon, 4 Mar 2019, Chris Angelico wrote: > > > Specifically, from my reading of your example, you need a list of > > strings for the applicable values. > > Chris, > > Yep. And I was not sure just how I would get these unitl I read your > answer. Right, right. Just be aware that your subject line implied that it was a ttk question, while in reality, it was more of an SQLAlchemy question. So I wanted to clarify that part early in the response. > > So you need to get a list of strings from SQLAlchemy. It's been a while > > since I did that sort of thing, but you should be able to mess with this > > independently of the ComboBox. I don't remember if you can specifically > > ask for all the values for ind_name, but worst case, you should be able to > > do this: > > names = [ind.ind_name for ind in session.query(Industries)] > > Then you can use that list in the ComboBox, once you've tested it. > > I've not before used SA, but it makes sense to run a query that returns > all rows in the industries table, assigns those to a list which is passed to > the combobox. I'll work out how exactly to implement this. > > Now that you've pointed it out to me it is quite obvious. :-) > > Thanks very much, Awesome! You're most welcome. Have fun! ChrisA From benjamin at python.org Sun Mar 3 22:30:52 2019 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 03 Mar 2019 22:30:52 -0500 Subject: [RELEASE] Python 2.7.16 Message-ID: <5cb021d0-bf2f-45aa-98f1-5f4bb77fb4a6@www.fastmail.com> Hello all, I'm pleased to announce the immediate availability of Python 2.7.16 for download at https://www.python.org/downloads/release/python-2716/. The only change since the release candidate was a fix for the IDLE icon on macOS. See https://bugs.python.org/issue32129. Refer to the changelog for a full list of changes: https://raw.githubusercontent.com/python/cpython/v2.7.16/Misc/NEWS.d/2.7.16rc1.rst Please report any bugs to https://bugs.python.org/. Regards, Benjamin 2.7 release manager (on behalf of all Python 2.7's contributors) From list at qtrac.plus.com Mon Mar 4 03:16:23 2019 From: list at qtrac.plus.com (Mark) Date: Mon, 4 Mar 2019 00:16:23 -0800 (PST) Subject: pyz and concurrent.futures Message-ID: <7c4c360a-d5c0-4ee3-8fb2-acdf83d6794d@googlegroups.com> I have two apps, one GUI one console, both using PySide2 bindings to Qt 5. Both use concurrent.futures and a processing pool to spread their work over multiple CPUs. I've written my own deployment script (since I can't get a successfull deploy with cx-freeze, py2exe, or pyinstaller) which creates this structure: myapp/ myapp/python/ # copy of Python 3.6 i.e., WinPython's python-3.6.7 dir myapp/myapp.pyz myapp/*.DLL # some custom and commercial DLLs the apps depend on I create the .pyz by copying myapp's .py files, running python3 -m compileall -b on the copied dir, then deleting all the original .py files, then renaming myapp.py as __main__.py and then zipping it all up as myapp.pyz. I can then run the programs using .bat files like this: Console app: "%~dp0\python\python.exe" "%~dp0\myapp.pyz" %* GUI app: "%~dp0\python\pythonw.exe" "%~dp0\myapp.pyz" %* The GUI app works fine. One significant difference is that the GUI app has two threads, the main thread running the GUI and a worker thread in which the calls to concurrent.futures process pool are made. Whereas the console app uses a single thread. Another difference is that the GUI app has an event loop and the console app doesn't. The console app works fine in the dev dir, but silently fails when run as a pyz. And it fails executing the same code as the GUI app (they share many modules). Has anyone encountered this issue before and have a solution? I plan to try to use two threads for the console app to see if that helps; but I'd still like to understand what is causing the problem. From larry at hastings.org Mon Mar 4 04:23:33 2019 From: larry at hastings.org (Larry Hastings) Date: Mon, 4 Mar 2019 01:23:33 -0800 Subject: [RELEASED] Python 3.4.10rc1 and Python 3.5.7rc1 are now available Message-ID: On behalf of the Python development community, I'm chuffed to announce the availability of Python 3.4.10rc1 and Python 3.5.7rc1. Both Python 3.4 and 3.5 are in "security fixes only" mode.? Both versions only accept security fixes, not conventional bug fixes, and both releases are source-only. The "final" releases on both these branches should be out in about two weeks.? Of particular note: that release of Python 3.4, Python 3.4.10 final, will be the final release ever in the Python 3.4 series.? After 3.4.10, the branch will be closed for good and I'll retire as Python 3.4 Release Manager.? I'll still be the Python 3.5 Release Manager until 3.5 similarly concludes, approximately eighteen months from now. You can find Python 3.4.10rc1 here: https://www.python.org/downloads/release/python-3410rc1/ And you can find Python 3.5.7rc1 here: https://www.python.org/downloads/release/python-357rc1/ Best wishes, //arry/ From list at qtrac.plus.com Mon Mar 4 07:07:01 2019 From: list at qtrac.plus.com (Mark) Date: Mon, 4 Mar 2019 04:07:01 -0800 (PST) Subject: pyz and concurrent.futures In-Reply-To: <7c4c360a-d5c0-4ee3-8fb2-acdf83d6794d@googlegroups.com> References: <7c4c360a-d5c0-4ee3-8fb2-acdf83d6794d@googlegroups.com> Message-ID: <43abe497-3dea-4c4a-9502-88a1bedb0dd9@googlegroups.com> I've now just tried with Python 3.7.1 and the same problem persists, so I'll now try to use a second thread for the console app. PS For these CPU-intensive apps which use multiprocessing to use all the CPUs, compared with Python 3.4, 3.6 is 13% faster, and 3.7 is 33% faster! From skauser at rocketsoftware.com Mon Mar 4 02:23:18 2019 From: skauser at rocketsoftware.com (Saba Kauser) Date: Mon, 4 Mar 2019 07:23:18 +0000 Subject: "How to package additional files under site-packages " Message-ID: Hello, I have a setup.py that has this: package_data = { 'tests': [ '*.png', '*.jpg']} data_files = [ ('', ['./README.md']), ('', ['./CHANGES']), ('', ['./LICENSE']) ] setup( name = PACKAGE, version = VERSION, . . packages = find_packages(), package_data = package_data, data_files = data_files, include_package_data = True, . ) This setup is copying README.md, CHANGES and LICENSE files under python-install path/Lib e.g: /Library/Frameworks/Python.framework/Versions/3.7/CHANGES /Library/Frameworks/Python.framework/Versions/3.7/LICENSE /Library/Frameworks/Python.framework/Versions/3.7/README.md And my package is installed under : /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ibm_db.cpython-37m-darwin.so I want data_files to be copied under my package install path. How do I achieve this? Thanks in advance! Saba. -------------------------------------------------------------------- Saba Kauser Db2 Connect development and support. Rocket Software Development India Pvt Ltd Karle Town Centre - SEZ, HUB 1 building, 4th Floor (North West Wing), 100 ft. Kempapura road, adjacent to Nagawara lake, Nagawara, Bangalore - 560 045 E: skauser at rocketsoftware.com --------------------------------------------------------------------- ================================ Rocket Software, Inc. and subsidiaries ? 77 Fourth Avenue, Waltham MA 02451 ? Main Office Toll Free Number: +1 855.577.4323 Contact Customer Support: https://my.rocketsoftware.com/RocketCommunity/RCEmailSupport Unsubscribe from Marketing Messages/Manage Your Subscription Preferences - http://www.rocketsoftware.com/manage-your-email-preferences Privacy Policy - http://www.rocketsoftware.com/company/legal/privacy-policy ================================ This communication and any attachments may contain confidential information of Rocket Software, Inc. All unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify Rocket Software immediately and destroy all copies of this communication. Thank you. From angiielovee177 at gmail.com Mon Mar 4 11:01:59 2019 From: angiielovee177 at gmail.com (Angie GL) Date: Mon, 4 Mar 2019 08:01:59 -0800 (PST) Subject: Decodificar base64 en Odoo 12 Message-ID: <28ab8172-fcb4-462b-9045-21084ce8235b@googlegroups.com> Hola a todos, tengo un problema al decodificar el contenido de una variable base64. De esta manera lo hago: cfdi = base64.b64decode(inv.l10n_mx_edi_cfdi) Al momento de decodificar el resultado que me env?a es esto: b'\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n' Alguien que me pueda decir que estoy haciendo mal, lo cheque en la consola Python3 y todo va bien, pero dentro de Odoo no lo decodifica. From __peter__ at web.de Mon Mar 4 12:07:09 2019 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Mar 2019 18:07:09 +0100 Subject: Decodificar base64 en Odoo 12 References: <28ab8172-fcb4-462b-9045-21084ce8235b@googlegroups.com> Message-ID: Angie GL wrote: > Hola a todos, tengo un problema al decodificar el contenido de una > variable base64. > > De esta manera lo hago: > > cfdi = base64.b64decode(inv.l10n_mx_edi_cfdi) > > > > Al momento de decodificar el resultado que me env?a es esto: > > b'\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n' > > Alguien que me pueda decir que estoy haciendo mal, lo cheque en la consola > Python3 y todo va bien, pero dentro de Odoo no lo decodifica. What result did you expect? What is the value of inv.l10n_mx_edi_cfdi? For b'CgogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCgo=' you see the correct result: >>> base64.b64decode(b'CgogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCgo=') b'\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n' From ijkl at netc.fr Mon Mar 4 13:02:44 2019 From: ijkl at netc.fr (Jimmy Girardet) Date: Mon, 4 Mar 2019 19:02:44 +0100 Subject: about types.new_class and module Message-ID: Hello, I'm looking for an explanation where live classes created by types.new_class() : py> import types py> types.new_class('A') types.A py> types.A AttributeError: module 'types' has no attribute 'A' py> _.__module__ 'types' The new class comes from `types` module without being inside. That's annoying to me for my use case : I'm trying to create dataclasses on the fly using? make_dataclass (which uses types.new_class). For new created classes, I have a cache to not recreate twice the same class. But I want to be sure not to override an existing class somewhere in the namespace which is already 'types.MyNewclass'. but how to check it if it's not in types ? To be clear : make_dataclass('Bla', {}) should raise an error if something named 'types.Bla' already exists. I hope I'm clear enough. Jimmy From python at mrabarnett.plus.com Mon Mar 4 14:31:34 2019 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 4 Mar 2019 19:31:34 +0000 Subject: about types.new_class and module In-Reply-To: References: Message-ID: <59a3558a-cf46-d068-3ceb-afccd7f5d3d8@mrabarnett.plus.com> On 2019-03-04 18:02, Jimmy Girardet wrote: > Hello, > > I'm looking for an explanation where live classes created by > types.new_class() : > > py> import types > > py> types.new_class('A') > > types.A > > py> types.A > > AttributeError: module 'types' has no attribute 'A' > > py> _.__module__ > > 'types' > > > The new class comes from `types` module without being inside. > > That's annoying to me for my use case : > > I'm trying to create dataclasses on the fly using? make_dataclass (which > uses types.new_class). For new created classes, I have a cache to not > recreate twice the same class. > > But I want to be sure not to override an existing class somewhere in the > namespace which is already 'types.MyNewclass'. but how to check it if > it's not in types ? > > To be clear : > > make_dataclass('Bla', {}) should raise an error if something named > 'types.Bla' already exists. > > I hope I'm clear enough. > 'new_class' creates a new class with the given name and returns a reference to it. The class doesn't 'live' anywhere. Although you might /think/ that an object lives in a certain namespace, it's just that there's a name there that's bound to the object. You can, in fact, create 2 classes with the same name. >>> import types >>> t1 = types.new_class('A') >>> t2 = types.new_class('A') >>> t1 is t2 False From __peter__ at web.de Mon Mar 4 14:37:19 2019 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Mar 2019 20:37:19 +0100 Subject: Totally Legit Signing Key? Message-ID: For once I tried to verify a download from python.org, following the steps outlined at https://www.python.org/downloads/#pubkeys """ You can import the release manager public keys by either downloading the public key file from here and then running gpg --import pubkeys.txt """ When I ran the command above I saw $ gpg --import pubkeys.txt gpg: Schl?ssel 6F5E1540: "Ned Deily " 2 neue Signaturen gpg: Schl?ssel 6A45C816: "Anthony Baxter " nicht ge?ndert gpg: Schl?ssel 36580288: "Georg Brandl (Python release signing key) " 2 neue Signaturen gpg: Schl?ssel 7D9DC8D2: "Martin v. L?wis " nicht ge?ndert gpg: Schl?ssel 18ADD4FF: "Benjamin Peterson " 3 neue Signaturen gpg: Schl?ssel A4135B38: "Benjamin Peterson " 1 neue Signatur gpg: Schl?ssel A74B06BF: "Barry Warsaw " 138 neue Signaturen gpg: Schl?ssel EA5BBD71: "Barry A. Warsaw " 6 neue Signaturen gpg: Schl?ssel E6DF025C: "Ronald Oussoren " nicht ge?ndert gpg: Schl?ssel F73C700D: "Larry Hastings " 2 neue Signaturen gpg: Schl?ssel AA65421D: "Ned Deily (Python release signing key) " 1 neue User-ID gpg: Schl?ssel AA65421D: "Ned Deily (Python release signing key) " 20 neue Signaturen gpg: Schl?ssel 487034E5: "Steve Dower (Python Release Signing) " 8 neue Signaturen gpg: Schl?ssel 10250568: ?ffentlicher Schl?ssel "?ukasz Langa (GPG langa.pl) " importiert gpg: Schl?ssel 487034E5: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert gpg: Schl?ssel F73C700D: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert gpg: Schl?ssel 6F5E1540: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert gpg: Schl?ssel AA65421D: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert gpg: Schl?ssel E6DF025C: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert gpg: Schl?ssel EA5BBD71: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert [...] Now "totally legit" does sound like anything but "totally legit". Is there a problem with my machine, or python.org, or is this all "totally legit"? Advice or pointers welcome. From ijkl at netc.fr Mon Mar 4 14:51:39 2019 From: ijkl at netc.fr (Jimmy Girardet) Date: Mon, 4 Mar 2019 20:51:39 +0100 Subject: about types.new_class and module In-Reply-To: <59a3558a-cf46-d068-3ceb-afccd7f5d3d8@mrabarnett.plus.com> References: <59a3558a-cf46-d068-3ceb-afccd7f5d3d8@mrabarnett.plus.com> Message-ID: <668fa804-6c05-e1c2-7581-21eb6102a5d6@netc.fr> Thank you for the clarification. I thought everything was bounded to anything. Shouldn't the name be changed from `types.A` to `unbound.A` to be less confusing ? Le 04/03/2019 ? 20:31, MRAB a ?crit : >> > 'new_class' creates a new class with the given name and returns a > reference to it. > > The class doesn't 'live' anywhere. > > Although you might /think/ that an object lives in a certain > namespace, it's just that there's a name there that's bound to the > object. > > You can, in fact, create 2 classes with the same name. > > >>> import types > >>> t1 = types.new_class('A') > >>> t2 = types.new_class('A') > >>> t1 is t2 > False From __peter__ at web.de Mon Mar 4 14:55:12 2019 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Mar 2019 20:55:12 +0100 Subject: about types.new_class and module References: <59a3558a-cf46-d068-3ceb-afccd7f5d3d8@mrabarnett.plus.com> Message-ID: MRAB wrote: > On 2019-03-04 18:02, Jimmy Girardet wrote: >> Hello, >> >> I'm looking for an explanation where live classes created by >> types.new_class() : >> >> py> import types >> >> py> types.new_class('A') >> >> types.A >> >> py> types.A >> >> AttributeError: module 'types' has no attribute 'A' >> >> py> _.__module__ >> >> 'types' >> >> >> The new class comes from `types` module without being inside. >> >> That's annoying to me for my use case : >> >> I'm trying to create dataclasses on the fly using make_dataclass (which >> uses types.new_class). For new created classes, I have a cache to not >> recreate twice the same class. >> >> But I want to be sure not to override an existing class somewhere in the >> namespace which is already 'types.MyNewclass'. but how to check it if >> it's not in types ? >> >> To be clear : >> >> make_dataclass('Bla', {}) should raise an error if something named >> 'types.Bla' already exists. >> >> I hope I'm clear enough. >> > 'new_class' creates a new class with the given name and returns a > reference to it. > > The class doesn't 'live' anywhere. > > Although you might /think/ that an object lives in a certain namespace, > it's just that there's a name there that's bound to the object. > > You can, in fact, create 2 classes with the same name. > > >>> import types > >>> t1 = types.new_class('A') > >>> t2 = types.new_class('A') > >>> t1 is t2 > False However, the underlying type() call assumes that you are going to inject the class into the current module -- which is why the OP's class appears to be part of the types module >>> types.new_class("Foo") and >>> type("Foo", (), {}) appears to be in __main__. This is correct in the majority of cases where the class is defined with class A: pass which can be thought of as syntactic sugar for A = type("A", (), {}) In the case of types.new_class() it is rather confusing -- perhaps the function should follow the example of collections.namedtuple and set the __module__ attribute to the caller's namespace. From ben+python at benfinney.id.au Mon Mar 4 17:04:47 2019 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 05 Mar 2019 09:04:47 +1100 Subject: Totally Legit Signing Key? References: Message-ID: <86zhqa2t4w.fsf@benfinney.id.au> Peter Otten <__peter__ at web.de> writes: > $ gpg --import pubkeys.txt > [?] > gpg: Schl?ssel 487034E5: "Steve Dower (Python Release Signing) " 8 neue Signaturen > gpg: Schl?ssel 10250568: ?ffentlicher Schl?ssel "?ukasz Langa (GPG langa.pl) " importiert > gpg: Schl?ssel 487034E5: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > gpg: Schl?ssel F73C700D: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > gpg: Schl?ssel 6F5E1540: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > gpg: Schl?ssel AA65421D: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > gpg: Schl?ssel E6DF025C: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > gpg: Schl?ssel EA5BBD71: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > [...] > > Now "totally legit" does sound like anything but "totally legit". Another clue is in the email address for that key: the ?example.org? domain is guaranteed to never resolve to any machine on the internet. There's nothing stopping anyone putting a fake email address, and any description they like, into a GnuPG userid. This was an inexpensive way to discover that :-) > Is there a problem with my machine, or python.org, or is this all > "totally legit"? Your computer, and your GnuPG program, are working as intended. Those specific signatures are made with a key that is bogus (and has been constructed to look as fake as it in fact is), and so you can ignore them. > Advice or pointers welcome. Cryptographic signatures should be trusted no more than you trust the provenance of the key that made the signature. -- \ ?Human reason is snatching everything to itself, leaving | `\ nothing for faith.? ?Bernard of Clairvaux, 1090?1153 CE | _o__) | Ben Finney From rosuav at gmail.com Mon Mar 4 17:23:14 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Mar 2019 09:23:14 +1100 Subject: Totally Legit Signing Key? In-Reply-To: <86zhqa2t4w.fsf@benfinney.id.au> References: <86zhqa2t4w.fsf@benfinney.id.au> Message-ID: On Tue, Mar 5, 2019 at 9:06 AM Ben Finney wrote: > > Peter Otten <__peter__ at web.de> writes: > > > $ gpg --import pubkeys.txt > > [?] > > gpg: Schl?ssel 487034E5: "Steve Dower (Python Release Signing) " 8 neue Signaturen > > gpg: Schl?ssel 10250568: ?ffentlicher Schl?ssel "?ukasz Langa (GPG langa.pl) " importiert > > gpg: Schl?ssel 487034E5: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > > gpg: Schl?ssel F73C700D: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > > gpg: Schl?ssel 6F5E1540: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > > gpg: Schl?ssel AA65421D: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > > gpg: Schl?ssel E6DF025C: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > > gpg: Schl?ssel EA5BBD71: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > > [...] > > > > Now "totally legit" does sound like anything but "totally legit". > > Another clue is in the email address for that key: the ?example.org? > domain is guaranteed to never resolve to any machine on the internet. (More or less - that domain DOES resolve (and has an explanatory web site running on both HTTP and HTTPS), but it's guaranteed never to be anything more significant than an example.) Also of note is that the user portion of the address is "Mallory", a well-known member of the "Alice and Bob" set of names. https://en.wikipedia.org/wiki/Alice_and_Bob#Cast_of_characters So I would expect these keys to be used for example malicious messages or mis-signed content, to test the recognition of legit signatures. If those keys are included in the pubkeys.txt download, it's minorly wasteful, but not a major problem. ChrisA From tjol at tjol.eu Mon Mar 4 17:41:07 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 4 Mar 2019 23:41:07 +0100 Subject: Totally Legit Signing Key? In-Reply-To: References: Message-ID: On 04/03/2019 20:37, Peter Otten wrote: > For once I tried to verify a download from python.org, following the steps outlined at > > https://www.python.org/downloads/#pubkeys > > """ > You can import the release manager public keys by either downloading the public key file from here and then running > > gpg --import pubkeys.txt > """ > > When I ran the command above I saw > > $ gpg --import pubkeys.txt > gpg: Schl?ssel 6F5E1540: "Ned Deily " 2 neue Signaturen > gpg: Schl?ssel 6A45C816: "Anthony Baxter " nicht ge?ndert > gpg: Schl?ssel 36580288: "Georg Brandl (Python release signing key) " 2 neue Signaturen > gpg: Schl?ssel 7D9DC8D2: "Martin v. L?wis " nicht ge?ndert > gpg: Schl?ssel 18ADD4FF: "Benjamin Peterson " 3 neue Signaturen > gpg: Schl?ssel A4135B38: "Benjamin Peterson " 1 neue Signatur > gpg: Schl?ssel A74B06BF: "Barry Warsaw " 138 neue Signaturen > gpg: Schl?ssel EA5BBD71: "Barry A. Warsaw " 6 neue Signaturen > gpg: Schl?ssel E6DF025C: "Ronald Oussoren " nicht ge?ndert > gpg: Schl?ssel F73C700D: "Larry Hastings " 2 neue Signaturen > gpg: Schl?ssel AA65421D: "Ned Deily (Python release signing key) " 1 neue User-ID > gpg: Schl?ssel AA65421D: "Ned Deily (Python release signing key) " 20 neue Signaturen > gpg: Schl?ssel 487034E5: "Steve Dower (Python Release Signing) " 8 neue Signaturen > gpg: Schl?ssel 10250568: ?ffentlicher Schl?ssel "?ukasz Langa (GPG langa.pl) " importiert > gpg: Schl?ssel 487034E5: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > gpg: Schl?ssel F73C700D: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > gpg: Schl?ssel 6F5E1540: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > gpg: Schl?ssel AA65421D: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > gpg: Schl?ssel E6DF025C: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > gpg: Schl?ssel EA5BBD71: ?ffentlicher Schl?ssel "Totally Legit Signing Key " importiert > [...] Everything's working fine on your end. If you have a closer look, you'll see that all of the "Totally Legit" keys have key IDs that are identical to key IDs of actual Python release managers. e.g. in the last line, EA5BBD71 refers to the key pub rsa1024 2015-05-22 [C] 801BD5AE93D392E22DDC6C7AFEA3DC6DEA5BBD71 uid [ unknown] Totally Legit Signing Key but it ALSO refers to the key pub dsa1024 2005-11-24 [SC] DBBF2EEBF925FAADCF1F3FFFD9866941EA5BBD71 uid [ unknown] Barry A. Warsaw uid [ unknown] Barry A. Warsaw uid [ unknown] Barry A. Warsaw uid [ unknown] Barry A. Warsaw uid [ unknown] Barry Warsaw (GNU Mailman) uid [ unknown] Barry A. Warsaw sub elg2048 2005-11-24 [E] The thing is that 32-bit key IDs are not secure and can easily be cloned. [1] I imagine that Barry at least knows this, seeing as he apparently cloned his own old (compromised) key: pub rsa1024 2014-06-16 [SCEA] [revoked: 2016-08-16] 2C7E264D238159CB07A3C350192720F7EA5BBD71 uid [ revoked] Barry A. Warsaw What I imagine happened here is that whoever exported the pubkeys.txt file did so on the basis of 32-bit key IDs. This is not ideal, as it pulled in bogus keys, but there's no real harm done. For good measure, I've put this on bpo (36191) -- Thomas [1] https://evil32.com/ > > Now "totally legit" does sound like anything but "totally legit". Is there a > problem with my machine, or python.org, or is this all "totally legit"? > > Advice or pointers welcome. > > From angiielovee177 at gmail.com Mon Mar 4 18:56:23 2019 From: angiielovee177 at gmail.com (angiielovee177 at gmail.com) Date: Mon, 4 Mar 2019 15:56:23 -0800 (PST) Subject: Decodificar base64 en Odoo 12 In-Reply-To: References: <28ab8172-fcb4-462b-9045-21084ce8235b@googlegroups.com> Message-ID: <0a1c2819-4739-454b-bd71-60537f3032c8@googlegroups.com> El lunes, 4 de marzo de 2019, 11:07:40 (UTC-6), Peter Otten escribi?: > Angie GL wrote: > > > Hola a todos, tengo un problema al decodificar el contenido de una > > variable base64. > > > > De esta manera lo hago: > > > > cfdi = base64.b64decode(inv.l10n_mx_edi_cfdi) > > > > > > > > Al momento de decodificar el resultado que me env?a es esto: > > > > b'\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n' > > > > Alguien que me pueda decir que estoy haciendo mal, lo cheque en la consola > > Python3 y todo va bien, pero dentro de Odoo no lo decodifica. > > What result did you expect? > > What is the value of inv.l10n_mx_edi_cfdi? For > > b'CgogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCgo=' > > you see the correct result: > > >>> base64.b64decode(b'CgogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCgo=') > b'\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n' El valor de la variable inv.l10n_mx_edi_cfdi es una factura en formato base64, el resultado que espero es que decodifique la factura para posteriormente mostrarlo. PERO NO LO DECODIFICA,ya verifique el valor de la variable pero no lo hace. From dieter at handshake.de Tue Mar 5 01:33:54 2019 From: dieter at handshake.de (dieter) Date: Tue, 05 Mar 2019 07:33:54 +0100 Subject: "How to package additional files under site-packages " References: Message-ID: <87o96p25kd.fsf@handshake.de> Saba Kauser writes: > ... > I want data_files to be copied under my package install path. > How do I achieve this? You could look at one of my packages (i.e. "dm.*", e.g. "dm.pdb"). Essentially, I have the data files besides the Python sources and let "setuptools" determine the relevant files (sources and data) as those managed via a source code control system (=SCCS). For the latter to work, your Python must have installed the integration module for your SCCS. From __peter__ at web.de Tue Mar 5 04:04:39 2019 From: __peter__ at web.de (Peter Otten) Date: Tue, 05 Mar 2019 10:04:39 +0100 Subject: Decodificar base64 en Odoo 12 References: <28ab8172-fcb4-462b-9045-21084ce8235b@googlegroups.com> <0a1c2819-4739-454b-bd71-60537f3032c8@googlegroups.com> Message-ID: angiielovee177 at gmail.com wrote: > El lunes, 4 de marzo de 2019, 11:07:40 (UTC-6), Peter Otten escribi?: >> Angie GL wrote: >> >> > Hola a todos, tengo un problema al decodificar el contenido de una >> > variable base64. >> > >> > De esta manera lo hago: >> > >> > cfdi = base64.b64decode(inv.l10n_mx_edi_cfdi) >> > >> > >> > >> > Al momento de decodificar el resultado que me env?a es esto: >> > >> > b'\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n' >> > >> > Alguien que me pueda decir que estoy haciendo mal, lo cheque en la >> > consola Python3 y todo va bien, pero dentro de Odoo no lo decodifica. >> >> What result did you expect? >> >> What is the value of inv.l10n_mx_edi_cfdi? For >> >> b'CgogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCgo=' >> >> you see the correct result: >> >> >>> base64.b64decode(b'CgogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCgo=') >> b'\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n' > > El valor de la variable inv.l10n_mx_edi_cfdi es una factura en formato > base64, el resultado que espero es que decodifique la factura para > posteriormente mostrarlo. PERO NO LO DECODIFICA,ya verifique el valor de > la variable pero no lo hace. If you replace the line >> > cfdi = base64.b64decode(inv.l10n_mx_edi_cfdi) in your script with cfdi = inv.l10n_mx_edi_cfdi print(type(cfdi)) print(repr(cfdi)) cfdi = base64.b64decode(cdfi) print(repr(cfdi)) what gets printed? Use cut and paste to post the result. If there is a traceback post that, too. Thank you. From info at wingware.com Tue Mar 5 08:44:45 2019 From: info at wingware.com (Wingware) Date: Tue, 05 Mar 2019 08:44:45 -0500 Subject: ANN: Wing Python IDE 6.1.5 released Message-ID: <5C7E7D4D.20905@wingware.com> Wing Python IDE version 6.1.5 is now available for download . Changes in 6.1.5 * Improves code intelligence for extension modules on remote hosts * Adds a debug status icon to the debug process selector, and does a better job truncating items in the process selection menu * Checks for conflicts before introducing names with refactoring operations, to avoid inadvertently reusing an existing symbol name * Improves support for py.exe on Windows, so that the correct Python version is launched This release also makes about 30 other minor improvements. See the change log for details. About Wing Wingware's family of cross-platform Python IDEs provide powerful integrated editing, debugging, unit testing, and project management features for interactive Python development. Wing can speed development and improve code quality for any kind of Python project, including web, desktop, scientific, data analysis, embedded scripting, and other applications. For more information, please visit wingware.com Stephan Deibel Wing Python IDE | The Intelligent Development Environment for Python From t2 at NetRH.com Tue Mar 5 17:39:40 2019 From: t2 at NetRH.com (Milt) Date: Tue, 5 Mar 2019 14:39:40 -0800 Subject: Class Issue` Message-ID: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> The following code gives me unusual results - base on experience with C++. class Car: ?? # carColor = None ?? # mileage = None ?? def __init__(self, color = None, miles = None): ????? self.mileage = miles ????? self.carColor = color ?? def print(self): ????? print(f"Color:?? {self.carColor}") ????? print(f"Mileage: {self.mileage}") myCar = Car('blue', 15000) myCar.print() print() myCar = Car(25000, 'orange') myCar.print() When executed the following results: Color:?? blue Mileage: 15000 Color:?? 25000 Mileage: orange It appears that the constructor ignores the assignment statements and makes the assignment based on the ordering in the __init__ declaration. -- Regards, Milt From rosuav at gmail.com Tue Mar 5 18:07:03 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Mar 2019 10:07:03 +1100 Subject: Class Issue` In-Reply-To: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> References: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> Message-ID: On Wed, Mar 6, 2019 at 10:01 AM Milt wrote: > > The following code gives me unusual results - base on experience with C++. > def __init__(self, color = None, miles = None): > self.mileage = miles > self.carColor = color > > myCar = Car('blue', 15000) > myCar = Car(25000, 'orange') > > It appears that the constructor ignores the assignment statements and > makes the assignment based on the ordering in the __init__ declaration. Based on your experience with C++, what tells the compiler that you can pass arguments in any order? Would you write multiple constructors taking different arguments? Because you didn't do that here. What you CAN do is call the constructor with keyword arguments: Car(color='blue', miles=15000) Car(miles=25000, color='orange') But otherwise, Python (just like C++) will pass the arguments in the order you wrote them. ChrisA From hxy9243 at gmail.com Tue Mar 5 18:11:48 2019 From: hxy9243 at gmail.com (Kevin Hu) Date: Tue, 5 Mar 2019 17:11:48 -0600 Subject: Class Issue` In-Reply-To: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> References: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> Message-ID: <0B27D9A4-F6C6-47F6-B543-64623E322531@gmail.com> I believe for the correct behavior you?ll need: myCar = Car(color=?blue?, miles=15000) myCar = Car(miles=25000, color=?orange?) In which case both objects will be initialized as the way you?d expect. Python is a language with very weak typing, and it?ll happily shoehorn data into variables even when you don?t expect it to. In this case it?ll assign arguments to parameters in order, which is the expected behavior. Regards, Kevin > On Mar 5, 2019, at 16:39, Milt wrote: > > The following code gives me unusual results - base on experience with C++. > > class Car: > # carColor = None > # mileage = None > > def __init__(self, color = None, miles = None): > self.mileage = miles > self.carColor = color > > def print(self): > print(f"Color: {self.carColor}") > print(f"Mileage: {self.mileage}") > > myCar = Car('blue', 15000) > myCar.print() > > print() > > myCar = Car(25000, 'orange') > myCar.print() > > > When executed the following results: > > Color: blue > Mileage: 15000 > > Color: 25000 > Mileage: orange > > It appears that the constructor ignores the assignment statements and makes the assignment based on the ordering in the __init__ declaration. > -- > Regards, > > Milt > > -- > https://mail.python.org/mailman/listinfo/python-list From angiielovee177 at gmail.com Tue Mar 5 18:16:18 2019 From: angiielovee177 at gmail.com (angiielovee177 at gmail.com) Date: Tue, 5 Mar 2019 15:16:18 -0800 (PST) Subject: Decodificar base64 en Odoo 12 In-Reply-To: References: <28ab8172-fcb4-462b-9045-21084ce8235b@googlegroups.com> <0a1c2819-4739-454b-bd71-60537f3032c8@googlegroups.com> Message-ID: <90fb94c2-7bbc-4703-badb-2d265263cf39@googlegroups.com> El martes, 5 de marzo de 2019, 3:05:07 (UTC-6), Peter Otten escribi?: > angiielovee177 at gmail.com wrote: > > > El lunes, 4 de marzo de 2019, 11:07:40 (UTC-6), Peter Otten escribi?: > >> Angie GL wrote: > >> > >> > Hola a todos, tengo un problema al decodificar el contenido de una > >> > variable base64. > >> > > >> > De esta manera lo hago: > >> > > >> > cfdi = base64.b64decode(inv.l10n_mx_edi_cfdi) > >> > > >> > > >> > > >> > Al momento de decodificar el resultado que me env?a es esto: > >> > > >> > b'\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n' > >> > > >> > Alguien que me pueda decir que estoy haciendo mal, lo cheque en la > >> > consola Python3 y todo va bien, pero dentro de Odoo no lo decodifica. > >> > >> What result did you expect? > >> > >> What is the value of inv.l10n_mx_edi_cfdi? For > >> > >> b'CgogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCgo=' > >> > >> you see the correct result: > >> > >> >>> base64.b64decode(b'CgogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCgo=') > >> b'\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n' > > > > El valor de la variable inv.l10n_mx_edi_cfdi es una factura en formato > > base64, el resultado que espero es que decodifique la factura para > > posteriormente mostrarlo. PERO NO LO DECODIFICA,ya verifique el valor de > > la variable pero no lo hace. > > If you replace the line > > >> > cfdi = base64.b64decode(inv.l10n_mx_edi_cfdi) > > in your script with > > cfdi = inv.l10n_mx_edi_cfdi > print(type(cfdi)) > print(repr(cfdi)) > cfdi = base64.b64decode(cdfi) > print(repr(cfdi)) > > what gets printed? Use cut and paste to post the result. If there is a > traceback post that, too. Thank you. Este es el resultado de cada linea: > cfdi = inv.l10n_mx_edi_cfdi > print(type(cfdi)) No imprime nada > print(repr(cfdi)) Imprime la cadena en base64, es bastabte larga.(b'PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0nVVRGLTgnPz4KPGNmZGk6Q29tcHJvYmFudGUgeG1sbnM6Y2ZkaT0iaHR0cDovL3d3dy5zYXQuZ29iLm14L2NmZC8zIiB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIiB4c2k6c2NoZW1hTG9jYXRpb249Imh0dHA6Ly93d3cuc2F0LmdvYi5teC9jZmQvMyBodHRwOi8vd3d3LnNhdC5nb2IubXgvc2l0aW9faW50ZXJuZXQvY2ZkLzMvY2ZkdjMzLnhzZCIgVmVyc2lvbj0iMy4zIiBTZWxsbz0iR1k1MVlrd1FCTC9vL2I2ZHA4aXBXcFM1MjlZcTFNSkdXV2IwN1VodW82UXFzb3I2MGJKNGZOVWZjS0t5YlVOR0tud0RCTEJ0c2tZTDVUVFU1SThLZ2MxbkxTYzZXdkl5YXcxQkVYd0hVSXdUM1pJSXBjYXhITTVadzRrMkhCZ0JraDZ3SndoOVAwZWN1Mk94bXd4dkhoMmhrUGRCbVNXcm1SUWt3NThVNWpieStqU1ltTW9SOUZacnVPVEt6NXlseTNUamJZODBwMUt0MXNOZXhJQW9rM0ZIbEQ4cmhrZmVLVDVyam10WXZ2Q2l2NmhuaVExclBPeHpYek1TY3VXY0pCZFJvQ1AxUmRGVkNmY1FxOVF1Umptb3VTRW9HZzl5N1BkSFlNa01vZnNnRXJuaGg2ZXcwRncrWUtyMFV5V1lNSHMvZ2JJckxucHJndlRXTmVnNG5RPT0iIEZlY2hhPSIyMDE5LTAzLTA0VDE1OjE3OjAyIiBGb2xpbz0iMTEiIFNlcmllPSJJTlYvMjAxOS8iIEZvcm1hUGFnbz0iMDQiIE5vQ2VydGlmaWNhZG89IjIwMDAxMDAwMDAwMzAwMDIyODE1IiBDZXJ0aWZpY2Fkbz0iTUlJRnhUQ0NBNjJnQXdJQkFnSVVNakF3TURFd01EQXdNREF6TURBd01qSTRNVFV3RFFZSktvWklodmNOQVFFTEJRQXdnZ0ZtTVNBd0hnWURWUVFEREJkQkxrTXVJRElnWkdVZ2NISjFaV0poY3lnME1EazJLVEV2TUMwR0ExVUVDZ3dtVTJWeWRtbGphVzhnWkdVZ1FXUnRhVzVwYzNSeVlXTnB3N051SUZSeWFXSjFkR0Z5YVdFeE9EQTJCZ05WQkFzTUwwRmtiV2x1YVhOMGNtRmphY096YmlCa1pTQlRaV2QxY21sa1lXUWdaR1VnYkdFZ1NXNW1iM0p0WVdOcHc3TnVNU2t3SndZSktvWklodmNOQVFrQkZocGhjMmx6Ym1WMFFIQnlkV1ZpWVhNdWMyRjBMbWR2WWk1dGVERW1NQ1FHQTFVRUNRd2RRWFl1SUVocFpHRnNaMjhnTnpjc0lFTnZiQzRnUjNWbGNuSmxjbTh4RGpBTUJnTlZCQkVNQlRBMk16QXdNUXN3Q1FZRFZRUUdFd0pOV0RFWk1CY0dBMVVFQ0F3UVJHbHpkSEpwZEc4Z1JtVmtaWEpoYkRFU01CQUdBMVVFQnd3SlEyOTViMkZqdzZGdU1SVXdFd1lEVlFRdEV3eFRRVlE1TnpBM01ERk9Uak14SVRBZkJna3Foa2lHOXcwQkNRSU1FbEpsYzNCdmJuTmhZbXhsT2lCQlEwUk5RVEFlRncweE5qRXdNalV5TVRVeU1URmFGdzB5TURFd01qVXlNVFV5TVRGYU1JR3hNUm93R0FZRFZRUURFeEZEU1U1RVJVMUZXQ0JUUVNCRVJTQkRWakVhTUJnR0ExVUVLUk1SUTBsT1JFVk5SVmdnVTBFZ1JFVWdRMVl4R2pBWUJnTlZCQW9URVVOSlRrUkZUVVZZSUZOQklFUkZJRU5XTVNVd0l3WURWUVF0RXh4TVFVNDNNREE0TVRjelVqVWdMeUJHVlVGQ056Y3dNVEUzUWxoQk1SNHdIQVlEVlFRRkV4VWdMeUJHVlVGQ056Y3dNVEUzVFVSR1VrNU9NRGt4RkRBU0JnTlZCQXNVQzFCeWRXVmlZVjlEUmtSSk1JSUJJakFOQmdrcWhraUc5dzBCQVFFRkFBT0NBUThBTUlJQkNnS0NBUUVBZ3Z2Q2lDRkRGVmFZWDd4ZFZSaHAvMzhVTFd0by9MS0RTWnkxeXJYS3BhcUZYcUVSSldGNzhZSEtmM041R0JvWGd6d0ZQdURYKzVrdlk1d3RZTnh4L093dTJzaE5acUZGaDZFS3N5c1FNZVA1cno2a0UxZ0ZZZW5hUEVVUDl6aitoMGJMM3hSNWFxb1RzcUdGMjRtS0JMb2lhSzQ0cFhCekd6Z3N4WmlzaFZKVk02WGJ6TkpWb25FVU5iSTI1RGhnV0FkODZmMmFVM0JtT0gySzFSWng0MWR0VFQ1NlVzc3pKbHM0dFBGT0RyL2NhV3VaRXVVdkxwMU0zbmo3RHl1ODhtaEQyZisxZkEvZzdremNVLzF0Y3BGWEYvckl5OTNBUHZrVTcyand2a3JucHJ6cytTbkc4MSsvRjE2YWh1R3NiMkVaODhkS0h3cXhFa3d6aE15VGJRSURBUUFCb3gwd0d6QU1CZ05WSFJNQkFmOEVBakFBTUFzR0ExVWREd1FFQXdJR3dEQU5CZ2txaGtpRzl3MEJBUXNGQUFPQ0FnRUFKL3hrTDhJK2ZwaWxaUCs5YU84bjkzKzIwWHhWb21MSmplU0wrTmcyRXJMMkdnYXRwTHVONUprbkZCa1pBaHhWSWdNYVRTMjN6emsxUkx0UmFZdkg4M2xCSDVFK00ra0VqRkdwMTRGbmUxaVYyUG0zdkw0amVMbXpIZ1kxS2Y1SG1lVnJycDRQVTdXUWcxNlZweUhhSi9lb25QTmlFQlVqY3lRMWlGZmt6Sm1uU0p2REd0ZlFLMlRpRW9sREpBcFl2ME9XZG00aXM5QnNmaTlqNmxJOS9UNk1OWisvTE0yTC90NzJWYXU0cjdtOTRKREV6YU8zQTB3SEF0UTk3ZmpCZkJpTzVNOEFFSVNBVjdlWmlkSWwzaWFKSkhrUWJCWWlpVzJnaWtyZVVaS1BVWDBIbWxuSXFxUWNCSmhXS1J1Nk5xazZhWkJURVRMTHBHcnZGOU9BclYxSlNzYmR3L1pIK1A4OFJBdDVlbTUvZ2p3d3RGbE5IeWlLRzV3K1VGcGFaT0szZ1pQMHN1MHNhNmRsUGVROUVMNEpsRmtHcVFDZ1NRK05Pc1hxYU9hdmdvUDVWTHlrTHd1R253SVVudWhCVFZlRGJ6cGdyZzlMdUY1ZFlwL3pzK1k5U2NKcWU1Vk1BYWdMU1lUU2hOdE44bHVWN0x2eEY5cGdXd1pkY003bFV3cUptVWRkQ2lacWRuZ2czdnpUYWN0TVRvRzE2Z1pBNENXbk1nYlU0RStyNTQxK0ZOTXBnQVpOdnMyQ2lXL2VBcGZhYVFvanNaRUFIRHNEdjRMNW4zTTFDQzdmWWpFL2Q2MWFTbmcxTGFPNlQxbWgrZEVmUHZMenA3enl6eitVZ1dNaGk1Q3M0cGNYeDFlaWM1cjd1eFBvQndjQ1R0M1lJMWpLVlZuVjcvdz0iIENvbmRpY2lvbmVzRGVQYWdvPSJQYWdvIGlubWVkaWF0byIgU3ViVG90YWw9IjQwMDAuMDAiIE1vbmVkYT0iTVhOIiBUb3RhbD0iNDY0MC4wMCIgVGlwb0RlQ29tcHJvYmFudGU9IkkiIE1ldG9kb1BhZ289IlBVRSIgTHVnYXJFeHBlZGljaW9uPSI3MTEwMCI+CiAgPGNmZGk6RW1pc29yIFJmYz0iTEFONzAwODE3M1I1IiBOb21icmU9Ik15IENvbXBhbnkiIFJlZ2ltZW5GaXNjYWw9IjYwMSIvPgogIDxjZmRpOlJlY2VwdG9yIFJmYz0iTUFHMDQxMTI2R1Q4IiBOb21icmU9IkJ1aWxkIiBVc29DRkRJPSJHMDMiLz4KICA8Y2ZkaTpDb25jZXB0b3M+CiAgICA8Y2ZkaTpDb25jZXB0byBDbGF2ZVByb2RTZXJ2PSIwMTAxMDEwMSIgTm9JZGVudGlmaWNhY2lvbj0iQ09OIiBDYW50aWRhZD0iMi4wIiBDbGF2ZVVuaWRhZD0iSDg3IiBVbmlkYWQ9IlVuaWRhZChlcykiIERlc2NyaXBjaW9uPSJbQ09OXSBDb25zdWx0b3JpYSIgVmFsb3JVbml0YXJpbz0iMjAwMC4wMCIgSW1wb3J0ZT0iNDAwMC4wMCI+CiAgICAgIDxjZmRpOkltcHVlc3Rvcz4KICAgICAgICA8Y2ZkaTpUcmFzbGFkb3M+CiAgICAgICAgICA8Y2ZkaTpUcmFzbGFkbyBCYXNlPSI0MDAwLjAwIiBJbXB1ZXN0bz0iMDAyIiBUaXBvRmFjdG9yPSJUYXNhIiBUYXNhT0N1b3RhPSIwLjE2MDAwMCIgSW1wb3J0ZT0iNjQwLjAwIi8+CiAgICAgICAgPC9jZmRpOlRyYXNsYWRvcz4KICAgICAgPC9jZmRpOkltcHVlc3Rvcz4KICAgIDwvY2ZkaTpDb25jZXB0bz4KICA8L2NmZGk6Q29uY2VwdG9zPgogIDxjZmRpOkltcHVlc3RvcyBUb3RhbEltcHVlc3Rvc1RyYXNsYWRhZG9zPSI2NDAuMDAiPgogICAgPGNmZGk6VHJhc2xhZG9zPgogICAgICA8Y2ZkaTpUcmFzbGFkbyBJbXBvcnRlPSI2NDAuMDAiIEltcHVlc3RvPSIwMDIiIFRpcG9GYWN0b3I9IlRhc2EiIFRhc2FPQ3VvdGE9IjAuMTYwMDAwIi8+CiAgICA8L2NmZGk6VHJhc2xhZG9zPgogIDwvY2ZkaTpJbXB1ZXN0b3M+CjwvY2ZkaTpDb21wcm9iYW50ZT4=') > cfdi = base64.b64decode(cdfi) > print(repr(cfdi)) Imprime b'\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n' Intente con otra cadena en base64 y lo hace bien, al momento de que sea una factura no lo hace. ?Qu? podr? ser?, llevo d?as tratando de resolver este problema y solo no veo soluci?n. From PythonList at DancesWithMice.info Tue Mar 5 18:31:36 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 6 Mar 2019 12:31:36 +1300 Subject: Class Issue` In-Reply-To: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> References: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> Message-ID: Milt, On 6/03/19 11:39 AM, Milt wrote: > The following code gives me unusual results - base on experience with C++. > class Car: > ?? # carColor = None > ?? # mileage = None > ?? def __init__(self, color = None, miles = None): > ????? self.mileage = miles > ????? self.carColor = color > ?? def print(self): > ????? print(f"Color:?? {self.carColor}") > ????? print(f"Mileage: {self.mileage}") > myCar = Car('blue', 15000) > myCar.print() > print() > myCar = Car(25000, 'orange') > myCar.print() > > When executed the following results: > Color:?? blue > Mileage: 15000 > Color:?? 25000 > Mileage: orange > It appears that the constructor ignores the assignment statements and > makes the assignment based on the ordering in the __init__ declaration. It is risky to decide that Python should behave in a certain fashion, just because another language does. Would you decide that the word "blue" may not be used because in French it is "bleu"? If all programming languages did look/work the same way, why would there be multiple languages? However, your understanding of C++ gives you a flying start with Python - apart from a few pesky 'gotchas'! In the term "ignores the assignment statements", what "assignment statements" are being discussed? Yes, without keywords, the positional rule applies. myCar = Car('blue', 15000) is the same as: myCar = Car(color = 'blue', miles = 15000) Instead of: myCar = Car(25000, 'orange') try: myCar = Car(miles=25000, color='orange') If you've gone to the trouble of defining keyword-arguments in the method, greater satisfaction will be gained from calling the method similarly (and cause less confusion on the part of your readers!) Meantime I have a very low-mileage Edsel in an attractive lemon color, going cheap... Jokes aside: using the __str__() and __repr__() "magic methods" is more 'pythonic' than adding a print method to a class. For a nicely-formatted output (albeit without mentioning that it is describing a "Car" or "myCar" - per print(), above): def __str__(self): return f"Color: {self.carColor}\nMileage: {self.mileage}" ... myCar = Car(color = 'blue', miles = 15000) print( myCar ) For extra credit, seeing we're talking about 'being pythonic': car_color and my_car. Alternately, to present the output formatted as a class definition/ready for instantiation: def __repr__(self): return f"Car( color={self.car_color}, miles={self.mileage} )" NB if both methods appear in a class, printing the class (ie print( my_car ) ) will prefer __repr__() over __str__(). All the best... -- Regards =dn From eryksun at gmail.com Tue Mar 5 20:10:54 2019 From: eryksun at gmail.com (eryk sun) Date: Tue, 5 Mar 2019 19:10:54 -0600 Subject: Class Issue` In-Reply-To: <0B27D9A4-F6C6-47F6-B543-64623E322531@gmail.com> References: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> <0B27D9A4-F6C6-47F6-B543-64623E322531@gmail.com> Message-ID: On 3/5/19, Kevin Hu wrote: > > Python is a language with very weak typing, and it?ll happily shoehorn data > into variables even when you don?t expect it to. Python has strong typing, in that it doesn't implicitly coerce unrelated types in expressions. However, it has no enforced static typing of variables. It relies on runtime type checking and protocols. The term "duck typing" was coined for this case. From tjreedy at udel.edu Tue Mar 5 21:04:43 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 5 Mar 2019 21:04:43 -0500 Subject: Class Issue` In-Reply-To: <0B27D9A4-F6C6-47F6-B543-64623E322531@gmail.com> References: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> <0B27D9A4-F6C6-47F6-B543-64623E322531@gmail.com> Message-ID: On 3/5/2019 6:11 PM, Kevin Hu wrote: > Python is a language with very weak typing, Python runtime objects are strongly dynamically typed. Their type/class is one of their attributes. All classes are subclasses of class 'object'. Python names (variables) are untyped in a sense, or one could say their default type is 'object'. and it?ll happily shoehorn data into variables This describes C, which puts data into permanently names blocks of memory. Python puts data into objects, not names. It associates names/variables with objects. it?ll assign arguments to parameters in order, which is the expected behavior. Parameters are names and arguments are objects. Yes, if the arguments are not named in a called, they named in order. -- Terry Jan Reedy From skauser at rocketsoftware.com Tue Mar 5 23:06:16 2019 From: skauser at rocketsoftware.com (Saba Kauser) Date: Wed, 6 Mar 2019 04:06:16 +0000 Subject: "How to package additional files under site-packages " In-Reply-To: <87o96p25kd.fsf@handshake.de> References: <87o96p25kd.fsf@handshake.de> Message-ID: Thanks! My package (ibm_db) has LICENSE, README.md and CHANGES files that I want to be available in the same location as my package is installed I.e under site-packages. However, with current setup.py https://github.com/ibmdb/python-ibmdb/blob/master/IBM_DB/ibm_db/setup.py, these files get installed under python install path. e.g: C:\Users\skauser\AppData\Local\Programs\Python\Python36\LICENSE I have specified them as: data_files = [ ('', ['./README.md']), ('', ['./CHANGES']), ('', ['./LICENSE']) ] Setup( .. package_data = package_data, data_files = data_files, include_package_data = True, cmdclass = cmd_class, ..) Since the directory path is empty, these files get copied under current path of execution. However, I want them to be copied under the install location of my package. Is there any other way I can achieve this? Thanks! -----Original Message----- From: dieter Sent: Tuesday, March 5, 2019 12:04 PM To: python-list at python.org Subject: Re: "How to package additional files under site-packages " Saba Kauser writes: > ... > I want data_files to be copied under my package install path. > How do I achieve this? You could look at one of my packages (i.e. "dm.*", e.g. "dm.pdb"). Essentially, I have the data files besides the Python sources and let "setuptools" determine the relevant files (sources and data) as those managed via a source code control system (=SCCS). For the latter to work, your Python must have installed the integration module for your SCCS. ================================ Rocket Software, Inc. and subsidiaries ? 77 Fourth Avenue, Waltham MA 02451 ? Main Office Toll Free Number: +1 855.577.4323 Contact Customer Support: https://my.rocketsoftware.com/RocketCommunity/RCEmailSupport Unsubscribe from Marketing Messages/Manage Your Subscription Preferences - http://www.rocketsoftware.com/manage-your-email-preferences Privacy Policy - http://www.rocketsoftware.com/company/legal/privacy-policy ================================ This communication and any attachments may contain confidential information of Rocket Software, Inc. All unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify Rocket Software immediately and destroy all copies of this communication. Thank you. From dieter at handshake.de Wed Mar 6 01:44:30 2019 From: dieter at handshake.de (dieter) Date: Wed, 06 Mar 2019 07:44:30 +0100 Subject: "How to package additional files under site-packages " References: <87o96p25kd.fsf@handshake.de> Message-ID: <87k1hca4dt.fsf@handshake.de> Saba Kauser writes: > ... > My package (ibm_db) has LICENSE, README.md and CHANGES files that I want to be available in the same location as my package is installed I.e under site-packages. However, with current setup.py https://github.com/ibmdb/python-ibmdb/blob/master/IBM_DB/ibm_db/setup.py, these files get installed under python install path. > e.g: C:\Users\skauser\AppData\Local\Programs\Python\Python36\LICENSE > > I have specified them as: > data_files = [ ('', ['./README.md']), > ('', ['./CHANGES']), > ('', ['./LICENSE']) ] > > Setup( > .. > package_data = package_data, > data_files = data_files, > include_package_data = True, > cmdclass = cmd_class, > ..) > > Since the directory path is empty, these files get copied under current path of execution. However, I want them to be copied under the install location of my package. > Is there any other way I can achieve this? As you do not want to follow my example, maybe read the "setuptools" documentation. There definitely is a way to achieve your goal -- other than my approach. If necessary override parts of the "distutils/setuptools" machinery. From __peter__ at web.de Wed Mar 6 03:06:40 2019 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Mar 2019 09:06:40 +0100 Subject: Decodificar base64 en Odoo 12 References: <28ab8172-fcb4-462b-9045-21084ce8235b@googlegroups.com> <0a1c2819-4739-454b-bd71-60537f3032c8@googlegroups.com> <90fb94c2-7bbc-4703-badb-2d265263cf39@googlegroups.com> Message-ID: angiielovee177 at gmail.com wrote: > El martes, 5 de marzo de 2019, 3:05:07 (UTC-6), Peter Otten escribi?: >> angiielovee177 at gmail.com wrote: >> >> > El lunes, 4 de marzo de 2019, 11:07:40 (UTC-6), Peter Otten escribi?: >> >> Angie GL wrote: >> >> >> >> > Hola a todos, tengo un problema al decodificar el contenido de una >> >> > variable base64. >> >> > >> >> > De esta manera lo hago: >> >> > >> >> > cfdi = base64.b64decode(inv.l10n_mx_edi_cfdi) >> >> > >> >> > >> >> > >> >> > Al momento de decodificar el resultado que me env?a es esto: >> >> > >> >> > b'\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n' >> >> > >> >> > Alguien que me pueda decir que estoy haciendo mal, lo cheque en la >> >> > consola Python3 y todo va bien, pero dentro de Odoo no lo >> >> > decodifica. >> >> >> >> What result did you expect? >> >> >> >> What is the value of inv.l10n_mx_edi_cfdi? For >> >> >> >> b'CgogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCgo=' >> >> >> >> you see the correct result: >> >> >> >> >>> base64.b64decode(b'CgogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCiAKIAogCgo=') >> >> b'\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n' >> > >> > El valor de la variable inv.l10n_mx_edi_cfdi es una factura en formato >> > base64, el resultado que espero es que decodifique la factura para >> > posteriormente mostrarlo. PERO NO LO DECODIFICA,ya verifique el valor >> > de la variable pero no lo hace. >> >> If you replace the line >> >> >> > cfdi = base64.b64decode(inv.l10n_mx_edi_cfdi) >> >> in your script with >> >> cfdi = inv.l10n_mx_edi_cfdi >> print(type(cfdi)) >> print(repr(cfdi)) >> cfdi = base64.b64decode(cdfi) >> print(repr(cfdi)) >> >> what gets printed? Use cut and paste to post the result. If there is a >> traceback post that, too. Thank you. > > Este es el resultado de cada linea: > >> cfdi = inv.l10n_mx_edi_cfdi >> print(type(cfdi)) No imprime nada That's strange. What does print(isinstance(cdfi, bytes)) print(isinstance(cdfi, bytesarray)) print? If both print False, does print(memoryview(cdfi).tobyes()) produce the same long string that you posted below? If it's much shorter then the "magic" happens here. Otherwise (more likely) read on below. >> print(repr(cfdi)) Imprime la cadena en base64, es bastabte >> larga.(b'PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZG... >> cfdi = base64.b64decode(cdfi) print(repr(cfdi)) Imprime b'\n\n \n \n \n >> \n \n \n \n \n \n \n \n \n \n \n \n \n\n' > > Intente con otra cadena en base64 y lo hace bien, al momento de que sea > una factura no lo hace. ?Qu? podr? ser?, llevo d?as tratando de resolver > este problema y solo no veo soluci?n. The output is an XML document, and if you extract only the text with the following little script $ cat demo.py import base64 from lxml import etree data = b'PD...' # what you posted tree = etree.fromstring(base64.b64decode(data)) print(repr("".join(tree.xpath("//text()")))) you get something similar to what you see: $ python3 demo.py '\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n' I don't know Odoo, perhaps it tries to be smart and shows XML in a "user- friendly" way, like it would appear in a browser? In this case I suggest that you present your problem to the Odoo support or an Odoo specific forum. Perhaps there is a way to switch off this feature and show the raw data instead. From rhodri at kynesim.co.uk Wed Mar 6 07:12:15 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 6 Mar 2019 12:12:15 +0000 Subject: Class Issue` In-Reply-To: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> References: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> Message-ID: <3b7d6163-1836-f786-1bba-ed209a655a33@kynesim.co.uk> On 05/03/2019 22:39, Milt wrote: > The following code gives me unusual results - base on experience with C++. > > class Car: > ?? # carColor = None > ?? # mileage = None > > ?? def __init__(self, color = None, miles = None): > ????? self.mileage = miles > ????? self.carColor = color > > ?? def print(self): > ????? print(f"Color:?? {self.carColor}") > ????? print(f"Mileage: {self.mileage}") > > myCar = Car('blue', 15000) > myCar.print() > > print() > > myCar = Car(25000, 'orange') > myCar.print() The behaviour you should expect even from C++ (a language I have no respect for) is a compile-time error complaining that you are passing an integer to a string parameter and vice versa. Python is a dynamically typed language; it doesn't enforce any restrictions on what types of object can be bound to any given name. This is occasionally a surprise when you're being careless, but it really shouldn't break your expectations. -- Rhodri James *-* Kynesim Ltd From cspealma at redhat.com Wed Mar 6 09:15:01 2019 From: cspealma at redhat.com (Calvin Spealman) Date: Wed, 6 Mar 2019 09:15:01 -0500 Subject: Class Issue` In-Reply-To: <3b7d6163-1836-f786-1bba-ed209a655a33@kynesim.co.uk> References: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> <3b7d6163-1836-f786-1bba-ed209a655a33@kynesim.co.uk> Message-ID: > C++ (a language I have no respect for) This was uncalled for and inappropriate. Please keep discord civil. On Wed, Mar 6, 2019 at 7:12 AM Rhodri James wrote: > On 05/03/2019 22:39, Milt wrote: > > The following code gives me unusual results - base on experience with > C++. > > > > class Car: > > # carColor = None > > # mileage = None > > > > def __init__(self, color = None, miles = None): > > self.mileage = miles > > self.carColor = color > > > > def print(self): > > print(f"Color: {self.carColor}") > > print(f"Mileage: {self.mileage}") > > > > myCar = Car('blue', 15000) > > myCar.print() > > > > print() > > > > myCar = Car(25000, 'orange') > > myCar.print() > > The behaviour you should expect even from C++ (a language I have no > respect for) is a compile-time error complaining that you are passing an > integer to a string parameter and vice versa. Python is a dynamically > typed language; it doesn't enforce any restrictions on what types of > object can be bound to any given name. This is occasionally a surprise > when you're being careless, but it really shouldn't break your > expectations. > > -- > Rhodri James *-* Kynesim Ltd > -- > https://mail.python.org/mailman/listinfo/python-list > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER cspealma at redhat.com M: +1.336.210.5107 TRIED. TESTED. TRUSTED. From rhodri at kynesim.co.uk Wed Mar 6 09:32:51 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 6 Mar 2019 14:32:51 +0000 Subject: Class Issue` In-Reply-To: References: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> <3b7d6163-1836-f786-1bba-ed209a655a33@kynesim.co.uk> Message-ID: On 06/03/2019 14:15, Calvin Spealman wrote: >> C++ (a language I have no respect for) > This was uncalled for and inappropriate. Please keep discord civil. That was the civil version :-) -- Rhodri James *-* Kynesim Ltd From rosuav at gmail.com Wed Mar 6 09:44:45 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Mar 2019 01:44:45 +1100 Subject: Class Issue` In-Reply-To: References: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> <3b7d6163-1836-f786-1bba-ed209a655a33@kynesim.co.uk> Message-ID: On Thu, Mar 7, 2019 at 1:34 AM Rhodri James wrote: > > On 06/03/2019 14:15, Calvin Spealman wrote: > >> C++ (a language I have no respect for) > > This was uncalled for and inappropriate. Please keep discord civil. > > That was the civil version :-) > Ouch, did C++ burn you in the past? IMO it's a language that has way too many features stuffed into it (yes, the language, not just the standard library - the actual syntax is overly complicated IMO), but it isn't an abysmal language. There *are* horrendous languages in the world, and C++ is not one of them. That said, though, saying "I have no respect for" is a reasonably civil statement, but perhaps factually wrong. Here it is in context: > The behaviour you should expect even from C++ (a language I have no > respect for) is a compile-time error complaining that you are passing an > integer to a string parameter and vice versa. Sounds like Rhodri has strong expectations about how languages should behave, and C++ does fulfil this. So maybe there's some respect here after all :) But it wasn't terribly uncivil. ChrisA From rhodri at kynesim.co.uk Wed Mar 6 10:04:15 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 6 Mar 2019 15:04:15 +0000 Subject: Class Issue` In-Reply-To: References: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> <3b7d6163-1836-f786-1bba-ed209a655a33@kynesim.co.uk> Message-ID: <79387383-249a-02bb-7686-547fe2985379@kynesim.co.uk> On 06/03/2019 14:44, Chris Angelico wrote: > Ouch, did C++ burn you in the past? I've tried and failed to learn the language three times. It's been suggested that my mistake was using Stroustrop's book :-) There just seem to be so much boilerplate and fiddly bits that it quickly gets too complex to hold a project design in my head. Python, by contrast, Just Worked and showed me how to think about OO design without half the drama. > Sounds like Rhodri has strong expectations about how languages should > behave, and C++ does fulfil this. So maybe there's some respect here > after all:) Fine, you've got me there :-) -- Rhodri James *-* Kynesim Ltd From duncan at invalid.invalid Wed Mar 6 11:14:01 2019 From: duncan at invalid.invalid (duncan smith) Date: Wed, 6 Mar 2019 16:14:01 +0000 Subject: in a pickle Message-ID: Hello, I've been trying to figure out why one of my classes can be pickled but not unpickled. (I realise the problem is probably with the pickling, but I get the error when I attempt to unpickle.) A relatively minimal example is pasted below. >>> import pickle >>> class test(dict): def __init__(self, keys, shape=None): self.shape = shape for key in keys: self[key] = None def __setitem__(self, key, val): print (self.shape) dict.__setitem__(self, key, val) >>> x = test([1,2,3]) None None None >>> s = pickle.dumps(x) >>> y = pickle.loads(s) Traceback (most recent call last): File "", line 1, in y = pickle.loads(s) File "", line 8, in __setitem__ print (self.shape) AttributeError: 'test' object has no attribute 'shape' I have DUCkDuckGo'ed the issue and have tinkered with __getnewargs__ and __getnewargs_ex__ without being able to figure out exactly what's going on. If I comment out the print call, then it seems to be fine. I'd appreciate any pointers to the underlying problem. I have one or two other things I can do to try to isolate the issue further, but I think the example is perhaps small enough that someone in the know could spot the problem at a glance. Cheers. Duncan From marko at pacujo.net Wed Mar 6 11:18:33 2019 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 06 Mar 2019 18:18:33 +0200 Subject: Class Issue` References: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> <3b7d6163-1836-f786-1bba-ed209a655a33@kynesim.co.uk> Message-ID: <874l8gnfhi.fsf@elektro.pacujo.net> Rhodri James : > On 06/03/2019 14:15, Calvin Spealman wrote: >>> C++ (a language I have no respect for) >> This was uncalled for and inappropriate. Please keep discord civil. > > That was the civil version :-) C++ is a programming language without feelings. It's nobody's ethnicity, sexual orientation, race or religion, either. You can despise it freely. Marko From duncan at invalid.invalid Wed Mar 6 11:57:49 2019 From: duncan at invalid.invalid (duncan smith) Date: Wed, 6 Mar 2019 16:57:49 +0000 Subject: in a pickle In-Reply-To: References: Message-ID: [snip] Sorry, this is Python 3.6 on Linux. Duncan From David.Raymond at tomtom.com Wed Mar 6 12:31:27 2019 From: David.Raymond at tomtom.com (David Raymond) Date: Wed, 6 Mar 2019 17:31:27 +0000 Subject: in a pickle In-Reply-To: References: Message-ID: https://docs.python.org/3.7/library/pickle.html#pickling-class-instances includes 2 notes, which I think are the relevant ones: When a class instance is unpickled, its __init__() method is usually not invoked. The default behaviour first creates an uninitialized instance and then restores the saved attributes. At unpickling time, some methods like __getattr__(), __getattribute__(), or __setattr__() may be called upon the instance. In case those methods rely on some internal invariant being true, the type should implement __getnewargs__() or __getnewargs_ex__() to establish such an invariant; otherwise, neither __new__() nor __init__() will be called. So I think that without using the various dunders you can't rely on the bits being restored in a specific order. So at the point in the restoration where you're getting the exception, self.shape hasn't been restored yet while it's trying to set self[1], which is why trying to print self.shape is failing. Here's a modified version with more prints to show some of that: import pickle class test(dict): def __init__(self, keys, shape = None): print("__init__ is running") print("keys:", keys) print("shape:", shape) self.shape = shape for key in keys: self[key] = None def __setitem__(self, key, val): print("__setitem__ is running") print("self:", self) print("key:", key) print("val:", val) try: print("self.shape:", self.shape) except AttributeError as err: print("AttributeError:", err) dict.__setitem__(self, key, val) x = test([1, 2, 3]) print(x, x.shape) s = pickle.dumps(x) print("\n---About to load it---\n") y = pickle.loads(s) print(".loads() complete") print(y, y.shape) This is what that outputs: __init__ is running keys: [1, 2, 3] shape: None __setitem__ is running self: {} key: 1 val: None self.shape: None __setitem__ is running self: {1: None} key: 2 val: None self.shape: None __setitem__ is running self: {1: None, 2: None} key: 3 val: None self.shape: None {1: None, 2: None, 3: None} None ---About to load it--- __setitem__ is running self: {} key: 1 val: None AttributeError: 'test' object has no attribute 'shape' __setitem__ is running self: {1: None} key: 2 val: None AttributeError: 'test' object has no attribute 'shape' __setitem__ is running self: {1: None, 2: None} key: 3 val: None AttributeError: 'test' object has no attribute 'shape' .loads() complete {1: None, 2: None, 3: None} None Alas, I can't offer any help with how to use __getnewargs__() or the other dunders to properly handle it. -----Original Message----- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom.com at python.org] On Behalf Of duncan smith Sent: Wednesday, March 06, 2019 11:14 AM To: python-list at python.org Subject: in a pickle Hello, I've been trying to figure out why one of my classes can be pickled but not unpickled. (I realise the problem is probably with the pickling, but I get the error when I attempt to unpickle.) A relatively minimal example is pasted below. >>> import pickle >>> class test(dict): def __init__(self, keys, shape=None): self.shape = shape for key in keys: self[key] = None def __setitem__(self, key, val): print (self.shape) dict.__setitem__(self, key, val) >>> x = test([1,2,3]) None None None >>> s = pickle.dumps(x) >>> y = pickle.loads(s) Traceback (most recent call last): File "", line 1, in y = pickle.loads(s) File "", line 8, in __setitem__ print (self.shape) AttributeError: 'test' object has no attribute 'shape' I have DUCkDuckGo'ed the issue and have tinkered with __getnewargs__ and __getnewargs_ex__ without being able to figure out exactly what's going on. If I comment out the print call, then it seems to be fine. I'd appreciate any pointers to the underlying problem. I have one or two other things I can do to try to isolate the issue further, but I think the example is perhaps small enough that someone in the know could spot the problem at a glance. Cheers. Duncan -- https://mail.python.org/mailman/listinfo/python-list From duncan at invalid.invalid Wed Mar 6 13:30:45 2019 From: duncan at invalid.invalid (duncan smith) Date: Wed, 6 Mar 2019 18:30:45 +0000 Subject: in a pickle In-Reply-To: References: Message-ID: On 06/03/2019 16:14, duncan smith wrote: > Hello, > I've been trying to figure out why one of my classes can be > pickled but not unpickled. (I realise the problem is probably with the > pickling, but I get the error when I attempt to unpickle.) > > A relatively minimal example is pasted below. > > >>>> import pickle >>>> class test(dict): > def __init__(self, keys, shape=None): > self.shape = shape > for key in keys: > self[key] = None > > def __setitem__(self, key, val): > print (self.shape) > dict.__setitem__(self, key, val) > > >>>> x = test([1,2,3]) > None > None > None >>>> s = pickle.dumps(x) >>>> y = pickle.loads(s) > Traceback (most recent call last): > File "", line 1, in > y = pickle.loads(s) > File "", line 8, in __setitem__ > print (self.shape) > AttributeError: 'test' object has no attribute 'shape' > > > I have DUCkDuckGo'ed the issue and have tinkered with __getnewargs__ and > __getnewargs_ex__ without being able to figure out exactly what's going > on. If I comment out the print call, then it seems to be fine. I'd > appreciate any pointers to the underlying problem. I have one or two > other things I can do to try to isolate the issue further, but I think > the example is perhaps small enough that someone in the know could spot > the problem at a glance. Cheers. > > Duncan > OK, this seems to be a "won't fix" bug dating back to 2003 (https://bugs.python.org/issue826897). The workaround, class DictPlus(dict): def __init__(self, *args, **kwargs): self.extra_thing = ExtraThingClass() dict.__init__(self, *args, **kwargs) def __setitem__(self, k, v): try: do_something_with(self.extra_thing, k, v) except AttributeError: self.extra_thing = ExtraThingClass() do_something_with(self.extra_thing, k, v) dict.__setitem__(self, k, v) def __setstate__(self, adict): pass doesn't work around the problem for me because I need the actual value of self.shape from the original instance. But I only need it for sanity checking, and under the assumption that the original instance was valid, I don't need to do this when unpickling. I haven't managed to find a workaround that exploits that (yet?). Cheers. Duncan From grant.b.edwards at gmail.com Wed Mar 6 13:54:16 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 6 Mar 2019 18:54:16 -0000 (UTC) Subject: Class Issue` References: <2ba83eed-c251-6218-8c79-b1d6e2555506@NetRH.com> <3b7d6163-1836-f786-1bba-ed209a655a33@kynesim.co.uk> <874l8gnfhi.fsf@elektro.pacujo.net> Message-ID: On 2019-03-06, Marko Rauhamaa wrote: > Rhodri James : >> On 06/03/2019 14:15, Calvin Spealman wrote: >>>> C++ (a language I have no respect for) >>> This was uncalled for and inappropriate. Please keep discord civil. >> >> That was the civil version :-) > > C++ is a programming language without feelings. I dunno about that -- I've had to maintain C++ code on a couple projects, and I'm pretty sure C++ hates _me_. > It's nobody's ethnicity, sexual orientation, race or religion, > either. You can despise it freely. And I think I've know people for whom it is their religion. :) That said, I don't think that stating ones lack of respect for some particular programming language is uncivil -- particularly compared to the things I've said about PHP in the past (maybe not in this group). -- Grant Edwards grant.b.edwards Yow! I just heard the at SEVENTIES were over!! And gmail.com I was just getting in touch with my LEISURE SUIT!! From __peter__ at web.de Wed Mar 6 15:24:31 2019 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Mar 2019 21:24:31 +0100 Subject: in a pickle References: Message-ID: duncan smith wrote: > On 06/03/2019 16:14, duncan smith wrote: >> Hello, >> I've been trying to figure out why one of my classes can be >> pickled but not unpickled. (I realise the problem is probably with the >> pickling, but I get the error when I attempt to unpickle.) >> >> A relatively minimal example is pasted below. >> >> >>>>> import pickle >>>>> class test(dict): >> def __init__(self, keys, shape=None): >> self.shape = shape >> for key in keys: >> self[key] = None >> >> def __setitem__(self, key, val): >> print (self.shape) >> dict.__setitem__(self, key, val) >> >> >>>>> x = test([1,2,3]) >> None >> None >> None >>>>> s = pickle.dumps(x) >>>>> y = pickle.loads(s) >> Traceback (most recent call last): >> File "", line 1, in >> y = pickle.loads(s) >> File "", line 8, in __setitem__ >> print (self.shape) >> AttributeError: 'test' object has no attribute 'shape' >> >> >> I have DUCkDuckGo'ed the issue and have tinkered with __getnewargs__ and >> __getnewargs_ex__ without being able to figure out exactly what's going >> on. If I comment out the print call, then it seems to be fine. I'd >> appreciate any pointers to the underlying problem. I have one or two >> other things I can do to try to isolate the issue further, but I think >> the example is perhaps small enough that someone in the know could spot >> the problem at a glance. Cheers. >> >> Duncan >> > > OK, this seems to be a "won't fix" bug dating back to 2003 > (https://bugs.python.org/issue826897). The workaround, > > > class DictPlus(dict): > def __init__(self, *args, **kwargs): > self.extra_thing = ExtraThingClass() > dict.__init__(self, *args, **kwargs) > def __setitem__(self, k, v): > try: > do_something_with(self.extra_thing, k, v) > except AttributeError: > self.extra_thing = ExtraThingClass() > do_something_with(self.extra_thing, k, v) > dict.__setitem__(self, k, v) > def __setstate__(self, adict): > pass > > > doesn't work around the problem for me because I need the actual value > of self.shape from the original instance. But I only need it for sanity > checking, and under the assumption that the original instance was valid, > I don't need to do this when unpickling. I haven't managed to find a > workaround that exploits that (yet?). Cheers. I've been playing around with __getnewargs__(), and it looks like you can get it to work with a custom __new__(). Just set the shape attribute there rather than in __init__(): $ cat pickle_dict_subclass.py import pickle class A(dict): def __new__(cls, keys=(), shape=None): obj = dict.__new__(cls) obj.shape = shape return obj def __init__(self, keys=(), shape=None): print("INIT") for key in keys: self[key] = None print("EXIT") def __setitem__(self, key, val): print(self.shape, ": ", key, " <-- ", val, sep="") super().__setitem__(key, val) def __getnewargs__(self): print("GETNEWARGS") return ("xyz", self.shape) x = A([1, 2, 3], shape="SHAPE") x["foo"] = "bar" print("pickling:") s = pickle.dumps(x) print("unpickling:") y = pickle.loads(s) print(y) $ python3 pickle_dict_subclass.py INIT SHAPE: 1 <-- None SHAPE: 2 <-- None SHAPE: 3 <-- None EXIT SHAPE: foo <-- bar pickling: GETNEWARGS unpickling: SHAPE: 1 <-- None SHAPE: 2 <-- None SHAPE: 3 <-- None SHAPE: foo <-- bar {1: None, 2: None, 3: None, 'foo': 'bar'} It's not clear to me how the dict items survive when they are not included in the __getnewargs__() result, but apparently they do. From ethan at stoneleaf.us Wed Mar 6 19:18:19 2019 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 6 Mar 2019 16:18:19 -0800 Subject: in a pickle In-Reply-To: References: Message-ID: <72186683-ba57-7827-1f48-8dcf788a5390@stoneleaf.us> On 03/06/2019 10:30 AM, duncan smith wrote: > I've been trying to figure out why one of my classes can be > pickled but not unpickled. (I realise the problem is probably with the > pickling, but I get the error when I attempt to unpickle.) > > A relatively minimal example is pasted below. > > > --> import pickle > --> class test(dict): > ... def __init__(self, keys, shape=None): > ... self.shape = shape > ... for key in keys: > ... self[key] = None > ... def __setitem__(self, key, val): > ... print (self.shape) > ... dict.__setitem__(self, key, val) > ... > --> x = test([1,2,3]) > None > None > None > --> s = pickle.dumps(x) > --> y = pickle.loads(s) > Traceback (most recent call last): > File "", line 1, in > y = pickle.loads(s) > File "", line 8, in __setitem__ > print (self.shape) > AttributeError: 'test' object has no attribute 'shape' It seems to me the problem only exists because you are trying to print `self.shape` -- stop printing it, and everything works normally. What problem are you actually trying to solve? -- ~Ethan~ From duncan at invalid.invalid Wed Mar 6 20:18:59 2019 From: duncan at invalid.invalid (duncan smith) Date: Thu, 7 Mar 2019 01:18:59 +0000 Subject: in a pickle In-Reply-To: References: Message-ID: <8k_fE.1130$%l2.824@fx42.iad> On 06/03/2019 20:24, Peter Otten wrote: > duncan smith wrote: > >> On 06/03/2019 16:14, duncan smith wrote: >>> Hello, >>> I've been trying to figure out why one of my classes can be >>> pickled but not unpickled. (I realise the problem is probably with the >>> pickling, but I get the error when I attempt to unpickle.) >>> >>> A relatively minimal example is pasted below. >>> >>> >>>>>> import pickle >>>>>> class test(dict): >>> def __init__(self, keys, shape=None): >>> self.shape = shape >>> for key in keys: >>> self[key] = None >>> >>> def __setitem__(self, key, val): >>> print (self.shape) >>> dict.__setitem__(self, key, val) >>> >>> >>>>>> x = test([1,2,3]) >>> None >>> None >>> None >>>>>> s = pickle.dumps(x) >>>>>> y = pickle.loads(s) >>> Traceback (most recent call last): >>> File "", line 1, in >>> y = pickle.loads(s) >>> File "", line 8, in __setitem__ >>> print (self.shape) >>> AttributeError: 'test' object has no attribute 'shape' >>> >>> >>> I have DUCkDuckGo'ed the issue and have tinkered with __getnewargs__ and >>> __getnewargs_ex__ without being able to figure out exactly what's going >>> on. If I comment out the print call, then it seems to be fine. I'd >>> appreciate any pointers to the underlying problem. I have one or two >>> other things I can do to try to isolate the issue further, but I think >>> the example is perhaps small enough that someone in the know could spot >>> the problem at a glance. Cheers. >>> >>> Duncan >>> >> >> OK, this seems to be a "won't fix" bug dating back to 2003 >> (https://bugs.python.org/issue826897). The workaround, >> >> >> class DictPlus(dict): >> def __init__(self, *args, **kwargs): >> self.extra_thing = ExtraThingClass() >> dict.__init__(self, *args, **kwargs) >> def __setitem__(self, k, v): >> try: >> do_something_with(self.extra_thing, k, v) >> except AttributeError: >> self.extra_thing = ExtraThingClass() >> do_something_with(self.extra_thing, k, v) >> dict.__setitem__(self, k, v) >> def __setstate__(self, adict): >> pass >> >> >> doesn't work around the problem for me because I need the actual value >> of self.shape from the original instance. But I only need it for sanity >> checking, and under the assumption that the original instance was valid, >> I don't need to do this when unpickling. I haven't managed to find a >> workaround that exploits that (yet?). Cheers. > > I've been playing around with __getnewargs__(), and it looks like you can > get it to work with a custom __new__(). Just set the shape attribute there > rather than in __init__(): > > $ cat pickle_dict_subclass.py > import pickle > > > class A(dict): > def __new__(cls, keys=(), shape=None): > obj = dict.__new__(cls) > obj.shape = shape > return obj > > def __init__(self, keys=(), shape=None): > print("INIT") > for key in keys: > self[key] = None > print("EXIT") > > def __setitem__(self, key, val): > print(self.shape, ": ", key, " <-- ", val, sep="") > super().__setitem__(key, val) > > def __getnewargs__(self): > print("GETNEWARGS") > return ("xyz", self.shape) > > x = A([1, 2, 3], shape="SHAPE") > x["foo"] = "bar" > print("pickling:") > s = pickle.dumps(x) > print("unpickling:") > y = pickle.loads(s) > print(y) > $ python3 pickle_dict_subclass.py > INIT > SHAPE: 1 <-- None > SHAPE: 2 <-- None > SHAPE: 3 <-- None > EXIT > SHAPE: foo <-- bar > pickling: > GETNEWARGS > unpickling: > SHAPE: 1 <-- None > SHAPE: 2 <-- None > SHAPE: 3 <-- None > SHAPE: foo <-- bar > {1: None, 2: None, 3: None, 'foo': 'bar'} > > It's not clear to me how the dict items survive when they are not included > in the __getnewargs__() result, but apparently they do. > > > Thanks Peter. The docs for pickle say "When a class instance is unpickled, its __init__() method is usually not invoked. The default behaviour first creates an uninitialized instance and then restores the saved attributes." Your outputs above seem to confirm that it isn't calling my __init__(), but it *is* calling my __setitem__() when it is restoring the dict items. I actually have about 50-60 lines of code in my real __setitem__(), but I probably don't need it if I'm unpickling. My __setitem__() actually updates a secondary data structure which was why I thought I needed to do more than just restore the items, but if that's going to be restored in the same way I just need the dict items to be restored. The following seems to achieve that. def __setitem__(self, key, val): try: self.shape except AttributeError: dict.__setitem__(self, key, val) else: # do other stuff A bit close to original workaround that I didn't think would work (although that used __setstate__() for some reason). I'm not sure I prefer it to defining __new__() though. Ideally I'd have something like, def __setitem__(self, key, val): if unpickling: dict.__setitem__(self, key, val) else: # do other stuff rather than potentially masking a bug. Anyway, thanks for your solution and the outputs that pointed me to another possible solution. Cheers. Duncan From duncan at invalid.invalid Wed Mar 6 20:52:10 2019 From: duncan at invalid.invalid (duncan smith) Date: Thu, 7 Mar 2019 01:52:10 +0000 Subject: in a pickle In-Reply-To: References: <72186683-ba57-7827-1f48-8dcf788a5390@stoneleaf.us> Message-ID: On 07/03/2019 00:18, Ethan Furman wrote: > On 03/06/2019 10:30 AM, duncan smith wrote: > >> ?I've been trying to figure out why one of my classes can be >> pickled but not unpickled. (I realise the problem is probably with the >> pickling, but I get the error when I attempt to unpickle.) >> >> A relatively minimal example is pasted below. >> >> >> --> import pickle >> --> class test(dict): >> ...??? def __init__(self, keys, shape=None): >> ...??????? self.shape = shape >> ...??????? for key in keys: >> ...??????????? self[key] = None >> ...??? def __setitem__(self, key, val): >> ...??????? print (self.shape) >> ...??????? dict.__setitem__(self, key, val) >> ... >> --> x = test([1,2,3]) >> None >> None >> None >> --> s = pickle.dumps(x) >> --> y = pickle.loads(s) >> Traceback (most recent call last): >> ?? File "", line 1, in >> ???? y = pickle.loads(s) >> ?? File "", line 8, in __setitem__ >> ???? print (self.shape) >> AttributeError: 'test' object has no attribute 'shape' > > It seems to me the problem only exists because you are trying to print > `self.shape` -- stop printing it, and everything works normally. > > What problem are you actually trying to solve? > > -- > ~Ethan~ > Accessing self.shape at that point in the code. In my actual code I am updating a secondary data structure and doing some sanity checking at that point. That fails because self.shape doesn't exist. Peter's post makes it clear that although it fails in my __setitem__() it is not via calling my __init__(). It must be being called by pickle.loads(). So on the basis that pickle.loads() will restore the secondary data structure correctly, and having no need for sanity checking assuming the original object was valid, then the problem almost goes away. e.g. I can catch the AttributeError and just call dict.__setitem__(self, key, val). That I still need to test. I might yet employ Peter's solution (for when I thought I needed access to self.shape and other attributes, which I now doubt) which is to define __new__() so that the relevant attributes do exist when they are required. Duncan From jim.womeldorf at gmail.com Thu Mar 7 08:16:43 2019 From: jim.womeldorf at gmail.com (jim.womeldorf at gmail.com) Date: Thu, 7 Mar 2019 05:16:43 -0800 (PST) Subject: ConfigParser: use newline in INI file In-Reply-To: <6b8279ba-135b-4412-b332-c92c0ed076ae@googlegroups.com> References: <85lgy7kev5.fsf@benfinney.id.au> <6b8279ba-135b-4412-b332-c92c0ed076ae@googlegroups.com> Message-ID: On Saturday, October 1, 2016 at 7:41:40 PM UTC-5, Ned Batchelder wrote: > On Saturday, October 1, 2016 at 6:25:16 PM UTC-4, Thorsten Kampe wrote: > > * Ben Finney (Sun, 02 Oct 2016 07:12:46 +1100) > > > > > > Thorsten Kampe writes: > > > > > > > ConfigParser escapes `\n` in ini values as `\\n`. > > > > Indenting solves the problem. I'd rather keep it one line per value > > but it solves the problem. > > If you want to have \n mean a newline in your config file, you can > do the conversion after you read the value: > > >>> "a\\nb".decode("string-escape") > 'a\nb' > > --Ned. Wow! Thanks so much Ned. I've been looking for the solution to this issue for several days and had nearly given up. Jim From lists at vanderhoff.org Thu Mar 7 09:36:21 2019 From: lists at vanderhoff.org (tony) Date: Thu, 7 Mar 2019 15:36:21 +0100 Subject: ConfigParser: use newline in INI file In-Reply-To: References: <85lgy7kev5.fsf@benfinney.id.au> <6b8279ba-135b-4412-b332-c92c0ed076ae@googlegroups.com> Message-ID: <891db9ed-9e68-6814-fed7-7598fb93f31c@vanderhoff.org> On 07/03/2019 14:16, jim.womeldorf at gmail.com wrote: > On Saturday, October 1, 2016 at 7:41:40 PM UTC-5, Ned Batchelder wrote: >> On Saturday, October 1, 2016 at 6:25:16 PM UTC-4, Thorsten Kampe wrote: >>> * Ben Finney (Sun, 02 Oct 2016 07:12:46 +1100) >>>> >>>> Thorsten Kampe writes: >>>> >>>>> ConfigParser escapes `\n` in ini values as `\\n`. >>> >>> Indenting solves the problem. I'd rather keep it one line per value >>> but it solves the problem. >> >> If you want to have \n mean a newline in your config file, you can >> do the conversion after you read the value: >> >> >>> "a\\nb".decode("string-escape") >> 'a\nb' >> >> --Ned. > > Wow! Thanks so much Ned. I've been looking for the solution to this issue for several days and had nearly given up. > Jim > How does that translate to Python3? From jim.womeldorf at gmail.com Thu Mar 7 10:58:48 2019 From: jim.womeldorf at gmail.com (jim.womeldorf at gmail.com) Date: Thu, 7 Mar 2019 07:58:48 -0800 (PST) Subject: ConfigParser: use newline in INI file In-Reply-To: References: <85lgy7kev5.fsf@benfinney.id.au> <6b8279ba-135b-4412-b332-c92c0ed076ae@googlegroups.com> <891db9ed-9e68-6814-fed7-7598fb93f31c@vanderhoff.org> Message-ID: <481a6357-06fb-4132-a42b-e436c2879a8c@googlegroups.com> On Thursday, March 7, 2019 at 8:55:31 AM UTC-6, tony wrote: > On 07/03/2019 14:16, jim.womeldorf at gmail.com wrote: > > On Saturday, October 1, 2016 at 7:41:40 PM UTC-5, Ned Batchelder wrote: > >> On Saturday, October 1, 2016 at 6:25:16 PM UTC-4, Thorsten Kampe wrote: > >>> * Ben Finney (Sun, 02 Oct 2016 07:12:46 +1100) > >>>> > >>>> Thorsten Kampe writes: > >>>> > >>>>> ConfigParser escapes `\n` in ini values as `\\n`. > >>> > >>> Indenting solves the problem. I'd rather keep it one line per value > >>> but it solves the problem. > >> > >> If you want to have \n mean a newline in your config file, you can > >> do the conversion after you read the value: > >> > >> >>> "a\\nb".decode("string-escape") > >> 'a\nb' > >> > >> --Ned. > > > > Wow! Thanks so much Ned. I've been looking for the solution to this issue for several days and had nearly given up. > > Jim > > > How does that translate to Python3? I have no idea. I'm on 2.7.3 I'd be interested in knowing if someone would try it on 3. I do very little Python programming. I've written a messaging system for Linuxcnc and could not get it to work using bash, so I tried Python and now, thanks to you, I have it working. I can provide you with the code if you want to play with it. When it is run with an integer as a parameter it displays a message from an INI file. Jim From __peter__ at web.de Thu Mar 7 11:19:41 2019 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Mar 2019 17:19:41 +0100 Subject: ConfigParser: use newline in INI file References: <85lgy7kev5.fsf@benfinney.id.au> <6b8279ba-135b-4412-b332-c92c0ed076ae@googlegroups.com> <891db9ed-9e68-6814-fed7-7598fb93f31c@vanderhoff.org> Message-ID: tony wrote: >> On Saturday, October 1, 2016 at 7:41:40 PM UTC-5, Ned Batchelder wrote: >>> If you want to have \n mean a newline in your config file, you can >>> do the conversion after you read the value: >>> >>> >>> "a\\nb".decode("string-escape") >>> 'a\nb' > How does that translate to Python3? >>> import codecs >>> codecs.decode("a\\nb", "unicode-escape") 'a\nb' From lists at vanderhoff.org Thu Mar 7 11:19:38 2019 From: lists at vanderhoff.org (tony) Date: Thu, 7 Mar 2019 17:19:38 +0100 Subject: ConfigParser: use newline in INI file In-Reply-To: <481a6357-06fb-4132-a42b-e436c2879a8c@googlegroups.com> References: <85lgy7kev5.fsf@benfinney.id.au> <6b8279ba-135b-4412-b332-c92c0ed076ae@googlegroups.com> <891db9ed-9e68-6814-fed7-7598fb93f31c@vanderhoff.org> <481a6357-06fb-4132-a42b-e436c2879a8c@googlegroups.com> Message-ID: On 07/03/2019 16:58, jim.womeldorf at gmail.com wrote: > On Thursday, March 7, 2019 at 8:55:31 AM UTC-6, tony wrote: >> On 07/03/2019 14:16, jim.womeldorf at gmail.com wrote: >>> On Saturday, October 1, 2016 at 7:41:40 PM UTC-5, Ned Batchelder wrote: >>>> On Saturday, October 1, 2016 at 6:25:16 PM UTC-4, Thorsten Kampe wrote: >>>>> * Ben Finney (Sun, 02 Oct 2016 07:12:46 +1100) >>>>>> >>>>>> Thorsten Kampe writes: >>>>>> >>>>>>> ConfigParser escapes `\n` in ini values as `\\n`. >>>>> >>>>> Indenting solves the problem. I'd rather keep it one line per value >>>>> but it solves the problem. >>>> >>>> If you want to have \n mean a newline in your config file, you can >>>> do the conversion after you read the value: >>>> >>>> >>> "a\\nb".decode("string-escape") >>>> 'a\nb' >>>> >>>> --Ned. >>> >>> Wow! Thanks so much Ned. I've been looking for the solution to this issue for several days and had nearly given up. >>> Jim >>> >> How does that translate to Python3? > > I have no idea. I'm on 2.7.3 > I'd be interested in knowing if someone would try it on 3. > I do very little Python programming. I've written a messaging system for Linuxcnc and could not get it to work using bash, so I tried Python and now, thanks to you, I have it working. > I can provide you with the code if you want to play with it. When it is run with an integer as a parameter it displays a message from an INI file. > Jim > Python 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. >>> >>> "a\\nb".decode("string-escape") Traceback (most recent call last): File "", line 1, in AttributeError: 'str' object has no attribute 'decode' >>> From jim.womeldorf at gmail.com Thu Mar 7 11:37:50 2019 From: jim.womeldorf at gmail.com (jim.womeldorf at gmail.com) Date: Thu, 7 Mar 2019 08:37:50 -0800 (PST) Subject: ConfigParser: use newline in INI file In-Reply-To: References: Message-ID: On Saturday, October 1, 2016 at 9:57:24 AM UTC-5, Thorsten Kampe wrote: > Hi, > > ConfigParser escapes `\n` in ini values as `\\n`. Is there a way to > signal to ConfigParser that there is a line break? > > Thorsten And now we know! I think they should have named Python 3 something else From jim.womeldorf at gmail.com Thu Mar 7 11:59:27 2019 From: jim.womeldorf at gmail.com (jim.womeldorf at gmail.com) Date: Thu, 7 Mar 2019 08:59:27 -0800 (PST) Subject: ConfigParser: use newline in INI file In-Reply-To: References: Message-ID: On Thursday, March 7, 2019 at 10:38:03 AM UTC-6, jim.wo... at gmail.com wrote: > On Saturday, October 1, 2016 at 9:57:24 AM UTC-5, Thorsten Kampe wrote: > > Hi, > > > > ConfigParser escapes `\n` in ini values as `\\n`. Is there a way to > > signal to ConfigParser that there is a line break? > > > > Thorsten > > And now we know! > I think they should have named Python 3 something else I just tried "unicode_decode" in place of "string-decode" and it works. My impression is that it will also work in Python 3 From python.list at tim.thechases.com Thu Mar 7 11:46:19 2019 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 7 Mar 2019 10:46:19 -0600 Subject: ConfigParser: use newline in INI file In-Reply-To: References: <85lgy7kev5.fsf@benfinney.id.au> <6b8279ba-135b-4412-b332-c92c0ed076ae@googlegroups.com> <891db9ed-9e68-6814-fed7-7598fb93f31c@vanderhoff.org> <481a6357-06fb-4132-a42b-e436c2879a8c@googlegroups.com> Message-ID: <20190307104619.26fe8e01@bigbox.christie.dr> On 2019-03-07 17:19, tony wrote: > Python 3.5.3 (default, Sep 27 2018, 17:25:39) > >>> "a\\nb".decode("string-escape") > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'str' object has no attribute 'decode' Looks like bytestring.decode('unicode_escape') does what you're describing: >>> b"hello\nworld".decode('unicode_escape') 'hello\nworld' >>> print(b"hello\nworld".decode('unicode_escape')) hello world -tkc From skauser at rocketsoftware.com Thu Mar 7 22:24:02 2019 From: skauser at rocketsoftware.com (Saba Kauser) Date: Fri, 8 Mar 2019 03:24:02 +0000 Subject: "How to package additional files under site-packages " In-Reply-To: <87k1hca4dt.fsf@handshake.de> References: <87o96p25kd.fsf@handshake.de> <87k1hca4dt.fsf@handshake.de> Message-ID: Thank you! I used get_python_lib() for directory in data_files, and it seem to have worked. Thanks for your assistance! -----Original Message----- From: dieter Sent: Wednesday, March 6, 2019 12:15 PM To: python-list at python.org Subject: Re: "How to package additional files under site-packages " Saba Kauser writes: > ... > My package (ibm_db) has LICENSE, README.md and CHANGES files that I want to be available in the same location as my package is installed I.e under site-packages. However, with current setup.py https://github.com/ibmdb/python-ibmdb/blob/master/IBM_DB/ibm_db/setup.py, these files get installed under python install path. > e.g: C:\Users\skauser\AppData\Local\Programs\Python\Python36\LICENSE > > I have specified them as: > data_files = [ ('', ['./README.md']), > ('', ['./CHANGES']), > ('', ['./LICENSE']) ] > > Setup( > .. > package_data = package_data, > data_files = data_files, > include_package_data = True, > cmdclass = cmd_class, > ..) > > Since the directory path is empty, these files get copied under current path of execution. However, I want them to be copied under the install location of my package. > Is there any other way I can achieve this? As you do not want to follow my example, maybe read the "setuptools" documentation. There definitely is a way to achieve your goal -- other than my approach. If necessary override parts of the "distutils/setuptools" machinery. ================================ Rocket Software, Inc. and subsidiaries ? 77 Fourth Avenue, Waltham MA 02451 ? Main Office Toll Free Number: +1 855.577.4323 Contact Customer Support: https://my.rocketsoftware.com/RocketCommunity/RCEmailSupport Unsubscribe from Marketing Messages/Manage Your Subscription Preferences - http://www.rocketsoftware.com/manage-your-email-preferences Privacy Policy - http://www.rocketsoftware.com/company/legal/privacy-policy ================================ This communication and any attachments may contain confidential information of Rocket Software, Inc. All unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify Rocket Software immediately and destroy all copies of this communication. Thank you. From drake.gossi at gmail.com Fri Mar 8 14:12:56 2019 From: drake.gossi at gmail.com (Drake Gossi) Date: Fri, 8 Mar 2019 11:12:56 -0800 Subject: trying to retrieve comments with activated API key Message-ID: Hi everyone, I'm further along than I was last time. I've installed python and am running this in spyder. This is the code I'm working with: import requests import csv import time import sys api_key = 'my api key' docket_id = 'ED-2018-OCR-0064' total_docs = 32068 docs_per_page = 1000 Where the "my api key" is, is actually my api key. I was just told not to give it out. But I put this into spyder and clicked run and nothing happened. I went to right before "import requests and clicked run." I think. I'm better in R. But I'm horrible at both. If you can't already tell. Well, this might have happened: runfile('/Users/susan/.spyder-py3/temp.py', wdir='/Users/susan/.spyder-py3') but I don't know what to do with it, if it actually happened. But I feel like I'm missing something super important. Like, for instance, how is python being told to go to the right website? Again, I'm trying to retrieve these comments off of regulations.gov. I don't know if this helps, but the interactive API interface is here . I've installed anaconda. I was told to get postman. Should I get postman? Help! At the end of the day, I'm trying to use python to get the comments from regulations.gov into a csv file so that I can analyze them in R. And then I think that I only need the name, comment, date, and category in the JSON dictionary. I can't send a picture through the list, but I have one of what I'm talking about. Drake From rosuav at gmail.com Fri Mar 8 14:29:20 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Mar 2019 06:29:20 +1100 Subject: trying to retrieve comments with activated API key In-Reply-To: References: Message-ID: On Sat, Mar 9, 2019 at 6:14 AM Drake Gossi wrote: > > Hi everyone, > > I'm further along than I was last time. I've installed python and am > running this in spyder. This is the code I'm working with: > > import requests > import csv > import time > import sys > api_key = 'my api key' > docket_id = 'ED-2018-OCR-0064' > total_docs = 32068 > docs_per_page = 1000 This is all just setup. You're importing some useful modules and setting up some variables. > runfile('/Users/susan/.spyder-py3/temp.py', wdir='/Users/susan/.spyder-py3') Not sure what's going on here; is that something you ran? Did you create the file in a hidden directory? > But I feel like I'm missing something super important. Like, for instance, > how is python being told to go to the right website? Again, I'm trying to > retrieve these comments > > off of regulations.gov. I don't know if this helps, but the interactive API > interface is here . > Help! At the end of the day, I'm trying to use python to get the comments > from regulations.gov into a csv file so that I can analyze them in R. I'm not sure about comments, but based on the docs you linked to, I would try to retrieve some documents. The first block in that page says: GET /documents.{response_format} The response_format will be JSON (you mentioned wanting to use JSON), so that means you're trying to get /documents.json. Try out the interactive parameter setting, and then use the button at the bottom to get a URL. As a bare minimum, it'll be something like this: https://api.data.gov:443/regulations/v3/documents.json?api_key=DEMO_KEY (No, I've no idea why it says ":443" in there.) To do that from Python, make a call like this: r = requests.get("https://api.data.gov:443/regulations/v3/documents.json", params={ "api_key": api_key, "dktid": docket_id, }) Add whichever parameters you need in there; it's a plain Python dictionary, so you can create it any way you like. That should give you back a *response* object. The easiest thing to do from there is to turn HTTP errors into Python exceptions, and then get the results as JSON: r.raise_for_status() data = r.json() At this point, 'data' should be a dict or list with the content that you want. It's up to you to delve into that. Have fun! Hopefully that can get you started. ChrisA From Gronicus at SGA.Ninja Fri Mar 8 13:13:49 2019 From: Gronicus at SGA.Ninja (Steve) Date: Fri, 8 Mar 2019 13:13:49 -0500 Subject: System Beep? Message-ID: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> How can I cause a system beep using code? This is using the computer's internal speaker, not an audio external speaker. Do I have control of duration or volume? Steve Footnote: Every minute, every single day, the equivalent of a truckload of plastic enters our oceans. From t2 at NetRH.com Fri Mar 8 14:37:06 2019 From: t2 at NetRH.com (Milt) Date: Fri, 8 Mar 2019 11:37:06 -0800 Subject: Duplicates Message-ID: I get two messages for every post - py at NetRH.com -- Regards, Milt Milt at RatcliffNet.com From Gronicus at SGA.Ninja Fri Mar 8 14:55:40 2019 From: Gronicus at SGA.Ninja (Steve) Date: Fri, 8 Mar 2019 14:55:40 -0500 Subject: Duplicates In-Reply-To: References: Message-ID: <000401d4d5e8$e8a2f670$b9e8e350$@SGA.Ninja> Are they going to the same or another eddress? Do you have a second e-mail address in the list? Footnote: Ultrasound Technician Asks Pregnant Woman If She'd Like To Know Baby's Name -----Original Message----- From: Python-list On Behalf Of Milt Sent: Friday, March 8, 2019 2:37 PM To: python-list at python.org Subject: Duplicates I get two messages for every post - py at NetRH.com -- Regards, Milt Milt at RatcliffNet.com -- https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Fri Mar 8 14:55:33 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Fri, 8 Mar 2019 13:55:33 -0600 Subject: System Beep? In-Reply-To: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> Message-ID: Hi, On Fri, Mar 8, 2019 at 1:35 PM Steve wrote: > > How can I cause a system beep using code? > This is using the computer's internal speaker, not an audio external > speaker. Print 0x07. Thank you. > Do I have control of duration or volume? > > Steve > > > > > > Footnote: > Every minute, every single day, the equivalent of a truckload of plastic > enters our oceans. > > > -- > https://mail.python.org/mailman/listinfo/python-list From David.Raymond at tomtom.com Fri Mar 8 15:01:50 2019 From: David.Raymond at tomtom.com (David Raymond) Date: Fri, 8 Mar 2019 20:01:50 +0000 Subject: System Beep? In-Reply-To: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> Message-ID: Windows has the built in winsound module that lets you set frequency and duration, not sure about other OS's. https://docs.python.org/3.7/library/winsound.html -----Original Message----- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom.com at python.org] On Behalf Of Steve Sent: Friday, March 08, 2019 1:14 PM To: python-list at python.org Subject: System Beep? How can I cause a system beep using code? This is using the computer's internal speaker, not an audio external speaker. Do I have control of duration or volume? Steve Footnote: Every minute, every single day, the equivalent of a truckload of plastic enters our oceans. -- https://mail.python.org/mailman/listinfo/python-list From Gronicus at SGA.Ninja Fri Mar 8 15:16:28 2019 From: Gronicus at SGA.Ninja (Steve) Date: Fri, 8 Mar 2019 15:16:28 -0500 Subject: System Beep? In-Reply-To: References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> Message-ID: <000b01d4d5eb$d0ab11d0$72013570$@SGA.Ninja> ========= RESTART: C:\____Gork\Med Insulin codes\MedReminder 127.py ========= Traceback (most recent call last): File "C:\____Gork\Med Insulin codes\MedReminder 127.py", line 13, in windsound.Beep #(frequency, duration) NameError: name 'windsound' is not defined Something missing in my code? ------------------------------------------------------------------------ 98% of lawyers give the other 2% a bad name. -----Original Message----- From: Python-list On Behalf Of David Raymond Sent: Friday, March 8, 2019 3:02 PM To: python-list at python.org Subject: RE: System Beep? Windows has the built in winsound module that lets you set frequency and duration, not sure about other OS's. https://docs.python.org/3.7/library/winsound.html -----Original Message----- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom.com at python.org] On Behalf Of Steve Sent: Friday, March 08, 2019 1:14 PM To: python-list at python.org Subject: System Beep? How can I cause a system beep using code? This is using the computer's internal speaker, not an audio external speaker. Do I have control of duration or volume? Steve Footnote: Every minute, every single day, the equivalent of a truckload of plastic enters our oceans. -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list From David.Raymond at tomtom.com Fri Mar 8 15:20:34 2019 From: David.Raymond at tomtom.com (David Raymond) Date: Fri, 8 Mar 2019 20:20:34 +0000 Subject: System Beep? In-Reply-To: <000b01d4d5eb$d0ab11d0$72013570$@SGA.Ninja> References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <000b01d4d5eb$d0ab11d0$72013570$@SGA.Ninja> Message-ID: I believe you added an extra D there. winsound, not winDsound -----Original Message----- From: Steve [mailto:Gronicus at SGA.Ninja] Sent: Friday, March 08, 2019 3:16 PM To: David Raymond; python-list at python.org Subject: RE: System Beep? ========= RESTART: C:\____Gork\Med Insulin codes\MedReminder 127.py ========= Traceback (most recent call last): File "C:\____Gork\Med Insulin codes\MedReminder 127.py", line 13, in windsound.Beep #(frequency, duration) NameError: name 'windsound' is not defined Something missing in my code? ------------------------------------------------------------------------ 98% of lawyers give the other 2% a bad name. -----Original Message----- From: Python-list On Behalf Of David Raymond Sent: Friday, March 8, 2019 3:02 PM To: python-list at python.org Subject: RE: System Beep? Windows has the built in winsound module that lets you set frequency and duration, not sure about other OS's. https://docs.python.org/3.7/library/winsound.html -----Original Message----- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom.com at python.org] On Behalf Of Steve Sent: Friday, March 08, 2019 1:14 PM To: python-list at python.org Subject: System Beep? How can I cause a system beep using code? This is using the computer's internal speaker, not an audio external speaker. Do I have control of duration or volume? Steve Footnote: Every minute, every single day, the equivalent of a truckload of plastic enters our oceans. -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list From Gronicus at SGA.Ninja Fri Mar 8 15:25:05 2019 From: Gronicus at SGA.Ninja (Steve) Date: Fri, 8 Mar 2019 15:25:05 -0500 Subject: System Beep? In-Reply-To: References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> Message-ID: <000e01d4d5ed$04d0df70$0e729e50$@SGA.Ninja> I used print(0x07) as the system called for parentheses but no error but also no sound. Should this use a default or do I have to specify frequency and duration? Footnote: Ultrasound Technician Asks Pregnant Woman If She?d Like To Know Baby?s Name -----Original Message----- From: Igor Korot Sent: Friday, March 8, 2019 2:56 PM To: Steve Cc: python-list at python.org Subject: Re: System Beep? Hi, On Fri, Mar 8, 2019 at 1:35 PM Steve wrote: > > How can I cause a system beep using code? > This is using the computer's internal speaker, not an audio external > speaker. Print 0x07. Thank you. > Do I have control of duration or volume? > > Steve > > > > > > Footnote: > Every minute, every single day, the equivalent of a truckload of > plastic enters our oceans. > > > -- > https://mail.python.org/mailman/listinfo/python-list From rambiusparkisanius at gmail.com Fri Mar 8 15:24:47 2019 From: rambiusparkisanius at gmail.com (Ivan "Rambius" Ivanov) Date: Fri, 8 Mar 2019 15:24:47 -0500 Subject: System Beep? In-Reply-To: <000b01d4d5eb$d0ab11d0$72013570$@SGA.Ninja> References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <000b01d4d5eb$d0ab11d0$72013570$@SGA.Ninja> Message-ID: Hello, On Fri, Mar 8, 2019, 3:19 PM Steve wrote: > ========= RESTART: C:\____Gork\Med Insulin codes\MedReminder 127.py > ========= > Traceback (most recent call last): > File "C:\____Gork\Med Insulin codes\MedReminder 127.py", line 13, in > > windsound.Beep #(frequency, duration) > NameError: name 'windsound' is not defined > > Something missing in my code? > You have a typo. It is winsound, not winDsound. Regards rambius > ------------------------------------------------------------------------ > 98% of lawyers give the other 2% a bad name. > > > -----Original Message----- > From: Python-list On > Behalf Of David Raymond > Sent: Friday, March 8, 2019 3:02 PM > To: python-list at python.org > Subject: RE: System Beep? > > Windows has the built in winsound module that lets you set frequency and > duration, not sure about other OS's. > > https://docs.python.org/3.7/library/winsound.html > > > -----Original Message----- > From: Python-list > [mailto:python-list-bounces+david.raymond=tomtom.com at python.org] On Behalf > Of Steve > Sent: Friday, March 08, 2019 1:14 PM > To: python-list at python.org > Subject: System Beep? > > How can I cause a system beep using code? > This is using the computer's internal speaker, not an audio external > speaker. > Do I have control of duration or volume? > > Steve > > > > > > Footnote: > Every minute, every single day, the equivalent of a truckload of plastic > enters our oceans. > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- > https://mail.python.org/mailman/listinfo/python-list > > -- > https://mail.python.org/mailman/listinfo/python-list > From Gronicus at SGA.Ninja Fri Mar 8 15:31:56 2019 From: Gronicus at SGA.Ninja (Steve) Date: Fri, 8 Mar 2019 15:31:56 -0500 Subject: System Beep? In-Reply-To: References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <000b01d4d5eb$d0ab11d0$72013570$@SGA.Ninja> Message-ID: <001601d4d5ed$f9f55f80$ede01e80$@SGA.Ninja> Yes, I saw that. It still failed with, or without, the ?d?. I played with case and the use of (). They all produced similar errors Footnote: Ultrasound Technician Asks Pregnant Woman If She?d Like To Know Baby?s Name From: Ivan "Rambius" Ivanov Sent: Friday, March 8, 2019 3:25 PM To: Steve Cc: David Raymond ; python-list at python.org Subject: Re: System Beep? Hello, On Fri, Mar 8, 2019, 3:19 PM Steve > wrote: ========= RESTART: C:\____Gork\Med Insulin codes\MedReminder 127.py ========= Traceback (most recent call last): File "C:\____Gork\Med Insulin codes\MedReminder 127.py", line 13, in windsound.Beep #(frequency, duration) NameError: name 'windsound' is not defined Something missing in my code? You have a typo. It is winsound, not winDsound. Regards rambius ------------------------------------------------------------------------ 98% of lawyers give the other 2% a bad name. -----Original Message----- From: Python-list > On Behalf Of David Raymond Sent: Friday, March 8, 2019 3:02 PM To: python-list at python.org Subject: RE: System Beep? Windows has the built in winsound module that lets you set frequency and duration, not sure about other OS's. https://docs.python.org/3.7/library/winsound.html -----Original Message----- From: Python-list [mailto:python-list-bounces+david.raymond =tomtom.com at python.org ] On Behalf Of Steve Sent: Friday, March 08, 2019 1:14 PM To: python-list at python.org Subject: System Beep? How can I cause a system beep using code? This is using the computer's internal speaker, not an audio external speaker. Do I have control of duration or volume? Steve Footnote: Every minute, every single day, the equivalent of a truckload of plastic enters our oceans. -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Fri Mar 8 15:42:23 2019 From: __peter__ at web.de (Peter Otten) Date: Fri, 08 Mar 2019 21:42:23 +0100 Subject: System Beep? References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <000b01d4d5eb$d0ab11d0$72013570$@SGA.Ninja> <001601d4d5ed$f9f55f80$ede01e80$@SGA.Ninja> Message-ID: Steve wrote: >> You have a typo. It is winsound, not winDsound. > Yes, I saw that. It still failed with, or without, the ?d?. I played > with case and the use of (). They all produced similar errors Did you import the winsound module before trying to use it? From drake.gossi at gmail.com Fri Mar 8 15:43:43 2019 From: drake.gossi at gmail.com (Drake Gossi) Date: Fri, 8 Mar 2019 12:43:43 -0800 Subject: trying to retrieve comments with activated API key In-Reply-To: References: Message-ID: Still having issues: 7. import requests 8. import csv 9. import time 10. import sys 11. api_key = 'PUT API KEY HERE' 12. docket_id = 'ED-2018-OCR-0064' 13. total_docs = 32068 14. docs_per_page = 1000 15. 16. r = requests.get("https://api.data.gov:443/regulations/v3/documents.json ", 17. params={ 18. "api_key": api_key, 19. "dktid": docket_id, 20. "rrp": docs_per_page, }) I'm getting an "imported but unused" by 8, 9 & 10. But then also, on the interactive API , it has something called a "po"--i.e., page offset. I was able to figure out that "rrp" means results per page, but now I'm unsure how to get all 32000 comments into a response object. Do I have to add an "ro" on line 21? or something else? Also, I ran the code as is starting on line 7 and got this: runfile('/Users/susan/.spyder-py3/temp.py', wdir='/Users/susan/.spyder-py3') This was in the terminal, I think. Since nothing popped up in what I assume is the environment--I'm running this in spyder--I assume it didn't work. Drake On Fri, Mar 8, 2019 at 12:29 PM Chris Angelico wrote: > On Sat, Mar 9, 2019 at 7:26 AM Drake Gossi wrote: > > > > Yea, it looks like the request url is: > > > > import requests > > import csv > <-------------------------------------------------------------------on > these three, I have an "imported but unused warning" > > import time > <------------------------------------------------------------------- > > import sys > <------------------------------------------------------------------- > > api_key = 'PUT API KEY HERE' > > docket_id = 'ED-2018-OCR-0064' > > total_docs = 32068 <-but then also, what happens here? does it have to > do with po page offset? how do I get all 32000 instead of a 1000 > > docs_per_page = 1000 > > > > Can you post on the list, please? Also - leave the original text as > is, and add your responses underneath, like this; don't use colour to > indicate what's your text and what you're replying to, as not everyone > can see colour. Text is the only form that truly communicates. > > ChrisA > From rosuav at gmail.com Fri Mar 8 15:51:00 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Mar 2019 07:51:00 +1100 Subject: trying to retrieve comments with activated API key In-Reply-To: References: Message-ID: On Sat, Mar 9, 2019 at 7:47 AM Drake Gossi wrote: > > Still having issues: > > 7. import requests > 8. import csv > 9. import time > 10. import sys > 11. api_key = 'PUT API KEY HERE' > 12. docket_id = 'ED-2018-OCR-0064' > 13. total_docs = 32068 > 14. docs_per_page = 1000 > 15. > 16. r = requests.get("https://api.data.gov:443/regulations/v3/documents.json > ", > 17. params={ > 18. "api_key": api_key, > 19. "dktid": docket_id, > 20. "rrp": docs_per_page, > > }) > > I'm getting an "imported but unused" by 8, 9 & 10. Doesn't matter - may as well leave them in. > But then also, on the interactive API > , > it has something called a "po"--i.e., page offset. I was able to figure out > that "rrp" means results per page, but now I'm unsure how to get all 32000 > comments into a response object. Do I have to add an "ro" on line 21? or > something else? Probably you'll need a loop. For now, don't worry about it, and concentrate on getting the first page. > Also, I ran the code as is starting on line 7 and got this: > > runfile('/Users/susan/.spyder-py3/temp.py', wdir='/Users/susan/.spyder-py3') > > This was in the terminal, I think. Since nothing popped up in what I assume > is the environment--I'm running this in spyder--I assume it didn't work. Ahh, that might be making things confusing. My recommendation is to avoid Spyder altogether. Just run your script directly and let it do its downloading. Keep it simple! ChrisA From PythonList at DancesWithMice.info Fri Mar 8 15:51:24 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 9 Mar 2019 09:51:24 +1300 Subject: System Beep? In-Reply-To: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> Message-ID: <279e5a0a-4707-3d71-5c91-c08f24c16a37@DancesWithMice.info> Dear Squeak, sorry, Dear Steve, Back in the ?good, old days when we used to walk alongside a mainframe CPU whilst it cogitated, we would often use the BEL character to alert us to job completion (and meantime bunk-off to go have a coffee, cakes, ...) - more seriously, it alerted telegraph and telex operators to an incoming message (you can still hear similar "beeps" on some emergency-worker radio systems, NASA moon mission video-replays, etc). In the grips of nostalgia, I tried to make it work using the REPL, and failed, but first... On 9/03/19 7:13 AM, Steve wrote: > How can I cause a system beep using code? > This is using the computer's internal speaker, not an audio external > speaker. > Do I have control of duration or volume? The BEL character was included in the ASCII standard as chr(7)*. Back in those days, the rest of the world didn't exist - the "A" stands for "American". Accordingly, the huge advance was that we would be allowed to use lower-case letters, instead of all-caps (capital letters). Using French accents or German umlauts (etc), anything beyond the "standard" 26-letters of "the" alphabet, would have been infra-dig to a well brought-up, clean-cut, American boy ("truth, justice, and the American way"*) - excepting that he wouldn't have understood the term, because didn't know of any other language than English. This problem was acknowledged and solved with Unicode. Viva Python 3! Before you laugh, perhaps in disbelief that at one time computers ran exclusively in upper-case, take a closer look at ASCII, because even then there was no "$" or "?", only a generic currency symbol, "?". What were they thinking? Simple: computers worked with numbers - why clutter-up the place by adding pesky letters, labelling 'answers', and stuff like that? Whilst we have protocols or understandings in Python, eg a file simply ends, there is no need for any special indication or code; back in those ?good, old days there were a number of different ways to encode characters AND to indicate other features of a file. Accordingly, the "II" part of ASCII - Information Interchange. So, it was not merely a character set in terms of an alphabet, but by standardising some universal 'understandings' made "interchange" possible between computer systems (without which the Internet would never have become a possibility!). We knew these non-alpha components as "control characters". They still exist in various forms today - I was helping a Network Tech revise for his exams, and we ran through the exchanges necessary to establish a computer on a network using DHCP, and instead of "right" or "correct" I joked with him by saying "ACK" (and later, when he made a mistake "NAK") which really made him blink! The really 'fun' ones today (because there is a difference between Linux and MS-Windows, ie we've lost the "standard") are "carriage return" (the process of pushing a typewriter's "carriage" (roller holding the paper) from the (right-hand!) end of one line all the way to the left again), "line feed" which was the second half of the typewriter process, when you first pulled the big handle at the top-right of the machine, it rolled the paper upward (normally) one line - sometimes called "New line". Thus "CR", "LF", and often "CRLF", and "NL". (why have two codes to perform what is (now!) one action?) "BEL" is one of those "control characters". If you are familiar with Python's chr() and ord(), you will remember that characters can be represented both as strings and as integers (in the case of ASCII, one character occupied one byte; but now that Python 3 uses Unicode, the one-to-one is no longer necessarily true). Thus control characters can be expressed in either representation*. In the case of BEL, my elephantine memory immediately recalled it as 7! As if that wasn't enough, Python also has its set of string literals and escape characters*. Just for fun, I started playing in the Python shell. I couldn't persuade v3.6 to ring my bell (sob, sob). Searching revealed discussion of "\A" and of an official Unicode character, but despite the "you got mail" message ringing in my ears, I couldn't bell the cat* (er, python) >>> print( chr( 7 ) ) >>> print ('\a') >>> print( u"\u2407" ) [in each case, the blank line of 'output' and end="\n" default-action should have followed the bell ringing/beeping, but didn't] Does it work for you? * web-refs: https://en.wikipedia.org/wiki/Bell_character https://docs.python.org/3.6/reference/lexical_analysis.html#literals https://linuxconfig.org/list-of-python-escape-sequence-characters-with-examples in case you program in multiple languages: https://rosettacode.org/wiki/Terminal_control/Ringing_the_terminal_bell being supercilious: https://www.outsidethebeltway.com/superman_truth_justice_and_all_that_stuff/ https://en.wikipedia.org/wiki/Belling_the_Cat [this guy is an ancestor - does that perhaps explain why I answer questions on this list?] -- Regards =dn From Karsten.Hilbert at gmx.net Fri Mar 8 16:03:35 2019 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Fri, 8 Mar 2019 22:03:35 +0100 Subject: System Beep? In-Reply-To: <000b01d4d5eb$d0ab11d0$72013570$@SGA.Ninja> References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <000b01d4d5eb$d0ab11d0$72013570$@SGA.Ninja> Message-ID: <20190308210335.GA8000@hermes.hilbert.loc> On Fri, Mar 08, 2019 at 03:16:28PM -0500, Steve wrote: > ========= RESTART: C:\____Gork\Med Insulin codes\MedReminder 127.py > ========= > Traceback (most recent call last): > File "C:\____Gork\Med Insulin codes\MedReminder 127.py", line 13, in > > windsound.Beep #(frequency, duration) > NameError: name 'windsound' is not defined > > Something missing in my code? No. There's too much. A 'd'. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From drake.gossi at gmail.com Fri Mar 8 16:23:12 2019 From: drake.gossi at gmail.com (Drake Gossi) Date: Fri, 8 Mar 2019 13:23:12 -0800 Subject: trying to retrieve comments with activated API key In-Reply-To: References: Message-ID: Ok, I think it worked. Embarrassingly, in my environment, I was clicked on "help" rather than "variable explorer." This is what is represented: api_key string 1 DEMO KEY docket_id string 1 ED-2018-OCR-0064 docs_per_page int 1 1000 total_docs int 1 32068 Does this mean I can add on the loop? that is, to get all 32000? and is this in JSON format? it has to be, right? eventually I'd like it to be in csv, but that's because I assume I have to manipulate it was R later... D On Fri, Mar 8, 2019 at 12:54 PM Chris Angelico wrote: > On Sat, Mar 9, 2019 at 7:47 AM Drake Gossi wrote: > > > > Still having issues: > > > > 7. import requests > > 8. import csv > > 9. import time > > 10. import sys > > 11. api_key = 'PUT API KEY HERE' > > 12. docket_id = 'ED-2018-OCR-0064' > > 13. total_docs = 32068 > > 14. docs_per_page = 1000 > > 15. > > 16. r = requests.get(" > https://api.data.gov:443/regulations/v3/documents.json > > ", > > 17. params={ > > 18. "api_key": api_key, > > 19. "dktid": docket_id, > > 20. "rrp": docs_per_page, > > > > }) > > > > I'm getting an "imported but unused" by 8, 9 & 10. > > Doesn't matter - may as well leave them in. > > > But then also, on the interactive API > > < > https://regulationsgov.github.io/developers/console/#!/documents.json/documents_get_0 > >, > > it has something called a "po"--i.e., page offset. I was able to figure > out > > that "rrp" means results per page, but now I'm unsure how to get all > 32000 > > comments into a response object. Do I have to add an "ro" on line 21? or > > something else? > > Probably you'll need a loop. For now, don't worry about it, and > concentrate on getting the first page. > > > Also, I ran the code as is starting on line 7 and got this: > > > > runfile('/Users/susan/.spyder-py3/temp.py', > wdir='/Users/susan/.spyder-py3') > > > > This was in the terminal, I think. Since nothing popped up in what I > assume > > is the environment--I'm running this in spyder--I assume it didn't work. > > Ahh, that might be making things confusing. > > My recommendation is to avoid Spyder altogether. Just run your script > directly and let it do its downloading. Keep it simple! > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From Gronicus at SGA.Ninja Fri Mar 8 17:03:50 2019 From: Gronicus at SGA.Ninja (Steve) Date: Fri, 8 Mar 2019 17:03:50 -0500 Subject: System Beep? In-Reply-To: <279e5a0a-4707-3d71-5c91-c08f24c16a37@DancesWithMice.info> References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <279e5a0a-4707-3d71-5c91-c08f24c16a37@DancesWithMice.info> Message-ID: <000001d4d5fa$d06c5d50$714517f0$@SGA.Ninja> I tried all three, nothing audio. I am beginning to wonder if something I the operating system is at fault. The three lines do produce symbols. The first two are a rectangle with a space in the middle and the last one spelled out "bel" in short/small characters. -------------------------------------------------------------------------------------------- There's 99 bugs in the code, in the code. 99 bugs in the code. Take one down and patch it all around. Now there's 117 bugs in the code. -----Original Message----- From: Python-list On Behalf Of DL Neil Sent: Friday, March 8, 2019 3:51 PM To: python-list at python.org Subject: Re: System Beep? Dear Squeak, sorry, Dear Steve, Back in the ?good, old days when we used to walk alongside a mainframe CPU whilst it cogitated, we would often use the BEL character to alert us to job completion (and meantime bunk-off to go have a coffee, cakes, ...) - more seriously, it alerted telegraph and telex operators to an incoming message (you can still hear similar "beeps" on some emergency-worker radio systems, NASA moon mission video-replays, etc). In the grips of nostalgia, I tried to make it work using the REPL, and failed, but first... On 9/03/19 7:13 AM, Steve wrote: > How can I cause a system beep using code? > This is using the computer's internal speaker, not an audio external > speaker. > Do I have control of duration or volume? The BEL character was included in the ASCII standard as chr(7)*. Back in those days, the rest of the world didn't exist - the "A" stands for "American". Accordingly, the huge advance was that we would be allowed to use lower-case letters, instead of all-caps (capital letters). Using French accents or German umlauts (etc), anything beyond the "standard" 26-letters of "the" alphabet, would have been infra-dig to a well brought-up, clean-cut, American boy ("truth, justice, and the American way"*) - excepting that he wouldn't have understood the term, because didn't know of any other language than English. This problem was acknowledged and solved with Unicode. Viva Python 3! Before you laugh, perhaps in disbelief that at one time computers ran exclusively in upper-case, take a closer look at ASCII, because even then there was no "$" or "?", only a generic currency symbol, "?". What were they thinking? Simple: computers worked with numbers - why clutter-up the place by adding pesky letters, labelling 'answers', and stuff like that? Whilst we have protocols or understandings in Python, eg a file simply ends, there is no need for any special indication or code; back in those ?good, old days there were a number of different ways to encode characters AND to indicate other features of a file. Accordingly, the "II" part of ASCII - Information Interchange. So, it was not merely a character set in terms of an alphabet, but by standardising some universal 'understandings' made "interchange" possible between computer systems (without which the Internet would never have become a possibility!). We knew these non-alpha components as "control characters". They still exist in various forms today - I was helping a Network Tech revise for his exams, and we ran through the exchanges necessary to establish a computer on a network using DHCP, and instead of "right" or "correct" I joked with him by saying "ACK" (and later, when he made a mistake "NAK") which really made him blink! The really 'fun' ones today (because there is a difference between Linux and MS-Windows, ie we've lost the "standard") are "carriage return" (the process of pushing a typewriter's "carriage" (roller holding the paper) from the (right-hand!) end of one line all the way to the left again), "line feed" which was the second half of the typewriter process, when you first pulled the big handle at the top-right of the machine, it rolled the paper upward (normally) one line - sometimes called "New line". Thus "CR", "LF", and often "CRLF", and "NL". (why have two codes to perform what is (now!) one action?) "BEL" is one of those "control characters". If you are familiar with Python's chr() and ord(), you will remember that characters can be represented both as strings and as integers (in the case of ASCII, one character occupied one byte; but now that Python 3 uses Unicode, the one-to-one is no longer necessarily true). Thus control characters can be expressed in either representation*. In the case of BEL, my elephantine memory immediately recalled it as 7! As if that wasn't enough, Python also has its set of string literals and escape characters*. Just for fun, I started playing in the Python shell. I couldn't persuade v3.6 to ring my bell (sob, sob). Searching revealed discussion of "\A" and of an official Unicode character, but despite the "you got mail" message ringing in my ears, I couldn't bell the cat* (er, python) >>> print( chr( 7 ) ) >>> print ('\a') >>> print( u"\u2407" ) [in each case, the blank line of 'output' and end="\n" default-action should have followed the bell ringing/beeping, but didn't] Does it work for you? * web-refs: https://en.wikipedia.org/wiki/Bell_character https://docs.python.org/3.6/reference/lexical_analysis.html#literals https://linuxconfig.org/list-of-python-escape-sequence-characters-with-examples in case you program in multiple languages: https://rosettacode.org/wiki/Terminal_control/Ringing_the_terminal_bell being supercilious: https://www.outsidethebeltway.com/superman_truth_justice_and_all_that_stuff/ https://en.wikipedia.org/wiki/Belling_the_Cat [this guy is an ancestor - does that perhaps explain why I answer questions on this list?] -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list From Gronicus at SGA.Ninja Fri Mar 8 17:11:41 2019 From: Gronicus at SGA.Ninja (Steve) Date: Fri, 8 Mar 2019 17:11:41 -0500 Subject: System Beep? In-Reply-To: References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <000b01d4d5eb$d0ab11d0$72013570$@SGA.Ninja> <001601d4d5ed$f9f55f80$ede01e80$@SGA.Ninja> Message-ID: <000301d4d5fb$e8fa1c80$baee5580$@SGA.Ninja> Import winsound winsound No error, no beep either. ------------------------------------------------------------------------- Footnote A cat looks up and sees a bird in a tree and says" "Hey, let's do lunch someday..." -----Original Message----- From: Python-list On Behalf Of Peter Otten Sent: Friday, March 8, 2019 3:42 PM To: python-list at python.org Subject: RE: System Beep? Steve wrote: >> You have a typo. It is winsound, not winDsound. > Yes, I saw that. It still failed with, or without, the ?d?. I played > with case and the use of (). They all produced similar errors Did you import the winsound module before trying to use it? -- https://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Fri Mar 8 17:53:27 2019 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 8 Mar 2019 22:53:27 +0000 Subject: System Beep? In-Reply-To: <000301d4d5fb$e8fa1c80$baee5580$@SGA.Ninja> References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <000b01d4d5eb$d0ab11d0$72013570$@SGA.Ninja> <001601d4d5ed$f9f55f80$ede01e80$@SGA.Ninja> <000301d4d5fb$e8fa1c80$baee5580$@SGA.Ninja> Message-ID: On 2019-03-08 22:11, Steve wrote: > Import winsound > winsound > > No error, no beep either. > You haven't called anything. >>> import winsound >>> dir(winsound) ['Beep', 'MB_ICONASTERISK', 'MB_ICONEXCLAMATION', 'MB_ICONHAND', 'MB_ICONQUESTION', 'MB_OK', 'MessageBeep', 'PlaySound', 'SND_ALIAS', 'SND_APPLICATION', 'SND_ASYNC', 'SND_FILENAME', 'SND_LOOP', 'SND_MEMORY', 'SND_NODEFAULT', 'SND_NOSTOP', 'SND_NOWAIT', 'SND_PURGE', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__'] >>> help(winsound.Beep) Help on built-in function Beep in module winsound: Beep(frequency, duration) A wrapper around the Windows Beep API. frequency Frequency of the sound in hertz. Must be in the range 37 through 32,767. duration How long the sound should play, in milliseconds. >>> winsound.Beep(200, 1000) There's sound from the PC's sound system, but not from the internal speaker. (Is it even a speaker? It might be a piezo buzzer.) > -----Original Message----- > From: Python-list On Behalf Of Peter Otten > Sent: Friday, March 8, 2019 3:42 PM > To: python-list at python.org > Subject: RE: System Beep? > > Steve wrote: > >>> You have a typo. It is winsound, not winDsound. > >> Yes, I saw that. It still failed with, or without, the ?d?. I played >> with case and the use of (). They all produced similar errors > > Did you import the winsound module before trying to use it? > > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at DancesWithMice.info Fri Mar 8 17:55:03 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 9 Mar 2019 11:55:03 +1300 Subject: System Beep? In-Reply-To: <000001d4d5fa$d06c5d50$714517f0$@SGA.Ninja> References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <279e5a0a-4707-3d71-5c91-c08f24c16a37@DancesWithMice.info> <000001d4d5fa$d06c5d50$714517f0$@SGA.Ninja> Message-ID: <7f34000c-bc1b-bc02-0fe2-ffb695a0e881@DancesWithMice.info> Steve, On 9/03/19 11:03 AM, Steve wrote: > I tried all three, nothing audio. I am beginning to wonder if something I the operating system is at fault. > The three lines do produce symbols. The first two are a rectangle with a space in the middle and the last one spelled out "bel" in short/small characters. You've piqued my interest. I haven't worked with sound using Python, but a future project, presently graphics/video, could easily expand... I don't think it is an OpSys fault, per-se. Someone with some Python-audio, indeed Linux-audio (in my case) experience may well blow-apart my theory, but here goes (E&OE): Python print()s to files. Normally the shell and a running program will print() to the screen. This can be piped or re-directed to a disk-file (for example). Thus, many such implementations have no bell to ring! In the case of Linux, audio has long been problematic. Indeed there are Python interfaces to both Alsa and gstreamer. Ahah! Does this mean that the Python-OpSys relationship doesn't include sound, natively? ie that one interfaces?pipes sound to an audio sub-system rather than the OpSys itself. Web-searching for "python sound" produces a number of 'hits'. A quick scan revealed a preference for working with audio files, eg mp3, wav; cf ASCII (or whatever) characters. I did come across https://pypi.org/project/kaching/ which offers similar facilities to those described earlier, from my mainframe days: "it worked", "it didn't", "you're a winner!". A Linux 'solution' which led to my thinking (above): ossaudiodev ? Access to OSS-compatible audio devices This module allows you to access the OSS (Open Sound System) audio interface. OSS is available for a wide range of open-source and commercial Unices, and is the standard audio interface for Linux and recent versions of FreeBSD. https://docs.python.org/3/library/ossaudiodev.html (presumably it relates to the Windows i/f others have mentioned) A survey: https://wiki.python.org/moin/Audio (last edited three years ago) No date on this one, but comments are very recent: Play sound in Python Play sound on Python is easy. There are several modules that can play a sound file (.wav). These solutions are cross platform (Windows, Mac, Linux). The main difference is in the ease of use and supported file formats. All of them should work with Python 3. The audio file should be in the same directory as your python program, unless you specify a path. https://pythonbasics.org/python-play-sound/ Playsound 1.2.2 (last release nine months ago) Pure Python, cross platform, single function module with no dependencies for playing sounds. https://pypi.org/project/playsound/ Pypi has: 762 projects for "sound" https://pypi.org/search/?q=sound "Python and Sound" is a constructive tutorial which looks a bit old, but may suit your application (beyond BEL). However, it uses JES (which I came across years-and-years ago, but rejected because it is Java-based (bias alert!) which may/not be available for Python (or Jython!?) these days): http://www.cs.uregina.ca/Links/class-info/325/PythonSound/index.html -- Regards =dn From grant.b.edwards at gmail.com Fri Mar 8 17:56:45 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 8 Mar 2019 22:56:45 -0000 (UTC) Subject: System Beep? References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <279e5a0a-4707-3d71-5c91-c08f24c16a37@DancesWithMice.info> <000001d4d5fa$d06c5d50$714517f0$@SGA.Ninja> Message-ID: On 2019-03-08, Steve wrote: > I tried all three, nothing audio. I am beginning to wonder if > something I the operating system is at fault. The three lines do > produce symbols. The first two are a rectangle with a space in the > middle and the last one spelled out "bel" in short/small characters. Not all terminals produce a beep when they receive a BEL character. Many X11 terminals used to flash the entire terminal window instead (otherwise you had no way to know which terminal caused the "beep"). I just tested three of the terminals on my laptop, and none of them beep when they receive a BEL. -- Grant From shaunagm at gmail.com Fri Mar 8 17:10:28 2019 From: shaunagm at gmail.com (Shauna Gordon-McKeon) Date: Fri, 8 Mar 2019 17:10:28 -0500 Subject: join us at the new Maintainers Summit at PyCon US Message-ID: Hello CompLangPythonistas! I am co-organizing a "Maintainers Summit" at PyCon US this year. The goal is to create a community of practice to help support Python project maintainers socially, technologically, and logistically. This is the first time the event will be held, so I'm trying to spread the word around. The summit will take place in the morning and early afternoon of Saturday May 4, 2019. It will be structured through a series of lightning talks and breakout sessions. Anyone is welcome to submit a lightning talk through our CFP, which closes on March 15th: https://www.papercall.io/pycon-maintainers-summit My apologies if this is too off topic, and mods feel free to screen this post out if it is. Thanks, Shauna From eryksun at gmail.com Fri Mar 8 22:37:11 2019 From: eryksun at gmail.com (eryk sun) Date: Fri, 8 Mar 2019 21:37:11 -0600 Subject: System Beep? In-Reply-To: References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <279e5a0a-4707-3d71-5c91-c08f24c16a37@DancesWithMice.info> <000001d4d5fa$d06c5d50$714517f0$@SGA.Ninja> Message-ID: On 3/8/19, Grant Edwards wrote: > > I just tested three of the terminals on my laptop, and none of them > beep when they receive a BEL. In Ubuntu, enable sound effects and select an alert sound, and then enable "Terminal bell" in GNOME Terminal's preferences. In Windows, the console calls PlaySound to play the "SystemHand" (i.e. "Critical Stop") sound. If there's no sound defined for that event, the system plays the ".Default" (i.e. "Default Beep") sound, and if that's also not defined and system sounds are enabled, it defaults to a simple tone. From tjreedy at udel.edu Sat Mar 9 00:53:08 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 9 Mar 2019 00:53:08 -0500 Subject: System Beep? In-Reply-To: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> Message-ID: On 3/8/2019 1:13 PM, Steve wrote: > How can I cause a system beep using code? >>> import winsound as ws >>> ws.Beep(500, 1000) and >>> from tkinter import Tk >>> root = Tk() >>> root.bell() work for me. The bell is not exactly a bell, but different from a monotone beep. -- Terry Jan Reedy From Gronicus at SGA.Ninja Sat Mar 9 01:16:04 2019 From: Gronicus at SGA.Ninja (Steve) Date: Sat, 9 Mar 2019 01:16:04 -0500 Subject: System Beep? In-Reply-To: References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> Message-ID: <001e01d4d63f$945291f0$bcf7b5d0$@SGA.Ninja> Thank you, both work for me too. Mischief managed. Steve Footnote: I am simply a thing that thinks. Rene Descartes -----Original Message----- From: Python-list On Behalf Of Terry Reedy Sent: Saturday, March 9, 2019 12:53 AM To: python-list at python.org Subject: Re: System Beep? On 3/8/2019 1:13 PM, Steve wrote: > How can I cause a system beep using code? >>> import winsound as ws >>> ws.Beep(500, 1000) and >>> from tkinter import Tk >>> root = Tk() >>> root.bell() work for me. The bell is not exactly a bell, but different from a monotone beep. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list From Gronicus at SGA.Ninja Sat Mar 9 01:27:03 2019 From: Gronicus at SGA.Ninja (Steve) Date: Sat, 9 Mar 2019 01:27:03 -0500 Subject: System Beep? In-Reply-To: References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> Message-ID: <001f01d4d641$1ca5c030$55f14090$@SGA.Ninja> Mischief almost managed. They both work when using IDLE but the second one leaves an empty window to be closed. I do like the second one. Is there a follow up command to close that window? Steve Footnote: I am simply a thing that thinks. Rene Descartes -----Original Message----- From: Python-list On Behalf Of Terry Reedy Sent: Saturday, March 9, 2019 12:53 AM To: python-list at python.org Subject: Re: System Beep? On 3/8/2019 1:13 PM, Steve wrote: > How can I cause a system beep using code? >>> import winsound as ws >>> ws.Beep(500, 1000) and >>> from tkinter import Tk >>> root = Tk() >>> root.bell() work for me. The bell is not exactly a bell, but different from a monotone beep. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list From Karsten.Hilbert at gmx.net Sat Mar 9 06:32:15 2019 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sat, 9 Mar 2019 12:32:15 +0100 Subject: System Beep? In-Reply-To: <7f34000c-bc1b-bc02-0fe2-ffb695a0e881@DancesWithMice.info> References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <279e5a0a-4707-3d71-5c91-c08f24c16a37@DancesWithMice.info> <000001d4d5fa$d06c5d50$714517f0$@SGA.Ninja> <7f34000c-bc1b-bc02-0fe2-ffb695a0e881@DancesWithMice.info> Message-ID: <20190309113215.GC2791@hermes.hilbert.loc> On Sat, Mar 09, 2019 at 11:55:03AM +1300, DL Neil wrote: > You've piqued my interest. I haven't worked with sound using Python, but a > future project, presently graphics/video, could easily expand... > > I don't think it is an OpSys fault, per-se. Someone with some Python-audio, > indeed Linux-audio (in my case) experience may well blow-apart my theory, > but here goes (E&OE): > > Python print()s to files. Normally the shell and a running program will > print() to the screen. This can be piped or re-directed to a disk-file (for > example). Thus, many such implementations have no bell to ring! Well, "back in the days", there was a known difference between "playing music" and beeping the system speaker. The latter was a built-in real speaker which could be beeped by various arcane and magic incantations, one of which was sending the BEL control character to the terminal. Many, but not all, terminals still support that one way or another. But it's got nothing to do with access to any DSPs. However, under the hood, the "system speaker" will nowadays be faked any number of ways: flashing the terminal, piezo buzzer, sending stuff to DSPs below the beloved beep-the-speaker interface. So, first of all, one needs to decide: do I want to *play* sound, very likely from a file, or do I "simply" want to make the system "beep" one way or another. Or, in fact, do I want to grab user attention - for which there is additional ways in today's toolkits, say https://wxpython.org/Phoenix/docs/html/wx.TopLevelWindow.html#wx.TopLevelWindow.RequestUserAttention Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From rosuav at gmail.com Sat Mar 9 11:30:00 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Mar 2019 03:30:00 +1100 Subject: System Beep? In-Reply-To: <20190309113215.GC2791@hermes.hilbert.loc> References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <279e5a0a-4707-3d71-5c91-c08f24c16a37@DancesWithMice.info> <000001d4d5fa$d06c5d50$714517f0$@SGA.Ninja> <7f34000c-bc1b-bc02-0fe2-ffb695a0e881@DancesWithMice.info> <20190309113215.GC2791@hermes.hilbert.loc> Message-ID: On Sat, Mar 9, 2019 at 10:33 PM Karsten Hilbert wrote: > > On Sat, Mar 09, 2019 at 11:55:03AM +1300, DL Neil wrote: > > > You've piqued my interest. I haven't worked with sound using Python, but a > > future project, presently graphics/video, could easily expand... > > > > I don't think it is an OpSys fault, per-se. Someone with some Python-audio, > > indeed Linux-audio (in my case) experience may well blow-apart my theory, > > but here goes (E&OE): > > > > Python print()s to files. Normally the shell and a running program will > > print() to the screen. This can be piped or re-directed to a disk-file (for > > example). Thus, many such implementations have no bell to ring! > > Well, "back in the days", there was a known difference > between "playing music" and beeping the system speaker. Speak for yourself! I played music on the system speaker.... Okay, it was one-bit music, but still! If you don't have a sound card, PC Speaker Music is all you have! I probably still know all the frequencies for musical notes - 262Hz for middle C, 277 for C#, 294 for D... ahh, old memories. :) ChrisA From eryksun at gmail.com Sat Mar 9 12:18:08 2019 From: eryksun at gmail.com (eryk sun) Date: Sat, 9 Mar 2019 11:18:08 -0600 Subject: System Beep? In-Reply-To: References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <279e5a0a-4707-3d71-5c91-c08f24c16a37@DancesWithMice.info> <000001d4d5fa$d06c5d50$714517f0$@SGA.Ninja> Message-ID: On 3/9/19, Dennis Lee Bieber wrote: > > ... produces a sound on my system... But has to be run from a Windows > console (command line -- either "DOS" or PowerShell). Say "CMD" if that's what you mean. DOS was an OS (albeit a simple one). The CMD shell is not an OS and was never a DOS program. (It was written for OS/2.) Also, python.exe doesn't have to be "run from a console", by which I think you mean it has to be run from a shell that's attached to a console. Like any console application, python.exe allocates its own console if it doesn't inherit one. cmd.exe and powershell.exe are exactly the same in this regard. From luuk at invalid.lan Sat Mar 9 12:53:53 2019 From: luuk at invalid.lan (Luuk) Date: Sat, 9 Mar 2019 18:53:53 +0100 Subject: System Beep? In-Reply-To: References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <001f01d4d641$1ca5c030$55f14090$@SGA.Ninja> Message-ID: <84511469-425e-3a06-f345-eb1bd96819ff@invalid.lan> On 9-3-2019 07:27, Steve wrote: > Mischief almost managed. > They both work when using IDLE but the second one leaves an empty window to > be closed. > I do like the second one. Is there a follow up command to close that > window? > > Steve see below.... > > > > Footnote: > I am simply a thing that thinks. > Rene Descartes > > -----Original Message----- > From: Python-list On > Behalf Of Terry Reedy > Sent: Saturday, March 9, 2019 12:53 AM > To: python-list at python.org > Subject: Re: System Beep? > > On 3/8/2019 1:13 PM, Steve wrote: >> How can I cause a system beep using code? > > >>> import winsound as ws > >>> ws.Beep(500, 1000) > > and > > >>> from tkinter import Tk > >>> root = Tk() > >>> root.bell() > > work for me. The bell is not exactly a bell, but different from a monotone > beep. > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list > root.destroy() see: https://stackoverflow.com/questions/110923/how-do-i-close-a-tkinter-window -- Luuk From ar at zeit.io Sat Mar 9 09:01:48 2019 From: ar at zeit.io (Arup Rakshit) Date: Sat, 9 Mar 2019 19:31:48 +0530 Subject: Python resources recommendations Message-ID: <125F0B9A-9346-4C99-B375-BD4327A8BC6E@zeit.io> Hello Python, This is my first time in this mailing list. I am a Ruby/JS developer by day. I have decided to learn Python now this year. Being an experienced developer as I said above which resources I should pick to learn Python in and out? Currently I am reading this https://docs.python.org/3/tutorial/index.html . What next you would recommend me after this? I would like to learn Flask once I feel good with Python core. Thanks, Arup Rakshit ar at zeit.io From luuk34 at gmail.com Sat Mar 9 12:53:53 2019 From: luuk34 at gmail.com (Luuk) Date: Sat, 9 Mar 2019 18:53:53 +0100 Subject: System Beep? In-Reply-To: References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <001f01d4d641$1ca5c030$55f14090$@SGA.Ninja> Message-ID: <84511469-425e-3a06-f345-eb1bd96819ff@invalid.lan> On 9-3-2019 07:27, Steve wrote: > Mischief almost managed. > They both work when using IDLE but the second one leaves an empty window to > be closed. > I do like the second one. Is there a follow up command to close that > window? > > Steve see below.... > > > > Footnote: > I am simply a thing that thinks. > Rene Descartes > > -----Original Message----- > From: Python-list On > Behalf Of Terry Reedy > Sent: Saturday, March 9, 2019 12:53 AM > To: python-list at python.org > Subject: Re: System Beep? > > On 3/8/2019 1:13 PM, Steve wrote: >> How can I cause a system beep using code? > > >>> import winsound as ws > >>> ws.Beep(500, 1000) > > and > > >>> from tkinter import Tk > >>> root = Tk() > >>> root.bell() > > work for me. The bell is not exactly a bell, but different from a monotone > beep. > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list > root.destroy() see: https://stackoverflow.com/questions/110923/how-do-i-close-a-tkinter-window -- Luuk From PythonList at DancesWithMice.info Sat Mar 9 15:56:59 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 10 Mar 2019 09:56:59 +1300 Subject: Python resources recommendations In-Reply-To: <125F0B9A-9346-4C99-B375-BD4327A8BC6E@zeit.io> References: <125F0B9A-9346-4C99-B375-BD4327A8BC6E@zeit.io> Message-ID: <903cba01-c61c-1527-c8f6-c407ef8b737d@DancesWithMice.info> Hello Arup, On 10/03/19 3:01 AM, Arup Rakshit wrote: > Hello Python, > This is my first time in this mailing list. I am a Ruby/JS developer by day. I have decided to learn Python now this year. Being an experienced developer as I said above which resources I should pick to learn Python in and out? Currently I am reading this https://docs.python.org/3/tutorial/index.html . What next you would recommend me after this? I would like to learn Flask once I feel good with Python core. There is such a wealth of resources to learn Python that this question is somewhat difficult to answer. Firstly, there is another mailing list 'here', called Python-Tutor. Secondly, it depends upon your starting-point and your preferred mode of learning. Apparently you are a programmer, so you don't need to be told the difference between integers and reals/floating-point numbers, and thus 'My first programming book using Python' would be ineffectual. There are Python courses on all of the major learning platforms, eg edX, Coursera, Lynda/LinkedIn, etc. Most of which one may access for $free or pay for a certificate (pending tests, assignments, etc). I've recently audited a "Py3" course out of U.Mich which features an interesting on-line course-book and coding environment (if you head this way, I'll be interested to hear feedback!) The same also offer "Dr Chuck's" 'Python for Everyone' courseware (videos alongside his "Python for Informatics" book). There are many, many books - if you ask for specific recommendations you will be inundated! The book I used (many years ago, 'Chun') was Python2. I recommend that you start with Python3 and not look back! Several 'books' are available for download/CC-license. If you have access to a library, they're likely to have something, otherwise your favorite search engine... All the best! -- Regards =dn From mystirk at gmail.com Sat Mar 9 18:41:24 2019 From: mystirk at gmail.com (Alex Kaye) Date: Sat, 9 Mar 2019 16:41:24 -0700 Subject: Python resources recommendations In-Reply-To: <903cba01-c61c-1527-c8f6-c407ef8b737d@DancesWithMice.info> References: <125F0B9A-9346-4C99-B375-BD4327A8BC6E@zeit.io> <903cba01-c61c-1527-c8f6-c407ef8b737d@DancesWithMice.info> Message-ID: DL, Good advice. U of M is well done and interesting. One wonders what Arup plans to use Python for. I am dabbling and am relearning from DOS and machine language on AppleII. A K. Virus-free. www.avg.com <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> On Sat, Mar 9, 2019 at 2:09 PM DL Neil wrote: > Hello Arup, > > On 10/03/19 3:01 AM, Arup Rakshit wrote: > > Hello Python, > > This is my first time in this mailing list. I am a Ruby/JS developer by > day. I have decided to learn Python now this year. Being an experienced > developer as I said above which resources I should pick to learn Python in > and out? Currently I am reading this > https://docs.python.org/3/tutorial/index.html < > https://docs.python.org/3/tutorial/index.html> . What next you would > recommend me after this? I would like to learn Flask once I feel good with > Python core. > > > There is such a wealth of resources to learn Python that this question > is somewhat difficult to answer. > > Firstly, there is another mailing list 'here', called Python-Tutor. > > Secondly, it depends upon your starting-point and your preferred mode of > learning. > > Apparently you are a programmer, so you don't need to be told the > difference between integers and reals/floating-point numbers, and thus > 'My first programming book using Python' would be ineffectual. > > There are Python courses on all of the major learning platforms, eg edX, > Coursera, Lynda/LinkedIn, etc. Most of which one may access for $free or > pay for a certificate (pending tests, assignments, etc). I've recently > audited a "Py3" course out of U.Mich which features an interesting > on-line course-book and coding environment (if you head this way, I'll > be interested to hear feedback!) The same also offer "Dr Chuck's" > 'Python for Everyone' courseware (videos alongside his "Python for > Informatics" book). > > There are many, many books - if you ask for specific recommendations you > will be inundated! The book I used (many years ago, 'Chun') was Python2. > I recommend that you start with Python3 and not look back! Several > 'books' are available for download/CC-license. If you have access to a > library, they're likely to have something, otherwise your favorite > search engine... > > All the best! > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at danceswithmice.info Sat Mar 9 20:18:55 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Sun, 10 Mar 2019 14:18:55 +1300 Subject: Python resources recommendations In-Reply-To: References: <125F0B9A-9346-4C99-B375-BD4327A8BC6E@zeit.io> <903cba01-c61c-1527-c8f6-c407ef8b737d@DancesWithMice.info> Message-ID: <885e9393-13e2-f620-9216-4b9b775fa7e1@DancesWithMice.info> AK, On 10/03/19 12:41 PM, Alex Kaye wrote: > DL, > Good advice. > U of M is well done and interesting. Actually, I criticised them - but was looking at matters such as "delivery" and from a cognitive psychology perspective - on behalf of, but quite different to, the needs of 'the average' trainee! From a programming/Pythonic view-point, I sadly noted Java-influence creeping-in: weak use of Python terminology, pythonic coding approaches, and similar. Probably won't hurt the average beginner, but not the best training approach. At the moment, there are a number of unhappy people who purchased the entire specialisation (five courses), but currently stalled because the last course will not be produced and ready for use until early next month. Slightly naughty, but courseware needs to be carefully constructed and that (as per program design) is both time-consuming and something it pays not to rush! On the plus-side, the material covers the ground, and does-so quite quickly. I haven't seen any feedback from 'beginners' to be sure of pace. There are a number of interesting worked-examples, which can be a point-of-boredom in training/'toy examples' (I played with Python's "turtle", simply because I'd never touched that sort of thing before). So, to the OP, please put my bias(es) aside, take AK's positive experience, and try it for yourself... (you can always start-out $free, and once satisfied, return later to fulfil the requirements and achieve certification!) > One wonders what Arup plans to use Python for. That's a very good point, which I didn't cover, earlier. Whereas previously one started with books that might be called 'Python for raw beginners' or some-such, these days there are plenty of more specialised books, eg 'Learn Python for Data Science', etc. > I am dabbling and am relearning from DOS and machine language on AppleII. Which is another somewhat specialised area: MicroPython, Python for Raspberry Pi, and similar for other smaller/older machines, SBCs, etc! We now risk confusing the OP... I remember those words - back in the days when my hair had color (and not from out of a bottle either). Using the power of Linux, every day I see much of the 'old' from DOS, CP/M, PDP minis; in our ever-green terminal interface. However, despite much of my hardware being 'old' (by other people's standards) I have no wish to go back as far as the Apple ][ - floppy disks, poor-quality display screens, etc. IMHO, there's too much to learn, attempting to keep-up with 'the modern stuff', the opening of new vistas... However, I can imagine the appeal of 'history'. Have fun! -- Regards =dn From formisc at gmail.com Sat Mar 9 21:14:52 2019 From: formisc at gmail.com (Andrew Z) Date: Sat, 9 Mar 2019 21:14:52 -0500 Subject: Python resources recommendations In-Reply-To: <125F0B9A-9346-4C99-B375-BD4327A8BC6E@zeit.io> References: <125F0B9A-9346-4C99-B375-BD4327A8BC6E@zeit.io> Message-ID: I would think that your experience with other languages would guide you on the route of learning another tool.. On Sat, Mar 9, 2019, 13:01 Arup Rakshit wrote: > Hello Python, > > This is my first time in this mailing list. I am a Ruby/JS developer by > day. I have decided to learn Python now this year. Being an experienced > developer as I said above which resources I should pick to learn Python in > and out? Currently I am reading this > https://docs.python.org/3/tutorial/index.html < > https://docs.python.org/3/tutorial/index.html> . What next you would > recommend me after this? I would like to learn Flask once I feel good with > Python core. > > > Thanks, > > Arup Rakshit > ar at zeit.io > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sun Mar 10 10:20:24 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Mar 2019 01:20:24 +1100 Subject: Configuring the REPL's tab completion Message-ID: I have absolutely no idea how to do this or even where to go looking, so I'd appreciate a starting pointer :) When you're in the Python REPL (just the basic core one, not IDLE or anything), you can tab-complete global and built-in names, attributes of known objects, etc. But quoted strings work kinda weirdly - they try to tab-complete a global or keyword: Python 3.8.0a0 (heads/master:8b9c33ea9c, Nov 20 2018, 02:18:50) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. >>> "in in input( int( >>> "input(" 'input(' I typed "in and hit tab twice, then typed p and hit tab, enter. It filled in the function name *input*, added an open parenthesis... and then closed the quote. Which doesn't make a lot of sense, but then, tab completing globals and keywords inside a text string doesn't make that much sense either. What would be more useful would be tab-completing file names from the current directory. open("Foo to fill in the name of a file. Sure, not every quoted string is a file name (in fact, very few are), but I don't know of anything else that would feel natural. (Also, Pike's REPL behaves this way, so presumably it's of use to more people than me.) Where would I start looking to try to make this happen? Doesn't necessarily have to be pushed upstream as a core Python feature; I'm guessing this can probably be done in sitecustomize.py. Anyone have tutorials on messing with tab completion? There's not a lot of info in the rlcompleter module docs. ChrisA From djoyceb at gmail.com Sun Mar 10 14:30:07 2019 From: djoyceb at gmail.com (djoyceb at gmail.com) Date: Sun, 10 Mar 2019 11:30:07 -0700 (PDT) Subject: Help!!! How to apply my created function to another function Message-ID: <044c0f9d-5e57-42b6-8d80-f35ff229a497@googlegroups.com> Please see the last line When I put vectorMagnitude(A), it returns perfectly corrected that means my function create right. But when I try to put vectorMagnitude(B) which I was thinking to put new list from buildRandomVector(A),it returns an error. I have been attempting to import buildRandomVector(A) to a list, but I can not understand why the list can not apply to vectorMagnitude(B). Can you assist me in figuring the problem? Thank you!! A = [ 4, 5, 1] #TASK0 def displayVector(v) : print(v) displayVector(A) #TASK1 def buildVector(v) : print(v[0],v[1],v[2]) buildVector(A) #TASK2 import random def buildRandomVector(v) : Z = [] for i in range(len(v)): x = (random.randint(0, 9)) Z.append(x) print(Z) buildRandomVector(A) #TASK3 import math B = buildRandomVector(A) def vectorMagnitude(v) : tsum = 0 for i in v: tsum = tsum + i**2 x = math.sqrt(tsum) print(x) vectorMagnitude(B) ==>>>> this is problem From PythonList at danceswithmice.info Sun Mar 10 14:55:43 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Mon, 11 Mar 2019 07:55:43 +1300 Subject: Help!!! How to apply my created function to another function In-Reply-To: <044c0f9d-5e57-42b6-8d80-f35ff229a497@googlegroups.com> References: <044c0f9d-5e57-42b6-8d80-f35ff229a497@googlegroups.com> Message-ID: <79f2fa26-c5a8-4769-7722-cf56a4298629@DancesWithMice.info> Dear Joyce, On 11/03/19 7:30 AM, djoyceb at gmail.com wrote: ... > A = [ 4, 5, 1] > > #TASK0 > > def displayVector(v) : > > print(v) > > displayVector(A) ... > B = buildRandomVector(A) > > def vectorMagnitude(v) : > > tsum = 0 > > for i in v: > > tsum = tsum + i**2 > > x = math.sqrt(tsum) > > print(x) > > vectorMagnitude(B) ==>>>> this is problem Perhaps "this..." is not, but is merely where you *notice* a problem? After defining B, and before assessing its magnitude, try displaying that vector. Does it contain what you expect? -- Regards =dn From luuk at invalid.lan Sun Mar 10 15:02:08 2019 From: luuk at invalid.lan (Luuk) Date: Sun, 10 Mar 2019 20:02:08 +0100 Subject: Help!!! How to apply my created function to another function In-Reply-To: <044c0f9d-5e57-42b6-8d80-f35ff229a497@googlegroups.com> References: <044c0f9d-5e57-42b6-8d80-f35ff229a497@googlegroups.com> Message-ID: <5c855f2f$0$22359$e4fe514c@news.xs4all.nl> On 10-3-2019 19:30, djoyceb at gmail.com wrote: > Please see the last line When reading above, i was thinking about this joke: Q: how will you be able to keep a blonde busy for hours? A: get a paper and write see other side on both sides of the paper > > When I put vectorMagnitude(A), it returns perfectly corrected that means my function create right. But when I try to put vectorMagnitude(B) which I was thinking to put new list from buildRandomVector(A),it returns an error. I have been attempting to import buildRandomVector(A) to a list, but I can not understand why the list can not apply to vectorMagnitude(B). > .... > vectorMagnitude(B) ==>>>> this is problem > Luckily the text 'Please see first line' is missing ;) -- Luuk From PythonList at danceswithmice.info Sun Mar 10 15:30:35 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Mon, 11 Mar 2019 08:30:35 +1300 Subject: Help!!! How to apply my created function to another function In-Reply-To: <5c855f2f$0$22359$e4fe514c@news.xs4all.nl> References: <044c0f9d-5e57-42b6-8d80-f35ff229a497@googlegroups.com> <5c855f2f$0$22359$e4fe514c@news.xs4all.nl> Message-ID: Luuk, On 11/03/19 8:02 AM, Luuk wrote: > On 10-3-2019 19:30, djoyceb at gmail.com wrote: >> Please see the last line > > When reading above, i was thinking about this joke: ...> ;) Yes, I had a similar reaction to the wording: why not put *it* first. Having lived and worked in many countries/cultures, I try not to demand high degrees of English spelling or grammatical competence - and ask that natives of such places expect (only) similarly of me, in their language! OTOH... One of the disadvantages of an interpreted language is that 'things' must be defined before they can be 'used' (except in certain specific cases). So, it is not possible to execute func( args ) until 'the last line' - or more accurately, until *after* the def func( params ): etc definition. [insert discussion about "single-pass" and "multi-pass" interpreters here] I often think how much more preferable it would be to begin my programs with the 'mainline' and leave the 'compiler' to integrate the mentioned functions, classes, modules... 'later'/as-needed - instead of having if __name__ == "__main__" : towards the "last line", and having to find/scroll the editor to start reading. [yes, much web-based code has a 'director' as its mainline/.wsgi file; and imports routines as (page) handlers!] When you think about it, Python often says 'see later'/'see the last line'. Maybe the 'joke' is on us? -- Regards =dn From greg.ewing at canterbury.ac.nz Sun Mar 10 17:25:07 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 11 Mar 2019 10:25:07 +1300 Subject: Help!!! How to apply my created function to another function In-Reply-To: <044c0f9d-5e57-42b6-8d80-f35ff229a497@googlegroups.com> References: <044c0f9d-5e57-42b6-8d80-f35ff229a497@googlegroups.com> Message-ID: djoyceb at gmail.com wrote: > def buildVector(v) : > print(v[0],v[1],v[2]) If you want to be able to use the result of this function in another computation, you need to return it, not print it: def buildVector(v) : return (v[0],v[1],v[2]) Similarly with buildRandomVector and vectorMagnitude. -- Greg From tjol at tjol.eu Mon Mar 11 06:37:08 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 11 Mar 2019 11:37:08 +0100 Subject: Configuring the REPL's tab completion In-Reply-To: References: Message-ID: <69f5d7a3-ca00-f341-5329-51a29ca01719@tjol.eu> On 10/03/2019 15.20, Chris Angelico wrote: > I have absolutely no idea how to do this or even where to go looking, > so I'd appreciate a starting pointer :) > > When you're in the Python REPL (just the basic core one, not IDLE or > anything), you can tab-complete global and built-in names, attributes > of known objects, etc. But quoted strings work kinda weirdly - they > try to tab-complete a global or keyword: > > Python 3.8.0a0 (heads/master:8b9c33ea9c, Nov 20 2018, 02:18:50) > [GCC 6.3.0 20170516] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> "in > in input( int( >>>> "input(" > 'input(' > > I typed "in and hit tab twice, then typed p and hit tab, enter. It > filled in the function name *input*, added an open parenthesis... and > then closed the quote. Which doesn't make a lot of sense, but then, > tab completing globals and keywords inside a text string doesn't make > that much sense either. > > What would be more useful would be tab-completing file names from the > current directory. > > open("Foo > > to fill in the name of a file. Sure, not every quoted string is a file > name (in fact, very few are), but I don't know of anything else that > would feel natural. (Also, Pike's REPL behaves this way, so presumably > it's of use to more people than me.) > > Where would I start looking to try to make this happen? Doesn't > necessarily have to be pushed upstream as a core Python feature; I'm > guessing this can probably be done in sitecustomize.py. Anyone have > tutorials on messing with tab completion? There's not a lot of info in > the rlcompleter module docs. I had a quick look at the code - rlcompleter sets itself as the completer using readline.set_completer I imagine you could write your own completer, and call set_completer again after rlcompleter has been imported. -- Thomas From dimplemathew.17 at gmail.com Mon Mar 11 06:38:32 2019 From: dimplemathew.17 at gmail.com (dimplemathew.17 at gmail.com) Date: Mon, 11 Mar 2019 03:38:32 -0700 (PDT) Subject: Converting hex data to image In-Reply-To: References: <7w61ruwv0q.fsf@benfinney.id.au> <7w1u2iwu3l.fsf@benfinney.id.au> Message-ID: <04f92a06-0720-453b-a988-dd4717797466@googlegroups.com> On Friday, November 15, 2013 at 3:52:58 AM UTC+5:30, Shyam Parimal Katti wrote: > Perfect. Thank you @Ben and @Tim > > > > > On Thu, Nov 14, 2013 at 4:29 PM, Ben Finney wrote: > > > Ben Finney writes: > > > > > > To turn a byte string into a file-like object for use with PIL, extract > > > the byte string as ?image_data?, use the standard library ?io.StringIO? > > > class , then > > > create a new ?PIL.Image? object by reading from that pseudo-file:: > > > > My apologies, I showed the wrong usage. This should work:: > > > > > ? ? import io > > > > ? ? import PIL > > > > ? ? photo_data = # ? get the byte string from wherever it is ? > > ? ? photo_infile = io.StringIO(photo_data) > > ? ? photo_image = PIL.Image.open(photo_infile) > > > > That is, ?PIL.Image.frombytes? allows you to read the bytes from a byte > > string, but requires you to also specify metadata about the image data > > (format, pixel mode, size), whereas ?PIL.Image.open? reads the data from > > a file-like object and parses all the metadata. So you usually want to > > use the latter, as shown here. > > > > -- > > ?\ ? ? ? ? ?People's Front To Reunite Gondwanaland: Stop the Laurasian | > > ? `\ ? ? ? ? ? ? ?Separatist Movement!? ?wiredog, http://kuro5hin.org/ | > > > > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| > > Ben Finney > > > > -- > > https://mail.python.org/mailman/listinfo/python-list Hi i have a similar challenge where i need to store the thumbnailPhoto attribute to my local db and display the image every-time user logs in. But this solution does work . data looks like this: \xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00`\x00`\x00\x00\xff\xdb\x00C\x00 \x08\x06\x06\x07\x06\x05\x08\x07\x07\x07\t\t\x08\n\x0c\x14\r\x0c\x0b\x0b\x0c\x19\x12\x13\x0f\x14\x1d\x1a\x1f\x1e\x1d\x1a\x1c\x1c $.\' ",#\x1c\x1c(7),01444\x1f\'9=82<.342\xff\xdb\x00C\x01\t\t\t\x0c\x0b\x0c\x18\r\r\x182!\x1c!222222222222222222222222222222222 import PIL from PIL import Image import io data = open("bytes.txt") my_data=(data.read()) photo_inline = io.StringIO(my_data) photo = PIL.Image.open(photo_inline) error: Traceback (most recent call last): File "convertToImage.py", line 9, in photo = PIL.Image.open(photo_inline) File "", line 2657, in open % (filename if filename else fp)) OSError: cannot identify image file <_io.StringIO object at 0x0367FD00> From __peter__ at web.de Mon Mar 11 07:02:14 2019 From: __peter__ at web.de (Peter Otten) Date: Mon, 11 Mar 2019 12:02:14 +0100 Subject: Converting hex data to image References: <7w61ruwv0q.fsf@benfinney.id.au> <7w1u2iwu3l.fsf@benfinney.id.au> <04f92a06-0720-453b-a988-dd4717797466@googlegroups.com> Message-ID: dimplemathew.17 at gmail.com wrote: > Hi i have a similar challenge where i need to store the thumbnailPhoto > attribute to my local db and display the image every-time user logs in. > But this solution does work . data looks like this: > \xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00`\x00`\x00\x00\xff\xdb\x00C\x00 > import PIL > from PIL import Image > import io > data = open("bytes.txt") > my_data=(data.read()) > photo_inline = io.StringIO(my_data) > photo = PIL.Image.open(photo_inline) > error: > Traceback (most recent call last): > File "convertToImage.py", line 9, in > photo = PIL.Image.open(photo_inline) > File "", line 2657, in open > % (filename if filename else fp)) > OSError: cannot identify image file <_io.StringIO object at 0x0367FD00> Did you try photo = PIL.Image.open("bytes.txt") ? If the above code is illustrative, and you really need the bytes in memory remember to open the file in binary mode: with open("bytes.txt", "rb") as instream: data = instream.read() To create the image later the file-like objects needs to produce bytes: instream = io.BytesIO(data) # not StringIO! photo = Image.open(instream) From hello at ezaquarii.com Mon Mar 11 10:06:00 2019 From: hello at ezaquarii.com (Chris Narkiewicz) Date: Mon, 11 Mar 2019 14:06:00 +0000 Subject: pydistutils.cfg injection Message-ID: Hi, I'm trying to build a Python application in Launchpad and I'm currently having some issues with distutils. The build on Launchpad is constrained by 2 things: 1) the builder is isolated from network. 2) must be fully open source (can't ship pre-built binaries). I vendored in my PyPI dependencies in form of source packages and I pip install them: pip instal --find-links=/my/own/vendored/pypi/packages This works like a charm until pip tries to build a package that has build-time dependencies and does not conform to PEP 518: https://www.python.org/dev/peps/pep-0518/ (which is majority of packages, sadly). Then, easy_install kicks in and it tries to fetch from network, as it does not use pip's --find-links option. Thanks to some earlier answer on this group, I found pydistutils.cfg workaround for this issue, but this approach has some very annoying limitation - cfg file is read from 3 pre-defined locations: 1) ${PWD} 2) distutils directory (which is inside system installed Python distribution) 3) ${HOME} All 3 are no-go in most automated environments. I checked distutils source code and I have a proposal. In ${PYTHON_INSTALL}/distutils/dist.py there is a function: class Distribution: def find_config_files(self): ...snip... if self.want_user_cfg: user_file = os.path.join(os.path.expanduser('~'), user_filename) if os.path.isfile(user_file): files.append(user_file) ...snip... return files How about adding an environment variable, let's say DISTUTILS_CONFIG_PATH, and resolving it alongside ~? For now, I need to re-define my ${HOME} to simulate this behaviour. This hack might however break some other code that depends on proper ${HOME} value, so while working for me, could still be an issue for somebody else. What do you think? Is such change feasible? I can make a patch - how to submit it? Best regards, Chris Narkiewicz -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: From arj.python at gmail.com Mon Mar 11 13:45:38 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Mon, 11 Mar 2019 21:45:38 +0400 Subject: "use strict" Message-ID: Greetings, would it be a good idea to add a use strict in py like js? recently i was helping someone and that was one annoying part where a typo in a var name caused an unintended variable to slip in. maybe something like that # -*- strict -*- # -*- explicit -*- could be used to prevent it Abdur-Rahmaan Janhangeer Mauritius From rhodri at kynesim.co.uk Mon Mar 11 14:14:33 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 11 Mar 2019 18:14:33 +0000 Subject: "use strict" In-Reply-To: References: Message-ID: On 11/03/2019 17:45, Abdur-Rahmaan Janhangeer wrote: > Greetings, > > would it be a good idea to add a use strict in py like js? > > recently i was helping someone and that was one annoying part where a typo > in a var name caused an unintended variable to slip in. > > maybe something like that > > # -*- strict -*- > > > # -*- explicit -*- > > could be used to prevent it What exactly would you want "strict" (in whatever form) to do? I'm guessing, but it sounds like you want more static checking. Usually that's the province of linters and type annotation, depending on just what you want. -- Rhodri James *-* Kynesim Ltd From PythonList at danceswithmice.info Mon Mar 11 14:39:48 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Tue, 12 Mar 2019 07:39:48 +1300 Subject: "use strict" In-Reply-To: References: Message-ID: Abdur-Rahmaan, with greetings, On 12/03/19 6:45 AM, Abdur-Rahmaan Janhangeer wrote: > Greetings, > would it be a good idea to add a use strict in py like js? > recently i was helping someone and that was one annoying part where a typo > in a var name caused an unintended variable to slip in. > maybe something like that > # -*- strict -*- > # -*- explicit -*- > could be used to prevent it We asked for this consideration, in COBOL and FORTRAN, back in the seventies - when the time between "submitting a job" and the computer reporting typos was measured in hours, if not 'overnight'. Surely the computer could auto-correct: AND ONE TO COUNTER. to: ADD ... The problem with that, is that if the computer does something 'wrong' in its attempt to be 'right', it would be even more "annoying"! When we moved to PCs, the 'bright, young, things' pointed-out that computer-time had become cheap (and staff-time expensive) and that I should become more inclined to 'throw' my code at the interpreter and have it 'check for errors'. However, you've pointed-out the 'down-side' to such practice (even if your experience was accidental)! Is there any substitute for reviewing one's code with a critical eye - do the job descriptions say "attention to detail"? Perhaps there is some happy medium? More constructively: doesn't every competent programming editor anticipate data-entry: suggesting variableNMs, python key-words and even whole constructs, also offer a spelling-checker? I find such, VERY helpful! -- Regards =dn From arj.python at gmail.com Mon Mar 11 15:00:01 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Mon, 11 Mar 2019 23:00:01 +0400 Subject: "use strict" In-Reply-To: References: Message-ID: missed reply all ---------- Forwarded message --------- From: Abdur-Rahmaan Janhangeer Date: Mon, 11 Mar 2019, 22:59 Subject: Re: "use strict" To: DL Neil about the editor part i think yes it'd underline unused variables or somewhat similar. the problem was that i was reviewing the code, since everything worked (no errors but wrong output for sure) it took sometimes to find that var. it was like someone telling me there is fish in that lake and i was throwing my line trying ... just a way to flag those types of vars when needed. Abdur-Rahmaan Janhangeer Mauritius From rhodri at kynesim.co.uk Mon Mar 11 15:05:29 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 11 Mar 2019 19:05:29 +0000 Subject: "use strict" In-Reply-To: References: Message-ID: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> On 11/03/2019 18:24, Abdur-Rahmaan Janhangeer wrote: > i mean a way to solve the problem of declaring variables beforehand and not > changing in loop. like not using undeclated variables. but that's precisely > what python has, you can't just declare a variable with no assignment. > > > maybe some special symbils to mark that. You sent this to me instead of the list, but never mind. If you want this, Guido's time machine strikes again. Just use type annotations and mypy, or pylint or the like for static checking of unexpected variables. -- Rhodri James *-* Kynesim Ltd From arj.python at gmail.com Mon Mar 11 15:08:41 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Mon, 11 Mar 2019 23:08:41 +0400 Subject: "use strict" In-Reply-To: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> Message-ID: proposing a special python syntax for it, like if flag set, it halts execution. not relying on external tools like linters. From PythonList at danceswithmice.info Mon Mar 11 16:34:19 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Tue, 12 Mar 2019 09:34:19 +1300 Subject: "use strict" In-Reply-To: References: Message-ID: On 12/03/19 8:00 AM, Abdur-Rahmaan Janhangeer wrote: > about the editor part i think yes it'd underline unused variables or > somewhat similar. is that the best we can hope for (coupled with type annotations)? > the problem was that i was reviewing the code, since everything worked (no > errors but wrong output for sure) it took sometimes to find that var. it > was like someone telling me there is fish in that lake and i was throwing > my line trying ... > just a way to flag those types of vars when needed. Yes. Such is enormously frustrating, but where does it fit in the wider scope of coding in Python? Proportionally? Once again at risk of tripping over my long, flowing, beard: in the (?)good, old days, when every compilation resulted in a pile of print-out (and hopefully no syntax errors or typos); we could request a list of all of the variables/symbols defined in the code. One still had to scan that list manually, and pick-out any inconsistencies, eg misspellings! Which made me think about the Python debugger (https://docs.python.org/3/library/debug.html) [regret: since working with a team that demanded I update/learn/follow TDD (Test-driven Development), I haven't (?gone back to) used PDB since the time when all of my coding was in Py2!] If you haven't already, it might be worth a quick shufti. Aspects may help you/your colleague! A debugger will enable you to monitor the values stored in variables - but may not be so helpful, in that you must either look at 'everything' or first be aware of which variable(s) is/are causing problems. (per my 'history lesson', above) There are a variety of Python-compatible debuggers. One may suitably cover your need. (https://wiki.python.org/moin/PythonDebuggingTools) In other threads I've enthused about the learning tools employed in the new-ish U.Mich/Coursera Py3 course. One of those tools, which your colleague might find helpful, is Philip Guo's Python Tutor (http://www.pythontutor.com/). This tool also allows one to step-through Python code (or run to 'the end'), and right beside its 'terminal window', dynamically maintains a diagrammatic view of current-values and where they are kept in storage (making use of the "frames" within Python's 'innards') - so, also handy for noting separations of "scope"... Trivial example: http://www.pythontutor.com/visualize.html#code=a%20%3D%201%0Ab%20%3D%202%0Ac%20%3D%20a%20%2B%20b%0Aprint%28%20f'%7Ba%7D%20%2B%20%7Bb%7D%20%3D%20%7Bc%7D'%20%29%0A&cumulative=false&curInstr=4&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&textReferences=false [NB I'm not sure how long this link will live] Ahah! Showing the global frame/list of variables and their values, immediately highlights the situation where an "h" shows-up when we think we're using "g". OTOH it's a tutorial tool - so its use may be more trouble than it is worth in the professional environment. So, returning to my (personal) comment about PDB. (which was not meant to be at all derisive - every tool has its place) My experience (again, personal - if I may), is that once 'the guys' tuned me in to TDD, I found that because we were writing (and testing) smaller units of code at one time (for later assembly/integration into larger units), 'silly mistakes', eg my making a typo, became evident much 'earlier' - and when the debugging/tracing/testing was so much easier! That said, I can immediately see why a 10~20 line function is unlikely to require my pulling-out a "big gun" such as PDB - and if it was particularly tricky/causing me frustration, such would be easy-enough to drop into the PythonTutor tool! [others may counsel differently - in which case, I'm ready to (re-)learn...] -- Regards =dn From rosuav at gmail.com Mon Mar 11 18:26:10 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Mar 2019 09:26:10 +1100 Subject: Configuring the REPL's tab completion In-Reply-To: <69f5d7a3-ca00-f341-5329-51a29ca01719@tjol.eu> References: <69f5d7a3-ca00-f341-5329-51a29ca01719@tjol.eu> Message-ID: On Mon, Mar 11, 2019 at 9:38 PM Thomas Jollans wrote: > > On 10/03/2019 15.20, Chris Angelico wrote: > > I have absolutely no idea how to do this or even where to go looking, > > so I'd appreciate a starting pointer :) > > > > When you're in the Python REPL (just the basic core one, not IDLE or > > anything), you can tab-complete global and built-in names, attributes > > of known objects, etc. But quoted strings work kinda weirdly - they > > try to tab-complete a global or keyword: > > > > Python 3.8.0a0 (heads/master:8b9c33ea9c, Nov 20 2018, 02:18:50) > > [GCC 6.3.0 20170516] on linux > > Type "help", "copyright", "credits" or "license" for more information. > >>>> "in > > in input( int( > >>>> "input(" > > 'input(' > > > > I typed "in and hit tab twice, then typed p and hit tab, enter. It > > filled in the function name *input*, added an open parenthesis... and > > then closed the quote. Which doesn't make a lot of sense, but then, > > tab completing globals and keywords inside a text string doesn't make > > that much sense either. > > > > What would be more useful would be tab-completing file names from the > > current directory. > > > > open("Foo > > > > to fill in the name of a file. Sure, not every quoted string is a file > > name (in fact, very few are), but I don't know of anything else that > > would feel natural. (Also, Pike's REPL behaves this way, so presumably > > it's of use to more people than me.) > > > > Where would I start looking to try to make this happen? Doesn't > > necessarily have to be pushed upstream as a core Python feature; I'm > > guessing this can probably be done in sitecustomize.py. Anyone have > > tutorials on messing with tab completion? There's not a lot of info in > > the rlcompleter module docs. > > I had a quick look at the code - > > rlcompleter sets itself as the completer > > using readline.set_completer > > > I imagine you could write your own completer, and call set_completer > again after rlcompleter has been imported. Hmm. Been tinkering with this a bit, and it's not easy to get info about whether the word to be completed is inside a quoted string. There MAY be more info available if I use the third-party 'rl' module [1], but on playing with that, I managed to bomb Python hard with a SIGABRT. Not promising. I get the feeling that this ought to be really really easy, yet there's nothing obvious saying "do this, you can interact with the completer that way". Maybe the problem is that the CPython core "readline" module simply doesn't have the functionality I want, but if that's the case, I'll need to figure out why on earth my simple probing of rl.readline is crashing hard. It'd be way better if I could work entirely with the stdlib. So here's my current exploration: class Completer(rlcompleter.Completer): def complete(self, text, state): ret = super().complete(text, state) txt = readline.get_line_buffer()[readline.get_begidx():readline.get_endidx()] print("complete(%r, %r) -> %r [%r]" % (text, state, ret, txt), file=tracer) tracer.flush() return ret readline.set_completer(Completer().complete) With this, I can inspect the current buffer and find the parts of it that are being flagged by the completer. (txt and text should always have the same value.) Figuring out whether something is inside a quoted string is actually a bit of a hard problem, but maybe I'll cheat and say "if you're tab-completing a word immediately after a quote character, it's a file name". I think coping with triple-quoted strings across multiple input lines is so hard that it's not worth attempting, but it'd be nice to be able to correctly handle single-line strings. This really does feel like it ought to be a lot simpler, though. GNU Readline has file name facilities built-in, I believe; it certainly has quoted string detection (see, for instance, the way it autocloses a string with current Python behaviour). I must be missing something here. [1] https://pythonhosted.org/rl/index.html ChrisA From arj.python at gmail.com Mon Mar 11 20:58:07 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 12 Mar 2019 04:58:07 +0400 Subject: "use strict" In-Reply-To: References: Message-ID: great post, i understand what you are saying. the smaller pieces was interesting. but poor me, i should have posted this to python-ideas Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius From dimplemathew.17 at gmail.com Mon Mar 11 23:40:02 2019 From: dimplemathew.17 at gmail.com (dimplemathew.17 at gmail.com) Date: Mon, 11 Mar 2019 20:40:02 -0700 (PDT) Subject: Converting hex data to image In-Reply-To: References: Message-ID: <3d9f458a-dc38-4dc6-9d85-23c5ceb49e84@googlegroups.com> On Thursday, November 14, 2013 at 9:02:52 PM UTC+5:30, Shyam Parimal Katti wrote: > I am implementing an authentication system(in Django) using LDAP as the backend(django-auth-ldap). When we fetch the data from the LDAP server for a particular valid user, the data associated with the user contains the thumbnail photo in hex representation. E.x.: > > > [('CN=XX,OU=Users,OU=Accounts,DC=test,DC=com', {'msExchBlockedSendersHash': ['\xce'], 'mailNickname': ['test_user'], 'primaryGroupID': ['513'], 'logonCount': ['1021'], thumbnailPhoto: ['\xef\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00`\x00`\x00\x00\xff\xdb\x00C\x00\x08\x06\x06\x07\x06\x05\x08\x07\x07\x07\t\t\x08\n\x0c\x14\r\x0c.....'] ...... ] > > > How do I convert the hex data for an image to the actual image? > > Any help would be greatly appreciated. > > > Thanks, > Shyam Hey, It shows the same error. I am actually getting that image from ldap in bytes: '\xef\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00`\x00`\x00\x00\xff\xdb\x00C\x00\x08\x06\x06\x07\x06\x05\x08\x07\x07\x07\t\t\x08\n\x0c\x14\r\x0c..... I want to display this image on my template. From dimplemathew.17 at gmail.com Mon Mar 11 23:42:39 2019 From: dimplemathew.17 at gmail.com (dimplemathew.17 at gmail.com) Date: Mon, 11 Mar 2019 20:42:39 -0700 (PDT) Subject: Converting hex data to image In-Reply-To: References: <7w61ruwv0q.fsf@benfinney.id.au> <7w1u2iwu3l.fsf@benfinney.id.au> <04f92a06-0720-453b-a988-dd4717797466@googlegroups.com> Message-ID: <2f4ef238-11cb-4c4f-aae5-1151046e19c2@googlegroups.com> On Monday, March 11, 2019 at 4:32:48 PM UTC+5:30, Peter Otten wrote: > dimplemathew.17 at gmail.com wrote: > > > Hi i have a similar challenge where i need to store the thumbnailPhoto > > attribute to my local db and display the image every-time user logs in. > > But this solution does work . data looks like this: > > > \xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00`\x00`\x00\x00\xff\xdb\x00C\x00 > > > import PIL > > from PIL import Image > > import io > > data = open("bytes.txt") > > my_data=(data.read()) > > photo_inline = io.StringIO(my_data) > > photo = PIL.Image.open(photo_inline) > > error: > > Traceback (most recent call last): > > File "convertToImage.py", line 9, in > > photo = PIL.Image.open(photo_inline) > > File "", line 2657, in open > > % (filename if filename else fp)) > > OSError: cannot identify image file <_io.StringIO object at 0x0367FD00> > > Did you try > > photo = PIL.Image.open("bytes.txt") > > ? > > If the above code is illustrative, and you really need the bytes in memory > remember to open the file in binary mode: > > with open("bytes.txt", "rb") as instream: > data = instream.read() > > To create the image later the file-like objects needs to produce bytes: > > instream = io.BytesIO(data) # not StringIO! > photo = Image.open(instream) Hey, It shows the same error. I am actually getting that image from ldap in bytes: '\xef\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00`\x00`\x00\x00\xff\xdb\x00C\x00\x08\x06\x06\x07\x06\x05\x08\x07\x07\x07\t\t\x08\n\x0c\x14\r\x0c..... I want to display this image on my template. From __peter__ at web.de Tue Mar 12 04:38:42 2019 From: __peter__ at web.de (Peter Otten) Date: Tue, 12 Mar 2019 09:38:42 +0100 Subject: Converting hex data to image References: <7w61ruwv0q.fsf@benfinney.id.au> <7w1u2iwu3l.fsf@benfinney.id.au> <04f92a06-0720-453b-a988-dd4717797466@googlegroups.com> <2f4ef238-11cb-4c4f-aae5-1151046e19c2@googlegroups.com> Message-ID: dimplemathew.17 at gmail.com wrote: > On Monday, March 11, 2019 at 4:32:48 PM UTC+5:30, Peter Otten wrote: >> dimplemathew.17 at gmail.com wrote: >> >> > Hi i have a similar challenge where i need to store the thumbnailPhoto >> > attribute to my local db and display the image every-time user logs in. >> > But this solution does work . data looks like this: >> > >> \xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00`\x00`\x00\x00\xff\xdb\x00C\x00 >> >> > import PIL >> > from PIL import Image >> > import io >> > data = open("bytes.txt") >> > my_data=(data.read()) >> > photo_inline = io.StringIO(my_data) >> > photo = PIL.Image.open(photo_inline) >> > error: >> > Traceback (most recent call last): >> > File "convertToImage.py", line 9, in >> > photo = PIL.Image.open(photo_inline) >> > File "", line 2657, in open >> > % (filename if filename else fp)) >> > OSError: cannot identify image file <_io.StringIO object at 0x0367FD00> >> >> Did you try >> >> photo = PIL.Image.open("bytes.txt") >> >> ? >> >> If the above code is illustrative, and you really need the bytes in >> memory remember to open the file in binary mode: >> >> with open("bytes.txt", "rb") as instream: >> data = instream.read() >> >> To create the image later the file-like objects needs to produce bytes: >> >> instream = io.BytesIO(data) # not StringIO! >> photo = Image.open(instream) > > Hey, > It shows the same error. > I am actually getting that image from ldap in bytes: > '\xef\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00`\x00`\x00\x00\xff\xdb\x00C\x00\x08\x06\x06\x07\x06\x05\x08\x07\x07\x07\t\t\x08\n\x0c\x14\r\x0c..... > I want to display this image on my template. Save the image to a file (in binary mode!) and then try to open it with an image viewer. The data may be corrupted. From dimplemathew.17 at gmail.com Tue Mar 12 05:14:39 2019 From: dimplemathew.17 at gmail.com (dimplemathew.17 at gmail.com) Date: Tue, 12 Mar 2019 02:14:39 -0700 (PDT) Subject: Converting hex data to image In-Reply-To: References: <7w61ruwv0q.fsf@benfinney.id.au> <7w1u2iwu3l.fsf@benfinney.id.au> <04f92a06-0720-453b-a988-dd4717797466@googlegroups.com> <2f4ef238-11cb-4c4f-aae5-1151046e19c2@googlegroups.com> Message-ID: On Tuesday, March 12, 2019 at 2:09:06 PM UTC+5:30, Peter Otten wrote: > dimplemathew.17 at gmail.com wrote: > > > On Monday, March 11, 2019 at 4:32:48 PM UTC+5:30, Peter Otten wrote: > >> dimplemathew.17 at gmail.com wrote: > >> > >> > Hi i have a similar challenge where i need to store the thumbnailPhoto > >> > attribute to my local db and display the image every-time user logs in. > >> > But this solution does work . data looks like this: > >> > > >> > \xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00`\x00`\x00\x00\xff\xdb\x00C\x00 > >> > >> > import PIL > >> > from PIL import Image > >> > import io > >> > data = open("bytes.txt") > >> > my_data=(data.read()) > >> > photo_inline = io.StringIO(my_data) > >> > photo = PIL.Image.open(photo_inline) > >> > error: > >> > Traceback (most recent call last): > >> > File "convertToImage.py", line 9, in > >> > photo = PIL.Image.open(photo_inline) > >> > File "", line 2657, in open > >> > % (filename if filename else fp)) > >> > OSError: cannot identify image file <_io.StringIO object at 0x0367FD00> > >> > >> Did you try > >> > >> photo = PIL.Image.open("bytes.txt") > >> > >> ? > >> > >> If the above code is illustrative, and you really need the bytes in > >> memory remember to open the file in binary mode: > >> > >> with open("bytes.txt", "rb") as instream: > >> data = instream.read() > >> > >> To create the image later the file-like objects needs to produce bytes: > >> > >> instream = io.BytesIO(data) # not StringIO! > >> photo = Image.open(instream) > > > > Hey, > > It shows the same error. > > I am actually getting that image from ldap in bytes: > > > '\xef\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00`\x00`\x00\x00\xff\xdb\x00C\x00\x08\x06\x06\x07\x06\x05\x08\x07\x07\x07\t\t\x08\n\x0c\x14\r\x0c..... > > I want to display this image on my template. > > Save the image to a file (in binary mode!) and then try to open it with an > image viewer. The data may be corrupted. When i tried doing that it says Invalid Image... From __peter__ at web.de Tue Mar 12 05:23:22 2019 From: __peter__ at web.de (Peter Otten) Date: Tue, 12 Mar 2019 10:23:22 +0100 Subject: Converting hex data to image References: <7w61ruwv0q.fsf@benfinney.id.au> <7w1u2iwu3l.fsf@benfinney.id.au> <04f92a06-0720-453b-a988-dd4717797466@googlegroups.com> <2f4ef238-11cb-4c4f-aae5-1151046e19c2@googlegroups.com> Message-ID: dimplemathew.17 at gmail.com wrote: >> Save the image to a file (in binary mode!) and then try to open it with >> an image viewer. The data may be corrupted. > > When i tried doing that it says Invalid Image... So it looks like the problem occurs somewhere before you are decoding the image with the PIL... From dimplemathew.17 at gmail.com Tue Mar 12 05:31:32 2019 From: dimplemathew.17 at gmail.com (dimplemathew.17 at gmail.com) Date: Tue, 12 Mar 2019 02:31:32 -0700 (PDT) Subject: Converting hex data to image In-Reply-To: References: <7w61ruwv0q.fsf@benfinney.id.au> <7w1u2iwu3l.fsf@benfinney.id.au> <04f92a06-0720-453b-a988-dd4717797466@googlegroups.com> <2f4ef238-11cb-4c4f-aae5-1151046e19c2@googlegroups.com> Message-ID: On Tuesday, March 12, 2019 at 2:53:49 PM UTC+5:30, Peter Otten wrote: > dimplemathew.17 at gmail.com wrote: > > >> Save the image to a file (in binary mode!) and then try to open it with > >> an image viewer. The data may be corrupted. > > > > When i tried doing that it says Invalid Image... > > So it looks like the problem occurs somewhere before you are decoding the > image with the PIL... This is what i am doing : for associate in self.conn.response[:-1]: attributes = associate['attributes'] obj = { 'img':attributes['thumbnailPhoto'],} This img i am calling in my view and writing to the file... From rhodri at kynesim.co.uk Tue Mar 12 07:29:26 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 12 Mar 2019 11:29:26 +0000 Subject: "use strict" In-Reply-To: References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> Message-ID: On 11/03/2019 19:08, Abdur-Rahmaan Janhangeer wrote: > proposing a special python syntax for it, like if flag set, it halts > execution. not relying on external tools like linters. Do you mean on the command line, like "python --lint-me-baby myprog.py"? I could live with that, though I'd hate to be the one trying to implement it and I imagine it's likely to slow down execution a fair bit. Under what condition do you want execution halted? At the moment you haven't been much more specific than "when my program is wrong", which isn't very helpful. -- Rhodri James *-* Kynesim Ltd From arj.python at gmail.com Tue Mar 12 07:32:41 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 12 Mar 2019 15:32:41 +0400 Subject: "use strict" In-Reply-To: References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> Message-ID: no i mean # *-* use strict *-* program typovar = x # line y ... Traceback: on the fly var at line y Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius From rhodri at kynesim.co.uk Tue Mar 12 07:37:42 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 12 Mar 2019 11:37:42 +0000 Subject: "use strict" In-Reply-To: References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> Message-ID: <2747e200-5f7e-b538-07b1-53d13e701508@kynesim.co.uk> On 12/03/2019 11:32, Abdur-Rahmaan Janhangeer wrote: > no i mean > > # *-* use strict *-* Ugh. > program > typovar = x # line y > > ... > > > Traceback: > on the fly var at line y Yes, but how is the program supposed to know that typovar is a typo? Are you proposing mandatory declarations for all variables, because I think you know what the answer to that one will be. -- Rhodri James *-* Kynesim Ltd From arj.python at gmail.com Tue Mar 12 07:40:02 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 12 Mar 2019 15:40:02 +0400 Subject: "use strict" In-Reply-To: <2747e200-5f7e-b538-07b1-53d13e701508@kynesim.co.uk> References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> <2747e200-5f7e-b538-07b1-53d13e701508@kynesim.co.uk> Message-ID: no just the var you want to track maybe _var or something like that, i want to solve that problem and this is just a proposal Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius From arj.python at gmail.com Tue Mar 12 07:41:05 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 12 Mar 2019 15:41:05 +0400 Subject: "use strict" In-Reply-To: <2747e200-5f7e-b538-07b1-53d13e701508@kynesim.co.uk> References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> <2747e200-5f7e-b538-07b1-53d13e701508@kynesim.co.uk> Message-ID: i also proposed # -*- explicit -*- above Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius From rosuav at gmail.com Tue Mar 12 07:56:34 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Mar 2019 22:56:34 +1100 Subject: "use strict" In-Reply-To: References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> <2747e200-5f7e-b538-07b1-53d13e701508@kynesim.co.uk> Message-ID: On Tue, Mar 12, 2019 at 10:43 PM Abdur-Rahmaan Janhangeer wrote: > > no just the var you want to track maybe > > _var > > or something like that, i want to solve that problem and this is just a > proposal > How do you specify which variables should be tracked? What defines this? Be completely clear here - "I wish Python could catch my bugs" isn't enough. What is legal code and what isn't? ChrisA From arj.python at gmail.com Tue Mar 12 07:58:44 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 12 Mar 2019 15:58:44 +0400 Subject: "use strict" In-Reply-To: References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> <2747e200-5f7e-b538-07b1-53d13e701508@kynesim.co.uk> Message-ID: by some special symbols before the variable name like _that some code: _tht ^ Traceback: ... Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius From rosuav at gmail.com Tue Mar 12 07:59:39 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Mar 2019 22:59:39 +1100 Subject: "use strict" In-Reply-To: References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> <2747e200-5f7e-b538-07b1-53d13e701508@kynesim.co.uk> Message-ID: On Tue, Mar 12, 2019 at 10:58 PM Abdur-Rahmaan Janhangeer wrote: > > by some special symbols before the variable name > > like > > _that > > some code: > _tht > I don't understand. How is Python to know that "_that" is correct but "_tht" is not? ChrisA From arj.python at gmail.com Tue Mar 12 08:02:44 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 12 Mar 2019 16:02:44 +0400 Subject: "use strict" In-Reply-To: References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> <2747e200-5f7e-b538-07b1-53d13e701508@kynesim.co.uk> Message-ID: by keeping a list /a record of those variables beforehand and knowing that no new assignments in loops or such blocks of code. Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius From rosuav at gmail.com Tue Mar 12 08:05:17 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Mar 2019 23:05:17 +1100 Subject: "use strict" In-Reply-To: References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> <2747e200-5f7e-b538-07b1-53d13e701508@kynesim.co.uk> Message-ID: On Tue, Mar 12, 2019 at 11:02 PM Abdur-Rahmaan Janhangeer wrote: > > by keeping a list /a record of those variables beforehand and knowing that no new assignments in loops or such blocks of code. > Please, quote posts with proper context. Your posts are all context-free, which is great for a grammar but not for a discussion. Okay, so you're saying that all variables (with this tag) must be created outside of... what blocks of code exactly? Also, I can't get away from the thought that a linter can most likely find this. Unless you spell something correctly in two places AND incorrectly in two places (and the same way), one of the usages is going to show up as either NameError or "unused variable". ChrisA From arj.python at gmail.com Tue Mar 12 08:18:06 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 12 Mar 2019 16:18:06 +0400 Subject: "use strict" In-Reply-To: References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> <2747e200-5f7e-b538-07b1-53d13e701508@kynesim.co.uk> Message-ID: excuses. have you used Js? well a bit like that in py. not necessarily unused as currently as it is, you can use the real one many times, the typo one many times. it's not an error but it's not what you expect. a linter basically parses the text, proposing to catch that without linter. the root catch is by catching undeclared variables usage. since in python you don't have declaration then assignment but you have both at the same time, i am proposing we solve this issue by having a special type of variables. Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius From rosuav at gmail.com Tue Mar 12 08:23:08 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Mar 2019 23:23:08 +1100 Subject: "use strict" In-Reply-To: References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> <2747e200-5f7e-b538-07b1-53d13e701508@kynesim.co.uk> Message-ID: On Tue, Mar 12, 2019 at 11:18 PM Abdur-Rahmaan Janhangeer wrote: > > excuses. > > have you used Js? well a bit like that in py. Yes, I have used JS, and in fact it's a critical part of my day job. But JS has a big difference in that you *declare* variables. As Rhodri says, asking for mandatory variable declarations in Python is unlikely to fly. > not necessarily unused as currently as it is, you can use the real one many times, the typo one many times. it's not an error but it's not what you expect. a linter basically parses the text, proposing to catch that without linter. > > the root catch is by catching undeclared variables usage. since in python you don't have declaration then assignment but you have both at the same time, i am proposing we solve this issue by having a special type of variables. > You still haven't explained how your special type of variable will work. Does it need to be declared? Is it that none of these special variables are allowed to be created inside loops? What is it? BE SPECIFIC. And please, quote some context in your replies. ChrisA From arj.python at gmail.com Tue Mar 12 08:28:07 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 12 Mar 2019 16:28:07 +0400 Subject: "use strict" In-Reply-To: References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> <2747e200-5f7e-b538-07b1-53d13e701508@kynesim.co.uk> Message-ID: ok, writing a pep-like document to explain all at once. sorry for eyes-hurting and brain-hunting. Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius From skauser at rocketsoftware.com Tue Mar 12 08:30:31 2019 From: skauser at rocketsoftware.com (Saba Kauser) Date: Tue, 12 Mar 2019 12:30:31 +0000 Subject: "Post install setup does not work as expected with pip install" Message-ID: Hello, I have a post install class that looks like this: if('darwin' in sys.platform): class PostInstall(install): """ Post installation - run install_name_tool on Darwin """ def run(self): clipath = os.getenv('IBM_DB_HOME', '@loader_path/clidriver') print("in PostInstall with {}".format(clipath)) for so in glob.glob(r'build/lib*/ibm_db*.so'): os.system("install_name_tool -change libdb2.dylib {}/lib/libdb2.dylib {}".format(clipath, so)) install.run(self) cmd_class = dict(install = PostInstall) And I pass cmd_class to setup(..) as: setup(.. include_package_data = True, cmdclass = cmd_class, **extra ) When I execute setup.py as "python setup.py install", then the PostInstall operation is executed after the ibm_db.so is built and installed and I see the intended result. Howeever, when I run "pip install ibm_db" or "pip install .", the execution order looks like this: warnings.warn(notifyString) running install in PostInstall with /Applications/dsdriver/ ==> this is my post install script running build running build_py creating build creating build/lib.macosx-10.9-x86_64-3.7 ==> I need to traverse to this folder to find my shared library I would expect it to be run post the ibm_db is installed, not before it gets built. Can you please let me know how can this be fixed. Is this a bug with pip? -------------------------------------------------------------------- Saba Kauser Db2 Connect development and support. Rocket Software Development India Pvt Ltd Karle Town Centre - SEZ, HUB 1 building, 4th Floor (North West Wing), 100 ft. Kempapura road, adjacent to Nagawara lake, Nagawara, Bangalore - 560 045 E: skauser at rocketsoftware.com --------------------------------------------------------------------- ================================ Rocket Software, Inc. and subsidiaries ? 77 Fourth Avenue, Waltham MA 02451 ? Main Office Toll Free Number: +1 855.577.4323 Contact Customer Support: https://my.rocketsoftware.com/RocketCommunity/RCEmailSupport Unsubscribe from Marketing Messages/Manage Your Subscription Preferences - http://www.rocketsoftware.com/manage-your-email-preferences Privacy Policy - http://www.rocketsoftware.com/company/legal/privacy-policy ================================ This communication and any attachments may contain confidential information of Rocket Software, Inc. All unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify Rocket Software immediately and destroy all copies of this communication. Thank you. From rhodri at kynesim.co.uk Tue Mar 12 07:53:20 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 12 Mar 2019 11:53:20 +0000 Subject: "use strict" In-Reply-To: References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> <2747e200-5f7e-b538-07b1-53d13e701508@kynesim.co.uk> Message-ID: On 12/03/2019 11:41, Abdur-Rahmaan Janhangeer wrote: > i also proposed > > # -*- explicit -*- To expand on my previous "ugh", I don't like hiding major run-time changes in cryptic comments. Behaviour like this should be very explicit in the way that a comment isn't, and shouldn't be so easily the default. -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Tue Mar 12 07:57:53 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 12 Mar 2019 11:57:53 +0000 Subject: "use strict" In-Reply-To: References: <0959fab2-7be4-ba60-3340-7f72cc10d8f1@kynesim.co.uk> <2747e200-5f7e-b538-07b1-53d13e701508@kynesim.co.uk> Message-ID: [[Replacing snipped context:]] > = Abdur-Rahmaan, no indent is me. On 12/03/2019 11:32, Abdur-Rahmaan Janhangeer wrote: > no i mean > > # *-* use strict *-* Ugh. > program > typovar = x # line y > > ... > > > Traceback: > on the fly var at line y Yes, but how is the program supposed to know that typovar is a typo? Are you proposing mandatory declarations for all variables, because I think you know what the answer to that one will be. [[End of previous post]] On 12/03/2019 11:40, Abdur-Rahmaan Janhangeer wrote: > no just the var you want to track maybe > > _var > > or something like that, i want to solve that problem and this is just a > proposal Sorry, I still don't understand. *What* do you want to mark with "_var"? It that a comment? A new keyword? Just a leading underscore? Could you give a full example, please? -- Rhodri James *-* Kynesim Ltd From ssmitch at gmail.com Tue Mar 12 09:13:40 2019 From: ssmitch at gmail.com (ssmitch at gmail.com) Date: Tue, 12 Mar 2019 06:13:40 -0700 (PDT) Subject: System Beep? In-Reply-To: References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> Message-ID: <11bcfdd1-89c7-463b-bc24-e022d76e1912@googlegroups.com> On Saturday, March 9, 2019 at 12:53:35 AM UTC-5, Terry Reedy wrote: > On 3/8/2019 1:13 PM, Steve wrote: > > How can I cause a system beep using code? > > >>> import winsound as ws > >>> ws.Beep(500, 1000) > > and > > >>> from tkinter import Tk > >>> root = Tk() > >>> root.bell() > > work for me. The bell is not exactly a bell, but different from a > monotone beep. > > -- > Terry Jan Reedy Another way that works (at least in Python 2.7) is >>> import winsound >>> winsound.MessageBeep(-1) Not exactly a beep, but definitely a pleasant alert. Stephen Mitchell From __peter__ at web.de Tue Mar 12 09:27:01 2019 From: __peter__ at web.de (Peter Otten) Date: Tue, 12 Mar 2019 14:27:01 +0100 Subject: "Post install setup does not work as expected with pip install" References: Message-ID: Saba Kauser wrote: > Hello, > > I have a post install class that looks like this: > if('darwin' in sys.platform): > class PostInstall(install): > """ Post installation - run install_name_tool on Darwin """ > def run(self): > clipath = os.getenv('IBM_DB_HOME', '@loader_path/clidriver') > print("in PostInstall with {}".format(clipath)) > for so in glob.glob(r'build/lib*/ibm_db*.so'): > os.system("install_name_tool -change libdb2.dylib > {}/lib/libdb2.dylib {}".format(clipath, so)) > install.run(self) I know nothing about what you are up to, but this looks odd to me. Wouldn't you need to call the superclass method install.run(self) *before* your custom code with the for loop? > cmd_class = dict(install = PostInstall) > > > And I pass cmd_class to setup(..) as: > setup(.. > include_package_data = True, > cmdclass = cmd_class, > **extra > ) > > When I execute setup.py as "python setup.py install", then the PostInstall > operation is executed after the ibm_db.so is built and installed and I see > the intended result. Howeever, when I run "pip install ibm_db" or "pip > install .", the execution order looks like this: > warnings.warn(notifyString) > running install > in PostInstall with /Applications/dsdriver/ ==> this is my post > install script running build > running build_py > creating build > creating build/lib.macosx-10.9-x86_64-3.7 ==> I need to traverse to > this folder to find my shared library > > I would expect it to be run post the ibm_db is installed, not before it > gets built. > > Can you please let me know how can this be fixed. Is this a bug with pip? > > -------------------------------------------------------------------- > Saba Kauser > Db2 Connect development and support. > > Rocket Software Development India Pvt Ltd > Karle Town Centre - SEZ, > HUB 1 building, 4th Floor (North West Wing), > 100 ft. Kempapura road, adjacent to Nagawara lake, > Nagawara, Bangalore - 560 045 > E: skauser at rocketsoftware.com > --------------------------------------------------------------------- > > > ================================ > Rocket Software, Inc. and subsidiaries ? 77 Fourth Avenue, Waltham MA > 02451 ? Main Office Toll Free Number: +1 855.577.4323 Contact Customer > Support: https://my.rocketsoftware.com/RocketCommunity/RCEmailSupport > Unsubscribe from Marketing Messages/Manage Your Subscription Preferences - > http://www.rocketsoftware.com/manage-your-email-preferences Privacy Policy > - http://www.rocketsoftware.com/company/legal/privacy-policy > ================================ > > This communication and any attachments may contain confidential > information of Rocket Software, Inc. All unauthorized use, disclosure or > distribution is prohibited. If you are not the intended recipient, please > notify Rocket Software immediately and destroy all copies of this > communication. Thank you. From rosuav at gmail.com Tue Mar 12 09:52:25 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Mar 2019 00:52:25 +1100 Subject: System Beep? In-Reply-To: <11bcfdd1-89c7-463b-bc24-e022d76e1912@googlegroups.com> References: <000e01d4d5da$ae618340$0b2489c0$@SGA.Ninja> <11bcfdd1-89c7-463b-bc24-e022d76e1912@googlegroups.com> Message-ID: On Wed, Mar 13, 2019 at 12:16 AM wrote: > > On Saturday, March 9, 2019 at 12:53:35 AM UTC-5, Terry Reedy wrote: > > On 3/8/2019 1:13 PM, Steve wrote: > > > How can I cause a system beep using code? > > > > >>> import winsound as ws > > >>> ws.Beep(500, 1000) > > > > and > > > > >>> from tkinter import Tk > > >>> root = Tk() > > >>> root.bell() > > > > work for me. The bell is not exactly a bell, but different from a > > monotone beep. > > > > -- > > Terry Jan Reedy > > Another way that works (at least in Python 2.7) is > >>> import winsound > >>> winsound.MessageBeep(-1) > > Not exactly a beep, but definitely a pleasant alert. Something to be careful of is that the message beep is controlled by the user's sound configs (along with warning, error, etc). This may include it having no audio attached to it at all. If your intention is "tell the user there's a message", then by all means, use it; but otherwise, you may want to stick with winsound.Beep. ChrisA From ar at zeit.io Tue Mar 12 10:38:14 2019 From: ar at zeit.io (Arup Rakshit) Date: Tue, 12 Mar 2019 20:08:14 +0530 Subject: Python scope question Message-ID: I have questions how nonlocal and global affecting the variable assignment. Also how each print statement looking up the values for the spam variable. This scope thing in python is very confusing too me still. Can anyone help me to understand this code w.r.t to scope in Python? def scope_test(): def do_local(): spam = "local spam" def do_nonlocal(): nonlocal spam spam = "nonlocal spam" def do_global(): global spam spam = "global spam" spam = "test spam" do_local() print("After local assignment:", spam) do_nonlocal() print("After nonlocal assignment:", spam) do_global() print("After global assignment:", spam) scope_test() print("In global scope:", spam) ?? $ python3 sample.py After local assignment: test spam After nonlocal assignment: nonlocal spam After global assignment: nonlocal spam In global scope: global spam Thanks, Arup Rakshit ar at zeit.io From grant.b.edwards at gmail.com Tue Mar 12 10:47:49 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 12 Mar 2019 14:47:49 -0000 (UTC) Subject: Python scope question References: Message-ID: On 2019-03-12, Arup Rakshit wrote: > I have questions how nonlocal and global affecting the variable > assignment. Also how each print statement looking up the values for > the spam variable. This scope thing in python is very confusing too > me still. Can anyone help me to understand this code w.r.t to scope > in Python? https://www.ynonperek.com/2017/09/11/python-variable-scope-implicit-global-and-nonlocal/ -- Grant Edwards grant.b.edwards Yow! If I pull this SWITCH at I'll be RITA HAYWORTH!! gmail.com Or a SCIENTOLOGIST! From torriem at gmail.com Tue Mar 12 10:42:13 2019 From: torriem at gmail.com (Michael Torrie) Date: Tue, 12 Mar 2019 08:42:13 -0600 Subject: "use strict" In-Reply-To: References: Message-ID: <0429cd61-4b4f-6958-12d8-4c9a99d54d0e@gmail.com> On 03/11/2019 01:00 PM, Abdur-Rahmaan Janhangeer wrote: > the problem was that i was reviewing the code, since everything worked (no > errors but wrong output for sure) it took sometimes to find that var. it > was like someone telling me there is fish in that lake and i was throwing > my line trying ... Code review is precisely the sort of time when a linter should be run on the code to try to flag potential problems like this. Sure it will flag things that don't really matter, but you can ignore those. Additionally using the type annotations that are now a part of Python (3) will help the linter be even more useful to you in this scenario. > just a way to flag those types of vars when needed. Until you forget to flag one sometime. Or end up flagging every variable, which takes us back around to type annotations and linters. So no, the answer is probably still, use a linter. From python at bdurham.com Tue Mar 12 10:51:12 2019 From: python at bdurham.com (Malcolm Greene) Date: Tue, 12 Mar 2019 10:51:12 -0400 Subject: Convert Windows paths to Linux style paths Message-ID: Looking for best practice technique for converting Windows style paths to Linux paths. Is there an os function or pathlib method that I'm missing or is it some combination of replacing Windows path separators with Linux path separators plus some other platform specific logic? Thank you, Malcolm From thecompletebackoffice at gmail.com Tue Mar 12 06:33:12 2019 From: thecompletebackoffice at gmail.com (Louis Aucamp) Date: Tue, 12 Mar 2019 12:33:12 +0200 Subject: 0x80070005 - acess denied when installing Python Message-ID: Goodday to all Members I need help with an installation problem. The background is as follows: I used PyScripter and Python 3.7 for learning python. I am taking a course on Edx "introduction to data science" and one of the requirements is that you install Anaconda. I have had bad experiences with anaconda in a previous attempt and was reluctant to try again but decided to give it another try . I had the same problems of programs freezing and crashing and uninstalled anaconda. This cured my PC but now I cannot install Python 37 at all and get the error notice above. I have been through the usual google recommended fixes but none works and I have checked that anaconda is cleanly removed and that I have full administartors rights for installing programs. Can somebody out there please supply some help? Enjoy the day Louis Aucamp From python at bdurham.com Tue Mar 12 11:00:09 2019 From: python at bdurham.com (Malcolm Greene) Date: Tue, 12 Mar 2019 11:00:09 -0400 Subject: Multiprocessing vs subprocess to run Python scripts in parallel Message-ID: <91680fb6-6d75-491b-a045-dca23294f8c8@www.fastmail.com> Use case: I have a Python manager script that monitors several conditions (not just time based schedules) that needs to launch Python worker scripts to respond to the conditions it detects. Several of these worker scripts may end up running in parallel. There are no dependencies between individual worker scripts. I'm looking for the pros and cons of using multiprocessing or subprocess to launch these worker scripts. Looking for a solution that works across Windows and Linux. Open to using a 3rd party library. Hoping to avoid the use of yet another system component like Celery if possible and rational. My understanding (so far) is that the tradeoff of using multiprocessing is that my manager script can not exit until all the work processes it starts finish. If one of the worker scripts locks up, this could be problematic. Is there a way to use multiprocessing where processes are launched independent of the parent (manager) process? Thank you, Malcolm From rosuav at gmail.com Tue Mar 12 11:13:28 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Mar 2019 02:13:28 +1100 Subject: Multiprocessing vs subprocess to run Python scripts in parallel In-Reply-To: <91680fb6-6d75-491b-a045-dca23294f8c8@www.fastmail.com> References: <91680fb6-6d75-491b-a045-dca23294f8c8@www.fastmail.com> Message-ID: On Wed, Mar 13, 2019 at 2:01 AM Malcolm Greene wrote: > > Use case: I have a Python manager script that monitors several conditions (not just time based schedules) that needs to launch Python worker scripts to respond to the conditions it detects. Several of these worker scripts may end up running in parallel. There are no dependencies between individual worker scripts. I'm looking for the pros and cons of using multiprocessing or subprocess to launch these worker scripts. Looking for a solution that works across Windows and Linux. Open to using a 3rd party library. Hoping to avoid the use of yet another system component like Celery if possible and rational. > > My understanding (so far) is that the tradeoff of using multiprocessing is that my manager script can not exit until all the work processes it starts finish. If one of the worker scripts locks up, this could be problematic. Is there a way to use multiprocessing where processes are launched independent of the parent (manager) process? > One advantage of multiprocessing is that it can fork, rather than spinning up an entire new Python process from scratch. This doesn't work on Windows, but it can give huge performance advantages on Unix systems. If the subprocesses are basically spun off and abandoned, you probably want to use subprocess, but at this point, you're talking architectural style and there are no right/wrong answers, just consequences of different decisions. For instance, multiprocessing will always run all the children in the exact same Python interpreter that the master was invoked from, but with subprocess, you can invoke anything you like (doesn't even have to be Python). OTOH, the aforementioned performance advantage could be pretty significant if you're starting lots of different processes in a short space of time. And maybe you don't even need subprocesses at all, but could do it all with threads or other forms of asynchronicity. You may need to mess around a bit before making a decision. ChrisA From tjol at tjol.eu Tue Mar 12 11:05:27 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 12 Mar 2019 16:05:27 +0100 Subject: Convert Windows paths to Linux style paths In-Reply-To: References: Message-ID: On 12/03/2019 15.51, Malcolm Greene wrote: > Looking for best practice technique for converting Windows style paths to Linux paths. Is there an os function or pathlib method that I'm missing or is it some combination of replacing Windows path separators with Linux path separators plus some other platform specific logic? > > Thank you, > Malcolm > Could you give some examples of what sort of paths you want to convert in what way? From bill at celestial.net Tue Mar 12 11:40:36 2019 From: bill at celestial.net (Bill Campbell) Date: Tue, 12 Mar 2019 08:40:36 -0700 Subject: Convert Windows paths to Linux style paths In-Reply-To: References: Message-ID: <20190312154036.GA7754@ayn.mi.celestial.com> On Tue, Mar 12, 2019, Malcolm Greene wrote: >Looking for best practice technique for converting Windows style paths to >Linux paths. Is there an os function or pathlib method that I'm missing or >is it some combination of replacing Windows path separators with Linux path >separators plus some other platform specific logic? See os.path.join Bill -- INTERNET: bill at celestial.com Bill Campbell; Celestial Software LLC URL: http://www2.celestial.com/ 6641 E. Mercer Way Mobile: (206) 947-5591 PO Box 820 Fax: (206) 232-9186 Mercer Island, WA 98040-0820 The very concept of objective truth is fading out of the world. Lies will pass into history. -- George Orwell From p.f.moore at gmail.com Tue Mar 12 12:24:55 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 12 Mar 2019 16:24:55 +0000 Subject: Convert Windows paths to Linux style paths In-Reply-To: References: Message-ID: On Tue, 12 Mar 2019 at 14:54, Malcolm Greene wrote: > > Looking for best practice technique for converting Windows style paths to Linux paths. Is there an os function or pathlib method that I'm missing or is it some combination of replacing Windows path separators with Linux path separators plus some other platform specific logic? You need to explain what you mean by "converting". How would you want "C:\Windows" to be converted? Or "\\myserver\myshare\path\to\file.txt"? Or "\\?\D:\very long path"? What if the path is too long for POSIX filename length limitations? How do you want to handle Unicode? Do you care about case sensitivity (for example, is it important to you whether filenames "foo" and "FOO" map to the same file or not on Linux, given that they do on Windows)? It's quite possible that your answer to any or all of these questions are "I don't need to consider these cases". But we don't know which cases matter to you unless you clarify, and the *general* problem of "converting filenames" between operating systems is essentially impossible, because semantics are radically different. Paul From Joseph.Schachner at Teledyne.com Tue Mar 12 12:24:25 2019 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Tue, 12 Mar 2019 16:24:25 +0000 Subject: Multiprocessing vs subprocess Message-ID: Re: " My understanding (so far) is that the tradeoff of using multiprocessing is that my manager script can not exit until all the work processes it starts finish. If one of the worker scripts locks up, this could be problematic. Is there a way to use multiprocessing where processes are launched independent of the parent (manager) process?" I just want to point out that subprocess (which uses the operating system to start another processes, to run whatever you say - doesn't have to be Python running another script, can be an .exe) does not have that restriction. The subprocess call can be blocking (the caller waits), or not. If not the caller can do whatever it wants including decide not to wait forever, and it can even exit. Of course, if one of the processes you launched is locked up that is a problem all by itself, even thought the manager can exit. --- Joseph S. From PythonList at danceswithmice.info Tue Mar 12 14:41:57 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Wed, 13 Mar 2019 07:41:57 +1300 Subject: Python scope question In-Reply-To: References: Message-ID: Arup, On 13/03/19 3:38 AM, Arup Rakshit wrote: > I have questions how nonlocal and global affecting the variable assignment. Also how each print statement looking up the values for the spam variable. This scope thing in python is very confusing too me still. Can anyone help me to understand this code w.r.t to scope in Python? ... > $ python3 sample.py > After local assignment: test spam > After nonlocal assignment: nonlocal spam > After global assignment: nonlocal spam > In global scope: global spam Think this will help. Watch the scopes 'appear' and operate in front of your very eyes: https://goo.gl/JC6SSh or http://pythontutor.com/visualize.html#code=def%20scope_test%28%29%3A%0A%20%20%20%20def%20do_local%28%29%3A%0A%20%20%20%20%20%20%20%20spam%20%3D%20%22local%20spam%22%0A%0A%20%20%20%20def%20do_nonlocal%28%29%3A%0A%20%20%20%20%20%20%20%20nonlocal%20spam%0A%20%20%20%20%20%20%20%20spam%20%3D%20%22nonlocal%20spam%22%0A%0A%20%20%20%20def%20do_global%28%29%3A%0A%20%20%20%20%20%20%20%20global%20spam%0A%20%20%20%20%20%20%20%20spam%20%3D%20%22global%20spam%22%0A%0A%20%20%20%20spam%20%3D%20%22test%20spam%22%0A%20%20%20%20do_local%28%29%0A%20%20%20%20print%28%22After%20local%20assignment%3A%22,%20spam%29%0A%20%20%20%20do_nonlocal%28%29%0A%20%20%20%20print%28%22After%20nonlocal%20assignment%3A%22,%20spam%29%0A%20%20%20%20do_global%28%29%0A%20%20%20%20print%28%22After%20global%20assignment%3A%22,%20spam%29%0A%0Ascope_test%28%29%0Aprint%28%22In%20global%20scope%3A%22,%20spam%29%0A&cumulative=false&curInstr=24&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&textReferences=false -- Regards =dn From jakub.bista at gmail.com Tue Mar 12 18:54:06 2019 From: jakub.bista at gmail.com (Jakub Bista) Date: Tue, 12 Mar 2019 15:54:06 -0700 (PDT) Subject: 3D visualizations in Python Message-ID: Hello. I want to do 3D visualization in Python. Which framework do you recommend me for creating such a Interface? From larry.martell at gmail.com Tue Mar 12 18:58:17 2019 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 12 Mar 2019 18:58:17 -0400 Subject: 3D visualizations in Python In-Reply-To: References: Message-ID: On Tue, Mar 12, 2019 at 6:55 PM Jakub Bista wrote: > > Hello. I want to do 3D visualization in Python. Which framework do you recommend me for creating such a Interface? https://plot.ly/python/ From nad at python.org Tue Mar 12 19:28:52 2019 From: nad at python.org (Ned Deily) Date: Tue, 12 Mar 2019 19:28:52 -0400 Subject: [RELEASE] Python 3.7.3rc1 is now available for testing. Message-ID: Python 3.7.3rc1 is now available for testing. 3.7.3rc1 is the release preview of the next maintenance release of Python 3.7, the latest feature release of Python. Assuming no critical problems are found prior to 2019-03-25, no code changes are planned between now and the final release. This release candidate is intended to give you the opportunity to test the new security and bug fixes in 3.7.3. We strongly encourage you to test your projects and report issues found to bugs.python.org as soon as possible. Please keep in mind that this is a preview release and, thus, its use is not recommended for production environments. You can find the release files, a link to the changelog, and more information here: https://www.python.org/downloads/release/python-373rc1/ -- Ned Deily nad at python.org -- [] From ar at zeit.io Wed Mar 13 01:31:47 2019 From: ar at zeit.io (Arup Rakshit) Date: Wed, 13 Mar 2019 11:01:47 +0530 Subject: Python scope question In-Reply-To: References: Message-ID: Hello, Thanks for this beautiful link. This is amazing. Thanks, Arup Rakshit ar at zeit.io > On 13-Mar-2019, at 12:11 AM, DL Neil wrote: > > Arup, > > > On 13/03/19 3:38 AM, Arup Rakshit wrote: >> I have questions how nonlocal and global affecting the variable assignment. Also how each print statement looking up the values for the spam variable. This scope thing in python is very confusing too me still. Can anyone help me to understand this code w.r.t to scope in Python? > ... >> $ python3 sample.py >> After local assignment: test spam >> After nonlocal assignment: nonlocal spam >> After global assignment: nonlocal spam >> In global scope: global spam > > > Think this will help. > > Watch the scopes 'appear' and operate in front of your very eyes: https://goo.gl/JC6SSh > > or > http://pythontutor.com/visualize.html#code=def%20scope_test%28%29%3A%0A%20%20%20%20def%20do_local%28%29%3A%0A%20%20%20%20%20%20%20%20spam%20%3D%20%22local%20spam%22%0A%0A%20%20%20%20def%20do_nonlocal%28%29%3A%0A%20%20%20%20%20%20%20%20nonlocal%20spam%0A%20%20%20%20%20%20%20%20spam%20%3D%20%22nonlocal%20spam%22%0A%0A%20%20%20%20def%20do_global%28%29%3A%0A%20%20%20%20%20%20%20%20global%20spam%0A%20%20%20%20%20%20%20%20spam%20%3D%20%22global%20spam%22%0A%0A%20%20%20%20spam%20%3D%20%22test%20spam%22%0A%20%20%20%20do_local%28%29%0A%20%20%20%20print%28%22After%20local%20assignment%3A%22,%20spam%29%0A%20%20%20%20do_nonlocal%28%29%0A%20%20%20%20print%28%22After%20nonlocal%20assignment%3A%22,%20spam%29%0A%20%20%20%20do_global%28%29%0A%20%20%20%20print%28%22After%20global%20assignment%3A%22,%20spam%29%0A%0Ascope_test%28%29%0Aprint%28%22In%20global%20scope%3A%22,%20spam%29%0A&cumulative=false&curInstr=24&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&te > xtReferences=false > > > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list From eryksun at gmail.com Wed Mar 13 04:10:20 2019 From: eryksun at gmail.com (eryk sun) Date: Wed, 13 Mar 2019 03:10:20 -0500 Subject: Convert Windows paths to Linux style paths In-Reply-To: References: Message-ID: On 3/12/19, Paul Moore wrote: > > Do you care about case sensitivity (for example, is it important to you > whether filenames "foo" and "FOO" map to the same file or not on > Linux, given that they do on Windows)? That's no longer a given in Windows, since NTFS in Windows 10 supports case-sensitive directories that override the Windows API. For some reason they didn't expose this as a file attribute set on the directory, so it can only be queried using either an NT system call or the fsutil.exe command-line program. Our Windows filesystem code (e.g. in pathlib) that assumes case-insensitive filename matching (e.g. via the casefold, lower, or upper string methods) is wrong for case-sensitive directories. For example: >>> p = pathlib.Path('C:/CaseSensitive') >>> os.system(f'fsutil file queryCaseSensitiveInfo "{p}"') Case sensitive attribute on directory C:\CaseSensitive is enabled. 0 >>> (p / 'foo').touch() >>> (p / 'FOO').touch() >>> os.listdir(p) ['FOO', 'foo'] Due to pathlib's use of case folding in Windows, globbing "foo" and "FOO" both match "foo": >>> list(p.glob('foo')) [WindowsPath('C:/CaseSensitive/foo')] >>> list(p.glob('FOO')) [WindowsPath('C:/CaseSensitive/foo')] If we remove "foo", glob('FOO') no longer matches anything since it checks for the existence of "foo" instead of "FOO": >>> os.remove(p / 'foo') >>> os.listdir(p) ['FOO'] >>> list(p.glob('FOO')) [] From jonas.thornvall at gmail.com Wed Mar 13 04:23:35 2019 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Wed, 13 Mar 2019 01:23:35 -0700 (PDT) Subject: Not a python question, just programming logic trap? Message-ID: <1a96f848-9fa5-4edc-902b-3a77d03990fd@googlegroups.com> Anyone who is good at see logic traps in programming? comp.lang.javascript is defunct so i try here. Using the metronome. https://midisequenser.000webhostapp.com I've tried to understand how following code can lead to that after the keyreleased the front of the keyed scrollbar raise/extend faster while the backend stay correct "in sync". One could think/imagine xFrontStart=scrollBarPos-FRONTOFFSET; somehow executed more then once after release, but how could it, the keyrelease is true only in that part of code and only done once??? var FRONTOFFSET=0; var xKeylength=0; var xFrontStart=0; var xBackEnd=0; var keyreleased=false; function pianoSCROLL(){ if(mess.data[0]==NOTE_ON && keyreleased==false){ xBackEnd=keylength; ctm.fillStyle = "magenta"; ctm.fillRect(xBackEnd,(PistartX+keyHeight*88)-(keyHeight*(mess.data[1]-8)), xFrontStart, keyHeight); if(FRONTOFFSET==0) {FRONTOFFSET=scrollBarPos;} xFrontStart=scrollBarPos-FRONTOFFSET; } else if(mess.data[0]==NOTE_OFF && keyreleased==false){ console.log("keyreleased!"); keyreleased=true; xBarLength=Math.round(xFrontStart-xBackEnd); ctm.fillStyle = "black"; ctm.fillRect(keylength, (PistartX+keyHeight*88)-(keyHeight*(mess.data[1]-8)), Mwidth, keyHeight+2); } if (keyreleased) { //console.log("timebar backend moving"); ctm.fillStyle = "black"; ctm.fillRect(keylength, (PistartX+keyHeight*88)-(keyHeight*(mess.data[1]-8)), Mwidth, keyHeight+2); ctm.fillStyle = "orange"; ctm.fillRect(xBackEnd,(PistartX+keyHeight*88)-(keyHeight*(mess.data[1]-8)),xFrontStart, keyHeight); xFrontStart=scrollBarPos-FRONTOFFSET; xBackEnd=Math.round(xFrontStart-xBarLength); console.log("xBackEnd="+xBackEnd+" xBarLength="+xBarLength+" xFrontStart="+xFrontStart); } } From jonas.thornvall at gmail.com Wed Mar 13 04:30:34 2019 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Wed, 13 Mar 2019 01:30:34 -0700 (PDT) Subject: Not a python question, just programming logic trap? In-Reply-To: <1a96f848-9fa5-4edc-902b-3a77d03990fd@googlegroups.com> References: <1a96f848-9fa5-4edc-902b-3a77d03990fd@googlegroups.com> Message-ID: Den onsdag 13 mars 2019 kl. 09:23:50 UTC+1 skrev jonas.t... at gmail.com: > Anyone who is good at see logic traps in programming? comp.lang.javascript is defunct so i try here. > > Using the metronome. > > https://midisequenser.000webhostapp.com > > I've tried to understand how following code can lead to that after the keyreleased the front of the keyed scrollbar raise/extend faster while the backend stay correct "in sync". One could think/imagine xFrontStart=scrollBarPos-FRONTOFFSET; somehow executed more then once after release, but how could it, the keyrelease is true only in that part of code and only done once??? > > var FRONTOFFSET=0; > var xKeylength=0; > var xFrontStart=0; > var xBackEnd=0; > var keyreleased=false; > function pianoSCROLL(){ > > if(mess.data[0]==NOTE_ON && keyreleased==false){ > xBackEnd=keylength; > ctm.fillStyle = "magenta"; > ctm.fillRect(xBackEnd,(PistartX+keyHeight*88)-(keyHeight*(mess.data[1]-8)), xFrontStart, keyHeight); > if(FRONTOFFSET==0) {FRONTOFFSET=scrollBarPos;} > xFrontStart=scrollBarPos-FRONTOFFSET; > } else if(mess.data[0]==NOTE_OFF && keyreleased==false){ > console.log("keyreleased!"); > keyreleased=true; > xBarLength=Math.round(xFrontStart-xBackEnd); > ctm.fillStyle = "black"; > ctm.fillRect(keylength, (PistartX+keyHeight*88)-(keyHeight*(mess.data[1]-8)), Mwidth, keyHeight+2); > } > if (keyreleased) { > //console.log("timebar backend moving"); > ctm.fillStyle = "black"; > ctm.fillRect(keylength, (PistartX+keyHeight*88)-(keyHeight*(mess.data[1]-8)), Mwidth, keyHeight+2); > ctm.fillStyle = "orange"; > ctm.fillRect(xBackEnd,(PistartX+keyHeight*88)-(keyHeight*(mess.data[1]-8)),xFrontStart, keyHeight); > xFrontStart=scrollBarPos-FRONTOFFSET; > xBackEnd=Math.round(xFrontStart-xBarLength); > console.log("xBackEnd="+xBackEnd+" xBarLength="+xBarLength+" xFrontStart="+xFrontStart); > } > } Yes i am aware i should buffer keystrokes in range of canvas in an array, but first i want the actual logic to sync keystrokes with scrollbar. From p.f.moore at gmail.com Wed Mar 13 06:27:07 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 13 Mar 2019 10:27:07 +0000 Subject: Convert Windows paths to Linux style paths In-Reply-To: References: Message-ID: On Wed, 13 Mar 2019 at 08:13, eryk sun wrote: > > On 3/12/19, Paul Moore wrote: > > > > Do you care about case sensitivity (for example, is it important to you > > whether filenames "foo" and "FOO" map to the same file or not on > > Linux, given that they do on Windows)? > > That's no longer a given in Windows, since NTFS in Windows 10 supports > case-sensitive directories that override the Windows API. I know, but I thought my answer to the OP included enough complexities for them to think about without going into this level of detail ;-) But yes, "converting filenames" is a hard problem, unless you really do just want a simple text based transformation. Paul From marco.nawijn at colosso.nl Wed Mar 13 07:19:29 2019 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Wed, 13 Mar 2019 04:19:29 -0700 (PDT) Subject: 3D visualizations in Python In-Reply-To: References: Message-ID: <7254405a-6a79-45e3-996f-7a5703c992ec@googlegroups.com> On Tuesday, March 12, 2019 at 11:54:22 PM UTC+1, Jakub Bista wrote: > Hello. I want to do 3D visualization in Python. Which framework do you recommend me for creating such a Interface? I would recommend the VTK library (https://vtk.org/). It has excellent Python bindings. Marco From oliver.schoenborn at gmail.com Wed Mar 13 08:27:31 2019 From: oliver.schoenborn at gmail.com (oliver) Date: Wed, 13 Mar 2019 08:27:31 -0400 Subject: Multiprocessing vs subprocess In-Reply-To: References: Message-ID: With multiprocessing you can take advantage of multi-core processing as it launches a separate python interpreter process and communicates with it via shared memory (at least on windows). The big advantage of multiprocessing module is that the interaction between processes is much richer than subprocess: subprocess is limited to pipes (unless you build your own alternate comms mechanism), whereas multiprocessing takes care of marshalling python objects and transporting them to the other processes. This can be huge in some applications, like we were using it to run batch monte carlo simulations where we needed to pass simulation related datastructures, would have been a pain with subprocess. On Tue, Mar 12, 2019 at 12:30 PM Schachner, Joseph < Joseph.Schachner at teledyne.com> wrote: > Re: " My understanding (so far) is that the tradeoff of using > multiprocessing is that my manager script can not exit until all the work > processes it starts finish. If one of the worker scripts locks up, this > could be problematic. Is there a way to use multiprocessing where processes > are launched independent of the parent (manager) process?" > > I just want to point out that subprocess (which uses the operating system > to start another processes, to run whatever you say - doesn't have to be > Python running another script, can be an .exe) does not have that > restriction. The subprocess call can be blocking (the caller waits), or > not. If not the caller can do whatever it wants including decide not to > wait forever, and it can even exit. > > Of course, if one of the processes you launched is locked up that is a > problem all by itself, even thought the manager can exit. > > --- Joseph S. > -- > https://mail.python.org/mailman/listinfo/python-list > From skauser at rocketsoftware.com Wed Mar 13 10:59:45 2019 From: skauser at rocketsoftware.com (Saba Kauser) Date: Wed, 13 Mar 2019 14:59:45 +0000 Subject: "Post install setup does not work as expected with pip install" In-Reply-To: References: Message-ID: I am able to get this to work. I had to invoke parent's run before my post install logic could kick. _____________________________________________ From: Saba Kauser Sent: Tuesday, March 12, 2019 6:01 PM To: python-list at python.org Subject: "Post install setup does not work as expected with pip install" Hello, I have a post install class that looks like this: if('darwin' in sys.platform): class PostInstall(install): """ Post installation - run install_name_tool on Darwin """ def run(self): clipath = os.getenv('IBM_DB_HOME', '@loader_path/clidriver') print("in PostInstall with {}".format(clipath)) for so in glob.glob(r'build/lib*/ibm_db*.so'): os.system("install_name_tool -change libdb2.dylib {}/lib/libdb2.dylib {}".format(clipath, so)) install.run(self) cmd_class = dict(install = PostInstall) And I pass cmd_class to setup(..) as: setup(.. include_package_data = True, cmdclass = cmd_class, **extra ) When I execute setup.py as "python setup.py install", then the PostInstall operation is executed after the ibm_db.so is built and installed and I see the intended result. Howeever, when I run "pip install ibm_db" or "pip install .", the execution order looks like this: warnings.warn(notifyString) running install in PostInstall with /Applications/dsdriver/ ==> this is my post install script running build running build_py creating build creating build/lib.macosx-10.9-x86_64-3.7 ==> I need to traverse to this folder to find my shared library I would expect it to be run post the ibm_db is installed, not before it gets built. Can you please let me know how can this be fixed. Is this a bug with pip? -------------------------------------------------------------------- Saba Kauser Db2 Connect development and support. Rocket Software Development India Pvt Ltd Karle Town Centre - SEZ, HUB 1 building, 4th Floor (North West Wing), 100 ft. Kempapura road, adjacent to Nagawara lake, Nagawara, Bangalore - 560 045 E: skauser at rocketsoftware.com --------------------------------------------------------------------- ================================ Rocket Software, Inc. and subsidiaries ? 77 Fourth Avenue, Waltham MA 02451 ? Main Office Toll Free Number: +1 855.577.4323 Contact Customer Support: https://my.rocketsoftware.com/RocketCommunity/RCEmailSupport Unsubscribe from Marketing Messages/Manage Your Subscription Preferences - http://www.rocketsoftware.com/manage-your-email-preferences Privacy Policy - http://www.rocketsoftware.com/company/legal/privacy-policy ================================ This communication and any attachments may contain confidential information of Rocket Software, Inc. All unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify Rocket Software immediately and destroy all copies of this communication. Thank you. From ingy at ingy.net Wed Mar 13 13:02:24 2019 From: ingy at ingy.net (Ingy dot Net) Date: Wed, 13 Mar 2019 10:02:24 -0700 Subject: [ANN] PyYAML-5.1: YAML parser and emitter for Python Message-ID: ======================= Announcing PyYAML-5.1 ======================= A new MAJOR RELEASE of PyYAML is now available: https://pypi.org/project/PyYAML/ This is the first major release of PyYAML under the new maintenance team. Among the many changes listed below, this release specifically addresses the arbitrary code execution issue raised by: https://nvd.nist.gov/vuln/detail/CVE-2017-18342 (See https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation for complete details). The PyYAML project is now maintained by the YAML and Python communities. Planning happens on the #yaml-dev, #pyyaml and #libyaml IRC channels on irc.freenode.net. Changes ======= * https://github.com/yaml/pyyaml/pull/35 -- Some modernization of the test running * https://github.com/yaml/pyyaml/pull/42 -- Install tox in a virtualenv * https://github.com/yaml/pyyaml/pull/45 -- Allow colon in a plain scalar in a flow context * https://github.com/yaml/pyyaml/pull/48 -- Fix typos * https://github.com/yaml/pyyaml/pull/55 -- Improve RepresenterError creation * https://github.com/yaml/pyyaml/pull/59 -- Resolves #57, update readme issues link * https://github.com/yaml/pyyaml/pull/60 -- Document and test Python 3.6 support * https://github.com/yaml/pyyaml/pull/61 -- Use Travis CI built in pip cache support * https://github.com/yaml/pyyaml/pull/62 -- Remove tox workaround for Travis CI * https://github.com/yaml/pyyaml/pull/63 -- Adding support to Unicode characters over codepoint 0xffff * https://github.com/yaml/pyyaml/pull/65 -- Support unicode literals over codepoint 0xffff * https://github.com/yaml/pyyaml/pull/75 -- add 3.12 changelog * https://github.com/yaml/pyyaml/pull/76 -- Fallback to Pure Python if Compilation fails * https://github.com/yaml/pyyaml/pull/84 -- Drop unsupported Python 3.3 * https://github.com/yaml/pyyaml/pull/102 -- Include license file in the generated wheel package * https://github.com/yaml/pyyaml/pull/105 -- Removed Python 2.6 & 3.3 support * https://github.com/yaml/pyyaml/pull/111 -- Remove commented out Psyco code * https://github.com/yaml/pyyaml/pull/129 -- Remove call to `ord` in lib3 emitter code * https://github.com/yaml/pyyaml/pull/143 -- Allow to turn off sorting keys in Dumper * https://github.com/yaml/pyyaml/pull/149 -- Test on Python 3.7-dev * https://github.com/yaml/pyyaml/pull/158 -- Support escaped slash in double quotes "\/" * https://github.com/yaml/pyyaml/pull/181 -- Import Hashable from collections.abc * https://github.com/yaml/pyyaml/pull/256 -- Make default_flow_style=False * https://github.com/yaml/pyyaml/pull/257 -- Deprecate yaml.load and add FullLoader and UnsafeLoader classes * https://github.com/yaml/pyyaml/pull/263 -- Windows Appveyor build Resources ========= PyYAML IRC Channel: #pyyaml on irc.freenode.net PyYAML homepage: https://github.com/yaml/pyyaml PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation Source and binary installers: https://pypi.org/project/PyYAML/ GitHub repository: https://github.com/yaml/pyyaml/ Bug tracking: https://github.com/yaml/pyyaml/issues YAML homepage: http://yaml.org/ YAML-core mailing list: http://lists.sourceforge.net/lists/listinfo/yaml-core About PyYAML ============ YAML is a data serialization format designed for human readability and interaction with scripting languages. PyYAML is a YAML parser and emitter for Python. PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object. PyYAML is applicable for a broad range of tasks from complex configuration files to object serialization and persistence. Example ======= >>> import yaml >>> yaml.full_load(""" ... name: PyYAML ... description: YAML parser and emitter for Python ... homepage: https://github.com/yaml/pyyaml ... keywords: [YAML, serialization, configuration, persistence, pickle] ... """) {'keywords': ['YAML', 'serialization', 'configuration', 'persistence', 'pickle'], 'homepage': 'https://github.com/yaml/pyyaml', 'description': 'YAML parser and emitter for Python', 'name': 'PyYAML'} >>> print(yaml.dump(_)) name: PyYAML homepage: https://github.com/yaml/pyyaml description: YAML parser and emitter for Python keywords: [YAML, serialization, configuration, persistence, pickle] Maintainers =========== The following people are currently responsible for maintaining PyYAML: * Ingy d?t Net * Tina Mueller * Matt Davis and many thanks to all who have contribributed! See: https://github.com/yaml/pyyaml/pulls Copyright ========= Copyright (c) 2017-2019 Ingy d?t Net Copyright (c) 2006-2016 Kirill Simonov The PyYAML module was written by Kirill Simonov . It is currently maintained by the YAML and Python communities. PyYAML is released under the MIT license. See the file LICENSE for more details. From ben+python at benfinney.id.au Wed Mar 13 16:15:33 2019 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 14 Mar 2019 07:15:33 +1100 Subject: Not a python question, just programming logic trap? References: <1a96f848-9fa5-4edc-902b-3a77d03990fd@googlegroups.com> Message-ID: <86muly350a.fsf@benfinney.id.au> jonas.thornvall at gmail.com writes: > Anyone who is good at see logic traps in programming? > comp.lang.javascript is defunct so i try here. Please don't; this forum should primarily be used for discussing Python. I appreciate that you have tried another forum for JavaScript, but that's unrelated to whether this is an approriate forum for the question. It isn't. You could try but really it's not good to be using this Python discussion forum for that purpose. -- \ ?I went to a museum where all the artwork was done by children. | `\ They had all the paintings up on refrigerators.? ?Steven Wright | _o__) | Ben Finney From ijbrewster at alaska.edu Wed Mar 13 17:42:54 2019 From: ijbrewster at alaska.edu (Israel Brewster) Date: Wed, 13 Mar 2019 13:42:54 -0800 Subject: uWISGI with Qt for Python Message-ID: <15930F5D-97F6-4845-AF03-A2EE6F5A12DC@alaska.edu> I?m working on a Qt for python app that needs to run a local web server. For the web server portion I?m using flask and uWISGI, and at the moment I have my application launching uWISGI using subprocess before firing off the Qt QApplication instance and entering the Qt event loop. Some sample code to illustrate the process: If __name__ ==?__main__?: CUR_DIRECTORY = os.path.dirname(__file__) UWSGI_CONFIG = os.path.realpath(os.path.join(CUR_DIRECTORY, 'Other Files/TROPOMI.ini')) UWSGI_EXE = os.path.realpath(os.path.join(CUR_DIRECTORY, 'bin/uwsgi')) uwsgi_proc = subprocess.Popen([UWSGI_EXE, UWSGI_CONFIG]) qt_app = QApplication(sys.argv) ?. res = qt_app.exec_() Now this works, but it strikes me as kinda kludgy, as the uWISGI is effectively a separate application needed. More to the point, however, it?s a bit fragile, in that if the main application crashes (really, ANY sort of unclean exit), you get stray uWISGI processes hanging around that prevent proper functioning of the app the next time you try to launch it. Unfortunately as the app is still in early days, this happens occasionally. So I have two questions: 1) Is there a ?better way?? This GitHub repo: https://github.com/unbit/uwsgi-qtloop seems to indicate that it should be possible to run a Qt event loop from within a uWSGI app, thus eliminating the extra ?subprocess? spinoff, but it hasn?t been updated in 5 years and I have been unable to get it to work with my current Qt/Python/OS setup 2) Baring any ?better way?, is there a way to at least ensure that the subprocess is killed in the event of parent death, or alternately to look for and kill any such lingering processes on application startup? P.S. The purpose of running the web server is to be able to load and use Plotly charts in my app (via a QWebEngineView). So a ?better way? may be using a different plotting library that can essentially ?cut out? the middle man. I?ve tried Matplotlib, but I found its performance to be worse than Plotly - given the size of my data sets, performance matters. Also I had some glitches with it when using a lasso selector (plot going black). Still, with some work, it may be an option. --- 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 From preinbold at gmx.net Wed Mar 13 17:45:37 2019 From: preinbold at gmx.net (Pierre Reinbold) Date: Wed, 13 Mar 2019 22:45:37 +0100 Subject: Generator question In-Reply-To: <1a96f848-9fa5-4edc-902b-3a77d03990fd@googlegroups.com> References: <1a96f848-9fa5-4edc-902b-3a77d03990fd@googlegroups.com> Message-ID: <0d67b71e-b3ce-e0a7-fe7b-bc87c052680a@gmx.net> Dear all, I want to implement a function computing the Cartesian product if the elements of a list of lists, but using generator expressions. I know that it is already available in itertools but it is for the sake of understanding how things work. I already have a working recursive version, and I'm quite sure that this iterative version used to work (at least in some Python2.X) : def flat_genexp_cat_prod(lists): solutions = [[]] for a_list in lists: solutions = (part_sol+[el] for part_sol in solutions for el in a_list) return solutions But, with Python3.7.2, all I got is this : >>> list(flat_genexp_cat_prod([[1, 2], [3, 4], [5, 6]])) [[5, 5, 5], [5, 5, 6], [5, 6, 5], [5, 6, 6], [6, 5, 5], [6, 5, 6], [6, 6, 5], [6, 6, 6]] instead of >>> list(flat_genexp_cat_prod([[1, 2], [3, 4], [5, 6]])) [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6]] Using a list comprehension instead of a generator expression solves the problem, but I can't understand why the version above fails. Even stranger, when debugging I tried to use itertools.tee to duplicate the solutions generators and have a look at them : def flat_genexp_cat_prod(lists): solutions = [[]] for a_list in lists: solutions, debug = tee( part_sol+[el] for part_sol in solutions for el in a_list) print("DEBUG", list(debug)) return solutions And, that version seems to work! >>> list(flat_genexp_cat_prod([[1, 2], [3, 4], [5, 6]])) DEBUG [[1], [2]] DEBUG [[1, 3], [1, 4], [2, 3], [2, 4]] DEBUG [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6]] [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6]] Can you help me understand what I'm doing wrong ? Thank you by advance, ?r From ijbrewster at alaska.edu Wed Mar 13 19:41:48 2019 From: ijbrewster at alaska.edu (Israel Brewster) Date: Wed, 13 Mar 2019 15:41:48 -0800 Subject: uWISGI with Qt for Python In-Reply-To: <15930F5D-97F6-4845-AF03-A2EE6F5A12DC@alaska.edu> References: <15930F5D-97F6-4845-AF03-A2EE6F5A12DC@alaska.edu> Message-ID: <73EFDF57-8151-4DC6-BA19-AC241C0AC28A@alaska.edu> Never mind this request. I realized that for what I am doing, the web server was unnecessary. I could just load local HTML files directly into the QWebEngineView with no need of an intermediate server. Thanks anyway, and sorry for the noise! --- 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 > On Mar 13, 2019, at 1:42 PM, Israel Brewster wrote: > > I?m working on a Qt for python app that needs to run a local web server. For the web server portion I?m using flask and uWISGI, and at the moment I have my application launching uWISGI using subprocess before firing off the Qt QApplication instance and entering the Qt event loop. Some sample code to illustrate the process: > > If __name__ ==?__main__?: > CUR_DIRECTORY = os.path.dirname(__file__) > > UWSGI_CONFIG = os.path.realpath(os.path.join(CUR_DIRECTORY, 'Other Files/TROPOMI.ini')) > UWSGI_EXE = os.path.realpath(os.path.join(CUR_DIRECTORY, 'bin/uwsgi')) > uwsgi_proc = subprocess.Popen([UWSGI_EXE, UWSGI_CONFIG]) > > qt_app = QApplication(sys.argv) > ?. > res = qt_app.exec_() > > > Now this works, but it strikes me as kinda kludgy, as the uWISGI is effectively a separate application needed. More to the point, however, it?s a bit fragile, in that if the main application crashes (really, ANY sort of unclean exit), you get stray uWISGI processes hanging around that prevent proper functioning of the app the next time you try to launch it. Unfortunately as the app is still in early days, this happens occasionally. So I have two questions: > > 1) Is there a ?better way?? This GitHub repo: https://github.com/unbit/uwsgi-qtloop seems to indicate that it should be possible to run a Qt event loop from within a uWSGI app, thus eliminating the extra ?subprocess? spinoff, but it hasn?t been updated in 5 years and I have been unable to get it to work with my current Qt/Python/OS setup > > 2) Baring any ?better way?, is there a way to at least ensure that the subprocess is killed in the event of parent death, or alternately to look for and kill any such lingering processes on application startup? > > P.S. The purpose of running the web server is to be able to load and use Plotly charts in my app (via a QWebEngineView). So a ?better way? may be using a different plotting library that can essentially ?cut out? the middle man. I?ve tried Matplotlib, but I found its performance to be worse than Plotly - given the size of my data sets, performance matters. Also I had some glitches with it when using a lasso selector (plot going black). Still, with some work, it may be an option. > > --- > 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 > From ian.g.kelly at gmail.com Wed Mar 13 21:44:18 2019 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Mar 2019 19:44:18 -0600 Subject: Generator question In-Reply-To: <0d67b71e-b3ce-e0a7-fe7b-bc87c052680a@gmx.net> References: <1a96f848-9fa5-4edc-902b-3a77d03990fd@googlegroups.com> <0d67b71e-b3ce-e0a7-fe7b-bc87c052680a@gmx.net> Message-ID: You're basically running into this: https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result To see why, let's try disassembling your function. I'm using Python 3.5 here, but it shouldn't make much of a difference. py> import dis py> dis.dis(flat_genexp_cat_prod) 2 0 BUILD_LIST 0 3 BUILD_LIST 1 6 STORE_FAST 1 (solutions) 3 9 SETUP_LOOP 39 (to 51) 12 LOAD_FAST 0 (lists) 15 GET_ITER >> 16 FOR_ITER 31 (to 50) 19 STORE_DEREF 0 (a_list) 4 22 LOAD_CLOSURE 0 (a_list) 25 BUILD_TUPLE 1 28 LOAD_CONST 1 ( at 0x73f31571ac90, file "", line 4>) 31 LOAD_CONST 2 ('flat_genexp_cat_prod..') 34 MAKE_CLOSURE 0 37 LOAD_FAST 1 (solutions) 40 GET_ITER 41 CALL_FUNCTION 1 (1 positional, 0 keyword pair) 44 STORE_FAST 1 (solutions) 47 JUMP_ABSOLUTE 16 >> 50 POP_BLOCK 5 >> 51 LOAD_FAST 1 (solutions) 54 RETURN_VALUE Now, take a look at the difference between the instruction at address 22 and the one at address 37: 4 22 LOAD_CLOSURE 0 (a_list) 37 LOAD_FAST 1 (solutions) The value of solutions is passed directly to the generator as an argument, which is the reason why building the generator up iteratively like this works at all: although the nested generators are evaluated lazily, each new generator that is constructed contains as its input a reference to the previous generator. By contrast, the value of a_list is a closure. The contents of the closure are just whatever the value of a_list is when the generator gets evaluated, not when the generator was created. Since the entire nested generated structure is evaluated lazily, it doesn't get evaluated until list() is called after the function has returned. The value of the a_list closure at that point is the last value that was assigned to it: the list [5, 6] from the last iteration of the for loop. This same list value then gets used for all three nested generators. So now why do solutions and a_list get treated differently like this? To answer this, look at this paragraph about generator expressions from the language reference: """ Variables used in the generator expression are evaluated lazily when the __next__() method is called for the generator object (in the same fashion as normal generators). However, the iterable expression in the leftmost for clause is immediately evaluated, so that an error produced by it will be emitted at the point where the generator expression is defined, rather than at the point where the first value is retrieved. Subsequent for clauses and any filter condition in the leftmost for clause cannot be evaluated in the enclosing scope as they may depend on the values obtained from the leftmost iterable. For example: (x*y for x in range(10) for y in range(x, x+10)). """ So, it's simply because the iterable expression in the leftmost for clause is treated differently from every other value in the generator expression. On Wed, Mar 13, 2019 at 3:49 PM Pierre Reinbold wrote: > Dear all, > > I want to implement a function computing the Cartesian product if the > elements > of a list of lists, but using generator expressions. I know that it is > already > available in itertools but it is for the sake of understanding how things > work. > > I already have a working recursive version, and I'm quite sure that this > iterative version used to work (at least in some Python2.X) : > > def flat_genexp_cat_prod(lists): > solutions = [[]] > for a_list in lists: > solutions = (part_sol+[el] for part_sol in solutions for el in > a_list) > return solutions > > But, with Python3.7.2, all I got is this : > > >>> list(flat_genexp_cat_prod([[1, 2], [3, 4], [5, 6]])) > [[5, 5, 5], [5, 5, 6], [5, 6, 5], [5, 6, 6], [6, 5, 5], [6, 5, 6], [6, 6, > 5], > [6, 6, 6]] > > instead of > > >>> list(flat_genexp_cat_prod([[1, 2], [3, 4], [5, 6]])) > [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, > 5], > [2, 4, 6]] > > Using a list comprehension instead of a generator expression solves the > problem, > but I can't understand why the version above fails. > > Even stranger, when debugging I tried to use itertools.tee to duplicate the > solutions generators and have a look at them : > > def flat_genexp_cat_prod(lists): > solutions = [[]] > for a_list in lists: > solutions, debug = tee( > part_sol+[el] for part_sol in solutions for el in a_list) > print("DEBUG", list(debug)) > return solutions > > And, that version seems to work! > > >>> list(flat_genexp_cat_prod([[1, 2], [3, 4], [5, 6]])) > DEBUG [[1], [2]] > DEBUG [[1, 3], [1, 4], [2, 3], [2, 4]] > DEBUG [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], > [2, 4, > 5], [2, 4, 6]] > [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, > 5], > [2, 4, 6]] > > Can you help me understand what I'm doing wrong ? > > Thank you by advance, > > > ?r > -- > https://mail.python.org/mailman/listinfo/python-list > From jonas.thornvall at gmail.com Thu Mar 14 00:49:11 2019 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Wed, 13 Mar 2019 21:49:11 -0700 (PDT) Subject: Not a python question, just programming logic trap? In-Reply-To: <2e2d07d8-9d51-4957-b1e4-cae9674975e8@googlegroups.com> References: <1a96f848-9fa5-4edc-902b-3a77d03990fd@googlegroups.com> <2e2d07d8-9d51-4957-b1e4-cae9674975e8@googlegroups.com> Message-ID: <7f38db4b-9ed9-4171-8820-f29edff5a6a8@googlegroups.com> Den onsdag 13 mars 2019 kl. 21:56:56 UTC+1 skrev Rick Johnson: > On Wednesday, March 13, 2019 at 3:23:50 AM UTC-5, jonas.t... at gmail.com wrote: > > Anyone who is good at see logic traps in programming? comp.lang.javascript is defunct so i try here. > > > > Using the metronome. > > > > https://midisequenser.000webhostapp.com > > > > I've tried to understand how following code can lead to that after the keyreleased the front of the keyed scrollbar raise/extend faster while the backend stay correct "in sync". One could think/imagine xFrontStart=scrollBarPos-FRONTOFFSET; somehow executed more then once after release, but how could it, the keyrelease is true only in that part of code and only done once??? > > First of all: this a Python group, so; if you want to ask a question, then write your code in Python syntax and then present it here. And if you don't know Python syntax, well; think of this as a good excuse to learn. :-) > > Secondly: If your issue is related to _logic_, then the bodies of those conditions is nothing but loud, distracting noise. My advice is to (1) simplify the statements in each clause, and (2) replace the entire body of each condition with a call to stdout. > > For instance, this code: > > if(mess.data[0]==NOTE_ON && keyreleased==false){ > > Could be replaced by this Python code: > > # > # First, unpack some values. > # > firstMessage = mess.data[0] > firstMessIsNoteOn = (firstMessage == NOTE_ON) > # > # Now, begin the logic. > # > if firstMessIsNoteOn and (not keyreleased): > print('clause-1') > elif ... > print('clause-2') > # > # You fill in the rest! > # > else: > print('else-clause') > > > Here endeth the lesson. (for now!) > > PS: Boy, this code sure was a "mess" :-) > > PPS: My example code was not checked for syntax errors. Nah i can't see the error is due to the "If clause" branching possibly it should been an elseif at instead of separate if. No there is something going wrong with the variables. From jonas.thornvall at gmail.com Thu Mar 14 00:51:35 2019 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Wed, 13 Mar 2019 21:51:35 -0700 (PDT) Subject: Not a python question, just programming logic trap? In-Reply-To: <2e2d07d8-9d51-4957-b1e4-cae9674975e8@googlegroups.com> References: <1a96f848-9fa5-4edc-902b-3a77d03990fd@googlegroups.com> <2e2d07d8-9d51-4957-b1e4-cae9674975e8@googlegroups.com> Message-ID: <718459da-92b9-48aa-b79d-9d175cf807d4@googlegroups.com> Den onsdag 13 mars 2019 kl. 21:56:56 UTC+1 skrev Rick Johnson: > On Wednesday, March 13, 2019 at 3:23:50 AM UTC-5, jonas.t... at gmail.com wrote: > > Anyone who is good at see logic traps in programming? comp.lang.javascript is defunct so i try here. > > > > Using the metronome. > > > > https://midisequenser.000webhostapp.com > > > > I've tried to understand how following code can lead to that after the keyreleased the front of the keyed scrollbar raise/extend faster while the backend stay correct "in sync". One could think/imagine xFrontStart=scrollBarPos-FRONTOFFSET; somehow executed more then once after release, but how could it, the keyrelease is true only in that part of code and only done once??? > > First of all: this a Python group, so; if you want to ask a question, then write your code in Python syntax and then present it here. And if you don't know Python syntax, well; think of this as a good excuse to learn. :-) > > Secondly: If your issue is related to _logic_, then the bodies of those conditions is nothing but loud, distracting noise. My advice is to (1) simplify the statements in each clause, and (2) replace the entire body of each condition with a call to stdout. > > For instance, this code: > > if(mess.data[0]==NOTE_ON && keyreleased==false){ > > Could be replaced by this Python code: > > # > # First, unpack some values. > # > firstMessage = mess.data[0] > firstMessIsNoteOn = (firstMessage == NOTE_ON) > # > # Now, begin the logic. > # > if firstMessIsNoteOn and (not keyreleased): > print('clause-1') > elif ... > print('clause-2') > # > # You fill in the rest! > # > else: > print('else-clause') > > > Here endeth the lesson. (for now!) > > PS: Boy, this code sure was a "mess" :-) > > PPS: My example code was not checked for syntax errors. Honestly i would write the thing "sequenser" in Python if it was supported for webscripting in browsers, and had a graphic library as javascript canvas. From arj.python at gmail.com Thu Mar 14 01:53:34 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 14 Mar 2019 09:53:34 +0400 Subject: UG Announcement - Python Mauritius User-Group (pymug) Message-ID: As per requirements, i'm announcing the existence of the Python User-Group for Mauritius, an island in the Indian Ocean. Below are some info. Name: Python Mauritius User-Group Website: pymug.com Github: github.com/pymug Mailing list: https://mail.python.org/mailman3/lists/pymug.python.org/ Wiki mention: https://wiki.python.org/moin/LocalUserGroups#Other_Africa under Other Africa First local meeting held: yes Organising members: 4 Motivation: Python promotion and helping with docs translations. Should anybody require any info, please let me know. Yours, -- Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius Garanti sans virus. www.avast.com <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> From tjol at tjol.eu Thu Mar 14 04:23:38 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 14 Mar 2019 09:23:38 +0100 Subject: uWISGI with Qt for Python In-Reply-To: <15930F5D-97F6-4845-AF03-A2EE6F5A12DC@alaska.edu> References: <15930F5D-97F6-4845-AF03-A2EE6F5A12DC@alaska.edu> Message-ID: On 13/03/2019 22:42, Israel Brewster wrote: > 1) Is there a ?better way?? This GitHub repo: https://github.com/unbit/uwsgi-qtloop seems to indicate that it should be possible to run a Qt event loop from within a uWSGI app, thus eliminating the extra ?subprocess? spinoff, but it hasn?t been updated in 5 years and I have been unable to get it to work with my current Qt/Python/OS setup > > 2) Baring any ?better way?, is there a way to at least ensure that the subprocess is killed in the event of parent death, or alternately to look for and kill any such lingering processes on application startup? > > P.S. The purpose of running the web server is to be able to load and use Plotly charts in my app (via a QWebEngineView). So a ?better way? may be using a different plotting library that can essentially ?cut out? the middle man. I?ve tried Matplotlib, but I found its performance to be worse than Plotly - given the size of my data sets, performance matters. Also I had some glitches with it when using a lasso selector (plot going black). Still, with some work, it may be an option. In a similar situation (web component in a Qt app) we simply use werkzeug's built-in web server in a Python/Qt thread. This works very nicely, but the performance probably isn't perfect. Our use case is allowing a small part of our experiments to be controlled from a phone in the local network, so the performance requirements aren't severe at all. As for live plotting in a GUI app, you're right, matplotlib isn't really suitable. But pyQtgraph is: http://www.pyqtgraph.org/ I've had no problems with it at all for streaming live measurement data to screen and interacting with reasonable-sized 2d images. I expect that's your best option. Despite what the description says, it does PyQt5 as well as PyQt4. Best, - Thomas From scopensource at gmail.com Thu Mar 14 05:02:30 2019 From: scopensource at gmail.com (Simon Connah) Date: Thu, 14 Mar 2019 09:02:30 +0000 Subject: asyncio Question Message-ID: Hi, Hopefully this isn't a stupid question. For the record I am using Python 3.7 on Ubuntu Linux. I've decided to use asyncio to write a TCP network server using Streams and asyncio.start_server(). I can handle that part of it without many problems as the documentation is pretty good. I have one problem though that I am not sure how to solve. Each request to the server will be a JSON string and one of the components of the JSON string will be the latitude and longitude. What I want to do is associate a latitude and longitude with the client connection. Every time the latitude and longitude changes then the two values will be updated. There will only ever be one latitude and longitude for each client connection (since a device can only ever be in one place). I'm just not sure what the best method to achieve this would be when using asyncio.start_server(). Any help would be greatly appreciated. From preinbold at gmx.net Thu Mar 14 05:04:04 2019 From: preinbold at gmx.net (Pierre Reinbold) Date: Thu, 14 Mar 2019 10:04:04 +0100 Subject: Generator question In-Reply-To: References: <1a96f848-9fa5-4edc-902b-3a77d03990fd@googlegroups.com> <0d67b71e-b3ce-e0a7-fe7b-bc87c052680a@gmx.net> Message-ID: <67e50e1c-26e8-44b9-29ad-8adeec520997@gmx.net> Wow, thank you Ian for this very detailed answer, and thank you for taking the time for that! Much appreciated! If I get this right, I have to somehow fix the value of a_list during the loop, like when you use the classic default value argument trick with lambdas (damn, I should have thought of that!). So if I "unfold" the generator expression, using default values for both iterables, I get this : def flat_gen_cat_prod(lists): solutions = [[]] for a_list in lists: def new_solutions(l=a_list, s=solutions): for part_sol in s: for el in l: yield part_sol+[el] solutions = new_solutions() return solutions With this I get the right behavior! Thanks again! Doest that mean that there is no possibility to use a generator expression in this case ? (gen. exp. are sooo much more elegant :-)) Thanks again for the answer and helpful comments! ?r Le 14/03/19 ? 02:44, Ian Kelly a ?crit?: > You're basically running into this: > https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result > > To see why, let's try disassembling your function. I'm using Python 3.5 > here, but it shouldn't make much of a difference. > > py> import dis > py> dis.dis(flat_genexp_cat_prod) > 2 0 BUILD_LIST 0 > 3 BUILD_LIST 1 > 6 STORE_FAST 1 (solutions) > > 3 9 SETUP_LOOP 39 (to 51) > 12 LOAD_FAST 0 (lists) > 15 GET_ITER > >> 16 FOR_ITER 31 (to 50) > 19 STORE_DEREF 0 (a_list) > > 4 22 LOAD_CLOSURE 0 (a_list) > 25 BUILD_TUPLE 1 > 28 LOAD_CONST 1 ( at > 0x73f31571ac90, file "", line 4>) > 31 LOAD_CONST 2 > ('flat_genexp_cat_prod..') > 34 MAKE_CLOSURE 0 > 37 LOAD_FAST 1 (solutions) > 40 GET_ITER > 41 CALL_FUNCTION 1 (1 positional, 0 keyword pair) > 44 STORE_FAST 1 (solutions) > 47 JUMP_ABSOLUTE 16 > >> 50 POP_BLOCK > > 5 >> 51 LOAD_FAST 1 (solutions) > 54 RETURN_VALUE > > Now, take a look at the difference between the instruction at address 22 > and the one at address 37: > > 4 22 LOAD_CLOSURE 0 (a_list) > 37 LOAD_FAST 1 (solutions) > > The value of solutions is passed directly to the generator as an argument, > which is the reason why building the generator up iteratively like this > works at all: although the nested generators are evaluated lazily, each new > generator that is constructed contains as its input a reference to the > previous generator. > > By contrast, the value of a_list is a closure. The contents of the closure > are just whatever the value of a_list is when the generator gets evaluated, > not when the generator was created. Since the entire nested generated > structure is evaluated lazily, it doesn't get evaluated until list() is > called after the function has returned. The value of the a_list closure at > that point is the last value that was assigned to it: the list [5, 6] from > the last iteration of the for loop. This same list value then gets used for > all three nested generators. > > So now why do solutions and a_list get treated differently like this? To > answer this, look at this paragraph about generator expressions from the > language reference: > > """ > Variables used in the generator expression are evaluated lazily when the > __next__() method is called for the generator object (in the same fashion > as normal generators). However, the iterable expression in the leftmost for > clause is immediately evaluated, so that an error produced by it will be > emitted at the point where the generator expression is defined, rather than > at the point where the first value is retrieved. Subsequent for clauses and > any filter condition in the leftmost for clause cannot be evaluated in the > enclosing scope as they may depend on the values obtained from the leftmost > iterable. For example: (x*y for x in range(10) for y in range(x, x+10)). > """ > > So, it's simply because the iterable expression in the leftmost for clause > is treated differently from every other value in the generator expression. > > On Wed, Mar 13, 2019 at 3:49 PM Pierre Reinbold wrote: > >> Dear all, >> >> I want to implement a function computing the Cartesian product if the >> elements >> of a list of lists, but using generator expressions. I know that it is >> already >> available in itertools but it is for the sake of understanding how things >> work. >> >> I already have a working recursive version, and I'm quite sure that this >> iterative version used to work (at least in some Python2.X) : >> >> def flat_genexp_cat_prod(lists): >> solutions = [[]] >> for a_list in lists: >> solutions = (part_sol+[el] for part_sol in solutions for el in >> a_list) >> return solutions >> >> But, with Python3.7.2, all I got is this : >> >>>>> list(flat_genexp_cat_prod([[1, 2], [3, 4], [5, 6]])) >> [[5, 5, 5], [5, 5, 6], [5, 6, 5], [5, 6, 6], [6, 5, 5], [6, 5, 6], [6, 6, >> 5], >> [6, 6, 6]] >> >> instead of >> >>>>> list(flat_genexp_cat_prod([[1, 2], [3, 4], [5, 6]])) >> [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, >> 5], >> [2, 4, 6]] >> >> Using a list comprehension instead of a generator expression solves the >> problem, >> but I can't understand why the version above fails. >> >> Even stranger, when debugging I tried to use itertools.tee to duplicate the >> solutions generators and have a look at them : >> >> def flat_genexp_cat_prod(lists): >> solutions = [[]] >> for a_list in lists: >> solutions, debug = tee( >> part_sol+[el] for part_sol in solutions for el in a_list) >> print("DEBUG", list(debug)) >> return solutions >> >> And, that version seems to work! >> >>>>> list(flat_genexp_cat_prod([[1, 2], [3, 4], [5, 6]])) >> DEBUG [[1], [2]] >> DEBUG [[1, 3], [1, 4], [2, 3], [2, 4]] >> DEBUG [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], >> [2, 4, >> 5], [2, 4, 6]] >> [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, >> 5], >> [2, 4, 6]] >> >> Can you help me understand what I'm doing wrong ? >> >> Thank you by advance, >> >> >> ?r >> -- >> https://mail.python.org/mailman/listinfo/python-list >> From __peter__ at web.de Thu Mar 14 05:45:25 2019 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Mar 2019 10:45:25 +0100 Subject: Generator question References: <1a96f848-9fa5-4edc-902b-3a77d03990fd@googlegroups.com> <0d67b71e-b3ce-e0a7-fe7b-bc87c052680a@gmx.net> <67e50e1c-26e8-44b9-29ad-8adeec520997@gmx.net> Message-ID: Pierre Reinbold wrote: > Wow, thank you Ian for this very detailed answer, and thank you for taking > the time for that! Much appreciated! > > If I get this right, I have to somehow fix the value of a_list during the > loop, like when you use the classic default value argument trick with > lambdas (damn, I should have thought of that!). So if I "unfold" the > generator expression, using default values for both iterables, I get this > : > > def flat_gen_cat_prod(lists): > solutions = [[]] > for a_list in lists: > def new_solutions(l=a_list, s=solutions): > for part_sol in s: > for el in l: > yield part_sol+[el] > solutions = new_solutions() > return solutions > > With this I get the right behavior! Thanks again! > > Doest that mean that there is no possibility to use a generator expression > in this case ? (gen. exp. are sooo much more elegant :-)) The obvious approach is to put the genexpr into a function: def prod(lists): solutions = [[]] def new_solutions(a_list): return (part_sol + [el] for part_sol in solutions for el in a_list) for a_list in lists: solutions = new_solutions(a_list) return solutions If you want to avoid the function you can take advantage of the fact that the outermost iterable is bound early: def prod(lists): solutions = [[]] for a_list in lists: solutions = ( part_sol + [el] for solutions, a_list in [(solutions, a_list)] for part_sol in solutions for el in a_list ) return solutions From preinbold at gmx.net Thu Mar 14 08:46:18 2019 From: preinbold at gmx.net (Pierre Reinbold) Date: Thu, 14 Mar 2019 13:46:18 +0100 Subject: Generator question In-Reply-To: References: <1a96f848-9fa5-4edc-902b-3a77d03990fd@googlegroups.com> <0d67b71e-b3ce-e0a7-fe7b-bc87c052680a@gmx.net> <67e50e1c-26e8-44b9-29ad-8adeec520997@gmx.net> Message-ID: Le 14/03/19 ? 10:45, Peter Otten a ?crit?: > Pierre Reinbold wrote: > >> Wow, thank you Ian for this very detailed answer, and thank you for taking >> the time for that! Much appreciated! >> >> If I get this right, I have to somehow fix the value of a_list during the >> loop, like when you use the classic default value argument trick with >> lambdas (damn, I should have thought of that!). So if I "unfold" the >> generator expression, using default values for both iterables, I get this >> : >> >> def flat_gen_cat_prod(lists): >> solutions = [[]] >> for a_list in lists: >> def new_solutions(l=a_list, s=solutions): >> for part_sol in s: >> for el in l: >> yield part_sol+[el] >> solutions = new_solutions() >> return solutions >> >> With this I get the right behavior! Thanks again! >> >> Doest that mean that there is no possibility to use a generator expression >> in this case ? (gen. exp. are sooo much more elegant :-)) > > The obvious approach is to put the genexpr into a function: > > def prod(lists): > solutions = [[]] > def new_solutions(a_list): > return (part_sol + [el] for part_sol in solutions for el in a_list) > > for a_list in lists: > solutions = new_solutions(a_list) > return solutions > > If you want to avoid the function you can take advantage of the fact that > the outermost iterable is bound early: > > def prod(lists): > solutions = [[]] > > for a_list in lists: > solutions = ( > part_sol + [el] > for solutions, a_list in [(solutions, a_list)] > for part_sol in solutions for el in a_list > ) > return solutions > > Thank you Peter, very clever suggestions ! ?r From tdldev at gmail.com Thu Mar 14 10:05:47 2019 From: tdldev at gmail.com (Jack Dangler) Date: Thu, 14 Mar 2019 10:05:47 -0400 Subject: Not Defined error in basic code Message-ID: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> Just getting started with tutorials and such, and don't understand this - class weapon: ??? weaponId ??? manufacturerName ??? def printWeaponInfo(self): ??????? infoString = "ID: %d Mfg: %s Model: %s" % (self.weaponId, self.manufacturerName) ??????? return infoString import class_weapon MyWeapon=weapon() MyWeapon.weaponId = 100 MyWeapon.manufacturerName = "Glock" print(MyWeapon.printWeaponInfo) executing 'python3 weaponTrack.py' results in this bailing on the first element in the class with "not defined". I've been staring at templates of this exact structure for about an hour trying to figure out why this isn't running at all. Is it simply because it isn't all in one file? Thanks for any guidance. Really appreciate the help. Thanks. From cspealma at redhat.com Thu Mar 14 10:11:00 2019 From: cspealma at redhat.com (Calvin Spealman) Date: Thu, 14 Mar 2019 10:11:00 -0400 Subject: Not Defined error in basic code In-Reply-To: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> References: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> Message-ID: Where are you seeing something like this? The two lines under `class weapon:` are not correct because they are variable names that you've never defined. Maybe you intended this to "declare" the attributes for the class? That isn't something you need to do in Python. If you simply remove these lines your example should work. On Thu, Mar 14, 2019 at 10:05 AM Jack Dangler wrote: > Just getting started with tutorials and such, and don't understand this - > > > > class weapon: > weaponId > manufacturerName > > def printWeaponInfo(self): > infoString = "ID: %d Mfg: %s Model: %s" % (self.weaponId, > self.manufacturerName) > return infoString > > > > import class_weapon > > MyWeapon=weapon() > MyWeapon.weaponId = 100 > MyWeapon.manufacturerName = "Glock" > > print(MyWeapon.printWeaponInfo) > > executing 'python3 weaponTrack.py' results in this bailing on the first > element in the class with "not defined". I've been staring at templates > of this exact structure for about an hour trying to figure out why this > isn't running at all. Is it simply because it isn't all in one file? > Thanks for any guidance. Really appreciate the help. > > > Thanks. > > -- > https://mail.python.org/mailman/listinfo/python-list > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER cspealma at redhat.com M: +1.336.210.5107 TRIED. TESTED. TRUSTED. From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Mar 14 10:17:53 2019 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Thu, 14 Mar 2019 09:17:53 -0500 Subject: Not Defined error in basic code In-Reply-To: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> References: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> Message-ID: <4bc72163-8df3-4670-57ba-b735ff6c9848@potatochowder.com> On 3/14/19 9:05 AM, Jack Dangler wrote: > Just getting started with tutorials and such, and don't understand this - > > > > class weapon: > ??? weaponId > ??? manufacturerName The previous two lines attempt to refer to existing names, but neither name exists. > ??? def printWeaponInfo(self): > ??????? infoString = "ID: %d Mfg: %s Model: %s" % (self.weaponId, > self.manufacturerName > ??????? return infoString > > > > import class_weapon > > MyWeapon=weapon() > MyWeapon.weaponId = 100 > MyWeapon.manufacturerName = "Glock" > > print(MyWeapon.printWeaponInfo) > > executing 'python3 weaponTrack.py' results in this bailing on the first > element in the class with "not defined". I've been staring at templates > of this exact structure for about an hour trying to figure out why this > isn't running at all. Is it simply because it isn't all in one file? > Thanks for any guidance. Really appreciate the help. I'm curious about the tutorial you're following. Depending on how faithfully you're following along, it seems to violate some Python conventions, such as CamelCasing class names and snake_casing (or lowercasing) other names. Also, when you encounter an error, please copy and paste the traceback instead of saying "this bailed" so that we have something to go on rather that having to study your example from top to bottom to try to figure out what's wrong. From jsf80238 at gmail.com Thu Mar 14 10:21:08 2019 From: jsf80238 at gmail.com (Jason Friedman) Date: Thu, 14 Mar 2019 08:21:08 -0600 Subject: Not Defined error in basic code In-Reply-To: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> References: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> Message-ID: On Thu, Mar 14, 2019 at 8:07 AM Jack Dangler wrote: > > > class weapon: > weaponId > manufacturerName > > def printWeaponInfo(self): > infoString = "ID: %d Mfg: %s Model: %s" % (self.weaponId, > self.manufacturerName) > return infoString > > > > import class_weapon > > MyWeapon=weapon() > MyWeapon.weaponId = 100 > MyWeapon.manufacturerName = "Glock" > > print(MyWeapon.printWeaponInfo) > > executing 'python3 weaponTrack.py' results in this bailing on the first > element in the class with "not defined". Try running your module file by itself, that will give you a clue: $ python3 class_weapon.py Traceback (most recent call last): File "class_weapon.py", line 1, in class weapon: File "class_weapon.py", line 2, in weapon weaponId NameError: name 'weaponId' is not defined You have another error in the file which will be revealed when you get it to compile. Also, your printWeapon method could renamed to __repr__ or __str__ (see https://docs.python.org/3/reference/datamodel.html#object.__repr__) Also most Python programmers would spell MyWeapon as my_weapon (see https://www.python.org/dev/peps/pep-0008/). From tdldev at gmail.com Thu Mar 14 10:32:47 2019 From: tdldev at gmail.com (Jack Dangler) Date: Thu, 14 Mar 2019 10:32:47 -0400 Subject: Not Defined error in basic code In-Reply-To: References: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> Message-ID: <02a308c3-c141-5b7f-5716-888c32ff726f@gmail.com> On 3/14/19 10:11 AM, Calvin Spealman wrote: > Where are you seeing something like this? The two lines under `class > weapon:` are not correct because they are variable names that you've > never defined. > > Maybe you intended this to "declare" the attributes for the class? > That isn't something you need to do in Python. If you simply remove > these lines your example should work. > > On Thu, Mar 14, 2019 at 10:05 AM Jack Dangler > wrote: > > Just getting started with tutorials and such, and don't understand > this - > > > > class weapon: > ???? weaponId > ???? manufacturerName > > ???? def printWeaponInfo(self): > ???????? infoString = "ID: %d Mfg: %s Model: %s" % (self.weaponId, > self.manufacturerName) > ???????? return infoString > > > > import class_weapon > > MyWeapon=weapon() > MyWeapon.weaponId = 100 > MyWeapon.manufacturerName = "Glock" > > print(MyWeapon.printWeaponInfo) > > executing 'python3 weaponTrack.py' results in this bailing on the > first > element in the class with "not defined". I've been staring at > templates > of this exact structure for about an hour trying to figure out why > this > isn't running at all. Is it simply because it isn't all in one file? > Thanks for any guidance. Really appreciate the help. > > > Thanks. > > -- > https://mail.python.org/mailman/listinfo/python-list > > > > -- > > CALVIN SPEALMAN > > SENIOR QUALITY ENGINEER > > cspealma at redhat.com M: +1.336.210.5107 > > > > TRIED. TESTED. TRUSTED. Calvin Thank you for the reply. I tried defining them in the form of 'int weaponId' but that didn't help. I finally put it in this form 'weaponId=0" and it liked that. So, i updated the class file to be as follows - class weapon: ???? weaponId=0 ???? manufacturerName="" ???? def printWeaponInfo(self): ???????? infoString = "ID: %d Mfg: %s " % (self.weaponId, self.manufacturerName) ???????? return infoString The second file now looks like this - import class_weapon MyWeapon=class_weapon.weapon MyWeapon.weaponId = 100 MyWeapon.manufacturerName = "Glock" print(MyWeapon.printWeaponInfo) so now, when I run 'python3 weaponTrack.py', I get , but am expecting ID: 100 Mfg: Glock ... From cspealma at redhat.com Thu Mar 14 10:39:50 2019 From: cspealma at redhat.com (Calvin Spealman) Date: Thu, 14 Mar 2019 10:39:50 -0400 Subject: Not Defined error in basic code In-Reply-To: <02a308c3-c141-5b7f-5716-888c32ff726f@gmail.com> References: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> <02a308c3-c141-5b7f-5716-888c32ff726f@gmail.com> Message-ID: A few notes, Jack: On Thu, Mar 14, 2019 at 10:32 AM Jack Dangler wrote: > > On 3/14/19 10:11 AM, Calvin Spealman wrote: > > Where are you seeing something like this? The two lines under `class > weapon:` are not correct because they are variable names that you've never > defined. > > Maybe you intended this to "declare" the attributes for the class? That > isn't something you need to do in Python. If you simply remove these lines > your example should work. > > On Thu, Mar 14, 2019 at 10:05 AM Jack Dangler wrote: > >> Just getting started with tutorials and such, and don't understand this - >> >> >> >> class weapon: >> weaponId >> manufacturerName >> >> def printWeaponInfo(self): >> infoString = "ID: %d Mfg: %s Model: %s" % (self.weaponId, >> self.manufacturerName) >> return infoString >> >> >> >> import class_weapon >> >> MyWeapon=weapon() >> MyWeapon.weaponId = 100 >> MyWeapon.manufacturerName = "Glock" >> >> print(MyWeapon.printWeaponInfo) >> >> executing 'python3 weaponTrack.py' results in this bailing on the first >> element in the class with "not defined". I've been staring at templates >> of this exact structure for about an hour trying to figure out why this >> isn't running at all. Is it simply because it isn't all in one file? >> Thanks for any guidance. Really appreciate the help. >> >> >> Thanks. >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > -- > > CALVIN SPEALMAN > > SENIOR QUALITY ENGINEER > > cspealma at redhat.com M: +1.336.210.5107 > > TRIED. TESTED. TRUSTED. > > Calvin > > Thank you for the reply. I tried defining them in the form of 'int > weaponId' but that didn't help. I finally put it in this form 'weaponId=0" > and it liked that. So, i updated the class file to be as follows - > > > > class weapon: > weaponId=0 > manufacturerName="" > Technically this will work, but it won't always work. You're assigning these values directly to the class (or type) and not to individual objects of that type. This will break very badly if you try to do this with any type of value that can be changed (like a list, which you can add things to) because you'll accidentally modify values shared between ALL objects of the same type. Instead, you want to define a __init__ method, which is called when all objects of this type are created, and assign the attributes in there. Like this: def __init__(self): self.weaponId = 0 self.manufacturerName = "" Of course, you could make it easier to create the specific objects you want by passing parameters at the creation of the object: def __init__(self, weaponId, manufacturerName): self.weaponId = weaponId self.manufacturerName = manufacturerName def printWeaponInfo(self): > infoString = "ID: %d Mfg: %s " % (self.weaponId, > self.manufacturerName) > return infoString > > The second file now looks like this - > > > > import class_weapon > MyWeapon=class_weapon.weapon > MyWeapon.weaponId = 100 > MyWeapon.manufacturerName = "Glock" > If you follow my advice above, you won't need to override the values here. But you aren't actually creating anything here, because this line: MyWeapon = class_weapon.weapon Doesn't create anything. It just assigns the class you made to a new name. What you probably meant to do, and can do with the __init__ I suggest above, is create an instance of your weapon class like this: MyWeapon = class_weapon.weapon(100, "Glock") > > print(MyWeapon.printWeaponInfo) > Similarly, you probably meant to call this method but without parenthesis on the method you just printed the object representing the method itself, rather than calling it and printing the value it returns. print(MyWeapon.printWeaponInfo()) > so now, when I run 'python3 weaponTrack.py', I get weapon.printWeaponInfo at 0x7f2bd3ae7510>, but am expecting > > ID: 100 Mfg: Glock ... > I hope this helps. -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER cspealma at redhat.com M: +1.336.210.5107 TRIED. TESTED. TRUSTED. From tdldev at gmail.com Thu Mar 14 12:43:40 2019 From: tdldev at gmail.com (Jack Dangler) Date: Thu, 14 Mar 2019 12:43:40 -0400 Subject: Not Defined error in basic code In-Reply-To: References: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> <02a308c3-c141-5b7f-5716-888c32ff726f@gmail.com> Message-ID: <42395dbc-e52f-41f3-5f23-80885a0f49cf@gmail.com> On 3/14/19 10:39 AM, Calvin Spealman wrote: > A few notes, Jack: > > On Thu, Mar 14, 2019 at 10:32 AM Jack Dangler > wrote: > > > On 3/14/19 10:11 AM, Calvin Spealman wrote: >> Where are you seeing something like this? The two lines under >> `class weapon:` are not correct because they are variable names >> that you've never defined. >> >> Maybe you intended this to "declare" the attributes for the >> class? That isn't something you need to do in Python. If you >> simply remove these lines your example should work. >> >> On Thu, Mar 14, 2019 at 10:05 AM Jack Dangler > > wrote: >> >> Just getting started with tutorials and such, and don't >> understand this - >> >> >> >> class weapon: >> ???? weaponId >> ???? manufacturerName >> >> ???? def printWeaponInfo(self): >> ???????? infoString = "ID: %d Mfg: %s Model: %s" % >> (self.weaponId, >> self.manufacturerName) >> ???????? return infoString >> >> >> >> import class_weapon >> >> MyWeapon=weapon() >> MyWeapon.weaponId = 100 >> MyWeapon.manufacturerName = "Glock" >> >> print(MyWeapon.printWeaponInfo) >> >> executing 'python3 weaponTrack.py' results in this bailing on >> the first >> element in the class with "not defined". I've been staring at >> templates >> of this exact structure for about an hour trying to figure >> out why this >> isn't running at all. Is it simply because it isn't all in >> one file? >> Thanks for any guidance. Really appreciate the help. >> >> >> Thanks. >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> >> >> >> -- >> >> CALVIN SPEALMAN >> >> SENIOR QUALITY ENGINEER >> >> cspealma at redhat.com M: >> +1.336.210.5107 >> >> >> TRIED. TESTED. TRUSTED. > > Calvin > > Thank you for the reply. I tried defining them in the form of 'int > weaponId' but that didn't help. I finally put it in this form > 'weaponId=0" and it liked that. So, i updated the class file to be > as follows - > > > > class weapon: > ???? weaponId=0 > ???? manufacturerName="" > > Technically this will work, but it won't always work. You're assigning > these values directly to the class (or type) and not to individual > objects of that type. > > This will break very badly if you try to do this with any type of > value that can be changed (like a list, which you can add things to) > because you'll accidentally > modify values shared between ALL objects of the same type. Instead, > you want to define a __init__ method, which is called when all objects > of this type are > created, and assign the attributes in there. Like this: > > def __init__(self): > ??? self.weaponId = 0 > ??? self.manufacturerName = "" > > Of course, you could make it easier to create the specific objects you > want by passing parameters at the creation of the object: > > def __init__(self, weaponId, manufacturerName): > ??? self.weaponId = weaponId > ??? self.manufacturerName = manufacturerName > > ???? def printWeaponInfo(self): > ???????? infoString = "ID: %d Mfg: %s " % (self.weaponId, > self.manufacturerName) > ???????? return infoString > > The second file now looks like this - > > > > import class_weapon > MyWeapon=class_weapon.weapon > MyWeapon.weaponId = 100 > MyWeapon.manufacturerName = "Glock" > > If you follow my advice above, you won't need to override the values here. > > But you aren't actually creating anything here, because this line: > > MyWeapon = class_weapon.weapon > Doesn't create anything. It just assigns the class you made to a new > name. What you probably meant to do, and can do with the > __init__ I suggest above, is create an instance of your weapon class > like this: > > MyWeapon = class_weapon.weapon(100, "Glock") > > > print(MyWeapon.printWeaponInfo) > > Similarly, you probably meant to call this method but without > parenthesis on the method you just printed the object representing > the method itself, rather than calling it and printing the value it > returns. > > print(MyWeapon.printWeaponInfo()) > > so now, when I run 'python3 weaponTrack.py', I get weapon.printWeaponInfo at 0x7f2bd3ae7510>, but am expecting > > ID: 100 Mfg: Glock ... > > I hope this helps. > > -- > > CALVIN SPEALMAN > > SENIOR QUALITY ENGINEER > > cspealma at redhat.com M: +1.336.210.5107 > > > > TRIED. TESTED. TRUSTED. Calvin Really great explanation! Giving me a lot to go on. I changed the files as suggested (I think), and now have this - The first file now looks like this - class weapon: ??? weaponId ??? manufacturerName ??? # Creation/Instantiation ??? def __init__(self, weaponId, manufacturerName): ??????? self.weaponId = weaponId ??????? self.manufacturerName = manufacturerName ??? # Print the class data ??? def printWeaponInfo(self): ??????? infoString = "ID: %d Mfg: %s ." % (self.weaponId, self.manufacturerName) ??????? return infoString The second file now looks like this - import class_weapon MyWeapon = class_weapon.weapon(100, "Glock") #MyWeapon.weaponId = 100 #MyWeapon.manufacturerName = "Glock" print(MyWeapon.printWeaponInfo()) Results: python3 ./weaponTest.py Traceback (most recent call last): ? File "./weaponTest.py", line 1, in ??? import class_weapon ? File "/home/jack/Py/weaponTrack/class_weapon.py", line 1, in ??? class weapon: ? File "/home/jack/MyScripts/Py/weaponTrack/class_weapon.py", line 2, in weapon ??? weaponId NameError: name 'weaponId' is not defined From cspealma at redhat.com Thu Mar 14 12:50:41 2019 From: cspealma at redhat.com (Calvin Spealman) Date: Thu, 14 Mar 2019 12:50:41 -0400 Subject: Not Defined error in basic code In-Reply-To: <42395dbc-e52f-41f3-5f23-80885a0f49cf@gmail.com> References: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> <02a308c3-c141-5b7f-5716-888c32ff726f@gmail.com> <42395dbc-e52f-41f3-5f23-80885a0f49cf@gmail.com> Message-ID: You still need to get of the two lines at the start of your class, they are unnecessary and reference variables you never defined: class weapon: weaponId # Get rid of this line! manufacturerName # And this one, too! On Thu, Mar 14, 2019 at 12:43 PM Jack Dangler wrote: > > On 3/14/19 10:39 AM, Calvin Spealman wrote: > > A few notes, Jack: > > On Thu, Mar 14, 2019 at 10:32 AM Jack Dangler wrote: > >> >> On 3/14/19 10:11 AM, Calvin Spealman wrote: >> >> Where are you seeing something like this? The two lines under `class >> weapon:` are not correct because they are variable names that you've never >> defined. >> >> Maybe you intended this to "declare" the attributes for the class? That >> isn't something you need to do in Python. If you simply remove these lines >> your example should work. >> >> On Thu, Mar 14, 2019 at 10:05 AM Jack Dangler wrote: >> >>> Just getting started with tutorials and such, and don't understand this - >>> >>> >>> >>> class weapon: >>> weaponId >>> manufacturerName >>> >>> def printWeaponInfo(self): >>> infoString = "ID: %d Mfg: %s Model: %s" % (self.weaponId, >>> self.manufacturerName) >>> return infoString >>> >>> >>> >>> import class_weapon >>> >>> MyWeapon=weapon() >>> MyWeapon.weaponId = 100 >>> MyWeapon.manufacturerName = "Glock" >>> >>> print(MyWeapon.printWeaponInfo) >>> >>> executing 'python3 weaponTrack.py' results in this bailing on the first >>> element in the class with "not defined". I've been staring at templates >>> of this exact structure for about an hour trying to figure out why this >>> isn't running at all. Is it simply because it isn't all in one file? >>> Thanks for any guidance. Really appreciate the help. >>> >>> >>> Thanks. >>> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> >> >> -- >> >> CALVIN SPEALMAN >> >> SENIOR QUALITY ENGINEER >> >> cspealma at redhat.com M: +1.336.210.5107 >> >> TRIED. TESTED. TRUSTED. >> >> Calvin >> >> Thank you for the reply. I tried defining them in the form of 'int >> weaponId' but that didn't help. I finally put it in this form 'weaponId=0" >> and it liked that. So, i updated the class file to be as follows - >> >> >> >> class weapon: >> weaponId=0 >> manufacturerName="" >> > Technically this will work, but it won't always work. You're assigning > these values directly to the class (or type) and not to individual objects > of that type. > > This will break very badly if you try to do this with any type of value > that can be changed (like a list, which you can add things to) because > you'll accidentally > modify values shared between ALL objects of the same type. Instead, you > want to define a __init__ method, which is called when all objects of this > type are > created, and assign the attributes in there. Like this: > > def __init__(self): > self.weaponId = 0 > self.manufacturerName = "" > > Of course, you could make it easier to create the specific objects you > want by passing parameters at the creation of the object: > > def __init__(self, weaponId, manufacturerName): > self.weaponId = weaponId > self.manufacturerName = manufacturerName > > def printWeaponInfo(self): >> infoString = "ID: %d Mfg: %s " % (self.weaponId, >> self.manufacturerName) >> return infoString >> >> The second file now looks like this - >> >> >> >> import class_weapon >> MyWeapon=class_weapon.weapon >> MyWeapon.weaponId = 100 >> MyWeapon.manufacturerName = "Glock" >> > If you follow my advice above, you won't need to override the values here. > > But you aren't actually creating anything here, because this line: > > MyWeapon = class_weapon.weapon > > Doesn't create anything. It just assigns the class you made to a new name. > What you probably meant to do, and can do with the > __init__ I suggest above, is create an instance of your weapon class like > this: > > MyWeapon = class_weapon.weapon(100, "Glock") > >> >> print(MyWeapon.printWeaponInfo) >> > Similarly, you probably meant to call this method but without parenthesis > on the method you just printed the object representing > the method itself, rather than calling it and printing the value it > returns. > > print(MyWeapon.printWeaponInfo()) > >> so now, when I run 'python3 weaponTrack.py', I get > weapon.printWeaponInfo at 0x7f2bd3ae7510>, but am expecting >> >> ID: 100 Mfg: Glock ... >> > I hope this helps. > > -- > > CALVIN SPEALMAN > > SENIOR QUALITY ENGINEER > > cspealma at redhat.com M: +1.336.210.5107 > > TRIED. TESTED. TRUSTED. > > > Calvin > > Really great explanation! Giving me a lot to go on. I changed the files as > suggested (I think), and now have this - > > The first file now looks like this - > > > > class weapon: > weaponId > manufacturerName > > # Creation/Instantiation > def __init__(self, weaponId, manufacturerName): > self.weaponId = weaponId > self.manufacturerName = manufacturerName > > # Print the class data > def printWeaponInfo(self): > infoString = "ID: %d Mfg: %s ." % (self.weaponId, > self.manufacturerName) > return infoString > > The second file now looks like this - > > > import class_weapon > > MyWeapon = class_weapon.weapon(100, "Glock") > #MyWeapon.weaponId = 100 > #MyWeapon.manufacturerName = "Glock" > > print(MyWeapon.printWeaponInfo()) > > Results: > > python3 ./weaponTest.py > Traceback (most recent call last): > File "./weaponTest.py", line 1, in > import class_weapon > File "/home/jack/Py/weaponTrack/class_weapon.py", line 1, in > class weapon: > File "/home/jack/MyScripts/Py/weaponTrack/class_weapon.py", line 2, in > weapon > weaponId > NameError: name 'weaponId' is not defined > > > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER cspealma at redhat.com M: +1.336.210.5107 TRIED. TESTED. TRUSTED. From tdldev at gmail.com Thu Mar 14 13:23:14 2019 From: tdldev at gmail.com (Jack Dangler) Date: Thu, 14 Mar 2019 13:23:14 -0400 Subject: Not Defined error in basic code In-Reply-To: References: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> <02a308c3-c141-5b7f-5716-888c32ff726f@gmail.com> <42395dbc-e52f-41f3-5f23-80885a0f49cf@gmail.com> Message-ID: On 3/14/19 12:50 PM, Calvin Spealman wrote: > You still need to get of the two lines at the start of your class, > they are unnecessary and reference variables you never defined: > > class weapon: > ??? weaponId? # Get rid of this line! > ??? manufacturerName? # And this one, too! > > On Thu, Mar 14, 2019 at 12:43 PM Jack Dangler > wrote: > > > On 3/14/19 10:39 AM, Calvin Spealman wrote: >> A few notes, Jack: >> >> On Thu, Mar 14, 2019 at 10:32 AM Jack Dangler > > wrote: >> >> >> On 3/14/19 10:11 AM, Calvin Spealman wrote: >>> Where are you seeing something like this? The two lines >>> under `class weapon:` are not correct because they are >>> variable names that you've never defined. >>> >>> Maybe you intended this to "declare" the attributes for the >>> class? That isn't something you need to do in Python. If you >>> simply remove these lines your example should work. >>> >>> On Thu, Mar 14, 2019 at 10:05 AM Jack Dangler >>> > wrote: >>> >>> Just getting started with tutorials and such, and don't >>> understand this - >>> >>> >>> >>> class weapon: >>> ???? weaponId >>> ???? manufacturerName >>> >>> ???? def printWeaponInfo(self): >>> ???????? infoString = "ID: %d Mfg: %s Model: %s" % >>> (self.weaponId, >>> self.manufacturerName) >>> ???????? return infoString >>> >>> >>> >>> import class_weapon >>> >>> MyWeapon=weapon() >>> MyWeapon.weaponId = 100 >>> MyWeapon.manufacturerName = "Glock" >>> >>> print(MyWeapon.printWeaponInfo) >>> >>> executing 'python3 weaponTrack.py' results in this >>> bailing on the first >>> element in the class with "not defined". I've been >>> staring at templates >>> of this exact structure for about an hour trying to >>> figure out why this >>> isn't running at all. Is it simply because it isn't all >>> in one file? >>> Thanks for any guidance. Really appreciate the help. >>> >>> >>> Thanks. >>> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >>> >>> >>> -- >>> >>> CALVIN SPEALMAN >>> >>> SENIOR QUALITY ENGINEER >>> >>> cspealma at redhat.com M: >>> +1.336.210.5107 >>> >>> >>> TRIED. TESTED. TRUSTED. >> >> Calvin >> >> Thank you for the reply. I tried defining them in the form of >> 'int weaponId' but that didn't help. I finally put it in this >> form 'weaponId=0" and it liked that. So, i updated the class >> file to be as follows - >> >> >> >> class weapon: >> ???? weaponId=0 >> ???? manufacturerName="" >> >> Technically this will work, but it won't always work. You're >> assigning these values directly to the class (or type) and not to >> individual objects of that type. >> >> This will break very badly if you try to do this with any type of >> value that can be changed (like a list, which you can add things >> to) because you'll accidentally >> modify values shared between ALL objects of the same type. >> Instead, you want to define a __init__ method, which is called >> when all objects of this type are >> created, and assign the attributes in there. Like this: >> >> def __init__(self): >> ??? self.weaponId = 0 >> self.manufacturerName = "" >> >> Of course, you could make it easier to create the specific >> objects you want by passing parameters at the creation of the object: >> >> def __init__(self, weaponId, manufacturerName): >> ??? self.weaponId = weaponId >> self.manufacturerName = manufacturerName >> >> ???? def printWeaponInfo(self): >> ???????? infoString = "ID: %d Mfg: %s " % (self.weaponId, >> self.manufacturerName) >> ???????? return infoString >> >> The second file now looks like this - >> >> >> >> import class_weapon >> MyWeapon=class_weapon.weapon >> MyWeapon.weaponId = 100 >> MyWeapon.manufacturerName = "Glock" >> >> If you follow my advice above, you won't need to override the >> values here. >> >> But you aren't actually creating anything here, because this line: >> >> MyWeapon = class_weapon.weapon >> Doesn't create anything. It just assigns the class you made to a >> new name. What you probably meant to do, and can do with the >> __init__ I suggest above, is create an instance of your weapon >> class like this: >> >> MyWeapon = class_weapon.weapon(100, "Glock") >> >> >> print(MyWeapon.printWeaponInfo) >> >> Similarly, you probably meant to call this method but without >> parenthesis on the method you just printed the object representing >> the method itself, rather than calling it and printing the value >> it returns. >> >> print(MyWeapon.printWeaponInfo()) >> >> so now, when I run 'python3 weaponTrack.py', I get > weapon.printWeaponInfo at 0x7f2bd3ae7510>, but am expecting >> >> ID: 100 Mfg: Glock ... >> >> I hope this helps. >> >> -- >> >> CALVIN SPEALMAN >> >> SENIOR QUALITY ENGINEER >> >> cspealma at redhat.com M: >> +1.336.210.5107 >> >> >> TRIED. TESTED. TRUSTED. > > > Calvin > > Really great explanation! Giving me a lot to go on. I changed the > files as suggested (I think), and now have this - > > The first file now looks like this - > > > > class weapon: > ??? weaponId > ??? manufacturerName > > ??? # Creation/Instantiation > ??? def __init__(self, weaponId, manufacturerName): > ??????? self.weaponId = weaponId > ??????? self.manufacturerName = manufacturerName > > ??? # Print the class data > ??? def printWeaponInfo(self): > ??????? infoString = "ID: %d Mfg: %s ." % (self.weaponId, > self.manufacturerName) > ??????? return infoString > > The second file now looks like this - > > > > import class_weapon > > MyWeapon = class_weapon.weapon(100, "Glock") > #MyWeapon.weaponId = 100 > #MyWeapon.manufacturerName = "Glock" > > print(MyWeapon.printWeaponInfo()) > > Results: > > python3 ./weaponTest.py > Traceback (most recent call last): > ? File "./weaponTest.py", line 1, in > ??? import class_weapon > ? File "/home/jack/Py/weaponTrack/class_weapon.py", line 1, in > > ??? class weapon: > ? File "/home/jack/MyScripts/Py/weaponTrack/class_weapon.py", line > 2, in weapon > ??? weaponId > NameError: name 'weaponId' is not defined > > > > > -- > > CALVIN SPEALMAN > > SENIOR QUALITY ENGINEER > > cspealma at redhat.com M: +1.336.210.5107 > > > > TRIED. TESTED. TRUSTED. Calvin Thank you very much for your patience! so the elements in the class are both declared and defined using the def __init__(self... construct. A little foreign to me, but I get it! And it does lend itself to being a more portable framework for working with classes. Thank you once again. Now I can keep reading and understand a whole lot more ! Thanks, again! From jonas.thornvall at gmail.com Thu Mar 14 14:01:53 2019 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Thu, 14 Mar 2019 11:01:53 -0700 (PDT) Subject: Not a python question, just programming logic trap? In-Reply-To: <0a4cfdc5-e420-4788-9ffe-331d62db3bdc@googlegroups.com> References: <1a96f848-9fa5-4edc-902b-3a77d03990fd@googlegroups.com> <2e2d07d8-9d51-4957-b1e4-cae9674975e8@googlegroups.com> <7f38db4b-9ed9-4171-8820-f29edff5a6a8@googlegroups.com> <0a4cfdc5-e420-4788-9ffe-331d62db3bdc@googlegroups.com> Message-ID: <8b8d7709-7e02-4e9f-88f3-1bea46935539@googlegroups.com> Den torsdag 14 mars 2019 kl. 06:09:02 UTC+1 skrev Rick Johnson: > jonas.t... at gmail.com wrote: > > Nah i can't see the error is due to the "If clause" branching possibly it should been an elseif at instead of separate if. No there is something going wrong with the variables. > > Well, then you'd be wise to unpack those variables and inspect them. I've done that there is nothing wrong with them the error comes when writing out to the canvas, and i rounded them so it is integer pixels. To be honest i think there maybe something with the canvas that goes wrong. A block of fixed length can't expand. I run console.logg() barLength=xFrontStart-xBackEnd and it is constant at every call within if clause. It is just that when canvas write out the values apparently the draw rectangle function somehow hold other values. Well i restart the whole render programming, doing it right from start this time reading values from the record buffer and see if the animation problem magically dissapear. It could be something undefined affect the the variables. From PythonList at danceswithmice.info Thu Mar 14 14:19:53 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Fri, 15 Mar 2019 07:19:53 +1300 Subject: UG Announcement - Python Mauritius User-Group (pymug) In-Reply-To: References: Message-ID: <18e7e5fd-44b5-fde2-65e6-6acb27ded840@DancesWithMice.info> On 14/03/19 6:53 PM, Abdur-Rahmaan Janhangeer wrote: > As per requirements, i'm announcing the existence of the Python User-Group > for Mauritius, an island in the Indian Ocean. Below are some info. Congratulations! -- Regards =dn From PythonList at danceswithmice.info Thu Mar 14 14:28:30 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Fri, 15 Mar 2019 07:28:30 +1300 Subject: Not Defined error in basic code In-Reply-To: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> References: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> Message-ID: Jack, On 15/03/19 3:05 AM, Jack Dangler wrote: > Just getting started with tutorials and such, and don't understand this - Did you answer the post asking which tutorial you were following/copying? -- Regards =dn From tdldev at gmail.com Thu Mar 14 15:15:11 2019 From: tdldev at gmail.com (Jack Dangler) Date: Thu, 14 Mar 2019 15:15:11 -0400 Subject: Not Defined error in basic code In-Reply-To: References: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> Message-ID: <3a056971-d88b-1e51-fabb-8c01f6de16a4@gmail.com> On 3/14/19 2:28 PM, DL Neil wrote: > Jack, > > > On 15/03/19 3:05 AM, Jack Dangler wrote: >> Just getting started with tutorials and such, and don't understand >> this - > > > Did you answer the post asking which tutorial you were following/copying? > Sorry - it is this - https://www.learnpython.org/en/ .. The section is on classes and objects - https://www.learnpython.org/en/Classes_and_Objects From PythonList at danceswithmice.info Thu Mar 14 15:49:58 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Fri, 15 Mar 2019 08:49:58 +1300 Subject: Not Defined error in basic code In-Reply-To: <3a056971-d88b-1e51-fabb-8c01f6de16a4@gmail.com> References: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> <3a056971-d88b-1e51-fabb-8c01f6de16a4@gmail.com> Message-ID: >>> Just getting started with tutorials and such, and don't understand >>> this - >> Did you answer the post asking which tutorial you were following/copying? > Sorry - it is this - > https://www.learnpython.org/en/ .. > The section is on classes and objects - > https://www.learnpython.org/en/Classes_and_Objects Wanted to check: Someone publishing the 'first code' in this thread as training material, would have been 'unhelpful'. Those guys have a good reputation - if the code camp approach suits the learner, rapid progress can be made. The examples they provide illustrate attributes being 'defined' with a value. (unlike the first code 'here' which only listed attributes) This feature of Python's dynamic nature often confuses folk who come from other, more rigidly defined, languages - there is no need to declare "id" as an integer per-se, passing it an integer constant as its value performs two tasks for the price of one! Advice (if I may): don't be too literal in attempting to write Python the way you currently write xyz-language code. You may find it helpful to combine those tutorials with similar information from additional sources, eg the Python docs site's tutorial, other on-line books, 'dead-tree' sources, other on-line training, etc. Whilst it seems like more work (it's certainly more reading/scanning), two non-identical statements of 'the same thing', will express things differently. Often something from one source that is initially puzzling, when compared with another presentation of the 'same', helps learners' minds go 'click' or to enjoy that 'ahah moment'. All the best... -- Regards =dn From tdldev at gmail.com Thu Mar 14 16:49:05 2019 From: tdldev at gmail.com (Jack Dangler) Date: Thu, 14 Mar 2019 16:49:05 -0400 Subject: Not Defined error in basic code In-Reply-To: References: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> <3a056971-d88b-1e51-fabb-8c01f6de16a4@gmail.com> Message-ID: On 3/14/19 3:49 PM, DL Neil wrote: >>>> Just getting started with tutorials and such, and don't understand >>>> this - >>> Did you answer the post asking which tutorial you were >>> following/copying? >> Sorry - it is this - >> https://www.learnpython.org/en/ .. >> The section is on classes and objects - >> https://www.learnpython.org/en/Classes_and_Objects > > > Wanted to check: Someone publishing the 'first code' in this thread as > training material, would have been 'unhelpful'. > > Those guys have a good reputation - if the code camp approach suits > the learner, rapid progress can be made. > > The examples they provide illustrate attributes being 'defined' with a > value. (unlike the first code 'here' which only listed attributes) > > This feature of Python's dynamic nature often confuses folk who come > from other, more rigidly defined, languages - there is no need to > declare "id" as an integer per-se, passing it an integer constant as > its value performs two tasks for the price of one! > > Advice (if I may): don't be too literal in attempting to write Python > the way you currently write xyz-language code. > > You may find it helpful to combine those tutorials with similar > information from additional sources, eg the Python docs site's > tutorial, other on-line books, 'dead-tree' sources, other on-line > training, etc. Whilst it seems like more work (it's certainly more > reading/scanning), two non-identical statements of 'the same thing', > will express things differently. Often something from one source that > is initially puzzling, when compared with another presentation of the > 'same', helps learners' minds go 'click' or to enjoy that 'ahah moment'. > > All the best... Thank you sir. I think you may be on to something there. I've done mainframe, machine, 3GL, and 4GL languages, but the last couple I've taken on have given me headaches. I guess I'll have to just read a bunch first and then try and write something simpler than what I'm attempting to take on... Thanks for your help and understanding. From PythonList at danceswithmice.info Thu Mar 14 17:35:13 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Fri, 15 Mar 2019 10:35:13 +1300 Subject: Not Defined error in basic code In-Reply-To: References: <3ab8460c-4f48-2f83-7f0a-5aa6bb78478c@gmail.com> <3a056971-d88b-1e51-fabb-8c01f6de16a4@gmail.com> Message-ID: <7d05eb1b-b095-1049-3ae9-03c0e5b34127@DancesWithMice.info> > Thank you sir. I think you may be on to something there. I've done > mainframe, machine, 3GL, and 4GL languages, but the last couple I've > taken on have given me headaches. I guess I'll have to just read a bunch > first and then try and write something simpler than what I'm attempting > to take on... Thanks for your help and understanding. Apologies for any misunderstanding. Don't 'stop'! Keep reading one 'chunk' of learning at a time, and then proving it has lodged 'between the ears' by experimenting. However, if it doesn't make sense/come together for you, 'read around'. The frequent practice is vital to effective and efficient learning (in my professional opinion). In fact, as you have probably noted throughout your career, one of the best things a professional can do, is to keep reading, even re-reading, about the chosen topic. PS us 'silver surfers' have to stick together... -- Regards =dn From pierre.reinbold at uclouvain.be Thu Mar 14 04:28:38 2019 From: pierre.reinbold at uclouvain.be (Pierre Reinbold) Date: Thu, 14 Mar 2019 09:28:38 +0100 Subject: Generator question In-Reply-To: References: <1a96f848-9fa5-4edc-902b-3a77d03990fd@googlegroups.com> <0d67b71e-b3ce-e0a7-fe7b-bc87c052680a@gmx.net> Message-ID: <9d5103df-36b2-b93b-802e-f4624d8d2a30@uclouvain.be> Wow, thank you Ian for this very detailed answer, and thank you for taking the time for that! Much appreciated! If I get this right, I have to somehow fix the value of a_list during the loop, like when you use the classic default value argument trick with lambdas (damn, I should have thought of that!). So if I "unfold" the generator expression, using default values for both iterables, I get this : def flat_gen_cat_prod(lists): solutions = [[]] for a_list in lists: def new_solutions(l=a_list, s=solutions): for part_sol in s: for el in l: yield part_sol+[el] solutions = new_solutions() return solutions With this I get the right behavior! Thanks again! Doest that mean that there is no possibility to use a generator expression in this case ? (gen. exp. are sooo much more elegant :-)) Thanks again for the answer and helpful comments! ?r Le 14/03/19 ? 02:44, Ian Kelly a ?crit?: > You're basically running into this: > https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result > > To see why, let's try disassembling your function. I'm using Python 3.5 > here, but it shouldn't make much of a difference. > > py> import dis > py> dis.dis(flat_genexp_cat_prod) > 2 0 BUILD_LIST 0 > 3 BUILD_LIST 1 > 6 STORE_FAST 1 (solutions) > > 3 9 SETUP_LOOP 39 (to 51) > 12 LOAD_FAST 0 (lists) > 15 GET_ITER > >> 16 FOR_ITER 31 (to 50) > 19 STORE_DEREF 0 (a_list) > > 4 22 LOAD_CLOSURE 0 (a_list) > 25 BUILD_TUPLE 1 > 28 LOAD_CONST 1 ( at > 0x73f31571ac90, file "", line 4>) > 31 LOAD_CONST 2 > ('flat_genexp_cat_prod..') > 34 MAKE_CLOSURE 0 > 37 LOAD_FAST 1 (solutions) > 40 GET_ITER > 41 CALL_FUNCTION 1 (1 positional, 0 keyword pair) > 44 STORE_FAST 1 (solutions) > 47 JUMP_ABSOLUTE 16 > >> 50 POP_BLOCK > > 5 >> 51 LOAD_FAST 1 (solutions) > 54 RETURN_VALUE > > Now, take a look at the difference between the instruction at address 22 > and the one at address 37: > > 4 22 LOAD_CLOSURE 0 (a_list) > 37 LOAD_FAST 1 (solutions) > > The value of solutions is passed directly to the generator as an argument, > which is the reason why building the generator up iteratively like this > works at all: although the nested generators are evaluated lazily, each new > generator that is constructed contains as its input a reference to the > previous generator. > > By contrast, the value of a_list is a closure. The contents of the closure > are just whatever the value of a_list is when the generator gets evaluated, > not when the generator was created. Since the entire nested generated > structure is evaluated lazily, it doesn't get evaluated until list() is > called after the function has returned. The value of the a_list closure at > that point is the last value that was assigned to it: the list [5, 6] from > the last iteration of the for loop. This same list value then gets used for > all three nested generators. > > So now why do solutions and a_list get treated differently like this? To > answer this, look at this paragraph about generator expressions from the > language reference: > > """ > Variables used in the generator expression are evaluated lazily when the > __next__() method is called for the generator object (in the same fashion > as normal generators). However, the iterable expression in the leftmost for > clause is immediately evaluated, so that an error produced by it will be > emitted at the point where the generator expression is defined, rather than > at the point where the first value is retrieved. Subsequent for clauses and > any filter condition in the leftmost for clause cannot be evaluated in the > enclosing scope as they may depend on the values obtained from the leftmost > iterable. For example: (x*y for x in range(10) for y in range(x, x+10)). > """ > > So, it's simply because the iterable expression in the leftmost for clause > is treated differently from every other value in the generator expression. > > On Wed, Mar 13, 2019 at 3:49 PM Pierre Reinbold wrote: > >> Dear all, >> >> I want to implement a function computing the Cartesian product if the >> elements >> of a list of lists, but using generator expressions. I know that it is >> already >> available in itertools but it is for the sake of understanding how things >> work. >> >> I already have a working recursive version, and I'm quite sure that this >> iterative version used to work (at least in some Python2.X) : >> >> def flat_genexp_cat_prod(lists): >> solutions = [[]] >> for a_list in lists: >> solutions = (part_sol+[el] for part_sol in solutions for el in >> a_list) >> return solutions >> >> But, with Python3.7.2, all I got is this : >> >>>>> list(flat_genexp_cat_prod([[1, 2], [3, 4], [5, 6]])) >> [[5, 5, 5], [5, 5, 6], [5, 6, 5], [5, 6, 6], [6, 5, 5], [6, 5, 6], [6, 6, >> 5], >> [6, 6, 6]] >> >> instead of >> >>>>> list(flat_genexp_cat_prod([[1, 2], [3, 4], [5, 6]])) >> [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, >> 5], >> [2, 4, 6]] >> >> Using a list comprehension instead of a generator expression solves the >> problem, >> but I can't understand why the version above fails. >> >> Even stranger, when debugging I tried to use itertools.tee to duplicate the >> solutions generators and have a look at them : >> >> def flat_genexp_cat_prod(lists): >> solutions = [[]] >> for a_list in lists: >> solutions, debug = tee( >> part_sol+[el] for part_sol in solutions for el in a_list) >> print("DEBUG", list(debug)) >> return solutions >> >> And, that version seems to work! >> >>>>> list(flat_genexp_cat_prod([[1, 2], [3, 4], [5, 6]])) >> DEBUG [[1], [2]] >> DEBUG [[1, 3], [1, 4], [2, 3], [2, 4]] >> DEBUG [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], >> [2, 4, >> 5], [2, 4, 6]] >> [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, >> 5], >> [2, 4, 6]] >> >> Can you help me understand what I'm doing wrong ? >> >> Thank you by advance, >> >> >> ?r >> -- >> https://mail.python.org/mailman/listinfo/python-list >> From vokoyov at gmail.com Thu Mar 14 22:48:12 2019 From: vokoyov at gmail.com (vokoyov at gmail.com) Date: Thu, 14 Mar 2019 19:48:12 -0700 (PDT) Subject: How to modify Adaline Stochastic gradient descent Message-ID: Dear May I know how to modify my own Python programming so that I will get the same picture as refer to the attached file - Adaline Stochastic gradient descent (I am using? the Anaconda Python 3.7) Praye?rfully Tron Orino Yeong tcynotebook at yahoo.com 0916643858??????? from matplotlib.colors import ListedColormap import matplotlib.pyplot as plt import numpy as np from numpy.random import seed import pandas as pd # Stochastic Gradient Descent class SGD(object?): def __init__(self, rate = 0.01, niter = 10, shu?ffle=True, random_state=None): self.rate = rate self?.niter = niter? self.weight_initialized = False ? # If True, Shuffles tr?aining data every epoch self.shuffle = shuffle # Set random state for shuffling and initializing the weights. if random_state: seed(random_state) def fit(self, X, y): """Fit training data X : Training vectors, X.?shape : [#samples, #features] y : Target values, y.shape : [#samples] """ # weights self.initialize_weights(X.shape[1]) # Cost function self.cost = [] for i in range(self.niter): if self.shuffle: X, y = self.shuffle_set(X, y) cost = [] for xi, target in zip(X, y): cost.append(self.update_weights(xi, target)) avg_cost = sum(cost)/len(y) self.cost.append(avg_cost) return self def partial_fit(self, X, y): """Fit training data without reinitializing the weights""" if not self.weight_initialized: self.initialize_weights(X.shape[1]) if y.ravel().shape[0] > 1: for xi, target in zip(X, y): self.update_weights(xi, target) else: self.up return self def shuffle_set(self, X, y): """Shuffle training data""" r = np.random.permutation(len(y)) return X[r], y[r] def initialize_weights(self, m): """Initialize weights to zeros""" self.weight = np.zeros(1 + m) self.weight_initialized = True def update_weights(self, xi, target): """Apply SGD learning rule to update the weights""" output = self.net_input(xi) error = (target - output) self.weight[1:] += self.r?ate * xi.dot(error) self.weight[0] += self.rate * error cost = 0.5 * error**2 return cost def net_input(self, X): """Calculate net input""" return np.dot(X, self.weight[1:]) + self.weight[0] def activation(self, X): """Compute linear activation""" return self.net_input(X) def predict(self, X): """Return class label after unit step""" return np.where(self.activation(X) >= 0.0, 1, -1) def plot_decision_regions(X, y, classifier, resolution=0.02): # setup marker generator and color map markers = ('s', 'x', 'o', '^', 'v') colors = ('red', 'blue', 'lightgreen', 'gray', 'cyan') cmap = ListedColormap(colors[:len(np.unique(y))]) # plot the decision surface x1_min, x1_max = X[:, 0].min() - 1, X[:, 0].max() + 1 x2_min, x2_max = X[:, 1].min() - 1, X[:, 1].max() + 1 xx1, xx2 = np.meshgrid(np.arange(x1_min, x1_max, resolution), np.arange(x2_min, x2_max, resolution)) Z = classifier.predict(np.array([xx1.ravel(), xx2.ravel()]).T) Z = Z.reshape(xx1.shape) plt.contourf(xx1, xx2, Z, alpha=0.4, cmap=cmap) plt.xlim(xx1.min(), xx1.max()) plt.ylim(xx2.min(), xx2.max()) # plot class samples for idx, cl in enumerate(np.unique(y)): plt.scatter(x=X[y == cl, 0], y=X[y == cl, 1], alpha=0.8, c=cmap(idx), marker=markers[idx], label=cl) df = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data', header=None) y = df.iloc[0:100, 4].values y = np.where(y == 'Iris-setosa', -1, 1) X = df.iloc[0:100, [0, 2]].values # standardize X_std = np.copy(X) X_std[:,0] = (X[:,0] - X[:,0].mean()) / X[:,0].std() X_std[:,1] = (X[:,1] - X[:,1].mean()) / X[:,1].std() sgd1 = SGD(niter=100, rate=0.01, random_state=1) sgd2 = SGD(niter=50, rate=0.01, random_state=1) sgd3 = SGD(niter=10, rate=0.01, random_state=1) sgd1.fit(X_std, y) sgd2.fit(X_std, y) sgd3.fit(X_std, y) plt.plot(range(1, len(sgd1.cost) + 1), sgd1.cost, marker='o', linestyle='oo', label='batch=1') plt.plot(range(1, len(sgd2.cost_) + 1), np.array(sgd2.cost_) / len(y_train), marker='o', linestyle='--', label='batch=2') plt.plot(range(1, len(sgd3.cost_) + 1), np.array(sgd3.cost_) / len(y_train), marker='o', linestyle='xx', label='batch=3') plt.xlabel('Epochs') plt.ylabel('Average Cost') plt.show() ? ??? ? ? ? Please refer to the link - https://www.scienceforums.net/topic/118410-how-to-modify-adaline-stochastic-gradient-descent/?tab=comments#comment-1097272 From python at mrabarnett.plus.com Thu Mar 14 23:07:24 2019 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 15 Mar 2019 03:07:24 +0000 Subject: How to modify Adaline Stochastic gradient descent In-Reply-To: References: Message-ID: <225fd638-b427-e6d5-51b5-937e5884cdac@mrabarnett.plus.com> On 2019-03-15 02:48, vokoyov at gmail.com wrote: > Dear > > May I know how to modify my own Python programming so that I will get the > same picture as refer to the attached file - Adaline Stochastic gradient descent > [snip] This newsgroup is text-only, and all other attachments, including pictures, are removed. If you want to refer to a picture, you will need to use some kind of file-sharing site, such as DropBox, and provide a link to it. From ar at zeit.io Fri Mar 15 08:47:13 2019 From: ar at zeit.io (Arup Rakshit) Date: Fri, 15 Mar 2019 18:17:13 +0530 Subject: Question regarding the local function object Message-ID: <63A2BF7F-F633-489B-8A92-95EE4C00C2A2@zeit.io> Hi, I am reading a book where it says that: Just like module-level function definitions, the definition of a local function happens at run time when the def keyword is executed. Interestingly, this means that each call to sort_by_last_letter results in a new definition of the function last_letter. That is, just like any other name bound in a function body, last_letter is bound separately to a new function each time sort_by_last_letter is called. If that above is true, why the below program shows the same object reference for last_letter every time I call function sort_by_last_letter. # file name is sample.py def sort_by_last_letter(strings): def last_letter(s): return s[-1] print(last_letter) return sorted(strings, key=last_letter) python3 -i sample.py >>> sort_by_last_letter(['ghi', 'def', 'abc']) .last_letter at 0x1051e0730> ['abc', 'def', 'ghi'] >>> sort_by_last_letter(['ghi', 'def', 'abc']) .last_letter at 0x1051e0730> ['abc', 'def', 'ghi'] >>> sort_by_last_letter(['ghi', 'def', 'abckl']) .last_letter at 0x1051e0730> ['def', 'ghi', 'abckl'] >>> Thanks, Arup Rakshit ar at zeit.io From cspealma at redhat.com Fri Mar 15 08:54:20 2019 From: cspealma at redhat.com (Calvin Spealman) Date: Fri, 15 Mar 2019 08:54:20 -0400 Subject: Question regarding the local function object In-Reply-To: <63A2BF7F-F633-489B-8A92-95EE4C00C2A2@zeit.io> References: <63A2BF7F-F633-489B-8A92-95EE4C00C2A2@zeit.io> Message-ID: This is actually part of a not entirely uncommon misconception that can arise by comparing objects only by their repr() outputs (the string representation created when you pass them to print). You're comparing the ID or memory address of the objects and determining they must be the same object. In this case, it is a kind of illusion. The function is being garbage collected at the end of each call to sort_by_last_letter() and then, on the next call, that address is reused. It is just common for Python to take the next available location, and that happens to be the same because you're re-running generally the same code, so the same number of objects are created and destroyed each time. You can see this by making a slight change: try keeping references to ALL the created functions and you'll see they all have different IDs so long as none of them get cleaned up. Try this slightly modified version: functions = [] def sort_by_last_letter(strings): def last_letter(s): return s[-1] print(last_letter) functions.append(last_letter) return sorted(strings, key=last_letter) Which produces this output: >>> sort_by_last_letter(['ghi', 'def', 'abc']) .last_letter at 0x7f276dd571e0> ['abc', 'def', 'ghi'] >>> sort_by_last_letter(['ghi', 'def', 'abc']) .last_letter at 0x7f276dd57268> ['abc', 'def', 'ghi'] >>> sort_by_last_letter(['ghi', 'def', 'abc']) .last_letter at 0x7f276dd572f0> ['abc', 'def', 'ghi'] On Fri, Mar 15, 2019 at 8:47 AM Arup Rakshit wrote: > Hi, > > I am reading a book where it says that: > > Just like module-level function definitions, the definition of a local > function happens at run time when the def keyword is executed. > Interestingly, this means that each call to sort_by_last_letter results in > a new definition of the function last_letter. That is, just like any other > name bound in a function body, last_letter is bound separately to a new > function each time sort_by_last_letter is called. > > If that above is true, why the below program shows the same object > reference for last_letter every time I call function sort_by_last_letter. > > # file name is sample.py > > def sort_by_last_letter(strings): > def last_letter(s): > return s[-1] > print(last_letter) > return sorted(strings, key=last_letter) > > python3 -i sample.py > >>> sort_by_last_letter(['ghi', 'def', 'abc']) > .last_letter at 0x1051e0730> > ['abc', 'def', 'ghi'] > >>> sort_by_last_letter(['ghi', 'def', 'abc']) > .last_letter at 0x1051e0730> > ['abc', 'def', 'ghi'] > >>> sort_by_last_letter(['ghi', 'def', 'abckl']) > .last_letter at 0x1051e0730> > ['def', 'ghi', 'abckl'] > >>> > > > Thanks, > > Arup Rakshit > ar at zeit.io > > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER cspealma at redhat.com M: +1.336.210.5107 TRIED. TESTED. TRUSTED. From ar at zeit.io Fri Mar 15 09:06:45 2019 From: ar at zeit.io (Arup Rakshit) Date: Fri, 15 Mar 2019 18:36:45 +0530 Subject: Question regarding the local function object In-Reply-To: References: <63A2BF7F-F633-489B-8A92-95EE4C00C2A2@zeit.io> Message-ID: <52975039-467C-4ABC-B171-2797EEB6317E@zeit.io> Nice explanation. Thank you very much. Thanks, Arup Rakshit ar at zeit.io > On 15-Mar-2019, at 6:24 PM, Calvin Spealman wrote: > > This is actually part of a not entirely uncommon misconception that can arise by comparing objects only by their > repr() outputs (the string representation created when you pass them to print). > > You're comparing the ID or memory address of the objects and determining they must be the same object. In this case, > it is a kind of illusion. The function is being garbage collected at the end of each call to sort_by_last_letter() and then, on > the next call, that address is reused. It is just common for Python to take the next available location, and that happens to > be the same because you're re-running generally the same code, so the same number of objects are created and destroyed > each time. > > You can see this by making a slight change: try keeping references to ALL the created functions and you'll see they all > have different IDs so long as none of them get cleaned up. Try this slightly modified version: > > functions = [] > def sort_by_last_letter(strings): > def last_letter(s): > return s[-1] > print(last_letter) > functions.append(last_letter) > return sorted(strings, key=last_letter) > > Which produces this output: > > >>> sort_by_last_letter(['ghi', 'def', 'abc']) > .last_letter at 0x7f276dd571e0> > ['abc', 'def', 'ghi'] > >>> sort_by_last_letter(['ghi', 'def', 'abc']) > .last_letter at 0x7f276dd57268> > ['abc', 'def', 'ghi'] > >>> sort_by_last_letter(['ghi', 'def', 'abc']) > .last_letter at 0x7f276dd572f0> > ['abc', 'def', 'ghi'] > > On Fri, Mar 15, 2019 at 8:47 AM Arup Rakshit > wrote: > Hi, > > I am reading a book where it says that: > > Just like module-level function definitions, the definition of a local function happens at run time when the def keyword is executed. Interestingly, this means that each call to sort_by_last_letter results in a new definition of the function last_letter. That is, just like any other name bound in a function body, last_letter is bound separately to a new function each time sort_by_last_letter is called. > > If that above is true, why the below program shows the same object reference for last_letter every time I call function sort_by_last_letter. > > # file name is sample.py > > def sort_by_last_letter(strings): > def last_letter(s): > return s[-1] > print(last_letter) > return sorted(strings, key=last_letter) > > python3 -i sample.py > >>> sort_by_last_letter(['ghi', 'def', 'abc']) > .last_letter at 0x1051e0730> > ['abc', 'def', 'ghi'] > >>> sort_by_last_letter(['ghi', 'def', 'abc']) > .last_letter at 0x1051e0730> > ['abc', 'def', 'ghi'] > >>> sort_by_last_letter(['ghi', 'def', 'abckl']) > .last_letter at 0x1051e0730> > ['def', 'ghi', 'abckl'] > >>> > > > Thanks, > > Arup Rakshit > ar at zeit.io > > > > -- > https://mail.python.org/mailman/listinfo/python-list > > > -- > CALVIN SPEALMAN > SENIOR QUALITY ENGINEER > cspealma at redhat.com M: +1.336.210.5107 > TRIED. TESTED. TRUSTED. From tjreedy at udel.edu Fri Mar 15 13:00:50 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 15 Mar 2019 13:00:50 -0400 Subject: Question regarding the local function object In-Reply-To: <63A2BF7F-F633-489B-8A92-95EE4C00C2A2@zeit.io> References: <63A2BF7F-F633-489B-8A92-95EE4C00C2A2@zeit.io> Message-ID: On 3/15/2019 8:47 AM, Arup Rakshit wrote: > Hi, > > I am reading a book where it says that: > > Just like module-level function definitions, the definition of a local function happens at run time when the def keyword is executed. Interestingly, this means that each call to sort_by_last_letter results in a new definition of the function last_letter. That is, just like any other name bound in a function body, last_letter is bound separately to a new function each time sort_by_last_letter is called. > > If that above is true, why the below program shows the same object reference for last_letter every time I call function sort_by_last_letter. > > # file name is sample.py > > def sort_by_last_letter(strings): > def last_letter(s): > return s[-1] > print(last_letter) > return sorted(strings, key=last_letter) > > python3 -i sample.py >>>> sort_by_last_letter(['ghi', 'def', 'abc']) > .last_letter at 0x1051e0730> > ['abc', 'def', 'ghi'] >>>> sort_by_last_letter(['ghi', 'def', 'abc']) > .last_letter at 0x1051e0730> > ['abc', 'def', 'ghi'] >>>> sort_by_last_letter(['ghi', 'def', 'abckl']) > .last_letter at 0x1051e0730> > ['def', 'ghi', 'abckl'] To build on Calvin's explanation ... intersperse other function definitions between the repeated calls sort_by_last_letter(['ghi', 'def', 'abc']) def a(): return 'skjsjlskjlsjljs' print(a) sort_by_last_letter(['ghi', 'def', 'abc']) def b(): return 546465465454 print(b) sort_by_last_letter(['ghi', 'def', 'abc']) and memory gets reused a different way. .last_letter at 0x03A51D40> # <== is same memory as .....^^^^ .last_letter at 0x043C2710> # ditto .last_letter at 0x043C2768> Creating a new list or string did not have the same effect. I believe that CPython function objects must currently all have the same size or at least the same max size and conclude that CPython currently allocates them from a block of memory that is some multiple of that size. These are, of course, current internal implementation details, subject to change and even variation across hardware and OSes. -- Terry Jan Reedy From mdekauwe at gmail.com Fri Mar 15 18:17:22 2019 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Fri, 15 Mar 2019 15:17:22 -0700 (PDT) Subject: subprocess svn checkout password issue Message-ID: <0cbea8c6-5d88-494f-909c-23f8be530a14@googlegroups.com> Hi, I'm trying to write a script that will make a checkout from a svn repo and build the result for the user. However, when I attempt to interface with the shell it asks the user for their filename and I don't know how to capture this with my implementation. user = "XXX578" root="https://trac.nci.org.au/svn/cable" repo_name = "CMIP6-MOSRS" cmd = "svn checkout %s/branches/Users/%s/%s" % (root, user, repo_name) p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) error = subprocess.call(cmd, shell=True) if error is 1: raise("Error downloading repo" I tried adding .wait(timeout=60) to the subprocess.Popen command but that didn't work. Any advice on whether there is an augmentation to the above, or a better approach, would be much appreciated. I need to solve this with standard python libs as I'm trying to make this as simple as possible for the user. The full script is here if that helps: https://github.com/mdekauwe/CABLE_benchmarking/blob/master/scripts/get_cable.py Thanks From jcasale at activenetwerx.com Fri Mar 15 20:45:21 2019 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Sat, 16 Mar 2019 00:45:21 +0000 Subject: asyncio Question In-Reply-To: References: Message-ID: <9b44bea0531d4044bf1532ba87ca439e@activenetwerx.com> > -----Original Message----- > From: Python-list bounces+jcasale=activenetwerx.com at python.org> On Behalf Of Simon > Connah > Sent: Thursday, March 14, 2019 3:03 AM > To: Python > Subject: asyncio Question > > Hi, > > Hopefully this isn't a stupid question. For the record I am using Python > 3.7 on Ubuntu Linux. > > I've decided to use asyncio to write a TCP network server using Streams > and asyncio.start_server(). I can handle that part of it without many > problems as the documentation is pretty good. I have one problem though > that I am not sure how to solve. Each request to the server will be a > JSON string and one of the components of the JSON string will be the > latitude and longitude. What I want to do is associate a latitude and > longitude with the client connection. Every time the latitude and > longitude changes then the two values will be updated. There will only > ever be one latitude and longitude for each client connection (since a > device can only ever be in one place). I'm just not sure what the best > method to achieve this would be when using asyncio.start_server(). As you expect the client to provide the latitude and longitude, so what happens when it misbehaves either by accident or intentionally and all of a sudden you have several connections from the same values? You'd better rely on your means of differentiating them. From jfong at ms4.hinet.net Fri Mar 15 23:14:40 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Fri, 15 Mar 2019 20:14:40 -0700 (PDT) Subject: Implement C's Switch in Python 3 In-Reply-To: <20e49114-372a-4836-aab7-45be628fbe46@googlegroups.com> References: <9af572e7-63e7-43e4-a1d9-a4725b00f59a@googlegroups.com> <20190203013106.GA84610@cskk.homeip.net> <20e49114-372a-4836-aab7-45be628fbe46@googlegroups.com> Message-ID: Sayth Renshaw at 2019/2/3 UTC+8 AM9:52:50 wrote: > Or perhaps use a 3rd party library like https://github.com/mikeckennedy/python-switch Thank you for this link. It's a good general implementation. --Jach From dieter at handshake.de Sat Mar 16 01:50:00 2019 From: dieter at handshake.de (dieter) Date: Sat, 16 Mar 2019 06:50:00 +0100 Subject: subprocess svn checkout password issue References: <0cbea8c6-5d88-494f-909c-23f8be530a14@googlegroups.com> Message-ID: <87va0j4bcn.fsf@handshake.de> Martin De Kauwe writes: > I'm trying to write a script that will make a checkout from a svn repo and build the result for the user. However, when I attempt to interface with the shell it asks the user for their filename and I don't know how to capture this with my implementation. > > user = "XXX578" > root="https://trac.nci.org.au/svn/cable" > repo_name = "CMIP6-MOSRS" > > cmd = "svn checkout %s/branches/Users/%s/%s" % (root, user, repo_name) > p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, > stdout=subprocess.PIPE, stderr=subprocess.PIPE) > error = subprocess.call(cmd, shell=True) > if error is 1: > raise("Error downloading repo" > > I tried adding .wait(timeout=60) to the subprocess.Popen command but that didn't work. > > Any advice on whether there is an augmentation to the above, or a better approach, would be much appreciated. I need to solve this with standard python libs as I'm trying to make this as simple as possible for the user. That is non-trivial. Read the "svn" documentation. You might be able to pass in the required information by other means, maybe an option, maybe an envvar, maybe via a configuration file. Otherwise, you must monitor what it written to the subprocess' "stdout" and "stderr", recognized the interaction request perform the interaction with the user and send the result to the subprocess' stdin. From mdekauwe at gmail.com Sat Mar 16 02:50:40 2019 From: mdekauwe at gmail.com (Martin De Kauwe) Date: Fri, 15 Mar 2019 23:50:40 -0700 (PDT) Subject: subprocess svn checkout password issue In-Reply-To: References: <0cbea8c6-5d88-494f-909c-23f8be530a14@googlegroups.com> <87va0j4bcn.fsf@handshake.de> Message-ID: <29d668a2-20d5-459c-8b2e-9f46f327cf6d@googlegroups.com> On Saturday, 16 March 2019 16:50:23 UTC+11, dieter wrote: > Martin De Kauwe writes: > > > I'm trying to write a script that will make a checkout from a svn repo and build the result for the user. However, when I attempt to interface with the shell it asks the user for their filename and I don't know how to capture this with my implementation. > > > > user = "XXX578" > > root="https://trac.nci.org.au/svn/cable" > > repo_name = "CMIP6-MOSRS" > > > > cmd = "svn checkout %s/branches/Users/%s/%s" % (root, user, repo_name) > > p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, > > stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > error = subprocess.call(cmd, shell=True) > > if error is 1: > > raise("Error downloading repo" > > > > I tried adding .wait(timeout=60) to the subprocess.Popen command but that didn't work. > > > > Any advice on whether there is an augmentation to the above, or a better approach, would be much appreciated. I need to solve this with standard python libs as I'm trying to make this as simple as possible for the user. > > That is non-trivial. > > Read the "svn" documentation. You might be able to pass in the > required information by other means, maybe an option, maybe > an envvar, maybe via a configuration file. > > Otherwise, you must monitor what it written to the subprocess' > "stdout" and "stderr", recognized the interaction request > perform the interaction with the user and send the result > to the subprocess' stdin. Thanks, I think this solution will work. import subprocess import getpass user = "XXX578" root="https://trac.nci.org.au/svn/cable" repo_name = "CMIP6-MOSRS" pswd = "'" + getpass.getpass('Password:') + "'" cmd = "svn checkout %s/branches/Users/%s/%s --password %s" %\ (root, user, repo_name, pswd) error = subprocess.call(cmd, shell=True) if error is 1: raise("Error checking out repo") From greg.ewing at canterbury.ac.nz Sat Mar 16 05:48:57 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 16 Mar 2019 22:48:57 +1300 Subject: Question regarding the local function object In-Reply-To: References: <63A2BF7F-F633-489B-8A92-95EE4C00C2A2@zeit.io> Message-ID: Terry Reedy wrote: > I believe > that CPython function objects must currently all have the same size or > at least the same max size and conclude that CPython currently allocates > them from a block of memory that is some multiple of that size. I wouldn't be surprised if there is a free list for function objects, which would make it even more likely that you would observe this kind of re-use. -- Greg From akashsahu410 at gmail.com Sat Mar 16 06:24:47 2019 From: akashsahu410 at gmail.com (akashsahu410 at gmail.com) Date: Sat, 16 Mar 2019 03:24:47 -0700 (PDT) Subject: how to embed non-tkinter VLC player into grid of tkinter with python? In-Reply-To: References: Message-ID: how to add video within tkinter frame.I am trying to add multiple videos inside the frame. From 2QdxY4RzWzUUiLuE at potatochowder.com Sat Mar 16 07:19:32 2019 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Sat, 16 Mar 2019 06:19:32 -0500 Subject: subprocess svn checkout password issue In-Reply-To: <29d668a2-20d5-459c-8b2e-9f46f327cf6d@googlegroups.com> References: <0cbea8c6-5d88-494f-909c-23f8be530a14@googlegroups.com> <87va0j4bcn.fsf@handshake.de> <29d668a2-20d5-459c-8b2e-9f46f327cf6d@googlegroups.com> Message-ID: On 3/16/19 1:50 AM, Martin De Kauwe wrote: > On Saturday, 16 March 2019 16:50:23 UTC+11, dieter wrote: >> Martin De Kauwe writes: >> >> > I'm trying to write a script that will make a checkout from a svn repo and build the result for the user. However, when I attempt to interface with the shell it asks the user for their filename and I don't know how to capture this with my implementation. [...] >> That is non-trivial. >> >> Read the "svn" documentation. You might be able to pass in the >> required information by other means, maybe an option, maybe >> an envvar, maybe via a configuration file. >> >> Otherwise, you must monitor what it written to the subprocess' >> "stdout" and "stderr", recognized the interaction request >> perform the interaction with the user and send the result >> to the subprocess' stdin. > > Thanks, I think this solution will work. > > import subprocess > import getpass > > user = "XXX578" > root="https://trac.nci.org.au/svn/cable" > repo_name = "CMIP6-MOSRS" > > pswd = "'" + getpass.getpass('Password:') + "'" > cmd = "svn checkout %s/branches/Users/%s/%s --password %s" %\ > (root, user, repo_name, pswd) I'm not questioning whether or not that will work, but I will point out that the password will be exposed to anyone doing a process listing when that process is running (e.g., "ps -ef" on a posix-like system). This may or may not be an issue for your use case. > error = subprocess.call(cmd, shell=True) > if error is 1: > raise("Error checking out repo") > From grant.b.edwards at gmail.com Sat Mar 16 12:08:04 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 16 Mar 2019 16:08:04 -0000 (UTC) Subject: subprocess svn checkout password issue References: <0cbea8c6-5d88-494f-909c-23f8be530a14@googlegroups.com> <87va0j4bcn.fsf@handshake.de> Message-ID: On 2019-03-16, dieter wrote: > Otherwise, you must monitor what it written to the subprocess' > "stdout" and "stderr", recognized the interaction request > perform the interaction with the user and send the result > to the subprocess' stdin. I don't know about svn specifically, but in the past it was typical for programs requiring passwords and assuming interactive usage to issue the password prompt to and read the password from /dev/tty, rather than stdin/stdout. That allowed their use in a pipeline without contaminating the pipe's data with the password prompt and password. In "normal" usage /dev/tty and stdin/stdout/stderr are all the same device, but when used via a library like subprocess, you couldn't provide the password via stdin. -- Grant From george at fischhof.hu Sat Mar 16 18:58:35 2019 From: george at fischhof.hu (George Fischhof) Date: Sat, 16 Mar 2019 23:58:35 +0100 Subject: mocking for get method in requests In-Reply-To: References: Message-ID: Shakti Kumar ezt ?rta (id?pont: 2019. jan. 18., P, 18:18): > Hello people, > I noticed something weird (weird as per my current knowledge, though I know > its subjective) today. > > sample.py file > > -- > > import requests > def random_testing(): > out = requests.get('www.cisco.com') > a = out.json() > return a > > > testing.py file > > -- > > @patch(*?*sample.requests') > def test_random_testing(self, mock_req): > mock_req.get('').return_value = 'Hello' > out = api.random_testing() > > > Patching the sample.requests in this way does not lead the output of > requests.get() function in sample.py file to be ?Hello? as indicated > in > mock_req.get('').return_value = 'Hello' > Instead, it creates a new field called return_value in ?out', and > hence out.return_value is ?Hello? instead of just ?out?. > > But if I patch it as, > > @patch(*?*sample.requests') > def test_random_testing(self, mock_req): > mock_req.get.return_value = 'Hello' > out = api.random_testing() > > It does give the value of ?out? as ?Hello? in sample.py file. > I know I am missing something, which is where I need some help :) > > Thanks. > > -- > > > > UG, CSE, > RVCE, Bengaluru. > -- > https://mail.python.org/mailman/listinfo/python-list Hi Kumar, I saw that there was no answer. Perhaps you should check PyTest https://docs.pytest.org/en/latest/contents.html it has several plugins, it can mock, and can do much things. BR, George From torriem at gmail.com Sat Mar 16 20:54:18 2019 From: torriem at gmail.com (Michael Torrie) Date: Sat, 16 Mar 2019 18:54:18 -0600 Subject: subprocess svn checkout password issue In-Reply-To: References: <0cbea8c6-5d88-494f-909c-23f8be530a14@googlegroups.com> <87va0j4bcn.fsf@handshake.de> Message-ID: <64d40ae9-7aa5-b019-ea40-9507d3a1d263@gmail.com> On 03/16/2019 10:08 AM, Grant Edwards wrote: > I don't know about svn specifically, but in the past it was typical > for programs requiring passwords and assuming interactive usage to > issue the password prompt to and read the password from /dev/tty, > rather than stdin/stdout. That allowed their use in a pipeline > without contaminating the pipe's data with the password prompt and > password. In "normal" usage /dev/tty and stdin/stdout/stderr are all > the same device, but when used via a library like subprocess, you > couldn't provide the password via stdin. There's a python library (Linux and Unix only I think) called pexpect[1] that can drive programs that expect a pty for taking password input. [1] https://pypi.org/project/pexpect/ From kdaatwork at gmail.com Sun Mar 17 09:04:10 2019 From: kdaatwork at gmail.com (Keith Anthony) Date: Sun, 17 Mar 2019 09:04:10 -0400 Subject: 3D surface plot In-Reply-To: References: Message-ID: I should know this ...! Anyway, I have a list of 36 tuples, each with x, y, z values .... I want to create a surface plot ... Need help putting data into right format for matplot3D ... This is a gmail account used by Keith D. Anthony On Sat, Mar 16, 2019 at 12:03 PM wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > Today's Topics: > > 1. Re: Question regarding the local function object (Terry Reedy) > 2. subprocess svn checkout password issue (Martin De Kauwe) > 3. RE: asyncio Question (Joseph L. Casale) > 4. Re: Implement C's Switch in Python 3 (jfong at ms4.hinet.net) > 5. Re: subprocess svn checkout password issue (dieter) > 6. Re: subprocess svn checkout password issue (Martin De Kauwe) > 7. Re: Question regarding the local function object (Gregory Ewing) > 8. Re: how to embed non-tkinter VLC player into grid of tkinter > with python? (akashsahu410 at gmail.com) > 9. Re: subprocess svn checkout password issue (Dan Sommers) > > > > ---------- Forwarded message ---------- > From: Terry Reedy > To: python-list at python.org > Cc: > Bcc: > Date: Fri, 15 Mar 2019 13:00:50 -0400 > Subject: Re: Question regarding the local function object > On 3/15/2019 8:47 AM, Arup Rakshit wrote: > > Hi, > > > > I am reading a book where it says that: > > > > Just like module-level function definitions, the definition of a local > function happens at run time when the def keyword is executed. > Interestingly, this means that each call to sort_by_last_letter results in > a new definition of the function last_letter. That is, just like any other > name bound in a function body, last_letter is bound separately to a new > function each time sort_by_last_letter is called. > > > > If that above is true, why the below program shows the same object > reference for last_letter every time I call function sort_by_last_letter. > > > > # file name is sample.py > > > > def sort_by_last_letter(strings): > > def last_letter(s): > > return s[-1] > > print(last_letter) > > return sorted(strings, key=last_letter) > > > > python3 -i sample.py > >>>> sort_by_last_letter(['ghi', 'def', 'abc']) > > .last_letter at 0x1051e0730> > > ['abc', 'def', 'ghi'] > >>>> sort_by_last_letter(['ghi', 'def', 'abc']) > > .last_letter at 0x1051e0730> > > ['abc', 'def', 'ghi'] > >>>> sort_by_last_letter(['ghi', 'def', 'abckl']) > > .last_letter at 0x1051e0730> > > ['def', 'ghi', 'abckl'] > > To build on Calvin's explanation ... > intersperse other function definitions between the repeated calls > > sort_by_last_letter(['ghi', 'def', 'abc']) > def a(): return 'skjsjlskjlsjljs' > print(a) > sort_by_last_letter(['ghi', 'def', 'abc']) > def b(): return 546465465454 > print(b) > sort_by_last_letter(['ghi', 'def', 'abc']) > > and memory gets reused a different way. > > .last_letter at 0x03A51D40> > # <== is same memory as .....^^^^ > .last_letter at 0x043C2710> > # ditto > .last_letter at 0x043C2768> > > Creating a new list or string did not have the same effect. I believe > that CPython function objects must currently all have the same size or > at least the same max size and conclude that CPython currently allocates > them from a block of memory that is some multiple of that size. These > are, of course, current internal implementation details, subject to > change and even variation across hardware and OSes. > > -- > Terry Jan Reedy > > > > > > ---------- Forwarded message ---------- > From: Martin De Kauwe > To: python-list at python.org > Cc: > Bcc: > Date: Fri, 15 Mar 2019 15:17:22 -0700 (PDT) > Subject: subprocess svn checkout password issue > Hi, > > I'm trying to write a script that will make a checkout from a svn repo and > build the result for the user. However, when I attempt to interface with > the shell it asks the user for their filename and I don't know how to > capture this with my implementation. > > user = "XXX578" > root="https://trac.nci.org.au/svn/cable" > repo_name = "CMIP6-MOSRS" > > cmd = "svn checkout %s/branches/Users/%s/%s" % (root, user, repo_name) > p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, > stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > error = subprocess.call(cmd, shell=True) > if error is 1: > raise("Error downloading repo" > > I tried adding .wait(timeout=60) to the subprocess.Popen command but that > didn't work. > > Any advice on whether there is an augmentation to the above, or a better > approach, would be much appreciated. I need to solve this with standard > python libs as I'm trying to make this as simple as possible for the user. > > The full script is here if that helps: > > > https://github.com/mdekauwe/CABLE_benchmarking/blob/master/scripts/get_cable.py > > Thanks > > > > > ---------- Forwarded message ---------- > From: "Joseph L. Casale" > To: "'Simon Connah'" , Python < > python-list at python.org> > Cc: > Bcc: > Date: Sat, 16 Mar 2019 00:45:21 +0000 > Subject: RE: asyncio Question > > -----Original Message----- > > From: Python-list > bounces+jcasale=activenetwerx.com at python.org> On Behalf Of Simon > > Connah > > Sent: Thursday, March 14, 2019 3:03 AM > > To: Python > > Subject: asyncio Question > > > > Hi, > > > > Hopefully this isn't a stupid question. For the record I am using Python > > 3.7 on Ubuntu Linux. > > > > I've decided to use asyncio to write a TCP network server using Streams > > and asyncio.start_server(). I can handle that part of it without many > > problems as the documentation is pretty good. I have one problem though > > that I am not sure how to solve. Each request to the server will be a > > JSON string and one of the components of the JSON string will be the > > latitude and longitude. What I want to do is associate a latitude and > > longitude with the client connection. Every time the latitude and > > longitude changes then the two values will be updated. There will only > > ever be one latitude and longitude for each client connection (since a > > device can only ever be in one place). I'm just not sure what the best > > method to achieve this would be when using asyncio.start_server(). > > As you expect the client to provide the latitude and longitude, so what > happens when it misbehaves either by accident or intentionally and > all of a sudden you have several connections from the same values? > > You'd better rely on your means of differentiating them. > > > > > ---------- Forwarded message ---------- > From: jfong at ms4.hinet.net > To: python-list at python.org > Cc: > Bcc: > Date: Fri, 15 Mar 2019 20:14:40 -0700 (PDT) > Subject: Re: Implement C's Switch in Python 3 > Sayth Renshaw at 2019/2/3 UTC+8 AM9:52:50 wrote: > > Or perhaps use a 3rd party library like > https://github.com/mikeckennedy/python-switch > > Thank you for this link. It's a good general implementation. > > --Jach > > > > > > ---------- Forwarded message ---------- > From: dieter > To: python-list at python.org > Cc: > Bcc: > Date: Sat, 16 Mar 2019 06:50:00 +0100 > Subject: Re: subprocess svn checkout password issue > Martin De Kauwe writes: > > > I'm trying to write a script that will make a checkout from a svn repo > and build the result for the user. However, when I attempt to interface > with the shell it asks the user for their filename and I don't know how to > capture this with my implementation. > > > > user = "XXX578" > > root="https://trac.nci.org.au/svn/cable" > > repo_name = "CMIP6-MOSRS" > > > > cmd = "svn checkout %s/branches/Users/%s/%s" % (root, user, repo_name) > > p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, > > stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > > error = subprocess.call(cmd, shell=True) > > if error is 1: > > raise("Error downloading repo" > > > > I tried adding .wait(timeout=60) to the subprocess.Popen command but > that didn't work. > > > > Any advice on whether there is an augmentation to the above, or a better > approach, would be much appreciated. I need to solve this with standard > python libs as I'm trying to make this as simple as possible for the user. > > That is non-trivial. > > Read the "svn" documentation. You might be able to pass in the > required information by other means, maybe an option, maybe > an envvar, maybe via a configuration file. > > Otherwise, you must monitor what it written to the subprocess' > "stdout" and "stderr", recognized the interaction request > perform the interaction with the user and send the result > to the subprocess' stdin. > > > > > > ---------- Forwarded message ---------- > From: Martin De Kauwe > To: python-list at python.org > Cc: > Bcc: > Date: Fri, 15 Mar 2019 23:50:40 -0700 (PDT) > Subject: Re: subprocess svn checkout password issue > On Saturday, 16 March 2019 16:50:23 UTC+11, dieter wrote: > > Martin De Kauwe writes: > > > > > I'm trying to write a script that will make a checkout from a svn repo > and build the result for the user. However, when I attempt to interface > with the shell it asks the user for their filename and I don't know how to > capture this with my implementation. > > > > > > user = "XXX578" > > > root="https://trac.nci.org.au/svn/cable" > > > repo_name = "CMIP6-MOSRS" > > > > > > cmd = "svn checkout %s/branches/Users/%s/%s" % (root, user, repo_name) > > > p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, > > > stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > > > error = subprocess.call(cmd, shell=True) > > > if error is 1: > > > raise("Error downloading repo" > > > > > > I tried adding .wait(timeout=60) to the subprocess.Popen command but > that didn't work. > > > > > > Any advice on whether there is an augmentation to the above, or a > better approach, would be much appreciated. I need to solve this with > standard python libs as I'm trying to make this as simple as possible for > the user. > > > > That is non-trivial. > > > > Read the "svn" documentation. You might be able to pass in the > > required information by other means, maybe an option, maybe > > an envvar, maybe via a configuration file. > > > > Otherwise, you must monitor what it written to the subprocess' > > "stdout" and "stderr", recognized the interaction request > > perform the interaction with the user and send the result > > to the subprocess' stdin. > > Thanks, I think this solution will work. > > import subprocess > import getpass > > user = "XXX578" > root="https://trac.nci.org.au/svn/cable" > repo_name = "CMIP6-MOSRS" > > pswd = "'" + getpass.getpass('Password:') + "'" > cmd = "svn checkout %s/branches/Users/%s/%s --password %s" %\ > (root, user, repo_name, pswd) > error = subprocess.call(cmd, shell=True) > if error is 1: > raise("Error checking out repo") > > > > > ---------- Forwarded message ---------- > From: Gregory Ewing > To: python-list at python.org > Cc: > Bcc: > Date: Sat, 16 Mar 2019 22:48:57 +1300 > Subject: Re: Question regarding the local function object > Terry Reedy wrote: > > I believe > > that CPython function objects must currently all have the same size or > > at least the same max size and conclude that CPython currently allocates > > them from a block of memory that is some multiple of that size. > > I wouldn't be surprised if there is a free list for function objects, > which would make it even more likely that you would observe this > kind of re-use. > > -- > Greg > > > > > ---------- Forwarded message ---------- > From: akashsahu410 at gmail.com > To: python-list at python.org > Cc: > Bcc: > Date: Sat, 16 Mar 2019 03:24:47 -0700 (PDT) > Subject: Re: how to embed non-tkinter VLC player into grid of tkinter with > python? > how to add video within tkinter frame.I am trying to add multiple videos > inside the frame. > > > > > ---------- Forwarded message ---------- > From: Dan Sommers <2QdxY4RzWzUUiLuE at potatochowder.com> > To: python-list at python.org > Cc: > Bcc: > Date: Sat, 16 Mar 2019 06:19:32 -0500 > Subject: Re: subprocess svn checkout password issue > On 3/16/19 1:50 AM, Martin De Kauwe wrote: > > On Saturday, 16 March 2019 16:50:23 UTC+11, dieter wrote: > >> Martin De Kauwe writes: > >> > >> > I'm trying to write a script that will make a checkout from a svn > repo and build the result for the user. However, when I attempt to > interface with the shell it asks the user for their filename and I don't > know how to capture this with my implementation. > > [...] > > >> That is non-trivial. > >> > >> Read the "svn" documentation. You might be able to pass in the > >> required information by other means, maybe an option, maybe > >> an envvar, maybe via a configuration file. > >> > >> Otherwise, you must monitor what it written to the subprocess' > >> "stdout" and "stderr", recognized the interaction request > >> perform the interaction with the user and send the result > >> to the subprocess' stdin. > > > > Thanks, I think this solution will work. > > > > import subprocess > > import getpass > > > > user = "XXX578" > > root="https://trac.nci.org.au/svn/cable" > > repo_name = "CMIP6-MOSRS" > > > > pswd = "'" + getpass.getpass('Password:') + "'" > > cmd = "svn checkout %s/branches/Users/%s/%s --password %s" %\ > > (root, user, repo_name, pswd) > > I'm not questioning whether or not that will work, but I will > point out that the password will be exposed to anyone doing a > process listing when that process is running (e.g., "ps -ef" > on a posix-like system). This may or may not be an issue for > your use case. > > > error = subprocess.call(cmd, shell=True) > > if error is 1: > > raise("Error checking out repo") > > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From ar at zeit.io Sun Mar 17 14:15:00 2019 From: ar at zeit.io (Arup Rakshit) Date: Sun, 17 Mar 2019 23:45:00 +0530 Subject: Question about the @staticmethod decorator Message-ID: <638F3D8D-CB71-4C06-9D13-4E941B2A5207@zeit.io> I am reading a book where the author says that: In principle, it would also be possible to implement any @staticmethod completely outside of the class at module scope without any loss of functionality ? so you may want to consider carefully whether a particular function should be a module scope function or a static method. The @staticmethod decorator merely facilitates a particular organisation of the code allowing us to place what could otherwise be free functions within classes. I didn?t get quiet well this block of text. My first question is how would I make a module level function as static method of a class. Can anyone give me an example of this? What are the contexts that would let you to think if they are good fit inside the class or module level scope functions? Thanks, Arup Rakshit ar at zeit.io From p.f.moore at gmail.com Sun Mar 17 16:24:33 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Sun, 17 Mar 2019 20:24:33 +0000 Subject: Question about the @staticmethod decorator In-Reply-To: <638F3D8D-CB71-4C06-9D13-4E941B2A5207@zeit.io> References: <638F3D8D-CB71-4C06-9D13-4E941B2A5207@zeit.io> Message-ID: On Sun, 17 Mar 2019 at 18:18, Arup Rakshit wrote: > > I am reading a book where the author says that: > > In principle, it would also be possible to implement any @staticmethod completely outside of the class at module scope without any loss of functionality ? so you may want to consider carefully whether a particular function should be a module scope function or a static method. The @staticmethod decorator merely facilitates a particular organisation of the code allowing us to place what could otherwise be free functions within classes. > > I didn?t get quiet well this block of text. My first question is how would I make a module level function as static method of a class. Can anyone give me an example of this? What are the contexts that would let you to think if they are good fit inside the class or module level scope functions? The point the author is trying to make is that there's no practical difference between def say_hello(name): print("Hello,", name) and class Talker: @staticmethod def say_hello(name): print("Hello,", name) You refer to the first as "say_hello", and the second as "Talker.say_hello", but otherwise they are used identically. The static method has no access to the class or instance variables, so it has no special capabilities that the standalone "say_hello" function has. So, to rephrase the words you used, @staticmethod lets you organise your code in a certain way, but doesn't offer any extra capabilities over module-level functions. Paul From cs at cskk.id.au Sun Mar 17 17:46:12 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 18 Mar 2019 08:46:12 +1100 Subject: Question about the @staticmethod decorator In-Reply-To: References: Message-ID: <20190317214612.GA85859@cskk.homeip.net> On 17Mar2019 20:24, Paul Moore wrote: >On Sun, 17 Mar 2019 at 18:18, Arup Rakshit wrote: >> I am reading a book where the author says that: >> >> In principle, it would also be possible to implement any @staticmethod completely outside of the class at module scope without any loss of functionality ? so you may want to consider carefully whether a particular function should be a module scope function or a static method. The @staticmethod decorator merely facilitates a particular organisation of the code allowing us to place what could otherwise be free functions within classes. >> >> I didn?t get quiet well this block of text. My first question is how would I make a module level function as static method of a class. Can anyone give me an example of this? What are the contexts that would let you to think if they are good fit inside the class or module level scope functions? > >The point the author is trying to make is that there's no practical >difference between > >def say_hello(name): > print("Hello,", name) > >and > >class Talker: > @staticmethod > def say_hello(name): > print("Hello,", name) > >You refer to the first as "say_hello", and the second as >"Talker.say_hello", but otherwise they are used identically. The >static method has no access to the class or instance variables, so it >has no special capabilities that the standalone "say_hello" function >has. So, to rephrase the words you used, @staticmethod lets you >organise your code in a certain way, but doesn't offer any extra >capabilities over module-level functions. This is true in the narrow sense that the function itself has no access to any class of instance implicit context. However, the method's _name_ is in the class namespace and findable from the class or any instance. This means that in your example above, if I have a Talker instance: talker = Talker(....) I can access the class _appropriate_ say_hello() function from the instance: talker.say_hello("Paul") Compare this with another class: class Writer: @staticmethod def say_hello(name): global_pen.transcribe_text("Hello " + name) If I've got a Writer instead of a talker, or better still a mix of them, I can call their .say_hello() methods without caring what their backend is: leader = "Arup" for member in social_group: member.say_hello(leader) So to Arup's question, a @staticmethod does not need any access to the instance or class context. However, there are still good reasons for putting it in the class definition: - code organisation: you find this function in the class definition with all the other methods - instance access to the _appropriate_ version of the method because the instance finds the method name in its own class. Now, to the converse question: if you've a potential @staticmethod, why would you bother? Aside from accessing it via an instance (or class), marking a method as a staticmethod has at least 2 other advantages: It means you can call it via an instance or a class: # use speech Talker.say_hello("Cameron") # use writing Writer.say_hello("Cameron") # use whatever "someone" prefers someone.say_hello("Cameron") Importantly, if it were an ordinary method: class Talker: def say_hello(self, name): print("Hello", name) then you _couldn't_ use the Talker.say_hello() or Writer.say_hello() forms because you've got nothing for the "self" parameter. It also makes linters happier. What's a linter? It is a tool to inspect code and complain about all sorts of dubious things. They're incredibly useful. Complaint vary from cosmetic, such as poor style (which tends to correlate with hard to ready and maintain code) to semntic, such as variables which are used before they are initialised (which usually indicates a bug in the code, often as simple as a misspelt variable name but also frequently geniuine logic bugs). In the case of a static method, if cosider these two: class Talker: def say_hello(self, name): print("Hello", name) @staticmethod def say_hello2(name): print("Hello", name) You can call either from an instance: someone.say_hello("Arup") and get the same result. However, a linter will complain about the former say_hello() method because the parameter "self" is unused. It won't complain about the latter because there isn't a "self" method. You might not care here, but if you use linters you will find complaints about unused parameters useful. They generally indicate things like: - you misspelt the parameter name inside the function (or conversely in the header) so that it isn't correct. This is a bug and the linter is helping you here. - your function genuinely isn't using the parameter. This often indicates that the function is not completely implemented, because changing the value of the parameters does not affect what the function does: that parameter is useless. So you can see that usually these lint complaints help you find bugs in your code before it runs; that is almost always faster and easier. Finding bugs when the code runs requires you to actually use it in a way that triggers the bug, which isn't always the case - it sometimes isn't even easy if the bug is something that rarely occurs. So, once you start using linters what is your goal? To make their complaint output empty, because thatt makes new problems in you code obvious. A good linter has two basic ways to remove a complaint: change the code to conform to the linter's rule (the usual case) _or_ mark the code in some way to indicate that the rule should not apply here (infrequent, but sometimes necessary - often this involves special type of comment recognised by the linter). However, you can consider the @staticmethod decorator to be a way to tell linters that this method does not use "self", because (a) you're not using "self" and (b) it lets you omit "self" from the function header. The third method of these two is to adjust the linter's rules, particularly around style; I use 2 space indents in my personal code and run my linters with a special setting for that, as 4 spaces is the common default. Cheers, Cameron Simpson From tjreedy at udel.edu Mon Mar 18 05:15:09 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Mar 2019 05:15:09 -0400 Subject: Question about the @staticmethod decorator In-Reply-To: <638F3D8D-CB71-4C06-9D13-4E941B2A5207@zeit.io> References: <638F3D8D-CB71-4C06-9D13-4E941B2A5207@zeit.io> Message-ID: On 3/17/2019 2:15 PM, Arup Rakshit wrote: > I am reading a book where the author says that: > > In principle, it would also be possible to implement any @staticmethod completely outside of the class at module scope without any loss of functionality ? so you may want to consider carefully whether a particular function should be a module scope function or a static method. The @staticmethod decorator merely facilitates a particular organisation of the code allowing us to place what could otherwise be free functions within classes. > > I didn?t get quiet well this block of text. My first question is how would I make a module level function as static method of a class. Can anyone give me an example of this? What are the contexts that would let you to think if they are good fit inside the class or module level scope functions? The addition of @staticmethod was unnecessary in that it did not enable any new functionality. I think beginners should just ignore it. -- Terry Jan Reedy From finnkochinski at keemail.me Mon Mar 18 09:10:51 2019 From: finnkochinski at keemail.me (finnkochinski at keemail.me) Date: Mon, 18 Mar 2019 14:10:51 +0100 (CET) Subject: running "python -i" in subprocess shows no prompt Message-ID: Hello, I try to start a separate python subprocess using the attached code. This example should catch all stdout and stderr output from the launched subprocess and send commands to its stdin. The problem is that the prompt ">>>" asking for then next input is neither sent to stdout nor to stderr. The commands sent to stdin aren't echoed to stdout either. The output from the attached code looks as follows: ''' Python 2.7.13 (default, Nov 23 2017, 15:37:09) [GCC 6.3.0 20170406] on linux2 Type "help", "copyright", "credits" or "license" for more information. 1 4 9 16 ''' I am expecting to get the same output as if I sent the same input to a standalone interactive python interpreter, which would be this: ''' Python 2.7.13 (default, Nov 23 2017, 15:37:09) [GCC 6.3.0 20170406] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 1*1 1 >>> 2*2 4 >>> 3*3 9 >>> 4*4 16 >>> ''' I cannot simple print the ">>>" after each readline(), because I don't know how much output will follow before the next input prompt is required. What needs to be changed in my code to make the subprocess forward the missing parts to the output pipes? regards Finn From giordani.leonardo at gmail.com Sat Mar 16 07:29:45 2019 From: giordani.leonardo at gmail.com (giordani.leonardo at gmail.com) Date: Sat, 16 Mar 2019 04:29:45 -0700 (PDT) Subject: I wrote a free book about TDD and clean architecture in Python Message-ID: Hi all, I published on Leanpub a free book, "Clean Architectures in Python". It's a humble attempt to organise and expand some posts I published on my blog in the last years. You can find it here: https://leanpub.com/clean-architectures-in-python The main content is divided in two parts, this is a brief overview of the table of contents * Part 1 - Tools - Chapter 1 - Introduction to TDD - Chapter 2 - On unit testing - Chapter 3 - Mocks * Part 2 - The clean architecture - Chapter 1 - Components of a clean architecture - Chapter 2 - A basic example - Chapter 3 - Error management - Chapter 4 - Database repositories Some highlights: - The book is written with beginners in mind - It contains 3 full projects, two small ones to introduce TDD and mocks, a bigger one to describe the clean architecture approach - Each project is explained step-by-step, and each step is linked to a tag in a companion repository on GitHub The book is free, but if you want to contribute I will definitely appreciate the help. My target is to encourage the discussion about software architectures, both in the Python community and outside it. As of today the book has been downloaded by 7,500 readers. I hope you will enjoy the book! if you do, please spread the news on your favourite social network From rosuav at gmail.com Mon Mar 18 12:09:01 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Mar 2019 03:09:01 +1100 Subject: running "python -i" in subprocess shows no prompt In-Reply-To: References: Message-ID: On Tue, Mar 19, 2019 at 2:50 AM wrote: > > Hello, > I try to start a separate python subprocess using the attached code. This example should catch all stdout and stderr output from the launched subprocess and send commands to its stdin. > The problem is that the prompt ">>>" asking for then next input is neither sent to stdout nor to stderr. The commands sent to stdin aren't echoed to stdout either. > Many programs behave differently when they're connected to an actual TTY compared to being connected to a pipe. What you often need to do is use a pseudo-terminal, which you can then feed stuff to and capture stuff from. Python makes this available with the pty module: https://docs.python.org/3/library/pty.html https://docs.python.org/2/library/pty.html (I would strongly recommend using Python 3 rather than Python 2, but it should be possible to do either way.) ChrisA From ar at zeit.io Mon Mar 18 12:27:36 2019 From: ar at zeit.io (Arup Rakshit) Date: Mon, 18 Mar 2019 21:57:36 +0530 Subject: I wrote a free book about TDD and clean architecture in Python In-Reply-To: References: Message-ID: <254A3B83-4C18-41FC-B0CF-F4F1FE908030@zeit.io> Hello, Thanks for writing this great book. I joined python community just couple of weeks. Thanks, Arup Rakshit ar at zeit.io > On 16-Mar-2019, at 4:59 PM, giordani.leonardo at gmail.com wrote: > > Hi all, > > I published on Leanpub a free book, "Clean Architectures in Python". It's a humble attempt to organise and expand some posts I published on my blog in the last years. > > You can find it here: https://leanpub.com/clean-architectures-in-python > > The main content is divided in two parts, this is a brief overview of the table of contents > > * Part 1 - Tools > - Chapter 1 - Introduction to TDD > - Chapter 2 - On unit testing > - Chapter 3 - Mocks > > * Part 2 - The clean architecture > - Chapter 1 - Components of a clean architecture > - Chapter 2 - A basic example > - Chapter 3 - Error management > - Chapter 4 - Database repositories > > Some highlights: > > - The book is written with beginners in mind > > - It contains 3 full projects, two small ones to introduce TDD and mocks, a bigger one to describe the clean architecture approach > > - Each project is explained step-by-step, and each step is linked to a tag in a companion repository on GitHub > > The book is free, but if you want to contribute I will definitely appreciate the help. My target is to encourage the discussion about software architectures, both in the Python community and outside it. > > As of today the book has been downloaded by 7,500 readers. I hope you will enjoy the book! if you do, please spread the news on your favourite social network > -- > https://mail.python.org/mailman/listinfo/python-list From infneurodcr.mtz at infomed.sld.cu Mon Mar 18 12:00:06 2019 From: infneurodcr.mtz at infomed.sld.cu (Informatico de Neurodesarrollo) Date: Mon, 18 Mar 2019 12:00:06 -0400 Subject: tkinter Message-ID: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> Hello friends: I am a beginner on programming in python. I want make a simple program that test continuously (every 5 seg) the connection? to internet and change the background color when are not available. I try this , but not work properly: ?#!/usr/bin/env python3 # -*- coding: utf-8 -*- # from tkinter import * import socket, time def DetectarConexion(): ??? testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM) ??? try: ??? ??? testConn.connect(('8.8.8.8', 80)) ??? ??? testConn.close() ??? ??? return True ??? except: ??? ??? testConn.close() ??? ??? return False root = Tk() root.title("Conexi?n") root.geometry("80x50") while True: ??? if DetectarConexion(): ??? ??? # Background:Green ??? ??? root.config(background="#38EB5C") ??? else: ??? ??? # Background:Red ??? ??? root.config(background="#F50743") ??? time.sleep(5) root.mainloop() Any ideas, will be welcome. T.I.A -- Ing. Jes?s Reyes Piedra Admin Red Neurodesarrollo,C?rdenas La caja dec?a:"Requiere windows 95 o superior"... Entonces instal? LINUX. -- Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas Infomed: http://www.sld.cu/ From rosuav at gmail.com Mon Mar 18 12:44:29 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Mar 2019 03:44:29 +1100 Subject: tkinter In-Reply-To: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> References: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> Message-ID: On Tue, Mar 19, 2019 at 3:33 AM Informatico de Neurodesarrollo wrote: > > Hello friends: > > I am a beginner on programming in python. Cool! Then I would recommend making your program as simple as you possibly can. > I want make a simple program that test continuously (every 5 seg) the > connection to internet and change the background color when are not > available. I try this , but not work properly: > > #!/usr/bin/env python3 > # -*- coding: utf-8 -*- > # > from tkinter import * > import socket, time > > def DetectarConexion(): > testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM) > try: > testConn.connect(('8.8.8.8', 80)) > testConn.close() > return True > except: > testConn.close() > return False This part of the code is completely independent of the Tkinter code. Split it up into the two parts and develop each one separately. > root = Tk() > root.title("Conexi?n") > root.geometry("80x50") > > while True: > if DetectarConexion(): > # Background:Green > root.config(background="#38EB5C") > else: > # Background:Red > root.config(background="#F50743") > time.sleep(5) > > root.mainloop() > You have two separate parts to this code, and it's possible that neither of them is working. I would recommend concentrating first on the connection status function. Remove everything about Tkinter, and replace it with a simple print() call: while True: if DetectarConexion(): print("Connection is happy") else: print("Connection is down!") time.sleep(5) Now you can work on making sure your connection tester is working. What exactly are you testing? What goes wrong when you don't have a connection? Specific advice: 1) Avoid using the bare "except:" clause. It may be hiding bugs in your code. 2) Make sure you're trying something that actually does work. Connecting to 8.8.8.8 port 80 isn't going to succeed even if your connection is live. Start with that, and you should be able to get a lot further with your testing. Have fun with it! If you run into trouble, post your updated code, what you're trying, and what's happening. Chris Angelico From zleap at disroot.org Mon Mar 18 12:47:32 2019 From: zleap at disroot.org (Paul Sutton) Date: Mon, 18 Mar 2019 16:47:32 +0000 Subject: tkinter In-Reply-To: References: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> Message-ID: On 18/03/2019 16:00, Informatico de Neurodesarrollo wrote: > Hello friends: > > I am a beginner on programming in python. > > I want make a simple program that test continuously (every 5 seg) the > connection? to internet and change the background color when are not > available. I try this , but not work properly: > > ?#!/usr/bin/env python3 > # -*- coding: utf-8 -*- > # > from tkinter import * > import socket, time > > def DetectarConexion(): > ??? testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM) > ??? try: > ??? ??? testConn.connect(('8.8.8.8', 80)) > ??? ??? testConn.close() > ??? ??? return True > ??? except: > ??? ??? testConn.close() > ??? ??? return False > > root = Tk() > root.title("Conexi?n") > root.geometry("80x50") > > while True: > ??? if DetectarConexion(): > ??? ??? # Background:Green > ??? ??? root.config(background="#38EB5C") > ??? else: > ??? ??? # Background:Red > ??? ??? root.config(background="#F50743") > ??? time.sleep(5) > > root.mainloop() > > > Any ideas, will be welcome. > > > T.I.A > > I asked about a tkinter app for a project I am working on a while back , what was suggested (which was a very useful suggestion) is get the routine and feedback working without the GUI first, so in this case a simply python program would ping something ever 5 mins and say if this was successful or not. Not sure if you would ping as such, but if you can get a normal python script to do what you want, then you can add a gui later. hope this helps Paul From grant.b.edwards at gmail.com Mon Mar 18 13:21:51 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 18 Mar 2019 17:21:51 -0000 (UTC) Subject: running "python -i" in subprocess shows no prompt References: Message-ID: On 2019-03-18, wrote: > I try to start a separate python subprocess using the attached > code. This example should catch all stdout and stderr output from > the launched subprocess and send commands to its stdin. The problem > is that the prompt ">>>" asking for then next input is neither sent > to stdout nor to stderr. The commands sent to stdin aren't echoed > to stdout either. Perhaps the prompt/echo is sent to stdin? If not connected to a tty, it may not issue prompts and echo commands. Many command line utilities modify their behavior depending on whether they're connected to a tty or not. -- Grant Edwards grant.b.edwards Yow! I'm young ... I'm at HEALTHY ... I can HIKE gmail.com THRU CAPT GROGAN'S LUMBAR REGIONS! From infneurodcr.mtz at infomed.sld.cu Mon Mar 18 13:54:03 2019 From: infneurodcr.mtz at infomed.sld.cu (Informatico de Neurodesarrollo) Date: Mon, 18 Mar 2019 13:54:03 -0400 Subject: tkinter In-Reply-To: References: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> Message-ID: This code work fine, every 5 second test the connection to this machine (10.44.0.15) on my network. #!/usr/bin/env python # -*- coding: utf-8 -*- # #? DetectConn_1_0.py # #First: Testing connection # import socket, time def isInternet(): ??? testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM) ??? output = testConn.connect_ex(('10.44.0.15', 80)) ??? if output == 0: ??????? return True ??? else: ??????? return False ??? testConn.close() while True: ??? if isInternet(): ??? ??? print("Hay conexi?n") ??? else: ??? ??? print("No hay conexi?n") ??? time.sleep(5) What's next?, I am all eyes El 18/03/19 a las 12:44, Chris Angelico escribi?: > On Tue, Mar 19, 2019 at 3:33 AM Informatico de Neurodesarrollo > wrote: >> Hello friends: >> >> I am a beginner on programming in python. > Cool! Then I would recommend making your program as simple as you possibly can. > >> I want make a simple program that test continuously (every 5 seg) the >> connection to internet and change the background color when are not >> available. I try this , but not work properly: >> >> #!/usr/bin/env python3 >> # -*- coding: utf-8 -*- >> # >> from tkinter import * >> import socket, time >> >> def DetectarConexion(): >> testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM) >> try: >> testConn.connect(('8.8.8.8', 80)) >> testConn.close() >> return True >> except: >> testConn.close() >> return False > This part of the code is completely independent of the Tkinter code. > Split it up into the two parts and develop each one separately. > >> root = Tk() >> root.title("Conexi?n") >> root.geometry("80x50") >> >> while True: >> if DetectarConexion(): >> # Background:Green >> root.config(background="#38EB5C") >> else: >> # Background:Red >> root.config(background="#F50743") >> time.sleep(5) >> >> root.mainloop() >> > You have two separate parts to this code, and it's possible that > neither of them is working. I would recommend concentrating first on > the connection status function. Remove everything about Tkinter, and > replace it with a simple print() call: > > while True: > if DetectarConexion(): > print("Connection is happy") > else: > print("Connection is down!") > time.sleep(5) > > Now you can work on making sure your connection tester is working. > What exactly are you testing? What goes wrong when you don't have a > connection? > > Specific advice: > 1) Avoid using the bare "except:" clause. It may be hiding bugs in your code. > 2) Make sure you're trying something that actually does work. > Connecting to 8.8.8.8 port 80 isn't going to succeed even if your > connection is live. > > Start with that, and you should be able to get a lot further with your testing. > > Have fun with it! If you run into trouble, post your updated code, > what you're trying, and what's happening. > > Chris Angelico -- Ing. Jes?s Reyes Piedra Admin Red Neurodesarrollo,C?rdenas La caja dec?a:"Requiere windows 95 o superior"... Entonces instal? LINUX. -- Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas Infomed: http://www.sld.cu/ From ar at zeit.io Mon Mar 18 14:09:20 2019 From: ar at zeit.io (Arup Rakshit) Date: Mon, 18 Mar 2019 23:39:20 +0530 Subject: Reasoning of calling a method on class object instead of class instance object Message-ID: Hi, In this piece of code: class RefrigeratedShippingContainer(ShippingContainer): MAX_CELSIUS = 4.0 def __init__(self, owner_code, contents, celsius): super().__init__(owner_code, contents) if celsius > RefrigeratedShippingContainer.MAX_CELSIUS: raise ValueError("Temperature too hot!") self._celsius = celsius @staticmethod def _c_to_f(celsius): return celsius * 9/5 + 32 @staticmethod def _f_to_c(fahrenheit): return (fahrenheit - 32) * 5/9 @staticmethod def _make_bic_code(owner_code, serial): return iso6346.create(owner_code=owner_code, serial=str(serial).zfill(6), category='R') @property def celsius(self): return self._celsius @celsius.setter def celsius(self, value): if value > RefrigeratedShippingContainer.MAX_CELSIUS: raise ValueError("Temperature too hot!") self._celsius = value @property def fahrenheit(self): return RefrigeratedShippingContainer._c_to_f(self.celsius) @fahrenheit.setter def fahrenheit(self, value): self.celsius = RefrigeratedShippingContainer._f_to_c(value) If I call `_c_to_f`, `_f_to_c` methods on `self` instead of `RefrigeratedShippingContainer` class object, still it works. So what is the reason behind of this calling on the class object, instead class instance object? Thanks, Arup Rakshit ar at zeit.io From rosuav at gmail.com Mon Mar 18 14:11:03 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Mar 2019 05:11:03 +1100 Subject: tkinter In-Reply-To: References: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> Message-ID: On Tue, Mar 19, 2019 at 4:55 AM Informatico de Neurodesarrollo wrote: > > This code work fine, every 5 second test the connection to this machine > (10.44.0.15) on my network. > > def isInternet(): > testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM) > output = testConn.connect_ex(('10.44.0.15', 80)) > if output == 0: > return True > else: > return False > testConn.close() > > while True: > if isInternet(): > print("Hay conexi?n") > else: > print("No hay conexi?n") > > time.sleep(5) > > > What's next?, I am all eyes > Great! Now that that's working, you can go grab your Tkinter code back. But you'll have to rework things. Set your networking code aside, and just make something that, every five seconds, changes its background colour. You may want to do some research on how to do that reliably. Hint: you most likely won't have a "while" loop in your final code. Once you have both parts working separately, then you can put them together, by having the background colour change be controlled by the connection check. But first make sure that they work on their own. ChrisA From python at mrabarnett.plus.com Mon Mar 18 14:09:12 2019 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 18 Mar 2019 18:09:12 +0000 Subject: tkinter In-Reply-To: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> References: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> Message-ID: <1de5d85f-e9fc-ddc2-98c9-95dfcc303956@mrabarnett.plus.com> On 2019-03-18 16:00, Informatico de Neurodesarrollo wrote: > Hello friends: > > I am a beginner on programming in python. > > I want make a simple program that test continuously (every 5 seg) the > connection? to internet and change the background color when are not > available. I try this , but not work properly: > > ?#!/usr/bin/env python3 > # -*- coding: utf-8 -*- > # > from tkinter import * > import socket, time > > def DetectarConexion(): > ??? testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM) > ??? try: > ??? ??? testConn.connect(('8.8.8.8', 80)) > ??? ??? testConn.close() > ??? ??? return True > ??? except: > ??? ??? testConn.close() > ??? ??? return False > > root = Tk() > root.title("Conexi?n") > root.geometry("80x50") > You have a problem here: the loop will repeat forever, so you'll never reach the root.mainloop() line and show the GUI. > while True: > ??? if DetectarConexion(): > ??? ??? # Background:Green > ??? ??? root.config(background="#38EB5C") > ??? else: > ??? ??? # Background:Red > ??? ??? root.config(background="#F50743") > ??? time.sleep(5) > > root.mainloop() > > > Any ideas, will be welcome. > From python at bdurham.com Mon Mar 18 14:38:40 2019 From: python at bdurham.com (Malcolm Greene) Date: Mon, 18 Mar 2019 14:38:40 -0400 Subject: Block Ctrl+S while running Python script at Windows console? Message-ID: <22ad5ada-99a8-43c8-8eda-938ab1942ad2@www.fastmail.com> I'm running some Python 3.6 scripts at the Windows 10/Windows Server 2016 console. In my every day workflow, I seem to be accidentally sending Ctrl+S keystrokes to some of console sessions, pausing my running scripts until I send another corresponding Ctrl+S to un-pause the affected scripts. My challenge is I don't know when I'm sending these keystrokes other than seeing scripts that seem to have stopped, clicking on their console window, and typing Ctrl+S to unblock them. Wondering if there's a way to have my Python scripts ignore these Ctrl+S signals or if this behavior is outside of my Python script's control. If there's a way to disable this behavior under Windows 10/Windows Server 2016, I'm open to that as well. Thank you, Malcolm From infneurodcr.mtz at infomed.sld.cu Mon Mar 18 14:58:55 2019 From: infneurodcr.mtz at infomed.sld.cu (Informatico de Neurodesarrollo) Date: Mon, 18 Mar 2019 14:58:55 -0400 Subject: tkinter In-Reply-To: <1de5d85f-e9fc-ddc2-98c9-95dfcc303956@mrabarnett.plus.com> References: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> <1de5d85f-e9fc-ddc2-98c9-95dfcc303956@mrabarnett.plus.com> Message-ID: <2dadba0a-be59-71e4-5042-a1927a0df334@infomed.sld.cu> Thanks, I was noted it. I have figure out, how can I do that. I keep in touch El 18/03/19 a las 14:09, MRAB escribi?: > On 2019-03-18 16:00, Informatico de Neurodesarrollo wrote: >> Hello friends: >> >> I am a beginner on programming in python. >> >> I want make a simple program that test continuously (every 5 seg) the >> connection? to internet and change the background color when are not >> available. I try this , but not work properly: >> >> ? ?#!/usr/bin/env python3 >> # -*- coding: utf-8 -*- >> # >> from tkinter import * >> import socket, time >> >> def DetectarConexion(): >> ? ??? testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM) >> ? ??? try: >> ? ??? ??? testConn.connect(('8.8.8.8', 80)) >> ? ??? ??? testConn.close() >> ? ??? ??? return True >> ? ??? except: >> ? ??? ??? testConn.close() >> ? ??? ??? return False >> >> root = Tk() >> root.title("Conexi?n") >> root.geometry("80x50") >> > You have a problem here: the loop will repeat forever, so you'll never > reach the root.mainloop() line and show the GUI. > >> while True: >> ? ??? if DetectarConexion(): >> ? ??? ??? # Background:Green >> ? ??? ??? root.config(background="#38EB5C") >> ? ??? else: >> ? ??? ??? # Background:Red >> ? ??? ??? root.config(background="#F50743") >> ? ??? time.sleep(5) >> >> root.mainloop() >> >> >> Any ideas, will be welcome. >> -- Ing. Jes?s Reyes Piedra Admin Red Neurodesarrollo,C?rdenas La caja dec?a:"Requiere windows 95 o superior"... Entonces instal? LINUX. -- Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas Infomed: http://www.sld.cu/ From larry at hastings.org Mon Mar 18 16:38:41 2019 From: larry at hastings.org (Larry Hastings) Date: Mon, 18 Mar 2019 13:38:41 -0700 Subject: Python 3.5.7 is now available Message-ID: On behalf of the Python development community, I'm chuffed to announce the availability of Python 3.5.7. Python 3.5 is in "security fixes only" mode.? It only accepts security fixes, not conventional bug fixes, and the release is source-only. And you can find Python 3.5.7rc1 here: https://www.python.org/downloads/release/python-357/ Best wishes, //arry/ From larry at hastings.org Mon Mar 18 16:42:31 2019 From: larry at hastings.org (Larry Hastings) Date: Mon, 18 Mar 2019 13:42:31 -0700 Subject: Python 3.4.10 is now available Message-ID: On behalf of the Python development community, I'm proud--if slightly sad--to announce the availability of Python 3.4.10. Python 3.4.10 was released in "security fixes only" mode.? It only contains security fixes, not conventional bug fixes, and it is a source-only release. Python 3.4.10 is the final release in the Python 3.4 series. As of this release, the 3.4 branch has been retired, no further changes to 3.4 will be accepted, and no new releases will be made.? This is standard Python policy; Python releases get five years of support and are then retired. If you're still using Python 3.4, you should consider upgrading to the current version--3.7.2 as of this writing.? Newer versions of Python have many new features, performance improvements, and bug fixes, which should all serve to enhance your Python programming experience. We in the Python core development community thank you for your interest in 3.4, and we wish you all the best! You can find Python 3.4.10 here: https://www.python.org/downloads/release/python-3410/ One I completely finish the Python 3.4.10 release process, I will retire as Python 3.4 Release Manager.? I'll still be Python 3.5 Release Manager for another eighteen months or so. Python 3.4 is OVER! https://www.youtube.com/watch?v=YlGqN3AKOsA //arry/ From eryksun at gmail.com Mon Mar 18 17:24:20 2019 From: eryksun at gmail.com (eryk sun) Date: Mon, 18 Mar 2019 16:24:20 -0500 Subject: Block Ctrl+S while running Python script at Windows console? In-Reply-To: <22ad5ada-99a8-43c8-8eda-938ab1942ad2@www.fastmail.com> References: <22ad5ada-99a8-43c8-8eda-938ab1942ad2@www.fastmail.com> Message-ID: On 3/18/19, Malcolm Greene wrote: > > I'm running some Python 3.6 scripts at the Windows 10/Windows Server 2016 > console. In my every day workflow, I seem to be accidentally sending Ctrl+S > keystrokes to some of console sessions, pausing my running scripts until I > send another corresponding Ctrl+S to un-pause the affected scripts. My > challenge is I don't know when I'm sending these keystrokes other than > seeing scripts that seem to have stopped, clicking on their console window, > and typing Ctrl+S to unblock them. > > Wondering if there's a way to have my Python scripts ignore these Ctrl+S > signals or if this behavior is outside of my Python script's control. If > there's a way to disable this behavior under Windows 10/Windows Server 2016, > I'm open to that as well. Ctrl+S functions as pause in line-edit mode if extended text selection is enabled in the console defaults or properties dialog, It's implemented by blocking console I/O operations in the host process, conhost.exe. Pretty much any key will resume. It doesn't have to be Ctrl+Q or Ctrl+S. Another common culprit is quick-edit mode, in which case a stray mouse click can select text, even just a single character. The console pauses while text is selected. From eryksun at gmail.com Mon Mar 18 17:27:28 2019 From: eryksun at gmail.com (eryk sun) Date: Mon, 18 Mar 2019 16:27:28 -0500 Subject: Block Ctrl+S while running Python script at Windows console? In-Reply-To: References: <22ad5ada-99a8-43c8-8eda-938ab1942ad2@www.fastmail.com> Message-ID: On 3/18/19, eryk sun wrote: > > Ctrl+S functions as pause in line-edit mode if extended text selection > is enabled in the console defaults or properties dialog Correction, it pauses if extended text selection is *disabled*. From barry at barrys-emacs.org Mon Mar 18 18:31:40 2019 From: barry at barrys-emacs.org (Barry) Date: Mon, 18 Mar 2019 22:31:40 +0000 Subject: subprocess svn checkout password issue In-Reply-To: <0cbea8c6-5d88-494f-909c-23f8be530a14@googlegroups.com> References: <0cbea8c6-5d88-494f-909c-23f8be530a14@googlegroups.com> Message-ID: > On 15 Mar 2019, at 22:17, Martin De Kauwe wrote: > > Hi, > > I'm trying to write a script that will make a checkout from a svn repo and build the result for the user. However, when I attempt to interface with the shell it asks the user for their filename and I don't know how to capture this with my implementation. > > user = "XXX578" > root="https://trac.nci.org.au/svn/cable" > repo_name = "CMIP6-MOSRS" > > cmd = "svn checkout %s/branches/Users/%s/%s" % (root, user, repo_name) > p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, > stdout=subprocess.PIPE, stderr=subprocess.PIPE) > error = subprocess.call(cmd, shell=True) > if error is 1: > raise("Error downloading repo" > > I tried adding .wait(timeout=60) to the subprocess.Popen command but that didn't work. > > Any advice on whether there is an augmentation to the above, or a better approach, would be much appreciated. I need to solve this with standard python libs as I'm trying to make this as simple as possible for the user. > > The full script is here if that helps: > > https://github.com/mdekauwe/CABLE_benchmarking/blob/master/scripts/get_cable.py You could also use the pysvn library that provides a pythonic api to drive svn From https://pysvn.sourceforge.io/ notes its not on PyPi but ther are kits for windows, mac. Debian and Fedora provide pysvn as well. It allows you to provide the username and password via the api. See https://pysvn.sourceforge.io/Docs/pysvn_prog_ref.html#pysvn_client_checkout And https://pysvn.sourceforge.io/Docs/pysvn_prog_ref.html#pysvn_client_callback_get_login to provide the username and password. Barry Pysvn author > > Thanks > -- > https://mail.python.org/mailman/listinfo/python-list > From ben+python at benfinney.id.au Mon Mar 18 19:55:08 2019 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 19 Mar 2019 10:55:08 +1100 Subject: Reasoning of calling a method on class object instead of class instance object References: Message-ID: <86sgvj20wz.fsf@benfinney.id.au> Arup Rakshit writes: > class RefrigeratedShippingContainer(ShippingContainer): > # ... > > @staticmethod > def _c_to_f(celsius): > return celsius * 9/5 + 32 > > @staticmethod > def _f_to_c(fahrenheit): > return (fahrenheit - 32) * 5/9 Both those functions are decorated with ?staticmethod?. That means that the function will, unlike typical methods, not automatically receive any implicit first argument. That's why the function signature has no ?self? or ?klass? or the like. > If I call `_c_to_f`, `_f_to_c` methods on `self` instead of > `RefrigeratedShippingContainer` class object, still it works. That's right, and is indeed the point of making a static method on a class. From the above documentation link: [A staticmethod-decorated function] can be called either on the class (such as `C.f()`) or on an instance (such as `C().f()`). The instance is ignored except for its class. > So what is the reason behind of this calling on the class object, > instead class instance object? Whichever makes the most sense in the code where that function is called. The purpose of a static method is to imply that, though the function *could* be entirely separate from any class, it is conceptually part of a spacific class's behaviour. In the specific example you show, I expect the code maintenance was deemed to be easier when the RefrigeratedShippingContainer encapsulates the conversions of temperature units. -- \ ?When we pray to God we must be seeking nothing ? nothing.? | `\ ?Francis of Assisi | _o__) | Ben Finney From torriem at gmail.com Mon Mar 18 20:44:23 2019 From: torriem at gmail.com (Michael Torrie) Date: Mon, 18 Mar 2019 18:44:23 -0600 Subject: Reasoning of calling a method on class object instead of class instance object In-Reply-To: <86sgvj20wz.fsf@benfinney.id.au> References: <86sgvj20wz.fsf@benfinney.id.au> Message-ID: <07234b72-2e74-a54f-0542-14f3702cbe83@gmail.com> On 03/18/2019 05:55 PM, Ben Finney wrote: >> If I call `_c_to_f`, `_f_to_c` methods on `self` instead of >> `RefrigeratedShippingContainer` class object, still it works. > > That's right, and is indeed the point of making a static method on a > class. I'm confused. The methods that refer to RefigeratedShippingContainer.MAX_CELSIUS are not static methods. For example, __init__() and celsius(). In fact he never said anything about static methods unless I'm really missing something. > In the specific example you show, I expect the code maintenance was > deemed to be easier when the RefrigeratedShippingContainer encapsulates > the conversions of temperature units. I'm not sure this answers his question. He's asking why refer to a class variable with the class's name when self also apparently works. From ben+python at benfinney.id.au Mon Mar 18 21:09:41 2019 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 19 Mar 2019 12:09:41 +1100 Subject: Reasoning of calling a method on class object instead of class instance object References: <86sgvj20wz.fsf@benfinney.id.au> <07234b72-2e74-a54f-0542-14f3702cbe83@gmail.com> Message-ID: <86o9671xgq.fsf@benfinney.id.au> Arup Rakshit writes: Michael Torrie writes: > On 03/18/2019 05:55 PM, Ben Finney wrote: > >> If I call `_c_to_f`, `_f_to_c` methods on `self` instead of > >> `RefrigeratedShippingContainer` class object, still it works. > > > > That's right, and is indeed the point of making a static method on a > > class. > > I'm confused. [?] he never said anything about static methods unless > I'm really missing something. You included it, quoted above (but stripped out the attribution; please don't do that). The only methods discussed in Arup Rakshit's message are ?_c_to_f? and ?_f_to_c?, both static methods on the class. -- \ ?A child of five could understand this. Fetch me a child of | `\ five.? ?Groucho Marx | _o__) | Ben Finney From torriem at gmail.com Mon Mar 18 21:21:44 2019 From: torriem at gmail.com (Michael Torrie) Date: Mon, 18 Mar 2019 19:21:44 -0600 Subject: Reasoning of calling a method on class object instead of class instance object In-Reply-To: <86o9671xgq.fsf@benfinney.id.au> References: <86sgvj20wz.fsf@benfinney.id.au> <07234b72-2e74-a54f-0542-14f3702cbe83@gmail.com> <86o9671xgq.fsf@benfinney.id.au> Message-ID: On 03/18/2019 07:09 PM, Ben Finney wrote: > Arup Rakshit writes: > > Michael Torrie writes: > >> On 03/18/2019 05:55 PM, Ben Finney wrote: >>>> If I call `_c_to_f`, `_f_to_c` methods on `self` instead of >>>> `RefrigeratedShippingContainer` class object, still it works. >>> >>> That's right, and is indeed the point of making a static method on a >>> class. >> >> I'm confused. [?] he never said anything about static methods unless >> I'm really missing something. > > You included it, quoted above (but stripped out the attribution; please > don't do that). The only methods discussed in Arup Rakshit's message are > ?_c_to_f? and ?_f_to_c?, both static methods on the class. Gotcha. Thanks. From python at bdurham.com Mon Mar 18 21:57:35 2019 From: python at bdurham.com (Malcolm Greene) Date: Mon, 18 Mar 2019 21:57:35 -0400 Subject: =?UTF-8?Q?Re:_Block_Ctrl+S_while_running_Python_script_at_Windows_consol?= =?UTF-8?Q?e=3F_(solved)?= In-Reply-To: References: <22ad5ada-99a8-43c8-8eda-938ab1942ad2@www.fastmail.com> Message-ID: <5b1caade-1f07-4563-a04c-8ec060521bf1@www.fastmail.com> Eryk, > Another common culprit is quick-edit mode, in which case a stray mouse click can select text, even just a single character. The console pauses while text is selected. MYSTERY SOLVED !! THANK YOU !! Apparently, while mouse clicking between windows, I was inadvertently selecting a char on my console, thereby pausing the process that was running. Disabling Quick-Edit mode via the Properties dialog fixes this behavior. I tried other console property setting combinations to block Ctrl+S keyboard behavior, but without success. Not a problem since I'm pretty sure I'm not typing random Ctrl+S keystrokes while working. Thanks again Eryk! Malcolm From sharan.basappa at gmail.com Mon Mar 18 23:04:09 2019 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Mon, 18 Mar 2019 20:04:09 -0700 (PDT) Subject: error while importing a module Message-ID: <78e8cdde-875a-4fcd-9abe-b3fc0059eac2@googlegroups.com> I have a design file that I am importing in a test file to run some tests. The design file compiles fine when I run it standalone but when I import it in the test file, I see error on the very first line where I am importing the design file. This is the line from test file: """ test my design """ import assertion_design as asd Here is the error: WindowsErrorTraceback (most recent call last) D:\Users\sharanb\OneDrive - HCL Technologies Ltd\Projects\MyBackup\Projects\Initiatives\machine learning\programs\assertion\assertion_design_test.py in () 4 provided by the user 5 """ ----> 6 import assertion_design as asd Am I missing something? From sharan.basappa at gmail.com Mon Mar 18 23:11:39 2019 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Mon, 18 Mar 2019 20:11:39 -0700 (PDT) Subject: error while importing a module In-Reply-To: <78e8cdde-875a-4fcd-9abe-b3fc0059eac2@googlegroups.com> References: <78e8cdde-875a-4fcd-9abe-b3fc0059eac2@googlegroups.com> Message-ID: <3b48e91c-3f69-41df-82c6-035b58da6d2a@googlegroups.com> On Tuesday, 19 March 2019 08:34:25 UTC+5:30, Sharan Basappa wrote: > I have a design file that I am importing in a test file to run some tests. > The design file compiles fine when I run it standalone but when I import it in the test file, I see error on the very first line where I am importing the design file. > > This is the line from test file: > > """ > test my design > """ > import assertion_design as asd > > Here is the error: > WindowsErrorTraceback (most recent call last) > D:\Users\sharanb\OneDrive - HCL Technologies Ltd\Projects\MyBackup\Projects\Initiatives\machine learning\programs\assertion\assertion_design_test.py in () > 4 provided by the user > 5 """ > ----> 6 import assertion_design as asd > > Am I missing something? folks, i think i figured it out. The following 2 lines were missing before the import import sys sys.path.append('D:\Users\sharanb\OneDrive - HCL Technologies Ltd\Projects\MyBackup\Projects\Initiatives\machine learning\programs\assertion') From cs at cskk.id.au Tue Mar 19 00:16:50 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 19 Mar 2019 15:16:50 +1100 Subject: error while importing a module In-Reply-To: <3b48e91c-3f69-41df-82c6-035b58da6d2a@googlegroups.com> References: <3b48e91c-3f69-41df-82c6-035b58da6d2a@googlegroups.com> Message-ID: <20190319041650.GA13991@cskk.homeip.net> On 18Mar2019 20:11, Sharan Basappa wrote: >On Tuesday, 19 March 2019 08:34:25 UTC+5:30, Sharan Basappa wrote: >> I have a design file that I am importing in a test file to run some tests. [...] >> The design file compiles fine when I run it standalone but when I import it in the test file, I see error on the very first line where I am importing the design file. >The following 2 lines were missing before the import > >import sys >sys.path.append('D:\Users\sharanb\OneDrive - HCL Technologies Ltd\Projects\MyBackup\Projects\Initiatives\machine learning\programs\assertion') I suggest you make that string a "raw" string: sys.path.append(r'D:\Users\sharanb\OneDrive - HCL Technologies Ltd\Projects\MyBackup\Projects\Initiatives\machine learning\programs\assertion') Unlike a normal Python string 'foo', a raw string r'foo' does not interpret slosh escapes (\n, \r etc). In any string which is supposed to include sloshes (backslashes) you should write these as raw string to avoid unfortunate slosh escapes being interpreted as special characters. In your string above the sequence \a indicates an ASCII BEL character, which rings the terminal bell (in modern terminal emulators this often means to emit a beep or to flash the window to attract attention). So it isn't the path string you thought it was. There are several slosh escapes recognised by Python strings; see the documentation for details. But when you _don't_ want the sequences interpreted, use a raw string. Cheers, Cameron Simpson From tjreedy at udel.edu Tue Mar 19 02:18:57 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 19 Mar 2019 02:18:57 -0400 Subject: tkinter In-Reply-To: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> References: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> Message-ID: On 3/18/2019 12:00 PM, Informatico de Neurodesarrollo wrote: > Hello friends: > > I am a beginner on programming in python. > > I want make a simple program that test continuously (every 5 seg) the > connection? to internet and change the background color when are not > available. I try this , but not work properly: > > ?#!/usr/bin/env python3 > # -*- coding: utf-8 -*- Not needed for py 3 where utf-8 is default > from tkinter import * > import socket, time > > def DetectarConexion(): > ??? testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM) > ??? try: > ??? ??? testConn.connect(('8.8.8.8', 80)) > ??? ??? testConn.close() > ??? ??? return True > ??? except: > ??? ??? testConn.close() > ??? ??? return False > > root = Tk() > root.title("Conexi?n") > root.geometry("80x50") > > while True: > ??? if DetectarConexion(): > ??? ??? # Background:Green > ??? ??? root.config(background="#38EB5C") > ??? else: > ??? ??? # Background:Red > ??? ??? root.config(background="#F50743") > ??? time.sleep(5) This is your problem. Loop with event loop in order to not block gui. See working code below. > root.mainloop() #!/usr/bin/env python3 from tkinter import * connected = False def DetectarConexion(): global connected connected = not connected return connected root = Tk() root.title("Conexi?n") root.geometry("80x50") def colorupdate(): if DetectarConexion(): # Background:Green root.config(background="#38EB5C") else: # Background:Red root.config(background="#F50743") root.after(1000, colorupdate) # 1000 milliseconds = 1 second colorupdate() root.mainloop() -- Terry Jan Reedy From tjreedy at udel.edu Tue Mar 19 02:27:40 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 19 Mar 2019 02:27:40 -0400 Subject: running "python -i" in subprocess shows no prompt In-Reply-To: References: Message-ID: On 3/18/2019 9:10 AM, finnkochinski at keemail.me wrote: > I try to start a separate python subprocess using the attached code. This example should catch all stdout and stderr output from the launched subprocess and send commands to its stdin. Subprocess is not intended for interaction. My attempts to use the subprocess pipes failed like yours did. IDLE makes a socket connection to the execution subprocess, but using multiprocessing may be better for you. This was the answer I got when I asked the same question you did. (IDLE was written before multiprocess, and I may experiment with switching.) -- Terry Jan Reedy From eryksun at gmail.com Tue Mar 19 04:46:35 2019 From: eryksun at gmail.com (eryk sun) Date: Tue, 19 Mar 2019 03:46:35 -0500 Subject: Block Ctrl+S while running Python script at Windows console? In-Reply-To: <6aj09edjtopq19h2ora75be53310a4u8qa@4ax.com> References: <22ad5ada-99a8-43c8-8eda-938ab1942ad2@www.fastmail.com> <6aj09edjtopq19h2ora75be53310a4u8qa@4ax.com> Message-ID: On 3/18/19, Dennis Lee Bieber wrote: > On Mon, 18 Mar 2019 14:38:40 -0400, "Malcolm Greene" > declaimed the following: > >> >>Wondering if there's a way to have my Python scripts ignore these Ctrl+S >> signals or if this behavior is outside of my Python script's control. If >> there's a way to disable this behavior under Windows 10/Windows Server >> 2016, I'm open to that as well. >> > > / (XOFF/XON) are traditional terminal control codes to > stop/start transmission. The behavior is baked into the console being used. The Windows console does not really implement XOFF (DC3, Ctrl+S) and XON (DC1, Ctrl+Q) terminal behavior. In line-input mode, it implements Ctrl+S as equivalent to pressing the pause key (i.e. VK_PAUSE, which has the same numeric value as DC3), so it's meant to be familiar to people who are used to working in terminals. But, in contrast to a terminal emulator, there is no requirement to press Ctrl+Q (i.e. DC1) to resume. Almost any key suffices to resume the console, except for the pause key and modifiers (Ctrl, Alt, Shift). In particular, pressing Ctrl+S again, as the original poster did, will resume the Windows console, but it would not resume a terminal emulator. If enabled, the console's extended editing keys feature overrides the default pause behavior of Ctrl+S. It can be enabled via the console's ExtendedEditKey registry value, or in the defaults and properties dialogs by enabling "extended text selection keys". Disabling it also disables immediate access to the console's new text selection keys such as Shift+Arrows, in which case we have to first enter mark mode via Ctrl+M. The default extended-editing keymap doesn't define anything for Ctrl+S, so it's just a DC3 (0x13) character. In principle the extended editing keys can be customized to map Ctrl+S to a virtual key such as VK_PAUSE (i.e. retain the default behavior), but, as far as I know, the binary format of the console's ExtendedEditKeyCustom registry value is not documented. Regardless of the extended editing keys setting, we can always read Ctrl+S via msvcrt.getwch(), since it disables line-input mode. From __peter__ at web.de Tue Mar 19 05:06:27 2019 From: __peter__ at web.de (Peter Otten) Date: Tue, 19 Mar 2019 10:06:27 +0100 Subject: tkinter References: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> Message-ID: Terry Reedy wrote: > On 3/18/2019 12:00 PM, Informatico de Neurodesarrollo wrote: >> Hello friends: >> >> I am a beginner on programming in python. >> >> I want make a simple program that test continuously (every 5 seg) the >> connection to internet and change the background color when are not >> available. I try this , but not work properly: >> >> #!/usr/bin/env python3 >> # -*- coding: utf-8 -*- > > Not needed for py 3 where utf-8 is default > >> from tkinter import * >> import socket, time >> >> def DetectarConexion(): >> testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM) >> try: >> testConn.connect(('8.8.8.8', 80)) >> testConn.close() >> return True >> except: >> testConn.close() >> return False >> >> root = Tk() >> root.title("Conexi?n") >> root.geometry("80x50") >> >> while True: >> if DetectarConexion(): >> # Background:Green >> root.config(background="#38EB5C") >> else: >> # Background:Red >> root.config(background="#F50743") >> time.sleep(5) > > This is your problem. Loop with event loop in order to not block gui. > See working code below. > >> root.mainloop() > > #!/usr/bin/env python3 > > from tkinter import * > > connected = False > def DetectarConexion(): > global connected > connected = not connected > return connected > > root = Tk() > root.title("Conexi?n") > root.geometry("80x50") > > def colorupdate(): > if DetectarConexion(): > # Background:Green > root.config(background="#38EB5C") > else: > # Background:Red > root.config(background="#F50743") > root.after(1000, colorupdate) # 1000 milliseconds = 1 second > > colorupdate() > root.mainloop() If the DetectarConexion() function takes long to execute it will still block the GUI because it is called indirectly by the callback. In that case you may execute it in a separate thread: #!/usr/bin/env python3 from tkinter import * import random import threading import time # global flag used to communicate between the checker thread # and the GUI in the main thread. If the interaction gets more # complex you may use a queue.Queue() instead. connected = False def DetectarConexion(): # simulate that the function takes # 3 seconds to execute time.sleep(3) return random.random() < .7 # good with 70% probability def update_connection_state(): global connected while True: connected = DetectarConexion() time.sleep(1) # wait 1 second until the next check def colorupdate(): if connected: # Background:Green root.config(background="#38EB5C") else: # Background:Red root.config(background="#F50743") root.after(1000, colorupdate) # 1000 milliseconds = 1 second checker_thread = threading.Thread( target=update_connection_state, daemon=True ) checker_thread.start() root = Tk() root.title("Conexi?n") root.geometry("80x50") colorupdate() root.mainloop() From finnkochinski at keemail.me Tue Mar 19 05:11:33 2019 From: finnkochinski at keemail.me (finnkochinski at keemail.me) Date: Tue, 19 Mar 2019 10:11:33 +0100 (CET) Subject: running "python -i" in subprocess shows no prompt In-Reply-To: References: Message-ID: Thanks for letting me know that the list takes no attachments. Please find my modified code at the end of this email. I found one problem. I was reading streams with "proc.stderr.readline()", which never returned, because only ">>> " was sent to stderr repeatedly, "\n" only going to stdout. Now I am using proc.stderr.read(1) instead, and I do receive the prompts. Unfortunately both streams are mixed up: Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >1 >> 4 >>> 9 >>> 1>>> 6 > I found that the pty module might be a solution, also from the helpful comments in this thread, but I can't find a simple example how to make it work. regards Finn This is my last attempt, which produced the above output: import subprocess, threading, time, os, sys cont=True def pyout(proc): ? while cont: ??? c=proc.stdout.read(1) ??? # was: c=proc.stdout.readline() ??? sys.stdout.write(c) ??? sys.stdout.flush() def pyerr(proc): ? while cont: ??? c=proc.stderr.read(1) ??? # was: c=proc.stderr.readline() ??? sys.stderr.write(c) ??? sys.stderr.flush() proc=subprocess.Popen(['python','-i'], ? stdin=subprocess.PIPE, ? stdout=subprocess.PIPE, ? stderr=subprocess.PIPE ) threading.Thread(target=pyout,args=(proc,)).start() threading.Thread(target=pyerr,args=(proc,)).start() for i in range(1,5): ? time.sleep(1.) ? proc.stdin.write("print %d*%d\n" % (i,i)) ? proc.stdin.flush() time.sleep(0.1) cont=False proc.stdin.write("print\n") #make last read(1) finish Mar 18, 2019, 6:26 PM by wlfraed at ix.netcom.com: > On Mon, 18 Mar 2019 14:10:51 +0100 (CET), <> finnkochinski at keemail.me > > > declaimed the following: > > >Hello, > >I try to start a separate python subprocess using the attached code. This example should catch all stdout and stderr output from the launched subprocess and send commands to its stdin. > > No attachments here... either inline the code or provide a link to some > file server. > > >The problem is that the prompt ">>>" asking for then next input is neither sent to stdout nor to stderr. The commands sent to stdin aren't echoed to stdout either. > > The odds are very good that you are encountering the problems with > buffered I/O streams. Such streams tend to only transfer when a) closed by > the sending side, b) an end-of-line character sequence is sent. > > The prompt string does not have an end-of-line (it expects input to be > on the same terminal line)... so it is being held up in a buffer waiting > for the end-of-line. > > If you aren't encountering buffering problems, then it could be that > the (nonvisible) code is doing read line operations, and THAT is blocking > for an end-of-line. > > > -- > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed at ix.netcom.com > HTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Tue Mar 19 05:18:16 2019 From: __peter__ at web.de (Peter Otten) Date: Tue, 19 Mar 2019 10:18:16 +0100 Subject: Reasoning of calling a method on class object instead of class instance object References: Message-ID: Arup Rakshit wrote: > In this piece of code: > > class RefrigeratedShippingContainer(ShippingContainer): > @staticmethod > def _c_to_f(celsius): > return celsius * 9/5 + 32 > @property > def fahrenheit(self): > return RefrigeratedShippingContainer._c_to_f(self.celsius) > If I call `_c_to_f`, `_f_to_c` methods on `self` instead of > `RefrigeratedShippingContainer` class object, still it works. So what is > the reason behind of this calling on the class object, instead class > instance object? I don't know, but I would prefer self over the class name. From grant.b.edwards at gmail.com Tue Mar 19 10:22:10 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 19 Mar 2019 14:22:10 -0000 (UTC) Subject: Block Ctrl+S while running Python script at Windows console? References: <22ad5ada-99a8-43c8-8eda-938ab1942ad2@www.fastmail.com> Message-ID: On 2019-03-18, Malcolm Greene wrote: > Wondering if there's a way to have my Python scripts ignore these > Ctrl+S signals or if this behavior is outside of my Python script's > control. This has nothing to do with Python does it? Isn't Python is just writing to stdout and those write calls are blocking due because the terminal emulator has stopped reading the other end of the pipe/pty/queue/buffer/whatever-it's-called-in-windows? -- Grant Edwards grant.b.edwards Yow! It's some people at inside the wall! This is gmail.com better than mopping! From python at bdurham.com Tue Mar 19 10:45:26 2019 From: python at bdurham.com (Malcolm Greene) Date: Tue, 19 Mar 2019 10:45:26 -0400 Subject: Block Ctrl+S while running Python script at Windows console? In-Reply-To: References: <22ad5ada-99a8-43c8-8eda-938ab1942ad2@www.fastmail.com> Message-ID: <797750f9-4b0f-4847-88e8-77315bc3aeba@www.fastmail.com> > This has nothing to do with Python does it? Isn't Python is just writing to stdout and those write calls are blocking due because the terminal emulator has stopped reading the other end of the pipe/pty/queue/buffer/whatever-it's-called-in-windows? You're right. But I wasn't sure. I know Python can trap Ctrl+C break signals, so I wondered if there was a similar tie-in for Ctrl+S. Eryk did a great job explaining the tech details of what's happening behind the scenes in the Windows world. In my case it turned out that my clicking between windows was inadvertently selecting text pausing the running process. Unchecking the Windows console's Quick Edit mode stops this behavior. Malcolm From ar at zeit.io Tue Mar 19 11:09:22 2019 From: ar at zeit.io (Arup Rakshit) Date: Tue, 19 Mar 2019 20:39:22 +0530 Subject: Why can't access the property setter using the super? Message-ID: I have 3 classes which are connected to them through inheritance as you see in the below code: import iso6346 class ShippingContainer: """docstring for ShippingContainer""" HEIGHT_FT = 8.5 WIDTH_FT = 8.0 next_serial = 1337 @classmethod def _get_next_serial(cls): result = cls.next_serial cls.next_serial += 1 return result @staticmethod def _make_bic_code(owner_code, serial): return iso6346.create(owner_code=owner_code, serial=str(serial).zfill(6)) @classmethod def create_empty(cls, owner_code, length_ft, *args, **keyword_args): return cls(owner_code, length_ft, contents=None, *args, **keyword_args) # ... skipped def __init__(self, owner_code, length_ft, contents): self.contents = contents self.length_ft = length_ft self.bic = self._make_bic_code(owner_code=owner_code, serial=ShippingContainer._get_next_serial()) # ... skipped class RefrigeratedShippingContainer(ShippingContainer): MAX_CELSIUS = 4.0 FRIDGE_VOLUME_FT3 = 100 def __init__(self, owner_code, length_ft, contents, celsius): super().__init__(owner_code, length_ft, contents) self.celsius = celsius # ... skipped @staticmethod def _make_bic_code(owner_code, serial): return iso6346.create(owner_code=owner_code, serial=str(serial).zfill(6), category='R') @property def celsius(self): return self._celsius @celsius.setter def celsius(self, value): if value > RefrigeratedShippingContainer.MAX_CELSIUS: raise ValueError("Temperature too hot!") self._celsius = value # ... skipped class HeatedRefrigeratedShippingContainer(RefrigeratedShippingContainer): MIN_CELSIUS = -20.0 @RefrigeratedShippingContainer.celsius.setter def celsius(self, value): if value < HeatedRefrigeratedShippingContainer.MIN_CELSIUS: raise ValueError("Temperature too cold!") super().celsius = value Now when I run the code : Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from shipping import * >>> h1 = HeatedRefrigeratedShippingContainer.create_empty('YML', length_ft=40, celsius=-18) Traceback (most recent call last): File "", line 1, in File "/Users/aruprakshit/python_playground/shipping.py", line 23, in create_empty return cls(owner_code, length_ft, contents=None, *args, **keyword_args) File "/Users/aruprakshit/python_playground/shipping.py", line 47, in __init__ self.celsius = celsius File "/Users/aruprakshit/python_playground/shipping.py", line 92, in celsius super().celsius = value AttributeError: 'super' object has no attribute 'celsius' >>> Why here super is denying the fact that it has no celsius setter, although it has. While this code doesn?t work how can I solve this. The thing I am trying here not to duplicate the validation of temperature which is already in the setter property of the RefrigeratedShippingContainer class. Thanks, Arup Rakshit ar at zeit.io From ian.g.kelly at gmail.com Tue Mar 19 12:02:52 2019 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 19 Mar 2019 10:02:52 -0600 Subject: Why can't access the property setter using the super? In-Reply-To: References: Message-ID: Here's the thing: the result of calling super() is not an instance of the base class. It's just a proxy object with a __getattribute__ implementation that looks up class attributes in the base class, and knows how to pass self to methods to simulate calling base class methods on an instance. This works fine for looking up methods and property getters. It doesn't work so well for simulating other behaviors, like setters, or comparisons, or iteration, etc. A property is one example of what in Python is known as a descriptor, which is described here: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors A settable property has a __set__ method per the descriptor protocol. When you try to set an attribute with the name of the property, Python looks up the name in the class dict, finds the property object, and then calls its __set__ method. The class of the super proxy object, however, does not contain this property, and because you're not doing an attribute lookup, the super proxy's __getattribute__ does not get called. So all Python sees is that you tried to set an attribute that doesn't exist on the proxy object. The way I would suggest to get around this would be change your super() call so that it looks up the property from the base class instead of trying to set an attribute directly. For example, this should work: super(HeatedRefrigeratedShippingContainer, self.__class__).celsius.fset(self, value) On Tue, Mar 19, 2019 at 9:12 AM Arup Rakshit wrote: > I have 3 classes which are connected to them through inheritance as you > see in the below code: > > import iso6346 > > class ShippingContainer: > """docstring for ShippingContainer""" > > HEIGHT_FT = 8.5 > WIDTH_FT = 8.0 > next_serial = 1337 > > @classmethod > def _get_next_serial(cls): > result = cls.next_serial > cls.next_serial += 1 > return result > > @staticmethod > def _make_bic_code(owner_code, serial): > return iso6346.create(owner_code=owner_code, > serial=str(serial).zfill(6)) > > @classmethod > def create_empty(cls, owner_code, length_ft, *args, **keyword_args): > return cls(owner_code, length_ft, contents=None, *args, > **keyword_args) > > # ... skipped > > def __init__(self, owner_code, length_ft, contents): > self.contents = contents > self.length_ft = length_ft > self.bic = self._make_bic_code(owner_code=owner_code, > > serial=ShippingContainer._get_next_serial()) > # ... skipped > > > class RefrigeratedShippingContainer(ShippingContainer): > MAX_CELSIUS = 4.0 > FRIDGE_VOLUME_FT3 = 100 > > def __init__(self, owner_code, length_ft, contents, celsius): > super().__init__(owner_code, length_ft, contents) > self.celsius = celsius > > # ... skipped > > @staticmethod > def _make_bic_code(owner_code, serial): > return iso6346.create(owner_code=owner_code, > serial=str(serial).zfill(6), > category='R') > @property > def celsius(self): > return self._celsius > > @celsius.setter > def celsius(self, value): > if value > RefrigeratedShippingContainer.MAX_CELSIUS: > raise ValueError("Temperature too hot!") > self._celsius = value > > # ... skipped > > > class HeatedRefrigeratedShippingContainer(RefrigeratedShippingContainer): > MIN_CELSIUS = -20.0 > > @RefrigeratedShippingContainer.celsius.setter > def celsius(self, value): > if value < HeatedRefrigeratedShippingContainer.MIN_CELSIUS: > raise ValueError("Temperature too cold!") > super().celsius = value > > > > > Now when I run the code : > > Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43) > [Clang 6.0 (clang-600.0.57)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> from shipping import * >>> h1 = > HeatedRefrigeratedShippingContainer.create_empty('YML', length_ft=40, > celsius=-18) > Traceback (most recent call last): > File "", line 1, in > File "/Users/aruprakshit/python_playground/shipping.py", line 23, in > create_empty > return cls(owner_code, length_ft, contents=None, *args, **keyword_args) > File "/Users/aruprakshit/python_playground/shipping.py", line 47, in > __init__ > self.celsius = celsius > File "/Users/aruprakshit/python_playground/shipping.py", line 92, in > celsius > super().celsius = value > AttributeError: 'super' object has no attribute 'celsius' > >>> > > > Why here super is denying the fact that it has no celsius setter, although > it has. While this code doesn?t work how can I solve this. The thing I am > trying here not to duplicate the validation of temperature which is already > in the setter property of the RefrigeratedShippingContainer class. > > > > > Thanks, > > Arup Rakshit > ar at zeit.io > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From eryksun at gmail.com Tue Mar 19 13:00:48 2019 From: eryksun at gmail.com (eryk sun) Date: Tue, 19 Mar 2019 12:00:48 -0500 Subject: Block Ctrl+S while running Python script at Windows console? In-Reply-To: References: <22ad5ada-99a8-43c8-8eda-938ab1942ad2@www.fastmail.com> Message-ID: On 3/19/19, Grant Edwards wrote: > > This has nothing to do with Python does it? > > Isn't Python is just writing to stdout and those write calls are > blocking due because the terminal emulator has stopped reading It turns out the original poster had quick-edit mode enabled and the pause was due to accidentally selecting text. A Python script can disable this mode via GetConsoleMode / SetConsoleMode [1], called via PyWin32 or ctypes. The original mode should be restored using an atexit function. With quick-edit mode disabled, selecting text requires enabling mark mode via the edit menu or Ctrl+M. If it had been a Ctrl+S pause, the only way to programmatically disable it for the current console is to disable line-input mode, which is what msvcrt.getwch() does temporarily. However, disabling line-input mode in general would break the REPL and input(). [1]: https://docs.microsoft.com/en-us/windows/console/getconsolemode > the other end of the pipe/pty/queue/buffer/whatever-it's-called- > in-windows? In Windows 8+, a console client has handles for files on the ConDrv device, which by default includes "Reference" (inherited reference to a console), "Connect" (generic functions, such as setting the title), "Input" (stdin), and "Output" (stdout, stderr). The host process (conhost.exe) has a handle for ConDrv as well, from which it receives IOCTL requests from its registered clients. Windows 10 (release 1809) also supports pseudoconsoles [2], which are roughly equivalent to Unix PTYs. The pseudoconsole interface is restricted to virtual-terminal streams over a pair of pipes, so the console's function-based API still has to be implemented for clients by an instance of conhost.exe. It basically looks like the following: Pseudoconsole Host <-- Pipe I/O --> conhost.exe <-- ConDrv I/O --> Clients. [2]: https://docs.microsoft.com/en-us/windows/console/pseudoconsoles From PythonList at danceswithmice.info Mon Mar 18 23:06:39 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Tue, 19 Mar 2019 16:06:39 +1300 Subject: I wrote a free book about TDD and clean architecture in Python In-Reply-To: References: Message-ID: On 17/03/19 12:29 AM, giordani.leonardo at gmail.com wrote: > I published on Leanpub a free book, "Clean Architectures in Python". It's a humble attempt to organise and expand some posts I published on my blog in the last years. > You can find it here: https://leanpub.com/clean-architectures-in-python > > The main content is divided in two parts, this is a brief overview of the table of contents > * Part 1 - Tools > - Chapter 1 - Introduction to TDD > - Chapter 2 - On unit testing > - Chapter 3 - Mocks > * Part 2 - The clean architecture > - Chapter 1 - Components of a clean architecture > - Chapter 2 - A basic example > - Chapter 3 - Error management > - Chapter 4 - Database repositories Unfortunately, the Kindle edition does not have a Table of Contents. One might make a joke about (the book's) "architecture", but such humor often fails to carry-across language-translations. A great effort, G! -- Regards =dn From philippesdixon at gmail.com Tue Mar 19 08:04:48 2019 From: philippesdixon at gmail.com (Philippe Dixon) Date: Tue, 19 Mar 2019 08:04:48 -0400 Subject: I wrote a free book about TDD and clean architecture in Python In-Reply-To: <254A3B83-4C18-41FC-B0CF-F4F1FE908030@zeit.io> References: <254A3B83-4C18-41FC-B0CF-F4F1FE908030@zeit.io> Message-ID: I actually came across this book last week looking for resources on best practices for structuring a python app. I plan on leaning on the material heavily as I've been tasked with converting some Jupyter Notebooks to a stand-alone application at work. Thanks for sharing this Leonardo. On Mon, Mar 18, 2019 at 12:30 PM Arup Rakshit wrote: > Hello, > > Thanks for writing this great book. I joined python community just couple > of weeks. > > > Thanks, > > Arup Rakshit > ar at zeit.io > > > > > On 16-Mar-2019, at 4:59 PM, giordani.leonardo at gmail.com wrote: > > > > Hi all, > > > > I published on Leanpub a free book, "Clean Architectures in Python". > It's a humble attempt to organise and expand some posts I published on my > blog in the last years. > > > > You can find it here: https://leanpub.com/clean-architectures-in-python > > > > The main content is divided in two parts, this is a brief overview of > the table of contents > > > > * Part 1 - Tools > > - Chapter 1 - Introduction to TDD > > - Chapter 2 - On unit testing > > - Chapter 3 - Mocks > > > > * Part 2 - The clean architecture > > - Chapter 1 - Components of a clean architecture > > - Chapter 2 - A basic example > > - Chapter 3 - Error management > > - Chapter 4 - Database repositories > > > > Some highlights: > > > > - The book is written with beginners in mind > > > > - It contains 3 full projects, two small ones to introduce TDD and > mocks, a bigger one to describe the clean architecture approach > > > > - Each project is explained step-by-step, and each step is linked to a > tag in a companion repository on GitHub > > > > The book is free, but if you want to contribute I will definitely > appreciate the help. My target is to encourage the discussion about > software architectures, both in the Python community and outside it. > > > > As of today the book has been downloaded by 7,500 readers. I hope you > will enjoy the book! if you do, please spread the news on your favourite > social network > > -- > > https://mail.python.org/mailman/listinfo/python-list > > -- > https://mail.python.org/mailman/listinfo/python-list > From phd at phdru.name Tue Mar 19 14:30:28 2019 From: phd at phdru.name (Oleg Broytman) Date: Tue, 19 Mar 2019 19:30:28 +0100 Subject: CheetahTemplate 3.2.1 Message-ID: <20190319183028.3htg7msrcjwglmyk@phdru.name> Hello! I'm pleased to announce version 3.2.1, the first bugfix release of branch 3.2 of CheetahTemplate3. What's new in CheetahTemplate3 ============================== Contributor for this release is Nicola Soranzo. Minor features: - Changed LoadTemplate.loadTemplate{Module,Class}: the loaded module's __name__ set to just the file name. - Use imp for Python 2, importlib for Python 3. Bug fixes: - Fix a bug in LoadTemplate.loadTemplate{Module,Class}: raise ImportError if the template was not found. CI: - At Travis deploy wheels for macOS. - At AppVeyor deploy wheels directly to PyPI. What is CheetahTemplate3 ======================== Cheetah3 is a free and open source template engine. It's a fork of the original CheetahTemplate library. Python 2.7 or 3.4+ is required. Where is CheetahTemplate3 ========================= Site: http://cheetahtemplate.org/ Development: https://github.com/CheetahTemplate3 Download: https://pypi.org/project/Cheetah3/3.2.1/ News and changes: http://cheetahtemplate.org/news.html StackOverflow: https://stackoverflow.com/questions/tagged/cheetah Example ======= Below is a simple example of some Cheetah code, as you can see it's practically Python. You can import, inherit and define methods just like in a regular Python module, since that's what your Cheetah templates are compiled to :) :: #from Cheetah.Template import Template #extends Template #set $people = [{'name' : 'Tom', 'mood' : 'Happy'}, {'name' : 'Dick', 'mood' : 'Sad'}, {'name' : 'Harry', 'mood' : 'Hairy'}] How are you feeling?
    #for $person in $people
  • $person['name'] is $person['mood']
  • #end for
Oleg. -- Oleg Broytman https://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From ar at zeit.io Tue Mar 19 15:15:34 2019 From: ar at zeit.io (Arup Rakshit) Date: Wed, 20 Mar 2019 00:45:34 +0530 Subject: Why can't access the property setter using the super? In-Reply-To: References: Message-ID: <43DECBAE-AF75-4122-BF6C-2254EA3B3CF1@zeit.io> Hello Ian, That seems like too much code involved. Is this how we do write inheritance in Python. Coming from Ruby and JS world I find Python inheritance mechanism confusing so far. :/ Thanks, Arup Rakshit ar at zeit.io > On 19-Mar-2019, at 9:32 PM, Ian Kelly wrote: > > Here's the thing: the result of calling super() is not an instance of the > base class. It's just a proxy object with a __getattribute__ implementation > that looks up class attributes in the base class, and knows how to pass > self to methods to simulate calling base class methods on an instance. This > works fine for looking up methods and property getters. It doesn't work so > well for simulating other behaviors, like setters, or comparisons, or > iteration, etc. > > A property is one example of what in Python is known as a descriptor, which > is described here: > https://docs.python.org/3/reference/datamodel.html#implementing-descriptors > > A settable property has a __set__ method per the descriptor protocol. When > you try to set an attribute with the name of the property, Python looks up > the name in the class dict, finds the property object, and then calls its > __set__ method. The class of the super proxy object, however, does not > contain this property, and because you're not doing an attribute lookup, > the super proxy's __getattribute__ does not get called. So all Python sees > is that you tried to set an attribute that doesn't exist on the proxy > object. > > The way I would suggest to get around this would be change your super() > call so that it looks up the property from the base class instead of trying > to set an attribute directly. For example, this should work: > > super(HeatedRefrigeratedShippingContainer, > self.__class__).celsius.fset(self, value) > > On Tue, Mar 19, 2019 at 9:12 AM Arup Rakshit wrote: > >> I have 3 classes which are connected to them through inheritance as you >> see in the below code: >> >> import iso6346 >> >> class ShippingContainer: >> """docstring for ShippingContainer""" >> >> HEIGHT_FT = 8.5 >> WIDTH_FT = 8.0 >> next_serial = 1337 >> >> @classmethod >> def _get_next_serial(cls): >> result = cls.next_serial >> cls.next_serial += 1 >> return result >> >> @staticmethod >> def _make_bic_code(owner_code, serial): >> return iso6346.create(owner_code=owner_code, >> serial=str(serial).zfill(6)) >> >> @classmethod >> def create_empty(cls, owner_code, length_ft, *args, **keyword_args): >> return cls(owner_code, length_ft, contents=None, *args, >> **keyword_args) >> >> # ... skipped >> >> def __init__(self, owner_code, length_ft, contents): >> self.contents = contents >> self.length_ft = length_ft >> self.bic = self._make_bic_code(owner_code=owner_code, >> >> serial=ShippingContainer._get_next_serial()) >> # ... skipped >> >> >> class RefrigeratedShippingContainer(ShippingContainer): >> MAX_CELSIUS = 4.0 >> FRIDGE_VOLUME_FT3 = 100 >> >> def __init__(self, owner_code, length_ft, contents, celsius): >> super().__init__(owner_code, length_ft, contents) >> self.celsius = celsius >> >> # ... skipped >> >> @staticmethod >> def _make_bic_code(owner_code, serial): >> return iso6346.create(owner_code=owner_code, >> serial=str(serial).zfill(6), >> category='R') >> @property >> def celsius(self): >> return self._celsius >> >> @celsius.setter >> def celsius(self, value): >> if value > RefrigeratedShippingContainer.MAX_CELSIUS: >> raise ValueError("Temperature too hot!") >> self._celsius = value >> >> # ... skipped >> >> >> class HeatedRefrigeratedShippingContainer(RefrigeratedShippingContainer): >> MIN_CELSIUS = -20.0 >> >> @RefrigeratedShippingContainer.celsius.setter >> def celsius(self, value): >> if value < HeatedRefrigeratedShippingContainer.MIN_CELSIUS: >> raise ValueError("Temperature too cold!") >> super().celsius = value >> >> >> >> >> Now when I run the code : >> >> Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43) >> [Clang 6.0 (clang-600.0.57)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >>>>> from shipping import * >>> h1 = >> HeatedRefrigeratedShippingContainer.create_empty('YML', length_ft=40, >> celsius=-18) >> Traceback (most recent call last): >> File "", line 1, in >> File "/Users/aruprakshit/python_playground/shipping.py", line 23, in >> create_empty >> return cls(owner_code, length_ft, contents=None, *args, **keyword_args) >> File "/Users/aruprakshit/python_playground/shipping.py", line 47, in >> __init__ >> self.celsius = celsius >> File "/Users/aruprakshit/python_playground/shipping.py", line 92, in >> celsius >> super().celsius = value >> AttributeError: 'super' object has no attribute 'celsius' >>>>> >> >> >> Why here super is denying the fact that it has no celsius setter, although >> it has. While this code doesn?t work how can I solve this. The thing I am >> trying here not to duplicate the validation of temperature which is already >> in the setter property of the RefrigeratedShippingContainer class. >> >> >> >> >> Thanks, >> >> Arup Rakshit >> ar at zeit.io >> >> >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue Mar 19 15:27:35 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Mar 2019 06:27:35 +1100 Subject: Why can't access the property setter using the super? In-Reply-To: <43DECBAE-AF75-4122-BF6C-2254EA3B3CF1@zeit.io> References: <43DECBAE-AF75-4122-BF6C-2254EA3B3CF1@zeit.io> Message-ID: On Wed, Mar 20, 2019 at 6:17 AM Arup Rakshit wrote: > > Hello Ian, > > That seems like too much code involved. Is this how we do write inheritance in Python. Coming from Ruby and JS world I find Python inheritance mechanism confusing so far. :/ > > Ian gave the longhand form, but you can omit the arguments to super() if you're using it inside the class definition. Something you may want to consider, though, is NOT overriding the parent's setter. Instead, have a validation step prior to the actual setting, which you could then override in a subclass. Something like this: class RefrigeratedShippingContainer(ShippingContainer): def _validate_temp(self, value): """Ensure that the given temperature is valid for this container Invariant: At all times, self.validate_temp(self.celsius) will not raise. """ if value > RefrigeratedShippingContainer.MAX_CELSIUS: raise ValueError("Temperature too hot!") @property def celsius(self): return self._celsius @celsius.setter def celsius(self, value): self.validate_temp(value) self._celsius = value class HeatedRefrigeratedShippingContainer(RefrigeratedShippingContainer): MIN_CELSIUS = -20.0 def _validate_temp(self, value): if value < HeatedRefrigeratedShippingContainer.MIN_CELSIUS: raise ValueError("Temperature too cold!") super()._validate_temp(value) Now, your property function doesn't need to care WHAT the validation is, it just requests validation. You can redefine the validation logic without changing anything else. ChrisA From Gronicus at SGA.Ninja Tue Mar 19 14:23:46 2019 From: Gronicus at SGA.Ninja (Steve) Date: Tue, 19 Mar 2019 14:23:46 -0400 Subject: Can my python program send me a text message? Message-ID: <003a01d4de80$e49b7340$add259c0$@SGA.Ninja> I have a program that triggers a reminder timer. When that timer is done, I would like to receive a text message on my phone to tell me that it is time to reset the experiment. Can this be done using Python? Steve From arj.python at gmail.com Tue Mar 19 15:33:11 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 19 Mar 2019 23:33:11 +0400 Subject: Can my python program send me a text message? In-Reply-To: <003a01d4de80$e49b7340$add259c0$@SGA.Ninja> References: <003a01d4de80$e49b7340$add259c0$@SGA.Ninja> Message-ID: - 1) use pi with gsm module. or - 2) find some free sms api for python then use Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius From rosuav at gmail.com Tue Mar 19 15:35:09 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Mar 2019 06:35:09 +1100 Subject: Can my python program send me a text message? In-Reply-To: <003a01d4de80$e49b7340$add259c0$@SGA.Ninja> References: <003a01d4de80$e49b7340$add259c0$@SGA.Ninja> Message-ID: On Wed, Mar 20, 2019 at 6:31 AM Steve wrote: > > I have a program that triggers a reminder timer. When that timer is done, I would like to receive a text message on my phone to tell me that it is time to reset the experiment. > > Can this be done using Python? > Yes! There are APIs that will help you with that. Search the web for "text message api" and see what you can find. (Be aware that some of them will ask you to pay money.) Then pick one of them and see if you can access it from Python. Most of them will be HTTP-based APIs, so you will do well to use the "requests" module. ChrisA From larry.martell at gmail.com Tue Mar 19 15:45:49 2019 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 19 Mar 2019 15:45:49 -0400 Subject: Can my python program send me a text message? In-Reply-To: <003a01d4de80$e49b7340$add259c0$@SGA.Ninja> References: <003a01d4de80$e49b7340$add259c0$@SGA.Ninja> Message-ID: On Tue, Mar 19, 2019 at 3:30 PM Steve wrote: > > I have a program that triggers a reminder timer. When that timer is done, I would like to receive a text message on my phone to tell me that it is time to reset the experiment. > > Can this be done using Python? You can send a text with email if you know the carrier: Alltel [insert 10-digit number]@message.alltel.com AT&T [insert 10-digit number]@txt.att.net Boost Mobile [insert 10-digit number]@myboostmobile.com Cricket Wireless [insert 10-digit number]@mms.cricketwireless.net Sprint [insert 10-digit number]@messaging.sprintpcs.com T-Mobile [insert 10-digit number]@tmomail.net U.S. Cellular [insert 10-digit number]@email.uscc.net Verizon [insert 10-digit number]@vtext.com Virgin Mobile [insert 10-digit number]@vmobl.com From 2QdxY4RzWzUUiLuE at potatochowder.com Tue Mar 19 15:48:13 2019 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Tue, 19 Mar 2019 14:48:13 -0500 Subject: Can my python program send me a text message? In-Reply-To: References: <003a01d4de80$e49b7340$add259c0$@SGA.Ninja> Message-ID: <91313296-b513-5d88-0df6-fad7ce81d9a9@potatochowder.com> On 3/19/19 2:35 PM, Chris Angelico wrote: > On Wed, Mar 20, 2019 at 6:31 AM Steve wrote: >> >> I have a program that triggers a reminder timer. When that timer is done, I would like to receive a text message on my phone to tell me that it is time to reset the experiment. >> >> Can this be done using Python? >> > > Yes! There are APIs that will help you with that. Search the web for > "text message api" and see what you can find. (Be aware that some of > them will ask you to pay money.) Then pick one of them and see if you > can access it from Python. Some telephone carriers provide cost-free email-to-SMS gateways. > Most of them will be HTTP-based APIs, so you will do well to use the > "requests" module. Send email over SMTP; use Python's standard smtplib module. Dan From hjp-python at hjp.at Tue Mar 19 16:07:51 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 19 Mar 2019 21:07:51 +0100 Subject: Block Ctrl+S while running Python script at Windows console? In-Reply-To: References: <22ad5ada-99a8-43c8-8eda-938ab1942ad2@www.fastmail.com> Message-ID: <20190319200751.syhbtyir3qqjt2np@hjp.at> On 2019-03-19 14:22:10 -0000, Grant Edwards wrote: > On 2019-03-18, Malcolm Greene wrote: > > Wondering if there's a way to have my Python scripts ignore these > > Ctrl+S signals or if this behavior is outside of my Python script's > > control. > > This has nothing to do with Python does it? > > Isn't Python is just writing to stdout and those write calls are > blocking due because the terminal emulator has stopped reading the > other end of the pipe/pty/queue/buffer/whatever-it's-called-in-windows? Yes, but there might be a way to control this behaviour from Python. On Unix systems you can use the termios functions to turn flow control on and off. This doesn't help you on Windows, but curses also has raw() and noraw() functions which do that (among other things) and might work on Windows, too. However, curses does a lot more than just control flow control, so it may not be appropriate for the OP's problem. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From adam.preble at gmail.com Tue Mar 19 16:18:02 2019 From: adam.preble at gmail.com (adam.preble at gmail.com) Date: Tue, 19 Mar 2019 13:18:02 -0700 (PDT) Subject: REPL, global, and local scoping Message-ID: I got hit on the head and decided to try to write something of a Python interpreter for embedding. I'm starting to get into the ugly stuff like scoping. This has been a good way to learn the real deep details of the language. Here's a situation: >>> meow = 10 >>> def vartest(): ... x = 1 ... y = 2 ... def first(): ... x = 3 ... meow = 11 ... return x ... def second(): ... y = 4 ... meow = 12 ... return y ... return first() + second() + x + y + meow ... >>> vartest() 20 first() and second() are messing with their own versions of x and y. Side note: the peephole optimizer doesn't just slap a 3 and 4 on the stack, respectively, and just return that. It'll actually do a STORE_NAME to 0 for each. The meow variable is more peculiar. The first() and second() inner functions are working on their own copy. However, vartest() is using the one from the calling scope, which is the REPL. I can see in vartest() that it's using a LOAD_GLOBAL for that, yet first() and second() don't go searching upstairs for a meow variable. What is the basis behind this? I tripped on this in my unit tests when I was trying to note that a class' constructor had run successfully without getting into poking the class' variables. I was trying to have it set a variable in the parent scope that I'd just query after the test. It looks like in practice, that should totally not work at all: >>> meow = 10 >>> class Foo: ... def __init__(self): ... meow = 11 ... >>> f = Foo() >>> meow 10 ...and it's on me to carve out a throwaway inner meow variable. But hey, let's kick meow up to the class level: >>> meow = 10 >>> class Foo: ... meow = 11 ... def __init__(self): ... pass ... >>> f = Foo() >>> meow 10 So I guess it's a different ballgame for classes entirely. What are the rules in play here for: 1. A first-level function knowing to use a variable globally 2. A Second-level function using the name locally and uniquely 3. Classes having no visibility to upper-level variables at all by default From fw at deneb.enyo.de Tue Mar 19 16:32:34 2019 From: fw at deneb.enyo.de (Florian Weimer) Date: Tue, 19 Mar 2019 21:32:34 +0100 Subject: Reversible malformed UTF-8 to malformed UTF-16 encoding Message-ID: <87ftrik3kt.fsf@mid.deneb.enyo.de> I've seen occasional proposals like this one coming up: | I therefore suggested 1999-11-02 on the unicode at unicode.org mailing | list the following approach. Instead of using U+FFFD, simply encode | malformed UTF-8 sequences as malformed UTF-16 sequences. Malformed | UTF-8 sequences consist excludively of the bytes 0x80 - 0xff, and | each of these bytes can be represented using a 16-bit value from the | UTF-16 low-half surrogate zone U+DC80 to U+DCFF. Thus, the overlong | "K" (U+004B) 0xc1 0x8b from the above example would be represented | in UTF-16 as U+DCC1 U+DC8B. If we simply make sure that every UTF-8 | encoded surrogate character is also treated like a malformed | sequence, then there is no way that a single high-half surrogate | could precede the encoded malformed sequence and cause a valid | UTF-16 sequence to emerge. Has this ever been implemented in any Python version? I seem to remember something like that, but all I could find was me talking about this in 2000. It's not entirely clear whether this is a good idea as the default encoding for security reasons, but it might be nice to be able to read XML or JSON which is not quite properly encoded, only nearly so, without treating it as ISO-8859-1 or some other arbitrarily chose single-byte character set. From rosuav at gmail.com Tue Mar 19 16:48:00 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Mar 2019 07:48:00 +1100 Subject: REPL, global, and local scoping In-Reply-To: References: Message-ID: On Wed, Mar 20, 2019 at 7:23 AM wrote: > > I got hit on the head and decided to try to write something of a Python interpreter for embedding. I'm starting to get into the ugly stuff like scoping. This has been a good way to learn the real deep details of the language. Here's a situation: > > >>> meow = 10 > >>> def vartest(): > ... x = 1 > ... y = 2 > ... def first(): > ... x = 3 > ... meow = 11 > ... return x > ... def second(): > ... y = 4 > ... meow = 12 > ... return y > ... return first() + second() + x + y + meow > ... > >>> vartest() > 20 > > first() and second() are messing with their own versions of x and y. Side note: the peephole optimizer doesn't just slap a 3 and 4 on the stack, respectively, and just return that. It'll actually do a STORE_NAME to 0 for each. The meow variable is more peculiar. The first() and second() inner functions are working on their own copy. However, vartest() is using the one from the calling scope, which is the REPL. > > I can see in vartest() that it's using a LOAD_GLOBAL for that, yet first() and second() don't go searching upstairs for a meow variable. What is the basis behind this? > Both first() and second() assign to the name "meow", so the name is considered local to each of them. In vartest(), the name isn't assigned, so it looks for an outer scope. (Side note: the peephole optimizer COULD be written to simplify that case, and there's no reason it can't in the future. Probably wouldn't save all that much work though.) > I tripped on this in my unit tests when I was trying to note that a class' constructor had run successfully without getting into poking the class' variables. I was trying to have it set a variable in the parent scope that I'd just query after the test. > > It looks like in practice, that should totally not work at all: > >>> meow = 10 > >>> class Foo: > ... def __init__(self): > ... meow = 11 > ... > >>> f = Foo() > >>> meow > 10 > > ...and it's on me to carve out a throwaway inner meow variable. But hey, let's kick meow up to the class level: You've made "meow" a local variable here. If you want it to be an attribute of the object, you would need to apply it to the object itself ("self.meow = 11"). > >>> meow = 10 > >>> class Foo: > ... meow = 11 > ... def __init__(self): > ... pass > ... > >>> f = Foo() > >>> meow > 10 This has created a class attribute. If you inspect "Foo.meow" (or "f.meow", because of the way attribute lookup works), you'll see the 11. > So I guess it's a different ballgame for classes entirely. What are the rules in play here for: > 1. A first-level function knowing to use a variable globally > 2. A Second-level function using the name locally and uniquely > 3. Classes having no visibility to upper-level variables at all by default In all cases, you can use the declaration "global meow" to affect the global (module-level) name. In the inner-function case, you can also use "nonlocal x" to affect the "x" in the outer function. This applies any time you *assign to* a name; if you just reference it, the lookup will extend outwards in the most expected way. ChrisA From giordani.leonardo at gmail.com Tue Mar 19 14:18:56 2019 From: giordani.leonardo at gmail.com (Leonardo Giordani) Date: Tue, 19 Mar 2019 11:18:56 -0700 (PDT) Subject: I wrote a free book about TDD and clean architecture in Python In-Reply-To: References: Message-ID: <26756bf9-a371-4545-b4d5-a258501da415@googlegroups.com> Ha ha ha, yes I get it! =) I'm sorry, that depends entirely on the LeanPub processing chain (I believe, I'll have a look just to be sure). I hope the book will be useful even with this little issue. Thanks for reading it! From infneurodcr.mtz at infomed.sld.cu Tue Mar 19 15:46:17 2019 From: infneurodcr.mtz at infomed.sld.cu (Informatico de Neurodesarrollo) Date: Tue, 19 Mar 2019 15:46:17 -0400 Subject: tkinter In-Reply-To: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> References: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> Message-ID: <6f32e3f1-627d-391e-0d9a-a2d9a62be615@infomed.sld.cu> Thanks for all yours recommendations, finally I was successfully finished my first project about tkinter (and I hope, not the last). Here is the finally code: #!/usr/bin/env python # #? DetectConn_2_0.py # # from tkinter import * import time, socket def isInternet(): ??? ??? testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM) ??? ?? # Force a time limit to conect to the host (5 seg), may be more or less ???? ??? testConn.settimeout(5) ??? ???? output = testConn.connect_ex(('10.44.0.1', 80)) ??? ??? if output == 0: ??? ??? ??? return True ??? ??? else: ??? ??? ??? return False ??? ??? testConn.close() def colorupdate(): ??? if isInternet(): ??? ??? root.config(background="#38EB5C") ??? else: ??? ??? root.config(background="#F50743") ??? root.after(5000, colorupdate) root = Tk() root.title("Connection") root.geometry("80x50") root.resizable(width=False, height=False) colorupdate() root.mainloop() Thanks again -- Ing. Jes?s Reyes Piedra Admin Red Neurodesarrollo,C?rdenas La caja dec?a:"Requiere windows 95 o superior"... Entonces instal? LINUX. -- Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas Infomed: http://www.sld.cu/ From python at mrabarnett.plus.com Tue Mar 19 17:49:20 2019 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 19 Mar 2019 21:49:20 +0000 Subject: Reversible malformed UTF-8 to malformed UTF-16 encoding In-Reply-To: <87ftrik3kt.fsf@mid.deneb.enyo.de> References: <87ftrik3kt.fsf@mid.deneb.enyo.de> Message-ID: <17e4516e-5dfb-5179-2187-2165e29ec373@mrabarnett.plus.com> On 2019-03-19 20:32, Florian Weimer wrote: > I've seen occasional proposals like this one coming up: > > | I therefore suggested 1999-11-02 on the unicode at unicode.org mailing > | list the following approach. Instead of using U+FFFD, simply encode > | malformed UTF-8 sequences as malformed UTF-16 sequences. Malformed > | UTF-8 sequences consist excludively of the bytes 0x80 - 0xff, and > | each of these bytes can be represented using a 16-bit value from the > | UTF-16 low-half surrogate zone U+DC80 to U+DCFF. Thus, the overlong > | "K" (U+004B) 0xc1 0x8b from the above example would be represented > | in UTF-16 as U+DCC1 U+DC8B. If we simply make sure that every UTF-8 > | encoded surrogate character is also treated like a malformed > | sequence, then there is no way that a single high-half surrogate > | could precede the encoded malformed sequence and cause a valid > | UTF-16 sequence to emerge. > > > > Has this ever been implemented in any Python version? I seem to > remember something like that, but all I could find was me talking > about this in 2000. > > It's not entirely clear whether this is a good idea as the default > encoding for security reasons, but it might be nice to be able to read > XML or JSON which is not quite properly encoded, only nearly so, > without treating it as ISO-8859-1 or some other arbitrarily chose > single-byte character set. > Python 3 has "surrogate escape". Have a read of PEP 383 -- Non-decodable Bytes in System Character Interfaces. From python at mrabarnett.plus.com Tue Mar 19 17:55:15 2019 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 19 Mar 2019 21:55:15 +0000 Subject: tkinter In-Reply-To: <6f32e3f1-627d-391e-0d9a-a2d9a62be615@infomed.sld.cu> References: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> <6f32e3f1-627d-391e-0d9a-a2d9a62be615@infomed.sld.cu> Message-ID: On 2019-03-19 19:46, Informatico de Neurodesarrollo wrote: > Thanks for all yours recommendations, finally I was successfully > finished my first project about tkinter (and I hope, not the last). > > Here is the finally code: > > #!/usr/bin/env python > # > #? DetectConn_2_0.py > # > # > > from tkinter import * > import time, socket > > def isInternet(): > ??? ??? testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM) > ??? ?? # Force a time limit to conect to the host (5 seg), may be more > or less > ???? ??? testConn.settimeout(5) > ??? ???? output = testConn.connect_ex(('10.44.0.1', 80)) The following lines will cause a return from the function, so the testConn.close() line will never be reached. Fortunately, the socket will be closed anyway, when the garbage collection occurs. > ??? ??? if output == 0: > ??? ??? ??? return True > ??? ??? else: > ??? ??? ??? return False > ??? ??? testConn.close() > > def colorupdate(): > ??? if isInternet(): > ??? ??? root.config(background="#38EB5C") > ??? else: > ??? ??? root.config(background="#F50743") > ??? root.after(5000, colorupdate) > > root = Tk() > root.title("Connection") > root.geometry("80x50") > root.resizable(width=False, height=False) > > colorupdate() > root.mainloop() > > > Thanks again > > From fw at deneb.enyo.de Tue Mar 19 18:53:41 2019 From: fw at deneb.enyo.de (Florian Weimer) Date: Tue, 19 Mar 2019 23:53:41 +0100 Subject: Reversible malformed UTF-8 to malformed UTF-16 encoding In-Reply-To: <17e4516e-5dfb-5179-2187-2165e29ec373@mrabarnett.plus.com> (MRAB's message of "Tue, 19 Mar 2019 21:49:20 +0000") References: <87ftrik3kt.fsf@mid.deneb.enyo.de> <17e4516e-5dfb-5179-2187-2165e29ec373@mrabarnett.plus.com> Message-ID: <877ecufpca.fsf@mid.deneb.enyo.de> * MRAB: > On 2019-03-19 20:32, Florian Weimer wrote: >> I've seen occasional proposals like this one coming up: >> >> | I therefore suggested 1999-11-02 on the unicode at unicode.org mailing >> | list the following approach. Instead of using U+FFFD, simply encode >> | malformed UTF-8 sequences as malformed UTF-16 sequences. Malformed >> | UTF-8 sequences consist excludively of the bytes 0x80 - 0xff, and >> | each of these bytes can be represented using a 16-bit value from the >> | UTF-16 low-half surrogate zone U+DC80 to U+DCFF. Thus, the overlong >> | "K" (U+004B) 0xc1 0x8b from the above example would be represented >> | in UTF-16 as U+DCC1 U+DC8B. If we simply make sure that every UTF-8 >> | encoded surrogate character is also treated like a malformed >> | sequence, then there is no way that a single high-half surrogate >> | could precede the encoded malformed sequence and cause a valid >> | UTF-16 sequence to emerge. >> >> >> >> Has this ever been implemented in any Python version? I seem to >> remember something like that, but all I could find was me talking >> about this in 2000. > Python 3 has "surrogate escape". Have a read of PEP 383 -- Non-decodable > Bytes in System Character Interfaces. Thanks, this is the information I was looking for. From PythonList at danceswithmice.info Tue Mar 19 18:05:10 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Wed, 20 Mar 2019 11:05:10 +1300 Subject: I wrote a free book about TDD and clean architecture in Python In-Reply-To: <26756bf9-a371-4545-b4d5-a258501da415@googlegroups.com> References: <26756bf9-a371-4545-b4d5-a258501da415@googlegroups.com> Message-ID: <4f8e14d8-46c6-af20-91b7-2455104801a9@DancesWithMice.info> On 20/03/19 7:18 AM, Leonardo Giordani wrote: > Ha ha ha, yes I get it! =) I'm sorry, that depends entirely on the LeanPub processing chain (I believe, I'll have a look just to be sure). I hope the book will be useful even with this little issue. Thanks for reading it! To be fair, that was one of my assumptions - publishers often imagine that a simple tool will convert between formats. (Um, no!) However, if they think it acceptable to publish a learned text without a ToC (or an Index? - haven't read that far), then I'd recommend finding another publisher who will properly respect your efforts! "Lean" shouldn't mean "lazy"! Yes, I'm happy reading from cover-to-cover. Unfortunately, not being able to refer back to (say) the Mocks chapter, means it will be of little utility (to me) in-future. After all, if I access your blog on-line, can't I use a search facility to find a remembered post/'chapter'? (ComSc: sequential/serial cf direct-access!) Publishing criticisms aside, thank you! -- Regards =dn From adam.preble at gmail.com Tue Mar 19 22:28:30 2019 From: adam.preble at gmail.com (adam.preble at gmail.com) Date: Tue, 19 Mar 2019 19:28:30 -0700 (PDT) Subject: REPL, global, and local scoping In-Reply-To: References: Message-ID: <0962fe3f-302b-4375-a888-e9dab2fe3ee7@googlegroups.com> On Tuesday, March 19, 2019 at 3:48:27 PM UTC-5, Chris Angelico wrote: > > I can see in vartest() that it's using a LOAD_GLOBAL for that, yet first() and second() don't go searching upstairs for a meow variable. What is the basis behind this? > > > > Both first() and second() assign to the name "meow", so the name is > considered local to each of them. In vartest(), the name isn't > assigned, so it looks for an outer scope. Thanks for the responses. I wanted to poke on this part just a little bit more. I want to mimic the proper behavior without having to go back to it repeatedly. Let's say I'm parsing this code and generating the byte code for it. I run into meow on the right side of an expression but never the left. At this point, do I always generate a LOAD_GLOBAL opcode? Is that done whether or not I know if the variable is defined in a higher scope? That's what it looks like from renaming it to something I didn't define. I just want to double check. On the interpreter side seeing the opcode, does that generally mean I walk up the variables I have in higher frames until I either run out of them or find it? Does that mean defining "global meow" basically states "always use LOAD/STORE_GLOBAL opcodes for this one, even if it shows up on the left side of an assignment first?" From rosuav at gmail.com Tue Mar 19 22:49:21 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Mar 2019 13:49:21 +1100 Subject: REPL, global, and local scoping In-Reply-To: <0962fe3f-302b-4375-a888-e9dab2fe3ee7@googlegroups.com> References: <0962fe3f-302b-4375-a888-e9dab2fe3ee7@googlegroups.com> Message-ID: On Wed, Mar 20, 2019 at 1:31 PM wrote: > > On Tuesday, March 19, 2019 at 3:48:27 PM UTC-5, Chris Angelico wrote: > > > I can see in vartest() that it's using a LOAD_GLOBAL for that, yet first() and second() don't go searching upstairs for a meow variable. What is the basis behind this? > > > > > > > Both first() and second() assign to the name "meow", so the name is > > considered local to each of them. In vartest(), the name isn't > > assigned, so it looks for an outer scope. > > Thanks for the responses. I wanted to poke on this part just a little bit more. I want to mimic the proper behavior without having to go back to it repeatedly. > > Let's say I'm parsing this code and generating the byte code for it. I run into meow on the right side of an expression but never the left. At this point, do I always generate a LOAD_GLOBAL opcode? Is that done whether or not I know if the variable is defined in a higher scope? That's what it looks like from renaming it to something I didn't define. I just want to double check. > > On the interpreter side seeing the opcode, does that generally mean I walk up the variables I have in higher frames until I either run out of them or find it? > > Does that mean defining "global meow" basically states "always use LOAD/STORE_GLOBAL opcodes for this one, even if it shows up on the left side of an assignment first?" > I would recommend parsing in two broad steps, as CPython does: 1) Take the source code and turn it into an abstract syntax tree (AST). This conceptualizes the behaviour of the code more-or-less the way the programmer wrote it. 2) Implement the AST in byte-code. The AST for your first() function looks something like this: FunctionDef( name='first', args=arguments(args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[ Assign( targets=[Name(id='x', ctx=Store())], value=Constant(value=3, kind=None), type_comment=None ), Assign( targets=[Name(id='meow', ctx=Store())], value=Constant(value=11, kind=None), type_comment=None ), Return( value=Name(id='x', ctx=Load()) ) ], decorator_list=[], returns=None, type_comment=None ) (I got this by using ast.parse() and ast.dump() from the CPython 3.8 standard library. If you use a different version or interpreter, it may look slightly different, but it'll be broadly similar.) Since there are Assign entries with targets saying Name "x" and Name "meow", you know that both those names are local to the function. So you create local-to-function bytecode. But if you had a "global meow" statement in that function (which translates to an AST node of Global(names=['meow']) ), you would create STORE_GLOBAL opcodes, and similarly, any names not assigned in the local scope would be looked up globally. Of course, life's never this simple, and there are myriad other considerations. But hopefully that will help with an understanding of what Python's doing. ChrisA From Gronicus at SGA.Ninja Tue Mar 19 22:56:25 2019 From: Gronicus at SGA.Ninja (Steve) Date: Tue, 19 Mar 2019 22:56:25 -0400 Subject: Can my python program send me a text message? In-Reply-To: References: <003a01d4de80$e49b7340$add259c0$@SGA.Ninja> Message-ID: <002701d4dec8$822957c0$867c0740$@SGA.Ninja> Thanks for all the suggestions. It is going to take a while to sift through them. I will continue to watch for more discussion and will check back in if/when I get something working or if I get stuck. Steve Footnote: Fight the hand that feeds the hate. -----Original Message----- From: Python-list On Behalf Of Larry Martell Sent: Tuesday, March 19, 2019 3:46 PM To: Python Subject: Re: Can my python program send me a text message? On Tue, Mar 19, 2019 at 3:30 PM Steve wrote: > > I have a program that triggers a reminder timer. When that timer is done, I would like to receive a text message on my phone to tell me that it is time to reset the experiment. > > Can this be done using Python? You can send a text with email if you know the carrier: Alltel [insert 10-digit number]@message.alltel.com AT&T [insert 10-digit number]@txt.att.net Boost Mobile [insert 10-digit number]@myboostmobile.com Cricket Wireless [insert 10-digit number]@mms.cricketwireless.net Sprint [insert 10-digit number]@messaging.sprintpcs.com T-Mobile [insert 10-digit number]@tmomail.net U.S. Cellular [insert 10-digit number]@email.uscc.net Verizon [insert 10-digit number]@vtext.com Virgin Mobile [insert 10-digit number]@vmobl.com -- https://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Wed Mar 20 01:05:39 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 20 Mar 2019 01:05:39 -0400 Subject: Can my python program send me a text message? In-Reply-To: <002701d4dec8$822957c0$867c0740$@SGA.Ninja> References: <003a01d4de80$e49b7340$add259c0$@SGA.Ninja> <002701d4dec8$822957c0$867c0740$@SGA.Ninja> Message-ID: On 3/19/2019 10:56 PM, Steve wrote: > Thanks for all the suggestions. It is going to take a while to sift through > them. I will continue to watch for more discussion and will check back in > if/when I get something working or if I get stuck. > > Steve > > > Footnote: > Fight the hand that feeds the hate. > > -----Original Message----- > From: Python-list On > Behalf Of Larry Martell > Sent: Tuesday, March 19, 2019 3:46 PM > To: Python > Subject: Re: Can my python program send me a text message? > > On Tue, Mar 19, 2019 at 3:30 PM Steve wrote: >> >> I have a program that triggers a reminder timer. When that timer is done, > I would like to receive a text message on my phone to tell me that it is > time to reset the experiment. >> >> Can this be done using Python? > > You can send a text with email if you know the carrier: > > Alltel [insert 10-digit number]@message.alltel.com > AT&T [insert 10-digit number]@txt.att.net > Boost Mobile [insert 10-digit number]@myboostmobile.com > Cricket Wireless [insert 10-digit number]@mms.cricketwireless.net > Sprint [insert 10-digit number]@messaging.sprintpcs.com > T-Mobile [insert 10-digit number]@tmomail.net > U.S. Cellular [insert 10-digit number]@email.uscc.net > Verizon [insert 10-digit number]@vtext.com > Virgin Mobile [insert 10-digit number]@vmobl.com Since I know my carrier, I tried this and it works. -- Terry Jan Reedy From none at gmail.com Wed Mar 20 04:18:04 2019 From: none at gmail.com (ast) Date: Wed, 20 Mar 2019 09:18:04 +0100 Subject: File not closed Message-ID: <5c91f73d$0$31407$426a74cc@news.free.fr> Hello In the following snippet, a file is opened but without any variable referring to it. So the file can't be closed. [line.split(":")[0] for line in open('/etc/passwd') if line.strip() and not line.startswith("#")] What do you think about this practice ? From __peter__ at web.de Wed Mar 20 04:42:23 2019 From: __peter__ at web.de (Peter Otten) Date: Wed, 20 Mar 2019 09:42:23 +0100 Subject: File not closed References: <5c91f73d$0$31407$426a74cc@news.free.fr> Message-ID: ast wrote: > Hello > > In the following snippet, a file is opened but > without any variable referring to it. > So the file can't be closed. The file will be closed implicitly when the file object gets garbage- collected: $ python3 Python 3.4.3 (default, Nov 12 2018, 22:25:49) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> f = open("/etc/passwd") >>> [1]+ Stopped python3 $ lsof /etc/passwd COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME python3 6815 peter 3r REG 8,7 2899 8786346 /etc/passwd $ fg python3 >>> del f >>> [1]+ Stopped python3 $ lsof /etc/passwd $ > [line.split(":")[0] > for line in open('/etc/passwd') > if line.strip() and not line.startswith("#")] > > What do you think about this practice ? While in most cases relying on the gc does not do any harm I still prefer to close the file explicitly: with open("/etc/passwd") as instream: stuff = [... for line in instream ...] From turkcan at metu.edu.tr Wed Mar 20 03:55:02 2019 From: turkcan at metu.edu.tr (=?UTF-8?Q?T=c3=bcrkcan_Kurt?=) Date: Wed, 20 Mar 2019 10:55:02 +0300 Subject: nltk in 3.7.2 for win 10 64 bit Message-ID: <20d9abfa-4628-8f0e-cf47-6d8437140198@metu.edu.tr> is there a way to install nltk in win 10 64 bit in python 3.7.2 ? -- Te?ekk?rler, iyi ?al??malar. ODTU - B?DB Lisansl? Yaz?l?m Sorumlusu swbidb at metu.edu.tr Tel: 210 3311 From Amit.Laish at ge.com Wed Mar 20 06:18:16 2019 From: Amit.Laish at ge.com (Laish, Amit (GE Digital)) Date: Wed, 20 Mar 2019 10:18:16 +0000 Subject: Potential Security Bug Message-ID: Hello, I?m Amit Laish, a security researcher from GE Digital. During one of our assessments we discovered something that we consider a bug with security implications which can cause a denial of service by disk exhausting, and we would like to share it with you, and hear you opinion about it. Link for the required files: https://drive.google.com/open?id=1QxItN7cj0J9LIMqYa0SmmckeQrxSxkBC 1. 20GB.zip ? contains 200 files that each file is 100MB, after decompression the size is 20GB. 2. create_zip.py ? create new zip name malicious.zip which contains fake value of the uncompressed size header. 3. poc.py ? extracts the malicious archive Denial of Service via Decompression in Zipfile Library Background The Zipfile library can be used to extract data from compressed archives. Each file has a metadata that contains information regarding the file, such as uncompressed size, packed size, and more. The decompression progress should extract the data based on the information in the uncompressed data size header and check if the extracted data is equal to the size in the uncompressed data header. The problem The Zipfile library does not use the header of uncompressed size when extracting data from compressed archives. As a result, an attacker can craft a malicious compressed archive file that contains a fake value in the uncompressed size header and combine specific compressed data, which makes the decompressed data?s size more than the system can handle, and thus, cause a denial of service. [cid:image001.jpg at 01D4DF16.FDA28C70] Figure 1 ? Unpacked size is 200 bytes and after decompression 20GB of the disk space is taken The red team successfully exploited the vulnerability and caused a denial of service. Implications Malicious users can use this method and distribute the archive, and once the victim or application that relies on the uncompressed size header value decompresses it, the whole disk space is exhausted, causing a denial of service. This attack may cause sensitive services to stop working. How to reproduce Note: Both archive file and the malicious script to reproduce the attack are attached to the report. 1. Run create_zip.py file, which changes the header of the uncompressed size to 1 byte and saves it to new file archive called malicious.zip. 2. Run poc.py file to extract the malicious archive. 3. If the vulnerability exists, the disk?s space is approximately taken by 20 GB. Recommendation The extraction progress should use the metadata header that indicates the uncompressed size for each file or should extract the smaller value between the metadata and the file?s size. Thanks, Amit Laish ? GE Digital. From infneurodcr.mtz at infomed.sld.cu Wed Mar 20 09:00:37 2019 From: infneurodcr.mtz at infomed.sld.cu (Informatico de Neurodesarrollo) Date: Wed, 20 Mar 2019 09:00:37 -0400 Subject: tkinter In-Reply-To: References: <3bc49d5f-7fb9-a3cf-7fdd-7d57342a4f15@infomed.sld.cu> <6f32e3f1-627d-391e-0d9a-a2d9a62be615@infomed.sld.cu> Message-ID: <52040837-a4a7-f50e-4d07-abed29b8fe98@infomed.sld.cu> Thanks MRAB, for your advice. I will have close the connection before, the code fixed are below. def isInternet(): ??? ??? testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM) ??? ??? testConn.settimeout(5) ??? ??? output = testConn.connect_ex(('8.8.8.8', 80)) ??? ??? testConn.close() <----------------------------------- ??? ??? if output == 0: ??? ??? ??? return True ??? ??? else: ??? ??? ??? return False El 19/03/19 a las 17:55, MRAB escribi?: > On 2019-03-19 19:46, Informatico de Neurodesarrollo wrote: >> Thanks for all yours recommendations, finally I was successfully >> finished my first project about tkinter (and I hope, not the last). >> >> Here is the finally code: >> >> #!/usr/bin/env python >> # >> #? DetectConn_2_0.py >> # >> # >> >> from tkinter import * >> import time, socket >> >> def isInternet(): >> ? ??? ??? testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM) >> ? ??? ?? # Force a time limit to conect to the host (5 seg), may be more >> or less >> ? ???? ??? testConn.settimeout(5) >> ? ??? ???? output = testConn.connect_ex(('10.44.0.1', 80)) > > The following lines will cause a return from the function, so the > testConn.close() line will never be reached. > > Fortunately, the socket will be closed anyway, when the garbage > collection occurs. > >> ? ??? ??? if output == 0: >> ? ??? ??? ??? return True >> ? ??? ??? else: >> ? ??? ??? ??? return False >> ? ??? ??? testConn.close() >> >> def colorupdate(): >> ? ??? if isInternet(): >> ? ??? ??? root.config(background="#38EB5C") >> ? ??? else: >> ? ??? ??? root.config(background="#F50743") >> ? ??? root.after(5000, colorupdate) >> >> root = Tk() >> root.title("Connection") >> root.geometry("80x50") >> root.resizable(width=False, height=False) >> >> colorupdate() >> root.mainloop() >> >> >> Thanks again >> >> -- Ing. Jes?s Reyes Piedra Admin Red Neurodesarrollo,C?rdenas La caja dec?a:"Requiere windows 95 o superior"... Entonces instal? LINUX. -- Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas Infomed: http://www.sld.cu/ From rhodri at kynesim.co.uk Wed Mar 20 09:19:52 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 20 Mar 2019 13:19:52 +0000 Subject: Can my python program send me a text message? In-Reply-To: References: <003a01d4de80$e49b7340$add259c0$@SGA.Ninja> Message-ID: <9f35d60d-b28a-a280-3635-226b239a8754@kynesim.co.uk> On 19/03/2019 19:33, Abdur-Rahmaan Janhangeer wrote: > - 1) use pi with gsm module. > or > - 2) find some free sms api for python then use Slightly off-topic, but you (the OP) should be aware that carriers do not guarantee that texts will be delivered in a timely manner. In fact they don't guarantee to deliver the texts at all. We have had clients become very unhappy when confronted with the reality of that. -- Rhodri James *-* Kynesim Ltd From grant.b.edwards at gmail.com Wed Mar 20 10:14:46 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 20 Mar 2019 14:14:46 -0000 (UTC) Subject: File not closed References: <5c91f73d$0$31407$426a74cc@news.free.fr> Message-ID: On 2019-03-20, ast wrote: > Hello > > In the following snippet, a file is opened but > without any variable referring to it. > So the file can't be closed. > > [line.split(":")[0] > for line in open('/etc/passwd') > if line.strip() and not line.startswith("#")] > > What do you think about this practice ? If it's a short-lived program, then it will always get closed when the program terminates. Otherwise, it will get (eventually) get closed when the garbage collection system cleans up the orphan object. For short, throw-away progams, that's fine. For long running servers, it's bad style. -- Grant Edwards grant.b.edwards Yow! Hmmm ... A hash-singer at and a cross-eyed guy were gmail.com SLEEPING on a deserted island, when ... From Gronicus at SGA.Ninja Wed Mar 20 10:39:44 2019 From: Gronicus at SGA.Ninja (Steve) Date: Wed, 20 Mar 2019 10:39:44 -0400 Subject: Can my python program send me a text message? In-Reply-To: <9f35d60d-b28a-a280-3635-226b239a8754@kynesim.co.uk> References: <003a01d4de80$e49b7340$add259c0$@SGA.Ninja> <9f35d60d-b28a-a280-3635-226b239a8754@kynesim.co.uk> Message-ID: <000601d4df2a$c3667800$4a336800$@SGA.Ninja> This is a very good point since I am already finding that the arrival of texts, and voice mail, seem to be irregular with respect to delivery times with my phone as it is. On the other hand, I was not thinking fourth dimensionally when I thought about using text mail for this project. Since I am planning to migrate this program into my phone eventually, I can just use the beep in the phone instead. When I get the transfer done, I can then think about how to get the phone to make the sounds. Still, Python-to-text messaging code is an interesting concept to explore should I want to use it the future. ------------------------------------------------------------------------ Footnote: 98% of lawyers give the other 2% a bad name. -----Original Message----- From: Python-list On Behalf Of Rhodri James Sent: Wednesday, March 20, 2019 9:20 AM To: python-list at python.org Subject: Re: Can my python program send me a text message? On 19/03/2019 19:33, Abdur-Rahmaan Janhangeer wrote: > - 1) use pi with gsm module. > or > - 2) find some free sms api for python then use Slightly off-topic, but you (the OP) should be aware that carriers do not guarantee that texts will be delivered in a timely manner. In fact they don't guarantee to deliver the texts at all. We have had clients become very unhappy when confronted with the reality of that. -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Wed Mar 20 10:54:28 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Mar 2019 01:54:28 +1100 Subject: File not closed In-Reply-To: References: <5c91f73d$0$31407$426a74cc@news.free.fr> Message-ID: On Thu, Mar 21, 2019 at 1:16 AM Grant Edwards wrote: > > On 2019-03-20, ast wrote: > > Hello > > > > In the following snippet, a file is opened but > > without any variable referring to it. > > So the file can't be closed. > > > > [line.split(":")[0] > > for line in open('/etc/passwd') > > if line.strip() and not line.startswith("#")] > > > > What do you think about this practice ? > > If it's a short-lived program, then it will always get closed when the > program terminates. Otherwise, it will get (eventually) get closed > when the garbage collection system cleans up the orphan object. > > For short, throw-away progams, that's fine. For long running servers, > it's bad style. What Grant just said is the worst-case, btw. It'll often be closed more promptly than that, but it's not guaranteed, unless you explicitly call close() on the file, or (best recommendation) use it in a 'with' block to ensure that it's closed when you exit. ChrisA From tim at akwebsoft.com Wed Mar 20 14:31:39 2019 From: tim at akwebsoft.com (Tim Johnson) Date: Wed, 20 Mar 2019 10:31:39 -0800 Subject: Determining latest stable version for download Message-ID: <20190320183139.GC2313@mail.akwebsoft.com> Some time in the near future I will want to install the latest current stable version of python on a remote server. I anticipate that I will either use wget from the server shell or download to my workstation and transfer via FTP. I will need source to compile. I see python source at https://www.python.org/ftp/python/. How do I determine the following? 1) Latest current stable version of python 3* 2) Correct tarfile for linux - at this time I assume it will be linux centOS TIA -- Tim Johnson http://www.tj49.com From none at invalid.com Wed Mar 20 14:38:48 2019 From: none at invalid.com (mm0fmf) Date: Wed, 20 Mar 2019 18:38:48 +0000 Subject: Can my python program send me a text message? In-Reply-To: References: <003a01d4de80$e49b7340$add259c0$@SGA.Ninja> Message-ID: On 19/03/2019 18:23, Steve wrote: > I have a program that triggers a reminder timer. When that timer is done, I would like to receive a text message on my phone to tell me that it is time to reset the experiment. > > Can this be done using Python? > > Steve > Yes. After playing with assorted "free" systems I gave up being a cheapskate and got a paid account with a telephony as a service provider. From ian.g.kelly at gmail.com Wed Mar 20 15:51:46 2019 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 20 Mar 2019 13:51:46 -0600 Subject: Determining latest stable version for download In-Reply-To: <20190320183139.GC2313@mail.akwebsoft.com> References: <20190320183139.GC2313@mail.akwebsoft.com> Message-ID: 1) https://www.python.org/downloads/ has release information. Based on that you would currently want 3.7.2. Make sure you actually download 3.7.2 and not 3.7.2rc1. 2) The tarfiles are not distro-specific. For Linux there are really only two options: Python-3.7.2.tar.xz and Python-3.7.2.tgz. The only difference is that one is compressed with xz and the other is compressed with gzip. Pick the .xz unless you're unable to decompress it. On Wed, Mar 20, 2019 at 12:43 PM Tim Johnson wrote: > Some time in the near future I will want to install the latest > current stable version of python on a remote server. I anticipate > that I will either use wget from the server shell or download to my > workstation and transfer via FTP. I will need source to compile. > > I see python source at https://www.python.org/ftp/python/. > > How do I determine the following? > 1) Latest current stable version of python 3* > 2) Correct tarfile for linux - at this time I assume it will be > linux centOS > > TIA > -- > Tim Johnson > http://www.tj49.com > -- > https://mail.python.org/mailman/listinfo/python-list > From ian.g.kelly at gmail.com Wed Mar 20 15:57:15 2019 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 20 Mar 2019 13:57:15 -0600 Subject: Potential Security Bug In-Reply-To: References: Message-ID: On Wed, Mar 20, 2019 at 5:14 AM Laish, Amit (GE Digital) wrote: > > Hello, > I?m Amit Laish, a security researcher from GE Digital. > During one of our assessments we discovered something that we consider a bug with security implications which can cause a denial of service by disk exhausting, and we would like to share it with you, and hear you opinion about it. This is a general discussion list. https://www.python.org/news/security/ documents how to report Python security bugs. Please send your report to the PSRT as described there. From PythonList at DancesWithMice.info Wed Mar 20 15:58:25 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 21 Mar 2019 08:58:25 +1300 Subject: File not closed In-Reply-To: References: <5c91f73d$0$31407$426a74cc@news.free.fr> Message-ID: <02f98f7b-ccf2-b321-35ce-8d5fd0b982af@DancesWithMice.info> >> On 2019-03-20, ast wrote: >>> In the following snippet, a file is opened but >>> without any variable referring to it. >>> So the file can't be closed. >>> >>> [line.split(":")[0] >>> for line in open('/etc/passwd') >>> if line.strip() and not line.startswith("#")] >>> >>> What do you think about this practice ? As others have agreed, the lack of close() is not good practice, even if it is unlikely to reduce anyone to tears. Two other points, if I may: 1 it is a fairly complex line, having been split into three. If it is simplified into an explicit foreach-loop, then a file-handle becomes necessary - and can be closed. NB The greatest benefit there lies in the simplification/readability. (not a reflection on you, but thinking of 'future-readers') 2 this (revealed snippet of) code will fail on a huge number of machines. [insert comment about the superiority of Linux/the failings of MS-Windows, here] Accordingly, it should be wrapped into a try...except block. That being the case, by unwinding the foreach-loop (1) and adding try...finally, it'll 'tick all your boxes'! There's also room for an illuminating (and educational) "I can't do that Dave" errmsg... (despite my also being a fan of context-managers, per previous advice!) -- Regards =dn From jasonanyilian at gmail.com Wed Mar 20 19:34:36 2019 From: jasonanyilian at gmail.com (jasonanyilian at gmail.com) Date: Wed, 20 Mar 2019 16:34:36 -0700 (PDT) Subject: Might be doing this wrong? (Turtle graphics) Message-ID: So, I typed in code: from turtle import * forward(100) right(120) clear() It didn't work! It kept on saying that there was an indent and the first line was wrong. Help! From jasonanyilian at gmail.com Wed Mar 20 19:35:30 2019 From: jasonanyilian at gmail.com (CrazyVideoGamez) Date: Wed, 20 Mar 2019 16:35:30 -0700 (PDT) Subject: Might be doing this wrong? (Turtle graphics) In-Reply-To: References: Message-ID: On Wednesday, March 20, 2019, at 7:34:53 PM UTC-4, CrazyVideoGamez wrote: > So, I typed in code: > from turtle import * > forward(100) > right(120) > clear() > It didn't work! It kept on saying that there was an indent and the first line was wrong. Help! I'm a beginner by the way. From PythonList at danceswithmice.info Wed Mar 20 20:12:04 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Thu, 21 Mar 2019 13:12:04 +1300 Subject: Might be doing this wrong? (Turtle graphics) In-Reply-To: References: Message-ID: Jason, On 21/03/19 12:34 PM, jasonanyilian at gmail.com wrote: > So, I typed in code: > from turtle import * > forward(100) > right(120) > clear() > It didn't work! It kept on saying that there was an indent and the first line was wrong. Help! It would be most helpful if you gave us the exact error msg, in the same way that you copy-pasted the source-code. "Turtle" is not part of the Python 'core'. It has to be added from the Python Standard Library (PSL). My !GUESS! is that the Turtle library is not (yet) available on your system. Did you first "pip" or otherwise download the library? (I have, and the code works happily) WebRefs: (modify to suit the version of Python in-use) https://docs.python.org/3/installing/index.html?highlight=pip https://docs.python.org/3/library/turtle.html -- Regards =dn From python at mrabarnett.plus.com Wed Mar 20 20:29:18 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 21 Mar 2019 00:29:18 +0000 Subject: Might be doing this wrong? (Turtle graphics) In-Reply-To: References: Message-ID: On 2019-03-21 00:12, DL Neil wrote: > Jason, > > On 21/03/19 12:34 PM, jasonanyilian at gmail.com wrote: >> So, I typed in code: >> from turtle import * >> forward(100) >> right(120) >> clear() >> It didn't work! It kept on saying that there was an indent and the first line was wrong. Help! > > > It would be most helpful if you gave us the exact error msg, in the same > way that you copy-pasted the source-code. > > "Turtle" is not part of the Python 'core'. It has to be added from the > Python Standard Library (PSL). > > My !GUESS! is that the Turtle library is not (yet) available on your > system. Did you first "pip" or otherwise download the library? > > (I have, and the code works happily) > > WebRefs: (modify to suit the version of Python in-use) > https://docs.python.org/3/installing/index.html?highlight=pip > https://docs.python.org/3/library/turtle.html > It worked for me as written above (Python 3.7, Windows 10). From tim at akwebsoft.com Wed Mar 20 21:10:19 2019 From: tim at akwebsoft.com (Tim Johnson) Date: Wed, 20 Mar 2019 17:10:19 -0800 Subject: Determining latest stable version for download In-Reply-To: References: <20190320183139.GC2313@mail.akwebsoft.com> Message-ID: <20190321011019.GE2313@mail.akwebsoft.com> * Ian Kelly [190320 12:00]: > 1) https://www.python.org/downloads/ has release information. Based on that > you would currently want 3.7.2. Make sure you actually download 3.7.2 and > not 3.7.2rc1. Understood. Thanks. Your info is the solution. > 2) The tarfiles are not distro-specific. For Linux there are really only > two options: Python-3.7.2.tar.xz and Python-3.7.2.tgz. The only difference > is that one is compressed with xz and the other is compressed with gzip. > Pick the .xz unless you're unable to decompress it. > On Wed, Mar 20, 2019 at 12:43 PM Tim Johnson wrote: > > > Some time in the near future I will want to install the latest > > current stable version of python on a remote server. I anticipate > > that I will either use wget from the server shell or download to my > > workstation and transfer via FTP. I will need source to compile. > > > > I see python source at https://www.python.org/ftp/python/. > > > > How do I determine the following? > > 1) Latest current stable version of python 3* > > 2) Correct tarfile for linux - at this time I assume it will be > > linux centOS > > > > TIA > > -- > > Tim Johnson > > http://www.tj49.com > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list -- Tim Johnson http://www.tj49.com From akkana at shallowsky.com Wed Mar 20 21:07:54 2019 From: akkana at shallowsky.com (Akkana Peck) Date: Wed, 20 Mar 2019 19:07:54 -0600 Subject: I wrote a free book about TDD and clean architecture in Python In-Reply-To: <4f8e14d8-46c6-af20-91b7-2455104801a9@DancesWithMice.info> References: <26756bf9-a371-4545-b4d5-a258501da415@googlegroups.com> <4f8e14d8-46c6-af20-91b7-2455104801a9@DancesWithMice.info> Message-ID: <20190321010754.GF1105@shallowsky.com> > On 20/03/19 7:18 AM, Leonardo Giordani wrote: > > Ha ha ha, yes I get it! =) I'm sorry, that depends entirely on the LeanPub processing chain (I believe, I'll have a look just to be sure). I hope the book will be useful even with this little issue. Thanks for reading it! DL Neil writes: > Yes, I'm happy reading from cover-to-cover. Unfortunately, not being able to > refer back to (say) the Mocks chapter, means it will be of little utility > (to me) in-future. For what it's worth, the epub version has chapter links that work fine. So maybe you could download the epub version, and use calibre's ebook-convert to make a mobi version? Nice book, Leonardo. I haven't finished part 2 yet, but part 1 inspired me to go write some new tests for some of my existing programs, and I'm planning to try test-first development for my next project. ...Akkana From torriem at gmail.com Wed Mar 20 23:14:33 2019 From: torriem at gmail.com (Michael Torrie) Date: Wed, 20 Mar 2019 21:14:33 -0600 Subject: Determining latest stable version for download In-Reply-To: <20190321011019.GE2313@mail.akwebsoft.com> References: <20190320183139.GC2313@mail.akwebsoft.com> <20190321011019.GE2313@mail.akwebsoft.com> Message-ID: <3f43a683-47e5-8779-cf15-293c056997ad@gmail.com> On 03/20/2019 07:10 PM, Tim Johnson wrote: > * Ian Kelly [190320 12:00]: >> 1) https://www.python.org/downloads/ has release information. Based on that >> you would currently want 3.7.2. Make sure you actually download 3.7.2 and >> not 3.7.2rc1. > Understood. Thanks. Your info is the solution. I always found maintaining software installed from tarball on a remote server was difficult at best. You mentioned it will be on CentOS. If you have CentOS 7, the EPEL repository (nearly required by all installations in my opinion), has a package for Python 3.6, called python36. The advantage there is that it will be updated with point releases and kept somewhat secure by your normal yum update process. Also you might check out RedHat's Software Collections at https://www.softwarecollections.org/en/. They have Python 3.6 in it, and I imagine 3.7 will be there soon. Software Collections might not work for you as it installs to /opt and stays out of the default path. It's more for developers who want to play with multiple versions of languages and compilers. From tjreedy at udel.edu Thu Mar 21 00:44:46 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 21 Mar 2019 00:44:46 -0400 Subject: Might be doing this wrong? (Turtle graphics) In-Reply-To: References: Message-ID: On 3/20/2019 7:34 PM, jasonanyilian at gmail.com wrote: > So, I typed in code: > from turtle import * > forward(100) > right(120) > clear() > It didn't work! It kept on saying that there was an indent and the first line was wrong. Help! that suggests that what you typed above is not what you ran. Did you run a file or enter interactively? Either way, copy and paste the exact input and the full traceback. -- Terry Jan Reedy From giordani.leonardo at gmail.com Thu Mar 21 07:16:56 2019 From: giordani.leonardo at gmail.com (Leonardo Giordani) Date: Thu, 21 Mar 2019 04:16:56 -0700 (PDT) Subject: I wrote a free book about TDD and clean architecture in Python In-Reply-To: References: <26756bf9-a371-4545-b4d5-a258501da415@googlegroups.com> <4f8e14d8-46c6-af20-91b7-2455104801a9@DancesWithMice.info> <20190321010754.GF1105@shallowsky.com> Message-ID: Akkana, yes that is a good idea, even though I expected the LeanPub output to be already the correct one. I'll check with them. Thanks for reading the book, you actually gave me an idea: writing something about adding tests to a project *after* the code has been written. I already wrote a post on it, with a practical example, and this might be interesting. Many people discover TDD after they already wrote some code. Thanks On Thursday, 21 March 2019 01:15:40 UTC, Akkana Peck wrote: > > On 20/03/19 7:18 AM, Leonardo Giordani wrote: > > > Ha ha ha, yes I get it! =) I'm sorry, that depends entirely on the LeanPub processing chain (I believe, I'll have a look just to be sure). I hope the book will be useful even with this little issue. Thanks for reading it! > > DL Neil writes: > > Yes, I'm happy reading from cover-to-cover. Unfortunately, not being able to > > refer back to (say) the Mocks chapter, means it will be of little utility > > (to me) in-future. > > For what it's worth, the epub version has chapter links that work > fine. So maybe you could download the epub version, and use calibre's > ebook-convert to make a mobi version? > > Nice book, Leonardo. I haven't finished part 2 yet, but part 1 > inspired me to go write some new tests for some of my existing programs, > and I'm planning to try test-first development for my next project. > > ...Akkana From giordani.leonardo at gmail.com Thu Mar 21 09:21:21 2019 From: giordani.leonardo at gmail.com (Leonardo Giordani) Date: Thu, 21 Mar 2019 06:21:21 -0700 (PDT) Subject: I wrote a free book about TDD and clean architecture in Python In-Reply-To: References: <26756bf9-a371-4545-b4d5-a258501da415@googlegroups.com> <4f8e14d8-46c6-af20-91b7-2455104801a9@DancesWithMice.info> <20190321010754.GF1105@shallowsky.com> Message-ID: <736a72a8-1568-49fa-9ebb-771475f16f19@googlegroups.com> A couple of people asked the link to the post I mentioned, sorry I forgot to add it http://www.thedigitalcatonline.com/blog/2017/07/21/refactoring-with-test-in-python-a-practical-example/ This is just a very simple exercise in refactoring, but I believe it's a good starting point for people who never faced such a task. Enjoy! On Thursday, 21 March 2019 11:17:11 UTC, Leonardo Giordani wrote: > Akkana, yes that is a good idea, even though I expected the LeanPub output to be already the correct one. I'll check with them. > > Thanks for reading the book, you actually gave me an idea: writing something about adding tests to a project *after* the code has been written. I already wrote a post on it, with a practical example, and this might be interesting. Many people discover TDD after they already wrote some code. > > Thanks > > > On Thursday, 21 March 2019 01:15:40 UTC, Akkana Peck wrote: > > > On 20/03/19 7:18 AM, Leonardo Giordani wrote: > > > > Ha ha ha, yes I get it! =) I'm sorry, that depends entirely on the LeanPub processing chain (I believe, I'll have a look just to be sure). I hope the book will be useful even with this little issue. Thanks for reading it! > > > > DL Neil writes: > > > Yes, I'm happy reading from cover-to-cover. Unfortunately, not being able to > > > refer back to (say) the Mocks chapter, means it will be of little utility > > > (to me) in-future. > > > > For what it's worth, the epub version has chapter links that work > > fine. So maybe you could download the epub version, and use calibre's > > ebook-convert to make a mobi version? > > > > Nice book, Leonardo. I haven't finished part 2 yet, but part 1 > > inspired me to go write some new tests for some of my existing programs, > > and I'm planning to try test-first development for my next project. > > > > ...Akkana From Gronicus at SGA.Ninja Thu Mar 21 09:59:51 2019 From: Gronicus at SGA.Ninja (Steve) Date: Thu, 21 Mar 2019 09:59:51 -0400 Subject: What is the difference between "ws.Messagebeep(1)" and "ws.Messagebeep(-1)" ? Message-ID: <000001d4dfee$5b5318d0$11f94a70$@SGA.Ninja> Also: What is the code for other tones that I can call? Footnote: When someone asks "A penny for your thoughts" and you give your 2c worth, I wonder what happens to that other penny? TTKMAWAN From Gronicus at SGA.Ninja Thu Mar 21 09:59:51 2019 From: Gronicus at SGA.Ninja (Steve) Date: Thu, 21 Mar 2019 09:59:51 -0400 Subject: Timing problem? Message-ID: <000701d4dfee$5b913340$12b399c0$@SGA.Ninja> I believe I can see what is happening here but maybe someone can explain least I run into this again. Situation 1: I am using "ws.MessageBeep(1)" to generate a tone through the speakers. I wanted two tones to separate it from other tones that might happen and placed that code a second time in the next line. Sometimes it would not beep, others just one beep. Situation 2" At the end of my program a report is generated and then it calls timer1.py to remind me when to enter the next readings from the lab. It looks as if the report generation is interrupted when timer1.py is called. If I place "time.sleep(1)" between the commands for the beep, I get two beeps one second apart reliably. If I place "time.sleep(5)" between the report generation the call for timer1.py is called then apparently there is enough time for the report to be generated. What is happening? -------------------------------------------------------------------------------------------- Footnote: There's 99 bugs in the code, in the code. 99 bugs in the code. Take one down and patch it all around. Now there's 117 bugs in the code. From abrault at mapgears.com Thu Mar 21 10:18:17 2019 From: abrault at mapgears.com (Alexandre Brault) Date: Thu, 21 Mar 2019 10:18:17 -0400 Subject: What is the difference between "ws.Messagebeep(1)" and "ws.Messagebeep(-1)" ? In-Reply-To: <000001d4dfee$5b5318d0$11f94a70$@SGA.Ninja> References: <000001d4dfee$5b5318d0$11f94a70$@SGA.Ninja> Message-ID: <98acf423-6862-42c1-0f1f-ebf737ae35d9@mapgears.com> Assuming ws is winsound, MessageBeep(-1) produces a "simple beep". MessageBeep(1) doesn't seem to actually exist so it might fall back to that same "simple beep". The possible values are -1, MB_ICONASTERISK, MB_ICONEXCLAMATION, MB_ICONHAND, MB_ICONQUESTION, and MB_OK, all of which are defined in the winsound module. Alex On 2019-03-21 9:59 a.m., Steve wrote: > Also: What is the code for other tones that I can call? > > > > > > Footnote: > > When someone asks "A penny for your thoughts" and you give your 2c worth, > > I wonder what happens to that other penny? > > TTKMAWAN > > > From David.Raymond at tomtom.com Thu Mar 21 10:29:54 2019 From: David.Raymond at tomtom.com (David Raymond) Date: Thu, 21 Mar 2019 14:29:54 +0000 Subject: What is the difference between "ws.Messagebeep(1)" and "ws.Messagebeep(-1)" ? In-Reply-To: <000001d4dfee$5b5318d0$11f94a70$@SGA.Ninja> References: <000001d4dfee$5b5318d0$11f94a70$@SGA.Ninja> Message-ID: I'm assuming by ws you mean winsound? Check the docs: https://docs.python.org/3.7/library/winsound.html winsound.MessageBeep(type=MB_OK) Call the underlying MessageBeep() function from the Platform API. This plays a sound as specified in the registry. The type argument specifies which sound to play; possible values are -1, MB_ICONASTERISK, MB_ICONEXCLAMATION, MB_ICONHAND, MB_ICONQUESTION, and MB_OK, all described below. The value -1 produces a ?simple beep?; this is the final fallback if a sound cannot be played otherwise. If the system indicates an error, RuntimeError is raised. winsound.MB_ICONASTERISK Play the SystemDefault sound. winsound.MB_ICONEXCLAMATION Play the SystemExclamation sound. winsound.MB_ICONHAND Play the SystemHand sound. winsound.MB_ICONQUESTION Play the SystemQuestion sound. winsound.MB_OK Play the SystemDefault sound. -----Original Message----- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom.com at python.org] On Behalf Of Steve Sent: Thursday, March 21, 2019 10:00 AM To: python-list at python.org Subject: What is the difference between "ws.Messagebeep(1)" and "ws.Messagebeep(-1)" ? Also: What is the code for other tones that I can call? Footnote: When someone asks "A penny for your thoughts" and you give your 2c worth, I wonder what happens to that other penny? TTKMAWAN -- https://mail.python.org/mailman/listinfo/python-list From tim at akwebsoft.com Thu Mar 21 11:29:15 2019 From: tim at akwebsoft.com (Tim Johnson) Date: Thu, 21 Mar 2019 07:29:15 -0800 Subject: Determining latest stable version for download In-Reply-To: <3f43a683-47e5-8779-cf15-293c056997ad@gmail.com> References: <20190320183139.GC2313@mail.akwebsoft.com> <20190321011019.GE2313@mail.akwebsoft.com> <3f43a683-47e5-8779-cf15-293c056997ad@gmail.com> Message-ID: <20190321152915.GF2313@mail.akwebsoft.com> * Michael Torrie [190320 19:22]: > On 03/20/2019 07:10 PM, Tim Johnson wrote: > > * Ian Kelly [190320 12:00]: > >> 1) https://www.python.org/downloads/ has release information. Based on that > >> you would currently want 3.7.2. Make sure you actually download 3.7.2 and > >> not 3.7.2rc1. > > Understood. Thanks. Your info is the solution. > > I always found maintaining software installed from tarball on a remote > server was difficult at best. > > You mentioned it will be on CentOS. If you have CentOS 7, the EPEL > repository (nearly required by all installations in my opinion), has a > package for Python 3.6, called python36. The advantage there is that it > will be updated with point releases and kept somewhat secure by your > normal yum update process. > > Also you might check out RedHat's Software Collections at > https://www.softwarecollections.org/en/. They have Python 3.6 in it, > and I imagine 3.7 will be there soon. Software Collections might not > work for you as it installs to /opt and stays out of the default path. > It's more for developers who want to play with multiple versions of > languages and compilers. I'm currently on a shared server hosted by Hostmonster. I don't have root access, so a local install would be my only option. If local install doesn't work or is insufficient, then I would switch to a VPS. Since I'm retired and only a hobbyist in my Golden Years :), a shared server would be sufficient and cheaper, so that is my first choice. Having said that, if I have to go with a VPS (and root access) your information is very helpful. Thank you. -- Tim Johnson http://www.tj49.com From tim at akwebsoft.com Thu Mar 21 11:36:18 2019 From: tim at akwebsoft.com (Tim Johnson) Date: Thu, 21 Mar 2019 07:36:18 -0800 Subject: Determining latest stable version for download In-Reply-To: <3f43a683-47e5-8779-cf15-293c056997ad@gmail.com> References: <20190320183139.GC2313@mail.akwebsoft.com> <20190321011019.GE2313@mail.akwebsoft.com> <3f43a683-47e5-8779-cf15-293c056997ad@gmail.com> Message-ID: <20190321153618.GG2313@mail.akwebsoft.com> * Michael Torrie [190320 19:22]: > On 03/20/2019 07:10 PM, Tim Johnson wrote: > > * Ian Kelly [190320 12:00]: > >> 1) https://www.python.org/downloads/ has release information. Based on that > >> you would currently want 3.7.2. Make sure you actually download 3.7.2 and > >> not 3.7.2rc1. > > Understood. Thanks. Your info is the solution. > > I always found maintaining software installed from tarball on a remote > server was difficult at best. > > You mentioned it will be on CentOS. If you have CentOS 7, the EPEL > repository (nearly required by all installations in my opinion), has a > package for Python 3.6, called python36. The advantage there is that it > will be updated with point releases and kept somewhat secure by your > normal yum update process. > > Also you might check out RedHat's Software Collections at > https://www.softwarecollections.org/en/. They have Python 3.6 in it, > and I imagine 3.7 will be there soon. Software Collections might not > work for you as it installs to /opt and stays out of the default path. > It's more for developers who want to play with multiple versions of > languages and compilers. Michael, I should have asked the following question: Would I be able to install from the EPEL Repository or the Redhat Software Collections to a local ~/bin? thanks again -- Tim Johnson http://www.tj49.com From rosuav at gmail.com Thu Mar 21 12:25:34 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Mar 2019 03:25:34 +1100 Subject: Timing problem? In-Reply-To: <000701d4dfee$5b913340$12b399c0$@SGA.Ninja> References: <000701d4dfee$5b913340$12b399c0$@SGA.Ninja> Message-ID: On Fri, Mar 22, 2019 at 1:01 AM Steve wrote: > > I believe I can see what is happening here but maybe someone can explain least I run into this again. > > Situation 1: I am using "ws.MessageBeep(1)" to generate a tone through the speakers. I wanted two tones to separate it from other tones that might happen and placed that code a second time in the next line. Sometimes it would not beep, others just one beep. > > Situation 2" At the end of my program a report is generated and then it calls timer1.py to remind me when to enter the next readings from the lab. It looks as if the report generation is interrupted when timer1.py is called. > > If I place "time.sleep(1)" between the commands for the beep, I get two beeps one second apart reliably. > If I place "time.sleep(5)" between the report generation the call for timer1.py is called then apparently there is enough time for the report to be generated. > > What is happening? If I recall the context from previous discussion, "ws.MessageBeep(1)" creates the same tone that you would get if you had a message box pop up, right? In that case, Windows is probably suppressing duplicates - if there's a tone already playing, it won't play it again. This would be a good reason to switch back to using the PC speaker, as that would actually consume as much time as the beep does. An easy way to check this: >>> t = time.time(); ws.MessageBeep(1); print(time.time() - t) >>> t = time.time(); ws.Beep(262, 250); print(time.time() - t) My prediction is that the first one will take negligible time, but the second will pause for the quarter-second that the beep is taking. Additionally, this would let you play tones of different pitches, to separate them from other tones. Alternatively, if you don't want to use ws.Beep(), it might be best to switch to explicitly calling on VLC Media Player. Something like: >>> subprocess.check_call(["vlc", "--play-and-exit", "some-file.wav"]) which should play whatever audio tone you like. Freely usable sound bites can be obtained from various places on the internet, or you might have some yourself. (If you have "American McGee's Alice", the blunderbuss firing sound makes a great alarm tone. SssssssssssBOOOOOMssssss.) ChrisA From infneurodcr.mtz at infomed.sld.cu Thu Mar 21 15:17:58 2019 From: infneurodcr.mtz at infomed.sld.cu (Informatico de Neurodesarrollo) Date: Thu, 21 Mar 2019 15:17:58 -0400 Subject: Might be doing this wrong? (Turtle graphics) In-Reply-To: References: Message-ID: <45b6cddf-0af1-c917-1e4b-ee16de707df2@infomed.sld.cu> If you run on linux system? May be you are already installed for python 3, but not for python (python 2.7) or vice_versa . Checks this. (The code work fine, openSuSE Leap 15) El 20/03/19 a las 19:34, jasonanyilian at gmail.com escribi?: > So, I typed in code: > from turtle import * > forward(100) > right(120) > clear() > It didn't work! It kept on saying that there was an indent and the first line was wrong. Help! -- Ing. Jes?s Reyes Piedra Admin Red Neurodesarrollo,C?rdenas La caja dec?a:"Requiere windows 95 o superior"... Entonces instal? LINUX. -- Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas Infomed: http://www.sld.cu/ From artie.ziff at gmail.com Thu Mar 21 16:12:46 2019 From: artie.ziff at gmail.com (Artie Ziff) Date: Thu, 21 Mar 2019 13:12:46 -0700 Subject: how to handle response data that is streaming and chunked? Message-ID: Hello, I am trying to learn how to do use response library in the least confusing way possible. My data source is streaming. The sample I share below looks more complicated that it needs to be. I do not have enough experience with this to know better. Hence why I came here for guidance and direction. Comments are very welcome as well as pointers to reading material. I want to learn this. I expected that I was going to be able to use the JSON methods such as load or loads. After all, this is JSON and should be able to slurp into builtin python objects and data structures, I'd imagine. Does this mailing list use a paste site or is better to paste code in-line for future? Thanks for reading! --Art import os, sys, json, requests, signal from requests_oauthlib import OAuth1 api_key = 'HIDDEN' api_secret = 'HIDDEN' user_token_key = 'HIDDEN' user_token_secret = 'HIDDEN' authorization = OAuth1(api_key, api_secret, user_token_key, user_token_secret) session = requests.Session() session.auth = authorization finis = 0 def handler(signum, frame): global finis finis = 1 signal.signal(signal.SIGINT, handler) url = "https://stream.tradeking.com/v1/market/quotes.json?symbols=AAPL,DJT" resp = session.get(url, stream=True) lines = '' for chunk in resp.iter_content(None, decode_unicode=True): if finis: break lines += chunk.decode('utf-8') while lines.find('}}') > 0: line, lines = lines.split('}}', 1) print(line) From artie.ziff at gmail.com Thu Mar 21 17:09:49 2019 From: artie.ziff at gmail.com (Artie Ziff) Date: Thu, 21 Mar 2019 14:09:49 -0700 Subject: how to handle response data that is streaming and chunked? In-Reply-To: References: Message-ID: Some more info.... I wanted to add this relevant stack overflow post: https://stackoverflow.com/questions/17822342/understanding-python-http-streaming The code splitting on text produces the following sample output: {"status":"connected"}{"quote":{"ask":"195.95","asksz":"1000","bid":"195.93","bidsz":"1000","datetime":"2019-03-21T14:31:50-04:00","exch":{},"qcond":"REGULAR","symbol":"AAPL","timestamp":"1553193110" {"quote":{"ask":"195.95","asksz":"100","bid":"195.94","bidsz":"300","datetime":"2019-03-21T14:31:50-04:00","exch":{},"qcond":"REGULAR","symbol":"AAPL","timestamp":"1553193110" {"trade":{"cvol":"33872593","datetime":"2019-03-21T14:31:51-04:00","exch":{},"last":"195.9383","symbol":"AAPL","timestamp":"1553193111","vl":"100","vwap":"193.7212" {"quote":{"ask":"195.95","asksz":"900","bid":"195.93","bidsz":"1000","datetime":"2019-03-21T14:31:51-04:00","exch":{},"qcond":"REGULAR","symbol":"AAPL","timestamp":"1553193111" {"quote":{"ask":"195.95","asksz":"100","bid":"195.94","bidsz":"200","datetime":"2019-03-21T14:31:52-04:00","exch":{},"qcond":"REGULAR","symbol":"AAPL","timestamp":"1553193112" {"quote":{"ask":"195.95","asksz":"100","bid":"195.93","bidsz":"1000","datetime":"2019-03-21T14:31:53-04:00","exch":{},"qcond":"REGULAR","symbol":"AAPL","timestamp":"1553193113" {"trade":{"cvol":"33880369","datetime":"2019-03-21T14:31:53-04:00","exch":{},"last":"195.9449","symbol":"AAPL","timestamp":"1553193113","vl":"130","vwap":"193.7217" {"quote":{"ask":"195.95","asksz":"100","bid":"195.93","bidsz":"1000","datetime":"2019-03-21T14:31:53-04:00","exch":{},"qcond":"REGULAR","symbol":"AAPL","timestamp":"1553193113" {"trade":{"cvol":"33886479","datetime":"2019-03-21T14:31:54-04:00","exch":{},"last":"195.94","symbol":"AAPL","timestamp":"1553193114","vl":"100","vwap":"193.7221" {"trade":{"cvol":"33886650","datetime":"2019-03-21T14:31:55-04:00","exch":{},"last":"195.95","symbol":"AAPL","timestamp":"1553193115","vl":"20","vwap":"193.7221" {"trade":{"cvol":"33886779","datetime":"2019-03-21T14:31:55-04:00","exch":{},"last":"195.95","symbol":"AAPL","timestamp":"1553193115","vl":"100","vwap":"193.7221" {"trade":{"cvol":"33888294","datetime":"2019-03-21T14:31:56-04:00","exch":{},"last":"195.9489","symbol":"AAPL","timestamp":"1553193116","vl":"1464","vwap":"193.7222" {"quote":{"ask":"195.97","asksz":"200","bid":"195.95","bidsz":"300","datetime":"2019-03-21T14:31:56-04:00","exch":{},"qcond":"REGULAR","symbol":"AAPL","timestamp":"1553193116" This seems like a tedious way to move to forward. That is why I am trying to understand what my options are for chunked data and hopefully running the response data through a JSON decoder ring. I want well-known data structure objects. I believe it to be possible. I just do not know how to get there from here. Everybody may agree that doing it this way, and further, extracting this data from text with regex is the cornerstone of a poor implementation. My current journey is to learn a better way. :-) Thank you From grant.b.edwards at gmail.com Thu Mar 21 17:11:53 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 21 Mar 2019 21:11:53 -0000 (UTC) Subject: how to handle response data that is streaming and chunked? References: Message-ID: On 2019-03-21, Artie Ziff wrote: > I am trying to learn how to do use response library in the least > confusing way possible. > > [...] What do you mean by "response library"? > Does this mailing list use a paste site or is better to paste code > in-line for future? You can do either, but not everbody is willing to click on links, so you're limiting your audience if you don't actually include the source code you're asking about in your post. -- Grant Edwards grant.b.edwards Yow! Am I in GRADUATE at SCHOOL yet? gmail.com From python at mrabarnett.plus.com Thu Mar 21 17:21:49 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 21 Mar 2019 21:21:49 +0000 Subject: how to handle response data that is streaming and chunked? In-Reply-To: References: Message-ID: <11ccb960-c3be-fd30-7a3a-d8bab5fecd06@mrabarnett.plus.com> On 2019-03-21 20:12, Artie Ziff wrote: > Hello, > > I am trying to learn how to do use response library in the least confusing > way possible. My data source is streaming. > > The sample I share below looks more complicated that it needs to be. I do > not have enough experience with this to know better. Hence why I came here > for guidance and direction. Comments are very welcome as well as pointers > to reading material. I want to learn this. > > I expected that I was going to be able to use the JSON methods such as load > or loads. After all, this is JSON and should be able to slurp into builtin > python objects and data structures, I'd imagine. > > Does this mailing list use a paste site or is better to paste code in-line > for future? > > Thanks for reading! > --Art > > > import os, sys, json, requests, signal > from requests_oauthlib import OAuth1 > > api_key = 'HIDDEN' > api_secret = 'HIDDEN' > user_token_key = 'HIDDEN' > user_token_secret = 'HIDDEN' > > authorization = OAuth1(api_key, api_secret, user_token_key, > user_token_secret) > session = requests.Session() > session.auth = authorization > finis = 0 > > > def handler(signum, frame): > global finis > finis = 1 > > > signal.signal(signal.SIGINT, handler) > > url = "https://stream.tradeking.com/v1/market/quotes.json?symbols=AAPL,DJT" > resp = session.get(url, stream=True) > lines = '' > for chunk in resp.iter_content(None, decode_unicode=True): > if finis: > break > lines += chunk.decode('utf-8') > while lines.find('}}') > 0: > line, lines = lines.split('}}', 1) > print(line) > As far I can tell from the docs, calling '.iter_content' with 'decode_unicode=True' will make it decode, so you shouldn't be decoding it again. Also, string indexes start at 0, and '.find' will return -1 if the string is not found. As you don't need the index itself, you might as well use 'in' instead: while '}}' in lines: On the other hand, you're splitting the string, so maybe it would be better to use '.partition': before, sep, after = lines.partition('}}'): while sep: print(before + sep) lines = after before, sep, after = lines.partition('}}'): Note that when you split or partition on '}}', you'll lose the '}}' itself if you're not careful, hence the 'before + sep' above. From python at mrabarnett.plus.com Thu Mar 21 17:35:24 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 21 Mar 2019 21:35:24 +0000 Subject: how to handle response data that is streaming and chunked? In-Reply-To: References: Message-ID: <122f215e-5829-4ae8-0e64-c13d247ecf39@mrabarnett.plus.com> On 2019-03-21 21:09, Artie Ziff wrote: > Some more info.... > > I wanted to add this relevant stack overflow post: > https://stackoverflow.com/questions/17822342/understanding-python-http-streaming > > The code splitting on text produces the following sample output: > > {"status":"connected"}{"quote":{"ask":"195.95","asksz":"1000","bid":"195.93","bidsz":"1000","datetime":"2019-03-21T14:31:50-04:00","exch":{},"qcond":"REGULAR","symbol":"AAPL","timestamp":"1553193110" > {"quote":{"ask":"195.95","asksz":"100","bid":"195.94","bidsz":"300","datetime":"2019-03-21T14:31:50-04:00","exch":{},"qcond":"REGULAR","symbol":"AAPL","timestamp":"1553193110" > {"trade":{"cvol":"33872593","datetime":"2019-03-21T14:31:51-04:00","exch":{},"last":"195.9383","symbol":"AAPL","timestamp":"1553193111","vl":"100","vwap":"193.7212" > {"quote":{"ask":"195.95","asksz":"900","bid":"195.93","bidsz":"1000","datetime":"2019-03-21T14:31:51-04:00","exch":{},"qcond":"REGULAR","symbol":"AAPL","timestamp":"1553193111" > {"quote":{"ask":"195.95","asksz":"100","bid":"195.94","bidsz":"200","datetime":"2019-03-21T14:31:52-04:00","exch":{},"qcond":"REGULAR","symbol":"AAPL","timestamp":"1553193112" > {"quote":{"ask":"195.95","asksz":"100","bid":"195.93","bidsz":"1000","datetime":"2019-03-21T14:31:53-04:00","exch":{},"qcond":"REGULAR","symbol":"AAPL","timestamp":"1553193113" > {"trade":{"cvol":"33880369","datetime":"2019-03-21T14:31:53-04:00","exch":{},"last":"195.9449","symbol":"AAPL","timestamp":"1553193113","vl":"130","vwap":"193.7217" > {"quote":{"ask":"195.95","asksz":"100","bid":"195.93","bidsz":"1000","datetime":"2019-03-21T14:31:53-04:00","exch":{},"qcond":"REGULAR","symbol":"AAPL","timestamp":"1553193113" > {"trade":{"cvol":"33886479","datetime":"2019-03-21T14:31:54-04:00","exch":{},"last":"195.94","symbol":"AAPL","timestamp":"1553193114","vl":"100","vwap":"193.7221" > {"trade":{"cvol":"33886650","datetime":"2019-03-21T14:31:55-04:00","exch":{},"last":"195.95","symbol":"AAPL","timestamp":"1553193115","vl":"20","vwap":"193.7221" > {"trade":{"cvol":"33886779","datetime":"2019-03-21T14:31:55-04:00","exch":{},"last":"195.95","symbol":"AAPL","timestamp":"1553193115","vl":"100","vwap":"193.7221" > {"trade":{"cvol":"33888294","datetime":"2019-03-21T14:31:56-04:00","exch":{},"last":"195.9489","symbol":"AAPL","timestamp":"1553193116","vl":"1464","vwap":"193.7222" > {"quote":{"ask":"195.97","asksz":"200","bid":"195.95","bidsz":"300","datetime":"2019-03-21T14:31:56-04:00","exch":{},"qcond":"REGULAR","symbol":"AAPL","timestamp":"1553193116" > > This seems like a tedious way to move to forward. That is why I am trying > to understand what my options are for chunked data and hopefully running > the response data through a JSON decoder ring. I want well-known data > structure objects. I believe it to be possible. I just do not know how to > get there from here. > > Everybody may agree that doing it this way, and further, extracting this > data from text with regex is the cornerstone of a poor implementation. My > current journey is to learn a better way. :-) > I see that you lost the final '}}'! OK, try splitting on '}', decode the JSON, and if that fails (because of nested dicts), split on the next '}', etc, until it decodes successfully: # Start at the beginning. pos = 0 while True: pos = lines.find('}', pos) if pos < 0: # No (more) '}'. break # Keep the '}'. pos += 1 try: # Try decoding it. line = json.loads(lines[ : pos]) except ValueError: # Probably truncated; try again. pass else: # Success! print(line) # The remainder. lines = lines[pos : ] # Reset. pos = 0 From torriem at gmail.com Thu Mar 21 20:55:19 2019 From: torriem at gmail.com (Michael Torrie) Date: Thu, 21 Mar 2019 18:55:19 -0600 Subject: Determining latest stable version for download In-Reply-To: <20190321153618.GG2313@mail.akwebsoft.com> References: <20190320183139.GC2313@mail.akwebsoft.com> <20190321011019.GE2313@mail.akwebsoft.com> <3f43a683-47e5-8779-cf15-293c056997ad@gmail.com> <20190321153618.GG2313@mail.akwebsoft.com> Message-ID: <7b6e43f2-304e-1ae6-effd-b38595c0c968@gmail.com> On 03/21/2019 09:36 AM, Tim Johnson wrote: > Michael, I should have asked the following question: > Would I be able to install from the EPEL Repository or the Redhat > Software Collections to a local ~/bin? I am not sure, but have my doubts. Software Collections distributes software in RPM, with pathes hardcoded to /opt/rh/. You may be able to use "alien" to convert the RPM to a tarball that you could untar somewhere in your home directory. The scripts to "enable" a software collections module into your current path would work regardless of install point. Maybe this is faster than compiling from source? I'm not sure. From rosuav at gmail.com Thu Mar 21 21:08:28 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Mar 2019 12:08:28 +1100 Subject: Determining latest stable version for download In-Reply-To: <7b6e43f2-304e-1ae6-effd-b38595c0c968@gmail.com> References: <20190320183139.GC2313@mail.akwebsoft.com> <20190321011019.GE2313@mail.akwebsoft.com> <3f43a683-47e5-8779-cf15-293c056997ad@gmail.com> <20190321153618.GG2313@mail.akwebsoft.com> <7b6e43f2-304e-1ae6-effd-b38595c0c968@gmail.com> Message-ID: On Fri, Mar 22, 2019 at 11:56 AM Michael Torrie wrote: > > On 03/21/2019 09:36 AM, Tim Johnson wrote: > > Michael, I should have asked the following question: > > Would I be able to install from the EPEL Repository or the Redhat > > Software Collections to a local ~/bin? > > I am not sure, but have my doubts. Software Collections distributes > software in RPM, with pathes hardcoded to /opt/rh/. > > You may be able to use "alien" to convert the RPM to a tarball that you > could untar somewhere in your home directory. The scripts to "enable" a > software collections module into your current path would work regardless > of install point. Maybe this is faster than compiling from source? I'm > not sure. I don't know about RPMs, but it'll most likely be equivalent to what I've done with Debian packages. Advantages include not needing to install the dev libraries for everything, not needing to worry about optimization settings on the compilation (ideally, the upstream packager will use PGO), and some verification that it should work with your libraries. Disadvantages include that there may be paths hard-coded into it (if you build from source, you can tell it to put it in ~/bin), and having to learn how to extract your platform's packages. Often worth it. ChrisA From sharan.basappa at gmail.com Thu Mar 21 23:25:59 2019 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Thu, 21 Mar 2019 20:25:59 -0700 (PDT) Subject: log file Message-ID: <48b3fc78-a21d-4589-a5a8-844a4ee3322a@googlegroups.com> I am running a program and even though the program runs all fine, the log file is missing. I have pasted first few lines of the code. Any suggestions where I maybe going wrong? import os import csv import logging import assertion_design as asd import random #Create and configure logger logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s') import os import csv import logging import assertion_design as asd import random #Create and configure logger logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s') From adam.preble at gmail.com Thu Mar 21 23:34:45 2019 From: adam.preble at gmail.com (adam.preble at gmail.com) Date: Thu, 21 Mar 2019 20:34:45 -0700 (PDT) Subject: REPL, global, and local scoping In-Reply-To: References: <0962fe3f-302b-4375-a888-e9dab2fe3ee7@googlegroups.com> Message-ID: On Tuesday, March 19, 2019 at 9:49:48 PM UTC-5, Chris Angelico wrote: > I would recommend parsing in two broad steps, as CPython does: > > 1) Take the source code and turn it into an abstract syntax tree > (AST). This conceptualizes the behaviour of the code more-or-less the > way the programmer wrote it. > > 2) Implement the AST in byte-code. You are totally right. It's not getting me here, but I am running into a problem using ANTLR's visitors to deal with what kind of storage opcode to use when running into an assignment. I only roughly pondered it in my head but never really looked at the AST Python was generating for clues. But, you see, my cat is hungry and I have to, you know, ... take care of him. A lot. For awhile. Yeah. ;) From PythonList at danceswithmice.info Thu Mar 21 23:38:49 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Fri, 22 Mar 2019 16:38:49 +1300 Subject: log file In-Reply-To: <48b3fc78-a21d-4589-a5a8-844a4ee3322a@googlegroups.com> References: <48b3fc78-a21d-4589-a5a8-844a4ee3322a@googlegroups.com> Message-ID: <72be01fd-6149-20fc-9810-5d4cbbfa7b34@DancesWithMice.info> On 22/03/19 4:25 PM, Sharan Basappa wrote: > I am running a program and even though the program runs all fine, the log file is missing. I have pasted first few lines of the code. > > Any suggestions where I maybe going wrong? > > import os > import csv > import logging > import assertion_design as asd > import random > > #Create and configure logger > logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s') > import os > import csv > import logging > import assertion_design as asd > import random > > #Create and configure logger > logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s') > Do all of these lines actually appear, or is it an accidental copy-paste+paste? What do you use to actually record data in the log? eg logging.info("Informational message") Any error message from Python? When you say "the log file is missing" do you mean that there is no such file, that there is an empty file, or what? Which directory do you run the code from, and in which directory do you expect to find the log file? -- Regards =dn From adam.preble at gmail.com Thu Mar 21 23:39:05 2019 From: adam.preble at gmail.com (adam.preble at gmail.com) Date: Thu, 21 Mar 2019 20:39:05 -0700 (PDT) Subject: log file In-Reply-To: <48b3fc78-a21d-4589-a5a8-844a4ee3322a@googlegroups.com> References: <48b3fc78-a21d-4589-a5a8-844a4ee3322a@googlegroups.com> Message-ID: <8a5bd357-3cbc-4645-88ed-46ca7f2d0d41@googlegroups.com> On Thursday, March 21, 2019 at 10:26:14 PM UTC-5, Sharan Basappa wrote: > I am running a program and even though the program runs all fine, the log file is missing. I have pasted first few lines of the code. > I am thinking--hoping, rather--that you just kind of double pasted there. Anyways, you needed to specify the logging level in basicConfig: import os import csv import logging import random #Create and configure logger # Check out level=logging.INFO logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s', level=logging.INFO) log = logging.getLogger() log.info("Yay!") From python at mrabarnett.plus.com Thu Mar 21 23:43:04 2019 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 22 Mar 2019 03:43:04 +0000 Subject: log file In-Reply-To: <48b3fc78-a21d-4589-a5a8-844a4ee3322a@googlegroups.com> References: <48b3fc78-a21d-4589-a5a8-844a4ee3322a@googlegroups.com> Message-ID: On 2019-03-22 03:25, Sharan Basappa wrote: > I am running a program and even though the program runs all fine, the log file is missing. I have pasted first few lines of the code. > > Any suggestions where I maybe going wrong? > > import os > import csv > import logging > import assertion_design as asd > import random > > #Create and configure logger > logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s') > import os > import csv > import logging > import assertion_design as asd > import random > > #Create and configure logger > logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s') > Are you sure that you know where it's putting the log file? You have a relative path there, but relative to where? Try it with an absolute path. Are you sure that it's logging anything? Log a simple message just after configuring to double-check. From greg.ewing at canterbury.ac.nz Fri Mar 22 03:23:54 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 22 Mar 2019 20:23:54 +1300 Subject: array of characters? In-Reply-To: <87sgvf4fx1.fsf@nightsong.com> References: <87sgvf4fx1.fsf@nightsong.com> Message-ID: Paul Rubin wrote: > - array('u') works but it is deprecated, and (not sure) the doc page > says the object size is 2 bytes, so it may only handle BMP characters The docs actually say "Depending on the platform, it can be 16 bits or 32 bits". With Python 3.5 on MacOSX, it seems to work and hold the full range of unicode characters. Not sure why this is being deprecated instead of just making it always 32 bits. I'll make some enquiries. -- Greg From artie.ziff at gmail.com Fri Mar 22 15:44:14 2019 From: artie.ziff at gmail.com (Artie Ziff) Date: Fri, 22 Mar 2019 12:44:14 -0700 Subject: how to handle response data that is streaming and chunked? In-Reply-To: References: Message-ID: > > > What do you mean by "response library"? > So sorry for the vocabulary mislead. I intended to write "requests" referring to the http networking lib with the bazillion downloads. ;-) From ian.g.kelly at gmail.com Fri Mar 22 15:54:17 2019 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 22 Mar 2019 13:54:17 -0600 Subject: array of characters? In-Reply-To: References: <87sgvf4fx1.fsf@nightsong.com> Message-ID: I don't know the answer, and PEP 393 doesn't talk about the array('u') deprecation directly. But it seems to me that with Py_UNICODE going away this array type code would have to be completely reimplemented, and also at that point array('u') is just equivalent to array('L') with some extra conversion semantics. Maybe it's simply deprecated because nobody has proposed keeping it and anybody who really wants it can accomplish the same with 'L'. On Fri, Mar 22, 2019 at 1:28 AM Gregory Ewing wrote: > Paul Rubin wrote: > > - array('u') works but it is deprecated, and (not sure) the doc page > > says the object size is 2 bytes, so it may only handle BMP characters > > The docs actually say "Depending on the platform, it can be 16 bits or 32 > bits". > > With Python 3.5 on MacOSX, it seems to work and hold the full range of > unicode characters. > > Not sure why this is being deprecated instead of just making it always > 32 bits. I'll make some enquiries. > > -- > Greg > -- > https://mail.python.org/mailman/listinfo/python-list > From hjp-python at hjp.at Fri Mar 22 16:47:35 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 22 Mar 2019 21:47:35 +0100 Subject: Might be doing this wrong? (Turtle graphics) In-Reply-To: References: Message-ID: <20190322204735.t3iuurmsf2z5zkdf@hjp.at> On 2019-03-21 00:44:46 -0400, Terry Reedy wrote: > On 3/20/2019 7:34 PM, jasonanyilian at gmail.com wrote: > > So, I typed in code: > > from turtle import * > > forward(100) > > right(120) > > clear() > > It didn't work! It kept on saying that there was an indent and the first line was wrong. Help! > > that suggests that what you typed above is not what you ran. To be more specific, it suggests that jasonanyilian had some whitespace at the beginning of a line. Unlike most programming languages, Python is picky about whitespace at the beginning of lines (the "indentation"). This can be a problem when you copy and paste fragments of code. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From smilesonisamal at gmail.com Sat Mar 23 08:00:40 2019 From: smilesonisamal at gmail.com (Pradeep Patra) Date: Sat, 23 Mar 2019 17:30:40 +0530 Subject: Search and Replace of string in a yaml file Message-ID: Hi all, I have several yaml files in a directory around 100s. I have some values and my script should search a string(reading from the JSON file) from the series of yaml files and run some validation like the key of the file that is updated in the yaml file and run some basic validation tests like data integrity of the replaced string with the source string read from JSON. Can anyone suggest some reliable and efficient method to achieve this and appreciate some examples for the same? Regards Pradeep From tim at akwebsoft.com Sat Mar 23 15:23:47 2019 From: tim at akwebsoft.com (Tim Johnson) Date: Sat, 23 Mar 2019 11:23:47 -0800 Subject: Determining latest stable version for download In-Reply-To: <20190320183139.GC2313@mail.akwebsoft.com> References: <20190320183139.GC2313@mail.akwebsoft.com> Message-ID: <20190323192347.GA2213@mail.akwebsoft.com> * Tim Johnson [190320 10:46]: > Some time in the near future I will want to install the latest > current stable version of python on a remote server. I anticipate > that I will either use wget from the server shell or download to my > workstation and transfer via FTP. I will need source to compile. > > I see python source at https://www.python.org/ftp/python/. > > How do I determine the following? > 1) Latest current stable version of python 3* > 2) Correct tarfile for linux - at this time I assume it will be > linux centOS Thanks for the constructive replies. I'll attempt a compile from source after this weekend. I'll use these instructions: https://my.hostmonster.com/hosting/help/python-install as a guide and post results under a topic more appropriate to my goal: that of installing and running later versions of python on a shared server (sans root access). -- Tim Johnson http://www.tj49.com From npapoylias at gmail.com Sat Mar 23 12:53:39 2019 From: npapoylias at gmail.com (Nick Papoylias) Date: Sat, 23 Mar 2019 17:53:39 +0100 Subject: [CfP] DLS 2019 - 15th Dynamic Languages Symposium, co-located with SPLASH 2019 Message-ID: ======================================================================== Call for Papers DLS 2019 - 15th Dynamic Languages Symposium Co-located with SPLASH 2019, October 22, Athens, Greece https://conf.researchr.org/home/dls-2019 Follow us @dynlangsym ======================================================================== Dynamic Languages play a fundamental role in today?s world of software, from the perspective of research and practice. Languages such as JavaScript, R, and Python are vehicles for cutting edge research as well as building widely used products and computational tools. The 15th Dynamic Languages Symposium (DLS) at SPLASH 2019 is the premier forum for researchers and practitioners to share research and experience on all aspects on dynamic languages. DLS 2019 invites high quality papers reporting original research and experience related to the design, implementation, and applications of dynamic languages. Areas of interest are generally empirical studies, language design, implementation, and runtimes, which includes but is not limited to: - innovative language features - innovative implementation techniques - innovative applications - development environments and tools - experience reports and case studies - domain-oriented programming - late binding, dynamic composition, and run-time adaptation - reflection and meta-programming - software evolution - language symbiosis and multi-paradigm languages - dynamic optimization - interpretation, just-in-time and ahead-of-time compilation - soft/optional/gradual typing - hardware support - educational approaches and perspectives - semantics of dynamic languages - frameworks and languages for the Cloud and the IoT Submission Details ------------------ Submissions must neither be previously published nor under review at other events. DLS 2019 uses a single-blind, two-phase reviewing process. Papers are assumed to be in one of the following categories: Research Papers: describe work that advances the current state of the art Experience Papers: describe insights gained from substantive practical applications that should be of a broad interest Dynamic Pearls: describe a known idea in an appealing way to remind the community and capture a reader?s interest The program committee will evaluate each paper based on its relevance, significance, clarity, and originality. The paper category needs to be indicated during submission, and papers are judged accordingly. Papers are to be submitted electronically at https://dls19.hotcrp.com/ in PDF format. Submissions must be in the ACM SIGPLAN conference acmart format, 10 point font, and should not exceed 12 pages. Please see full details in the instructions for authors available at: https://conf.researchr.org/home/dls-2019#Instructions-for-Authors DLS 2019 will run a two-phase reviewing process to help authors make their final papers the best that they can be. Accepted papers will be published in the ACM Digital Library and will be freely available for one month, starting two weeks before the event. Important Deadlines ------------------- Abstract Submission: May 29, 2019 Paper Submission: June 5, 2019 First Phase Notification: July 3, 2019 Final Notifications: August 14, 2019 Camera Ready: August 28, 2019 All deadlines are 23:59 AoE (UTC-12h). AUTHORS TAKE NOTE: The official publication date is the date the proceedings are made available in the ACM Digital Library. This date may be up to two weeks prior to the first day of your conference. The official publication date affects the deadline for any patent filings related to published work. Program Committee ----------------- Alexandre Bergel, University of Chile Carl Friedrich Bolz-Tereick, Heinrich-Heine-Universit?t D?sseldorf Chris Seaton, Oracle Labs David Chisnall, Microsoft Research Elisa Gonzalez Boix, Vrije Universiteit Brussel Gregor Richards, University of Waterloo Guido Chari, Czech Technical University Hannes Payer, Google James Noble, Victoria University of Wellington Jeremy Singer, University of Glasgow Joe Gibbs Politz, University of California San Diego Juan Fumero, The University of Manchester Julien Ponge, Red Hat Mandana Vaziri, IBM Research Manuel Serrano, Inria Marc Feeley, Universit? de Montr?al Mark Marron, Microsoft Research Na Meng, Virginia Tech Nick Papoulias, Universit? Grenoble Alpes Richard Roberts, Victoria University of Wellington Sam Tobin-Hochstadt, Indiana University Sarah Mount, Aston University S?bastien Doeraene, ?cole polytechnique f?d?rale de Lausanne William Cook, University of Texas at Austin Program Chair ------------- Stefan Marr, University of Kent, United Kingdom From sharan.basappa at gmail.com Sun Mar 24 00:38:50 2019 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 23 Mar 2019 21:38:50 -0700 (PDT) Subject: log file In-Reply-To: References: <48b3fc78-a21d-4589-a5a8-844a4ee3322a@googlegroups.com> <72be01fd-6149-20fc-9810-5d4cbbfa7b34@DancesWithMice.info> Message-ID: On Friday, 22 March 2019 09:09:14 UTC+5:30, DL Neil wrote: > On 22/03/19 4:25 PM, Sharan Basappa wrote: > > I am running a program and even though the program runs all fine, the log file is missing. I have pasted first few lines of the code. > > > > Any suggestions where I maybe going wrong? > > > > import os > > import csv > > import logging > > import assertion_design as asd > > import random > > > > #Create and configure logger > > logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s') > > import os > > import csv > > import logging > > import assertion_design as asd > > import random > > > > #Create and configure logger > > logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s') > > > > > Do all of these lines actually appear, or is it an accidental > copy-paste+paste? > > What do you use to actually record data in the log? eg > > logging.info("Informational message") > > Any error message from Python? > > When you say "the log file is missing" do you mean that there is no such > file, that there is an empty file, or what? Which directory do you run > the code from, and in which directory do you expect to find the log file? > > -- > Regards =dn There is no log file at all in the directory where I am running. I expected the log file to be in the directory where I am running the test from. Let me describe it in more detail. This is the directory - "D:\Users\sharanb\OneDrive - HCL Technologies Ltd\Projects\MyBackup\Projects\Initiatives\machine learning\programs\assertion\CNN" The test program imports the design and runs some test on it. Both the design file and test file are in the above directory. From sharan.basappa at gmail.com Sun Mar 24 00:44:25 2019 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 23 Mar 2019 21:44:25 -0700 (PDT) Subject: log file In-Reply-To: <8a5bd357-3cbc-4645-88ed-46ca7f2d0d41@googlegroups.com> References: <48b3fc78-a21d-4589-a5a8-844a4ee3322a@googlegroups.com> <8a5bd357-3cbc-4645-88ed-46ca7f2d0d41@googlegroups.com> Message-ID: On Friday, 22 March 2019 09:09:16 UTC+5:30, adam.... at gmail.com wrote: > On Thursday, March 21, 2019 at 10:26:14 PM UTC-5, Sharan Basappa wrote: > > I am running a program and even though the program runs all fine, the log file is missing. I have pasted first few lines of the code. > > > I am thinking--hoping, rather--that you just kind of double pasted there. Anyways, you needed to specify the logging level in basicConfig: > > import os > import csv > import logging > import random > > #Create and configure logger > # Check out level=logging.INFO > logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s', level=logging.INFO) > log = logging.getLogger() > log.info("Yay!") Adam, I don't understand. The logger is set to DEBUG level using the following line. logger.setLevel(logging.DEBUG) Do you see anything incorrect? From sharan.basappa at gmail.com Sun Mar 24 00:47:19 2019 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 23 Mar 2019 21:47:19 -0700 (PDT) Subject: log file In-Reply-To: References: <48b3fc78-a21d-4589-a5a8-844a4ee3322a@googlegroups.com> Message-ID: <172a82d5-39b0-46f8-a939-82422e42038a@googlegroups.com> On Friday, 22 March 2019 09:13:18 UTC+5:30, MRAB wrote: > On 2019-03-22 03:25, Sharan Basappa wrote: > > I am running a program and even though the program runs all fine, the log file is missing. I have pasted first few lines of the code. > > > > Any suggestions where I maybe going wrong? > > > > import os > > import csv > > import logging > > import assertion_design as asd > > import random > > > > #Create and configure logger > > logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s') > > import os > > import csv > > import logging > > import assertion_design as asd > > import random > > > > #Create and configure logger > > logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s') > > > Are you sure that you know where it's putting the log file? You have a > relative path there, but relative to where? Try it with an absolute path. > > Are you sure that it's logging anything? Log a simple message just after > configuring to double-check. Would the file not get logged using the current directory? BTW, I changed the file location as follows and still I don't see it: logging.basicConfig(filename="D:\Users\sharanb\OneDrive - HCL Technologies Ltd\Projects\MyBackup\Projects\Initiatives\machine learning\programs\assertion\CNN\test_1.log", filemode='w', format='%(asctime)s %(message)s') From cs at cskk.id.au Sun Mar 24 01:26:58 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 24 Mar 2019 16:26:58 +1100 Subject: log file In-Reply-To: <172a82d5-39b0-46f8-a939-82422e42038a@googlegroups.com> References: <172a82d5-39b0-46f8-a939-82422e42038a@googlegroups.com> Message-ID: <20190324052658.GA98843@cskk.homeip.net> On 23Mar2019 21:47, Sharan Basappa wrote: >On Friday, 22 March 2019 09:13:18 UTC+5:30, MRAB wrote: >> On 2019-03-22 03:25, Sharan Basappa wrote: >> > I am running a program and even though the program runs all fine, the log file is missing. I have pasted first few lines of the code. >> > Any suggestions where I maybe going wrong? [...] >> > #Create and configure logger >> > logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s') >> > >> Are you sure that you know where it's putting the log file? You have a >> relative path there, but relative to where? Try it with an absolute path. >> >> Are you sure that it's logging anything? Log a simple message just after >> configuring to double-check. > >Would the file not get logged using the current directory? It should be. >BTW, I changed the file location as follows and still I don't see it: > >logging.basicConfig(filename="D:\Users\sharanb\OneDrive - HCL >Technologies Ltd\Projects\MyBackup\Projects\Initiatives\machine >learning\programs\assertion\CNN\test_1.log", filemode='w', >format='%(asctime)s %(message)s') Did you read my other recent post? You should define strings with backslashes in them such are your file path as 'raw strings', which start with r' or r" instead of a plain quote character. Raw strings do not interpret \x escapes. In particular your path above has a '\a' in it, which is not a backslash followed by an "a", it is a BEL character. That said, I can't see what's wrong with your original example which has no backslashes. Cheers, Cameron Simpson From sharan.basappa at gmail.com Sun Mar 24 04:50:23 2019 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sun, 24 Mar 2019 01:50:23 -0700 (PDT) Subject: log file In-Reply-To: References: <172a82d5-39b0-46f8-a939-82422e42038a@googlegroups.com> <20190324052658.GA98843@cskk.homeip.net> Message-ID: <4195e3f2-a274-4b62-bdff-e5766832caba@googlegroups.com> On Sunday, 24 March 2019 10:57:13 UTC+5:30, Cameron Simpson wrote: > On 23Mar2019 21:47, Sharan Basappa wrote: > >On Friday, 22 March 2019 09:13:18 UTC+5:30, MRAB wrote: > >> On 2019-03-22 03:25, Sharan Basappa wrote: > >> > I am running a program and even though the program runs all fine, the log file is missing. I have pasted first few lines of the code. > >> > Any suggestions where I maybe going wrong? > [...] > >> > #Create and configure logger > >> > logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s') > >> > > >> Are you sure that you know where it's putting the log file? You have a > >> relative path there, but relative to where? Try it with an absolute path. > >> > >> Are you sure that it's logging anything? Log a simple message just after > >> configuring to double-check. > > > >Would the file not get logged using the current directory? > > It should be. > > >BTW, I changed the file location as follows and still I don't see it: > > > >logging.basicConfig(filename="D:\Users\sharanb\OneDrive - HCL > >Technologies Ltd\Projects\MyBackup\Projects\Initiatives\machine > >learning\programs\assertion\CNN\test_1.log", filemode='w', > >format='%(asctime)s %(message)s') > > Did you read my other recent post? You should define strings with > backslashes in them such are your file path as 'raw strings', which > start with r' or r" instead of a plain quote character. Raw strings do > not interpret \x escapes. In particular your path above has a '\a' in > it, which is not a backslash followed by an "a", it is a BEL character. > > That said, I can't see what's wrong with your original example which has > no backslashes. > > Cheers, > Cameron Simpson Ah. I finally solved the issue though I don't know what the problem itself it. This is how the new code looks like: for handler in logging.root.handlers[:]: logging.root.removeHandler(handler) #Create and configure logger filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_1.log') logging.basicConfig(filename=filename, filemode='w', format='%(asctime)s %(message)s') I found the above tip from the following discussion: https://stackoverflow.com/questions/30861524/logging-basicconfig-not-creating-log-file-when-i-run-in-pycharm From ciaran.hudson at gmail.com Sun Mar 24 05:30:16 2019 From: ciaran.hudson at gmail.com (ciaran.hudson at gmail.com) Date: Sun, 24 Mar 2019 02:30:16 -0700 (PDT) Subject: scatter plot error - possibly data type Message-ID: <8fbfb621-b2f5-4326-b801-e43f27421eb9@googlegroups.com> Hi, Can anyone help me with this error? I suspect it is something to do with the data type, but don't know how to resolve. I'm trying to plot a 2 user system dates against each other and am getting the error below. print(type(DialogUsers.TRDAT)) plt.scatter(DialogUsers.TRDAT, DialogUsers.ERDAT) plt.show() --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in () ----> 1 plt.scatter(DialogUsers.TRDAT, DialogUsers.ERDAT) 2 plt.show() ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, hold, data, **kwargs) 3473 vmin=vmin, vmax=vmax, alpha=alpha, 3474 linewidths=linewidths, verts=verts, -> 3475 edgecolors=edgecolors, data=data, **kwargs) 3476 finally: 3477 ax._hold = washold ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs) 1865 "the Matplotlib list!)" % (label_namer, func.__name__), 1866 RuntimeWarning, stacklevel=2) -> 1867 return func(ax, *args, **kwargs) 1868 1869 inner.__doc__ = _add_data_doc(inner.__doc__, ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs) 4245 edgecolors = 'face' 4246 -> 4247 self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs) 4248 x = self.convert_xunits(x) 4249 y = self.convert_yunits(y) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes\_base.py in _process_unit_info(self, xdata, ydata, kwargs) 2170 # we only need to update if there is nothing set yet. 2171 if not self.yaxis.have_units(): -> 2172 self.yaxis.update_units(ydata) 2173 2174 # process kwargs 2nd since these will override default units ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axis.py in update_units(self, data) 1467 neednew = self.converter != converter 1468 self.converter = converter -> 1469 default = self.converter.default_units(data, self) 1470 if default is not None and self.units is None: 1471 self.set_units(default) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py in default_units(data, axis) 113 # default_units->axis_info->convert 114 if axis.units is None: --> 115 axis.set_units(UnitData(data)) 116 else: 117 axis.units.update(data) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py in __init__(self, data) 180 self._counter = itertools.count(start=0) 181 if data is not None: --> 182 self.update(data) 183 184 def update(self, data): ~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py in update(self, data) 199 for val in OrderedDict.fromkeys(data): 200 if not isinstance(val, VALID_TYPES): --> 201 raise TypeError("{val!r} is not a string".format(val=val)) 202 if val not in self._mapping: 203 self._mapping[val] = next(self._counter) TypeError: nan is not a string Thanks, Ciar?n From luuk34 at gmail.com Sun Mar 24 06:38:00 2019 From: luuk34 at gmail.com (Luuk) Date: Sun, 24 Mar 2019 11:38:00 +0100 Subject: log file In-Reply-To: <4195e3f2-a274-4b62-bdff-e5766832caba@googlegroups.com> References: <172a82d5-39b0-46f8-a939-82422e42038a@googlegroups.com> <20190324052658.GA98843@cskk.homeip.net> <4195e3f2-a274-4b62-bdff-e5766832caba@googlegroups.com> Message-ID: <8fe6766f-7f2e-4a95-11ff-6c9771157cf5@gmail.com> On 24-3-2019 09:50, Sharan Basappa wrote: > > Ah. I finally solved the issue though I don't know what the problem itself it. The problem, shown with a simple example Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> >>> print ("hallo") hallo >>> print ("h\allo") hllo >>> print (r"h\allo") h\allo >>> The first line is a simple print statement to print the text "hallo"?? (which is Dutch for "hello") In the second line i added a '\' (backslash), the letter 'a' seems to be missing, unless audio on your computer works. If audio works you will hear a bell. (see: https://docs.python.org/2.0/ref/strings.html ) In the third line a 'r' is put in front of the string, and now the 'a' is shown again (and also the '\'). In your path there is something like '.......programs\assertion\CNN......'. Python does see a '\a', after 'programs', and before 'ssertion', and tries to sound a 'bell'.... From sharan.basappa at gmail.com Sun Mar 24 13:08:12 2019 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sun, 24 Mar 2019 10:08:12 -0700 (PDT) Subject: log file In-Reply-To: <4195e3f2-a274-4b62-bdff-e5766832caba@googlegroups.com> References: <172a82d5-39b0-46f8-a939-82422e42038a@googlegroups.com> <20190324052658.GA98843@cskk.homeip.net> <4195e3f2-a274-4b62-bdff-e5766832caba@googlegroups.com> Message-ID: On Sunday, 24 March 2019 14:20:36 UTC+5:30, Sharan Basappa wrote: > On Sunday, 24 March 2019 10:57:13 UTC+5:30, Cameron Simpson wrote: > > On 23Mar2019 21:47, Sharan Basappa wrote: > > >On Friday, 22 March 2019 09:13:18 UTC+5:30, MRAB wrote: > > >> On 2019-03-22 03:25, Sharan Basappa wrote: > > >> > I am running a program and even though the program runs all fine, the log file is missing. I have pasted first few lines of the code. > > >> > Any suggestions where I maybe going wrong? > > [...] > > >> > #Create and configure logger > > >> > logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s') > > >> > > > >> Are you sure that you know where it's putting the log file? You have a > > >> relative path there, but relative to where? Try it with an absolute path. > > >> > > >> Are you sure that it's logging anything? Log a simple message just after > > >> configuring to double-check. > > > > > >Would the file not get logged using the current directory? > > > > It should be. > > > > >BTW, I changed the file location as follows and still I don't see it: > > > > > >logging.basicConfig(filename="D:\Users\sharanb\OneDrive - HCL > > >Technologies Ltd\Projects\MyBackup\Projects\Initiatives\machine > > >learning\programs\assertion\CNN\test_1.log", filemode='w', > > >format='%(asctime)s %(message)s') > > > > Did you read my other recent post? You should define strings with > > backslashes in them such are your file path as 'raw strings', which > > start with r' or r" instead of a plain quote character. Raw strings do > > not interpret \x escapes. In particular your path above has a '\a' in > > it, which is not a backslash followed by an "a", it is a BEL character. > > > > That said, I can't see what's wrong with your original example which has > > no backslashes. > > > > Cheers, > > Cameron Simpson > > Ah. I finally solved the issue though I don't know what the problem itself it. > This is how the new code looks like: > > for handler in logging.root.handlers[:]: > logging.root.removeHandler(handler) > > #Create and configure logger > filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_1.log') > logging.basicConfig(filename=filename, filemode='w', format='%(asctime)s %(message)s') > > I found the above tip from the following discussion: > https://stackoverflow.com/questions/30861524/logging-basicconfig-not-creating-log-file-when-i-run-in-pycharm I think I got some more idea about the issue though I still don't know the root cause. So, my test program is importing design file. Both test and design file are have the following lines: #Create and configure logger filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_5.log') logging.basicConfig(filename=filename, filemode='w', format='%(asctime)s %(message)s') #Creating an object logger = logging.getLogger() I think this is causing the issue. Anyway, I am able to log from the test program. However, I am not able to log anything from design program. I will open a separate thread on this topic. From sharan.basappa at gmail.com Sun Mar 24 13:13:07 2019 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sun, 24 Mar 2019 10:13:07 -0700 (PDT) Subject: Multiple log files using logging module Message-ID: I have a test program that imports a design program. Both the programs need to log messages. I have tried the following: 1) Both the programs have the following lines: for handler in logging.root.handlers[:]: logging.root.removeHandler(handler) #Create and configure logger filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), '<>') logging.basicConfig(filename=filename, filemode='w', format='%(asctime)s %(message)s') #Creating an object logger = logging.getLogger() #Setting the threshold of logger to DEBUG logger.setLevel(logging.DEBUG) replace <> above with respective log file names for test and design programs. However, the test program logs the messages but not the design program. 2) I removed the above lines from design program altogether hoping that the messages will appear in the same log file. There is no error, however, no message is logged from the design program. I would like to get comment from members here as well as some simple programs to illustrate this ... From luuk at invalid.lan Sun Mar 24 13:34:33 2019 From: luuk at invalid.lan (Luuk) Date: Sun, 24 Mar 2019 18:34:33 +0100 Subject: Multiple log files using logging module In-Reply-To: References: Message-ID: <5c97bfa6$0$22340$e4fe514c@news.xs4all.nl> On 24-3-2019 18:13, Sharan Basappa wrote: > I have a test program that imports a design program. > Both the programs need to log messages. > > I have tried the following: > > 1) Both the programs have the following lines: > for handler in logging.root.handlers[:]: > logging.root.removeHandler(handler) > > #Create and configure logger > filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), '<>') > logging.basicConfig(filename=filename, filemode='w', format='%(asctime)s %(message)s') > #Creating an object > logger = logging.getLogger() > #Setting the threshold of logger to DEBUG > logger.setLevel(logging.DEBUG) > > replace <> above with respective log file names for test and design programs. > However, the test program logs the messages but not the design program. > > 2) I removed the above lines from design program altogether hoping that the messages will appear in the same log file. There is no error, however, no message is logged from the design program. > > I would like to get comment from members here as well as some simple programs to illustrate this ... > As mentioned in your other thread, you should take note on HOW you put the filenames in there. How do you see the end of the line starting with 'filename =...'? Is it like: for TEST: ...., 'TEST') for DESIGN: ...., 'DESIGN') or did you put a full pathname in there? and, if you did put a full pathname in there (i.e. 'D:\TEMP\TEST' ), did you also put the 'r' in front of it, like this: ...., r'D:\TEMP\TEST') -- Luuk From PythonList at danceswithmice.info Sun Mar 24 14:26:18 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Mon, 25 Mar 2019 07:26:18 +1300 Subject: Multiple log files using logging module In-Reply-To: References: Message-ID: <2f8bb63a-1a77-45c5-9415-76a2404e50f7@DancesWithMice.info> On 25/03/19 6:13 AM, Sharan Basappa wrote: > I have a test program that imports a design program. > Both the programs need to log messages. ...> I would like to get comment from members here as well as some simple programs to illustrate this ... Have you copied this code from somewhere? Which tutorial, book, web article, or ??? are you using as your learning material? -- Regards =dn From __peter__ at web.de Sun Mar 24 14:33:25 2019 From: __peter__ at web.de (Peter Otten) Date: Sun, 24 Mar 2019 19:33:25 +0100 Subject: Multiple log files using logging module References: <5c97bfa6$0$22340$e4fe514c@news.xs4all.nl> Message-ID: Luuk wrote: > On 24-3-2019 18:13, Sharan Basappa wrote: >> I have a test program that imports a design program. >> Both the programs need to log messages. >> >> I have tried the following: >> >> 1) Both the programs have the following lines: >> for handler in logging.root.handlers[:]: >> logging.root.removeHandler(handler) >> >> #Create and configure logger >> filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), >> '<>') logging.basicConfig(filename=filename, filemode='w', >> format='%(asctime)s %(message)s') >> #Creating an object >> logger = logging.getLogger() >> #Setting the threshold of logger to DEBUG >> logger.setLevel(logging.DEBUG) >> >> replace <> above with respective log file names for test and design >> programs. However, the test program logs the messages but not the design >> program. >> >> 2) I removed the above lines from design program altogether hoping that >> the messages will appear in the same log file. There is no error, >> however, no message is logged from the design program. >> >> I would like to get comment from members here as well as some simple >> programs to illustrate this ... >> > > As mentioned in your other thread, you should take note on HOW you put > the filenames in there. I don't think that's the problem. Rather, if you call logging.basicConfig() multiple times in the same program only the first invocation has an effect, and only if there weren't any handlers added to the root logger by other means. > > How do you see the end of the line starting with 'filename =...'? > > > Is it like: > for TEST: ...., 'TEST') > for DESIGN: ...., 'DESIGN') > > or did you put a full pathname in there? > > and, if you did put a full pathname in there (i.e. 'D:\TEMP\TEST' ), > did you also put the 'r' in front of it, like this: > ...., r'D:\TEMP\TEST') > > From luuk34 at gmail.com Sun Mar 24 14:58:49 2019 From: luuk34 at gmail.com (Luuk) Date: Sun, 24 Mar 2019 19:58:49 +0100 Subject: Multiple log files using logging module In-Reply-To: References: <5c97bfa6$0$22340$e4fe514c@news.xs4all.nl> Message-ID: On 24-3-2019 19:33, Peter Otten wrote: > Luuk wrote: > >> On 24-3-2019 18:13, Sharan Basappa wrote: >>> I have a test program that imports a design program. >>> Both the programs need to log messages. >>> >>> I have tried the following: >>> >>> 1) Both the programs have the following lines: >>> for handler in logging.root.handlers[:]: >>> logging.root.removeHandler(handler) >>> >>> #Create and configure logger >>> filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), >>> '<>') logging.basicConfig(filename=filename, filemode='w', >>> format='%(asctime)s %(message)s') >>> #Creating an object >>> logger = logging.getLogger() >>> #Setting the threshold of logger to DEBUG >>> logger.setLevel(logging.DEBUG) >>> >>> replace <> above with respective log file names for test and design >>> programs. However, the test program logs the messages but not the design >>> program. >>> >>> 2) I removed the above lines from design program altogether hoping that >>> the messages will appear in the same log file. There is no error, >>> however, no message is logged from the design program. >>> >>> I would like to get comment from members here as well as some simple >>> programs to illustrate this ... >>> >> >> As mentioned in your other thread, you should take note on HOW you put >> the filenames in there. > > I don't think that's the problem. Rather, if you call logging.basicConfig() > multiple times in the same program only the first invocation has an effect, > and only if there weren't any handlers added to the root logger by other > means. > It's not clear, at least not to me, if the programs are called from each other. 'test' and 'design' is not giving much info about what a program should do. >> >> How do you see the end of the line starting with 'filename =...'? >> >> >> Is it like: >> for TEST: ...., 'TEST') >> for DESIGN: ...., 'DESIGN') >> >> or did you put a full pathname in there? >> >> and, if you did put a full pathname in there (i.e. 'D:\TEMP\TEST' ), >> did you also put the 'r' in front of it, like this: >> ...., r'D:\TEMP\TEST') >> >> > > -- Luuk From luuk at invalid.lan Sun Mar 24 14:58:49 2019 From: luuk at invalid.lan (Luuk) Date: Sun, 24 Mar 2019 19:58:49 +0100 Subject: Multiple log files using logging module In-Reply-To: References: <5c97bfa6$0$22340$e4fe514c@news.xs4all.nl> Message-ID: On 24-3-2019 19:33, Peter Otten wrote: > Luuk wrote: > >> On 24-3-2019 18:13, Sharan Basappa wrote: >>> I have a test program that imports a design program. >>> Both the programs need to log messages. >>> >>> I have tried the following: >>> >>> 1) Both the programs have the following lines: >>> for handler in logging.root.handlers[:]: >>> logging.root.removeHandler(handler) >>> >>> #Create and configure logger >>> filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), >>> '<>') logging.basicConfig(filename=filename, filemode='w', >>> format='%(asctime)s %(message)s') >>> #Creating an object >>> logger = logging.getLogger() >>> #Setting the threshold of logger to DEBUG >>> logger.setLevel(logging.DEBUG) >>> >>> replace <> above with respective log file names for test and design >>> programs. However, the test program logs the messages but not the design >>> program. >>> >>> 2) I removed the above lines from design program altogether hoping that >>> the messages will appear in the same log file. There is no error, >>> however, no message is logged from the design program. >>> >>> I would like to get comment from members here as well as some simple >>> programs to illustrate this ... >>> >> >> As mentioned in your other thread, you should take note on HOW you put >> the filenames in there. > > I don't think that's the problem. Rather, if you call logging.basicConfig() > multiple times in the same program only the first invocation has an effect, > and only if there weren't any handlers added to the root logger by other > means. > It's not clear, at least not to me, if the programs are called from each other. 'test' and 'design' is not giving much info about what a program should do. >> >> How do you see the end of the line starting with 'filename =...'? >> >> >> Is it like: >> for TEST: ...., 'TEST') >> for DESIGN: ...., 'DESIGN') >> >> or did you put a full pathname in there? >> >> and, if you did put a full pathname in there (i.e. 'D:\TEMP\TEST' ), >> did you also put the 'r' in front of it, like this: >> ...., r'D:\TEMP\TEST') >> >> > > -- Luuk From babdulbaki at gmail.com Mon Mar 25 08:14:25 2019 From: babdulbaki at gmail.com (Bassam Abdul-Baki) Date: Mon, 25 Mar 2019 08:14:25 -0400 Subject: Python 3.7 Bug In-Reply-To: References: Message-ID: Greetings, In the following code, there's a bug on certain parameters. ---------- def per(n, steps = 0): digits = [int(i) for i in str(n)] result = 1 for j in digits: result *= j steps += 1 print(steps, result, sep=" - ") if result == 0: print(result, str(result), len(str(result)), sep=" - ") if len(str(result)) == 1: print(" --- DONE ---") return "DONE" else: per(result, steps) ---------- What the program does: If I run per(X) and X is a multiple of 10, I should end up with 0 in a finite amount of steps. The problem: If I run per(54), I do not get 'DONE' printed through the return statement. WRONG! If I run per(20), I do get 'DONE' printed through the return statement. CORRECT! 20, 30, etc. are correct. 25, 45, etc. are not. Is this a bug? Thanks, Bassam From rosuav at gmail.com Mon Mar 25 14:21:25 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Mar 2019 05:21:25 +1100 Subject: Python 3.7 Bug In-Reply-To: References: Message-ID: On Tue, Mar 26, 2019 at 5:08 AM Bassam Abdul-Baki wrote: > > def per(n, steps = 0): > if len(str(result)) == 1: > print(" --- DONE ---") > return "DONE" > else: > per(result, steps) > > ---------- > > What the program does: > If I run per(X) and X is a multiple of 10, I should end up with 0 in a > finite amount of steps. > > The problem: > If I run per(54), I do not get 'DONE' printed through the return > statement. WRONG! > > If I run per(20), I do get 'DONE' printed through the return statement. > CORRECT! > > 20, 30, etc. are correct. 25, 45, etc. are not. > > Is this a bug? Yes, it is - not a bug in Python, but a bug in the above code :) I would recommend exploring the part of the code that I quoted above, and researching how recursion works, and specifically what 'return' does. That should put you on the right path to figuring this out. ChrisA From __peter__ at web.de Mon Mar 25 14:27:14 2019 From: __peter__ at web.de (Peter Otten) Date: Mon, 25 Mar 2019 19:27:14 +0100 Subject: Python 3.7 Bug References: Message-ID: Bassam Abdul-Baki wrote: > Greetings, > > In the following code, there's a bug on certain parameters. > > ---------- > > def per(n, steps = 0): > digits = [int(i) for i in str(n)] > result = 1 > for j in digits: > result *= j > steps += 1 > print(steps, result, sep=" - ") > if result == 0: > print(result, str(result), len(str(result)), sep=" - ") > if len(str(result)) == 1: > print(" --- DONE ---") > return "DONE" > else: > per(result, steps) An indent of four spaces per level would make this much easier to read. > What the program does: > If I run per(X) and X is a multiple of 10, I should end up with 0 in a > finite amount of steps. > > The problem: > If I run per(54), I do not get 'DONE' printed through the return > statement. WRONG! > > If I run per(20), I do get 'DONE' printed through the return statement. > CORRECT! > > 20, 30, etc. are correct. 25, 45, etc. are not. > > Is this a bug? If you write a function that does not do what you want it to do -- then, yes that is a bug ;) If I were to guess: You expect that line to return "DONE": > per(result, steps) However, in Python you need to be explicit: return per(result, steps) will return the result of the recursive call. From PythonList at danceswithmice.info Mon Mar 25 14:45:32 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Tue, 26 Mar 2019 07:45:32 +1300 Subject: Python 3.7 Bug In-Reply-To: References: Message-ID: <0f233220-394c-7126-99ac-df4c5bfcc2c9@DancesWithMice.info> Bassam, Greetings. On 26/03/19 1:14 AM, Bassam Abdul-Baki wrote: > Greetings, > > In the following code, there's a bug on certain parameters. > > ---------- > > def per(n, steps = 0): > digits = [int(i) for i in str(n)] > result = 1 > for j in digits: > result *= j > steps += 1 > print(steps, result, sep=" - ") > if result == 0: > print(result, str(result), len(str(result)), sep=" - ") > if len(str(result)) == 1: > print(" --- DONE ---") > return "DONE" > else: > per(result, steps) > > ---------- > > What the program does: > If I run per(X) and X is a multiple of 10, I should end up with 0 in a > finite amount of steps. > > The problem: > If I run per(54), I do not get 'DONE' printed through the return > statement. WRONG! > > If I run per(20), I do get 'DONE' printed through the return statement. > CORRECT! > > 20, 30, etc. are correct. 25, 45, etc. are not. > > Is this a bug? No - the Python 3.7 does exactly what you've asked it to do! 0 What is the objective of this piece of code? Other than "CORRECT!" and "WRONG!" there are few hints, especially the function name: "per". What does "per" mean - not everyone is a mathematician. 1 Had we been shown two entire output reports, eg one for 20 (correct) and another for 25 (incorrect), the answer would have been immediately apparent. 2 Is it a good idea/best practice to sometimes code the two values as "results" followed by "steps", and sometimes "steps" followed by "results"; or does this invite confusion? 3 Please express "len(str(result)) == 1" in English (or your preferred spoken-language). Is there an easier way to find numbers expressed in multiple digits? (and that's another overly-complicated way to say the same thing!) 4 If a 'debug print' is added at the beginning of the function, is the function being "called" more times than expected? Should/could more debug-print statements be added to check other sub-calculations along the way? (PS 'debug-print' added to your code for debugging/testing and then removed for 'production-use' is a quick-and-dirty tactic. Please add a note to your Python ToDo list: "learn to use logging library instead of debug-print", otherwise wiser heads will criticise this advice, which works well when learning but perhaps not at the professional level) 5 Humility: that it might be a bug in your code rather than in Python 3.7. Respect: It would be polite to mention if this is a student/homework assignment - or the text that you are following for self-improvement. Charity begins at home: That people here will volunteer to help you, and can be more helpful if you help us - particularly by providing information which will save our (valuable) time. Here's hoping you are now equipped to find the source of the problem... -- Regards =dn From tjreedy at udel.edu Mon Mar 25 15:29:23 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 25 Mar 2019 15:29:23 -0400 Subject: Python 3.7 Bug In-Reply-To: References: Message-ID: On 3/25/2019 8:14 AM, Bassam Abdul-Baki wrote: > Greetings, > > In the following code, there's a bug on certain parameters. > > ---------- > > def per(n, steps = 0): > digits = [int(i) for i in str(n)] > result = 1 > for j in digits: > result *= j > steps += 1 > print(steps, result, sep=" - ") > if result == 0: > print(result, str(result), len(str(result)), sep=" - ") If result is 0, then this just prints useless 0 - 0 - 1 > if len(str(result)) == 1: > print(" --- DONE ---") > return "DONE" > else: > per(result, steps) This function, properly written, was recently the subject of a youtube math video. The largest known # of steps is 11. Did you get it from there? > What the program does: > If I run per(X) and X is a multiple of 10, I should end up with 0 in a > finite amount of steps. > > The problem: > If I run per(54), I do not get 'DONE' printed through the return > statement. WRONG! > > If I run per(20), I do get 'DONE' printed through the return statement. > CORRECT! > > 20, 30, etc. are correct. 25, 45, etc. are not. > > Is this a bug? > > Thanks, > Bassam > -- Terry Jan Reedy From jasonanyilian at gmail.com Mon Mar 25 15:30:56 2019 From: jasonanyilian at gmail.com (CrazyVideoGamez) Date: Mon, 25 Mar 2019 12:30:56 -0700 (PDT) Subject: What does "TypeError: unsupported operand type(s) for +: 'function' and 'int'" mean? Message-ID: I have no idea what "TypeError: unsupported operand type(s) for +: 'function' and 'int'" means and I don't know how to fix it. Help! From jasonanyilian at gmail.com Mon Mar 25 15:32:27 2019 From: jasonanyilian at gmail.com (CrazyVideoGamez) Date: Mon, 25 Mar 2019 12:32:27 -0700 (PDT) Subject: What does "TypeError: unsupported operand type(s) for +: 'function' and 'int'" mean? In-Reply-To: References: Message-ID: <6e356dfa-f4d0-4299-abe8-765553fcbbd4@googlegroups.com> On Monday, March 25, 2019, at 3:31:09 PM UTC-4, CrazyVideoGamez wrote: > I have no idea what "TypeError: unsupported operand type(s) for +: 'function' and 'int'" means and I don't know how to fix it. Help! From jasonanyilian at gmail.com Mon Mar 25 15:34:16 2019 From: jasonanyilian at gmail.com (CrazyVideoGamez) Date: Mon, 25 Mar 2019 12:34:16 -0700 (PDT) Subject: Python 3.7 Bug In-Reply-To: References: Message-ID: <126ceca6-47df-41e3-9d1a-110bb1f5e0f1@googlegroups.com> On Monday, March 25, 2019 at 2:07:11 PM UTC-4, Bassam Abdul-Baki wrote: > Greetings, > > In the following code, there's a bug on certain parameters. > > ---------- > > def per(n, steps = 0): > digits = [int(i) for i in str(n)] > result = 1 > for j in digits: > result *= j > steps += 1 > print(steps, result, sep=" - ") > if result == 0: > print(result, str(result), len(str(result)), sep=" - ") > if len(str(result)) == 1: > print(" --- DONE ---") > return "DONE" > else: > per(result, steps) > > ---------- > > What the program does: > If I run per(X) and X is a multiple of 10, I should end up with 0 in a > finite amount of steps. > > The problem: > If I run per(54), I do not get 'DONE' printed through the return > statement. WRONG! > > If I run per(20), I do get 'DONE' printed through the return statement. > CORRECT! > > 20, 30, etc. are correct. 25, 45, etc. are not. > > Is this a bug? > > Thanks, > Bassam I dunno From rgaddi at highlandtechnology.invalid Mon Mar 25 15:35:09 2019 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Mon, 25 Mar 2019 12:35:09 -0700 Subject: What does "TypeError: unsupported operand type(s) for +: 'function' and 'int'" mean? In-Reply-To: References: Message-ID: On 3/25/19 12:30 PM, CrazyVideoGamez wrote: > I have no idea what "TypeError: unsupported operand type(s) for +: 'function' and 'int'" means and I don't know how to fix it. Help! > It means you can't add (i.e. apply the + operator) a function to an int. Which is only a problem because somewhere in your code, you're asking it to do that. In all likelihood, if you follow the line number provided in the traceback, you'll see that somewhere that you planned to use the result of calling a function you left out the parentheses and are instead using the function itself. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From jasonanyilian at gmail.com Mon Mar 25 15:37:02 2019 From: jasonanyilian at gmail.com (CrazyVideoGamez) Date: Mon, 25 Mar 2019 12:37:02 -0700 (PDT) Subject: Might be doing this wrong? (Turtle graphics) In-Reply-To: References: Message-ID: On Wednesday, March 20, 2019 at 8:29:42 PM UTC-4, MRAB wrote: > On 2019-03-21 00:12, DL Neil wrote: > > Jason, > > > > On 21/03/19 12:34 PM, jasonanyilian at gmail.com wrote: > >> So, I typed in code: > >> from turtle import * > >> forward(100) > >> right(120) > >> clear() > >> It didn't work! It kept on saying that there was an indent and the first line was wrong. Help! > > > > > > It would be most helpful if you gave us the exact error msg, in the same > > way that you copy-pasted the source-code. > > > > "Turtle" is not part of the Python 'core'. It has to be added from the > > Python Standard Library (PSL). > > > > My !GUESS! is that the Turtle library is not (yet) available on your > > system. Did you first "pip" or otherwise download the library? > > > > (I have, and the code works happily) > > > > WebRefs: (modify to suit the version of Python in-use) > > https://docs.python.org/3/installing/index.html?highlight=pip > > https://docs.python.org/3/library/turtle.html > > > It worked for me as written above (Python 3.7, Windows 10). that's weird From jasonanyilian at gmail.com Mon Mar 25 15:38:56 2019 From: jasonanyilian at gmail.com (CrazyVideoGamez) Date: Mon, 25 Mar 2019 12:38:56 -0700 (PDT) Subject: Might be doing this wrong? (Turtle graphics) In-Reply-To: References: Message-ID: On Wednesday, March 20, 2019, at 7:34:53 PM UTC-4, CrazyVideoGamez wrote: > So, I typed in code: > from turtle import * > forward(100) > right(120) > clear() > It didn't work! It kept on saying that there was an indent and the first line was wrong. Help! wait no nevermind im such an idiot From 2QdxY4RzWzUUiLuE at potatochowder.com Mon Mar 25 15:43:02 2019 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Mon, 25 Mar 2019 14:43:02 -0500 Subject: What does "TypeError: unsupported operand type(s) for +: 'function' and 'int'" mean? In-Reply-To: References: Message-ID: <25938190-ae54-a625-3c8c-f0c5386e9b84@potatochowder.com> On 3/25/19 2:30 PM, CrazyVideoGamez wrote: > I have no idea what "TypeError: unsupported operand type(s) for +: 'function' and 'int'" means It means that you're trying to add an int to a function. > ... and I don't know how to fix it. Help! Don't do that? It's possible that with the correct context (copied and pasted, not just retyped from memory), someone can help you appropriately. What version of Python are you using? What program are you running? Is this homework? From larry.martell at gmail.com Mon Mar 25 15:47:48 2019 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 25 Mar 2019 15:47:48 -0400 Subject: Might be doing this wrong? (Turtle graphics) In-Reply-To: References: Message-ID: On Mon, Mar 25, 2019 at 3:45 PM CrazyVideoGamez wrote: > wait no nevermind im such an idiot Every programmer I have ever known has said that. From john at doe.com Mon Mar 25 17:38:28 2019 From: john at doe.com (John Doe) Date: Mon, 25 Mar 2019 21:38:28 -0000 (UTC) Subject: Your IDE's? Message-ID: What is your favorite Python IDE? From oliver.schoenborn at gmail.com Mon Mar 25 17:59:16 2019 From: oliver.schoenborn at gmail.com (oliver) Date: Mon, 25 Mar 2019 17:59:16 -0400 Subject: Your IDE's? In-Reply-To: References: Message-ID: Been using IDEs for 30 years (turbopascal anyone?): by far, PyCharm (used for 5 years so far). Then VS Code (one year). I still use both. Vs Code is faster to load, uses less mem and has a simplicity about it that is appealing. BUT vscode has similar speed to pycharm once started (actually might even be slower), and although very capable, is not anything as capable as pycharm when it comes to refactoring, inspections, configurability, debugging, find/replace, integration with Git (way better than the 2 leading Git plugins for vs code), and various other capabilities you take for granted in pycharm like finding unused imports, deep integration with pytest, and many more. On Mon., Mar. 25, 2019, 17:41 John Doe, wrote: > > What is your favorite Python IDE? > > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at danceswithmice.info Mon Mar 25 18:20:29 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Tue, 26 Mar 2019 11:20:29 +1300 Subject: Your IDE's? In-Reply-To: References: Message-ID: <2c36e324-16ee-a133-c387-bfff8c2b34f6@DancesWithMice.info> On 26/03/19 10:38 AM, John Doe wrote: > > What is your favorite Python IDE? In case you are tempted to reply, neither of "John"'s supposed domains resolves (to a web site)/has been registered. -- Regards =dn From grant.b.edwards at gmail.com Mon Mar 25 18:38:49 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 25 Mar 2019 22:38:49 -0000 (UTC) Subject: Might be doing this wrong? (Turtle graphics) References: Message-ID: On 2019-03-25, Larry Martell wrote: > On Mon, Mar 25, 2019 at 3:45 PM CrazyVideoGamez wrote: >> wait no nevermind im such an idiot > > Every programmer I have ever known has said that. And never saying that is a 100% reliable indicator that you really are one... -- Grant Edwards grant.b.edwards Yow! Boy, am I glad it's at only 1971... gmail.com From nad at python.org Mon Mar 25 20:05:40 2019 From: nad at python.org (Ned Deily) Date: Mon, 25 Mar 2019 20:05:40 -0400 Subject: [RELEASE] Python 3.7.3 is now available Message-ID: https://blog.python.org/2019/03/python-373-is-now-available.html Python 3.7.3 is now available. Python 3.7.3 is the next maintenance release of Python 3.7, the latest feature release of Python. You can find Python 3.7.3 here: https://www.python.org/downloads/release/python-373/ See the What?s New In Python 3.7 document for more information about the many new features and optimizations included in the 3.7 series. Detailed information about the changes made in 3.7.3 can be found in its change log. Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation. https://docs.python.org/3.7/whatsnew/3.7.html https://docs.python.org/3.7/whatsnew/changelog.html#python-3-7-3-final https://www.python.org/psf/ -- Ned Deily nad at python.org -- [] From gheskett at shentel.net Mon Mar 25 19:55:28 2019 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 25 Mar 2019 19:55:28 -0400 Subject: Your IDE's? In-Reply-To: <2c36e324-16ee-a133-c387-bfff8c2b34f6@DancesWithMice.info> References: <2c36e324-16ee-a133-c387-bfff8c2b34f6@DancesWithMice.info> Message-ID: <201903251955.28073.gheskett@shentel.net> On Monday 25 March 2019 18:20:29 DL Neil wrote: > On 26/03/19 10:38 AM, John Doe wrote: > > What is your favorite Python IDE? > > In case you are tempted to reply, neither of "John"'s supposed domains > resolves (to a web site)/has been registered. > > -- > Regards =dn your email agent is inventing links? There were none in the single msg I got from a john doe. Unless they were buried in the headers that kmail doesn't show me.. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From ben+python at benfinney.id.au Mon Mar 25 20:14:01 2019 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 26 Mar 2019 11:14:01 +1100 Subject: Your IDE's? References: Message-ID: <86ef6u1ohi.fsf@benfinney.id.au> John Doe writes: > What is your favorite Python IDE? The same as my favourite JavaScript IDE, Haskell IDE, and any other language I need: Emacs and a shell multiplexer (today, that's GNU Screen, but others swear that I should try TMux). An IDE, like all of the tools that we rely on for getting our work done, should be free software and owned by its community to ensure it's always meeting its community's needs. An IDE in particular should handle my programming tasks well regardless of whether it was designed with that programming language in mind. So a mature, flexible, extensible, language-agnostic IDE is a must. Of those available, I know of Vim and GNU Emacs to be the strongest contenders. Maybe the Atom editor will get there some day, though for now I hear many complaints that with many plug-ins active it's just too slow when doing the kind of complex tasks we expect of a programmer's editor like Vim or GNU Emacs. -- \ ?The reason we come up with new versions is not to fix bugs. | `\ It's absolutely not.? ?Bill Gates, 1995-10-23 | _o__) | Ben Finney From dboland9 at offilive.com Mon Mar 25 20:10:40 2019 From: dboland9 at offilive.com (Dave) Date: Mon, 25 Mar 2019 20:10:40 -0400 Subject: configparser - which one? Message-ID: I use Python3 3, and expected learning how to use configparser would be no big deal. Well! Seems there is configparser, stdconfigparser, and safeconfigparser, and multiple ways to set the section and entries to the section. A little confusing. I want to future-proof may code, so what should I be using? As for setting the sections and entries, the following both work. from configparser import ConfigParser # Python 3 syntax parser = ConfigParser() parser['DEFAULT'] = {'Language': 'English', 'Units': 'English', 'UseDefaults': 'True', 'NumberRidesDisplay': '30', 'Pi': '3.14'} parser.add_section('Default') parser.set('default', 'language', 'english') parser.set('default', 'units_measure', 'english') parser.set('default', 'background_color', 'white') parser.set('default', 'useDefaults', 'true') parser.set('default', 'numToDisp', '12') parser.set('default', 'pi', '3.14') The advantage of the former is that it will handle 'DEFAULT', while the last one won't. I like the former, but not sure if it is the future. Thanks, Dave From hasan.diwan at gmail.com Mon Mar 25 20:28:23 2019 From: hasan.diwan at gmail.com (Hasan Diwan) Date: Mon, 25 Mar 2019 17:28:23 -0700 Subject: [Python-Dev] [RELEASE] Python 3.7.3 is now available In-Reply-To: References: Message-ID: Congrats to all for a timely release! -- H On Mon, 25 Mar 2019 at 17:19, Ned Deily wrote: > https://blog.python.org/2019/03/python-373-is-now-available.html > > Python 3.7.3 is now available. Python 3.7.3 is the next > maintenance release of Python 3.7, the latest feature release of Python. > You can find Python 3.7.3 here: > https://www.python.org/downloads/release/python-373/ > > See the What?s New In Python 3.7 document for more information about the > many new features and optimizations included in the 3.7 series. Detailed > information about the changes made in 3.7.3 can be found in its change log. > > Thanks to all of the many volunteers who help make Python Development and > these releases possible! Please consider supporting our efforts by > volunteering yourself or through organization contributions to the Python > Software Foundation. > > https://docs.python.org/3.7/whatsnew/3.7.html > https://docs.python.org/3.7/whatsnew/changelog.html#python-3-7-3-final > https://www.python.org/psf/ > > -- > Ned Deily > nad at python.org -- [] > > _______________________________________________ > Python-Dev mailing list > Python-Dev at python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/hasan.diwan%40gmail.com > -- OpenPGP: https://sks-keyservers.net/pks/lookup?op=get&search=0xFEBAD7FFD041BBA1 If you wish to request my time, please do so using *bit.ly/hd1AppointmentRequest *. Si vous voudrais faire connnaisance, allez a *bit.ly/hd1AppointmentRequest *. Sent from my mobile device Envoye de mon portable From python at mrabarnett.plus.com Mon Mar 25 21:08:44 2019 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 26 Mar 2019 01:08:44 +0000 Subject: Might be doing this wrong? (Turtle graphics) In-Reply-To: References: Message-ID: On 2019-03-25 22:38, Grant Edwards wrote: > On 2019-03-25, Larry Martell wrote: >> On Mon, Mar 25, 2019 at 3:45 PM CrazyVideoGamez wrote: >>> wait no nevermind im such an idiot >> >> Every programmer I have ever known has said that. > > And never saying that is a 100% reliable indicator that you really are > one... > Or you haven't been programming for long. From PythonList at danceswithmice.info Mon Mar 25 22:24:14 2019 From: PythonList at danceswithmice.info (DL Neil) Date: Tue, 26 Mar 2019 15:24:14 +1300 Subject: Your IDE's? In-Reply-To: <201903251955.28073.gheskett@shentel.net> References: <2c36e324-16ee-a133-c387-bfff8c2b34f6@DancesWithMice.info> <201903251955.28073.gheskett@shentel.net> Message-ID: <89001ee7-5d21-8616-32c8-660526611cd3@DancesWithMice.info> On 26/03/19 12:55 PM, Gene Heskett wrote: > On Monday 25 March 2019 18:20:29 DL Neil wrote: > >> On 26/03/19 10:38 AM, John Doe wrote: >>> What is your favorite Python IDE? >> >> In case you are tempted to reply, neither of "John"'s supposed domains >> resolves (to a web site)/has been registered. >> >> -- >> Regards =dn > your email agent is inventing links? There were none in the single msg I > got from a john doe. Unless they were buried in the headers that kmail > doesn't show me.. The invention is not mine: aside from his name, have a look at the OP's purported email address, and his requested ReplyTo: address. Then check the veracity of those domainNMs... -- Regards =dn From spencer.graves at prodsyse.com Mon Mar 25 22:14:48 2019 From: spencer.graves at prodsyse.com (Spencer Graves) Date: Mon, 25 Mar 2019 22:14:48 -0400 Subject: Your IDE's? In-Reply-To: <201903251955.28073.gheskett@shentel.net> References: <2c36e324-16ee-a133-c387-bfff8c2b34f6@DancesWithMice.info> <201903251955.28073.gheskett@shentel.net> Message-ID: <2b9bf389-d6c8-562d-9d98-65e88be7da92@prodsyse.com> On 2019-03-25 18:55, Gene Heskett wrote: > On Monday 25 March 2019 18:20:29 DL Neil wrote: > >> On 26/03/19 10:38 AM, John Doe wrote: >>> What is your favorite Python IDE? >> In case you are tempted to reply, neither of "John"'s supposed domains >> resolves (to a web site)/has been registered. >> >> -- >> Regards =dn > your email agent is inventing links? There were none in the single msg I > got from a john doe. Unless they were buried in the headers that kmail > doesn't show me.. ????? The original email was "From John Doe ", with a "Reply to John Doe ".? "Doe.com" is a URL being advertised for sale for $150,000.? "ping something.com" returns, "cannot resolve something.com:? Unknown host". ????? Clearly the original poster is playing games with us. ??? ? Spencer > > Cheers, Gene Heskett From PythonList at DancesWithMice.info Mon Mar 25 22:58:32 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 26 Mar 2019 15:58:32 +1300 Subject: configparser - which one? In-Reply-To: References: Message-ID: <71dd2f04-d34e-9992-a784-d4345ea9c86b@DancesWithMice.info> Dave, On 26/03/19 1:10 PM, Dave wrote: > I use Python3 3, and expected learning how to use configparser would be > no big deal.? Well!? Seems there is configparser, stdconfigparser, and > safeconfigparser, and multiple ways to set the section and entries to > the section.? A little confusing.? I want to future-proof may code, so > what should I be using? (with apologies for not answering the question directly) After striking this problem, I was encouraged to take a look at JSON, and thence YAML. Once there, as they say, didn't look back! - multi-dimensional possibilities, cf .ini - similarity/correspondence with Python data structures - convenient PSL - easily adopted by (power-)users, cf Python code WebRefs: - similar Q: https://stackoverflow.com/questions/5055042/whats-the-best-practice-using-a-settings-file-in-python - article: https://martin-thoma.com/configuration-files-in-python/ - similar discussion: https://stackoverflow.com/questions/3085029/pros-and-cons-for-different-configuration-formats -- Regards =dn From dboland9 at offilive.com Mon Mar 25 23:24:26 2019 From: dboland9 at offilive.com (Dave) Date: Mon, 25 Mar 2019 23:24:26 -0400 Subject: configparser - which one? References: <71dd2f04-d34e-9992-a784-d4345ea9c86b@DancesWithMice.info> Message-ID: On 3/25/19 10:58 PM, DL Neil wrote: > Dave, > > > On 26/03/19 1:10 PM, Dave wrote: >> I use Python3 3, and expected learning how to use configparser would >> be no big deal.? Well!? Seems there is configparser, stdconfigparser, >> and safeconfigparser, and multiple ways to set the section and entries >> to the section.? A little confusing.? I want to future-proof may code, >> so what should I be using? > > > (with apologies for not answering the question directly) > > After striking this problem, I was encouraged to take a look at JSON, > and thence YAML. Once there, as they say, didn't look back! > - multi-dimensional possibilities, cf .ini > - similarity/correspondence with Python data structures > - convenient PSL > - easily adopted by (power-)users, cf Python code > > > WebRefs: > > - similar Q: > https://stackoverflow.com/questions/5055042/whats-the-best-practice-using-a-settings-file-in-python > > > - article: https://martin-thoma.com/configuration-files-in-python/ > > - similar discussion: > https://stackoverflow.com/questions/3085029/pros-and-cons-for-different-configuration-formats > > Wish I could do that. Customer wants .ini. I would need to sell them on an alternative. The issue is human readable - .ini is easier for people to understand. Dave, From cs at cskk.id.au Tue Mar 26 00:38:45 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 26 Mar 2019 15:38:45 +1100 Subject: configparser - which one? In-Reply-To: References: Message-ID: <20190326043845.GA81414@cskk.homeip.net> On 25Mar2019 23:24, Dave wrote: >On 3/25/19 10:58 PM, DL Neil wrote: >>On 26/03/19 1:10 PM, Dave wrote: >>>I use Python3 3, and expected learning how to use configparser >>>would be no big deal.? Well!? Seems there is configparser, >>>stdconfigparser, and safeconfigparser, and multiple ways to set >>>the section and entries to the section.? A little confusing.? I >>>want to future-proof may code, so what should I be using? >> >> >>(with apologies for not answering the question directly) >> >>After striking this problem, I was encouraged to take a look at >>JSON, and thence YAML. Once there, as they say, didn't look back! >>- multi-dimensional possibilities, cf .ini >>- similarity/correspondence with Python data structures >>- convenient PSL >>- easily adopted by (power-)users, cf Python code [...] >> >Wish I could do that. Customer wants .ini. I would need to sell them >on an alternative. The issue is human readable - .ini is easier for >people to understand. And I agree with the customer, absent more info. Unless you need deeply nested stuff, .ini is much easier for humans to read. Not everything is a match for it (unless you start playing games with "[clause.subclause.subsubclause]" stuff, which I'd argue is a smell indicating a format change might be good). But for stuff which does fit nicely into .ini, it is FAR FAR easier on the reader. Like JSON, YAML etc are far far easier than XML for the reader. Lots of stuff, particularly simple configs, go well in .ini. All that opinion aside: just use the configparser.ConfigParser class. It is what _used_ to be "SafeConfigParser" in Python 2. Here endith the lesson. Cheers, Cameron Simpson From arj.python at gmail.com Tue Mar 26 01:07:15 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 26 Mar 2019 09:07:15 +0400 Subject: The Mailing List Digest Project Message-ID: As proposed on python-ideas, i setup a repo to turn mail threads into articles. here is the repo https://github.com/Abdur-rahmaanJ/py-mailing-list-summary i included a script to build .md to .html (with syntax highlighting) here is the index https://abdur-rahmaanj.github.io/py-mailing-list-summary/ included 3 articles as a start if you want to contribute an article, just follow existing .md format and put it in the .md folder planning to go across ideas, list and dev i can tell you, it's a really enjoyable experience. psst. we can enhance some html later -- Abdur-Rahmaan Janhangeer Mauritius From gheskett at shentel.net Tue Mar 26 01:26:38 2019 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 26 Mar 2019 01:26:38 -0400 Subject: Your IDE's? In-Reply-To: <2b9bf389-d6c8-562d-9d98-65e88be7da92@prodsyse.com> References: <201903251955.28073.gheskett@shentel.net> <2b9bf389-d6c8-562d-9d98-65e88be7da92@prodsyse.com> Message-ID: <201903260126.38748.gheskett@shentel.net> On Monday 25 March 2019 22:14:48 Spencer Graves wrote: > On 2019-03-25 18:55, Gene Heskett wrote: > > On Monday 25 March 2019 18:20:29 DL Neil wrote: > >> On 26/03/19 10:38 AM, John Doe wrote: > >>> What is your favorite Python IDE? > >> > >> In case you are tempted to reply, neither of "John"'s supposed > >> domains resolves (to a web site)/has been registered. > >> > >> -- > >> Regards =dn > > > > your email agent is inventing links? There were none in the single > > msg I got from a john doe. Unless they were buried in the headers > > that kmail doesn't show me.. > > ????? The original email was "From John Doe ", with a > "Reply to John Doe ".? "Doe.com" is a URL being > advertised for sale for $150,000.? "ping something.com" returns, > "cannot resolve something.com:? Unknown host". > > > ????? Clearly the original poster is playing games with us. > > And that, like excrement, happens. Sooner if you eat regularly. :-) > ??? ? Spencer > > > Cheers, Gene Heskett Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From gheskett at shentel.net Tue Mar 26 01:28:39 2019 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 26 Mar 2019 01:28:39 -0400 Subject: Your IDE's? In-Reply-To: <89001ee7-5d21-8616-32c8-660526611cd3@DancesWithMice.info> References: <201903251955.28073.gheskett@shentel.net> <89001ee7-5d21-8616-32c8-660526611cd3@DancesWithMice.info> Message-ID: <201903260128.39047.gheskett@shentel.net> On Monday 25 March 2019 22:24:14 DL Neil wrote: > On 26/03/19 12:55 PM, Gene Heskett wrote: > > On Monday 25 March 2019 18:20:29 DL Neil wrote: > >> On 26/03/19 10:38 AM, John Doe wrote: > >>> What is your favorite Python IDE? > >> > >> In case you are tempted to reply, neither of "John"'s supposed > >> domains resolves (to a web site)/has been registered. > >> > >> -- > >> Regards =dn > > > > your email agent is inventing links? There were none in the single > > msg I got from a john doe. Unless they were buried in the headers > > that kmail doesn't show me.. > > The invention is not mine: aside from his name, have a look at the > OP's purported email address, and his requested ReplyTo: address. Then > check the veracity of those domainNMs... > I only rarely do so as I can usually detect such from the pull on my leg. :) > -- > Regards =dn Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From PythonList at DancesWithMice.info Tue Mar 26 03:45:49 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 26 Mar 2019 20:45:49 +1300 Subject: OT Re: Your IDE's? In-Reply-To: <201903260128.39047.gheskett@shentel.net> References: <201903251955.28073.gheskett@shentel.net> <89001ee7-5d21-8616-32c8-660526611cd3@DancesWithMice.info> <201903260128.39047.gheskett@shentel.net> Message-ID: <4cca0c6e-07dc-7b25-8186-7037f1e90a26@DancesWithMice.info> Those of delicate disposition should look away now... >> The invention is not mine: aside from his name, have a look at the >> OP's purported email address, and his requested ReplyTo: address. Then >> check the veracity of those domainNMs... >> > I only rarely do so as I can usually detect such from the pull on my > leg. :) > Cheers, Gene Heskett Would that be a pull on your jeans' leg? -- Regards =dn From tjreedy at udel.edu Tue Mar 26 04:29:09 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 26 Mar 2019 04:29:09 -0400 Subject: configparser - which one? In-Reply-To: References: Message-ID: On 3/25/2019 8:10 PM, Dave wrote: > I use Python3 3, and expected learning how to use configparser would be > no big deal.? Well!? Seems there is configparser, stdconfigparser, and configparser is what IDLE uses. I would read the extra or deleted features of the others and see if they apply to your client's project. > safeconfigparser, and multiple ways to set the section and entries to > the section.? A little confusing.? I want to future-proof may code, so > what should I be using? > > As for setting the sections and entries, the following both work. > > from configparser import ConfigParser??? # Python 3 syntax > parser = ConfigParser() > > parser['DEFAULT'] = {'Language': 'English', > ???????????????????? 'Units': 'English', > ???????????????????? 'UseDefaults': 'True', > ???????????????????? 'NumberRidesDisplay': '30', > ???????????????????? 'Pi': '3.14'} The dict interface is newer but I doubt that the older one will go away. (IDLE uses it because it predates the dict interface. Since this code is pretty static, I do not currently see a payoff for conversion.) > parser.add_section('Default') > parser.set('default', 'language', 'english') > parser.set('default', 'units_measure', 'english') > parser.set('default', 'background_color', 'white') > parser.set('default', 'useDefaults', 'true') > parser.set('default', 'numToDisp', '12') > parser.set('default', 'pi', '3.14') > > The advantage of the former is that it will handle 'DEFAULT', while the > last one won't.? I like the former, but not sure if it is the future. We do not remove things and break backwards compatibility lightly. -- Terry Jan Reedy From lukasz at langa.pl Tue Mar 26 05:11:55 2019 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Tue, 26 Mar 2019 10:11:55 +0100 Subject: [RELEASE] Python 3.8.0a3 is now available for testing Message-ID: <17D69CA4-6E33-4FA4-BFF8-0642EC620639@langa.pl> It's time for the third alpha of Python 3.8.0. Go get it here: https://www.python.org/downloads/release/python-380a3/ Python 3.8.0a3 is the third of four planned alpha releases of Python 3.8, the next feature release of Python. During the alpha phase, Python 3.8 remains under heavy development: additional features will be added and existing features may be modified or deleted. Please keep in mind that this is a preview release and its use is not recommended for production environments. The last alpha release, 3.8.0a4, is planned for 2019-04-29. I am happy to say that this time all buildbots were properly green. Thank you to everybody who worked on that. - ? -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: Message signed with OpenPGP URL: From python.list at tim.thechases.com Mon Mar 25 22:47:35 2019 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 25 Mar 2019 21:47:35 -0500 Subject: Your IDE's? In-Reply-To: References: Message-ID: <20190325214735.0ee5721d@bigbox.christie.dr> On 2019-03-25 21:38, John Doe wrote: > What is your favorite Python IDE? Unix. https://sanctum.geek.nz/arabesque/series/unix-as-ide/ Namely $EDITOR (for some value of ed/vi/vim), a shell (usually bash, ksh, or /bin/sh), a VCS (usually git, subversion, rcs, or fossil, though sometimes CVS or Mercurial), and a whole suite of other battle-tested tools that work together. -tkc From Kenneth.R.Adams at wellsfargo.com Mon Mar 25 19:10:36 2019 From: Kenneth.R.Adams at wellsfargo.com (Kenneth.R.Adams at wellsfargo.com) Date: Mon, 25 Mar 2019 23:10:36 +0000 Subject: Text Similarity/Comparison Question Message-ID: <5f82b1907339419991f304bca4d69035@wellsfargo.com> Hello. I am working on a project where one system (System A) contains seven text fields (unstructured data for comments). I have concatenated all of the fields into a single field. There is a second system (System B) containing two unstructured fields that capture text comments. I have concatenated these fields into a single field just as I did for the first system. This system contains highly sensitive and prohibitive data. The issue that I'm trying to solve is that there should not be any text data from System B (sensitive narratives, investigative IDs, etc.) In essence, I am trying to find the following three items: 1) Find direct references to investigations ("Investigation number ABC123") 2) Language that talks about references (i.e. "Jane Doe is under investigation") 3) Actual cut-and-paste segments where they copied something verbatim from System B to System A in the commentary fields. It seems as though I may have to use different text similarity (comparison between System A and System B text) or search techniques for one or more of the three items. I was thinking that Cosine Similarity Computation (CSC) would perhaps be useful, but I thought I would solicit some advice as I'm a recent text analyst using Python. Thank you in advance. Kenneth R Adams Compliance Technology and Analytics TAS -Text Analytics as a Service Wells Fargo & Co. | 401 South Tryon Street, Twenty-sixth Floor | Charlotte, NC 28202 MAC: D1050-262 Cell: 704-408.5157 Kenneth.R.Adams at WellsFargo.com [WellsFargoLogo_w_SC] From gabriele1NOSPAM at hotmail.com Tue Mar 26 06:50:33 2019 From: gabriele1NOSPAM at hotmail.com (^Bart) Date: Tue, 26 Mar 2019 11:50:33 +0100 Subject: How to store scores of a race's players Message-ID: Hello! I need to store scores of three players for more than a race, after every race the user will read "Is the competition finished?", if the competition if finished the user will see the winner who got higest score: p1 = int (input ("Insert score of the first player: ")) p2 = int (input ("Insert score of the second player: ")) p3 = int (input ("Insert score of the third player: ")) race = str (input ("Is the competition finished?")) totalp1 = 0 totalp2 = 0 totalp3 = 0 winner = 0 if p1 > p2 and p1 > p3: winner = c1 elif p2 > p1 and p2 > p3: winner = p2 else: winner = p3 if "yes" in race: print("The winner is:",winner) else: p1 = int (input ("Insert score of the first player: ")) p2 = int (input ("Insert score of the second player: ")) p3 = int (input ("Insert score of the third player: ")) race = str (input ("Is the competition finished?")) You read above just my toughts, is there someone who could help me to understand how to solve it? Regards. ^Bart From dboland9 at offilive.com Tue Mar 26 07:18:29 2019 From: dboland9 at offilive.com (Dave) Date: Tue, 26 Mar 2019 07:18:29 -0400 Subject: configparser - which one? References: Message-ID: On 3/26/19 4:29 AM, Terry Reedy wrote: > On 3/25/2019 8:10 PM, Dave wrote: >> I use Python3 3, and expected learning how to use configparser would >> be no big deal.? Well!? Seems there is configparser, stdconfigparser, and > > configparser is what IDLE uses.? I would read the extra or deleted > features of the others and see if they apply to your client's project. > >> safeconfigparser, and multiple ways to set the section and entries to >> the section.? A little confusing.? I want to future-proof may code, so >> what should I be using? >> >> As for setting the sections and entries, the following both work. >> >> from configparser import ConfigParser??? # Python 3 syntax >> parser = ConfigParser() >> >> parser['DEFAULT'] = {'Language': 'English', >> ????????????????????? 'Units': 'English', >> ????????????????????? 'UseDefaults': 'True', >> ????????????????????? 'NumberRidesDisplay': '30', >> ????????????????????? 'Pi': '3.14'} > > The dict interface is newer but I doubt that the older one will go away. > ?(IDLE uses it because it predates the dict interface.? Since this code > is pretty static, I do not currently see a payoff for conversion.) > >> parser.add_section('Default') >> parser.set('default', 'language', 'english') >> parser.set('default', 'units_measure', 'english') >> parser.set('default', 'background_color', 'white') >> parser.set('default', 'useDefaults', 'true') >> parser.set('default', 'numToDisp', '12') >> parser.set('default', 'pi', '3.14') >> >> The advantage of the former is that it will handle 'DEFAULT', while >> the last one won't.? I like the former, but not sure if it is the future. > > We do not remove things and break backwards compatibility lightly. > Thanks everyone. So, I'll use configparser, but I do like the dictionary API as it makes the code a little easier as I can pass as arguments a section name and a dictionary with the contents to a function to write the complete section. Dave, From bgailer at gmail.com Tue Mar 26 09:01:56 2019 From: bgailer at gmail.com (Bob Gailer) Date: Tue, 26 Mar 2019 09:01:56 -0400 Subject: How to store scores of a race's players In-Reply-To: References: Message-ID: On Mar 26, 2019 6:55 AM, "^Bart" wrote: > > Hello! > > I need to store scores of three players for more than a race, after every race the user will read "Is the competition finished?", if the competition if finished the user will see the winner who got higest score: > Thank you for reaching out to us for help as You Learn Python. A good mailing list to use instead of the main python list is tutor at python.org. I'm including that list in the reply addresses; please use that address in the future and always reply all so a copy goes to that list. This looks like a homework assignment. Be advised we won't write code for you but we will help you when you get stuck and provide some guidance. I'm personally curious as to who wrote that specification, since it is not well written. One of the questions that fails to address is what if two or more players have the same high score? It's also a little hard to guide you since we don't know what you've already learned. One of the fundamental concepts in computer programming is that of a loop. Since the requirements indicate there will be more than one race that requires a loop. The simplest python construction for a loop is a while. Within that Loop you write the code once rather than rewriting it as you have done. I hope that is enough to get you started. Please apply that advice as best you can and come back with a revised program. > p1 = int (input ("Insert score of the first player: ")) > p2 = int (input ("Insert score of the second player: ")) > p3 = int (input ("Insert score of the third player: ")) > > race = str (input ("Is the competition finished?")) > > totalp1 = 0 > totalp2 = 0 > totalp3 = 0 > > winner = 0 > > if p1 > p2 and p1 > p3: > winner = c1 > elif p2 > p1 and p2 > p3: > winner = p2 > else: > winner = p3 > > if "yes" in race: > print("The winner is:",winner) > else: > p1 = int (input ("Insert score of the first player: ")) > p2 = int (input ("Insert score of the second player: ")) > p3 = int (input ("Insert score of the third player: ")) > > race = str (input ("Is the competition finished?")) > > You read above just my toughts, is there someone who could help me to understand how to solve it? > > Regards. > ^Bart > -- > https://mail.python.org/mailman/listinfo/python-list From jon+usenet at unequivocal.eu Tue Mar 26 09:27:32 2019 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 26 Mar 2019 13:27:32 -0000 (UTC) Subject: configparser - which one? References: <71dd2f04-d34e-9992-a784-d4345ea9c86b@DancesWithMice.info> Message-ID: On 2019-03-26, DL Neil wrote: > On 26/03/19 1:10 PM, Dave wrote: >> I use Python3 3, and expected learning how to use configparser would be >> no big deal.? Well!? Seems there is configparser, stdconfigparser, and >> safeconfigparser, and multiple ways to set the section and entries to >> the section.? A little confusing.? I want to future-proof may code, so >> what should I be using? > > (with apologies for not answering the question directly) > > After striking this problem, I was encouraged to take a look at JSON, > and thence YAML. Once there, as they say, didn't look back! Friends don't let friends use YAML. Indeed, I have always assumed that YAML is a joke that got out of control, like the Flat Earth Society. It's like they chose a list of goals and then set themselves a challenge to design a solution that fails at meeting those goals in the most spectacular way possible. I mean, the original point of it was that it was a simpler replacement for XML but the YAML spec is larger than the XML spec... that can't happen by accident, right? From grant.b.edwards at gmail.com Tue Mar 26 09:44:58 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 26 Mar 2019 13:44:58 -0000 (UTC) Subject: configparser - which one? References: <20190326043845.GA81414@cskk.homeip.net> Message-ID: On 2019-03-26, Cameron Simpson wrote: > Like JSON, YAML etc are far far easier than XML for the reader. If "far far easier than XML for the reader" is the bar, then we'll have to keep "nailgun to the eyeballs" on the list... That said, I agree with the rest of Cameron's post: for simpler stuff .ini is darn hard to beat. If you need nesting/arrays, then I'd probably pick YAML over JSON. Making simple changes to an automatically-generated JSON file by hand is easy enough. But, I find generating anything remotely complex by hand is far easier in YAML than it is in JSON. As usual, YMMV. -- Grant Edwards grant.b.edwards Yow! HUMAN REPLICAS are at inserted into VATS of gmail.com NUTRITIONAL YEAST ... From bgailer at gmail.com Tue Mar 26 09:57:34 2019 From: bgailer at gmail.com (Bob Gailer) Date: Tue, 26 Mar 2019 09:57:34 -0400 Subject: How to store scores of a race's players In-Reply-To: References: Message-ID: Please do not use a mangled return email address. It causes us a lot of pain when we fail to read your address to fix it and get the message bounced back. The only reason I'm even bothering to resend it is because I put a lot of work into it.: > On > Mar 26, 2019 6:55 AM, "^Bart" wrote: > > > > Hello! > > > > I need to store scores of three players for more than a race, after every race the user will read "Is the competition finished?", if the competition if finished the user will see the winner who got higest score: > > > Thank you for reaching out to us for help as You Learn Python. A good mailing list to use instead of the main python list is tutor at python.org. I'm including that list in the reply addresses; please use that address in the future and always reply all so a copy goes to that list. > > This looks like a homework assignment. Be advised we won't write code for you but we will help you when you get stuck and provide some guidance. I'm personally curious as to who wrote that specification, since it is not well written. One of the questions that fails to address is what if two or more players have the same high score? > > It's also a little hard to guide you since we don't know what you've already learned. One of the fundamental concepts in computer programming is that of a loop. Since the requirements indicate there will be more than one race that requires a loop. The simplest python construction for a loop is a while. Within that Loop you write the code once rather than rewriting it as you have done. I hope that is enough to get you started. Please apply that advice as best you can and come back with a revised program. > > > p1 = int (input ("Insert score of the first player: ")) > > p2 = int (input ("Insert score of the second player: ")) > > p3 = int (input ("Insert score of the third player: ")) > > > > race = str (input ("Is the competition finished?")) > > > > totalp1 = 0 > > totalp2 = 0 > > totalp3 = 0 > > > > winner = 0 > > > > if p1 > p2 and p1 > p3: > > winner = c1 > > elif p2 > p1 and p2 > p3: > > winner = p2 > > else: > > winner = p3 > > > > if "yes" in race: > > print("The winner is:",winner) > > else: > > p1 = int (input ("Insert score of the first player: ")) > > p2 = int (input ("Insert score of the second player: ")) > > p3 = int (input ("Insert score of the third player: ")) > > > > race = str (input ("Is the competition finished?")) > > > > You read above just my toughts, is there someone who could help me to understand how to solve it? > > > > Regards. > > ^Bart > > -- > > https://mail.python.org/mailman/listinfo/python-list From toni.sissala at gmail.com Tue Mar 26 10:15:52 2019 From: toni.sissala at gmail.com (Toni Sissala) Date: Tue, 26 Mar 2019 16:15:52 +0200 Subject: mocking for get method in requests In-Reply-To: References: Message-ID: <1fd76735-6a53-5a43-8df4-1528a509c833@gmail.com> On 18.1.2019 19:16, Shakti Kumar wrote: > Hello people, > I noticed something weird (weird as per my current knowledge, though I know > its subjective) today. Hi Kumar, > mock_req.get('').return_value = 'Hello' Here you are calling mock_req -MagicMocks get-method with parameter '' and assigning 'Hello' to its return value's return_value attribute. By default MagicMock instance methods always return a new MagicMock instance, which will create attributes on demand. You are not actually setting the return value of the patched requests, but rather assigning a return_value attribute to a local instance of a MagicMock. > mock_req.get.return_value = 'Hello' Here you are assigning 'hello' to mock_req instance's get -methods return_value. This is probably what you are after. Notice that you are not actually calling any of its methods, only assigning. Mocks are powerful but take some time to get use to. >>> from unittest import mock >>> a = mock.MagicMock() >>> a.get.return_value = 'asd' >>> a.get() 'asd' >>> a.get.assert_called_once_with() >>> b = mock.MagicMock() >>> new_mock = b.get() >>> new_mock.return_value = 'qwe' >>> new_mock() 'qwe' >>> b.get.assert_called_once_with() >>> new_mock.assert_called_once_with() >>> b.get() >>> b.get.assert_called_once_with() Traceback (most recent call last): ? File "", line 1, in ? File "/usr/lib/python3.5/unittest/mock.py", line 802, in assert_called_once_with ??? raise AssertionError(msg) AssertionError: Expected 'get' to be called once. Called 2 times. Hope this helps, Toni > > sample.py file > > -- > > import requests > def random_testing(): > out = requests.get('www.cisco.com') > a = out.json() > return a > > > testing.py file > > -- > > @patch(*?*sample.requests') > def test_random_testing(self, mock_req): > mock_req.get('').return_value = 'Hello' > out = api.random_testing() > > > Patching the sample.requests in this way does not lead the output of > requests.get() function in sample.py file to be ?Hello? as indicated > in > mock_req.get('').return_value = 'Hello' > Instead, it creates a new field called return_value in ?out', and > hence out.return_value is ?Hello? instead of just ?out?. > > But if I patch it as, > > @patch(*?*sample.requests') > def test_random_testing(self, mock_req): > mock_req.get.return_value = 'Hello' > out = api.random_testing() > > It does give the value of ?out? as ?Hello? in sample.py file. > I know I am missing something, which is where I need some help :) > > Thanks. > From arj.python at gmail.com Tue Mar 26 11:32:38 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 26 Mar 2019 19:32:38 +0400 Subject: The Mailing List Digest Project In-Reply-To: References: Message-ID: Great! will see sphinx but if i find the html hard to customise, i'll drop it. Search feature and tags coming. also, currently i'm formatting the mails rather than an article, i don't know if a real summary of the topic preferable ... Abdur-Rahmaan Janhangeer Mauritius From dboland9 at offilive.com Tue Mar 26 07:26:16 2019 From: dboland9 at offilive.com (dboland9 at offilive.com) Date: Tue, 26 Mar 2019 11:26:16 +0000 Subject: configparser - which one? In-Reply-To: <20190326043845.GA81414@cskk.homeip.net> References: <20190326043845.GA81414@cskk.homeip.net> Message-ID: <8f458dc567e72b2ed0a73248e409185d@offilive.com> Thanks Cameron. Dave, March 26, 2019 12:39 AM, "Cameron Simpson" wrote: > On 25Mar2019 23:24, Dave wrote: > >> On 3/25/19 10:58 PM, DL Neil wrote: >>> On 26/03/19 1:10 PM, Dave wrote: >> >> I use Python3 3, and expected learning how to use configparser >>>would be no big deal. Well! >> Seems there is configparser, >>>stdconfigparser, and safeconfigparser, and multiple ways to set >>>>> the section and entries to the section. A little confusing. I >>>want to future-proof may >> code, so what should I be using? >>> (with apologies for not answering the question directly) >>> >>> After striking this problem, I was encouraged to take a look at >>JSON, and thence YAML. Once >>> there, as they say, didn't look back! >>> - multi-dimensional possibilities, cf .ini >>> - similarity/correspondence with Python data structures >>> - convenient PSL >>> - easily adopted by (power-)users, cf Python code > > [...] >>> >> >> Wish I could do that. Customer wants .ini. I would need to sell them >on an alternative. The issue >> is human readable - .ini is easier for >people to understand. > > And I agree with the customer, absent more info. Unless you need deeply nested stuff, .ini is much > easier for humans to read. Not everything is a match for it (unless you start playing games with > "[clause.subclause.subsubclause]" stuff, which I'd argue is a smell indicating a format change > might be good). > > But for stuff which does fit nicely into .ini, it is FAR FAR easier on the reader. Like JSON, YAML > etc are far far easier than XML for the reader. > > Lots of stuff, particularly simple configs, go well in .ini. > > All that opinion aside: just use the configparser.ConfigParser class. It is what _used_ to be > "SafeConfigParser" in Python 2. > > Here endith the lesson. > > Cheers, > Cameron Simpson From pythonchb at gmail.com Tue Mar 26 11:28:14 2019 From: pythonchb at gmail.com (Christopher Barker) Date: Tue, 26 Mar 2019 08:28:14 -0700 Subject: The Mailing List Digest Project In-Reply-To: References: Message-ID: On Mon, Mar 25, 2019 at 10:01 PM Abdur-Rahmaan Janhangeer < arj.python at gmail.com> wrote: > As proposed on python-ideas, i setup a repo to turn mail threads into > articles. > Thanks for doing this ? I find myself frequently telling people about past relevant threads on this list - it will be great to have a single place to point people. It can be hard to find stuff in the archives if you?re not sure what to search for. here is the repo > > https://github.com/Abdur-rahmaanJ/py-mailing-list-summary > > i included a script to build .md to .html > Maybe Sphinx and RST instead? For consistency with other Python docs? But markup is far less important than content. -CHB (with syntax highlighting) here is the index > > https://abdur-rahmaanj.github.io/py-mailing-list-summary/ > > included 3 articles as a start > > if you want to contribute an article, just follow existing .md format and > put it in the .md folder > > planning to go across ideas, list and dev > > i can tell you, it's a really enjoyable experience. > > psst. we can enhance some html later > > -- > Abdur-Rahmaan Janhangeer > Mauritius > -- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython From PythonList at DancesWithMice.info Tue Mar 26 15:08:49 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 27 Mar 2019 08:08:49 +1300 Subject: configparser - which one? In-Reply-To: References: <20190326043845.GA81414@cskk.homeip.net> Message-ID: <3fa3923f-6e93-7081-508c-660a7b4f96b4@DancesWithMice.info> On 27/03/19 2:44 AM, Grant Edwards wrote: > On 2019-03-26, Cameron Simpson wrote: > >> Like JSON, YAML etc are far far easier than XML for the reader. > > If "far far easier than XML for the reader" is the bar, then we'll > have to keep "nailgun to the eyeballs" on the list... > > That said, I agree with the rest of Cameron's post: for simpler stuff > .ini is darn hard to beat. If you need nesting/arrays, then I'd > probably pick YAML over JSON. Making simple changes to an > automatically-generated JSON file by hand is easy enough. But, I find > generating anything remotely complex by hand is far easier in YAML > than it is in JSON. As usual, YMMV. In my users' case, choosing YAML was a decision made before the (relatively) recent improvements to the .ini interface. (Thanks for that news!) From a programmer's PoV, the convenience of having whatever config-file-rules handled within a library, so that your incoming data is 'reduced' to a dict/list structure, cannot be understated. From a user's PoV, (the few who should ever be allowed to come into contact with such things) both .ini and YAML (and presumably) JSON are readily understandable, in my experience (YMMV) - perhaps in this case I've been 'blessed' with scientific/math/stats-types who are relatively 'power users' and used to planning their experiments/analyses! As far as specs go, I can't say I've ever bothered to read those for JSON, YAML, or even .ini. Have you? Read some article(s), started 'playing', achieved what was required, no fuss-no muss... The previous post criticising same, lacks specifics, so can't learn from it. Earlier, mention was made of multiple 'dimensions' which are (at least to me, and those users) 'cleaner' in YAML/JSON/XML - however, heading 'too far' in that direction invites 'trouble'. What does the Zen of Python say about simplicity! As with all tools, one really important criteria is the quality of information-provided when things 'go wrong'. We've all been frustrated because a 'missing comma/bracket/colon/...' "on line nnn" is not supposed to be there at all - and we've had to comb 'backwards' through the code to find where the missing punctuation should have been... Given the relative ease with which both .ini and YAML can (now) be utilised (both by 'them' and by 'us'), there are not sufficient advantages/disadvantages to make it a 'big deal'. Other factors come into play and assume greater import: the OP mentioned user-preference/spec; whichever format this user's other systems utilise; the ease (reduced cost) of reaching into one's 'bag of tricks' for an already-coded ("re-usable") config-function... -- Regards =dn From a24061 at ducksburg.com Tue Mar 26 15:55:17 2019 From: a24061 at ducksburg.com (Adam Funk) Date: Tue, 26 Mar 2019 19:55:17 +0000 Subject: Creating LF, NEL line terminators by accident? (python3) Message-ID: <5mcqmfxirn.ln2@news.ducksburg.com> Hi, I have a Python 3 (using 3.6.7) program that reads a TSV file, does some churning with the data, and writes a TSV file out. #v+ print('reading', options.input_file) with open(options.input_file, 'r', encoding='utf-8-sig') as f: for line in f.readlines(): row = line.split('\t') # DO STUFF WITH THE CELLS IN THE ROW # ... print('writing', options.output_file) with open(options.output_file, 'w', encoding='utf-8') as f: # MAKE THE HEADER list of str f.write('\t'.join(header) + '\n') for doc_id in sorted(all_ids): # CREATE A ROW list of str FOR EACH DOCUMENT ID f.write('\t'.join(row) + '\n') #v- I noticed that the file command on the output returns "UTF-8 Unicode text, with very long lines, with LF, NEL line terminators". I'd never come across NEL terminators until now, and I've never (AFAIK) created a file with them before. Any idea why this is happening? (I tried changing the input encoding from 'utf-8-sig' to 'utf-8' but got the same results with the output.) Thanks, Adam -- I am at the moment writing a lengthy indictment against our century. When my brain begins to reel from my literary labors, I make an occasional cheese dip. ---Ignatius J Reilly From python at mrabarnett.plus.com Tue Mar 26 17:41:23 2019 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 26 Mar 2019 21:41:23 +0000 Subject: Creating LF, NEL line terminators by accident? (python3) In-Reply-To: <5mcqmfxirn.ln2@news.ducksburg.com> References: <5mcqmfxirn.ln2@news.ducksburg.com> Message-ID: <9655982b-972c-68a9-7051-258c43333808@mrabarnett.plus.com> On 2019-03-26 19:55, Adam Funk wrote: > Hi, > > I have a Python 3 (using 3.6.7) program that reads a TSV file, does > some churning with the data, and writes a TSV file out. > > #v+ > print('reading', options.input_file) > with open(options.input_file, 'r', encoding='utf-8-sig') as f: > for line in f.readlines(): > row = line.split('\t') > # DO STUFF WITH THE CELLS IN THE ROW > > # ... > > print('writing', options.output_file) > with open(options.output_file, 'w', encoding='utf-8') as f: > # MAKE THE HEADER list of str > f.write('\t'.join(header) + '\n') > > for doc_id in sorted(all_ids): > # CREATE A ROW list of str FOR EACH DOCUMENT ID > f.write('\t'.join(row) + '\n') > #v- > > I noticed that the file command on the output returns "UTF-8 Unicode > text, with very long lines, with LF, NEL line terminators". > > I'd never come across NEL terminators until now, and I've never > (AFAIK) created a file with them before. Any idea why this is > happening? > > (I tried changing the input encoding from 'utf-8-sig' to 'utf-8' but > got the same results with the output.) > Does the input contain any NEL? Do the strings that you write out contain them? From tim at akwebsoft.com Tue Mar 26 17:57:52 2019 From: tim at akwebsoft.com (Tim Johnson) Date: Tue, 26 Mar 2019 13:57:52 -0800 Subject: Managing pipenv virtualenvs Message-ID: <20190326215752.GA5115@mail.akwebsoft.com> I'm on ubuntu 16.04 using pipenv for the "Django for Beginners..." tutorial book. each chapter instructs me to create a new virtual environment with a folder under ~/.local/share/virtualenvs folders are named with the project name followed by an hyphen and a brief codified string. examples helloworld-_e28Oloi pages-Du4qJjUr What would happen if I deleted the first folder, which was created in a previous chapter? ... trying to minimize my SSD real estate. thanks -- Tim Johnson http://www.tj49.com From onlinejudge95 at gmail.com Tue Mar 26 18:14:31 2019 From: onlinejudge95 at gmail.com (Test Bot) Date: Wed, 27 Mar 2019 03:44:31 +0530 Subject: Managing pipenv virtualenvs In-Reply-To: <20190326215752.GA5115@mail.akwebsoft.com> References: <20190326215752.GA5115@mail.akwebsoft.com> Message-ID: Nothing much i think. If you are properly managing dependencies for each venv, then each new venv should have the same state as the previous one along with some extra dependencies for each new chapter (haven't gone through the specific book, but I am assuming that in the book, every chapter builds on the previous one). On a personal note it sounds strange why the author wants to have different venv's for each chapter. On Wed, Mar 27, 2019, 3:30 AM Tim Johnson wrote: > I'm on ubuntu 16.04 > > using pipenv for the "Django for Beginners..." tutorial book. > > each chapter instructs me to create a new virtual environment with a > folder under ~/.local/share/virtualenvs > > folders are named with the project name followed by an hyphen and a > brief codified string. > examples > helloworld-_e28Oloi > pages-Du4qJjUr > > What would happen if I deleted the first folder, which was created > in a previous chapter? > > ... trying to minimize my SSD real estate. > thanks > -- > Tim Johnson > http://www.tj49.com > -- > https://mail.python.org/mailman/listinfo/python-list > From cs at cskk.id.au Tue Mar 26 18:34:45 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 27 Mar 2019 09:34:45 +1100 Subject: Your IDE's? In-Reply-To: <20190325214735.0ee5721d@bigbox.christie.dr> References: <20190325214735.0ee5721d@bigbox.christie.dr> Message-ID: <20190326223445.GA27852@cskk.homeip.net> On 25Mar2019 21:47, Tim Chase wrote: >On 2019-03-25 21:38, John Doe wrote: >> What is your favorite Python IDE? > >Unix. > >https://sanctum.geek.nz/arabesque/series/unix-as-ide/ > >Namely $EDITOR (for some value of ed/vi/vim), a shell (usually >bash, ksh, or /bin/sh), a VCS (usually git, subversion, rcs, or >fossil, though sometimes CVS or Mercurial), and a whole suite of >other battle-tested tools that work together. The same. A good terminal emultator helps a lot too: I use iTerm3 on a Mac, and it is outstanding. In particular, it lets one tile terminal sessions really well. Cheers, Cameron Simpson From tim at akwebsoft.com Tue Mar 26 18:48:40 2019 From: tim at akwebsoft.com (Tim Johnson) Date: Tue, 26 Mar 2019 14:48:40 -0800 Subject: Managing pipenv virtualenvs In-Reply-To: References: <20190326215752.GA5115@mail.akwebsoft.com> Message-ID: <20190326224840.GB5115@mail.akwebsoft.com> * Test Bot [190326 14:18]: > Nothing much i think. If you are properly managing dependencies for each > venv, then each new venv should have the same state as the previous one Good to hear.... > along with some extra dependencies for each new chapter (haven't gone > through the specific book, but I am assuming that in the book, every > chapter builds on the previous one). The author's source code is on github, so I downloaded all of it for my edification. It appears that consecutive chapters do not always build on the following, i.e. have the previous chapter files. I guess I will find out why ... thank you > On a personal note it sounds strange why the author wants to have different > venv's for each chapter. > > On Wed, Mar 27, 2019, 3:30 AM Tim Johnson wrote: > > > I'm on ubuntu 16.04 > > > > using pipenv for the "Django for Beginners..." tutorial book. > > > > each chapter instructs me to create a new virtual environment with a > > folder under ~/.local/share/virtualenvs > > > > folders are named with the project name followed by an hyphen and a > > brief codified string. > > examples > > helloworld-_e28Oloi > > pages-Du4qJjUr > > > > What would happen if I deleted the first folder, which was created > > in a previous chapter? > > > > ... trying to minimize my SSD real estate. > > thanks > > -- > > Tim Johnson > > http://www.tj49.com > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list -- Tim Johnson http://www.tj49.com From rshepard at appl-ecosys.com Tue Mar 26 19:09:40 2019 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 26 Mar 2019 16:09:40 -0700 (PDT) Subject: Your IDE's? In-Reply-To: <20190326223445.GA27852@cskk.homeip.net> References: <20190325214735.0ee5721d@bigbox.christie.dr> <20190326223445.GA27852@cskk.homeip.net> Message-ID: On 2019-03-25 21:38, John Doe wrote: > What is your favorite Python IDE? Emacs on Slackware. Rich From onlinejudge95 at gmail.com Tue Mar 26 19:38:20 2019 From: onlinejudge95 at gmail.com (Test Bot) Date: Wed, 27 Mar 2019 05:08:20 +0530 Subject: Managing pipenv virtualenvs In-Reply-To: <20190326224840.GB5115@mail.akwebsoft.com> References: <20190326215752.GA5115@mail.akwebsoft.com> <20190326224840.GB5115@mail.akwebsoft.com> Message-ID: If the chapters are not contiguous then I can't find a reason to delete them (previous venv). Moreover it would be better practice to keep separate venv and not to use a single venv for multiple codebase. Highly discouraged should be to use the systemwide interpreter. Moreover the whole idea of using pipenv/pip is to make the venv easy to recreate. That being said I would focus more on whether my pipfile/requirements.txt is maintained properly or not. If it is then spinning up the same venv is an easy task. On Wed, Mar 27, 2019, 4:21 AM Tim Johnson wrote: > * Test Bot [190326 14:18]: > > Nothing much i think. If you are properly managing dependencies for each > > venv, then each new venv should have the same state as the previous one > Good to hear.... > > > along with some extra dependencies for each new chapter (haven't gone > > through the specific book, but I am assuming that in the book, every > > chapter builds on the previous one). > The author's source code is on github, so I downloaded all of it > for my edification. > > It appears that consecutive chapters do not always build on the > following, i.e. have the previous chapter files. > > I guess I will find out why ... > thank you > > On a personal note it sounds strange why the author wants to have > different > > venv's for each chapter. > > > > On Wed, Mar 27, 2019, 3:30 AM Tim Johnson wrote: > > > > > I'm on ubuntu 16.04 > > > > > > using pipenv for the "Django for Beginners..." tutorial book. > > > > > > each chapter instructs me to create a new virtual environment with a > > > folder under ~/.local/share/virtualenvs > > > > > > folders are named with the project name followed by an hyphen and a > > > brief codified string. > > > examples > > > helloworld-_e28Oloi > > > pages-Du4qJjUr > > > > > > What would happen if I deleted the first folder, which was created > > > in a previous chapter? > > > > > > ... trying to minimize my SSD real estate. > > > thanks > > > -- > > > Tim Johnson > > > http://www.tj49.com > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > -- > Tim Johnson > http://www.tj49.com > -- > https://mail.python.org/mailman/listinfo/python-list > From tim at akwebsoft.com Tue Mar 26 19:56:19 2019 From: tim at akwebsoft.com (Tim Johnson) Date: Tue, 26 Mar 2019 15:56:19 -0800 Subject: Managing pipenv virtualenvs In-Reply-To: References: <20190326215752.GA5115@mail.akwebsoft.com> <20190326224840.GB5115@mail.akwebsoft.com> Message-ID: <20190326235619.GC5115@mail.akwebsoft.com> * Test Bot [190326 15:44]: > If the chapters are not contiguous then I can't find a reason to delete > them (previous venv). Moreover it would be better practice to keep separate > venv and not to use a single venv for multiple codebase. Highly discouraged > should be to use the systemwide interpreter. > > Moreover the whole idea of using pipenv/pip is to make the venv easy to > recreate. That being said I would focus more on whether my > pipfile/requirements.txt is maintained properly or not. If it is then > spinning up the same venv is an easy task. thanks again, Test Bot ... > On Wed, Mar 27, 2019, 4:21 AM Tim Johnson wrote: > > > * Test Bot [190326 14:18]: > > > Nothing much i think. If you are properly managing dependencies for each > > > venv, then each new venv should have the same state as the previous one > > Good to hear.... > > > > > along with some extra dependencies for each new chapter (haven't gone > > > through the specific book, but I am assuming that in the book, every > > > chapter builds on the previous one). > > The author's source code is on github, so I downloaded all of it > > for my edification. > > > > It appears that consecutive chapters do not always build on the > > following, i.e. have the previous chapter files. > > > > I guess I will find out why ... > > thank you > > > On a personal note it sounds strange why the author wants to have > > different > > > venv's for each chapter. > > > > > > On Wed, Mar 27, 2019, 3:30 AM Tim Johnson wrote: > > > > > > > I'm on ubuntu 16.04 > > > > > > > > using pipenv for the "Django for Beginners..." tutorial book. > > > > > > > > each chapter instructs me to create a new virtual environment with a > > > > folder under ~/.local/share/virtualenvs > > > > > > > > folders are named with the project name followed by an hyphen and a > > > > brief codified string. > > > > examples > > > > helloworld-_e28Oloi > > > > pages-Du4qJjUr > > > > > > > > What would happen if I deleted the first folder, which was created > > > > in a previous chapter? > > > > > > > > ... trying to minimize my SSD real estate. > > > > thanks > > > > -- > > > > Tim Johnson > > > > http://www.tj49.com > > > > -- > > > > https://mail.python.org/mailman/listinfo/python-list > > > > > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > -- > > Tim Johnson > > http://www.tj49.com > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list -- Tim Johnson http://www.tj49.com From bill at baddogconsulting.com Tue Mar 26 20:04:11 2019 From: bill at baddogconsulting.com (Bill Deegan) Date: Tue, 26 Mar 2019 17:04:11 -0700 Subject: SCons 3.0.5 Released Message-ID: A new SCons release, 3.0.5, is now available on the SCons download page: https://scons.org/pages/download.html And via pypi: pip install scons SCons is a tool for building software (and other files). SCons is implemented in Python, and its "configuration files" are actually Python scripts, allowing you to use the full power of a real scripting language to solve build problems. You do not, however, need to know Python to use SCons effectively. Here is a summary of the changes since 3.0.4: CHANGED/ENHANCED EXISTING FUNCTIONALITY - Change the default for AppendENVPath to delete_existing=0, so path order will not be changed, unless explicitly set (Issue #3276) - Add lex construction variable LEXUNISTD for turning off unix headers on windows - Update lex tool to use win_flex on windows if available - Add the textfile tool to the default tool list FIXES - Fix Issue #3283 - Handle using --config=force in combination with Decider('MD5-timestamp'). 3.0.2 in fix for issue #2980 added that deciders can throw DeciderNeedsNode exception. The Configure logic directly calls the decider when using --config=force but wasn't handling that exception. This would yield minimally configure tests using TryLink() not running and leaving TypeError Nonetype exception in config.log - Fix Issue #3303 - Handle --config=force overwriting the Environment passed into Configure()'s Decider and not clearing it when the configure context is completed. - Add default paths for yacc tool on windows to include cygwin, mingw, and chocolatey - Fix issue #2799 - Fix mingw tool to respect SHCCCOMSTR, SHLINKCOMSTR and LDMODULECOMSTR - Fix Issue #3329 - Add support for MS SDK V10.0A (which is commonly installed with VS2017) - Fix Issue #3333 - Add support for finding vswhere under 32 bit windows installs. - Update the MSVC tool to include the nologo flag by default in RCFLAGS - Fixed bug which threw error when running SCons on windows system with no MSVC installed. IMPROVEMENTS - Do not store build host+user name if reproducible builds are wanted git shortlog --no-merges -ns 3.0.4..HEAD 34 William Deegan 33 Mats Wichmann 18 Daniel 4 Daniel Moody 3 Bernhard M. Wiedemann 2 Maciej Kumorek From tim at akwebsoft.com Tue Mar 26 20:26:29 2019 From: tim at akwebsoft.com (Tim Johnson) Date: Tue, 26 Mar 2019 16:26:29 -0800 Subject: Your IDE's? In-Reply-To: References: <20190325214735.0ee5721d@bigbox.christie.dr> <20190326223445.GA27852@cskk.homeip.net> Message-ID: <20190327002629.GD5115@mail.akwebsoft.com> * Rich Shepard [190326 15:19]: > On 2019-03-25 21:38, John Doe wrote: > > > What is your favorite Python IDE? > > Emacs on Slackware. I'm an old Slacker, but got lazy and even older, so now use ubuntu. I also use emacs to which I have added evil and elpy; and further customized with plenty of my own elisp code. They won't take any of that away unless they pry it from my cold, dead fingers, but that's just me. :) I wouldn't wish emacs or vim on anyone who didn't feel that the learning curve was worth it. MTCW -- Tim Johnson http://www.tj49.com From pythonchb at gmail.com Tue Mar 26 21:00:24 2019 From: pythonchb at gmail.com (Christopher Barker) Date: Tue, 26 Mar 2019 18:00:24 -0700 Subject: The Mailing List Digest Project In-Reply-To: References: Message-ID: On Tue, Mar 26, 2019 at 8:32 AM Abdur-Rahmaan Janhangeer < arj.python at gmail.com> wrote: > Great! will see sphinx but if i find the html hard to customise, i'll drop > it. > Sphinx has theming support, plus you can do custom CSS if you want. But Highly discourage you from worrying about formatting ? decent structure is good enough, and content is what matters. Search feature and tags coming. > Sphinx has search built in. also, currently i'm formatting the mails rather than an article, i don't > know if a real summary of the topic preferable ... > These mailing lists are really big, and the threads are long and scattered, and they are archived and searchable already. So I think the real value would be article-style summaries (with links to the threads). For Python-Ideas, I?m thinking kind of a mini rejected PEP ... -CHB > > Abdur-Rahmaan Janhangeer > Mauritius > -- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython From arj.python at gmail.com Tue Mar 26 22:22:32 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Wed, 27 Mar 2019 06:22:32 +0400 Subject: The Mailing List Digest Project In-Reply-To: References: Message-ID: #agree From alexey.muranov at gmail.com Wed Mar 27 04:21:58 2019 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Wed, 27 Mar 2019 09:21:58 +0100 Subject: Syntax for one-line "nonymous" functions in "declaration style" Message-ID: <1553674918.3032.0@gmail.com> Whey you need a simple function in Python, there is a choice between a normal function declaration and an assignment of a anonymous function (defined by a lambda-expression) to a variable: def f(x): return x*x or f = lambda x: x*x It would be however more convenient to be able to write instead just f(x) = x*x (like in Haskell and such). Have this idea been discussed before? I do not see any conflicts with the existing syntax. The following would also work: incrementer(m)(n) = n + m instead of incrementer = lambda m: lambda n: n + m Alexey. From as at sci.fi Wed Mar 27 04:55:01 2019 From: as at sci.fi (Anssi Saari) Date: Wed, 27 Mar 2019 10:55:01 +0200 Subject: Your IDE's? References: <86ef6u1ohi.fsf@benfinney.id.au> Message-ID: Ben Finney writes: > Emacs and a shell multiplexer (today, that's GNU Screen, but others > swear that I should try TMux). I've actually been using tmux for a while. The only reason and the only thing I can think of that it does and screen doesn't is that tmux can display italic text and screen apparently can't. So I went with tmux for Usenet. Well, there were some claims from tmux about it being a better terminal but I can't really see a difference. From p.f.moore at gmail.com Wed Mar 27 05:10:40 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 27 Mar 2019 09:10:40 +0000 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: <1553674918.3032.0@gmail.com> References: <1553674918.3032.0@gmail.com> Message-ID: On Wed, 27 Mar 2019 at 08:25, Alexey Muranov wrote: > > Whey you need a simple function in Python, there is a choice between a > normal function declaration and an assignment of a anonymous function > (defined by a lambda-expression) to a variable: > > def f(x): return x*x > > or > > f = lambda x: x*x > > It would be however more convenient to be able to write instead just > > f(x) = x*x Why? Is saving a few characters really that helpful? So much so that it's worth adding a *third* method of defining functions, which would need documenting, adding to training materials, etc, etc? -1 on this. Paul From onlinejudge95 at gmail.com Wed Mar 27 05:42:48 2019 From: onlinejudge95 at gmail.com (Test Bot) Date: Wed, 27 Mar 2019 15:12:48 +0530 Subject: Search and Replace of string in a yaml file In-Reply-To: References: Message-ID: Assuming you are asking about the logic at the uber level. You can try handling yaml file with pyyaml. It is a 3rd party package which has a good support for I/O related to yaml files. After you are able to read the data from the file, you need to apply your business logic to it. And log all the erroneous matches. For example import yaml with open(path/to/yaml/file, "r") as fp: yaml_data = yaml.safe_load(fp) On Sat, Mar 23, 2019, 5:33 PM Pradeep Patra wrote: > Hi all, > > I have several yaml files in a directory around 100s. I have some values > and my script should search a string(reading from the JSON file) from the > series of yaml files and run some validation like the key of the file that > is updated in the yaml file and run some basic validation tests like data > integrity of the replaced string with the source string read from JSON. Can > anyone suggest some reliable and efficient method to achieve this and > appreciate some examples for the same? > > Regards > Pradeep > -- > https://mail.python.org/mailman/listinfo/python-list > From alexey.muranov at gmail.com Wed Mar 27 08:27:53 2019 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Wed, 27 Mar 2019 13:27:53 +0100 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: References: <1553674918.3032.0@gmail.com> Message-ID: <1553689673.7168.0@gmail.com> On mer., mars 27, 2019 at 10:10 AM, Paul Moore wrote: > On Wed, 27 Mar 2019 at 08:25, Alexey Muranov > wrote: >> >> Whey you need a simple function in Python, there is a choice >> between a >> normal function declaration and an assignment of a anonymous >> function >> (defined by a lambda-expression) to a variable: >> >> def f(x): return x*x >> >> or >> >> f = lambda x: x*x >> >> It would be however more convenient to be able to write instead just >> >> f(x) = x*x > > Why? Is saving a few characters really that helpful? So much so that > it's worth adding a *third* method of defining functions, which would > need documenting, adding to training materials, etc, etc? > Because i think i would prefer to write it this way. (Almost no new documentation or tutorials would be needed IMHO.) Alexey. From fabiofz at gmail.com Wed Mar 27 09:49:37 2019 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Wed, 27 Mar 2019 10:49:37 -0300 Subject: PyDev 7.2.0 Released Message-ID: PyDev 7.2.0 Release Highlights ------------------------------- * Debugger improvements (updated to pydevd 1.6.0). * Fixed issue quoting/unquoting parameters for subprocess. * Fixed exception breakpoints for Django and Jinja2. * Console hook import compatibility with matplotlib and pylab fixed. * Fixed issue where pipenv executable search was being executed over and over when it was not found. About PyDev --------------------------- PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development, now also available for Python on Visual Studio Code. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. It is also available as a standalone through LiClipse with goodies such as multiple cursors, theming and support for many other languages, such as Django Templates, Jinja2, Html, JavaScript, etc. Links: PyDev: http://pydev.org PyDev Blog: http://pydev.blogspot.com PyDev on VSCode: http://pydev.org/vscode LiClipse: http://www.liclipse.com PyVmMonitor - Python Profiler: http://www.pyvmmonitor.com/ Cheers, Fabio Zadrozny From grant.b.edwards at gmail.com Wed Mar 27 10:05:25 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 27 Mar 2019 14:05:25 -0000 (UTC) Subject: Your IDE's? References: Message-ID: On 2019-03-25, John Doe wrote: > What is your favorite Python IDE? Unix+Emacs I sometimes wish that Emacs had a better code folding mode when browsing other people's code, but the editors I've tried that do have nice code-folding fall down at too many other tasks. -- Grant Edwards grant.b.edwards Yow! Was my SOY LOAF left at out in th'RAIN? It tastes gmail.com REAL GOOD!! From p.f.moore at gmail.com Wed Mar 27 10:42:17 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 27 Mar 2019 14:42:17 +0000 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: <1553689673.7168.0@gmail.com> References: <1553674918.3032.0@gmail.com> <1553689673.7168.0@gmail.com> Message-ID: On Wed, 27 Mar 2019 at 12:27, Alexey Muranov wrote: > > On mer., mars 27, 2019 at 10:10 AM, Paul Moore > wrote: > > On Wed, 27 Mar 2019 at 08:25, Alexey Muranov > > wrote: > >> > >> Whey you need a simple function in Python, there is a choice > >> between a > >> normal function declaration and an assignment of a anonymous > >> function > >> (defined by a lambda-expression) to a variable: > >> > >> def f(x): return x*x > >> > >> or > >> > >> f = lambda x: x*x > >> > >> It would be however more convenient to be able to write instead just > >> > >> f(x) = x*x > > > > Why? Is saving a few characters really that helpful? So much so that > > it's worth adding a *third* method of defining functions, which would > > need documenting, adding to training materials, etc, etc? > > Because i think i would prefer to write it this way. That's not likely to be sufficient reason for changing a language that's used by literally millions of people. > (Almost no new documentation or tutorials would be needed IMHO.) Documentation would be needed to explain how the new construct worked, for people who either wanted to use it or encountered it in other people's code. While it may be obvious to you how it works, it likely won't be to others, and there will probably be edge cases you haven't considered that others will find and ask about. Your interest in improving the language is great, but there are a great many practical considerations in any change, and if you actually want your idea to progress, you'll need to be prepared to address those. Paul From antoon.pardon at vub.be Wed Mar 27 11:41:42 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 27 Mar 2019 16:41:42 +0100 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: <1553674918.3032.0@gmail.com> References: <1553674918.3032.0@gmail.com> Message-ID: <9c62f5fc-2123-c9e5-124e-36e71d5f502e@vub.be> On 27/03/19 09:21, Alexey Muranov wrote: > Whey you need a simple function in Python, there is a choice between a > normal function declaration and an assignment of a anonymous function > (defined by a lambda-expression) to a variable: > > ?? def f(x): return x*x > > or > > ?? f = lambda x: x*x > > It would be however more convenient to be able to write instead just > > ?? f(x) = x*x > > (like in Haskell and such). > > Have this idea been discussed before? > > I do not see any conflicts with the existing syntax.?? The following > would also work: I don't know. Something like the following is already legal: f(x)[n] = x * n And it does something completly different. -- Antoon Pardon. From countryone77 at gmail.com Wed Mar 27 12:15:03 2019 From: countryone77 at gmail.com (Bev in TX) Date: Wed, 27 Mar 2019 11:15:03 -0500 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: <9c62f5fc-2123-c9e5-124e-36e71d5f502e@vub.be> References: <1553674918.3032.0@gmail.com> <9c62f5fc-2123-c9e5-124e-36e71d5f502e@vub.be> Message-ID: <6D84088B-D562-42D8-980B-9C8505FB0ADA@gmail.com> > On Mar 27, 2019, at 10:41 AM, Antoon Pardon wrote: > > I don't know. Something like the following is already legal: > > f(x)[n] = x * n > > And it does something completly different. Where would I find information on what this does in the documentation? Bev in TX From rhodri at kynesim.co.uk Wed Mar 27 12:25:49 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 27 Mar 2019 16:25:49 +0000 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: <6D84088B-D562-42D8-980B-9C8505FB0ADA@gmail.com> References: <1553674918.3032.0@gmail.com> <9c62f5fc-2123-c9e5-124e-36e71d5f502e@vub.be> <6D84088B-D562-42D8-980B-9C8505FB0ADA@gmail.com> Message-ID: <09fc2b2c-b46e-1c46-d3d0-84c157c7d659@kynesim.co.uk> On 27/03/2019 16:15, Bev in TX wrote: > >> On Mar 27, 2019, at 10:41 AM, Antoon Pardon wrote: >> >> I don't know. Something like the following is already legal: >> >> f(x)[n] = x * n >> >> And it does something completly different. > > Where would I find information on what this does in the documentation? Nowhere in particular, it's a consequence of putting things together. The part that Antoon isn't mentioning is that he's presuming the function f(x) returns a list or something similar that we can then index. You're more likely to see that sort of code written as: a = f(x) a[n] = x *n which makes it look a lot less magical. -- Rhodri James *-* Kynesim Ltd From abrault at mapgears.com Wed Mar 27 12:41:16 2019 From: abrault at mapgears.com (Alexandre Brault) Date: Wed, 27 Mar 2019 12:41:16 -0400 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: References: <1553674918.3032.0@gmail.com> <1553689673.7168.0@gmail.com> Message-ID: <1a8f6176-0c9d-e1d4-3189-d273bd22dba9@mapgears.com> On 2019-03-27 10:42 a.m., Paul Moore wrote: > On Wed, 27 Mar 2019 at 12:27, Alexey Muranov wrote: >> On mer., mars 27, 2019 at 10:10 AM, Paul Moore >> wrote: >>> On Wed, 27 Mar 2019 at 08:25, Alexey Muranov >>> wrote: >>>> Whey you need a simple function in Python, there is a choice >>>> between a >>>> normal function declaration and an assignment of a anonymous >>>> function >>>> (defined by a lambda-expression) to a variable: >>>> >>>> def f(x): return x*x >>>> >>>> or >>>> >>>> f = lambda x: x*x >>>> >>>> It would be however more convenient to be able to write instead just >>>> >>>> f(x) = x*x >>> Why? Is saving a few characters really that helpful? So much so that >>> it's worth adding a *third* method of defining functions, which would >>> need documenting, adding to training materials, etc, etc? >> Because i think i would prefer to write it this way. > That's not likely to be sufficient reason for changing a language > that's used by literally millions of people. > >> (Almost no new documentation or tutorials would be needed IMHO.) > Documentation would be needed to explain how the new construct worked, > for people who either wanted to use it or encountered it in other > people's code. While it may be obvious to you how it works, it likely > won't be to others, and there will probably be edge cases you haven't > considered that others will find and ask about. For what it's worth, if I encountered "f(x) = x * x" in code, my first thought would be that Python somehow added a way to return an assignable reference from a function, rather than this being an anonymous function declaration. So documentation of that syntax would 100% be required Alex From tagrain at gmail.com Wed Mar 27 14:25:58 2019 From: tagrain at gmail.com (Thomas Grainger) Date: Wed, 27 Mar 2019 18:25:58 +0000 Subject: asyncio KeyboardInterrupt in select Message-ID: It seems quite easy to cause asyncio to deadlock: File "/usr/lib/python3.6/asyncio/base_events.py", line 1404, in _run_once event_list = self._selector.select(timeout) File "/usr/lib/python3.6/selectors.py", line 445, in select fd_event_list = self._epoll.poll(timeout, max_ev) KeyboardInterrupt ^CError in atexit._run_exitfuncs: Traceback (most recent call last): File "/usr/lib/python3.6/concurrent/futures/thread.py", line 40, in _python_exit t.join() File "/usr/lib/python3.6/threading.py", line 1056, in join self._wait_for_tstate_lock() File "/usr/lib/python3.6/threading.py", line 1072, in _wait_for_tstate_lock elif lock.acquire(block, timeout): and you get a lot of hits for this exception on google: https://www.google.com/search?q=File+ "/usr/lib/python3.6/selectors.py",+line+445,+in+select+++++fd_event_list+%3D+self._epoll.poll(timeout,+max_ev)+KeyboardInterrupt&filter=0 Thomas Grainger From p.f.moore at gmail.com Wed Mar 27 14:41:40 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 27 Mar 2019 18:41:40 +0000 Subject: Library for parsing binary structures Message-ID: I'm looking for a library that lets me parse binary data structures. The stdlib struct module is fine for simple structures, but when it gets to more complicated cases, you end up doing a lot of the work by hand (which isn't that hard, and is generally perfectly viable, but I'm feeling lazy ;-)) I know of Construct, which is a nice declarative language, but it's either weak, or very badly documented, when it comes to recursive structures. (I really like Construct, and if I could only understand the docs better I may well not need to look any further, but as it is, I can't see anything showing how to do recursive structures...) I am specifically trying to parse a structure that looks something like the following: Multiple instances of: - a type byte - a chunk of data structured based on the type types include primitives like byte, integer, etc, as well as (type byte, count, data) - data is "count" occurrences of data of the given type. That last one is a list, and yes, you can have lists of lists, so the structure is recursive. Does anyone know of any other binary data parsing libraries, that can handle recursive structures reasonably cleanly? I'm already *way* past the point where it would have been quicker for me to write the parsing code by hand rather than trying to find a "quick way", so the questions, honestly mostly about finding out what people recommend for jobs like this rather than actually needing something specific to this problem. But I do keep hitting the need to parse binary structures, and having something in my toolbox for the future would be really nice. Paul From alexey.muranov at gmail.com Wed Mar 27 15:33:58 2019 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Wed, 27 Mar 2019 20:33:58 +0100 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: References: Message-ID: <1553715238.2942.0@gmail.com> On mer., Mar 27, 2019 at 5:00 PM, python-list-request at python.org wrote: > On 27/03/19 09:21, Alexey Muranov wrote: >> Whey you need a simple function in Python, there is a choice >> between a >> normal function declaration and an assignment of a anonymous >> function >> (defined by a lambda-expression) to a variable: >> >> def f(x): return x*x >> >> or >> >> f = lambda x: x*x >> >> It would be however more convenient to be able to write instead just >> >> f(x) = x*x >> >> (like in Haskell and such). >> >> Have this idea been discussed before? >> >> I do not see any conflicts with the existing syntax. The following >> would also work: > > I don't know. Something like the following is already legal: > > f(x)[n] = x * n > > And it does something completly different. > Thanks for pointing out this example, but so far i do not see any issue with this. Of course assignment (to an identifier) is a completely different type of operation than in-place mutation (of an object) with __setitem__, etc. In <...> [<...>] = <...> the part to the left of "[<...>]=" is an expression that is to be evaluated, and only its value matters. Here "[]=" can be viewed as a method call, which is distinguished by the context from "[]" method call (__getitem__). In = <...> the is not evaluated. I still think that ()...() = <...> is unambiguous. The following seems possible too: a[m][n](x)(y) = m*x + n*y It would be the same as a[m][n] = lambda x: lambda y: m*x + n*y Here a[m] is evaluated, and on the result the method "[]=" (__setitem__) is called. Basically, "()...()=" seems to technically fit all contexts where "=" fits... Alexey. From matthew.herzog at gmail.com Wed Mar 27 16:51:44 2019 From: matthew.herzog at gmail.com (Mr Zaug) Date: Wed, 27 Mar 2019 13:51:44 -0700 (PDT) Subject: Your IDE's? In-Reply-To: References: Message-ID: <395e5dae-5d50-4571-9df0-72c55af3da22@googlegroups.com> On Monday, March 25, 2019 at 5:38:41 PM UTC-4, John Doe wrote: > What is your favorite Python IDE? "Your IDE's?" is not a question, nor is any word in English made plural with an apostrophe s. From tjreedy at udel.edu Wed Mar 27 17:25:35 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Mar 2019 17:25:35 -0400 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: <1553674918.3032.0@gmail.com> References: <1553674918.3032.0@gmail.com> Message-ID: On 3/27/2019 4:21 AM, Alexey Muranov wrote: > Whey you need a simple function in Python, there is a choice between a > normal function declaration and an assignment of a anonymous function > (defined by a lambda-expression) to a variable: > > ?? def f(x): return x*x > > or > > ?? f = lambda x: x*x PEP 8 properly recommends against this the latter as functionally it has no advantage and the disadvantage that f.__name__ becomes the generic '' instead of the specific 'f'. This is not useful for code that expects specific names. Tracebacks are one example. Here is another intended to list callable objects and their types. def call_clas(container): for item in vars(container).values(): if hasattr(item, '__call__'): yield item.__name__, item.__class__ def print_cc(container): for name, clas in call_clas(container): print(f'{name:30s}{clas}') # Examples. print_cc(int) from idlelib import pyshell print_cc(pyshell) Multiple output lines of ' function' defeat the purpose. So my opinion is that lambda expressions should only be used within larger expressions and never directly bound. > It would be however more convenient to be able to write instead just > > ?? f(x) = x*x Given my view above, this is, standing alone, strictly an abbreviation of the equivalent def statement. I am presuming that a proper implementation would result in f.__name__ == 'f'. Is the convenience and (very low) frequency of applicability worth the inconvenience of confusing the meaning of '=' and complicating the implementation? > I do not see any conflicts with the existing syntax. It heavily conflicts with existing syntax. The current meaning of target_expression = object_expression is 1. Evaluate object_expression in the existing namespace to an object, prior to any new bindings and independent of the target_expression. 2. Evaluate target_expression in the existing namespace to one or more targets. 3. Bind object to target or iterate target to bind to multiple targets. Part of step 2 is making calls, because calls cannot be targets. This is why 'f(a+b)[c] = d' can work. Note that 'a+b' makes calls to a.__add__ or b.__radd__ or both. In the proposal, the treatment of the object expression would depend on the target expression and the alternative would be to quote it as code; compile the code in a manner that depends on the target expression to mark local names versus global names; and finally make a function instance, presumably taking __name__ from the target. This would have the advantage over lambda assignment of getting the name right, but I don't think one should be doing lambda assignment anyway. There is a good reason to have a separate syntax. Before 3.8, I would stop here and say no to the proposal. But we now have assignment expressions in addition to assignment statements. >>> int(s:='42'+'742') 42742 >>> s '42742' To me, function assignment expressions, as a enhanced replacement for lambda expressions, is more inviting than function assignment statements as an abbreviation for function definition statements. In other words, replace map(lambda x: x*x, range(10)) with map(square(x):=x*x, range(10)) or, if one does not want a specific name, map(_(x):=x*x, range(10)) Many people dislike lambda expressions, to the point that Guido considered leaving them out of 3.x. So this replacement might get more traction. It would make assignment expressions much more useful. -- Terry Jan Reedy From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Wed Mar 27 17:49:08 2019 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Wed, 27 Mar 2019 21:49:08 +0000 Subject: Getting file extensions [linux fs] Message-ID: Hi! I don't know if this is the right group to ask ... sorry if it isn't. Is there a way to get the file extensions of a file in linux, the same way as "filefrag -e " does? The purpose is to see if two files are the same file, namely those copied with the --reflink option in btrfs. A solution for C is also welcome - I can write a small python extension to handle that. BTW, executing filefrag from python is not a solution, because I have lots of files and that would be too slow. Thanks for any help. Anyway, as last resource, I can always look at filefrag source. I am just trying to avoid that. From attreya01 at gmail.com Wed Mar 27 18:17:19 2019 From: attreya01 at gmail.com (Attreya Bhatt) Date: Wed, 27 Mar 2019 15:17:19 -0700 (PDT) Subject: Create GUI with Python using Tkinter | Youtube Playlist Message-ID: <8a2434c6-6b91-4726-ae1f-92c857159383@googlegroups.com> In this series of 30 videos we learn how to create a Music Player from scratch using Python. Youtube Playlist - https://www.youtube.com/playlist?list=PLhTjy8cBISEp6lNKUO3iwbB1DKAkRwutl From cs at cskk.id.au Wed Mar 27 19:01:49 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 28 Mar 2019 10:01:49 +1100 Subject: Your IDE's? In-Reply-To: References: Message-ID: <20190327230149.GA87875@cskk.homeip.net> On 27Mar2019 10:55, Anssi Saari wrote: >Ben Finney writes: >> Emacs and a shell multiplexer (today, that's GNU Screen, but others >> swear that I should try TMux). > >I've actually been using tmux for a while. The only reason and the only >thing I can think of that it does and screen doesn't is that tmux can >display italic text and screen apparently can't. So I went with tmux for >Usenet. > >Well, there were some claims from tmux about it being a better terminal >but I can't really see a difference. I find the tmux command line far more regular and flexible. Screen's option set is ... weird and complex and has clearly just grown over time. Tmux is far better there. It also has more features: panes within windows, etc. I rarely use that (I use panes in my terminal emulator heavily though), although my mutt composition mode uses a tmux pane for the composition so I still have access to the main index above it. Cheers, Cameron Simpson From cs at cskk.id.au Wed Mar 27 19:09:34 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 28 Mar 2019 10:09:34 +1100 Subject: Getting file extensions [linux fs] In-Reply-To: References: Message-ID: <20190327230934.GA10768@cskk.homeip.net> On 27Mar2019 21:49, Paulo da Silva wrote: >I don't know if this is the right group to ask ... sorry if it isn't. > >Is there a way to get the file extensions of a file in linux, the same >way as "filefrag -e " does? > >The purpose is to see if two files are the same file, namely those >copied with the --reflink option in btrfs. > >A solution for C is also welcome - I can write a small python extension >to handle that. > >BTW, executing filefrag from python is not a solution, because I have >lots of files and that would be too slow. The filefrag manual entry says it works by calling one of 2 ioctls. You can do that from Python with the ioctl() function in the standard fcntl module. I haven't tried to do this, but the results should be basicly as fast as filefrag itself. You'll need to decode the result the ioctl returns of course. Cheers, Cameron Simpson From ben+python at benfinney.id.au Wed Mar 27 19:53:55 2019 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 28 Mar 2019 10:53:55 +1100 Subject: Your IDE's? References: <395e5dae-5d50-4571-9df0-72c55af3da22@googlegroups.com> Message-ID: <865zs327sc.fsf@benfinney.id.au> Mr Zaug writes: > On Monday, March 25, 2019 at 5:38:41 PM UTC-4, John Doe wrote: > > What is your favorite Python IDE? > > "Your IDE's?" is not a question It is a topic for discussion though. Hence, appropriate for the Subject field. Especially because he then wrote a full sentence question in the message body. > nor is any word in English made plural with an apostrophe s. Bob the Angry Flower agrees . -- \ ?The history of Western science confirms the aphorism that the | `\ great menace to progress is not ignorance but the illusion of | _o__) knowledge.? ?Daniel J. Boorstin, historian, 1914?2004 | Ben Finney From ben+python at benfinney.id.au Wed Mar 27 19:56:59 2019 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 28 Mar 2019 10:56:59 +1100 Subject: configparser - which one? References: <71dd2f04-d34e-9992-a784-d4345ea9c86b@DancesWithMice.info> Message-ID: <861s2r27n8.fsf@benfinney.id.au> DL Neil writes: > After striking this problem, I was encouraged to take a look at JSON, > and thence YAML. Once there, as they say, didn't look back! > - multi-dimensional possibilities, cf .ini > - similarity/correspondence with Python data structures > - convenient PSL > - easily adopted by (power-)users, cf Python code Those are all true. Drawbacks for YAML as a configuration format: * Not implemented in Python standard library. * Not a single, unambiguous standard which all implementations support (this may be one reason for no Python standard library implementation). Despite those, yes I would very much prefer to use YAML as a configuration format. (ConfigParser INI format is acceptable. JSON is definitely not, because it has no simple way to put comments in the file.) -- \ ?In the long run, the utility of all non-Free software | `\ approaches zero. All non-Free software is a dead end.? ?Mark | _o__) Pilgrim, 2006 | Ben Finney From ben+python at benfinney.id.au Wed Mar 27 20:11:20 2019 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 28 Mar 2019 11:11:20 +1100 Subject: Syntax for one-line "nonymous" functions in "declaration style" References: <1553674918.3032.0@gmail.com> Message-ID: <86wokjzwlz.fsf@benfinney.id.au> Alexey Muranov writes: > It would be however more convenient to be able to write instead just > > f(x) = x*x That's not an anonymous function then, is it? You want to assign a name to that function, and (to be useful in development tools, such as a stack trace) the function needs to know its own name. The way to do that is, as you point out, the ?def? statement: def f(x): return (x * x) What does that prevent you from doing? It will need to be pretty significant improvement to be considered as a change to language syntax. > Have this idea been discussed before? Too many times to count :-) -- \ ?Theology is the effort to explain the unknowable in terms of | `\ the not worth knowing.? ?Henry L. Mencken | _o__) | Ben Finney From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Wed Mar 27 21:12:05 2019 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Thu, 28 Mar 2019 01:12:05 +0000 Subject: Getting file extensions [linux fs] References: <20190327230934.GA10768@cskk.homeip.net> Message-ID: ?s 23:09 de 27/03/19, Cameron Simpson escreveu: > On 27Mar2019 21:49, Paulo da Silva wrote: ... > The filefrag manual entry says it works by calling one of 2 ioctls. You > can do that from Python with the ioctl() function in the standard fcntl > module. I haven't tried to do this, but the results should be basicly as > fast as filefrag itself. > > You'll need to decode the result the ioctl returns of course. > Thanks Cameron, I'll take a look at that. From jsf80238 at gmail.com Wed Mar 27 21:48:33 2019 From: jsf80238 at gmail.com (Jason Friedman) Date: Wed, 27 Mar 2019 19:48:33 -0600 Subject: The Mailing List Digest Project In-Reply-To: References: Message-ID: On Mon, Mar 25, 2019 at 11:03 PM Abdur-Rahmaan Janhangeer < arj.python at gmail.com> wrote: > As proposed on python-ideas, i setup a repo to turn mail threads into > articles. > > i included a script to build .md to .html (with syntax highlighting) here > is the index > > https://abdur-rahmaanj.github.io/py-mailing-list-summary/ > > Pretty cool. FYI, the index page (now containing 4 articles) with Google Chrome 72.0.3626.x prompts me to translate to French. The articles themselves do not. From arj.python at gmail.com Thu Mar 28 00:53:08 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 28 Mar 2019 08:53:08 +0400 Subject: The Mailing List Digest Project In-Reply-To: References: Message-ID: hum maybe beacuse i speak french some settings got configured but i don't see how. btw we are moving to a better repo with sphinx Garanti sans virus. www.avast.com <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> On Thu, Mar 28, 2019 at 5:48 AM Jason Friedman wrote: > On Mon, Mar 25, 2019 at 11:03 PM Abdur-Rahmaan Janhangeer < > arj.python at gmail.com> wrote: > > > As proposed on python-ideas, i setup a repo to turn mail threads into > > articles. > > > > i included a script to build .md to .html (with syntax highlighting) here > > is the index > > > > https://abdur-rahmaanj.github.io/py-mailing-list-summary/ > > > > Pretty cool. FYI, the index page (now containing 4 articles) with > Google > Chrome 72.0.3626.x prompts me to translate to French. The articles > themselves do not. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius From arj.python at gmail.com Thu Mar 28 02:01:58 2019 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 28 Mar 2019 10:01:58 +0400 Subject: The Mailing List Digest Project In-Reply-To: References: Message-ID: continuing a better effort here: https://github.com/PythonCHB/PythonListsSummaries moving to an impersonal repo later! Garanti sans virus. www.avast.com <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> From dieter at handshake.de Thu Mar 28 04:12:46 2019 From: dieter at handshake.de (dieter) Date: Thu, 28 Mar 2019 09:12:46 +0100 Subject: Library for parsing binary structures References: Message-ID: <87sgv7a03l.fsf@handshake.de> Paul Moore writes: > I'm looking for a library that lets me parse binary data structures. > The stdlib struct module is fine for simple structures, but when it > gets to more complicated cases, you end up doing a lot of the work by > hand (which isn't that hard, and is generally perfectly viable, but > I'm feeling lazy ;-)) > > I know of Construct, which is a nice declarative language, but it's > either weak, or very badly documented, when it comes to recursive > structures. (I really like Construct, and if I could only understand > the docs better I may well not need to look any further, but as it is, > I can't see anything showing how to do recursive structures...) I am > specifically trying to parse a structure that looks something like the > following: > > Multiple instances of: > - a type byte > - a chunk of data structured based on the type > types include primitives like byte, integer, etc, as well as > (type byte, count, data) - data is "count" occurrences of data of > the given type. What you have is a generalized deserialization problem. It can be solved with a set of deserializers. def deserialize(file): """read the beginning of file and return the corresponding object.""" In the above case, you have a mapping "type byte --> deserializer", called "TYPE" and (obviously) "(" is one such "type byte". The deserializer corresponding to "(" is: def sequence_deserialize(file): type_byte = file.read(1) if not type_byte: raise EOFError() type = TYPE[type_byte] count = TYPE[INT].deserialize(file) seq = [type.deserialize(file) for i in range(count)] assert file.read(1) == ")" return seq The top level "deserialize" could look like: def top_deserialize(file): """generates all values found in *file*.""" while True: type_byte = file.read(1) if not type_byte: return yield TYPE[type_byte].deserialize(file) From antoon.pardon at vub.be Thu Mar 28 04:28:40 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 28 Mar 2019 09:28:40 +0100 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: References: <1553674918.3032.0@gmail.com> Message-ID: <01c00555-26c6-8bea-9ea5-673feb21c4eb@vub.be> On 27/03/19 22:25, Terry Reedy wrote: > ... > > Before 3.8, I would stop here and say no to the proposal.? But we now > have assignment expressions in addition to assignment statements. > > >>> int(s:='42'+'742') > 42742 > >>> s > '42742' > > To me, function assignment expressions, as a enhanced replacement for > lambda expressions, is more inviting than function assignment > statements as an abbreviation for function definition statements. > > In other words, replace > > ? map(lambda x: x*x, range(10)) > > with > > ? map(square(x):=x*x, range(10)) > > or, if one does not want a specific name, > > ? map(_(x):=x*x, range(10)) > > Many people dislike lambda expressions, to the point that Guido > considered leaving them out of 3.x.? So this replacement might get > more traction.? It would make assignment expressions much more useful. I think map is not a good example, since I would just replace them with Since we are talking python 3.8 why not just use a generator here: (x*x for x in range(10)) instead of map? From p.f.moore at gmail.com Thu Mar 28 05:07:38 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 28 Mar 2019 09:07:38 +0000 Subject: Library for parsing binary structures In-Reply-To: <87sgv7a03l.fsf@handshake.de> References: <87sgv7a03l.fsf@handshake.de> Message-ID: On Thu, 28 Mar 2019 at 08:15, dieter wrote: > What you have is a generalized deserialization problem. > It can be solved with a set of deserializers. Yes, and thanks for the suggested code structure. As I say, I can certainly do the parsing "by hand", and the way you describe is very similar to how I'd approach that. My real interest is in whether any libraries exist to do this sort of thing (there are plenty of parser libraries for text, pyparsing being the obvious one, but far fewer for binary structures). Paul From babita.trial at gmail.com Thu Mar 28 05:19:38 2019 From: babita.trial at gmail.com (babita.trial at gmail.com) Date: Thu, 28 Mar 2019 02:19:38 -0700 (PDT) Subject: embedding python - PyImport_ImportModule returns null In-Reply-To: <3607e8e4.0303051802.7ddf1dfd@posting.google.com> References: <3607e8e4.0303051802.7ddf1dfd@posting.google.com> Message-ID: <94185427-44bb-4d8c-a141-c4c0eba57c45@googlegroups.com> If nothing works mentioned above, please try building your application from common path. ( not from c:\users\ ). While working on office environment, this has impact. From lists at vanderhoff.org Thu Mar 28 05:38:38 2019 From: lists at vanderhoff.org (Tony van der Hoff) Date: Thu, 28 Mar 2019 09:38:38 +0000 Subject: Prepare accented characters for HTML Message-ID: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> Hi, I have a MariaDB database, which contains accented (mostly French) characters. I need to display these on an HTML page. I'm using the Jinja templating engine. So, for instance, ? needs to be replaced by é and so on. I've had some success using string.replace(), but it is difficult to cater for every case. Ideally there would be a library function to handle this, either in Python, or Jinja, but Googling around has not revealed such. Does anyone know of such a function, and where I might find it? Cheers, Tony -- Tony van der Hoff | mailto:tony at vanderhoff.org Buckinghamshire, England | From dieter at handshake.de Thu Mar 28 06:07:22 2019 From: dieter at handshake.de (dieter) Date: Thu, 28 Mar 2019 11:07:22 +0100 Subject: Library for parsing binary structures References: <87sgv7a03l.fsf@handshake.de> Message-ID: <87o95v9usl.fsf@handshake.de> Paul Moore writes: > On Thu, 28 Mar 2019 at 08:15, dieter wrote: > ... > My real interest is in whether any > libraries exist to do this sort of thing (there are plenty of parser > libraries for text, pyparsing being the obvious one, but far fewer for > binary structures). Sure. *BUT* the library must fit your specific binary structure. How should a general libary know how to interpret your specific "type byte"s or that "(" introduces a homogenous sequence of given length which must be terminated by ")"? On the other hand, if those specifics are known, then the remaining is trivial (as shown in my previous message). If the binary structure is not fixed (i.e. you deserialize only things you yourself have serialized), then you can use Python's "pickle" (and likely also "marshal"). It supports the structuring you need and (among others) the Python elementary types. There is also "asn1" (--> "https://pypi.org/project/asn1/") for ASN.1 (BER/DER) binary formats. ASN.1 is a widely used very flexible language to describe structured data (which typically has a binary encoding) -- used e.g. by LDAP and X.509. It supports (among others) an extremely rich set of elementary types and structuring via "Sequence", "Set" and "Choice". The elementary binary format is "tag value". This is near to your "type_byte value". However, "tag" is not a byte. Instead, it consists of a number (identifying the type within its class), a class and an encoding indication. This more general type specification is necessary as in the general case, a byte is not sufficient to identify all possible relevant types. From antoon.pardon at vub.be Thu Mar 28 06:19:33 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 28 Mar 2019 11:19:33 +0100 Subject: Prepare accented characters for HTML In-Reply-To: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> Message-ID: <579ecf7d-df73-80b3-afa5-1289e334caf8@vub.be> On 28/03/19 10:38, Tony van der Hoff wrote: > Hi, > > I have a MariaDB database, which contains accented (mostly French) > characters. I need to display these on an HTML page. I'm using the Jinja > templating engine. > > So, for instance, ? needs to be replaced by é and so on. I've had > some success using string.replace(), but it is difficult to cater for > every case. How about this function (python3): def char2html(l): return '&#%d;' % ord(l) -- Antoon Pardon From rosuav at gmail.com Thu Mar 28 07:02:33 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2019 22:02:33 +1100 Subject: Prepare accented characters for HTML In-Reply-To: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> Message-ID: On Thu, Mar 28, 2019 at 8:58 PM Tony van der Hoff wrote: > > Hi, > > I have a MariaDB database, which contains accented (mostly French) > characters. I need to display these on an HTML page. I'm using the Jinja > templating engine. > > So, for instance, ? needs to be replaced by é and so on. I've had > some success using string.replace(), but it is difficult to cater for > every case. Why not just include them as-is? Modern web browsers should have no trouble at all. ChrisA From vk530873 at gmail.com Thu Mar 28 07:04:59 2019 From: vk530873 at gmail.com (Vaibhav Kumar) Date: Thu, 28 Mar 2019 04:04:59 -0700 (PDT) Subject: Regarding 3D buttons in PyQT5 Message-ID: Hi, I want to know that how can i create 3D buttons in PyQT5 window or an animated button. Regards Vaibhav From lists at vanderhoff.org Thu Mar 28 07:50:27 2019 From: lists at vanderhoff.org (Tony van der Hoff) Date: Thu, 28 Mar 2019 11:50:27 +0000 Subject: Prepare accented characters for HTML In-Reply-To: <579ecf7d-df73-80b3-afa5-1289e334caf8@vub.be> References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <579ecf7d-df73-80b3-afa5-1289e334caf8@vub.be> Message-ID: On 28/03/2019 10:19, Antoon Pardon wrote: > On 28/03/19 10:38, Tony van der Hoff wrote: >> Hi, >> >> I have a MariaDB database, which contains accented (mostly French) >> characters. I need to display these on an HTML page. I'm using the Jinja >> templating engine. >> >> So, for instance, ? needs to be replaced by é and so on. I've had >> some success using string.replace(), but it is difficult to cater for >> every case. > > How about this function (python3): > > def char2html(l): > return '&#%d;' % ord(l) > Thanks, that'll work, but it's a bit of a pain examining every character in the long (unicode?) string, and replacing it if necessary. Meanwhile, by trial-and-error, I've found this workaround (maybe there's a better way): >>>'ann?e'.encode(encoding='ascii',errors='xmlcharrefreplace').decode('ascii') 'année' -- Tony van der Hoff | mailto:tony at vanderhoff.org Buckinghamshire, England | From lists at vanderhoff.org Thu Mar 28 07:53:50 2019 From: lists at vanderhoff.org (Tony van der Hoff) Date: Thu, 28 Mar 2019 11:53:50 +0000 Subject: Prepare accented characters for HTML In-Reply-To: References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> Message-ID: <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> On 28/03/2019 11:02, Chris Angelico wrote: > On Thu, Mar 28, 2019 at 8:58 PM Tony van der Hoff wrote: >> >> Hi, >> >> I have a MariaDB database, which contains accented (mostly French) >> characters. I need to display these on an HTML page. I'm using the Jinja >> templating engine. >> >> So, for instance, ? needs to be replaced by é and so on. I've had >> some success using string.replace(), but it is difficult to cater for >> every case. > > Why not just include them as-is? Modern web browsers should have no > trouble at all. > > ChrisA > Thanks, Chris. The problem is not with the browser, but Jinja crashes. Probably a bug, but I'm too wedded to that engine to change now. I'll raise it on the Jinja bug site. -- Tony van der Hoff | mailto:tony at vanderhoff.org Buckinghamshire, England | From blmadhavan at gmail.com Thu Mar 28 07:54:31 2019 From: blmadhavan at gmail.com (Madhavan Bomidi) Date: Thu, 28 Mar 2019 04:54:31 -0700 (PDT) Subject: Levenberg-Marquardt non-linear least-squares fitting in Python Message-ID: <459e5208-f464-4d07-9900-42d89bd3912d@googlegroups.com> Hi, I have x and y variables data arrays. These two variables are assumed to be related as y = A * exp(x/B). Now, I wanted to use Levenberg-Marquardt non-linear least-squares fitting to find A and B for the best fit of the data. Can anyone suggest me how I can proceed with the same. My intention is to obtain A and B for best fit. Look forward to your suggestions and sample code as an example. Thanks and regards, Madhavan From rosuav at gmail.com Thu Mar 28 08:08:28 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Mar 2019 23:08:28 +1100 Subject: Prepare accented characters for HTML In-Reply-To: <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> Message-ID: On Thu, Mar 28, 2019 at 10:55 PM Tony van der Hoff wrote: > > On 28/03/2019 11:02, Chris Angelico wrote: > > On Thu, Mar 28, 2019 at 8:58 PM Tony van der Hoff wrote: > >> > >> Hi, > >> > >> I have a MariaDB database, which contains accented (mostly French) > >> characters. I need to display these on an HTML page. I'm using the Jinja > >> templating engine. > >> > >> So, for instance, ? needs to be replaced by é and so on. I've had > >> some success using string.replace(), but it is difficult to cater for > >> every case. > > > > Why not just include them as-is? Modern web browsers should have no > > trouble at all. > > > > ChrisA > > > Thanks, Chris. The problem is not with the browser, but Jinja crashes. > Probably a bug, but I'm too wedded to that engine to change now. I'll > raise it on the Jinja bug site. > Ah. Yeah, I would definitely raise that with Jinja. Or you could just raise *that* issue here on the list and see if anyone knows a solution/workaround (obviously with posting the full error message etc). It may make a difference whether you're working with Unicode strings or UTF-8 encoded byte strings, too. ChrisA From jon+usenet at unequivocal.eu Thu Mar 28 08:46:39 2019 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Thu, 28 Mar 2019 12:46:39 -0000 (UTC) Subject: Prepare accented characters for HTML References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> Message-ID: On 2019-03-28, Tony van der Hoff wrote: > Thanks, Chris. The problem is not with the browser, but Jinja crashes. > Probably a bug, but I'm too wedded to that engine to change now. I'll > raise it on the Jinja bug site. It'll almost certainly be a mistake in the way you're using Jinja. I can't believe nobody's used non-ASCII characters in Jinja before. From Richard at Damon-family.org Thu Mar 28 09:18:33 2019 From: Richard at Damon-family.org (Richard Damon) Date: Thu, 28 Mar 2019 09:18:33 -0400 Subject: Prepare accented characters for HTML In-Reply-To: <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> Message-ID: <457F1116-4807-47B8-B78B-C92215B43C41@Damon-family.org> > On Mar 28, 2019, at 7:53 AM, Tony van der Hoff wrote: > Thanks, Chris. The problem is not with the browser, but Jinja crashes. > Probably a bug, but I'm too wedded to that engine to change now. I'll > raise it on the Jinja bug site. > Using Google, it says that Jinja2 is Unicode capable, if you are using the first version of Jinja, it may be that it is know to not handle Unicode well (a bytes/string issue) and simply updating to Jinja2 may be simple. From wrw at mac.com Thu Mar 28 10:51:39 2019 From: wrw at mac.com (William Ray Wing) Date: Thu, 28 Mar 2019 10:51:39 -0400 Subject: Levenberg-Marquardt non-linear least-squares fitting in Python In-Reply-To: <459e5208-f464-4d07-9900-42d89bd3912d@googlegroups.com> References: <459e5208-f464-4d07-9900-42d89bd3912d@googlegroups.com> Message-ID: <7855E1E5-A8FC-4830-9B57-F9901ECDCDBC@mac.com> > On Mar 28, 2019, at 7:54 AM, Madhavan Bomidi wrote: > > Hi, > > I have x and y variables data arrays. These two variables are assumed to be related as y = A * exp(x/B). Now, I wanted to use Levenberg-Marquardt non-linear least-squares fitting to find A and B for the best fit of the data. Can anyone suggest me how I can proceed with the same. My intention is to obtain A and B for best fit. > Have you looked at the non-linear least-squares solutions in scicpy? Specifically, a system I?ve had to solve several times in the past uses it and it works quite well. from scipy.optimize import curve_fit def func2fit(x,a,b,c): return a - b * np.exp(-c * x) Bill > Look forward to your suggestions and sample code as an example. > > Thanks and regards, > Madhavan > -- > https://mail.python.org/mailman/listinfo/python-list From lists at vanderhoff.org Thu Mar 28 10:59:19 2019 From: lists at vanderhoff.org (Tony van der Hoff) Date: Thu, 28 Mar 2019 14:59:19 +0000 Subject: Prepare accented characters for HTML In-Reply-To: References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> Message-ID: <02c538ed-c529-80ff-b02b-7c36824723e8@vanderhoff.org> On 28/03/2019 12:46, Jon Ribbens wrote: > On 2019-03-28, Tony van der Hoff wrote: >> Thanks, Chris. The problem is not with the browser, but Jinja crashes. >> Probably a bug, but I'm too wedded to that engine to change now. I'll >> raise it on the Jinja bug site. > > It'll almost certainly be a mistake in the way you're using Jinja. > I can't believe nobody's used non-ASCII characters in Jinja before. > I'm open to suggestions. -- Tony van der Hoff | mailto:tony at vanderhoff.org Buckinghamshire, England | From __peter__ at web.de Thu Mar 28 11:09:39 2019 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 Mar 2019 16:09:39 +0100 Subject: Prepare accented characters for HTML References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> <02c538ed-c529-80ff-b02b-7c36824723e8@vanderhoff.org> Message-ID: Tony van der Hoff wrote: > On 28/03/2019 12:46, Jon Ribbens wrote: >> On 2019-03-28, Tony van der Hoff wrote: >>> Thanks, Chris. The problem is not with the browser, but Jinja crashes. >>> Probably a bug, but I'm too wedded to that engine to change now. I'll >>> raise it on the Jinja bug site. >> >> It'll almost certainly be a mistake in the way you're using Jinja. >> I can't believe nobody's used non-ASCII characters in Jinja before. >> > > I'm open to suggestions. You have to describe the "crash". If you can provide a small script to reproduce it that would be best. For demonstration purposes feed the renderer a constant string instead of reading from the db. You should also tell us which version of Python and Jinja you are using. From blmadhavan at gmail.com Thu Mar 28 12:08:47 2019 From: blmadhavan at gmail.com (Madhavan Bomidi) Date: Thu, 28 Mar 2019 09:08:47 -0700 (PDT) Subject: Levenberg-Marquardt non-linear least-squares fitting in Python In-Reply-To: References: <459e5208-f464-4d07-9900-42d89bd3912d@googlegroups.com> <7855E1E5-A8FC-4830-9B57-F9901ECDCDBC@mac.com> Message-ID: Hi Bill, Thanks for your suggestion. Where am I actually using the curve_fit in the defined function func2fit? Don't I need to initial assumption of a, b and c values so that optimized convergence occur with iteration of the function for the input data of x? Look forward to your suggestions, Madhavan From alexey.muranov at gmail.com Thu Mar 28 12:29:30 2019 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Thu, 28 Mar 2019 17:29:30 +0100 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: References: Message-ID: <1553790570.8480.0@gmail.com> On jeu., Mar 28, 2019 at 5:00 PM, python-list-request at python.org wrote: > > So my opinion is that lambda expressions should only be used within > larger expressions and never directly bound. > >> It would be however more convenient to be able to write instead just >> >> f(x) = x*x > > Given my view above, this is, standing alone, strictly an > abbreviation of the equivalent def statement. I am presuming that a > proper implementation would result in f.__name__ == 'f'. > No, after some thought, i think it should be an abbreviation of "f = lambda x: x*x", f.__name__ would still be ''. But i see your point about never assigning lambdas directly, it makes sense. But sometimes i do assign short lambdas directly to variable. > Is the convenience and (very low) frequency of applicability worth > the inconvenience of confusing the meaning of '=' and complicating > the implementation? > >> I do not see any conflicts with the existing syntax. > > It heavily conflicts with existing syntax. The current meaning of > target_expression = object_expression > is > 1. Evaluate object_expression in the existing namespace to an object, > prior to any new bindings and independent of the target_expression. > 2. Evaluate target_expression in the existing namespace to one or > more targets. > 3. Bind object to target or iterate target to bind to multiple > targets. I do not thick so. In "x = 42" the variable x is not evaluated. All examples of the proposed syntax i can think of are currently illegal, so i suppose there is no conflicts. (I would appreciate a counterexample, if any.) Thanks for the reference to PEP 8, this is indeed an argument against. Alexey. From lists at vanderhoff.org Thu Mar 28 12:45:53 2019 From: lists at vanderhoff.org (Tony van der Hoff) Date: Thu, 28 Mar 2019 16:45:53 +0000 Subject: Prepare accented characters for HTML In-Reply-To: References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> <02c538ed-c529-80ff-b02b-7c36824723e8@vanderhoff.org> Message-ID: On 28/03/2019 15:09, Peter Otten wrote: > Tony van der Hoff wrote: > >> On 28/03/2019 12:46, Jon Ribbens wrote: >>> On 2019-03-28, Tony van der Hoff wrote: >>>> Thanks, Chris. The problem is not with the browser, but Jinja crashes. >>>> Probably a bug, but I'm too wedded to that engine to change now. I'll >>>> raise it on the Jinja bug site. >>> >>> It'll almost certainly be a mistake in the way you're using Jinja. >>> I can't believe nobody's used non-ASCII characters in Jinja before. >>> >> >> I'm open to suggestions. > > You have to describe the "crash". If you can provide a small script to > reproduce it that would be best. For demonstration purposes feed the > renderer a constant string instead of reading from the db. > > You should also tell us which version of Python and Jinja you are using. > > OK,The crash is evidenced by an empty web page being generated, containing just elements, with no content. No error messages nor exceptions. I.m using python3.5.3 and jinja 2.10. I have placed a sample script with a jnj template at https://drive.google.com/drive/folders/1rM5F46wRqHYn0VBXUhSl8DkNcwsp2u8b?usp=sharing The template contains a commented-out line, which when uncommented shows the alleged bug. Good luck! -- Tony van der Hoff | mailto:tony at vanderhoff.org Buckinghamshire, England | From rosuav at gmail.com Thu Mar 28 12:58:48 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2019 03:58:48 +1100 Subject: Prepare accented characters for HTML In-Reply-To: References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> <02c538ed-c529-80ff-b02b-7c36824723e8@vanderhoff.org> Message-ID: On Fri, Mar 29, 2019 at 3:47 AM Tony van der Hoff wrote: > > On 28/03/2019 15:09, Peter Otten wrote: > > Tony van der Hoff wrote: > > > >> On 28/03/2019 12:46, Jon Ribbens wrote: > >>> On 2019-03-28, Tony van der Hoff wrote: > >>>> Thanks, Chris. The problem is not with the browser, but Jinja crashes. > >>>> Probably a bug, but I'm too wedded to that engine to change now. I'll > >>>> raise it on the Jinja bug site. > >>> > >>> It'll almost certainly be a mistake in the way you're using Jinja. > >>> I can't believe nobody's used non-ASCII characters in Jinja before. > >>> > >> > >> I'm open to suggestions. > > > > You have to describe the "crash". If you can provide a small script to > > reproduce it that would be best. For demonstration purposes feed the > > renderer a constant string instead of reading from the db. > > > > You should also tell us which version of Python and Jinja you are using. > > > > > OK,The crash is evidenced by an empty web page being generated, > containing just > elements, with no content. No error messages nor exceptions. > > I.m using python3.5.3 and jinja 2.10. > > I have placed a sample script with a jnj template at > https://drive.google.com/drive/folders/1rM5F46wRqHYn0VBXUhSl8DkNcwsp2u8b?usp=sharing > > The template contains a commented-out line, which when uncommented shows > the alleged bug. I can't see any of the code. Are you able to share it in a more code-friendly way, such as linking to a repository on GitHub, GitLab, BitBucket, SourceForge, or something else (probably with a capital letter in the middle of the name, for consistency)? Or, even better: create a short enough example that you can just include it in the body of your post? ChrisA From ian.g.kelly at gmail.com Thu Mar 28 13:02:18 2019 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 28 Mar 2019 11:02:18 -0600 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: References: <1553674918.3032.0@gmail.com> Message-ID: On Wed, Mar 27, 2019 at 3:13 AM Paul Moore wrote: > > On Wed, 27 Mar 2019 at 08:25, Alexey Muranov wrote: > > > > Whey you need a simple function in Python, there is a choice between a > > normal function declaration and an assignment of a anonymous function > > (defined by a lambda-expression) to a variable: > > > > def f(x): return x*x > > > > or > > > > f = lambda x: x*x > > > > It would be however more convenient to be able to write instead just > > > > f(x) = x*x > > Why? Is saving a few characters really that helpful? So much so that > it's worth adding a *third* method of defining functions, which would > need documenting, adding to training materials, etc, etc? Well, it does seem a bit silly to have more ways of formatting strings than of defining functions. We have four of the former, so clearly we need to address this by adding two more of the latter. From lists at vanderhoff.org Thu Mar 28 13:09:21 2019 From: lists at vanderhoff.org (Tony van der Hoff) Date: Thu, 28 Mar 2019 17:09:21 +0000 Subject: Prepare accented characters for HTML In-Reply-To: References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> <02c538ed-c529-80ff-b02b-7c36824723e8@vanderhoff.org> Message-ID: On 28/03/2019 16:58, Chris Angelico wrote: > On Fri, Mar 29, 2019 at 3:47 AM Tony van der Hoff wrote: >> >> On 28/03/2019 15:09, Peter Otten wrote: >>> Tony van der Hoff wrote: >>> >>>> On 28/03/2019 12:46, Jon Ribbens wrote: >>>>> On 2019-03-28, Tony van der Hoff wrote: >>>>>> Thanks, Chris. The problem is not with the browser, but Jinja crashes. >>>>>> Probably a bug, but I'm too wedded to that engine to change now. I'll >>>>>> raise it on the Jinja bug site. >>>>> >>>>> It'll almost certainly be a mistake in the way you're using Jinja. >>>>> I can't believe nobody's used non-ASCII characters in Jinja before. >>>>> >>>> >>>> I'm open to suggestions. >>> >>> You have to describe the "crash". If you can provide a small script to >>> reproduce it that would be best. For demonstration purposes feed the >>> renderer a constant string instead of reading from the db. >>> >>> You should also tell us which version of Python and Jinja you are using. >>> >>> >> OK,The crash is evidenced by an empty web page being generated, >> containing just >> elements, with no content. No error messages nor exceptions. >> >> I.m using python3.5.3 and jinja 2.10. >> >> I have placed a sample script with a jnj template at >> https://drive.google.com/drive/folders/1rM5F46wRqHYn0VBXUhSl8DkNcwsp2u8b?usp=sharing >> >> The template contains a commented-out line, which when uncommented shows >> the alleged bug. > > I can't see any of the code. Are you able to share it in a more > code-friendly way, such as linking to a repository on GitHub, GitLab, > BitBucket, SourceForge, or something else (probably with a capital > letter in the middle of the name, for consistency)? > > Or, even better: create a short enough example that you can just > include it in the body of your post? > I hate Google! This'll probably work: accent-test/accent-test.py: ##################################################################### #!/usr/bin/env python3 import os from jinja2 import Environment, FileSystemLoader PATH = os.path.dirname(os.path.abspath(__file__)) TEMPLATE_ENVIRONMENT = Environment( autoescape=False, loader=FileSystemLoader(os.path.join(PATH, 'templates')), trim_blocks=False) def render_template(template_filename, context): return TEMPLATE_ENVIRONMENT.get_template(template_filename).render(context) def create_index_html(): # put the list into a dictionary for rendering context = { 'title': "accent-test", 'french': 'ann?e', 'french1': 'année', } # render the template to html print ("Content-type: text/html\n\n") print (render_template('accent-test.jnj', context)) def main(): create_index_html() ######################################## if __name__ == "__main__": main() ##################################################################### accent-test/templates/accent-test.jnj: ##################################################################### {{title}}

{{title}}

{#

{{french}}

#}

{{french1}}

##################################################################### -- Tony van der Hoff | mailto:tony at vanderhoff.org Buckinghamshire, England | From __peter__ at web.de Thu Mar 28 13:57:26 2019 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 Mar 2019 18:57:26 +0100 Subject: Prepare accented characters for HTML References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> <02c538ed-c529-80ff-b02b-7c36824723e8@vanderhoff.org> Message-ID: Tony van der Hoff wrote: > On 28/03/2019 16:58, Chris Angelico wrote: >> On Fri, Mar 29, 2019 at 3:47 AM Tony van der Hoff >> wrote: >>> >>> On 28/03/2019 15:09, Peter Otten wrote: >>>> Tony van der Hoff wrote: >>>> >>>>> On 28/03/2019 12:46, Jon Ribbens wrote: >>>>>> On 2019-03-28, Tony van der Hoff wrote: >>>>>>> Thanks, Chris. The problem is not with the browser, but Jinja >>>>>>> crashes. Probably a bug, but I'm too wedded to that engine to change >>>>>>> now. I'll raise it on the Jinja bug site. >>>>>> >>>>>> It'll almost certainly be a mistake in the way you're using Jinja. >>>>>> I can't believe nobody's used non-ASCII characters in Jinja before. >>>>>> >>>>> >>>>> I'm open to suggestions. >>>> >>>> You have to describe the "crash". If you can provide a small script to >>>> reproduce it that would be best. For demonstration purposes feed the >>>> renderer a constant string instead of reading from the db. >>>> >>>> You should also tell us which version of Python and Jinja you are >>>> using. >>>> >>>> >>> OK,The crash is evidenced by an empty web page being generated, >>> containing just >>> elements, with no content. No error messages nor exceptions. >>> >>> I.m using python3.5.3 and jinja 2.10. >>> >>> I have placed a sample script with a jnj template at >>> https://drive.google.com/drive/folders/1rM5F46wRqHYn0VBXUhSl8DkNcwsp2u8b?usp=sharing >>> >>> The template contains a commented-out line, which when uncommented shows >>> the alleged bug. >> >> I can't see any of the code. Are you able to share it in a more >> code-friendly way, such as linking to a repository on GitHub, GitLab, >> BitBucket, SourceForge, or something else (probably with a capital >> letter in the middle of the name, for consistency)? >> >> Or, even better: create a short enough example that you can just >> include it in the body of your post? >> > > I hate Google! > > This'll probably work: > > accent-test/accent-test.py: > ##################################################################### > #!/usr/bin/env python3 > > import os > from jinja2 import Environment, FileSystemLoader > > PATH = os.path.dirname(os.path.abspath(__file__)) > TEMPLATE_ENVIRONMENT = Environment( > autoescape=False, > loader=FileSystemLoader(os.path.join(PATH, 'templates')), > trim_blocks=False) > > > def render_template(template_filename, context): > return > TEMPLATE_ENVIRONMENT.get_template(template_filename).render(context) > > > def create_index_html(): > > # put the list into a dictionary for rendering > context = { > 'title': "accent-test", > 'french': 'ann?e', > 'french1': 'année', > } > > # render the template to html > print ("Content-type: text/html\n\n") > print (render_template('accent-test.jnj', context)) > > def main(): > create_index_html() > > ######################################## > > if __name__ == "__main__": > main() > ##################################################################### > > accent-test/templates/accent-test.jnj: > > ##################################################################### > > > > > {{title}} > > >
>

{{title}}

> {# >

{{french}}

> #} >

{{french1}}

>
> > > > ##################################################################### > When I run this from the command line it doesn't raise an exception. Are you absolutely sure the script is executed with Python 3? If it were Python 2 you'd need to specify the encoding and ensure that the non-ascii text is unicode (u"..." rather than "...") #!/usr/bin/env python # -*- coding: utf-8 -*- ... 'french': u'ann?e', ... If that's not the problem maybe there is something useful in the server logs? From rosuav at gmail.com Thu Mar 28 14:04:36 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2019 05:04:36 +1100 Subject: Jinja and non-ASCII characters (was Re: Prepare accented characters for HTML) In-Reply-To: References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> <02c538ed-c529-80ff-b02b-7c36824723e8@vanderhoff.org> Message-ID: On Fri, Mar 29, 2019 at 4:10 AM Tony van der Hoff wrote: > > This'll probably work: > > accent-test/accent-test.py: > ##################################################################### > #!/usr/bin/env python3 > > import os > from jinja2 import Environment, FileSystemLoader > > PATH = os.path.dirname(os.path.abspath(__file__)) > TEMPLATE_ENVIRONMENT = Environment( > autoescape=False, > loader=FileSystemLoader(os.path.join(PATH, 'templates')), > trim_blocks=False) > > > def render_template(template_filename, context): > return > TEMPLATE_ENVIRONMENT.get_template(template_filename).render(context) > > > def create_index_html(): > > # put the list into a dictionary for rendering > context = { > 'title': "accent-test", > 'french': 'ann?e', > 'french1': 'année', > } > > # render the template to html > print ("Content-type: text/html\n\n") > print (render_template('accent-test.jnj', context)) > > def main(): > create_index_html() > > ######################################## > > if __name__ == "__main__": > main() > ##################################################################### > > accent-test/templates/accent-test.jnj: > > ##################################################################### > > > > > {{title}} > > >
>

{{title}}

> {# >

{{french}}

> #} >

{{french1}}

>
> > > > ##################################################################### Well, I just tried this, and it worked fine (even after uncommenting the 'french' line). Gave me this output: Content-type: text/html accent-test

accent-test

ann?e

année

You have a python3 shebang, but are you definitely running this under Python 3? Here's a much more minimal example. Can you see if this also fails for you? import sys from jinja2 import Template print(Template("French: {{french}}").render({"french": "ann?e"})) print(sys.version) ChrisA From alexey.muranov at gmail.com Thu Mar 28 15:56:02 2019 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Thu, 28 Mar 2019 20:56:02 +0100 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: References: Message-ID: <1553802962.5276.0@gmail.com> On jeu., mars 28, 2019 at 5:00 PM, python-list-request at python.org wrote: > On 2019-03-27 10:42 a.m., Paul Moore wrote: >> On Wed, 27 Mar 2019 at 12:27, Alexey Muranov >> wrote: >>> On mer., mars 27, 2019 at 10:10 AM, Paul Moore >>> >>> wrote: >>>> On Wed, 27 Mar 2019 at 08:25, Alexey Muranov >>>> wrote: >>>>> Whey you need a simple function in Python, there is a choice >>>>> between a >>>>> normal function declaration and an assignment of a anonymous >>>>> function >>>>> (defined by a lambda-expression) to a variable: >>>>> >>>>> def f(x): return x*x >>>>> >>>>> or >>>>> >>>>> f = lambda x: x*x >>>>> >>>>> It would be however more convenient to be able to write instead >>>>> just >>>>> >>>>> f(x) = x*x >>>> Why? Is saving a few characters really that helpful? So much so >>>> that >>>> it's worth adding a *third* method of defining functions, which >>>> would >>>> need documenting, adding to training materials, etc, etc? >>> Because i think i would prefer to write it this way. >> That's not likely to be sufficient reason for changing a language >> that's used by literally millions of people. >> >>> (Almost no new documentation or tutorials would be needed IMHO.) >> Documentation would be needed to explain how the new construct >> worked, >> for people who either wanted to use it or encountered it in other >> people's code. While it may be obvious to you how it works, it >> likely >> won't be to others, and there will probably be edge cases you >> haven't >> considered that others will find and ask about. > > For what it's worth, if I encountered "f(x) = x * x" in code, my first > thought would be that Python somehow added a way to return an > assignable > reference from a function, rather than this being an anonymous > function > declaration. > > So documentation of that syntax would 100% be required > > Alex > The thing to the right of the assignment symbol represents a value (an object), but the thing to the left does not represent a value, it represents a place for a value. What would an "assignable reference" mean? Say, variable "x" holds an "assignable reference", what can be done next? Alexey. From alexey.muranov at gmail.com Thu Mar 28 16:21:48 2019 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Thu, 28 Mar 2019 21:21:48 +0100 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: <35237f68-05ec-6516-4ae3-0f3fd2d2ba6d@udel.edu> References: <1553790570.8480.0@gmail.com> <35237f68-05ec-6516-4ae3-0f3fd2d2ba6d@udel.edu> Message-ID: <1553804508.10745.0@gmail.com> On jeu., mars 28, 2019 at 8:57 PM, Terry Reedy wrote: > >> But i see your point about never assigning lambdas directly, it >> makes sense. But sometimes i do assign short lambdas directly to >> variable. >> >>> Is the convenience and (very low) frequency of applicability worth >>> the inconvenience of confusing the meaning of '=' and >>> complicating the implementation? >>> >>>> I do not see any conflicts with the existing syntax. >>> >>> It heavily conflicts with existing syntax. The current meaning of >>> target_expression = object_expression >>> is >>> 1. Evaluate object_expression in the existing namespace to an >>> object, prior to any new bindings and independent of the >>> target_expression. >>> 2. Evaluate target_expression in the existing namespace to one or >>> more targets. >>> 3. Bind object to target or iterate target to bind to multiple >>> targets. >> >> I do not thick so. In "x = 42" the variable x is not evaluated. >> >> All examples of the proposed syntax i can think of are currently >> illegal, so i suppose there is no conflicts. (I would appreciate a >> counterexample, if any.) > > You are talking about syntax conflicts, I am talking about semantic > conflict, which is important for human understanding. I believe there is no semantic conflict either, or could you be more specific? Alexey. From alexey.muranov at gmail.com Thu Mar 28 16:27:47 2019 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Thu, 28 Mar 2019 21:27:47 +0100 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: <35237f68-05ec-6516-4ae3-0f3fd2d2ba6d@udel.edu> References: <1553790570.8480.0@gmail.com> <35237f68-05ec-6516-4ae3-0f3fd2d2ba6d@udel.edu> Message-ID: <1553804867.10745.1@gmail.com> On jeu., mars 28, 2019 at 8:57 PM, Terry Reedy wrote: > On 3/28/2019 12:29 PM, Alexey Muranov wrote: >> On jeu., Mar 28, 2019 at 5:00 PM, python-list-request at python.org >> wrote: >>> >>> So my opinion is that lambda expressions should only be used within >>> larger expressions and never directly bound. >>> >>>> It would be however more convenient to be able to write instead >>>> just >>>> >>>> f(x) = x*x >>> >>> Given my view above, this is, standing alone, strictly an >>> abbreviation of the equivalent def statement. I am presuming >>> that a proper implementation would result in f.__name__ == 'f'. >>> >> >> No, after some thought, i think it should be an abbreviation of "f = >> lambda x: x*x", f.__name__ would still be ''. > > Throwing the name away is foolish. Testing functions is another > situation in which function names are needed for proper report. My idea however was to have it as an exact synonyme of an assignment of a lambda. Assignment is an assignment, it should not modify the attributs of the value that is being assigned. > >> But i see your point about never assigning lambdas directly, it >> makes sense. But sometimes i do assign short lambdas directly to >> variable. >> >>> Is the convenience and (very low) frequency of applicability worth >>> the inconvenience of confusing the meaning of '=' and >>> complicating the implementation? >>> >>>> I do not see any conflicts with the existing syntax. >>> >>> It heavily conflicts with existing syntax. The current meaning of >>> target_expression = object_expression >>> is >>> 1. Evaluate object_expression in the existing namespace to an >>> object, prior to any new bindings and independent of the >>> target_expression. >>> 2. Evaluate target_expression in the existing namespace to one or >>> more targets. >>> 3. Bind object to target or iterate target to bind to multiple >>> targets. >> >> I do not thick so. In "x = 42" the variable x is not evaluated. >> >> All examples of the proposed syntax i can think of are currently >> illegal, so i suppose there is no conflicts. (I would appreciate a >> counterexample, if any.) > > You are talking about syntax conflicts, I am talking about semantic > conflict, which is important for human understanding. > >> Thanks for the reference to PEP 8, this is indeed an argument >> against. > > The situation in which assigning lambda expressions is more tempting > is when assigning to attributes or dicts. > > def double(x): return x*x > C.double = double > d['double'] = double > versus > > C.double = lambda x: x*x > d['double'] = lambda x: x*x These are some of examples i had in mind as well: C.double(x) = x*x d['double'](x) = x*x Alexey. From PythonList at DancesWithMice.info Thu Mar 28 16:32:03 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Fri, 29 Mar 2019 09:32:03 +1300 Subject: Handy utilities = Friday Filosofical Finking Message-ID: How do you keep, use, and maintain those handy snippets, functions, classes... - units of code, which you employ over-and-over again? Having coded 'stuff' once, most of us will keep units of code, "utilities", which we expect will be useful in-future (DRY principle), eg functions to rename files, choose unique back-up/new fileNMs, accessing a DB, journalling (logging) start/stop msgs, building specs from YAML/JSON/XML/.ini config files (tongue~cheek), etc. Do you 'keep' these, or perhaps next time you need something you've 'done before' do you remember when/where a technique was last used/burrow into 'history'? (else, code it from scratch, all over again) How do you keep them updated, ie if add some new idea, better err-checking, re-factor - how to add these 'back' into previous places utility is used? (who wants more "technical debt", plus handling classic update/versioning issue) How do you keep these? eg special file/dir, within IDE, leave in app and 'remember', on paper, ... If the former, how do you access/import them from the various applications/systems? (Python's import rules and restrictions, change control/version control) Am interested to hear your tactics; to learn, compare, and contrast... -- Regards, =dn From alexey.muranov at gmail.com Thu Mar 28 16:36:40 2019 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Thu, 28 Mar 2019 21:36:40 +0100 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: References: Message-ID: <1553805400.10745.2@gmail.com> On jeu., mars 28, 2019 at 5:00 PM, python-list-request at python.org wrote: > So documentation of that syntax would 100% be required Regarding documentation, i believe there would be 3 line to add: > () = > > is a syntactic sugar for > > = lambda : Alexey. From ian.g.kelly at gmail.com Thu Mar 28 16:42:02 2019 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 28 Mar 2019 14:42:02 -0600 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: <1553804867.10745.1@gmail.com> References: <1553790570.8480.0@gmail.com> <35237f68-05ec-6516-4ae3-0f3fd2d2ba6d@udel.edu> <1553804867.10745.1@gmail.com> Message-ID: On Thu, Mar 28, 2019 at 2:30 PM Alexey Muranov wrote: > > On jeu., mars 28, 2019 at 8:57 PM, Terry Reedy wrote: > > Throwing the name away is foolish. Testing functions is another > > situation in which function names are needed for proper report. > > My idea however was to have it as an exact synonyme of an assignment of > a lambda. Assignment is an assignment, it should not modify the > attributs of the value that is being assigned. There could perhaps be a special case for lambda expressions such that, when they are directly assigned to a variable, Python would use the variable name as the function name. I expect this could be accomplished by a straightforward transformation of the AST, perhaps even by just replacing the assignment with a def statement. Since this could just as easily be applied to lambda though, I'm afraid it doesn't offer much of a case for the "f(x)" syntactic sugar. From rosuav at gmail.com Thu Mar 28 16:43:24 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2019 07:43:24 +1100 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: <1553804867.10745.1@gmail.com> References: <1553790570.8480.0@gmail.com> <35237f68-05ec-6516-4ae3-0f3fd2d2ba6d@udel.edu> <1553804867.10745.1@gmail.com> Message-ID: On Fri, Mar 29, 2019 at 7:29 AM Alexey Muranov wrote: > My idea however was to have it as an exact synonyme of an assignment of > a lambda. Assignment is an assignment, it should not modify the > attributs of the value that is being assigned. Assigning lambda functions to names generally shouldn't be done. Just use def. You're asking for another way to do a bad thing that has a better alternative. There have periodically been proposals for the opposite, which would take care of some of the alternatives: def op["double"](x): return x * x This kind of proposal has its own issues, but I think it has a much better chance of being accepted than a way of creating and assigning lambda functions. ChrisA From onlinejudge95 at gmail.com Thu Mar 28 17:39:05 2019 From: onlinejudge95 at gmail.com (Test Bot) Date: Fri, 29 Mar 2019 03:09:05 +0530 Subject: Handy utilities = Friday Filosofical Finking In-Reply-To: References: Message-ID: +1 On Fri, Mar 29, 2019, 2:04 AM DL Neil wrote: > How do you keep, use, and maintain those handy snippets, functions, > classes... - units of code, which you employ over-and-over again? > > > Having coded 'stuff' once, most of us will keep units of code, > "utilities", which we expect will be useful in-future (DRY principle), > eg functions to rename files, choose unique back-up/new fileNMs, > accessing a DB, journalling (logging) start/stop msgs, building specs > from YAML/JSON/XML/.ini config files (tongue~cheek), etc. > > Do you 'keep' these, or perhaps next time you need something you've > 'done before' do you remember when/where a technique was last > used/burrow into 'history'? > (else, code it from scratch, all over again) > > How do you keep them updated, ie if add some new idea, better > err-checking, re-factor - how to add these 'back' into previous places > utility is used? > (who wants more "technical debt", plus handling classic > update/versioning issue) > > How do you keep these? eg special file/dir, within IDE, leave in app and > 'remember', on paper, ... If the former, how do you access/import them > from the various applications/systems? > (Python's import rules and restrictions, change control/version control) > > > Am interested to hear your tactics; to learn, compare, and contrast... > -- > Regards, > =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From cs at cskk.id.au Thu Mar 28 18:18:20 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 29 Mar 2019 09:18:20 +1100 Subject: Getting file extensions [linux fs] In-Reply-To: References: Message-ID: <20190328221820.GA67141@cskk.homeip.net> On 28Mar2019 01:12, Paulo da Silva wrote: >?s 23:09 de 27/03/19, Cameron Simpson escreveu: >> On 27Mar2019 21:49, Paulo da Silva wrote: >... >> The filefrag manual entry says it works by calling one of 2 ioctls. You >> can do that from Python with the ioctl() function in the standard fcntl >> module. I haven't tried to do this, but the results should be basicly as >> fast as filefrag itself. >> >> You'll need to decode the result the ioctl returns of course. >> >Thanks Cameron, I'll take a look at that. Oh, just tangential to this. If you were doing this ad hoc, yes calling the filefrag executable is very expensive. But if you are always doing a large batch of filenames invoking: filefrag lots of filenames here ... and reading from its output can be very effective, because the expense of the executable is amortized over all the files - the per file cost is much reduced. And it saves you working out how to use the ioctls from Python :-) You'll learn more from going the ioctl route though, and it gives you complete control if you need it. Cheers, Cameron Simpson From tjreedy at udel.edu Thu Mar 28 15:57:43 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 Mar 2019 15:57:43 -0400 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: <1553790570.8480.0@gmail.com> References: <1553790570.8480.0@gmail.com> Message-ID: <35237f68-05ec-6516-4ae3-0f3fd2d2ba6d@udel.edu> On 3/28/2019 12:29 PM, Alexey Muranov wrote: > On jeu., Mar 28, 2019 at 5:00 PM, python-list-request at python.org wrote: >> >> So my opinion is that lambda expressions should only be used within >> larger expressions and never directly bound. >> >>> It would be however more convenient to be able to write instead just >>> >>> ??? f(x) = x*x >> >> Given my view above, this is, standing alone, strictly an abbreviation >> of the equivalent def statement.? I am presuming that a proper >> implementation would result in f.__name__ == 'f'. >> > > No, after some thought, i think it should be an abbreviation of "f = > lambda x: x*x", f.__name__ would still be ''. Throwing the name away is foolish. Testing functions is another situation in which function names are needed for proper report. I wrote and use a test function something like the following, simplified and adapted for use with unittest: def ftest(func, io_pairs): errors = [] for input, expected in io_pairs: actual = func(input) if actual != expected: errors.append( f"Func: {func.__name__}, input: {input}, " f"expected: {expected}, actual: {actual}.") return errors if errors else None (Then "self.assertNone(ftest(func, io_pairs))" will test all pairs and list at least part of the error list.) If all the names were '', not very useful. (The workaround would be to require the caller to know a name and pass it separately, without mis-typing.) for unittest, a > But i see your point about never assigning lambdas directly, it makes > sense.? But sometimes i do assign short lambdas directly to variable. > >> Is the convenience and (very low) frequency of applicability worth the >> inconvenience of confusing the meaning of '=' and complicating the >> implementation? >> >>> I do not see any conflicts with the existing syntax. >> >> It heavily conflicts with existing syntax.? The current meaning of >> ? target_expression = object_expression >> is >> 1. Evaluate object_expression in the existing namespace to an object, >> prior to any new bindings and independent of the target_expression. >> 2. Evaluate target_expression in the existing namespace to one or more >> targets. >> 3. Bind object to target or iterate target to bind to multiple targets. > > I do not thick so.? In "x = 42" the variable x is not evaluated. > > All examples of the proposed syntax i can think of are currently > illegal, so i suppose there is no conflicts. (I would appreciate a > counterexample, if any.) You are talking about syntax conflicts, I am talking about semantic conflict, which is important for human understanding. > Thanks for the reference to PEP 8, this is indeed an argument against. The situation in which assigning lambda expressions is more tempting is when assigning to attributes or dicts. def double(x): return x*x C.double = double d['double'] = double versus C.double = lambda x: x*x d['double'] = lambda x: x*x For attributes, "def C.double(x): return x*x" has been proposed but not accepted. From wrw at mac.com Thu Mar 28 23:26:39 2019 From: wrw at mac.com (William Ray Wing) Date: Thu, 28 Mar 2019 23:26:39 -0400 Subject: Levenberg-Marquardt non-linear least-squares fitting in Python [follow-on] In-Reply-To: References: <459e5208-f464-4d07-9900-42d89bd3912d@googlegroups.com> <7855E1E5-A8FC-4830-9B57-F9901ECDCDBC@mac.com> Message-ID: <94D8AAD1-1818-4087-B67D-921B1F8F6343@mac.com> Below I?ve included the code I ran, reasonably (I think) commented. Note the reference to the example. The data actually came from a pandas data frame that was in turn filled from a 100 MB data file that included lots of other data not needed for this, which was a curve fit to a calibration run. Bill PS: If you want, I can probably still find a couple of the plots of the raw data and fitted result. --------------------- import numpy as np, matplotlib.pyplot as plt # # Inverted exponential that axymptotically approaches "a" as x gets large # def func2fit(x,a,b,c): return a - b * np.exp(-c * x) # Curve fitting below from: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html from scipy.optimize import curve_fit def fit(xdata, ydata, run_num): ll = len(xdata) # # The next four lines shift and scale the data so that the curve fit routine can # do its work without needing to use 8 or 16-byte precision. After fitting, we # will scale everything back. # ltemp = [ydata[i] - ydata[0] for i in range(ll)] ytemp = [ltemp[i] * .001 for i in range(ll)] ltemp = [xdata[i] - xdata[0] for i in range(ll)] xtemp = [ltemp[i] * .001 for i in range(ll)] # # popt is a list of the three optimized fittine parameters [a, b, c] # we are interested in the value of a. # cov is the 3 x 3 covariance matrix, the standard deviation (error) of the fit is # the square root of the diagonal. # popt,cov = curve_fit(func2fit, xtemp, ytemp) # # Here is what the fitted line looks like for plotting # fitted = [popt[0] - popt[1] * np.exp(-popt[2] * xtemp[i]) for i in range(ll)] # # And now plot the results to check the fit # fig1, ax1 = plt.subplots() plt.title('Normalized Data ' + str(run_num)) color_dic = {0: "red", 1: "green", 2: "blue", 3: "red", 4: "green", 5: "blue"} ax1.plot(xtemp, ytemp, marker = '.', linestyle = 'none', color = color_dic[run_num]) ax1.plot(xtemp, fitted, linestyle = '-', color = color_dic[run_num]) plt.savefig('Normalized ' + str(run_num)) perr = np.sqrt(np.diag(cov)) return popt, cov, xdata[0], ydata[0], fitted, perr[0] From dieter at handshake.de Fri Mar 29 02:17:31 2019 From: dieter at handshake.de (dieter) Date: Fri, 29 Mar 2019 07:17:31 +0100 Subject: Prepare accented characters for HTML References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> Message-ID: <87sgv68aro.fsf@handshake.de> Tony van der Hoff writes: > I have a MariaDB database, which contains accented (mostly French) > characters. I need to display these on an HTML page. I'm using the Jinja > templating engine. Why do you (still) need this? HTML is prepared to work all over the world - even in Asia where few characters are representable via ASCII and turning all non-ASCII characters into character references would be really tedious. An alternative would be to use the "utf-8" encoding when delivering your HTML pages. Then, there is no longer any need to use character references. From edmondo.giovannozzi at gmail.com Fri Mar 29 05:35:04 2019 From: edmondo.giovannozzi at gmail.com (edmondo.giovannozzi at gmail.com) Date: Fri, 29 Mar 2019 02:35:04 -0700 (PDT) Subject: Levenberg-Marquardt non-linear least-squares fitting in Python [follow-on] In-Reply-To: References: <459e5208-f464-4d07-9900-42d89bd3912d@googlegroups.com> <7855E1E5-A8FC-4830-9B57-F9901ECDCDBC@mac.com> <94D8AAD1-1818-4087-B67D-921B1F8F6343@mac.com> Message-ID: > ltemp = [ydata[i] - ydata[0] for i in range(ll)] > ytemp = [ltemp[i] * .001 for i in range(ll)] > ltemp = [xdata[i] - xdata[0] for i in range(ll)] > xtemp = [ltemp[i] * .001 for i in range(ll)] Use the vectorization given by numpy: ytemp = (ydata - ydata[0]) * 0.001 xtemp = (xdata - xdata[0]) * 0.001 .... fitted = popt[0] - popt[1] * np.exp(-popt[2] * xtemp) or better fitted = func2fit(xtemp, *popt) > # > # popt is a list of the three optimized fittine parameters [a, b, c] > # we are interested in the value of a. > # cov is the 3 x 3 covariance matrix, the standard deviation (error) of the fit is > # the square root of the diagonal. > # > popt,cov = curve_fit(func2fit, xtemp, ytemp) > # > # Here is what the fitted line looks like for plotting > # > fitted = [popt[0] - popt[1] * np.exp(-popt[2] * xtemp[i]) for i in range(ll)] > # > # And now plot the results to check the fit > # > fig1, ax1 = plt.subplots() > plt.title('Normalized Data ' + str(run_num)) > color_dic = {0: "red", 1: "green", 2: "blue", 3: "red", 4: "green", 5: "blue"} > ax1.plot(xtemp, ytemp, marker = '.', linestyle = 'none', color = color_dic[run_num]) > ax1.plot(xtemp, fitted, linestyle = '-', color = color_dic[run_num]) > plt.savefig('Normalized ' + str(run_num)) > perr = np.sqrt(np.diag(cov)) > return popt, cov, xdata[0], ydata[0], fitted, perr[0] From lists at vanderhoff.org Fri Mar 29 06:10:59 2019 From: lists at vanderhoff.org (Tony van der Hoff) Date: Fri, 29 Mar 2019 10:10:59 +0000 Subject: Jinja and non-ASCII characters (was Re: Prepare accented characters for HTML) In-Reply-To: References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> <02c538ed-c529-80ff-b02b-7c36824723e8@vanderhoff.org> Message-ID: Hello Chris. Thanks for your interest. On 28/03/2019 18:04, Chris Angelico wrote: > On Fri, Mar 29, 2019 at 4:10 AM Tony van der Hoff wrote: >> >> This'll probably work: > > You have a python3 shebang, but are you definitely running this under Python 3? > Absolutely. > Here's a much more minimal example. Can you see if this also fails for you? > > import sys > from jinja2 import Template > print(Template("French: {{french}}").render({"french": "ann?e"})) > print(sys.version) > Presumably you expect to run this from the command line. It works as expected: French: ann?e 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] However, with a slight modification: #!/usr/bin/env python3 import sys from jinja2 import Template print ("Content-type: text/html\n\n") print(Template("French: {{french}}").render({"french": "ann?e"})) print(sys.version) and running it in a browser (tried both chrome and Firefox), it fails as before: blank web page. Replacing the accented character displays the expected result: French: annee 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] Thanks to all who have pitched in. As I previously mentioned, I have a work-around, so no big deal, but I would like to get to the bottom of this. Cheers, Tony -- Tony van der Hoff | mailto:tony at vanderhoff.org Buckinghamshire, England | From antoon.pardon at vub.be Fri Mar 29 06:49:03 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 29 Mar 2019 11:49:03 +0100 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: <1553674918.3032.0@gmail.com> References: <1553674918.3032.0@gmail.com> Message-ID: <61e702e0-92f9-1526-bcd1-1e14acccff00@vub.be> On 27/03/19 09:21, Alexey Muranov wrote: > Whey you need a simple function in Python, there is a choice between a > normal function declaration and an assignment of a anonymous function > (defined by a lambda-expression) to a variable: > > ?? def f(x): return x*x > > or > > ?? f = lambda x: x*x > > It would be however more convenient to be able to write instead just > > ?? f(x) = x*x I have mixed feelings about this. I think anonymous functions only have a place as arguments to a function. So f(x) = x * x, doesn't look like an anonymous function but just an other way to have a named fuction. (as others have already pointed out) If we really want an alternative for the lambda expresion, I would go for the following. f = x -> x*x (or maybe we could have the ? instead of lambda) If we want haskell like patterns for defining functions I would go for the following: fac(0) -> 1 fac(n) -> n * fac(n - 1) Which seems incompatible with the proposal for an alternative lambda. -- Antoon Pardon. From tjol at tjol.eu Fri Mar 29 06:45:27 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 29 Mar 2019 11:45:27 +0100 Subject: Jinja and non-ASCII characters (was Re: Prepare accented characters for HTML) In-Reply-To: References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> <02c538ed-c529-80ff-b02b-7c36824723e8@vanderhoff.org> Message-ID: On 29/03/2019 11.10, Tony van der Hoff wrote: > and running it in a browser (tried both chrome and Firefox), How? > it fails as before: blank web page. No traceback? There must be a traceback somewhere. In a log file perhaps. From rosuav at gmail.com Fri Mar 29 07:08:15 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Mar 2019 22:08:15 +1100 Subject: Jinja and non-ASCII characters (was Re: Prepare accented characters for HTML) In-Reply-To: References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> <02c538ed-c529-80ff-b02b-7c36824723e8@vanderhoff.org> Message-ID: On Fri, Mar 29, 2019 at 9:12 PM Tony van der Hoff wrote: > > Hello Chris. > Thanks for your interest. > > On 28/03/2019 18:04, Chris Angelico wrote: > > On Fri, Mar 29, 2019 at 4:10 AM Tony van der Hoff wrote: > >> > >> This'll probably work: > > > > You have a python3 shebang, but are you definitely running this under Python 3? > > > Absolutely. > > > Here's a much more minimal example. Can you see if this also fails for you? > > > > import sys > > from jinja2 import Template > > print(Template("French: {{french}}").render({"french": "ann?e"})) > > print(sys.version) > > > > Presumably you expect to run this from the command line. It works as > expected: > > French: ann?e > 3.5.3 (default, Sep 27 2018, 17:25:39) > [GCC 6.3.0 20170516] > > However, with a slight modification: > > #!/usr/bin/env python3 > > import sys > from jinja2 import Template > print ("Content-type: text/html\n\n") Try: text/html; charset=utf-8 That might be all you need to make the browser understand it correctly. Otherwise, as Thomas says, you will need to figure out where the traceback is, which can probably be answered by figuring out what "running it in a browser" actually means. ChrisA From lists at vanderhoff.org Fri Mar 29 07:39:18 2019 From: lists at vanderhoff.org (Tony van der Hoff) Date: Fri, 29 Mar 2019 11:39:18 +0000 Subject: Jinja and non-ASCII characters (was Re: Prepare accented characters for HTML) In-Reply-To: References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> <02c538ed-c529-80ff-b02b-7c36824723e8@vanderhoff.org> Message-ID: On 29/03/2019 11:08, Chris Angelico wrote: > On Fri, Mar 29, 2019 at 9:12 PM Tony van der Hoff wrote: >> >> Hello Chris. >> Thanks for your interest. >> >> On 28/03/2019 18:04, Chris Angelico wrote: >>> On Fri, Mar 29, 2019 at 4:10 AM Tony van der Hoff wrote: >>>> >>>> This'll probably work: >>> >>> You have a python3 shebang, but are you definitely running this under Python 3? >>> >> Absolutely. >> >>> Here's a much more minimal example. Can you see if this also fails for you? >>> >>> import sys >>> from jinja2 import Template >>> print(Template("French: {{french}}").render({"french": "ann?e"})) >>> print(sys.version) >>> >> >> Presumably you expect to run this from the command line. It works as >> expected: >> >> French: ann?e >> 3.5.3 (default, Sep 27 2018, 17:25:39) >> [GCC 6.3.0 20170516] >> >> However, with a slight modification: >> >> #!/usr/bin/env python3 >> >> import sys >> from jinja2 import Template >> print ("Content-type: text/html\n\n") > > Try: text/html; charset=utf-8 > No difference > That might be all you need to make the browser understand it > correctly. Otherwise, as Thomas says, you will need to figure out > where the traceback is, which can probably be answered by figuring out > what "running it in a browser" actually means. > Running in browser: http://localhost/~tony/private/home/learning/jinja/minimal/minimal.py In apache2.access.log: ::1 - tony [29/Mar/2019:11:22:13 +0000] "GET /~tony/private/home/learning/jinja/minimal/minimal.py HTTP/1.1" 200 204 "http://localhost/~tony/private/home/learning/jinja/minimal/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36" ::1 - - [29/Mar/2019:11:23:04 +0000] "-" 408 0 "-" "-" ::1 - - [29/Mar/2019:11:23:04 +0000] "-" 408 0 "-" "-" So, 408 is a bit unusual for localhost. With the accented character removed, no timeout is reported. Maybe a clue. Can find no other traceback. Nothing relevant in apache2/error.log -- Tony van der Hoff | mailto:tony at vanderhoff.org Buckinghamshire, England | From tjol at tjol.eu Fri Mar 29 07:56:00 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 29 Mar 2019 12:56:00 +0100 Subject: Jinja and non-ASCII characters (was Re: Prepare accented characters for HTML) In-Reply-To: References: <48ce52b5-3710-a9bc-a4bf-74ef68475901@vanderhoff.org> <24db7f74-1c89-ee7a-8edb-74008d13ec51@vanderhoff.org> <02c538ed-c529-80ff-b02b-7c36824723e8@vanderhoff.org> Message-ID: On 29/03/2019 12.39, Tony van der Hoff wrote: > On 29/03/2019 11:08, Chris Angelico wrote: >> On Fri, Mar 29, 2019 at 9:12 PM Tony van der Hoff wrote: >>> >>> Hello Chris. >>> Thanks for your interest. >>> >>> On 28/03/2019 18:04, Chris Angelico wrote: >>>> On Fri, Mar 29, 2019 at 4:10 AM Tony van der Hoff wrote: >>>>> >>>>> This'll probably work: >>>> >>>> You have a python3 shebang, but are you definitely running this under Python 3? >>>> >>> Absolutely. >>> >>>> Here's a much more minimal example. Can you see if this also fails for you? >>>> >>>> import sys >>>> from jinja2 import Template >>>> print(Template("French: {{french}}").render({"french": "ann?e"})) >>>> print(sys.version) >>>> >>> >>> Presumably you expect to run this from the command line. It works as >>> expected: >>> >>> French: ann?e >>> 3.5.3 (default, Sep 27 2018, 17:25:39) >>> [GCC 6.3.0 20170516] >>> >>> However, with a slight modification: >>> >>> #!/usr/bin/env python3 >>> >>> import sys >>> from jinja2 import Template >>> print ("Content-type: text/html\n\n") >> >> Try: text/html; charset=utf-8 >> > No difference > >> That might be all you need to make the browser understand it >> correctly. Otherwise, as Thomas says, you will need to figure out >> where the traceback is, which can probably be answered by figuring out >> what "running it in a browser" actually means. >> > > Running in browser: > http://localhost/~tony/private/home/learning/jinja/minimal/minimal.py > > In apache2.access.log: So it's running in apache! Now the question is what apache is doing. Is it running it as a CGI script? Is it doing something clever for Python files (maybe involving Python 2?) ... wild guess: if the script is running as CGI in an enviroment with an ASCII-using "C" locale, with Python 3.5, you wouldn't be able to print non-ASCII characters by default. I think. In any case I remember reading about this problem (if this is the problem) being fixed in a newer version of Python. > ::1 - tony [29/Mar/2019:11:22:13 +0000] "GET > /~tony/private/home/learning/jinja/minimal/minimal.py HTTP/1.1" 200 204 > "http://localhost/~tony/private/home/learning/jinja/minimal/" > "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) > Chrome/72.0.3626.81 Safari/537.36" > ::1 - - [29/Mar/2019:11:23:04 +0000] "-" 408 0 "-" "-" > ::1 - - [29/Mar/2019:11:23:04 +0000] "-" 408 0 "-" "-" > > So, 408 is a bit unusual for localhost. With the accented character > removed, no timeout is reported. Maybe a clue. > > Can find no other traceback. Nothing relevant in apache2/error.log > > From ar at zeit.io Fri Mar 29 08:52:34 2019 From: ar at zeit.io (Arup Rakshit) Date: Fri, 29 Mar 2019 18:22:34 +0530 Subject: Understanding the MRO with multiple inheritance Message-ID: <80E9A894-50F9-454F-B576-EE9C6EBC5020@zeit.io> I basically had defined 4 classes. SimpleList be the base class for all the other 3 classes. SortedList and IntList both being the child of the base class SimpleList. They have a single inheritance relationship. Now I have the last class called SortedIntList which has multiple inheritance relationship with IntList and SortedList. The classes looks like: class SimpleList: def __init__(self, items): self._items = list(items) def add(self, item): self._items.append(item) def __getitem__(self, index): return self._items[index] def sort(self): self._items.sort() def __len__(self): return len(self._items) def __repr__(self): return "SimpleList({!r})".format(self._items) class SortedList(SimpleList): def __init__(self, items=()): super().__init__(items) def add(self, item): super().add(item) self.sort() def __repr__(self): return "SortedList({!r})".format(list(self)) class IntList(SimpleList): def __init__(self, items=()): for x in items: self._validate(x) super().__init__(items) @staticmethod def _validate(x): if not isinstance(x, int): raise TypeError('IntList only supports integer values.') def add(self, item): self._validate(item) super().add(item) def __repr__(self): return "IntList({!r})".format(list(self)) class SortedIntList(IntList, SortedList): def __repr__(self): return "SortedIntList({!r})".format(list(self)) Now when I call the add method on the SortedIntList class?s instance, I was expecting super.add() call inside the IntList class add method will dispatch it to the base class SimpleList. But in reality it doesn?t, it rather forwards it to the SortedList add method. How MRO guides here can anyone explain please? I am little lost in the chain. ob = SortedIntList((2,4,3)) ob.add(0) print(ob) # SortedIntList([0, 2, 3, 4]) Thanks, Arup Rakshit ar at zeit.io From neilc at norwich.edu Fri Mar 29 09:47:34 2019 From: neilc at norwich.edu (Neil Cerutti) Date: 29 Mar 2019 13:47:34 GMT Subject: Handy utilities = Friday Filosofical Finking References: Message-ID: On 2019-03-28, DL Neil wrote: > How do you keep, use, and maintain those handy snippets, > functions, classes... - units of code, which you employ > over-and-over again? > > Having coded 'stuff' once, most of us will keep units of code, > "utilities", which we expect will be useful in-future (DRY > principle), eg functions to rename files, choose unique > back-up/new fileNMs, accessing a DB, journalling (logging) > start/stop msgs, building specs from YAML/JSON/XML/.ini config > files (tongue~cheek), etc. > > Do you 'keep' these, or perhaps next time you need something > you've 'done before' do you remember when/where a technique was > last used/burrow into 'history'? (else, code it from scratch, > all over again) I usually wait until I notice I've written or wanted the same code snippet many times before I'll make it into a library. > How do you keep them updated, ie if add some new idea, better > err-checking, re-factor - how to add these 'back' into previous > places utility is used? (who wants more "technical debt", plus > handling classic update/versioning issue) After the library is written back-porting it to other place where it will be useful is done slowly over time as those utilities need updating for other reasons. > How do you keep these? eg special file/dir, within IDE, leave > in app and 'remember', on paper, ... If the former, how do you > access/import them from the various applications/systems? > (Python's import rules and restrictions, change control/version > control) I have a lib directory in my PYTHONPATH to dump 'em. -- Neil Cerutti From hjp-python at hjp.at Fri Mar 29 10:51:36 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 29 Mar 2019 15:51:36 +0100 Subject: Jinja and non-ASCII characters (was Re: Prepare accented characters for HTML) In-Reply-To: References: <02c538ed-c529-80ff-b02b-7c36824723e8@vanderhoff.org> Message-ID: <20190329145136.nhn7623b34cpqkpl@hjp.at> On 2019-03-29 12:56:00 +0100, Thomas Jollans wrote: > On 29/03/2019 12.39, Tony van der Hoff wrote: > > Running in browser: > > http://localhost/~tony/private/home/learning/jinja/minimal/minimal.py > > > > In apache2.access.log: > > So it's running in apache! > > Now the question is what apache is doing. Is it running it as a CGI > script? Is it doing something clever for Python files (maybe involving > Python 2?) > > ... wild guess: if the script is running as CGI in an enviroment with an > ASCII-using "C" locale, with Python 3.5, you wouldn't be able to print > non-ASCII characters by default. I think. In any case I remember reading > about this problem (if this is the problem) being fixed in a newer > version of Python. This is very likely correct. I also had this problem with the default Apache configuration on Debian, which explicitely sets LANG=C (Edit /etc/apache2/envvars to change this). The behaviour can be easily reproduced on the command line: hrunkner:~/tmp 15:27 :-) 1021% ./annee Content-type: text/html French: ann?e 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] hrunkner:~/tmp 15:27 :-) 1022% echo $LANG en_US.UTF-8 hrunkner:~/tmp 15:34 :-) 1023% LANG=C hrunkner:~/tmp 15:34 :-) 1024% ./annee Content-type: text/html Traceback (most recent call last): File "./annee", line 6, in print(Template("French: {{french}}").render({"french": "ann\xe9e"})) UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 11: ordinal not in range(128) This was fixed(?) in Python 3.7. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From __peter__ at web.de Fri Mar 29 11:42:37 2019 From: __peter__ at web.de (Peter Otten) Date: Fri, 29 Mar 2019 16:42:37 +0100 Subject: Jinja and non-ASCII characters (was Re: Prepare accented characters for HTML) References: <02c538ed-c529-80ff-b02b-7c36824723e8@vanderhoff.org> <20190329145136.nhn7623b34cpqkpl@hjp.at> Message-ID: Peter J. Holzer wrote: > On 2019-03-29 12:56:00 +0100, Thomas Jollans wrote: >> On 29/03/2019 12.39, Tony van der Hoff wrote: >> > Running in browser: >> > http://localhost/~tony/private/home/learning/jinja/minimal/minimal.py >> > >> > In apache2.access.log: >> >> So it's running in apache! >> >> Now the question is what apache is doing. Is it running it as a CGI >> script? Is it doing something clever for Python files (maybe involving >> Python 2?) >> >> ... wild guess: if the script is running as CGI in an enviroment with an >> ASCII-using "C" locale, with Python 3.5, you wouldn't be able to print >> non-ASCII characters by default. I think. In any case I remember reading >> about this problem (if this is the problem) being fixed in a newer >> version of Python. > > This is very likely correct. I also had this problem with the default > Apache configuration on Debian, which explicitely sets LANG=C (Edit > /etc/apache2/envvars to change this). > > The behaviour can be easily reproduced on the command line: > > hrunkner:~/tmp 15:27 :-) 1021% ./annee > Content-type: text/html > > > French: ann?e > 3.5.3 (default, Sep 27 2018, 17:25:39) > [GCC 6.3.0 20170516] > > hrunkner:~/tmp 15:27 :-) 1022% echo $LANG > en_US.UTF-8 > > hrunkner:~/tmp 15:34 :-) 1023% LANG=C > > hrunkner:~/tmp 15:34 :-) 1024% ./annee > Content-type: text/html > > > Traceback (most recent call last): > File "./annee", line 6, in > print(Template("French: {{french}}").render({"french": "ann\xe9e"})) > UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in > position 11: ordinal not in range(128) > > This was fixed(?) in Python 3.7. > > hp You could try to specify the encoding with PYTHONIOENCODING: $ LANG=C python3 -c "print('ann\xe9e')" Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 3: ordinal not in range(128) $ PYTHONIOENCODING=UTF-8 LANG=C python3 -c "print('ann\xe9e')" ann?e From akkana at shallowsky.com Fri Mar 29 11:44:19 2019 From: akkana at shallowsky.com (Akkana Peck) Date: Fri, 29 Mar 2019 09:44:19 -0600 Subject: Handy utilities = Friday Filosofical Finking In-Reply-To: References: Message-ID: <20190329154419.GA1229@shallowsky.com> DL Neil writes: > How do you keep, use, and maintain those handy snippets, functions, > classes... - units of code, which you employ over-and-over again? Fun topic! I have two methods: First, in my scripts directory I have a file called "python-cheatsheet.py" where I save small tips that I think I might not remember; mostly 2- to 5-liners. Second, I wrote a script called langgrep that searches in known places for files written in a specified language (it looks at file extensions and shebangs), then greps for a pattern in all those files. It looks in ~/bin plus a set of other directories, like certain projects under ~/src. So for instance if I'm trying to remember the syntax to read a CSV file as a dictionary, I might run langgrep python csv.DictReader or langgrep python -i csv | grep -i dict Since you asked about importing libraries: in my ~/bin I have a directory pythonlibs, which is in my PYTHONPATH, where I put (usually symlinks to) python files and packages I use regularly that aren't installed systemwide. ...Akkana From hjp-python at hjp.at Fri Mar 29 12:13:42 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 29 Mar 2019 17:13:42 +0100 Subject: Library for parsing binary structures In-Reply-To: <87o95v9usl.fsf@handshake.de> References: <87sgv7a03l.fsf@handshake.de> <87o95v9usl.fsf@handshake.de> Message-ID: <20190329161342.qal27cbappvbdqh7@hjp.at> On 2019-03-28 11:07:22 +0100, dieter wrote: > Paul Moore writes: > > My real interest is in whether any libraries exist to do this sort > > of thing (there are plenty of parser libraries for text, pyparsing > > being the obvious one, but far fewer for binary structures). > > Sure. *BUT* the library must fit your specific binary structure. > How should a general libary know how to interpret your > specific "type byte"s or that "(" introduces a homogenous > sequence of given length which must be terminated by ")"? Obviously you need some way to describe the specific binary format you want to parse - in other words, a grammar. The library could then use the grammar to parse the input - either by interpreting it directly, or by generating (Python) code from it. The latter has the advantage that it has to be done only once, not every time you want to parse a file. If that sounds familiar, it's what yacc does. Except that it does it for text files, not binary files. I am not aware of any generic binary parser generator for Python. I have read research papers about such generators for (I think) C and Java, but I don't remember the names and I'm not sure if the generators got beyond the proof of concept stage. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Mar 29 12:32:43 2019 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Fri, 29 Mar 2019 12:32:43 -0400 Subject: Library for parsing binary structures In-Reply-To: <20190329161342.qal27cbappvbdqh7@hjp.at> References: <87sgv7a03l.fsf@handshake.de> <87o95v9usl.fsf@handshake.de> <20190329161342.qal27cbappvbdqh7@hjp.at> Message-ID: On 3/29/19 12:13 PM, Peter J. Holzer wrote: > Obviously you need some way to describe the specific binary format you > want to parse - in other words, a grammar. The library could then use > the grammar to parse the input - either by interpreting it directly, or > by generating (Python) code from it. The latter has the advantage that > it has to be done only once, not every time you want to parse a file. > > If that sounds familiar, it's what yacc does. Except that it does it for > text files, not binary files. I am not aware of any generic binary > parser generator for Python. I have read research papers about such > generators for (I think) C and Java, but I don't remember the names and > I'm not sure if the generators got beyond the proof of concept stage. It's been a while since I've used those tools, but if you create a lexer (the yylex() function) that can tokenize a binary stream, then yacc won't know the difference. From p.f.moore at gmail.com Fri Mar 29 12:34:35 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 29 Mar 2019 16:34:35 +0000 Subject: Library for parsing binary structures In-Reply-To: <20190329161342.qal27cbappvbdqh7@hjp.at> References: <87sgv7a03l.fsf@handshake.de> <87o95v9usl.fsf@handshake.de> <20190329161342.qal27cbappvbdqh7@hjp.at> Message-ID: On Fri, 29 Mar 2019 at 16:16, Peter J. Holzer wrote: > Obviously you need some way to describe the specific binary format you > want to parse - in other words, a grammar. The library could then use > the grammar to parse the input - either by interpreting it directly, or > by generating (Python) code from it. The latter has the advantage that > it has to be done only once, not every time you want to parse a file. > > If that sounds familiar, it's what yacc does. Except that it does it for > text files, not binary files. I am not aware of any generic binary > parser generator for Python. I have read research papers about such > generators for (I think) C and Java, but I don't remember the names and > I'm not sure if the generators got beyond the proof of concept stage. That's precisely what I'm looking at. The construct library (https://pypi.org/project/construct/) basically does that, but using a DSL implemented in Python rather than generating Python code from a grammar. In fact, the problem I had with my recursive data structure turned out to be solvable in construct - as the DSL effectively builds a data structure describing the grammar, I was able to convert the problem of writing a recursive grammar into one of writing a recursive data structure: type_layouts = {} layout1 = layout2 = type_layouts[1] = layout1 type_layouts[2] = layout2 data_layout = However, the resulting parser works, but it gives horrible error messages. This is a normal problem with generated parsers, there are plenty of books and articles covering how to persuade tools like yacc to produce usable error reports on parse failures. There don't seem to be any particularly good error reporting features in construct (although I haven't looked closely), so I'm actually now looking at writing a hand-crafted parser, just to control the error reporting[1]. I don't know which solution I'll ultimately use, but it's an interesting exercise doing it both ways. And parsing binary data, unlike parsing text, is actually easy enough that hand crafting a parser isn't that much of a bother - maybe that's why there's less existing work in this area. Paul [1] The errors I'm reporting on are likely to be errors in my parsing code at this point, rather than errors in the data, but the problem is pretty much the same either way ;-) From jsf80238 at gmail.com Fri Mar 29 14:27:54 2019 From: jsf80238 at gmail.com (Jason Friedman) Date: Fri, 29 Mar 2019 12:27:54 -0600 Subject: The Mailing List Digest Project In-Reply-To: References: Message-ID: > > Pretty cool. FYI, the index page (now containing 4 articles) with Google >> Chrome 72.0.3626.x prompts me to translate to French. The articles >> themselves do not. >> > > I'm now getting the translation offer on other web pages with Chrome, not just this one. Thus, please ignore my prior posting. From hjp-python at hjp.at Fri Mar 29 16:38:34 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 29 Mar 2019 21:38:34 +0100 Subject: Library for parsing binary structures In-Reply-To: References: <87sgv7a03l.fsf@handshake.de> <87o95v9usl.fsf@handshake.de> <20190329161342.qal27cbappvbdqh7@hjp.at> Message-ID: <20190329203834.f623s3qhsykxfx2l@hjp.at> On 2019-03-29 16:34:35 +0000, Paul Moore wrote: > On Fri, 29 Mar 2019 at 16:16, Peter J. Holzer wrote: > > > Obviously you need some way to describe the specific binary format you > > want to parse - in other words, a grammar. The library could then use > > the grammar to parse the input - either by interpreting it directly, or > > by generating (Python) code from it. The latter has the advantage that > > it has to be done only once, not every time you want to parse a file. > > > > If that sounds familiar, it's what yacc does. Except that it does it for > > text files, not binary files. I am not aware of any generic binary > > parser generator for Python. I have read research papers about such > > generators for (I think) C and Java, but I don't remember the names and > > I'm not sure if the generators got beyond the proof of concept stage. > > That's precisely what I'm looking at. The construct library > (https://pypi.org/project/construct/) basically does that, but using a > DSL implemented in Python rather than generating Python code from a > grammar. Good to know. I'll add that to my list of Tools Which I'm Not Likely To Use Soon But Which May Be Useful Some Day. > However, the resulting parser works, but it gives horrible error > messages. This is a normal problem with generated parsers, there are > plenty of books and articles covering how to persuade tools like yacc > to produce usable error reports on parse failures. Yeah, that still seems to be an unsolved problem. > I don't know which solution I'll ultimately use, but it's an > interesting exercise doing it both ways. And parsing binary data, > unlike parsing text, is actually easy enough that hand crafting a > parser isn't that much of a bother - maybe that's why there's less > existing work in this area. I'm a bit sceptical about that. Writing a hand-crafted parser for most text-based grammars isn't that hard either, but there are readily- available tools (like yacc), so people use them (despite problems like horrible error messages). For binary protocols, such tools are much less well-known. It may be true that binary grammars seem simpler. But in practice there are lots and lots of security holes because hand-crafted parsers tend to use un-warranted shortcuts (see heart-bleed or the JPEG parsing bug of the week), which an automatically generated parser would not take. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From cs at cskk.id.au Fri Mar 29 18:44:48 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 30 Mar 2019 09:44:48 +1100 Subject: Library for parsing binary structures In-Reply-To: References: Message-ID: <20190329224448.GA58989@cskk.homeip.net> On 27Mar2019 18:41, Paul Moore wrote: >I'm looking for a library that lets me parse binary data structures. >The stdlib struct module is fine for simple structures, but when it >gets to more complicated cases, you end up doing a lot of the work by >hand (which isn't that hard, and is generally perfectly viable, but >I'm feeling lazy ;-)) I wrote my own: cs.binary, available on PyPI. The PyPI page has is module docs, which I think are ok: https://pypi.org/project/cs.binary/ Here's a binary packet protocol built on to of it: https://pypi.org/project/cs.packetstream/ and here's an ISO14496 (the MP4 format) parser using it: https://pypi.org/project/cs.iso14496/ Of interest is that ISO 14496 uses recursive data structures. The command line "main" function is up the top, which shows how it is used. Cheers, Cameron Simpson From cs at cskk.id.au Fri Mar 29 19:14:59 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 30 Mar 2019 10:14:59 +1100 Subject: Library for parsing binary structures In-Reply-To: <20190329224448.GA58989@cskk.homeip.net> References: <20190329224448.GA58989@cskk.homeip.net> Message-ID: <20190329231459.GA44154@cskk.homeip.net> On 30Mar2019 09:44, Cameron Simpson wrote: >On 27Mar2019 18:41, Paul Moore wrote: >>I'm looking for a library that lets me parse binary data structures. >>The stdlib struct module is fine for simple structures, but when it >>gets to more complicated cases, you end up doing a lot of the work by >>hand (which isn't that hard, and is generally perfectly viable, but >>I'm feeling lazy ;-)) > >I wrote my own: cs.binary, available on PyPI. The PyPI page has is >module docs, which I think are ok: > > https://pypi.org/project/cs.binary/ [...] >and here's an ISO14496 (the MP4 format) parser using it: > https://pypi.org/project/cs.iso14496/ >Of interest is that ISO 14496 uses recursive data structures. I neglected to mention: with cs.binary you write binary formats as classes (which allows for easy conditional parsing and so forth). And... normally those classes know how to write themselves back out, which makes for easy transcription and binary data generation. Conditional binary formats require a class specific .transcribe method (which just yields binary data or some other convenient things including other binary class instances, see doco) but flat records have a default .transcribe. Cheers, Cameron Simpson From PythonList at DancesWithMice.info Fri Mar 29 21:28:51 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 30 Mar 2019 14:28:51 +1300 Subject: Understanding the MRO with multiple inheritance In-Reply-To: <80E9A894-50F9-454F-B576-EE9C6EBC5020@zeit.io> References: <80E9A894-50F9-454F-B576-EE9C6EBC5020@zeit.io> Message-ID: <0f65b606-d193-589b-540f-05a68f4d2ec3@DancesWithMice.info> Arup, There is a minefield here. Are you using Python 2 or 3? -- Regards =dn From rosuav at gmail.com Fri Mar 29 21:32:11 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Mar 2019 12:32:11 +1100 Subject: Understanding the MRO with multiple inheritance In-Reply-To: <80E9A894-50F9-454F-B576-EE9C6EBC5020@zeit.io> References: <80E9A894-50F9-454F-B576-EE9C6EBC5020@zeit.io> Message-ID: On Fri, Mar 29, 2019 at 11:54 PM Arup Rakshit wrote: > > Now when I call the add method on the SortedIntList class?s instance, I was expecting super.add() call inside the IntList class add method will dispatch it to the base class SimpleList. But in reality it doesn?t, it rather forwards it to the SortedList add method. How MRO guides here can anyone explain please? > When you call super, you're saying "go to the next in the MRO". You can examine the MRO by looking at SortedIntList.__mro__ - that should show you the exact order that methods will be called. ChrisA From mons.sidus at gmail.com Fri Mar 29 23:06:00 2019 From: mons.sidus at gmail.com (mons.sidus at gmail.com) Date: Fri, 29 Mar 2019 20:06:00 -0700 (PDT) Subject: Query windows event log with python In-Reply-To: References: <8e37e86b-2f07-494e-a913-f7d2fb6ba9a4@googlegroups.com> <2ba544a0-4a19-4c1e-bae3-c916ce83a84e@googlegroups.com> Message-ID: <1e41060f-985e-4ddb-a839-642d4934c2fe@googlegroups.com> lol cheeky as. server = 'x' # name of the target computer to get event logs source = 'x' # 'Application' # 'Security' hand = win32evtlog.OpenEventLog(server, source) flags = win32evtlog.EVENTLOG_BACKWARDS_READ | win32evtlog.EVENTLOG_SEQUENTIAL_READ total = win32evtlog.GetNumberOfEventLogRecords(hand) event_no = 1 log = win32evtlog.ReadEventLog(hand, flags, 0, ) i wanna keep going hard as i do and learn it but keep getting a nonsensical error OverflowError: days=1834132873; must have magnitude <= 999999999 The above exception was the direct cause of the following exception: Traceback (most recent call last): SystemError: returned a result with an error set cant find much info, tried a few win32 modules to see if it made a difference. From dieter at handshake.de Sat Mar 30 02:06:52 2019 From: dieter at handshake.de (dieter) Date: Sat, 30 Mar 2019 07:06:52 +0100 Subject: Understanding the MRO with multiple inheritance References: <80E9A894-50F9-454F-B576-EE9C6EBC5020@zeit.io> Message-ID: <87ftr4ew03.fsf@handshake.de> Arup Rakshit writes: > I basically had defined 4 classes. SimpleList be the base class for all the other 3 classes. SortedList and IntList both being the child of the base class SimpleList. They have a single inheritance relationship. Now I have the last class called SortedIntList which has multiple inheritance relationship with IntList and SortedList. The classes looks like: > > class SimpleList: > ... > def add(self, item): > self._items.append(item) > ... > > class SortedList(SimpleList): > ... > def add(self, item): > super().add(item) > self.sort() > ... > > class IntList(SimpleList): > ... > def add(self, item): > self._validate(item) > super().add(item) > ... > > class SortedIntList(IntList, SortedList): > ... > > > Now when I call the add method on the SortedIntList class?s instance, I was expecting super.add() call inside the IntList class add method will dispatch it to the base class SimpleList. "super" is mainly for the use case of "mixin classes". By design, a "mixin class" must cope with an unknown inheritance structure and it must be able to cooperate with all classes in this structure. Especially, there must be a way to give all classes in the structure the chance to apply a method. This way is "super". As an example, think of "__init__". Each class in the class structure might need to perform its own initialization. To archieve this, "__init__" likely has the signature "__init__(self, **kw)" and each class pickes its initialization arguments from "kw" and then delegates to the next (in MRO) class with "super().__init__(kw)". This class may not be a base class of the current class. Thus, you use "super" when you want to delegate to an unknown class in the inheritance structure; if you want to delegate to a specific base class, then you do not use "super" but delegate explicitly to this class. From ar at zeit.io Sat Mar 30 02:44:19 2019 From: ar at zeit.io (Arup Rakshit) Date: Sat, 30 Mar 2019 12:14:19 +0530 Subject: Understanding the MRO with multiple inheritance In-Reply-To: <0f65b606-d193-589b-540f-05a68f4d2ec3@DancesWithMice.info> References: <80E9A894-50F9-454F-B576-EE9C6EBC5020@zeit.io> <0f65b606-d193-589b-540f-05a68f4d2ec3@DancesWithMice.info> Message-ID: <676DA093-AC94-4F7C-A92D-3BF2C0B42C76@zeit.io> Hello DL, I am using Python3. Thanks, Arup Rakshit ar at zeit.io > On 30-Mar-2019, at 6:58 AM, DL Neil wrote: > > Arup, > > There is a minefield here. Are you using Python 2 or 3? > > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list From ar at zeit.io Sat Mar 30 04:06:05 2019 From: ar at zeit.io (Arup Rakshit) Date: Sat, 30 Mar 2019 13:36:05 +0530 Subject: Understanding the MRO with multiple inheritance In-Reply-To: References: <80E9A894-50F9-454F-B576-EE9C6EBC5020@zeit.io> Message-ID: <1D1C8965-454C-4E4C-AFF6-AFD21D43A884@zeit.io> Thanks Chris and Dieter. I think I got it. It seems it follows the __mro__ of the caller class, not the current class __mro_. if __name__ == '__main__': print('MRO of SortedIntList {}'.format(SortedIntList.__mro__)) print('MRO of IntList {}'.format(IntList.__mro__)) # MRO of SortedIntList (, , , , ) # MRO of IntList (, , ) I thought obj.add(0) goes to the IntList by following its factory class __mro__, and then it follows the __mro__ of the current class(IntList) which is SimpleList . Thanks again. Thanks, Arup Rakshit ar at zeit.io > On 30-Mar-2019, at 7:02 AM, Chris Angelico wrote: > > On Fri, Mar 29, 2019 at 11:54 PM Arup Rakshit wrote: >> >> Now when I call the add method on the SortedIntList class?s instance, I was expecting super.add() call inside the IntList class add method will dispatch it to the base class SimpleList. But in reality it doesn?t, it rather forwards it to the SortedList add method. How MRO guides here can anyone explain please? >> > > When you call super, you're saying "go to the next in the MRO". You > can examine the MRO by looking at SortedIntList.__mro__ - that should > show you the exact order that methods will be called. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From ar at zeit.io Sat Mar 30 04:20:09 2019 From: ar at zeit.io (Arup Rakshit) Date: Sat, 30 Mar 2019 13:50:09 +0530 Subject: Why do I need to use pip3 but not pip Message-ID: <80E71FA6-F8CA-48B8-92CA-E499047D5A20@zeit.io> Hi, When I read this https://pip.pypa.io/en/stable/installing/ it says I have the pip installed when I installed the python from official doc. But when I run the `pip` command from shell, I get error, but pip3 works. ~/python_playground ? pip --version zsh: command not found: pip ~/python_playground ? ? pip3 --version pip 18.1 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7) Do I always need to install using pip3 program then? Thanks, Arup Rakshit ar at zeit.io From cs at cskk.id.au Sat Mar 30 04:35:32 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 30 Mar 2019 19:35:32 +1100 Subject: Why do I need to use pip3 but not pip In-Reply-To: <80E71FA6-F8CA-48B8-92CA-E499047D5A20@zeit.io> References: <80E71FA6-F8CA-48B8-92CA-E499047D5A20@zeit.io> Message-ID: <20190330083532.GA73794@cskk.homeip.net> On 30Mar2019 13:50, Arup Rakshit wrote: >When I read this https://pip.pypa.io/en/stable/installing/ it says I >have the pip installed when I installed the python from official doc. >But when I run the `pip` command from shell, I get error, but pip3 >works. > >~/python_playground >? pip --version > >zsh: command not found: pip > >~/python_playground ? >? pip3 --version > >pip 18.1 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7) Ok, you've installed python 3 on a Mac. Historically most systems have shipped with python 2 (from the OS vendor, which is Apple in your case), and the "python" command invokes Python 2. So python 3 is installed as the "python3" command to avoid confusion. The "pip" command from your python 3 install looks like it is also installed as "pip3" to avoid confusion. >Do I always need to install using pip3 program then? Yes, that is correct for this particular install. Cheers, Cameron Simpson From gandalf at shopzeus.com Sat Mar 30 04:32:47 2019 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Sat, 30 Mar 2019 09:32:47 +0100 Subject: Why do I need to use pip3 but not pip In-Reply-To: <80E71FA6-F8CA-48B8-92CA-E499047D5A20@zeit.io> References: <80E71FA6-F8CA-48B8-92CA-E499047D5A20@zeit.io> Message-ID: <7d350f28-9403-fe9f-22b7-38accb4e71cc@shopzeus.com> ? Hello, It depends on the operating system. For example on Ubuntu, the default python version is still 2.7. When you install both python2.7 and python3 on a system, then usually the "pip" will be a symlink to pip version 2 or 3. The default python interpreter can be different on different systems. The most portable way to run pip with a given version (AFAIK) is to use "python -m pip" instead of "pip". E.g.: python3 -m pip install PACKAGE_NAME However, there is still a problem when you have multiple python versions on the same machine. For example, python3.6 and python3.7. On those systems, python3 will be a symlink to the default one. For example: $ which python /usr/bin/python $ ls -lah /usr/bin/python lrwxrwxrwx 1 root root 9 apr?? 16? 2018 /usr/bin/python -> python2.7 $ which python3????????? /usr/bin/python3 $ ls -lah /usr/bin/python3 lrwxrwxrwx 1 root root 9 oct?? 25 13:11 /usr/bin/python3 -> python3.6 Regards, ?? Laszlo 2019. 03. 30. 9:20 keltez?ssel, Arup Rakshit ?rta: > Hi, > > When I read this https://pip.pypa.io/en/stable/installing/ it says I > have the pip installed when I installed the python from official doc. > But when I run the `pip` command from shell, I get error, but pip3 works. > > ~/python_playground ? pip --version > > zsh: command not found: pip > > ~/python_playground ? > ? pip3 --version > > pip 18.1 from > /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip > (python 3.7) > > Do I always need to install using pip3 program then? > > > Thanks, > > Arup Rakshit > ar at zeit.io > > > From rosuav at gmail.com Sat Mar 30 05:07:24 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Mar 2019 20:07:24 +1100 Subject: Understanding the MRO with multiple inheritance In-Reply-To: <1D1C8965-454C-4E4C-AFF6-AFD21D43A884@zeit.io> References: <80E9A894-50F9-454F-B576-EE9C6EBC5020@zeit.io> <1D1C8965-454C-4E4C-AFF6-AFD21D43A884@zeit.io> Message-ID: On Sat, Mar 30, 2019 at 7:08 PM Arup Rakshit wrote: > > Thanks Chris and Dieter. I think I got it. It seems it follows the __mro__ of the caller class, not the current class __mro_. That is correct. It is the object that has an MRO, and it's that object's MRO that matters to super. ChrisA From ar at zeit.io Sat Mar 30 05:42:21 2019 From: ar at zeit.io (Arup Rakshit) Date: Sat, 30 Mar 2019 15:12:21 +0530 Subject: Why do I need to use pip3 but not pip In-Reply-To: <20190330083532.GA73794@cskk.homeip.net> References: <80E71FA6-F8CA-48B8-92CA-E499047D5A20@zeit.io> <20190330083532.GA73794@cskk.homeip.net> Message-ID: <488B9A17-9528-4D79-A092-575A38CCFD10@zeit.io> Hello All, Thanks I got it now. One related question: Can I use pip3 for example to install packages project specific, but not globally? So that when I delete the project, all of them gone also from my disk. Thanks, Arup Rakshit ar at zeit.io > On 30-Mar-2019, at 2:05 PM, Cameron Simpson wrote: > > On 30Mar2019 13:50, Arup Rakshit wrote: >> When I read this https://pip.pypa.io/en/stable/installing/ it says I have the pip installed when I installed the python from official doc. But when I run the `pip` command from shell, I get error, but pip3 works. >> >> ~/python_playground >> ? pip --version >> >> zsh: command not found: pip >> >> ~/python_playground ? >> ? pip3 --version >> >> pip 18.1 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7) > > Ok, you've installed python 3 on a Mac. > > Historically most systems have shipped with python 2 (from the OS vendor, which is Apple in your case), and the "python" command invokes Python 2. So python 3 is installed as the "python3" command to avoid confusion. The "pip" command from your python 3 install looks like it is also installed as "pip3" to avoid confusion. > >> Do I always need to install using pip3 program then? > > Yes, that is correct for this particular install. > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Sat Mar 30 05:56:38 2019 From: __peter__ at web.de (Peter Otten) Date: Sat, 30 Mar 2019 10:56:38 +0100 Subject: Why do I need to use pip3 but not pip References: <80E71FA6-F8CA-48B8-92CA-E499047D5A20@zeit.io> <20190330083532.GA73794@cskk.homeip.net> <488B9A17-9528-4D79-A092-575A38CCFD10@zeit.io> Message-ID: Arup Rakshit wrote: > Hello All, > > Thanks I got it now. > > One related question: Can I use pip3 for example to install packages > project specific, but not globally? So that when I delete the project, all > of them gone also from my disk. For that you can create a "virtual environment": $ python3 -m venv foo $ cd foo $ . bin/activate Once you have activated it you can use 'pip' and 'python' to invoke the versions attached to the virtual environment: (foo) $ pip install example Downloading/unpacking example Downloading example-0.1.0.tar.gz Running setup.py (path:/home/petto/foo/build/example/setup.py) egg_info for package example Downloading/unpacking six (from example) Downloading six-1.12.0-py2.py3-none-any.whl Installing collected packages: example, six Running setup.py install for example Successfully installed example six Cleaning up... (foo) $ python Python 3.4.3 (default, Nov 12 2018, 22:25:49) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import example >>> Let's get rid of it now: (foo) $ deactivate $ cd .. $ rm -r foo # everything should be gone From ar at zeit.io Sat Mar 30 06:27:55 2019 From: ar at zeit.io (Arup Rakshit) Date: Sat, 30 Mar 2019 15:57:55 +0530 Subject: Why do I need to use pip3 but not pip In-Reply-To: References: <80E71FA6-F8CA-48B8-92CA-E499047D5A20@zeit.io> <20190330083532.GA73794@cskk.homeip.net> <488B9A17-9528-4D79-A092-575A38CCFD10@zeit.io> Message-ID: <8A25623A-C848-422E-9079-6E7E183DD7EC@zeit.io> Hi Peter, This is awesome. Now where should I put my source code? I see many folders into it. Thanks, Arup Rakshit ar at zeit.io > On 30-Mar-2019, at 3:26 PM, Peter Otten <__peter__ at web.de> wrote: > > Arup Rakshit wrote: > >> Hello All, >> >> Thanks I got it now. >> >> One related question: Can I use pip3 for example to install packages >> project specific, but not globally? So that when I delete the project, all >> of them gone also from my disk. > > For that you can create a "virtual environment": > > $ python3 -m venv foo > $ cd foo > $ . bin/activate > > Once you have activated it you can use 'pip' and 'python' to invoke the > versions attached to the virtual environment: > > (foo) $ pip install example > Downloading/unpacking example > Downloading example-0.1.0.tar.gz > Running setup.py (path:/home/petto/foo/build/example/setup.py) egg_info > for package example > > Downloading/unpacking six (from example) > Downloading six-1.12.0-py2.py3-none-any.whl > Installing collected packages: example, six > Running setup.py install for example > > Successfully installed example six > Cleaning up... > (foo) $ python > Python 3.4.3 (default, Nov 12 2018, 22:25:49) > [GCC 4.8.4] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import example >>>> > > Let's get rid of it now: > > (foo) $ deactivate > $ cd .. > $ rm -r foo # everything should be gone > > > -- > https://mail.python.org/mailman/listinfo/python-list From p.f.moore at gmail.com Sat Mar 30 06:29:53 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Sat, 30 Mar 2019 10:29:53 +0000 Subject: Library for parsing binary structures In-Reply-To: <20190329224448.GA58989@cskk.homeip.net> References: <20190329224448.GA58989@cskk.homeip.net> Message-ID: On Fri, 29 Mar 2019 at 23:21, Cameron Simpson wrote: > > On 27Mar2019 18:41, Paul Moore wrote: > >I'm looking for a library that lets me parse binary data structures. > >The stdlib struct module is fine for simple structures, but when it > >gets to more complicated cases, you end up doing a lot of the work by > >hand (which isn't that hard, and is generally perfectly viable, but > >I'm feeling lazy ;-)) > > I wrote my own: cs.binary, available on PyPI. The PyPI page has is > module docs, which I think are ok: > > https://pypi.org/project/cs.binary/ Nice, thanks - that's exactly the sort of pointer I was looking for. I'll take a look and see how it works for my use case. Paul From alexey.muranov at gmail.com Sat Mar 30 07:27:18 2019 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Sat, 30 Mar 2019 12:27:18 +0100 Subject: Python-list Digest, Vol 186, Issue 31 In-Reply-To: References: Message-ID: <1553945238.4712.0@gmail.com> On ven., Mar 29, 2019 at 4:51 PM, python-list-request at python.org wrote: > On Thu, Mar 28, 2019 at 2:30 PM Alexey Muranov > > wrote: >> >> On jeu., mars 28, 2019 at 8:57 PM, Terry Reedy >> wrote: >> > Throwing the name away is foolish. Testing functions is another >> > situation in which function names are needed for proper report. >> >> My idea however was to have it as an exact synonyme of an >> assignment of >> a lambda. Assignment is an assignment, it should not modify the >> attributs of the value that is being assigned. > > There could perhaps be a special case for lambda expressions such > that, > when they are directly assigned to a variable, Python would use the > variable name as the function name. I expect this could be > accomplished by > a straightforward transformation of the AST, perhaps even by just > replacing > the assignment with a def statement. If this will happen, that is, if in Python assigning a lambda-defined function to a variable will mutate the function's attributes, or else, if is some "random" syntactically-determined cases f = ... will stop being the same as evaluating the right-hand side and assigning the result to "f" variable, it will be a fairly good extra reason for me to go away from Python. > Since this could just as easily be applied to lambda though, I'm > afraid it > doesn't offer much of a case for the "f(x)" syntactic sugar. I did not get this. My initial idea was exactly about introducing a syntactic sugar for better readability. I've already understood that the use cases contradict PEP 8 recommendations. Alexey. From alexey.muranov at gmail.com Sat Mar 30 07:29:05 2019 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Sat, 30 Mar 2019 12:29:05 +0100 Subject: Syntax for one-line "nonymous" functions in "declaration style" Message-ID: <1553945345.4712.1@gmail.com> On ven., Mar 29, 2019 at 4:51 PM, python-list-request at python.org wrote: > On Thu, Mar 28, 2019 at 2:30 PM Alexey Muranov >  > wrote: >> >> On jeu., mars 28, 2019 at 8:57 PM, Terry Reedy >> wrote: >> > Throwing the name away is foolish. Testing functions is another >> > situation in which function names are needed for proper report. >> >> My idea however was to have it as an exact synonyme of an >> assignment of >> a lambda. Assignment is an assignment, it should not modify the >> attributs of the value that is being assigned. > > There could perhaps be a special case for lambda expressions such > that, > when they are directly assigned to a variable, Python would use the > variable name as the function name. I expect this could be > accomplished by > a straightforward transformation of the AST, perhaps even by just > replacing > the assignment with a def statement. If this will happen, that is, if in Python assigning a lambda-defined function to a variable will mutate the function's attributes, or else, if is some "random" syntactically-determined cases f = ... will stop being the same as evaluating the right-hand side and assigning the result to "f" variable, it will be a fairly good extra reason for me to go away from Python. > Since this could just as easily be applied to lambda though, I'm > afraid it > doesn't offer much of a case for the "f(x)" syntactic sugar. I did not get this. My initial idea was exactly about introducing a syntactic sugar for better readability. I've already understood that the use cases contradict PEP 8 recommendations. Alexey. From hjp-python at hjp.at Sat Mar 30 07:43:17 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 30 Mar 2019 12:43:17 +0100 Subject: Why do I need to use pip3 but not pip In-Reply-To: <8A25623A-C848-422E-9079-6E7E183DD7EC@zeit.io> References: <80E71FA6-F8CA-48B8-92CA-E499047D5A20@zeit.io> <20190330083532.GA73794@cskk.homeip.net> <488B9A17-9528-4D79-A092-575A38CCFD10@zeit.io> <8A25623A-C848-422E-9079-6E7E183DD7EC@zeit.io> Message-ID: <20190330114317.onncey3ha2lavblt@hjp.at> On 2019-03-30 15:57:55 +0530, Arup Rakshit wrote: > This is awesome. Now where should I put my source code? I see many folders into it. You don't. In my opinion virtual environments should be expendable: You can destroy and recreate them at will. That leaves two possibilies: 1) Use a "central repository" of virtual environments. For example, I have a directory ~/venv/ which contains the virtual environments. My project directories are elsewhere, so when I'm working on a project, I' usually do something like: % venv project-environment % cd ~/wrk/project/src % pip install -r requirements.txt The first (venv is a litte shell function I wrote, see below) activates the environment, the second cds to the source code (note that the environment and the project don't have to have the same name, although they often do), the third installs any required packages into the virtual environment (of course I do that only after they change, not every time). 2) Put each virtual environment into a subdirectory of the project, like this: . ??? project1 ??? ??? src ??? ??? venv ??? project2 ??? src ??? venv Then I would do something like: % cd project1 % venv % cd src % pip install -r requirements.txt I started with the second method and switched to the first. I like the flexibility: I can reuse the same environment for multiple projects or test the same project in multiple environments. I can also easily see which environments I have and delete them if I don't need them any more (I can always recreate them with pip install -r requirements.txt) The requirements.txt file contains the packages your project needs. Every project should have one. Some people like to generate it automatically with "pip freeze", but I prefer to write it myself and put only first-level requirements (not requirements of those requirements) into it. I also only put version numbers into it if I know that I need a specific version (or range of versions). Normally getting the newest version is fine. Finally, here is my venv function: venv() { for d in venv/"$1" ve/"$1" ~/venv/"$1" "$1" do if [ -f "$d"/bin/activate ] then . "$d"/bin/activate break fi done } hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From ian.g.kelly at gmail.com Sat Mar 30 12:37:35 2019 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 30 Mar 2019 10:37:35 -0600 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: <1553945345.4712.1@gmail.com> References: <1553945345.4712.1@gmail.com> Message-ID: On Sat, Mar 30, 2019, 5:32 AM Alexey Muranov wrote: > > On ven., Mar 29, 2019 at 4:51 PM, python-list-request at python.org wrote: > > > > There could perhaps be a special case for lambda expressions such > > that, > > when they are directly assigned to a variable, Python would use the > > variable name as the function name. I expect this could be > > accomplished by > > a straightforward transformation of the AST, perhaps even by just > > replacing > > the assignment with a def statement. > > If this will happen, that is, if in Python assigning a lambda-defined > function to a variable will mutate the function's attributes, or else, > if is some "random" syntactically-determined cases > > f = ... > > will stop being the same as evaluating the right-hand side and > assigning the result to "f" variable, it will be a fairly good extra > reason for me to go away from Python. > Is there a particular reason you don't like this? It's not too different from the syntactic magic Python already employs to support the 0-argument form of super(). From cs at cskk.id.au Sat Mar 30 19:46:25 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 31 Mar 2019 10:46:25 +1100 Subject: Library for parsing binary structures In-Reply-To: References: Message-ID: <20190330234625.GA94398@cskk.homeip.net> On 30Mar2019 10:29, Paul Moore wrote: >On Fri, 29 Mar 2019 at 23:21, Cameron Simpson wrote: >> >> On 27Mar2019 18:41, Paul Moore wrote: >> >I'm looking for a library that lets me parse binary data structures. >> >The stdlib struct module is fine for simple structures, but when it >> >gets to more complicated cases, you end up doing a lot of the work by >> >hand (which isn't that hard, and is generally perfectly viable, but >> >I'm feeling lazy ;-)) >> >> I wrote my own: cs.binary, available on PyPI. The PyPI page has is >> module docs, which I think are ok: >> >> https://pypi.org/project/cs.binary/ > >Nice, thanks - that's exactly the sort of pointer I was looking for. >I'll take a look and see how it works for my use case. I'd be happy to consider adapting some stuff for your use cases; as you may imagine it is written to my use cases. Also, I should point you at the cs.binary.structtuple factory, which makes a class for those structures trivially defined with a struct format string. As it uses struct for the parse step and transcribe steps, so it should be performant. Here's an example from the cs.iso14496 module: PDInfo = structtuple('PDInfo', '>LL', 'rate initial_delay') which makes a PDInfo class for 2 big endian unsigned longs with .rate and .initial_delay attributes. Cheers, Cameron Simpson From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Sat Mar 30 20:27:39 2019 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Sun, 31 Mar 2019 00:27:39 +0000 Subject: Getting file extensions [linux fs] References: <20190328221820.GA67141@cskk.homeip.net> Message-ID: ?s 22:18 de 28/03/19, Cameron Simpson escreveu: > On 28Mar2019 01:12, Paulo da Silva wrote: >> ?s 23:09 de 27/03/19, Cameron Simpson escreveu: ... > > Oh, just tangential to this. > > If you were doing this ad hoc, yes calling the filefrag executable is > very expensive. But if you are always doing a large batch of filenames > invoking: > > ?filefrag lots of filenames here ...> > and reading from its output can be very effective, because the expense > of the executable is amortized over all the files - the per file cost is > much reduced. And it saves you working out how to use the ioctls from > Python :-) That's not the case. I need to do it on some files basis which I don't know in advance. Using IOCTL, I don't need to parse or unpack the output. Only compare the output arrays. Besides I need to store many of the outputs. Doing that from filefrag text output would be unpractical. I needed, at least, to compress the data. Although may be I might have to compress the ioctl arrays ... Let's see how big in average is the storage needed. I have to go with ioctl. I have to open the files anyway, so there is no overhead for that when calling the ioctl. Anyway, thank you for the suggestion. Regards. Paulo From adam.preble at gmail.com Sun Mar 31 11:11:27 2019 From: adam.preble at gmail.com (adam.preble at gmail.com) Date: Sun, 31 Mar 2019 08:11:27 -0700 (PDT) Subject: From parsing a class to code object to class to mappingproxy to object (oh my!) Message-ID: I have been mimicking basic Python object constructs successfully until I started trying to handle methods as well in my hand-written interpreter. At that point, I wasn't sure where to stage all the methods before they get shuffled over to an actual instance of an object. I'm having to slap this out here partially to rubber duck it and partially because I really don't know what's going on. Here's something tangible we can use: >>> def construct(): ... class Meow: ... def __init__(self): ... self.a = 1 ... def change_a(self, new_a): ... self.a = new_a ... return Meow() ... >>> dis(construct) 2 0 LOAD_BUILD_CLASS 2 LOAD_CONST 1 (", line 2>) 4 LOAD_CONST 2 ('Meow') 6 MAKE_FUNCTION 0 8 LOAD_CONST 2 ('Meow') 10 CALL_FUNCTION 2 12 STORE_FAST 0 (Meow) 7 14 LOAD_FAST 0 (Meow) 16 CALL_FUNCTION 0 18 RETURN_VALUE I've wrapped my class in a function so I could more readily poke it with a stick. I understand LOAD_BUILD_CLASS will invoke builtins.__build_class__(). By the way, why the special opcode for that? Anyways, it takes that code object, which looks to be particularly special. Note that I'm inserting some newlines and extra junk for sanity: >>> import ctypes >>> c = ctypes.cast(0x0000021BD59170C0, ctypes.py_object).value >>> c.co_consts ('construct..Meow', ", line 3>, 'construct..Meow.__init__', ", line 5>, 'construct..Meow.change_a', None) >>> c.co_names ('__name__', '__module__', '__qualname__', '__init__', 'change_a') >>> dis(c.co_code) 0 LOAD_NAME 0 (0) -> __name__ ... 2 STORE_NAME 1 (1) -> ... goes into __module__ 4 LOAD_CONST 0 (0) -> Name of the class = 'construct..Meow' ... 6 STORE_NAME 2 (2) -> ... goes into __qualname__ 8 LOAD_CONST 1 (1) -> __init__ code object 10 LOAD_CONST 2 (2) -> The name "__init__" ... 12 MAKE_FUNCTION 0 -> ... Made into a function 14 STORE_NAME 3 (3) -> Stash it 16 LOAD_CONST 3 (3) -> The name "change_a" ... 18 LOAD_CONST 4 (4) -> The __change_a__ code object ... 20 MAKE_FUNCTION 0 -> ... Made into a function 22 STORE_NAME 4 (4) -> Stash it 24 LOAD_CONST 5 (5) -> Returns None 26 RETURN_VALUE I'm not too surprised to see stuff like this since this kind of thing is what I expect to find in flexible languages that do object-oriented programming by basically blessing a variable and heaping stuff on it. It's just that I'm trying to figure out where this goes in the process of language parsing to class declaration to object construction. What I'm assuming is that when builtins.__build_class__() is invoked, it does all the metaclass/subclass chasing first, and then ultimately invokes this code object to populate the class. If I look at the __dict__ for the class afterwards, I see: mappingproxy( {'__module__': '__main__', '__init__': .Meow.__init__ at 0x0000021BD592AAE8>, 'change_a': .Meow.change_a at 0x0000021BD5915F28>, '__dict__': , '__weakref__': , '__doc__': None}) What is the plumbing taking the result of that code object over to this proxy? I'm assuming __build_class__ runs that code object and then starts looking for new names and see to create this. Is this mapping proxy the important thing for carrying the method declaration? Is this also where prepare (and __prepare__) comes into play? Running into that was where I felt the need to start asking questions because I got six layers deep and my brain melted. I'm then assuming that in object construction, this proxy is carried by some reference to the final object in such a way that if the class's fields are modified, all instances would see the modification unless the local object itself was overridden. From alexey.muranov at gmail.com Sun Mar 31 15:08:53 2019 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Sun, 31 Mar 2019 21:08:53 +0200 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: References: Message-ID: <1554059333.3186.0@gmail.com> On dim., Mar 31, 2019 at 6:00 PM, python-list-request at python.org wrote: > On Sat, Mar 30, 2019, 5:32 AM Alexey Muranov > > wrote: > >> >> On ven., Mar 29, 2019 at 4:51 PM, python-list-request at python.org >> wrote: >> > >> > There could perhaps be a special case for lambda expressions such >> > that, >> > when they are directly assigned to a variable, Python would use >> the >> > variable name as the function name. I expect this could be >> > accomplished by >> > a straightforward transformation of the AST, perhaps even by just >> > replacing >> > the assignment with a def statement. >> >> If this will happen, that is, if in Python assigning a >> lambda-defined >> function to a variable will mutate the function's attributes, or >> else, >> if is some "random" syntactically-determined cases >> >> f = ... >> >> will stop being the same as evaluating the right-hand side and >> assigning the result to "f" variable, it will be a fairly good extra >> reason for me to go away from Python. >> > > Is there a particular reason you don't like this? It's not too > different > from the syntactic magic Python already employs to support the > 0-argument > form of super(). I do not want any magic in a programming language i use, especially if it breaks simple rules. I do not like 0-argument `super()` either, but at least I do not have to use it. I am suspicious of `__class__` too. But here only identifiers are hacked, not the assignment operator. (I suppose the hack can be unhacked by using your own meta-class with a custom `__prepare__`.) Neither i like how a function magically turns into a generator if the keyword `yield` appears somewhere within its definition. Those are the things i don't like the most in Python. Alexey. From ian.g.kelly at gmail.com Sun Mar 31 15:45:10 2019 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 31 Mar 2019 13:45:10 -0600 Subject: Syntax for one-line "nonymous" functions in "declaration style" In-Reply-To: <1554059333.3186.0@gmail.com> References: <1554059333.3186.0@gmail.com> Message-ID: On Sun, Mar 31, 2019 at 1:09 PM Alexey Muranov wrote: > > On dim., Mar 31, 2019 at 6:00 PM, python-list-request at python.org wrote: > > On Sat, Mar 30, 2019, 5:32 AM Alexey Muranov > > > > wrote: > > > >> > >> On ven., Mar 29, 2019 at 4:51 PM, python-list-request at python.org > >> wrote: > >> > > >> > There could perhaps be a special case for lambda expressions such > >> > that, > >> > when they are directly assigned to a variable, Python would use > >> the > >> > variable name as the function name. I expect this could be > >> > accomplished by > >> > a straightforward transformation of the AST, perhaps even by just > >> > replacing > >> > the assignment with a def statement. > >> > >> If this will happen, that is, if in Python assigning a > >> lambda-defined > >> function to a variable will mutate the function's attributes, or > >> else, > >> if is some "random" syntactically-determined cases > >> > >> f = ... > >> > >> will stop being the same as evaluating the right-hand side and > >> assigning the result to "f" variable, it will be a fairly good extra > >> reason for me to go away from Python. > >> > > > > Is there a particular reason you don't like this? It's not too > > different > > from the syntactic magic Python already employs to support the > > 0-argument > > form of super(). > > I do not want any magic in a programming language i use, especially if > it breaks simple rules. > > I do not like 0-argument `super()` either, but at least I do not have > to use it. Well, you wouldn't have to use my suggestion either, since it only applies to assignments of the form "f = lambda x: blah". As has already been stated, the preferred way to do this is with a def statement. So just use a def statement for this, and it wouldn't affect you (unless you *really* want the function's name to be "" for some reason). That said, that's also the reason why this probably wouldn't happen. Why go to the trouble of fixing people's lambda assignments for them when the preferred fix would be for them to do it themselves by replacing them with def statements? > Neither i like how a function magically turns into a generator if the > keyword `yield` appears somewhere within its definition. I agree, there should have been a required syntactic element on the "def" line as well to signal it immediately to the reader. It won't stop me from using them, though. From contact at fastfatchef.com Sun Mar 31 04:55:32 2019 From: contact at fastfatchef.com (Shane) Date: Sun, 31 Mar 2019 01:55:32 -0700 (PDT) Subject: Python Remote Work Message-ID: Hi, Bit of a long shot! I am looking for remote work and like the look of Python. I am an Australian, with a degree in Commercial computing, with 15 years using Delphi in a business environment. I am looking for a company to X train me to Python remotely, or maybe even a remote Python developer with too much work on his/her plate that wants some paid help and is willing to point me in the right direction. cheers Shane