From formisc at gmail.com Wed Nov 1 00:24:27 2017 From: formisc at gmail.com (Andrew Z) Date: Wed, 1 Nov 2017 00:24:27 -0400 Subject: matplot plot hangs In-Reply-To: References: Message-ID: Stefan, I intentionally tried to use the qt backend that i do not have. I wanted to check i the switch was working (or not). All i want at this point is to use (seemed to be default) tkagg. On Oct 31, 2017 20:15, "Stefan Ram" wrote: > Andrew Z writes: > >ImportError: *No module named 'PyQt4'* > > Matplotlib requires a large number of dependencies, > like ?NumPy?, ?dateutil?, ?libpng?, or ?pytz?. > > There are also some capabilities provided by optional > backends which have their own dependencies. > > If one would like to use the ?Qt4Agg? backend, one would > also need to have ?PyQt4? installed. > > Some Python distributions might already contain many > dependencies. > > -- > https://mail.python.org/mailman/listinfo/python-list > From dieter at handshake.de Wed Nov 1 04:21:46 2017 From: dieter at handshake.de (dieter) Date: Wed, 01 Nov 2017 09:21:46 +0100 Subject: right list for SIGABRT python binary question ? References: <20171016203215.vk7eacfnsaa3v64m@hermes.hilbert.loc> <59e5570a$0$14952$b1db1813$d948b532@news.astraweb.com> <20171017073043.piszqyu7dsqo55eu@hermes.hilbert.loc> <20171018114358.fzj4vvsyzrf6rihu@hermes.hilbert.loc> <47a09a35-f929-528f-3110-8d660e6fb46f@tjol.eu> <20171019172745.76i3lltjtck2m5gw@hermes.hilbert.loc> <20171019174907.iqgznoroyieipend@hermes.hilbert.loc> <87y3o5gdn9.fsf@handshake.de> <20171023122312.uupsxzhdwat3stt7@hermes.hilbert.loc> Message-ID: <87lgjq5rz9.fsf@handshake.de> Karsten Hilbert writes: > On Sat, Oct 21, 2017 at 09:31:54AM +0200, dieter wrote: >> It points to a memory corruption. > While running valgrind and friends is beyond my capabilitis I > have run the problem through gdb to at least obtain a stack > trace to see what gives: The i386/x64 architecture supports memory access breakpoints and GDB, too, has support for this. You know the address which gets corrupted. Thus, the following apporach could have a chance to succeed: Put a "memory write" breakpoint on the address which gets corrupted. this should stop the program each time this address is written; Check then the backtrace. As the address forms part of the address block prologue, it should only be accessed from Python's "malloc" (and "free") implementation. Any other access indicates bad behaviour. Should your program get stopped too often (because the memory block is reused too often), you must find a good point in your program to activate the memory access breakpoint in a delayed way. You could use the Python debugger for this: execute significant parts of your program in the Python debugger; switching to GDB, check whether the address is already corrupted - if so, restart and refine the checks above in the portion of your program which caused the corruption. If the part in your program is sufficiently small, you can activate the memory access breakpoint. This approach may also be feasible, should you use a CPU without memory access breakpoints. From dieter at handshake.de Wed Nov 1 04:36:17 2017 From: dieter at handshake.de (dieter) Date: Wed, 01 Nov 2017 09:36:17 +0100 Subject: Objects with __name__ attribute References: <59f033de$0$4836$426a74cc@news.free.fr> Message-ID: <87h8ue5rb2.fsf@handshake.de> "ast" writes: > I know two Python's objects which have an intrinsic name, classes and > functions. > ... > Are there others objects with a __name__ attribute > and what is it used for ? Some Python objects naturally have a name: functions, classes, modules, ...; others don't: tuples, lists, integers, ... If a Python object natureally has a name, there is a good chance that it is accessible in a standard way: "obj.__name__". Sometimes, the name is a bit special. An example is the "filename" (potentially) associated with a "file" like object. In those cases, the name can be accessed in a slightly different way, e.g. "file.filename". I recommend that you do not try to enumerate all cases where an object has a name accessible via "obj.__name__". Instead, start with your concrete task. Select the objects appropriate for your task. Use the "buildin" functions "dir" and "help" on a sample object to find out (in an interactive Python sesssion) which attributes and methods it supports. If this does not give enough information, consult the documentation. From dieter at handshake.de Wed Nov 1 04:42:58 2017 From: dieter at handshake.de (dieter) Date: Wed, 01 Nov 2017 09:42:58 +0100 Subject: Let's talk about debuggers! References: <27f3e171-c9ca-2d08-2dd6-bce45d2967fa@tjol.eu> Message-ID: <87d1525qzx.fsf@handshake.de> Thomas Jollans writes: > I just wanted to know what tools everyone used for debugging Python > applications - scripts / backend / desktop apps / notebooks / whatever. > Apart from the usual dance with log files and strategically inserted > print() calls, that is. > > Of course we all know and mildly dislike pdb. I mostly develop backend components for internet applications based on the web application framework "Zope". There, the extension "Products.PDBDebugMode" is highly helpfull: it enters the Python debugger ("pdb"), whenever an uncatched exception is raised or an error is logged; "pdb" can then be used to examine the state and check what caused the problem. From storchaka at gmail.com Wed Nov 1 05:09:53 2017 From: storchaka at gmail.com (Serhiy Storchaka) Date: Wed, 1 Nov 2017 11:09:53 +0200 Subject: Performance of map vs starmap. In-Reply-To: References: Message-ID: 30.10.17 12:10, Kirill Balunov ????: > Sometime ago I asked this question at SO [1], and among the responses > received was paragraph: > > - `zip` re-uses the returned `tuple` if it has a reference count of 1 when > the `__next__` call is made. > - `map` build a new `tuple` that is passed to the mapped function every > time a `__next__` call is made. > > Why can not `map` use the same approach as `zip`? > > Also it turns out that a faster solution looks not reasonable, since it > requires additional calculations.. > > [1] https://stackoverflow.com/questions/46172018/perfomance- > of-map-vs-starmap Sometime ago I had wrote a sample patch for using cached arg tuples in map() and several other functions [1]. It increased the speed in microbenchmarks up to 24-38%. But the code was too complex and fragile, I didn't want to commit it. Later, after numerous of attempts, this resulted in implementing by Victor Stinner the new private "fastcall" calling method which allowed to avoid creation a new tuple (and a dict for keyword arguments) in many cases. It was added just before releasing of 3.6 and was used in few places. In 3.7 it was optimized further. Now map() is faster than starmap()+zip(). Python 3.6: $ ./python -m timeit -s 'from operator import eq; from itertools import starmap; seq1 = [1]*10000; seq2 = [1]*10000' 'list(map(eq, seq1, seq2))' 1000 loops, best of 3: 559 usec per loop $ ./python -m timeit -s 'from operator import eq; from itertools import starmap; seq1 = [1]*10000; seq2 = [1]*10000' 'list(starmap(eq, zip(seq1, seq2)))' 1000 loops, best of 3: 399 usec per loop Python 3.7: $ ./python -m timeit -s 'from operator import eq; from itertools import starmap; seq1 = [1]*10000; seq2 = [1]*10000' 'list(map(eq, seq1, seq2))' 1000 loops, best of 5: 338 usec per loop $ ./python -m timeit -s 'from operator import eq; from itertools import starmap; seq1 = [1]*10000; seq2 = [1]*10000' 'list(starmap(eq, zip(seq1, seq2)))' 1000 loops, best of 5: 359 usec per loop [1] https://bugs.python.org/issue23507 From Karsten.Hilbert at gmx.net Wed Nov 1 05:27:54 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Wed, 1 Nov 2017 10:27:54 +0100 Subject: right list for SIGABRT python binary question ? In-Reply-To: <87lgjq5rz9.fsf@handshake.de> References: <59e5570a$0$14952$b1db1813$d948b532@news.astraweb.com> <20171017073043.piszqyu7dsqo55eu@hermes.hilbert.loc> <20171018114358.fzj4vvsyzrf6rihu@hermes.hilbert.loc> <47a09a35-f929-528f-3110-8d660e6fb46f@tjol.eu> <20171019172745.76i3lltjtck2m5gw@hermes.hilbert.loc> <20171019174907.iqgznoroyieipend@hermes.hilbert.loc> <87y3o5gdn9.fsf@handshake.de> <20171023122312.uupsxzhdwat3stt7@hermes.hilbert.loc> <87lgjq5rz9.fsf@handshake.de> Message-ID: <20171101092753.tfcvckzaezunxnej@hermes.hilbert.loc> On Wed, Nov 01, 2017 at 09:21:46AM +0100, dieter wrote: > >> It points to a memory corruption. > > The i386/x64 architecture supports memory access breakpoints > and GDB, too, has support for this. You know the address which > gets corrupted. Thus, the following apporach could have a chance > to succeed: > > Put a "memory write" breakpoint on the address which gets corrupted. > this should stop the program each time this address is written; > Check then the backtrace. As the address forms part of the > address block prologue, it should only be accessed from > Python's "malloc" (and "free") implementation. Any other access > indicates bad behaviour. I understand. Thank you for the explanation. This may seem like a dumb question: the actual address that gets corrupted varies from run to run (it may be the same "place" in the code but that place gets put at a different address each run). Since I don't know the address of a given run, how do I set a break point on that address ? It seems to me I first need to map the "place" to its address before the SIGABRT happens. How do I find out out which "place" needs to be mapped from the output I already have ? (the "place" is the memory block you refer to) Other than that I understand what you are getting at and am willing to try. Thanks, Karsten > Should your program get stopped too often (because the memory > block is reused too often), you must find a good point in your > program to activate the memory access breakpoint in a delayed way. > You could use the Python debugger for this: execute significant > parts of your program in the Python debugger; switching to > GDB, check whether the address is already corrupted - if > so, restart and refine the checks above in the portion of your program > which caused the corruption. If the part in your program > is sufficiently small, you can activate the memory access breakpoint. > This approach may also be feasible, should you use a CPU > without memory access breakpoints. -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 From wolfgang.maier at biologie.uni-freiburg.de Wed Nov 1 05:43:42 2017 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 1 Nov 2017 10:43:42 +0100 Subject: matplot plot hangs In-Reply-To: References: Message-ID: On 01.11.2017 00:40, Andrew Z wrote: > hello, > learning python's plotting by using matplotlib with python35 on fedora 24 > x86. > > Installed matplotlib into user's directory. > tk, seemed to work - > http://www.tkdocs.com/tutorial/install.html#installlinux - the window shows > up just fine. > but when trying to run the simple plot ( > https://matplotlib.org/examples/pylab_examples/simple_plot.html) the script > is hanging on; > > plt.plot(t, s) > > attempts to > matplotlib.interactive(True) didn't bring anything, > Hi Andrew, From which environment are you trying to run the example? In the terminal, from within some IDE, inside a jupyter notebook? Are you sure the script "is hanging on plt.plot(t, s)" and not after that? Best, Wolfgang From Karsten.Hilbert at gmx.net Wed Nov 1 06:14:08 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Wed, 1 Nov 2017 11:14:08 +0100 Subject: right list for SIGABRT python binary question ? In-Reply-To: <20171101092753.tfcvckzaezunxnej@hermes.hilbert.loc> References: <59e5570a$0$14952$b1db1813$d948b532@news.astraweb.com> <20171017073043.piszqyu7dsqo55eu@hermes.hilbert.loc> <20171018114358.fzj4vvsyzrf6rihu@hermes.hilbert.loc> <47a09a35-f929-528f-3110-8d660e6fb46f@tjol.eu> <20171019172745.76i3lltjtck2m5gw@hermes.hilbert.loc> <20171019174907.iqgznoroyieipend@hermes.hilbert.loc> <87y3o5gdn9.fsf@handshake.de> <20171023122312.uupsxzhdwat3stt7@hermes.hilbert.loc> <87lgjq5rz9.fsf@handshake.de> <20171101092753.tfcvckzaezunxnej@hermes.hilbert.loc> Message-ID: <20171101101407.5dfugcvqbqaozyyp@hermes.hilbert.loc> On Wed, Nov 01, 2017 at 10:27:54AM +0100, Karsten Hilbert wrote: > > >> It points to a memory corruption. > > > > The i386/x64 architecture supports memory access breakpoints > > and GDB, too, has support for this. You know the address which > > gets corrupted. Thus, the following apporach could have a chance > > to succeed: > > > > Put a "memory write" breakpoint on the address which gets corrupted. > > this should stop the program each time this address is written; > > Check then the backtrace. As the address forms part of the > > address block prologue, it should only be accessed from > > Python's "malloc" (and "free") implementation. Any other access > > indicates bad behaviour. > > I understand. Thank you for the explanation. This may seem > like a dumb question: the actual address that gets corrupted > varies from run to run (it may be the same "place" in the > code but that place gets put at a different address each > run). Since I don't know the address of a given run, how do I > set a break point on that address ? It seems to me I first > need to map the "place" to its address before the SIGABRT > happens. How do I find out out which "place" needs to be > mapped from the output I already have ? Or rather: I need to find out which "place" a given address refers to, check whether the changing addresses always belong to the same "place" between runs and _then_ map a "place" to its address and breakpoint that address on yet another run. It might seem gdb> info symbol should give me the "place". Then gdb> info address on another run. Or even just "watch References: <20171017073043.piszqyu7dsqo55eu@hermes.hilbert.loc> <20171018114358.fzj4vvsyzrf6rihu@hermes.hilbert.loc> <47a09a35-f929-528f-3110-8d660e6fb46f@tjol.eu> <20171019172745.76i3lltjtck2m5gw@hermes.hilbert.loc> <20171019174907.iqgznoroyieipend@hermes.hilbert.loc> <87y3o5gdn9.fsf@handshake.de> <20171023122312.uupsxzhdwat3stt7@hermes.hilbert.loc> <87lgjq5rz9.fsf@handshake.de> <20171101092753.tfcvckzaezunxnej@hermes.hilbert.loc> <20171101101407.5dfugcvqbqaozyyp@hermes.hilbert.loc> Message-ID: <20171101104507.sbvdjfymtjeiafwn@hermes.hilbert.loc> On Wed, Nov 01, 2017 at 11:14:08AM +0100, Karsten Hilbert wrote: > Or rather: I need to find out which "place" a given address > refers to, check whether the changing addresses always belong > to the same "place" between runs and _then_ map a "place" to > its address and breakpoint that address on yet another run. > > It might seem > > gdb> info symbol > > should give me the "place". Given this: Debug memory block at address p=0x6aab7c: API '' 0 bytes originally requested The 3 pad bytes at p-3 are not all FORBIDDENBYTE (0xfb): at p-3: 0x33 *** OUCH at p-2: 0x47 *** OUCH at p-1: 0x00 *** OUCH Because memory is corrupted at the start, the count of bytes requested may be bogus, and checking the trailing pad bytes may segfault. The 4 pad bytes at tail=0x6aab7c are not all FORBIDDENBYTE (0xfb): at tail+0: 0x00 *** OUCH at tail+1: 0x00 *** OUCH at tail+2: 0x00 *** OUCH at tail+3: 0x00 *** OUCH The block was made by call #0 to debug malloc/realloc. Fatal Python error: bad ID: Allocated using API '', verified using API 'o' Program received signal SIGABRT, Aborted. 0xb7fd9ce9 in __kernel_vsyscall () (gdb) info symbol 0x6aab7c _Py_ZeroStruct in section .data of /usr/bin/python2.7-dbg (gdb) my assumption would be that something clobbers 0x6aab7c, which seems to be in (?) _Py_ZeroStruct in this run. I'll re-run a few times to make sure the corruption "reliably" hits _Py_ZeroStruct. If so, I'll set a memory write breakpoint on _Py_ZeroStruct. Am I on the right track ? Thanks, Karsten BTW, the backtrace for this run was ... (gdb) bt #0 0xb7fd9ce9 in __kernel_vsyscall () #1 0xb7d70dd0 in __libc_signal_restore_set (set=0xbfffee90) at ../sysdeps/unix/sysv/linux/nptl-signals.h:79 #2 __GI_raise (sig=6) at ../sysdeps/unix/sysv/linux/raise.c:48 #3 0xb7d72297 in __GI_abort () at abort.c:89 #4 0x0055fb74 in Py_FatalError (msg=0xbffff13c "bad ID: Allocated using API '\037', verified using API 'o'") at ../Python/pythonrun.c:1700 #5 0x00499adb in _PyObject_DebugCheckAddressApi (api=111 'o', p=0x6aab7c <_Py_ZeroStruct>) at ../Objects/obmalloc.c:1640 #6 0x004997a5 in _PyObject_DebugFreeApi (api=111 'o', p=0x6aab7c <_Py_ZeroStruct>) at ../Objects/obmalloc.c:1527 #7 0x0049964f in _PyObject_DebugFree (p=0x6aab7c <_Py_ZeroStruct>) at ../Objects/obmalloc.c:1471 #8 0x00471043 in int_dealloc (v=0x6aab7c <_Py_ZeroStruct>) at ../Objects/intobject.c:139 ... so I could've known without "info symbol" :-) #9 0x00497bee in _Py_Dealloc (op=False) at ../Objects/object.c:2262 #10 0x004885d7 in insertdict_by_entry (mp=0xb7fc5674, key='dont_write_bytecode', hash=591857026, ep=0x7c5c08, value=None) at ../Objects/dictobject.c:519 #11 0x00488857 in insertdict (mp=0xb7fc5674, key='dont_write_bytecode', hash=591857026, value=None) at ../Objects/dictobject.c:556 #12 0x0048910f in dict_set_item_by_hash_or_entry ( op={ 'setrecursionlimit': None, 'dont_write_bytecode': None, 'getfilesystemencoding': , 'long_info': , 'path_importer_cache': None, 'stdout': , 'getprofile': , '__stdin__': , 'version_info': , 'exc_clear': , 'gettotalrefcount': , 'getrefcount': , 'byteorder': 'little', '_clear_type_cache': None, 'excepthook': , 'subversion': ('CPython', '', ''), '_multiarch': None, 'exc_type': None, 'ps1': None, '__excepthook__': , 'executable': '/usr/bin/python2.7-dbg', 'float_info': None, 'copyright': 'Copyright (c) 2001-2017 Python Software Foundation.\nAll Rights Reserved.\n\nCopyright (c) 2000 BeOpen.com.\nAll Rights Reserved.\n\nCopyright (c) 1995-2001 Corporation for Nation...(truncated), key='dont_write_bytecode', hash=591857026, ep=0x0, value=None ) at ../Objects/dictobject.c:795 #13 0x00489285 in PyDict_SetItem ( op={'setrecursionlimit': None, 'dont_write_bytecode': None, 'getfilesystemencoding': , 'long_info': , 'path_importer_cache': None, 'stdout': , 'getprofile': , '__stdin__': , 'version_info': , 'exc_clear': , 'gettotalrefcount': , 'getrefcount': , 'byteorder': 'little', '_clear_type_cache': None, 'excepthook': , 'subversion': ('CPython', '', ''), '_multiarch': None, 'exc_type': None, 'ps1': None, '__excepthook__': , 'executable': '/usr/bin/python2.7-dbg', 'float_info': None, 'copyright': 'Copyright (c) 2001-2017 Python Software Foundation.\nAll Rights Reserved.\n\nCopyright (c) 2000 BeOpen.com.\nAll Rights Reserved.\n\nCopyright (c) 1995-2001 Corporation for Nation...(truncated), key='dont_write_bytecode', value=None) at ../Objects/dictobject.c:848 #14 0x0049281f in _PyModule_Clear (m=) at ../Objects/moduleobject.c:139 #15 0x0054a3ec in PyImport_Cleanup () at ../Python/import.c:540 #16 0x0055c53c in Py_Finalize () at ../Python/pythonrun.c:458 #17 0x0055fe9c in Py_Exit (sts=1) at ../Python/pythonrun.c:1783 #18 0x0055e0fc in handle_system_exit () at ../Python/pythonrun.c:1151 #19 0x0055e152 in PyErr_PrintEx (set_sys_last_vars=1) at ../Python/pythonrun.c:1161 #20 0x0055dd5b in PyErr_Print () at ../Python/pythonrun.c:1064 #21 0x0055d61f in PyRun_SimpleFileExFlags (fp=0x7ee010, filename=0xbffff7e6 "./bootstrap_gm_db_system.py", closeit=1, flags=0xbffff4f4) at ../Python/pythonrun.c:952 #22 0x0055cc4e in PyRun_AnyFileExFlags (fp=0x7ee010, filename=0xbffff7e6 "./bootstrap_gm_db_system.py", closeit=1, flags=0xbffff4f4) at ../Python/pythonrun.c:752 #23 0x00577cb0 in Py_Main (argc=5, argv=0xbffff684) at ../Modules/main.c:645 #24 0x004259c8 in main (argc=5, argv=0xbffff684) at ../Modules/python.c:20 -- From Karsten.Hilbert at gmx.net Wed Nov 1 07:40:56 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Wed, 1 Nov 2017 12:40:56 +0100 Subject: right list for SIGABRT python binary question ? In-Reply-To: <20171101104507.sbvdjfymtjeiafwn@hermes.hilbert.loc> References: <20171018114358.fzj4vvsyzrf6rihu@hermes.hilbert.loc> <47a09a35-f929-528f-3110-8d660e6fb46f@tjol.eu> <20171019172745.76i3lltjtck2m5gw@hermes.hilbert.loc> <20171019174907.iqgznoroyieipend@hermes.hilbert.loc> <87y3o5gdn9.fsf@handshake.de> <20171023122312.uupsxzhdwat3stt7@hermes.hilbert.loc> <87lgjq5rz9.fsf@handshake.de> <20171101092753.tfcvckzaezunxnej@hermes.hilbert.loc> <20171101101407.5dfugcvqbqaozyyp@hermes.hilbert.loc> <20171101104507.sbvdjfymtjeiafwn@hermes.hilbert.loc> Message-ID: <20171101114056.ik24kwurm7cebnva@hermes.hilbert.loc> > my assumption would be that something clobbers 0x6aab7c, > which seems to be in (?) _Py_ZeroStruct in this run. I'll > re-run a few times to make sure the corruption "reliably" > hits _Py_ZeroStruct. > > If so, I'll set a memory write breakpoint on _Py_ZeroStruct. Interestingly, on subsequent runs, it seems to hit the same address, 0x6aab7c, belonging to the same symbol, _Py_ZeroStruct. This is what happens: (gdb) watch *0x6aab7c Hardware watchpoint 1: *0x6aab7c (gdb) run Starting program: /usr/bin/python2.7-dbg ./bootstrap_gm_db_system.py --log-file=./bootstrap-latest.log --conf-file=bootstrap-latest.conf -- [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1". Hardware watchpoint 1: *0x6aab7c Old value = 0 New value = -1208182272 _Py_AddToAllObjects (op=False, force=0) at ../Objects/object.c:70 70 ../Objects/object.c: Datei oder Verzeichnis nicht gefunden. (gdb) which means I'll probably have to apply the delayed breakpoint setting strategy, or else it is just some initial relocation at startup. Let's see what "cont" brings. The next hit after the Python script has run until just before it usually aborts: Hardware watchpoint 1: *0x6aab7c Old value = -1208182272 New value = 0 _Py_ForgetReference (op=False) at ../Objects/object.c:2255 2255 in ../Objects/object.c (gdb) The backtrace at this point says: (gdb) bt #0 _Py_ForgetReference (op=False) at ../Objects/object.c:2255 #1 0x00497be0 in _Py_Dealloc (op=False) at ../Objects/object.c:2261 #2 0x004885d7 in insertdict_by_entry (mp=0xb7fc5674, key='dont_write_bytecode', hash=591857026, ep=0x7c5c08, value=None) at ../Objects/dictobject.c:519 #3 0x00488857 in insertdict (mp=0xb7fc5674, key='dont_write_bytecode', hash=591857026, value=None) at ../Objects/dictobject.c:556 #4 0x0048910f in dict_set_item_by_hash_or_entry ( op={'setrecursionlimit': None, 'dont_write_bytecode': None, 'getfilesystemencoding': , 'long_info': , 'path_importer_cache': None, 'stdout': , 'getprofile': , '__stdin__': , 'version_info': , 'exc_clear': , 'gettotalrefcount': , 'getrefcount': , 'byteorder': 'little', '_clear_type_cache': None, 'excepthook': , 'subversion': ('CPython', '', ''), '_multiarch': None, 'exc_type': None, 'ps1': None, '__excepthook__': , 'executable': '/usr/bin/python2.7-dbg', 'float_info': None, 'copyright': 'Copyright (c) 2001-2017 Python Software Foundation.\nAll Rights Reserved.\n\nCopyright (c) 2000 BeOpen.com.\nAll Rights Reserved.\n\nCopyright (c) 1995-2001 Corporation for Nation...(truncated), key='dont_write_bytecode', hash=591857026, ep=0x0, value=None) at ../Objects/dictobject.c:795 #5 0x00489285 in PyDict_SetItem ( op={'setrecursionlimit': None, 'dont_write_bytecode': None, 'getfilesystemencoding': , 'long_info': , 'path_importer_cache': None, 'stdout': , 'getprofile': , '__stdin__': , 'version_info': , 'exc_clear': , 'gettotalrefcount': , 'getrefcount': , 'byteorder': 'little', '_clear_type_cache': None, 'excepthook': , 'subversion': ('CPython', '', ''), '_multiarch': None, 'exc_type': None, 'ps1': None, '__excepthook__': , 'executable': '/usr/bin/python2.7-dbg', 'float_info': None, 'copyright': 'Copyright (c) 2001-2017 Python Software Foundation.\nAll Rights Reserved.\n\nCopyright (c) 2000 BeOpen.com.\nAll Rights Reserved.\n\nCopyright (c) 1995-2001 Corporation for Nation...(truncated), key='dont_write_bytecode', value=None) at ../Objects/dictobject.c:848 #6 0x0049281f in _PyModule_Clear (m=) at ../Objects/moduleobject.c:139 #7 0x0054a3ec in PyImport_Cleanup () at ../Python/import.c:540 #8 0x0055c53c in Py_Finalize () at ../Python/pythonrun.c:458 #9 0x0055fe9c in Py_Exit (sts=1) at ../Python/pythonrun.c:1783 #10 0x0055e0fc in handle_system_exit () at ../Python/pythonrun.c:1151 #11 0x0055e152 in PyErr_PrintEx (set_sys_last_vars=1) at ../Python/pythonrun.c:1161 #12 0x0055dd5b in PyErr_Print () at ../Python/pythonrun.c:1064 #13 0x0055d61f in PyRun_SimpleFileExFlags (fp=0x7ee010, filename=0xbffff7e6 "./bootstrap_gm_db_system.py", closeit=1, flags=0xbffff4f4) at ../Python/pythonrun.c:952 #14 0x0055cc4e in PyRun_AnyFileExFlags (fp=0x7ee010, filename=0xbffff7e6 "./bootstrap_gm_db_system.py", closeit=1, flags=0xbffff4f4) at ../Python/pythonrun.c:752 #15 0x00577cb0 in Py_Main (argc=5, argv=0xbffff684) at ../Modules/main.c:645 #16 0x004259c8 in main (argc=5, argv=0xbffff684) at ../Modules/python.c:20 And continuing hits the SIGABRT right away: (gdb) cont Continuing. Debug memory block at address p=0x6aab7c: API '' 0 bytes originally requested The 3 pad bytes at p-3 are not all FORBIDDENBYTE (0xfb): at p-3: 0x33 *** OUCH at p-2: 0x47 *** OUCH at p-1: 0x00 *** OUCH Because memory is corrupted at the start, the count of bytes requested may be bogus, and checking the trailing pad bytes may segfault. The 4 pad bytes at tail=0x6aab7c are not all FORBIDDENBYTE (0xfb): at tail+0: 0x00 *** OUCH at tail+1: 0x00 *** OUCH at tail+2: 0x00 *** OUCH at tail+3: 0x00 *** OUCH The block was made by call #0 to debug malloc/realloc. Fatal Python error: bad ID: Allocated using API '', verified using API 'o' Program received signal SIGABRT, Aborted. 0xb7fd9ce9 in __kernel_vsyscall () (gdb) Does that help ? Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 From Karsten.Hilbert at gmx.net Wed Nov 1 07:43:56 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Wed, 1 Nov 2017 12:43:56 +0100 Subject: right list for SIGABRT python binary question ? In-Reply-To: <20171101114056.ik24kwurm7cebnva@hermes.hilbert.loc> References: <47a09a35-f929-528f-3110-8d660e6fb46f@tjol.eu> <20171019172745.76i3lltjtck2m5gw@hermes.hilbert.loc> <20171019174907.iqgznoroyieipend@hermes.hilbert.loc> <87y3o5gdn9.fsf@handshake.de> <20171023122312.uupsxzhdwat3stt7@hermes.hilbert.loc> <87lgjq5rz9.fsf@handshake.de> <20171101092753.tfcvckzaezunxnej@hermes.hilbert.loc> <20171101101407.5dfugcvqbqaozyyp@hermes.hilbert.loc> <20171101104507.sbvdjfymtjeiafwn@hermes.hilbert.loc> <20171101114056.ik24kwurm7cebnva@hermes.hilbert.loc> Message-ID: <20171101114356.6e6pg74qph5e444u@hermes.hilbert.loc> On Wed, Nov 01, 2017 at 12:40:56PM +0100, Karsten Hilbert wrote: > Interestingly, on subsequent runs, it seems to hit the same > address, 0x6aab7c, belonging to the same symbol, _Py_ZeroStruct. > > This is what happens: > > (gdb) watch *0x6aab7c > Hardware watchpoint 1: *0x6aab7c > (gdb) run > Starting program: /usr/bin/python2.7-dbg ./bootstrap_gm_db_system.py --log-file=./bootstrap-latest.log --conf-file=bootstrap-latest.conf -- > [Thread debugging using libthread_db enabled] > Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1". > > Hardware watchpoint 1: *0x6aab7c > > Old value = 0 > New value = -1208182272 > _Py_AddToAllObjects (op=False, force=0) at ../Objects/object.c:70 > 70 ../Objects/object.c: Datei oder Verzeichnis nicht gefunden. > (gdb) I forgot the backtrace from this point: (gdb) bt #0 _Py_AddToAllObjects (op=False, force=0) at ../Objects/object.c:70 #1 0x0051e052 in _PyBuiltin_Init () at ../Python/bltinmodule.c:2708 #2 0x0055bebf in Py_InitializeEx (install_sigs=1) at ../Python/pythonrun.c:233 #3 0x0055c4dd in Py_Initialize () at ../Python/pythonrun.c:381 #4 0x00577805 in Py_Main (argc=5, argv=0xbffff684) at ../Modules/main.c:551 #5 0x004259c8 in main (argc=5, argv=0xbffff684) at ../Modules/python.c:20 Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 From ned at nedbatchelder.com Wed Nov 1 08:33:55 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 1 Nov 2017 08:33:55 -0400 Subject: The syntax of replacement fields in format strings In-Reply-To: References: Message-ID: <2b58ceb7-af22-2391-515f-2753f3a768df@nedbatchelder.com> On 10/31/17 12:45 PM, John Smith wrote: > If we keep the current implementation as is, perhaps the documentation > should at least be altered ? John, it looks like you are responding to a Python-Dev message, but on this list, somehow... --Ned. From formisc at gmail.com Wed Nov 1 08:49:25 2017 From: formisc at gmail.com (Andrew Z) Date: Wed, 1 Nov 2017 08:49:25 -0400 Subject: matplot plot hangs In-Reply-To: References: Message-ID: Wolfgang, I tried to ran from ide with no rwsults, so now im trying from a terminal in xwindow. The .plot is the last line in the script and it does hang trying to execute it. On Nov 1, 2017 05:44, "Wolfgang Maier" < wolfgang.maier at biologie.uni-freiburg.de> wrote: On 01.11.2017 00:40, Andrew Z wrote: > hello, > learning python's plotting by using matplotlib with python35 on fedora 24 > x86. > > Installed matplotlib into user's directory. > tk, seemed to work - > http://www.tkdocs.com/tutorial/install.html#installlinux - the window > shows > up just fine. > but when trying to run the simple plot ( > https://matplotlib.org/examples/pylab_examples/simple_plot.html) the > script > is hanging on; > > plt.plot(t, s) > > attempts to > matplotlib.interactive(True) didn't bring anything, > > Hi Andrew, >From which environment are you trying to run the example? In the terminal, from within some IDE, inside a jupyter notebook? Are you sure the script "is hanging on plt.plot(t, s)" and not after that? Best, Wolfgang -- https://mail.python.org/mailman/listinfo/python-list From vlastimil.brom at gmail.com Wed Nov 1 09:31:05 2017 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 1 Nov 2017 14:31:05 +0100 Subject: matplot plot hangs In-Reply-To: References: Message-ID: 2017-11-01 13:49 GMT+01:00 Andrew Z : > Wolfgang, > I tried to ran from ide with no rwsults, so now im trying from a terminal > in xwindow. > The .plot is the last line in the script and it does hang trying to execute > it. > > > On Nov 1, 2017 05:44, "Wolfgang Maier" < > wolfgang.maier at biologie.uni-freiburg.de> wrote: > > On 01.11.2017 00:40, Andrew Z wrote: > >> hello, >> learning python's plotting by using matplotlib with python35 on fedora 24 >> x86. >> >> Installed matplotlib into user's directory. >> tk, seemed to work - >> http://www.tkdocs.com/tutorial/install.html#installlinux - the window >> shows >> up just fine. >> but when trying to run the simple plot ( >> https://matplotlib.org/examples/pylab_examples/simple_plot.html) the >> script >> is hanging on; >> >> plt.plot(t, s) >> >> attempts to >> matplotlib.interactive(True) didn't bring anything, >> >> > Hi Andrew, > > From which environment are you trying to run the example? In the terminal, > from within some IDE, inside a jupyter notebook? > > Are you sure the script "is hanging on plt.plot(t, s)" and not after that? > > Best, > Wolfgang > > -- Hi, sorry if it is too trivial, just to make sure, do you have a call to "show()" the resulting plot in the code? An elementary plotting code might be e.g.: import matplotlib.pyplot as plt plt.plot([1,2,4,1]) plt.show() Does this work in your environment? It was not quite clear, what do you plan with interactive drawing, or whether you are using e.g. plt.interactive(True) already - this might be a problem as there could be collisions or the plot window is closed after the standalone script finishes. hth, vbr From Karsten.Hilbert at gmx.net Wed Nov 1 12:06:34 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Wed, 1 Nov 2017 17:06:34 +0100 Subject: right list for SIGABRT python binary question ? In-Reply-To: References: <20171017073043.piszqyu7dsqo55eu@hermes.hilbert.loc> <20171018114358.fzj4vvsyzrf6rihu@hermes.hilbert.loc> <47a09a35-f929-528f-3110-8d660e6fb46f@tjol.eu> <20171019172745.76i3lltjtck2m5gw@hermes.hilbert.loc> <20171019174907.iqgznoroyieipend@hermes.hilbert.loc> <87y3o5gdn9.fsf@handshake.de> <20171023122312.uupsxzhdwat3stt7@hermes.hilbert.loc> <87lgjq5rz9.fsf@handshake.de> <20171101092753.tfcvckzaezunxnej@hermes.hilbert.loc> Message-ID: <20171101160633.3d4bkt5uro4uni7x@hermes.hilbert.loc> On Wed, Nov 01, 2017 at 11:58:53AM -0400, Dennis Lee Bieber wrote: > >I understand. Thank you for the explanation. This may seem > >like a dumb question: the actual address that gets corrupted > >varies from run to run (it may be the same "place" in the > > Since the process virtual memory space should be the same on each run > -- even heap allocations should be deterministic, UNLESS the program is > doing things with external non-deterministic data (the time of day, random > numbers not initialized with a repeatable seed, dynamic web pages, multiple > threads that are non-deterministic due to I/O delays, etc.), Mine doesn't to my knowledge hence I can expect "fixed" addresses -- which is confirmed by what I found during consecutive runs. Thanks for the affirmative explanation. > the only other source for varying addresses would be > OS-level shared libraries that are getting mapped at > different locations due to changes in the order of other > programs running. IOW I should take care I haven't run any relevant amount of Python code before debugging this problem, it seems ? > The physical memory may vary due to paging fragmentation, > but should still be the same virtual addresses. I see. Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 From grant.b.edwards at gmail.com Wed Nov 1 12:28:02 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 1 Nov 2017 16:28:02 +0000 (UTC) Subject: right list for SIGABRT python binary question ? References: <59e5570a$0$14952$b1db1813$d948b532@news.astraweb.com> <20171017073043.piszqyu7dsqo55eu@hermes.hilbert.loc> <20171018114358.fzj4vvsyzrf6rihu@hermes.hilbert.loc> <47a09a35-f929-528f-3110-8d660e6fb46f@tjol.eu> <20171019172745.76i3lltjtck2m5gw@hermes.hilbert.loc> <20171019174907.iqgznoroyieipend@hermes.hilbert.loc> <87y3o5gdn9.fsf@handshake.de> <20171023122312.uupsxzhdwat3stt7@hermes.hilbert.loc> <87lgjq5rz9.fsf@handshake.de> <20171101092753.tfcvckzaezunxnej@hermes.hilbert.loc> Message-ID: On 2017-11-01, Dennis Lee Bieber wrote: > On Wed, 1 Nov 2017 10:27:54 +0100, Karsten Hilbert > declaimed the following: > > >> >>I understand. Thank you for the explanation. This may seem >>like a dumb question: the actual address that gets corrupted >>varies from run to run (it may be the same "place" in the > > Since the process virtual memory space should be the same on each run Not with modern OS kernels: https://en.wikipedia.org/wiki/Address_space_layout_randomization -- Grant Edwards grant.b.edwards Yow! ... My pants just went at on a wild rampage through a gmail.com Long Island Bowling Alley!! From israel at ravnalaska.net Wed Nov 1 13:04:58 2017 From: israel at ravnalaska.net (Israel Brewster) Date: Wed, 1 Nov 2017 09:04:58 -0800 Subject: Thread safety issue (I think) with defaultdict In-Reply-To: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> Message-ID: <27A7DA1E-E6D6-44A5-B181-A2366B0B12FC@ravnalaska.net> Let me rephrase the question, see if I can simplify it. I need to be able to access a defaultdict from two different threads - one thread that responds to user requests which will populate the dictionary in response to a user request, and a second thread that will keep the dictionary updated as new data comes in. The value of the dictionary will be a timestamp, with the default value being datetime.min, provided by a lambda: lambda: datetime.min At the moment my code is behaving as though each thread has a *separate* defaultdict, even though debugging shows the same addresses - the background update thread never sees the data populated into the defaultdict by the main thread. I was thinking race conditions or the like might make it so one particular loop of the background thread occurs before the main thread, but even so subsequent loops should pick up on the changes made by the main thread. How can I *properly* share a dictionary like object between two threads, with both threads seeing the updates made by the other? ----------------------------------------------- Israel Brewster Systems Analyst II Ravn Alaska 5245 Airport Industrial Rd Fairbanks, AK 99709 (907) 450-7293 ----------------------------------------------- > On Oct 31, 2017, at 9:38 AM, Israel Brewster wrote: > > A question that has arisen before (for example, here: https://mail.python.org/pipermail/python-list/2010-January/565497.html ) is the question of "is defaultdict thread safe", with the answer generally being a conditional "yes", with the condition being what is used as the default value: apparently default values of python types, such as list, are thread safe, whereas more complicated constructs, such as lambdas, make it not thread safe. In my situation, I'm using a lambda, specifically: > > lambda: datetime.min > > So presumably *not* thread safe. > > My goal is to have a dictionary of aircraft and when they were last "seen", with datetime.min being effectively "never". When a data point comes in for a given aircraft, the data point will be compared with the value in the defaultdict for that aircraft, and if the timestamp on that data point is newer than what is in the defaultdict, the defaultdict will get updated with the value from the datapoint (not necessarily current timestamp, but rather the value from the datapoint). Note that data points do not necessarily arrive in chronological order (for various reasons not applicable here, it's just the way it is), thus the need for the comparison. > > When the program first starts up, two things happen: > > 1) a thread is started that watches for incoming data points and updates the dictionary as per above, and > 2) the dictionary should get an initial population (in the main thread) from hard storage. > > The behavior I'm seeing, however, is that when step 2 happens (which generally happens before the thread gets any updates), the dictionary gets populated with 56 entries, as expected. However, none of those entries are visible when the thread runs. It's as though the thread is getting a separate copy of the dictionary, although debugging says that is not the case - printing the variable from each location shows the same address for the object. > > So my questions are: > > 1) Is this what it means to NOT be thread safe? I was thinking of race conditions where individual values may get updated wrong, but this apparently is overwriting the entire dictionary. > 2) How can I fix this? > > Note: I really don't care if the "initial" update happens after the thread receives a data point or two, and therefore overwrites one or two values. I just need the dictionary to be fully populated at some point early in execution. In usage, the dictionary is used to see of an aircraft has been seen "recently", so if the most recent datapoint gets overwritten with a slightly older one from disk storage, that's fine - it's just if it's still showing datetime.min because we haven't gotten in any datapoint since we launched the program, even though we have "recent" data in disk storage thats a problem. So I don't care about the obvious race condition between the two operations, just that the end result is a populated dictionary. Note also that as datapoint come in, they are being written to disk, so the disk storage doesn't lag significantly anyway. > > The framework of my code is below: > > File: watcher.py > > last_points = defaultdict(lambda:datetime.min) > > # This function is launched as a thread using the threading module when the first client connects > def watch(): > while true: > > pointtime= > if last_points[] < pointtime: > > last_points[]=pointtime > #DEBUGGING > print("At update:", len(last_points)) > > > File: main.py: > > from .watcher import last_points > > # This function will be triggered by a web call from a client, so could happen at any time > # Client will call this function immediately after connecting, as well as in response to various user actions. > def getac(): > > > for record in aclist: > last_points[]=record_timestamp > #DEBUGGING > print("At get AC:", len(last_points)) > > > ----------------------------------------------- > Israel Brewster > Systems Analyst II > Ravn Alaska > 5245 Airport Industrial Rd > Fairbanks, AK 99709 > (907) 450-7293 > ----------------------------------------------- > > > > > -- > https://mail.python.org/mailman/listinfo/python-list From israel at ravnalaska.net Wed Nov 1 13:45:49 2017 From: israel at ravnalaska.net (Israel Brewster) Date: Wed, 1 Nov 2017 09:45:49 -0800 Subject: Thread safety issue (I think) with defaultdict In-Reply-To: <27A7DA1E-E6D6-44A5-B181-A2366B0B12FC@ravnalaska.net> References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <27A7DA1E-E6D6-44A5-B181-A2366B0B12FC@ravnalaska.net> Message-ID: On Nov 1, 2017, at 9:04 AM, Israel Brewster wrote: > > Let me rephrase the question, see if I can simplify it. I need to be able to access a defaultdict from two different threads - one thread that responds to user requests which will populate the dictionary in response to a user request, and a second thread that will keep the dictionary updated as new data comes in. The value of the dictionary will be a timestamp, with the default value being datetime.min, provided by a lambda: > > lambda: datetime.min > > At the moment my code is behaving as though each thread has a *separate* defaultdict, even though debugging shows the same addresses - the background update thread never sees the data populated into the defaultdict by the main thread. I was thinking race conditions or the like might make it so one particular loop of the background thread occurs before the main thread, but even so subsequent loops should pick up on the changes made by the main thread. > > How can I *properly* share a dictionary like object between two threads, with both threads seeing the updates made by the other? For what it's worth, if I insert a print statement in both threads (which I am calling "Get AC", since that is the function being called in the first thread, and "update", since that is the purpose of the second thread), I get the following output: Length at get AC: 54 ID: 4524152200 Time: 2017-11-01 09:41:24.474788 Length At update: 1 ID: 4524152200 Time: 2017-11-01 09:41:24.784399 Length At update: 2 ID: 4524152200 Time: 2017-11-01 09:41:25.228853 Length At update: 3 ID: 4524152200 Time: 2017-11-01 09:41:25.530434 Length At update: 4 ID: 4524152200 Time: 2017-11-01 09:41:25.532073 Length At update: 5 ID: 4524152200 Time: 2017-11-01 09:41:25.682161 Length At update: 6 ID: 4524152200 Time: 2017-11-01 09:41:26.807127 ... So the object ID hasn't changed as I would expect it to if, in fact, we have created a separate object for the thread. And the first call that populates it with 54 items happens "well" before the first update call - a full .3 seconds, which I would think would be an eternity is code terms. So it doesn't even look like it's a race condition causing the issue. It seems to me this *has* to be something to do with the use of threads, but I'm baffled as to what. > ----------------------------------------------- > Israel Brewster > Systems Analyst II > Ravn Alaska > 5245 Airport Industrial Rd > Fairbanks, AK 99709 > (907) 450-7293 > ----------------------------------------------- > > > > >> On Oct 31, 2017, at 9:38 AM, Israel Brewster wrote: >> >> A question that has arisen before (for example, here: https://mail.python.org/pipermail/python-list/2010-January/565497.html ) is the question of "is defaultdict thread safe", with the answer generally being a conditional "yes", with the condition being what is used as the default value: apparently default values of python types, such as list, are thread safe, whereas more complicated constructs, such as lambdas, make it not thread safe. In my situation, I'm using a lambda, specifically: >> >> lambda: datetime.min >> >> So presumably *not* thread safe. >> >> My goal is to have a dictionary of aircraft and when they were last "seen", with datetime.min being effectively "never". When a data point comes in for a given aircraft, the data point will be compared with the value in the defaultdict for that aircraft, and if the timestamp on that data point is newer than what is in the defaultdict, the defaultdict will get updated with the value from the datapoint (not necessarily current timestamp, but rather the value from the datapoint). Note that data points do not necessarily arrive in chronological order (for various reasons not applicable here, it's just the way it is), thus the need for the comparison. >> >> When the program first starts up, two things happen: >> >> 1) a thread is started that watches for incoming data points and updates the dictionary as per above, and >> 2) the dictionary should get an initial population (in the main thread) from hard storage. >> >> The behavior I'm seeing, however, is that when step 2 happens (which generally happens before the thread gets any updates), the dictionary gets populated with 56 entries, as expected. However, none of those entries are visible when the thread runs. It's as though the thread is getting a separate copy of the dictionary, although debugging says that is not the case - printing the variable from each location shows the same address for the object. >> >> So my questions are: >> >> 1) Is this what it means to NOT be thread safe? I was thinking of race conditions where individual values may get updated wrong, but this apparently is overwriting the entire dictionary. >> 2) How can I fix this? >> >> Note: I really don't care if the "initial" update happens after the thread receives a data point or two, and therefore overwrites one or two values. I just need the dictionary to be fully populated at some point early in execution. In usage, the dictionary is used to see of an aircraft has been seen "recently", so if the most recent datapoint gets overwritten with a slightly older one from disk storage, that's fine - it's just if it's still showing datetime.min because we haven't gotten in any datapoint since we launched the program, even though we have "recent" data in disk storage thats a problem. So I don't care about the obvious race condition between the two operations, just that the end result is a populated dictionary. Note also that as datapoint come in, they are being written to disk, so the disk storage doesn't lag significantly anyway. >> >> The framework of my code is below: >> >> File: watcher.py >> >> last_points = defaultdict(lambda:datetime.min) >> >> # This function is launched as a thread using the threading module when the first client connects >> def watch(): >> while true: >> >> pointtime= >> if last_points[] < pointtime: >> >> last_points[]=pointtime >> #DEBUGGING >> print("At update:", len(last_points)) >> >> >> File: main.py: >> >> from .watcher import last_points >> >> # This function will be triggered by a web call from a client, so could happen at any time >> # Client will call this function immediately after connecting, as well as in response to various user actions. >> def getac(): >> >> >> for record in aclist: >> last_points[]=record_timestamp >> #DEBUGGING >> print("At get AC:", len(last_points)) >> >> >> ----------------------------------------------- >> Israel Brewster >> Systems Analyst II >> Ravn Alaska >> 5245 Airport Industrial Rd >> Fairbanks, AK 99709 >> (907) 450-7293 >> ----------------------------------------------- >> >> >> >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > > -- > https://mail.python.org/mailman/listinfo/python-list From ian.g.kelly at gmail.com Wed Nov 1 13:58:29 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 1 Nov 2017 11:58:29 -0600 Subject: Thread safety issue (I think) with defaultdict In-Reply-To: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> Message-ID: On Tue, Oct 31, 2017 at 11:38 AM, Israel Brewster wrote: > A question that has arisen before (for example, here: https://mail.python.org/pipermail/python-list/2010-January/565497.html ) is the question of "is defaultdict thread safe", with the answer generally being a conditional "yes", with the condition being what is used as the default value: apparently default values of python types, such as list, are thread safe, I would not rely on this. It might be true for current versions of CPython, but I don't think there's any general guarantee and you could run into trouble with other implementations. > whereas more complicated constructs, such as lambdas, make it not thread safe. In my situation, I'm using a lambda, specifically: > > lambda: datetime.min > > So presumably *not* thread safe. > > My goal is to have a dictionary of aircraft and when they were last "seen", with datetime.min being effectively "never". When a data point comes in for a given aircraft, the data point will be compared with the value in the defaultdict for that aircraft, and if the timestamp on that data point is newer than what is in the defaultdict, the defaultdict will get updated with the value from the datapoint (not necessarily current timestamp, but rather the value from the datapoint). Note that data points do not necessarily arrive in chronological order (for various reasons not applicable here, it's just the way it is), thus the need for the comparison. Since you're going to immediately replace the default value with an actual value, it's not clear to me what the purpose of using a defaultdict is here. You could use a regular dict and just check if the key is present, perhaps with the additional argument to .get() to return a default value. Individual lookups and updates of ordinary dicts are atomic (at least in CPython). A lookup followed by an update is not, and this would be true for defaultdict as well. > When the program first starts up, two things happen: > > 1) a thread is started that watches for incoming data points and updates the dictionary as per above, and > 2) the dictionary should get an initial population (in the main thread) from hard storage. > > The behavior I'm seeing, however, is that when step 2 happens (which generally happens before the thread gets any updates), the dictionary gets populated with 56 entries, as expected. However, none of those entries are visible when the thread runs. It's as though the thread is getting a separate copy of the dictionary, although debugging says that is not the case - printing the variable from each location shows the same address for the object. > > So my questions are: > > 1) Is this what it means to NOT be thread safe? I was thinking of race conditions where individual values may get updated wrong, but this apparently is overwriting the entire dictionary. No, a thread-safety issue would be something like this: account[user] = account[user] + 1 where the value of account[user] could potentially change between the time it is looked up and the time it is set again. That said it's not obvious to me what your problem actually is. From neilc at norwich.edu Wed Nov 1 14:06:27 2017 From: neilc at norwich.edu (Neil Cerutti) Date: Wed, 1 Nov 2017 18:06:27 +0000 (UTC) Subject: Code Snippets References: Message-ID: On 2017-11-01, Stefan Ram wrote: > I started to collect some code snippets: > > Sleep one second > > __import__( "time" ).sleep( 1 ) > > What I'm supposed to do instead, I guess, is: > > Sleep one second > > import time > ... > time.sleep( 1 ) > > Get current directory > > import os > ... > os.getcwd() > > Get a random number > > import random > ... > random.random() > > Now, the user has to cut the import, paste it to the top > of his code, then go back to the list of snippets, find > the same snippet again, copy the expression, go to his code, > then find the point where he wanted to insert the snippet again, > and finally insert the snippet. And still there now is a > risk of name collisions. So, it seems to me that __import__ > is just so much better! You can import wherever you like--only good style requires you to put them at the top of your file. Moreover, snippets could be a library, with each snippet a function, with the import inside the function. That would keep the module name out of your global namespace. -- Neil Cerutti From ned at nedbatchelder.com Wed Nov 1 14:43:00 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 1 Nov 2017 14:43:00 -0400 Subject: Code Snippets In-Reply-To: References: Message-ID: On 11/1/17 1:25 PM, Stefan Ram wrote: > I started to collect some code snippets: > > Sleep one second > > __import__( "time" ).sleep( 1 ) > > Get current directory > > __import__( "os" ).getcwd() > > Get a random number > > __import__( "random" ).random() > > And so on. You get the idea. > > However, reportedly, all those snippets are anti-patterns > because they use ?__import__?. > > But what I like about them: You just paste them in where > you want them to be, and your done. > > What I'm supposed to do instead, I guess, is: > > Sleep one second > > import time > ... > time.sleep( 1 ) > > Get current directory > > import os > ... > os.getcwd() > > Get a random number > > import random > ... > random.random() > > Now, the user has to cut the import, paste it to the top > of his code, then go back to the list of snippets, find > the same snippet again, copy the expression, go to his code, > then find the point where he wanted to insert the snippet again, > and finally insert the snippet. And still there now is a > risk of name collisions. So, it seems to me that __import__ > is just so much better! > You should not optimize for the shortest time to paste a line of code.? You should take time and care writing your code, so that it reads best and runs best.? If you needed another os function, would you have two __import__("os") in your code? Ugh. --Ned. From ned at nedbatchelder.com Wed Nov 1 14:47:25 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 1 Nov 2017 14:47:25 -0400 Subject: Report on non-breaking spaces in posts In-Reply-To: References: <0b6ba27b-1127-f812-da22-df1e005f75f1@nedbatchelder.com> Message-ID: <7285cd7c-8a28-53b1-ae93-8c8db1b6f1c6@nedbatchelder.com> On 10/31/17 1:23 PM, Stefan Ram wrote: > Ok, here's a report on me seing non-breaking spaces in > posts in this NG. I have written this report so that you > can see that it's not my newsreader that is converting > something, because there is no newsreader involved. You've worded this as if 1) non-breaking spaces are a problem, 2) you've reported them before, and 3) someone has claimed that it is your newsreader at fault.? Have I missed a previous discussion? --Ned. From israel at ravnalaska.net Wed Nov 1 14:53:20 2017 From: israel at ravnalaska.net (Israel Brewster) Date: Wed, 1 Nov 2017 10:53:20 -0800 Subject: Thread safety issue (I think) with defaultdict In-Reply-To: References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> Message-ID: <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> On Nov 1, 2017, at 9:58 AM, Ian Kelly wrote: > > On Tue, Oct 31, 2017 at 11:38 AM, Israel Brewster wrote: >> A question that has arisen before (for example, here: https://mail.python.org/pipermail/python-list/2010-January/565497.html ) is the question of "is defaultdict thread safe", with the answer generally being a conditional "yes", with the condition being what is used as the default value: apparently default values of python types, such as list, are thread safe, > > I would not rely on this. It might be true for current versions of > CPython, but I don't think there's any general guarantee and you could > run into trouble with other implementations. Right, completely agreed. Kinda feels "dirty" to rely on things like this to me. > >> [...] > > [...] You could use a regular dict and just check if > the key is present, perhaps with the additional argument to .get() to > return a default value. True. Using defaultdict is simply saves having to stick the same default in every call to get(). DRY principal and all. That said, see below - I don't think the defaultdict is the issue. > > Individual lookups and updates of ordinary dicts are atomic (at least > in CPython). A lookup followed by an update is not, and this would be > true for defaultdict as well. > >> [...] >> 1) Is this what it means to NOT be thread safe? I was thinking of race conditions where individual values may get updated wrong, but this apparently is overwriting the entire dictionary. > > No, a thread-safety issue would be something like this: > > account[user] = account[user] + 1 > > where the value of account[user] could potentially change between the > time it is looked up and the time it is set again. That's what I thought - changing values/different values from expected, not missing values. All that said, I just had a bit of an epiphany: the main thread is actually a Flask app, running through UWSGI with multiple *processes*, and using the flask-uwsgi-websocket plugin, which further uses greenlets. So what I was thinking was simply a separate thread was, in reality, a completely separate *process*. I'm sure that makes a difference. So what's actually happening here is the following: 1) the main python process starts, which initializes the dictionary (since it is at a global level) 2) uwsgi launches off a bunch of child worker processes (10 to be exact, each of which is set up with 10 gevent threads) 3a) a client connects (web socket connection to be exact). This connection is handled by an arbitrary worker, and an arbitrary green thread within that worker, based on UWSGI algorithms. 3b) This connection triggers launching of a *true* thread (using the python threading library) which, presumably, is now a child thread of that arbitrary uwsgi worker. <== BAD THING, I would think 4) The client makes a request for the list, which is handled by a DIFFERENT (presumably) arbitrary worker process and green thread. So the end result is that the thread that "updates" the dictionary, and the thread that initially *populates* the dictionary are actually running in different processes. In fact, any given request could be in yet another process, which would seem to indicate that all bets are off as to what data is seen. Now that I've thought through what is really happening, I think I need to re-architect things a bit here. For one thing, the update thread should be launched from the main process, not an arbitrary UWSGI worker. I had launched it from the client connection because there is no point in having it running if there is no one connected, but I may need to launch it from the __init__.py file instead. For another thing, since this dictionary will need to be accessed from arbitrary worker processes, I'm thinking I may need to move it to some sort of external storage, such as a redis database. Oy, I made my life complicated :-) > That said it's not > obvious to me what your problem actually is. > -- > https://mail.python.org/mailman/listinfo/python-list From ned at nedbatchelder.com Wed Nov 1 15:26:01 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 1 Nov 2017 15:26:01 -0400 Subject: String changing size on failure? Message-ID: <0a1e64db-19cc-fd96-04c6-b6aedb2c201c@nedbatchelder.com> From David Beazley (https://twitter.com/dabeaz/status/925787482515533830): >>> a = 'n' >>> b = '?' >>> sys.getsizeof(a) 50 >>> sys.getsizeof(b) 74 >>> float(b) Traceback (most recent call last): ? File "", line 1, in ValueError: could not convert string to float: '?' >>> sys.getsizeof(b) 77 Huh? --Ned. From skip.montanaro at gmail.com Wed Nov 1 15:53:43 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 1 Nov 2017 14:53:43 -0500 Subject: String changing size on failure? In-Reply-To: <0a1e64db-19cc-fd96-04c6-b6aedb2c201c@nedbatchelder.com> References: <0a1e64db-19cc-fd96-04c6-b6aedb2c201c@nedbatchelder.com> Message-ID: Leave it to DB to ask the tough questions other people won't. :-) Skip On Wed, Nov 1, 2017 at 2:26 PM, Ned Batchelder wrote: > From David Beazley (https://twitter.com/dabeaz/status/925787482515533830): > > >>> a = 'n' > >>> b = '?' > >>> sys.getsizeof(a) > 50 > >>> sys.getsizeof(b) > 74 > >>> float(b) > Traceback (most recent call last): > File "", line 1, in > ValueError: could not convert string to float: '?' > >>> sys.getsizeof(b) > 77 > > Huh? > > --Ned. > > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Wed Nov 1 16:01:10 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Nov 2017 07:01:10 +1100 Subject: String changing size on failure? In-Reply-To: <0a1e64db-19cc-fd96-04c6-b6aedb2c201c@nedbatchelder.com> References: <0a1e64db-19cc-fd96-04c6-b6aedb2c201c@nedbatchelder.com> Message-ID: On Thu, Nov 2, 2017 at 6:26 AM, Ned Batchelder wrote: > From David Beazley (https://twitter.com/dabeaz/status/925787482515533830): > > >>> a = 'n' > >>> b = '?' > >>> sys.getsizeof(a) > 50 > >>> sys.getsizeof(b) > 74 > >>> float(b) > Traceback (most recent call last): > File "", line 1, in > ValueError: could not convert string to float: '?' > >>> sys.getsizeof(b) > 77 > > Huh? There are optional parts to the Python string object that don't get memory allocated for them until they're used. Apparently calling float() on a string triggers one of those allocations (possibly the UTF-8 representation?). You'd have to mess around with ctypes to see exactly what's going on. ChrisA From wolfgang.maier at biologie.uni-freiburg.de Wed Nov 1 16:01:15 2017 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 1 Nov 2017 21:01:15 +0100 Subject: Code Snippets In-Reply-To: References: Message-ID: On 01.11.2017 18:25, Stefan Ram wrote: > I started to collect some code snippets: > > Sleep one second > > __import__( "time" ).sleep( 1 ) > > Get current directory > > __import__( "os" ).getcwd() > > Get a random number > > __import__( "random" ).random() > > And so on. You get the idea. > > However, reportedly, all those snippets are anti-patterns > because they use ?__import__?. > > But what I like about them: You just paste them in where > you want them to be, and your done. > > What I'm supposed to do instead, I guess, is: > > Sleep one second > > import time > ... > time.sleep( 1 ) > > Get current directory > > import os > ... > os.getcwd() > > Get a random number > > import random > ... > random.random() > > Now, the user has to cut the import, paste it to the top > of his code, then go back to the list of snippets, find > the same snippet again, copy the expression, go to his code, > then find the point where he wanted to insert the snippet again, > and finally insert the snippet. And still there now is a > risk of name collisions. So, it seems to me that __import__ > is just so much better! > I'm not sure why you think this has to do with import vs __import__. If you're worried bout having things on separate lines, you could write: import os; os.getcwd() ,etc., which is actually saving a few characters :) From python at mrabarnett.plus.com Wed Nov 1 16:17:41 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 1 Nov 2017 20:17:41 +0000 Subject: String changing size on failure? In-Reply-To: <0a1e64db-19cc-fd96-04c6-b6aedb2c201c@nedbatchelder.com> References: <0a1e64db-19cc-fd96-04c6-b6aedb2c201c@nedbatchelder.com> Message-ID: On 2017-11-01 19:26, Ned Batchelder wrote: > From David Beazley (https://twitter.com/dabeaz/status/925787482515533830): > > >>> a = 'n' > >>> b = '?' > >>> sys.getsizeof(a) > 50 > >>> sys.getsizeof(b) > 74 > >>> float(b) > Traceback (most recent call last): > ? File "", line 1, in > ValueError: could not convert string to float: '?' > >>> sys.getsizeof(b) > 77 > > Huh? > It's all explained in PEP 393. It's creating an additional representation (UTF-8 + zero-byte terminator) of the value and is caching that, so there'll then be the bytes for '?' and the bytes for the UTF-8 (0xC3 0xB1 0x00). When the string is ASCII, the bytes of the UTF-8 representation is identical to those or the original string, so it can share them. From rosuav at gmail.com Wed Nov 1 16:23:33 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Nov 2017 07:23:33 +1100 Subject: Code Snippets In-Reply-To: References: Message-ID: On Thu, Nov 2, 2017 at 7:17 AM, Stefan Ram wrote: > Wolfgang Maier writes: >>If you're worried bout having things on separate lines, you could write: >>import os; os.getcwd() >>,etc., which is actually saving a few characters :) > > Yes, but there still is the risk of the identifier ?os? > already being used in the sorrounding code. While > > __import__( "os" ).getcwd() > > does not seem to "leak" names into the enclosing scope. If you're using the name "os" for something else, you need to be aware of that anyway. Leaking names of core modules shouldn't normally be a problem. ChrisA From dave at dabeaz.com Wed Nov 1 16:32:00 2017 From: dave at dabeaz.com (David Beazley) Date: Wed, 1 Nov 2017 15:32:00 -0500 Subject: String changing size on failure? In-Reply-To: References: <0a1e64db-19cc-fd96-04c6-b6aedb2c201c@nedbatchelder.com> Message-ID: Nah. I discuss this behavior (caching of UTF-8 conversions in the C API) in section 15.14 of the Python Cookbook. The tweet was a tutorial, not a question ;-). Admittedly, an evil tutorial... Cheers, Dave > On Nov 1, 2017, at 2:53 PM, Skip Montanaro wrote: > > Leave it to DB to ask the tough questions other people won't. :-) > > Skip > > > On Wed, Nov 1, 2017 at 2:26 PM, Ned Batchelder wrote: >> From David Beazley (https://twitter.com/dabeaz/status/925787482515533830): >> >>>>> a = 'n' >>>>> b = '?' >>>>> sys.getsizeof(a) >> 50 >>>>> sys.getsizeof(b) >> 74 >>>>> float(b) >> Traceback (most recent call last): >> File "", line 1, in >> ValueError: could not convert string to float: '?' >>>>> sys.getsizeof(b) >> 77 >> >> Huh? >> >> --Ned. >> >> -- >> https://mail.python.org/mailman/listinfo/python-list From irmen.NOSPAM at xs4all.nl Wed Nov 1 16:33:27 2017 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Wed, 1 Nov 2017 21:33:27 +0100 Subject: Code Snippets In-Reply-To: References: Message-ID: <59fa2f97$0$747$e4fe514c@news.xs4all.nl> On 11/01/2017 06:25 PM, Stefan Ram wrote: > import random > ... > random.random() > > Now, the user has to cut the import, paste it to the top > of his code, then go back to the list of snippets, find > the same snippet again, copy the expression, go to his code, > then find the point where he wanted to insert the snippet again, > and finally insert the snippet. And still there now is a > risk of name collisions. So, it seems to me that __import__ > is just so much better! ..or suggest them to use an IDE instead? For instance in PyCharm you can type: random.random() (squiggle appears under random) (it suggests: Import This name) (it suggests: from random) done, an import random has been added at the top of my module. Irmen From ned at nedbatchelder.com Wed Nov 1 16:34:20 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 1 Nov 2017 16:34:20 -0400 Subject: String changing size on failure? In-Reply-To: References: <0a1e64db-19cc-fd96-04c6-b6aedb2c201c@nedbatchelder.com> Message-ID: <2d26aa9a-d311-987c-3fd4-75f1a128de5e@nedbatchelder.com> On 11/1/17 4:17 PM, MRAB wrote: > On 2017-11-01 19:26, Ned Batchelder wrote: >> ? From David Beazley >> (https://twitter.com/dabeaz/status/925787482515533830): >> >> ????? >>> a = 'n' >> ????? >>> b = '?' >> ????? >>> sys.getsizeof(a) >> ???? 50 >> ????? >>> sys.getsizeof(b) >> ???? 74 >> ????? >>> float(b) >> ???? Traceback (most recent call last): >> ????? ? File "", line 1, in >> ???? ValueError: could not convert string to float: '?' >> ????? >>> sys.getsizeof(b) >> ???? 77 >> >> Huh? >> > It's all explained in PEP 393. > > It's creating an additional representation (UTF-8 + zero-byte > terminator) of the value and is caching that, so there'll then be the > bytes for '?' and the bytes for the UTF-8 (0xC3 0xB1 0x00). > > When the string is ASCII, the bytes of the UTF-8 representation is > identical to those or the original string, so it can share them. That explains why b is larger than a to begin with, but it doesn't explain why float(b) is changing the size of b. --Ned. From rosuav at gmail.com Wed Nov 1 16:38:14 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Nov 2017 07:38:14 +1100 Subject: String changing size on failure? In-Reply-To: <2d26aa9a-d311-987c-3fd4-75f1a128de5e@nedbatchelder.com> References: <0a1e64db-19cc-fd96-04c6-b6aedb2c201c@nedbatchelder.com> <2d26aa9a-d311-987c-3fd4-75f1a128de5e@nedbatchelder.com> Message-ID: On Thu, Nov 2, 2017 at 7:34 AM, Ned Batchelder wrote: > On 11/1/17 4:17 PM, MRAB wrote: >> >> On 2017-11-01 19:26, Ned Batchelder wrote: >>> >>> From David Beazley >>> (https://twitter.com/dabeaz/status/925787482515533830): >>> >>> >>> a = 'n' >>> >>> b = '?' >>> >>> sys.getsizeof(a) >>> 50 >>> >>> sys.getsizeof(b) >>> 74 >>> >>> float(b) >>> Traceback (most recent call last): >>> File "", line 1, in >>> ValueError: could not convert string to float: '?' >>> >>> sys.getsizeof(b) >>> 77 >>> >>> Huh? >>> >> It's all explained in PEP 393. >> >> It's creating an additional representation (UTF-8 + zero-byte terminator) >> of the value and is caching that, so there'll then be the bytes for '?' and >> the bytes for the UTF-8 (0xC3 0xB1 0x00). >> >> When the string is ASCII, the bytes of the UTF-8 representation is >> identical to those or the original string, so it can share them. > > > That explains why b is larger than a to begin with, but it doesn't explain > why float(b) is changing the size of b. b doesn't initially even _have_ a UTF-8 representation. When float() tries to parse the string, it asks for the UTF-8 form, and that form gets saved into the string object in case it's needed later. ChrisA From grant.b.edwards at gmail.com Wed Nov 1 16:39:43 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 1 Nov 2017 20:39:43 +0000 (UTC) Subject: String changing size on failure? References: <0a1e64db-19cc-fd96-04c6-b6aedb2c201c@nedbatchelder.com> <2d26aa9a-d311-987c-3fd4-75f1a128de5e@nedbatchelder.com> Message-ID: On 2017-11-01, Ned Batchelder wrote: > On 11/1/17 4:17 PM, MRAB wrote: >> On 2017-11-01 19:26, Ned Batchelder wrote: >>> ? From David Beazley >>> (https://twitter.com/dabeaz/status/925787482515533830): >>> >>> ????? >>> a = 'n' >>> ????? >>> b = '?' >>> ????? >>> sys.getsizeof(a) >>> ???? 50 >>> ????? >>> sys.getsizeof(b) >>> ???? 74 >>> ????? >>> float(b) >>> ???? Traceback (most recent call last): >>> ????? ? File "", line 1, in >>> ???? ValueError: could not convert string to float: '?' >>> ????? >>> sys.getsizeof(b) >>> ???? 77 >>> >>> Huh? >>> >> It's all explained in PEP 393. >> >> It's creating an additional representation (UTF-8 + zero-byte >> terminator) of the value and is caching that, so there'll then be the >> bytes for '?' and the bytes for the UTF-8 (0xC3 0xB1 0x00). >> >> When the string is ASCII, the bytes of the UTF-8 representation is >> identical to those or the original string, so it can share them. > > That explains why b is larger than a to begin with No, that size difference is due to the additional bytes required for the internal representation of the string. > but it doesn't explain why float(b) is changing the size of b. The additional UTF-8 representation isn't being created and cached until the float() call is made. -- Grant Edwards grant.b.edwards Yow! ONE LIFE TO LIVE for at ALL MY CHILDREN in ANOTHER gmail.com WORLD all THE DAYS OF OUR LIVES. From ben.usenet at bsb.me.uk Wed Nov 1 17:02:46 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Wed, 01 Nov 2017 21:02:46 +0000 Subject: Code Snippets References: Message-ID: <87zi85btl5.fsf@bsb.me.uk> ram at zedat.fu-berlin.de (Stefan Ram) writes: > Wolfgang Maier writes: >>If you're worried bout having things on separate lines, you could write: >>import os; os.getcwd() >>,etc., which is actually saving a few characters :) > > Yes, but there still is the risk of the identifier ?os? > already being used in the sorrounding code. While > > __import__( "os" ).getcwd() > > does not seem to "leak" names into the enclosing scope. Also it's an expression which may be important in your "quick and dirty" scripts. -- Ben. From rosuav at gmail.com Wed Nov 1 17:11:48 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Nov 2017 08:11:48 +1100 Subject: Code Snippets In-Reply-To: <87zi85btl5.fsf@bsb.me.uk> References: <87zi85btl5.fsf@bsb.me.uk> Message-ID: On Thu, Nov 2, 2017 at 8:02 AM, Ben Bacarisse wrote: > ram at zedat.fu-berlin.de (Stefan Ram) writes: > >> Wolfgang Maier writes: >>>If you're worried bout having things on separate lines, you could write: >>>import os; os.getcwd() >>>,etc., which is actually saving a few characters :) >> >> Yes, but there still is the risk of the identifier ?os? >> already being used in the sorrounding code. While >> >> __import__( "os" ).getcwd() >> >> does not seem to "leak" names into the enclosing scope. > > Also it's an expression which may be important in your "quick and dirty" > scripts. If your quick-and-dirties are needing these kinds of imports all the time, the best solution might be to slap something into site.py that "pre-imports" those into the builtins. Then you can just use os.getcwd() without worrying about the import, and without calling a dunder. ChrisA From alexey.muranov at gmail.com Wed Nov 1 17:12:41 2017 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Wed, 01 Nov 2017 22:12:41 +0100 Subject: replacing `else` with `then` in `for` and `try` Message-ID: <1509570761.4585.0@smtp.gmail.com> Hello, what do you think about the idea of replacing "`else`" with "`then`" in the contexts of `for` and `try`? It seems clear that it should be rather "then" than "else." Compare also "try ... then ... finally" with "try ... else ... finally". Currently, with "else", it is almost impossible to guess the meaning without looking into the documentation. Off course, it should not be changed in Python 3, maybe in Python 4 or 5, but in Python 3 `then` could be an alias of `else` in these contexts. Alexey. From rosuav at gmail.com Wed Nov 1 17:21:58 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Nov 2017 08:21:58 +1100 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <1509570761.4585.0@smtp.gmail.com> References: <1509570761.4585.0@smtp.gmail.com> Message-ID: On Thu, Nov 2, 2017 at 8:12 AM, Alexey Muranov wrote: > Hello, > > what do you think about the idea of replacing "`else`" with "`then`" in the > contexts of `for` and `try`? > > It seems clear that it should be rather "then" than "else." Compare also > "try ... then ... finally" with "try ... else ... finally". > > Currently, with "else", it is almost impossible to guess the meaning without > looking into the documentation. > > Off course, it should not be changed in Python 3, maybe in Python 4 or 5, > but in Python 3 `then` could be an alias of `else` in these contexts. > The cost of creating a new keyword is incredibly high. You'll need to demonstrate much more than a marginal improvement. With try/except/else, it's "do this, and if an exception happens, do this, else do this". So else makes perfect sense. With the 'for' loop, it's a bit more arguable, but I've never seen anything more than a weak argument in favour of 'then', and since it'd be a completely new keyword, there's very approximately 0% chance that this will be changed. ChrisA From ned at nedbatchelder.com Wed Nov 1 17:23:34 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 1 Nov 2017 17:23:34 -0400 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <1509570761.4585.0@smtp.gmail.com> References: <1509570761.4585.0@smtp.gmail.com> Message-ID: On 11/1/17 5:12 PM, Alexey Muranov wrote: > Hello, > > what do you think about the idea of replacing "`else`" with "`then`" > in the contexts of `for` and `try`? > > It seems clear that it should be rather "then" than "else." Compare > also "try ... then ... finally" with "try ... else ... finally". > > Currently, with "else", it is almost impossible to guess the meaning > without looking into the documentation. > > Off course, it should not be changed in Python 3, maybe in Python 4 or > 5, but in Python 3 `then` could be an alias of `else` in these contexts. > > Alexey. > Apart from the questions of backward compatibility etc (Python is unlikely to ever go through another shift like the 2/3 breakage), are you sure "then" is what you mean?? This won't print "end": ??? for i in range(10): ??????? print(i) ??? else: ??????? print(end) --Ned. From rosuav at gmail.com Wed Nov 1 17:29:49 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Nov 2017 08:29:49 +1100 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> Message-ID: On Thu, Nov 2, 2017 at 8:23 AM, Ned Batchelder wrote: > On 11/1/17 5:12 PM, Alexey Muranov wrote: >> >> Hello, >> >> what do you think about the idea of replacing "`else`" with "`then`" in >> the contexts of `for` and `try`? >> >> It seems clear that it should be rather "then" than "else." Compare also >> "try ... then ... finally" with "try ... else ... finally". >> >> Currently, with "else", it is almost impossible to guess the meaning >> without looking into the documentation. >> >> Off course, it should not be changed in Python 3, maybe in Python 4 or 5, >> but in Python 3 `then` could be an alias of `else` in these contexts. >> >> Alexey. >> > > Apart from the questions of backward compatibility etc (Python is unlikely > to ever go through another shift like the 2/3 breakage), are you sure "then" > is what you mean? This won't print "end": > > for i in range(10): > print(i) > else: > print(end) Well, it'll bomb with NameError when it tries to look up the *name* end. But it will run that line of code - if you quote it, it will work. ChrisA From formisc at gmail.com Wed Nov 1 18:29:27 2017 From: formisc at gmail.com (Andrew Z) Date: Wed, 1 Nov 2017 18:29:27 -0400 Subject: matplot plot hangs In-Reply-To: References: Message-ID: nope. it doesnt: I added print-s after each line and that produced: [az at hp src]$ cat ./main1.py import matplotlib.pyplot as plt print("imported") plt.plot([1,2,4,1]) print("plot is done") plt.show() print("show is done") [az at hp src]$ python3.5 ./main1.py imported ^C^Z [1]+ Stopped python3.5 ./main1.py On Wed, Nov 1, 2017 at 9:31 AM, Vlastimil Brom wrote: > 2017-11-01 13:49 GMT+01:00 Andrew Z : > > Wolfgang, > > I tried to ran from ide with no rwsults, so now im trying from a > terminal > > in xwindow. > > The .plot is the last line in the script and it does hang trying to > execute > > it. > > > > > > On Nov 1, 2017 05:44, "Wolfgang Maier" < > > wolfgang.maier at biologie.uni-freiburg.de> wrote: > > > > On 01.11.2017 00:40, Andrew Z wrote: > > > >> hello, > >> learning python's plotting by using matplotlib with python35 on > fedora 24 > >> x86. > >> > >> Installed matplotlib into user's directory. > >> tk, seemed to work - > >> http://www.tkdocs.com/tutorial/install.html#installlinux - the window > >> shows > >> up just fine. > >> but when trying to run the simple plot ( > >> https://matplotlib.org/examples/pylab_examples/simple_plot.html) the > >> script > >> is hanging on; > >> > >> plt.plot(t, s) > >> > >> attempts to > >> matplotlib.interactive(True) didn't bring anything, > >> > >> > > Hi Andrew, > > > > From which environment are you trying to run the example? In the > terminal, > > from within some IDE, inside a jupyter notebook? > > > > Are you sure the script "is hanging on plt.plot(t, s)" and not after > that? > > > > Best, > > Wolfgang > > > > -- > Hi, > sorry if it is too trivial, just to make sure, do you have a call to > "show()" the resulting plot in the code? > > An elementary plotting code might be e.g.: > > import matplotlib.pyplot as plt > plt.plot([1,2,4,1]) > plt.show() > > Does this work in your environment? > > It was not quite clear, what do you plan with interactive drawing, or > whether you are using e.g. plt.interactive(True) already - this might > be a problem as there could be collisions or the plot window is closed > after the standalone script finishes. > > hth, > vbr > -- > https://mail.python.org/mailman/listinfo/python-list > From ned at nedbatchelder.com Wed Nov 1 19:10:26 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 1 Nov 2017 19:10:26 -0400 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> Message-ID: <401b4034-ac5c-8970-1128-5b9be741b891@nedbatchelder.com> On 11/1/17 5:29 PM, Chris Angelico wrote: > On Thu, Nov 2, 2017 at 8:23 AM, Ned Batchelder wrote: >> On 11/1/17 5:12 PM, Alexey Muranov wrote: >>> Hello, >>> >>> what do you think about the idea of replacing "`else`" with "`then`" in >>> the contexts of `for` and `try`? >>> >>> It seems clear that it should be rather "then" than "else." Compare also >>> "try ... then ... finally" with "try ... else ... finally". >>> >>> Currently, with "else", it is almost impossible to guess the meaning >>> without looking into the documentation. >>> >>> Off course, it should not be changed in Python 3, maybe in Python 4 or 5, >>> but in Python 3 `then` could be an alias of `else` in these contexts. >>> >>> Alexey. >>> >> Apart from the questions of backward compatibility etc (Python is unlikely >> to ever go through another shift like the 2/3 breakage), are you sure "then" >> is what you mean? This won't print "end": >> >> for i in range(10): >> print(i) >> else: >> print(end) > Well, it'll bomb with NameError when it tries to look up the *name* > end. But it will run that line of code - if you quote it, it will > work. > > ChrisA Naturally, I messed up on both a shallow and deep level! :) Or should I say derp level... :) --Ned. From jjmaldonis at gmail.com Wed Nov 1 19:13:29 2017 From: jjmaldonis at gmail.com (Jason Maldonis) Date: Wed, 1 Nov 2017 18:13:29 -0500 Subject: what exactly does type.__call__ do? Message-ID: Hi everyone, I want to use a metaclass to override how class instantiation works. I've done something analogous to using the Singleton metaclass from the Python3 Cookbook example. However, I want to provide a classmethod that allows for "normal" class instantiation that prevents this metaclass from being used. To do that, I think I just make a @classmethod constructor function. However, I can imagine a few different ways of writing this: @classmethod def normal_constructor(cls, *args, **kwargs): return type.__call__(*args, **kwargs) @classmethod def normal_constructor(cls, *args, **kwargs): return super(???).__call__(*args, **kwargs) # I'm not sure what should go in the super here (I'm using python3) @classmethod def normal_constructor(cls, *args, **kwargs): self = cls.__new__(cls) self.__init__(*args, **kwargs) return self Is one of these correct? Or do they all do the same thing? I was looking for documentation for what exactly `type.__call__` does so that I can emulate it, but I wasn't able to find any docs explicitly detailing what that method does. If someone knows where this info is that would be great too. From jjmaldonis at gmail.com Wed Nov 1 20:05:37 2017 From: jjmaldonis at gmail.com (Jason Maldonis) Date: Wed, 1 Nov 2017 19:05:37 -0500 Subject: what exactly does type.__call__ do? In-Reply-To: References: Message-ID: Thanks for the reply. And I think I wasn't clear enough. I was wondering what the metaclass `type`'s `type.__call__` does explicitly. I'm reasonably comfortable writing metaclasses when I need them, and I understand how `.__call__` works for non-metaclass objects. In my first email I gave three possible ways to write a @classmethod that returns an instance of that class. I'm not sure which one is the "most pythonic" or "most correct", but I'm pretty sure I can get them all to work. I'll paste them below again, and I'm wondering which one I should use and why. Thanks! @classmethod def normal_constructor(cls, *args, **kwargs): return type.__call__(*args, **kwargs) @classmethod def normal_constructor(cls, *args, **kwargs): return super(???).__call__(*args, **kwargs) # I'm not sure what should go in the super here (I'm using python3) @classmethod def normal_constructor(cls, *args, **kwargs): self = cls.__new__(cls) self.__init__(*args, **kwargs) return self On Wed, Nov 1, 2017 at 6:51 PM, Stefan Ram wrote: > Jason Maldonis writes: > >I was looking for documentation for what exactly `type.__call__` does so > >that I can emulate it, but I wasn't able to find any docs explicitly > >detailing what that method does. If someone knows where this info is that > >would be great too. > > Instances are callable if their class has a __call__ method. > > When an instance is called, this __call__ method will be called. > > main.py > > class example: > def __call__( this ): > print( 'called' ) > instance = example() > instance() > > transcript > > called > > The general contract of this method is that it can do > whatever the author of the class deems appropriate. > > What exectly this is has to be documented in the > documentation of each specific class. > > In fact, the attribute ?instance.__call__? has a ?__call__? > attribute itself, thus: > > main.py > > class example: > def __call__( this ): > print( 'called' ) > instance = example() > instance() > instance.__call__() > instance.__call__.__call__() > > transcript > > called > called > called > > A type also is an instance, so > > int.__call__(whatever) > > should do the same as > > int( whatever ) > > . In Python 2 they had > > operator.isCallable( obj ) > > , in Python 3 we can emulate this using > > hasattr( obj, '__call__' ) > > . > > -- > https://mail.python.org/mailman/listinfo/python-list > From steve+python at pearwood.info Wed Nov 1 20:24:59 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 02 Nov 2017 11:24:59 +1100 Subject: Code Snippets References: Message-ID: <59fa65de$0$18589$b1db1813$d948b532@news.astraweb.com> On Thu, 2 Nov 2017 04:25 am, Stefan Ram wrote: > I started to collect some code snippets: [...] > __import__( "random" ).random() > > And so on. You get the idea. > > However, reportedly, all those snippets are anti-patterns > because they use ?__import__?. Correct. Nearly all dunder functions and methods are reserved for use by the interpreter. It isn't an outright error to call __import__ directly, but you should avoid it unless absolutely necessary. [...] > What I'm supposed to do instead, I guess, is: [...] > import random > ... > random.random() > > Now, the user has to cut the import, paste it to the top > of his code, then go back to the list of snippets, find > the same snippet again, copy the expression, go to his code, > then find the point where he wanted to insert the snippet again, > and finally insert the snippet. The ellipsis do nothing, why are they there? And surely you are capable of copying two lines at a time. import random random.random() requires only one copy operation. There is no outright requirement to collect all the imports at the top of your module. That's merely a very good convention to follow. If you don't mind breaking the convention, you can simply paste the result where you want the random number: # code here # more code # paste here >> import random random.random() # and edit as needed This has saved you ten seconds of editing time while writing the code. It will probably cost you ten minutes, when you come back to maintain the program in six months and the imports are scattered all through the module, inside functions and classes, but that's your decision to make. > And still there now is a > risk of name collisions. So, it seems to me that __import__ > is just so much better! Only if you wish to write ugly, inefficient code. The idea of code snippets is that they are intended as *templates*, not that you repeat them over and over again. That would be the worst sort of copy and paste programming, an anti-pattern. If you need four random numbers, would you write this? a = __import__( "random" ).random() b = __import__( "random" ).random() c = __import__( "random" ).random() d = __import__( "random" ).random() Or a list of them? numbers = [__import__( "random" ).random() for i in range(1000)] Do I need to explain how terrible that code is? Code snippets are not an alternative to actually thinking about your code and writing the best code you can. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Nov 1 20:53:57 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 02 Nov 2017 11:53:57 +1100 Subject: Thread safety issue (I think) with defaultdict References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> Message-ID: <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> On Thu, 2 Nov 2017 05:53 am, Israel Brewster wrote: [...] > So the end result is that the thread that "updates" the dictionary, and the > thread that initially *populates* the dictionary are actually running in > different processes. If they are in different processes, that would explain why the second (non)thread sees an empty dict even after the first thread has populated it: # from your previous post > Length at get AC: 54 ID: 4524152200 Time: 2017-11-01 09:41:24.474788 > Length At update: 1 ID: 4524152200 Time: 2017-11-01 09:41:24.784399 > Length At update: 2 ID: 4524152200 Time: 2017-11-01 09:41:25.228853 You cannot rely on IDs being unique across different processes. Its an unfortunately coincidence(!) that they end up with the same ID. Or possibly there's some sort of weird side-effect or bug in Flask that, when it shares the dict between two processes (how?) it clears the dict. Or... have you considered the simplest option, that your update thread clears the dict when it is first called? Since you haven't shared your code with us, I cannot rule out a simple logic error like this: def launch_update_thread(dict): dict.clear() # code to start update thread > In fact, any given request could be in yet another > process, which would seem to indicate that all bets are off as to what data > is seen. > > Now that I've thought through what is really happening, I think I need to > re-architect things a bit here. Indeed. I've been wondering why you are using threads at all, since there doesn't seem to be any benefit to initialising the dict and updating it in different thread. Now I learn that your architecture is even more complex. I guess some of that is unavailable, due to it being a web app, but still. > For one thing, the update thread should be > launched from the main process, not an arbitrary UWSGI worker. I had > launched it from the client connection because there is no point in having > it running if there is no one connected, but I may need to launch it from > the __init__.py file instead. For another thing, since this dictionary will > need to be accessed from arbitrary worker processes, I'm thinking I may need > to move it to some sort of external storage, such as a redis database That sounds awful. What if the arbitrary worker decides to remove a bunch of planes from your simulation, or insert them? There should be one and only one way to insert or remove planes from the simulation (I **really** hope it is a simulation). Surely the right solution is to have the worker process request whatever information it needs, like "the next plane", and have the main process provide the data. Having worker processes have the ability to reach deep into the data structures used by the main program and mess with them seems like a good way to have mind-boggling bugs. > Oy, I made my life complicated :-) "Some people, when confronted with a problem, think, 'I know, I'll use threads. Nothew y htwo probave lems." :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Nov 1 21:06:05 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 02 Nov 2017 12:06:05 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> Message-ID: <59fa6f7e$0$18600$b1db1813$d948b532@news.astraweb.com> On Thu, 2 Nov 2017 08:12 am, Alexey Muranov wrote: > Hello, > > what do you think about the idea of replacing "`else`" with "`then`" in > the contexts of `for` and `try`? Yes, this, exactly!!! (For while and for loops, but not try -- see below.) I have argued this for many years. The current choice of "else" is painfully misleading, and it causes people (including myself) to wrongly guess that the "else" block runs only if the for/while block doesn't run at all: # This is wrong! for x in sequence: ... else: print("sequence is empty") The actually semantics of "else" is that the block is UNCONDITIONALLY run after the for/while loop completes, unless you jump out of the loop using return, raise or break. That makes it a "then" block, not "else". > It seems clear that it should be rather "then" than "else." Compare > also "try ... then ... finally" with "try ... else ... finally". I disagree about the try block though. The semantics of the try block are: try: A except: B else: C finally: D (1) code block A is attempted; (2) IF an exception occurs, jump to code block B; (3) otherwise (else), no exception occurs, so jump to code block C; (4) finally run code block D on your way out, regardless of which blocks are executed and how you exit them. So I think "else" is correct here. The else block only gets called if there is no exception. > Currently, with "else", it is almost impossible to guess the meaning > without looking into the documentation. It is worse than that: it is easy to guess the WRONG meaning, namely that the else block runs when the for/while loop doesn't execute at all (the for-loop sequence is empty, or the while-loop condition is initially false). > Off course, it should not be changed in Python 3, maybe in Python 4 or > 5, but in Python 3 `then` could be an alias of `else` in these contexts. Unfortunately, this is almost certainly not going to happen. It would require adding a new keyword, and unless Guido changes his mind, he doesn't think this change is worthwhile. If I were the BDFL, this would be the first change I make :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Nov 1 21:19:15 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 02 Nov 2017 12:19:15 +1100 Subject: Code Snippets References: Message-ID: <59fa7294$0$18584$b1db1813$d948b532@news.astraweb.com> On Thu, 2 Nov 2017 05:57 am, Stefan Ram wrote: > I also have heard that there was a module cache, so I > was hoping that a second import of the same module might > not be such an effort for the implementation. There is: sys.modules. Although `import spam` is cheap when spam is in the cache, its not free, and `__import__("spam")` is even less cheap (more costly). Its a function call, not a statement, so it requires a runtime name lookup and a function call on top of the same process of checking the cache and importing the module. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Nov 1 21:19:32 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 02 Nov 2017 12:19:32 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> Message-ID: <59fa733f$0$18611$b1db1813$d948b532@news.astraweb.com> On Thu, 2 Nov 2017 08:21 am, Chris Angelico wrote: > With the 'for' loop, > it's a bit more arguable, but I've never seen anything more than a > weak argument in favour of 'then' Thhpptpt! "else" is an completely inappropriate term that doesn't describe the semantics of the statement even a little bit. The argument that it means "else no break" is feeble because break is not the only way to exit the loop and therefore skip executing the else clause. It is not even necessarily the most common: I wouldn't be surprised if there were more returns out of the middle of a loop than breaks, although I wouldn't necessarily predict it either. If we spoke in ordinary English using "else" the way Python uses it for looping, we would say: "Shampoo your hair twice, ELSE apply conditioner and leave for five minutes before rinsing." "Boil the pasta until it is soft, ELSE drain it and mix in the sauce." -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Nov 1 21:21:59 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 02 Nov 2017 12:21:59 +1100 Subject: Code Snippets References: <87zi85btl5.fsf@bsb.me.uk> Message-ID: <59fa7337$0$18611$b1db1813$d948b532@news.astraweb.com> On Thu, 2 Nov 2017 08:02 am, Ben Bacarisse wrote: > ram at zedat.fu-berlin.de (Stefan Ram) writes: > >> Wolfgang Maier writes: >>>If you're worried bout having things on separate lines, you could write: >>>import os; os.getcwd() >>>,etc., which is actually saving a few characters :) >> >> Yes, but there still is the risk of the identifier ?os? >> already being used in the sorrounding code. While >> >> __import__( "os" ).getcwd() >> >> does not seem to "leak" names into the enclosing scope. > > Also it's an expression which may be important in your "quick and dirty" > scripts. No script is so quick or so dirty to justify calling __import__ with a string literal argument instead of import. We've all written quick and dirty throw-away scripts where we don't care too much about best practices. But this isn't so much less-than-best practices as worst-practices: optimizing to save a few seconds during the initial editing run, by using the copy-and-paste anti-pattern. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Nov 1 21:26:11 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 02 Nov 2017 12:26:11 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> Message-ID: <59fa7434$0$18588$b1db1813$d948b532@news.astraweb.com> On Thu, 2 Nov 2017 08:23 am, Ned Batchelder wrote: > Apart from the questions of backward compatibility etc (Python is > unlikely to ever go through another shift like the 2/3 breakage), are > you sure "then" is what you mean?? This won't print "end": > > for i in range(10): > print(i) > else: > print(end) You are neither the first nor the last person to have mistakenly understood the "else" clause to run only if the main loop does not. It is a common error. I've done it. And this demonstrates exactly why the choice of keyword is so poor. If somebody of your experience can misread it, I don't feel so bad about how long it too me to understand it when I was a newbie. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From bc at freeuk.com Wed Nov 1 21:33:58 2017 From: bc at freeuk.com (bartc) Date: Thu, 2 Nov 2017 01:33:58 +0000 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <59fa733f$0$18611$b1db1813$d948b532@news.astraweb.com> References: <1509570761.4585.0@smtp.gmail.com> <59fa733f$0$18611$b1db1813$d948b532@news.astraweb.com> Message-ID: <6CuKB.106160$M01.92541@fx32.am4> On 02/11/2017 01:19, Steve D'Aprano wrote: > On Thu, 2 Nov 2017 08:21 am, Chris Angelico wrote: > >> With the 'for' loop, >> it's a bit more arguable, but I've never seen anything more than a >> weak argument in favour of 'then' > > Thhpptpt! > > "else" is an completely inappropriate term that doesn't describe the semantics > of the statement even a little bit. The argument that it means "else no > break" is feeble because break is not the only way to exit the loop and > therefore skip executing the else clause. > > It is not even necessarily the most common: I wouldn't be surprised if there > were more returns out of the middle of a loop than breaks, although I > wouldn't necessarily predict it either. > > If we spoke in ordinary English using "else" the way Python uses it for > looping, we would say: > > "Shampoo your hair twice, ELSE apply conditioner and leave for five minutes > before rinsing." > > "Boil the pasta until it is soft, ELSE drain it and mix in the sauce." 1 Start boiling the pasta 2 Wait one minute 3 If it's not soft (some of us prefer al dente), repeat from step 2, else drain it From bc at freeuk.com Wed Nov 1 21:42:00 2017 From: bc at freeuk.com (bartc) Date: Thu, 2 Nov 2017 01:42:00 +0000 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <59fa6f7e$0$18600$b1db1813$d948b532@news.astraweb.com> References: <1509570761.4585.0@smtp.gmail.com> <59fa6f7e$0$18600$b1db1813$d948b532@news.astraweb.com> Message-ID: On 02/11/2017 01:06, Steve D'Aprano wrote: > On Thu, 2 Nov 2017 08:12 am, Alexey Muranov wrote: > >> Hello, >> >> what do you think about the idea of replacing "`else`" with "`then`" in >> the contexts of `for` and `try`? > > > Yes, this, exactly!!! > > (For while and for loops, but not try -- see below.) > > I have argued this for many years. The current choice of "else" is painfully > misleading, and it causes people (including myself) to wrongly guess that > the "else" block runs only if the for/while block doesn't run at all: > > > # This is wrong! > for x in sequence: > ... > else: > print("sequence is empty") > > > The actually semantics of "else" is that the block is UNCONDITIONALLY run > after the for/while loop completes, /If/ it completes, and /when/ it completes. Otherwise why bother with using 'else'? Just have the code immediately following the loop. And there are some circumstances where the 'else' part is never executed. But if people prefer a different keyword, then why not? I think 'then' can be used, without impacting its use as an identifier, because it will always be followed by ":". Of course you would need to allow both "else" and "then" for backwards compatibility. -- bartc From skip.montanaro at gmail.com Wed Nov 1 21:49:39 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 1 Nov 2017 20:49:39 -0500 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <59fa6f7e$0$18600$b1db1813$d948b532@news.astraweb.com> References: <1509570761.4585.0@smtp.gmail.com> <59fa6f7e$0$18600$b1db1813$d948b532@news.astraweb.com> Message-ID: I don't know. The word "then" doesn't connote different ways of exiting a loop to me ("else" doesn't really either, I will grant you that, but it's what we have). Here's how I would read things: - *while* some condition holds, execute the loop, possibly breaking out, *then* do some finishing work - *for* each element in some sequence, execute the loop, possibly breaking out, *then* do some finishing work In neither case does it seem to me that you execute the finishing work only if you break out of the loop, but not if the loop terminates when the while condition becomes false or the for loop's sequence is exhausted. You might consider that while/then or for/then actually reads too much like English, fooling you into interpreting it as English, opening you up to ambiguity. You might argue that "else" doesn't either, but it has the strangely nice property of actually being a bit clumsier to read, forcing the reader to learn and apply the precise rules of the programming language instead of infer the more ambiguous rules of English. Either way, we are down to two imperfect solutions, and have a case of tomato, tomahto, I think. If I was starting with a clean sheet of paper, I might put the raise and except keywords to work, and add a LoopExit exception: while some condition holds: blah blah blah if some other condition rears its ugly head: raise LoopExit blah blah blah except LoopExit: execute exceptional code English and other natural languages aren't precise enough to serve as programming languages. Neither are programming languages fluid enough that we can always expect them to read naturally. There will always be cases like this where there is no perfect solution. Other examples I can think of are the if/else expression added to the language relatively recently (never really reads well to me, though I agree it can be handy), or all the proposals for switch/case/computed goto statements which litter the Python PEP cemetery. The desire to add such a statement has been very strong at times (there is a powerful desire from a performance perspective to have something akin to C's switch statement), but nothing ever worked well enough to be accepted. Skip From ben.usenet at bsb.me.uk Wed Nov 1 21:50:28 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Thu, 02 Nov 2017 01:50:28 +0000 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fa6f7e$0$18600$b1db1813$d948b532@news.astraweb.com> Message-ID: <87zi85a1p7.fsf@bsb.me.uk> Steve D'Aprano writes: > On Thu, 2 Nov 2017 08:12 am, Alexey Muranov wrote: > >> what do you think about the idea of replacing "`else`" with "`then`" in >> the contexts of `for` and `try`? > > Yes, this, exactly!!! > > (For while and for loops, but not try -- see below.) > > I have argued this for many years. The current choice of "else" is painfully > misleading, and it causes people (including myself) to wrongly guess that > the "else" block runs only if the for/while block doesn't run at all: > > > # This is wrong! > for x in sequence: > ... > else: > print("sequence is empty") > > > The actually semantics of "else" is that the block is UNCONDITIONALLY run > after the for/while loop completes, unless you jump out of the loop using > return, raise or break. That makes it a "then" block, not "else". > > >> It seems clear that it should be rather "then" than "else." Compare >> also "try ... then ... finally" with "try ... else ... finally". > > I disagree about the try block though. The semantics of the try block are: > > try: > A > except: > B > else: > C > finally: > D > > (1) code block A is attempted; > > (2) IF an exception occurs, jump to code block B; > > (3) otherwise (else), no exception occurs, so jump to code block C; > > (4) finally run code block D on your way out, regardless of which blocks are > executed and how you exit them. > > > So I think "else" is correct here. The else block only gets called if there is > no exception. > > >> Currently, with "else", it is almost impossible to guess the meaning >> without looking into the documentation. > > It is worse than that: it is easy to guess the WRONG meaning, namely that the > else block runs when the for/while loop doesn't execute at all (the for-loop > sequence is empty, or the while-loop condition is initially false). > > >> Off course, it should not be changed in Python 3, maybe in Python 4 or >> 5, but in Python 3 `then` could be an alias of `else` in these contexts. > > Unfortunately, this is almost certainly not going to happen. It would require > adding a new keyword, and unless Guido changes his mind, he doesn't think > this change is worthwhile. Re-using finally would not need a new keyword and might be close enough in meaning. -- Ben. From rosuav at gmail.com Wed Nov 1 22:04:09 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Nov 2017 13:04:09 +1100 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <59fa733f$0$18611$b1db1813$d948b532@news.astraweb.com> References: <1509570761.4585.0@smtp.gmail.com> <59fa733f$0$18611$b1db1813$d948b532@news.astraweb.com> Message-ID: On Thu, Nov 2, 2017 at 12:19 PM, Steve D'Aprano wrote: > On Thu, 2 Nov 2017 08:21 am, Chris Angelico wrote: > >> With the 'for' loop, >> it's a bit more arguable, but I've never seen anything more than a >> weak argument in favour of 'then' > > Thhpptpt! > > "else" is an completely inappropriate term that doesn't describe the semantics > of the statement even a little bit. The argument that it means "else no > break" is feeble because break is not the only way to exit the loop and > therefore skip executing the else clause. > > It is not even necessarily the most common: I wouldn't be surprised if there > were more returns out of the middle of a loop than breaks, although I > wouldn't necessarily predict it either. I'd say that's plausible, partly because it's easier than messing around with the else clause. Sometimes, it's easier to just make another function so you can use 'return' as flow control. > If we spoke in ordinary English using "else" the way Python uses it for > looping, we would say: > > "Shampoo your hair twice, ELSE apply conditioner and leave for five minutes > before rinsing." You wouldn't use 'else' with a simple iteration loop like that - there's no difference between 'else' and simply having more code after the loop, unless you have a break. for _ in range(2): hair.shampoo() condition() sleep(300) > "Boil the pasta until it is soft, ELSE drain it and mix in the sauce." Except that the else keyword doesn't mean that. Here's the nearest I can come up with as an equivalent: while pot.water_level: pasta.boil() if pasta.is_soft(): break else: print("HELP! You boiled the pot dry!") The else clause happens if you don't break. If you break, you skip the rest of the loop - including the else. You could use "then" for this, and it would make sense, but not enough to create a new keyword, and DEFINITELY not enough to justify changing it now. Yes, there are arguments against calling this feature "else". But I stand by my assertion that there are none strong enough to justify a new keyword. ChrisA From jjmaldonis at gmail.com Wed Nov 1 23:11:54 2017 From: jjmaldonis at gmail.com (Jason Maldonis) Date: Wed, 1 Nov 2017 22:11:54 -0500 Subject: what exactly does type.__call__ do? In-Reply-To: References: Message-ID: Ok no worries then! Thanks for the tips. I might wait until tomorrow then until someone comes along who deals with metaclasses and alternate class constructors. In case you're curious, I'm doing two things that are relevant here, and I'll link the python3 cookbook examples that are super useful (I love that book): http://chimera.labs.oreilly.com/books/1230000000393/ch09. html#_discussion_155 and http://chimera.labs.oreilly.com/books/1230000000393/ch08.html#_solution_134 They explain things very well. Metaclasses are so useful when you hit a use case that they fit into. I don't often deal with multiple class constructors, so I'm a bit new to that territory and I'm trying to delve into the details of how python classes are constructed (namely, whether `type.__call__` does more than just call `cls.__new__` and `self.__init__`). Thanks for the help too. On Wed, Nov 1, 2017 at 8:49 PM, Stefan Ram wrote: > ram at zedat.fu-berlin.de (Stefan Ram) writes: > >|PyObject *meth = lookup_method(self, &PyId___call__); > ... > >|Call self as a function. > > Oh, I guess this might be what makes > > int(x) > > call > > int.__call__(x) > > . And all other instances of this metaclass. > > Let's try to overwrite it to call 'charles' instead. > > main.py > > class mymetaclass( type ): > def __call__( this, *args ): > this.charles( *args ) > > class myclass( metaclass=mymetaclass ): > def charles(): > print( "Charles" ) > > myclass() > > transcript > > Charles > > Ok, while I managed to make ?myclass? print ?Charles? > using a ?__call__? function of it's metaclass, I still > don't know what I am doing. This is the first time I > actually deal with the topic of metaclasses. I have not > yet read a text book chapter about them, so I'm still > in the dark like the Chinese in the Chinese room. > > -- > https://mail.python.org/mailman/listinfo/python-list > From steve+python at pearwood.info Thu Nov 2 01:04:05 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 02 Nov 2017 16:04:05 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fa6f7e$0$18600$b1db1813$d948b532@news.astraweb.com> <87zi85a1p7.fsf@bsb.me.uk> Message-ID: <59faa748$0$18588$b1db1813$d948b532@news.astraweb.com> On Thu, 2 Nov 2017 12:50 pm, Ben Bacarisse wrote: > Steve D'Aprano writes: > >> On Thu, 2 Nov 2017 08:12 am, Alexey Muranov wrote: >> >>> what do you think about the idea of replacing "`else`" with "`then`" in >>> the contexts of `for` and `try`? [...] > Re-using finally would not need a new keyword and might be close enough > in meaning. Reusing finally would be *completely* wrong. The semantics of `finally` is that it should be executed no matter[1] how you exit the previous block. E.g. if we write: try: return 1 finally: print("exiting") then "exiting" is printed. Replace the return with a raise, and the same applies. Reusing `finally` in for and while loops would imply the similar behaviour: for i in range(100): return i finally: print("exiting") should print "exiting", when in fact it does not. Likewise if you replace the return with a break. [1] Within the bounds of normal processing. There are ways to halt Python without executing any subsequent code, namely os._exit, and os.abort dumps core to exit immediately. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Thu Nov 2 01:28:05 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 02 Nov 2017 16:28:05 +1100 Subject: what exactly does type.__call__ do? References: Message-ID: <59faace7$0$14949$b1db1813$d948b532@news.astraweb.com> On Thu, 2 Nov 2017 10:13 am, Jason Maldonis wrote: > Hi everyone, > > I want to use a metaclass to override how class instantiation works. I've > done something analogous to using the Singleton metaclass from the Python3 > Cookbook example. In my opinion, nine times out of ten, using a metaclass for something like that is overkill. (And that's putting aside the fact that 999 out of a thousand, using a Singleton is the wrong solution, no matter what the question is.) > However, I want to provide a classmethod that allows for "normal" class > instantiation that prevents this metaclass from being used. To me, that strongly suggests that a metaclass is the wrong solution. > To do that, I think I just make a @classmethod constructor function. > However, I can imagine a few different ways of writing this: > > @classmethod > def normal_constructor(cls, *args, **kwargs): > return type.__call__(*args, **kwargs) Untested, but I think that should be: return type.__call__(cls, *args, **kwargs) > @classmethod > def normal_constructor(cls, *args, **kwargs): > return super(???).__call__(*args, **kwargs) # I'm not sure what should > go in the super here (I'm using python3) > > @classmethod > def normal_constructor(cls, *args, **kwargs): > self = cls.__new__(cls) > self.__init__(*args, **kwargs) > return self > > Is one of these correct? Or do they all do the same thing? None of them look "correct", they all look "weird and scary" :-) If I had to pick one of these three -- and I hope that I would not -- I'd pick the first one. > I was looking for documentation for what exactly `type.__call__` does so > that I can emulate it, And then if type.__call__ changes, your emulation will be wrong. > but I wasn't able to find any docs explicitly > detailing what that method does. If someone knows where this info is that > would be great too. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From noah-list at enabled.com Thu Nov 2 02:50:45 2017 From: noah-list at enabled.com (Noah) Date: Wed, 1 Nov 2017 23:50:45 -0700 Subject: install on host not connected to the internet and no local proxy Message-ID: Hi, I am trying to install a python package with about 80 dependencies on a server that is not connected to the internet and has no local proxy. I can ssh to it via VPN. I was able to find python bundle and download the tarballs for all the main python package and all the tarballs for the subsequent dependencies. They reside in the same directory on the isolated server. Does anybody have some recommendations on how to install the main package and that process triggers the installation of all the dependencies from their corresponding tar.gz file? I cant seem to figure out how to do that easily with pip. Cheers From dieter at handshake.de Thu Nov 2 02:56:50 2017 From: dieter at handshake.de (dieter) Date: Thu, 02 Nov 2017 07:56:50 +0100 Subject: right list for SIGABRT python binary question ? References: <59e5570a$0$14952$b1db1813$d948b532@news.astraweb.com> <20171017073043.piszqyu7dsqo55eu@hermes.hilbert.loc> <20171018114358.fzj4vvsyzrf6rihu@hermes.hilbert.loc> <47a09a35-f929-528f-3110-8d660e6fb46f@tjol.eu> <20171019172745.76i3lltjtck2m5gw@hermes.hilbert.loc> <20171019174907.iqgznoroyieipend@hermes.hilbert.loc> <87y3o5gdn9.fsf@handshake.de> <20171023122312.uupsxzhdwat3stt7@hermes.hilbert.loc> <87lgjq5rz9.fsf@handshake.de> <20171101092753.tfcvckzaezunxnej@hermes.hilbert.loc> Message-ID: <871slhyxql.fsf@handshake.de> Karsten Hilbert writes: >> >> It points to a memory corruption. >> >> The i386/x64 architecture supports memory access breakpoints >> and GDB, too, has support for this. You know the address which >> gets corrupted. Thus, the following apporach could have a chance >> to succeed: >> >> Put a "memory write" breakpoint on the address which gets corrupted. >> this should stop the program each time this address is written; >> Check then the backtrace. As the address forms part of the >> address block prologue, it should only be accessed from >> Python's "malloc" (and "free") implementation. Any other access >> indicates bad behaviour. > > I understand. Thank you for the explanation. This may seem > like a dumb question: the actual address that gets corrupted > varies from run to run (it may be the same "place" in the > code but that place gets put at a different address each > run). That's sad. It is a long time ago (more than 10 years) that I had to analyse such a kind of memory corruption. Fortunately, in my case, the address was stable accross runs. Likely, ASLR was not yet used by that time on a standard Linux platform. Maybe, you find a way to disable ASLR. If ASLR is the cause of the randomness, it might also be possible to compute the new address. More on this later. In another message, you reported how you tried to obtain an invariant for the affected address by using "info symbol". I have not much hope that this will succeed: It is most likely, that the corrupted memory block is part of the heap (in may also be a stack block, wrongly freed; this would be a local error - and easily detectable from the traceback). If you use "info symbol" on a heap address, you get not very reliable information - especially, if ASLR is in effect (which randomizes the various process segments and the heap blocks independently from one another). Back to an approach how to maybe compute the corrupted address for a new run. The approach assumes a heap address and uses that "mallog" (and friends) request large (which means hopefully few) memory blocks from the OS which are then split into smaller blocks internally. You can then catalog the large memory block requests and determine the index of the block and the corrupted offset. In a following run, you determine the new base address of this block and apply the same offset to find the corrupted address. Of cause, this assumes that your application is totally deterministic (apart from maybe ASLR). From rosuav at gmail.com Thu Nov 2 03:09:34 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Nov 2017 18:09:34 +1100 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fa6f7e$0$18600$b1db1813$d948b532@news.astraweb.com> Message-ID: On Thu, Nov 2, 2017 at 12:42 PM, bartc wrote: > But if people prefer a different keyword, then why not? I think 'then' can > be used, without impacting its use as an identifier, because it will always > be followed by ":". Of course you would need to allow both "else" and "then" > for backwards compatibility. No, it can't. Contextually-sensitive keywords are a road to major confusion. It's been done before, but usually (always?) as a migration plan towards full keyword status; most recently, 'async' and 'await' were brought in that way: Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170118] on linux Type "help", "copyright", "credits" or "license" for more information. >>> async def foo(): ... pass ... >>> async = 1 >>> Python 3.7.0a2+ (heads/master:4f469c0966, Nov 2 2017, 18:04:12) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. >>> async def foo(): ... pass ... >>> async = 1 File "", line 1 async = 1 ^ SyntaxError: invalid syntax >From Python 3.4 to Python 3.7, async changes from being an identifier to being a keyword. The only reason it's a "soft keyword" for 3.5 and 3.6 is for the sake of transition - it's not a means of avoiding the costs of keyword creation. The proposal for async functions had to justify the creation of two keywords. Additionally, the notion of having both "else" and "then" is even worse: everyone has to learn BOTH keywords, and figure out when to use each. For compatibility with older Python versions, most people will use "else", but some will go with "then" because it's the new and trendy option. Ugh. I deal with this sort of thing in JavaScript. I don't want to have it in Python too. ChrisA From rosuav at gmail.com Thu Nov 2 03:17:44 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Nov 2017 18:17:44 +1100 Subject: install on host not connected to the internet and no local proxy In-Reply-To: References: Message-ID: On Thu, Nov 2, 2017 at 5:50 PM, Noah wrote: > Hi, > > I am trying to install a python package with about 80 dependencies on a > server that is not connected to the internet and has no local proxy. I can > ssh to it via VPN. > > I was able to find python bundle and download the tarballs for all the main > python package and all the tarballs for the subsequent dependencies. They > reside in the same directory on the isolated server. > > Does anybody have some recommendations on how to install the main package > and that process triggers the installation of all the dependencies from > their corresponding tar.gz file? I cant seem to figure out how to do that > easily with pip. Hmm. The first thing that comes to my mind is a virtual environment. I'm assuming here that you have a local system that has the same CPU architecture and Python as the main server, and which *does* have an internet connection; if that's not the case, it'll be more complicated. But in theory, this should work: local$ python3 -m venv env local$ source env/bin/activate local$ pip install -r requirements.txt At this point, you have a directory called "env" which contains all the packages listed in your requirements.txt file (you DO have one of those, right?) and everything those packages depend on. Then SSH to your server, and set up an equivalent environment: server$ python3 -m venv env server$ source env/bin/activate Copy in the contents of env/lib/pythonX.Y/site-packages (where X.Y is your Python version, eg python3.7 on my system), and then try importing stuff. In theory, you should be able to load everything in just fine. If that doesn't work, you might have to manually run setup.py for each of your eighty dependencies, and possibly all of their dependencies too. I'd definitely try the venv transfer before going to that level of tedium. ChrisA From alexey.muranov at gmail.com Thu Nov 2 04:04:03 2017 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Thu, 02 Nov 2017 09:04:03 +0100 Subject: replacing `else` with `then` in `for` and `try` Message-ID: <1509609843.5503.0@smtp.gmail.com> On Thu, 2017-11-02 at 08:29 +1100, Chris Angelico wrote: > > On Thu, Nov 2, 2017 at 8:23 AM, Ned Batchelder > > > wrote: >> > > >> > > >> > > Apart from the questions of backward compatibility etc (Python is >> > > unlikely >> > > to ever go through another shift like the 2/3 breakage), are you >> > > sure "then" >> > > is what you mean? This won't print "end": >> > > >> > > for i in range(10): >> > > print(i) >> > > else: >> > > print(end) > > > > Well, it'll bomb with NameError when it tries to look up the *name* > > end. But it will run that line of code - if you quote it, it will > > work. You see how people are confused over "for ... else". Alexey. From alexey.muranov at gmail.com Thu Nov 2 04:05:36 2017 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Thu, 02 Nov 2017 09:05:36 +0100 Subject: replacing `else` with `then` in `for` and `try` Message-ID: <1509609936.5503.1@smtp.gmail.com> On Wed, 2017-11-01 at 21:30 +0000, Stefan Ram wrote: > > > > In languages like Algol 68, ?then? is used for a clause > > that is to be executed when the main condition of an > > if-statement /is/ true, so this might cause some confusion. > > sure, and `else` is used for a clause that is to be executed when the main condition of `if` is false. So, in try: do_something except: catch_exception else: continue_doing_something when no exception occurs in `do_something`, is `do_something` more true, or more false? Alexey. From tjreedy at udel.edu Thu Nov 2 04:14:15 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 2 Nov 2017 04:14:15 -0400 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <1509570761.4585.0@smtp.gmail.com> References: <1509570761.4585.0@smtp.gmail.com> Message-ID: On 11/1/2017 5:12 PM, Alexey Muranov wrote: > what do you think about the idea of replacing "`else`" with "`then`" in > the contexts of `for` and `try`? This idea has been argued to death more than once before. I am opposed on both logical and practical grounds, but will not repeat myself for the fourth or fifth time. -- Terry Jan Reedy From alexey.muranov at gmail.com Thu Nov 2 04:21:51 2017 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Thu, 02 Nov 2017 09:21:51 +0100 Subject: replacing `else` with `then` in `for` and `try` Message-ID: <1509610911.5945.0@smtp.gmail.com> On Thu, 2017-11-02 at 08:21 +1100, Chris Angelico wrote: > > > > > With try/except/else, it's "do this, and if an exception happens, do > this, else do this". So else makes perfect sense. Indeed, i forgot about `except`. I agree that "try/then/except/finally" would be better than "try/except/then/finally", but "try/except/else/finally" does not make a perfect sense IMHO. Alexey. From rosuav at gmail.com Thu Nov 2 04:29:51 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Nov 2017 19:29:51 +1100 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <1509609936.5503.1@smtp.gmail.com> References: <1509609936.5503.1@smtp.gmail.com> Message-ID: On Thu, Nov 2, 2017 at 7:05 PM, Alexey Muranov wrote: > On Wed, 2017-11-01 at 21:30 +0000, Stefan Ram wrote: >> >> > >> > In languages like Algol 68, ?then? is used for a clause >> > that is to be executed when the main condition of an >> > if-statement /is/ true, so this might cause some confusion. >> > > > > sure, and `else` is used for a clause that is to be executed when the main > condition of `if` is false. > > So, in > > try: > do_something > except: > catch_exception > else: > continue_doing_something > > when no exception occurs in `do_something`, is `do_something` more true, or > more false? It's neither. It didn't happen. That's the whole point of exceptions - they aren't about normal flow and normal values, they are fundamentally different. But if you like, consider this kind of model: caught_exception = catch {{{ do_something }}} if caught_exception is not None: handle_exception else: continue_doing_something The caught exception is either a thing, or not a thing. ChrisA From steve+python at pearwood.info Thu Nov 2 06:04:10 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 02 Nov 2017 21:04:10 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fa6f7e$0$18600$b1db1813$d948b532@news.astraweb.com> Message-ID: <59faed9c$0$18566$b1db1813$d948b532@news.astraweb.com> On Thu, 2 Nov 2017 12:49 pm, Skip Montanaro wrote: > I don't know. The word "then" doesn't connote different ways of exiting a > loop to me ("else" doesn't really either, I will grant you that, but it's > what we have). Here's how I would read things: > > - *while* some condition holds, execute the loop, possibly breaking out, > *then* do some finishing work > - *for* each element in some sequence, execute the loop, possibly > breaking out, *then* do some finishing work And that is exactly the behaviour of the for...else and while...else construct. You're reading it correctly. When you say "possibly breaking out", I assume you mean breaking out of the *entire* compound statement, because the alternative would be just silly. The alternative would be exactly equivalent to just following the loop with some unindented code: while condition: block # on break we jump to here finishing In that case, it makes no sense to include a do-nothing "else" or "then" keyword. To put it another way, if we are trying to infer the semantics of a statement, and can interpret it in one of two ways: - it does something - it does nothing then (with special case) of `pass`, we should always assume the first case, thus resolving the ambiguity in favour of "Guido isn't an idiot who added a pointless keyword" :-) > In neither case does it seem to me that you execute the finishing work only > if you break out of the loop, but not if the loop terminates when the while > condition becomes false or the for loop's sequence is exhausted. If I'm reading you correctly, I think you are confused about the `else` clause. It is incorrect to say that the `else` clause runs "only if you break out of the loop" (as you say). The `else` clause runs *after* the loop completes, but NOT if you jump out with break/return/raise. If we don't jump out of the loop, the else block is equivalent to just following the loop with unindented code: for x in sequence: block else: follows is equivalent to: for x in sequence: block follows Hence, in the absence of any early exit from the loop, the `else` block behaves more like an *then* rather than an "else". The behaviour of `else` confused me utterly until I realised that the semantics of the compound for...else was the loop to execute, then the `else` block. So why even bother with `else`? Unlike the second case, the `else` block is part for the compound for/while statement. And so `break` doesn't just exit the loop, it exits the whole compound statement, jumping past the `else`: for x in sequence: block else: follows # break jumps to here more code The motive for allowing this pattern is described here: https://shahriar.svbtle.com/pythons-else-clause-in-loops > You might > consider that while/then or for/then actually reads too much like English, > fooling you into interpreting it as English, opening you up to ambiguity. If you interpret it as English, it works fine. You run the loop, then you run the "then" clause. If you jump out of the loop (whether by return, raise or break) you jump out of the *entire* statement, not just the loop part. There's no ambiguity because we can assume Guido wouldn't introduce a pointless block keyword that does literally nothing except require an indent. > You might argue that "else" doesn't either, but it has the strangely nice > property of actually being a bit clumsier to read, forcing the reader to > learn and apply the precise rules of the programming language instead of > infer the more ambiguous rules of English. If only that were true... There's a simple, obvious, but sadly WRONG plain English interpretation of for...else, namely that the `else` clause runs if the for sequence was empty: for x in L: pass else: # This is wrong! print("L is empty") and similar for while. That lead me astray for the longest time! And I'm not the only one. > English and other natural languages aren't precise enough to serve as > programming languages. Hmmm... I think Hypertalk might have something to say about that. And Inform7 I think would laugh in your face :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Thu Nov 2 06:10:39 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 02 Nov 2017 21:10:39 +1100 Subject: A use-case for for...else with no break Message-ID: <59faef21$0$18601$b1db1813$d948b532@news.astraweb.com> Occasionally it is useful to loop over a bunch of stuff in the interactive interpreter, printing them as you go on a single line: for x in something(): print(x, end='') If you do that, the prompt overwrites your output, and you get a mess: py> for x in "abcdefgh": ... print(x, end='') ... py> efghpy> "For ... else" to the rescue! py> for char in "abcdefgh": ... print(char, end='') ... else: ... print() ... abcdefgh py> -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From p.f.moore at gmail.com Thu Nov 2 06:24:08 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 2 Nov 2017 10:24:08 +0000 Subject: install on host not connected to the internet and no local proxy In-Reply-To: References: Message-ID: On 2 November 2017 at 07:17, Chris Angelico wrote: > On Thu, Nov 2, 2017 at 5:50 PM, Noah wrote: >> Hi, >> >> I am trying to install a python package with about 80 dependencies on a >> server that is not connected to the internet and has no local proxy. I can >> ssh to it via VPN. >> >> I was able to find python bundle and download the tarballs for all the main >> python package and all the tarballs for the subsequent dependencies. They >> reside in the same directory on the isolated server. >> >> Does anybody have some recommendations on how to install the main package >> and that process triggers the installation of all the dependencies from >> their corresponding tar.gz file? I cant seem to figure out how to do that >> easily with pip. > > Hmm. The first thing that comes to my mind is a virtual environment. > I'm assuming here that you have a local system that has the same CPU > architecture and Python as the main server, and which *does* have an > internet connection; if that's not the case, it'll be more > complicated. But in theory, this should work: > > local$ python3 -m venv env > local$ source env/bin/activate > local$ pip install -r requirements.txt > > At this point, you have a directory called "env" which contains all > the packages listed in your requirements.txt file (you DO have one of > those, right?) and everything those packages depend on. Then SSH to > your server, and set up an equivalent environment: > > server$ python3 -m venv env > server$ source env/bin/activate > > Copy in the contents of env/lib/pythonX.Y/site-packages (where X.Y is > your Python version, eg python3.7 on my system), and then try > importing stuff. In theory, you should be able to load everything in > just fine. > > If that doesn't work, you might have to manually run setup.py for each > of your eighty dependencies, and possibly all of their dependencies > too. I'd definitely try the venv transfer before going to that level > of tedium. Alternatively, you can do (on your internet-connected system) mkdir wheels pip wheel --wheel-directory wheels -r requirements.txt This will create a set of .whl files in the directory "wheels". You can copy that directory to the target machine and (assuming the two machines do have the same architecture/OS) on that machine do pip install --no-index --find-links wheels -r requirements.txt This will tell pip to not use PyPI (and so not need the internet) and to satisfy the requirements using only the wheel files in the "wheels" directory. Paul From steve+python at pearwood.info Thu Nov 2 06:25:25 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 02 Nov 2017 21:25:25 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fa6f7e$0$18600$b1db1813$d948b532@news.astraweb.com> <59faed9c$0$18566$b1db1813$d948b532@news.astraweb.com> Message-ID: <59faf296$0$18567$b1db1813$d948b532@news.astraweb.com> On Thu, 2 Nov 2017 09:04 pm, Steve D'Aprano wrote: > then (with special case) of `pass` That should read "then except for the special case of `pass`". Sorry. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ben.usenet at bsb.me.uk Thu Nov 2 07:09:53 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Thu, 02 Nov 2017 11:09:53 +0000 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fa6f7e$0$18600$b1db1813$d948b532@news.astraweb.com> <87zi85a1p7.fsf@bsb.me.uk> <59faa748$0$18588$b1db1813$d948b532@news.astraweb.com> Message-ID: <87mv459bsu.fsf@bsb.me.uk> Steve D'Aprano writes: > On Thu, 2 Nov 2017 12:50 pm, Ben Bacarisse wrote: > >> Steve D'Aprano writes: >> >>> On Thu, 2 Nov 2017 08:12 am, Alexey Muranov wrote: >>> >>>> what do you think about the idea of replacing "`else`" with "`then`" in >>>> the contexts of `for` and `try`? > [...] >> Re-using finally would not need a new keyword and might be close enough >> in meaning. > > Reusing finally would be *completely* wrong. > > The semantics of `finally` is that it should be executed no matter[1] how you > exit the previous block. E.g. if we write: > > > try: > return 1 > finally: > print("exiting") > > > then "exiting" is printed. Replace the return with a raise, and the same > applies. Reusing `finally` in for and while loops would imply the similar > behaviour: > > > for i in range(100): > return i > finally: > print("exiting") > > > should print "exiting", when in fact it does not. Likewise if you replace the > return with a break. Sure, but your argument seemed to that else has entirely the wrong meaning (I certainly to a double take when I have to remember what it means) and, in that context, finally has a meaning closer to what you want. The problem that it carries different meanings when added to different statements is already the case with else -- it's an alternative to an if and not an alternative to a loop. -- Ben. From Megan.Hinds at experian.com Thu Nov 2 07:17:39 2017 From: Megan.Hinds at experian.com (Hinds, Megan) Date: Thu, 2 Nov 2017 11:17:39 +0000 Subject: Python Packages Error - Unresolved Message-ID: Hi there, I was hoping you could help, as I have tried many different websites on this query and even asked the question on stackflow. I have tried many different types of commands in command prompt with the same error. I have recently installed Python 3.6. The 32 bit installation (automatically downloaded to this). I have set the correct environment path variables: C:\Users\MH\AppData\Local\Programs\Python\Python36-32;C:\Users\MH\AppData\Local\Programs\Python\Python36-32\Scripts; I am on a work laptop with admin rights. A few days ago I could install python packages using the following command in command prompt (in python36-32 directory): pip install -index-url=http://pypi.python.org/simple -trusted-host pypi.python.org pandas I managed to install pillow, cx_Oracle, and a few others previously. But not pandas and others (see attached file). I was thinking to move on to anaconda, however, I may see the same error in installing packages in there (Oracle related packaged that are not in conda). I would be very grateful for any help. Thanks, Megan Hinds Information in this e-mail and any attachments is confidential, and may not be copied or used by anyone other than the addressee, nor disclosed to any third party without our permission. There is no intention to create any legally binding contract or other binding commitment through the use of this electronic communication unless it is issued in accordance with the Experian Limited standard terms and conditions of purchase or other express written agreement between Experian Limited and the recipient. Although Experian has taken reasonable steps to ensure that this communication and any attachments are free from computer viruses, you are advised to take your own steps to ensure that they are actually virus free. Experian Ltd is authorised and regulated by the Financial Conduct Authority. Companies Act information: Registered name: Experian Limited. Registered office: The Sir John Peace Building, Experian Way, NG2 Business Park, Nottingham, NG80 1ZZ, United Kingdom. Place of registration: England and Wales. Registered number: 653331. From steve+python at pearwood.info Thu Nov 2 07:21:44 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 02 Nov 2017 22:21:44 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fa6f7e$0$18600$b1db1813$d948b532@news.astraweb.com> <87zi85a1p7.fsf@bsb.me.uk> <59faa748$0$18588$b1db1813$d948b532@news.astraweb.com> <87mv459bsu.fsf@bsb.me.uk> Message-ID: <59faffc9$0$18606$b1db1813$d948b532@news.astraweb.com> On Thu, 2 Nov 2017 10:09 pm, Ben Bacarisse wrote: > Sure, but your argument seemed to that else has entirely the wrong > meaning (I certainly to a double take when I have to remember what it > means) and, in that context, finally has a meaning closer to what you > want. That's an argument about whether "yellow" or "purple" is closer in meaning to the word we actually want, "spicy" :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From dvl at psu.edu Thu Nov 2 07:24:07 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Thu, 2 Nov 2017 07:24:07 -0400 Subject: Reading a remove csv file In-Reply-To: mailman.31.1509552004.16197.python-list@python.org References: Message-ID: <1509621847l.38011130l.0l@psu.edu> Just a quick question on how best to read a remote CSV file. So far, I tried: filelink = urllib.request.urlopen(path) dictread = csv.DictReader(filelink) for row in dictread: ... But I'm running into the difference between strings and bytes. I'd like to squeeze a note that talks about the utf-8 encoding, but although I find that as an option for a local file (with open()) I did not see that on my first glance at the two functions above. Is there an easy way to read a remove CSV file with utf-8 encoding without copying the whole file locally first? Roger Christman Pennsylvania State University From Karsten.Hilbert at gmx.net Thu Nov 2 07:26:16 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Thu, 2 Nov 2017 12:26:16 +0100 Subject: right list for SIGABRT python binary question ? In-Reply-To: References: <20171018114358.fzj4vvsyzrf6rihu@hermes.hilbert.loc> <47a09a35-f929-528f-3110-8d660e6fb46f@tjol.eu> <20171019172745.76i3lltjtck2m5gw@hermes.hilbert.loc> <20171019174907.iqgznoroyieipend@hermes.hilbert.loc> <87y3o5gdn9.fsf@handshake.de> <20171023122312.uupsxzhdwat3stt7@hermes.hilbert.loc> <87lgjq5rz9.fsf@handshake.de> <20171101092753.tfcvckzaezunxnej@hermes.hilbert.loc> Message-ID: <20171102112616.ifbrfwrcvjibed66@hermes.hilbert.loc> On Wed, Nov 01, 2017 at 04:28:02PM +0000, Grant Edwards wrote: > >>I understand. Thank you for the explanation. This may seem > >>like a dumb question: the actual address that gets corrupted > >>varies from run to run (it may be the same "place" in the > > > > Since the process virtual memory space should be the same on each run > > Not with modern OS kernels: > > https://en.wikipedia.org/wiki/Address_space_layout_randomization I feared as much. However, I discovered that during subsequent runs the address seems stable due to shared libraries being preloaded: On the first run the affected code is loaded at some randomized address and the corruption is hit at a certain address giving me the value to watch on during subsequent runs, as long as the affected code is not evicted from being preloaded the address is stable. I have posted backtraces taken from the address being watched. Does that help any at all ? Thanks, Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 From sayalitip at gmail.com Thu Nov 2 07:32:58 2017 From: sayalitip at gmail.com (sayalitip at gmail.com) Date: Thu, 2 Nov 2017 04:32:58 -0700 (PDT) Subject: Rise of Iot Application Has Opened a Potential Avenue of Application for Mobility Sharing Market 2025 Message-ID: <2cf7882e-0465-4ac1-bf7b-8cdfebb72323@googlegroups.com> FREE| Sample Copy is available at https://tinyurl.com/ybhr3gaj Mobility sharing is a term that is used to describe the transportation services that are shared among users. This includes public transit, taxis and limos, bike sharing, car sharing, ride sharing, scooter sharing, shuttle services among others. Increasing demographics is one of the major driver for the growth of the mobility sharing market.Consumer culture and scarce of resources are some of the factors that are driving the growth of these market in the coming years. Some of the key players influencing the market are Robert Bosch GmbH, Uber Technologies Inc., Spinlister, Lyft, Tamyca GmbH, Delphi Automotive GmbH, Denso Corporation, Intel Corporation, Tomtom NV and Didi Chuxing. From alberto at metapensiero.it Thu Nov 2 07:45:30 2017 From: alberto at metapensiero.it (Alberto Berti) Date: Thu, 02 Nov 2017 12:45:30 +0100 Subject: A use-case for for...else with no break References: <59faef21$0$18601$b1db1813$d948b532@news.astraweb.com> Message-ID: <87wp38j44l.fsf@ender.lizardnet> >>>>> "Steve" == Steve D'Aprano writes: py> for x in "abcdefgh": Steve> ... print(x, end='') Steve> ... py> efghpy> Steve> "For ... else" to the rescue! py> for char in "abcdefgh": Steve> ... print(char, end='') Steve> ... else: Steve> ... print() Steve> ... Steve> abcdefgh py> else doesn't seem to bring any advantage over: for char in "abcdefgh": print(char, end='') print() From wolfgang.maier at biologie.uni-freiburg.de Thu Nov 2 07:56:43 2017 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Thu, 2 Nov 2017 12:56:43 +0100 Subject: A use-case for for...else with no break In-Reply-To: <87wp38j44l.fsf@ender.lizardnet> References: <59faef21$0$18601$b1db1813$d948b532@news.astraweb.com> <87wp38j44l.fsf@ender.lizardnet> Message-ID: On 11/02/2017 12:45 PM, Alberto Berti wrote: >>>>>> "Steve" == Steve D'Aprano writes: > > py> for x in "abcdefgh": > Steve> ... print(x, end='') > Steve> ... > py> efghpy> > > > Steve> "For ... else" to the rescue! > > py> for char in "abcdefgh": > Steve> ... print(char, end='') > Steve> ... else: > Steve> ... print() > Steve> ... > Steve> abcdefgh > py> > > else doesn't seem to bring any advantage over: > > for char in "abcdefgh": > print(char, end='') > print() > Try running it interactively and you'll see, wolfgang From ben.usenet at bsb.me.uk Thu Nov 2 08:09:32 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Thu, 02 Nov 2017 12:09:32 +0000 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fa6f7e$0$18600$b1db1813$d948b532@news.astraweb.com> <87zi85a1p7.fsf@bsb.me.uk> <59faa748$0$18588$b1db1813$d948b532@news.astraweb.com> <87mv459bsu.fsf@bsb.me.uk> <59faffc9$0$18606$b1db1813$d948b532@news.astraweb.com> Message-ID: <87efpganlv.fsf@bsb.me.uk> Steve D'Aprano writes: > On Thu, 2 Nov 2017 10:09 pm, Ben Bacarisse wrote: > >> Sure, but your argument seemed to that else has entirely the wrong >> meaning (I certainly to a double take when I have to remember what it >> means) and, in that context, finally has a meaning closer to what you >> want. > > That's an argument about whether "yellow" or "purple" is closer in meaning to > the word we actually want, "spicy" :-) I note the smiley, but it was in fact an argument that "finally" is closer to "and afterwards" than "else" is :-) -- Ben. From rhodri at kynesim.co.uk Thu Nov 2 08:18:41 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 2 Nov 2017 12:18:41 +0000 Subject: Code Snippets In-Reply-To: References: Message-ID: On 01/11/17 18:57, Stefan Ram wrote: > Ned Batchelder writes: >> You should not optimize for the shortest time to paste a line of code.? >> You should take time and care writing your code, so that it reads best >> and runs best.?? If you needed another os function, would you have two >> __import__("os") in your code? Ugh. > > I make a distinction between two kinds of code: > > 1.) Quick-and-dirty code (rapid prototyping) > > One just wants to find out something using Python code. > The code might be written into the Shell and not be saved, > or only be saved temporarily. For example, what the sum of > 5412 and 2141 is, or whether an idea for a program code > works at all. > > The snippets are also intended for such code. > > 2.) Library-grade code > > This is code that might be around for a longer time and > might be maintained in the future. It even is possible that > it will become part of a library. > > It is possible that qnd-code might evolve into lg-code. > In this case, it is still possible to remove all ?__imports__?. > > Your comments might apply more to lg-code than to qnd-code. The bad thing here is that you are training yourself in a coding style (quick and dirty) that ought to be rejected in any code that isn't completely ephemeral. And in my experience, most "throw-away" code isn't thrown away. -- Rhodri James *-* Kynesim Ltd From alberto at metapensiero.it Thu Nov 2 08:19:10 2017 From: alberto at metapensiero.it (Alberto Berti) Date: Thu, 02 Nov 2017 13:19:10 +0100 Subject: A use-case for for...else with no break References: <59faef21$0$18601$b1db1813$d948b532@news.astraweb.com> <87wp38j44l.fsf@ender.lizardnet> Message-ID: <87shdwj2kh.fsf@ender.lizardnet> >>>>> "Wolfgang" == Wolfgang Maier writes: Wolfgang> Try running it interactively and you'll see, Wolfgang> wolfgang I've tried but my muscolar memory failed me... i've issued a C-c C-c that usually would have sent the region of text to the interpreter session (when done from python-mode opened files in emacs) but instead i was in gnus and it sent the half prepared email :-) From tjandacw at cox.net Thu Nov 2 08:28:49 2017 From: tjandacw at cox.net (Tim Williams) Date: Thu, 2 Nov 2017 05:28:49 -0700 (PDT) Subject: matplot plot hangs In-Reply-To: References: Message-ID: On Wednesday, November 1, 2017 at 6:30:27 PM UTC-4, Andrew Z wrote: > nope. it doesnt: > > I added print-s after each line and that produced: > [az at hp src]$ cat ./main1.py > import matplotlib.pyplot as plt > print("imported") > plt.plot([1,2,4,1]) > print("plot is done") > plt.show() > print("show is done") > > [az at hp src]$ python3.5 ./main1.py > imported > ^C^Z > [1]+ Stopped python3.5 ./main1.py > > > On Wed, Nov 1, 2017 at 9:31 AM, Vlastimil Brom > wrote: > > > 2017-11-01 13:49 GMT+01:00 Andrew Z : > > > Wolfgang, > > > I tried to ran from ide with no rwsults, so now im trying from a > > terminal > > > in xwindow. > > > The .plot is the last line in the script and it does hang trying to > > execute > > > it. > > > > > > > > > On Nov 1, 2017 05:44, "Wolfgang Maier" < > > > wolfgang.maier at biologie.uni-freiburg.de> wrote: > > > > > > On 01.11.2017 00:40, Andrew Z wrote: > > > > > >> hello, > > >> learning python's plotting by using matplotlib with python35 on > > fedora 24 > > >> x86. > > >> > > >> Installed matplotlib into user's directory. > > >> tk, seemed to work - > > >> http://www.tkdocs.com/tutorial/install.html#installlinux - the window > > >> shows > > >> up just fine. > > >> but when trying to run the simple plot ( > > >> https://matplotlib.org/examples/pylab_examples/simple_plot.html) the > > >> script > > >> is hanging on; > > >> > > >> plt.plot(t, s) > > >> > > >> attempts to > > >> matplotlib.interactive(True) didn't bring anything, > > >> > > >> > > > Hi Andrew, > > > > > > From which environment are you trying to run the example? In the > > terminal, > > > from within some IDE, inside a jupyter notebook? > > > > > > Are you sure the script "is hanging on plt.plot(t, s)" and not after > > that? > > > > > > Best, > > > Wolfgang > > > > > > -- > > Hi, > > sorry if it is too trivial, just to make sure, do you have a call to > > "show()" the resulting plot in the code? > > > > An elementary plotting code might be e.g.: > > > > import matplotlib.pyplot as plt > > plt.plot([1,2,4,1]) > > plt.show() > > > > Does this work in your environment? > > > > It was not quite clear, what do you plan with interactive drawing, or > > whether you are using e.g. plt.interactive(True) already - this might > > be a problem as there could be collisions or the plot window is closed > > after the standalone script finishes. > > > > hth, > > vbr > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Have you tried plt.show(block=False) ? From steve+python at pearwood.info Thu Nov 2 08:35:16 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 02 Nov 2017 23:35:16 +1100 Subject: A use-case for for...else with no break References: <59faef21$0$18601$b1db1813$d948b532@news.astraweb.com> <87wp38j44l.fsf@ender.lizardnet> Message-ID: <59fb1106$0$18567$b1db1813$d948b532@news.astraweb.com> On Thu, 2 Nov 2017 10:45 pm, Alberto Berti wrote: >>>>>> "Steve" == Steve D'Aprano writes: > > py> for x in "abcdefgh": > Steve> ... print(x, end='') > Steve> ... > py> efghpy> > > > Steve> "For ... else" to the rescue! > > py> for char in "abcdefgh": > Steve> ... print(char, end='') > Steve> ... else: > Steve> ... print() > Steve> ... > Steve> abcdefgh > py> > > else doesn't seem to bring any advantage over: > > for char in "abcdefgh": > print(char, end='') > print() Have you tried it in the interactive interpreter? py> for char in "abcdefgh": ... print(char, end='') ... print() File "", line 3 print() ^ SyntaxError: invalid syntax -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From karishmamtip at gmail.com Thu Nov 2 08:37:05 2017 From: karishmamtip at gmail.com (karishmamtip at gmail.com) Date: Thu, 2 Nov 2017 05:37:05 -0700 (PDT) Subject: Worldwide Latest new Feature Automotive Power Electronics 2017 by Technology and news Message-ID: Automotive Power Electronics are the devices installed and used for controlling the high voltage and converting varied electric power in a most proficient way. These devices also helps in monitoring a power consumption in an optimized manner. One of the major driver for the growth of Automotive Power Electronics market is the rapid growth in the electric vehicles owing to the reasons that electric vehicle use batteries and doesn't harm the environment. FREE Sample Copy is Available https://tinyurl.com/yb5guadz Important Market Players : Infineon Technologies AG, Renesas Electronics Corporation, Vishay Intertechnology Inc., Robert Bosch GmbH, Mitsubishi Electric Corporation, Qualcomm Technologies Inc., ON Semiconductor Corporation, NXP Semiconductors, GAN Systems Inc., and Rohm Corporation ltd. From karishmamtip at gmail.com Thu Nov 2 08:37:08 2017 From: karishmamtip at gmail.com (karishmamtip at gmail.com) Date: Thu, 2 Nov 2017 05:37:08 -0700 (PDT) Subject: Worldwide Latest new Feature Automotive Power Electronics 2017 by Technology and news Message-ID: <224204be-5859-434b-ba6b-c606755e7ba5@googlegroups.com> Automotive Power Electronics are the devices installed and used for controlling the high voltage and converting varied electric power in a most proficient way. These devices also helps in monitoring a power consumption in an optimized manner. One of the major driver for the growth of Automotive Power Electronics market is the rapid growth in the electric vehicles owing to the reasons that electric vehicle use batteries and doesn't harm the environment. FREE Sample Copy is Available https://tinyurl.com/yb5guadz Important Market Players : Infineon Technologies AG, Renesas Electronics Corporation, Vishay Intertechnology Inc., Robert Bosch GmbH, Mitsubishi Electric Corporation, Qualcomm Technologies Inc., ON Semiconductor Corporation, NXP Semiconductors, GAN Systems Inc., and Rohm Corporation ltd. From __peter__ at web.de Thu Nov 2 08:45:14 2017 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Nov 2017 13:45:14 +0100 Subject: Reading a remove csv file References: <1509621847l.38011130l.0l@psu.edu> Message-ID: ROGER GRAYDON CHRISTMAN wrote: > Just a quick question on how best to read a remote CSV file. > So far, I tried: > > filelink = urllib.request.urlopen(path) > dictread = csv.DictReader(filelink) > for row in dictread: ... > But I'm running into the difference between strings and bytes. > I'd like to squeeze a note that talks about the utf-8 encoding, > but although I find that as an option for a local file (with open()) > I did not see that on my first glance at the two functions above. > > Is there an easy way to read a remove CSV file with utf-8 encoding > without copying the whole file locally first? Try wrapping the resqponse, it should be sufficiently file-like: response = urllib.request.urlopen(...) stream = io.TextIOWrapper(response, newline="", encoding="utf-8") rows = csv.DictReader(stream) From breamoreboy at gmail.com Thu Nov 2 09:06:38 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Thu, 2 Nov 2017 06:06:38 -0700 (PDT) Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> Message-ID: <98a8b06c-4f75-4296-bdc8-44633a114d40@googlegroups.com> On Wednesday, November 1, 2017 at 9:14:05 PM UTC, Alexey Muranov wrote: > Hello, > > what do you think about the idea of replacing "`else`" with "`then`" in > the contexts of `for` and `try`? > > It seems clear that it should be rather "then" than "else." Compare > also "try ... then ... finally" with "try ... else ... finally". > > Currently, with "else", it is almost impossible to guess the meaning > without looking into the documentation. > > Off course, it should not be changed in Python 3, maybe in Python 4 or > 5, but in Python 3 `then` could be an alias of `else` in these contexts. > > Alexey. It has been discussed before. I believe the chances of it ever happening are roughly zero. There's a good write up on the subject here http://python-notes.curiousefficiency.org/en/latest/python_concepts/break_else.html -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From dvl at psu.edu Thu Nov 2 09:18:21 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Thu, 2 Nov 2017 09:18:21 -0400 Subject: FW: Reading a remove csv file In-Reply-To: 1509621847l.38011130l.0l@psu.edu References: <1509621847l.38011130l. 0l@psu.edu> Message-ID: <1509628701l.35455224l.0l@psu.edu> I have a partial answer to my own question: This seems to work for me: --- link = urllib.request.urlopen(urlpath) data = link.read().decode('utf-8').split('\n') reader = csv.DictReader(data) for row in reader: --- I think here my concern is that now 'data' is now a variable in my program's memory (all of the data), instead of streamlike. I suppose I did read somewhere about setting a stream option. Roger Christman Pennsylvania State University ---------------- Forwarded Message ---------------- Just a quick question on how best to read a remote CSV file. So far, I tried: filelink = urllib.request.urlopen(path) dictread = csv.DictReader(filelink) for row in dictread: ... But I'm running into the difference between strings and bytes. I'd like to squeeze a note that talks about the utf-8 encoding, but although I find that as an option for a local file (with open()) I did not see that on my first glance at the two functions above. Is there an easy way to read a remove CSV file with utf-8 encoding without copying the whole file locally first? Roger Christman Pennsylvania State University From malaclypse2 at gmail.com Thu Nov 2 09:30:23 2017 From: malaclypse2 at gmail.com (Jerry Hill) Date: Thu, 2 Nov 2017 09:30:23 -0400 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <1509570761.4585.0@smtp.gmail.com> References: <1509570761.4585.0@smtp.gmail.com> Message-ID: On Wed, Nov 1, 2017 at 5:12 PM, Alexey Muranov wrote: > what do you think about the idea of replacing "`else`" with "`then`" in > the contexts of `for` and `try`? > ?I wish the core python developers? had done it 20 years ago. Given that python is a relatively mature language at this point, I don't expect that it will ever change. -- Jerry From jon+usenet at unequivocal.eu Thu Nov 2 09:39:37 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Thu, 2 Nov 2017 13:39:37 -0000 (UTC) Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> Message-ID: On 2017-11-01, Alexey Muranov wrote: > what do you think about the idea of replacing "`else`" with "`then`" in > the contexts of `for` and `try`? > > It seems clear that it should be rather "then" than "else." Compare > also "try ... then ... finally" with "try ... else ... finally". > > Currently, with "else", it is almost impossible to guess the meaning > without looking into the documentation. Why would we want to make the language worse? It is fairly obvious what 'else' means, whereas 'then' has an obvious meaning that is in fact the opposite of what it would actually do. It seems clear that 'else' is the correct word (or at least, far better than 'then'). Maybe the change should be that it is a syntax error to use a 'for/while...else' with no 'break'. From rhodri at kynesim.co.uk Thu Nov 2 11:48:44 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 2 Nov 2017 15:48:44 +0000 Subject: Python Packages Error - Unresolved In-Reply-To: References: Message-ID: <6c24e385-0c6a-16a5-da66-be6cd54a4d53@kynesim.co.uk> On 02/11/17 11:17, Hinds, Megan wrote: > Hi there, > > I was hoping you could help, as I have tried many different websites on this query and even asked the question on stackflow. I have tried many different types of commands in command prompt with the same error. > > I have recently installed Python 3.6. The 32 bit installation (automatically downloaded to this). I have set the correct environment path variables: C:\Users\MH\AppData\Local\Programs\Python\Python36-32;C:\Users\MH\AppData\Local\Programs\Python\Python36-32\Scripts; > > I am on a work laptop with admin rights. > > A few days ago I could install python packages using the following command in command prompt (in python36-32 directory): > > > pip install -index-url=http://pypi.python.org/simple -trusted-host pypi.python.org pandas > > > I managed to install pillow, cx_Oracle, and a few others previously. But not pandas and others (see attached file). > > I was thinking to move on to anaconda, however, I may see the same error in installing packages in there (Oracle related packaged that are not in conda). > > I would be very grateful for any help. I'm afraid the mailing list has stripped your attachments (as well it should, since this is also a newsgroup). Could you repeat them in the body of your message? If they include the exact error messages and any traceback, that would be a great help. -- Rhodri James *-* Kynesim Ltd From steve+python at pearwood.info Thu Nov 2 11:57:40 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 03 Nov 2017 02:57:40 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> Message-ID: <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> On Fri, 3 Nov 2017 12:39 am, Jon Ribbens wrote: > On 2017-11-01, Alexey Muranov wrote: >> what do you think about the idea of replacing "`else`" with "`then`" in >> the contexts of `for` and `try`? >> >> It seems clear that it should be rather "then" than "else." Compare >> also "try ... then ... finally" with "try ... else ... finally". >> >> Currently, with "else", it is almost impossible to guess the meaning >> without looking into the documentation. > > Why would we want to make the language worse? It is fairly obvious > what 'else' means, Yes, obvious and WRONG. for x in seq: do_something() else: print("seq was empty") is an obvious, common and wrong interpretation. > whereas 'then' has an obvious meaning that is in > fact the opposite of what it would actually do. Er... is today opposite day? Because 'then' describes precisely what it actually does. Perhaps before we continue, we should ask what you think for...else and while...else statements do. Just to be sure we are all on the same page here. > It seems clear that > 'else' is the correct word (or at least, far better than 'then'). Not clear at all. The 'for...else' block is a common source of confusion, if it was clear what it did, people wouldn't so often get it wrong. > Maybe the change should be that it is a syntax error to use a > 'for/while...else' with no 'break'. Only if you want to make the experience of using Python in the interactive interpreter worse. See my recent post: "A use-case for for...else with no break" -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From israel at ravnalaska.net Thu Nov 2 12:27:41 2017 From: israel at ravnalaska.net (Israel Brewster) Date: Thu, 2 Nov 2017 08:27:41 -0800 Subject: Thread safety issue (I think) with defaultdict In-Reply-To: <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: > On Nov 1, 2017, at 4:53 PM, Steve D'Aprano wrote: > > On Thu, 2 Nov 2017 05:53 am, Israel Brewster wrote: > > [...] >> So the end result is that the thread that "updates" the dictionary, and the >> thread that initially *populates* the dictionary are actually running in >> different processes. > > If they are in different processes, that would explain why the second > (non)thread sees an empty dict even after the first thread has populated it: > > > # from your previous post >> Length at get AC: 54 ID: 4524152200 Time: 2017-11-01 09:41:24.474788 >> Length At update: 1 ID: 4524152200 Time: 2017-11-01 09:41:24.784399 >> Length At update: 2 ID: 4524152200 Time: 2017-11-01 09:41:25.228853 > > > You cannot rely on IDs being unique across different processes. Its an > unfortunately coincidence(!) that they end up with the same ID. I think it's more than a coincidence, given that it is 100% reproducible. Plus, in an earlier debug test I was calling print() on the defaultdict object, which gives output like "", where presumably the 0x1066467f0 is a memory address (correct me if I am wrong in that). In every case, that address was the same. So still a bit puzzling. > > Or possibly there's some sort of weird side-effect or bug in Flask that, when > it shares the dict between two processes (how?) it clears the dict. Well, it's UWSGI that is creating the processes, not Flask, but that's semantics :-) The real question though is "how does python handle such situations?" because, really, there would be no difference (I wouldn't think) between what is happening here and what is happening if you were to create a new process using the multiprocessing library and reference a variable created outside that process. In fact, I may have to try exactly that, just to see what happens. > > Or... have you considered the simplest option, that your update thread clears > the dict when it is first called? Since you haven't shared your code with us, > I cannot rule out a simple logic error like this: > > def launch_update_thread(dict): > dict.clear() > # code to start update thread Actually, I did share my code. It's towards the end of my original message. I cut stuff out for readability/length, but nothing having to do with the dictionary in question. So no, clear is never called, nor any other operation that could clear the dict. > > >> In fact, any given request could be in yet another >> process, which would seem to indicate that all bets are off as to what data >> is seen. >> >> Now that I've thought through what is really happening, I think I need to >> re-architect things a bit here. > > Indeed. I've been wondering why you are using threads at all, since there > doesn't seem to be any benefit to initialising the dict and updating it in > different thread. Now I learn that your architecture is even more complex. I > guess some of that is unavailable, due to it being a web app, but still. What it boils down to is this: I need to update this dictionary in real time as data flows in. Having that update take place in a separate thread enables this update to happen without interfering with the operation of the web app, and offloads the responsibility for deciding when to switch to the OS. There *are* other ways to do this, such as using gevent greenlets or asyncio, but simply spinning off a separate thread is the easiest/simplest option, and since it is a long-running thread the overhead of spinning off the thread (as opposed to a gevent style interlacing) is of no consequence. As far as the initialization, that happens in response to a user request, at which point I am querying the data anyway (since the user asked for it). The idea is I already have the data, since the user asked for it, why not save it in this dict rather than waiting to update the dict until new data comes in? I could, of course, do a separate request for the data in the same thread that updates the dict, but there doesn't seem to be any purpose in that, since until someone requests the data, I don't need it for anything. > > >> For one thing, the update thread should be >> launched from the main process, not an arbitrary UWSGI worker. I had >> launched it from the client connection because there is no point in having >> it running if there is no one connected, but I may need to launch it from >> the __init__.py file instead. For another thing, since this dictionary will >> need to be accessed from arbitrary worker processes, I'm thinking I may need >> to move it to some sort of external storage, such as a redis database > > That sounds awful. What if the arbitrary worker decides to remove a bunch of > planes from your simulation, or insert them? There should be one and only one > way to insert or remove planes from the simulation (I **really** hope it is a > simulation). UWSGI uses worker processes to respond to requests from web clients. What can and can't be done from a web interface is, of course, completely up to me as the developer, and may well be modifying basic data structures. HOW the requests are handled, however, is completely up to UWSGI. > > Surely the right solution is to have the worker process request whatever > information it needs, like "the next plane", and have the main process > provide the data. Having worker processes have the ability to reach deep into > the data structures used by the main program and mess with them seems like a > good way to have mind-boggling bugs. Except the worker processes *are* the main program. That's how UWSGI works - it launches a number of worker processes to handle incoming web requests. It's not like I have a main process that is doing something, and *additionally* a bunch of worker processes. While I'm sure UWSGI does have a "master" process it uses to control the workers, that's all an internal implementation detail of UWSGI, not something I deal with directly. I just have the flask code, which doesn't deal with or know about separate processes at all. The only exception is the one *thread* I launch (not process, thread) to handle the background updating. > > > >> Oy, I made my life complicated :-) > > "Some people, when confronted with a problem, think, 'I know, I'll use > threads. Nothew y htwo probave lems." > > :-) Actually, that saying is about regular expressions, not threads :-) . In the end, threads are as good a way as handling concurrency as any other, and simpler than many. They have their drawbacks, of course, mainly in the area of overhead, and of course only multiprocessing can *really* take advantage of multiple cores/CPU's on a machine, but unlike regular expressions, threads aren't ugly or complicated. Only the details of dealing with concurrency make things complicated, and you'll have to deal with that in *any* concurrency model. > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list From jon+usenet at unequivocal.eu Thu Nov 2 12:31:04 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Thu, 2 Nov 2017 16:31:04 -0000 (UTC) Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-11-02, Steve D'Aprano wrote: > On Fri, 3 Nov 2017 12:39 am, Jon Ribbens wrote: >> Why would we want to make the language worse? It is fairly obvious >> what 'else' means, > > Yes, obvious and WRONG. Nope, obvious and right. > for x in seq: > do_something() > else: > print("seq was empty") > > is an obvious, common and wrong interpretation. No, it's an obvious bug. You have a 'for...else' with no 'break'. Like I said, that should probably be a syntax error. >> whereas 'then' has an obvious meaning that is in >> fact the opposite of what it would actually do. > > Er... is today opposite day? Because 'then' describes precisely what it > actually does. No, 'then' describes the opposite of what it does. The word 'then' implies something that always happens next, whereas 'else' conveys the correct meaning, which is something that happens if the course of the preceding piece of code did not go as expected. > Perhaps before we continue, we should ask what you think for...else > and while...else statements do. Just to be sure we are all on the > same page here. I think they do what the Python Language Reference sections 8.2 and 8.3 say they do. >> It seems clear that 'else' is the correct word (or at least, far >> better than 'then'). > > Not clear at all. The 'for...else' block is a common source of > confusion, if it was clear what it did, people wouldn't so often get > it wrong. That might be an argument that it is imperfect. It doesn't even begin to constitute an argument that 'then' would be an improvement. >> Maybe the change should be that it is a syntax error to use a >> 'for/while...else' with no 'break'. > > Only if you want to make the experience of using Python in the interactive > interpreter worse. See my recent post: > > "A use-case for for...else with no break" Yes, I saw that. It's possible you are the only person in the world ever to have done that. It would not make the interactive interpreter 'worse' in the slightest for that silly trick to be lost. From skip.montanaro at gmail.com Thu Nov 2 13:09:42 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 2 Nov 2017 12:09:42 -0500 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <59faed9c$0$18566$b1db1813$d948b532@news.astraweb.com> References: <1509570761.4585.0@smtp.gmail.com> <59fa6f7e$0$18600$b1db1813$d948b532@news.astraweb.com> <59faed9c$0$18566$b1db1813$d948b532@news.astraweb.com> Message-ID: Eh, what can I say? I guess I was paying too much attention to the baseball game. Yes, "else" handles the "fall off the end" termination, not the "exit early" termination. My apologies. I do think that having a way to spell "do this when the loop exits early" makes things clearer. So, perhaps while and for loops could someday grow except clauses. :-) On Thu, Nov 2, 2017 at 5:04 AM, Steve D'Aprano wrote: > On Thu, 2 Nov 2017 12:49 pm, Skip Montanaro wrote: > > > I don't know. The word "then" doesn't connote different ways of exiting a > > loop to me ("else" doesn't really either, I will grant you that, but it's > > what we have). Here's how I would read things: > > > > - *while* some condition holds, execute the loop, possibly breaking > out, > > *then* do some finishing work > > - *for* each element in some sequence, execute the loop, possibly > > breaking out, *then* do some finishing work > > And that is exactly the behaviour of the for...else and while...else > construct. You're reading it correctly. > > When you say "possibly breaking out", I assume you mean breaking out of the > *entire* compound statement, because the alternative would be just silly. > The > alternative would be exactly equivalent to just following the loop with > some > unindented code: > > > while condition: > block > # on break we jump to here > finishing > > > In that case, it makes no sense to include a do-nothing "else" or "then" > keyword. > > To put it another way, if we are trying to infer the semantics of a > statement, > and can interpret it in one of two ways: > > - it does something > > - it does nothing > > then (with special case) of `pass`, we should always assume the first case, > thus resolving the ambiguity in favour of "Guido isn't an idiot who added a > pointless keyword" :-) > > > > In neither case does it seem to me that you execute the finishing work > only > > if you break out of the loop, but not if the loop terminates when the > while > > condition becomes false or the for loop's sequence is exhausted. > > If I'm reading you correctly, I think you are confused about the `else` > clause. It is incorrect to say that the `else` clause runs "only if you > break > out of the loop" (as you say). The `else` clause runs *after* the loop > completes, but NOT if you jump out with break/return/raise. > > If we don't jump out of the loop, the else block is equivalent to just > following the loop with unindented code: > > > for x in sequence: > block > else: > follows > > > is equivalent to: > > > for x in sequence: > block > follows > > > Hence, in the absence of any early exit from the loop, the `else` block > behaves more like an *then* rather than an "else". The behaviour of `else` > confused me utterly until I realised that the semantics of the compound > for...else was the loop to execute, then the `else` block. > > So why even bother with `else`? > > Unlike the second case, the `else` block is part for the compound for/while > statement. And so `break` doesn't just exit the loop, it exits the whole > compound statement, jumping past the `else`: > > for x in sequence: > block > else: > follows > # break jumps to here > more code > > > The motive for allowing this pattern is described here: > > https://shahriar.svbtle.com/pythons-else-clause-in-loops > > > > You might > > consider that while/then or for/then actually reads too much like > English, > > fooling you into interpreting it as English, opening you up to ambiguity. > > If you interpret it as English, it works fine. You run the loop, then you > run > the "then" clause. If you jump out of the loop (whether by return, raise or > break) you jump out of the *entire* statement, not just the loop part. > > There's no ambiguity because we can assume Guido wouldn't introduce a > pointless block keyword that does literally nothing except require an > indent. > > > > You might argue that "else" doesn't either, but it has the strangely nice > > property of actually being a bit clumsier to read, forcing the reader to > > learn and apply the precise rules of the programming language instead of > > infer the more ambiguous rules of English. > > If only that were true... > > There's a simple, obvious, but sadly WRONG plain English interpretation of > for...else, namely that the `else` clause runs if the for sequence was > empty: > > > for x in L: > pass > else: > # This is wrong! > print("L is empty") > > > and similar for while. That lead me astray for the longest time! And I'm > not > the only one. > > > > English and other natural languages aren't precise enough to serve as > > programming languages. > > Hmmm... I think Hypertalk might have something to say about that. > > And Inform7 I think would laugh in your face :-) > > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list > From wolfgang.maier at biologie.uni-freiburg.de Thu Nov 2 13:47:57 2017 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Thu, 2 Nov 2017 18:47:57 +0100 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fa6f7e$0$18600$b1db1813$d948b532@news.astraweb.com> <59faed9c$0$18566$b1db1813$d948b532@news.astraweb.com> Message-ID: <88fedff6-63a4-8704-15ae-73e3eac39509@biologie.uni-freiburg.de> On 11/02/2017 06:09 PM, Skip Montanaro wrote: > Eh, what can I say? I guess I was paying too much attention to the baseball > game. Yes, "else" handles the "fall off the end" termination, not the "exit > early" termination. My apologies. I do think that having a way to spell "do > this when the loop exits early" makes things clearer. So, perhaps while and > for loops could someday grow except clauses. :-) > ... and even this idea has been discussed before: https://mail.python.org/pipermail/python-ideas/2017-March/044932.html There wasn't much enthusiasm about it though because few people (ok, maybe even just me) thought it had interesting use cases. From israel at ravnalaska.net Thu Nov 2 14:54:43 2017 From: israel at ravnalaska.net (Israel Brewster) Date: Thu, 2 Nov 2017 10:54:43 -0800 Subject: Share unpickleable object across processes Message-ID: I have a Flask/UWSGI web app that serves up web socket connections. When a web socket connection is created, I want to store a reference to said web socket so I can do things like write messages to every connected socket/disconnect various sockets/etc. UWSGI, however, launches multiple child processes which handle incoming connections, so the data structure that stores the socket connections needs to be shared across all said processes. How can I do this? Tried so far: 1) using a multiprocessing Manager(), from which I have gotten a dict(). This just gives me "BlockingIOError: [Errno 35] Resource temporarily unavailable" errors whenever I try to access the dict object. 2) Using redis/some other third-party store. This fails because it requires you to be able to pickle the object, and the web socket objects I'm getting are not pickle able. In C I might do something like store a void pointer to the object, then cast it to the correct object type, but that's not an option in python. So how can I get around this issue? ----------------------------------------------- Israel Brewster Systems Analyst II Ravn Alaska 5245 Airport Industrial Rd Fairbanks, AK 99709 (907) 450-7293 ----------------------------------------------- From rosuav at gmail.com Thu Nov 2 16:24:55 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Nov 2017 07:24:55 +1100 Subject: Thread safety issue (I think) with defaultdict In-Reply-To: References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: On Fri, Nov 3, 2017 at 3:27 AM, Israel Brewster wrote: > > Actually, that saying is about regular expressions, not threads :-) . In the end, threads are as good a way as handling concurrency as any other, and simpler than many. They have their drawbacks, of course, mainly in the area of overhead, and of course only multiprocessing can *really* take advantage of multiple cores/CPU's on a machine, but unlike regular expressions, threads aren't ugly or complicated. Only the details of dealing with concurrency make things complicated, and you'll have to deal with that in *any* concurrency model. > Thank you. I've had this argument with many people, smart people (like Steven), people who haven't grokked that all concurrency has costs - that threads aren't magically more dangerous than other options. They have a few limitations (for instance, you can't viably have more than a few thousand threads in a process, but you could easily have orders of magnitude more open sockets managed by asyncio), but for many situations, they're the perfect representation of program logic. They're also easy to explain, and then other concurrency models can be explained in terms of threads (eg async functions are like threads but they only switch from thread to thread at an 'await' point). ChrisA From rosuav at gmail.com Thu Nov 2 16:30:04 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Nov 2017 07:30:04 +1100 Subject: Share unpickleable object across processes In-Reply-To: References: Message-ID: On Fri, Nov 3, 2017 at 5:54 AM, Israel Brewster wrote: > I have a Flask/UWSGI web app that serves up web socket connections. When a web socket connection is created, I want to store a reference to said web socket so I can do things like write messages to every connected socket/disconnect various sockets/etc. UWSGI, however, launches multiple child processes which handle incoming connections, so the data structure that stores the socket connections needs to be shared across all said processes. How can I do this? > You're basically going to need to have a single process that manages all the socket connections. Do you actually NEED multiple processes to do your work? If you can do it with multiple threads in a single process, you'll be able to share your socket info easily. Otherwise, you could have one process dedicated to managing the websockets, and all the others message that process saying "please send this to all processes". ChrisA From israel at ravnalaska.net Thu Nov 2 16:32:35 2017 From: israel at ravnalaska.net (Israel Brewster) Date: Thu, 2 Nov 2017 12:32:35 -0800 Subject: Share unpickleable object across processes In-Reply-To: References: Message-ID: On Nov 2, 2017, at 11:15 AM, Stefan Ram wrote: > > Israel Brewster writes: >> the data structure that stores the socket connections needs >> to be shared across all said processes. > > IIRC that's the difference between threads and > processes: threads share a common memory. > > You can use the standard module mmap to share > data between processes. > > If it's not pickleable, but if you can write code > to serialize it to a text format yourself, you > can share that text representation via, er, sockets. If I could serialize it to a text format, then I could pickle said text format and store it in redis/some other third party store. :-) > >> In C I might do something like store a void pointer to the >> object, then cast it to the correct object type > > Restrictions of the OS or MMU even apply to > C code. Sure, I was just talking in general "ideas". I'm not saying I tried it or it would work. > >> , but that's not an option in python. So how can I get around >> this issue? > > You can always write parts of a CPython program > in C, for example, using Cython. True, but I just need to be able to share this piece of data - I don't want to reinvent the wheel just to write an app that uses web sockets! I *must* be thinking about this wrong. Take even a basic chat app that uses websockets. Client a, which connected to process 1, sends a message to the server. There are three other clients connected, each of which needs to receive said message. Given that the way UWSGI works said clients could have connected to any one of the worker processes, how can the server push the message out to *all* clients? What am I missing here? > > -- > https://mail.python.org/mailman/listinfo/python-list From israel at ravnalaska.net Thu Nov 2 16:35:23 2017 From: israel at ravnalaska.net (Israel Brewster) Date: Thu, 2 Nov 2017 12:35:23 -0800 Subject: Share unpickleable object across processes In-Reply-To: References: Message-ID: <1EC73EB6-AFE4-428C-AE82-AF2F32E1E1E4@ravnalaska.net> On Nov 2, 2017, at 12:30 PM, Chris Angelico wrote: > > On Fri, Nov 3, 2017 at 5:54 AM, Israel Brewster wrote: >> I have a Flask/UWSGI web app that serves up web socket connections. When a web socket connection is created, I want to store a reference to said web socket so I can do things like write messages to every connected socket/disconnect various sockets/etc. UWSGI, however, launches multiple child processes which handle incoming connections, so the data structure that stores the socket connections needs to be shared across all said processes. How can I do this? >> > > You're basically going to need to have a single process that manages > all the socket connections. Do you actually NEED multiple processes to > do your work? If you can do it with multiple threads in a single > process, you'll be able to share your socket info easily. Otherwise, > you could have one process dedicated to managing the websockets, and > all the others message that process saying "please send this to all > processes". Ok, that makes sense, but again: it's UWSGI that creates the processes, not me. I'm not creating *any* processes or threads. Aside from telling UWSGI to only use a single worker, I have no control over what happens where. But maybe that's what I need to do? > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Thu Nov 2 16:36:48 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Nov 2017 07:36:48 +1100 Subject: Share unpickleable object across processes In-Reply-To: <1EC73EB6-AFE4-428C-AE82-AF2F32E1E1E4@ravnalaska.net> References: <1EC73EB6-AFE4-428C-AE82-AF2F32E1E1E4@ravnalaska.net> Message-ID: On Fri, Nov 3, 2017 at 7:35 AM, Israel Brewster wrote: > On Nov 2, 2017, at 12:30 PM, Chris Angelico wrote: >> >> On Fri, Nov 3, 2017 at 5:54 AM, Israel Brewster wrote: >>> I have a Flask/UWSGI web app that serves up web socket connections. When a web socket connection is created, I want to store a reference to said web socket so I can do things like write messages to every connected socket/disconnect various sockets/etc. UWSGI, however, launches multiple child processes which handle incoming connections, so the data structure that stores the socket connections needs to be shared across all said processes. How can I do this? >>> >> >> You're basically going to need to have a single process that manages >> all the socket connections. Do you actually NEED multiple processes to >> do your work? If you can do it with multiple threads in a single >> process, you'll be able to share your socket info easily. Otherwise, >> you could have one process dedicated to managing the websockets, and >> all the others message that process saying "please send this to all >> processes". > > Ok, that makes sense, but again: it's UWSGI that creates the processes, not me. I'm not creating *any* processes or threads. Aside from telling UWSGI to only use a single worker, I have no control over what happens where. But maybe that's what I need to do? > That's exactly what I mean, yeah. UWSGI should be able to be told to use threads instead of processes. I don't know it in detail, but a cursory look at the docos suggests that it's happy to use either (or even both). ChrisA From israel at ravnalaska.net Thu Nov 2 17:10:30 2017 From: israel at ravnalaska.net (Israel Brewster) Date: Thu, 2 Nov 2017 13:10:30 -0800 Subject: Share unpickleable object across processes In-Reply-To: References: <1EC73EB6-AFE4-428C-AE82-AF2F32E1E1E4@ravnalaska.net> Message-ID: <9328DB69-1270-4041-873E-431CCE36F4B4@ravnalaska.net> On Nov 2, 2017, at 12:36 PM, Chris Angelico wrote: > > On Fri, Nov 3, 2017 at 7:35 AM, Israel Brewster > wrote: >> On Nov 2, 2017, at 12:30 PM, Chris Angelico wrote: >>> >>> On Fri, Nov 3, 2017 at 5:54 AM, Israel Brewster wrote: >>>> I have a Flask/UWSGI web app that serves up web socket connections. When a web socket connection is created, I want to store a reference to said web socket so I can do things like write messages to every connected socket/disconnect various sockets/etc. UWSGI, however, launches multiple child processes which handle incoming connections, so the data structure that stores the socket connections needs to be shared across all said processes. How can I do this? >>>> >>> >>> You're basically going to need to have a single process that manages >>> all the socket connections. Do you actually NEED multiple processes to >>> do your work? If you can do it with multiple threads in a single >>> process, you'll be able to share your socket info easily. Otherwise, >>> you could have one process dedicated to managing the websockets, and >>> all the others message that process saying "please send this to all >>> processes". >> >> Ok, that makes sense, but again: it's UWSGI that creates the processes, not me. I'm not creating *any* processes or threads. Aside from telling UWSGI to only use a single worker, I have no control over what happens where. But maybe that's what I need to do? >> > > That's exactly what I mean, yeah. UWSGI should be able to be told to > use threads instead of processes. I don't know it in detail, but a > cursory look at the docos suggests that it's happy to use either (or > even both). Gotcha, thanks. The hesitation I have there is that the UWSGI config is a user setting. Sure, I can set up my install to only run one process, but what if someone else tries to use my code, and they set up UWSGI to run multiple? I hate the idea of my code being so fragile that a simple user setting change which I have no control over can break it. But it is what it is, and if that's the only option, I'll just put a note in the readme to NEVER, under any circumstances, set UWSGI to use multiple processes when running this app and call it good :-) > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From theNurd at nurdletech.com Thu Nov 2 17:30:57 2017 From: theNurd at nurdletech.com (Ken Kundert) Date: Thu, 2 Nov 2017 14:30:57 -0700 Subject: bug in ''.format() Message-ID: I just encountered this: >>> '{:0s}'.format('hello') Traceback (most recent call last): File "", line 1, in ValueError: '=' alignment not allowed in string format specifier The exception goes away if I do not specify a width of the string: >>> '{:s}'.format('hello') 'hello' My reading of the documentation says I should be able to specify a width when interpolating a string. I have tried this in 2.7.13, 3.6.1 and 3.6.2 and it fails in all of them. Is this a bug or am I confused? -Ken From rosuav at gmail.com Thu Nov 2 17:39:12 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Nov 2017 08:39:12 +1100 Subject: Share unpickleable object across processes In-Reply-To: <9328DB69-1270-4041-873E-431CCE36F4B4@ravnalaska.net> References: <1EC73EB6-AFE4-428C-AE82-AF2F32E1E1E4@ravnalaska.net> <9328DB69-1270-4041-873E-431CCE36F4B4@ravnalaska.net> Message-ID: On Fri, Nov 3, 2017 at 8:10 AM, Israel Brewster wrote: > Gotcha, thanks. The hesitation I have there is that the UWSGI config is a > user setting. Sure, I can set up my install to only run one process, but > what if someone else tries to use my code, and they set up UWSGI to run > multiple? I hate the idea of my code being so fragile that a simple user > setting change which I have no control over can break it. But it is what it > is, and if that's the only option, I'll just put a note in the readme to > NEVER, under any circumstances, set UWSGI to use multiple processes when > running this app and call it good :-) IMO that's not a problem. People have gotten into the bad habit of assuming that all requests are independent, and that's something that is OFTEN true, but can leak. That's why some web sites randomly log you out now and then - because you landed on a different instance of the web server, and it doesn't have your login (because they messed up the sharing across nodes). For something like this, where different clients directly interact with each other, it's entirely reasonable to demand that they all be handled by a single process. In MUDs, it's normal to run a single process for all clients. Of course, MUDs aren't heavy-weight, but it's possible to handle a thousand concurrent clients without a blip on the CPU monitor. You'd be surprised how many HTTP clients you can manage on a single process, as long as you have the RAM for it. ChrisA From python at mrabarnett.plus.com Thu Nov 2 18:00:34 2017 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 2 Nov 2017 22:00:34 +0000 Subject: bug in ''.format() In-Reply-To: References: Message-ID: <85af3bce-e3af-8342-9423-c6433ca78b23@mrabarnett.plus.com> On 2017-11-02 21:30, Ken Kundert wrote: > I just encountered this: > >>>> '{:0s}'.format('hello') > Traceback (most recent call last): > File "", line 1, in > ValueError: '=' alignment not allowed in string format specifier > > The exception goes away if I do not specify a width of the string: > >>>> '{:s}'.format('hello') > 'hello' > > My reading of the documentation says I should be able to specify a width > when interpolating a string. > > I have tried this in 2.7.13, 3.6.1 and 3.6.2 and it fails in all of them. > > Is this a bug or am I confused? > -Ken > The docs say this: """ When no explicit alignment is given, preceding the width field by a zero ('0') character enables sign-aware zero-padding for numeric types. This is equivalent to a fill character of '0' with an alignment type of '='. """ It thinks that the "0" means zero-padding, etc, as explained above. (Having an explicit width of 0 is kind of odd anyway, if you think about it!) The solution is to include an alignment character: >>> '{:<0s}'.format('hello') 'hello' From tjreedy at udel.edu Thu Nov 2 18:20:26 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 2 Nov 2017 18:20:26 -0400 Subject: A use-case for for...else with no break In-Reply-To: <59faef21$0$18601$b1db1813$d948b532@news.astraweb.com> References: <59faef21$0$18601$b1db1813$d948b532@news.astraweb.com> Message-ID: On 11/2/2017 6:10 AM, Steve D'Aprano wrote: > Occasionally it is useful to loop over a bunch of stuff in the interactive > interpreter, printing them as you go on a single line: > > for x in something(): > print(x, end='') > > If you do that, the prompt overwrites your output, and you get a mess: > > > py> for x in "abcdefgh": > ... print(x, end='') > ... > py> efghpy> This seems like a bug in how Python interacts with your console. On Windows, in Python started from an icon or in Command Prompt: >>> for c in 'abc': print(c, end='') ... abc>>> IDLE adds \n if needed, so prompts always starts on a fresh line. >>> for x in 'abcdefgh': print(x, end='') abcdefgh >>> > "For ... else" to the rescue! > > py> for char in "abcdefgh": > ... print(char, end='') > ... else: > ... print() > ... > abcdefgh > py> -- Terry Jan Reedy From theNurd at nurdletech.com Thu Nov 2 18:24:58 2017 From: theNurd at nurdletech.com (Ken Kundert) Date: Thu, 2 Nov 2017 15:24:58 -0700 Subject: bug in ''.format() References: Message-ID: Sure enough. There is it, right there in the documentation. I did not read far enough. My bad. Thanks! -Ken From tjreedy at udel.edu Thu Nov 2 18:57:12 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 2 Nov 2017 18:57:12 -0400 Subject: FW: Reading a remove csv file In-Reply-To: <1509628701l.35455224l.0l@psu.edu> References: <1509621847l.38011130l. 0l@psu.edu> <1509628701l.35455224l.0l@psu.edu> Message-ID: On 11/2/2017 9:18 AM, ROGER GRAYDON CHRISTMAN wrote: > I have a partial answer to my own question: > This seems to work for me: > > --- > link = urllib.request.urlopen(urlpath) > data = link.read().decode('utf-8').split('\n') > > reader = csv.DictReader(data) > for row in reader: > --- > > I think here my concern is that now 'data' is now a variable > in my program's memory (all of the data), > instead of streamlike. I suppose I did read > somewhere about setting a stream option. csv.reader and csv.DictReader are transformation iterators whose first argument must be an iterable of string lines. Given an iterator of bytes lines, you just need to interpose a bytes to string iterator -- something like (untested) def strgen(bytesource, encoding): for line in bytesource: yield line.decode(encoding) with urllib.request.urlopen(urlpath) as link: lines = strgen(link, 'utf-8') reader = csv.DictReader(lines) # plus any other args for row in reader: process(row) Iterators are intended to be chained together like this. -- Terry Jan Reedy From phd at phdru.name Thu Nov 2 19:46:45 2017 From: phd at phdru.name (Oleg Broytman) Date: Fri, 3 Nov 2017 00:46:45 +0100 Subject: mimedecode 2.8.0 Message-ID: <20171102234645.GA4593@phdru.name> Hello! mimedecode.py WHAT IS IT Mail users, especially in non-English countries, often find that mail messages arrived in different formats, with different content types, in different encodings and charsets. Usually this is good because it allows us to use appropriate format/encoding/whatever. Sometimes, though, some unification is desirable. For example, one may want to put mail messages into an archive, make HTML indices, run search indexer, etc. In such situations converting messages to text in one character set and skipping some binary attachments is much desirable. Here is the solution - mimedecode.py. This is a program to decode MIME messages. The program expects one input file (either on command line or on stdin) which is treated as an RFC822 message, and decodes to stdout or an output file. If the file is not an RFC822 message it is just copied to the output one-to-one. If the file is a simple RFC822 message it is decoded as one part. If it is a MIME message with multiple parts ("attachments") all parts are decoded. Decoding can be controlled by command-line options. Version 2.8.0 (2017-11-03) Python 3. Stop supporting Python 2.6. Code cleanup: fixed flake8 errors and warnings. Pushed to GitHub. Tests at Travis. WHERE TO GET Home page: http://phdru.name/Software/Python/#mimedecode git clone https://github.com/phdru/mimedecode.git git clone http://git.phdru.name/mimedecode.git git clone git://git.phdru.name/mimedecode.git Requires: Python 2.7 or Python 3.4+, m_lib.defenc 1.0+. Tests require: tox, m_lib 3.1+. Recommends: configured mailcap database. Documentation: http://phdru.name/Software/Python/mimedecode.html (also included in the package in html, man and txt formats). AUTHOR Oleg Broytman COPYRIGHT Copyright (C) 2001-2017 PhiloSoft Design. LICENSE GPL Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From rosuav at gmail.com Thu Nov 2 20:07:30 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Nov 2017 11:07:30 +1100 Subject: Share unpickleable object across processes In-Reply-To: References: Message-ID: On Fri, Nov 3, 2017 at 11:00 AM, Dennis Lee Bieber wrote: > On Thu, 2 Nov 2017 12:32:35 -0800, Israel Brewster > declaimed the following: > > >> >>I *must* be thinking about this wrong. Take even a basic chat app that uses websockets. Client a, which connected to process 1, sends a message to the server. There are three other clients connected, each of which needs to receive said message. Given that the way UWSGI works said clients could have connected to any one of the worker processes, how can the server push the message out to *all* clients? What am I missing here? >> > > This is beginning to sound like a form of publisher/subscriber system. > > http://learning-0mq-with-pyzmq.readthedocs.io/en/latest/pyzmq/patterns/pubsub.html > > Though I have to admit I don't quite see how to set up bidirectional > communication. Having the workers subscribe to receive data from a single > publisher is the easier part -- but how a worker can send data to the > publisher for distribution is not clear; the distribution process can't > subscribe to every worker automatically... Perhaps something using > > http://learning-0mq-with-pyzmq.readthedocs.io/en/latest/pyzmq/devices/forwarder.html > > with each worker making both publisher and subscriber connections. That > could let a worker publish to the forwarder, which then distributes to all > subscribed workers. Might need some way to identify one's own message > (perhaps each worker has a topic, and filters its own topic out of the > return stream). Websockets are perfect for this sort of thing. It's not difficult.... but you need to have all the clients managed by a single central hub, which is the exact problem the OP faced. Here's a simple websocket app that does this sort of thing: https://github.com/Rosuav/monopoly-open-bid/blob/master/server.py It depends on running a single process to handle every client, and then simply maintains an in-memory list of concurrent clients. (This uses asyncio, but equivalent models using threads are also possible.) ChrisA From jjmaldonis at gmail.com Thu Nov 2 20:12:40 2017 From: jjmaldonis at gmail.com (Jason Maldonis) Date: Thu, 2 Nov 2017 19:12:40 -0500 Subject: what exactly does type.__call__ do? In-Reply-To: <59faace7$0$14949$b1db1813$d948b532@news.astraweb.com> References: <59faace7$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: Thanks for your response. I'm confident that my use case for this metaclass is correct for what I'm trying to do. I've been using them for a few years now, but sparingly because as you said they are almost always unnecessary. I simplified my example significantly for discussion -- I'm not actually using a Singleton, but it's an easy situation to think about. I'd like to ask a couple follow up questions here: By using... @classmethod def normal_constructor(cls, *args, **kwargs): return type.__call__(cls, *args, **kwargs) # Aside: Yes, the `cls` does need to be in here ... I'm assuming that there are no inherited metaclasses. I'm explicitly saying, "No matter what the super() functionality for creating the class is, always use `type`.__call__'s functionality". That seems wrong/unpythonic to me, or at least inconsistent with how non-metaclass inheritance works in python (ie you are encouraged to use `super()` when using single inheritance). Because of that, my guess is... @classmethod def normal_constructor(cls, *args, **kwargs): return super(cls).__call__(cls, *args, **kwargs) # or maybe it should be: return super(my_metaclass, cls).__call__(cls, *args, **kwargs) ... is closer to the correct approach because it will properly hit the `__call__` method of the metaclass's parent class (which will often ey `type`'s `__call__` method if the metaclass doesn't inherit from any other metaclass). However, I've never seen anything like that after years of working with / reading about metaclasses. Does that help redefine my question a little bit? You said all three look "weird and scary", but I don't know why. Can you explain that a bit please? The 3rd example I gave (using `cls.__new__` and `self.__init__`) I agree is a bit weird and scary, and in my opinion that's because I am assuming what the correct sequence of calls is for how classes are normally instantiated. So I'm the least thrilled with that one. I feel like using super is the correct choice -- for the reasons I listed above -- but I would like a more expert opinion (and I'd like to learn why :)). Thanks! Jason On Thu, Nov 2, 2017 at 12:28 AM, Steve D'Aprano wrote: > On Thu, 2 Nov 2017 10:13 am, Jason Maldonis wrote: > > > Hi everyone, > > > > I want to use a metaclass to override how class instantiation works. I've > > done something analogous to using the Singleton metaclass from the > Python3 > > Cookbook example. > > In my opinion, nine times out of ten, using a metaclass for something like > that is overkill. > > (And that's putting aside the fact that 999 out of a thousand, using a > Singleton is the wrong solution, no matter what the question is.) > > > > However, I want to provide a classmethod that allows for "normal" class > > instantiation that prevents this metaclass from being used. > > To me, that strongly suggests that a metaclass is the wrong solution. > > > > To do that, I think I just make a @classmethod constructor function. > > However, I can imagine a few different ways of writing this: > > > > @classmethod > > def normal_constructor(cls, *args, **kwargs): > > return type.__call__(*args, **kwargs) > > Untested, but I think that should be: > > return type.__call__(cls, *args, **kwargs) > > > > @classmethod > > def normal_constructor(cls, *args, **kwargs): > > return super(???).__call__(*args, **kwargs) # I'm not sure what > should > > go in the super here (I'm using python3) > > > > @classmethod > > def normal_constructor(cls, *args, **kwargs): > > self = cls.__new__(cls) > > self.__init__(*args, **kwargs) > > return self > > > > Is one of these correct? Or do they all do the same thing? > > None of them look "correct", they all look "weird and scary" :-) > > If I had to pick one of these three -- and I hope that I would not -- I'd > pick > the first one. > > > > I was looking for documentation for what exactly `type.__call__` does so > > that I can emulate it, > > And then if type.__call__ changes, your emulation will be wrong. > > > > but I wasn't able to find any docs explicitly > > detailing what that method does. If someone knows where this info is that > > would be great too. > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list > From steve+python at pearwood.info Thu Nov 2 20:53:01 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 03 Nov 2017 11:53:01 +1100 Subject: A use-case for for...else with no break References: <59faef21$0$18601$b1db1813$d948b532@news.astraweb.com> Message-ID: <59fbbdf0$0$18593$b1db1813$d948b532@news.astraweb.com> On Fri, 3 Nov 2017 09:20 am, Terry Reedy wrote: > This seems like a bug in how Python interacts with your console. On > Windows, in Python started from an icon or in Command Prompt: > > >>> for c in 'abc': print(c, end='') > ... > abc>>> That's still unfortunate: the prompt is immediately after the output, rather than starting on a new line. > IDLE adds \n if needed, so prompts always starts on a fresh line. > > >>> for x in 'abcdefgh': > print(x, end='') > > abcdefgh > >>> The prompts and the output aren't aligned -- the prompts are indented by an additional space. Is that intentional? Does IDLE do this only when writing to an actual console? Because if it does so even when output is redirected to a file, adding an extra, unexpected newline would be a bug in IDLE. In any case, in the interactive interpreter there are times one wishes to follow a loop with additional code that executes immediately after the loop, and have them do so *together* without a prompt in between. It might not even be because you care about the output: you might be timing something, and don't want it to pause and wait for you to type the following code. But you cannot write this: py> for x in seq: ... do_this() ... do_that() as the interpreter in interactive mode requires a blank line to terminate the indented block. But if you include such a blank: py> for x in seq: ... do_this() ... py> do_that() the output of "do_this()" is separated from the output of "do_that()", which may be inconvenient. Another work around is: if True: for x in seq: do_this() do_that() -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Thu Nov 2 20:58:16 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 03 Nov 2017 11:58:16 +1100 Subject: Thread safety issue (I think) with defaultdict References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: <59fbbf2b$0$18593$b1db1813$d948b532@news.astraweb.com> On Fri, 3 Nov 2017 07:24 am, Chris Angelico wrote: > On Fri, Nov 3, 2017 at 3:27 AM, Israel Brewster > wrote: >> >> Actually, that saying is about regular expressions, not threads :-) . In >> the end, threads are as good a way as handling concurrency as any other, >> and simpler than many. They have their drawbacks, of course, mainly in the >> area of overhead, and of course only multiprocessing can *really* take >> advantage of multiple cores/CPU's on a machine, but unlike regular >> expressions, threads aren't ugly or complicated. Only the details of >> dealing with concurrency make things complicated, and you'll have to deal >> with that in *any* concurrency model. >> > > Thank you. I've had this argument with many people, smart people (like > Steven), people who haven't grokked that all concurrency has costs - Of course I grok that all concurrency has costs. Apart from comparatively rare cases of "embarrassingly parallel" algorithms, any form of concurrent or parallel processing is significantly harder than sequential code. > that threads aren't magically more dangerous than other options. There's nothing magical about it. Threads are very much UNMAGICALLY more dangerous than other options because they combine: - shared data; and - non-deterministic task switching. Having both together is clearly more dangerous than only one or the other: - async: shared data, but fully deterministic task switching; - multiprocessing: non-deterministic task switching, but by default fully isolated data. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Thu Nov 2 21:02:19 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 03 Nov 2017 12:02:19 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> Message-ID: <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> On Fri, 3 Nov 2017 03:31 am, Jon Ribbens wrote: > On 2017-11-02, Steve D'Aprano wrote: >> On Fri, 3 Nov 2017 12:39 am, Jon Ribbens wrote: >>> Why would we want to make the language worse? It is fairly obvious >>> what 'else' means, >> >> Yes, obvious and WRONG. > > Nope, obvious and right. > >> for x in seq: >> do_something() >> else: >> print("seq was empty") >> >> is an obvious, common and wrong interpretation. > > No, it's an obvious bug. You have a 'for...else' with no 'break'. > Like I said, that should probably be a syntax error. It should absolutely not be a syntax error. There's no reason for it to be a syntax error, except to satisfy some arrogant and foolish idea of purity. There are uncountable ways of writing code which is seemingly "pointless", and we don't make it a syntax error. Sometimes it is even useful. A for...else with no break should no more be a syntax error than "if True". >>> whereas 'then' has an obvious meaning that is in >>> fact the opposite of what it would actually do. >> >> Er... is today opposite day? Because 'then' describes precisely what it >> actually does. > > No, 'then' describes the opposite of what it does. The word 'then' > implies something that always happens next, Right, which is what happens with the for...else block. The else block is executed after the for loop, unless you jump out of the statement using return, raise or break. The flow is: # this is what actually happens loop then `else` block rather than: # this is incorrect loop else (otherwise) `else` block which implies that that `else` block runs if the loop did not. > whereas 'else' conveys > the correct meaning, which is something that happens if the course > of the preceding piece of code did not go as expected. That's not what happens. This is WRONG: for x in sequence: ... else: print("something unexpected happened") Apart from the impossibility of deciding what "unexpected" means in general, the behaviour is the opposite. The `else` clause executes immediately after you fall out the bottom of the for-loop, NOT conditional on some event (whether unexpected or not). >>> Maybe the change should be that it is a syntax error to use a >>> 'for/while...else' with no 'break'. >> >> Only if you want to make the experience of using Python in the interactive >> interpreter worse. See my recent post: >> >> "A use-case for for...else with no break" > > Yes, I saw that. It's possible you are the only person in the world > ever to have done that. It would not make the interactive interpreter > 'worse' in the slightest for that silly trick to be lost. Just because you personally haven't used this technique doesn't make it a "silly trick". And while I thank you for the complement that I am the cleverest and most insightful Python coder in the world, I'm sure I'm not. If I could think of this technique, I daresay that many other people who are much smarter than me have done so too. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From nodnarb at gmx.us Thu Nov 2 22:40:49 2017 From: nodnarb at gmx.us (brandon wallace) Date: Fri, 3 Nov 2017 03:40:49 +0100 Subject: Key Press Not Working In-Reply-To: References: Message-ID: ? I am trying to catch a key press but it is not working. How can I fix this code? There is no error message so there is no error message to do a search on. I am using Python3.5 64-bit inside the terminal. while True: key = input("Enter a letter: ") if key == ord('q'): break ? ?The loop keeps running even though I have pressed the letter 'q'. From python at mrabarnett.plus.com Thu Nov 2 23:11:37 2017 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 3 Nov 2017 03:11:37 +0000 Subject: Key Press Not Working In-Reply-To: References: Message-ID: On 2017-11-03 02:40, brandon wallace wrote: > > > I am trying to catch a key press but it is not working. How can I fix this code? There is no error message so there is no error message to do a search on. > I am using Python3.5 64-bit inside the terminal. > > while True: > key = input("Enter a letter: ") > if key == ord('q'): > break > > ?The loop keeps running even though I have pressed the letter 'q'. > It's waiting for you to press Enter. 'input' is for inputting a line. It returns a string. >>> s = input("Enter a line: ") Enter a line: foo >>> s 'foo' From tjreedy at udel.edu Thu Nov 2 23:12:43 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 2 Nov 2017 23:12:43 -0400 Subject: A use-case for for...else with no break In-Reply-To: <59fbbdf0$0$18593$b1db1813$d948b532@news.astraweb.com> References: <59faef21$0$18601$b1db1813$d948b532@news.astraweb.com> <59fbbdf0$0$18593$b1db1813$d948b532@news.astraweb.com> Message-ID: On 11/2/2017 8:53 PM, Steve D'Aprano wrote: > On Fri, 3 Nov 2017 09:20 am, Terry Reedy wrote: > >> This seems like a bug in how Python interacts with your console. On >> Windows, in Python started from an icon or in Command Prompt: >> >> >>> for c in 'abc': print(c, end='') >> ... >> abc>>> > > That's still unfortunate: the prompt is immediately after the output, rather > than starting on a new line. I agree. It is just less bad than backspacing into user output first. It is easy for IDLE to detect if the prompt needs a \n prefix. I am guessing that this is harder on consoles, and OS dependent. >> IDLE adds \n if needed, so prompts always starts on a fresh line. >> >> >>> for x in 'abcdefgh': >> print(x, end='') >> >> abcdefgh >> >>> > > The prompts and the output aren't aligned -- the prompts are indented by an > additional space. Is that intentional? A copy-paste error (I rechecked) that I should have noticed. > Does IDLE do this only when writing to an actual console? IDLE does this when Python writes to its Shell via stdout or stderr. > Because if it does > so even when output is redirected to a file, adding an extra, unexpected > newline would be a bug in IDLE. IDLE compiles and execs your code. During the exec call, IDLE only sees output sent to its stdout/stderr replacements. If your code sends output to a file it opens, IDLE is not involved. -- Terry Jan Reedy From rustompmody at gmail.com Thu Nov 2 23:19:59 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 2 Nov 2017 20:19:59 -0700 (PDT) Subject: Thread safety issue (I think) with defaultdict In-Reply-To: <59fbbf2b$0$18593$b1db1813$d948b532@news.astraweb.com> References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> <59fbbf2b$0$18593$b1db1813$d948b532@news.astraweb.com> Message-ID: On Friday, November 3, 2017 at 6:28:28 AM UTC+5:30, Steve D'Aprano wrote: > On Fri, 3 Nov 2017 07:24 am, Chris Angelico wrote: > > > On Fri, Nov 3, 2017 at 3:27 AM, Israel Brewster wrote: > >> > >> Actually, that saying is about regular expressions, not threads :-) . In > >> the end, threads are as good a way as handling concurrency as any other, > >> and simpler than many. They have their drawbacks, of course, mainly in the > >> area of overhead, and of course only multiprocessing can *really* take > >> advantage of multiple cores/CPU's on a machine, but unlike regular > >> expressions, threads aren't ugly or complicated. Only the details of > >> dealing with concurrency make things complicated, and you'll have to deal > >> with that in *any* concurrency model. > >> > > > > Thank you. I've had this argument with many people, smart people (like > > Steven), people who haven't grokked that all concurrency has costs - > > Of course I grok that all concurrency has costs. Apart from comparatively rare > cases of "embarrassingly parallel" algorithms, any form of concurrent or > parallel processing is significantly harder than sequential code. > > > > that threads aren't magically more dangerous than other options. > > There's nothing magical about it. > > Threads are very much UNMAGICALLY more dangerous than other options because > they combine: > > - shared data; and > > - non-deterministic task switching. ? which is to say ?bad mix of imperative programming and concurrency? ?The world is concurrent? [Joe Armstrong creator of Erlang] If you get up from your computer just now for a coffee, it does not mean I have to at the same time. More pertinently, it would be rather wasteful if the billion+ transistors of an i7 waited for each other rather than switching independently. The problem is that von Neumann preferred to simplify the programming task along the lines nowadays called "imperative programming"? after whom we get the terms "von Neumann model", "von Neumann machine" etc IOW threads are a particularly extreme example of the deleterious effects of stuffing the world into the mold of someone's (von Neumann's) brain. ie shared data + task switching = combinatorially explosive results Take your own statement ?any form of concurrent or parallel processing is significantly harder than sequential code? and apply it to the abc of imperative programming: Problem: Interchange values of variables x and y Layman answer: x = y y = x [Ignore for a moment that python has an answer that is almost identical to the above and is correct: x,y = y,x] "Correct" answer: temp = x x = y y = temp Correct? Really??? Or is that being trained to "think like a programmer" means learning to convolute our brains into an arbitrary and unnecessary sequentiality? From rustompmody at gmail.com Thu Nov 2 23:37:35 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 2 Nov 2017 20:37:35 -0700 (PDT) Subject: Invoking return through a function? In-Reply-To: <59f80b97$0$18593$b1db1813$d948b532@news.astraweb.com> References: <6b7f9d04-e912-4c58-be55-c5adb05bde22@googlegroups.com> <7f4ed4dc-ad4b-43b6-b647-6004d3e959b4@googlegroups.com> <59f80b97$0$18593$b1db1813$d948b532@news.astraweb.com> Message-ID: <1455b86b-9ca8-4934-abc5-deb9ee22c98f@googlegroups.com> On Tuesday, October 31, 2017 at 11:05:30 AM UTC+5:30, Steve D'Aprano wrote: > On Tue, 31 Oct 2017 02:26 pm, Rustom Mody wrote: > > > My own feeling about lisp-macros is conflicted: > > - They are likely the most unique feature of lisp, putting it at the top of > > the blub-language tower > > - They are the single reason Lisp can never succeed like mainstream > > languages: Any significant Lisp sub-ecosystem will inevitably develop a > > macro set which succinctly and precisely expresses its needs but is arcane > > and incomprehensible to someone from another sub-ecosystem. > > Well said. That's one of the disadvantages of Forth as well: since Forth > allows you to define your own control-structures, even the structure of the > code can be unfamiliar. > > Another way to put it might be that any sufficiently complex Lisp program > doesn't look like Lisp any more. It seems we agree on the facts but not the accounting Facts: A fixed syntax language (C, Java, Python etc) is likely to have similar looking programs across a wide spectrum of applications as compared to a syntax-definable-at-runtime language like Lisp Accounting: You seem to count this as advantage to fixed-syntax? Note that if you carry this principle all the way, any application whatever running on an x86 will be running x86 instructions; which look more uniform than the diverse hl-languages that produced them. > > Except perhaps for the myriad parentheses *wink* Not so: reader-macros can change lisp all the way to the lexical level And used to do things like html-templating, sql-embedding etc From steve+python at pearwood.info Fri Nov 3 00:33:33 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 03 Nov 2017 15:33:33 +1100 Subject: Thread safety issue (I think) with defaultdict References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> <59fbbf2b$0$18593$b1db1813$d948b532@news.astraweb.com> Message-ID: <59fbf19f$0$18601$b1db1813$d948b532@news.astraweb.com> On Fri, 3 Nov 2017 02:19 pm, Rustom Mody wrote: > ?The world is concurrent? [Joe Armstrong creator of Erlang] And the world is extremely complex, complicated and hard to understand. The point of programming is to simplify the world, not emulate it in its full complexity. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Fri Nov 3 00:35:45 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 03 Nov 2017 15:35:45 +1100 Subject: Thread safety issue (I think) with defaultdict References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> <59fbbf2b$0$18593$b1db1813$d948b532@news.astraweb.com> Message-ID: <59fbf264$0$18570$b1db1813$d948b532@news.astraweb.com> On Fri, 3 Nov 2017 02:32 pm, Stefan Ram wrote: > Here is an excerpt from a text from Edward E. Lee: > > A part of the Ptolemy Project experiment was to see > whether effective software engineering practices could be > developed for an academic research setting. [...] > No problems were observed until the code deadlocked > on April 26, 2004, four years later. That is a fantastic anecdote, thank you. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From no.email at nospam.invalid Fri Nov 3 01:22:17 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 02 Nov 2017 22:22:17 -0700 Subject: A use-case for for...else with no break References: <59faef21$0$18601$b1db1813$d948b532@news.astraweb.com> Message-ID: <871slgszqu.fsf@nightsong.com> Steve D'Aprano writes: > for x in something(): > print(x, end='') print(''.join(something())) From dieter at handshake.de Fri Nov 3 02:31:56 2017 From: dieter at handshake.de (dieter) Date: Fri, 03 Nov 2017 07:31:56 +0100 Subject: right list for SIGABRT python binary question ? References: <20171018114358.fzj4vvsyzrf6rihu@hermes.hilbert.loc> <47a09a35-f929-528f-3110-8d660e6fb46f@tjol.eu> <20171019172745.76i3lltjtck2m5gw@hermes.hilbert.loc> <20171019174907.iqgznoroyieipend@hermes.hilbert.loc> <87y3o5gdn9.fsf@handshake.de> <20171023122312.uupsxzhdwat3stt7@hermes.hilbert.loc> <87lgjq5rz9.fsf@handshake.de> <20171101092753.tfcvckzaezunxnej@hermes.hilbert.loc> <20171102112616.ifbrfwrcvjibed66@hermes.hilbert.loc> Message-ID: <87mv43hnz7.fsf@handshake.de> Karsten Hilbert writes: > ... > I have posted backtraces taken from the address being > watched. Does that help any at all ? Only in the case that the error is "local", i.e. detected (quite) immediately. You might be in this case as you have observed that the address is stable after library preload. Thus, it might not be a heap address but one associated with one of the libraries. Such a memory block should never be "freed". The backtrace would allow you to determine the library affected. Obtain its source. Recompile with symbols and try to find out where this memory block comes from. From dieter at handshake.de Fri Nov 3 02:58:10 2017 From: dieter at handshake.de (dieter) Date: Fri, 03 Nov 2017 07:58:10 +0100 Subject: Share unpickleable object across processes References: Message-ID: <87inerhmrh.fsf@handshake.de> Israel Brewster writes: > I have a Flask/UWSGI web app that serves up web socket connections. When a web socket connection is created, I want to store a reference to said web socket so I can do things like write messages to every connected socket/disconnect various sockets/etc. UWSGI, however, launches multiple child processes which handle incoming connections, so the data structure that stores the socket connections needs to be shared across all said processes. How can I do this? At low (= Posix) level, socket objects are represented as ints, representing an "open communication object". Usually, a child process shares the parent's "open communication object"s *AT THE TINE OF THE CHILD CREATION*. However, often, this sharing is broken very quickly: the parent may have set up those objects to close automatically in the child; the parent may close its "open communication object" after the spawning of the child. If two processes have not inherited the same "open communication object" from a common ancestor, there is no way that they can share the communication object. I am quite convinced that UWSGI will be set up to close "open communication object"s passed on to child processes. Thus, I see little chance that your current approach can succeed. From ali.r.keles at gmail.com Fri Nov 3 05:24:37 2017 From: ali.r.keles at gmail.com (=?UTF-8?B?QWxpIFLEsXphIEtFTEXFng==?=) Date: Fri, 3 Nov 2017 12:24:37 +0300 Subject: python3 byte decode Message-ID: Hi, Yesterday, while working with redis, i encountered a strange case. I want to ask why is the following `True` ``` "s" is b"s".decode() ``` while the followings are `False`? ``` "so" is b"so".decode() "som" is b"som".decode() "some" is b"some".decode() ``` Or vice versa? I read that `is` compares same objects, not values. So my question is why "s" and b"s".decode() are same objects, while the others aren't? My python version is 3.6.3. Thanks. -- -- Ali R?za Kele? From steve+python at pearwood.info Fri Nov 3 05:30:34 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 03 Nov 2017 20:30:34 +1100 Subject: A use-case for for...else with no break References: <59faef21$0$18601$b1db1813$d948b532@news.astraweb.com> <871slgszqu.fsf@nightsong.com> Message-ID: <59fc376c$0$18601$b1db1813$d948b532@news.astraweb.com> On Fri, 3 Nov 2017 04:22 pm, Paul Rubin wrote: > Steve D'Aprano writes: >> for x in something(): >> print(x, end='') > > print(''.join(something())) I hoped that people would recognise a simplified, toy example used only to illustrate a technique, rather than an exact copy and paste of something I'm actually doing. Try this instead: for s in sequence: if isinstance(s, bytes): try: s = s.decode.('utf-8') except UnicodeDecodeError: s = s.decode.('latin-1') print(s, end='') else: print() Without writing a helper function, got a fancy one liner for that too? Or another example, sometimes you really don't want to wait until the entire sequence is processed before printing any output. count = 0 for obj in sequence: if count == 60: print(' ', time.asctime()) count = 0 print('.', end='') expensive_time_consuming_process_that_might_take_minutes_or_hours(obj) count += 1 else: del count print() print("finished at", time.asctime()) Now honestly, do you think the more complex examples illustrate the point I was making, and the usefulness of for...else, better than the simple version? Because I think they make them more complicated and hard to understand, and distract from the point I am making. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From alexey.muranov at gmail.com Fri Nov 3 05:48:27 2017 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Fri, 03 Nov 2017 10:48:27 +0100 Subject: replacing `else` with `then` in `for` and `try` Message-ID: <1509702507.10265.0@smtp.gmail.com> On Thu, 2017-11-02 at 16:31 +0000, Jon Ribbens wrote: > > On 2017-11-02, Steve D'Aprano wrote: >> > > On Fri, 3 Nov 2017 12:39 am, Jon Ribbens wrote: >>> > > > Why would we want to make the language worse? It is fairly >>> > > > obvious >>> > > > what 'else' means, >> > > >> > > Yes, obvious and WRONG. > > > > Nope, obvious and right. > > I suppose that to continue this way we'd need at some point define somehow the meaning of "obvious." > >>> > > > whereas 'then' has an obvious meaning that is in >>> > > > fact the opposite of what it would actually do. >> > > >> > > Er... is today opposite day? Because 'then' describes precisely >> > > what it >> > > actually does. > > > > No, 'then' describes the opposite of what it does. The word 'then' > > implies something that always happens next, whereas 'else' conveys > > the correct meaning, which is something that happens if the course > > of the preceding piece of code did not go as expected. > > Jon, i get from this that for you, when there is no exception in `try`, or no `break` in a loop, the things did not go as expected. Either we need to agree that what is "expected" is subjective, or agree on some kind of formal or informal common meaning for it, because i would not have put it this way. 'Then' describes what happens next indeed, unless some extraordinary situation prevents it from happening, for example: try: go_to_the_bakery() then: buy_croissants(2) except BakeryClosed: go_to_the_grociery() buy_baguette(1) finally: come_back() I know this is a poor program example (why not to use a boolean return value instead of an exception, etc.), and i know that currently in Python `except` must precede `else`, it is just to illustrate the choice of terms. Best regards, Alexey. From storchaka at gmail.com Fri Nov 3 06:13:04 2017 From: storchaka at gmail.com (Serhiy Storchaka) Date: Fri, 3 Nov 2017 12:13:04 +0200 Subject: A use-case for for...else with no break In-Reply-To: <59faef21$0$18601$b1db1813$d948b532@news.astraweb.com> References: <59faef21$0$18601$b1db1813$d948b532@news.astraweb.com> Message-ID: 02.11.17 12:10, Steve D'Aprano ????: > Occasionally it is useful to loop over a bunch of stuff in the interactive > interpreter, printing them as you go on a single line: > > for x in something(): > print(x, end='') > > If you do that, the prompt overwrites your output, and you get a mess: > > > py> for x in "abcdefgh": > ... print(x, end='') > ... > py> efghpy> What the interpreter or configuration do you use? The standard interpreter uses '>>> ' as a prompt. From rosuav at gmail.com Fri Nov 3 07:03:58 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Nov 2017 22:03:58 +1100 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <1509702507.10265.0@smtp.gmail.com> References: <1509702507.10265.0@smtp.gmail.com> Message-ID: On Fri, Nov 3, 2017 at 8:48 PM, Alexey Muranov wrote: > 'Then' describes what happens next indeed, unless some extraordinary > situation prevents it from happening, for example: > > try: > go_to_the_bakery() > then: > buy_croissants(2) > except BakeryClosed: > go_to_the_grociery() > buy_baguette(1) > finally: > come_back() > > I know this is a poor program example (why not to use a boolean return value > instead of an exception, etc.), and i know that currently in Python `except` > must precede `else`, it is just to illustrate the choice of terms. What is the semantic difference between that code and the same without the "then:"? The normal behaviour of both Python code and human instruction sheets is to proceed to the next instruction if nothing went wrong: 1. Go to the office. 2. Sit down at the desk. 3. Open the third drawer down at your right hand. 4. Take the secret instructions. 5. Read and follow the instructions. -- if something goes wrong, take out your pistol and kill every zombie you find -- If there's no desk in the office, you won't continue to the next steps. But for the normal case, you don't have to say "then". ChrisA From rhodri at kynesim.co.uk Fri Nov 3 07:26:17 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 3 Nov 2017 11:26:17 +0000 Subject: Thread safety issue (I think) with defaultdict In-Reply-To: References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: On 02/11/17 20:24, Chris Angelico wrote: > Thank you. I've had this argument with many people, smart people (like > Steven), people who haven't grokked that all concurrency has costs - > that threads aren't magically more dangerous than other options. I'm with Steven. To be fair, the danger with threads is that most people don't understand thread-safety, and in particular don't understand either that they have a responsibility to ensure that shared data access is done properly or what the cost of that is. I've seen far too much thread-based code over the years that would have been markedly less buggy and not much slower if it had been written sequentially. -- Rhodri James *-* Kynesim Ltd From jon+usenet at unequivocal.eu Fri Nov 3 07:28:11 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 3 Nov 2017 11:28:11 -0000 (UTC) Subject: replacing `else` with `then` in `for` and `try` References: <1509702507.10265.0@smtp.gmail.com> Message-ID: On 2017-11-03, Alexey Muranov wrote: > 'Then' describes what happens next indeed, unless some extraordinary > situation prevents it from happening, for example: > > try: > go_to_the_bakery() > then: > buy_croissants(2) > except BakeryClosed: > go_to_the_grociery() > buy_baguette(1) > finally: > come_back() > > I know this is a poor program example (why not to use a boolean return > value instead of an exception, etc.), and i know that currently in > Python `except` must precede `else`, it is just to illustrate the > choice of terms. It looks like you're suggesting not just changing the 'else' keyword to 'then', but changing the syntax completely. The above is certainly not an improvement on the status quo, as it is completely counter-intuitive that exceptions in the 'then' clause will not be caught by the 'except' clauses. From jon+usenet at unequivocal.eu Fri Nov 3 07:49:15 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 3 Nov 2017 11:49:15 -0000 (UTC) Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-11-03, Steve D'Aprano wrote: > On Fri, 3 Nov 2017 03:31 am, Jon Ribbens wrote: >> No, it's an obvious bug. You have a 'for...else' with no 'break'. >> Like I said, that should probably be a syntax error. > > It should absolutely not be a syntax error. There's no reason for it > to be a syntax error, except to satisfy some arrogant and foolish > idea of purity. It'd be nice if you could be a little less rude. It's not an "arrogant and foolish idea of purity", it's to help people catch bugs in their code, and to aid their understanding of the language. > There are uncountable ways of writing code which is seemingly > "pointless", and we don't make it a syntax error. And there's uncountable ways of writing code which we *do* make a syntax error. I'm not sure what your point is there. >> No, 'then' describes the opposite of what it does. The word 'then' >> implies something that always happens next, > > Right, which is what happens with the for...else block. No. Ok, so look. It's obvious that you and I have different mental models of the situation here. You're thinking of 'for...else' as two arbitrary clauses that run consecutively unless the whole thing is aborted by a 'break', whereas I'm thinking of the 'for' clause as being a search for a situation that matches a condition and the 'else' clause being what happens if the condition is not matched (i.e. exactly the same as 'if...else'). Now there's nothing inherently *wrong* with your choice of mental model, except it's leading you into confusion because my model means the meaning of the 'else' keyword is intuitive and obvious, and yours means it's counter-intuitive and confusing. Your suggestion is that the fix is to change the language, my suggestion is to fix your model. I'd suggest that changing your mind is easier than changing the language ;-) Also, my model has the advantage that if what the 'for' clause is doing doesn't match the concept of 'searching for a match' then it's obvious that you shouldn't be using 'for...else' in the first place. Again, sure, the language doesn't currently strictly enforce the requirement for a 'break', but nevertheless if you don't have one you almost certainly have a bug. >> Yes, I saw that. It's possible you are the only person in the world >> ever to have done that. It would not make the interactive interpreter >> 'worse' in the slightest for that silly trick to be lost. > > Just because you personally haven't used this technique doesn't make it > a "silly trick". It's an incredibly obscure work-around for a different problem, i.e. an infelicity in the way the interactive prompt parses input blocks. If the parsing is a genuine issue then the answer is to fix that, not to look for hacks that almost never help anyway. > And while I thank you for the complement that I am the cleverest and most > insightful Python coder in the world, I didn't say anything even remotely resembling that. From bc at freeuk.com Fri Nov 3 09:00:09 2017 From: bc at freeuk.com (bartc) Date: Fri, 3 Nov 2017 13:00:09 +0000 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> Message-ID: On 03/11/2017 11:49, Jon Ribbens wrote: > On 2017-11-03, Steve D'Aprano wrote: >> Right, which is what happens with the for...else block. > > No. Ok, so look. It's obvious that you and I have different mental > models of the situation here. You're thinking of 'for...else' as two > arbitrary clauses that run consecutively unless the whole thing is > aborted by a 'break', whereas I'm thinking of the 'for' clause as > being a search for a situation that matches a condition and the > 'else' clause being what happens if the condition is not matched > (i.e. exactly the same as 'if...else'). > > Now there's nothing inherently *wrong* with your choice of mental > model, except it's leading you into confusion because my model means > the meaning of the 'else' keyword is intuitive and obvious, and yours > means it's counter-intuitive and confusing. Your suggestion is that > the fix is to change the language, my suggestion is to fix your model. > I'd suggest that changing your mind is easier than changing the > language ;-) I don't think there will be a short keyword that will suit everyone. It may be necessary to use this to spell out exactly how it works: for i in r: pass ... after_normal_loop_termination_then: pass ... (And now, there is the possibility of having an additional 'else' clause to cover abnormal termination via break. This time what 'else' does is more obvious.) -- bartc From steve+python at pearwood.info Fri Nov 3 09:59:09 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 04 Nov 2017 00:59:09 +1100 Subject: A use-case for for...else with no break References: <59faef21$0$18601$b1db1813$d948b532@news.astraweb.com> Message-ID: <59fc762d$0$18564$b1db1813$d948b532@news.astraweb.com> On Fri, 3 Nov 2017 09:13 pm, Serhiy Storchaka wrote: > What the interpreter or configuration do you use? The standard > interpreter uses '>>> ' as a prompt. I have this in my Python startup file: if (sys.version_info[0] >= 3 and os.name == 'posix' and os.environ['TERM'] in ['xterm', 'vt100']): # Make the prompt bold in Python 3. sys.ps1 = '\001\x1b[1m\002py> \001\x1b[0m\002' sys.ps2 = '\001\x1b[1m\002... \001\x1b[0m\002' else: sys.ps1 = 'py> ' -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Fri Nov 3 10:32:21 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Nov 2017 01:32:21 +1100 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> Message-ID: On Fri, Nov 3, 2017 at 10:49 PM, Jon Ribbens wrote: > On 2017-11-03, Steve D'Aprano wrote: >> On Fri, 3 Nov 2017 03:31 am, Jon Ribbens wrote: >>> No, it's an obvious bug. You have a 'for...else' with no 'break'. >>> Like I said, that should probably be a syntax error. >> >> It should absolutely not be a syntax error. There's no reason for it >> to be a syntax error, except to satisfy some arrogant and foolish >> idea of purity. > > It'd be nice if you could be a little less rude. It's not an "arrogant > and foolish idea of purity", it's to help people catch bugs in their > code, and to aid their understanding of the language. That wasn't rudeness. That was an accurate description of the situation. It is entirely possible for code to be opinionated, arrogant, foolish, and all those other adjectives that we normally appropriate to people. I don't think it would do much for comprehension. And if it's to catch bugs, that is NOT the job of syntax - it's the job of linters. By all means, have a linter that says "else clause after loop with no break"; but don't make it *illegal*. >> There are uncountable ways of writing code which is seemingly >> "pointless", and we don't make it a syntax error. > > And there's uncountable ways of writing code which we *do* make a > syntax error. I'm not sure what your point is there. The point is that syntax errors are for things that cannot possibly make sense, not for things that are likely to be bugs. There are a very few exceptions, and they're usually things that are massive bug magnets, or where the semantics are subtly different. And I can't think of any examples right now other than the way "async def" forces a function to be a coroutine even if it has no "await"s in it; note that it does *not* make a syntax error, it simply causes the semantics to be correct anyway. >>> No, 'then' describes the opposite of what it does. The word 'then' >>> implies something that always happens next, >> >> Right, which is what happens with the for...else block. > > No. Ok, so look. It's obvious that you and I have different mental > models of the situation here. You're thinking of 'for...else' as two > arbitrary clauses that run consecutively unless the whole thing is > aborted by a 'break', whereas I'm thinking of the 'for' clause as > being a search for a situation that matches a condition and the > 'else' clause being what happens if the condition is not matched > (i.e. exactly the same as 'if...else'). > > Now there's nothing inherently *wrong* with your choice of mental > model, except it's leading you into confusion because my model means > the meaning of the 'else' keyword is intuitive and obvious, and yours > means it's counter-intuitive and confusing. Your suggestion is that > the fix is to change the language, my suggestion is to fix your model. > I'd suggest that changing your mind is easier than changing the > language ;-) If anything, I would say that Steven's model is at a lower abstraction layer than yours - though IMO your model is more of an example use-case than a description of what is actually happening. >>> Yes, I saw that. It's possible you are the only person in the world >>> ever to have done that. It would not make the interactive interpreter >>> 'worse' in the slightest for that silly trick to be lost. >> >> Just because you personally haven't used this technique doesn't make it >> a "silly trick". > > It's an incredibly obscure work-around for a different problem, > i.e. an infelicity in the way the interactive prompt parses input > blocks. If the parsing is a genuine issue then the answer is to > fix that, not to look for hacks that almost never help anyway. TBH I prefer the "if 1:" trick to gather code into a block. But that requires pre-planning, whereas slapping an "else:" after the loop can be done after the event. ChrisA From rosuav at gmail.com Fri Nov 3 10:47:11 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Nov 2017 01:47:11 +1100 Subject: python3 byte decode In-Reply-To: References: Message-ID: On Fri, Nov 3, 2017 at 8:24 PM, Ali R?za KELE? wrote: > Hi, > > Yesterday, while working with redis, i encountered a strange case. > > I want to ask why is the following `True` > > ``` > "s" is b"s".decode() > ``` > > while the followings are `False`? > > ``` > "so" is b"so".decode() > "som" is b"som".decode() > "some" is b"some".decode() > ``` > > Or vice versa? > > I read that `is` compares same objects, not values. So my question is > why "s" and b"s".decode() are same objects, while the others aren't? > > My python version is 3.6.3. You shouldn't be comparing string objects with 'is'. Sometimes two equal strings will be identical, and sometimes they won't. All you're seeing is that the interpreter happened to notice and/or cache this particular lookup. ChrisA From rosuav at gmail.com Fri Nov 3 10:50:13 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Nov 2017 01:50:13 +1100 Subject: Thread safety issue (I think) with defaultdict In-Reply-To: References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: On Fri, Nov 3, 2017 at 10:26 PM, Rhodri James wrote: > On 02/11/17 20:24, Chris Angelico wrote: >> >> Thank you. I've had this argument with many people, smart people (like >> Steven), people who haven't grokked that all concurrency has costs - >> that threads aren't magically more dangerous than other options. > > > I'm with Steven. To be fair, the danger with threads is that most people > don't understand thread-safety, and in particular don't understand either > that they have a responsibility to ensure that shared data access is done > properly or what the cost of that is. I've seen far too much thread-based > code over the years that would have been markedly less buggy and not much > slower if it had been written sequentially. Yes, but what you're seeing is that *concurrent* code is more complicated than *sequential* code. Would the code in question have been less buggy if it had used multiprocessing instead of multithreading? What if it used explicit yield points? Multiprocessing brings with it a whole lot of extra complications around moving data around. Multithreading brings with it a whole lot of extra complications around NOT moving data around. Yield points bring with them the risk of locking another thread out unexpectedly (particularly since certain system calls aren't async-friendly on certain OSes). All three models have their pitfalls. It's not that threads are somehow worse than every other model. ChrisA From rhodri at kynesim.co.uk Fri Nov 3 11:11:11 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 3 Nov 2017 15:11:11 +0000 Subject: Thread safety issue (I think) with defaultdict In-Reply-To: References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: On 03/11/17 14:50, Chris Angelico wrote: > On Fri, Nov 3, 2017 at 10:26 PM, Rhodri James wrote: >> On 02/11/17 20:24, Chris Angelico wrote: >>> >>> Thank you. I've had this argument with many people, smart people (like >>> Steven), people who haven't grokked that all concurrency has costs - >>> that threads aren't magically more dangerous than other options. >> >> >> I'm with Steven. To be fair, the danger with threads is that most people >> don't understand thread-safety, and in particular don't understand either >> that they have a responsibility to ensure that shared data access is done >> properly or what the cost of that is. I've seen far too much thread-based >> code over the years that would have been markedly less buggy and not much >> slower if it had been written sequentially. > > Yes, but what you're seeing is that *concurrent* code is more > complicated than *sequential* code. Would the code in question have > been less buggy if it had used multiprocessing instead of > multithreading? What if it used explicit yield points? My experience with situations where I can do a reasonable comparison is limited, but the answer appears to be "Yes". Multiprocessing > brings with it a whole lot of extra complications around moving data > around. People generally understand how to move data around, and the mistakes are usually pretty obvious when they happen. People may not understand how to move data around efficiently, but that's a separate argument. Multithreading brings with it a whole lot of extra > complications around NOT moving data around. I think this involves more subtle bugs that are harder to spot. People seem to find it harder to reason about atomicity and realising that widely separated pieces of code may interact unexpectedly. Yield points bring with > them the risk of locking another thread out unexpectedly (particularly > since certain system calls aren't async-friendly on certain OSes). I've got to admit I find coroutines straightforward, but I did cut my teeth on a cooperative OS. It certainly makes the atomicity issues easier to deal with. All > three models have their pitfalls. Assuredly. I just think threads are soggier and hard to light^W^W^W^W^W prone to subtler and more mysterious-looking bugs. -- Rhodri James *-* Kynesim Ltd From steve+python at pearwood.info Fri Nov 3 11:45:14 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 04 Nov 2017 02:45:14 +1100 Subject: Thread safety issue (I think) with defaultdict References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: <59fc8f0c$0$18611$b1db1813$d948b532@news.astraweb.com> On Sat, 4 Nov 2017 01:50 am, Chris Angelico wrote: > On Fri, Nov 3, 2017 at 10:26 PM, Rhodri James wrote: >> I'm with Steven. To be fair, the danger with threads is that most people >> don't understand thread-safety, and in particular don't understand either >> that they have a responsibility to ensure that shared data access is done >> properly or what the cost of that is. I've seen far too much thread-based >> code over the years that would have been markedly less buggy and not much >> slower if it had been written sequentially. > > Yes, but what you're seeing is that *concurrent* code is more > complicated than *sequential* code. Would the code in question have > been less buggy if it had used multiprocessing instead of > multithreading? Maybe. There's no way to be sure unless you actually compare a threading implementation with a processing implementation -- and they have to be "equally good, for the style" implementations. No fair comparing the multiprocessing equivalent of "Stooge Sort" with the threading equivalent of "Quick Sort", and concluding that threading is better. However, we can predict the likelihood of which will be less buggy by reasoning in general principles. And the general principle is that shared data tends, all else being equal, to lead to more bugs than no shared data. The more data is shared, the more bugs, more or less. I don't know if there are any hard scientific studies on this, but experience and anecdote strongly suggests it is true. Programming is not yet fully evidence-based. For example, most of us accept "global variables considered harmful". With few exceptions, the use of application-wide global variables to communicate between functions is harmful and leads to problems. This isn't because of any sort of mystical or magical malignity from global variables. It is because the use of global variables adds coupling between otherwise distant parts of the code, and that adds complexity, and the more complex code is, the more likely we mere humans are to screw it up. So, all else being equal, which is likely to have more bugs? 1. Multiprocessing code with very little coupling between processes; or 2. Threaded code with shared data and hence higher coupling between threads? Obviously the *best* threaded code will have fewer bugs than the *worst* multiprocessing code, but my heuristic is that, in general, the average application using threading is likely to be more highly coupled, hence more complicated, than the equivalent using multiprocessing. (Async is too new, and to me, too confusing, for me to have an opinion on yet, but I lean slightly towards the position that deterministic task-switching is probably better than non-deterministic.) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From alexey.muranov at gmail.com Fri Nov 3 12:15:08 2017 From: alexey.muranov at gmail.com (Alexey Muranov) Date: Fri, 03 Nov 2017 17:15:08 +0100 Subject: replacing `else` with `then` in `for` and `try` Message-ID: <1509725708.5518.0@smtp.gmail.com> On Fri, 2017-11-03 at 22:03 +1100, Chris Angelico wrote: > On Fri, Nov 3, 2017 at 8:48 PM, Alexey Muranov com> wrote: > > 'Then' describes what happens next indeed, unless some > > extraordinary > > situation prevents it from happening, for example: > > > > try: > > go_to_the_bakery() > > then: > > buy_croissants(2) > > except BakeryClosed: > > go_to_the_grociery() > > buy_baguette(1) > > finally: > > come_back() > > > > I know this is a poor program example (why not to use a boolean > > return value > > instead of an exception, etc.), and i know that currently in Python > > `except` > > must precede `else`, it is just to illustrate the choice of terms. > > What is the semantic difference between that code and the same > without the "then:"? Chris, the semantic difference is that their meanings/behaviours are not identical (i imply that `then` here does what `else` currently does). I agree however that from practical viewpoint the difference will probably never be observable (unless the person enters the bakery and asks for croissants, but during this time the baker exits the bakery and closes it to go on vacation). I can try to think of a better example if you give me any good use-case for `else` in `try`. I have searched on-line, and on StackOverflow in particular, but didn't find anything better that this: * https://stackoverflow.com/a/6051978 People seem very shy when it comes to giving a real-life example of `else` in `try`. Alexey. From rosuav at gmail.com Fri Nov 3 12:18:11 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Nov 2017 03:18:11 +1100 Subject: Thread safety issue (I think) with defaultdict In-Reply-To: <59fc8f0c$0$18611$b1db1813$d948b532@news.astraweb.com> References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> <59fc8f0c$0$18611$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sat, Nov 4, 2017 at 2:45 AM, Steve D'Aprano wrote: > So, all else being equal, which is likely to have more bugs? > > > 1. Multiprocessing code with very little coupling between processes; or > > 2. Threaded code with shared data and hence higher coupling between threads? > Obviously, option 1. But that's "all else being equal". How often can you actually have your processes that decoupled? And if you can write your code to be completely (or largely) decoupled, what's to stop you having your *threads* equally decoupled? You're assuming that "running in the same memoryspace" equates to "higher coupling", which is no more proven than any other assertion. Ultimately, real-world code IS going to have some measure of coupling (you could concoct a scenario in which requests are handled 100% independent of each other, but even with a web application, there's going to be SOME connection between different requests), so all you do is move it around (eg in a web app scenario, the most common solution is to do all coupling through a database or equivalent). ChrisA From rosuav at gmail.com Fri Nov 3 12:24:42 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Nov 2017 03:24:42 +1100 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <1509725708.5518.0@smtp.gmail.com> References: <1509725708.5518.0@smtp.gmail.com> Message-ID: On Sat, Nov 4, 2017 at 3:15 AM, Alexey Muranov wrote: > On Fri, 2017-11-03 at 22:03 +1100, Chris Angelico wrote: >> On Fri, Nov 3, 2017 at 8:48 PM, Alexey Muranov > com> wrote: >> > 'Then' describes what happens next indeed, unless some >> > extraordinary >> > situation prevents it from happening, for example: >> > >> > try: >> > go_to_the_bakery() >> > then: >> > buy_croissants(2) >> > except BakeryClosed: >> > go_to_the_grociery() >> > buy_baguette(1) >> > finally: >> > come_back() >> > >> > I know this is a poor program example (why not to use a boolean >> > return value >> > instead of an exception, etc.), and i know that currently in Python >> > `except` >> > must precede `else`, it is just to illustrate the choice of terms. >> >> What is the semantic difference between that code and the same >> without the "then:"? > > Chris, > > the semantic difference is that their meanings/behaviours are not identical > (i imply that `then` here does what `else` currently does). I agree however > that from practical viewpoint the difference will probably never be > observable (unless the person enters the bakery and asks for croissants, but > during this time the baker exits the bakery and closes it to go on > vacation). Okay, so what you're doing is taking the current "try/else" semantics, and hoisting the "happy path" up to immediately underneath the part guarded by the try. That's not unreasonable, but also not a huge advantage. It's basically saying: try: do_stuff except None: # let's pretend print("all is well") except ValueError: print("do_stuff has the wrong value") finally: print("we're done") But if the difference between this and the current layout (with "else" coming *after* the except blocks) is significant to you, I would recommend refactoring the try/finally into a context manager: with car_trip() as trip: try: trip.goto(bakery) buy_croissants(2) except BakeryClosed: trip.goto(grocery) buy_baguette(1) The context manager takes care of bringing us home unconditionally, leaving us with cleaner logic. ChrisA From grant.b.edwards at gmail.com Fri Nov 3 12:28:03 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 3 Nov 2017 16:28:03 +0000 (UTC) Subject: Thread safety issue (I think) with defaultdict References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> <59fc8f0c$0$18611$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-11-03, Chris Angelico wrote: > On Sat, Nov 4, 2017 at 2:45 AM, Steve D'Aprano > wrote: >> So, all else being equal, which is likely to have more bugs? >> >> >> 1. Multiprocessing code with very little coupling between processes; or >> >> 2. Threaded code with shared data and hence higher coupling between threads? >> > > Obviously, option 1. But that's "all else being equal". How often can > you actually have your processes that decoupled? And if you can write > your code to be completely (or largely) decoupled, what's to stop you > having your *threads* equally decoupled? You're assuming that "running > in the same memoryspace" equates to "higher coupling", which is no > more proven than any other assertion. The big difference is that with threaded code you can have accidental coupling. With multiprocessing, code you have to explicitly work to create coupling. That said, I do a lot of threading coding (in both Python and C), and have never found it particularly tricky. It does require that you understand what you're doing and probably doesn't work well if you're a stack-overflow, cargo-cult, cut-and-paste programmer. But then again, what does? -- Grant Edwards grant.b.edwards Yow! Maybe I should have at asked for my Neutron Bomb gmail.com in PAISLEY -- From ian.g.kelly at gmail.com Fri Nov 3 12:39:36 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 3 Nov 2017 10:39:36 -0600 Subject: Thread safety issue (I think) with defaultdict In-Reply-To: References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: On Thu, Nov 2, 2017 at 10:27 AM, Israel Brewster wrote: > >> On Nov 1, 2017, at 4:53 PM, Steve D'Aprano wrote: >> >> On Thu, 2 Nov 2017 05:53 am, Israel Brewster wrote: >> >> [...] >>> So the end result is that the thread that "updates" the dictionary, and the >>> thread that initially *populates* the dictionary are actually running in >>> different processes. >> >> If they are in different processes, that would explain why the second >> (non)thread sees an empty dict even after the first thread has populated it: >> >> >> # from your previous post >>> Length at get AC: 54 ID: 4524152200 Time: 2017-11-01 09:41:24.474788 >>> Length At update: 1 ID: 4524152200 Time: 2017-11-01 09:41:24.784399 >>> Length At update: 2 ID: 4524152200 Time: 2017-11-01 09:41:25.228853 >> >> >> You cannot rely on IDs being unique across different processes. Its an >> unfortunately coincidence(!) that they end up with the same ID. > > I think it's more than a coincidence, given that it is 100% reproducible. Plus, in an earlier debug test I was calling print() on the defaultdict object, which gives output like "", where presumably the 0x1066467f0 is a memory address (correct me if I am wrong in that). In every case, that address was the same. So still a bit puzzling. If the empty dict is created before the process is forked then I don't think it's all that surprising. From gheskett at shentel.net Fri Nov 3 12:52:00 2017 From: gheskett at shentel.net (Gene Heskett) Date: Fri, 3 Nov 2017 12:52:00 -0400 Subject: Thread safety issue (I think) with defaultdict In-Reply-To: References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> Message-ID: <201711031252.00520.gheskett@shentel.net> On Friday 03 November 2017 10:50:13 Chris Angelico wrote: > On Fri, Nov 3, 2017 at 10:26 PM, Rhodri James wrote: > > On 02/11/17 20:24, Chris Angelico wrote: > >> Thank you. I've had this argument with many people, smart people > >> (like Steven), people who haven't grokked that all concurrency has > >> costs - that threads aren't magically more dangerous than other > >> options. > > > > I'm with Steven. To be fair, the danger with threads is that most > > people don't understand thread-safety, and in particular don't > > understand either that they have a responsibility to ensure that > > shared data access is done properly or what the cost of that is. > > I've seen far too much thread-based code over the years that would > > have been markedly less buggy and not much slower if it had been > > written sequentially. > > Yes, but what you're seeing is that *concurrent* code is more > complicated than *sequential* code. Would the code in question have > been less buggy if it had used multiprocessing instead of > multithreading? What if it used explicit yield points? Multiprocessing > brings with it a whole lot of extra complications around moving data > around. Multithreading brings with it a whole lot of extra > complications around NOT moving data around. Yield points bring with > them the risk of locking another thread out unexpectedly (particularly > since certain system calls aren't async-friendly on certain OSes). All > three models have their pitfalls. It's not that threads are somehow > worse than every other model. > > ChrisA I think that this discussion of threads and threading must be a different context than threading as I am using it in linuxcnc. There, one assigns a function to run in a certain sequence in an assigned thread, which there can be several of. There, each thread is assigned a repetition rate, and the higher repetition rate stuff can always interrupt the slower threaded function in order to get the real time stuff done in a usable for the job time frame, and the high frequency thread can be as fast as every 25 microseconds on a good motherboard. Surprisingly, this seems to be far more board dependent than processor dependent, altho its pushing an AMD processor quite hard at 40 microseconds, while the slower intel atoms can do 25 microseconds with about the same effort. This is where a stepper motor is being stepped by software which didles pins on a parport. And it limits how fast you can move the motor compared to using an fpga card running at 200 MHz, not because of the step rate, but because of the latency of the mobo/cpu combination. Jitter in step rate issuance is death to high performance with stepper motors because torque to do usefull work vanishes when the instant speed of the motor is wobbling with that timing jitter. OTOH, hand controls of a machine using an encoder dial are nicely done in a thread running at 100 Hz, far more reliably that I can do it from the keyboard on a raspberry pi 3b. Why? The dials data goes into linuxcnc by way of a hardware fpga card that talks to the pi over an SPI buss, with the pi writing 32 bit packets at 41 megabaud, and reading the results at 25 megabaud. It doesn't have to get thru that usb2 internal hub in the pi that all the other i/o has to go thru. Mouse and keyboard events get dropped on the floor, particularly dangerous when its a keyup event that gets dropped. The machine keeps moving until it crashes into something, often breaking drive parts or cutting tooling, all of which cost real money. My point is that with an interpretor such as hal managing things, threads Just Work(TM). It does of course take a specially built kernel to do that magic. I'll get me coat. 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 jon+usenet at unequivocal.eu Fri Nov 3 13:02:12 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 3 Nov 2017 17:02:12 -0000 (UTC) Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-11-03, Chris Angelico wrote: > On Fri, Nov 3, 2017 at 10:49 PM, Jon Ribbens wrote: >>> It should absolutely not be a syntax error. There's no reason for it >>> to be a syntax error, except to satisfy some arrogant and foolish >>> idea of purity. >> >> It'd be nice if you could be a little less rude. It's not an "arrogant >> and foolish idea of purity", it's to help people catch bugs in their >> code, and to aid their understanding of the language. > > That wasn't rudeness. Yes, it was. >> No. Ok, so look. It's obvious that you and I have different mental >> models of the situation here. You're thinking of 'for...else' as two >> arbitrary clauses that run consecutively unless the whole thing is >> aborted by a 'break', whereas I'm thinking of the 'for' clause as >> being a search for a situation that matches a condition and the >> 'else' clause being what happens if the condition is not matched >> (i.e. exactly the same as 'if...else'). >> >> Now there's nothing inherently *wrong* with your choice of mental >> model, except it's leading you into confusion because my model means >> the meaning of the 'else' keyword is intuitive and obvious, and yours >> means it's counter-intuitive and confusing. Your suggestion is that >> the fix is to change the language, my suggestion is to fix your model. >> I'd suggest that changing your mind is easier than changing the >> language ;-) > > If anything, I would say that Steven's model is at a lower abstraction > layer than yours Yes, absolutely. > - though IMO your model is more of an example use-case than a > description of what is actually happening. It's a high-level way of thinking about it that avoids confusion and leads to correct code. Unless you can come up with a *sensible* use-case that it doesn't cover, it's also a comprehensive way of thinking about it. > TBH I prefer the "if 1:" trick to gather code into a block. But that > requires pre-planning, Or pressing up-arrow ;-) > whereas slapping an "else:" after the loop can be done after the event. From steve+python at pearwood.info Fri Nov 3 13:03:04 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 04 Nov 2017 04:03:04 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> Message-ID: <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> On Fri, 3 Nov 2017 10:49 pm, Jon Ribbens wrote: > On 2017-11-03, Steve D'Aprano wrote: >> On Fri, 3 Nov 2017 03:31 am, Jon Ribbens wrote: >>> No, it's an obvious bug. You have a 'for...else' with no 'break'. >>> Like I said, that should probably be a syntax error. >> >> It should absolutely not be a syntax error. There's no reason for it >> to be a syntax error, except to satisfy some arrogant and foolish >> idea of purity. > > It'd be nice if you could be a little less rude. How else should we respond to the idea that something that has been legal syntax for over twenty years and is in no way an error should be treated as a syntax error, just to satisfy the opinion that nobody should write for...else unless they are performing a search and it contains a break? >> There are uncountable ways of writing code which is seemingly >> "pointless", and we don't make it a syntax error. > > And there's uncountable ways of writing code which we *do* make a > syntax error. I'm not sure what your point is there. None of these are syntax errors: if False: do_something() for x in '': pass if True: pass and uncountable other pieces of code which are, from some perspective, pointless. We don't make them syntax errors because *pointless* doesn't imply is is an error. You think that a for...else loop with no break is pointless and "silly", even when I demonstrate an actual use for it. Too bad. Even if it is "silly", in your opinion, that still does not make it an error. Is my point clear now? >>> No, 'then' describes the opposite of what it does. The word 'then' >>> implies something that always happens next, >> >> Right, which is what happens with the for...else block. > > No. Yes. It is not a matter of opinion that the `else` clause executes after execution falls out the bottom of the loop, i.e. the loop runs, THEN the `else` block runs. It is an objective fact that in the absence of something which causes execution to jump outside of the loop altogether (a return, a raise, or a break) the execution order is loop first, then `else` block. Both of these two sentences makes sense in English: "Execution reaches the end of the loop, and THEN the `else` block runs." "Execution reaches the end of the loop, or ELSE the `else` block runs." but only the first describes what Python's for...else statement actually does. This is not just my mental model, it is the actual objective behaviour of the for...else statement. > Ok, so look. It's obvious that you and I have different mental > models of the situation here. You're thinking of 'for...else' as two > arbitrary clauses that run consecutively Scrub out the "arbitrary", and that is exactly what they are. They aren't arbitrary: the `else` is optional, but if present it must follow after the loop, and never the other way around. The code inside the blocks can, of course, be any legal code we like. There's no rule that says "only code approved by Jon Ribbens' is allowed", and there's no rule that says "only searches are allowed". > unless the whole thing is aborted by a 'break', Or return, raise, os._exit, os.abort, or having the process killed by the OS. For simplicity we can ignore the last three (as well as more exotic mechanisms such as "pull the power supply out" or "drop a two-tonne weight on the computer"), but return and raise are common ways of exiting a loop and should not be ignored or forgotten. > whereas I'm thinking of the 'for' clause as > being a search for a situation that matches a condition and the > 'else' clause being what happens if the condition is not matched > (i.e. exactly the same as 'if...else'). That model conflates one specific use-case for the for...else statement with the semantics of the statement, rather like insisting that "print displays a greeting to the world" merely because 'print("Hello, World")' is so common. The for loop does not necessarily perform a search: count = 1 for obj in sequence: if count > MAX_OBJECTS: print("too many objects, halting") break process(obj) else: print("finished") According to your mental model, this code is... what? Illegal? Silly? Impossible? A syntax error? Obviously wrong and almost certainly buggy? Even when there is a search, the sense of the search may be reversed from your mental model: for request in sequence: if 'please' not in request: break process(request) else: print('done') return raise SysExit('failure to say please') It doesn't matter if you can think of alternative ways of writing these code snippets. They're legal, and they work, and your mental model doesn't cover them, at all or easily. That means your mental model is at best incomplete. This is what happens when you treat one use-case for a general purpose statement as synonymous with the statement itself. `for...else` is not just for searching, and the `else` clause doesn't necessarily run if the search is unsuccessful. You've trapped yourself into considering the *motivating* use-case of for...else as the *only* allowable use-case. Quoting you: if what the 'for' clause is doing doesn't match the concept of 'searching for a match' then it's obvious that you shouldn't be using 'for...else' Or to put it another way: If the meal you are preparing isn't a peanut butter and jelly sandwich, then it is obvious that you shouldn't be using bread in the first place. which is no more or less foolish than your comment. for...else is not a dedicated search function. It is a *control structure*, it controls the execution order of code. We can use it for ANY purpose we like, not just searching. > Now there's nothing inherently *wrong* with your choice of mental > model, except it's leading you into confusion What *did* lead me into confusion long ago was the keyword `else`. It took me an embarrassingly long time to understand what for...else actually does, because of the misleading keyword. It was only after I realised that the `else` block runs after execution falls out the bottom of the loop that it became clear. In other words, it was only when I realised that `else` would be better written as `then` that I understood the behaviour of the statement. If I read it as "else", then the natural interpretation is that the block runs only if the loop doesn't run: for x in seq: pass else: print("seq is empty") In this very thread, we've seen experienced Pythonistas fall into that trap. > because my model means the meaning of the 'else' keyword is intuitive > and obvious, Your mental model cannot explain any use of for...else that doesn't involve a search, or where the `else` block runs only on an unsuccessful search. I've already given examples. You'll probably dismiss them as "silly" because they don't meet your mental model, and insist that I would be wrong to use them. Your mental model cannot cope with the fact that for...else is a generic control structure. It is not a dedicated "search" command. We can put anything we like inside the blocks, even if it fails to match your mental model. That just makes your model a poor match to reality. Your response to code that doesn't match your mental model is to say that it is obviously wrong and probably buggy and should be made into a syntax error if possible. Rather than accept the limitations of your poor mental model, you want to ban code that your model doesn't deal with. > and yours > means it's counter-intuitive and confusing. Your suggestion is that > the fix is to change the language, my suggestion is to fix your model. > I'd suggest that changing your mind is easier than changing the > language ;-) And my mental model is to treat "else" in this concept as some foreign word, perhaps Dutch, a false-friend that actually means "next" but due to some awful coincidence happens to look exactly like the English word for "else". > Also, my model has the advantage that if what the 'for' clause is > doing doesn't match the concept of 'searching for a match' then it's > obvious that you shouldn't be using 'for...else' in the first place. Because legal, working code doesn't meet your mental model, it must be wrong. > Again, sure, the language doesn't currently strictly enforce the > requirement for a 'break', but nevertheless if you don't have one > you almost certainly have a bug. Ah yes, because it is inconceivable that anyone might have thought of a use for for...else without a break. And if they have, well, it must be buggy. Never mind if it works correctly or solves a problem, those things aren't important. What matters is that only code that matches your model is allowed. >>> Yes, I saw that. It's possible you are the only person in the world >>> ever to have done that. It would not make the interactive interpreter >>> 'worse' in the slightest for that silly trick to be lost. >> >> Just because you personally haven't used this technique doesn't make it >> a "silly trick". > > It's an incredibly obscure work-around for a different problem, You mean a different problem to "searching"? Yes indeed it is. Believe it or not, for...else is not limited to only solving problems involving searching. And as for "obscure", of course it would seem obscure to people who think that the only use of for...else is for searching. > i.e. an infelicity in the way the interactive prompt parses input > blocks. If the parsing is a genuine issue then the answer is to > fix that, not to look for hacks that almost never help anyway. It helps solve my problem perfectly well, thank you. And you're welcome to raise a bug report, but even if the REPL display issue is fixed in Python 3.7, I'll still be using this technique from time to time in older versions. >> And while I thank you for the complement that I am the cleverest and most >> insightful Python coder in the world, > > I didn't say anything even remotely resembling that. That was sarcasm. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jon+usenet at unequivocal.eu Fri Nov 3 13:44:40 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 3 Nov 2017 17:44:40 -0000 (UTC) Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-11-03, Steve D'Aprano wrote: > The for loop does not necessarily perform a search: > > count = 1 > for obj in sequence: > if count > MAX_OBJECTS: > print("too many objects, halting") > break > process(obj) > else: > print("finished") > > According to your mental model, this code is... what? Illegal? Silly? > Impossible? A syntax error? That conforms to my model. It's searching for the condition 'count > MAX_OBJECTS'. > Even when there is a search, the sense of the search may be reversed > from your mental model: > > for request in sequence: > if 'please' not in request: > break > process(request) > else: > print('done') > return > raise SysExit('failure to say please') That's searching for the condition "'please' not in request". > It doesn't matter if you can think of alternative ways of writing these code > snippets. They're legal, and they work, and your mental model doesn't cover > them, at all or easily. That means your mental model is at best incomplete. You've yet to come up with one that it doesn't cover. > In other words, it was only when I realised that `else` would be better > written as `then` that I understood the behaviour of the statement. If I read > it as "else", then the natural interpretation is that the block runs only if > the loop doesn't run: You're repeating yourself. > You'll probably dismiss them as "silly" because they don't meet your mental > model, and insist that I would be wrong to use them. As above, you're mistaken. > Your response to code that doesn't match your mental model is to say > that it is obviously wrong and probably buggy and should be made > into a syntax error if possible. No, it isn't. Try reading again what I actually wrote. > And my mental model is to treat "else" in this concept as some foreign word, > perhaps Dutch, a false-friend that actually means "next" but due to some > awful coincidence happens to look exactly like the English word for "else". And that's leading you into confusion, as you've demonstrated. > Ah yes, because it is inconceivable that anyone might have thought of a use > for for...else without a break. It's not inconceivable, but nobody has thought of a sensible use so far (by which I mean one that shows it's a useful feature). > What matters is that only code that matches your model is allowed. You do seem to enjoy telling other people what their opinions are. Frankly, I don't know why I even bother having opinions when you're here to tell me what they are. In future, I'll just come to you to find out what I think. >> It's an incredibly obscure work-around for a different problem, > > You mean a different problem to "searching"? Yes indeed it is. No, I mean a problem that has nothing to do with 'for...else' clauses. If your door is stuck then you might climb in through a window, but that doesn't mean that the purpose of windows is to be entrances, or that windows should be designed to make them better entrances, or that the problem isn't the stuck door. >>> And while I thank you for the complement that I am the cleverest and most >>> insightful Python coder in the world, >> >> I didn't say anything even remotely resembling that. > > That was sarcasm. Yes dear. From ian.g.kelly at gmail.com Fri Nov 3 13:55:05 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 3 Nov 2017 11:55:05 -0600 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> Message-ID: On Fri, Nov 3, 2017 at 8:32 AM, Chris Angelico wrote: > On Fri, Nov 3, 2017 at 10:49 PM, Jon Ribbens wrote: >> On 2017-11-03, Steve D'Aprano wrote: >>> On Fri, 3 Nov 2017 03:31 am, Jon Ribbens wrote: >>>> No, it's an obvious bug. You have a 'for...else' with no 'break'. >>>> Like I said, that should probably be a syntax error. >>> >>> It should absolutely not be a syntax error. There's no reason for it >>> to be a syntax error, except to satisfy some arrogant and foolish >>> idea of purity. >> >> It'd be nice if you could be a little less rude. It's not an "arrogant >> and foolish idea of purity", it's to help people catch bugs in their >> code, and to aid their understanding of the language. > > That wasn't rudeness. That was an accurate description of the > situation. It is entirely possible for code to be opinionated, > arrogant, foolish, and all those other adjectives that we normally > appropriate to people. Steve was clearly referring to the coder, not the code. Please stop defending the use of incivility on this list. From israel at ravnalaska.net Fri Nov 3 14:12:39 2017 From: israel at ravnalaska.net (Israel Brewster) Date: Fri, 3 Nov 2017 10:12:39 -0800 Subject: Thread safety issue (I think) with defaultdict In-Reply-To: References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: ----------------------------------------------- Israel Brewster Systems Analyst II Ravn Alaska 5245 Airport Industrial Rd Fairbanks, AK 99709 (907) 450-7293 ----------------------------------------------- > On Nov 3, 2017, at 7:11 AM, Rhodri James wrote: > > On 03/11/17 14:50, Chris Angelico wrote: >> On Fri, Nov 3, 2017 at 10:26 PM, Rhodri James wrote: >>> On 02/11/17 20:24, Chris Angelico wrote: >>>> >>>> Thank you. I've had this argument with many people, smart people (like >>>> Steven), people who haven't grokked that all concurrency has costs - >>>> that threads aren't magically more dangerous than other options. >>> >>> >>> I'm with Steven. To be fair, the danger with threads is that most people >>> don't understand thread-safety, and in particular don't understand either >>> that they have a responsibility to ensure that shared data access is done >>> properly or what the cost of that is. I've seen far too much thread-based >>> code over the years that would have been markedly less buggy and not much >>> slower if it had been written sequentially. >> Yes, but what you're seeing is that *concurrent* code is more >> complicated than *sequential* code. Would the code in question have >> been less buggy if it had used multiprocessing instead of >> multithreading? What if it used explicit yield points? > > My experience with situations where I can do a reasonable comparison is limited, but the answer appears to be "Yes". > Multiprocessing >> brings with it a whole lot of extra complications around moving data >> around. > > People generally understand how to move data around, and the mistakes are usually pretty obvious when they happen. I think the existence of this thread indicates otherwise :-) This mistake was far from obvious, and clearly I didn't understand properly how to move data around *between processes*. Unless you are just saying I am ignorant or something? :-) > People may not understand how to move data around efficiently, but that's a separate argument. > > Multithreading brings with it a whole lot of extra >> complications around NOT moving data around. > > I think this involves more subtle bugs that are harder to spot. Again, the existence of this thread indicates otherwise. This bug was quite subtile and hard to spot. It was only when I started looking at how many times a given piece of code was called (specifically, the part that handled data coming in for which there wasn't an entry in the dictionary) that I spotted the problem. If I hadn't had logging in place in that code block, I would have never realized it wasn't working as intended. You don't get much more subtile than that. And, furthermore, it only existed because I *wasn't* using threads. This bug simply doesn't exist in a threaded model, only in a multiprocessing model. Yes, the *explanation* of the bug is simple enough - each process "sees" a different value, since memory isn't shared - but the bug in my code was neither obvious or easy to spot, at least until you knew what was happening. > People seem to find it harder to reason about atomicity and realising that widely separated pieces of code may interact unexpectedly. > > Yield points bring with >> them the risk of locking another thread out unexpectedly (particularly >> since certain system calls aren't async-friendly on certain OSes). > > I've got to admit I find coroutines straightforward, but I did cut my teeth on a cooperative OS. It certainly makes the atomicity issues easier to deal with. I still can't claim to understand them. Threads? No problem. Obviously I'm still lacking some understanding of how data works in the multiprocessing model, however. > > All >> three models have their pitfalls. > > Assuredly. I just think threads are soggier and hard to light^W^W^W^W^W prone to subtler and more mysterious-looking bugs. And yet, this thread exists because of a subtle and mysterious-looking bug with multiple *processes* that doesn't exist with multiple *threads*. Thus the point - threads are no *worse* - just different - than any other concurrency model. > > -- > Rhodri James *-* Kynesim Ltd > -- > https://mail.python.org/mailman/listinfo/python-list From torriem at gmail.com Fri Nov 3 15:15:58 2017 From: torriem at gmail.com (Michael Torrie) Date: Fri, 3 Nov 2017 13:15:58 -0600 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> Message-ID: <20dbbfc4-1779-2a54-931e-5b4406bd757c@gmail.com> On 11/03/2017 11:44 AM, Jon Ribbens wrote: > And that's leading you into confusion, as you've demonstrated. And indeed I've been led into considerable confusion about the else: clause over the years. Every time I need to use it, I run a python shell and try it out to remind myself how it works. However now with your mental model, Jon, I think I finally have it! Thank you. I can't think of any normal circumstance where for/else is useful without a break. In fact if you have no break you may as well drop the else entirely, because the block will always execute. A linter should definitely flag this. One reason to leave it as valid syntax is maybe I am coding up some skeleton code that I plan to fill in later. So for now the loop falls through, but at some future point I'll have finished the searching code and added the break. But if it were a syntax error I don't think that'd be any big deal. Anyway, thank you again, Jon. Your explanation and model has greatly cleared up my confusion, and I think if the docs reasoned along the same lines it would clear up confusion in most programmers. Certainly it appears your line of reasoning is what Guido had in mind when he added the else block. Sorry Steven, I think Jon's right in this instance and your reasoning isn't persuasive. From rhodri at kynesim.co.uk Fri Nov 3 15:28:46 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 3 Nov 2017 19:28:46 +0000 Subject: Thread safety issue (I think) with defaultdict In-Reply-To: References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: On 03/11/17 18:12, Israel Brewster wrote: > On Nov 3, 2017, at 7:11 AM, Rhodri James wrote: >> People generally understand how to move data around, and the mistakes are usually pretty obvious when they happen. > > I think the existence of this thread indicates otherwise :-) This mistake was far from obvious, and clearly I didn't understand properly how to move data around *between processes*. Unless you are just saying I am ignorant or something? :-) Ah, but from the point of view of this argument, you didn't make a mistake, you made a meta-mistake. It wasn't that you didn't understand how to move data around between processes, it was that you didn't think you were moving between processes! Whether or not you do understand remains to be seen :-) -- Rhodri James *-* Kynesim Ltd From tjreedy at udel.edu Fri Nov 3 15:53:20 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 3 Nov 2017 15:53:20 -0400 Subject: python3 byte decode In-Reply-To: References: Message-ID: On 11/3/2017 5:24 AM, Ali R?za KELE? wrote: > Hi, > > Yesterday, while working with redis, i encountered a strange case. > > I want to ask why is the following `True` > > ``` > "s" is b"s".decode() > ``` > > while the followings are `False`? > > ``` > "so" is b"so".decode() > "som" is b"som".decode() > "some" is b"some".decode() > ``` > > Or vice versa? > > I read that `is` compares same objects, not values. So my question is > why "s" and b"s".decode() are same objects, while the others aren't? For the same reason as >>> a = 1 >>> b = 1 >>> a is b True >>> a = 1000 >>> b = 1000 >>> a is b False For CPython, 'small' ints are cached on startup. Ditto for 'small' strings, which I think includes all 128 ascii chars, and maybe latin1 chars. Details depends on the implemention and version. The main use of 'is' for immutable builtins is for developers to test the implementation in the test suite. -- Terry Jan Reedy From ian.g.kelly at gmail.com Fri Nov 3 17:57:05 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 3 Nov 2017 15:57:05 -0600 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> Message-ID: On Fri, Nov 3, 2017 at 3:25 PM, Stefan Ram wrote: > Jon Ribbens writes: >>No, it's an obvious bug. You have a 'for...else' with no 'break'. >>Like I said, that should probably be a syntax error. > > It should make the syntax of Python much more complicated, > when one would try to encode this rule in the /syntax/. > > (Just try to write down the EBNF.) > > It would be more reasonable to call it a constraint. > Maybe it could still be a parser error (not a runtime > error). Regardless of whether it's encoded in the EBNF or a constraint on the resulting parse tree, the eventual outcome would still be called a syntax error. From steve+python at pearwood.info Fri Nov 3 21:04:22 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 04 Nov 2017 12:04:22 +1100 Subject: Thread safety issue (I think) with defaultdict References: <2236CA4C-C444-44E2-8B8A-4642B2ED3D25@ravnalaska.net> <5F1B7EEE-1344-4852-9C0B-26FA2A0C7612@ravnalaska.net> <59fa6ca7$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: <59fd1217$0$18598$b1db1813$d948b532@news.astraweb.com> On Sat, 4 Nov 2017 05:12 am, Israel Brewster wrote: [...] >> People generally understand how to move data around, and the mistakes are >> usually pretty obvious when they happen. > > I think the existence of this thread indicates otherwise :-) This mistake > was far from obvious, and clearly I didn't understand properly how to move > data around *between processes*. Unless you are just saying I am ignorant or > something? :-) Yes, you were ignorant -- you didn't even realise that you were using processes, you thought you were using threaded code when it was actually multiprocessing code. No wonder you got it wrong. Of course you have a good excuse: the multiprocessing is hidden deep inside not just the library you were using, but the library *it* was using. (I don't know how obvious the documentation of the libraries make this -- maybe they're to blame, for not being clear enough -- or maybe you were simply ignorant about the tools you were using.) You can't judge multiprocessing code on the basis of bugs caused by assuming that it was threading code, writing in a threading style with shared data. If you misuse your tools, that's not the tool's fault. If anything, we can say that the ultimate error was that you decided to write in a threaded style without actually using threads: the error was your (dangerous?) choice to write non-deterministic code using shared data. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Fri Nov 3 21:09:21 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 04 Nov 2017 12:09:21 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <20dbbfc4-1779-2a54-931e-5b4406bd757c@gmail.com> Message-ID: <59fd1341$0$18598$b1db1813$d948b532@news.astraweb.com> On Sat, 4 Nov 2017 06:15 am, Michael Torrie wrote: > In fact if you have no break you may as well drop the > else entirely, because the block will always execute. That's incorrect. There are multiple ways to exit a loop that will prevent the `else` block from executing, `break` is only one. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From torriem at gmail.com Fri Nov 3 22:57:11 2017 From: torriem at gmail.com (Michael Torrie) Date: Fri, 3 Nov 2017 20:57:11 -0600 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <59fd1341$0$18598$b1db1813$d948b532@news.astraweb.com> References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <20dbbfc4-1779-2a54-931e-5b4406bd757c@gmail.com> <59fd1341$0$18598$b1db1813$d948b532@news.astraweb.com> Message-ID: <0747b713-594a-1a83-ebed-639a728e5821@gmail.com> On 11/03/2017 07:09 PM, Steve D'Aprano wrote: > On Sat, 4 Nov 2017 06:15 am, Michael Torrie wrote: > >> In fact if you have no break you may as well drop the >> else entirely, because the block will always execute. > > That's incorrect. There are multiple ways to exit a loop that will prevent the > `else` block from executing, `break` is only one. Such as? From rosuav at gmail.com Fri Nov 3 23:06:31 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Nov 2017 14:06:31 +1100 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <0747b713-594a-1a83-ebed-639a728e5821@gmail.com> References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <20dbbfc4-1779-2a54-931e-5b4406bd757c@gmail.com> <59fd1341$0$18598$b1db1813$d948b532@news.astraweb.com> <0747b713-594a-1a83-ebed-639a728e5821@gmail.com> Message-ID: On Sat, Nov 4, 2017 at 1:57 PM, Michael Torrie wrote: > On 11/03/2017 07:09 PM, Steve D'Aprano wrote: >> On Sat, 4 Nov 2017 06:15 am, Michael Torrie wrote: >> >>> In fact if you have no break you may as well drop the >>> else entirely, because the block will always execute. >> >> That's incorrect. There are multiple ways to exit a loop that will prevent the >> `else` block from executing, `break` is only one. > > Such as? There are many. But other than break, I don't know of any that WOULD execute the next line of code immediately _after_ the loop. ChrisA From torriem at gmail.com Sat Nov 4 00:57:50 2017 From: torriem at gmail.com (Michael Torrie) Date: Fri, 3 Nov 2017 22:57:50 -0600 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <20dbbfc4-1779-2a54-931e-5b4406bd757c@gmail.com> <59fd1341$0$18598$b1db1813$d948b532@news.astraweb.com> <0747b713-594a-1a83-ebed-639a728e5821@gmail.com> Message-ID: <2abf5736-fd0a-9465-c55f-6f4bd8ceb5c7@gmail.com> On 11/03/2017 09:06 PM, Chris Angelico wrote: > On Sat, Nov 4, 2017 at 1:57 PM, Michael Torrie wrote: >> On 11/03/2017 07:09 PM, Steve D'Aprano wrote: >>> On Sat, 4 Nov 2017 06:15 am, Michael Torrie wrote: >>> >>>> In fact if you have no break you may as well drop the >>>> else entirely, because the block will always execute. >>> >>> That's incorrect. There are multiple ways to exit a loop that will prevent the >>> `else` block from executing, `break` is only one. >> >> Such as? > > There are many. But other than break, I don't know of any that WOULD > execute the next line of code immediately _after_ the loop. Can you be more specific? What are some of these "many" ways of aborting a loop? Help a guy out here. I know, for example, that we have exceptions. But those hardly matter in this discussion because they wouldn't execute the else clause either. They'd either be caught elsewhere, or end the program. sys.exit() can also terminate a for loop, but it terminates the whole program without running the else statement. From ben+python at benfinney.id.au Sat Nov 4 01:55:48 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 04 Nov 2017 16:55:48 +1100 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> Message-ID: <85375u1taz.fsf_-_@benfinney.id.au> Ian Kelly writes: > Steve was clearly referring to the coder, not the code. Not at all. Steve was referring specifically to the *idea*: [A ?for ? else? structure without a ?break?] should absolutely not be a syntax error. There's no reason for it to be a syntax error, except to satisfy some arrogant and foolish idea of purity. This is clearly a criticism of the idea behind the expectation of a syntax error. It doesn't refer to the coder, it refers explicitly to the idea being criticised. To respond to the criticism of an idea ? criticism containing no mention of the person ? as though it ?clearly refers to the [person]?, is of significant concern on a software dicussion forum such as this. > Please stop defending the use of incivility on this list. Please stop conflating people, who deserve civility, with ideas. We must not allow the civility deserved by people, to prevent us from criticising any ideas ? especially not ideas about the behaviour of software. -- \ ?I used to be a proofreader for a skywriting company.? ?Steven | `\ Wright | _o__) | Ben Finney From jon+usenet at unequivocal.eu Sat Nov 4 08:22:28 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sat, 4 Nov 2017 12:22:28 -0000 (UTC) Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <20dbbfc4-1779-2a54-931e-5b4406bd757c@gmail.com> <59fd1341$0$18598$b1db1813$d948b532@news.astraweb.com> <0747b713-594a-1a83-ebed-639a728e5821@gmail.com> <2abf5736-fd0a-9465-c55f-6f4bd8ceb5c7@gmail.com> Message-ID: On 2017-11-04, Michael Torrie wrote: > On 11/03/2017 09:06 PM, Chris Angelico wrote: >> On Sat, Nov 4, 2017 at 1:57 PM, Michael Torrie wrote: >>> On 11/03/2017 07:09 PM, Steve D'Aprano wrote: >>>> That's incorrect. There are multiple ways to exit a loop that >>>> will prevent the `else` block from executing, `break` is only one. >>> >>> Such as? >> >> There are many. But other than break, I don't know of any that WOULD >> execute the next line of code immediately _after_ the loop. > > Can you be more specific? What are some of these "many" ways of aborting > a loop? Help a guy out here. > > I know, for example, that we have exceptions. But those hardly matter in > this discussion because they wouldn't execute the else clause either. > They'd either be caught elsewhere, or end the program. sys.exit() can > also terminate a for loop, but it terminates the whole program without > running the else statement. Yes, those are the sort of thing that Steve was referring to. He was being unhelpfully pedantic. A giant meteor destroying the computer the program was running on would prevent the 'else' block from executing too. From jon+usenet at unequivocal.eu Sat Nov 4 08:25:18 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sat, 4 Nov 2017 12:25:18 -0000 (UTC) Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On 2017-11-04, Ben Finney wrote: > To respond to the criticism of an idea ? criticism containing no mention > of the person ? as though it ?clearly refers to the [person]?, is of > significant concern on a software dicussion forum such as this. No, the thing that is "of significant conern on a software discussion forum such as this" is people such as yourself defending the abuse of other contributors. From rosuav at gmail.com Sat Nov 4 08:39:15 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Nov 2017 23:39:15 +1100 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <20dbbfc4-1779-2a54-931e-5b4406bd757c@gmail.com> <59fd1341$0$18598$b1db1813$d948b532@news.astraweb.com> <0747b713-594a-1a83-ebed-639a728e5821@gmail.com> <2abf5736-fd0a-9465-c55f-6f4bd8ceb5c7@gmail.com> Message-ID: On Sat, Nov 4, 2017 at 11:22 PM, Jon Ribbens wrote: > On 2017-11-04, Michael Torrie wrote: >> On 11/03/2017 09:06 PM, Chris Angelico wrote: >>> On Sat, Nov 4, 2017 at 1:57 PM, Michael Torrie wrote: >>>> On 11/03/2017 07:09 PM, Steve D'Aprano wrote: >>>>> That's incorrect. There are multiple ways to exit a loop that >>>>> will prevent the `else` block from executing, `break` is only one. >>>> >>>> Such as? >>> >>> There are many. But other than break, I don't know of any that WOULD >>> execute the next line of code immediately _after_ the loop. >> >> Can you be more specific? What are some of these "many" ways of aborting >> a loop? Help a guy out here. >> >> I know, for example, that we have exceptions. But those hardly matter in >> this discussion because they wouldn't execute the else clause either. >> They'd either be caught elsewhere, or end the program. sys.exit() can >> also terminate a for loop, but it terminates the whole program without >> running the else statement. > > Yes, those are the sort of thing that Steve was referring to. > He was being unhelpfully pedantic. A giant meteor destroying > the computer the program was running on would prevent the 'else' > block from executing too. My definition of "preventing else from executing" is that it would (a) not execute code inside the else block, and (b) execute unindented code immediately *after* that else block. Consider a try/finally block: try: print("Setup") ... finally: print("Cleanup") print("Carrying on") Before we reach "carrying on", we are guaranteed to pass through "cleanup". Steve's pedantry is 100% accurate for situations where the setup and cleanup involve the network; you can't actually guarantee that the cleanup will be performed (a hard exit will abort the whole process, a 'kill -9' will shut you down, powering down the computer means nothing happens), so you have to assume that the cleanup might not happen (eg with PostgreSQL, the database server will roll back your transaction and clean up the trash). But AFAIK there is no way to reach "carrying on" without first executing "cleanup". With the for-else clause, we have the same valid pedantry, but with a few differences. A 'return' inside the loop will skip the 'else' clause (but wouldn't skip a 'finally'), as will any exception. But neither of those would hit "carrying on" either. AFAIK the only way to skip the else *and hit the "carrying on" call* is to use 'break'. That's a non-pedantic interpretation of "skip the else clause". ChrisA From rosuav at gmail.com Sat Nov 4 08:40:50 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Nov 2017 23:40:50 +1100 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On Sat, Nov 4, 2017 at 11:25 PM, Jon Ribbens wrote: > On 2017-11-04, Ben Finney wrote: >> To respond to the criticism of an idea ? criticism containing no mention >> of the person ? as though it ?clearly refers to the [person]?, is of >> significant concern on a software dicussion forum such as this. > > No, the thing that is "of significant conern on a software discussion > forum such as this" is people such as yourself defending the abuse of > other contributors. Maybe we're not defending the abuse of other contributors. Maybe we're defending a legitimate, if somewhat caustic, response to a ridiculous suggestion. ChrisA From formisc at gmail.com Sat Nov 4 11:10:18 2017 From: formisc at gmail.com (Andrew Z) Date: Sat, 4 Nov 2017 11:10:18 -0400 Subject: matplot plot hangs In-Reply-To: References: Message-ID: Tim, it won't even advance to that line. On Thu, Nov 2, 2017 at 8:28 AM, Tim Williams wrote: > On Wednesday, November 1, 2017 at 6:30:27 PM UTC-4, Andrew Z wrote: > > nope. it doesnt: > > > > I added print-s after each line and that produced: > > [az at hp src]$ cat ./main1.py > > import matplotlib.pyplot as plt > > print("imported") > > plt.plot([1,2,4,1]) > > print("plot is done") > > plt.show() > > print("show is done") > > > > [az at hp src]$ python3.5 ./main1.py > > imported > > ^C^Z > > [1]+ Stopped python3.5 ./main1.py > > > > > > On Wed, Nov 1, 2017 at 9:31 AM, Vlastimil Brom > > > wrote: > > > > > 2017-11-01 13:49 GMT+01:00 Andrew Z : > > > > Wolfgang, > > > > I tried to ran from ide with no rwsults, so now im trying from a > > > terminal > > > > in xwindow. > > > > The .plot is the last line in the script and it does hang trying to > > > execute > > > > it. > > > > > > > > > > > > On Nov 1, 2017 05:44, "Wolfgang Maier" < > > > > wolfgang.maier at biologie.uni-freiburg.de> wrote: > > > > > > > > On 01.11.2017 00:40, Andrew Z wrote: > > > > > > > >> hello, > > > >> learning python's plotting by using matplotlib with python35 on > > > fedora 24 > > > >> x86. > > > >> > > > >> Installed matplotlib into user's directory. > > > >> tk, seemed to work - > > > >> http://www.tkdocs.com/tutorial/install.html#installlinux - the > window > > > >> shows > > > >> up just fine. > > > >> but when trying to run the simple plot ( > > > >> https://matplotlib.org/examples/pylab_examples/simple_plot.html) > the > > > >> script > > > >> is hanging on; > > > >> > > > >> plt.plot(t, s) > > > >> > > > >> attempts to > > > >> matplotlib.interactive(True) didn't bring anything, > > > >> > > > >> > > > > Hi Andrew, > > > > > > > > From which environment are you trying to run the example? In the > > > terminal, > > > > from within some IDE, inside a jupyter notebook? > > > > > > > > Are you sure the script "is hanging on plt.plot(t, s)" and not after > > > that? > > > > > > > > Best, > > > > Wolfgang > > > > > > > > -- > > > Hi, > > > sorry if it is too trivial, just to make sure, do you have a call to > > > "show()" the resulting plot in the code? > > > > > > An elementary plotting code might be e.g.: > > > > > > import matplotlib.pyplot as plt > > > plt.plot([1,2,4,1]) > > > plt.show() > > > > > > Does this work in your environment? > > > > > > It was not quite clear, what do you plan with interactive drawing, or > > > whether you are using e.g. plt.interactive(True) already - this might > > > be a problem as there could be collisions or the plot window is closed > > > after the standalone script finishes. > > > > > > hth, > > > vbr > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > > Have you tried > > plt.show(block=False) > ? > -- > https://mail.python.org/mailman/listinfo/python-list > From nodnarb at gmx.us Sat Nov 4 11:31:25 2017 From: nodnarb at gmx.us (brandon wallace) Date: Sat, 4 Nov 2017 16:31:25 +0100 Subject: Try: Except: evaluates to True every time Message-ID: I have this code that tests a server to see if it is listening on port 123 runs and evaluates to True every time. Even if the server does not exist but it is not supposed to do that. I am getting no error message at all. What is going on with this code? ? ? #!/usr/bin/env python import socket hostname = ["192.168.1.22", "192.168.1.23", "200.168.1.24", "19.0.0.0"] port = 123 def check_udp(hosts, port_num): ??? '''Test the UDP port on a remove server.''' ??? s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) ??? for host in hosts: ??????? try: ??????????? s.connect((host, port_num)) ??????????? return "Port 53 is reachable on: %s" % host ??????? except socket.error as e: ??????????? return "Error on connect: %s" % e check_udp(hostname, port) From steve+python at pearwood.info Sat Nov 4 12:00:46 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 05 Nov 2017 03:00:46 +1100 Subject: Try: Except: evaluates to True every time References: Message-ID: <59fde430$0$18584$b1db1813$d948b532@news.astraweb.com> On Sun, 5 Nov 2017 02:31 am, brandon wallace wrote: > > I have this code that tests a server to see if it is listening on port 123 > runs and evaluates to True every time. Even if the server does not exist but > it is not supposed to do that. I am getting no error message at all. What is > going on with this code? You're returning a string in both cases. Both strings evaluate as true when treated as bools. Success: > return "Port 53 is reachable on: %s" % host Failure: > except socket.error as e: > return "Error on connect: %s" % e > > check_udp(hostname, port) That's the first bug. The second bug is that I don't think the code does what you think it does. You seem to be calling it with a single hostname, presumably a string. But then you split the hostname into individual letters, and try to connect to each of them. The *first* attempt either succeeds or fails, and then returns. So if you call check_udp("mailserver", 143), your function calls for host in "mailserver": try: s.connect((host, port_num)) which attempts to connect to ("m", 143). That will either succeed (probably not), or fail (probably this), and then the function returns a string, which you apparently never look at. I suggest you re-write your check_udp function to something more like this: def check_udp(host, port_num): '''Test the UDP port on a remove server.''' s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: s.connect((host, port_num)) return True except socket.error as e: return False But even this is suspicious, since it is vulnerable to a "Time Of Check To Time Of Use" bug. Just because you can connect to the host *now*, when you call check_udp, doesn't mean it will still respond two seconds later (or even two milliseconds later) when you attempt to connect again. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From Karsten.Hilbert at gmx.net Sat Nov 4 12:07:26 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sat, 4 Nov 2017 17:07:26 +0100 Subject: Aw: Try: Except: evaluates to True every time In-Reply-To: References: Message-ID: Try in an interactive interpreter: python> "a string" is True Karsten > Gesendet: Samstag, 04. November 2017 um 16:31 Uhr > Von: "brandon wallace" > An: python-list at python.org > Betreff: Try: Except: evaluates to True every time > > > I have this code that tests a server to see if it is listening on port 123 runs and evaluates to True every time. Even if the server does not exist but it is not supposed to do that. I am getting no error message at all. What is going on with this code? > ? > ? > > #!/usr/bin/env python > > import socket > > hostname = ["192.168.1.22", "192.168.1.23", "200.168.1.24", "19.0.0.0"] > port = 123 > > def check_udp(hosts, port_num): > ??? '''Test the UDP port on a remove server.''' > ??? s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > ??? for host in hosts: > ??????? try: > ??????????? s.connect((host, port_num)) > ??????????? return "Port 53 is reachable on: %s" % host > ??????? except socket.error as e: > ??????????? return "Error on connect: %s" % e > > check_udp(hostname, port) > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sat Nov 4 13:10:58 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 5 Nov 2017 04:10:58 +1100 Subject: Try: Except: evaluates to True every time In-Reply-To: References: Message-ID: On Sun, Nov 5, 2017 at 2:31 AM, brandon wallace wrote: > > I have this code that tests a server to see if it is listening on port 123 runs and evaluates to True every time. Even if the server does not exist but it is not supposed to do that. I am getting no error message at all. What is going on with this code? > > > > #!/usr/bin/env python > > import socket > > hostname = ["192.168.1.22", "192.168.1.23", "200.168.1.24", "19.0.0.0"] > port = 123 > > def check_udp(hosts, port_num): > '''Test the UDP port on a remove server.''' > s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > for host in hosts: > try: > s.connect((host, port_num)) > return "Port 53 is reachable on: %s" % host > except socket.error as e: > return "Error on connect: %s" % e > > check_udp(hostname, port) Do you understand what it actually means to connect a UDP socket? If not, I suggest reading up on the nature of UDP. You can't probe a remote server this way; it simply doesn't work like that. ChrisA From steve+python at pearwood.info Sat Nov 4 13:32:13 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 05 Nov 2017 04:32:13 +1100 Subject: Read Firefox sqlite files with Python Message-ID: <59fdf99f$0$14949$b1db1813$d948b532@news.astraweb.com> I'm trying to dump a Firefox IndexDB sqlite file to text using Python 3.5. import sqlite3 con = sqlite3.connect('foo.sqlite') with open('dump.sql', 'w') as f: for line in con.iterdump(): f.write(line + '\n') The error I get is: Traceback (most recent call last): File "", line 2, in File "/usr/local/lib/python3.5/sqlite3/dump.py", line 30, in _iterdump schema_res = cu.execute(q) sqlite3.DatabaseError: file is encrypted or is not a database If I open the file in a hex editor, it starts with: SQLite format 3 and although I can see a few human readable words, the bulk of the file looks like noise. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From __peter__ at web.de Sat Nov 4 14:48:54 2017 From: __peter__ at web.de (Peter Otten) Date: Sat, 04 Nov 2017 19:48:54 +0100 Subject: Read Firefox sqlite files with Python References: <59fdf99f$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > I'm trying to dump a Firefox IndexDB sqlite file to text using Python 3.5. > > > import sqlite3 > con = sqlite3.connect('foo.sqlite') > with open('dump.sql', 'w') as f: > for line in con.iterdump(): > f.write(line + '\n') > > > The error I get is: > > Traceback (most recent call last): > File "", line 2, in > File "/usr/local/lib/python3.5/sqlite3/dump.py", line 30, in _iterdump > schema_res = cu.execute(q) > sqlite3.DatabaseError: file is encrypted or is not a database > > > If I open the file in a hex editor, it starts with: > > SQLite format 3 > > and although I can see a few human readable words, the bulk of the file > looks like noise. I've seen that error message before: https://mail.python.org/pipermail/tutor/2013-July/097022.html From Karsten.Hilbert at gmx.net Sat Nov 4 14:59:12 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sat, 4 Nov 2017 19:59:12 +0100 Subject: Try: Except: evaluates to True every time In-Reply-To: References: Message-ID: <20171104185912.6bomo7vvc6bugqbp@hermes.hilbert.loc> On Sat, Nov 04, 2017 at 05:07:26PM +0100, Karsten Hilbert wrote: > Try in an interactive interpreter: > > python> "a string" is True Or, rather, python> if 'a string': print 'success' Sorry, Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 From Karsten.Hilbert at gmx.net Sat Nov 4 15:12:59 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sat, 4 Nov 2017 20:12:59 +0100 Subject: right list for SIGABRT python binary question ? In-Reply-To: <87mv43hnz7.fsf@handshake.de> References: <20171019172745.76i3lltjtck2m5gw@hermes.hilbert.loc> <20171019174907.iqgznoroyieipend@hermes.hilbert.loc> <87y3o5gdn9.fsf@handshake.de> <20171023122312.uupsxzhdwat3stt7@hermes.hilbert.loc> <87lgjq5rz9.fsf@handshake.de> <20171101092753.tfcvckzaezunxnej@hermes.hilbert.loc> <20171102112616.ifbrfwrcvjibed66@hermes.hilbert.loc> <87mv43hnz7.fsf@handshake.de> Message-ID: <20171104191258.wzpmkfj7z5b4m7we@hermes.hilbert.loc> On Fri, Nov 03, 2017 at 07:31:56AM +0100, dieter wrote: > > I have posted backtraces taken from the address being > > watched. Does that help any at all ? > > Only in the case that the error is "local", i.e. detected > (quite) immediately. > > You might be in this case as you have observed that the address > is stable after library preload. Thus, it might not be a heap > address but one associated with one of the libraries. Such > a memory block should never be "freed". The backtrace would allow > you to determine the library affected. Obtain its source. Recompile > with symbols and try to find out where this memory block comes from. Dieter, thanks for taking the time to explain the general procedure. However, recompiling a library and trying to find out where given block of memory comes from is way beyond skills. I fear I have reached the end of what I can do. Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 From hjp-usenet3 at hjp.at Sat Nov 4 15:59:19 2017 From: hjp-usenet3 at hjp.at (Peter J. Holzer) Date: Sat, 4 Nov 2017 20:59:19 +0100 Subject: [TSBOAPOOOWTDI]using names from modules References: Message-ID: On 2017-11-04 19:42, Stefan Ram wrote: > What is better: > > ... > import math > ... > ... math.cos ... > ... > > or > > ... > from math import cos > ... > ... cos ... > ... > > ? > > (To me, the first is more readable, because at the site > where ?math.cos? is used, it is made clear that ?cos? > comes from math. If I'm doing trigonometric computations I think the *second* is *much* more readable. I'm using the well-known cosine function - that this was imported from the math module is pure noise. For other functions this may be less clear. I tend to use the first style more often, although that gets a bit verbose sometimes (os.path.join(os.path.dirname(...), ...)), And I do notice that the second style seems to be preferred in Django. > But I assume that the second might use > one less name lookup and therefore is faster. What is the > one way to do it?) I'm not worried about performance unless there is clear performance advantage (for real programs, not benchmarks). hp -- _ | Peter J. Holzer | Fluch der elektronischen Textverarbeitung: |_|_) | | Man feilt solange an seinen Text um, bis | | | hjp at hjp.at | die Satzbestandteile des Satzes nicht mehr __/ | http://www.hjp.at/ | zusammenpa?t. -- Ralph Babel From flebber.crue at gmail.com Sat Nov 4 17:01:48 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sat, 4 Nov 2017 14:01:48 -0700 (PDT) Subject: Looping on a list in json Message-ID: <8feddeca-97b4-492c-b6f2-48443bcb02e9@googlegroups.com> Hi I want to get a result from a largish json api. One section of the json structure returns lists of data. I am wanting to get each resulting list returned. This is my code. import json from pprint import pprint with open(r'/home/sayth/Projects/results/Canterbury_2017-01-20.json', 'rb') as f, open('socks3.json','w') as outfile: to_read = json.load(f) print(to_read.keys()) # pprint(to_read) meet = to_read["RaceDay"]["Meetings"] meeting_id = to_read["RaceDay"]["Meetings"][0] pprint(meeting_id.keys()) # result = meeting_id["Races"][1]["RacingFormGuide"]["Event"]["Runners"] result = meeting_id["Races"] #failing for item in result: pprint(["RacingFormGuide"]["Event"]["Runners"]) The key to the issue is that result = meeting_id["Races"][0]["RacingFormGuide"]["Event"]["Runners"] result = meeting_id["Races"][1]["RacingFormGuide"]["Event"]["Runners"] result = meeting_id["Races"][2]["RacingFormGuide"]["Event"]["Runners"] the numbers though in the above results could go from 0 to 10. What is the best way to and return the data? would just save meeting_id["Races"] to my result however there are a lot of other junk dictionaries and lists I am filtering. Cheers Sayth From cs at cskk.id.au Sat Nov 4 17:27:00 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 5 Nov 2017 08:27:00 +1100 Subject: Looping on a list in json In-Reply-To: <8feddeca-97b4-492c-b6f2-48443bcb02e9@googlegroups.com> References: <8feddeca-97b4-492c-b6f2-48443bcb02e9@googlegroups.com> Message-ID: <20171104212700.GA25596@cskk.homeip.net> On 04Nov2017 14:01, Sayth Renshaw wrote: >I want to get a result from a largish json api. One section of the json >structure returns lists of data. I am wanting to get each resulting list >returned. > >This is my code. >import json >from pprint import pprint > >with open(r'/home/sayth/Projects/results/Canterbury_2017-01-20.json', 'rb') as f, open('socks3.json','w') as outfile: > to_read = json.load(f) [...] > meeting_id = to_read["RaceDay"]["Meetings"][0] > result = meeting_id["Races"] > #failing > for item in result: > pprint(["RacingFormGuide"]["Event"]["Runners"]) I'd just keep the interesting runners, along with their race numbers, in a dict. The enumerate function is handy here. Something like (untested): runner_lists = {} for n, item in enumerate(result): if this one is interested/not-filtered: runner_lists[n] = result["RacingFormGuide"]["Event"]["Runners"] and just return runner_lists. That way you know what the race numbers were for each list of runners. >What is the best way to and return the data? The basic idea is to make a small data structure of your own (just the dictionary runner_lists in the example above) and fill it in with the infomation you care about in a convenient and useful shape. Then just return the data structure. The actual data structure will depend on what you need to do with this later. Cheers, Cameron Simpson (formerly cs at zip.com.au) From cs at cskk.id.au Sat Nov 4 17:34:47 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 5 Nov 2017 08:34:47 +1100 Subject: [TSBOAPOOOWTDI]using names from modules In-Reply-To: References: Message-ID: <20171104213447.GA36885@cskk.homeip.net> On 04Nov2017 20:59, Peter J. Holzer wrote: >On 2017-11-04 19:42, Stefan Ram wrote: >> What is better: >> ... >> import math >> ... >> ... math.cos ... >> >> or >> ... >> from math import cos >> ... >> ... cos ... >> ? >> >> (To me, the first is more readable, because at the site >> where ?math.cos? is used, it is made clear that ?cos? >> comes from math. > >If I'm doing trigonometric computations I think the *second* is *much* >more readable. I'm using the well-known cosine function - that this was >imported from the math module is pure noise. > >For other functions this may be less clear. I tend to use the first >style more often, although that gets a bit verbose sometimes >(os.path.join(os.path.dirname(...), ...)), [...] I think the same. If the function is well known and idstinctively named, just use the short form ("cos(value)"). I also use the first style, but not often. Regarding the less clear function names, particularly things like "os.path.join", my os.path imports often look like this these days: from os.path import dirname, exists as pathexists, isdir as pathisdir, join as joinpath This lets me use distinct but short names in the code. To take Peter's example: joinpath(dirname(...), ...) You can see I've given a distinctive name to "join", which would otherwise be pretty vague. Cheers, Cameron Simpson (formerly cs at zip.com.au)" From flebber.crue at gmail.com Sat Nov 4 20:11:19 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sat, 4 Nov 2017 17:11:19 -0700 (PDT) Subject: Looping on a list in json In-Reply-To: References: <8feddeca-97b4-492c-b6f2-48443bcb02e9@googlegroups.com> <20171104212700.GA25596@cskk.homeip.net> Message-ID: <7458c50e-ca0f-46f8-9754-27df13e343f0@googlegroups.com> On Sunday, 5 November 2017 09:53:37 UTC+11, Cameron Simpson wrote: > >I want to get a result from a largish json api. One section of the json > >structure returns lists of data. I am wanting to get each resulting list > >returned. > > > >This is my code. > >import json > >from pprint import pprint > > > >with open(r'/home/sayth/Projects/results/Canterbury_2017-01-20.json', 'rb') as f, open('socks3.json','w') as outfile: > > to_read = json.load(f) > [...] > > meeting_id = to_read["RaceDay"]["Meetings"][0] > > result = meeting_id["Races"] > > #failing > > for item in result: > > pprint(["RacingFormGuide"]["Event"]["Runners"]) > > I'd just keep the interesting runners, along with their race numbers, in a > dict. The enumerate function is handy here. Something like (untested): > > runner_lists = {} > for n, item in enumerate(result): > if this one is interested/not-filtered: > runner_lists[n] = result["RacingFormGuide"]["Event"]["Runners"] > > and just return runner_lists. That way you know what the race numbers were for > each list of runners. > > >What is the best way to and return the data? > > The basic idea is to make a small data structure of your own (just the > dictionary runner_lists in the example above) and fill it in with the > infomation you care about in a convenient and useful shape. Then just return > the data structure. > > The actual data structure will depend on what you need to do with this later. > > Cheers, Thank you. That does seem a good approach. I was intending to merge other dictionary data from other dicts within the json structure and that's where the trouble starts i guess trying to get too much from json. Thanks Sayth From flebber.crue at gmail.com Sat Nov 4 20:13:28 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sat, 4 Nov 2017 17:13:28 -0700 (PDT) Subject: Read Firefox sqlite files with Python In-Reply-To: <59fdf99f$0$14949$b1db1813$d948b532@news.astraweb.com> References: <59fdf99f$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: <5e8c4636-99ef-4408-9e1e-3a7f5cc8d2ff@googlegroups.com> On Sunday, 5 November 2017 04:32:26 UTC+11, Steve D'Aprano wrote: > I'm trying to dump a Firefox IndexDB sqlite file to text using Python 3.5. > > > import sqlite3 > con = sqlite3.connect('foo.sqlite') > with open('dump.sql', 'w') as f: > for line in con.iterdump(): > f.write(line + '\n') > > > The error I get is: > > Traceback (most recent call last): > File "", line 2, in > File "/usr/local/lib/python3.5/sqlite3/dump.py", line 30, in _iterdump > schema_res = cu.execute(q) > sqlite3.DatabaseError: file is encrypted or is not a database > > > If I open the file in a hex editor, it starts with: > > SQLite format 3 > > and although I can see a few human readable words, the bulk of the file looks > like noise. > > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. https://stackoverflow.com/a/18601429 Version mismatch between sqlite CLI and python sqlite API? I created again my db from the script instead of the CLI. Now insert and select work from the script, but not from the CLI. $sqlite -version returns 2.8.17, while the python version is 2.7.3. Sayth From ben+python at benfinney.id.au Sat Nov 4 20:21:52 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 05 Nov 2017 11:21:52 +1100 Subject: Ideas about how software should behave References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: <85y3nlzian.fsf@benfinney.id.au> Jon Ribbens writes: > On 2017-11-04, Ben Finney wrote: > > To respond to the criticism of an idea ? criticism containing no > > mention of the person ? as though it ?clearly refers to the > > [person]?, is of significant concern on a software dicussion forum > > such as this. > > No, the thing that is "of significant conern on a software discussion > forum such as this" is people such as yourself defending the abuse of > other contributors. I have defended no such thing, because there was no such abuse of any person in what you quoted. Ideas are not people, and ideas do not automatically deserve respect merely because some people hold those ideas. -- \ ?Compulsory unification of opinion achieves only the unanimity | `\ of the graveyard.? ?Justice Roberts in 319 U.S. 624 (1943) | _o__) | Ben Finney From steve+python at pearwood.info Sat Nov 4 20:28:44 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 05 Nov 2017 11:28:44 +1100 Subject: Aw: Try: Except: evaluates to True every time References: Message-ID: <59fe5b3e$0$18582$b1db1813$d948b532@news.astraweb.com> On Sun, 5 Nov 2017 03:07 am, Karsten Hilbert wrote: > Try in an interactive interpreter: > > python> "a string" is True Did you try that yourself? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From flebber.crue at gmail.com Sat Nov 4 20:40:29 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sat, 4 Nov 2017 17:40:29 -0700 (PDT) Subject: Looping on a list in json In-Reply-To: References: <8feddeca-97b4-492c-b6f2-48443bcb02e9@googlegroups.com> <20171104212700.GA25596@cskk.homeip.net> Message-ID: <4e087c25-eb29-4c66-b595-be243a3bbef2@googlegroups.com> > I'd just keep the interesting runners, along with their race numbers, in a > dict. The enumerate function is handy here. Something like (untested): > > runner_lists = {} > for n, item in enumerate(result): > if this one is interested/not-filtered: > runner_lists[n] = result["RacingFormGuide"]["Event"]["Runners"] > > and just return runner_lists. That way you know what the race numbers were for > each list of runners. > > > Cheers, > Cameron Simpson The main issue is that enumerate doesn't enumerate on the lists when trying to filter. result = meeting_id["Races"] so yes enumerating this works, showing just printing n and item. runner_lists = {} for n, item in enumerate(result): # if this one is interested / not -filtered: print(n, item) 0 {'FeatureRaceBonusActive': 'Disabled', 'FixedPriceSummary': {'FixedPrices': [{'SportId': 8, 'LeagueId': 102, 'MeetingId': 1218, 'MainEventId': 650350, 'SubEventId': 3601361, 'Status': 'F', 'StatusDescription': 'FINALISED', 'BetTypeName': 'Win', 'EnablePlaceBetting': True}]}, 'RacingFormGuide': {'Copyright': ..... and so on it goes through the 7 items in this file. but including runner_lists = {} for n, item in enumerate(result): # if this one is interested / not -filtered: print(n, item) runner_lists[n] = result["RacingFormGuide"]["Event"]["Runners"] ## Produces Traceback (most recent call last): dict_keys(['RaceDay', 'ErrorInfo', 'Success']) File "/home/sayth/PycharmProjects/ubet_api_mongo/parse_json.py", line 31, in runner_lists[n] = result["RacingFormGuide"]["Event"]["Runners"] TypeError: list indices must be integers or slices, not str Cheers Sayth From flebber.crue at gmail.com Sat Nov 4 20:43:04 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sat, 4 Nov 2017 17:43:04 -0700 (PDT) Subject: Looping on a list in json In-Reply-To: <4e087c25-eb29-4c66-b595-be243a3bbef2@googlegroups.com> References: <8feddeca-97b4-492c-b6f2-48443bcb02e9@googlegroups.com> <20171104212700.GA25596@cskk.homeip.net> <4e087c25-eb29-4c66-b595-be243a3bbef2@googlegroups.com> Message-ID: Sorry figured it. Needed to use n to iterate when creating. runner_lists = {} for n, item in enumerate(result): # if this one is interested / not -filtered: print(n, item) runner_lists[n] = result[n]["RacingFormGuide"]["Event"]["Runners"] Sayth From cs at cskk.id.au Sat Nov 4 20:56:07 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 5 Nov 2017 11:56:07 +1100 Subject: Looping on a list in json In-Reply-To: References: Message-ID: <20171105005607.GA17459@cskk.homeip.net> On 04Nov2017 17:43, Sayth Renshaw wrote: >figured it. Needed to use n to iterate when creating. Yeah, my mistake. >runner_lists = {} > for n, item in enumerate(result): > # if this one is interested / not -filtered: > print(n, item) > runner_lists[n] = result[n]["RacingFormGuide"]["Event"]["Runners"] That's the beauty of offering untested code: I don't have to find and fix my errors:-) Cheers, Cameron Simpson (formerly cs at zip.com.au) From tjreedy at udel.edu Sat Nov 4 20:57:03 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 4 Nov 2017 20:57:03 -0400 Subject: [TSBOAPOOOWTDI]using names from modules In-Reply-To: References: Message-ID: On 11/4/2017 3:42 PM, Stefan Ram wrote: > What is better: > > ... > import math > ... > ... math.cos ... > ... > > or > > ... > from math import cos > ... > ... cos ... > ... > > ? > > (To me, the first is more readable, because at the site > where ?math.cos? is used, it is made clear that ?cos? > comes from math. But I assume that the second might use > one less name lookup and therefore is faster. What is the > one way to do it?) There is no 'one way', which is why there is more than one way. The first lets the reader know the source at each use site. The second lets the reader know what use is made of the source at the top. The advantage depends on how familiar the *reader* is with the source module and the functions therein. Is your question generic to any module and object, or specific to the math module? If generic, and mode is part of the package you are writing, then 'import mod' is less likely to create a circular import error. On the other hand, 'from mod import obj' is better for testing because it lets one mock obj in the importing module without touching the imported module (where the original may be internally needed in the same test). With idlelib, there are both circular import and testing issues. If importing a module is expensive in some way, then knowing that B only needs one or two 'cheap' items from A is needed may suggest a workaround or refactoring. For instance, move items from A to B and reverse the import between them. Replacing an existing 'from tkinter import *' with 'import tkinter' or 'import tkinter as tk' requires prefixing every existing reference to a tkinter object. Replacing the same with 'from tkinter import Tk, ...' requires list each object. The latter localizes the patch. Plus see the preceding paragraphs. In either case, complete enough test coverage is needed to make the change. I initially started with the 'as tk' replacement, but switched to the list version. A tkinter-specific reason was planning to switch from tk to ttk versions of widgets. Moving, for instance, 'Button' from the tkinter list to the tkinter.ttk list, instead of changing prefixes, would be both easy and make it obvious, at the top, that the change had been made, and for all Buttons. -- Terry Jan Reedy From cs at cskk.id.au Sat Nov 4 21:06:24 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 5 Nov 2017 12:06:24 +1100 Subject: python3 byte decode In-Reply-To: References: Message-ID: <20171105010624.GA22883@cskk.homeip.net> On 04Nov2017 01:47, Chris Angelico wrote: >On Fri, Nov 3, 2017 at 8:24 PM, Ali R?za KELE? wrote: >> Yesterday, while working with redis, i encountered a strange case. >> >> I want to ask why is the following `True` >> >> ``` >> "s" is b"s".decode() >> ``` >> >> while the followings are `False`? >> >> ``` >> "so" is b"so".decode() >> "som" is b"som".decode() >> "some" is b"some".decode() >> ``` >> >> Or vice versa? >> >> I read that `is` compares same objects, not values. So my question is >> why "s" and b"s".decode() are same objects, while the others aren't? >> >> My python version is 3.6.3. > >You shouldn't be comparing string objects with 'is'. Sometimes two >equal strings will be identical, and sometimes they won't. All you're >seeing is that the interpreter happened to notice and/or cache this >particular lookup. To be more clear here, usually when humans say "identical" they mean having exactly the same value or attributes. Here, Chris means that the two strings are actually the same object rather than two equivalent objects. "is" tests the former (the same object). "==" is for testing the latter (the objects have the same value). For speed and memory reasons, Python notices small values of strings and ints, and allocates them only once. So When your write: a = "s" b = "s" Python will reuse the same str object for both. Because of this, not only is "a == b" (i.e. they have the same value) but also "a is b" (a and b refer to the same object). But this is not guarrenteed, and certainly for larger values Python doesn't bother. Eg: a = "ghghghghghg" b = "ghghghghghg" Here they will have the same value but be different objects. So "==" will still return True, but "is" would return False. You should usually be using "==" to compare things. "is" has its place, but it is usually not what you're after. In your example code, b"s".decode() returns the string value "s", and Python is internally deciding to reuse the existing "s" from the left half of your comparison. It can do this because strings are immutable. (For example, "+=" on a string makes a new string). Hoping this is now more clear, Cameron Simpson (formerly cs at zip.com.au) From steve+python at pearwood.info Sat Nov 4 21:19:48 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 05 Nov 2017 12:19:48 +1100 Subject: [TSBOAPOOOWTDI]using names from modules References: Message-ID: <59fe6734$0$18585$b1db1813$d948b532@news.astraweb.com> On Sun, 5 Nov 2017 06:42 am, Stefan Ram wrote: > What is the one way to do it? There is no philosophy of "one way to do it" in Python, that is a misunderstanding (possibly deliberate...) spread about by Perl users, to contrast Python from Perl's "more than one way to do it". The Zen of Python says: There should be one-- and preferably only one --obvious way to do it. The emphasis is on "obvious", not "one". There should be *at least* one, but preferably only one, OBVIOUS way to solve any problem. As for the question of importing names, the obvious way is to use a regular import: import math y = math.cos(x) which has the advantage of making it obvious where the name comes from, but the disadvantage that it is more to type and involves an extra name lookup at runtime, which is not free. But: - when performance matters - or the name is very well known - or you're only using a single name from the module (or at most a few) - especially if it repeats the module name (e.g. fractions.Fraction) it is acceptable to use the "from module import name" version: from math import cos y = cos(x) Which you use depends on the situation and personal taste. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Nov 4 21:22:12 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 05 Nov 2017 12:22:12 +1100 Subject: Read Firefox sqlite files with Python References: <59fdf99f$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: <59fe67c4$0$18585$b1db1813$d948b532@news.astraweb.com> On Sun, 5 Nov 2017 04:32 am, Steve D'Aprano wrote: > I'm trying to dump a Firefox IndexDB sqlite file to text using Python 3.5. > > > import sqlite3 > con = sqlite3.connect('foo.sqlite') > with open('dump.sql', 'w') as f: > for line in con.iterdump(): > f.write(line + '\n') Never mind. I dumped the file using the sqlite3 command line tool. Thank you to all those who answered. The file contains three INSERT statements, the first two don't have anything of interest, and the third (which presumably contains all the data I'm trying to recover) is an opaque 600+ KB blob. Naturally. Why would you use a database as a database, when instead you could just dump a big ball of mud into it? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ben+python at benfinney.id.au Sat Nov 4 21:49:34 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 05 Nov 2017 12:49:34 +1100 Subject: Zen of Python =?utf-8?Q?=E2=80=9Cobvious?= way to do =?utf-8?Q?it?= =?utf-8?Q?=E2=80=9D?= (was: [TSBOAPOOOWTDI]using names from modules) References: <59fe6734$0$18585$b1db1813$d948b532@news.astraweb.com> Message-ID: <85tvy9ze8h.fsf_-_@benfinney.id.au> Steve D'Aprano writes: > On Sun, 5 Nov 2017 06:42 am, Stefan Ram wrote: > > > What is the one way to do it? > > There is no philosophy of "one way to do it" in Python, that is a > misunderstanding (possibly deliberate...) spread about by Perl users, > to contrast Python from Perl's "more than one way to do it". > > The Zen of Python says: > > There should be one-- and preferably only one --obvious way to do it. > > > The emphasis is on "obvious", not "one". There should be *at least* > one, but preferably only one, OBVIOUS way to solve any problem. I think the confusion is quite understandable, and that the Zen was written quite consciously referencing the (at the time quite well-known) Perl princple ?There's more than one way to do it?. Of course, ?consciously referencing and contrasting with some well-known meme? is very close to ?deliberately inviting confusion from those who don't examine the contrast closely enough?. So, I have given up trying to assign *blame* for that confusion. But from what I can tell it's a canard to say that the confusion is ?spread about by Perl users?. On the contrary, in my experience, the confusion is also spread quite well by non-Perl-using, Python advocates. Heck, as someoone who works to *dispel* that confusion, I still find it difficult to place the emphasis correctly when rattling off that admonishment from the Zen. -- \ ?Perchance you who pronounce my sentence are in greater fear | `\ than I who receive it.? ?Giordano Bruno, burned at the stake by | _o__) the Catholic church for the heresy of heliocentrism, 1600-02-16 | Ben Finney From steve+python at pearwood.info Sat Nov 4 23:02:52 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 05 Nov 2017 14:02:52 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> Message-ID: <59fe7f5e$0$18601$b1db1813$d948b532@news.astraweb.com> On Sat, 4 Nov 2017 04:44 am, Jon Ribbens wrote: > On 2017-11-03, Steve D'Aprano wrote: >> The for loop does not necessarily perform a search: >> >> count = 1 >> for obj in sequence: >> if count > MAX_OBJECTS: >> print("too many objects, halting") >> break >> process(obj) >> else: >> print("finished") >> >> According to your mental model, this code is... what? Illegal? Silly? >> Impossible? A syntax error? > > That conforms to my model. It's searching for the condition > 'count > MAX_OBJECTS'. That's sounds to me that you are willing to call just about any test of a condition inside a loop a "search". I don't think that's helpful. I think it is mangling the word to the point it is meaningless. How about a loop that exits at some random time? Is that a search? for i in range(100, 0, -1): if flip_coin() == 'Heads': print("surprise!") break print("still running") else: print("countdown completed") [...] >> Your response to code that doesn't match your mental model is to say >> that it is obviously wrong and probably buggy and should be made >> into a syntax error if possible. > > No, it isn't. Try reading again what I actually wrote. What you actually wrote, in various posts: You have a 'for...else' with no 'break'. Like I said, that should probably be a syntax error. if what the 'for' clause is doing doesn't match the concept of 'searching for a match' then it's obvious that you shouldn't be using 'for...else' in the first place. the language doesn't currently strictly enforce the requirement for a 'break', but nevertheless if you don't have one you almost certainly have a bug. I stand by my comment as an accurate description of your response. >> Ah yes, because it is inconceivable that anyone might have thought of a use >> for for...else without a break. > > It's not inconceivable, but nobody has thought of a sensible use so far > (by which I mean one that shows it's a useful feature). I find the code useful. I shouldn't have to justify why it is useful to me, but for the record it especially comes in handy when I've already typed out a multi-line loop in the REPL, and only then realised that I'll need some way to add an extra line at the end. Since I spend a lot of time in the REPL doing exploratory coding, this happens more often than I'd like. Of course I could cancel the edit, then add in some sort of scaffolding code to allow me to print an extra line at the end, then hit the up arrow repeatedly to re-enter the lines I've already typed, editing them to fit the scaffolding, then add the final print. But that's tedious and painful and a waste of time and effort when it is trivially easy to just add "else: print()". That is *simple* and it *works* and it solves the problem. And yes, a better REPL would also solve that problem. But I have to use the REPL that exists, not the imaginary one that I'd like. If you want to call this a hackish work around for a limitation of the REPL, I'll say... okay. What's your point? It is still useful. Try thinking outside the box. There's nothing wrong with finding unusual and hackish uses for flow control statements. [...] >>> It's an incredibly obscure work-around for a different problem, >> >> You mean a different problem to "searching"? Yes indeed it is. > > No, I mean a problem that has nothing to do with 'for...else' clauses. I would say that it has nothing to do with the original motivation for introducing for...else clauses into the language. Since it uses for...else, it is pretty obtuse to deny that it has anything to do with for...else. The for...else control statement is a tool. We can use tools for any purpose we want, not just the ones that they were originally designed for. You are declaring that a perfectly useful, albeit hackish, trick for the REPL is illegitimate because it doesn't match your mental model. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From fatma.fars33 at gmail.com Sun Nov 5 01:21:09 2017 From: fatma.fars33 at gmail.com (fatma.fars33 at gmail.com) Date: Sat, 4 Nov 2017 22:21:09 -0700 (PDT) Subject: Specialization for learning python from university of Michigan school of information Message-ID: <428dc1b0-b5a0-4ad1-9545-d59215dcb650@googlegroups.com> https://youtu.be/eblAxa5iO24. The video is just an introduction for a course on https://studyscienceblog.wordpress.com/2017/10/28/university-of-mitchigan-s-courses From flebber.crue at gmail.com Sun Nov 5 01:36:04 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Sat, 4 Nov 2017 22:36:04 -0700 (PDT) Subject: Looping on a list in json In-Reply-To: References: <20171105005607.GA17459@cskk.homeip.net> Message-ID: <31a822df-d2f7-41bb-af52-b48eafe5123c@googlegroups.com> no doubt tho after playing with this is that enumerate value ends up in the output which is a dictionary. The enumerate has no key which makes it invalid json if dumped. Not massive issue but getting the effect of enumerate without polluting output would be the winner. >runner_lists = {} > for n, item in enumerate(result): > # if this one is interested / not -filtered: > print(n, item) > runner_lists[n] = result[n]["RacingFormGuide"]["Event"]["Runners"] Sayth From steve+python at pearwood.info Sun Nov 5 04:18:47 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 05 Nov 2017 20:18:47 +1100 Subject: Zen of Python =?UTF-8?B?4oCcb2J2aW91cyB3YXkgdG8gZG8gaXTigJ0gKHdhczogW1RTQk9BUE9PT1dURElddXNpbmcgbmFtZXMgZnJvbSBtb2R1bGVzKQ==?= References: <59fe6734$0$18585$b1db1813$d948b532@news.astraweb.com> <85tvy9ze8h.fsf_-_@benfinney.id.au> Message-ID: <59fed991$0$18607$b1db1813$d948b532@news.astraweb.com> On Sun, 5 Nov 2017 12:49 pm, Ben Finney wrote: > Steve D'Aprano writes: > >> On Sun, 5 Nov 2017 06:42 am, Stefan Ram wrote: >> >> > What is the one way to do it? >> >> There is no philosophy of "one way to do it" in Python, that is a >> misunderstanding (possibly deliberate...) spread about by Perl users, >> to contrast Python from Perl's "more than one way to do it". [...] > I think the confusion is quite understandable, and that the Zen was > written quite consciously referencing the (at the time quite well-known) > Perl princple ?There's more than one way to do it?. I daresay you are right about the second part, but I'm not so sure about the first. Python supports both while and for loops, and recursion, and it is well known than anything written recursively can be re-written using iteration (and vice versa), and anything using a for-loop can be re-written using while (but not vice versa). I don't think it is reasonable to give any credence to the idea that Python allows "only one way" to solve problems. Sure, it's easy to toss the phrase out without thinking, and I'm sure that in my early years as a Python user I probably did exactly that. I suppose that "people say things without thinking about them first" is a kind of understanding, so I guess I'll have to admit that technically you are right :-) > So, I have given up trying to assign *blame* for that confusion. But > from what I can tell it's a canard to say that the confusion is ?spread > about by Perl users?. Perhaps I should have said "*was*. I hardly see this "Only One Way" business these days. A decade or two ago, it was much more common, and mostly (in my experience) coming from Perl users as a put-down, that Python needlessly limits what the programmer can do. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From Karsten.Hilbert at gmx.net Sun Nov 5 05:53:07 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sun, 5 Nov 2017 11:53:07 +0100 Subject: Aw: Try: Except: evaluates to True every time In-Reply-To: <59fe5b3e$0$18582$b1db1813$d948b532@news.astraweb.com> References: <59fe5b3e$0$18582$b1db1813$d948b532@news.astraweb.com> Message-ID: <20171105105307.fjesogjs3tt3kdr5@hermes.hilbert.loc> On Sun, Nov 05, 2017 at 11:28:44AM +1100, Steve D'Aprano wrote: > > Try in an interactive interpreter: > > > > python> "a string" is True > > Did you try that yourself? Yes, eventually, which is why I corrected myself publicly. However, while it doesn't return True (as I mistakenly suggested) it does return False, always, which is the very same reason for OP's problem, namely returning a string, doing a logic test on that, and assuming that would tell whether the check succeeded or failed. Unless I am totally mistaken :-) Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 From p.f.moore at gmail.com Sun Nov 5 08:35:49 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Sun, 5 Nov 2017 13:35:49 +0000 Subject: [TSBOAPOOOWTDI]using names from modules In-Reply-To: <59fe6734$0$18585$b1db1813$d948b532@news.astraweb.com> References: <59fe6734$0$18585$b1db1813$d948b532@news.astraweb.com> Message-ID: On 5 November 2017 at 01:19, Steve D'Aprano wrote: > On Sun, 5 Nov 2017 06:42 am, Stefan Ram wrote: > >> What is the one way to do it? > > There is no philosophy of "one way to do it" in Python, that is a > misunderstanding (possibly deliberate...) spread about by Perl users, to > contrast Python from Perl's "more than one way to do it". > > The Zen of Python says: > > There should be one-- and preferably only one --obvious way to do it. > > > The emphasis is on "obvious", not "one". There should be *at least* one, but > preferably only one, OBVIOUS way to solve any problem. > > As for the question of importing names, the obvious way is to use a regular > import: > > > import math > y = math.cos(x) > > > which has the advantage of making it obvious where the name comes from, but > the disadvantage that it is more to type and involves an extra name lookup at > runtime, which is not free. > > But: > > - when performance matters > > - or the name is very well known > > - or you're only using a single name from the module (or at most a few) > > - especially if it repeats the module name (e.g. fractions.Fraction) > > it is acceptable to use the "from module import name" version: > > from math import cos > y = cos(x) > > > Which you use depends on the situation and personal taste. Also, if what you are trying to "do" is different (for example, you're trying to write code that looks familiar to mathematicians) the obvious way may be different too (so "from math import cos" may be the obvious approach in that situation). But regardless, the Zen isn't intended to be taken quite as literally as the OP was trying to do. It's a statement of principles, not a set of rules. Paul From p.f.moore at gmail.com Sun Nov 5 08:39:13 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Sun, 5 Nov 2017 13:39:13 +0000 Subject: Read Firefox sqlite files with Python In-Reply-To: <59fe67c4$0$18585$b1db1813$d948b532@news.astraweb.com> References: <59fdf99f$0$14949$b1db1813$d948b532@news.astraweb.com> <59fe67c4$0$18585$b1db1813$d948b532@news.astraweb.com> Message-ID: On 5 November 2017 at 01:22, Steve D'Aprano wrote: > On Sun, 5 Nov 2017 04:32 am, Steve D'Aprano wrote: > >> I'm trying to dump a Firefox IndexDB sqlite file to text using Python 3.5. >> >> >> import sqlite3 >> con = sqlite3.connect('foo.sqlite') >> with open('dump.sql', 'w') as f: >> for line in con.iterdump(): >> f.write(line + '\n') > > > Never mind. I dumped the file using the sqlite3 command line tool. Thank you > to all those who answered. > > The file contains three INSERT statements, the first two don't have anything > of interest, and the third (which presumably contains all the data I'm trying > to recover) is an opaque 600+ KB blob. > > Naturally. Why would you use a database as a database, when instead you could > just dump a big ball of mud into it? Hmm, *.sql files normally contain SQL source code (as this one does). SQLIte databases in my experiences typically use either ".sqlite" or ".db" for the extension. Are you sure you're looking at the right file? Alternatively I guess it's possible that Firefox creates an in-memory database, then executes the dump.sql file to populate it, for performance reasons. Paul From steve+python at pearwood.info Sun Nov 5 08:59:11 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 06 Nov 2017 00:59:11 +1100 Subject: Aw: Try: Except: evaluates to True every time References: <59fe5b3e$0$18582$b1db1813$d948b532@news.astraweb.com> <20171105105307.fjesogjs3tt3kdr5@hermes.hilbert.loc> Message-ID: <59ff1932$0$18636$b1db1813$d948b532@news.astraweb.com> On Sun, 5 Nov 2017 09:53 pm, Karsten Hilbert wrote: > On Sun, Nov 05, 2017 at 11:28:44AM +1100, Steve D'Aprano wrote: > >> > Try in an interactive interpreter: >> > >> > python> "a string" is True >> >> Did you try that yourself? > > Yes, eventually, which is why I corrected myself publicly. Oops, didn't see that. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sun Nov 5 09:13:54 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 06 Nov 2017 01:13:54 +1100 Subject: [TSBOAPOOOWTDI]using names from modules References: <59fe6734$0$18585$b1db1813$d948b532@news.astraweb.com> Message-ID: <59ff1ca4$0$18629$b1db1813$d948b532@news.astraweb.com> On Mon, 6 Nov 2017 12:54 am, Stefan Ram wrote: > Paul Moore writes: >>But regardless, the Zen isn't intended to be taken quite as literally >>as the OP was trying to do. It's a statement of principles, not a set >>of rules. > > What I am looking for is a default notation to use in my > beginner's tutorial and also to recommand for beginners. When I first started learning Python, I had a bit of difficulty with the two import forms. For about an hour, until I experimented in the interactive interpreter until I got it. Part of the problem at the time was that I had no concept of "namespaces" or modules. If your students are experienced in other languages, don't treat them like dummies. They'll probably understand about namespaces and variable scopes. Teach them that math.cos is the syntax for accessing a name "cos" inside the "math" namespace, and they'll get it. Teach them that the from...import version brings the name into the current scope, and they'll get that too. You might have to give them analogous examples from whatever languages they're used to. If your students are completely new to this, like I was, then it might help to start them with just the "import math" form, and then later introduce "from...import" as syntactic sugar for: import math cos = math.cos del math Although I wouldn't literally teach `del` at this point, I'd just leave it out and and "except that the name 'math' isn't actually made available". > Learners have a limited capacity for learning and storing > information. People don't learn isolated facts too well. But they learn *models* which they can then infer behaviour from VERY well. This is why the Principle of Least Surprise is so important for usable interfaces and APIs. If you try to teach things as isolated facts, students will struggle. But: - teach import math first; - then show how `from math import cos` is syntactic sugar for making a local alias for math.cos; - then you can show that there's no particular reason why the names have to be the same: from math import cos as mycos is just sugar for import math mycos = math.cos But don't teach them this: > |from math import * There's no reason for beginners to use wildcard imports until they've mastered *not* using wildcard imports. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jon+usenet at unequivocal.eu Sun Nov 5 09:39:15 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sun, 5 Nov 2017 14:39:15 -0000 (UTC) Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <59fe7f5e$0$18601$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-11-05, Steve D'Aprano wrote: > On Sat, 4 Nov 2017 04:44 am, Jon Ribbens wrote: >> That conforms to my model. It's searching for the condition >> 'count > MAX_OBJECTS'. > > That's sounds to me that you are willing to call just about any test of a > condition inside a loop a "search". I don't think that's helpful. I think it > is mangling the word to the point it is meaningless. You're entitled to your opinion, of course. I've provided you with a way of thinking about 'for...else' that makes its purpose and meaning intuitively obvious. You'd apparently prefer to think about it a different way that makes it counter-intuitive, and would like to change the language to match your thinking instead. I'd regretfully suggest that that is not going to happen. > How about a loop that exits at some random time? Is that a search? > > for i in range(100, 0, -1): > if flip_coin() == 'Heads': Of course, that's searching for the condition "flip_coin() == 'Heads'". > What you actually wrote, in various posts: > > You have a 'for...else' with no 'break'. Like I said, that should > probably be a syntax error. > > if what the 'for' clause is doing doesn't match the concept > of 'searching for a match' then it's obvious that you shouldn't > be using 'for...else' in the first place. > > the language doesn't currently strictly enforce the requirement > for a 'break', but nevertheless if you don't have one you almost > certainly have a bug. > > I stand by my comment as an accurate description of your response. You're conflating two completely different points: * whether to allow 'for...else' with no 'break' * how to think about 'for...else' with a 'break' My comment about syntax errors only has any relevance at all to the former point. > I find the code useful. I shouldn't have to justify why it is useful to me, > but for the record it especially comes in handy when I've already typed out a > multi-line loop in the REPL, and only then realised that I'll need some way > to add an extra line at the end. Just press up arrow to go back and edit the first line of your current input and insert an 'if 1:' as someone else suggested. > And yes, a better REPL would also solve that problem. But I have to use the > REPL that exists, not the imaginary one that I'd like. If you want to call > this a hackish work around for a limitation of the REPL, I'll say... okay. > What's your point? It is still useful. The question isn't whether it's useful, but whether it's *more* useful than preventing bugs in peoples' code. You're entitled to your opinion on that, and I'm entitled to mine, and neither opinion is 'arrogant'. We're all just making guesses in the dark, unless anybody has any statistics about how much time is wasted each year by bugs caused by 'for...else' with no 'break' and how much time would be wasted each year by people being unable to use your REPL trick. From p.f.moore at gmail.com Sun Nov 5 14:18:43 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Sun, 5 Nov 2017 19:18:43 +0000 Subject: [TSBOAPOOOWTDI]using names from modules In-Reply-To: References: <59fe6734$0$18585$b1db1813$d948b532@news.astraweb.com> Message-ID: On 5 November 2017 at 13:54, Stefan Ram wrote: > Paul Moore writes: >>But regardless, the Zen isn't intended to be taken quite as literally >>as the OP was trying to do. It's a statement of principles, not a set >>of rules. > > What I am looking for is a default notation to use in my > beginner's tutorial and also to recommand for beginners. Then "import math" at the top of the file, and refer to module functions as "math.sin". That's the normal approach you'd see in pretty much every Python project on the web, so "follow normal practice" applies. By the time your students know enough to ask if there's a way to avoid needing to repeat "math" (and understand the answer) they are likely to be experienced enough to judge which option is better in a given situation. Paul From stefanossofroniou542 at gmail.com Sun Nov 5 16:09:20 2017 From: stefanossofroniou542 at gmail.com (=?UTF-8?B?zqPPhM6tz4bOsc69zr/PgiDOo8+Jz4bPgc6/zr3Or86/z4U=?=) Date: Sun, 5 Nov 2017 13:09:20 -0800 (PST) Subject: Python Mailing list moderators Message-ID: Folks, More and more nonsense are coming in and I find it really difficult to follow any new post that may come and I have to either search for specific content or scroll down until I hit it by accident. Can we do something about it? It's getting really frustrating :/ Cheers. From cs at cskk.id.au Sun Nov 5 16:14:37 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 6 Nov 2017 08:14:37 +1100 Subject: Python Mailing list moderators In-Reply-To: References: Message-ID: <20171105211437.GA94644@cskk.homeip.net> On 05Nov2017 13:09, ???????? ????????? wrote: >Folks, >More and more nonsense are coming in and I find it really difficult to follow >any new post that may come and I have to either search for specific content or >scroll down until I hit it by accident. > >Can we do something about it? >It's getting really frustrating :/ It seems from the headers on your message that you're actually using the comp.lang.python newsgroup and not the mailing list. The newsgroup is completed unmoderated. The mailing list is far less noisy. Go here: https://mail.python.org/mailman/listinfo/python-list and subscribe, and see if things seem better than the newsgroup. Cheers, Cameron Simpson (formerly cs at zip.com.au) From tjreedy at udel.edu Sun Nov 5 17:28:05 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 5 Nov 2017 17:28:05 -0500 Subject: Python Mailing list moderators In-Reply-To: <20171105211437.GA94644@cskk.homeip.net> References: <20171105211437.GA94644@cskk.homeip.net> Message-ID: On 11/5/2017 4:14 PM, Cameron Simpson wrote: > On 05Nov2017 13:09, ???????? ????????? > wrote: >> Folks, >> More and more nonsense are coming in and I find it really difficult to >> follow any new post that may come and I have to either search for >> specific content or scroll down until I hit it by accident. >> >> Can we do something about it? >> It's getting really frustrating :/ > > It seems from the headers on your message that you're actually using the > comp.lang.python newsgroup and not the mailing list. The newsgroup is > completed unmoderated.? The mailing list is far less noisy. > > Go here: > > ?https://mail.python.org/mailman/listinfo/python-list > > and subscribe, and see if things seem better than the newsgroup. Or point your newsreader to news.gmane.org group gmane.comp.python.general, which mirrors python-list. Terry Jan Reedy From ben+python at benfinney.id.au Sun Nov 5 17:54:11 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 06 Nov 2017 09:54:11 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <59fe7f5e$0$18601$b1db1813$d948b532@news.astraweb.com> Message-ID: <85po8wz698.fsf@benfinney.id.au> Jon Ribbens writes: > I've provided you with a way of thinking about 'for...else' that makes > its purpose and meaning intuitively obvious. I've read that sentence several times, and I still can't make it anything but a contradiction in terms. Something that is ?intuitively obvious? surely has the property that it *does not need* a special ?way of thinking about? it. So I can't see that it could be ?intuitively obvious? if that special way of thinking about it is needed. Did you mean something else? -- \ ?Don't worry about what anybody else is going to do. The best | `\ way to predict the future is to invent it.? ?Alan Kay | _o__) | Ben Finney From jon+usenet at unequivocal.eu Sun Nov 5 18:06:03 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sun, 5 Nov 2017 23:06:03 -0000 (UTC) Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <59fe7f5e$0$18601$b1db1813$d948b532@news.astraweb.com> <85po8wz698.fsf@benfinney.id.au> Message-ID: On 2017-11-05, Ben Finney wrote: > Jon Ribbens writes: >> I've provided you with a way of thinking about 'for...else' that makes >> its purpose and meaning intuitively obvious. > > I've read that sentence several times, and I still can't make it > anything but a contradiction in terms. Well, keep at it and I'm sure you'll work it out eventually. From ben+python at benfinney.id.au Sun Nov 5 19:03:03 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 06 Nov 2017 11:03:03 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <59fe7f5e$0$18601$b1db1813$d948b532@news.astraweb.com> <85po8wz698.fsf@benfinney.id.au> Message-ID: <85lgjkz32g.fsf@benfinney.id.au> Jon Ribbens writes: > On 2017-11-05, Ben Finney wrote: > > Jon Ribbens writes: > >> I've provided you with a way of thinking about 'for...else' that makes > >> its purpose and meaning intuitively obvious. > > > > I've read that sentence several times, and I still can't make it > > anything but a contradiction in terms. > > Well, keep at it and I'm sure you'll work it out eventually. You don't want to provide me with a way of thinking about it that makes it mean something non-contradictory? :-) -- \ ?Capitalism has destroyed our belief in any effective power but | `\ that of self interest backed by force.? ?George Bernard Shaw | _o__) | Ben Finney From steve+python at pearwood.info Sun Nov 5 19:06:34 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 06 Nov 2017 11:06:34 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <59fe7f5e$0$18601$b1db1813$d948b532@news.astraweb.com> <85po8wz698.fsf@benfinney.id.au> Message-ID: <59ffa78d$0$18577$b1db1813$d948b532@news.astraweb.com> On Mon, 6 Nov 2017 10:06 am, Jon Ribbens wrote: > On 2017-11-05, Ben Finney wrote: >> Jon Ribbens writes: >>> I've provided you with a way of thinking about 'for...else' that makes >>> its purpose and meaning intuitively obvious. >> >> I've read that sentence several times, and I still can't make it >> anything but a contradiction in terms. > > Well, keep at it and I'm sure you'll work it out eventually. Alice laughed. 'There's no use trying,' she said. 'One can't believe impossible things.' 'I daresay you haven't had much practice,' said the Queen. 'When I was your age, I always did it for half-an-hour a day. Why, sometimes I've believed as many as six impossible things before breakfast.' -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sun Nov 5 19:39:35 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Nov 2017 11:39:35 +1100 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <59ffa78d$0$18577$b1db1813$d948b532@news.astraweb.com> References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <59fe7f5e$0$18601$b1db1813$d948b532@news.astraweb.com> <85po8wz698.fsf@benfinney.id.au> <59ffa78d$0$18577$b1db1813$d948b532@news.astraweb.com> Message-ID: On Mon, Nov 6, 2017 at 11:06 AM, Steve D'Aprano wrote: > On Mon, 6 Nov 2017 10:06 am, Jon Ribbens wrote: > >> On 2017-11-05, Ben Finney wrote: >>> Jon Ribbens writes: >>>> I've provided you with a way of thinking about 'for...else' that makes >>>> its purpose and meaning intuitively obvious. >>> >>> I've read that sentence several times, and I still can't make it >>> anything but a contradiction in terms. >> >> Well, keep at it and I'm sure you'll work it out eventually. > > > Alice laughed. 'There's no use trying,' she said. 'One can't > believe impossible things.' > > 'I daresay you haven't had much practice,' said the Queen. > 'When I was your age, I always did it for half-an-hour a day. > Why, sometimes I've believed as many as six impossible things > before breakfast.' Yes, that. Although I was more thinking of the word "intuitively": `When _I_ use a word,' Humpty Dumpty said in rather a scornful tone, `it means just what I choose it to mean -- neither more nor less.' `The question is,' said Alice, `whether you CAN make words mean so many different things.' `The question is,' said Humpty Dumpty, `which is to be master - - that's all.' ChrisA From steve+python at pearwood.info Sun Nov 5 20:47:22 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 06 Nov 2017 12:47:22 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <59fe7f5e$0$18601$b1db1813$d948b532@news.astraweb.com> Message-ID: <59ffbf2d$0$14972$b1db1813$d948b532@news.astraweb.com> On Mon, 6 Nov 2017 01:39 am, Jon Ribbens wrote: > On 2017-11-05, Steve D'Aprano wrote: >> On Sat, 4 Nov 2017 04:44 am, Jon Ribbens wrote: >>> That conforms to my model. It's searching for the condition >>> 'count > MAX_OBJECTS'. >> >> That's sounds to me that you are willing to call just about any test of a >> condition inside a loop a "search". I don't think that's helpful. I think >> it is mangling the word to the point it is meaningless. > > You're entitled to your opinion, of course. I've provided you with a > way of thinking about 'for...else' that makes its purpose and meaning > intuitively obvious. By definition, if people have to learn the "right mental model" (as opposed to the one which just comes to them naturally) then there is nothing intuitive about it. [...] >> I find the code useful. I shouldn't have to justify why it is useful to me, >> but for the record it especially comes in handy when I've already typed out >> a multi-line loop in the REPL, and only then realised that I'll need some >> way to add an extra line at the end. > > Just press up arrow to go back and edit the first line of your > current input and insert an 'if 1:' as someone else suggested. "Just press up arrow" -- and that will magically fill in the other 10 lines I typed, will it? Don't be so condescending. I know how to use up-arrow, and I even described using it, which you cut out of your reply. That's a pretty dishonest trick. You saw that I had already discussed the limitations of using up-arrow to retrieve lines from command line history, but rather than acknowledge that, you deleted my comment and added condescending and useless "advice" to make me seem like I don't even know something as simple as up-arrow. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sun Nov 5 21:28:39 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 06 Nov 2017 13:28:39 +1100 Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <20dbbfc4-1779-2a54-931e-5b4406bd757c@gmail.com> <59fd1341$0$18598$b1db1813$d948b532@news.astraweb.com> <0747b713-594a-1a83-ebed-639a728e5821@gmail.com> <2abf5736-fd0a-9465-c55f-6f4bd8ceb5c7@gmail.com> Message-ID: <59ffc8d8$0$18611$b1db1813$d948b532@news.astraweb.com> On Sat, 4 Nov 2017 03:57 pm, Michael Torrie wrote: > On 11/03/2017 09:06 PM, Chris Angelico wrote: >> On Sat, Nov 4, 2017 at 1:57 PM, Michael Torrie wrote: >>> On 11/03/2017 07:09 PM, Steve D'Aprano wrote: >>>> On Sat, 4 Nov 2017 06:15 am, Michael Torrie wrote: >>>> >>>>> In fact if you have no break you may as well drop the >>>>> else entirely, because the block will always execute. >>>> >>>> That's incorrect. There are multiple ways to exit a loop that will >>>> prevent the `else` block from executing, `break` is only one. >>> >>> Such as? >> >> There are many. But other than break, I don't know of any that WOULD >> execute the next line of code immediately _after_ the loop. > > Can you be more specific? What are some of these "many" ways of aborting > a loop? Help a guy out here. Aside from more exotic methods such as os.abort, os._exit and signal handlers, the common ways of breaking out of a loop are: - raise - return - break Am I being pedantic? Of course I am. But we're programmers -- if we don't have an accurate and complete understanding of code, who will? Given how many people find it difficult to understand the semanics of for...else, I think we need to be pedantic about it. I raise these because such commonplace ways of exiting a loop rules out suggestions that we think of or rename `else` as "else no break" or "finally": (1) `else no break` is misleading as it implies that `break` is the only way to avoid running the block; (2) `finally` is misleading as it suggests that the block runs even when you raise or return out of the loop, like a try...finally block. > I know, for example, that we have exceptions. But those hardly matter in > this discussion because they wouldn't execute the else clause either. That contradicts what you said earlier: "if you have no break the [else] block will always execute." Of course you are right -- an exception will also prevent the `else` clause from running. But that's not what you said earlier. Hence my correction. The fact that `raise` and `return` avoid running the `else` block is not a given. We cannot afford to say "that's so obvious it doesn't need to be said". It isn't obvious. There are at least two other code blocks that make guarantees about code "always"[1] running, even if you raise or return: - in a try...except...else block, the `finally` block will still run; - in a `with` block, the context manager's `__exit__` method will usually run (it depends on the context manager). [1] For reasonable values of "always". Obviously if you drop a 1000 tonne weight on the computer, the `finally` clause will not get a chance to run before the CPU is crushed into powder :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sun Nov 5 22:12:14 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 06 Nov 2017 14:12:14 +1100 Subject: Read Firefox sqlite files with Python References: <59fdf99f$0$14949$b1db1813$d948b532@news.astraweb.com> <59fe67c4$0$18585$b1db1813$d948b532@news.astraweb.com> Message-ID: <59ffd30f$0$18565$b1db1813$d948b532@news.astraweb.com> On Mon, 6 Nov 2017 12:39 am, Paul Moore wrote: > On 5 November 2017 at 01:22, Steve D'Aprano > wrote: >> On Sun, 5 Nov 2017 04:32 am, Steve D'Aprano wrote: >> >>> I'm trying to dump a Firefox IndexDB sqlite file to text using Python 3.5. >>> >>> >>> import sqlite3 >>> con = sqlite3.connect('foo.sqlite') >>> with open('dump.sql', 'w') as f: >>> for line in con.iterdump(): >>> f.write(line + '\n') >> >> >> Never mind. I dumped the file using the sqlite3 command line tool. Thank >> you to all those who answered. >> >> The file contains three INSERT statements, the first two don't have >> anything of interest, and the third (which presumably contains all the data >> I'm trying to recover) is an opaque 600+ KB blob. >> >> Naturally. Why would you use a database as a database, when instead you >> could just dump a big ball of mud into it? > > Hmm, *.sql files normally contain SQL source code (as this one does). The .sql file is the result of running .dump from the sqlite command line tool. The original source database is 'foo.sqlite'. To be precise, it is the database used by the Firefox Add-On "One Tab". /home/steve/.mozilla/firefox/2z5po7dx.default/storage/permanent/indexeddb+++extension-at-one-tab-dot-com/idb/1832832054obnaet.sqlite One Tab provides an alternative bookmark-like function, allowing you to record URLs in groups for later use -- a bit like bookmarks. So I've been using this for some months, until the add-on stopped working. (Yet again an automatic update has screwed me and broken functionality.) So now I'm trying to retrieve the bookmarks. The database itself (the .sqlite file) is not corrupt. The sqlite CLI processes it fine, and gives me a dump file containing a valid looking transaction: PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; CREATE TABLE file (id INTEGER PRIMARY KEY, refcount INTEGER NOT NULL); CREATE TABLE "database" ( name TEXT PRIMARY KEY, origin TEXT NOT NULL, version INTEGER NOT NULL DEFAULT 0, last_vacuum_time INTEGER NOT NULL DEFAULT 0, last_analyze_time INTEGER NOT NULL DEFAULT 0, last_vacuum_size INTEGER NOT NULL DEFAULT 0) WITHOUT ROWID; ... COMMIT; But the *interesting* part, the actual data which I hoped would be something useful like a table of URLs, is a binary blob: CREATE TABLE "object_data"( object_store_id INTEGER NOT NULL, key BLOB NOT NULL, index_data_values BLOB DEFAULT NULL, file_ids TEXT, data BLOB NOT NULL, PRIMARY KEY (object_store_id, key), FOREIGN KEY (object_store_id) REFERENCES object_store(id) ) WITHOUT ROWID; which then has three insertions, all of which look something like: INSERT INTO "object_data" VALUES(1,X'307475627566',NULL,NULL,X'B8F32BA8...'); where the last argument is anything up to 11000+ hex digits. So it looks like it might be just dumping its in-memory data structure into the database as a blob. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jon+usenet at unequivocal.eu Mon Nov 6 06:34:47 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 6 Nov 2017 11:34:47 -0000 (UTC) Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <59fe7f5e$0$18601$b1db1813$d948b532@news.astraweb.com> <85po8wz698.fsf@benfinney.id.au> <85lgjkz32g.fsf@benfinney.id.au> Message-ID: On 2017-11-06, Ben Finney wrote: > Jon Ribbens writes: >> On 2017-11-05, Ben Finney wrote: >> > Jon Ribbens writes: >> >> I've provided you with a way of thinking about 'for...else' that makes >> >> its purpose and meaning intuitively obvious. >> > >> > I've read that sentence several times, and I still can't make it >> > anything but a contradiction in terms. >> >> Well, keep at it and I'm sure you'll work it out eventually. > > You don't want to provide me with a way of thinking about it that makes > it mean something non-contradictory? :-) It already does mean something non-contradictory. This is comp.lang.python (or python-list), not alt.english.remedial. If you start from the wrong premise, as Steve is doing, then even the most obvious of things can be rendered opaque and confusing. As I said, I've provided a solution to the problem, what more do you want? This feels very much like you're arguing for argument's sake, which is a game I'm not willing to play along with for much longer. From bc at freeuk.com Mon Nov 6 06:37:50 2017 From: bc at freeuk.com (bartc) Date: Mon, 6 Nov 2017 11:37:50 +0000 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <59ffc8d8$0$18611$b1db1813$d948b532@news.astraweb.com> References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <20dbbfc4-1779-2a54-931e-5b4406bd757c@gmail.com> <59fd1341$0$18598$b1db1813$d948b532@news.astraweb.com> <0747b713-594a-1a83-ebed-639a728e5821@gmail.com> <2abf5736-fd0a-9465-c55f-6f4bd8ceb5c7@gmail.com> <59ffc8d8$0$18611$b1db1813$d948b532@news.astraweb.com> Message-ID: <0QXLB.10599$Sy2.7420@fx26.am4> On 06/11/2017 02:28, Steve D'Aprano wrote: > On Sat, 4 Nov 2017 03:57 pm, Michael Torrie wrote: >> Can you be more specific? What are some of these "many" ways of aborting >> a loop? Help a guy out here. > > Aside from more exotic methods such as os.abort, os._exit and signal handlers, > the common ways of breaking out of a loop are: > > - raise > - return > - break > > Am I being pedantic? Of course I am. But we're programmers -- if we don't have > an accurate and complete understanding of code, who will? Given how many > people find it difficult to understand the semanics of for...else, I think we > need to be pedantic about it. Take this for-loop: for I in R: A else: B C Here are the various ways of exiting the loop, with Y or N indicating whether that particular block (or 'suite') is executed: B C Normal termination: Y Y Break from A: N Y Raise/return/etc from A: N N Here, we're only interested in whether B and C have different entries, as that would be the only reason to have an 'else' part in the first place. And that only happens when the loop is terminated with a Break. Unless someone knows of any other circumstances where B is not executed but C is. (Both B and C also contain raise, return, exit(), infinite loops etc, but that shouldn't effect this point.) Break inside the loop can also be conditional (I think it has to be if you want more than one iteration!), which means that sometimes, it will never break, then you get the Y/Y (or N/N) result. But the expectation is that there the break COULD be executed, so you will need the 'else'. -- bartc From rosuav at gmail.com Mon Nov 6 06:58:45 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Nov 2017 22:58:45 +1100 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <59fe7f5e$0$18601$b1db1813$d948b532@news.astraweb.com> <85po8wz698.fsf@benfinney.id.au> <85lgjkz32g.fsf@benfinney.id.au> Message-ID: On Mon, Nov 6, 2017 at 10:34 PM, Jon Ribbens wrote: > On 2017-11-06, Ben Finney wrote: >> Jon Ribbens writes: >>> On 2017-11-05, Ben Finney wrote: >>> > Jon Ribbens writes: >>> >> I've provided you with a way of thinking about 'for...else' that makes >>> >> its purpose and meaning intuitively obvious. >>> > >>> > I've read that sentence several times, and I still can't make it >>> > anything but a contradiction in terms. >>> >>> Well, keep at it and I'm sure you'll work it out eventually. >> >> You don't want to provide me with a way of thinking about it that makes >> it mean something non-contradictory? :-) > > It already does mean something non-contradictory. This is > comp.lang.python (or python-list), not alt.english.remedial. > If you start from the wrong premise, as Steve is doing, then > even the most obvious of things can be rendered opaque and > confusing. If you start with the assumption that "intuitively obvious" doesn't actually mean "intuitively obvious" but actually means something completely different, then your statement definitely means something non-contradictory. But if you start with the assumption that "intuitively obvious" really does mean that the purpose and meaning of for-else can be understood easily without external information, then your statement contradicts itself. This is comp.lang.python, not alt.english.remedial, so we expect you to use English competently, or at least accept correction when you misuse words. > As I said, I've provided a solution to the problem, what more > do you want? This feels very much like you're arguing for > argument's sake, which is a game I'm not willing to play along > with for much longer. Except that you haven't. Your proposed solution is incorrect and false. ChrisA From jon+usenet at unequivocal.eu Mon Nov 6 08:05:28 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 6 Nov 2017 13:05:28 -0000 (UTC) Subject: replacing `else` with `then` in `for` and `try` References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <59fe7f5e$0$18601$b1db1813$d948b532@news.astraweb.com> <85po8wz698.fsf@benfinney.id.au> <85lgjkz32g.fsf@benfinney.id.au> Message-ID: On 2017-11-06, Chris Angelico wrote: > If you start with the assumption that "intuitively obvious" doesn't > actually mean "intuitively obvious" but actually means something > completely different, then your statement definitely means something > non-contradictory. But if you start with the assumption that > "intuitively obvious" really does mean that the purpose and meaning of > for-else can be understood easily without external information, then > your statement contradicts itself. I didn't say that 'for...else' was inherently "intutively obvious". In fact I said the opposite of that. I said that *if* you start from the right premise then it *becomes* intuitively obvious. > This is comp.lang.python, not alt.english.remedial, so we expect you > to use English competently, or at least accept correction when you > misuse words. I'm glad your expectations are being met then. You might want to work on also reading English competently, and then everyone will be happy! >> As I said, I've provided a solution to the problem, what more >> do you want? This feels very much like you're arguing for >> argument's sake, which is a game I'm not willing to play along >> with for much longer. > > Except that you haven't. Your proposed solution is incorrect and false. Yes, your logical argument there as to why is undeniable. I must admit that your little gang's assertion that I'm foolish and mistaken because I find Python's syntax simple to understand and you find it hard to understand seems a little contradictory. From rustompmody at gmail.com Mon Nov 6 08:24:53 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 6 Nov 2017 05:24:53 -0800 (PST) Subject: Read Firefox sqlite files with Python In-Reply-To: <59ffd30f$0$18565$b1db1813$d948b532@news.astraweb.com> References: <59fdf99f$0$14949$b1db1813$d948b532@news.astraweb.com> <59fe67c4$0$18585$b1db1813$d948b532@news.astraweb.com> <59ffd30f$0$18565$b1db1813$d948b532@news.astraweb.com> Message-ID: On Monday, November 6, 2017 at 8:42:29 AM UTC+5:30, Steve D'Aprano wrote: > On Mon, 6 Nov 2017 12:39 am, Paul Moore wrote: > > > On 5 November 2017 at 01:22, Steve D'Aprano wrote: > >> On Sun, 5 Nov 2017 04:32 am, Steve D'Aprano wrote: > >> > >>> I'm trying to dump a Firefox IndexDB sqlite file to text using Python 3.5. > >>> > >>> > >>> import sqlite3 > >>> con = sqlite3.connect('foo.sqlite') > >>> with open('dump.sql', 'w') as f: > >>> for line in con.iterdump(): > >>> f.write(line + '\n') > >> > >> > >> Never mind. I dumped the file using the sqlite3 command line tool. Thank > >> you to all those who answered. > >> > >> The file contains three INSERT statements, the first two don't have > >> anything of interest, and the third (which presumably contains all the data > >> I'm trying to recover) is an opaque 600+ KB blob. > >> > >> Naturally. Why would you use a database as a database, when instead you > >> could just dump a big ball of mud into it? > > > > Hmm, *.sql files normally contain SQL source code (as this one does). > > The .sql file is the result of running .dump from the sqlite command line > tool. The original source database is 'foo.sqlite'. To be precise, it is the > database used by the Firefox Add-On "One Tab". > > /home/steve/.mozilla/firefox/2z5po7dx.default/storage/permanent/indexeddb+++extension-at-one-tab-dot-com/idb/1832832054obnaet.sqlite > > One Tab provides an alternative bookmark-like function, allowing you to record > URLs in groups for later use -- a bit like bookmarks. So I've been using this > for some months, until the add-on stopped working. (Yet again an automatic > update has screwed me and broken functionality.) So now I'm trying to > retrieve the bookmarks. [Not python-related and likely not an answer? Just what I would try] 1. Get hold of an old live ubuntu (say 12.4) ISO/flash/CD and boot 2. Mount /home 3. Make livecd~/.mozilla symlink to home/~steven/.mozilla Do you see your bookmarks? From tb.sm.text at gmail.com Mon Nov 6 08:30:55 2017 From: tb.sm.text at gmail.com (tb.sm.text at gmail.com) Date: Mon, 6 Nov 2017 05:30:55 -0800 (PST) Subject: solutions manual, test bank for Industrial Organizational Psychology 4e Paul Levy, contact direct by email at studentshelp(at)hotmail(dot)com In-Reply-To: References: Message-ID: <99039bc4-41b3-4a57-8e7d-a25f9b523d19@googlegroups.com> for any test bank or solutions manual please contact :tbsmtext(at)gmail(dot)com From tb.sm.text at gmail.com Mon Nov 6 08:33:37 2017 From: tb.sm.text at gmail.com (tb.sm.text at gmail.com) Date: Mon, 6 Nov 2017 05:33:37 -0800 (PST) Subject: solutions manual, test bank for Psychological Testing Principles, Applications, and Issues, 9e Robert Kaplan, Dennis Saccuzzo, contact direct by email at studentshelp(at)hotmail(dot)com In-Reply-To: <962cafa7-18a5-44ef-8564-101567b1bb0f@googlegroups.com> References: <962cafa7-18a5-44ef-8564-101567b1bb0f@googlegroups.com> Message-ID: for any test bank or solutions manual please contact :tbsmtext(at)gmail(dot)com From rosuav at gmail.com Mon Nov 6 08:55:29 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Nov 2017 00:55:29 +1100 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <59fe7f5e$0$18601$b1db1813$d948b532@news.astraweb.com> <85po8wz698.fsf@benfinney.id.au> <85lgjkz32g.fsf@benfinney.id.au> Message-ID: On Tue, Nov 7, 2017 at 12:05 AM, Jon Ribbens wrote: > On 2017-11-06, Chris Angelico wrote: >> If you start with the assumption that "intuitively obvious" doesn't >> actually mean "intuitively obvious" but actually means something >> completely different, then your statement definitely means something >> non-contradictory. But if you start with the assumption that >> "intuitively obvious" really does mean that the purpose and meaning of >> for-else can be understood easily without external information, then >> your statement contradicts itself. > > I didn't say that 'for...else' was inherently "intutively obvious". > In fact I said the opposite of that. I said that *if* you start from > the right premise then it *becomes* intuitively obvious. If you have to start by explaining a premise, it's not intuitive. ChrisA From ned at nedbatchelder.com Mon Nov 6 08:56:48 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 6 Nov 2017 08:56:48 -0500 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <59fca14b$0$18601$b1db1813$d948b532@news.astraweb.com> <59fe7f5e$0$18601$b1db1813$d948b532@news.astraweb.com> <85po8wz698.fsf@benfinney.id.au> <85lgjkz32g.fsf@benfinney.id.au> Message-ID: <3a7e715d-a1cf-b88c-0c23-3203448ada6f@nedbatchelder.com> On 11/6/17 8:05 AM, Jon Ribbens wrote: > On 2017-11-06, Chris Angelico wrote: >> If you start with the assumption that "intuitively obvious" doesn't >> actually mean "intuitively obvious" but actually means something >> completely different, then your statement definitely means something >> non-contradictory. But if you start with the assumption that >> "intuitively obvious" really does mean that the purpose and meaning of >> for-else can be understood easily without external information, then >> your statement contradicts itself. > I didn't say that 'for...else' was inherently "intutively obvious". > In fact I said the opposite of that. I said that *if* you start from > the right premise then it *becomes* intuitively obvious. > >> This is comp.lang.python, not alt.english.remedial, so we expect you >> to use English competently, or at least accept correction when you >> misuse words. > I'm glad your expectations are being met then. You might want to work > on also reading English competently, and then everyone will be happy! > >>> As I said, I've provided a solution to the problem, what more >>> do you want? This feels very much like you're arguing for >>> argument's sake, which is a game I'm not willing to play along >>> with for much longer. >> Except that you haven't. Your proposed solution is incorrect and false. > Yes, your logical argument there as to why is undeniable. I must admit > that your little gang's assertion that I'm foolish and mistaken because > I find Python's syntax simple to understand and you find it hard to > understand seems a little contradictory. Ugh, can't we all just give each other the benefit of the doubt, and use the principle of charity?? It's easy to miscommunicate in a purely textual medium.?? Everyone just take your foot off the "i'm right and you're wrong" gas pedal for moment. --Ned. From tjol at tjol.eu Mon Nov 6 10:14:52 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 6 Nov 2017 16:14:52 +0100 Subject: FW: Reading a remove csv file In-Reply-To: References: <1509621847l.38011130l. 0l@psu.edu> <1509628701l.35455224l.0l@psu.edu> Message-ID: <17fbf191-49ed-4d3e-5659-08ed89ce20da@tjol.eu> On 2017-11-03 00:40, Stefan Ram wrote: > I knew I re?nvented something. Maybe it was ?map?. Quite. If you really need that one-argument callable, you can curry map() with functools.partial. Also, that tr?ma is highly unorthodox. -- Thomas Jollans From dvl at psu.edu Mon Nov 6 10:37:17 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Mon, 6 Nov 2017 10:37:17 -0500 Subject: replacing 'else' with 'then' in 'for' and 'try' In-Reply-To: mailman.23.1509901204.9896.python-list@python.org References: Message-ID: <1509982637l.32964774l.0l@psu.edu> Just a little two-cent opinion from the peanut gallery: I've been following all the discussion on this go by, sometimes getting a bit heated at times, and just sitting nice and safe and secure in my little ivory tower, where I simply tell my students to not use 'break'. As a stodgy educator, I usually restrict them for these two reasons: 1) the loop condition should describe your expected loop conditions, and 2) the exception handling structure allows more control over where the exceptional circumstances will be handled (including which function) When it comes to searching an iterable collection, my ivory-tower view point tells me that the looping condition is based on whether the item is found, and is not a for loop traversing the entirety. To me, that is the 'one obvious way to do it' If I expect the item will be found, but fear that it will not, I can always compare a subscript to len(), or if that seems too hard, catch the StopIteration exception. I only recommend the for loop when the true expectation is to visit the entire collection (which can later be moderated with iter's sentinel parameter, or some of the filters in itertools) And I see that simply removing 'break' from my vocabulary, this whole 'else on a loop' issue completely dissolves. So thank you for, even unintentionally, helping me to feel good about living inside my ivory tower! Roger Christman Pennsylvania State University From saxri89 at gmail.com Mon Nov 6 10:43:17 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Mon, 6 Nov 2017 07:43:17 -0800 (PST) Subject: DJANGO app loose path from batch file Message-ID: I try to learn more about Django celery and rabbitmq to create some async tasks and I have some question. Some programs can provide PYTHON API to can some development to use modules from this program in python. one most way to take that PYTHON API from this program is to use batch file like this : @echo off SET PROGRAM_ROOT=C:\main-folder call "%PROGRAM_ROOT%"\bin\some-batch-file.bat SET PYCHARM="C:\Program Files\JetBrains\PyCharm 2017.1.5\bin\pycharm64.exe" set PYTHONPATH=%PYTHONPATH%;%PROGRAM_ROOT%\python; set PYTHONPATH=%PYTHONPATH%;%PROGRAM_ROOT%\site-packages; start "PyCharm aware of PROGRAM" /B %PYCHARM% %* if I run this batch file can I use all imports and modules from this program. that to release if add celery in my app and broker url rabbitmq server then if i use some module or some import from this python api then I take error message : no module name some_module_from_program (for all other modules celery and rabbitmq app work fine). that mean in celery and rabbitmq server loose that paths from batch file and I take this error. my question how to can define rabbitmq server to start server with that paths like batch file before to avoid this error? From random832 at fastmail.com Mon Nov 6 11:49:39 2017 From: random832 at fastmail.com (Random832) Date: Mon, 06 Nov 2017 11:49:39 -0500 Subject: replacing `else` with `then` in `for` and `try` In-Reply-To: <1509570761.4585.0@smtp.gmail.com> References: <1509570761.4585.0@smtp.gmail.com> Message-ID: <1509986979.1202995.1163341984.62913D45@webmail.messagingengine.com> I haven't read over every message in the thread, so sorry if this has been suggested before, but how about "if not break:" and "if not except:" as synonyms for the current 'else' clause? They're already keywords, and this sequence of keywords has no current meaning. From pkpearson at nowhere.invalid Mon Nov 6 12:53:59 2017 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 6 Nov 2017 17:53:59 GMT Subject: Python Mailing list moderators References: <20171105211437.GA94644@cskk.homeip.net> Message-ID: On Sun, 5 Nov 2017 17:28:05 -0500, Terry Reedy wrote: > On 11/5/2017 4:14 PM, Cameron Simpson wrote: >> On 05Nov2017 13:09, ???????? ????????? >> wrote: >>> Folks, >>> More and more nonsense are coming in and I find it really difficult to >>> follow any new post that may come and I have to either search for >>> specific content or scroll down until I hit it by accident. >>> >>> Can we do something about it? >>> It's getting really frustrating :/ >> >> It seems from the headers on your message that you're actually using the >> comp.lang.python newsgroup and not the mailing list. The newsgroup is >> completed unmoderated.? The mailing list is far less noisy. >> >> Go here: >> >> ?https://mail.python.org/mailman/listinfo/python-list >> >> and subscribe, and see if things seem better than the newsgroup. > Or point your newsreader to news.gmane.org group > gmane.comp.python.general, which mirrors python-list. [snip] Or use a newsgroup reader that can be easily taught to ignore certain subjects or posters. Or buy your newsgroup service from a provider that does some filtering. I use slrn to read news from news.individual.net, and see only a handful of spam posts on a typical day. -- To email me, substitute nowhere->runbox, invalid->com. From skip.montanaro at gmail.com Mon Nov 6 17:40:09 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 6 Nov 2017 16:40:09 -0600 Subject: Incomplete description using sqlite3 Message-ID: I'm using sqlite3 (2.6.0, SQLite version 3.13.0, Python 2.7.13) and was hoping to introspect the types of a table using the cursor's description attribute. PEP 249 states: "The first two items (name and type_code) are mandatory..." I tried this query: conn = sqlite3("/some/existing/database") curs = conn.cursor() curs.execute("select * from mytable limit 1") curs.fetchall() Looking at curs.description, I see that it contained a seven-element tuple for each column, but only the first element (name) was non-None. Even the type_code field (required, according to the PEP) was None. I tried the same trick using pyodbc talking to SQL Server (select top(1) * from mytable). It returned more useful information. Did I go about things wrong with SQLite, or is the sqlite3 module (or SQLite database underlying it) not capable enough? Thx, Skip From johnpote at jptechnical.co.uk Mon Nov 6 18:43:27 2017 From: johnpote at jptechnical.co.uk (John Pote) Date: Mon, 6 Nov 2017 23:43:27 +0000 Subject: Easiest way to access C module in Python Message-ID: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> Hi all, I have successfully used Python to perform unit and integration tests in the past and I'd like to do the same for some C modules I'm working with at work. There seem to be a number of ways of doing this but being busy at work and home I looking for the approach with the least learning curve. I don't want to add the C modules into the CPython build itself as I've never done this and at work it's a real pain getting admin rights to do this, and when you do it lasts just 24 hours. The C modules are likely to change frequently as bugs are found and features added. The other option I'm considering is to use sockets and write a C wrapper round the C modules I want to test. This has the advantage for me that I know about sockets from Python & C points of view and I get complete control of the C compile process. This may be important as the C modules come from an embedded project and I don't want to change them in any way. Are there any other approachs to this problem? I'll be using Python 3.5 (work) and 3.6 (home). Feedback appriciated. From BILL_NOSPAM at Noway.net Mon Nov 6 19:57:50 2017 From: BILL_NOSPAM at Noway.net (Bill) Date: Mon, 6 Nov 2017 19:57:50 -0500 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> Message-ID: John Pote wrote: > Hi all, > I have successfully used Python to perform unit and integration tests > in the past and I'd like to do the same for some C modules I'm working > with at work. There seem to be a number of ways of doing this but > being busy at work and home I looking for the approach with the least > learning curve. > > I don't want to add the C modules into the CPython build itself as > I've never done this and at work it's a real pain getting admin rights > to do this, and when you do it lasts just 24 hours. The C modules are > likely to change frequently as bugs are found and features added. > > The other option I'm considering is to use sockets and write a C > wrapper round the C modules I want to test. This has the advantage for > me that I know about sockets from Python & C points of view and I get > complete control of the C compile process. This may be important as > the C modules come from an embedded project and I don't want to change > them in any way. > > Are there any other approachs to this problem? > I'll be using Python 3.5 (work) and 3.6 (home). > Feedback appriciated. Install Oracle's "Virtual Box" software on your computer. It's free. Then install a version of Linux on it (or something else, if you prefer). Whatever you do, if you don't like it, you can replace your installation in a matter of minutes. From rosuav at gmail.com Mon Nov 6 19:58:42 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Nov 2017 11:58:42 +1100 Subject: Easiest way to access C module in Python In-Reply-To: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> Message-ID: On Tue, Nov 7, 2017 at 10:43 AM, John Pote wrote: > Hi all, > I have successfully used Python to perform unit and integration tests in the > past and I'd like to do the same for some C modules I'm working with at > work. There seem to be a number of ways of doing this but being busy at work > and home I looking for the approach with the least learning curve. > > I don't want to add the C modules into the CPython build itself as I've > never done this and at work it's a real pain getting admin rights to do > this, and when you do it lasts just 24 hours. The C modules are likely to > change frequently as bugs are found and features added. Fortunately, you don't have to modify CPython to do this :) > The other option I'm considering is to use sockets and write a C wrapper > round the C modules I want to test. This has the advantage for me that I > know about sockets from Python & C points of view and I get complete control > of the C compile process. This may be important as the C modules come from > an embedded project and I don't want to change them in any way. > > Are there any other approachs to this problem? > I'll be using Python 3.5 (work) and 3.6 (home). > Feedback appriciated. This. The best way to do this is to create a wrapper... but the best way to create that wrapper is with Cython. (Not to be confused with CPython.) Check out http://cython.org/ to see what it takes to carry information into and out of the C module. You'd compile the Cython wrapper and then import that from Python directly. ChrisA From bc at freeuk.com Mon Nov 6 20:52:37 2017 From: bc at freeuk.com (bartc) Date: Tue, 7 Nov 2017 01:52:37 +0000 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> Message-ID: On 07/11/2017 00:58, Chris Angelico wrote: > On Tue, Nov 7, 2017 at 10:43 AM, John Pote wrote: >> Hi all, >> I have successfully used Python to perform unit and integration tests in the >> past and I'd like to do the same for some C modules I'm working with at >> work. There seem to be a number of ways of doing this but being busy at work >> and home I looking for the approach with the least learning curve. >> >> I don't want to add the C modules into the CPython build itself as I've >> never done this and at work it's a real pain getting admin rights to do >> this, and when you do it lasts just 24 hours. The C modules are likely to >> change frequently as bugs are found and features added. > > Fortunately, you don't have to modify CPython to do this :) > >> The other option I'm considering is to use sockets and write a C wrapper >> round the C modules I want to test. This has the advantage for me that I >> know about sockets from Python & C points of view and I get complete control >> of the C compile process. This may be important as the C modules come from >> an embedded project and I don't want to change them in any way. >> >> Are there any other approachs to this problem? >> I'll be using Python 3.5 (work) and 3.6 (home). >> Feedback appriciated. > > This. The best way to do this is to create a wrapper... but the best > way to create that wrapper is with Cython. (Not to be confused with > CPython.) Check out http://cython.org/ to see what it takes to carry > information into and out of the C module. You'd compile the Cython > wrapper and then import that from Python directly. Cython seems very confusing to me. The simplest way for Python to run C is for Python to just run the executable created using C. If that is possible. Otherwise what /I/ would look for is ways to call C functions inside shared libraries (.dll and .so). That requires that the modules under test be wrapped as a shared library, which may be extra effort (but it will still be using C, so with familiar tools and no crossover with Python at this point). To call shared library C functions from Python I think involves the ctypes module (I've never done it). Googling 'ctypes shared library' gives some promising results. -- bartc From grant.b.edwards at gmail.com Mon Nov 6 20:59:34 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 7 Nov 2017 01:59:34 +0000 (UTC) Subject: Easiest way to access C module in Python References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> Message-ID: On 2017-11-06, John Pote wrote: > I have successfully used Python to perform unit and integration tests in > the past and I'd like to do the same for some C modules I'm working with > at work. There seem to be a number of ways of doing this but being busy > at work and home I looking for the approach with the least learning curve. When I want to test C modules (usually destined for an embedded system) using a Python framework, I use ctypes. https://docs.python.org/3/library/ctypes.html -- Grant From rosuav at gmail.com Mon Nov 6 21:23:41 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Nov 2017 13:23:41 +1100 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> Message-ID: On Tue, Nov 7, 2017 at 12:52 PM, bartc wrote: > On 07/11/2017 00:58, Chris Angelico wrote: >> >> On Tue, Nov 7, 2017 at 10:43 AM, John Pote >> wrote: >>> >>> Hi all, >>> I have successfully used Python to perform unit and integration tests in >>> the >>> past and I'd like to do the same for some C modules I'm working with at >>> work. There seem to be a number of ways of doing this but being busy at >>> work >>> and home I looking for the approach with the least learning curve. >>> >>> I don't want to add the C modules into the CPython build itself as I've >>> never done this and at work it's a real pain getting admin rights to do >>> this, and when you do it lasts just 24 hours. The C modules are likely to >>> change frequently as bugs are found and features added. >> >> >> Fortunately, you don't have to modify CPython to do this :) >> >>> The other option I'm considering is to use sockets and write a C wrapper >>> round the C modules I want to test. This has the advantage for me that I >>> know about sockets from Python & C points of view and I get complete >>> control >>> of the C compile process. This may be important as the C modules come >>> from >>> an embedded project and I don't want to change them in any way. >>> >>> Are there any other approachs to this problem? >>> I'll be using Python 3.5 (work) and 3.6 (home). >>> Feedback appriciated. >> >> >> This. The best way to do this is to create a wrapper... but the best >> way to create that wrapper is with Cython. (Not to be confused with >> CPython.) Check out http://cython.org/ to see what it takes to carry >> information into and out of the C module. You'd compile the Cython >> wrapper and then import that from Python directly. > > > Cython seems very confusing to me. > > The simplest way for Python to run C is for Python to just run the > executable created using C. If that is possible. > > Otherwise what /I/ would look for is ways to call C functions inside shared > libraries (.dll and .so). That requires that the modules under test be > wrapped as a shared library, which may be extra effort (but it will still be > using C, so with familiar tools and no crossover with Python at this point). > > To call shared library C functions from Python I think involves the ctypes > module (I've never done it). Googling 'ctypes shared library' gives some > promising results. The point of Cython is to make this easier. It's worth learning. ChrisA From auriocus at gmx.de Tue Nov 7 01:46:58 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 7 Nov 2017 07:46:58 +0100 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> Message-ID: Am 07.11.17 um 02:59 schrieb Grant Edwards: > On 2017-11-06, John Pote wrote: > >> I have successfully used Python to perform unit and integration tests in >> the past and I'd like to do the same for some C modules I'm working with >> at work. There seem to be a number of ways of doing this but being busy >> at work and home I looking for the approach with the least learning curve. > > When I want to test C modules (usually destined for an embedded > system) using a Python framework, I use ctypes. > > https://docs.python.org/3/library/ctypes.html > Another possibility is SWIG http://www.swig.org/ When you already have a C header file, SWIG creates a Python module out of it. In many cases this is sufficient to get a runnable interface, but sometimes you need to add additional functions (like initialisation functions) to your module to make it usable from Python. Christian From tysondogerz at gmail.com Tue Nov 7 02:18:18 2017 From: tysondogerz at gmail.com (tysondogerz at gmail.com) Date: Mon, 6 Nov 2017 23:18:18 -0800 (PST) Subject: I am trying to delete duplicates but the job just finishes with an exit code 0 Message-ID: <8df60dd2-e898-4fc6-8bae-53074668035a@googlegroups.com> I am trying to delete duplicates but the job just finishes with an exit code 0 and does not delete any duplicates. The duplicates for the data always exist in Column F and I am desiring to delete the entire row B-I Any ideas? import openpyxl wb1 = openpyxl.load_workbook('C:/dwad/SWWA.xlsx') ws1 = wb1.active # keep naming convention consistent values = [] for i in range(2,ws1.max_row+1): if ws1.cell(row=i,column=1).value in values: #pass #else: values.append(ws1.cell(row=i,column=1).value) for value in values: ws1.append([value]) I have attempted to do this with openpyxl for an excel as well as other methods (including csv though this deleted rows excessively). CSV: with open('1.csv','r') as in_file, open('2.csv','w') as out_file: seen = set() # set for fast O(1) amortized lookup for line in in_file: if line not in seen: seen.add(line) out_file.write(line) From durumdara at gmail.com Tue Nov 7 02:58:27 2017 From: durumdara at gmail.com (Durumdara) Date: Tue, 7 Nov 2017 08:58:27 +0100 Subject: Calling of GetVolumeInformation returns empty serial number Message-ID: Hi! Windows 10, Python 3.6. I want to get the serial number of the drives (without external modules like Win32 or WMI). It is needed for identification of removable devices (like USB external drives). Somewhere I saw this code: def GetVolumeID(Drive): import ctypes kernel32 = ctypes.windll.kernel32 volumeNameBuffer = ctypes.create_unicode_buffer(1024) fileSystemNameBuffer = ctypes.create_unicode_buffer(1024) serial_number = None max_component_length = None file_system_flags = None rc = kernel32.GetVolumeInformationW( ctypes.c_wchar_p(Drive), volumeNameBuffer, ctypes.sizeof(volumeNameBuffer), serial_number, max_component_length, file_system_flags, fileSystemNameBuffer, ctypes.sizeof(fileSystemNameBuffer) ) return serial_number; print(GetVolumeID('c:\\')) This function is working with other values (volumeNameBuffer), but for serial it returns None. The serial number is empty. How to I pass this parameter to I get the value? The doc said it's LPDWORD (pointer to DWORD): https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx _Out_opt_ LPDWORD lpVolumeSerialNumber, Thank you for any advance in this theme! Best wishes dd From tjol at tjol.eu Tue Nov 7 05:36:00 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 7 Nov 2017 11:36:00 +0100 Subject: Calling of GetVolumeInformation returns empty serial number In-Reply-To: References: Message-ID: On 2017-11-07 08:58, Durumdara wrote: > Hi! > > Windows 10, Python 3.6. > > I want to get the serial number of the drives (without external modules > like Win32 or WMI). > It is needed for identification of removable devices (like USB external > drives). > > Somewhere I saw this code: > > def GetVolumeID(Drive): > import ctypes > kernel32 = ctypes.windll.kernel32 > volumeNameBuffer = ctypes.create_unicode_buffer(1024) > fileSystemNameBuffer = ctypes.create_unicode_buffer(1024) > serial_number = None > max_component_length = None > file_system_flags = None > > rc = kernel32.GetVolumeInformationW( > ctypes.c_wchar_p(Drive), > volumeNameBuffer, > ctypes.sizeof(volumeNameBuffer), > serial_number, > max_component_length, > file_system_flags, > fileSystemNameBuffer, > ctypes.sizeof(fileSystemNameBuffer) > ) > return serial_number; > > print(GetVolumeID('c:\\')) > > > This function is working with other values (volumeNameBuffer), but for > serial it returns None. > The serial number is empty. > How to I pass this parameter to I get the value? Do you get a value for max_component_length? (I wouldn't expect so, but that is what you imply). Anyway, the ctypes docs are pretty clear: https://docs.python.org/3/library/ctypes.html#passing-pointers-or-passing-parameters-by-reference > > The doc said it's LPDWORD (pointer to DWORD): > > https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx > > _Out_opt_ LPDWORD lpVolumeSerialNumber, > > > Thank you for any advance in this theme! > > Best wishes > dd > -- Thomas Jollans From fabiofz at gmail.com Tue Nov 7 06:02:03 2017 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 7 Nov 2017 09:02:03 -0200 Subject: PyDev 6.1.0 Released Message-ID: PyDev 6.1.0 Release Highlights - *Important* PyDev now requires Java 8 and Eclipse 4.6 (Neon) onwards. - PyDev 5.2.0 is the last release supporting Eclipse 4.5 (Mars). - *Code Formatter* - The PyDev code formatter can now add/remove blank lines to comply with pep-8. - Added preference to skip blank lines formatting. - *Editor* - Editor now tolerant against errors in the definitions of style ranges. - When in link mode (after a code completion with params for instance), properly skip closing parenthesis if already well balanced. - Fix logic error in editor preferences for disabling subword navigation (patch by *Stuart Berg*). - *Others* - Using *python -m 'pip'* when unable to find pip executable in interpreter preferences (*#PyDev-853*). - PyDev set next statement action set no longer disables Debug action set (*#PyDev-859*). - It's possible to silence question about saving resources before a refactoring operation. - Add problem markers for python files that declare invalid encodings (patch by *Mat Booth*). - Other minor bugfixes. What is PyDev? PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com What is LiClipse? LiClipse is a PyDev standalone with goodies such as support for Multiple cursors, theming, TextMate bundles and a number of other languages such as Django Templates, Jinja2, Kivy Language, Mako Templates, Html, Javascript, etc. It's also a commercial counterpart which helps supporting the development of PyDev. Details on LiClipse: http://www.liclipse.com/ Cheers, -- Fabio Zadrozny ------------------------------ Software Developer LiClipse http://www.liclipse.com PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com PyVmMonitor - Python Profiler http://www.pyvmmonitor.com/ From bc at freeuk.com Tue Nov 7 06:06:44 2017 From: bc at freeuk.com (bartc) Date: Tue, 7 Nov 2017 11:06:44 +0000 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> Message-ID: On 07/11/2017 02:23, Chris Angelico wrote: > On Tue, Nov 7, 2017 at 12:52 PM, bartc wrote: >> Cython seems very confusing to me. > > >> Otherwise what /I/ would look for is ways to call C functions inside shared >> libraries (.dll and .so). That requires that the modules under test be >> wrapped as a shared library, which may be extra effort (but it will still be >> using C, so with familiar tools and no crossover with Python at this point). >> >> To call shared library C functions from Python I think involves the ctypes >> module (I've never done it). Googling 'ctypes shared library' gives some >> promising results. > > The point of Cython is to make this easier. It's worth learning. My experience is different. I created a function fred() in a C module, then linked that into a .dll (.so on Linux should be similar). Then I wrote this code, adapted from the first hit I found for 'python ctypes example': import ctypes testlib = ctypes.CDLL('c:/c/c.dll') testlib.fred() And it worked perfectly (on Py2 and Py3). (I understand passing arguments is a bit more complicated, but at least you have a working base.) Then I tried the first example I saw for 'cython examples' which was this, first create a .pyx file as suggested, then: from distutils.core import setup from Cython.Build import cythonize setup(ext_modules=cythonize("helloworld.pyx")) It spend several seconds thinking about it, then I got this enlightening error report: 17.299999999999997 Traceback (most recent call last): File "c:\langs\a.py", line 10, in from distutils.core import setup File "c:\python36\lib\distutils\core.py", line 16, in from distutils.dist import Distribution File "c:\python36\lib\distutils\dist.py", line 10, in from email import message_from_file ImportError: cannot import name 'message_from_file' That was Py3; on Py2, I had 30 seconds of disk activity, and nearly full memory that almost stalled my machine before I aborted it. (Actually I mispelled both 'cythonize's in the example; it didn't make any difference). And I still have no idea how to relate this to calling a native C function in an external shared library. -- bartc From rosuav at gmail.com Tue Nov 7 06:16:46 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Nov 2017 22:16:46 +1100 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> Message-ID: On Tue, Nov 7, 2017 at 10:06 PM, bartc wrote: > On 07/11/2017 02:23, Chris Angelico wrote: >> >> On Tue, Nov 7, 2017 at 12:52 PM, bartc wrote: > > >>> Cython seems very confusing to me. >> >> > >> >>> Otherwise what /I/ would look for is ways to call C functions inside >>> shared >>> libraries (.dll and .so). That requires that the modules under test be >>> wrapped as a shared library, which may be extra effort (but it will still >>> be >>> using C, so with familiar tools and no crossover with Python at this >>> point). >>> >>> To call shared library C functions from Python I think involves the >>> ctypes >>> module (I've never done it). Googling 'ctypes shared library' gives some >>> promising results. >> >> >> The point of Cython is to make this easier. It's worth learning. > > > My experience is different. Thanks for the FUD. I love it when someone, on the basis of one failed experiment, trash-talks an excellent piece of software that would solve the OP's problem. ChrisA From bc at freeuk.com Tue Nov 7 06:27:53 2017 From: bc at freeuk.com (bartc) Date: Tue, 7 Nov 2017 11:27:53 +0000 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> Message-ID: On 07/11/2017 11:16, Chris Angelico wrote: > On Tue, Nov 7, 2017 at 10:06 PM, bartc wrote: >> My experience is different. > > Thanks for the FUD. I love it when someone, on the basis of one failed > experiment, trash-talks an excellent piece of software that would > solve the OP's problem. OK, I gave a working example that called an actual C function. Perhaps you can give one based on Cython that does the same thing. From p.f.moore at gmail.com Tue Nov 7 06:35:48 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 7 Nov 2017 11:35:48 +0000 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> Message-ID: On 7 November 2017 at 11:16, Chris Angelico wrote: > Thanks for the FUD. I love it when someone, on the basis of one failed > experiment, trash-talks an excellent piece of software that would > solve the OP's problem. It *is* true that the learning curve for Cython is steeper than that of ctypes. But for anything more complex than simple "call a function with no arguments", ctypes rapidly gets fairly complex and messy - and the docs are not exactly the best. At that point, investing the time in learning how to use Cython definitely pays off. Another option for the OP is cffi, which might offer a middle ground (in terms of complexity vs power - it's hard to objectively assess "complexity" without knowing the audience's background). Paul From bc at freeuk.com Tue Nov 7 06:53:44 2017 From: bc at freeuk.com (bartc) Date: Tue, 7 Nov 2017 11:53:44 +0000 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> Message-ID: On 07/11/2017 11:35, Paul Moore wrote: > On 7 November 2017 at 11:16, Chris Angelico wrote: >> Thanks for the FUD. I love it when someone, on the basis of one failed >> experiment, trash-talks an excellent piece of software that would >> solve the OP's problem. > > It *is* true that the learning curve for Cython is steeper than that > of ctypes. But for anything more complex than simple "call a function > with no arguments", ctypes rapidly gets fairly complex and messy - and > the docs are not exactly the best. At that point, investing the time > in learning how to use Cython definitely pays off. But just staying with the "function with no arguments" for the minute (the equivalent of Hello World for this exercise), how would it be done in Cython? Would a working example be simple enough to show in a usenet post? > Another option for the OP is cffi, And perhaps another example here. (cffi doesn't seem to be part of any of my pythons, so that would be an obstacle for me as installing extra stuff rarely seems to work. Having said that, I located pip.exe, trying typing 'pip install cffi' and it seemed to be doing something but then failed with a bunch of errors.) -- bartc From eryksun at gmail.com Tue Nov 7 07:10:37 2017 From: eryksun at gmail.com (eryk sun) Date: Tue, 7 Nov 2017 12:10:37 +0000 Subject: Calling of GetVolumeInformation returns empty serial number In-Reply-To: References: Message-ID: On Tue, Nov 7, 2017 at 7:58 AM, Durumdara wrote: > > I want to get the serial number of the drives (without external modules > like Win32 or WMI). The volume serial number is more easily available as os.stat(drive).st_dev, which comes from calling GetFileInformationByHandle. Note that despite using the volume serial number (VSN) as the nearest equivalent of POSIX st_dev, there is no requirement that the VSN is unique or even non-zero. The same applies to the file index number that's used for POSIX st_ino. For example, both values are 0 on a WebDav drive, for which Python's implementation of os.path.samefile is useless. Practically speaking, however, it's good enough in most cases, especially for mounted disk volumes. That said, maybe what you really want is the hardware (disk) serial number -- not a volume serial number. The easiest way to get that is via WMI. You can use subprocess to run wmic.exe if you don't want an external dependency. You can also get the disk serial number by calling DeviceIoControl via ctypes. This is a fairly complex IOCTL_STORAGE_QUERY_PROPERTY request, with an input STORAGE_PROPERTY_QUERY structure requesting the StorageDeviceProperty. The result is a STORAGE_DEVICE_DESCRIPTOR structure that has a SerialNumberOffset field that's the byte offset from the beginning of the buffer of the serial number as a null-terminated string. Getting back to the VSN, note that the mount-point manager doesn't rely on it as a unique identifier. For associating volume devices with logical DOS drives and volume GUID names (i.e. names like "Volume{12345678-0000-0000-0000-123456789abc}", which are used to mount volumes as NTFS junctions), the mount-point manager queries a unique ID via IOCTL_MOUNTDEV_QUERY_UNIQUE_ID. Sometimes the volume driver returns a unique ID that's very long -- over 200 bytes. This doesn't matter because it's only used to uniquely associate a GUID name (and maybe a DOS drive) with the given volume when the system boots. This association is persisted in HKLM\System\MountedDevices. From lele at metapensiero.it Tue Nov 7 07:14:54 2017 From: lele at metapensiero.it (Lele Gaifax) Date: Tue, 07 Nov 2017 13:14:54 +0100 Subject: Easiest way to access C module in Python References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> Message-ID: <87375q8ev5.fsf@metapensiero.it> bartc writes: > But just staying with the "function with no arguments" for the minute (the > equivalent of Hello World for this exercise), how would it be done in > Cython? Would a working example be simple enough to show in a usenet post? fred.c:: int fred(void) { return 42; } life.pyx:: cdef extern: int fred() def life(): return fred() setup.py:: from distutils.core import setup from distutils.extension import Extension from Cython.Build import cythonize setup( ext_modules = cythonize([Extension("life", ["life.pyx", "fred.c"])]) ) $ python setup.py build_ext --inplace Compiling life.pyx because it changed. [1/1] Cythonizing life.pyx running build_ext building 'life' extension creating build creating build/temp.linux-x86_64-3.6 x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-5reRaQ/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/tmp/ct/include -I/usr/include/python3.6m -c life.c -o build/temp.linux-x86_64-3.6/life.o x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-5reRaQ/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/tmp/ct/include -I/usr/include/python3.6m -c fred.c -o build/temp.linux-x86_64-3.6/fred.o x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -g -fdebug-prefix-map=/build/python3.6-5reRaQ/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.6/life.o build/temp.linux-x86_64-3.6/fred.o -o /tmp/ct/life.cpython-36m-x86_64-linux-gnu.so $ python -c "import life; print(life.life())" 42 As other said, for a single function accepting no arguments and returning a single value Cython may be an heavy tool, but I bet you can imagine more complex situations... ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From bc at freeuk.com Tue Nov 7 08:11:40 2017 From: bc at freeuk.com (bartc) Date: Tue, 7 Nov 2017 13:11:40 +0000 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> <87375q8ev5.fsf@metapensiero.it> Message-ID: On 07/11/2017 12:14, Lele Gaifax wrote: > bartc writes: > >> But just staying with the "function with no arguments" for the minute (the >> equivalent of Hello World for this exercise), how would it be done in >> Cython? Would a working example be simple enough to show in a usenet post? > > fred.c:: > > int fred(void) { > return 42; > } > > life.pyx:: > > cdef extern: > int fred() > > def life(): > return fred() > > setup.py:: > > from distutils.core import setup > from distutils.extension import Extension > from Cython.Build import cythonize > > setup( > ext_modules = cythonize([Extension("life", ["life.pyx", "fred.c"])]) > ) > > $ python setup.py build_ext --inplace OK, thanks. Although when I get to this bit, my system still says: 17.299999999999997 Traceback (most recent call last): File "setup.py", line 1, in from distutils.core import setup .... So obviously something is wrong with it, but I'll have to assume it normally works. > Compiling life.pyx because it changed. > [1/1] Cythonizing life.pyx > running build_ext > building 'life' extension > creating build > creating build/temp.linux-x86_64-3.6 > x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-5reRaQ/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/tmp/ct/include -I/usr/include/python3.6m -c life.c -o build/temp.linux-x86_64-3.6/life.o However, it doesn't look that simple a process, and it seems to solve a different problem from the ctypes solution. That one took an EXISTING function, already compiled and linked into a binary, and does not need the C source nor need to compile it. Often, you will only have the binary shared library anyway. -I/tmp/ct/include -I/usr/include/python3.6m -c fred.c -o build/temp.linux-x86_64-3.6/fred.o OK, compiling fred.c. Is there a dependency on gcc too? This looks more like makefile hell. People use languages like Python to get away from this stuff. > x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -g -fdebug-prefix-map=/build/python3.6-5reRaQ/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.6/life.o build/temp.linux-x86_64-3.6/fred.o -o /tmp/ct/life.cpython-36m-x86_64-linux-gnu.so > $ python -c "import life; print(life.life())" > 42 > > As other said, for a single function accepting no arguments and returning a > single value Cython may be an heavy tool, but I bet you can imagine more > complex situations... In my normal work, I'm calling C functions from interpreted code all the time, just not in Python (example below sig). It's not that complicated. With this Cython solution you have the .c (which has to be compiled and linked using this process), you have .pyx, whatever that is, you have .py which is not really Python, but has to be processed as Cython, and then you have .py which is actual Python, which is the code that wanted to call that C function in the first. So simple. I understand that Cython lets you write Python-like code with special annotations that allows it to be compiled to efficient native code (or something like that), but that's not what this task is, which is 100% Python calling 100% C, with both developed using their normal tools. -- bartc # in interpreted code, run as normal: importdll jpeg = clang function loadjpeg(string, ref int64, ref int64)ref byte end In C: byte* loadjpeg(char* file, int64* width, int64* height) {... From __peter__ at web.de Tue Nov 7 08:17:53 2017 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Nov 2017 14:17:53 +0100 Subject: I am trying to delete duplicates but the job just finishes with an exit code 0 References: <8df60dd2-e898-4fc6-8bae-53074668035a@googlegroups.com> Message-ID: tysondogerz at gmail.com wrote: > I am trying to delete duplicates but the job just finishes with an exit > code 0 and does not delete any duplicates. > > The duplicates for the data always exist in Column F and I am desiring to > delete the entire row B-I > > Any ideas? > > > import openpyxl > wb1 = openpyxl.load_workbook('C:/dwad/SWWA.xlsx') > ws1 = wb1.active # keep naming convention consistent > > values = [] > for i in range(2,ws1.max_row+1): > if ws1.cell(row=i,column=1).value in values: > #pass > #else: > values.append(ws1.cell(row=i,column=1).value) > > for value in values: > ws1.append([value]) append() will add even more duplicates to the sheet. If you do not care about cell styles you can create a new sheet and copy only unique values. A complete example: import openpyxl SOURCE_FILE = "duplicates.xlsx" DEST_FILE = "unique.xlsx" HEADER_COUNT = 1 KEY_COLUMNS = [1] # zero-based A=0, B=1, ... workbook = openpyxl.load_workbook(SOURCE_FILE) source_sheet = workbook.active dest_sheet = workbook.create_sheet() seen = set() for i, row in enumerate(source_sheet.values): if i < HEADER_COUNT: dest_sheet.append(row) else: key = tuple(row[i] for i in KEY_COLUMNS) print("row = %r, key = %r" %(row, key)) if key not in seen: print("adding row", row) seen.add(key) dest_sheet.append(row) workbook.save(DEST_FILE) > I have attempted to do this with openpyxl for an excel as well as other > methods (including csv though this deleted rows excessively). I find that hard to believe. If anything it should keep more rows as you compare whole lines, not just the columns you are interested in. > CSV: > with open('1.csv','r') as in_file, open('2.csv','w') as out_file: > seen = set() # set for fast O(1) amortized lookup > for line in in_file: > if line not in seen: > seen.add(line) > out_file.write(line) General remark: use the csv module in the standard library rather than trying to parse the records manually. From bc at freeuk.com Tue Nov 7 08:21:05 2017 From: bc at freeuk.com (bartc) Date: Tue, 7 Nov 2017 13:21:05 +0000 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> <87375q8ev5.fsf@metapensiero.it> Message-ID: On 07/11/2017 13:11, bartc wrote: >> $ python setup.py build_ext --inplace > > OK, thanks. Although when I get to this bit, my system still says: > > 17.299999999999997 > Traceback (most recent call last): > ? File "setup.py", line 1, in > ??? from distutils.core import setup > ?.... Update: if I copy the relevant files to the actual Python directory (so running Python as 'python' rather than '\python34\python'), the problem seems to be simply: ImportError: No module named 'Cython' (And trying script\pip install cython generated some promising disk activity for about a minute but then loads of errors, although no definitive message about whether it installed Cython or not. But since it still can't import the Cython module, I guess it didn't.) -- bartc From lele at metapensiero.it Tue Nov 7 08:26:39 2017 From: lele at metapensiero.it (Lele Gaifax) Date: Tue, 07 Nov 2017 14:26:39 +0100 Subject: Easiest way to access C module in Python References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> <87375q8ev5.fsf@metapensiero.it> Message-ID: <87y3ni6wz4.fsf@metapensiero.it> bartc writes: > OK, compiling fred.c. Is there a dependency on gcc too? This looks more like > makefile hell. That's pretty standard distutils functionality. I'm pretty sure that on M$Windows it would invoke its C compiler, not gcc. I wrote "fred.c" to get closer to the case you mentioned, but obviously that function can very well come from a library. > People use languages like Python to get away from this stuff. Which people? The OP explicitly asked for a way to access a C module from Python, and Cython surely is one option to accomplish that. ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From tjol at tjol.eu Tue Nov 7 08:30:27 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 7 Nov 2017 14:30:27 +0100 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> Message-ID: <1f7bf4bc-2e24-40bf-8fe4-84b58ac84763@tjol.eu> On 2017-11-07 12:53, bartc wrote: > Having > said that, I located pip.exe, trying typing 'pip install cffi' and it > seemed to be doing something but then failed with a bunch of errors.) So you're missing out on all of PyPI? That's tragic. You should really try to fix that. I'm sure people on this list will be happy to help if you start a new thread with some details of what is happening on your system. -- Thomas Jollans From bc at freeuk.com Tue Nov 7 09:20:40 2017 From: bc at freeuk.com (bartc) Date: Tue, 7 Nov 2017 14:20:40 +0000 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> <1f7bf4bc-2e24-40bf-8fe4-84b58ac84763@tjol.eu> Message-ID: On 07/11/2017 13:30, Thomas Jollans wrote: > On 2017-11-07 12:53, bartc wrote: >> Having >> said that, I located pip.exe, trying typing 'pip install cffi' and it >> seemed to be doing something but then failed with a bunch of errors.) > > So you're missing out on all of PyPI? That's tragic. You should really > try to fix that. I'm sure people on this list will be happy to help if > you start a new thread with some details of what is happening on your > system. You've lost me. I had to look up pyPI and it's something to do with a Package Index. But I don't know how that relates to installing Cython. The problem with pip was in Py3.4. I also have Py3.6, and that didn't have pip at all. Or it is something that itself needs to be installed first? Or is pyPI a new thing that replaces it? I'm not a serious Python user so it's not worth the effort of going around in circles trying to get these things working. I remember how difficult it was to get Numpy going a couple of years back. If it's already built-in, then fine, but if not, forget it. But for me it doesn't matter. -- bartc From mail at timgolden.me.uk Tue Nov 7 09:33:35 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 7 Nov 2017 14:33:35 +0000 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> <1f7bf4bc-2e24-40bf-8fe4-84b58ac84763@tjol.eu> Message-ID: <3ae291b3-221e-d425-7e93-d0635cfc76f6@timgolden.me.uk> On 07/11/2017 14:20, bartc wrote: > On 07/11/2017 13:30, Thomas Jollans wrote: >> On 2017-11-07 12:53, bartc wrote: >>> Having >>> said that, I located pip.exe, trying typing 'pip install cffi' and it >>> seemed to be doing something but then failed with a bunch of errors.) >> >> So you're missing out on all of PyPI? That's tragic. You should really >> try to fix that. I'm sure people on this list will be happy to help if >> you start a new thread with some details of what is happening on your >> system. > > You've lost me. I had to look up pyPI and it's something to do with a > Package Index. But I don't know how that relates to installing Cython. Can I just step in now with my Moderator hat on and ask: please avoid a lengthy "educate Bart C about Python" thread. If anyone wants to take it up with him in private, that's up to you. But please leave it off the list / newsgroup. Thanks TJG From bc at freeuk.com Tue Nov 7 10:10:18 2017 From: bc at freeuk.com (bartc) Date: Tue, 7 Nov 2017 15:10:18 +0000 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> <1f7bf4bc-2e24-40bf-8fe4-84b58ac84763@tjol.eu> <3ae291b3-221e-d425-7e93-d0635cfc76f6@timgolden.me.uk> Message-ID: <91kMB.10583$_I2.1949@fx32.am4> On 07/11/2017 14:33, Tim Golden wrote: > On 07/11/2017 14:20, bartc wrote: >> You've lost me. I had to look up pyPI and it's something to do with a >> Package Index. But I don't know how that relates to installing Cython. > > Can I just step in now with my Moderator hat on and ask: please avoid a > lengthy "educate Bart C about Python" thread. If anyone wants to take it > up with him in private, that's up to you. But please leave it off the > list / newsgroup. Well, that's not going to work because my email is not valid. But I've already said I'm not interested, and this is anyway getting a long way from what the OP is trying to do. I've stated that ctypes is my preferred approach for that. However I doubt I'm the only one having trouble with these peripheral aspects, and a mention of such problems can help others, even if it's for reassurance that the problems are not their fault! (This of course doesn't apply to the expert contributors here.) -- bartc From nomail at com.invalid Tue Nov 7 10:39:56 2017 From: nomail at com.invalid (ast) Date: Tue, 7 Nov 2017 16:39:56 +0100 Subject: What happens to module's variables after a "from module import" ? Message-ID: <5a01d3cd$0$7174$426a74cc@news.free.fr> Hello Here is my module tmp.py: a=0 def test(): global a print(a) a+=1 If I import function "test" from module "tmp" with: >>> from tmp import test it works >>> test() 0 >>> test() 1 But where variable "a" is located ? I can't find it anywhere Regards From p.f.moore at gmail.com Tue Nov 7 10:50:23 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 7 Nov 2017 15:50:23 +0000 Subject: What happens to module's variables after a "from module import" ? In-Reply-To: <5a01d3cd$0$7174$426a74cc@news.free.fr> References: <5a01d3cd$0$7174$426a74cc@news.free.fr> Message-ID: On 7 November 2017 at 15:39, ast wrote: > Hello > > Here is my module tmp.py: > > a=0 > > def test(): > global a > print(a) > a+=1 > > If I import function "test" from module "tmp" with: > >>>> from tmp import test > > > it works > >>>> test() > > 0 >>>> >>>> test() > > 1 > > But where variable "a" is located ? I can't find it anywhere It's in the "tmp" module, where you defined it. But because you didn't ask for a reference to it in your import statement, it's not accessible to you[1]. Do import tmp print(tmp.a) and you can see it. Paul [1] Technically you can find it via the globals of the function test, as test.__globals__['a'], but if you understand how that works, you wouldn't have been asking the question in the first place :-) From nulla.epistola at web.de Tue Nov 7 10:56:14 2017 From: nulla.epistola at web.de (Sibylle Koczian) Date: Tue, 7 Nov 2017 16:56:14 +0100 Subject: Incomplete description using sqlite3 In-Reply-To: References: Message-ID: Am 06.11.2017 um 23:40 schrieb Skip Montanaro: > I'm using sqlite3 (2.6.0, SQLite version 3.13.0, Python 2.7.13) and > was hoping to introspect the types of a table using the cursor's > description attribute. PEP 249 states: "The first two items (name and > type_code) are mandatory..." I tried this query: > > conn = sqlite3("/some/existing/database") > curs = conn.cursor() > curs.execute("select * from mytable limit 1") > curs.fetchall() > > Looking at curs.description, I see that it contained a seven-element > tuple for each column, but only the first element (name) was non-None. > Even the type_code field (required, according to the PEP) was None. I > tried the same trick using pyodbc talking to SQL Server (select top(1) > * from mytable). It returned more useful information. > > Did I go about things wrong with SQLite, or is the sqlite3 module (or > SQLite database underlying it) not capable enough? > > Thx, > > Skip > I'd suspect the explanation is here: https://sqlite.org/datatype3.html HTH Sibylle From nomail at com.invalid Tue Nov 7 10:56:46 2017 From: nomail at com.invalid (ast) Date: Tue, 7 Nov 2017 16:56:46 +0100 Subject: What happens to module's variables after a "from module import" ? In-Reply-To: References: <5a01d3cd$0$7174$426a74cc@news.free.fr> Message-ID: <5a01d7c0$0$7153$426a74cc@news.free.fr> "Paul Moore" a ?crit dans le message de news:mailman.53.1510069830.2819.python-list at python.org... > On 7 November 2017 at 15:39, ast wrote: > > It's in the "tmp" module, where you defined it. But because you didn't > ask for a reference to it in your import statement, it's not > accessible to you[1]. > Do > > import tmp > print(tmp.a) > > and you can see it. > > Paul > > [1] Technically you can find it via the globals of the function test, > as test.__globals__['a'], but if you understand how that works, you > wouldn't have been asking the question in the first place :-) Clear, ty From __peter__ at web.de Tue Nov 7 10:57:09 2017 From: __peter__ at web.de (Peter Otten) Date: Tue, 07 Nov 2017 16:57:09 +0100 Subject: What happens to module's variables after a "from module import" ? References: <5a01d3cd$0$7174$426a74cc@news.free.fr> Message-ID: ast wrote: > Hello > > Here is my module tmp.py: > > a=0 > > def test(): > global a > print(a) > a+=1 > > If I import function "test" from module "tmp" with: > >>>> from tmp import test > > it works > >>>> test() > 0 >>>> test() > 1 > > But where variable "a" is located ? I can't find it anywhere The function keeps a reference to the global namespace of the tmp module. >>> from tmp import test >>> test.__globals__["a"] 0 >>> test() 0 >>> test.__globals__["a"] 1 The module is cached; thus a subsequent import gives the same function and of course accesses the same global namespace: >>> from tmp import test as test2 >>> test is test2 True >>> test2() 1 When you remove the module from the cache (usually a bad idea, done here for demonstration purposes) you will get a new function and a new global namespace: >>> import sys >>> del sys.modules["tmp"] >>> from tmp import test as test3 >>> test is test3 False >>> test() 2 >>> test3() 0 From ian.g.kelly at gmail.com Tue Nov 7 12:10:32 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 7 Nov 2017 10:10:32 -0700 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) In-Reply-To: <85375u1taz.fsf_-_@benfinney.id.au> References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On Fri, Nov 3, 2017 at 11:55 PM, Ben Finney wrote: > Ian Kelly writes: > >> Please stop defending the use of incivility on this list. > > Please stop conflating people, who deserve civility, with ideas. We must > not allow the civility deserved by people, to prevent us from > criticising any ideas ? especially not ideas about the behaviour of > software. No, I won't. I once believed this, too. I used it as a defense for criticism of religious ideas. "Oh, I'm not attacking the believers in religion. I'm attacking the *ideas* of religion." And I meant it, too: I wasn't *trying* to insult anybody when I would say that religious belief was foolish and ignorant. Nowadays I realize and accept that this is preposterous. You cannot criticize an idea without also criticizing the people who are attached to that idea. Even if no personal slight is intended, it is received that way. If your idea is bad, then by implication you are a person with bad ideas. Now, I'm not saying that we can't criticize ideas. We can, however, choose to be polite or not in how we go about it. From ian.g.kelly at gmail.com Tue Nov 7 12:28:49 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 7 Nov 2017 10:28:49 -0700 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On Sat, Nov 4, 2017 at 6:40 AM, Chris Angelico wrote: > On Sat, Nov 4, 2017 at 11:25 PM, Jon Ribbens wrote: >> On 2017-11-04, Ben Finney wrote: >>> To respond to the criticism of an idea ? criticism containing no mention >>> of the person ? as though it ?clearly refers to the [person]?, is of >>> significant concern on a software dicussion forum such as this. >> >> No, the thing that is "of significant conern on a software discussion >> forum such as this" is people such as yourself defending the abuse of >> other contributors. > > Maybe we're not defending the abuse of other contributors. Maybe we're > defending a legitimate, if somewhat caustic, response to a ridiculous > suggestion. I don't think it was a ridiculous suggestion. Assigment to False is a syntax error, even though it's lexically valid and was accepted in the past. Inconsistent indentation is a syntax error, even though it could be parsed and has been in the past. Wildcard imports inside a function are a syntax error, even though it's lexically valid and mostly harmless. Using "yield from" inside an async coroutine is a syntax error, even though it's lexically valid and "await" and "yield from" are nearly identical. I haven't seen any argument against making "else" without "break" a syntax error that wouldn't also apply to the above, with the exception of Steve's manufactured interactive example ("manufactured" because who really uses for-else interactively? If I really care that much about output formatting I'm going to put it in a script). If there is any extant code that would actually be broken by this, it's very likely buggy. From rgaddi at highlandtechnology.invalid Tue Nov 7 12:52:02 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Tue, 7 Nov 2017 09:52:02 -0800 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> Message-ID: On 11/06/2017 05:59 PM, Grant Edwards wrote: > On 2017-11-06, John Pote wrote: > >> I have successfully used Python to perform unit and integration tests in >> the past and I'd like to do the same for some C modules I'm working with >> at work. There seem to be a number of ways of doing this but being busy >> at work and home I looking for the approach with the least learning curve. > > When I want to test C modules (usually destined for an embedded > system) using a Python framework, I use ctypes. > > https://docs.python.org/3/library/ctypes.html > I'll second ctypes. It's pretty straightforward and I've made it do some very heavy lifting over the years. Cython is definitely more work. SWIG makes sense if you've got a huge number of interfaces you're trying to map and need to automate the process, but if you've got south of 20 I'd just do it natively with ctypes. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From gisle.vanem at gmail.com Tue Nov 7 13:38:07 2017 From: gisle.vanem at gmail.com (Gisle Vanem) Date: Tue, 7 Nov 2017 19:38:07 +0100 Subject: Easiest way to access C module in Python In-Reply-To: <87375q8ev5.fsf@metapensiero.it> References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> <87375q8ev5.fsf@metapensiero.it> Message-ID: <097b1ad8-6c84-f2ba-604f-0e8a4985123b@gmail.com> Lele Gaifax wrote: > $ python setup.py build_ext --inplace > Compiling life.pyx because it changed. > [1/1] Cythonizing life.pyx > running build_ext > building 'life' extension > creating build > creating build/temp.linux-x86_64-3.6 > x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-5reRaQ/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/tmp/ct/include -I/usr/include/python3.6m -c life.c -o build/temp.linux-x86_64-3.6/life.o > x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-5reRaQ/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/tmp/ct/include -I/usr/include/python3.6m -c fred.c -o build/temp.linux-x86_64-3.6/fred.o > x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -g -fdebug-prefix-map=/build/python3.6-5reRaQ/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.6/life.o build/temp.linux-x86_64-3.6/fred.o -o /tmp/ct/life.cpython-36m-x86_64-linux-gnu.so > $ python -c "import life; print(life.life())" > 42 I tried your example on Python 2.7 (Win-10 / MSVC), but failed: python.exe setup.py build_ext --inplace running build_ext building 'life' extension creating build creating build\temp.win32-2.7 creating build\temp.win32-2.7\Release f:\gv\VC_2017\VC\Tools\MSVC\14.11.25503\bin\HostX86\x86\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -If:\ProgramFiler\Python27\include -If:\ProgramFiler\Python27\PC /Tclife.c /Fobuild\temp.win32-2.7\Release\life.obj life.c f:\gv\VC_2017\VC\Tools\MSVC\14.11.25503\bin\HostX86\x86\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -If:\ProgramFiler\Python27\include -If:\ProgramFiler\Python27\PC /Tcfred.c /Fobuild\temp.win32-2.7\Release\fred.obj fred.c f:\gv\VC_2017\VC\Tools\MSVC\14.11.25503\bin\HostX86\x86\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:f:\ProgramFiler\Python27\libs /LIBPATH:f:\ProgramFiler\Python27\PCbuild /EXPORT:initlife build\temp.win32-2.7\Release\life.obj build\temp.win32-2.7\Release\fred.obj /OUT:F:\ProgramFiler\Python27\test\Cython-test2\life.pyd /IMPLIB:build\temp.win32-2.7\Release\life.lib /MANIFESTFILE:build\temp.win32-2.7\Release\life.pyd.manifest Creating library build\temp.win32-2.7\Release\life.lib and object build\temp.win32-2.7\Release\life.exp python.exe -c "import life; print(life.life())" Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'life' Can you give a hint? -- --gv From lele at metapensiero.it Tue Nov 7 14:07:56 2017 From: lele at metapensiero.it (Lele Gaifax) Date: Tue, 07 Nov 2017 20:07:56 +0100 Subject: Easiest way to access C module in Python References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> <87375q8ev5.fsf@metapensiero.it> <097b1ad8-6c84-f2ba-604f-0e8a4985123b@gmail.com> Message-ID: <87tvy57vqr.fsf@metapensiero.it> Gisle Vanem writes: > python.exe -c "import life; print(life.life())" > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute 'life' > > Can you give a hint? I tried with Python 2, and the same recipe works for me, on GNU/Linux: $ python -c "import life; print life.life()" 42 I'm sorry, but I have no opportunity to try on a M$Windows system. Anyway, is your interpreter able to load the extension module produced by the "setup.py build_ext" step? On my PC, I get the following, using the "-v" option to verbosely see the imported modules: $ $ python -v # installing zipimport hook import zipimport # builtin # installed zipimport hook ... >>> import life dlopen("./life.so", 2); import life # dynamically loaded from life.so >>> dir(life) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__test__', 'life'] Can you try to import the "life" module and print its "dir()" to see the symbols it exposes? ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From rosuav at gmail.com Tue Nov 7 14:10:08 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Nov 2017 06:10:08 +1100 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On Wed, Nov 8, 2017 at 4:28 AM, Ian Kelly wrote: > On Sat, Nov 4, 2017 at 6:40 AM, Chris Angelico wrote: >> On Sat, Nov 4, 2017 at 11:25 PM, Jon Ribbens wrote: >>> On 2017-11-04, Ben Finney wrote: >>>> To respond to the criticism of an idea ? criticism containing no mention >>>> of the person ? as though it ?clearly refers to the [person]?, is of >>>> significant concern on a software dicussion forum such as this. >>> >>> No, the thing that is "of significant conern on a software discussion >>> forum such as this" is people such as yourself defending the abuse of >>> other contributors. >> >> Maybe we're not defending the abuse of other contributors. Maybe we're >> defending a legitimate, if somewhat caustic, response to a ridiculous >> suggestion. > > I don't think it was a ridiculous suggestion. > > Assigment to False is a syntax error, even though it's lexically valid > and was accepted in the past. Assignment to None was and is a syntax error, and assignment to False was legal only for backward compatibility within the 2.x line. I'm not sure what your point is. None, False, and True are all keywords, not built-ins, so you can't assign to them (any more than you could assign to a literal integer). > Inconsistent indentation is a syntax error, even though it could be > parsed and has been in the past. I'm not sure what you mean by "inconsistent" here, unless it's that tabs and spaces had a declared equivalency that they now don't. Unindenting to a level you've never used has always been an error; being sloppy has never been: if 1: if 2: pass pass # always an error if 3: pass # never an error Again, though, I'm not sure what your point is. Are you saying that it was ridiculous (or called ridiculous) to separate tabs and spaces rather than treat them as equivalent? Or are you saying that it ought to be legal? > Wildcard imports inside a function are a syntax error, even though > it's lexically valid and mostly harmless. Mostly harmless? Hmm. Okay: def func1(): spam = 1 def func2(): from module import * def func3(): nonlocal spam spam += 1 What does func3's spam refer to? I don't know for sure if that's why star imports got banned, but I also don't know for sure what should happen in the above situation either. > Using "yield from" inside an async coroutine is a syntax error, even > though it's lexically valid and "await" and "yield from" are nearly > identical. I'm not sure about this one, but the equivalence of await and yield from is a red herring. The part that's more surprising is this: >>> async def foo(): ... yield from [1,2,3] ... File "", line 2 SyntaxError: 'yield from' inside async function >>> async def foo(): ... for _ in [1,2,3]: yield _ ... (Yes, I know "yield from" does a lot more than "for... yield" does) But in comparison to "for... break", this is definitely not an error on the basis that it "makes no sense". It's more likely to be an error because of some internal limitation, in the same way that async coroutines weren't possible _at all_ initially: Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170118] on linux Type "help", "copyright", "credits" or "license" for more information. >>> async def foo(): yield 1 ... File "", line 1 SyntaxError: 'yield' inside async function That's no longer a SyntaxError as of 3.6, and I suspect that making "yield from" work inside an async function is, if not actually on the roadmap, certainly a possibility. > I haven't seen any argument against making "else" without "break" a > syntax error that wouldn't also apply to the above, with the exception > of Steve's manufactured interactive example ("manufactured" because > who really uses for-else interactively? If I really care that much > about output formatting I'm going to put it in a script). If there is > any extant code that would actually be broken by this, it's very > likely buggy. There are many MANY constructs that are broadly useless. Global declaration without assignment: >>> def foo(): ... global print ... print("hello") ... Unused variable (often indicates a misspelling): >>> def bar(): ... x = 1 ... return y ... Never-executed bodies: >>> def spam(): ... if False: print("ham") ... while False: print("ham") ... for _ in []: print("ham") ... try: pass ... except ZeroDivisionError: print("ham") ... (In CPython 3.7, the optimizer will eliminate the first two, but not the for or try. That could change, of course.) Not one of these is syntactically invalid. Why should "else without break" be trapped by the parser? Your other examples mostly have good parser-level reasons for being errors (you could argue from a language design POV about why False is a keyword but Ellipsis is just a built-in, but it's obvious that assigning to keywords has to be an error). Merely being pointless does not justify being an error; *maybe* the language could trap something if it's a known bug magnet, but it has to be a pretty serious bug magnet to justify that. ChrisA From grant.b.edwards at gmail.com Tue Nov 7 14:59:40 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 7 Nov 2017 19:59:40 +0000 (UTC) Subject: Ideas about how software should behave References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On 2017-11-07, Stefan Ram wrote: > Chris Angelico writes: >>sure what your point is. None, False, and True are all keywords, not >>built-ins, so you can't assign to them (any more than you could assign >>to a literal integer). > >|Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)] on win32 >|Type "help", "copyright", "credits" or "license" for more information. >|>>> >|>>> import ctypes >|>>> >|>>> value = 2 >|>>> ob_ival_offset = ctypes.sizeof(ctypes.c_size_t) + ctypes.sizeof(ctypes.c_voidp) >|>>> ob_ival = ctypes.c_int.from_address(id(value)+ob_ival_offset) >|>>> ob_ival.value = 3 >|>>> >|>>> print 2 >|3 I vaguely remember being able to do that in some implementations of FORTRAN yonks ago: subroutine foo(i) i = 3 end subroutine func [...] foo(2) write(*,*) 2 output would be: 3 -- Grant Edwards grant.b.edwards Yow! If I pull this SWITCH at I'll be RITA HAYWORTH!! gmail.com Or a SCIENTOLOGIST! From rosuav at gmail.com Tue Nov 7 14:59:55 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Nov 2017 06:59:55 +1100 Subject: Ideas about how software should behave In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On Wed, Nov 8, 2017 at 6:44 AM, Stefan Ram wrote: > Chris Angelico writes: >>sure what your point is. None, False, and True are all keywords, not >>built-ins, so you can't assign to them (any more than you could assign >>to a literal integer). > > |Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)] on win32 > |Type "help", "copyright", "credits" or "license" for more information. > |>>> > |>>> import ctypes > |>>> > |>>> value = 2 > |>>> ob_ival_offset = ctypes.sizeof(ctypes.c_size_t) + ctypes.sizeof(ctypes.c_voidp) > |>>> ob_ival = ctypes.c_int.from_address(id(value)+ob_ival_offset) > |>>> ob_ival.value = 3 > |>>> > |>>> print 2 > |3 That's still not assigning to a literal; that's mutating a cached object. There's a difference :) Also, once you start messing with ctypes like this, all language guarantees are out the window. ChrisA From info at wingware.com Tue Nov 7 15:01:46 2017 From: info at wingware.com (Wingware) Date: Tue, 07 Nov 2017 15:01:46 -0500 Subject: ANN: Wing Python IDE v. 6.0.8 released Message-ID: <5A02112A.4090502@wingware.com> Hi, We've just released Wing 6.0.8, a minor release that improves display of PEP 287 docstrings, fixes stability problems seen on Linux, fixes remote debugging of Django code, further improves remote development, adds some missing vi bindings, and makes about 30 other improvements. For details, see https://wingware.com/pub/wingide/6.0.8/CHANGELOG.txt Wing 6 is the latest major release in Wingware's family of Python IDEs, including Wing Pro, Wing Personal, and Wing 101. Wing 6 adds many new features, introduces a new annual license option for Wing Pro, and makes Wing Personal free. New Features in Wing 6 * Improved Multiple Selections: Quickly add selections and edit them all at once * Easy Remote Development: Work seamlessly on remote Linux, OS X, and Raspberry Pi systems * Debugging in the Python Shell: Reach breakpoints and exceptions in (and from) the Python Shell * Recursive Debugging: Debug code invoked in the context of stack frames that are already being debugged * PEP 484 and PEP 526 Type Hinting: Inform Wing's static analysis engine of types it cannot infer * Support for Python 3.6 and Stackless 3.4: Use async and other new language features * Optimized debugger: Run faster, particularly in multi-process and multi-threaded code * Support for OS X full screen mode: Zoom to a virtual screen, with auto-hiding menu bar * Added a new One Dark color palette: Enjoy the best dark display style yet * Updated French and German localizations: Thanks to Jean Sanchez, Laurent Fasnacht, and Christoph Heitkamp For a more detailed overview of new features see the release notice at https://wingware.com/news/2017-11-03 Annual License Option Wing 6 adds the option of purchasing a lower-cost expiring annual license for Wing Pro. An annual license includes access to all available Wing Pro versions while it is valid, and then ceases to function until it is renewed. Pricing for annual licenses is US$ 179/user for Commercial Use and US$ 69/user for Non-Commercial Use. Perpetual licenses for Wing Pro will continue to be available at the same pricing. The cost of extending Support+Upgrades subscriptions on Non-Commercial Use perpetual licenses for Wing Pro has also been dropped from US$ 89 to US$ 39 per user. For details, see https://wingware.com/store/ Wing Personal is Free Wing Personal is now free and no longer requires a license to run. It now also includes the Source Browser, PyLint, and OS Commands tools, and supports the scripting API and Perspectives. However, Wing Personal does not include Wing Pro's advanced editing, debugging, testing and code management features, such as remote development, refactoring, find uses, version control, unit testing, interactive debug probe, multi-process and child process debugging, move program counter, conditional breakpoints, debug watch, framework-specific support (for Jupyter, Django, and others), find symbol in project, and other features. Links Release notice: https://wingware.com/news/2017-11-03 Downloads and Free Trial: https://wingware.com/downloads Buy: https://wingware.com/store/purchase Upgrade: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at support at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE The Intelligent Development Environment for Python Programmers wingware.com From gisle.vanem at gmail.com Tue Nov 7 15:08:55 2017 From: gisle.vanem at gmail.com (Gisle Vanem) Date: Tue, 7 Nov 2017 21:08:55 +0100 Subject: Easiest way to access C module in Python In-Reply-To: <87tvy57vqr.fsf@metapensiero.it> References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> <87375q8ev5.fsf@metapensiero.it> <097b1ad8-6c84-f2ba-604f-0e8a4985123b@gmail.com> <87tvy57vqr.fsf@metapensiero.it> Message-ID: Lele Gaifax wrote: > On my PC, I get the following, using the "-v" option to verbosely see the > imported modules: > > $ $ python -v > # installing zipimport hook > import zipimport # builtin > # installed zipimport hook > ... >>>> import life > dlopen("./life.so", 2); > import life # dynamically loaded from life.so >>>> dir(life) > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__test__', 'life'] > > Can you try to import the "life" module and print its "dir()" to see the > symbols it exposes? From inside python 2.7: Python 2.7.13rc1 (v2.7.13rc1:4d6fd49eeb14, Dec 3 2016, 21:49:42) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import life >>> dir(life) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__test__'] >>> works fine. But as I wrote, doing a: python -vc "import life; print(life.life())" from the cmd-line doesn't work: ... import life # dynamically loaded from life.pyd Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'life' ... Inspection life.pyd shows no problems. It do export a "initlife" function. -- --gv From grant.b.edwards at gmail.com Tue Nov 7 15:34:36 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 7 Nov 2017 20:34:36 +0000 (UTC) Subject: Ideas about how software should behave References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On 2017-11-07, Chris Angelico wrote: > On Wed, Nov 8, 2017 at 6:44 AM, Stefan Ram wrote: >> Chris Angelico writes: >>>sure what your point is. None, False, and True are all keywords, not >>>built-ins, so you can't assign to them (any more than you could assign >>>to a literal integer). >> >> |Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)] on win32 >> |Type "help", "copyright", "credits" or "license" for more information. >> |>>> >> |>>> import ctypes >> |>>> >> |>>> value = 2 >> |>>> ob_ival_offset = ctypes.sizeof(ctypes.c_size_t) + ctypes.sizeof(ctypes.c_voidp) >> |>>> ob_ival = ctypes.c_int.from_address(id(value)+ob_ival_offset) >> |>>> ob_ival.value = 3 >> |>>> >> |>>> print 2 >> |3 > > That's still not assigning to a literal; that's mutating a cached > object. There's a difference :) True. > Also, once you start messing with ctypes like this, all language > guarantees are out the window. In FORTRAN, the only language gurantees were 1) When running your program, you'd almost, but not always, get all of your cards back. 2) The probability (P) of finding an available IBM 29 cardpunch was approximately D**2 where D is how many day's you had left before your deadline: with one hour left, P = 1/(24*24). -- Grant Edwards grant.b.edwards Yow! LOOK!! Sullen at American teens wearing gmail.com MADRAS shorts and "Flock of Seagulls" HAIRCUTS! From bc at freeuk.com Tue Nov 7 16:00:15 2017 From: bc at freeuk.com (bartc) Date: Tue, 7 Nov 2017 21:00:15 +0000 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> <87375q8ev5.fsf@metapensiero.it> <097b1ad8-6c84-f2ba-604f-0e8a4985123b@gmail.com> <87tvy57vqr.fsf@metapensiero.it> Message-ID: On 07/11/2017 20:08, Gisle Vanem wrote: > Lele Gaifax wrote: > >> On my PC, I get the following, using the "-v" option to verbosely see the >> imported modules: >> >> $ $ python -v >> # installing zipimport hook >> import zipimport # builtin >> # installed zipimport hook >> ... >>>>> import life >> dlopen("./life.so", 2); >> import life # dynamically loaded from life.so >>>>> dir(life) >> ['__builtins__', '__doc__', '__file__', '__name__', '__package__', >> '__test__', 'life'] >> >> Can you try to import the "life" module and print its "dir()" to see the >> symbols it exposes? > > From inside python 2.7: > ? Python 2.7.13rc1 (v2.7.13rc1:4d6fd49eeb14, Dec? 3 2016, 21:49:42) > [MSC v.1500 32 bit (Intel)] on win32 > ? Type "help", "copyright", "credits" or "license" for more information. > ? >>> import life > ? >>> dir(life) > ? ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > '__test__'] > ? >>> > > works fine. Not really, as it's missing the attribute 'life' which is needed for the second part of 'life.life': But as I wrote, doing a: > ? python -vc "import life; print(life.life())" -- bartc From ian.g.kelly at gmail.com Tue Nov 7 16:16:49 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 7 Nov 2017 14:16:49 -0700 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On Tue, Nov 7, 2017 at 12:10 PM, Chris Angelico wrote: > On Wed, Nov 8, 2017 at 4:28 AM, Ian Kelly wrote: >> On Sat, Nov 4, 2017 at 6:40 AM, Chris Angelico wrote: >>> Maybe we're not defending the abuse of other contributors. Maybe we're >>> defending a legitimate, if somewhat caustic, response to a ridiculous >>> suggestion. >> >> I don't think it was a ridiculous suggestion. >> >> Assigment to False is a syntax error, even though it's lexically valid >> and was accepted in the past. > > Assignment to None was and is a syntax error, and assignment to False > was legal only for backward compatibility within the 2.x line. I'm not > sure what your point is. None, False, and True are all keywords, not > built-ins, so you can't assign to them (any more than you could assign > to a literal integer). That's a false equivalence. There is nothing about None, False or True that *requires* them to be keywords, and my point is that in Python 2, two out of the three were *not* keywords. Making them keywords was a backward-incompatible change and entirely unnecessary, but it was done because it was deemed to be worthwhile. >> Inconsistent indentation is a syntax error, even though it could be >> parsed and has been in the past. > > I'm not sure what you mean by "inconsistent" here, unless it's that > tabs and spaces had a declared equivalency that they now don't. Yes. > Unindenting to a level you've never used has always been an error; > being sloppy has never been: > > if 1: > if 2: > pass > pass # always an error > if 3: > pass # never an error > > Again, though, I'm not sure what your point is. Are you saying that it > was ridiculous (or called ridiculous) to separate tabs and spaces > rather than treat them as equivalent? Or are you saying that it ought > to be legal? No, my point is not about indentation. I listed these things as examples of useful syntax errors that are not unlike the for-else syntax error suggestion. In this case, the change to treat tabs and spaces separately for indentation was a good one, albeit backward incompatible, and the suggestion to disallow for-else without break is likewise a good one, albeit backward incompatible. >> Wildcard imports inside a function are a syntax error, even though >> it's lexically valid and mostly harmless. > > Mostly harmless? Hmm. Okay: > > def func1(): > spam = 1 > def func2(): > from module import * > def func3(): > nonlocal spam > spam += 1 > > What does func3's spam refer to? In my opinion, it should refer to the variable from func1, since the star import can't be assumed to introduce a "spam" variable, and it doesn't make sense for the meaning of the code (and the generated byte code content) to depend on whether it does. > I don't know for sure if that's why star imports got banned, but I > also don't know for sure what should happen in the above situation > either. I think it's more likely because fast locals don't support dynamic modification, the same reason why a call to exec() from a function body can't modify the local variables either. It's not that this is technically infeasible; it's just unsupported. >> Using "yield from" inside an async coroutine is a syntax error, even >> though it's lexically valid and "await" and "yield from" are nearly >> identical. > > I'm not sure about this one, but the equivalence of await and yield > from is a red herring. The part that's more surprising is this: > >>>> async def foo(): > ... yield from [1,2,3] > ... > File "", line 2 > SyntaxError: 'yield from' inside async function >>>> async def foo(): > ... for _ in [1,2,3]: yield _ > ... > > (Yes, I know "yield from" does a lot more than "for... yield" does) > > But in comparison to "for... break", this is definitely not an error > on the basis that it "makes no sense". It's more likely to be an error > because of some internal limitation, in the same way that async > coroutines weren't possible _at all_ initially: No, it isn't. They share implementation. The only difference between the two apart from the syntactic restrictions is that await validates the type of its argument and looks for a method called __await__ instead of __iter__; see PEP 492. I suspect that the reason for the restriction was to reserve lexical space for asynchronous generators to be supported in the future, although PEP 525 only permits yield and not yield from, having explicitly deferred yield from as "less critical" and "requiring serious redesign". >> I haven't seen any argument against making "else" without "break" a >> syntax error that wouldn't also apply to the above, with the exception >> of Steve's manufactured interactive example ("manufactured" because >> who really uses for-else interactively? If I really care that much >> about output formatting I'm going to put it in a script). If there is >> any extant code that would actually be broken by this, it's very >> likely buggy. > > There are many MANY constructs that are broadly useless. > > Global declaration without assignment: >>>> def foo(): > ... global print > ... print("hello") > ... > > Unused variable (often indicates a misspelling): >>>> def bar(): > ... x = 1 > ... return y > ... > > Never-executed bodies: >>>> def spam(): > ... if False: print("ham") > ... while False: print("ham") > ... for _ in []: print("ham") > ... try: pass > ... except ZeroDivisionError: print("ham") > ... > > (In CPython 3.7, the optimizer will eliminate the first two, but not > the for or try. That could change, of course.) All of these are things that a linter should probably catch and warn about. If you had said that the break syntax suggestion was a good idea but probably better suited as a linter warning than as a SyntaxError integrated into the parser, then I would likely agree with you. That's not what you said, though. You said the suggestion was "ridiculous". > Not one of these is syntactically invalid. Why should "else without > break" be trapped by the parser? Your other examples mostly have good > parser-level reasons for being errors No, they don't. All four of them could just as easily also be accepted by the parser and only flagged as linter warnings. From gisle.vanem at gmail.com Tue Nov 7 16:27:08 2017 From: gisle.vanem at gmail.com (Gisle Vanem) Date: Tue, 7 Nov 2017 22:27:08 +0100 Subject: Easiest way to access C module in Python In-Reply-To: References: <1d6eccba-5baf-9a75-8fb9-042db7dc84be@jptechnical.co.uk> <87375q8ev5.fsf@metapensiero.it> <097b1ad8-6c84-f2ba-604f-0e8a4985123b@gmail.com> <87tvy57vqr.fsf@metapensiero.it> Message-ID: <85377647-b14d-c32b-d635-4729e44acf39@gmail.com> bartc wrote: >> ?From inside python 2.7: >> ?? Python 2.7.13rc1 (v2.7.13rc1:4d6fd49eeb14, Dec? 3 2016, 21:49:42) [MSC v.1500 32 bit (Intel)] on win32 >> ?? Type "help", "copyright", "credits" or "license" for more information. >> ?? >>> import life >> ?? >>> dir(life) >> ?? ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__test__'] >> ?? >>> >> >> works fine. > > Not really, as it's missing the attribute 'life' which is needed for the second part of 'life.life': Not sure what happend there. All is working now. But as you stated, Cython is truly a "beast". But as I wrote to Lele privately, the main reason for the failure, was Cygwin's Python2.7 messing up. I invoked the build from a GNU-Makefile. Thus Cygwin's Python was picked up from /bin/bash instead of my regular Python on PATH. A real PITA. -- --gv From rosuav at gmail.com Tue Nov 7 16:42:28 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Nov 2017 08:42:28 +1100 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On Wed, Nov 8, 2017 at 8:16 AM, Ian Kelly wrote: > All of these are things that a linter should probably catch and warn > about. If you had said that the break syntax suggestion was a good > idea but probably better suited as a linter warning than as a > SyntaxError integrated into the parser, then I would likely agree with > you. That's not what you said, though. You said the suggestion was > "ridiculous". Someone did mention linters at one point, and if I didn't explicitly agree, I certainly didn't disagree. Let me make my position clearer: The suggestion that these should be hard errors in the parser is ridiculous because it is not the parser's job to catch all bugs. Python is not intended to be that sort of language. It is the job of a linter to detect probable errors. >> Not one of these is syntactically invalid. Why should "else without >> break" be trapped by the parser? Your other examples mostly have good >> parser-level reasons for being errors > > No, they don't. All four of them could just as easily also be accepted > by the parser and only flagged as linter warnings. If everyone in the world agreed that a tab was equal to eight spaces, then I would agree that the tab/space discrepancy could be considered a linter warning. But there's no such agreement, which means that having the language declare some equivalency is extremely dangerous. Py2 had several language features and misfeatures that are that dangerous (having the simple name "input()" do evaluation is a trap that MANY people have fallen into), and it's correct to fix that. If Python had, from the start, treated tabs and spaces as different forms of indentation, there would be no reason to change that now. Whether True and False are keywords or builtins is a matter of debate, but there are definite advantages to them being locked down, and the only real disadvantage that I see is the question of consistency (eg "Ellipsis" is not a keyword, so you can still assign to that). Having star imports be bypassed when looking for nonlocals is going to be extremely confusing if you DO import a name from the other module. There's no right answer to the nonlocal lookup question, so the best thing to do is to not permit it. There's fundamentally no way for this to be both legal and sane in all situations, so it can't be left up to the linter. Mixing 'async def' and 'yield from' is, AIUI, more of a NotImplementedError than a SyntaxError; the wording of the PEP basically says that it's low priority, not that it's a bad thing. So that one is never going to be flagged by a linter - once it's made possible, it'll be the normal and expected behaviour, so there's no reason to flag it (except perhaps as "beware that this is not backward compatible with Python <3.8"). So, no, this is not the same. ChrisA From ben+python at benfinney.id.au Tue Nov 7 17:48:19 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Nov 2017 09:48:19 +1100 Subject: Ideas about how software should behave References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: <85fu9pzowc.fsf@benfinney.id.au> Ian Kelly writes: > Nowadays I realize and accept that this is preposterous. You cannot > criticize an idea without also criticizing the people who are attached > to that idea. Maybe so. Does that mean we must not criticise ideas? Later in your message you say no, but everything leading up to it argues you think so. In the thread which spawned this one, an idea was criticised, *because* someone expressed attachment to the idea. The idea was expressly one about software behaviour. Should that idea not be criticised in this forum, because someone expressed attachment to the idea? Does this forum allow ideas to be criticised only if no-one is attached to them? > Even if no personal slight is intended, it is received that way. If > your idea is bad, then by implication you are a person with bad ideas. Yes. And people with bad ideas rarely abandon bad ideas if those ideas are not shown to be bad. > Now, I'm not saying that we can't criticize ideas. We can, however, > choose to be polite or not in how we go about it. Certainly. It is incivil to make personal attacks. The criticism which started this sub-thread made no personal attack. Yet you've already pointed out that criticism of an idea ? an idea specifically about how software should behave ? is *perceived as* an attack, by people who are attached to the idea. You called such criticism ?incivility?; presumably on the basis that the person was attached to the idea that was criticised. By responding, in this forum, to criticism of ideas with the admonishment of ?incivility?, you effectively imply that it is incivil to criticise ideas strongly held ? even when those ideas are about the behaviour of Python software, in a forum whose purpose is discussion of Python software. This is the condescension of low expectation: that someone who is attached to an idea deserves *less respect*, that they should not be exposed to criticism of ideas they hold lest they perceive it as an attack. That treats people as too fragile to examine an idea as separate from their person. I thoroughly reject that condescending attitude, and choose instead to promote respect that people *can* examine ideas when those ideas are criticised. Ideas, whether lightly or strongly held, are never immune from criticism. Indeed, for the purpose of reducing the amount of bad ideas held by people, those ideas must be criticised. Ideas about software behaviour, in this forum, are surely not an exception to that. -- \ ?We jealously reserve the right to be mistaken in our view of | `\ what exists, given that theories often change under pressure | _o__) from further investigation.? ?Thomas W. Clark, 2009 | Ben Finney From ned at nedbatchelder.com Tue Nov 7 18:03:20 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 7 Nov 2017 18:03:20 -0500 Subject: Ideas about how software should behave In-Reply-To: <85fu9pzowc.fsf@benfinney.id.au> References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> Message-ID: <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> On 11/7/17 5:48 PM, Ben Finney wrote: > Ian Kelly writes: > >> Nowadays I realize and accept that this is preposterous. You cannot >> criticize an idea without also criticizing the people who are attached >> to that idea. > Maybe so. Does that mean we must not criticise ideas? Later in your > message you say no, but everything leading up to it argues you think so. > > In the thread which spawned this one, an idea was criticised, *because* > someone expressed attachment to the idea. > > The idea was expressly one about software behaviour. Should that idea > not be criticised in this forum, because someone expressed attachment to > the idea? > > Does this forum allow ideas to be criticised only if no-one is attached > to them? > >> Even if no personal slight is intended, it is received that way. If >> your idea is bad, then by implication you are a person with bad ideas. > Yes. And people with bad ideas rarely abandon bad ideas if those ideas > are not shown to be bad. > >> Now, I'm not saying that we can't criticize ideas. We can, however, >> choose to be polite or not in how we go about it. > Certainly. It is incivil to make personal attacks. The criticism which > started this sub-thread made no personal attack. > > Yet you've already pointed out that criticism of an idea ? an idea > specifically about how software should behave ? is *perceived as* an > attack, by people who are attached to the idea. > > You called such criticism ?incivility?; presumably on the basis that the > person was attached to the idea that was criticised. > > By responding, in this forum, to criticism of ideas with the > admonishment of ?incivility?, you effectively imply that it is incivil > to criticise ideas strongly held ? even when those ideas are about the > behaviour of Python software, in a forum whose purpose is discussion of > Python software. > > This is the condescension of low expectation: that someone who is > attached to an idea deserves *less respect*, that they should not be > exposed to criticism of ideas they hold lest they perceive it as an > attack. That treats people as too fragile to examine an idea as separate > from their person. > > I thoroughly reject that condescending attitude, and choose instead to > promote respect that people *can* examine ideas when those ideas are > criticised. > > Ideas, whether lightly or strongly held, are never immune from > criticism. Indeed, for the purpose of reducing the amount of bad ideas > held by people, those ideas must be criticised. > > Ideas about software behaviour, in this forum, are surely not an > exception to that. > All of this could have been avoided.? Steve called an idea arrogant. Jon felt that Steve was calling him arrogant. If Steve had simply said, "I'm sorry, I didn't mean that to apply to you," we wouldn't be here now. Why is it so hard to treat people as if they mattered? People are so caught up in proving others wrong and themselves right, that just saying, "Sorry, I wasn't clear" feels like giving ground. We need more civil discussion, and less sniping.? We're better than this. --Ned. From steve+python at pearwood.info Tue Nov 7 18:28:46 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 08 Nov 2017 10:28:46 +1100 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: <5a0241b0$0$18574$b1db1813$d948b532@news.astraweb.com> On Wed, 8 Nov 2017 04:28 am, Ian Kelly wrote: > Steve's manufactured interactive example ("manufactured" because > who really uses for-else interactively? If I really care that much > about output formatting I'm going to put it in a script). Me. As I have said. I really don't appreciate you implying that I'm lying about that. As for the question of whether anyone else uses it... that depends on whether there is anyone else: - using the REPL in an exploratory manner - entering loops with more than, say, two or three lines on the fly - that requires an additional block that has to run after the loop, without a pause for input - and they don't realise this until after they've started typing the loop (it's *exploratory* coding, which means sometimes you haven't thought things through until after you start typing) - AND they have the insight to realise that you can use an else block to rescue the situation without having to re-enter the lines already entered. Given how unfamiliar for...else is, it's probably only a small number of people that meet *all* these conditions, especially the last. I fear that most people wouldn't have the insight to realise that you can do this -- because they either don't know for...else at all, or they have the wrong mental model for it, or they simply aren't good at thinking outside the box. Who knows what other "thinking outside the box" uses for for...else with no break there are? Where there is one, there are probably others. The point is, if you require break and make the absence a syntax error, you rule them out. As things are today, the for block and the else block are loosely coupled. Apart from the requirement that else must immediately follow a for (or while) block, the language doesn't *force* there to be any coupling between the for block and the else block. We may consider them to be separate blocks, almost unrelated in principle (if not in practice). That has the conceptual advantage that we can teach, learn and think about the for and else blocks as separate concepts, which allows us to reason about them by composition: - we can reason about the for block as iteration over a sequence; - if we now add an else block after it, we don't have to revise our reasoning about the for block, we simply add the else block after it. Which is why I was able to think outside the box and realise I could rescue my already-typed dozen line for loop by adding an else clause. Whereas Jon's model requires us to change our understanding of the for block: - we reason about the for block as iteration; - if we then add an else block, we have to go back and re-interpret the for block as some sort of metaphorical search, whether or not it actually is a search, before we can think about the else block. Otherwise it doesn't make sense in his model of "search, else if not condition leading to break". In Jon's model, if we interpret else as "else no break", then we're also left with the mystery of what happened to the "if break" clause. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ian.g.kelly at gmail.com Tue Nov 7 18:37:43 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 7 Nov 2017 16:37:43 -0700 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) In-Reply-To: <5a0241b0$0$18574$b1db1813$d948b532@news.astraweb.com> References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <5a0241b0$0$18574$b1db1813$d948b532@news.astraweb.com> Message-ID: On Tue, Nov 7, 2017 at 4:28 PM, Steve D'Aprano wrote: > On Wed, 8 Nov 2017 04:28 am, Ian Kelly wrote: > >> Steve's manufactured interactive example ("manufactured" because >> who really uses for-else interactively? If I really care that much >> about output formatting I'm going to put it in a script). > > Me. As I have said. > > I really don't appreciate you implying that I'm lying about that. Sorry, I wasn't aware that you had said that. From daiyueweng at gmail.com Tue Nov 7 19:38:28 2017 From: daiyueweng at gmail.com (Daiyue Weng) Date: Wed, 8 Nov 2017 00:38:28 +0000 Subject: dictionary comparing int keys and joins their values if two key are within a certain distance Message-ID: I have a nested dictionary of defaultdict(dict) whose sub dict have int keys and lists (list of ints) as values, 'A' = {2092: [1573], 2093: [1576, 1575], 2094: [1577], 2095: [1574]}'B' = {2098: [1], 2099: [2, 3], 2101: [4], 2102: [5]}'C' = {2001: [6], 2003: [7, 8], 2004: [9], 2005: [10]} I union two list values if the difference of their sub keys equals to 1 under the same outer key e.g. A, and put the joined lists into another list. So this list will look like, [1573, 1576, 1575, 1577, 1574][1, 2, 3][4, 5][6][7, 8, 9, 10] here since 2092, 2093, 2094, 2095 are consecutive by 1, their values are put into a list [1573, 1576, 1575, 1577, 1574]. based on Detecting consecutive integers in a list , a simple solution can be built when the distance between two neighbouring sub keys is set to 1. results = []for key, sub_dict in d.items(): sub_dict_keys = sorted(sub_dict.keys()) for k, g in groupby(enumerate(sub_dict_keys), lambda ix: ix[0] - ix[1]): consecutive_keys = list(map(itemgetter(1), g)) val_list = [] for dict_key in consecutive_keys: val_list.extend(sub_dict[dict_key]) results.append(val_list) print(results) , however, the code can only work when the difference between two keys is 1, I am wondering how to make the code account for an arbitrary distance, e.g. the distance between two consecutive keys are less than or equal to 2 or 3, ... e.g. set the distance to 2, 'A' = {2092: [1573], 2093: [1576, 1575], 2095: [1577], 2097: [1574]}'B' = {2098: [1], 2099: [2, 3], 2101: [4], 2102: [5]}'C' = {2001: [6], 2003: [7, 8], 2008: [9], 2009: [10]} the result list will look like, [1573, 1576, 1575, 1577, 1574][1, 2, 3, 4, 5][6, 7, 8][9, 10] From ali.r.keles at gmail.com Wed Nov 8 00:36:22 2017 From: ali.r.keles at gmail.com (=?UTF-8?B?QWxpIFLEsXphIEtFTEXFng==?=) Date: Wed, 8 Nov 2017 08:36:22 +0300 Subject: python3 byte decode In-Reply-To: <20171105010624.GA22883@cskk.homeip.net> References: <20171105010624.GA22883@cskk.homeip.net> Message-ID: Hi, On 5 November 2017 at 04:06, Cameron Simpson wrote: > On 04Nov2017 01:47, Chris Angelico wrote: >> >> On Fri, Nov 3, 2017 at 8:24 PM, Ali R?za KELE? >> wrote: >>> >>> Yesterday, while working with redis, i encountered a strange case. >>> >>> I want to ask why is the following `True` >>> >>> ``` >>> "s" is b"s".decode() >>> ``` >>> >>> while the followings are `False`? >>> >>> ``` >>> "so" is b"so".decode() >>> "som" is b"som".decode() >>> "some" is b"some".decode() >>> ``` >>> >>> Or vice versa? >>> >>> I read that `is` compares same objects, not values. So my question is >>> why "s" and b"s".decode() are same objects, while the others aren't? >>> >>> My python version is 3.6.3. > For speed and memory reasons, Python notices small values of strings and > ints, and allocates them only once. So When your write: > > a = "s" > b = "s" > > Python will reuse the same str object for both. Because of this, not only is > "a == b" (i.e. they have the same value) but also "a is b" (a and b refer to > the same object). But this is not guarrenteed, and certainly for larger > values Python doesn't bother. Eg: Actually I guessed that it should be a caching mechanism or something like, but i was not sure since I do not know python internals in detail. >> You shouldn't be comparing string objects with 'is'. Sometimes two >> equal strings will be identical, and sometimes they won't. All you're >> seeing is that the interpreter happened to notice and/or cache this >> particular lookup. > > > To be more clear here, usually when humans say "identical" they mean having > exactly the same value or attributes. > Here, Chris means that the two strings are actually the same object rather > than two equivalent objects. "is" tests the former (the same object). "==" > is for testing the latter (the objects have the same value). Initially the 'is' compared returned value with None, I changed the code and it remained as is. After i have noticed this issue. Using `is` to compare with None is OK, isn't it? Cameron, Terry, Chris thanks for your replies in depth. - Ali Riza >> >> > > > a = "ghghghghghg" > b = "ghghghghghg" > > Here they will have the same value but be different objects. So "==" will > still return True, but "is" would return False. > > You should usually be using "==" to compare things. "is" has its place, but > it is usually not what you're after. > > In your example code, b"s".decode() returns the string value "s", and Python > is internally deciding to reuse the existing "s" from the left half of your > comparison. It can do this because strings are immutable. (For example, "+=" > on a string makes a new string). > > Hoping this is now more clear, > Cameron Simpson (formerly cs at zip.com.au) > -- > https://mail.python.org/mailman/listinfo/python-list -- -- Ali R?za Kele? From rosuav at gmail.com Wed Nov 8 01:03:04 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Nov 2017 17:03:04 +1100 Subject: python3 byte decode In-Reply-To: References: <20171105010624.GA22883@cskk.homeip.net> Message-ID: On Wed, Nov 8, 2017 at 4:36 PM, Ali R?za KELE? wrote: >> To be more clear here, usually when humans say "identical" they mean having >> exactly the same value or attributes. >> Here, Chris means that the two strings are actually the same object rather >> than two equivalent objects. "is" tests the former (the same object). "==" >> is for testing the latter (the objects have the same value). > > Initially the 'is' compared returned value with None, I changed the > code and it remained as is. After i have noticed this issue. > > Using `is` to compare with None is OK, isn't it? Yes, that's correct. None is a singleton, so you check for it by identity. There are other uses of identity checks, such as: if str is bytes: # we're running Python 2, so encode/decode appropriately if blah() is NotImplemented: # use a fallback But when you're working with strings or numbers, you'll generally want to use equality checks. ChrisA From davidgshi at yahoo.co.uk Wed Nov 8 04:26:04 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Wed, 8 Nov 2017 09:26:04 +0000 (UTC) Subject: Any good explanations on pd.merge(df,df2, on=['Code', 'Region']) In-Reply-To: <1551326177.7840529.1510133140749@mail.yahoo.com> References: <1551326177.7840529.1510133140749.ref@mail.yahoo.com> <1551326177.7840529.1510133140749@mail.yahoo.com> Message-ID: <268578134.7774158.1510133164370@mail.yahoo.com> I am trying to gain a clear understanding on?pd.merge(df,df2, on=['Code', 'Region']). Can anyone assist? Regards, David From Karsten.Hilbert at gmx.net Wed Nov 8 06:15:40 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Wed, 8 Nov 2017 12:15:40 +0100 Subject: Any good explanations on pd.merge(df,df2, on=['Code', 'Region']) In-Reply-To: <268578134.7774158.1510133164370@mail.yahoo.com> References: <1551326177.7840529.1510133140749.ref@mail.yahoo.com> <1551326177.7840529.1510133140749@mail.yahoo.com> <268578134.7774158.1510133164370@mail.yahoo.com> Message-ID: <20171108111540.xb5q2tirwhqjcwiq@hermes.hilbert.loc> On Wed, Nov 08, 2017 at 09:26:04AM +0000, David Shi via Python-list wrote: > I am trying to gain a clear understanding on?pd.merge(df,df2, on=['Code', 'Region']). > Can anyone assist? ncq at hermes:~$ python Python 2.7.14 (default, Sep 17 2017, 18:50:44) [GCC 7.2.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> pd.merge(df,df2, on=['Code', 'Region']) Traceback (most recent call last): File "", line 1, in NameError: name 'pd' is not defined >>> You will need to provide more context to get help. Regards, Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 From ben+python at benfinney.id.au Wed Nov 8 06:50:06 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Nov 2017 22:50:06 +1100 Subject: Ideas about how software should behave References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> Message-ID: <85bmkdyopd.fsf@benfinney.id.au> Ned Batchelder writes: > All of this could have been avoided.? Steve called an idea arrogant. > Jon felt that Steve was calling him arrogant. If Steve had simply > said, "I'm sorry, I didn't mean that to apply to you," we wouldn't be > here now. Why is it so hard to treat people as if they mattered? I both agree ? people are of primary importance, this could have been avoided ? and disagree. I see that Steve *did* treat Jon as though he mattered: he gave quite a lot of detailed discourse in getting to the nub of disagreement, and in exploring in various ways what he saw as flaws in some of the ideas expressed. To treat our community members with respect entails, among other things that you rightly champion, the respect of obliging each other to engage with turning an idea around and examining it critically, and to allow one's mind to be changed and discard a bad idea if it is shown to be bad. I think Steve's actions were respectful and civil in that regard. I also think Jon had cause to bristle somewhat at the characterisation. I don't think Jon was attacked by Steve's remark, but I do sympathise with the instinct to feel a criticism as an attack. The criticism of ideas is a respectful, civil action. Can it be done brusquely, even incivilly? Yes, certainly. Is it necessarily an incivil action to criticise an idea harshly? No, I don't think it is. We can be respectful and civil with each other, and simultaneously harsh and disrespectful to ideas held by each other. Done well, it is a respectful thing to criticise ideas harshly: it shows the respect that the person trusts you to recognise and discard a bad idea, when it is convincingly demonstrated. Criticism can of course be done less well, and frequently is. Nothing about this principle, of respectfully holding ideas up to harsh criticism, protects us from instead behaving incivilly and disrespectfully when we botch the attempt. I am in accord with Ian Kelly about that, to be sure. > People are so caught up in proving others wrong and themselves right, > that just saying, "Sorry, I wasn't clear" feels like giving ground. > > We need more civil discussion, and less sniping.? We're better than this. Amen to that. -- \ ?Timid men prefer the calm of despotism to the boisterous sea | `\ of liberty.? ?Thomas Jefferson | _o__) | Ben Finney From p.f.moore at gmail.com Wed Nov 8 06:50:31 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 8 Nov 2017 11:50:31 +0000 Subject: Any good explanations on pd.merge(df,df2, on=['Code', 'Region']) In-Reply-To: <20171108111540.xb5q2tirwhqjcwiq@hermes.hilbert.loc> References: <1551326177.7840529.1510133140749.ref@mail.yahoo.com> <1551326177.7840529.1510133140749@mail.yahoo.com> <268578134.7774158.1510133164370@mail.yahoo.com> <20171108111540.xb5q2tirwhqjcwiq@hermes.hilbert.loc> Message-ID: On 8 November 2017 at 11:15, Karsten Hilbert wrote: > On Wed, Nov 08, 2017 at 09:26:04AM +0000, David Shi via Python-list wrote: > >> I am trying to gain a clear understanding on pd.merge(df,df2, on=['Code', 'Region']). >> Can anyone assist? > > ncq at hermes:~$ python > Python 2.7.14 (default, Sep 17 2017, 18:50:44) > [GCC 7.2.0] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> pd.merge(df,df2, on=['Code', 'Region']) > Traceback (most recent call last): > File "", line 1, in > NameError: name 'pd' is not defined > >>> > > You will need to provide more context to get help. ... but given that I happen to know (mostly by chance) that pd is a commonly used short form when importing Pandas ("import pandas as pd") you should probably start with the documentation on merge: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html If that isn't sufficient for you, please provide a better explanation of what you don't understand, what you have tried and how it didn't match your expectations, and maybe someone on the list who is familiar with Pandas will be able to assist you. Paul From durumdara at gmail.com Wed Nov 8 08:11:44 2017 From: durumdara at gmail.com (Durumdara) Date: Wed, 8 Nov 2017 14:11:44 +0100 Subject: Calling of GetVolumeInformation returns empty serial number In-Reply-To: References: Message-ID: Hello! Eryk, your solution is the best solution for me: os.stat(drive).st_dev I don't need the real ID. I write a Recycle Bin manager in Python - for my machine only. It just simply registers all rec. bin files to an SQLite DB (only the new ones with a date). After 30 days it deletes too old registered recycle bin files. Without the serial the external drives make more records for one file (E:\, F:\, G:\). And because of different drives I may search in wrong drive (on deletion process the registered E:\...\x.dcu is on G:\., so I can't find it). But with this code is I can substitute the drive + RecBin folder with the serial, and later I can search it in good drive. Thank you! dd 2017-11-07 13:10 GMT+01:00 eryk sun : > On Tue, Nov 7, 2017 at 7:58 AM, Durumdara wrote: > > > > I want to get the serial number of the drives (without external modules > > like Win32 or WMI). > > The volume serial number is more easily available as > os.stat(drive).st_dev, which comes from calling > GetFileInformationByHandle. Note that despite using the volume serial > number (VSN) as the nearest equivalent of POSIX st_dev, there is no > requirement that the VSN is unique or even non-zero. The same applies > to the file index number that's used for POSIX st_ino. For example, > both values are 0 on a WebDav drive, for which Python's implementation > of os.path.samefile is useless. Practically speaking, however, it's > good enough in most cases, especially for mounted disk volumes. > > That said, maybe what you really want is the hardware (disk) serial > number -- not a volume serial number. The easiest way to get that is > via WMI. You can use subprocess to run wmic.exe if you don't want an > external dependency. You can also get the disk serial number by > calling DeviceIoControl via ctypes. This is a fairly complex > IOCTL_STORAGE_QUERY_PROPERTY request, with an input > STORAGE_PROPERTY_QUERY structure requesting the StorageDeviceProperty. > The result is a STORAGE_DEVICE_DESCRIPTOR structure that has a > SerialNumberOffset field that's the byte offset from the beginning of > the buffer of the serial number as a null-terminated string. > > Getting back to the VSN, note that the mount-point manager doesn't > rely on it as a unique identifier. For associating volume devices with > logical DOS drives and volume GUID names (i.e. names like > "Volume{12345678-0000-0000-0000-123456789abc}", which are used to > mount volumes as NTFS junctions), the mount-point manager queries a > unique ID via IOCTL_MOUNTDEV_QUERY_UNIQUE_ID. Sometimes the volume > driver returns a unique ID that's very long -- over 200 bytes. This > doesn't matter because it's only used to uniquely associate a GUID > name (and maybe a DOS drive) with the given volume when the system > boots. This association is persisted in HKLM\System\MountedDevices. > From hemla21 at gmail.com Wed Nov 8 10:58:40 2017 From: hemla21 at gmail.com (Heli) Date: Wed, 8 Nov 2017 07:58:40 -0800 (PST) Subject: import issues python3.4 Message-ID: <6deb808f-0612-4ec8-958f-9eecbcc7c744@googlegroups.com> Dear all, I have a software code that is written in python and has a structure like this. package/ run_my_gui.py #gui sub_package/ main.py sub_sub_package/ __init__.py A.py B.py C.py All the imports in main.py are absolute and look like below: (1) from package.sub_package.sub_sub_package import A The issue is I have an external script that tests main.py. I do not want to manually edit all import statements in my code to look like below: (2) from sub_sub_package import A Is there anyway I can run my external script without changing the absolute path from (1) to (2) in my code. I use subprocess.call to run main.py within my external script and it gets few arguments to run. Thanks a lot in advance for your replies, From ian.g.kelly at gmail.com Wed Nov 8 11:19:20 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 8 Nov 2017 09:19:20 -0700 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On Tue, Nov 7, 2017 at 2:42 PM, Chris Angelico wrote: > On Wed, Nov 8, 2017 at 8:16 AM, Ian Kelly wrote: >>> Not one of these is syntactically invalid. Why should "else without >>> break" be trapped by the parser? Your other examples mostly have good >>> parser-level reasons for being errors >> >> No, they don't. All four of them could just as easily also be accepted >> by the parser and only flagged as linter warnings. > > If everyone in the world agreed that a tab was equal to eight spaces, > then I would agree that the tab/space discrepancy could be considered > a linter warning. But there's no such agreement, which means that > having the language declare some equivalency is extremely dangerous. Really? I've never actually heard a story of anybody being bitten by this. I'm not disputing that it was a useful change, but I think "extremely dangerous" is an exaggeration. > Py2 had several language features and misfeatures that are that > dangerous (having the simple name "input()" do evaluation is a trap > that MANY people have fallen into), and it's correct to fix that. If > Python had, from the start, treated tabs and spaces as different forms > of indentation, there would be no reason to change that now. There were also plenty of backward-incompatible changes in Py3 that had nothing to do with dangerous code. > Whether True and False are keywords or builtins is a matter of debate, > but there are definite advantages to them being locked down, and the > only real disadvantage that I see is the question of consistency (eg > "Ellipsis" is not a keyword, so you can still assign to that). The other disadvantages are: making the change was backward-incompatible, and it prevents the user from overriding their values, which might sometimes be useful in the same way that overriding print might sometimes be useful -- which was one of the reasons for demoting print from keyword status! > Having star imports be bypassed when looking for nonlocals is going to > be extremely confusing if you DO import a name from the other module. > There's no right answer to the nonlocal lookup question, so the best > thing to do is to not permit it. There's fundamentally no way for this > to be both legal and sane in all situations, so it can't be left up to > the linter. I disagree. Always using the variable that is explicitly assigned would be both legal and sane in all situations. It also allows an easy fix: just explicitly assign the variable in the scope where you actually want it. Yes, some people might be confused when their star import isn't picked up by nonlocal, but people also get confused by late binding of nonlocals, or the behavior of mutable default values, or the distinction between modifying a list and reassigning it, etc. etc. Nobody is suggesting that defining a closure inside a loop ought to be a SyntaxError, but it is probably something that linters should be looking for, if they don't already. > Mixing 'async def' and 'yield from' is, AIUI, more of a > NotImplementedError than a SyntaxError; the wording of the PEP > basically says that it's low priority, not that it's a bad thing. So > that one is never going to be flagged by a linter - once it's made > possible, it'll be the normal and expected behaviour, so there's no > reason to flag it (except perhaps as "beware that this is not backward > compatible with Python <3.8"). I was not referring to the possible future use of yield from for async generators; I was referring to the possibility *today* of using "yield from" as a synonym for *await*. As far as I know the only major obstacle to that is that the authors (with good reason) made it a SyntaxError. This is exactly the same sort of situation: it's a construct that would otherwise be perfectly valid, but it's made a SyntaxError specifically to prevent users from doing some the devs don't want them to. From rosuav at gmail.com Wed Nov 8 11:31:23 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Nov 2017 03:31:23 +1100 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On Thu, Nov 9, 2017 at 3:19 AM, Ian Kelly wrote: > I was not referring to the possible future use of yield from for async > generators; I was referring to the possibility *today* of using "yield > from" as a synonym for *await*. As far as I know the only major > obstacle to that is that the authors (with good reason) made it a > SyntaxError. This is exactly the same sort of situation: it's a > construct that would otherwise be perfectly valid, but it's made a > SyntaxError specifically to prevent users from doing some the devs > don't want them to. I don't understand why you would use "yield from" as a synonym for "await". They are not equivalent. Why would you use one in place of the other? ChrisA From william.ayd at icloud.com Wed Nov 8 11:54:37 2017 From: william.ayd at icloud.com (William Ayd) Date: Wed, 08 Nov 2017 11:54:37 -0500 Subject: Any good explanations on pd.merge(df,df2, on=['Code', 'Region']) Message-ID: <169984D5-3AB4-4C77-9F66-E86CF599D6F6@icloud.com> Assuming df and df2 are dataframes you are essentially doing a SQL-like join of the two objects where the records within match on both the Code and Region columns Sent from my iPhone From __peter__ at web.de Wed Nov 8 12:11:58 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 08 Nov 2017 18:11:58 +0100 Subject: dictionary comparing int keys and joins their values if two key are within a certain distance References: Message-ID: Daiyue Weng wrote: > I have a nested dictionary of defaultdict(dict) whose sub dict have int > keys and lists (list of ints) as values, > > 'A' = {2092: [1573], 2093: [1576, 1575], 2094: [1577], 2095: > [1574]}'B' = {2098: [1], 2099: [2, 3], 2101: [4], 2102: [5]}'C' = > {2001: [6], 2003: [7, 8], 2004: [9], 2005: [10]} > > I union two list values if the difference of their sub keys equals to 1 > under the same outer key e.g. A, and put the joined lists into another > list. So this list will look like, > > [1573, 1576, 1575, 1577, 1574][1, 2, 3][4, 5][6][7, 8, 9, 10] > > here since 2092, 2093, 2094, 2095 are consecutive by 1, their values are > put into a list [1573, 1576, 1575, 1577, 1574]. > > based on Detecting consecutive integers in a list > integers-in-a-list>, > a simple solution can be built when the distance between two > neighbouring sub keys is set to 1. > > results = []for key, sub_dict in d.items(): > sub_dict_keys = sorted(sub_dict.keys()) > for k, g in groupby(enumerate(sub_dict_keys), lambda ix: ix[0] - > ix[1]): > consecutive_keys = list(map(itemgetter(1), g)) > val_list = [] > > for dict_key in consecutive_keys: > val_list.extend(sub_dict[dict_key]) > > results.append(val_list) > print(results) > > , however, the code can only work when the difference between two keys is > 1, I am wondering how to make the code account for an arbitrary distance, > e.g. the distance between two consecutive keys are less than or equal to 2 > or 3, ... e.g. set the distance to 2, > > 'A' = {2092: [1573], 2093: [1576, 1575], 2095: [1577], 2097: > [1574]}'B' = {2098: [1], 2099: [2, 3], 2101: [4], 2102: [5]}'C' = > {2001: [6], 2003: [7, 8], 2008: [9], 2009: [10]} > > the result list will look like, > > [1573, 1576, 1575, 1577, 1574][1, 2, 3, 4, 5][6, 7, 8][9, 10] There's a lot of noise in your question. The actual problem has nothing to do with dictionaries, it's about dividing a list into groups. The answer boils down to building the groups by identifying gaps between them instead of calculating a key that is common to the group. To find a gap you need two adjacent items, and while you can get those by combining tee and zip, or by constructing a stateful key function that remembers the previous value I prefer to start from scratch, with the grouped() generator replacing itertools.groupby(): $ cat group_neighbors_simple.py from itertools import groupby def grouped(items, is_neighbor): items = iter(items) try: prev = next(items) except StopIteration: return group = [prev] for value in items: if is_neighbor(prev, value): group.append(value) else: yield group group = [value] prev = value yield group sample = [1, 1, 2, 4, 6, 7, 6] print([ [v for i, v in group] for key, group in groupby(enumerate(sample), lambda iv: iv[0] - iv[1]) ]) print(list(grouped(sample, lambda a, b: b - a == 1))) print(list(grouped(sample, lambda a, b: b - a == 2))) print(list(grouped(sample, lambda a, b: abs(b - a) < 2))) $ python3 group_neighbors_simple.py [[1], [1, 2], [4], [6, 7], [6]] [[1], [1, 2], [4], [6, 7], [6]] [[1], [1], [2, 4, 6], [7], [6]] [[1, 1, 2], [4], [6, 7, 6]] From ian.g.kelly at gmail.com Wed Nov 8 13:05:27 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 8 Nov 2017 11:05:27 -0700 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On Wed, Nov 8, 2017 at 9:31 AM, Chris Angelico wrote: > On Thu, Nov 9, 2017 at 3:19 AM, Ian Kelly wrote: >> I was not referring to the possible future use of yield from for async >> generators; I was referring to the possibility *today* of using "yield >> from" as a synonym for *await*. As far as I know the only major >> obstacle to that is that the authors (with good reason) made it a >> SyntaxError. This is exactly the same sort of situation: it's a >> construct that would otherwise be perfectly valid, but it's made a >> SyntaxError specifically to prevent users from doing some the devs >> don't want them to. > > I don't understand why you would use "yield from" as a synonym for > "await". They are not equivalent. Why would you use one in place of > the other? There's not really a good reason to use "yield from" with "async def" when you could just use "await", but the point is that in principle you could. In a generator-based coroutine (e.g. asyncio prior to Python 3.5), "yield from" is used to pause the coroutine and wait on some future. In a native coroutine (e.g. after Python 3.5), "await" is used to pause the coroutine and wait on some future. The implementation AIUI is essentially the same; the __await__ method is even required to return an iterator, just like __iter__. That's why I'm saying that they're basically synonyms. All that's really separating them is the syntax error. From rosuav at gmail.com Wed Nov 8 13:12:23 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Nov 2017 05:12:23 +1100 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On Thu, Nov 9, 2017 at 5:05 AM, Ian Kelly wrote: > On Wed, Nov 8, 2017 at 9:31 AM, Chris Angelico wrote: >> On Thu, Nov 9, 2017 at 3:19 AM, Ian Kelly wrote: >>> I was not referring to the possible future use of yield from for async >>> generators; I was referring to the possibility *today* of using "yield >>> from" as a synonym for *await*. As far as I know the only major >>> obstacle to that is that the authors (with good reason) made it a >>> SyntaxError. This is exactly the same sort of situation: it's a >>> construct that would otherwise be perfectly valid, but it's made a >>> SyntaxError specifically to prevent users from doing some the devs >>> don't want them to. >> >> I don't understand why you would use "yield from" as a synonym for >> "await". They are not equivalent. Why would you use one in place of >> the other? > > There's not really a good reason to use "yield from" with "async def" > when you could just use "await", but the point is that in principle > you could. In a generator-based coroutine (e.g. asyncio prior to > Python 3.5), "yield from" is used to pause the coroutine and wait on > some future. In a native coroutine (e.g. after Python 3.5), "await" is > used to pause the coroutine and wait on some future. The > implementation AIUI is essentially the same; the __await__ method is > even required to return an iterator, just like __iter__. > > That's why I'm saying that they're basically synonyms. All that's > really separating them is the syntax error. Except that "yield from" is used by generators to delegate to other generators, and "await" is used by coroutines to delegate to other coroutines. In an asynchronous generator, "yield" produces values, and "yield from" would delegate to another asynchronous generator. They are NOT synonyms. ChrisA From jon+usenet at unequivocal.eu Wed Nov 8 13:18:36 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Wed, 8 Nov 2017 18:18:36 -0000 (UTC) Subject: Ideas about how software should behave References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> Message-ID: On 2017-11-08, Ben Finney wrote: > I also think Jon had cause to bristle somewhat at the characterisation. > I don't think Jon was attacked by Steve's remark, but I do sympathise > with the instinct to feel a criticism as an attack. Steve called me arrogant, that's an attack - never mind that he hadn't the slightest justification for it. If you're going to respond again that he was calling the idea arrogant, then please just stop and think for a moment: an idea, in the abstract, cannot be arrogant. Arrogance is simply not a concept that applies to ideas, it is a concept that applies to people. If you call an idea arrogant you are necessarily stating that the person espousing the idea is guilty of arrogance - that's what the word means. Chris also called the idea "ridiculous", which is also fairly rude, not least because, again, he hadn't the slightest justification for it. The idea is clearly not ridiculous. One might reasonably think that the idea was a bad idea, or unwise, etc, and someone else might reasonably think it isn't - but to call it ridiculous is not legitimate disagrement, it is insulting hyperbole. You have also, in the past, pretty much straight-up called me a liar. That is also, obviously, insulting - yet again, not that you had any justification for it at all. It is my experience of this group/list that if one disagrees with any of you, Steve and Chris, you all rally round and gang up on that person to insult and belittle them. This makes the atmosphere quite hostile, and it would be quite remarkable if it isn't hurting the community by driving people away. Please stop doing it. (Finally, to forestall the inevitable accusation that I am being unusually fragile, please let me point out that I have been around on Usenet since the early 1990s. I am used to flamewars etc. But this is not alt.usenet.kooks, this is comp.lang.python / python-list, and it's supposed to be a civilised discussion forum. If people can't have on-topic discussions without being called ridiculous arrogant liars, then there's something wrong.) From ian.g.kelly at gmail.com Wed Nov 8 13:20:01 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 8 Nov 2017 11:20:01 -0700 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On Wed, Nov 8, 2017 at 11:12 AM, Chris Angelico wrote: > On Thu, Nov 9, 2017 at 5:05 AM, Ian Kelly wrote: >> On Wed, Nov 8, 2017 at 9:31 AM, Chris Angelico wrote: >>> On Thu, Nov 9, 2017 at 3:19 AM, Ian Kelly wrote: >>>> I was not referring to the possible future use of yield from for async >>>> generators; I was referring to the possibility *today* of using "yield >>>> from" as a synonym for *await*. As far as I know the only major >>>> obstacle to that is that the authors (with good reason) made it a >>>> SyntaxError. This is exactly the same sort of situation: it's a >>>> construct that would otherwise be perfectly valid, but it's made a >>>> SyntaxError specifically to prevent users from doing some the devs >>>> don't want them to. >>> >>> I don't understand why you would use "yield from" as a synonym for >>> "await". They are not equivalent. Why would you use one in place of >>> the other? >> >> There's not really a good reason to use "yield from" with "async def" >> when you could just use "await", but the point is that in principle >> you could. In a generator-based coroutine (e.g. asyncio prior to >> Python 3.5), "yield from" is used to pause the coroutine and wait on >> some future. In a native coroutine (e.g. after Python 3.5), "await" is >> used to pause the coroutine and wait on some future. The >> implementation AIUI is essentially the same; the __await__ method is >> even required to return an iterator, just like __iter__. >> >> That's why I'm saying that they're basically synonyms. All that's >> really separating them is the syntax error. > > Except that "yield from" is used by generators to delegate to other > generators, and "await" is used by coroutines to delegate to other > coroutines. In an asynchronous generator, "yield" produces values, and > "yield from" would delegate to another asynchronous generator. They > are NOT synonyms. Only because the devs have chosen to reserve the possibility of asynchronous generators. Abstractly, coroutines and generators are distinct concepts, but pragmatically, coroutines *are* generators. Native coroutines don't actually change this; they just do a better job of hiding it. From rosuav at gmail.com Wed Nov 8 13:29:19 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Nov 2017 05:29:19 +1100 Subject: Ideas about how software should behave In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> Message-ID: On Thu, Nov 9, 2017 at 5:18 AM, Jon Ribbens wrote: > On 2017-11-08, Ben Finney wrote: >> I also think Jon had cause to bristle somewhat at the characterisation. >> I don't think Jon was attacked by Steve's remark, but I do sympathise >> with the instinct to feel a criticism as an attack. > > Steve called me arrogant, that's an attack - never mind that he hadn't > the slightest justification for it. If you're going to respond again > that he was calling the idea arrogant, then please just stop and > think for a moment: an idea, in the abstract, cannot be arrogant. > Arrogance is simply not a concept that applies to ideas, it is > a concept that applies to people. If you call an idea arrogant > you are necessarily stating that the person espousing the idea is > guilty of arrogance - that's what the word means. If that's true, then it's not possible for software to be "opinionated" either, because that definitely implies something human. And it's illogical to say "Windows is feeling cranky today" when something inexplicably fails. Nor should you talk about autocorrect "thinking it knows better than you". But all of these are ways that we talk about software. Ideas are just like software for our brains; when they're complex enough, they have lives and characteristics of their own. I suppose if this were comp.lang.iso.standardized.python or something, we could stick with dry and dull language, and avoid any of these problems. But personally, I would consider that a step backwards. The occasional confusion is the price we pay for what we have - and don't forget, we're discussing a language that derives heavily from high class comedy. Please, Jon, accept that we were not deliberately trying to put you down. Steve, if you can clearly state your position on this (possibly worded in the form of an apology?), it would go a long way to clearing this up. ChrisA From rosuav at gmail.com Wed Nov 8 13:34:10 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Nov 2017 05:34:10 +1100 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On Thu, Nov 9, 2017 at 5:20 AM, Ian Kelly wrote: > On Wed, Nov 8, 2017 at 11:12 AM, Chris Angelico wrote: >> Except that "yield from" is used by generators to delegate to other >> generators, and "await" is used by coroutines to delegate to other >> coroutines. In an asynchronous generator, "yield" produces values, and >> "yield from" would delegate to another asynchronous generator. They >> are NOT synonyms. > > Only because the devs have chosen to reserve the possibility of > asynchronous generators. Abstractly, coroutines and generators are > distinct concepts, but pragmatically, coroutines *are* generators. > Native coroutines don't actually change this; they just do a better > job of hiding it. Coroutines *are implemented using* generators. And I don't know what you mean by "reserve the possibility of"; asynchronous generators do exist: >>> async def gen(): ... yield 1 ... yield 2 ... yield 3 ... await something ... yield 4 ... >>> gen() PEP 525 https://www.python.org/dev/peps/pep-0525/ says: """ While it is theoretically possible to implement yield from support for asynchronous generators, it would require a serious redesign of the generators implementation. """ In other words, it's only because of *implementation details* that "yield from" inside a generator is difficult. There's no language-level reason for it to be forbidden, and there is absolutely NO correlation between "await" and "yield from" in an async function. ChrisA From torriem at gmail.com Wed Nov 8 14:44:03 2017 From: torriem at gmail.com (Michael Torrie) Date: Wed, 8 Nov 2017 12:44:03 -0700 Subject: Ideas about how software should behave In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> Message-ID: <02d79fa2-1ce5-c4cb-141c-81ad7408f6fe@gmail.com> On 11/08/2017 11:29 AM, Chris Angelico wrote: > If that's true, then it's not possible for software to be > "opinionated" either, because that definitely implies something human. > And it's illogical to say "Windows is feeling cranky today" when > something inexplicably fails. Nor should you talk about autocorrect > "thinking it knows better than you". But all of these are ways that we > talk about software. Ideas are just like software for our brains; when > they're complex enough, they have lives and characteristics of their > own. This reminds me of a classic video clip from a few years ago. The new Microsoft "We Share Your Pain" program. https://www.youtube.com/watch?v=D28FkfJiauk > Please, Jon, accept that we were not deliberately trying > to put you down. Thanks for saying this, Chris. Sometimes we all need to be humble and apologize even when offense was not intended. From rosuav at gmail.com Wed Nov 8 15:00:27 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Nov 2017 07:00:27 +1100 Subject: Ideas about how software should behave In-Reply-To: <02d79fa2-1ce5-c4cb-141c-81ad7408f6fe@gmail.com> References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> <02d79fa2-1ce5-c4cb-141c-81ad7408f6fe@gmail.com> Message-ID: On Thu, Nov 9, 2017 at 6:44 AM, Michael Torrie wrote: > This reminds me of a classic video clip from a few years ago. The new > Microsoft "We Share Your Pain" program. > > https://www.youtube.com/watch?v=D28FkfJiauk I've never actually seen this before. That's awesome! Thanks for sharing :) ChrisA From marko at pacujo.net Wed Nov 8 15:05:22 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 08 Nov 2017 22:05:22 +0200 Subject: Ideas about how software should behave References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> Message-ID: <87bmkc35a5.fsf@elektro.pacujo.net> Jon Ribbens : > It is my experience of this group/list that if one disagrees with any > of you, Steve and Chris, you all rally round and gang up on that > person to insult and belittle them. This makes the atmosphere quite > hostile, and it would be quite remarkable if it isn't hurting the > community by driving people away. Please stop doing it. This forum is about a dead thing, a programming language. I wouldn't make too big a deal about "the community." If someone's postings constantly frustrate you, simply place them in your killfile. I've done that to people. People have done that to me. Marko From ian.g.kelly at gmail.com Wed Nov 8 15:52:04 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 8 Nov 2017 13:52:04 -0700 Subject: Ideas about how software should behave (was: replacing `else` with `then` in `for` and `try`) In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: On Wed, Nov 8, 2017 at 11:34 AM, Chris Angelico wrote: > On Thu, Nov 9, 2017 at 5:20 AM, Ian Kelly wrote: >> On Wed, Nov 8, 2017 at 11:12 AM, Chris Angelico wrote: >>> Except that "yield from" is used by generators to delegate to other >>> generators, and "await" is used by coroutines to delegate to other >>> coroutines. In an asynchronous generator, "yield" produces values, and >>> "yield from" would delegate to another asynchronous generator. They >>> are NOT synonyms. >> >> Only because the devs have chosen to reserve the possibility of >> asynchronous generators. Abstractly, coroutines and generators are >> distinct concepts, but pragmatically, coroutines *are* generators. >> Native coroutines don't actually change this; they just do a better >> job of hiding it. > > Coroutines *are implemented using* generators. And I don't know what > you mean by "reserve the possibility of"; asynchronous generators do > exist: They didn't exist when native coroutines were implemented. That's when the possibility was reserved. > PEP 525 https://www.python.org/dev/peps/pep-0525/ says: > """ > While it is theoretically possible to implement yield from support for > asynchronous generators, it would require a serious redesign of the > generators implementation. > """ > > In other words, it's only because of *implementation details* that > "yield from" inside a generator is difficult. There's no > language-level reason for it to be forbidden, and there is absolutely > NO correlation between "await" and "yield from" in an async function. Since we're quoting PEPs, here's what PEP 492 says about "await": https://www.python.org/dev/peps/pep-0492/#id56 """ await, similarly to yield from, suspends execution of [the] coroutine until [the] awaitable completes and returns the result data. It uses the yield from implementation with an extra step of validating its argument. await only accepts an awaitable, which can be one of: * A native coroutine object returned from a native coroutine function. * A generator-based coroutine object returned from a function decorated with types.coroutine(). * An object with an __await__ method returning an iterator. Any yield from chain of calls ends with a yield. This is a fundamental mechanism of how Futures are implemented. Since, internally, coroutines are a special kind of generators, every await is suspended by a yield somewhere down the chain of await calls (please refer to PEP 3156 for a detailed explanation). To enable this behavior for coroutines, a new magic method called __await__ is added. In asyncio, for instance, to enable Future objects in await statements, the only change is to add __await__ = __iter__ line to asyncio.Future class. [remainder of section snipped for brevity] """ Points to note: "similarly to yield from"; "uses the yield from implementation"; "internally, coroutines are a special kind of generators"; "every await is suspended by a yield"; "to enable Future objects in await statements, the only change is to add __await__ = __iter__". "await" was designed to be a *drop-in replacement* for "yield from" so your insistence that they're unrelated is kind of mind-boggling. From ben+python at benfinney.id.au Wed Nov 8 17:22:02 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Nov 2017 09:22:02 +1100 Subject: Ideas about how software should behave References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> Message-ID: <851sl8za0l.fsf@benfinney.id.au> Jon Ribbens writes: > On 2017-11-08, Ben Finney wrote: > > I also think Jon had cause to bristle somewhat at the characterisation. > > I don't think Jon was attacked by Steve's remark, but I do sympathise > > with the instinct to feel a criticism as an attack. > > Steve called me arrogant, that's an attack To say that someone is being arrogant simply is not an attack, and I really want you to see that. It's also not true that he called you arrogant. > Arrogance is simply not a concept that applies to ideas, it is > a concept that applies to people. Arrogance, like generosity or cleverness or foolishness, is a concept that applies to *behaviour*. Someone can commit an act that is arrogant, or generous or clever or foolish, and we can call the *idea that informed that act* as arrogant or generous or clever or foolish. > If you call an idea arrogant you are necessarily stating that the > person espousing the idea is guilty of arrogance - that's what the > word means. Yes: it describes the behaviour. It does not imply characterisation of the person. To describe the idea as arrogant, or generous or clever or foolish, is *not* to say that the person holding that idea is arrogant. That would be as unwarranted as calling Bill Gates generous merely because he sometimes gives a small portion of his wealth to charity. Yet we would not hesitate to say that the giving of funds to malaria research is a generous idea. Similarly, to say that someone expressed an arrogant idea is indeed to say their bewhaviour was arrogant, and that necessarily accuses the person of arrogant behaviour. That does not characterise the person as arrogant and it is not an attack on the person. > Chris also called the idea "ridiculous", which is also fairly rude, It is not rude to describe an idea as ridiculous. It is deeply *respectful* to people to show when ideas are ridiculous. If the idea *is* correctly described as ridiculous, we want the *person* to stop holding the ridiculous idea. The idea is not the person, and rudeness to the idea is often *compassion and respect* for the person. (Whether the idea is correctly described that way is a separate matter, of course; that is why discussion is required, preferably with the participation of the person holding the idea.) > The idea is clearly not ridiculous. Great! That should be a good discussion to have. No-one needs to identify with an idea about how software behaves, in order to participate in that discussion; no-one is attacked by merely calling the idea ridiculous. > You have also, in the past, pretty much straight-up called me a liar. > That is also, obviously, insulting - yet again, not that you had any > justification for it at all. I hope that we can do the necessary work of seeking factual basis for claims talk about facts, without calling each other liars. I also hope that we can receive challenges on our claims, without being perceived as under attack. -- \ ?If you continue running Windows, your system may become | `\ unstable.? ?Microsoft, Windows 95 bluescreen error message | _o__) | Ben Finney From rosuav at gmail.com Wed Nov 8 17:38:23 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Nov 2017 09:38:23 +1100 Subject: Ideas about how software should behave In-Reply-To: <851sl8za0l.fsf@benfinney.id.au> References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> <851sl8za0l.fsf@benfinney.id.au> Message-ID: On Thu, Nov 9, 2017 at 9:22 AM, Ben Finney wrote: >> If you call an idea arrogant you are necessarily stating that the >> person espousing the idea is guilty of arrogance - that's what the >> word means. > > Yes: it describes the behaviour. It does not imply characterisation of > the person. > > To describe the idea as arrogant, or generous or clever or foolish, is > *not* to say that the person holding that idea is arrogant. > > That would be as unwarranted as calling Bill Gates generous merely > because he sometimes gives a small portion of his wealth to charity. Yet > we would not hesitate to say that the giving of funds to malaria > research is a generous idea. > > Similarly, to say that someone expressed an arrogant idea is indeed to > say their bewhaviour was arrogant, and that necessarily accuses the > person of arrogant behaviour. That does not characterise the person as > arrogant and it is not an attack on the person. Yep. My way of looking at this is: actions are generous, or arrogant, or whatever, based on the moral decisions behind them. (So for example, it doesn't count as "generous" to accidentally drop a whole lot of money to the Mudders of Higgins' Moon, even though people benefited a lot from it.) To describe a *person* as any of those things is to say that you expect, on balance, that this person's decisions (and thus actions) are likely to fit that description. You would describe Superman as altruistic and a helper of those in trouble, because you can confidently expect that he will selflessly help anyone who needs it. Describing *him* as altruistic is a descriptor/predictor. To call a *person* arrogant is to say "Not only was this action of yours arrogant, I fully expect that your future actions will be arrogant too". But that isn't what happened here. ChrisA From ned at nedbatchelder.com Wed Nov 8 19:16:53 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 8 Nov 2017 19:16:53 -0500 Subject: Ideas about how software should behave In-Reply-To: <851sl8za0l.fsf@benfinney.id.au> References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> <851sl8za0l.fsf@benfinney.id.au> Message-ID: <7c3a7837-9faa-db89-85f5-79993436d138@nedbatchelder.com> On 11/8/17 5:22 PM, Ben Finney wrote: > Jon Ribbens writes: > >> On 2017-11-08, Ben Finney wrote: >>> I also think Jon had cause to bristle somewhat at the characterisation. >>> I don't think Jon was attacked by Steve's remark, but I do sympathise >>> with the instinct to feel a criticism as an attack. >> Steve called me arrogant, that's an attack > To say that someone is being arrogant simply is not an attack, and I > really want you to see that. Ben, this idea is really stupid! Be honest: when you read what I just wrote, did you feel a dispassionate discussion starting, or did you feel a bit attacked? I think it is unrealistic to expect people to be completely dissociated from the ideas they hold. Second, now you want us to agree that calling someone arrogant isn't an attack?? Perhaps you are able to discuss your own behavior this way, but I assure you, most people are not.? You are holding up this kind of distance from yourself as an ideal we should all strive for.? To me it seems like a Dr.-Spock-like separation from feelings.? People don't work this way. How many paragraphs of close parsing are we going to twist ourselves through, just to avoid saying, "Yeah, sorry, that went a bit far.? I didn't want to alienate you in the pursuit of a demonstration of my own correctness." --Ned. From cs at cskk.id.au Wed Nov 8 21:55:32 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 9 Nov 2017 13:55:32 +1100 Subject: Ideas about how software should behave In-Reply-To: References: Message-ID: <20171109025532.GA64500@cskk.homeip.net> On 09Nov2017 05:29, Chris Angelico wrote: >On Thu, Nov 9, 2017 at 5:18 AM, Jon Ribbens wrote: >> On 2017-11-08, Ben Finney wrote: >>> I also think Jon had cause to bristle somewhat at the characterisation. >>> I don't think Jon was attacked by Steve's remark, but I do sympathise >>> with the instinct to feel a criticism as an attack. >> >> Steve called me arrogant, that's an attack - never mind that he hadn't >> the slightest justification for it. If you're going to respond again >> that he was calling the idea arrogant, then please just stop and >> think for a moment: an idea, in the abstract, cannot be arrogant. I'm with Jon here. >> Arrogance is simply not a concept that applies to ideas, it is >> a concept that applies to people. If you call an idea arrogant >> you are necessarily stating that the person espousing the idea is >> guilty of arrogance - that's what the word means. > >If that's true, then it's not possible for software to be >"opinionated" either, because that definitely implies something human. [...] That is also true (let us ignore hypothical sentient software). And I admit that I have myself spoken of "opinionated" software, and when I do so I'm usually talking about software with IMO excessive "policy" over mechanism, particularly software whose policy cannot be adjusted. When I do that, the opinion/policy comes from the developer (mandated by management or not) and arguably I'm impugning the quality of the dev's decisions. While I'd hope that a term like "opinionated" might be tolerable (though in some contexts, particularly with an audience of the dev's peers or colleagues, possibly a source of affront), I think I'm again with Jon on "arrogant": without a lot of context or ambiance, I think I'd take this as personal and somewhat attacking if it were used directed at me or my code. I've just dug out the source posting, Message-ID <59fbc01b$0$18593$b1db1813$d948b532 at news.astraweb.com>, and we've already got the word "obvious" being bandied about in a slightly heated exchange. I've discovered myself that "obvious" is a remarkably subjective desciption. I think Jon is arguing that an "obvious" inference is inherently "right" and that if the language semantics don't match that, _particularly_ in a language like Python where significant thought has gone into making the language read quite naturally to most English speakers, then such a disconnect between an obvious/intuitive expectation of the code's prose and the actual language semantics constitutes a design bug. I think Steve was making the point that the language's semntics are what they are and that inferring different semantics, regardless of how obvious they seem, is the wrong thing to do. And then went on to characterise an inferred "idea of purity" as "arrogant and foolish". I think I can, myself, imagine why Steve thinks of the idea this way, but that will be inference on inference. Regardless, I think that "arrogant and foolish" crosses into incivility, to use Ben's term. And that is because, as Jon remarks, "an idea, in the abstract, cannot be arrogant"; the terms inherently characterise the person holding the idea. And because of that, I want to argue for avoiding terms like this. I've definitely sinned in this way myself in the past. In the distant past, a _lot_. Particularly here (python-list) I try to reread my own posts for this kind of thing before sending (and also for my very high typo rate). We _should_ strive really hard to be dispassionate and civil, _particularly_ when criticising things: criticism is usually unpleasant to receive, regardless of how valid or constructive. I'm not a big believer in "egoless programming" as my ego is bound up in my desire for quality, but a consequence of that is that criticism _is_ received personally, and therefore it should be as well phrased as feasible. Before signing out, let me hark to some words from the glorious film "Harvey": "I used to be smart. I recommend nice." Cheers, Cameron Simpson (formerly cs at zip.com.au) From ben+python at benfinney.id.au Wed Nov 8 22:18:22 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Nov 2017 14:18:22 +1100 Subject: Ideas about how software should behave References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> <851sl8za0l.fsf@benfinney.id.au> <7c3a7837-9faa-db89-85f5-79993436d138@nedbatchelder.com> Message-ID: <85vaikxhq9.fsf@benfinney.id.au> Ned Batchelder writes: > On 11/8/17 5:22 PM, Ben Finney wrote: > > To say that someone is being arrogant simply is not an attack, and I > > really want you to see that. > Ben, this idea is really stupid! > > Be honest: when you read what I just wrote, did you feel a > dispassionate discussion starting, or did you feel a bit attacked? I feel attacked. Does that mean I am attacked? If I feel attacked, does that mean one should never call an idea stupid? I think the answer to both those questions is ?no?. > I think it is unrealistic to expect people to be completely > dissociated from the ideas they hold. I don't expect that. What I do expect is that people will, when experiencing that feeling, to figure out whether the feeling of attack reflects the nature of what happened, or merely a perception. That's how I expect adults to behave. Sometimes we ? and of course I include myself ? don't meet that, yet we need to keep aiming for that. > Second, now you want us to agree that calling someone arrogant isn't > an attack? It's one thing to say ?this idea is arrogant?, which is what Steve did. That's not in any way personal, nor an attack on a person. It criticises an idea. If instead Steve said ?that was an arrogant action?, the person is being criticised. But it's still not *characterising* the person; it characterises the action. It says nothing about whether the person is arrogant. If instead of either of those Steve said ?you are arrogant?, that would warrant the response, in my estimation. That it got nowhere near that is why I'm pleading that we stop treating criticism of ideas as though it were an attack on a person. > Perhaps you are able to discuss your own behavior this way Too often I fail. But it's what we need to keep trying to do. > but I assure you, most people are not. I think we are better than that. We all have these responses to some degree; we can choose to respond differently. I think we can, and I ask that we do. >? You are holding up this kind of distance from yourself as an ideal we >should all strive for.? To me it seems like a Dr.-Spock-like separation >from feelings.? People don't work this way. We can't avoid feeling what we feel, and I would never fault someone for that. > How many paragraphs of close parsing are we going to twist ourselves > through, just to avoid saying, "Yeah, sorry, that went a bit far.? I > didn't want to alienate you in the pursuit of a demonstration of my > own correctness." I don't have any aim of avoiding that. If I need to apologise for something, that hasn't been made clear to me. If you're seeking an apology from someone else, I can't do it for them. What has been made clear to me is that we have a long way to go in pursuit of allowing ideas to be held at arm's length, discussed and criticised, with respect and compassion for one another. -- \ ?[?] we don?t understand what we mean when we say that [God] is | `\ ?good?, ?wise?, or ?intelligent?.? ?Karen Armstrong, _The Case | _o__) For God_, 2009 | Ben Finney From ben+python at benfinney.id.au Thu Nov 9 00:08:19 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Nov 2017 16:08:19 +1100 Subject: Ideas about how software should behave References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> <87bmkc35a5.fsf@elektro.pacujo.net> Message-ID: <85r2t8xcn0.fsf@benfinney.id.au> Marko Rauhamaa writes: > Jon Ribbens : > > It is my experience of this group/list that if one disagrees with any > > of you, Steve and Chris, you all rally round and gang up on that > > person to insult and belittle them. This makes the atmosphere quite > > hostile, and it would be quite remarkable if it isn't hurting the > > community by driving people away. Please stop doing it. > > This forum is about a dead thing, a programming language. I wouldn't > make too big a deal about "the community." On the contrary, this forum is about a *community of people*, formed around a programming language. The community is primary here, I am in full agreement with Jon on that. -- \ ?Room service? Send up a larger room.? ?Groucho Marx | `\ | _o__) | Ben Finney From rurpy at yahoo.com Thu Nov 9 01:32:34 2017 From: rurpy at yahoo.com (Rurpy) Date: Thu, 9 Nov 2017 06:32:34 +0000 (UTC) Subject: Ideas about how software should behave References: <1343750507.4927257.1510209154414.ref@mail.yahoo.com> Message-ID: <1343750507.4927257.1510209154414@mail.yahoo.com> On 11/08/2017 08:18 PM, Ben Finney wrote: > Ned Batchelder writes: > [...] >> Second, now you want us to agree that calling someone arrogant isn't >> an attack? > > It's one thing to say ?this idea is arrogant?, which is what Steve did. > That's not in any way personal, nor an attack on a person. It criticises > an idea. > > If instead Steve said ?that was an arrogant action?, the person is being > criticised. But it's still not *characterising* the person; it > characterises the action. It says nothing about whether the person is > arrogant. > > If instead of either of those Steve said ?you are arrogant?, that would > warrant the response, in my estimation. > > That it got nowhere near that is why I'm pleading that we stop treating > criticism of ideas as though it were an attack on a person. People and their ideas are not separable. The ideas that people have and promote are part of what makes them who they are. You cannot criticize their ideas without criticizing them. That you make up some pet theory about how people *should* be does not change the reality of how people *are*. And when you apply anthropocentric terms to "an idea" (which obviously does not have "behavior" of it's own, the attempts of you and Chris to make that claim not withstanding) you reinforce the sense that you are talking about the person. If I said, "that's an idea that an asshole would think up", there is no one (other than perhaps you and Chris) who wouldn't recognize that I was calling you an asshole. Conversely, while you claim any incivility is allowable when criticizing an idea you claim there's a requirement to respect a person. Do you respect the terrorist who killed the hostages in Sydney a couple years ago? Or any number of other lowlifes? Or maybe you'll now waffle about and limit respect to speech? Suppose I came here and start spouting neo-Nazi racist rants. Do you seriously claim people should criticize my ideas but not me? That's so far from recognized human behavior that it justifies being called a crackpot theory. If you want to show respect to people whose ideas you disagree with or even disrespect you do so by leaving out the insults, the innuendos, the aggressive language, completely subjective and unprovable non-facts like "arrogant" and "stupid", and just make a rational case why the other person is wrong in your opinion. That also shows respect to other readers most of whom I bet dont want to read the constant verbal dueling that occurs so regularly here. Nobody is saying not to criticize: it is how it is done that is the problem. But of course that is nowhere near as much fun, is it? From r161637 at rguktrkv.ac.in Thu Nov 9 01:51:20 2017 From: r161637 at rguktrkv.ac.in (r161637 at rguktrkv.ac.in) Date: Wed, 8 Nov 2017 22:51:20 -0800 (PST) Subject: converting numbers into words Message-ID: <4ec09111-c8fe-436b-b1d3-2d2c58e5f06d@googlegroups.com> How can I covert numbers into word like ex:-123 One hundred twenty three? From jladasky at itu.edu Thu Nov 9 02:21:55 2017 From: jladasky at itu.edu (jladasky at itu.edu) Date: Wed, 8 Nov 2017 23:21:55 -0800 (PST) Subject: converting numbers into words In-Reply-To: <4ec09111-c8fe-436b-b1d3-2d2c58e5f06d@googlegroups.com> References: <4ec09111-c8fe-436b-b1d3-2d2c58e5f06d@googlegroups.com> Message-ID: <3180d6b3-ecc2-449c-9194-1c9749a64deb@googlegroups.com> On Wednesday, November 8, 2017 at 10:51:35 PM UTC-8, r16... at rguktrkv.ac.in wrote: > How can I covert numbers into word like ex:-123 One hundred twenty three? That's a classic homework exercise. Expect guidance, not an answer. Why don't you solve a related, but simpler task first? This is a good approach to learning computer programming. Write a program that accepts a single digit as input, and outputs the corresponding word. Post the code here. From greg.ewing at canterbury.ac.nz Thu Nov 9 02:53:01 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 09 Nov 2017 20:53:01 +1300 Subject: Ideas about how software should behave In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> Message-ID: Chris Angelico wrote: > I don't understand why you would use "yield from" as a synonym for > "await". They are not equivalent. Why would you use one in place of > the other? As far as I understand, currently the implementations of "yield from" and "await" are sufficiently similar that they *would* be equivalent if the compiler didn't go out of its way to prevent you from mixing them up. It does that because they're conceptually different things, and a future version of CPython might implement them differently. -- Greg From greg.ewing at canterbury.ac.nz Thu Nov 9 03:13:34 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 09 Nov 2017 21:13:34 +1300 Subject: Ideas about how software should behave In-Reply-To: References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> Message-ID: Chris Angelico wrote: > And it's illogical to say "Windows is feeling cranky today" when > something inexplicably fails. Everyone understands that to be a tongue-in-cheek metaphor for "Windows is misbehaving in unfathomable ways", and not "the people who wrote Windows were feeling cranky when they did it". But ideas are not software -- they don't actively *do* anything, so trying to anthropomorphise them doesn't really work. It's hard not to read "this idea is arrogant" as an implied criticism of the person putting forward the idea, even if it wasn't meant that way. There are plenty of good ways of criticising an idea that are clearly about the idea itself, so there is no need to resort to adjectives that could be misunderstood as veiled ad-hominem attacks. -- Greg From p.f.moore at gmail.com Thu Nov 9 03:49:44 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 9 Nov 2017 08:49:44 +0000 Subject: Ideas about how software should behave In-Reply-To: <85r2t8xcn0.fsf@benfinney.id.au> References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> <87bmkc35a5.fsf@elektro.pacujo.net> <85r2t8xcn0.fsf@benfinney.id.au> Message-ID: On 9 November 2017 at 05:08, Ben Finney wrote: > Marko Rauhamaa writes: > >> Jon Ribbens : >> > It is my experience of this group/list that if one disagrees with any >> > of you, Steve and Chris, you all rally round and gang up on that >> > person to insult and belittle them. This makes the atmosphere quite >> > hostile, and it would be quite remarkable if it isn't hurting the >> > community by driving people away. Please stop doing it. >> >> This forum is about a dead thing, a programming language. I wouldn't >> make too big a deal about "the community." > > On the contrary, this forum is about a *community of people*, formed > around a programming language. > > The community is primary here, I am in full agreement with Jon on that. 100% agreed. And on that note, shouldn't participants on this list follow the Python code of conduct[1]? Specifically, I don't see a lot of adherence to the mandate to be "tactful when approaching differing views" in this debate :-( Tact isn't about explaining how what *you* said shouldn't be taken the way the other person appears to be taking it. It's about accepting that the other person took your words in a particular way, and acknowledging and dealing with the fact that their interpretation is real to them, and should not be dismissed as "mistaken". Paul [1] https://www.python.org/psf/codeofconduct/ PS I won't respond to any explanations of how what I'm saying here is incorrect, or misguided. I don't want to further fan the flames. From lingmaaki at gmail.com Thu Nov 9 06:05:02 2017 From: lingmaaki at gmail.com (lingmaaki at gmail.com) Date: Thu, 9 Nov 2017 03:05:02 -0800 (PST) Subject: import issues python3.4 In-Reply-To: <6deb808f-0612-4ec8-958f-9eecbcc7c744@googlegroups.com> References: <6deb808f-0612-4ec8-958f-9eecbcc7c744@googlegroups.com> Message-ID: <1a5f0f64-cb09-46b8-9ec3-ef76052ebd30@googlegroups.com> Python Tutorial.... http://net-informations.com/python/default.htm From john_ladasky at sbcglobal.net Thu Nov 9 06:45:29 2017 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Thu, 9 Nov 2017 03:45:29 -0800 (PST) Subject: converting numbers into words (Posting On Python-List Prohibited) In-Reply-To: <31e3ed02-4e00-40fd-bd05-a2c1985e0f80@googlegroups.com> References: <4ec09111-c8fe-436b-b1d3-2d2c58e5f06d@googlegroups.com> <31e3ed02-4e00-40fd-bd05-a2c1985e0f80@googlegroups.com> Message-ID: On Wednesday, November 8, 2017 at 11:40:18 PM UTC-8, Lawrence D?Oliveiro wrote: > On Thursday, November 9, 2017 at 7:51:35 PM UTC+13, r16... at rguktrkv.ac.in wrote: > > > How can I covert numbers into word like ex:-123 One hundred twenty three? > > Here?s one I did earlier, in Algol 68. > > Conversion to Python is left as an exercise for the reader. I think that gives away rather more than I wanted the student to see. From marko at pacujo.net Thu Nov 9 06:58:32 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 09 Nov 2017 13:58:32 +0200 Subject: Ideas about how software should behave References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> Message-ID: <877euz3bpz.fsf@elektro.pacujo.net> Gregory Ewing : > There are plenty of good ways of criticising an idea that are clearly > about the idea itself, so there is no need to resort to adjectives > that could be misunderstood as veiled ad-hominem attacks. I disagree. Ad hominems are needed when you run out of reasoned arguments but feel the need to defend the honor of your dear programming language. Marko From bc at freeuk.com Thu Nov 9 08:23:10 2017 From: bc at freeuk.com (bartc) Date: Thu, 9 Nov 2017 13:23:10 +0000 Subject: converting numbers into words In-Reply-To: <4ec09111-c8fe-436b-b1d3-2d2c58e5f06d@googlegroups.com> References: <4ec09111-c8fe-436b-b1d3-2d2c58e5f06d@googlegroups.com> Message-ID: On 09/11/2017 06:51, r161637 at rguktrkv.ac.in wrote: > How can I covert numbers into word like ex:-123 One hundred twenty three? > google for something like "algorithm numbers to words". If this is homework, then it's not cheating as everyone else will be doing the same. > How can I covert numbers into word like ex:-123 One hundred twenty three? And you need to refine your specification of the task. I would render your example as: minus one hundred and twenty-three From christopher_reimer at icloud.com Thu Nov 9 08:26:28 2017 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Thu, 09 Nov 2017 05:26:28 -0800 Subject: converting numbers into words (Posting On Python-List Prohibited) In-Reply-To: References: <4ec09111-c8fe-436b-b1d3-2d2c58e5f06d@googlegroups.com> <31e3ed02-4e00-40fd-bd05-a2c1985e0f80@googlegroups.com> Message-ID: <547DD8E0-E695-49AA-9E31-857221C516D9@icloud.com> On Nov 9, 2017, at 3:45 AM, John Ladasky wrote: > >> On Wednesday, November 8, 2017 at 11:40:18 PM UTC-8, Lawrence D?Oliveiro wrote: >>> On Thursday, November 9, 2017 at 7:51:35 PM UTC+13, r16... at rguktrkv.ac.in wrote: >>> >>> How can I covert numbers into word like ex:-123 One hundred twenty three? >> >> Here?s one I did earlier, in Algol 68. >> >> Conversion to Python is left as an exercise for the reader. > > I think that gives away rather more than I wanted the student to see. > -- > https://mail.python.org/mailman/listinfo/python-list I thought the classic homework problem was to convert an Arabic numeral into a Roman numeral. Bonus points for correctly converting any number above 12 and/or copyright year from any old movie. Most students have seen Roman numerals on clocks (1-12). Maybe that's too hard for today's kids with digital clocks. Chris R. From rurpy at yahoo.com Thu Nov 9 10:14:55 2017 From: rurpy at yahoo.com (Rurpy) Date: Thu, 9 Nov 2017 15:14:55 +0000 (UTC) Subject: Ideas about how software should behave References: <1190311362.5114939.1510240495207.ref@mail.yahoo.com> Message-ID: <1190311362.5114939.1510240495207@mail.yahoo.com> On 11/08/2017 11:29 AM, Chris Angelico wrote: > [...] > Please, Jon, accept that we were not deliberately trying > to put you down. Steve, if you can clearly state your position on this > (possibly worded in the form of an apology?), it would go a long way > to clearing this up. > ChrisA Are you the same ChrisA who wrote in this very list just a month ago towards a poster you disagreed with: "Yep. Good reasons like that you're a moron." [*] Maybe you could set an example for Steve? It would go a long way to showing that you, Steven, Ben an a few others aren't setting a duel standard where favored regular "alpha male" posters can be as rude as they want but the Code of Conduct is dragged out to whack non-alphas when they respond the same way. [*] https://mail.python.org/pipermail/python-list/2017-October/727190.html From rosuav at gmail.com Thu Nov 9 11:33:04 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Nov 2017 03:33:04 +1100 Subject: Ideas about how software should behave In-Reply-To: <1190311362.5114939.1510240495207@mail.yahoo.com> References: <1190311362.5114939.1510240495207.ref@mail.yahoo.com> <1190311362.5114939.1510240495207@mail.yahoo.com> Message-ID: On Fri, Nov 10, 2017 at 2:14 AM, Rurpy via Python-list wrote: > On 11/08/2017 11:29 AM, Chris Angelico wrote: >> [...] >> Please, Jon, accept that we were not deliberately trying >> to put you down. Steve, if you can clearly state your position on this >> (possibly worded in the form of an apology?), it would go a long way >> to clearing this up. >> ChrisA > > Are you the same ChrisA who wrote in this very list just a month ago > towards a poster you disagreed with: > > "Yep. Good reasons like that you're a moron." [*] If I said that, there's more to it than just that I disagreed with the person. ChrisA From bc at freeuk.com Thu Nov 9 12:00:23 2017 From: bc at freeuk.com (bartc) Date: Thu, 9 Nov 2017 17:00:23 +0000 Subject: Ideas about how software should behave In-Reply-To: References: <1190311362.5114939.1510240495207.ref@mail.yahoo.com> <1190311362.5114939.1510240495207@mail.yahoo.com> Message-ID: On 09/11/2017 16:33, Chris Angelico wrote: > On Fri, Nov 10, 2017 at 2:14 AM, Rurpy via Python-list > wrote: >> On 11/08/2017 11:29 AM, Chris Angelico wrote: >>> [...] >>> Please, Jon, accept that we were not deliberately trying >>> to put you down. Steve, if you can clearly state your position on this >>> (possibly worded in the form of an apology?), it would go a long way >>> to clearing this up. >>> ChrisA >> >> Are you the same ChrisA who wrote in this very list just a month ago >> towards a poster you disagreed with: >> >> "Yep. Good reasons like that you're a moron." [*] > > If I said that, there's more to it than just that I disagreed with the person. Such as? From rosuav at gmail.com Thu Nov 9 12:04:48 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Nov 2017 04:04:48 +1100 Subject: Ideas about how software should behave In-Reply-To: References: <1190311362.5114939.1510240495207.ref@mail.yahoo.com> <1190311362.5114939.1510240495207@mail.yahoo.com> Message-ID: On Fri, Nov 10, 2017 at 4:00 AM, bartc wrote: > On 09/11/2017 16:33, Chris Angelico wrote: >> >> On Fri, Nov 10, 2017 at 2:14 AM, Rurpy via Python-list >> wrote: >>> >>> On 11/08/2017 11:29 AM, Chris Angelico wrote: >>>> >>>> [...] >>>> Please, Jon, accept that we were not deliberately trying >>>> to put you down. Steve, if you can clearly state your position on this >>>> (possibly worded in the form of an apology?), it would go a long way >>>> to clearing this up. >>>> ChrisA >>> >>> >>> Are you the same ChrisA who wrote in this very list just a month ago >>> towards a poster you disagreed with: >>> >>> "Yep. Good reasons like that you're a moron." [*] >> >> >> If I said that, there's more to it than just that I disagreed with the >> person. > > > Such as? > I don't know. Why don't you go read the thread? ChrisA From grant.b.edwards at gmail.com Thu Nov 9 12:17:20 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 9 Nov 2017 17:17:20 +0000 (UTC) Subject: converting numbers into words References: <4ec09111-c8fe-436b-b1d3-2d2c58e5f06d@googlegroups.com> Message-ID: On 2017-11-09, r161637 at rguktrkv.ac.in wrote: > How can I covert numbers into word like ex:-123 One hundred twenty three? That's one of the classic freshman intro-to-programming homework problems. I remember having to write a Pascal program to do that back in the 70's... -- Grant Edwards grant.b.edwards Yow! Are we laid back yet? at gmail.com From bc at freeuk.com Thu Nov 9 12:24:11 2017 From: bc at freeuk.com (bartc) Date: Thu, 9 Nov 2017 17:24:11 +0000 Subject: Ideas about how software should behave In-Reply-To: References: <1190311362.5114939.1510240495207.ref@mail.yahoo.com> <1190311362.5114939.1510240495207@mail.yahoo.com> Message-ID: On 09/11/2017 17:04, Chris Angelico wrote: > On Fri, Nov 10, 2017 at 4:00 AM, bartc wrote: >> On 09/11/2017 16:33, Chris Angelico wrote: >>> >>> On Fri, Nov 10, 2017 at 2:14 AM, Rurpy via Python-list >>> wrote: >>>> >>>> On 11/08/2017 11:29 AM, Chris Angelico wrote: >>>>> >>>>> [...] >>>>> Please, Jon, accept that we were not deliberately trying >>>>> to put you down. Steve, if you can clearly state your position on this >>>>> (possibly worded in the form of an apology?), it would go a long way >>>>> to clearing this up. >>>>> ChrisA >>>> >>>> >>>> Are you the same ChrisA who wrote in this very list just a month ago >>>> towards a poster you disagreed with: >>>> >>>> "Yep. Good reasons like that you're a moron." [*] >>> >>> >>> If I said that, there's more to it than just that I disagreed with the >>> person. >> >> >> Such as? >> > > I don't know. Why don't you go read the thread? I did. You seemed to have disagreed very strongly with someone else's opinions. The context was a set of UI annoyances of BC: BC: >> There are dozens more, yet you are surprised why sometimes I prefer doing >> things my own way? There are good reasons! CA: > Yep. Good reasons like that you're a moron. You assume that since > *you* have never needed to produce one lower-case letter in a block of > upper-case, that "probably no one else has", and then you make it > impossible to do that in your editor. I have wanted to produce a > lower-case letter by holding Shift. I have also used this behaviour to > detect and recognize faults of various sorts. Do you understand the > concept of debugging a system by getting more information, not less? (Thread "The loop and a half", around 19:10 UK time 8/10/17.) -- bartc From torriem at gmail.com Thu Nov 9 12:41:17 2017 From: torriem at gmail.com (Michael Torrie) Date: Thu, 9 Nov 2017 10:41:17 -0700 Subject: Ideas about how software should behave In-Reply-To: References: <1190311362.5114939.1510240495207.ref@mail.yahoo.com> <1190311362.5114939.1510240495207@mail.yahoo.com> Message-ID: On 11/09/2017 09:33 AM, Chris Angelico wrote: > On Fri, Nov 10, 2017 at 2:14 AM, Rurpy via Python-list > wrote: >> On 11/08/2017 11:29 AM, Chris Angelico wrote: >>> [...] >>> Please, Jon, accept that we were not deliberately trying >>> to put you down. Steve, if you can clearly state your position on this >>> (possibly worded in the form of an apology?), it would go a long way >>> to clearing this up. >>> ChrisA >> >> Are you the same ChrisA who wrote in this very list just a month ago >> towards a poster you disagreed with: >> >> "Yep. Good reasons like that you're a moron." [*] > > If I said that, there's more to it than just that I disagreed with the person. But how does that justify the comment? Sounds like a rationalization to me. A little humility on all our parts goes a long ways. One can apologize for offense taken, even if none was intended, and even if my own opinion is still strongly held. From rhodri at kynesim.co.uk Thu Nov 9 12:51:19 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 9 Nov 2017 17:51:19 +0000 Subject: Ideas about how software should behave In-Reply-To: References: <1190311362.5114939.1510240495207.ref@mail.yahoo.com> <1190311362.5114939.1510240495207@mail.yahoo.com> Message-ID: On 09/11/17 17:41, Michael Torrie wrote: > On 11/09/2017 09:33 AM, Chris Angelico wrote: >> On Fri, Nov 10, 2017 at 2:14 AM, Rurpy via Python-list >> wrote: >>> On 11/08/2017 11:29 AM, Chris Angelico wrote: >>>> [...] >>>> Please, Jon, accept that we were not deliberately trying >>>> to put you down. Steve, if you can clearly state your position on this >>>> (possibly worded in the form of an apology?), it would go a long way >>>> to clearing this up. >>>> ChrisA >>> >>> Are you the same ChrisA who wrote in this very list just a month ago >>> towards a poster you disagreed with: >>> >>> "Yep. Good reasons like that you're a moron." [*] >> >> If I said that, there's more to it than just that I disagreed with the person. > > But how does that justify the comment? Sounds like a rationalization to > me. A little humility on all our parts goes a long ways. One can > apologize for offense taken, even if none was intended, and even if my > own opinion is still strongly held. But some people really do behave moronically on this list. I generally killfile them before the urge to insult gets too strong, but I do see Chris's point; leaving people with the idea that unacceptable behaviour is acceptable is a service to no one. -- Rhodri James *-* Kynesim Ltd From rurpy at yahoo.com Thu Nov 9 12:51:58 2017 From: rurpy at yahoo.com (Rurpy) Date: Thu, 9 Nov 2017 17:51:58 +0000 (UTC) Subject: Ideas about how software should behave References: <987886108.5223397.1510249918381.ref@mail.yahoo.com> Message-ID: <987886108.5223397.1510249918381@mail.yahoo.com> On 11/09/2017 09:33 AM, Chris Angelico wrote: > On Fri, Nov 10, 2017 at 2:14 AM, Rurpy via Python-list wrote: >> On 11/08/2017 11:29 AM, Chris Angelico wrote: >>> [...] >>> Please, Jon, accept that we were not deliberately trying >>> to put you down. Steve, if you can clearly state your position on this >>> (possibly worded in the form of an apology?), it would go a long way >>> to clearing this up. >>> ChrisA >> >> Are you the same ChrisA who wrote in this very list just a month ago >> towards a poster you disagreed with: >> >> "Yep. Good reasons like that you're a moron." [*] > > If I said that, there's more to it than just that I disagreed with the person. "If"? You are not sure? I included a link to your message in my post which you seem to have cut. Here it is again: https://mail.python.org/pipermail/python-list/2017-October/727190.html If it is a forgery, maybe the moderators can remove it. But unless you want to categorically deny you wrote it, I think we can assume that you did. I stand by what I've claimed on several occasions: that offensive (and CoC violating) posts such as your's and Steven's are regularly posted by a handful of regulars here, and not only are there typically no objections but other members of the cabal actually jump in to defend the bad behavior. From dvl at psu.edu Thu Nov 9 13:14:16 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Thu, 9 Nov 2017 13:14:16 -0500 Subject: Ideas about how software should behave In-Reply-To: mailman.27.1510246805.7117.python-list@python.org References: Message-ID: <1510251256l.38666324l.0l@psu.edu> On Thu, Nov 9, 2017, Gregory Ewing wrote:> But ideas are not software -- they don't actively >*do* anything, so trying to anthropomorphise them >doesn't really work. Generally true. I just remember the notable exception: Colorless green ideas sleep furiously. That case of anthropomorphism works just as well as it was intended. As far as this whole thing about criticism being taken personally, I just can't get a certain sketch out of my head: ".. but I came here for an argument!" "Oh, oh! I'm sorry! This is abuse!... You want room 12A next door." It is hard to tell the difference sometimes. But on this count, I would still try to find the distinction about whether a particular idea seems to ridiculous, or arrogant, as an anomalous statement from the presenter vs. it being representative of a regular pattern. I think many of the posters here appear commonly enough to place the spirit of a particular post in the context of their general presentation style. Roger Christman Pennsylvania State University On Thu, Nov 9, 2017, Gregory Ewing wrote:But ideas are not software -- they don't actively *do* anything, so trying to anthropomorphise them doesn't really work. From rurpy at yahoo.com Thu Nov 9 13:43:31 2017 From: rurpy at yahoo.com (Rurpy) Date: Thu, 9 Nov 2017 18:43:31 +0000 (UTC) Subject: Ideas about how software should behave References: <468452825.5271661.1510253011072.ref@mail.yahoo.com> Message-ID: <468452825.5271661.1510253011072@mail.yahoo.com> On 11/09/2017 10:51 AM, Rhodri James wrote: > On 09/11/17 17:41, Michael Torrie wrote: >> On 11/09/2017 09:33 AM, Chris Angelico wrote: >>> On Fri, Nov 10, 2017 at 2:14 AM, Rurpy via Python-list >>> wrote: >>>> On 11/08/2017 11:29 AM, Chris Angelico wrote: >>>>> [...] Please, Jon, accept that we were not deliberately >>>>> trying to put you down. Steve, if you can clearly state your >>>>> position on this (possibly worded in the form of an >>>>> apology?), it would go a long way to clearing this up. >>>>> ChrisA >>>> >>>> Are you the same ChrisA who wrote in this very list just a >>>> month ago towards a poster you disagreed with: >>>> >>>> "Yep. Good reasons like that you're a moron." [*] >>> >>> If I said that, there's more to it than just that I disagreed >>> with the person. >> >> But how does that justify the comment? Sounds like a >> rationalization to me. A little humility on all our parts goes a >> long ways. One can apologize for offense taken, even if none was >> intended, and even if my own opinion is still strongly held. > > But some people really do behave moronically on this list. I > generally killfile them before the urge to insult gets too strong, > but I do see Chris's point; leaving people with the idea that > unacceptable behaviour is acceptable is a service to no one. "unacceptable behavior" being having an opinion different than Chris'? And a response of "you're a moron" is quite acceptable in your opinion? You are obviously not alone in feeling that way but if that is the defacto policy here then the CoC should be changed to reflect that. From ben+python at benfinney.id.au Thu Nov 9 16:51:19 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 10 Nov 2017 08:51:19 +1100 Subject: Ideas about how software should behave References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> <87bmkc35a5.fsf@elektro.pacujo.net> <85r2t8xcn0.fsf@benfinney.id.au> Message-ID: <85mv3vxgrs.fsf@benfinney.id.au> Paul Moore writes: > And on that note, shouldn't participants on this list follow the > Python code of conduct[1]? Specifically, I don't see a lot of > adherence to the mandate to be "tactful when approaching differing > views" in this debate :-( Yes, we should all adhere to the forum's Code of Conduct. Where I've not done that ? and certainly it happens often enough ? I want to know, and to work harder to live up to it, without compromising the critical examination of ideas expressed. > Tact isn't about explaining how what *you* said shouldn't be taken the > way the other person appears to be taking it. It's about accepting > that the other person took your words in a particular way, and > acknowledging and dealing with the fact that their interpretation is > real to them, and should not be dismissed as "mistaken". I accept all of that, and I do think tact is too often in short supply. -- \ ?Begin with false premises and you risk reaching false | `\ conclusions. Begin with falsified premises and you forfeit your | _o__) authority.? ?Kathryn Schulz, 2015-10-19 | Ben Finney From smtbportal at gmail.com Fri Nov 10 06:51:26 2017 From: smtbportal at gmail.com (smtbportal at gmail.com) Date: Fri, 10 Nov 2017 03:51:26 -0800 (PST) Subject: Test bank and Solutions Manual for Microeconomics (8th Edition) (The Pearson Series in Economics) 8th Edition, 8th e, 8e by Jeffrey M. Perloff Message-ID: Dear Students, To get Test bank and Solutions Manual for Microeconomics (8th Edition) (The Pearson Series in Economics) 8th Edition,8th e,8e by Jeffrey M. Perloff Contact us 24/7 at smtbportal @ gmail dot com, smtbportal @ hotmail . com Please DO NOT POST/REPLY HERE, just email us at smtbportal (@) gmail (dot) com Good Luck with your Exams. From smtbportal at gmail.com Fri Nov 10 06:51:40 2017 From: smtbportal at gmail.com (smtbportal at gmail.com) Date: Fri, 10 Nov 2017 03:51:40 -0800 (PST) Subject: Test bank and Solutions Manual for Criminology Today: An Integrative Introduction 8th Edition,8th e,8e by Frank Schmalleger Message-ID: <8dfac364-f371-4eca-afee-b928bbf4ac76@googlegroups.com> Dear Students, To get Test bank and Solutions Manual for Criminology Today: An Integrative Introduction 8th Edition,8th e,8e by Frank Schmalleger Contact us 24/7 at smtbportal @ gmail dot com, smtbportal @ hotmail . com Please DO NOT POST/REPLY HERE, just email us at smtbportal (@) gmail (dot) com Good Luck with your Exams. From smtbportal at gmail.com Fri Nov 10 06:52:33 2017 From: smtbportal at gmail.com (smtbportal at gmail.com) Date: Fri, 10 Nov 2017 03:52:33 -0800 (PST) Subject: Test bank and Solutions Manual for Financial Accounting 17th Edition, 8th e, 8e by Jan Williams, Susan Haka, Mark S Bettner, Joseph V Carcello Message-ID: Dear Students, To get Test bank and Solutions Manual for Financial Accounting 17th Edition,8th e,8e by Jan Williams,Susan Haka,Mark S Bettner, Joseph V Carcello Contact us 24/7 at smtbportal @ gmail dot com, smtbportal @ hotmail . com Please DO NOT POST/REPLY HERE, just email us at smtbportal (@) gmail (dot) com Good Luck with your Exams. From smtbportal at gmail.com Fri Nov 10 06:53:06 2017 From: smtbportal at gmail.com (smtbportal at gmail.com) Date: Fri, 10 Nov 2017 03:53:06 -0800 (PST) Subject: Test bank and Solutions Manual for Managerial Accounting 6th Edition,8th e,8e by John J Wild, Ken W. Shaw, Barbara Chiappetta Message-ID: Dear Students, To get Test bank and Solutions Manual for Managerial Accounting 6th Edition,8th e,8e by John J Wild, Ken W. Shaw, Barbara Chiappetta Contact us 24/7 at smtbportal @ gmail dot com, smtbportal @ hotmail . com Please DO NOT POST/REPLY HERE, just email us at smtbportal (@) gmail (dot) com Good Luck with your Exams. From smtbportal at gmail.com Fri Nov 10 06:53:46 2017 From: smtbportal at gmail.com (smtbportal at gmail.com) Date: Fri, 10 Nov 2017 03:53:46 -0800 (PST) Subject: Test bank and Solutions Manual for Managerial Accounting 16th Edition,16th e, 16e by Ray H Garrison, Eric Noreen, Peter C. Brewer Message-ID: <5a528f7f-184c-4b25-81ab-366f5a24a485@googlegroups.com> Dear Students, To get Test bank and Solutions Manual for Managerial Accounting 16th Edition,16th e, 16e by Ray H Garrison, Eric Noreen, Peter C. Brewer Contact us 24/7 at smtbportal @ gmail dot com, smtbportal @ hotmail . com Please DO NOT POST/REPLY HERE, just email us at smtbportal (@) gmail (dot) com Good Luck with your Exams. From smtbportal at gmail.com Fri Nov 10 06:57:46 2017 From: smtbportal at gmail.com (smtbportal at gmail.com) Date: Fri, 10 Nov 2017 03:57:46 -0800 (PST) Subject: Test bank and Solutions Manual for Intermediate Accounting 9th Edition,9th e,9e by J. David Spiceland,Mark W. Nelson, Wayne M Thomas Message-ID: <6940a33c-9da9-480c-88c4-f335614a7e73@googlegroups.com> Dear Students, To get Test bank and Solutions Manual for Intermediate Accounting 9th Edition,9th e,9e by J. David Spiceland,Mark W. Nelson, Wayne M Thomas Contact us 24/7 at smtbportal @ gmail dot com, smtbportal @ hotmail . com Please DO NOT POST/REPLY HERE, just email us at smtbportal (@) gmail (dot) com Good Luck with your Exams. From smtbportal at gmail.com Fri Nov 10 06:57:58 2017 From: smtbportal at gmail.com (smtbportal at gmail.com) Date: Fri, 10 Nov 2017 03:57:58 -0800 (PST) Subject: Test bank and Solutions Manual for ACCOUNTING INFORMATION SYSTEMS 2nd Edition,2nd e,2e by Richardson,Janie Chang Vern Odmark,Rod E. Smith Message-ID: Dear Students, To get Test bank and Solutions Manual for ACCOUNTING INFORMATION SYSTEMS 2nd Edition,2nd e,2e by Richardson,Janie Chang Vern Odmark,Rod E. Smith Contact us 24/7 at smtbportal @ gmail dot com, smtbportal @ hotmail . com Please DO NOT POST/REPLY HERE, just email us at smtbportal (@) gmail (dot) com Good Luck with your Exams. From smtbportal at gmail.com Fri Nov 10 06:58:28 2017 From: smtbportal at gmail.com (smtbportal at gmail.com) Date: Fri, 10 Nov 2017 03:58:28 -0800 (PST) Subject: Test bank and Solutions Manual for Financial Accounting Fundamentals 6th Edition,6th e,6e by John J Wild, Ken W. Shaw,Chiappetta Message-ID: <3333b20a-eeb1-4066-9c05-fc9a498332d2@googlegroups.com> Dear Students, To get Test bank and Solutions Manual for Financial Accounting Fundamentals 6th Edition,6th e,6e by John J Wild, Ken W. Shaw,Chiappetta Contact us 24/7 at smtbportal @ gmail dot com, smtbportal @ hotmail . com Please DO NOT POST/REPLY HERE, just email us at smtbportal (@) gmail (dot) com Good Luck with your Exams. From smtbportal at gmail.com Fri Nov 10 06:58:40 2017 From: smtbportal at gmail.com (smtbportal at gmail.com) Date: Fri, 10 Nov 2017 03:58:40 -0800 (PST) Subject: Test bank and Solutions Manual for McGraw-Hill's Essentials of Federal Taxation 2018 Edition 9th Edition,9th e,9e by Brian C. Spilker, Benjamin C. Ayers, John Robinson, Edmund Outslay, Worsham, Barrick, Weaver Message-ID: Dear Students, To get Test bank and Solutions Manual for McGraw-Hill's Essentials of Federal Taxation 2018 Edition 9th Edition,9th e,9e by Brian C. Spilker,Benjamin C. Ayers,John Robinson,Edmund Outslay,Worsham,Barrick,Weaver Contact us 24/7 at smtbportal @ gmail dot com, smtbportal @ hotmail . com Please DO NOT POST/REPLY HERE, just email us at smtbportal (@) gmail (dot) com Good Luck with your Exams. From m at funkyhat.org Fri Nov 10 08:59:50 2017 From: m at funkyhat.org (Matt Wheeler) Date: Fri, 10 Nov 2017 13:59:50 +0000 (UTC) Subject: import issues python3.4 In-Reply-To: <6deb808f-0612-4ec8-958f-9eecbcc7c744@googlegroups.com> References: <6deb808f-0612-4ec8-958f-9eecbcc7c744@googlegroups.com> Message-ID: On Wed, 8 Nov 2017 at 15:58 Heli wrote: > Is there anyway I can run my external script without changing the absolute > path from (1) to (2) in my code. > I would recommend using tox [0] to run your test script, and setting up an entry point in your `setup.py` [1] so that your `main` command is "installed" when you install the package. This also means that regular users of your package will be able to run the script by just typing the command name you choose, instead of needing to know exactly where the package got installed. > I use subprocess.call to run main.py within my external script and it gets > few arguments to run. tox handles setting up a virtualenv & installing your packages into it, which means in the context of your tox run, when your test script calls out to your `main` "entry point" using `subprocess.call` it will be available in the local $PATH [0] https://tox.readthedocs.io/en/latest/ [1] http://setuptools.readthedocs.io/en/latest/setuptools.html#dynamic-discovery-of-services-and-plugins -- -- Matt Wheeler http://funkyh.at From kirillbalunov at gmail.com Fri Nov 10 09:16:50 2017 From: kirillbalunov at gmail.com (Kirill Balunov) Date: Fri, 10 Nov 2017 17:16:50 +0300 Subject: What is the future of the PEP 467? Message-ID: What is the future of the PEP 467 ("Minor API improvements for binary sequences")? It was not accepted and was not rejected, although there was a rather active discussion. In addition to what is stated in the PEP, I would like to know your opinion on the additional issue: At present, the repr() and str() of bytes return the same thing - which looks more as "binary string". May be it is better if the repr() will return "binary sequence" -> only escaped hex values. While the str() representation would return the same thing as now (some ascii analogue)? - with kind regards, gdg From ian.g.kelly at gmail.com Fri Nov 10 16:24:55 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 10 Nov 2017 14:24:55 -0700 Subject: What is the future of the PEP 467? In-Reply-To: References: Message-ID: On Fri, Nov 10, 2017 at 7:16 AM, Kirill Balunov wrote: > What is the future of the PEP 467 ("Minor API improvements for binary > sequences")? It was not accepted and was not rejected, although there was a > rather active discussion. I don't know. This is probably a question for python-dev. > In addition to what is stated in the PEP, I would like to know your opinion > on the additional issue: > At present, the repr() and str() of bytes return the same thing - which > looks more as "binary string". May be it is better if the repr() will > return "binary sequence" -> only escaped hex values. Why would this be better? For bytes objects that are based on ASCII or UTF-8 strings it will make them harder to read. For users who might be using the repr() to serialize the bytes object, it will make the serialization larger. Also, the str() of a container like a list uses the repr() of its contents, so while readability is not the main goal of a repr() it is still a good thing to have. From ned at nedbatchelder.com Fri Nov 10 17:15:52 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 10 Nov 2017 17:15:52 -0500 Subject: Ideas about how software should behave In-Reply-To: <87bmkc35a5.fsf@elektro.pacujo.net> References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> <87bmkc35a5.fsf@elektro.pacujo.net> Message-ID: <407bc8ad-4200-df3c-77d4-eb334a5e79be@nedbatchelder.com> On 11/8/17 3:05 PM, Marko Rauhamaa wrote: > Jon Ribbens : >> It is my experience of this group/list that if one disagrees with any >> of you, Steve and Chris, you all rally round and gang up on that >> person to insult and belittle them. This makes the atmosphere quite >> hostile, and it would be quite remarkable if it isn't hurting the >> community by driving people away. Please stop doing it. > This forum is about a dead thing, a programming language. I wouldn't > make too big a deal about "the community." > > If someone's postings constantly frustrate you, simply place them in > your killfile. I've done that to people. People have done that to me. > > Tolerating bad behavior and advising people to cope by kill-filing is terrible advice. It means the bad behavior continues, unseen by regulars, and newcomers find a place rife with muck, unaddressed. Use a kill file if you like, but that is not the way the group as a whole is going to deal with it. --Ned. From ned at nedbatchelder.com Fri Nov 10 17:21:18 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 10 Nov 2017 17:21:18 -0500 Subject: Ideas about how software should behave In-Reply-To: <85vaikxhq9.fsf@benfinney.id.au> References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> <851sl8za0l.fsf@benfinney.id.au> <7c3a7837-9faa-db89-85f5-79993436d138@nedbatchelder.com> <85vaikxhq9.fsf@benfinney.id.au> Message-ID: On 11/8/17 10:18 PM, Ben Finney wrote: >> How many paragraphs of close parsing are we going to twist ourselves >> through, just to avoid saying, "Yeah, sorry, that went a bit far.? I >> didn't want to alienate you in the pursuit of a demonstration of my >> own correctness." > I don't have any aim of avoiding that. If I need to apologise for > something, that hasn't been made clear to me. If you're seeking an > apology from someone else, I can't do it for them. You have nothing to apologize for.? This started because of an exchange between Steve and Jon.? Steve has been notably silent during the ensuing discussion. > > What has been made clear to me is that we have a long way to go in > pursuit of allowing ideas to be held at arm's length, discussed and > criticised, with respect and compassion for one another. Indeed.? Beyond just respect and compassion, this discussion has mentioned "changing people's minds" a few times.? How's that going? Calling an idea "arrogant" may or may not be reasonable (I'm divided on this question myself).? But is it an effective way to change the person's mind?? It's a great term to use if you want to smack someone down, and convince everyone else that you are right.? But it's going to put the other person on the defensive, and you've lost your chance to change their mind. Both of the terms that have been brought up recently ("arrogant" and "moronic") seem ineffective to me.? If the goal truly is to engage in a discussion that will bring everyone to a point of agreement, then we have to choose words more wisely.? These words seem to me to have been chosen with a different goal. --Ned. From ben+python at benfinney.id.au Fri Nov 10 18:03:53 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 11 Nov 2017 10:03:53 +1100 Subject: Ideas about how software should behave References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> <851sl8za0l.fsf@benfinney.id.au> <7c3a7837-9faa-db89-85f5-79993436d138@nedbatchelder.com> <85vaikxhq9.fsf@benfinney.id.au> Message-ID: <85efp5ybvq.fsf@benfinney.id.au> Ned Batchelder writes: > On 11/8/17 10:18 PM, Ben Finney wrote: > > What has been made clear to me is that we have a long way to go in > > pursuit of allowing ideas to be held at arm's length, discussed and > > criticised, with respect and compassion for one another. > > Indeed.? Beyond just respect and compassion, this discussion has > mentioned "changing people's minds" a few times.? How's that going? Impressively well, in my opinion. This is a forum that is worthy of its reputation for respecting its participants by critically examining problems and ideas, while resisting personal abuse. That's valuable to me, which is why I am passionately defending that tradition. -- \ ?The only tyrant I accept in this world is the still voice | `\ within.? ?Mohandas K. Gandhi | _o__) | Ben Finney From ned at nedbatchelder.com Fri Nov 10 20:52:49 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 10 Nov 2017 20:52:49 -0500 Subject: Ideas about how software should behave In-Reply-To: <85efp5ybvq.fsf@benfinney.id.au> References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> <851sl8za0l.fsf@benfinney.id.au> <7c3a7837-9faa-db89-85f5-79993436d138@nedbatchelder.com> <85vaikxhq9.fsf@benfinney.id.au> <85efp5ybvq.fsf@benfinney.id.au> Message-ID: On 11/10/17 6:03 PM, Ben Finney wrote: > Ned Batchelder writes: > >> On 11/8/17 10:18 PM, Ben Finney wrote: >>> What has been made clear to me is that we have a long way to go in >>> pursuit of allowing ideas to be held at arm's length, discussed and >>> criticised, with respect and compassion for one another. >> Indeed.? Beyond just respect and compassion, this discussion has >> mentioned "changing people's minds" a few times.? How's that going? > Impressively well, in my opinion. It seems to me that Steve has not changed Jon's mind at all. Abrasive words don't change people's minds. --Ned. From ben+python at benfinney.id.au Fri Nov 10 21:13:36 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 11 Nov 2017 13:13:36 +1100 Subject: Ideas about how software should behave References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> <851sl8za0l.fsf@benfinney.id.au> <7c3a7837-9faa-db89-85f5-79993436d138@nedbatchelder.com> <85vaikxhq9.fsf@benfinney.id.au> <85efp5ybvq.fsf@benfinney.id.au> Message-ID: <854lq1y33j.fsf@benfinney.id.au> Ned Batchelder writes: > On 11/10/17 6:03 PM, Ben Finney wrote: > > Ned Batchelder writes: > >> Beyond just respect and compassion, this discussion has mentioned > >> "changing people's minds" a few times.? How's that going? > > Impressively well, in my opinion. > > It seems to me that Steve has not changed Jon's mind at all. Oh, my comment wasn't intending to speak for any of the participants in this thread on whether their minds are changed. I didn't realise that's what you wanted to ascertain. I was giving the general response that, admirably often, I see people's opinions changed here as a result of discussing an idea and critically examining it, respecting the members here to engage with ideas and get to the truth of a matter. It works well, and it's a reason I recommend people to this forum. -- \ ?That's all very good in practice, but how does it work in | `\ *theory*?? ?anonymous | _o__) | Ben Finney From marko at pacujo.net Fri Nov 10 23:52:00 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 11 Nov 2017 06:52:00 +0200 Subject: Ideas about how software should behave References: <1509570761.4585.0@smtp.gmail.com> <59fb4075$0$18561$b1db1813$d948b532@news.astraweb.com> <59fbc01b$0$18593$b1db1813$d948b532@news.astraweb.com> <85375u1taz.fsf_-_@benfinney.id.au> <85fu9pzowc.fsf@benfinney.id.au> <5a9f1157-663e-bb16-d370-f6bcfa29b89f@nedbatchelder.com> <85bmkdyopd.fsf@benfinney.id.au> <87bmkc35a5.fsf@elektro.pacujo.net> <407bc8ad-4200-df3c-77d4-eb334a5e79be@nedbatchelder.com> Message-ID: <87lgjdxvrj.fsf@elektro.pacujo.net> Ned Batchelder : > On 11/8/17 3:05 PM, Marko Rauhamaa wrote: >> If someone's postings constantly frustrate you, simply place them in >> your killfile. I've done that to people. People have done that to me. > > Tolerating bad behavior and advising people to cope by kill-filing is > terrible advice. It means the bad behavior continues, unseen by > regulars, and newcomers find a place rife with muck, unaddressed. Use > a kill file if you like, but that is not the way the group as a whole > is going to deal with it. Outright abuse should not be tolerated; that's just general humanity. However, not all obnoxiousness is abuse. If a thread is off topic or too long, or if someone has an irritating style or frustrates you otherwise, the best way to deal with it is to skip the discussion or plonk the individual. I don't believe I normally would use such crude expressions myself, but calling some idea idiocy in an intellectual debate is *not* automatically abuse. Marko From jfong at ms4.hinet.net Sat Nov 11 06:56:11 2017 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sat, 11 Nov 2017 03:56:11 -0800 (PST) Subject: How to modify this from Python 2.x to v3.4? Message-ID: <9fb5a25b-3fb0-4587-968c-69dbf6997a8f@googlegroups.com> I learned python start from using v3.4 and never has any v2.x experience. There is a Pypi project "ctypesgen" I like to use, but it seems is for v2.x. (un)Fortunately I found one of its branch on github which announced is for Python3, but strangely it still use some v2.x words, for example, print. Its last update was at July 2009, maybe at the early age of v3? The one below which I can't figure out how to modify. Can someone show me the answer? (I don't want to spend time on learning the old history:-) --------------------- # Available instance types. This is used when lexers are defined by a class. # It's a little funky because I want to preserve backwards compatibility # with Python 2.0 where types.ObjectType is undefined. try: _INSTANCETYPE = (types.InstanceType, types.ObjectType) except AttributeError: _INSTANCETYPE = types.InstanceType class object: pass # Note: needed if no new-style classes present ... ... ... if module: # User supplied a module object. if isinstance(module, types.ModuleType): ldict = module.__dict__ elif isinstance(module, _INSTANCETYPE): _items = [(k,getattr(module,k)) for k in dir(module)] ... ... --------------- Best Regards, Jach Fong From ned at nedbatchelder.com Sat Nov 11 07:48:48 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 11 Nov 2017 07:48:48 -0500 Subject: How to modify this from Python 2.x to v3.4? In-Reply-To: <9fb5a25b-3fb0-4587-968c-69dbf6997a8f@googlegroups.com> References: <9fb5a25b-3fb0-4587-968c-69dbf6997a8f@googlegroups.com> Message-ID: <0f2b5cac-9ad5-069d-cf3f-442267544247@nedbatchelder.com> On 11/11/17 6:56 AM, jfong at ms4.hinet.net wrote: > I learned python start from using v3.4 and never has any v2.x experience. There is a Pypi project "ctypesgen" I like to use, but it seems is for v2.x. (un)Fortunately I found one of its branch on github which announced is for Python3, but strangely it still use some v2.x words, for example, print. Its last update was at July 2009, maybe at the early age of v3? The one below which I can't figure out how to modify. Can someone show me the answer? (I don't want to spend time on learning the old history:-) > > --------------------- > # Available instance types. This is used when lexers are defined by a class. > # It's a little funky because I want to preserve backwards compatibility > # with Python 2.0 where types.ObjectType is undefined. > > try: > _INSTANCETYPE = (types.InstanceType, types.ObjectType) > except AttributeError: > _INSTANCETYPE = types.InstanceType > class object: pass # Note: needed if no new-style classes present > ... > ... > ... > if module: > # User supplied a module object. > if isinstance(module, types.ModuleType): > ldict = module.__dict__ > elif isinstance(module, _INSTANCETYPE): > _items = [(k,getattr(module,k)) for k in dir(module)] > This looks like fairly advanced code.? It will be difficult to port to Python 3 *without* understanding some of the old history.? There seem to be forks on GitHub, including one with a pull request about Python 3 made in the last few days: https://github.com/davidjamesca/ctypesgen/pull/58 .? I'd recommend working with others on this. --Ned. From skip.montanaro at gmail.com Sat Nov 11 18:27:07 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 11 Nov 2017 17:27:07 -0600 Subject: Need some help with Python Job Board In-Reply-To: References: Message-ID: The Python Job Board could use a little help in a couple areas. One, we can always use help reviewing and approving (or rejecting) submissions. The backlog keeps growing, and the existing volunteers who help can't always keep up. (This is a good problem to have, reflecting on Python's broad popularity in many application domains.) Two, and perhaps more important, the submission form really needs to support WYSIWYG editing. Apparently, most posters are unable to handle markup-based systems, probably just pasting content from Word documents. Making this change would streamline the review process, as formatting problems are currently the biggest impediment to successful submissions. There is an open ticket to add this feature: https://github.com/python/pythondotorg/issues/655 If you can help with either task, please drop a note to jobs at python.org. Thanks, Skip From tonysmart.ct at gmail.com Sat Nov 11 20:08:08 2017 From: tonysmart.ct at gmail.com (tonysmart.ct at gmail.com) Date: Sat, 11 Nov 2017 17:08:08 -0800 (PST) Subject: Hide text in entry box when i click on it.(GUI using Tkinter in python) In-Reply-To: References: <01419236-7cb8-498e-b3bb-9f209b1db53e@googlegroups.com> Message-ID: Thanks it was helpful From jfong at ms4.hinet.net Sat Nov 11 21:06:52 2017 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sat, 11 Nov 2017 18:06:52 -0800 (PST) Subject: How to modify this from Python 2.x to v3.4? In-Reply-To: References: <9fb5a25b-3fb0-4587-968c-69dbf6997a8f@googlegroups.com> <0f2b5cac-9ad5-069d-cf3f-442267544247@nedbatchelder.com> Message-ID: <7ca60f86-68fa-4ff8-8b53-fc5e2d6e76e3@googlegroups.com> Ned Batchelder? 2017?11?11???? UTC+8??8?49?27???? > This looks like fairly advanced code.? It will be difficult to port to > Python 3 *without* understanding some of the old history.? There seem to > be forks on GitHub, including one with a pull request about Python 3 > made in the last few days: > https://github.com/davidjamesca/ctypesgen/pull/58 .? I'd recommend > working with others on this. Thank you, Ned. As I remember that I had opened a thread here last year, trying to use "2To3" tool to convert the ctypesgen package, but didn't success. https://groups.google.com/forum/#!topic/comp.lang.python/9G0FJXmtwbA This time, somehow I find this "ctypesgen-python-3" package and can't wait to give it a try, but is disappointed again. I suppose there are many v3.x users who like to use ctypesgen to ease the using of ctypes. But obviously, it's not an easy work to do, convert 2 to 3:-) By the way, does anyone know what the following codes does? (in printer.py file) and how to convert it to v3.x? class WrapperPrinter: def __init__(self,outpath,options,data): ... ... self.print_header() print >>self.file self.print_preamble() print >>self.file self.print_loader() print >>self.file ... ... --Jach From tjreedy at udel.edu Sat Nov 11 21:24:45 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 11 Nov 2017 21:24:45 -0500 Subject: How to modify this from Python 2.x to v3.4? In-Reply-To: <7ca60f86-68fa-4ff8-8b53-fc5e2d6e76e3@googlegroups.com> References: <9fb5a25b-3fb0-4587-968c-69dbf6997a8f@googlegroups.com> <0f2b5cac-9ad5-069d-cf3f-442267544247@nedbatchelder.com> <7ca60f86-68fa-4ff8-8b53-fc5e2d6e76e3@googlegroups.com> Message-ID: On 11/11/2017 9:06 PM, jfong at ms4.hinet.net wrote: > Ned Batchelder? 2017?11?11???? UTC+8??8?49?27???? >> This looks like fairly advanced code.? It will be difficult to port to >> Python 3 *without* understanding some of the old history.? There seem to >> be forks on GitHub, including one with a pull request about Python 3 >> made in the last few days: >> https://github.com/davidjamesca/ctypesgen/pull/58 .? I'd recommend >> working with others on this. > > Thank you, Ned. > > As I remember that I had opened a thread here last year, trying to use "2To3" tool to convert the ctypesgen package, but didn't success. > https://groups.google.com/forum/#!topic/comp.lang.python/9G0FJXmtwbA > > This time, somehow I find this "ctypesgen-python-3" package and can't wait to give it a try, but is disappointed again. I suppose there are many v3.x users who like to use ctypesgen to ease the using of ctypes. But obviously, it's not an easy work to do, convert 2 to 3:-) > > By the way, does anyone know what the following codes does? (in printer.py file) and how to convert it to v3.x? > > class WrapperPrinter: > def __init__(self,outpath,options,data): > ... > ... > self.print_header() > print >>self.file print(file=self.file) # print blank line > self.print_preamble() > print >>self.file > > self.print_loader() > print >>self.file > ... > ... > > --Jach > -- Terry Jan Reedy From rantingrickjohnson at gmail.com Sat Nov 11 22:07:07 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 11 Nov 2017 19:07:07 -0800 (PST) Subject: How to modify this from Python 2.x to v3.4? In-Reply-To: <7ca60f86-68fa-4ff8-8b53-fc5e2d6e76e3@googlegroups.com> References: <9fb5a25b-3fb0-4587-968c-69dbf6997a8f@googlegroups.com> <0f2b5cac-9ad5-069d-cf3f-442267544247@nedbatchelder.com> <7ca60f86-68fa-4ff8-8b53-fc5e2d6e76e3@googlegroups.com> Message-ID: <8e8b53d2-e86e-4998-82e6-c59318624259@googlegroups.com> On Saturday, November 11, 2017 at 8:07:06 PM UTC-6, jf... at ms4.hinet.net wrote: [...] > By the way, does anyone know what the following codes does? > (in printer.py file) and how to convert it to v3.x? > > class WrapperPrinter: > def __init__(self,outpath,options,data): > ... > ... > self.print_header() > print >>self.file > > self.print_preamble() > print >>self.file > > self.print_loader() > print >>self.file > ... > ... `print` was changed from a statement to a function, so it's just a matter of converting it to a function call. If you read the docs for the new print function, it should be relatively easy to translate. I don't understand why you're having so much trouble. https://docs.python.org/3/whatsnew/3.0.html?highlight=print#common-stumbling-blocks From zms.ethiopia at gmail.com Sun Nov 12 03:55:56 2017 From: zms.ethiopia at gmail.com (zms.ethiopia at gmail.com) Date: Sun, 12 Nov 2017 00:55:56 -0800 (PST) Subject: Solutions Manual Test Bank for Macroeconomics, 9th Edition by N. Gregory Mankiw In-Reply-To: References: Message-ID: <474f58c8-75d5-4b83-ab75-3ab6246fef4f@googlegroups.com> On Friday, July 7, 2017 at 12:49:50 AM UTC+3, Test Banks wrote: > Greetings, > > Solutions Manuals and Test Bank for " Macroeconomics, 9th Edition by N. Gregory Mankiw " is available at very reasonable price. You can get these files by sending email to pro.fast(@)hotmail(dot)com > > Send your requests to PRO.FAST(@)HOTMAIL(DOT)COM > > We do not monitor replies here so simply send us an email at above mentioned email ID > > MACROECONOMICS, 9TH EDITION BY N. GREGORY MANKIW SOLUTIONS MANUAL TEST BANK > > We have large collection for Solutions and Test Banks for all subjects. You can email us at PRO.FAST (@) HOTMAIL (DOT) COM for your queries and we will check that book SM and TB for you. > > ISBN Numbers for this book is given below > > ISBN-10: 1464182892 > ISBN-13: 9781464182891 > > > Cheers, > Solutions Manuals and Test Bank Team > Since 2008 From jfong at ms4.hinet.net Sun Nov 12 04:02:58 2017 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sun, 12 Nov 2017 01:02:58 -0800 (PST) Subject: How to modify this from Python 2.x to v3.4? In-Reply-To: <8e8b53d2-e86e-4998-82e6-c59318624259@googlegroups.com> References: <9fb5a25b-3fb0-4587-968c-69dbf6997a8f@googlegroups.com> <0f2b5cac-9ad5-069d-cf3f-442267544247@nedbatchelder.com> <7ca60f86-68fa-4ff8-8b53-fc5e2d6e76e3@googlegroups.com> <8e8b53d2-e86e-4998-82e6-c59318624259@googlegroups.com> Message-ID: Rick Johnson? 2017?11?12???? UTC+8??11?07?20???? > `print` was changed from a statement to a function, so it's > just a matter of converting it to a function call. If you > read the docs for the new print function, it should be > relatively easy to translate. I don't understand why you're > having so much trouble. > > https://docs.python.org/3/whatsnew/3.0.html?highlight=print#common-stumbling-blocks It's a shame I didn't read its doc in v3.4 thoughtfully: print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False) I thought position argument is essential, but it's not in this function: If no objects are given, print() will just write end. Thanks for your reminder. --Jach From tjol at tjol.eu Sun Nov 12 04:16:26 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 12 Nov 2017 10:16:26 +0100 Subject: How to modify this from Python 2.x to v3.4? In-Reply-To: <7ca60f86-68fa-4ff8-8b53-fc5e2d6e76e3@googlegroups.com> References: <9fb5a25b-3fb0-4587-968c-69dbf6997a8f@googlegroups.com> <0f2b5cac-9ad5-069d-cf3f-442267544247@nedbatchelder.com> <7ca60f86-68fa-4ff8-8b53-fc5e2d6e76e3@googlegroups.com> Message-ID: <2126d416-5207-72a4-625b-7e7a8085532e@tjol.eu> On 2017-11-12 03:06, jfong at ms4.hinet.net wrote: > I suppose there are many v3.x users who like to use ctypesgen to ease > the using of ctypes. Perhaps, but from what I can tell the increasingly popular cffi package serves a similar need. By all means, port ctypesgen to Python 3 (and publish your port) if you want to, but you might want to consider whether it's easier to port your code from ctypes/ctypesgen to cffi instead. -- Thomas Jollans From walters.justin01 at gmail.com Sun Nov 12 12:20:35 2017 From: walters.justin01 at gmail.com (justin walters) Date: Sun, 12 Nov 2017 09:20:35 -0800 Subject: Need some help with Python Job Board In-Reply-To: References: Message-ID: On Sat, Nov 11, 2017 at 3:27 PM, Skip Montanaro wrote: > The Python Job Board could use a little help in a couple areas. One, we can > always use help reviewing and approving (or rejecting) submissions. The > backlog keeps growing, and the existing volunteers who help can't always > keep up. (This is a good problem to have, reflecting on Python's broad > popularity in many application domains.) > > Two, and perhaps more important, the submission form really needs to > support WYSIWYG editing. Apparently, most posters are unable to handle > markup-based systems, probably just pasting content from Word documents. > Making this change would streamline the review process, as formatting > problems are currently the biggest impediment to successful submissions. > There is an open ticket to add this feature: > > https://github.com/python/pythondotorg/issues/655 > > If you can help with either task, please drop a note to jobs at python.org. > > Thanks, > > Skip > -- > https://mail.python.org/mailman/listinfo/python-list > I might be able to help implement a wysiwyg editor. The only issue I can think of at the moment would be finding a way to determine if the template should render wysiswyg content or Markdown content. I'll need to look over the repo a bit more closely first. From skip.montanaro at gmail.com Sun Nov 12 12:52:49 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 12 Nov 2017 11:52:49 -0600 Subject: Need some help with Python Job Board In-Reply-To: References: Message-ID: Thanks, Justin. I imagine editors probably exist which can switch between WYSIWYG and markup. Whether that markup can be Markdown or not, I don't know. Marc-Andr? Lemburg listed a few possible editors in the ticket he opened, but I've not dug into their properties. Skip On Sun, Nov 12, 2017 at 11:20 AM, justin walters wrote: > On Sat, Nov 11, 2017 at 3:27 PM, Skip Montanaro > wrote: > > > The Python Job Board could use a little help in a couple areas. One, we > can > > always use help reviewing and approving (or rejecting) submissions. The > > backlog keeps growing, and the existing volunteers who help can't always > > keep up. (This is a good problem to have, reflecting on Python's broad > > popularity in many application domains.) > > > > Two, and perhaps more important, the submission form really needs to > > support WYSIWYG editing. Apparently, most posters are unable to handle > > markup-based systems, probably just pasting content from Word documents. > > Making this change would streamline the review process, as formatting > > problems are currently the biggest impediment to successful submissions. > > There is an open ticket to add this feature: > > > > https://github.com/python/pythondotorg/issues/655 > > > > If you can help with either task, please drop a note to jobs at python.org. > > > > Thanks, > > > > Skip > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > I might be able to help implement a wysiwyg editor. The only issue I can > think of at the moment > would be finding a way to determine if the template should render wysiswyg > content or Markdown content. > > I'll need to look over the repo a bit more closely first. > -- > https://mail.python.org/mailman/listinfo/python-list > From texasblaze at aol.com Sun Nov 12 14:58:38 2017 From: texasblaze at aol.com (texasblaze at aol.com) Date: Sun, 12 Nov 2017 14:58:38 -0500 Subject: can't get python to run In-Reply-To: <15faedfd960-c0c-94e0@webjas-vac149.srv.aolmail.net> References: <15faedfd960-c0c-94e0@webjas-vac149.srv.aolmail.net> Message-ID: <15fb1cffb81-c0e-1fca@webjas-vaa199.srv.aolmail.net> trying to install and run Python 3.5.2 (64 bit) and keep getting error message: the program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer. Try reintalling the program to fix this problem. I am on Windows 7 Home Premium I have uninstalled and reinstalled 3.5.2 several times and tried repairing and still the error message keeps coming back and i can't run python 3.5.2 I was able to run Python27 and it opened just fine. I am not a computer person and am just starting to learn python and the professor said to install 3.5.2. I just have no idea what the issue is other than maybe an old computer???? regards, Mary Ann From p.f.moore at gmail.com Sun Nov 12 15:16:05 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Sun, 12 Nov 2017 20:16:05 +0000 Subject: can't get python to run In-Reply-To: <15fb1cffb81-c0e-1fca@webjas-vaa199.srv.aolmail.net> References: <15faedfd960-c0c-94e0@webjas-vac149.srv.aolmail.net> <15fb1cffb81-c0e-1fca@webjas-vaa199.srv.aolmail.net> Message-ID: On 12 November 2017 at 19:58, Mary Ann via Python-list wrote: > > trying to install and run Python 3.5.2 (64 bit) and keep getting error message: > > the program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer. Try reintalling the program to fix this problem. > > I am on Windows 7 Home Premium > > I have uninstalled and reinstalled 3.5.2 several times and tried repairing and still the error message keeps coming back and i can't run python 3.5.2 > > I was able to run Python27 and it opened just fine. > > > I am not a computer person and am just starting to learn python and the professor said to install 3.5.2. I just have no idea what the issue is other than maybe an old computer???? This is something that comes up for people quite often. In a situation like this, you can often find useful advice by searching Google. I put the message "api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer" into Google, and got a few hits immediately that would probably have been helpful to you. What you should do is to download and install the "Visual C++ redistributable for Visual Studio 2015", which you can get from https://www.microsoft.com/en-in/download/details.aspx?id=48145 You may also find that if you run "Check for updates" on your PC, this will be installed automatically - MS do distribute this update automatically, and it may be that you simply haven't updated recently. But the manual install will work just as well. Hope this helps, Paul PS The reason Python 2.7 works, is that it uses an older version of Visual C, which doesn't need the newer runtime installed. From jfong at ms4.hinet.net Sun Nov 12 19:55:09 2017 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sun, 12 Nov 2017 16:55:09 -0800 (PST) Subject: How to modify this from Python 2.x to v3.4? In-Reply-To: References: <9fb5a25b-3fb0-4587-968c-69dbf6997a8f@googlegroups.com> <0f2b5cac-9ad5-069d-cf3f-442267544247@nedbatchelder.com> <7ca60f86-68fa-4ff8-8b53-fc5e2d6e76e3@googlegroups.com> <2126d416-5207-72a4-625b-7e7a8085532e@tjol.eu> Message-ID: <3644b992-49d9-4269-9802-a43a7239f41a@googlegroups.com> Thomas Jollans? 2017?11?12???? UTC+8??5?17?38???? > By all means, port ctypesgen to Python 3 (and publish your port) if you > want to, I am not the right person because I have never use Python2 before:-) > but you might want to consider whether it's easier to port your > code from ctypes/ctypesgen to cffi instead. CFFI seems is a little complex, at least to me. I had read its document but didn't get through yet:-( --Jach From bob at mellowood.ca Sun Nov 12 21:17:53 2017 From: bob at mellowood.ca (bvdp) Date: Sun, 12 Nov 2017 18:17:53 -0800 (PST) Subject: from xx import yy Message-ID: <7370e1b8-595d-4ea5-8c00-4b03675dddcd@googlegroups.com> I'm having a conceptual mind-fart today. I just modified a bunch of code to use "from xx import variable" when variable is a global in xx.py. But, when I change/read 'variable' it doesn't appear to change. I've written a bit of code to show the problem: mod1.py myvar = 99 def setvar(x): global myvar myvar = x test1.py import mod1 mod1.myvar = 44 print (mod1.myvar) mod1.setvar(33) print (mod1.myvar) If this test1.py is run myvar is fine. But, if I run: test2.py from mod1 import myvar, setvar myvar = 44 print (myvar) setvar(33) print (myvar) It doesn't print the '33'. I thought (apparently incorrectly) that import as would import the name myvar into the current module's namespace where it could be read by functions in the module???? From ned at nedbatchelder.com Sun Nov 12 22:00:46 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 12 Nov 2017 22:00:46 -0500 Subject: from xx import yy In-Reply-To: <7370e1b8-595d-4ea5-8c00-4b03675dddcd@googlegroups.com> References: <7370e1b8-595d-4ea5-8c00-4b03675dddcd@googlegroups.com> Message-ID: <2913868e-b326-4531-0890-31b75e90bd87@nedbatchelder.com> On 11/12/17 9:17 PM, bvdp wrote: > I'm having a conceptual mind-fart today. I just modified a bunch of code to use "from xx import variable" when variable is a global in xx.py. But, when I change/read 'variable' it doesn't appear to change. I've written a bit of code to show the problem: > > mod1.py > myvar = 99 > def setvar(x): > global myvar > myvar = x > > test1.py > import mod1 > mod1.myvar = 44 > print (mod1.myvar) > mod1.setvar(33) > print (mod1.myvar) In this case "mod1" is a name in test1 that refers to the mod1 module.? You can access and assign attributes on that module. Anyone else referencing that module (including the module itself) will see those changed attributes. > If this test1.py is run myvar is fine. But, if I run: > > test2.py > from mod1 import myvar, setvar > myvar = 44 > print (myvar) > setvar(33) > print (myvar) > > It doesn't print the '33'. In this case, "myvar" is a name that references the same value as mod1.myvar.? Now both myvar and mod1.myvar refer to the same value. There is no direct connection between the myvar name and the mod1.myvar name.? When you reassign myvar, it now refers to some other value. mod1.myvar is unaffected. --Ned. > I thought (apparently incorrectly) that import as would import the name myvar into the current module's namespace where it could be read by functions in the module???? > From rosuav at gmail.com Sun Nov 12 22:01:46 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 13 Nov 2017 14:01:46 +1100 Subject: from xx import yy In-Reply-To: <7370e1b8-595d-4ea5-8c00-4b03675dddcd@googlegroups.com> References: <7370e1b8-595d-4ea5-8c00-4b03675dddcd@googlegroups.com> Message-ID: On Mon, Nov 13, 2017 at 1:17 PM, bvdp wrote: > I'm having a conceptual mind-fart today. I just modified a bunch of code to use "from xx import variable" when variable is a global in xx.py. But, when I change/read 'variable' it doesn't appear to change. I've written a bit of code to show the problem: > > mod1.py > myvar = 99 > def setvar(x): > global myvar > myvar = x > > test1.py > import mod1 > mod1.myvar = 44 > print (mod1.myvar) > mod1.setvar(33) > print (mod1.myvar) > > If this test1.py is run myvar is fine. But, if I run: > > test2.py > from mod1 import myvar, setvar > myvar = 44 > print (myvar) > setvar(33) > print (myvar) > > It doesn't print the '33'. > > I thought (apparently incorrectly) that import as would import the name myvar into the current module's namespace where it could be read by functions in the module???? It imports the *value*. What you have is basically this: import mod1 myvar = mod1.myvar setvar = mod1.setvar Since functions remember their contexts, setvar() still sees the globals of mod1. But myvar is a simple integer, so it's basically "myvar = 99". So basically, you can't from-import anything that's going to be changed. You can import constants that way ("from stat import S_IREAD"), or classes/functions (since they're not generally rebound), but as a general rule, don't from-import anything mutable. In fact, if you follow the even-more-general rule of "don't bother with from-imports at all", you'll be right far more than you'll be wrong. ChrisA From rantingrickjohnson at gmail.com Mon Nov 13 00:07:21 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 12 Nov 2017 21:07:21 -0800 (PST) Subject: from xx import yy In-Reply-To: <7370e1b8-595d-4ea5-8c00-4b03675dddcd@googlegroups.com> References: <7370e1b8-595d-4ea5-8c00-4b03675dddcd@googlegroups.com> Message-ID: On Sunday, November 12, 2017 at 8:18:04 PM UTC-6, bvdp wrote: > I'm having a conceptual mind-fart today. I just modified a bunch of code to use "from xx import variable" when variable is a global in xx.py. But, when I change/read 'variable' it doesn't appear to change. I've written a bit of code to show the problem: > > mod1.py > myvar = 99 > def setvar(x): > global myvar > myvar = x > > test1.py > import mod1 > mod1.myvar = 44 > print (mod1.myvar) > mod1.setvar(33) > print (mod1.myvar) > > If this test1.py is run myvar is fine. But, if I run: > > test2.py > from mod1 import myvar, setvar > myvar = 44 > print (myvar) > setvar(33) > print (myvar) > > It doesn't print the '33'. > > I thought (apparently incorrectly) that import as would > import the name myvar into the current module's namespace > where it could be read by functions in the module???? No. > test2.py > from mod1 import myvar, setvar Be aware that the previous line creates a _local_ "module- level variable" (in test2.py) named `myvar`, and assigns it the value of `99`. And also be aware that changes to this variable will not be reflected in `mod1'. As they are in no way connected. However, *SNIFF-SNIFF*, i smell a major flaw in this design. Why would you create a function to modify a module level variable anyway? If you want to modify a MLV from another module (aka: externally), then why not modify it using an explicit dot path? Observe: # from inside an external module import mod1 mod1.myvar = "foo" Now `myvar` is a string. So what is the point of this external modification? Are you attempting to share state between modules? From quintin9g at gmail.com Mon Nov 13 00:42:35 2017 From: quintin9g at gmail.com (Edward Montague) Date: Mon, 13 Nov 2017 18:42:35 +1300 Subject: matchpy Message-ID: After successfully installing python 3.6.3 and the appropriate version of IDLE , I attempted to run a matchpy example , to no avail . I'm using a debian distribution , 8.x or greater , is there something I need to be aware of . The error report points to a statement containing a ' -> ' character , as far as I know , this isn't valid python syntax . From rosuav at gmail.com Mon Nov 13 00:46:11 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 13 Nov 2017 16:46:11 +1100 Subject: matchpy In-Reply-To: References: Message-ID: On Mon, Nov 13, 2017 at 4:42 PM, Edward Montague wrote: > After successfully installing python 3.6.3 and the appropriate version of > IDLE , > I attempted to run a matchpy example , to no avail . > > I'm using a debian distribution , 8.x or greater , is there something I > need to be aware of . > The error report points to a statement containing a ' -> ' character , as > far as I know , > this isn't valid python syntax . It IS valid Python syntax (a function annotation). You'll need to give a lot more information for us to help you - preferably, a complete runnable example. ChrisA From mal at python.org Mon Nov 13 04:16:15 2017 From: mal at python.org (M.-A. Lemburg) Date: Mon, 13 Nov 2017 10:16:15 +0100 Subject: [Jobs] Need some help with Python Job Board In-Reply-To: References: Message-ID: <0ae6c166-9570-cd90-dc50-42d9acd4af98@python.org> Hi Justin, the default markup is currently set to restructuredtext: https://github.com/python/pythondotorg/blob/master/jobs/models.py but this can be changed to any of these supported ones: https://github.com/jamesturk/django-markupfield as long as we make sure that all existing records continue to be set to ReST (to not mess up the formatting). Since I had a look at WYSIWYG editors, some new ones may have surfaced. The templates are defined here: https://github.com/python/pythondotorg/tree/master/templates/jobs and the main project page has instructions on how to get a local copy of the website working: https://pythondotorg.readthedocs.io/ Thanks, -- Marc-Andre Lemburg Python Software Foundation http://www.python.org/psf/ http://www.malemburg.com/ On 12.11.2017 18:52, Skip Montanaro wrote: > Thanks, Justin. I imagine editors probably exist which can switch between > WYSIWYG and markup. Whether that markup can be Markdown or not, I don't > know. Marc-Andr? Lemburg listed a few possible editors in the ticket he > opened, but I've not dug into their properties. > > Skip > > On Sun, Nov 12, 2017 at 11:20 AM, justin walters > wrote: > >> On Sat, Nov 11, 2017 at 3:27 PM, Skip Montanaro >> wrote: >> >>> The Python Job Board could use a little help in a couple areas. One, we >> can >>> always use help reviewing and approving (or rejecting) submissions. The >>> backlog keeps growing, and the existing volunteers who help can't always >>> keep up. (This is a good problem to have, reflecting on Python's broad >>> popularity in many application domains.) >>> >>> Two, and perhaps more important, the submission form really needs to >>> support WYSIWYG editing. Apparently, most posters are unable to handle >>> markup-based systems, probably just pasting content from Word documents. >>> Making this change would streamline the review process, as formatting >>> problems are currently the biggest impediment to successful submissions. >>> There is an open ticket to add this feature: >>> >>> https://github.com/python/pythondotorg/issues/655 >>> >>> If you can help with either task, please drop a note to jobs at python.org. >>> >>> Thanks, >>> >>> Skip >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> >> I might be able to help implement a wysiwyg editor. The only issue I can >> think of at the moment >> would be finding a way to determine if the template should render wysiswyg >> content or Markdown content. >> >> I'll need to look over the repo a bit more closely first. >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > > _______________________________________________ > Jobs mailing list > Jobs at python.org > https://mail.python.org/mailman/listinfo/jobs > From bob at mellowood.ca Mon Nov 13 11:58:56 2017 From: bob at mellowood.ca (bvdp) Date: Mon, 13 Nov 2017 08:58:56 -0800 (PST) Subject: from xx import yy In-Reply-To: <7370e1b8-595d-4ea5-8c00-4b03675dddcd@googlegroups.com> References: <7370e1b8-595d-4ea5-8c00-4b03675dddcd@googlegroups.com> Message-ID: On Sunday, November 12, 2017 at 7:18:04 PM UTC-7, bvdp wrote: > I'm having a conceptual mind-fart today. I just modified a bunch of code to use "from xx import variable" when variable is a global in xx.py. But, when I change/read 'variable' it doesn't appear to change. I've written a bit of code to show the problem: > > mod1.py > myvar = 99 > def setvar(x): > global myvar > myvar = x > > test1.py > import mod1 > mod1.myvar = 44 > print (mod1.myvar) > mod1.setvar(33) > print (mod1.myvar) > > If this test1.py is run myvar is fine. But, if I run: > > test2.py > from mod1 import myvar, setvar > myvar = 44 > print (myvar) > setvar(33) > print (myvar) > > It doesn't print the '33'. > > I thought (apparently incorrectly) that import as would import the name myvar into the current module's namespace where it could be read by functions in the module???? Thanks all for confirming that I was wrong to use "from .. import". Hmmm, perhaps for functions it might be okay. But, in most cases it's a lot more obvious to use module.function() when calling. Maybe a bit slower, but I'm sure it's negligible in most cases. And, yes, I am trying to share state info between modules. Is this a bad thing? I guess I would write getter() and setter() functions for all this. But that does seem to remind me too much of some other language :) From walters.justin01 at gmail.com Mon Nov 13 12:14:03 2017 From: walters.justin01 at gmail.com (justin walters) Date: Mon, 13 Nov 2017 09:14:03 -0800 Subject: [Jobs] Need some help with Python Job Board In-Reply-To: <0ae6c166-9570-cd90-dc50-42d9acd4af98@python.org> References: <0ae6c166-9570-cd90-dc50-42d9acd4af98@python.org> Message-ID: On Mon, Nov 13, 2017 at 1:16 AM, M.-A. Lemburg wrote: > Hi Justin, > > the default markup is currently set to restructuredtext: > > https://github.com/python/pythondotorg/blob/master/jobs/models.py > > but this can be changed to any of these supported ones: > > https://github.com/jamesturk/django-markupfield > > as long as we make sure that all existing records continue > to be set to ReST (to not mess up the formatting). > > Since I had a look at WYSIWYG editors, some new ones may have > surfaced. > > The templates are defined here: > > https://github.com/python/pythondotorg/tree/master/templates/jobs > > and the main project page has instructions on how to get > a local copy of the website working: > > https://pythondotorg.readthedocs.io/ > > Thanks, > -- > Marc-Andre Lemburg > Python Software Foundation > http://www.python.org/psf/ > http://www.malemburg.com/ > _____________________________________ > > Jobs mailing list > > Jobs at python.org > > https://mail.python.org/mailman/listinfo/jobs > > > > Thank you Marc. I'll take a look over this stuff and hopefully I can squeeze in some time this week to work on it. From rosuav at gmail.com Mon Nov 13 12:58:11 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Nov 2017 04:58:11 +1100 Subject: from xx import yy In-Reply-To: References: <7370e1b8-595d-4ea5-8c00-4b03675dddcd@googlegroups.com> Message-ID: On Tue, Nov 14, 2017 at 3:58 AM, bvdp wrote: > Thanks all for confirming that I was wrong to use "from .. import". Hmmm, perhaps for functions it might be okay. But, in most cases it's a lot more obvious to use module.function() when calling. Maybe a bit slower, but I'm sure it's negligible in most cases. > > And, yes, I am trying to share state info between modules. Is this a bad thing? I guess I would write getter() and setter() functions for all this. But that does seem to remind me too much of some other language :) > It's going to be so very marginally slower that you won't even be able to measure it, outside of a micro-benchmark. Worry about code correctness first, and then performance only if you actually know you have a problem. Sharing state between modules is fine as long as it's controlled by one module - which is what you have here. Go ahead! Not an issue. ChrisA From sjeik_appie at hotmail.com Mon Nov 13 15:27:40 2017 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Mon, 13 Nov 2017 20:27:40 +0000 Subject: Book recommendation for Spark/Pyspark? Message-ID: Hi, Can anybody recommend a good, preferably recent, book about Spark and Pyspark? I am using Pyspark now, but I am looking for a book that also gives a thorough background about Spark itself. I've been looking around on e.g. Amazon but, as the saying goes, one can't judge a book by its cover. Thanks! Albert-Jan From ben+python at benfinney.id.au Mon Nov 13 18:00:27 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 14 Nov 2017 10:00:27 +1100 Subject: reStrcuturedText WYSIWYG online editor (was: Need some help with Python Job Board) References: Message-ID: <85zi7pwzqs.fsf_-_@benfinney.id.au> Skip Montanaro writes: > Thanks, Justin. I imagine editors probably exist which can switch between > WYSIWYG and markup. The ?rsted? app is a reStructuredText WYSIWYG editor written in the Flask framework. -- \ ?Remember: every member of your ?target audience? also owns a | `\ broadcasting station. These ?targets? can shoot back.? ?Michael | _o__) Rathbun to advertisers, news.admin.net-abuse.email | Ben Finney From joshjon2017 at gmail.com Mon Nov 13 19:03:08 2017 From: joshjon2017 at gmail.com (joshjon2017 at gmail.com) Date: Mon, 13 Nov 2017 16:03:08 -0800 (PST) Subject: ANN: obfuscate 0.2.2 In-Reply-To: <4bc08cbc$0$8850$c3e8da3@news.astraweb.com> References: <4bc08cbc$0$8850$c3e8da3@news.astraweb.com> Message-ID: <1789c631-b667-4027-9eca-2e827ad7e3e8@googlegroups.com> for importing obfuscate do we just type in import obfuscate or import obfuscate 0.2.2 From rantingrickjohnson at gmail.com Mon Nov 13 21:42:45 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 13 Nov 2017 18:42:45 -0800 (PST) Subject: from xx import yy In-Reply-To: References: <7370e1b8-595d-4ea5-8c00-4b03675dddcd@googlegroups.com> Message-ID: <3ad9f18c-7d7a-43ed-9823-ca865d42df38@googlegroups.com> On Monday, November 13, 2017 at 10:59:06 AM UTC-6, bvdp wrote: > Thanks all for confirming that I was wrong to use "from .. > import". In this case, but i wouldn't extrapolate that advice to mean that the form `from X import Y` is _always_ bad. You just need to understand the consequences of each unique form of Python's import. > Hmmm, perhaps for functions it might be okay. But, > in most cases it's a lot more obvious to use > module.function() when calling. Well, again, i think you're over generalizing. If the imported symbol is a "self-contained code object" (aka: a function or a custom class, whether instanced or not), or especially a "read-only variable", then `from mod import x, y, z` won't typically cause any of these surprises. But of course, the previous paragraph only applies if i understood your initial question "correctly". Meaning, in the context of "your own personal expectations". My understanding of those _expectations_ (aka: _your_ expectations), is that you assumed that by importing a symbol (namely: `myvar`) into a "foreign module" (namely: "test2.py") that such action would allow you to mutate the _value_ of `myvar` from two distinct modules. But this is not true. Because each module creates its own local variables when names are imported. And that peculiarity is directly related to Python's strange implementation of global variables (psst: which, in the next paragraph, you'll discover are not really global at all!) (but for now, let's keep that dirty little secret between you and me, mmmkay?) One important lesson to learn about Python is that it has no "normally accepted" concept of "global variables". (meaning, variables that are known to all scopes within a program). So throw out everything you've ever know about global variables. Go ahead... We're waiting! Sure, you can create a _real_ global variable in Python if you were so inclined, but there is no "official support" for doing such a thing, and it requires some esoteric knowledge about how names are injected into module namespace by Python itself. But, to unlock this knowledge, you'll first to master the secret handshake and speakeasy a secret password. "Officially" speaking, the most promiscuous naturally occuring variable in a python program is what i call a "Module Level Variable" (or MLV for short). MLVs are the variables that are defined _outside_ of self-contained code objects like functions and/or classes, and these are the types of variables that require the use of the specialized `global` keyword (at least, if one wishes to modify them from inside a self-contained code object that is.) So basically, what you were trying to do was to create a global variable, a _real_ global variable that is, not the fake and utterly confusing ones that Python implements, nope, but a _real_, bonafide global variable that could be mutated from inside multiple modules (or more generically, multiple namespaces or scopes). And i'm sorry, but you're not allowed to do that. > Maybe a bit slower, but I'm sure it's negligible in most > cases. And, yes, I am trying to share state info between > modules. Is this a bad thing? I guess I would write > getter() and setter() functions for all this. But that does > seem to remind me too much of some other language :) I never write getters or setters unless i need functional behavior during the reading or writing of an attribute. IOW, if your getters and setters look like this: # pseudo some_value = "foo" def get_value(): return some_value def set_value(new): some_value = value ...then you're wasting your time and that of those who are forced to read the code. OTOH. If your getters and setters can justify their existence like this: # pseudo some_value = "foo" def get_value(): perform_some_test_or_action() return some_value def set_value(new): perform_some_test_or_action() some_value = new Then it makes sense to use them. Sometimes the value needs to be calculated; or updated; or type checked; or whatever. From rantingrickjohnson at gmail.com Tue Nov 14 00:20:13 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 13 Nov 2017 21:20:13 -0800 (PST) Subject: ANN: obfuscate 0.2.2 In-Reply-To: <1789c631-b667-4027-9eca-2e827ad7e3e8@googlegroups.com> References: <4bc08cbc$0$8850$c3e8da3@news.astraweb.com> <1789c631-b667-4027-9eca-2e827ad7e3e8@googlegroups.com> Message-ID: <0a03796a-55a1-4e16-ac59-736dbdccb8bc@googlegroups.com> On Monday, November 13, 2017 at 6:03:23 PM UTC-6, joshj... at gmail.com wrote: > for importing obfuscate do we just type in import obfuscate > or import obfuscate 0.2.2 Oh boy. I had forgotten about this little community "gem" dating back to 2010. And unfortunately for comrade Steven, there is no way to obfuscate this thread! Not even double rot13 will help! :-)) From rantingrickjohnson at gmail.com Tue Nov 14 00:27:21 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 13 Nov 2017 21:27:21 -0800 (PST) Subject: matchpy In-Reply-To: References: Message-ID: <81773a1b-1f5d-4d02-9016-668f3a8c6417@googlegroups.com> Chris Angelico wrote: > Edward Montague wrote: > > After successfully installing python 3.6.3 and the > > appropriate version of IDLE , I attempted to run a matchpy > > example , to no avail . I'm using a debian distribution , > > 8.x or greater , is there something I need to be aware of > > . The error report points to a statement containing a ' -> > > ' character , as far as I know , this isn't valid python > > syntax . > > It IS valid Python syntax (a function annotation). You'll > need to give a lot more information for us to help you - > preferably, a complete runnable example. Or a full traceback message. PS: Looks as though type-hints may have claimed its first victim. From formisc at gmail.com Tue Nov 14 00:44:18 2017 From: formisc at gmail.com (Andrew Z) Date: Tue, 14 Nov 2017 00:44:18 -0500 Subject: for/ if against dict - one liner Message-ID: Hello, i wonder how do i get the "for" and "if" to work against a dictionary in one line? basically i want to "squeeze": dct= [ 1 : "one", 2:"two", 3:"three"] for k, val in dct: if k >= 2: # do magnificent things Thank you AZ From formisc at gmail.com Tue Nov 14 00:56:03 2017 From: formisc at gmail.com (Andrew Z) Date: Tue, 14 Nov 2017 00:56:03 -0500 Subject: Time travel - how to simplify? Message-ID: well, yeah, it's unidirectional and final destination is always the same and have little to do with the question. Say, i have a dict: fut_suffix ={ 1 : 'F', 2 : 'G', 3 : 'H', 4 : 'J', 5 : 'K', 6 : 'M', 7 : 'N', 8 : 'Q', 9 : 'U', 10: 'V', 11: 'X', 12: 'Z' } where key is a month. Now i want to get certain number of months. Say, i need 3 months duration starting from any month in dict. so if i start @ 7th: my_choice =7 for mnth, value in fut_suffix: if my_choice >= mnth # life is great but if : my_choice = 12 then my "time travel" becomes pain in the neck.. And as such - the question is - what is the smart way to deal with cases like this? Thank you AZ From formisc at gmail.com Tue Nov 14 01:05:50 2017 From: formisc at gmail.com (Andrew Z) Date: Tue, 14 Nov 2017 01:05:50 -0500 Subject: Time travel - how to simplify? In-Reply-To: References: Message-ID: My implied solution is incorrect. I should start with using the date type and, for example, dateutil package for date manipulation and building the dictionary of needed dates/months. And only after that, map against the fut_suffix. On Tue, Nov 14, 2017 at 12:56 AM, Andrew Z wrote: > well, yeah, it's unidirectional and final destination is always the same > and have little to do with the question. > > Say, i have a dict: > > fut_suffix ={ 1 : 'F', > 2 : 'G', > 3 : 'H', > 4 : 'J', > 5 : 'K', > 6 : 'M', > 7 : 'N', > 8 : 'Q', > 9 : 'U', > 10: 'V', > 11: 'X', > 12: 'Z' > } > > where key is a month. > Now i want to get certain number of months. Say, i need 3 months duration > starting from any month in dict. > > so if i start @ 7th: > my_choice =7 > for mnth, value in fut_suffix: > if my_choice >= mnth > # life is great > but if : > my_choice = 12 then my "time travel" becomes pain in the neck.. > > And as such - the question is - what is the smart way to deal with cases > like this? > > Thank you > AZ > > > From vincent.vande.vyvre at telenet.be Tue Nov 14 02:24:28 2017 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Tue, 14 Nov 2017 08:24:28 +0100 Subject: for/ if against dict - one liner In-Reply-To: References: Message-ID: Le 14/11/17 ? 06:44, Andrew Z a ?crit?: > Hello, > i wonder how do i get the "for" and "if" to work against a dictionary in > one line? > > basically i want to "squeeze": > dct= [ 1 : "one", 2:"two", 3:"three"] > for k, val in dct: > if k >= 2: > # do magnificent things > > Thank you > AZ Maybe something like that: lst = [do_magnificent_thing(dct[k]) for k in dct if k >= 2] lst contains the returns of do_magnificent_thing(k) in unpredictable order. Vincent From lawrencedo99 at gmail.com Tue Nov 14 03:05:10 2017 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 14 Nov 2017 00:05:10 -0800 (PST) Subject: from xx import yy (Posting On Python-List Prohibited) In-Reply-To: <7370e1b8-595d-4ea5-8c00-4b03675dddcd@googlegroups.com> References: <7370e1b8-595d-4ea5-8c00-4b03675dddcd@googlegroups.com> Message-ID: <7c1d769e-b326-43bf-b580-e7ebf9a88b51@googlegroups.com> On Monday, November 13, 2017 at 3:18:04 PM UTC+13, bvdp wrote: > I'm having a conceptual mind-fart today. I just modified a bunch > of code to use "from xx import variable" when variable is a global > in xx.py. But, when I change/read 'variable' it doesn't appear to change. 1) Every name in Python is a variable. 2) Every distinct name (including qualifications) is a distinct variable. Changing one does not automatically change another. ?from xx import yy? creates a variable named ?yy? in the current scope, initialized to xx.yy but otherwise distinct from it. From tjol at tjol.eu Tue Nov 14 04:54:29 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 14 Nov 2017 10:54:29 +0100 Subject: for/ if against dict - one liner In-Reply-To: References: Message-ID: <3c4f90cf-e584-f80b-dd7e-9f0af6e06f2f@tjol.eu> On 2017-11-14 06:44, Andrew Z wrote: > Hello, > i wonder how do i get the "for" and "if" to work against a dictionary in > one line? > > basically i want to "squeeze": > dct= [ 1 : "one", 2:"two", 3:"three"] > for k, val in dct: Don't you mean dct.items() > if k >= 2: > # do magnificent things > > Thank you > AZ > -- Thomas Jollans From alister.ware at ntlworld.com Tue Nov 14 04:59:18 2017 From: alister.ware at ntlworld.com (alister) Date: Tue, 14 Nov 2017 09:59:18 GMT Subject: for/ if against dict - one liner Message-ID: On Tue, 14 Nov 2017 00:44:18 -0500, Andrew Z wrote: > Hello, > i wonder how do i get the "for" and "if" to work against a dictionary > in > one line? > > basically i want to "squeeze": > dct= [ 1 : "one", 2:"two", 3:"three"] > for k, val in dct: > if k >= 2: > # do magnificent things > > Thank you AZ why the need to single line it? is your computer running out of new line & space characters? it probably could be done with a dictionary comprehension but will that make things easier or harder to read/understand? "Readability counts" -- (Presuming for the sake of argument that it's even *possible* to design better code in Perl than in C. :-) -- Larry Wall on core code vs. module code design From tjol at tjol.eu Tue Nov 14 05:03:07 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 14 Nov 2017 11:03:07 +0100 Subject: for/ if against dict - one liner In-Reply-To: References: Message-ID: <3c344547-0d65-dd83-409f-e737762e77fc@tjol.eu> On 2017-11-14 07:29, Stefan Ram wrote: > Andrew Z writes: >> i wonder how do i get the "for" and "if" to work against a dictionary in >> one line? > > dict ={ 1 : "one", 2 : "two", 3 : "three" } > print( *( ( str( key )+ ' ' + str( dict[ key ])) for key in dict if key >= 2 ), sep='\n' ) > > prints: > > 2 two > 3 three > We can build something nicer than that, surely. The repeated str() calls and dictionary lookups just look like noise to my eyes. print('\n'.join(f'{k} {v}' for k, v in dict.items() if k >= 2)) But indeed, you can build concise dictionary filters like that with generator expressions and list comprehensions. -- Thomas Jollans From hemla21 at gmail.com Tue Nov 14 09:53:02 2017 From: hemla21 at gmail.com (Heli) Date: Tue, 14 Nov 2017 06:53:02 -0800 (PST) Subject: PySide window does not resize to fit screen In-Reply-To: <2a082305-37a7-4801-96cb-288696060896@googlegroups.com> References: <24851466-7de1-408f-a0a0-548d42d21ab4@googlegroups.com> <0536254e-4101-4b7c-a848-61a5c3e1a064@googlegroups.com> <2a082305-37a7-4801-96cb-288696060896@googlegroups.com> Message-ID: <1c782ad2-7794-4d63-bae5-3ab2c405ddf6@googlegroups.com> Hi Chris and others, I have re-designed my user interface to include layouts and now it fits the screen perfectly. Thanks a lot for all your help on this thread, Best From ben+python at benfinney.id.au Tue Nov 14 14:43:25 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 15 Nov 2017 06:43:25 +1100 Subject: Time travel - how to simplify? References: Message-ID: <85vaicwsrm.fsf@benfinney.id.au> Andrew Z writes: > Now i want to get certain number of months. Say, i need 3 months duration > starting from any month in dict. > > so if i start @ 7th: > my_choice =7 > for mnth, value in fut_suffix: > if my_choice >= mnth > # life is great > but if : > my_choice = 12 then my "time travel" becomes pain in the neck.. The ?itertools? library in the Python standard library has what you need: import itertools month_values = sorted(list(fut_suffix.keys())) month_cycle = itertools.cycle(month_values) month_choice = 7 three_months_starting_at_choice = [] while len(three_months_starting_at_choice) < 3: this_month = next(month_cycle) if this_month >= month_choice: three_months_starting_at_choice.append(this_month) -- \ ?God forbid that any book should be banned. The practice is as | `\ indefensible as infanticide.? ?Dame Rebecca West | _o__) | Ben Finney From cs at cskk.id.au Tue Nov 14 16:05:05 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 15 Nov 2017 08:05:05 +1100 Subject: inspecting a callable for the arguments it accepts Message-ID: <20171114210505.GA16626@cskk.homeip.net> I know that this isn't generally solvable, but I'm wondering if it is partially solvable. I have a task manager which accepts callables, usually functions or generators, and calls them on data items as needed. For reasons which, frankly, suggest user interface ergonomics failure to me it happens that inappropriate functions get submtted to this system. For example, functions accepting no arguments but which are handed one by the system. I would like to inspect submitted functions' signatures for suitability at submission time, without calling the function. For example to see if this function accepts exactly one argument, or to see if it is a generator, etc. Is this possible, even in a limited way? The present situation is that when I get this wrong I get highly cryptic exceptions at runtime, some of which I think I could be FAR better understood if caught at submittion time. Here's an example failure at runtime: pilfer.py: WorkerThreadPool:Later-1:WorkerThreadPool: worker thread: ran task: exception! (, TypeError('() takes 0 positional arguments but 1 was given',), ) Traceback (most recent call last): File "/Users/cameron/hg/css/cs/threads.py", line 163, in _handler result = func() File "/Users/cameron/hg/css/cs/app/pilfer.py", line 1550, in retry_func return func(P, *a, **kw) TypeError: () takes 0 positional arguments but 1 was given pilfer.py: MAIN:0:0:retriable().put(Pilfer-0[http://www.smh.com.au/]): (, TypeError('() takes 0 positional arguments but 1 was given',), ) Ignoring the slight repetition you can see that (a) there's no direct clue as to what the actual submitted function was originally, as it is a lambda and (b) there's no direct clue as to where the function came from, because the submission call stack is long gone and the function is being called via a thread pool. Had I caught the function as unsuitable at submission time, debugging would be far easier. To be clear: the task manager is my own project, as is the submitted function. I'm trying to improve its debuggability. Cheers, Cameron Simpson (formerly cs at zip.com.au) From cs at cskk.id.au Tue Nov 14 16:20:17 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 15 Nov 2017 08:20:17 +1100 Subject: from xx import yy In-Reply-To: References: Message-ID: <20171114212017.GA47992@cskk.homeip.net> On 13Nov2017 08:58, bvdp wrote: >On Sunday, November 12, 2017 at 7:18:04 PM UTC-7, bvdp wrote: >> I'm having a conceptual mind-fart today. I just modified a bunch of code to use "from xx import variable" when variable is a global in xx.py. But, when I change/read 'variable' it doesn't appear to change. I've written a bit of code to show the problem: >> >> mod1.py >> myvar = 99 >> def setvar(x): >> global myvar >> myvar = x >> >> test1.py >> import mod1 >> mod1.myvar = 44 >> print (mod1.myvar) >> mod1.setvar(33) >> print (mod1.myvar) >> >> If this test1.py is run myvar is fine. But, if I run: >> >> test2.py >> from mod1 import myvar, setvar >> myvar = 44 >> print (myvar) >> setvar(33) >> print (myvar) >> >> It doesn't print the '33'. >> >> I thought (apparently incorrectly) that import as would import the name myvar into the current module's namespace where it could be read by functions in the module???? > >Thanks all for confirming that I was wrong to use "from .. import". Hmmm, perhaps for functions it might be okay. But, in most cases it's a lot more obvious to use module.function() when calling. Maybe a bit slower, but I'm sure it's negligible in most cases. You're wrong to use it for this particular special case, and ony because you lose the reference to the module itself, which means you're no longer accessing the _reference_ "mod1.myvar", you're accessing a copy of the reference. So the wrong reference gets changed. In the general case, this isn't something people do a great deal. For most imports you want access to things from the module with no intention of changing those references in the source module. So "from xx import yy" is perfectly find for that, the most common use case. Consider: from os.path import basename, dirname Is your code more readable with: from os.path import basename, dirname base_of_parent_dir = basename(dirname(some_path)) or as: import os.path base_of_parent_dir = os.path.basename(os.path.dirname(some_path)) particularly when you make lots of such calls? I much prefer the former. >And, yes, I am trying to share state info between modules. Is this a bad >thing? I guess I would write getter() and setter() functions for all this. But >that does seem to remind me too much of some other language :) In controlled situations it can be ok. Usually I define a small class for this kind of thing and keep all the state in class instances. That way it can scale (keeping multiple "states" at once). However, it does depend on your particular situation. I find situations where I want to directly change "global" values in other modules very rare, though not unknown. Cheers, Cameron Simpson (formerly cs at zip.com.au) From ben+python at benfinney.id.au Tue Nov 14 16:43:01 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 15 Nov 2017 08:43:01 +1100 Subject: Time travel - how to simplify? References: <85vaicwsrm.fsf@benfinney.id.au> Message-ID: <85r2t0wn8a.fsf@benfinney.id.au> Ben Finney writes: > import itertools > > month_values = sorted(list(fut_suffix.keys())) > month_cycle = itertools.cycle(month_values) > > month_choice = 7 > three_months_starting_at_choice = [] > while len(three_months_starting_at_choice) < 3: > this_month = next(month_cycle) > if this_month >= month_choice: > three_months_starting_at_choice.append(this_month) Sorry, I now realise that won't do what you want; the wrap around from 12 to 1 will cause ?this_month >= month_choice? to be false. Well, I won't correct it; maybe this is a useful exercise. Do you have a way to fix that so it will work? -- \ ?I am too firm in my consciousness of the marvelous to be ever | `\ fascinated by the mere supernatural ?? ?Joseph Conrad, _The | _o__) Shadow-Line_ | Ben Finney From rantingrickjohnson at gmail.com Tue Nov 14 17:01:07 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 14 Nov 2017 14:01:07 -0800 (PST) Subject: Time travel - how to simplify? In-Reply-To: References: <85vaicwsrm.fsf@benfinney.id.au> Message-ID: On Tuesday, November 14, 2017 at 1:44:17 PM UTC-6, Ben Finney wrote: > Andrew Z writes: > > > Now i want to get certain number of months. Say, i need 3 months duration > > starting from any month in dict. > > > > so if i start @ 7th: > > my_choice =7 > > for mnth, value in fut_suffix: > > if my_choice >= mnth > > # life is great > > but if : > > my_choice = 12 then my "time travel" becomes pain in the neck.. > > The ?itertools? library in the Python standard library > has what you > need: > > import itertools > > month_values = sorted(list(fut_suffix.keys())) > month_cycle = itertools.cycle(month_values) > > month_choice = 7 > three_months_starting_at_choice = [] > while len(three_months_starting_at_choice) < 3: > this_month = next(month_cycle) > if this_month >= month_choice: > three_months_starting_at_choice.append(this_month) Ben's advice is spot on[1], and exactly what i would do, but i believe it's important for you to discover how to implement a simple cycling algorithm yourself, _before_ reaching for the pre-packaged junkfood in the itertools module. Can you do it? If not, then do as much as you can and then ask for help. Hey, you're only hurting yourself if you don't learn how. And it's surprisingly easy! [1] and it looks as though he included the kitchen sink, washcloths, dish soap, and some fine china as well! ?_? From rosuav at gmail.com Tue Nov 14 17:12:08 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Nov 2017 09:12:08 +1100 Subject: inspecting a callable for the arguments it accepts In-Reply-To: <20171114210505.GA16626@cskk.homeip.net> References: <20171114210505.GA16626@cskk.homeip.net> Message-ID: On Wed, Nov 15, 2017 at 8:05 AM, Cameron Simpson wrote: > I know that this isn't generally solvable, but I'm wondering if it is > partially solvable. > > I have a task manager which accepts callables, usually functions or > generators, and calls them on data items as needed. For reasons which, > frankly, suggest user interface ergonomics failure to me it happens that > inappropriate functions get submtted to this system. For example, functions > accepting no arguments but which are handed one by the system. > > I would like to inspect submitted functions' signatures for suitability at > submission time, without calling the function. For example to see if this > function accepts exactly one argument, or to see if it is a generator, etc. > > Is this possible, even in a limited way? Yes, it is. Sometimes in a very limited way, other times fairly well. (NOTE: I'm using CPython for this. Other interpreters may differ wildly.) First off, you can look at the function's attributes to see some of the info you want: >>> def wants_one_arg(x): pass ... >>> wants_one_arg.__code__.co_argcount 1 >>> wants_one_arg.__code__.co_varnames ('x',) co_varnames has the names of all local variables, and the first N of those are the arguments. You aren't matching on the argument names, but they might help you make more readable error messages. As to recognizing generators, every function has a set of flags which will tell you whether it yields or just returns: >>> def fun(): pass ... >>> def gen(): yield 1 ... >>> fun.__code__.co_flags 67 >>> gen.__code__.co_flags 99 That's the raw info. For human-friendly functions that look at this info, check out the inspect module: >>> inspect.isgeneratorfunction(fun) False >>> inspect.isgeneratorfunction(gen) True >>> inspect.signature(wants_one_arg) Poke around with its functions and you should be able to find most of what you want, I think. ChrisA From lawrencedo99 at gmail.com Tue Nov 14 18:28:24 2017 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 14 Nov 2017 15:28:24 -0800 (PST) Subject: Windows10 keyboard interupt In-Reply-To: <87d7b5b0-5a8f-475c-aea4-7fd8fed31730@googlegroups.com> References: <77876a3b-aae8-4ca2-ac79-5da4e4947e2e@googlegroups.com> <87d7b5b0-5a8f-475c-aea4-7fd8fed31730@googlegroups.com> Message-ID: <1c202a97-a9b3-4cc1-93d9-40ed71994151@googlegroups.com> On Wednesday, November 15, 2017 at 3:01:37 AM UTC+13, Kasper Jepsen wrote: > Forgot.. python 2.7 From cs at cskk.id.au Tue Nov 14 19:08:33 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 15 Nov 2017 11:08:33 +1100 Subject: inspecting a callable for the arguments it accepts In-Reply-To: References: Message-ID: <20171115000833.GA7645@cskk.homeip.net> On 15Nov2017 09:12, Chris Angelico wrote: >On Wed, Nov 15, 2017 at 8:05 AM, Cameron Simpson wrote: >> I know that this isn't generally solvable, but I'm wondering if it is >> partially solvable. >> >> I have a task manager which accepts callables, usually functions or >> generators, and calls them on data items as needed. For reasons which, >> frankly, suggest user interface ergonomics failure to me it happens that >> inappropriate functions get submtted to this system. For example, functions >> accepting no arguments but which are handed one by the system. >> >> I would like to inspect submitted functions' signatures for suitability at >> submission time, without calling the function. For example to see if this >> function accepts exactly one argument, or to see if it is a generator, etc. >> >> Is this possible, even in a limited way? > >Yes, it is. Sometimes in a very limited way, other times fairly well. >(NOTE: I'm using CPython for this. Other interpreters may differ >wildly.) I'm using CPython too. >First off, you can look at the function's attributes to see >some of the info you want: > >>>> def wants_one_arg(x): pass >... >>>> wants_one_arg.__code__.co_argcount >1 >>>> wants_one_arg.__code__.co_varnames >('x',) > >co_varnames has the names of all local variables, and the first N of >those are the arguments. You aren't matching on the argument names, >but they might help you make more readable error messages. > >As to recognizing generators, every function has a set of flags which >will tell you whether it yields or just returns: > >>>> def fun(): pass >... >>>> def gen(): yield 1 >... >>>> fun.__code__.co_flags >67 >>>> gen.__code__.co_flags >99 > >That's the raw info. For human-friendly functions that look at this >info, check out the inspect module: > >>>> inspect.isgeneratorfunction(fun) >False >>>> inspect.isgeneratorfunction(gen) >True >>>> inspect.signature(wants_one_arg) > > >Poke around with its functions and you should be able to find most of >what you want, I think. Thank you, looks like just what I need. Cheers, Cameron Simpson (formerly cs at zip.com.au) From rosuav at gmail.com Tue Nov 14 19:20:55 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Nov 2017 11:20:55 +1100 Subject: inspecting a callable for the arguments it accepts In-Reply-To: References: <20171114210505.GA16626@cskk.homeip.net> Message-ID: On Wed, Nov 15, 2017 at 9:03 AM, Stefan Ram wrote: > Cameron Simpson writes: >>I would like to inspect submitted functions' signatures for suitability at >>submission time, without calling the function. For example to see if this >>function accepts exactly one argument, or to see if it is a generator, etc. > > Sometimes, there is a __text__signature__: > > |>>> cos.__text_signature__ > |'($module, x, /)' > > , but not always. True. However, I'm pretty sure that applies only to Argument Clinic functions, which are all implemented in C; the context suggests that the functions in question will all be implemented in Python. ChrisA From greg.ewing at canterbury.ac.nz Wed Nov 15 00:34:20 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 15 Nov 2017 18:34:20 +1300 Subject: inspecting a callable for the arguments it accepts In-Reply-To: References: <20171114210505.GA16626@cskk.homeip.net> Message-ID: Chris Angelico wrote: >>>>wants_one_arg.__code__.co_argcount > > 1 > >>>>wants_one_arg.__code__.co_varnames > > ('x',) That will give you some idea, but it's not foolproof -- e.g. if the function has * or ** arguments, it's impossible to tell in general how many arguments it accepts without studying the code (and maybe not even then -- halting problem, etc.) Some of the co_flags seem to indicate presence of * and **: 0x04 - has *args 0x08 - has **kwds In Py3 there is also co_kwonlyargcount. -- Greg From rosuav at gmail.com Wed Nov 15 01:15:16 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Nov 2017 17:15:16 +1100 Subject: inspecting a callable for the arguments it accepts In-Reply-To: References: <20171114210505.GA16626@cskk.homeip.net> Message-ID: On Wed, Nov 15, 2017 at 4:34 PM, Gregory Ewing wrote: > Chris Angelico wrote: > >>>>> wants_one_arg.__code__.co_argcount >> >> >> 1 >> >>>>> wants_one_arg.__code__.co_varnames >> >> >> ('x',) > > > That will give you some idea, but it's not foolproof -- e.g. > if the function has * or ** arguments, it's impossible to tell > in general how many arguments it accepts without studying the > code (and maybe not even then -- halting problem, etc.) > > Some of the co_flags seem to indicate presence of * and **: > > 0x04 - has *args > 0x08 - has **kwds > > In Py3 there is also co_kwonlyargcount. Yep. Browsing __code__'s attributes was the stepping-stone to the actual way of doing it: the inspect module. But I figured it's better to look at those attributes briefly rather than say "here's the inspect module, it uses magic". ChrisA From wxjmfauth at gmail.com Wed Nov 15 03:53:28 2017 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 15 Nov 2017 00:53:28 -0800 (PST) Subject: =?UTF-8?Q?Windows_=2D_py363_crashes_with_=22vonL=C3=B6wis=2Epy=22?= Message-ID: <92c9e012-d6b6-4c41-9e0f-3d2ce61114b0@googlegroups.com> Sorry, to have to say it. Have a nice day. From radha.parashar at ipinfusion.com Wed Nov 15 04:09:11 2017 From: radha.parashar at ipinfusion.com (Radhey Parashar) Date: Wed, 15 Nov 2017 09:09:11 -0000 Subject: All the list getting appended of a dict if you are updating only first element list of dict Message-ID: <6ee437b223a52b534aac46b06bda612a@mail.gmail.com> Hi python , I am facing 1 issue with python related to append command in a list I am attaching PDB code for more understanding:- *I am having two classes :- * *class CITY:* * num = 0* * connectivity = []* *class CON:* * name = 0* * type = 0* (Pdb) p cities {1: <__main__.CITY instance at 0x7f9c00e03638>, 2: <__main__.CITY instance at 0x7f9c00e03680>, 3: <__main__.CITY instance at 0x7f9c00e03950>, 4: <__main__.CITY instance at 0x7f9c00e03998>, 5: <__main__.CITY instance at 0x7f9c00e039e0>} (Pdb) > /home/radhey/python/code.py(16)func() -> list = [] (Pdb) p data ['1', '2', '3'] * (Pdb) p cities[int(data[0])].connectivity ----------------**? Here cities name dictionary are having city class object and each object connectivity list is empty * *[]* *(Pdb) p cities[int(data[1])].connectivity* *[]* *(Pdb) p cities[int(data[2])].connectivity* *[]* (Pdb) p cities[int(data[3])].connectivity *** IndexError: IndexError('list index out of range',) (Pdb) n > /home/radhey/python/code.py(17)func() -> list = cities[int(data[0])].connectivity (Pdb) > /home/radhey/python/code.py(18)func() -> list.append(con) (Pdb) > /home/radhey/python/code.py(19)func() -> cities[int(data[0])].connectivity = [] (Pdb) > /home/radhey/python/code.py(20)func() -> *cities[int(data[0])].connectivity.extend(list) -------------**? Here I extended the connectivity list for cities[1] object * (Pdb) > /home/radhey/python/code.py(21)func() -> con1 = CON (Pdb) p cities[int(data[1])].connectivity --------? BUT All the *connectivity list got updated * [] (Pdb) p cities[int(data[0])].connectivity [] (Pdb) p int(data[1]) 2 (Pdb) p int(data[0]) 1 (Pdb) Code.py :- root at OcNOS:/home/radhey/python# cat code.py class CITY: num = 0 connectivity = [] class CON: name = 0 type = 0 def func(cities): input = raw_input() con = '' con1 = '' data = input.strip().split(' ') con = CON con.name = int(data[1]) con.type = int(data[2]) list = [] list = cities[int(data[0])].connectivity list.append(con) cities[int(data[0])].connectivity = [] cities[int(data[0])].connectivity.extend(list) con1 = CON con1.name = int(data[0]) con1.type = int(data[2]) list = [] list = cities[int(data[1])].connectivity list.append(con1) cities[int(data[1])].connectivity = [] cities[int(data[1])].connectivity.extend(list) input = raw_input() city = int(input.split(' ')[0]) roads = int(input.split(' ')[1]) cities = {} for c in range(1,city+1): city = CITY() city.num = c cities[c] = city print city,roads for r in range(1,roads+1): func(cities) print cities Input :- 5 7 1 2 3 2 3 3 3 4 3 5 3 2 5 4 1 5 2 2 1 5 1 Thanks ~Radhey -- . From __peter__ at web.de Wed Nov 15 05:00:50 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 15 Nov 2017 11:00:50 +0100 Subject: All the list getting appended of a dict if you are updating only first element list of dict References: <6ee437b223a52b534aac46b06bda612a@mail.gmail.com> Message-ID: Radhey Parashar wrote: > I am facing 1 issue with python related to append command in a list > class CITY: > > num = 0 > > connectivity = [] The way you wrote it the connectivity list is shared between all instances of the CITY class. Consult a Python tutorial to learn why. To get per-instance lists you have to write an initializer like the one in the following example: class City: def __init__(self, num): self.num = num self.connectivity = [] From breamoreboy at gmail.com Wed Nov 15 06:58:23 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Wed, 15 Nov 2017 03:58:23 -0800 (PST) Subject: =?UTF-8?Q?Re=3A_Windows_=2D_py363_crashes_with_=22vonL=C3=B6wis=2Epy=22?= In-Reply-To: <92c9e012-d6b6-4c41-9e0f-3d2ce61114b0@googlegroups.com> References: <92c9e012-d6b6-4c41-9e0f-3d2ce61114b0@googlegroups.com> Message-ID: <485358ed-0d76-4ece-8b39-7a41e27c0909@googlegroups.com> On Wednesday, November 15, 2017 at 8:53:44 AM UTC, wxjm... at gmail.com wrote: > Sorry, to have to say it. > > Have a nice day. Do you mean it segfaults or simply provides a traceback? If the latter is your environment set correctly? From phd at phdru.name Wed Nov 15 09:13:20 2017 From: phd at phdru.name (Oleg Broytman) Date: Wed, 15 Nov 2017 15:13:20 +0100 Subject: SQLObject 3.5.0 Message-ID: <20171115141320.GA28654@phdru.name> Hello! I'm pleased to announce version 3.5.0, the first stable release of branch 3.5 of SQLObject. What's new in SQLObject ======================= Contributors for this release are Shailesh Mungikar and Michael S. Root. Minor features -------------- * Add Python3 special methods for division to SQLExpression. Pull request by Michael S. Root. Drivers ------- * Add support for `pg8000 `_ PostgreSQL driver. * Fix autoreconnect with pymysql driver. Contributed by Shailesh Mungikar. Documentation ------------- * Remove generated HTML from eggs/wheels (docs are installed into wrong place). Generated docs are still included in the source distribution. Tests ----- * Add tests for PyGreSQL, py-postgresql and pg8000 at AppVeyor. * Fixed bugs in py-postgresql at AppVeyor. SQLObject requires the latest version of the driver from our fork. For a more complete list, please see the news: http://sqlobject.org/News.html What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Python 2.7 or 3.4+ is required. Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Download: https://pypi.python.org/pypi/SQLObject/3.5.0 News and changes: http://sqlobject.org/News.html StackOverflow: https://stackoverflow.com/questions/tagged/sqlobject Example ======= Create a simple class that wraps a table:: >>> from sqlobject import * >>> >>> sqlhub.processConnection = connectionForURI('sqlite:/:memory:') >>> >>> class Person(SQLObject): ... fname = StringCol() ... mi = StringCol(length=1, default=None) ... lname = StringCol() ... >>> Person.createTable() Use the object:: >>> p = Person(fname="John", lname="Doe") >>> p >>> p.fname 'John' >>> p.mi = 'Q' >>> p2 = Person.get(1) >>> p2 >>> p is p2 True Queries:: >>> p3 = Person.selectBy(lname="Doe")[0] >>> p3 >>> pc = Person.select(Person.q.lname=="Doe").count() >>> pc 1 Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From mal at europython.eu Wed Nov 15 10:51:06 2017 From: mal at europython.eu (M.-A. Lemburg) Date: Wed, 15 Nov 2017 16:51:06 +0100 Subject: EuroPython 2018: Location and Dates Message-ID: <95f6d9d1-e3e2-e572-a3ca-78c156d71165@europython.eu> After a two month RFP bidding process with 19 venues from all over Europe, we are pleased to announce our selection of the location and venue for EuroPython 2018: * Location: Edinburgh, UK * Venue: Edinburgh International Conference Center (EICC) http://www.eicc.co.uk/ * Dates: July 23 - 29 2018 ... yes, this is just one week before the famous Edinburgh Festival Fringe, so you can extend your stay a little longer if you like: https://www.edfringe.com/ Based on the feedback we collected in the last few years, we have switched to a more compact conference layout for 2018: * Monday, Tuesday: Workshops and Trainings * Wednesday, Thursday, Friday: Main conference with talks, keynotes, exhibition * Saturday, Sunday: Sprints More information will be available as we progress with the organization. PS: We are now entering contract negotiations, so the above dates are highly likely, but we cannot confirm 100% yet. Enjoy, -- EuroPython Society http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europythons/status/930823621202898945 Thanks. From toby at tobiah.org Wed Nov 15 11:31:54 2017 From: toby at tobiah.org (Tobiah) Date: Wed, 15 Nov 2017 08:31:54 -0800 Subject: MySQLdb and conn.select_db() Message-ID: I have an older Ubuntu machine, 8.04 that errors when I try to do conn.select_db(). AttributeError: 'Connection' object has no attribute 'select_db' My 16.4 box acts as I'd expect. Did this get added at some point? I'd really like to be able to get generic links so I can do things like "show databases" and then maybe select_db() after that. It's also handy to be able to change databases on the fly for things like looking at the table set in multiple databases. The main docs that I can find only show select_db() under the _mysql library, yet my new machine is supporting it from the MySQLdb library. Are the docs lagging? Can I download the 'better' MySQLdb package and install it on the 8.04 machine? Thanks, Tobiah From lawrencedo99 at gmail.com Wed Nov 15 17:20:12 2017 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 15 Nov 2017 14:20:12 -0800 (PST) Subject: MySQLdb and conn.select_db() (Posting On Python-List Prohibited) In-Reply-To: References: Message-ID: On Thursday, November 16, 2017 at 5:32:23 AM UTC+13, Tobiah wrote: > AttributeError: 'Connection' object has no attribute 'select_db' You could always execute a ?use ?db_name?? MySQL command. From tjreedy at udel.edu Wed Nov 15 17:43:10 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 15 Nov 2017 17:43:10 -0500 Subject: =?UTF-8?Q?Re:_Windows_-_py363_crashes_with_=22vonL=c3=b6wis.py=22?= In-Reply-To: <485358ed-0d76-4ece-8b39-7a41e27c0909@googlegroups.com> References: <92c9e012-d6b6-4c41-9e0f-3d2ce61114b0@googlegroups.com> <485358ed-0d76-4ece-8b39-7a41e27c0909@googlegroups.com> Message-ID: On 11/15/2017 6:58 AM, breamoreboy at gmail.com wrote: > On Wednesday, November 15, 2017 at 8:53:44 AM UTC, wxjm... at gmail.com wrote: >> Sorry, to have to say it. >> >> Have a nice day. > > Do you mean it segfaults or simply provides a traceback? If the latter is your environment set correctly? Why bother? Anyway, for the obvious interpretation of the message, given f:/python/a/vonL?wis.py containing 'print("works")'" C:\Users\Terry>py -3.6 f:/python/a/vonL?wis.py works -- Terry Jan Reedy From lawrencedo99 at gmail.com Wed Nov 15 20:45:24 2017 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 15 Nov 2017 17:45:24 -0800 (PST) Subject: To ASCII Or Not To ASCII? (Posting On Python-List Prohibited) Message-ID: <44bd928d-d6eb-495f-8b33-294543479f5d@googlegroups.com> >From : def ra?se(self) : "raises this exception." libm.feraiseexcept(self.mask) #end ra?se raiise = ra?se # if you prefer From saeedbaig616 at icloud.com Thu Nov 16 01:16:11 2017 From: saeedbaig616 at icloud.com (Saeed Baig) Date: Thu, 16 Nov 2017 17:16:11 +1100 Subject: Should constants be introduced to Python? Message-ID: <5D4DA7B2-504A-4A3A-BACE-FFADEA1D25DF@icloud.com> Hey guys I am thinking of perhaps writing a PEP to introduce constants to Python. Something along the lines of Swift?s ?let? syntax (e.g. ?let pi = 3.14?). Since I?m sort of new to this, I just wanted to ask: - Has a PEP for this already been written? If so, where can I find the link/info to it? - Do you guys think it would be a good idea? Why or why not? Do you think there?s a better way to do it? I?d like to know what others think about this idea before making any formal submission. From auriocus at gmx.de Thu Nov 16 01:17:09 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 16 Nov 2017 07:17:09 +0100 Subject: To ASCII Or Not To ASCII? (Posting On Python-List Prohibited) In-Reply-To: <44bd928d-d6eb-495f-8b33-294543479f5d@googlegroups.com> References: <44bd928d-d6eb-495f-8b33-294543479f5d@googlegroups.com> Message-ID: Am 16.11.17 um 02:45 schrieb Lawrence D?Oliveiro: > From : > > def ra?se(self) : > "raises this exception." > libm.feraiseexcept(self.mask) > #end ra?se > > raiise = ra?se # if you prefer > you do this to annoy people? Christian From breamoreboy at gmail.com Thu Nov 16 05:51:51 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Thu, 16 Nov 2017 02:51:51 -0800 (PST) Subject: =?UTF-8?Q?Re=3A_Windows_=2D_py363_crashes_with_=22vonL=C3=B6wis=2Epy=22?= In-Reply-To: <1b7cae3b-5342-46e6-a5ca-6f7315ece10a@googlegroups.com> References: <92c9e012-d6b6-4c41-9e0f-3d2ce61114b0@googlegroups.com> <485358ed-0d76-4ece-8b39-7a41e27c0909@googlegroups.com> <1b7cae3b-5342-46e6-a5ca-6f7315ece10a@googlegroups.com> Message-ID: <94aba3ce-ecfe-4d8b-8986-93d75f41dd81@googlegroups.com> On Thursday, November 16, 2017 at 8:43:24 AM UTC, wxjm... at gmail.com wrote: > Le mercredi 15 novembre 2017 23:43:46 UTC+1, Terry Reedy a ?crit?: > > On 11/15/2017 6:58 AM, breamoreboy wrote: > > > On Wednesday, November 15, 2017 at 8:53:44 AM UTC, wxjm... at gmail.com wrote: > > >> Sorry, to have to say it. > > >> > > >> Have a nice day. > > > > > > Do you mean it segfaults or simply provides a traceback? If the latter is your environment set correctly? > > > > Why bother? Anyway, for the obvious interpretation of the message, > > given f:/python/a/vonL?wis.py containing 'print("works")'" > > > > C:\Users\Terry>py -3.6 f:/python/a/vonL?wis.py > > works > > > > -- > > Terry Jan Reedy > > Do you remember stringbench.py ? Years later, I still do > not understand how it is possible to write a test module, > which is supposed to test Unicode and does not even > contain a non ascii char... What has benchmarking (I assume) code got to do with your claim in the subject that Python 3.6 crashes? I have never known any other person make this claim. > > ----- > > Quick experiment > > 1) Download Py363, the embeded version. This just > avoid a Python installation. > 2) Unpacked it in a dir. > 2) Put "caf?.py" in python36.zip > 3) Launch python.exe So I'll repeat my question, does it segfault or does it give a traceback? > > --------- > > You do not imagine how this language is problematic > as soon as one leaves the ascii world (all platforms). > It is better to not speak about the Flexible String > Representation... The thing that works perfectly all around the world except for one user, you. > > Do not take this msg badly. It's only illustrating, > some people are still living on an another planet. It's quite clear that you're in another universe. Unless of course you'd actually, for the first time ever, like to produce some evidence to support your claims. I know that hell will freeze over before that happens. > > Regards. So how many bug reports have you raised over the years to report the dreadful state of Python's unicode implementation? What is the difference between you running vonL?wis.py and Terry Reedy running it? What is the difference between you running vonL?wis.py and caf?.py? Why are you incapable of running code that tens of thousands of users all around the world are quite content with, to the extent that Python 3.6 is widely recognised as the best ever version of Python? From breamoreboy at gmail.com Thu Nov 16 05:55:37 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Thu, 16 Nov 2017 02:55:37 -0800 (PST) Subject: Dropbox releases PyAnnotate -- auto-generate type annotations for mypy Message-ID: As type annotations seem to be taking off in a big way I thought that http://mypy-lang.blogspot.co.uk/2017/11/dropbox-releases-pyannotate-auto.html would be of interest, to some of you anyway. -- Kindest regards. Mark Lawrence. From tjol at tjol.eu Thu Nov 16 07:35:56 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 16 Nov 2017 13:35:56 +0100 Subject: =?UTF-8?Q?Re:_Windows_-_py363_crashes_with_=22vonL=c3=b6wis.py=22?= In-Reply-To: <94aba3ce-ecfe-4d8b-8986-93d75f41dd81@googlegroups.com> References: <92c9e012-d6b6-4c41-9e0f-3d2ce61114b0@googlegroups.com> <485358ed-0d76-4ece-8b39-7a41e27c0909@googlegroups.com> <1b7cae3b-5342-46e6-a5ca-6f7315ece10a@googlegroups.com> <94aba3ce-ecfe-4d8b-8986-93d75f41dd81@googlegroups.com> Message-ID: On 2017-11-16 11:51, breamoreboy at gmail.com wrote: > On Thursday, November 16, 2017 at 8:43:24 AM UTC, wxjm... at gmail.com wrote: >> Le mercredi 15 novembre 2017 23:43:46 UTC+1, Terry Reedy a ?crit?: >>> On 11/15/2017 6:58 AM, breamoreboy wrote: >>>> On Wednesday, November 15, 2017 at 8:53:44 AM UTC, wxjm... at gmail.com wrote: >> 2) Put "caf?.py" in python36.zip This is rather unorthodox. Perhaps the OP (or someone else) can clarify whether this is necessary: does the non-ASCII filename have to be in the stdlib zip? Does it have to be imported? Can it be in any other zip file on sys.path? Also... >> 3) Launch python.exe > > So I'll repeat my question, does it segfault or does it give a traceback? Indeed. From subharaj.manna at gmail.com Thu Nov 16 09:39:14 2017 From: subharaj.manna at gmail.com (Debraj Manna) Date: Thu, 16 Nov 2017 20:09:14 +0530 Subject: How to maintain same permissions on python dist-package after upgrade? Message-ID: I am using a python package patroni version 1.0 on Ubuntu 14. On doing ls -lrt /usr/local/lib/python2.7/dist-packages/ I am seeing the permission like below drwxr-sr-x 4 root staff 4096 Nov 6 14:29 patroni drwxr-sr-x 2 root staff 4096 Nov 6 14:29 patroni-1.0-py2.7.egg-info But once I upgrade the patroni via the command sudo pip install patroni --upgrade I am seeing the permission of the patroni change after upgrade drwxr-s--- 4 root staff 4096 Nov 6 15:29 patroni drwxr-s--- 2 root staff 4096 Nov 6 15:29 patroni-1.3.6.dist-info The installation output is attached (sudo-pip-install.txt). If I don't use sudo and just do pip install patroni --upgrade it fails. The output is attached (pip-install.txt). Can someone let me know :- 1. Why is the permission changing after upgrade? 2. How can I have the same permission even after the upgrade? Due to some other limitations I cannot switch to virtualenv like environment now. -------------- next part -------------- sudo pip install patroni --upgrade The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. /usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning Collecting patroni Requirement already up-to-date: requests in /usr/local/lib/python2.7/dist-packages (from patroni) Collecting cdiff (from patroni) Requirement already up-to-date: six>=1.7 in /usr/local/lib/python2.7/dist-packages (from patroni) Collecting python-etcd<0.5,>=0.4.3 (from patroni) Requirement already up-to-date: prettytable>=0.7 in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: tzlocal in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: boto in /usr/local/lib/python2.7/dist-packages (from patroni) Collecting python-consul>=0.7.0 (from patroni) Downloading python_consul-0.7.2-py2.py3-none-any.whl Requirement already up-to-date: psycopg2>=2.6.1 in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: kazoo==2.2.1 in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: urllib3>=1.9 in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: click>=4.1 in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: python-dateutil in /usr/local/lib/python2.7/dist-packages (from patroni) Collecting psutil (from patroni) Requirement already up-to-date: PyYAML in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: certifi>=2017.4.17 in /usr/local/lib/python2.7/dist-packages (from requests->patroni) Requirement already up-to-date: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python2.7/dist-packages (from requests->patroni) Requirement already up-to-date: idna<2.7,>=2.5 in /usr/local/lib/python2.7/dist-packages (from requests->patroni) Requirement already up-to-date: dnspython>=1.13.0 in /usr/local/lib/python2.7/dist-packages (from python-etcd<0.5,>=0.4.3->patroni) Requirement already up-to-date: pytz in /usr/local/lib/python2.7/dist-packages (from tzlocal->patroni) Installing collected packages: cdiff, python-etcd, python-consul, psutil, patroni Found existing installation: python-etcd 0.4.3 Uninstalling python-etcd-0.4.3: Successfully uninstalled python-etcd-0.4.3 Found existing installation: python-consul 0.6.0 Uninstalling python-consul-0.6.0: Successfully uninstalled python-consul-0.6.0 Found existing installation: patroni 1.0 Uninstalling patroni-1.0: Successfully uninstalled patroni-1.0 Successfully installed cdiff-1.0 patroni-1.3.6 psutil-5.4.1 python-consul-0.7.2 python-etcd-0.4.5 You are using pip version 7.1.2, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. -------------- next part -------------- pip install patroni --upgrade /usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning Collecting patroni Downloading patroni-1.3.6.tar.gz (90kB) 100% |????????????????????????????????| 94kB 1.0MB/s Requirement already up-to-date: urllib3>=1.9 in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: boto in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: psycopg2>=2.6.1 in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: PyYAML in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: requests in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: six>=1.7 in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: kazoo==2.2.1 in /usr/local/lib/python2.7/dist-packages (from patroni) Collecting python-etcd<0.5,>=0.4.3 (from patroni) Downloading python-etcd-0.4.5.tar.gz Collecting python-consul>=0.7.0 (from patroni) Downloading python_consul-0.7.2-py2.py3-none-any.whl Requirement already up-to-date: click>=4.1 in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: prettytable>=0.7 in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: tzlocal in /usr/local/lib/python2.7/dist-packages (from patroni) Requirement already up-to-date: python-dateutil in /usr/local/lib/python2.7/dist-packages (from patroni) Collecting psutil (from patroni) Downloading psutil-5.4.1.tar.gz (408kB) 100% |????????????????????????????????| 409kB 1.1MB/s Collecting cdiff (from patroni) Downloading cdiff-1.0.tar.gz Requirement already up-to-date: certifi>=2017.4.17 in /usr/local/lib/python2.7/dist-packages (from requests->patroni) Requirement already up-to-date: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python2.7/dist-packages (from requests->patroni) Requirement already up-to-date: idna<2.7,>=2.5 in /usr/local/lib/python2.7/dist-packages (from requests->patroni) Requirement already up-to-date: dnspython>=1.13.0 in /usr/local/lib/python2.7/dist-packages (from python-etcd<0.5,>=0.4.3->patroni) Requirement already up-to-date: pytz in /usr/local/lib/python2.7/dist-packages (from tzlocal->patroni) Building wheels for collected packages: patroni, python-etcd, psutil, cdiff Running setup.py bdist_wheel for patroni Stored in directory: /home/ubuntu/.cache/pip/wheels/86/5a/e3/cb4ac4ecf20bc7a2956062d3c3ad15c660a993a0cc3aa23d35 Running setup.py bdist_wheel for python-etcd Stored in directory: /home/ubuntu/.cache/pip/wheels/d1/79/df/26facc508cdb5fefaf3d574fb634d848754a7e69d95f53f056 Running setup.py bdist_wheel for psutil Stored in directory: /home/ubuntu/.cache/pip/wheels/05/a2/2a/2015d6af91fb5a4cc5bcdfa9699034e2f624fc9cc5acde7ab9 Running setup.py bdist_wheel for cdiff Stored in directory: /home/ubuntu/.cache/pip/wheels/d9/67/dc/d53a3cfea638a5652d0d2054b447d67a7d2a2bdebf0f67765e Successfully built patroni python-etcd psutil cdiff Installing collected packages: python-etcd, python-consul, psutil, cdiff, patroni Found existing installation: python-etcd 0.4.3 Uninstalling python-etcd-0.4.3: Exception: Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 211, in main status = self.run(options, args) File "/usr/local/lib/python2.7/dist-packages/pip/commands/install.py", line 311, in run root=options.root_path, File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 640, in install requirement.uninstall(auto_confirm=True) File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 716, in uninstall paths_to_remove.remove(auto_confirm) File "/usr/local/lib/python2.7/dist-packages/pip/req/req_uninstall.py", line 125, in remove renames(path, new_path) File "/usr/local/lib/python2.7/dist-packages/pip/utils/__init__.py", line 315, in renames shutil.move(old, new) File "/usr/lib/python2.7/shutil.py", line 303, in move os.unlink(src) OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/etcd/__init__.py' /usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning You are using pip version 7.1.2, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. From wxjmfauth at gmail.com Thu Nov 16 11:04:31 2017 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 16 Nov 2017 08:04:31 -0800 (PST) Subject: =?UTF-8?Q?Re=3A_Windows_=2D_py363_crashes_with_=22vonL=C3=B6wis=2Epy=22?= In-Reply-To: References: <92c9e012-d6b6-4c41-9e0f-3d2ce61114b0@googlegroups.com> <485358ed-0d76-4ece-8b39-7a41e27c0909@googlegroups.com> <1b7cae3b-5342-46e6-a5ca-6f7315ece10a@googlegroups.com> <94aba3ce-ecfe-4d8b-8986-93d75f41dd81@googlegroups.com> Message-ID: Le jeudi 16 novembre 2017 13:37:20 UTC+1, Thomas Jollans a ?crit?: > On 2017-11-16 11:51, breamoreboy at gmail.com wrote: > > On Thursday, November 16, 2017 at 8:43:24 AM UTC, wxjm... at gmail.com wrote: > >> Le mercredi 15 novembre 2017 23:43:46 UTC+1, Terry Reedy a ?crit?: > >>> On 11/15/2017 6:58 AM, breamoreboy wrote: > >>>> On Wednesday, November 15, 2017 at 8:53:44 AM UTC, wxjm... at gmail.com wrote: > >> 2) Put "caf?.py" in python36.zip > > This is rather unorthodox. Perhaps the OP (or someone else) can clarify > whether this is necessary: does the non-ASCII filename have to be in the > stdlib zip? Does it have to be imported? Can it be in any other zip file > on sys.path? Also... > > > >> 3) Launch python.exe > > > > So I'll repeat my question, does it segfault or does it give a traceback? > > Indeed. - Yes I'm aware of the asccii limitation of stdlib, but still I think the problem is elsewehre. - This zip technology has always been a perpetual mess. - For a windows user, a zip looks like a dir, a compressed directory with limitation (see below [x]). - It's beyond my knowledge. If MS does not allow executables in such dirs, there are probably good reasons. - [x] On my Western European box. If I attempt to put ??????.txt in a compressed zip dir, I'm receiving the following msg. [Window Title] Erreur des Dossiers compress?s [Content] Impossible de compresser ?D:\XXX\names\??????.txt?, car il comporte des caract?res qui ne peuvent pas ?tre utilis?s dans un dossier compress?, tel que ????????. Renommez le fichier ou le r?pertoire. [OK] From wxjmfauth at gmail.com Thu Nov 16 11:39:03 2017 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 16 Nov 2017 08:39:03 -0800 (PST) Subject: =?UTF-8?Q?Re=3A_Windows_=2D_py363_crashes_with_=22vonL=C3=B6wis=2Epy=22?= In-Reply-To: References: <92c9e012-d6b6-4c41-9e0f-3d2ce61114b0@googlegroups.com> <485358ed-0d76-4ece-8b39-7a41e27c0909@googlegroups.com> <1b7cae3b-5342-46e6-a5ca-6f7315ece10a@googlegroups.com> <94aba3ce-ecfe-4d8b-8986-93d75f41dd81@googlegroups.com> Message-ID: <7c8ddf90-5186-407b-b0cf-54f2b34e74d4@googlegroups.com> Le jeudi 16 novembre 2017 17:04:45 UTC+1, wxjm... at gmail.com a ?crit?: > Le jeudi 16 novembre 2017 13:37:20 UTC+1, Thomas Jollans a ?crit?: > > On 2017-11-16 11:51, breamoreboy at gmail.com wrote: > > > On Thursday, November 16, 2017 at 8:43:24 AM UTC, wxjm... at gmail.com wrote: > > >> Le mercredi 15 novembre 2017 23:43:46 UTC+1, Terry Reedy a ?crit?: > > >>> On 11/15/2017 6:58 AM, breamoreboy wrote: > > >>>> On Wednesday, November 15, 2017 at 8:53:44 AM UTC, wxjm... at gmail.com wrote: > > >> 2) Put "caf?.py" in python36.zip > > > > This is rather unorthodox. Perhaps the OP (or someone else) can clarify > > whether this is necessary: does the non-ASCII filename have to be in the > > stdlib zip? Does it have to be imported? Can it be in any other zip file > > on sys.path? Also... > > > > > > >> 3) Launch python.exe > > > > > > So I'll repeat my question, does it segfault or does it give a traceback? > > > > Indeed. > > - Yes I'm aware of the asccii limitation of stdlib, but still I > think the problem is elsewehre. > > - This zip technology has always been a perpetual mess. > > - For a windows user, a zip looks like a dir, a compressed > directory with limitation (see below [x]). > > - It's beyond my knowledge. If MS does not allow executables > in such dirs, there are probably good reasons. > > - [x] On my Western European box. > If I attempt to put ??????.txt in a compressed zip dir, I'm > receiving the following msg. > > [Window Title] > Erreur des Dossiers compress?s > > [Content] > Impossible de compresser ?D:\XXX\names\??????.txt?, car il comporte des > caract?res qui ne peuvent pas ?tre utilis?s dans un dossier compress?, > tel que ????????. Renommez le fichier ou le r?pertoire. > > [OK] Addendum I found my test apps and indeed in Py363 zip apps are working. Understand they can be launched. D:\XXX\YYY\testzipapps>py36 ??????.zip this ia a zip application, abc??? I guess, The limitation is on the stdlib. From bob at mellowood.ca Thu Nov 16 12:42:59 2017 From: bob at mellowood.ca (bvdp) Date: Thu, 16 Nov 2017 09:42:59 -0800 (PST) Subject: from xx import yy In-Reply-To: References: <20171114212017.GA47992@cskk.homeip.net> Message-ID: <6993df86-3e38-468f-a031-1f0a93a3c195@googlegroups.com> On Tuesday, November 14, 2017 at 2:53:22 PM UTC-7, Cameron Simpson wrote: > On 13Nov2017 08:58, bvdp wrote: > >On Sunday, November 12, 2017 at 7:18:04 PM UTC-7, bvdp wrote: > >> I'm having a conceptual mind-fart today. I just modified a bunch of code to use "from xx import variable" when variable is a global in xx.py. But, when I change/read 'variable' it doesn't appear to change. I've written a bit of code to show the problem: > >> > >> mod1.py > >> myvar = 99 > >> def setvar(x): > >> global myvar > >> myvar = x > >> > >> test1.py > >> import mod1 > >> mod1.myvar = 44 > >> print (mod1.myvar) > >> mod1.setvar(33) > >> print (mod1.myvar) > >> > >> If this test1.py is run myvar is fine. But, if I run: > >> > >> test2.py > >> from mod1 import myvar, setvar > >> myvar = 44 > >> print (myvar) > >> setvar(33) > >> print (myvar) > >> > >> It doesn't print the '33'. > >> > >> I thought (apparently incorrectly) that import as would import the name myvar into the current module's namespace where it could be read by functions in the module???? > > > >Thanks all for confirming that I was wrong to use "from .. import". Hmmm, perhaps for functions it might be okay. But, in most cases it's a lot more obvious to use module.function() when calling. Maybe a bit slower, but I'm sure it's negligible in most cases. > > You're wrong to use it for this particular special case, and ony because you > lose the reference to the module itself, which means you're no longer accessing > the _reference_ "mod1.myvar", you're accessing a copy of the reference. So the > wrong reference gets changed. > > In the general case, this isn't something people do a great deal. For most > imports you want access to things from the module with no intention of changing > those references in the source module. > > So "from xx import yy" is perfectly find for that, the most common use case. > > Consider: > > from os.path import basename, dirname > > Is your code more readable with: > > from os.path import basename, dirname > base_of_parent_dir = basename(dirname(some_path)) > > or as: > > import os.path > base_of_parent_dir = os.path.basename(os.path.dirname(some_path)) > > particularly when you make lots of such calls? I much prefer the former. > > >And, yes, I am trying to share state info between modules. Is this a bad > >thing? I guess I would write getter() and setter() functions for all this. But > >that does seem to remind me too much of some other language :) > > In controlled situations it can be ok. Usually I define a small class for this > kind of thing and keep all the state in class instances. That way it can scale > (keeping multiple "states" at once). > > However, it does depend on your particular situation. I find situations where I > want to directly change "global" values in other modules very rare, though not > unknown. > > Cheers, > Cameron Simpson (formerly cs at zip.com.au) In my original case, I think (!!!), the problem was that I had a variable in mod1.py and when I did the "from mod1 import myvarible" all was fine. Python create a new local-to-the-module variable and initialized it to the value it was set to in mod1. And at this point all is well. But, when mod1 changed the value of myvariable the change didn't get passed to the other modules. Of course, the reason for my confusion is that I'm thinking that python is using pointers :) Opps. Maybe we need pointers in python . From ned at nedbatchelder.com Thu Nov 16 13:24:04 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 16 Nov 2017 13:24:04 -0500 Subject: Should constants be introduced to Python? In-Reply-To: <5D4DA7B2-504A-4A3A-BACE-FFADEA1D25DF@icloud.com> References: <5D4DA7B2-504A-4A3A-BACE-FFADEA1D25DF@icloud.com> Message-ID: <9268703a-f87a-a092-41f9-1882b683670f@nedbatchelder.com> On 11/16/17 1:16 AM, Saeed Baig wrote: > Hey guys I am thinking of perhaps writing a PEP to introduce constants to Python. Something along the lines of Swift?s ?let? syntax (e.g. ?let pi = 3.14?). > > Since I?m sort of new to this, I just wanted to ask: > - Has a PEP for this already been written? If so, where can I find the link/info to it? > - Do you guys think it would be a good idea? Why or why not? Do you think there?s a better way to do it? I?d like to know what others think about this idea before making any formal submission. I don't know if a PEP like this has been attempted before.? They are all in one place (https://github.com/python/peps/), so it's not hard to find out. But talking about it here first will be a good way to flesh out your ideas, hear the most likely objections, and so forth. Start by telling us: Why should Python have constants?? Be specific: what current problems would it solve? --Ned. From tjreedy at udel.edu Thu Nov 16 13:27:14 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 Nov 2017 13:27:14 -0500 Subject: =?UTF-8?Q?Re:_Windows_-_py363_crashes_with_=22vonL=c3=b6wis.py=22?= In-Reply-To: <94aba3ce-ecfe-4d8b-8986-93d75f41dd81@googlegroups.com> References: <92c9e012-d6b6-4c41-9e0f-3d2ce61114b0@googlegroups.com> <485358ed-0d76-4ece-8b39-7a41e27c0909@googlegroups.com> <1b7cae3b-5342-46e6-a5ca-6f7315ece10a@googlegroups.com> <94aba3ce-ecfe-4d8b-8986-93d75f41dd81@googlegroups.com> Message-ID: On 11/16/2017 5:51 AM, breamoreboy at gmail.com wrote: > On Thursday, November 16, 2017 at 8:43:24 AM UTC, wxjm... at gmail.com wrote: Mark: Jmf's troll posts to the Google group are not propagated to python-list and the gmane mirror except when people, like you here, quote him. Please stop. >> Do you remember stringbench.py ? Years later, I still do >> not understand how it is possible to write a test module, >> which is supposed to test Unicode and does not even >> contain a non ascii char... For the benefit of any unicode newbies who read Mark's post but have not read https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals , by using \uxxxx, \Uxxxxxxxx, and \N{name} escape sequences in string literals. -- Terry Jan Reedy From jakub.rajcok at gmail.com Thu Nov 16 13:47:53 2017 From: jakub.rajcok at gmail.com (jakub.rajcok at gmail.com) Date: Thu, 16 Nov 2017 10:47:53 -0800 (PST) Subject: Artificial creating of [Lists], is it possible? the best way... Message-ID: <2e31fcb3-8087-466e-9e77-53b964d44870@googlegroups.com> Hello, im working on school project, its deck game Sorry! I need to create specific lists: My idea is about to using for For i in range (n): i=[] I know, that there is no possibility to make it from number, but i havent idea, how to reach my wants Li/L"i"/L(i), how to make possible for lists? From cs at cskk.id.au Thu Nov 16 16:46:15 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 17 Nov 2017 08:46:15 +1100 Subject: from xx import yy In-Reply-To: <6993df86-3e38-468f-a031-1f0a93a3c195@googlegroups.com> References: <6993df86-3e38-468f-a031-1f0a93a3c195@googlegroups.com> Message-ID: <20171116214615.GA21529@cskk.homeip.net> On 16Nov2017 09:42, bvdp wrote: >In my original case, I think (!!!), the problem was that I had a variable in >mod1.py and when I did the "from mod1 import myvarible" all was fine. Python >create a new local-to-the-module variable and initialized it to the value it >was set to in mod1. And at this point all is well. But, when mod1 changed the >value of myvariable the change didn't get passed to the other modules. Of >course, the reason for my confusion is that I'm thinking that python is using >pointers :) Opps. > >Maybe we need pointers in python . Thinking about this as pointers works pretty well. We call them references in Python because they are not (or need not be) memory addresses and C pointers are memory addresses. However the model is the same: an arrow from a variable name pointing at the place a value (the object) is stored. Look: mod1.py: x = 1 making: mod1.x --> 1 Now consider: mod2.py: from mod1 import x Making: mod1.x --> 1 ^ mod2.x ----+ both referring to the "1" object. Now: mod2.py: x = 2 Making: mod1.x --> 1 mod2.x --> 2 You see that mod1 is not adjusted. Versus: mod2.py: import mod1 Making: mod2.mod1 --> mod1, mod1.x --> 1 Then: mod2.py: mod1.x = 2 Making: mod2.mod1 --> mod1, mod1.x --> 2 Because you're adjusting the reference "mod1.x", _not_ the distinct reference "mod2.x". Cheers, Cameron Simpson (formerly cs at zip.com.au) Draw little boxes with arrows. It helps. - Michael J. Eager From torriem at gmail.com Thu Nov 16 16:55:35 2017 From: torriem at gmail.com (Michael Torrie) Date: Thu, 16 Nov 2017 14:55:35 -0700 Subject: Should constants be introduced to Python? In-Reply-To: <5D4DA7B2-504A-4A3A-BACE-FFADEA1D25DF@icloud.com> References: <5D4DA7B2-504A-4A3A-BACE-FFADEA1D25DF@icloud.com> Message-ID: On 11/15/2017 11:16 PM, Saeed Baig wrote: > - Do you guys think it would be a good idea? Why or why not? Do you > think there?s a better way to do it? I?d like to know what others > think about this idea before making any formal submission. Except for forcing it to be read-only, there's absolutely no difference between your idea of a constant and a normal module name in Python. Since Python is a dynamic language, all names have to be looked up at run time. So there's really no speed benefit to having a special const syntax. In Python, we normally expect developers to act as consenting adults. Thus a constant is often denoted by an uppercase name (at least in the scripts I've seen), similar to C or other languages. We can just say to developers, please don't rebind a name that's all capitals. That's it. Constants as you propose really only make sense in statically-typed, compiled languages where the compiler replaces the constant names with the values in the compiled code. Doesn't work that way in Python, where things are interpreted at run time. That's my opinion anyway. From tjreedy at udel.edu Thu Nov 16 17:27:52 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 Nov 2017 17:27:52 -0500 Subject: Should constants be introduced to Python? In-Reply-To: References: <5D4DA7B2-504A-4A3A-BACE-FFADEA1D25DF@icloud.com> Message-ID: On 11/16/2017 4:55 PM, Michael Torrie wrote: > On 11/15/2017 11:16 PM, Saeed Baig wrote: >> - Do you guys think it would be a good idea? Why or why not? Do you >> think there?s a better way to do it? I?d like to know what others >> think about this idea before making any formal submission. > > Except for forcing it to be read-only, there's absolutely no difference > between your idea of a constant and a normal module name in Python. > Since Python is a dynamic language, all names have to be looked up at > run time. So there's really no speed benefit to having a special const > syntax. In Python, we normally expect developers to act as consenting > adults. Thus a constant is often denoted by an uppercase name (at least > in the scripts I've seen), similar to C or other languages. We can just > say to developers, please don't rebind a name that's all capitals. > That's it. The idea of named constants has been proposed before, and rejected pretty much for the reason you give above. > Constants as you propose really only make sense in statically-typed, > compiled languages where the compiler replaces the constant names with > the values in the compiled code. Doesn't work that way in Python, where > things are interpreted at run time. CPython, at least, already has anonymous constant objects. Number and string literals are turned into objects when parsed. I presume that all implementations do this. Some constant expressions are replaced by (constant) objects during compiling, instead of when running. For instance "n = 10 + 3' will run as 'n = 13', and "for lang in ('C', 'Java', 'Python') will have the tuple pre-computed (whereas "for lang in ['C', 'Java', 'Python] will have to construct the list each time run). -- Terry Jan Reedy From dvl at psu.edu Thu Nov 16 17:35:59 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Thu, 16 Nov 2017 17:35:59 -0500 Subject: Shoulid constants be introduced to Python? In-Reply-To: mailman.31.1510851603.19027.python-list@python.org References: Message-ID: <1510871759l.23068676l.0l@psu.edu> On Thu, Nov 16, 2017, Saeed Baig wrote: > Message: 7 >Date: Thu, 16 Nov 2017 17:16:11 +1100 >From: Saeed Baig >To: python-list at python.org >Subject: Should constants be introduced to Python? >Message-ID: <5D4DA7B2-504A-4A3A-BACE-FFADEA1D25DF at icloud.com> >Content-Type: text/plain; charset=utf-8 > >Hey guys I am thinking of perhaps writing a PEP to introduce constants to >Python. Something along the lines of Swift?s ?let? syntax (e.g. ?let pi = >3.14?). > >Since I?m sort of new to this, I just wanted to ask: >- Has a PEP for this already been written? If so, where can I find the >link/info to it? >- Do you guys think it would be a good idea? Why or why not? Do you think >there?s a better way to do it? I?d like to know what others think about this >idea before making any formal submission. Well, pi already does have a value: >>> import math >>> math.pi 3.141592653589793 but it's not a constant in the sense you are looking for: >>> math.pi = 2 >>> math.pi 2 The only PEP I saw that makes any mention of constants is the PEP 8 Style Guide, which recommends all constants be named with all caps, such as "math.PI". (Why the math module doesn't do that beats me, unless it is there for hyster^H^H^H^H^Historical reasons.) But certainly if we saw code like this: AVOGRADO_NUMBER = x + 2 I would believe that code to be 'obviously' since it is clearly attempting to modify a constant -- and the naming convention tells me so. Do you have any particular reason you wish to promote constants? Is it anything beyond "because C++ and Java, etc. have them"? Because do note all of those constants in those languages are *declared* to be constants, and declarations (esp variable declarations) are notably absent. I took a peek at the PEP 484 about Type Hints, and I didn't see anything there about constants either. So if you want to make a proposal, I think you should provide a compelling argument in favor of a name change. Suggesting that an interpreted language have all the features of a compiled language just does not seem to be sufficient cause. After all: Python pretends to have 'private' and 'protected' data, by having 'hidden' variables with leading underscores, but they really are none of the above. Python claims to have immutable data types, but those immutable data types may contain mutable elements, which are indeed quite mutable. Python does range checking on list indexes, but will not at all complain if your code accidentally goes one step before [0] and ends up at [-1]. Python allows these loopholes in with the expectation that the programmer should know better. I think the same thing would be true with constants. If you need this crutch to protect yourself from accidentally clobbering constants, then do better. If you only need it to for documentation purposes, just tweak the documentation. Roger Christman Pennsylvania State University From rosuav at gmail.com Thu Nov 16 17:39:20 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Nov 2017 09:39:20 +1100 Subject: Should constants be introduced to Python? In-Reply-To: References: <5D4DA7B2-504A-4A3A-BACE-FFADEA1D25DF@icloud.com> Message-ID: On Fri, Nov 17, 2017 at 9:27 AM, Terry Reedy wrote: > CPython, at least, already has anonymous constant objects. Number and > string literals are turned into objects when parsed. I presume that all > implementations do this. Some constant expressions are replaced by > (constant) objects during compiling, instead of when running. For instance > "n = 10 + 3' will run as 'n = 13', and "for lang in ('C', 'Java', 'Python') > will have the tuple pre-computed (whereas "for lang in ['C', 'Java', > 'Python] will have to construct the list each time run). Just to thoroughly confuse people, CPython can actually optimize one into the other... >>> def f(): ... for lang in ['C', 'Java', 'Python']: ... print(lang) ... >>> dis.dis(f) 2 0 SETUP_LOOP 20 (to 22) 2 LOAD_CONST 4 (('C', 'Java', 'Python')) 4 GET_ITER >> 6 FOR_ITER 12 (to 20) 8 STORE_FAST 0 (lang) 3 10 LOAD_GLOBAL 0 (print) 12 LOAD_FAST 0 (lang) 14 CALL_FUNCTION 1 16 POP_TOP 18 JUMP_ABSOLUTE 6 >> 20 POP_BLOCK >> 22 LOAD_CONST 0 (None) 24 RETURN_VALUE Since there's no way to get a reference to the underlying list during iteration (which would allow you to mutate it), Python can happily pretend that you used a tuple. Similarly with membership tests: >>> dis.dis("x in [1,2,3,4,5]") 1 0 LOAD_NAME 0 (x) 2 LOAD_CONST 5 ((1, 2, 3, 4, 5)) 4 COMPARE_OP 6 (in) 6 RETURN_VALUE >>> dis.dis("x in {1,2,3,4,5}") 1 0 LOAD_NAME 0 (x) 2 LOAD_CONST 5 (frozenset({1, 2, 3, 4, 5})) 4 COMPARE_OP 6 (in) 6 RETURN_VALUE However, outside of these special optimization cases, you're right that a tuple is a constant and a list gets built at run time. ChrisA From pkpearson at nowhere.invalid Thu Nov 16 17:54:05 2017 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 16 Nov 2017 22:54:05 GMT Subject: Artificial creating of [Lists], is it possible? the best way... References: <2e31fcb3-8087-466e-9e77-53b964d44870@googlegroups.com> Message-ID: On Thu, 16 Nov 2017 10:47:53 -0800 (PST), jakub.rajcok at gmail.com wrote: > Hello, im working on school project, its deck game Sorry! > I need to create specific lists: > My idea is about to using for > For i in range (n): > i=[] This will create n different empty lists, in succession, and discard all but the last one, which will be bound to the name "i". > I know, that there is no possibility to make it from number, but i > havent idea, how to reach my wants Li/L"i"/L(i), how to make possible > for lists? You'll find that the people on this newsgroup are very helpful, but they might (like me) be unable to discern what you're asking. -- To email me, substitute nowhere->runbox, invalid->com. From python at mrabarnett.plus.com Thu Nov 16 19:04:16 2017 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Nov 2017 00:04:16 +0000 Subject: Artificial creating of [Lists], is it possible? the best way... In-Reply-To: <2e31fcb3-8087-466e-9e77-53b964d44870@googlegroups.com> References: <2e31fcb3-8087-466e-9e77-53b964d44870@googlegroups.com> Message-ID: <2ffa0f4f-c2e7-6b5c-9bba-6f7a467f705f@mrabarnett.plus.com> On 2017-11-16 18:47, jakub.rajcok at gmail.com wrote: > Hello, im working on school project, its deck game Sorry! > I need to create specific lists: > My idea is about to using for > For i in range (n): > i=[] > I know, that there is no possibility to make it from number, but i havent idea, how to reach my wants Li/L"i"/L(i), how to make possible for lists? > > If you want multiple lists, make a list of lists: my_lists = [] for i in range(n): my_lists.append([]) Then you can say my_lists[0], my_lists[1], etc. From bc at freeuk.com Thu Nov 16 19:26:35 2017 From: bc at freeuk.com (bartc) Date: Fri, 17 Nov 2017 00:26:35 +0000 Subject: Should constants be introduced to Python? In-Reply-To: References: <5D4DA7B2-504A-4A3A-BACE-FFADEA1D25DF@icloud.com> Message-ID: On 16/11/2017 06:16, Saeed Baig wrote: > Hey guys I am thinking of perhaps writing a PEP to introduce constants to Python. Something along the lines of Swift?s ?let? syntax (e.g. ?let pi = 3.14?). > > Since I?m sort of new to this, I just wanted to ask: > - Has a PEP for this already been written? If so, where can I find the link/info to it? > - Do you guys think it would be a good idea? Why or why not? Do you think there?s a better way to do it? I?d like to know what others think about this idea before making any formal submission. > I've taken part in a few discussions here on the subject. However, if you're going to write a PEP, does that require that you have some idea of how it would be implemented? For example, you write this: let A = 10 let B = 20 x = A + B On CPython, would the byte-code compiler reduce the A+B to 30, or would it still do the calculation? Suppose those lets were in an imported module M: import M x = M.A + M.B Would it reduce the expression here or not? (And if so, how? Remember that M itself is not constant, so M could have been reassigned as another module, or a class, so that another M.A is not a constant.) What would happen here: let A = 10 A = 12 Would the assignment be allowed or not? Because the way Python works now, is that EVERY (top-level) identifier created by the user is a variable, and can be assigned something else. To prohibit A=12 would mean creating a new category of identifier that is fixed. And the error would be hard to pick up at compile-time here: M.A = 12 As the category of M.A is not known to the byte-code compiler (also that M is not constant as I said). Note that names are created also with 'import', 'def' and 'class', and it might be desirable to have these constant too, for example: let def F(): -- bartc From dieter at handshake.de Fri Nov 17 02:32:47 2017 From: dieter at handshake.de (dieter) Date: Fri, 17 Nov 2017 08:32:47 +0100 Subject: How to maintain same permissions on python dist-package after upgrade? References: Message-ID: <874lptz7fk.fsf@handshake.de> Debraj Manna writes: > I am using a python package patroni version 1.0 on Ubuntu 14. On doing ls > -lrt /usr/local/lib/python2.7/dist-packages/ I am seeing the permission > like below > > drwxr-sr-x 4 root staff 4096 Nov 6 14:29 patroni > drwxr-sr-x 2 root staff 4096 Nov 6 14:29 patroni-1.0-py2.7.egg-info > > But once I upgrade the patroni via the command sudo pip install patroni > --upgrade I am seeing the permission of the patroni change after upgrade > > drwxr-s--- 4 root staff 4096 Nov 6 15:29 patroni > drwxr-s--- 2 root staff 4096 Nov 6 15:29 patroni-1.3.6.dist-info > > The installation output is attached (sudo-pip-install.txt). > > If I don't use sudo and just do pip install patroni --upgrade it fails. The > output is attached (pip-install.txt). > > Can someone let me know :- Verify the "umask" effective for your "sudo" user, i.e. sudo bash umask Should the "umask" result end in "7", then this may be responsible for the permissions you observe. On POSIX systems, the "umask" setting effects the permissions of newly created directories and files. Use "umask 0002" to change this setting temporarily. From Karsten.Hilbert at gmx.net Fri Nov 17 03:29:07 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Fri, 17 Nov 2017 09:29:07 +0100 Subject: Shoulid constants be introduced to Python? In-Reply-To: <1510871759l.23068676l.0l@psu.edu> References: <1510871759l.23068676l.0l@psu.edu> Message-ID: <20171117082907.6s2ugwyafgtqbg3n@hermes.hilbert.loc> On Thu, Nov 16, 2017 at 05:35:59PM -0500, ROGER GRAYDON CHRISTMAN wrote: > Well, pi already does have a value: > >>>> import math >>>> math.pi > > 3.141592653589793 > > but it's not a constant in the sense you are looking for: And, it's not really a constant at all, it's only got a constant definition :-) > The only PEP I saw that makes any mention of constants is the PEP 8 Style Guide, > which recommends all constants be named with all caps, such as "math.PI". > (Why the math module doesn't do that beats me, unless it is there for > hyster^H^H^H^H^Historical reasons.) So, import math math.PI = math.pi seems helpful :) Karsten -- From p.f.moore at gmail.com Fri Nov 17 08:40:14 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 17 Nov 2017 13:40:14 +0000 Subject: "help( pi )" In-Reply-To: References: Message-ID: On 17 November 2017 at 12:36, Stefan Ram wrote: > A web page says: > > ?The argument to pydoc can be the name of a function, > module, or package, or a dotted reference to a class, > method, or function within a module or module in a package.? [...] > , but not for ?pi?: > > from math import pi > help( pi ) math.pi is not "a class method, or function within a module or module in a package". It's a number. I can see why you would want to be able to do this, but technically the help function shows the object's docstring, and numbers don't have docstrings. Paul From marcin.tustin at gmail.com Fri Nov 17 10:14:51 2017 From: marcin.tustin at gmail.com (Marcin Tustin) Date: Fri, 17 Nov 2017 10:14:51 -0500 Subject: Should constants be introduced to Python? In-Reply-To: <5D4DA7B2-504A-4A3A-BACE-FFADEA1D25DF@icloud.com> References: <5D4DA7B2-504A-4A3A-BACE-FFADEA1D25DF@icloud.com> Message-ID: I'm against this because Python's strength is its simplicity. This doesn't actually simplify anything, but it does add a new language feature to understand. All the benefits of this can be achieved with linting. On Thu, Nov 16, 2017 at 1:16 AM, Saeed Baig wrote: > Hey guys I am thinking of perhaps writing a PEP to introduce constants to > Python. Something along the lines of Swift?s ?let? syntax (e.g. ?let pi = > 3.14?). > > Since I?m sort of new to this, I just wanted to ask: > - Has a PEP for this already been written? If so, where can I find the > link/info to it? > - Do you guys think it would be a good idea? Why or why not? Do you think > there?s a better way to do it? I?d like to know what others think about > this idea before making any formal submission. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Marcin Tustin Tel: +1 917 553 3974 From ethernet.zero at gmail.com Fri Nov 17 10:29:42 2017 From: ethernet.zero at gmail.com (eth0) Date: Fri, 17 Nov 2017 15:29:42 -0000 (UTC) Subject: Artificial creating of [Lists], is it possible? the best way... References: <2e31fcb3-8087-466e-9e77-53b964d44870@googlegroups.com> <2ffa0f4f-c2e7-6b5c-9bba-6f7a467f705f@mrabarnett.plus.com> Message-ID: On Fri, 17 Nov 2017 00:04:16 +0000 in comp.lang.python, MRAB said: > On 2017-11-16 18:47, jakub.rajcok at gmail.com wrote: > > Hello, im working on school project, its deck game Sorry! > > I need to create specific lists: > > My idea is about to using for > > For i in range (n): > > i=[] > > I know, that there is no possibility to make it from number, but > > i havent idea, how to reach my wants Li/L"i"/L(i), how to make > > possible for lists? > > > > > If you want multiple lists, make a list of lists: > > my_lists = [] > > for i in range(n): > my_lists.append([]) > > Then you can say my_lists[0], my_lists[1], etc. It'd be even shorter using a list comprehension: my_lists = [[] for i in range(n)] And _even shorter still_ just using the multiply operator: my_lists = [[]] * n From marko at pacujo.net Fri Nov 17 10:52:37 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 17 Nov 2017 17:52:37 +0200 Subject: "help( pi )" References: Message-ID: <87wp2olx6i.fsf@elektro.pacujo.net> Paul Moore : > numbers don't have docstrings. There's no reason they couldn't: >>> help(2) Help on built-in number 2 in module builtins: 2 2 -> int The natural number immediately succeeding 1 (qv). The number of hemispheres in a healthy mammal's brain. It might also be useful to define a __docstr__() method for cases where a static __doc__ string is unwieldy. Then, the class could construct the doc string for its objects. Marko From marko at pacujo.net Fri Nov 17 10:55:38 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 17 Nov 2017 17:55:38 +0200 Subject: Should constants be introduced to Python? References: <5D4DA7B2-504A-4A3A-BACE-FFADEA1D25DF@icloud.com> Message-ID: <87shdclx1h.fsf@elektro.pacujo.net> Marcin Tustin : > I'm against this because Python's strength is its simplicity. This > doesn't actually simplify anything, but it does add a new language > feature to understand. And there will be eternal debates on the correct use of the feature. One of the ugliest features of C is the "const" modifier. There's no way to use it correctly. Even the POSIX libraries and C standards abuse it. Marko From rosuav at gmail.com Fri Nov 17 11:08:56 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Nov 2017 03:08:56 +1100 Subject: Artificial creating of [Lists], is it possible? the best way... In-Reply-To: References: <2e31fcb3-8087-466e-9e77-53b964d44870@googlegroups.com> <2ffa0f4f-c2e7-6b5c-9bba-6f7a467f705f@mrabarnett.plus.com> Message-ID: On Sat, Nov 18, 2017 at 2:29 AM, eth0 wrote: > On Fri, 17 Nov 2017 00:04:16 +0000 in comp.lang.python, MRAB said: >> On 2017-11-16 18:47, jakub.rajcok at gmail.com wrote: >> > Hello, im working on school project, its deck game Sorry! >> > I need to create specific lists: >> > My idea is about to using for >> > For i in range (n): >> > i=[] >> > I know, that there is no possibility to make it from number, but >> > i havent idea, how to reach my wants Li/L"i"/L(i), how to make >> > possible for lists? >> > >> > >> If you want multiple lists, make a list of lists: >> >> my_lists = [] >> >> for i in range(n): >> my_lists.append([]) >> >> Then you can say my_lists[0], my_lists[1], etc. > > It'd be even shorter using a list comprehension: > > my_lists = [[] for i in range(n)] > > And _even shorter still_ just using the multiply operator: > > my_lists = [[]] * n Those are semantically different though. ChrisA From p.f.moore at gmail.com Fri Nov 17 11:15:51 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 17 Nov 2017 16:15:51 +0000 Subject: "help( pi )" In-Reply-To: <87wp2olx6i.fsf@elektro.pacujo.net> References: <87wp2olx6i.fsf@elektro.pacujo.net> Message-ID: On 17 November 2017 at 15:52, Marko Rauhamaa wrote: > Paul Moore : >> numbers don't have docstrings. > > There's no reason they couldn't: In the sense that the Python object model could be amended to attach docstrings to instances of classes like "int", and syntax could be added to the language to write those docstrings in your code, then yes, of course there's no reason they couldn't. I'd say "patches gratefully accepted" but actually I suspect "justifications for why the extra complexity is worth it, followed up with a patch, might just be accepted if the justification were *extremely* strong" is more accurate ;-) Paul From grant.b.edwards at gmail.com Fri Nov 17 11:44:52 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 17 Nov 2017 16:44:52 +0000 (UTC) Subject: Artificial creating of [Lists], is it possible? the best way... References: <2e31fcb3-8087-466e-9e77-53b964d44870@googlegroups.com> <2ffa0f4f-c2e7-6b5c-9bba-6f7a467f705f@mrabarnett.plus.com> Message-ID: On 2017-11-17, eth0 wrote: > On Fri, 17 Nov 2017 00:04:16 +0000 in comp.lang.python, MRAB said: >> On 2017-11-16 18:47, jakub.rajcok at gmail.com wrote: >> > Hello, im working on school project, its deck game Sorry! >> > I need to create specific lists: >> > My idea is about to using for >> > For i in range (n): >> > i=[] >> > I know, that there is no possibility to make it from number, but >> > i havent idea, how to reach my wants Li/L"i"/L(i), how to make >> > possible for lists? >> > >> > >> If you want multiple lists, make a list of lists: >> >> my_lists = [] >> >> for i in range(n): >> my_lists.append([]) >> >> Then you can say my_lists[0], my_lists[1], etc. > > It'd be even shorter using a list comprehension: > > my_lists = [[] for i in range(n)] > > And _even shorter still_ just using the multiply operator: > > my_lists = [[]] * n $ python Python 2.7.14 (default, Nov 2 2017, 11:45:51) [GCC 5.4.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = [[] for i in 1,2,3,4] >>> x [[], [], [], []] >>> y = [[]] * 4 >>> y [[], [], [], []] >>> x[0].append(1) >>> y[0].append(1) >>> x [[1], [], [], []] >>> y [[1], [1], [1], [1]] -- Grant Edwards grant.b.edwards Yow! Do I have a lifestyle at yet? gmail.com From bob at mellowood.ca Fri Nov 17 12:26:45 2017 From: bob at mellowood.ca (Bob van der Poel) Date: Fri, 17 Nov 2017 10:26:45 -0700 Subject: from xx import yy In-Reply-To: <20171116214615.GA21529@cskk.homeip.net> References: <6993df86-3e38-468f-a031-1f0a93a3c195@googlegroups.com> <20171116214615.GA21529@cskk.homeip.net> Message-ID: On Thu, Nov 16, 2017 at 2:46 PM, Cameron Simpson wrote: > On 16Nov2017 09:42, bvdp wrote: > >> In my original case, I think (!!!), the problem was that I had a variable >> in mod1.py and when I did the "from mod1 import myvarible" all was fine. >> Python create a new local-to-the-module variable and initialized it to the >> value it was set to in mod1. And at this point all is well. But, when mod1 >> changed the value of myvariable the change didn't get passed to the other >> modules. Of course, the reason for my confusion is that I'm thinking that >> python is using pointers :) Opps. >> >> Maybe we need pointers in python . >> > > Thinking about this as pointers works pretty well. We call them references > in Python because they are not (or need not be) memory addresses and C > pointers are memory addresses. However the model is the same: an arrow from > a variable name pointing at the place a value (the object) is stored. > > Look: > > mod1.py: x = 1 > > making: > > mod1.x --> 1 > > Now consider: > > mod2.py: from mod1 import x > > Making: > > mod1.x --> 1 > ^ > mod2.x ----+ > > both referring to the "1" object. > > Now: > mod2.py: x = 2 > > Making: > > mod1.x --> 1 > mod2.x --> 2 > > You see that mod1 is not adjusted. Versus: > > mod2.py: import mod1 > > Making: > > mod2.mod1 --> mod1, mod1.x --> 1 > > Then: > > mod2.py: mod1.x = 2 > > Making: > > mod2.mod1 --> mod1, mod1.x --> 2 > > Because you're adjusting the reference "mod1.x", _not_ the distinct > reference "mod2.x". > > Cheers, > Cameron Simpson (formerly cs at zip.com.au) > > Draw little boxes with arrows. It helps. - Michael J. Eager > Yes, your examples work perfectly. It's when one does an "from mod1 import var" that it doesn't. In mod1 set var to a value. Lets use 5. Now, in mod2 we do: from mod1 import var And, yes, var is equal to 5. But, to the folks like me who are not complete pythonistas, we'd think it worked and was wonderful. But, if we change the variable in mod1 whit a function in mod1, the value doesn't change in mod2. The problem is that from/import does not create var as a pointer, but as a new variable. -- **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW: http://www.mellowood.ca From bc at freeuk.com Fri Nov 17 13:48:46 2017 From: bc at freeuk.com (bartc) Date: Fri, 17 Nov 2017 18:48:46 +0000 Subject: Should constants be introduced to Python? In-Reply-To: References: <5D4DA7B2-504A-4A3A-BACE-FFADEA1D25DF@icloud.com> Message-ID: On 17/11/2017 15:14, Marcin Tustin wrote: > I'm against this because Python's strength is its simplicity. If it was simple once, then it isn't any more. Perhaps you mean consistency, in having only one class of identifier which can always be assigned to. > All the benefits of this can be achieved with linting. The significance of true constants can go beyond that, assuming the proposal is not merely for some 'write-protect' flag on an ordinary variable. Proper constants allow reduction of expressions using them at compile-time. They allow lightweight enums that do the same. They allow the possibility of an efficient 'switch' statement. And that's just for numeric constants. If applied also to constant defs, classes and imports, they introduce extra scope for compile-time optimising. -- bartc From rantingrickjohnson at gmail.com Fri Nov 17 13:53:54 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 17 Nov 2017 10:53:54 -0800 (PST) Subject: Artificial creating of [Lists], is it possible? the best way... In-Reply-To: <2e31fcb3-8087-466e-9e77-53b964d44870@googlegroups.com> References: <2e31fcb3-8087-466e-9e77-53b964d44870@googlegroups.com> Message-ID: <4a5b88e7-6711-45e1-9b96-9a7720a05e02@googlegroups.com> On Thursday, November 16, 2017 at 12:48:05 PM UTC-6, Jakub Raj ok wrote: > Artificial creating of [Lists], is it possible? the best way... There is nothing "artificial" about creating any object. Much less python lists. And i believe the usage of such word in the title of this thread was unfortunate, as it injects superfluous distraction into our comprehension of your true _intentions_. So, if the suggestions offered so far are _truely_ what you wanted to do -- and i have not reason to believe they are _not_ -- then the process here can more accurately be described, in English, as "creating a list containing N number of empty sublists". Words matter! Anecdotal speaking... an oft-stated observation of politics is that "Elections have consequences". And in the same spirit we should also understand that "words _themselves_ have consequences". Or rather: "your _word_choice_ is highly essential to our correct and efficient comprehension of your _intent_". So, in conclusion... If you cannot describe the result you want to achieve in _words_, then show us the result in actual _code_. For instance, the following question would have been self- explanatory: "How do i create a list that looks like this -> [[],[],[]] It is always better to restrict your use of natural language words to only those you _fully_ understand, than to attempt to stretch the definition of those words until they wrap around a concept, for which the "conceptual relationship" may only be obvious to _you_. PS: If you think about it, everything we _do_ in the "programming realm" is artificial. AKA: "Abstract". And while the end result of our incessant "juggling of abstractions" (which are _themselves_ built upon multiple layers of other abstractions) will inevitably be the concrete action of elections moving through a conductor, we, as programmers, are unconcerned with such "mechanical minutiae", and are only interested in the _results_ these worker-bee elections can bring to us. We are the shrewd military strategists and unapologetic mercenaries who fight endless, abstract battles against a manevolent, three- headed monster which plauges all of mankind -- namely: "needs", "wants", and "desires --, and who manevolently unleashes its legions of incoragble gremlins and hordes of mindless creepy crawlies to seek-out, and utlimately infest, every system that man -- in his boneheaded hubris -- has ever struggled to dominate. From greg.ewing at canterbury.ac.nz Fri Nov 17 16:27:07 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 18 Nov 2017 10:27:07 +1300 Subject: "help( pi )" In-Reply-To: References: Message-ID: It *could* be made to work: import math class PI(float): __doc__ = "The circle constant (Note: tau is better :-)" math.pi = PI(math.pi) print(math.pi) help(math.pi) -- Greg From rosuav at gmail.com Fri Nov 17 16:57:27 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Nov 2017 08:57:27 +1100 Subject: "help( pi )" In-Reply-To: References: Message-ID: On Sat, Nov 18, 2017 at 8:27 AM, Gregory Ewing wrote: > It *could* be made to work: > > import math > > class PI(float): > > __doc__ = "The circle constant (Note: tau is better :-)" > > math.pi = PI(math.pi) > > print(math.pi) > help(math.pi) How is THAT an improvement? Docstrings aren't supposed to give false information! *diving for cover* ChrisA From marcin.tustin at gmail.com Fri Nov 17 16:57:40 2017 From: marcin.tustin at gmail.com (Marcin Tustin) Date: Fri, 17 Nov 2017 16:57:40 -0500 Subject: Should constants be introduced to Python? In-Reply-To: References: <5D4DA7B2-504A-4A3A-BACE-FFADEA1D25DF@icloud.com> Message-ID: Yes the same consideration applies to any new feature. I think that Python's reticence to add new features has been a strength. And I do think the benefit here is absolutely negligible. It's not that I don't like constants - but there's a bunch of things that go great together, like constants, functional programming, and static type analysis, and none of those are in python. There are plenty of languages that have that; and nothing that prevents you from creating a desugaring compiler for an extended version of python. Indeed, I think that a lot of features like annotations would be better in an extension project. Constants (from a code quality perspective) really manifest their benefits in statically preventing errors. A linter can warn about assignment to ALL_CAPS, ClassNames, and built-in names. If you're following appropriate conventions (and your linter isn't a pure peephole linter) you can identify those errors. On Fri, Nov 17, 2017 at 4:47 PM, Saeed Baig wrote: > Well I think that depends on how one defines simplicity. Which seems > simpler, this: > > # Treat as constants > c = 299792458 # Speed of light > e = 2.71828 # Euler?s constant > > or this: > let c = 299792458 # Speed of light > let e = 2.71828 # Euler?s constant > > The latter involves less typing, and is hardly more difficult to > understand. > > I can see where you?re coming from; it does arguably add complexity. But > one could argue that ANY new feature to the language (list comprehension, > lambdas, type hints, etc) will add complexity to the language just by > virtue of being an extra thing to learn. One has to consider the benefit VS > cost of a new feature by comparing ?How useful is it? to ?How complex is > it?. > > And forgive me for my ignorance on this topic, but how can linting give > the benefits of constants? > > On 18 Nov 2017, at 02:14, Marcin Tustin wrote: > > I'm against this because Python's strength is its simplicity. This doesn't > actually simplify anything, but it does add a new language feature to > understand. > > All the benefits of this can be achieved with linting. > > On Thu, Nov 16, 2017 at 1:16 AM, Saeed Baig > wrote: > >> Hey guys I am thinking of perhaps writing a PEP to introduce constants to >> Python. Something along the lines of Swift?s ?let? syntax (e.g. ?let pi = >> 3.14?). >> >> Since I?m sort of new to this, I just wanted to ask: >> - Has a PEP for this already been written? If so, where can I find the >> link/info to it? >> - Do you guys think it would be a good idea? Why or why not? Do you think >> there?s a better way to do it? I?d like to know what others think about >> this idea before making any formal submission. >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Marcin Tustin > Tel: +1 917 553 3974 <(917)%20553-3974> > > > -- Marcin Tustin Tel: +1 917 553 3974 From python at bladeshadow.org Fri Nov 17 17:11:29 2017 From: python at bladeshadow.org (Python) Date: Fri, 17 Nov 2017 16:11:29 -0600 Subject: ctypes help Message-ID: <20171117221129.GC7520@bladeshadow.org> Hello Pythonistas, I'm starting to play with ctypes, as I'd like to provide Python interfaces to a C/C++ library I have. For now I'm just messing with a very simple piece of code to get things sorted out. I'm working with this example C++ library, which just wraps a call to stat(): -=-=-=-=-=-=- $ cat stat.cc #include #include #include extern "C" int my_stat(const char *path, struct stat *st) { return stat(path, st); } -=-=-=-=-=-=- Then I compile this to a shared object with g++ -shared -fPIC in /tmp. My attempt to wrap that looks as follows: -=-=-=-=-=-=- #!/usr/bin/python import ctypes libc = ctypes.CDLL("/tmp/my_stat.so") stat = libc.my_stat class Timespec(ctypes.Structure): _fields_ = [("tv_sec", ctypes.c_longlong), ("tv_usec", ctypes.c_longlong)] class Stat(ctypes.Structure): _fields_ = [("st_dev", ctypes.c_ulong), ("st_ino", ctypes.c_ulong), ("st_mode", ctypes.c_ulong), ("st_nlink", ctypes.c_ulong), ("st_uid", ctypes.c_ulong), ("st_gid", ctypes.c_ulong), ("st_rdev", ctypes.c_ulong), ("st_size", ctypes.c_ulonglong), ("st_blksize", ctypes.c_ulonglong), ("st_blocks", ctypes.c_ulonglong), ("st_atim", Timespec), ("st_mtim", Timespec), ("st_ctim", Timespec)] Stat_p = ctypes.POINTER(Stat) stat.argtypes = [ctypes.c_char_p, Stat_p] path = "/tmp" c_path = ctypes.c_char_p(path) st = Stat() rc = stat(c_path, ctypes.byref(st)) print rc print st.st_dev print st.st_ino print st.st_mode print st.st_nlink print st.st_uid print st.st_gid print st.st_size print st.st_atim print st.st_mtim -=-=-=-=-=-=- This crashes immediately on one system, actually does work as expected on another, but crashes before exiting. Clearly I must be doing something wrong, but what? On the system I have handy at the moment, it does not print any output, and backtrace looks like this: $ ./my_ctypes.py *** Error in `/usr/bin/python': corrupted size vs. prev_size: 0x00000000027b8320 *** ======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f6444a907e5] /lib/x86_64-linux-gnu/libc.so.6(+0x7e9dc)[0x7f6444a979dc] /lib/x86_64-linux-gnu/libc.so.6(+0x81cde)[0x7f6444a9acde] /lib/x86_64-linux-gnu/libc.so.6(__libc_malloc+0x54)[0x7f6444a9d184] /lib/x86_64-linux-gnu/libc.so.6(_IO_file_doallocate+0x55)[0x7f6444a861d5] /lib/x86_64-linux-gnu/libc.so.6(_IO_doallocbuf+0x34)[0x7f6444a94594] /lib/x86_64-linux-gnu/libc.so.6(_IO_file_overflow+0x1c8)[0x7f6444a938f8] /lib/x86_64-linux-gnu/libc.so.6(_IO_file_xsputn+0xad)[0x7f6444a9228d] /lib/x86_64-linux-gnu/libc.so.6(_IO_vfprintf+0xc90)[0x7f6444a66e00] /lib/x86_64-linux-gnu/libc.so.6(__fprintf_chk+0xf9)[0x7f6444b2fb89] /usr/bin/python[0x53290c] /usr/bin/python[0x511c1f] /usr/bin/python(PyFile_WriteObject+0x533)[0x5116d3] /usr/bin/python(PyEval_EvalFrameEx+0x3a8f)[0x4c7a8f] /usr/bin/python(PyEval_EvalCodeEx+0x255)[0x4c2765] /usr/bin/python(PyEval_EvalCode+0x19)[0x4c2509] /usr/bin/python[0x4f1def] /usr/bin/python(PyRun_FileExFlags+0x82)[0x4ec652] /usr/bin/python(PyRun_SimpleFileExFlags+0x191)[0x4eae31] /usr/bin/python(Py_Main+0x68a)[0x49e14a] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f6444a39830] /usr/bin/python(_start+0x29)[0x49d9d9] From cs at cskk.id.au Fri Nov 17 17:38:03 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 18 Nov 2017 09:38:03 +1100 Subject: "help( pi )" In-Reply-To: References: Message-ID: <20171117223803.GA26740@cskk.homeip.net> On 17Nov2017 11:09, Dennis Lee Bieber wrote: >On 17 Nov 2017 12:36:37 GMT, ram at zedat.fu-berlin.de (Stefan Ram) declaimed >>?The argument to pydoc can be the name of a function, >>module, or package, or a dotted reference to a class, >>method, or function within a module or module in a package.? >> >> , but not for ?pi?: > math.pi is NOT a "function, module, or package..." > Would you expect > help(1) >to produce something like "Multiplicative identity"? (or "Boolean truth" >especially for older Python code before True/False became standard). Why >should > help(3.1415926536) #or whatever precision is used in module math >produce anything? That IS what is seen by the help() operation, not the >name "pi", just a number. And if help() somehow recognizes 3.1415926536 as >pi, what does it do if provided with just 3.141592654 instead? This is not a consistent argument. mymath.py: def square(x): ''' Return the square of a value: its value muliplied by itself. ''' return x*x my code: from mymath import square def sq2(x): return x*x I expect help(square) to have doco and don't expect help(sq2) to have doco. Stefan's argument points to the deficiency that one cannot attach a docstring to things like numbers. I've certainly wanted to. I don't think he's arguing that help magicly recognises 3.1415926536 as "pi" and produces a docstring for it and all "sufficiently close" values. I'm not. But the math module has bound "pi" to a specific float. Why _can't_ we annotate that float with a docstring? math.py: pi = 3.1415926536 pi.__doc__ = 'The ratio of round things to straight things. Roughly 3.' Now, I accept that the "CPython coaleases some values to shared singletons" thing is an issue, but the language doesn't require it, and one could change implementations such that applying a docstring to an object _removed_ it from the magic-shared-singleton pool, avoiding conflicts with other uses of the same value by coincidence. Cheers, Cameron Simpson (formerly cs at zip.com.au) From rosuav at gmail.com Fri Nov 17 17:50:29 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Nov 2017 09:50:29 +1100 Subject: "help( pi )" In-Reply-To: <20171117223803.GA26740@cskk.homeip.net> References: <20171117223803.GA26740@cskk.homeip.net> Message-ID: On Sat, Nov 18, 2017 at 9:38 AM, Cameron Simpson wrote: > I don't think he's arguing that help magicly recognises 3.1415926536 as "pi" > and produces a docstring for it and all "sufficiently close" values. I'm > not. But the math module has bound "pi" to a specific float. Why _can't_ we > annotate that float with a docstring? > > math.py: > pi = 3.1415926536 > pi.__doc__ = 'The ratio of round things to straight things. Roughly 3.' > > Now, I accept that the "CPython coaleases some values to shared singletons" > thing is an issue, but the language doesn't require it, and one could change > implementations such that applying a docstring to an object _removed_ it > from the magic-shared-singleton pool, avoiding conflicts with other uses of > the same value by coincidence. > Perhaps what we want is not so much "attach docstrings to floats" but "get documentation for a module attribute, not for the object referred to". pi = 3.1415926536 # A yet-to-be-released version of TeX help("math.pi") ==> """ math.pi [3.1415926536] A yet-to-be-released version of TeX """ To make this work, the help() function would have to be given a string, or else be some sort of magic UI feature rather than a plain function. It'd then also need to get hold of either the source code or the compiled math.pyc (but not the importable module) and somehow locate the module attribute assignment operation. It wouldn't be efficient, but it would be something that's only done when a human specifically asks for it, so taking 50ms isn't going to mean much. Possible? Yes. Practical? Not so sure. ChrisA From python at bladeshadow.org Fri Nov 17 18:34:23 2017 From: python at bladeshadow.org (Python) Date: Fri, 17 Nov 2017 17:34:23 -0600 Subject: "help( pi )" In-Reply-To: References: <20171117223803.GA26740@cskk.homeip.net> Message-ID: <20171117233423.GD7520@bladeshadow.org> On Sat, Nov 18, 2017 at 09:50:29AM +1100, Chris Angelico wrote: > Perhaps what we want is not so much "attach docstrings to floats" but > "get documentation for a module attribute, not for the object referred > to". The reason this can't really work is that members are just variables with arbitrary values. It does not make sense for them to have doc strings. You *can* (and probably should!) document the members in the class' (or module's) doc string. That's really the only sensible place to do it. But remember that Python's idea of objects is more fluid than in other languages... You don't have constants, so you can arbitrarily change any object's member values to anything, even to the point of adding new ones at your whim. This probably would make more sense for constants, if Python had them. But you don't really need them, and there's no reason documenting the purpose of the members of a class or module in the parent object's doc string shouldn't be sufficient. From rosuav at gmail.com Fri Nov 17 18:47:55 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Nov 2017 10:47:55 +1100 Subject: "help( pi )" In-Reply-To: <20171117233423.GD7520@bladeshadow.org> References: <20171117223803.GA26740@cskk.homeip.net> <20171117233423.GD7520@bladeshadow.org> Message-ID: On Sat, Nov 18, 2017 at 10:34 AM, Python wrote: > On Sat, Nov 18, 2017 at 09:50:29AM +1100, Chris Angelico wrote: >> Perhaps what we want is not so much "attach docstrings to floats" but >> "get documentation for a module attribute, not for the object referred >> to". > > The reason this can't really work is that members are just variables > with arbitrary values. It does not make sense for them to have doc > strings. Did you read my post? ChrisA From rosuav at gmail.com Fri Nov 17 18:49:40 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Nov 2017 10:49:40 +1100 Subject: ctypes help In-Reply-To: <20171117221129.GC7520@bladeshadow.org> References: <20171117221129.GC7520@bladeshadow.org> Message-ID: On Sat, Nov 18, 2017 at 9:11 AM, Python wrote: > Hello Pythonistas, > > I'm starting to play with ctypes, as I'd like to provide Python > interfaces to a C/C++ library I have. For now I'm just messing with a > very simple piece of code to get things sorted out. I'm working with > this example C++ library, which just wraps a call to stat(): I would recommend you look into Cython, which can help you write C code that links to Python without all the hassle of manually tracking refcounts etc. (I also recommend using Python 3 instead of Python 2, but that's a separate point.) ChrisA From rosuav at gmail.com Fri Nov 17 21:45:13 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Nov 2017 13:45:13 +1100 Subject: "help( pi )" In-Reply-To: References: Message-ID: On Sat, Nov 18, 2017 at 10:35 AM, Stefan Ram wrote: > Dennis Lee Bieber writes: >>should >> help(3.1415926536) #or whatever precision is used in module math >>produce anything? > > That question made me try something else whose output > surprises me: > > |Python 3.7.0 ... > |>>> help( 'math.pi' ) > |Help on float in math object: > | > |math.pi = class float(object) > | | math.pi(x=0, /) > | | > | | Convert a string or number to a floating point number, if possible. > | |... Yes, that's correct; it's critical for anything that's a keyword (eg help("if")), but legal for others. And it can have the side-effect of importing and caching a module. ChrisA From python at bladeshadow.org Fri Nov 17 22:12:07 2017 From: python at bladeshadow.org (Python) Date: Fri, 17 Nov 2017 21:12:07 -0600 Subject: "help( pi )" In-Reply-To: References: <20171117223803.GA26740@cskk.homeip.net> <20171117233423.GD7520@bladeshadow.org> Message-ID: <20171118031207.GA3791@bladeshadow.org> On Sat, Nov 18, 2017 at 10:47:55AM +1100, Chris Angelico wrote: > On Sat, Nov 18, 2017 at 10:34 AM, Python wrote: > > On Sat, Nov 18, 2017 at 09:50:29AM +1100, Chris Angelico wrote: > >> Perhaps what we want is not so much "attach docstrings to floats" but > >> "get documentation for a module attribute, not for the object referred > >> to". > > > > The reason this can't really work is that members are just variables > > with arbitrary values. It does not make sense for them to have doc > > strings. > > Did you read my post? Yes! Did you read mine? I tried to explain to you that what you're suggesting doesn't really fit Python's paradigm: Doc strings describe their owner class, not individual instances--the class' doc string is where the description of your class (or module--same thing) attributes should go. Of course, in most cases you can set the doc strings to whatever you want, but in doing so you wipe out the owner class' documentation. If others are using your code, they may not expect or want this, so that's mostly a bad idea. You need a new attribute to set the instance description, and you can in fact just add that yourself if you want to. Monkeypatch to your heart's content! In this paradigm, the class for pi in your example is float, i.e. a floating point number, where the doc string for that class would logically be "A floating point number"--but since this is obvious, there is no compelling reason to even have it. In fact, it DOES have it: >>> x = 1.3 >>> x.__doc__ 'float(x) -> floating point number\n\nConvert a string or number to a floating point number, if possible.' Fundamental types have read-only doc strings, because it's the only thing that makes sense. But know what? In fact, if you really want to, you *can* get your attrs to have descriptive doc strings... by defining your own class that inherits from float (or whatever): -=-=-=-=-=-=- $ cat pi.py #!/usr/bin/python class Pi(float): def __init__(self): self.__doc__ = "the constant pi" def __new__(cls, value = 3.1415927): return float.__new__(cls, 3.1415927) x = Pi() print x print x + 2 print x.__doc__ $ ./pi.py 3.1415927 5.1415927 the constant pi -=-=-=-=-=-=- But asking the standard modules to do this is mostly silly, because it doesn't fit the paradigm... It changes the purpose of the doc string, and obliterates the information it is INTENDED to convey. But since this is Python, you can still do it if you want to. From rosuav at gmail.com Fri Nov 17 22:19:25 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Nov 2017 14:19:25 +1100 Subject: "help( pi )" In-Reply-To: <20171118031207.GA3791@bladeshadow.org> References: <20171117223803.GA26740@cskk.homeip.net> <20171117233423.GD7520@bladeshadow.org> <20171118031207.GA3791@bladeshadow.org> Message-ID: On Sat, Nov 18, 2017 at 2:12 PM, Python wrote: > On Sat, Nov 18, 2017 at 10:47:55AM +1100, Chris Angelico wrote: >> On Sat, Nov 18, 2017 at 10:34 AM, Python wrote: >> > On Sat, Nov 18, 2017 at 09:50:29AM +1100, Chris Angelico wrote: >> >> Perhaps what we want is not so much "attach docstrings to floats" but >> >> "get documentation for a module attribute, not for the object referred >> >> to". >> > >> > The reason this can't really work is that members are just variables >> > with arbitrary values. It does not make sense for them to have doc >> > strings. >> >> Did you read my post? > > Yes! Did you read mine? I tried to explain to you that what you're > suggesting doesn't really fit Python's paradigm: Doc strings describe > their owner class, not individual instances--the class' doc string is > where the description of your class (or module--same thing) attributes > should go. I gave a detailed example of something that was NOT a docstring. That was, in fact, the whole point of my post. ChrisA From python at bladeshadow.org Fri Nov 17 22:23:13 2017 From: python at bladeshadow.org (Python) Date: Fri, 17 Nov 2017 21:23:13 -0600 Subject: ctypes help In-Reply-To: References: <20171117221129.GC7520@bladeshadow.org> Message-ID: <20171118032313.GB3791@bladeshadow.org> On Sat, Nov 18, 2017 at 10:49:40AM +1100, Chris Angelico wrote: > On Sat, Nov 18, 2017 at 9:11 AM, Python wrote: > > Hello Pythonistas, > > > > I'm starting to play with ctypes, as I'd like to provide Python > > interfaces to a C/C++ library I have. For now I'm just messing with a > > very simple piece of code to get things sorted out. I'm working with > > this example C++ library, which just wraps a call to stat(): > > I would recommend you look into Cython, which can help you write C > code that links to Python without all the hassle of manually tracking > refcounts etc. (I also recommend using Python 3 instead of Python 2, > but that's a separate point.) Cython looks interesting, but none of your suggestions are options in my situation. From python at bladeshadow.org Fri Nov 17 22:38:56 2017 From: python at bladeshadow.org (Python) Date: Fri, 17 Nov 2017 21:38:56 -0600 Subject: "help( pi )" In-Reply-To: References: <20171117223803.GA26740@cskk.homeip.net> <20171117233423.GD7520@bladeshadow.org> <20171118031207.GA3791@bladeshadow.org> Message-ID: <20171118033856.GC3791@bladeshadow.org> On Sat, Nov 18, 2017 at 02:19:25PM +1100, Chris Angelico wrote: > On Sat, Nov 18, 2017 at 2:12 PM, Python wrote: > > On Sat, Nov 18, 2017 at 10:47:55AM +1100, Chris Angelico wrote: > >> On Sat, Nov 18, 2017 at 10:34 AM, Python wrote: > >> > On Sat, Nov 18, 2017 at 09:50:29AM +1100, Chris Angelico wrote: > >> >> Perhaps what we want is not so much "attach docstrings to floats" but > >> >> "get documentation for a module attribute, not for the object referred > >> >> to". > >> > > >> > The reason this can't really work is that members are just variables > >> > with arbitrary values. It does not make sense for them to have doc > >> > strings. > >> > >> Did you read my post? > > > > Yes! Did you read mine? I tried to explain to you that what you're > > suggesting doesn't really fit Python's paradigm: Doc strings describe > > their owner class, not individual instances--the class' doc string is > > where the description of your class (or module--same thing) attributes > > should go. > > I gave a detailed example of something that was NOT a docstring. That > was, in fact, the whole point of my post. Ah... Sorry, I didn't find that to be clear from your post, even after rereading it... I took it to mean that *conceptually* it was different from a doc string, but still actually using the doc string via some magic, the description of which I honestly found kind of vague and hand-wavey, not so much detailed. And TBH I still do, even now that I have a better idea what you're talking about. ?\_(?)_/? Apologies for my confusion. From rosuav at gmail.com Fri Nov 17 22:43:53 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Nov 2017 14:43:53 +1100 Subject: "help( pi )" In-Reply-To: <20171118033856.GC3791@bladeshadow.org> References: <20171117223803.GA26740@cskk.homeip.net> <20171117233423.GD7520@bladeshadow.org> <20171118031207.GA3791@bladeshadow.org> <20171118033856.GC3791@bladeshadow.org> Message-ID: On Sat, Nov 18, 2017 at 2:38 PM, Python wrote: > On Sat, Nov 18, 2017 at 02:19:25PM +1100, Chris Angelico wrote: >> On Sat, Nov 18, 2017 at 2:12 PM, Python wrote: >> > On Sat, Nov 18, 2017 at 10:47:55AM +1100, Chris Angelico wrote: >> >> On Sat, Nov 18, 2017 at 10:34 AM, Python wrote: >> >> > On Sat, Nov 18, 2017 at 09:50:29AM +1100, Chris Angelico wrote: >> >> >> Perhaps what we want is not so much "attach docstrings to floats" but >> >> >> "get documentation for a module attribute, not for the object referred >> >> >> to". >> >> > >> >> > The reason this can't really work is that members are just variables >> >> > with arbitrary values. It does not make sense for them to have doc >> >> > strings. >> >> >> >> Did you read my post? >> > >> > Yes! Did you read mine? I tried to explain to you that what you're >> > suggesting doesn't really fit Python's paradigm: Doc strings describe >> > their owner class, not individual instances--the class' doc string is >> > where the description of your class (or module--same thing) attributes >> > should go. >> >> I gave a detailed example of something that was NOT a docstring. That >> was, in fact, the whole point of my post. > > Ah... Sorry, I didn't find that to be clear from your post, even after > rereading it... I took it to mean that *conceptually* it was different > from a doc string, but still actually using the doc string via some > magic, the description of which I honestly found kind of vague and > hand-wavey, not so much detailed. And TBH I still do, even now that I > have a better idea what you're talking about. ?\_(?)_/? Apologies > for my confusion. Ah. Yeah, the point was that the comment *was actually* the documentation. That's why that idea is unlikely to be practical - it involves reading the source. But it IS possible, without any compiler help. Apology accepted :) ChrisA From gabsiwided12 at gmail.com Sat Nov 18 05:42:00 2017 From: gabsiwided12 at gmail.com (gabsiwided12 at gmail.com) Date: Sat, 18 Nov 2017 02:42:00 -0800 (PST) Subject: Python dos2unix one liner In-Reply-To: References: Message-ID: <6c5b2017-8450-4943-99c8-0bf21417e513@googlegroups.com> Hello, I need to perform a tp on semaphores and shared segments of memory, but I have a bit of trouble with the first notion. In short, we are asked to create 3 programs: The first director, who with the create capacity file argument, will create the museum with the different IPC system objects with the maximum capacity given in argument and the maximum number of visitors in the maximum queue given by the last argument. The open and close arguments will open or close the museum. The delete argument will delete the museum and IPC System 5 objects. Then, the controller program, called without argument, will ensure that the current capacity of the museum does not exceed the maximum capacity. Finally, the visitor program simulates the arrival of a visitor, with the time remaining in the arguments. It is called as many times as there are visitors. A visitor ends if the queue exceeds the limit set at creation, otherwise he asks for permission to enter the museum. We are asked here to use only the IPC system 5 objects that are the shared memory segments and semaphores. So we will have our semaphores as the only synchronization mechanism. So I create my 3 programs, with a shared memory segment for different information (maximum capacity and file) On the other hand, I can not really know how to use semaphores. Should I create a binary semaphore already for the case of open or close museum? Also, I do not really see how to implement everything in the case where we have to share information between 3 programs and suddenly how to implement semaphores of this kind ... thank you in advance From eryksun at gmail.com Sat Nov 18 05:56:27 2017 From: eryksun at gmail.com (eryk sun) Date: Sat, 18 Nov 2017 10:56:27 +0000 Subject: ctypes help In-Reply-To: <20171117221129.GC7520@bladeshadow.org> References: <20171117221129.GC7520@bladeshadow.org> Message-ID: On Fri, Nov 17, 2017 at 10:11 PM, Python wrote: > > I'm starting to play with ctypes, as I'd like to provide Python > interfaces to a C/C++ library I have. For now I'm just messing with a > very simple piece of code to get things sorted out. I'm working with > this example C++ library, which just wraps a call to stat(): Calling POSIX system functions via ctypes can be difficult if they use struct layouts that vary with the target platform and architecture. > class Stat(ctypes.Structure): > _fields_ = [("st_dev", ctypes.c_ulong), > ("st_ino", ctypes.c_ulong), > ("st_mode", ctypes.c_ulong), > ("st_nlink", ctypes.c_ulong), > ("st_uid", ctypes.c_ulong), > ("st_gid", ctypes.c_ulong), For x64 the above incorrectly uses 64-bit integers for mode, uid, and gid. Also, it has mode and nlink flipped around in the x86 order instead of the new x64 order. > ("st_rdev", ctypes.c_ulong), > ("st_size", ctypes.c_ulonglong), > ("st_blksize", ctypes.c_ulonglong), > ("st_blocks", ctypes.c_ulonglong), > ("st_atim", Timespec), > ("st_mtim", Timespec), > ("st_ctim", Timespec)] Try to strictly adhere to the defined types. Don't use `long long` for a `long`, even if it happens to be the same size in a given architecture. Also, avoid using definitions from docs and man pages. Use the exact headers that the compiler sees. In this case, you missed the 3 reserved long-integer fields at the end on x64 builds. Your Stat struct is 128 bytes overall instead of the required 144 bytes. glibc will corrupt the heap when it writes to the last 16 bytes. The best case is that this immediately crashes Python. Below I've included an example ctypes wrapper for calling stat() on Linux x64 and x86 systems. I verified the sizes and offsets and tested in 64-bit Python. From a C test program, I also have the field sizes and offsets for the two 32-bit cases (with and without large file support), but I'd need to build 32-bit Python to verify that the ctypes wrapper is correct. I have no personal use for 32-bit Python, so I leave that part up to you. C header definitions from time.h, bits/typesizes.h, bits/types.h, and bits/stat.h: #define __DEV_T_TYPE __UQUAD_TYPE #define __INO_T_TYPE __SYSCALL_ULONG_TYPE #define __INO64_T_TYPE __UQUAD_TYPE #ifdef __x86_64__ #define __NLINK_T_TYPE __SYSCALL_ULONG_TYPE #else #define __NLINK_T_TYPE __UWORD_TYPE #endif #define __MODE_T_TYPE __U32_TYPE #define __UID_T_TYPE __U32_TYPE #define __GID_T_TYPE __U32_TYPE #define __OFF_T_TYPE __SYSCALL_SLONG_TYPE #define __OFF64_T_TYPE __SQUAD_TYPE #define __BLKSIZE_T_TYPE __SYSCALL_SLONG_TYPE #define __BLKCNT_T_TYPE __SYSCALL_SLONG_TYPE #define __BLKCNT64_T_TYPE __SQUAD_TYPE #define __TIME_T_TYPE __SYSCALL_SLONG_TYPE struct timespec { __time_t tv_sec; __syscall_slong_t tv_nsec; }; struct stat { __dev_t st_dev; #ifndef __x86_64__ unsigned short int __pad1; #endif #if defined __x86_64__ || !defined __USE_FILE_OFFSET64 __ino_t st_ino; #else __ino_t __st_ino; #endif #ifndef __x86_64__ __mode_t st_mode; __nlink_t st_nlink; #else __nlink_t st_nlink; __mode_t st_mode; #endif __uid_t st_uid; __gid_t st_gid; #ifdef __x86_64__ int __pad0; #endif __dev_t st_rdev; #ifndef __x86_64__ unsigned short int __pad2; #endif #if defined __x86_64__ || !defined __USE_FILE_OFFSET64 __off_t st_size; #else __off64_t st_size; #endif __blksize_t st_blksize; #if defined __x86_64__ || !defined __USE_FILE_OFFSET64 __blkcnt_t st_blocks; #else __blkcnt64_t st_blocks; #endif #ifdef __USE_XOPEN2K8 struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; #else __time_t st_atime; __syscall_ulong_t st_atimensec; __time_t st_mtime; __syscall_ulong_t st_mtimensec; __time_t st_ctime; __syscall_ulong_t st_ctimensec; #endif #ifdef __x86_64__ __syscall_slong_t __glibc_reserved[3]; #else #ifndef __USE_FILE_OFFSET64 unsigned long int __glibc_reserved4; unsigned long int __glibc_reserved5; #else __ino64_t st_ino; #endif #endif }; ctypes: import os import sys import ctypes import ctypes.util libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True) def c_errcheck(result, func, args): if result == -1: err = ctypes.get_errno() raise OSError(err, os.strerror(err)) return args class timespec(ctypes.Structure): _fields_ = (('tv_sec', ctypes.c_long), ('tv_nsec', ctypes.c_long)) _FILE_OFFSET_BITS = 64 class stat_result(ctypes.Structure): if ctypes.sizeof(ctypes.c_void_p) == 8: _fields_ = (('st_dev', ctypes.c_uint64), ('st_ino', ctypes.c_ulong), ('st_nlink', ctypes.c_ulong), ('st_mode', ctypes.c_uint32), ('st_uid', ctypes.c_uint32), ('st_gid', ctypes.c_uint32), ('_pad0', ctypes.c_int), ('st_rdev', ctypes.c_uint64), ('st_size', ctypes.c_long), ('st_blksize', ctypes.c_long), ('st_blocks', ctypes.c_long), ('st_atim', timespec), ('st_mtim', timespec), ('st_ctim', timespec), ('_reserved', ctypes.c_long * 3)) elif _FILE_OFFSET_BITS == 64: _fields_ = (('st_dev', ctypes.c_uint64), ('_pad1', ctypes.c_int), ('_st_ino', ctypes.c_ulong), ('st_mode', ctypes.c_uint32), ('st_nlink', ctypes.c_uint), ('st_uid', ctypes.c_uint32), ('st_gid', ctypes.c_uint32), ('st_rdev', ctypes.c_uint64), ('_pad2', ctypes.c_ushort), ('st_size', ctypes.c_int64), ('st_blksize', ctypes.c_long), ('st_blocks', ctypes.c_int64), ('st_atim', timespec), ('st_mtim', timespec), ('st_ctim', timespec), ('st_ino', ctypes.c_uint64)) else: _fields_ = (('st_dev', ctypes.c_uint64), ('_pad1', ctypes.c_int), ('st_ino', ctypes.c_ulong), ('st_mode', ctypes.c_uint32), ('st_nlink', ctypes.c_uint), ('st_uid', ctypes.c_uint32), ('st_gid', ctypes.c_uint32), ('st_rdev', ctypes.c_uint64), ('_pad2', ctypes.c_ushort), ('st_size', ctypes.c_long), ('st_blksize', ctypes.c_long), ('st_blocks', ctypes.c_long), ('st_atim', timespec), ('st_mtim', timespec), ('st_ctim', timespec), ('_reserved4', ctypes.c_ulong), ('_reserved5', ctypes.c_ulong)) @property def st_atime(self): t = self.st_atim return t.tv_sec + t.tv_nsec * 1e-9 @property def st_mtime(self): t = self.st_mtim return t.tv_sec + t.tv_nsec * 1e-9 @property def st_ctime(self): t = self.st_ctim return t.tv_sec + t.tv_nsec * 1e-9 libc.__xstat.errcheck = c_errcheck libc.__xstat.argtypes = ( ctypes.c_int, # API version ctypes.c_char_p, # filename ctypes.POINTER(stat_result)) # buf if ctypes.sizeof(ctypes.c_void_p) == 8: _STAT_VER_KERNEL = 0 _STAT_VER_LINUX = 1 else: _STAT_VER_LINUX_OLD = 1 _STAT_VER_KERNEL = 1 _STAT_VER_SVR4 = 2 _STAT_VER_LINUX = 3 def mystat(filename): if not isinstance(filename, bytes): if hasattr(os, 'fsencode'): filename = os.fsencode(filename) else: filename = filename.encode(sys.getfilesystemencoding()) st = stat_result() libc.__xstat(_STAT_VER_LINUX, filename, ctypes.byref(st)) return st if __name__ == '__main__': st = os.stat('/') myst = mystat('/') assert (st.st_dev, st.st_ino) == (myst.st_dev, myst.st_ino) assert st.st_mode == myst.st_mode assert st.st_atime == myst.st_atime assert st.st_mtime == myst.st_mtime From rosuav at gmail.com Sat Nov 18 06:47:24 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Nov 2017 22:47:24 +1100 Subject: Python dos2unix one liner In-Reply-To: <6c5b2017-8450-4943-99c8-0bf21417e513@googlegroups.com> References: <6c5b2017-8450-4943-99c8-0bf21417e513@googlegroups.com> Message-ID: On Sat, Nov 18, 2017 at 9:42 PM, wrote: > Hello, > > I need to perform a tp on semaphores and shared segments of memory, but I have a bit of trouble with the first notion. A tp? Sorry, not something I'm familiar with. > We are asked here to use only the IPC system 5 objects that are the shared memory segments and semaphores. > > So we will have our semaphores as the only synchronization mechanism. > > So I create my 3 programs, with a shared memory segment for different information (maximum capacity and file) > > On the other hand, I can not really know how to use semaphores. Okay, sounds like you want to research IPC a bit before you go on. Are you looking for advice on where to start researching? If so, my first question to you is: What platform or platforms do you need this to run on? IPC is notoriously difficult to manage in a truly cross-platform way, particularly if you need performance. ChrisA From skip.montanaro at gmail.com Sat Nov 18 08:33:20 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 18 Nov 2017 05:33:20 -0800 (PST) Subject: Test - you can ignore In-Reply-To: <778e4cc6-4d65-4992-ab49-6b9e77a49684@googlegroups.com> References: <778e4cc6-4d65-4992-ab49-6b9e77a49684@googlegroups.com> Message-ID: <1c135c27-3356-4e66-8ae0-e1067c8f0db4@googlegroups.com> On Saturday, November 18, 2017 at 7:28:56 AM UTC-6, Skip Montanaro wrote: > This is a test posting from the Usenet side of things. Looking to see if/when it turns up in the gate_news logs on mail.python.org... This is another test, though with a bit more Python content... (python2) ~% python -c 'import this' The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! #!/usr/bin/env python from __future__ import print_function import csv import glob import os import sys import shutil rows = csv.DictReader(open("manifest.dump", "rb"), fieldnames="sha1 domain path flag".split(), delimiter='|') for row in rows: if (row["path"].lower().endswith(".jpg") or row["path"].lower().endswith(".jpeg")): src = glob.glob("caa*/*/{}".format(row["sha1"])) if not src: print("not found:", row["path"], file=sys.stderr) continue dst = os.path.join("iPhone", row["path"]) shutil.copy(src[0], dst) print(dst) From skip.montanaro at gmail.com Sat Nov 18 08:42:38 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 18 Nov 2017 05:42:38 -0800 (PST) Subject: Test - you can ignore In-Reply-To: <778e4cc6-4d65-4992-ab49-6b9e77a49684@googlegroups.com> References: <778e4cc6-4d65-4992-ab49-6b9e77a49684@googlegroups.com> Message-ID: <54095b5d-291f-4f69-878b-fa9290bd44b4@googlegroups.com> On Saturday, November 18, 2017 at 7:28:56 AM UTC-6, Skip Montanaro wrote: > This is a test posting from the Usenet side of things. Looking to see if/when it turns up in the gate_news logs on mail.python.org... > > Skip Yet another test. This time with SpamBayes x-mine_usenet_headers setting enabled... From formisc at gmail.com Sat Nov 18 14:54:49 2017 From: formisc at gmail.com (Andrew Z) Date: Sat, 18 Nov 2017 14:54:49 -0500 Subject: for/ if against dict - one liner In-Reply-To: References: Message-ID: Gentlemen, thank you very much for the replies and help. Vincent's solution worked perfectly for me. Alister - you are correct and for me, i was looking to achieve that - readability and slightly less keystrokes. On Tue, Nov 14, 2017 at 4:59 AM, alister via Python-list < python-list at python.org> wrote: > On Tue, 14 Nov 2017 00:44:18 -0500, Andrew Z wrote: > > > Hello, > > i wonder how do i get the "for" and "if" to work against a dictionary > > in > > one line? > > > > basically i want to "squeeze": > > dct= [ 1 : "one", 2:"two", 3:"three"] > > for k, val in dct: > > if k >= 2: > > # do magnificent things > > > > Thank you AZ > > why the need to single line it? > is your computer running out of new line & space characters? > it probably could be done with a dictionary comprehension but will that > make things easier or harder to read/understand? > > "Readability counts" > > > > > -- > (Presuming for the sake of argument that it's even *possible* to design > better code in Perl than in C. :-) > -- Larry Wall on core code vs. module code design > -- > https://mail.python.org/mailman/listinfo/python-list > From formisc at gmail.com Sat Nov 18 16:02:57 2017 From: formisc at gmail.com (Andrew Z) Date: Sat, 18 Nov 2017 16:02:57 -0500 Subject: Time travel - how to simplify? In-Reply-To: References: <85vaicwsrm.fsf@benfinney.id.au> Message-ID: Thank you for your input, gentlemen. I'm thinking about the following approach: import datetime from dateutil import relativedelta fut_suffix ={ 1 : 'F', 2 : 'G', 3 : 'H', 4 : 'J', 5 : 'K', 6 : 'M', 7 : 'N', 8 : 'Q', 9 : 'U', 10: 'V', 11: 'X', 12: 'Z' } endDate = datetime.date.today() startDate = endDate + relativedelta.relativedelta(months = -6,day = 1) LocalSmlSuffix = [ suffix for mnth, suffix in fut_suffix.items() if mnth == startDate.month] On Tue, Nov 14, 2017 at 5:01 PM, Rick Johnson wrote: > On Tuesday, November 14, 2017 at 1:44:17 PM UTC-6, Ben Finney wrote: > > Andrew Z writes: > > > > > Now i want to get certain number of months. Say, i need 3 months > duration > > > starting from any month in dict. > > > > > > so if i start @ 7th: > > > my_choice =7 > > > for mnth, value in fut_suffix: > > > if my_choice >= mnth > > > # life is great > > > but if : > > > my_choice = 12 then my "time travel" becomes pain in the neck.. > > > > The ?itertools? library in the Python standard library > > has what you > > need: > > > > import itertools > > > > month_values = sorted(list(fut_suffix.keys())) > > month_cycle = itertools.cycle(month_values) > > > > month_choice = 7 > > three_months_starting_at_choice = [] > > while len(three_months_starting_at_choice) < 3: > > this_month = next(month_cycle) > > if this_month >= month_choice: > > three_months_starting_at_choice.append(this_month) > > Ben's advice is spot on[1], and exactly what i would do, but > i believe it's important for you to discover how to > implement a simple cycling algorithm yourself, _before_ > reaching for the pre-packaged junkfood in the itertools > module. Can you do it? If not, then do as much as you can > and then ask for help. Hey, you're only hurting yourself if > you don't learn how. And it's surprisingly easy! > > [1] and it looks as though he included the kitchen sink, > washcloths, dish soap, and some fine china as well! ?_? > -- > https://mail.python.org/mailman/listinfo/python-list > From lawrencedo99 at gmail.com Sat Nov 18 17:48:26 2017 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 18 Nov 2017 14:48:26 -0800 (PST) Subject: Constants In Python (Posting On Python-List Prohibited) Message-ID: Every (unqualified) name in Python is a variable. Which means its value can be changed. If you want something that has a value that cannot be changed, you have to make it an attribute of an object. For example, enums work this way. You could define an enum for constants, but enums are nominally opaque to some degree. If you want non-opaque constant definitions, how about this: def constants(**kwargs) : "defines an object with attributes that are given read-only" \ " values according to the keyword arguments passed." class generator_class : "parent class for generating constant-container instance." pass #end generator_class def gen_constitem(name, val) : def constitem(self) : return \ val #end constitem #begin gen_constitem constitem.__name__ = name return \ property(constitem) #end gen_constitem #begin constants for name in kwargs : setattr(generator_class, name, gen_constitem(name, kwargs[name])) #end for return \ generator_class() #end constants Example use: MY_CONSTS = constants \ ( apple = "fruit", count = 3, compound = {"key" : "value"}, ) print(MY_CONSTS.apple) print(MY_CONSTS.count) print(MY_CONSTS.compound) MY_CONSTS.apple = 2.0 print(MY_CONSTS.apple) produces output: fruit 3 {'key': 'value'} --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in () 31 print(MY_CONSTS.count) 32 print(MY_CONSTS.compound) ---> 33 MY_CONSTS.apple = 2.0 34 print(MY_CONSTS.apple) AttributeError: can't set attribute From greg.ewing at canterbury.ac.nz Sat Nov 18 17:49:07 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 19 Nov 2017 11:49:07 +1300 Subject: "help( pi )" In-Reply-To: References: <20171117223803.GA26740@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > one could change implementations such that applying a docstring to an > object _removed_ it from the magic-shared-singleton pool, Is there any need to bother? If another float happened to end up with exactly the same value as pi and got merged with it, the docstring wouldn't be wrong. -- Greg From __peter__ at web.de Sat Nov 18 18:52:11 2017 From: __peter__ at web.de (Peter Otten) Date: Sun, 19 Nov 2017 00:52:11 +0100 Subject: Time travel - how to simplify? References: Message-ID: Andrew Z wrote: > well, yeah, it's unidirectional and final destination is always the same > and have little to do with the question. > > Say, i have a dict: > > fut_suffix ={ 1 : 'F', > 2 : 'G', > 3 : 'H', > 4 : 'J', > 5 : 'K', > 6 : 'M', > 7 : 'N', > 8 : 'Q', > 9 : 'U', > 10: 'V', > 11: 'X', > 12: 'Z' > } > > where key is a month. > Now i want to get certain number of months. Say, i need 3 months duration > starting from any month in dict. > > so if i start @ 7th: > my_choice =7 > for mnth, value in fut_suffix: > if my_choice >= mnth > # life is great > but if : > my_choice = 12 then my "time travel" becomes pain in the neck.. > > And as such - the question is - what is the smart way to deal with cases > like this? Make a lookup list that is big enough for your application and then use slicing: >>> def months(first, count, lookup=list("FGHJKMNQUVXZ" * 3)): ... start = first - 1 ... return lookup[start: start + count] ... >>> months(3, 3) ['H', 'J', 'K'] >>> months(12, 3) ['Z', 'F', 'G'] From adam at fromthemachine.org Sat Nov 18 19:25:48 2017 From: adam at fromthemachine.org (Adam M. Dobrin) Date: Sat, 18 Nov 2017 16:25:48 -0800 Subject: Time travel - how to simplify? In-Reply-To: References: <85vaicwsrm.fsf@benfinney.id.au> Message-ID: IMHO , letters and time travel do not mix well . ? On Sat, Nov 18, 2017 at 1:02 PM, Andrew Z wrote: > Thank you for your input, gentlemen. > > I'm thinking about the following approach: > > import datetime > from dateutil import relativedelta > > fut_suffix ={ 1 : 'F', > 2 : 'G', > 3 : 'H', > 4 : 'J', > 5 : 'K', > 6 : 'M', > 7 : 'N', > 8 : 'Q', > 9 : 'U', > 10: 'V', > 11: 'X', > 12: 'Z' > } > > endDate = datetime.date.today() > startDate = endDate + relativedelta.relativedelta(months = -6,day = 1) > > LocalSmlSuffix = [ suffix for mnth, suffix in fut_suffix.items() if > mnth == startDate.month] > > > On Tue, Nov 14, 2017 at 5:01 PM, Rick Johnson < > rantingrickjohnson at gmail.com> > wrote: > > > On Tuesday, November 14, 2017 at 1:44:17 PM UTC-6, Ben Finney wrote: > > > Andrew Z writes: > > > > > > > Now i want to get certain number of months. Say, i need 3 months > > duration > > > > starting from any month in dict. > > > > > > > > so if i start @ 7th: > > > > my_choice =7 > > > > for mnth, value in fut_suffix: > > > > if my_choice >= mnth > > > > # life is great > > > > but if : > > > > my_choice = 12 then my "time travel" becomes pain in the neck.. > > > > > > The ?itertools? library in the Python standard library > > > has what you > > > need: > > > > > > import itertools > > > > > > month_values = sorted(list(fut_suffix.keys())) > > > month_cycle = itertools.cycle(month_values) > > > > > > month_choice = 7 > > > three_months_starting_at_choice = [] > > > while len(three_months_starting_at_choice) < 3: > > > this_month = next(month_cycle) > > > if this_month >= month_choice: > > > three_months_starting_at_choice.append(this_month) > > > > Ben's advice is spot on[1], and exactly what i would do, but > > i believe it's important for you to discover how to > > implement a simple cycling algorithm yourself, _before_ > > reaching for the pre-packaged junkfood in the itertools > > module. Can you do it? If not, then do as much as you can > > and then ask for help. Hey, you're only hurting yourself if > > you don't learn how. And it's surprisingly easy! > > > > [1] and it looks as though he included the kitchen sink, > > washcloths, dish soap, and some fine china as well! ?_? > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > From python at bladeshadow.org Sat Nov 18 20:17:33 2017 From: python at bladeshadow.org (Python) Date: Sat, 18 Nov 2017 19:17:33 -0600 Subject: ctypes help In-Reply-To: References: <20171117221129.GC7520@bladeshadow.org> Message-ID: <20171119011733.GD3791@bladeshadow.org> Eryk, Thanks much for the excellent and highly detailed response! That made a lot of things clear. On Sat, Nov 18, 2017 at 10:56:27AM +0000, eryk sun wrote: > On Fri, Nov 17, 2017 at 10:11 PM, Python wrote: > > > > I'm starting to play with ctypes, as I'd like to provide Python > > interfaces to a C/C++ library I have. For now I'm just messing with a > > very simple piece of code to get things sorted out. I'm working with > > this example C++ library, which just wraps a call to stat(): > > Calling POSIX system functions via ctypes can be difficult if they use > struct layouts that vary with the target platform and architecture. > > > class Stat(ctypes.Structure): > > _fields_ = [("st_dev", ctypes.c_ulong), > > ("st_ino", ctypes.c_ulong), > > ("st_mode", ctypes.c_ulong), > > ("st_nlink", ctypes.c_ulong), > > ("st_uid", ctypes.c_ulong), > > ("st_gid", ctypes.c_ulong), > > For x64 the above incorrectly uses 64-bit integers for mode, uid, and > gid. Also, it has mode and nlink flipped around in the x86 order > instead of the new x64 order. > > > ("st_rdev", ctypes.c_ulong), > > ("st_size", ctypes.c_ulonglong), > > ("st_blksize", ctypes.c_ulonglong), > > ("st_blocks", ctypes.c_ulonglong), > > ("st_atim", Timespec), > > ("st_mtim", Timespec), > > ("st_ctim", Timespec)] > > Try to strictly adhere to the defined types. Don't use `long long` for > a `long`, even if it happens to be the same size in a given > architecture. Also, avoid using definitions from docs and man pages. > Use the exact headers that the compiler sees. In this case, you missed > the 3 reserved long-integer fields at the end on x64 builds. Your Stat > struct is 128 bytes overall instead of the required 144 bytes. glibc > will corrupt the heap when it writes to the last 16 bytes. The best > case is that this immediately crashes Python. > > Below I've included an example ctypes wrapper for calling stat() on > Linux x64 and x86 systems. I verified the sizes and offsets and tested > in 64-bit Python. From a C test program, I also have the field sizes > and offsets for the two 32-bit cases (with and without large file > support), but I'd need to build 32-bit Python to verify that the > ctypes wrapper is correct. I have no personal use for 32-bit Python, > so I leave that part up to you. > > C header definitions from time.h, bits/typesizes.h, bits/types.h, and > bits/stat.h: > > #define __DEV_T_TYPE __UQUAD_TYPE > #define __INO_T_TYPE __SYSCALL_ULONG_TYPE > #define __INO64_T_TYPE __UQUAD_TYPE > #ifdef __x86_64__ > #define __NLINK_T_TYPE __SYSCALL_ULONG_TYPE > #else > #define __NLINK_T_TYPE __UWORD_TYPE > #endif > #define __MODE_T_TYPE __U32_TYPE > #define __UID_T_TYPE __U32_TYPE > #define __GID_T_TYPE __U32_TYPE > #define __OFF_T_TYPE __SYSCALL_SLONG_TYPE > #define __OFF64_T_TYPE __SQUAD_TYPE > #define __BLKSIZE_T_TYPE __SYSCALL_SLONG_TYPE > #define __BLKCNT_T_TYPE __SYSCALL_SLONG_TYPE > #define __BLKCNT64_T_TYPE __SQUAD_TYPE > #define __TIME_T_TYPE __SYSCALL_SLONG_TYPE > > struct timespec > { > __time_t tv_sec; > __syscall_slong_t tv_nsec; > }; > > struct stat > { > __dev_t st_dev; > #ifndef __x86_64__ > unsigned short int __pad1; > #endif > #if defined __x86_64__ || !defined __USE_FILE_OFFSET64 > __ino_t st_ino; > #else > __ino_t __st_ino; > #endif > #ifndef __x86_64__ > __mode_t st_mode; > __nlink_t st_nlink; > #else > __nlink_t st_nlink; > __mode_t st_mode; > #endif > __uid_t st_uid; > __gid_t st_gid; > #ifdef __x86_64__ > int __pad0; > #endif > __dev_t st_rdev; > #ifndef __x86_64__ > unsigned short int __pad2; > #endif > #if defined __x86_64__ || !defined __USE_FILE_OFFSET64 > __off_t st_size; > #else > __off64_t st_size; > #endif > __blksize_t st_blksize; > #if defined __x86_64__ || !defined __USE_FILE_OFFSET64 > __blkcnt_t st_blocks; > #else > __blkcnt64_t st_blocks; > #endif > #ifdef __USE_XOPEN2K8 > struct timespec st_atim; > struct timespec st_mtim; > struct timespec st_ctim; > #else > __time_t st_atime; > __syscall_ulong_t st_atimensec; > __time_t st_mtime; > __syscall_ulong_t st_mtimensec; > __time_t st_ctime; > __syscall_ulong_t st_ctimensec; > #endif > #ifdef __x86_64__ > __syscall_slong_t __glibc_reserved[3]; > #else > #ifndef __USE_FILE_OFFSET64 > unsigned long int __glibc_reserved4; > unsigned long int __glibc_reserved5; > #else > __ino64_t st_ino; > #endif > #endif > }; > > > ctypes: > > import os > import sys > import ctypes > import ctypes.util > > libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True) > > def c_errcheck(result, func, args): > if result == -1: > err = ctypes.get_errno() > raise OSError(err, os.strerror(err)) > return args > > class timespec(ctypes.Structure): > _fields_ = (('tv_sec', ctypes.c_long), > ('tv_nsec', ctypes.c_long)) > > _FILE_OFFSET_BITS = 64 > > class stat_result(ctypes.Structure): > if ctypes.sizeof(ctypes.c_void_p) == 8: > _fields_ = (('st_dev', ctypes.c_uint64), > ('st_ino', ctypes.c_ulong), > ('st_nlink', ctypes.c_ulong), > ('st_mode', ctypes.c_uint32), > ('st_uid', ctypes.c_uint32), > ('st_gid', ctypes.c_uint32), > ('_pad0', ctypes.c_int), > ('st_rdev', ctypes.c_uint64), > ('st_size', ctypes.c_long), > ('st_blksize', ctypes.c_long), > ('st_blocks', ctypes.c_long), > ('st_atim', timespec), > ('st_mtim', timespec), > ('st_ctim', timespec), > ('_reserved', ctypes.c_long * 3)) > elif _FILE_OFFSET_BITS == 64: > _fields_ = (('st_dev', ctypes.c_uint64), > ('_pad1', ctypes.c_int), > ('_st_ino', ctypes.c_ulong), > ('st_mode', ctypes.c_uint32), > ('st_nlink', ctypes.c_uint), > ('st_uid', ctypes.c_uint32), > ('st_gid', ctypes.c_uint32), > ('st_rdev', ctypes.c_uint64), > ('_pad2', ctypes.c_ushort), > ('st_size', ctypes.c_int64), > ('st_blksize', ctypes.c_long), > ('st_blocks', ctypes.c_int64), > ('st_atim', timespec), > ('st_mtim', timespec), > ('st_ctim', timespec), > ('st_ino', ctypes.c_uint64)) > else: > _fields_ = (('st_dev', ctypes.c_uint64), > ('_pad1', ctypes.c_int), > ('st_ino', ctypes.c_ulong), > ('st_mode', ctypes.c_uint32), > ('st_nlink', ctypes.c_uint), > ('st_uid', ctypes.c_uint32), > ('st_gid', ctypes.c_uint32), > ('st_rdev', ctypes.c_uint64), > ('_pad2', ctypes.c_ushort), > ('st_size', ctypes.c_long), > ('st_blksize', ctypes.c_long), > ('st_blocks', ctypes.c_long), > ('st_atim', timespec), > ('st_mtim', timespec), > ('st_ctim', timespec), > ('_reserved4', ctypes.c_ulong), > ('_reserved5', ctypes.c_ulong)) > @property > def st_atime(self): > t = self.st_atim > return t.tv_sec + t.tv_nsec * 1e-9 > @property > def st_mtime(self): > t = self.st_mtim > return t.tv_sec + t.tv_nsec * 1e-9 > @property > def st_ctime(self): > t = self.st_ctim > return t.tv_sec + t.tv_nsec * 1e-9 > > libc.__xstat.errcheck = c_errcheck > libc.__xstat.argtypes = ( > ctypes.c_int, # API version > ctypes.c_char_p, # filename > ctypes.POINTER(stat_result)) # buf > > if ctypes.sizeof(ctypes.c_void_p) == 8: > _STAT_VER_KERNEL = 0 > _STAT_VER_LINUX = 1 > else: > _STAT_VER_LINUX_OLD = 1 > _STAT_VER_KERNEL = 1 > _STAT_VER_SVR4 = 2 > _STAT_VER_LINUX = 3 > > def mystat(filename): > if not isinstance(filename, bytes): > if hasattr(os, 'fsencode'): > filename = os.fsencode(filename) > else: > filename = filename.encode(sys.getfilesystemencoding()) > st = stat_result() > libc.__xstat(_STAT_VER_LINUX, filename, ctypes.byref(st)) > return st > > if __name__ == '__main__': > st = os.stat('/') > myst = mystat('/') > assert (st.st_dev, st.st_ino) == (myst.st_dev, myst.st_ino) > assert st.st_mode == myst.st_mode > assert st.st_atime == myst.st_atime > assert st.st_mtime == myst.st_mtime From cs at cskk.id.au Sat Nov 18 23:52:38 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 19 Nov 2017 15:52:38 +1100 Subject: "help( pi )" In-Reply-To: References: Message-ID: <20171119045238.GA8897@cskk.homeip.net> On 19Nov2017 11:49, Greg Ewing wrote: >Cameron Simpson wrote: >>one could change implementations such that applying a docstring to >>an object _removed_ it from the magic-shared-singleton pool, > >Is there any need to bother? If another float happened to end >up with exactly the same value as pi and got merged with it, >the docstring wouldn't be wrong. Unless one had a misfortune and wanted another docstring. For pi this might not be so likely, but consider: mod1.py: MAX_BUFSIZE = 8192 MAX_BUFSIZE.__doc__ = 'Size of the hardware buffer used for I/O on this device.' mod2.py DEFAULT_CACHESIZE = 8192 DEFAULT_CACHESIZE.__doc__ = 'Convenient size for the foo cache, not to big or too small.' Cheers, Cameron Simpson (formerly cs at zip.com.au) From shalu.ashu50 at gmail.com Sun Nov 19 10:31:28 2017 From: shalu.ashu50 at gmail.com (shalu.ashu50 at gmail.com) Date: Sun, 19 Nov 2017 07:31:28 -0800 (PST) Subject: Problem in defining multidimensional array matrix and regression Message-ID: Hi, All, I have 6 variables in CSV file. One is rainfall (dependent, at y-axis) and others are predictors (at x). I want to do multiple regression and create a correlation matrix between rainfall (y) and predictors (x; n1=5). Thus I want to read rainfall as a separate variable and others in separate columns, so I can apply the algo. However, I am not able to make a proper matrix for them. Here are my data and codes? Please suggest me for the same. I am new to Python. RF P1 P2 P3 P4 P5 120.235 0.234 -0.012 0.145 21.023 0.233 200.14 0.512 -0.021 0.214 22.21 0.332 185.362 0.147 -0.32 0.136 24.65 0.423 201.895 0.002 -0.12 0.217 30.25 0.325 165.235 0.256 0.001 0.22 31.245 0.552 198.236 0.012 -0.362 0.215 32.25 0.333 350.263 0.98 -0.85 0.321 38.412 0.411 145.25 0.046 -0.36 0.147 39.256 0.872 198.654 0.65 -0.45 0.224 40.235 0.652 245.214 0.47 -0.325 0.311 26.356 0.632 214.02 0.18 -0.012 0.242 22.01 0.745 147.256 0.652 -0.785 0.311 18.256 0.924 import numpy as np import statsmodels as sm import statsmodels.formula as smf import csv with open("pcp1.csv", "r") as csvfile: readCSV=csv.reader(csvfile) rainfall = [] csvFileList = [] for row in readCSV: Rain = row[0] rainfall.append(Rain) if len (row) !=0: csvFileList = csvFileList + [row] print(csvFileList) print(rainfall) Please suggest me guys Thanks From __peter__ at web.de Sun Nov 19 12:01:19 2017 From: __peter__ at web.de (Peter Otten) Date: Sun, 19 Nov 2017 18:01:19 +0100 Subject: Problem in defining multidimensional array matrix and regression References: Message-ID: shalu.ashu50 at gmail.com wrote: > Hi, All, > > I have 6 variables in CSV file. One is rainfall (dependent, at y-axis) and > others are predictors (at x). I want to do multiple regression and create > a correlation matrix between rainfall (y) and predictors (x; n1=5). Thus I > want to read rainfall as a separate variable and others in separate > columns, so I can apply the algo. However, I am not able to make a proper > matrix for them. > > Here are my data and codes? > Please suggest me for the same. > I am new to Python. > > RF P1 P2 P3 P4 P5 > 120.235 0.234 -0.012 0.145 21.023 0.233 > 200.14 0.512 -0.021 0.214 22.21 0.332 > 185.362 0.147 -0.32 0.136 24.65 0.423 > 201.895 0.002 -0.12 0.217 30.25 0.325 > 165.235 0.256 0.001 0.22 31.245 0.552 > 198.236 0.012 -0.362 0.215 32.25 0.333 > 350.263 0.98 -0.85 0.321 38.412 0.411 > 145.25 0.046 -0.36 0.147 39.256 0.872 > 198.654 0.65 -0.45 0.224 40.235 0.652 > 245.214 0.47 -0.325 0.311 26.356 0.632 > 214.02 0.18 -0.012 0.242 22.01 0.745 > 147.256 0.652 -0.785 0.311 18.256 0.924 > > import numpy as np > import statsmodels as sm > import statsmodels.formula as smf > import csv > > with open("pcp1.csv", "r") as csvfile: > readCSV=csv.reader(csvfile) > > rainfall = [] > csvFileList = [] > > for row in readCSV: > Rain = row[0] > rainfall.append(Rain) > > if len (row) !=0: > csvFileList = csvFileList + [row] > > print(csvFileList) > print(rainfall) You are not the first to read tabular data from a file; therefore numpy (and pandas) offer highlevel function to do just that. Once you have the complete table extracting a specific column is easy. For instance: $ cat rainfall.txt RF P1 P2 P3 P4 P5 120.235 0.234 -0.012 0.145 21.023 0.233 200.14 0.512 -0.021 0.214 22.21 0.332 185.362 0.147 -0.32 0.136 24.65 0.423 201.895 0.002 -0.12 0.217 30.25 0.325 165.235 0.256 0.001 0.22 31.245 0.552 198.236 0.012 -0.362 0.215 32.25 0.333 350.263 0.98 -0.85 0.321 38.412 0.411 145.25 0.046 -0.36 0.147 39.256 0.872 198.654 0.65 -0.45 0.224 40.235 0.652 245.214 0.47 -0.325 0.311 26.356 0.632 214.02 0.18 -0.012 0.242 22.01 0.745 147.256 0.652 -0.785 0.311 18.256 0.924 $ python3 Python 3.4.3 (default, Nov 17 2016, 01:08:31) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import numpy >>> rf = numpy.genfromtxt("rainfall.txt", names=True) >>> rf["RF"] array([ 120.235, 200.14 , 185.362, 201.895, 165.235, 198.236, 350.263, 145.25 , 198.654, 245.214, 214.02 , 147.256]) >>> rf["P3"] array([ 0.145, 0.214, 0.136, 0.217, 0.22 , 0.215, 0.321, 0.147, 0.224, 0.311, 0.242, 0.311]) From shalu.ashu50 at gmail.com Sun Nov 19 12:55:15 2017 From: shalu.ashu50 at gmail.com (shalu.ashu50 at gmail.com) Date: Sun, 19 Nov 2017 09:55:15 -0800 (PST) Subject: Problem in defining multidimensional array matrix and regression In-Reply-To: References: Message-ID: <619b7086-77a1-4173-b937-b91b6b085a04@googlegroups.com> Hello Peter, Many thanks for your suggestion. Now I am using Pandas & I already did that but now I need to make a multi-dimensional array for reading all variables (5 in this case) at one x-axis, so I can perform multiple regression analysis. I am not getting how to bring all variables at one axis (e.g. at x-axis)? Thanks Vishal On Sunday, 19 November 2017 22:32:06 UTC+5:30, Peter Otten wrote: > shalu.ashu50 at gmail.com wrote: > > > Hi, All, > > > > I have 6 variables in CSV file. One is rainfall (dependent, at y-axis) and > > others are predictors (at x). I want to do multiple regression and create > > a correlation matrix between rainfall (y) and predictors (x; n1=5). Thus I > > want to read rainfall as a separate variable and others in separate > > columns, so I can apply the algo. However, I am not able to make a proper > > matrix for them. > > > > Here are my data and codes? > > Please suggest me for the same. > > I am new to Python. > > > > RF P1 P2 P3 P4 P5 > > 120.235 0.234 -0.012 0.145 21.023 0.233 > > 200.14 0.512 -0.021 0.214 22.21 0.332 > > 185.362 0.147 -0.32 0.136 24.65 0.423 > > 201.895 0.002 -0.12 0.217 30.25 0.325 > > 165.235 0.256 0.001 0.22 31.245 0.552 > > 198.236 0.012 -0.362 0.215 32.25 0.333 > > 350.263 0.98 -0.85 0.321 38.412 0.411 > > 145.25 0.046 -0.36 0.147 39.256 0.872 > > 198.654 0.65 -0.45 0.224 40.235 0.652 > > 245.214 0.47 -0.325 0.311 26.356 0.632 > > 214.02 0.18 -0.012 0.242 22.01 0.745 > > 147.256 0.652 -0.785 0.311 18.256 0.924 > > > > import numpy as np > > import statsmodels as sm > > import statsmodels.formula as smf > > import csv > > > > with open("pcp1.csv", "r") as csvfile: > > readCSV=csv.reader(csvfile) > > > > rainfall = [] > > csvFileList = [] > > > > for row in readCSV: > > Rain = row[0] > > rainfall.append(Rain) > > > > if len (row) !=0: > > csvFileList = csvFileList + [row] > > > > print(csvFileList) > > print(rainfall) > > You are not the first to read tabular data from a file; therefore numpy (and > pandas) offer highlevel function to do just that. Once you have the complete > table extracting a specific column is easy. For instance: > > $ cat rainfall.txt > RF P1 P2 P3 P4 P5 > 120.235 0.234 -0.012 0.145 21.023 0.233 > 200.14 0.512 -0.021 0.214 22.21 0.332 > 185.362 0.147 -0.32 0.136 24.65 0.423 > 201.895 0.002 -0.12 0.217 30.25 0.325 > 165.235 0.256 0.001 0.22 31.245 0.552 > 198.236 0.012 -0.362 0.215 32.25 0.333 > 350.263 0.98 -0.85 0.321 38.412 0.411 > 145.25 0.046 -0.36 0.147 39.256 0.872 > 198.654 0.65 -0.45 0.224 40.235 0.652 > 245.214 0.47 -0.325 0.311 26.356 0.632 > 214.02 0.18 -0.012 0.242 22.01 0.745 > 147.256 0.652 -0.785 0.311 18.256 0.924 > $ python3 > Python 3.4.3 (default, Nov 17 2016, 01:08:31) > [GCC 4.8.4] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import numpy > >>> rf = numpy.genfromtxt("rainfall.txt", names=True) > >>> rf["RF"] > array([ 120.235, 200.14 , 185.362, 201.895, 165.235, 198.236, > 350.263, 145.25 , 198.654, 245.214, 214.02 , 147.256]) > >>> rf["P3"] > array([ 0.145, 0.214, 0.136, 0.217, 0.22 , 0.215, 0.321, 0.147, > 0.224, 0.311, 0.242, 0.311]) From blueyes7175 at gmail.com Sun Nov 19 13:10:22 2017 From: blueyes7175 at gmail.com (Cheri Castro) Date: Sun, 19 Nov 2017 10:10:22 -0800 (PST) Subject: Student can't get if elif final statement to print for discussion post for python Message-ID: I've tried several variations but haven't been able to figure out why my final if elif statement won't print. I tried using return, I tried using 1's and 0's rather than yes and no. Not sure what the issue is. Please, help. #This function will print how many yes answers the user has and a message def correctAnswers(job, house, yard, time): if correctAnswers == 'yes': print ("Congratulations! You should get a puppy!") else: return "I'm sorry, you shouldn't get a puppy." From Richard at Damon-Family.org Sun Nov 19 13:37:59 2017 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 19 Nov 2017 13:37:59 -0500 Subject: Student can't get if elif final statement to print for discussion post for python In-Reply-To: References: Message-ID: <9703860f-ca4a-b9b9-d49b-bc02b86946b0@Damon-Family.org> On 11/19/17 1:10 PM, Cheri Castro wrote: > I've tried several variations but haven't been able to figure out why my final if elif statement won't print. I tried using return, I tried using 1's and 0's rather than yes and no. Not sure what the issue is. Please, help. > > > #This function will print how many yes answers the user has and a message > def correctAnswers(job, house, yard, time): > if correctAnswers == 'yes': > print ("Congratulations! You should get a puppy!") > else: > return "I'm sorry, you shouldn't get a puppy." Why does one path print and the other return, those are different actions. -- Richard Damon From ben+python at benfinney.id.au Sun Nov 19 13:58:59 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 20 Nov 2017 05:58:59 +1100 Subject: Problem in defining multidimensional array matrix and regression References: <619b7086-77a1-4173-b937-b91b6b085a04@googlegroups.com> Message-ID: <85bmjyw0wc.fsf@benfinney.id.au> shalu.ashu50 at gmail.com writes: > I already did that Peter's suggestion was quite different from the code you first presented. So, I am not understanding what you mean by ?I already did that?. Can you: * Reply with your responses interleaved with the quote text , so that your message reads like a proper discussion. (This message is an example of that.) * Show the code you wrote where you ?already did that?, and say what happened different from what you expected. > but now I need to make a multi-dimensional array for reading all > variables (5 in this case) at one x-axis >From what I can tell, that's exactly what Peter's example shows: you get a multi-dimensional array, with all the named variables ?RF?, ?P1?, ?P2?, and so on, addressible by name. That should allow you to directly operate on that multi-dimensional array by naming the variables. > I am not getting how to bring all variables at one axis (e.g. at > x-axis)? I don't understand what you mean by that; all the variables are present in the array. -- \ ?I don't like country music, but I don't mean to denigrate | `\ those who do. And for the people who like country music, | _o__) denigrate means ?put down?.? ?Bob Newhart | Ben Finney From ben+python at benfinney.id.au Sun Nov 19 14:03:17 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 20 Nov 2017 06:03:17 +1100 Subject: Student can't get if elif final statement to print for discussion post for python References: Message-ID: <857eumw0p6.fsf@benfinney.id.au> Cheri Castro writes: > I've tried several variations but haven't been able to figure out why > my final if elif statement won't print. The code you presented here does not have any ?elif? clause. Did you mean to show different code? > I tried using return, I tried using 1's and 0's rather than yes and > no. Not sure what the issue is. Please, help. Your questions are welcome here, but you may also be interested in the ?tutor? discussion forum especially for Python beginners. > #This function will print how many yes answers the user has and a message > def correctAnswers(job, house, yard, time): > if correctAnswers == 'yes': > print ("Congratulations! You should get a puppy!") > else: > return "I'm sorry, you shouldn't get a puppy." The ?if? clause tests the value of ?correctAnswers?. Where do you expect that value to come from? Nothing in the function ever sets a value to that name. On the other hand, the function never makes use of ?job?, ?house?, ?yard?, or ?time?. Why are those parameters to the function? -- \ ?How wonderful that we have met with a paradox. Now we have | `\ some hope of making progress.? ?Niels Bohr | _o__) | Ben Finney From pengyu.ut at gmail.com Sun Nov 19 14:04:43 2017 From: pengyu.ut at gmail.com (Peng Yu) Date: Sun, 19 Nov 2017 13:04:43 -0600 Subject: Is there something like head() and str() of R in python? Message-ID: Hi, R has the functions head() and str() to show the brief content of an object. Is there something similar in python for this purpose? For example, I want to inspect the content of the variable "train". What is the best way to do so? Thanks. $ cat demo.py from __future__ import division, print_function, absolute_import import tflearn from tflearn.data_utils import to_categorical, pad_sequences from tflearn.datasets import imdb # IMDB Dataset loading train, test, _ = imdb.load_data(path='imdb.pkl', n_words=10000, valid_portion=0.1) # https://raw.githubusercontent.com/llSourcell/How_to_do_Sentiment_Analysis/master/demo.py -- Regards, Peng From python at mrabarnett.plus.com Sun Nov 19 14:32:04 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 19 Nov 2017 19:32:04 +0000 Subject: Student can't get if elif final statement to print for discussion post for python In-Reply-To: <857eumw0p6.fsf@benfinney.id.au> References: <857eumw0p6.fsf@benfinney.id.au> Message-ID: On 2017-11-19 19:03, Ben Finney wrote: > Cheri Castro writes: > >> I've tried several variations but haven't been able to figure out why >> my final if elif statement won't print. > > The code you presented here does not have any ?elif? clause. Did you > mean to show different code? > >> I tried using return, I tried using 1's and 0's rather than yes and >> no. Not sure what the issue is. Please, help. > > Your questions are welcome here, but you may also be interested in > the ?tutor? > discussion forum especially for Python beginners. > >> #This function will print how many yes answers the user has and a message >> def correctAnswers(job, house, yard, time): >> if correctAnswers == 'yes': >> print ("Congratulations! You should get a puppy!") >> else: >> return "I'm sorry, you shouldn't get a puppy." > > The ?if? clause tests the value of ?correctAnswers?. Where do you expect > that value to come from? Nothing in the function ever sets a value to > that name. > > On the other hand, the function never makes use of ?job?, ?house?, > ?yard?, or ?time?. Why are those parameters to the function? > The function itself is called 'correctAnswers', and a function is never equal to a string. From greg.ewing at canterbury.ac.nz Sun Nov 19 16:49:41 2017 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 20 Nov 2017 10:49:41 +1300 Subject: "help( pi )" In-Reply-To: <20171119045238.GA8897@cskk.homeip.net> References: <20171119045238.GA8897@cskk.homeip.net> Message-ID: <5A11FC75.2040006@canterbury.ac.nz> Cameron Simpson wrote: > Unless one had a misfortune and wanted another docstring. Good point. I guess having differing docstrings should make otherwise equal objects ineligible for merging. > mod1.py: > MAX_BUFSIZE = 8192 > MAX_BUFSIZE.__doc__ = 'Size of the hardware buffer used for I/O on > this device.' > > mod2.py > DEFAULT_CACHESIZE = 8192 > DEFAULT_CACHESIZE.__doc__ = 'Convenient size for the foo cache, not > to big or too small.' I think setting the docstring of an existing immutable object would have to be disallowed -- you need to create a new object if you want it to have a distinct docstring, e.g. MAX_BUFSIZE = int(8192, __doc__ = 'Size of the hardware buffer used for I/O on this device.') -- Greg From tjol at tjol.eu Sun Nov 19 17:01:20 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 19 Nov 2017 23:01:20 +0100 Subject: Problem in defining multidimensional array matrix and regression In-Reply-To: <619b7086-77a1-4173-b937-b91b6b085a04@googlegroups.com> References: <619b7086-77a1-4173-b937-b91b6b085a04@googlegroups.com> Message-ID: <1be9c49a-0f60-20b7-d364-401099f05882@tjol.eu> On 19/11/17 18:55, shalu.ashu50 at gmail.com wrote: > Hello Peter, > > Many thanks for your suggestion. > Now I am using Pandas & > I already did that but now I need to make a multi-dimensional array for reading all variables (5 in this case) at one x-axis, so I can perform multiple regression analysis. > > I am not getting how to bring all variables at one axis (e.g. at x-axis)? Pandas is great at this: index a single row of a DataFrame with your favourite selector from http://pandas.pydata.org/pandas-docs/stable/indexing.html (or just loop over the DataFrame's .iterrows) If you want a multi-dimensional array with all the data, numpy.loadtxt can do that for you. > > Thanks > Vishal > > On Sunday, 19 November 2017 22:32:06 UTC+5:30, Peter Otten wrote: >> shalu.ashu50 at gmail.com wrote: >> >>> Hi, All, >>> >>> I have 6 variables in CSV file. One is rainfall (dependent, at y-axis) and >>> others are predictors (at x). I want to do multiple regression and create >>> a correlation matrix between rainfall (y) and predictors (x; n1=5). Thus I >>> want to read rainfall as a separate variable and others in separate >>> columns, so I can apply the algo. However, I am not able to make a proper >>> matrix for them. >>> >>> Here are my data and codes? >>> Please suggest me for the same. >>> I am new to Python. >>> >>> RF P1 P2 P3 P4 P5 >>> 120.235 0.234 -0.012 0.145 21.023 0.233 >>> 200.14 0.512 -0.021 0.214 22.21 0.332 >>> 185.362 0.147 -0.32 0.136 24.65 0.423 >>> 201.895 0.002 -0.12 0.217 30.25 0.325 >>> 165.235 0.256 0.001 0.22 31.245 0.552 >>> 198.236 0.012 -0.362 0.215 32.25 0.333 >>> 350.263 0.98 -0.85 0.321 38.412 0.411 >>> 145.25 0.046 -0.36 0.147 39.256 0.872 >>> 198.654 0.65 -0.45 0.224 40.235 0.652 >>> 245.214 0.47 -0.325 0.311 26.356 0.632 >>> 214.02 0.18 -0.012 0.242 22.01 0.745 >>> 147.256 0.652 -0.785 0.311 18.256 0.924 >>> >>> import numpy as np >>> import statsmodels as sm >>> import statsmodels.formula as smf >>> import csv >>> >>> with open("pcp1.csv", "r") as csvfile: >>> readCSV=csv.reader(csvfile) >>> >>> rainfall = [] >>> csvFileList = [] >>> >>> for row in readCSV: >>> Rain = row[0] >>> rainfall.append(Rain) >>> >>> if len (row) !=0: >>> csvFileList = csvFileList + [row] >>> >>> print(csvFileList) >>> print(rainfall) >> >> You are not the first to read tabular data from a file; therefore numpy (and >> pandas) offer highlevel function to do just that. Once you have the complete >> table extracting a specific column is easy. For instance: >> >> $ cat rainfall.txt >> RF P1 P2 P3 P4 P5 >> 120.235 0.234 -0.012 0.145 21.023 0.233 >> 200.14 0.512 -0.021 0.214 22.21 0.332 >> 185.362 0.147 -0.32 0.136 24.65 0.423 >> 201.895 0.002 -0.12 0.217 30.25 0.325 >> 165.235 0.256 0.001 0.22 31.245 0.552 >> 198.236 0.012 -0.362 0.215 32.25 0.333 >> 350.263 0.98 -0.85 0.321 38.412 0.411 >> 145.25 0.046 -0.36 0.147 39.256 0.872 >> 198.654 0.65 -0.45 0.224 40.235 0.652 >> 245.214 0.47 -0.325 0.311 26.356 0.632 >> 214.02 0.18 -0.012 0.242 22.01 0.745 >> 147.256 0.652 -0.785 0.311 18.256 0.924 >> $ python3 >> Python 3.4.3 (default, Nov 17 2016, 01:08:31) >> [GCC 4.8.4] on linux >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import numpy >>>>> rf = numpy.genfromtxt("rainfall.txt", names=True) >>>>> rf["RF"] >> array([ 120.235, 200.14 , 185.362, 201.895, 165.235, 198.236, >> 350.263, 145.25 , 198.654, 245.214, 214.02 , 147.256]) >>>>> rf["P3"] >> array([ 0.145, 0.214, 0.136, 0.217, 0.22 , 0.215, 0.321, 0.147, >> 0.224, 0.311, 0.242, 0.311]) > From skip.montanaro at gmail.com Sun Nov 19 18:29:30 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 19 Nov 2017 15:29:30 -0800 (PST) Subject: Test - please ignore (again) In-Reply-To: <7bd282e5-323a-4997-94e0-eaf027db4aa7@googlegroups.com> References: <7bd282e5-323a-4997-94e0-eaf027db4aa7@googlegroups.com> Message-ID: <507bcc16-3a6e-45e7-b5c0-bc3514a45d0b@googlegroups.com> > Another test of SpamBayes in comp.lang.python -> python-list gateway. Still leaning on the submit button to see what gate_news thinks... Skip From mradul.k.dhakad at gmail.com Sun Nov 19 20:16:41 2017 From: mradul.k.dhakad at gmail.com (mradul dhakad) Date: Mon, 20 Nov 2017 06:46:41 +0530 Subject: How to Generate dynamic HTML Report using Python Message-ID: Hi All , I am new to python . I am trying to generate Dynamic HTML report using Pyhton based on number of rows selected from query .Do any one can suggest some thing for it. Thanks, Mradul From ned at nedbatchelder.com Sun Nov 19 21:44:07 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 19 Nov 2017 21:44:07 -0500 Subject: How to Generate dynamic HTML Report using Python In-Reply-To: References: Message-ID: On 11/19/17 8:40 PM, Stefan Ram wrote: > mradul dhakad writes: >> I am new to python . I am trying to generate Dynamic HTML report using >> Pyhton based on number of rows selected from query .Do any one can suggest >> some thing for it. > main.py > > import sqlite3 > conn = sqlite3.connect( ':memory:' ) > c = conn.cursor() > c.execute( "CREATE TABLE T ( A TEXT )" ) > c.execute( "INSERT INTO T ( A ) VALUES ( '1' ), ( '2' )" ) > conn.commit() > c.execute( "SELECT * FROM T WHERE A = '1'" ) > number_of_rows_selected_from_query = len( c.fetchall() ) > conn.close() > del c > del conn > del sqlite3 I'm curious what superstition compels you to delete these names? There's no need to. Also, why set headers that prevent the Python-List mailing list from archiving your messages? --Ned. > def HTML( x ): > return f''' > > > Number Of Rows Selected From Query

Number Of Rows Selected From Query

>

The number of rows selected from query is {x}.

''' > > print( HTML( number_of_rows_selected_from_query )) > > transcript > > > > > Number Of Rows Selected From Query

Number Of Rows Selected From Query

>

The number of rows selected from query is 1.

> From dvl at psu.edu Sun Nov 19 22:16:44 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Sun, 19 Nov 2017 22:16:44 -0500 Subject: Problem in defining multidimensional array matrix and regression In-Reply-To: mailman.36.1511110804.26071.python-list@python.org References: Message-ID: <1511147803l.6946852l.0l@psu.edu> On Sun, 19 Nov 2017, shalu.ashu50 at gmail.com wrote: > Hi, All, > >I have 6 variables in CSV file. One is rainfall (dependent, at >y-axis) and others are predictors (at x). I want to do multiple >regression and create a correlation matrix between rainfall (y) and >predictors (x; n1=5). Thus I want to read rainfall as a separate >variable and others in separate columns, so I can apply the algo. However, I am >not able to make a proper matrix for them. > >Here are my data and codes? >Please suggest me for the same. >I am new to Python. > >RF P1 P2 P3 P4 P5 >120.235 0.234 -0.012 0.145 21.023 0.233 >200.14 0.512 -0.021 0.214 22.21 0.332 >185.362 0.147 -0.32 0.136 24.65 0.423 >201.895 0.002 -0.12 0.217 30.25 0.325 >165.235 0.256 0.001 0.22 31.245 0.552 >198.236 0.012 -0.362 0.215 32.25 0.333 >350.263 0.98 -0.85 0.321 38.412 0.411 >145.25 0.046 -0.36 0.147 39.256 0.872 >198.654 0.65 -0.45 0.224 40.235 0.652 >245.214 0.47 -0.325 0.311 26.356 0.632 >214.02 0.18 -0.012 0.242 22.01 0.745 >147.256 0.652 -0.785 0.311 18.256 0.924 > >import numpy as np >import statsmodels as sm >import statsmodels.formula as smf >import csv > >with open("pcp1.csv", "r") as csvfile: > readCSV=csv.reader(csvfile) > > rainfall = [] > csvFileList = [] > > for row in readCSV: > Rain = row[0] > rainfall.append(Rain) > > if len (row) !=0: > csvFileList = csvFileList + [row] > >print(csvFileList) >print(rainfall) > >Please suggest me guys >Thanks > There seems to be a conceptual disconnect here. Do you happen to know what the letters C,S,V stand for in CSV file? Because I don't see any C's in your data, and I don't see anything in your code to use anything other than C to S your V's. I'm thinking that is the first place you should look. You could either modify your data file (with a nice global replace/change) or you could give a different value to one of the default parameters to the functions you use to open the file. Roger Christman Pennsylvania State University From kryptxy at protonmail.com Sun Nov 19 23:20:45 2017 From: kryptxy at protonmail.com (Kryptxy) Date: Sun, 19 Nov 2017 23:20:45 -0500 Subject: How to Generate dynamic HTML Report using Python In-Reply-To: References: Message-ID: <8q3BT0y0v5wsVIp0yIwyARlPfPDAIkB43JiBhpTbC9aX51D7bdqDOaFnXhqNLpwA6G4wCHClFmGzJc6x5BGrec8lO_Xix0ZbdxXYVwy8_R0=@protonmail.com> I have a piece of code (module) implementing dynamic html page generation. What it simply does is writes all the html content (tags + data) to a file, and the file is save with a (.html) extension. Served my purpose. Not really sure is this is something you are looking for. You can view the code here: https://github.com/kryptxy/torrench/blob/master/torrench/modules/tpb_details.py Hope this helps. -------- Original Message -------- On 20 Nov 2017, 6:46 AM, mradul dhakad wrote: > Hi All , > > I am new to python . I am trying to generate Dynamic HTML report using > Pyhton based on number of rows selected from query .Do any one can suggest > some thing for it. > > Thanks, > Mradul > -- > https://mail.python.org/mailman/listinfo/python-list From nimbiotics at gmail.com Mon Nov 20 09:40:55 2017 From: nimbiotics at gmail.com (Mario R. Osorio) Date: Mon, 20 Nov 2017 06:40:55 -0800 (PST) Subject: Is there something like head() and str() of R in python? In-Reply-To: References: Message-ID: <43107f01-8ad1-4c5c-aafa-8fef36f6581c@googlegroups.com> On Sunday, November 19, 2017 at 2:05:12 PM UTC-5, Peng Yu wrote: > Hi, R has the functions head() and str() to show the brief content of > an object. Is there something similar in python for this purpose? > > For example, I want to inspect the content of the variable "train". > What is the best way to do so? Thanks. > > $ cat demo.py > from __future__ import division, print_function, absolute_import > > import tflearn > from tflearn.data_utils import to_categorical, pad_sequences > from tflearn.datasets import imdb > > # IMDB Dataset loading > train, test, _ = imdb.load_data(path='imdb.pkl', n_words=10000, > valid_portion=0.1) > > # https://raw.githubusercontent.com/llSourcell/How_to_do_Sentiment_Analysis/master/demo.py > > -- > Regards, > Peng Python is very good at giving you a string representation of any object. However, such capabilities do fall short every now and then. That is why when defining your own classes, you must also override the __init__() and _-repr__() methods so you can get a better suited string representation of such objects. You can read more at: https://stackoverflow.com/questions/12448175/confused-about-str-in-python From jasonhihn at gmail.com Mon Nov 20 10:48:48 2017 From: jasonhihn at gmail.com (Jason) Date: Mon, 20 Nov 2017 07:48:48 -0800 (PST) Subject: General Purpose Pipeline library? Message-ID: a pipeline can be described as a sequence of functions that are applied to an input with each subsequent function getting the output of the preceding function: out = f6(f5(f4(f3(f2(f1(in)))))) However this isn't very readable and does not support conditionals. Tensorflow has tensor-focused pipepines: fc1 = layers.fully_connected(x, 256, activation_fn=tf.nn.relu, scope='fc1') fc2 = layers.fully_connected(fc1, 256, activation_fn=tf.nn.relu, scope='fc2') out = layers.fully_connected(fc2, 10, activation_fn=None, scope='out') I have some code which allows me to mimic this, but with an implied parameter. def executePipeline(steps, collection_funcs = [map, filter, reduce]): results = None for step in steps: func = step[0] params = step[1] if func in collection_funcs: print func, params[0] results = func(functools.partial(params[0], *params[1:]), results) else: print func if results is None: results = func(*params) else: results = func(*(params+(results,))) return results executePipeline( [ (read_rows, (in_file,)), (map, (lower_row, field)), (stash_rows, ('stashed_file', )), (map, (lemmatize_row, field)), (vectorize_rows, (field, min_count,)), (evaluate_rows, (weights, None)), (recombine_rows, ('stashed_file', )), (write_rows, (out_file,)) ] ) Which gets me close, but I can't control where rows gets passed in. In the above code, it is always the last parameter. I feel like I'm reinventing a wheel here. I was wondering if there's already something that exists? From skip.montanaro at gmail.com Mon Nov 20 11:03:56 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 20 Nov 2017 10:03:56 -0600 Subject: General Purpose Pipeline library? In-Reply-To: References: Message-ID: > I feel like I'm reinventing a wheel here. I was wondering if there's already something that exists? I've wondered from time-to-time about using shell pipeline notation within Python. Maybe the grapevine package could be a starting point? I realize that's probably not precisely what you're looking for, but maybe it will give you some ideas. (I've never used it, just stumbled on it with a bit of poking around.) Skip From bgailer at gmail.com Mon Nov 20 11:23:41 2017 From: bgailer at gmail.com (Bob Gailer) Date: Mon, 20 Nov 2017 11:23:41 -0500 Subject: General Purpose Pipeline library? In-Reply-To: References: Message-ID: On Nov 20, 2017 10:50 AM, "Jason" wrote: > > a pipeline can be described as a sequence of functions that are applied to an input with each subsequent function getting the output of the preceding function: > > out = f6(f5(f4(f3(f2(f1(in)))))) > > However this isn't very readable and does not support conditionals. > > Tensorflow has tensor-focused pipepines: > fc1 = layers.fully_connected(x, 256, activation_fn=tf.nn.relu, scope='fc1') > fc2 = layers.fully_connected(fc1, 256, activation_fn=tf.nn.relu, scope='fc2') > out = layers.fully_connected(fc2, 10, activation_fn=None, scope='out') > > I have some code which allows me to mimic this, but with an implied parameter. > > def executePipeline(steps, collection_funcs = [map, filter, reduce]): > results = None > for step in steps: > func = step[0] > params = step[1] > if func in collection_funcs: > print func, params[0] > results = func(functools.partial(params[0], *params[1:]), results) > else: > print func > if results is None: > results = func(*params) > else: > results = func(*(params+(results,))) > return results > > executePipeline( [ > (read_rows, (in_file,)), > (map, (lower_row, field)), > (stash_rows, ('stashed_file', )), > (map, (lemmatize_row, field)), > (vectorize_rows, (field, min_count,)), > (evaluate_rows, (weights, None)), > (recombine_rows, ('stashed_file', )), > (write_rows, (out_file,)) > ] > ) > > Which gets me close, but I can't control where rows gets passed in. In the above code, it is always the last parameter. > > I feel like I'm reinventing a wheel here. I was wondering if there's already something that exists? IBM has had for a very long time a program called Pipelines which runs on IBM mainframes. It does what you want. A number of attempts have been made to create cross-platform versions of this marvelous program. A long time ago I started but never completed an open source python version. If you are interested in taking a look at this let me know. From jabronson at gmail.com Mon Nov 20 12:47:01 2017 From: jabronson at gmail.com (Josh B.) Date: Mon, 20 Nov 2017 09:47:01 -0800 (PST) Subject: __hash__ and ordered vs. unordered collections Message-ID: Suppose we're implementing an immutable collection type that comes in unordered and ordered flavors. Let's call them MyColl and MyOrderedColl. We implement __eq__ such that MyColl(some_elements) == MyOrderedColl(other_elements) iff set(some_elements) == set(other_elements). But MyOrderedColl(some_elements) == MyOrderedColl(other_elements) iff list(some_elements) == list(other_elements). This works just like dict and collections.OrderedDict, in other words. Since our collection types are immutable, let's say we want to implement __hash__. We must ensure that our __hash__ results are consistent with __eq__. That is, we make sure that if MyColl(some_elements) == MyOrderedColl(other_elements), then hash(MyColl(some_elements)) == hash(MyOrderedColl(other_elements)). Now for the question: Is this useful? I ask because this leads to the following behavior: >>> unordered = MyColl([1, 2, 3]) >>> ordered = MyOrderedColl([3, 2, 1]) >>> s = {ordered, unordered} >>> len(s) 1 >>> s = {ordered} >>> unordered in s True >>> # etc. In other words, sets and mappings can't tell unordered and ordered apart; they're treated like the same values. This is a bit reminiscent of: >>> s = {1.0} >>> True in s True >>> d = {1: int, 1.0: float, True: bool} >>> len(d) 1 >>> # etc. The first time I encountered this was a bit of an "aha", but to be clear, I think this behavior is totally right. However, I'm less confident that this kind of behavior is useful for MyColl and MyOrderedColl. Could anyone who feels more certain one way or the other please explain the rationale and possibly even give some real-world examples? Thanks! Josh From torriem at gmail.com Mon Nov 20 13:47:17 2017 From: torriem at gmail.com (Michael Torrie) Date: Mon, 20 Nov 2017 11:47:17 -0700 Subject: How to Generate dynamic HTML Report using Python In-Reply-To: References: Message-ID: Your thoughts on scope are interesting, if unorthodox. There is a problem with your deleting names after use, which is why we rarely delete names. The problem is that deleting a name does not not necessarily or immediately destroy an object. This can lead to great confusion for programmers coming from a RAII language like C++. All del does is delete a name/object binding. Which is the exact same thing as reassigning the name to a new object. Thus I don't see how using del as you do is at all useful, either for programming correctness or understanding. In fact I think it might even be harmful. Far more useful to teach people to use context handlers when appropriate. For example, when working with your sql connection object. On 11/20/2017 07:50 AM, Stefan Ram wrote: > I am posting to a Usenet newsgroup. I am not aware of any > "Python-List mailing list". As far as I'm concerned, this list is primarily a mailing list, hosted by Mailman at python.org, and is mirrored to Usenet via a gateway as a service by python.org. Granted, this is just a matter of perspective. > I am posting specifically to the Usenet, because I am aware > of it's rules and I like it and wish to support it. What rules are these? I'm curious what news reader you are using as your posts are, well, unique. You've set headers that most do not, and your post bodies are all base64 encoded. Your quotes and block (un)indents are very odd also. A very curious setup. You also have this header set: > X-Copyright: (C) Copyright 2017 Stefan Ram. All rights reserved. > Distribution through any means other than regular usenet > channels is forbidden. It is forbidden to publish this > article in the world wide web. It is forbidden to change > URIs of this article into links. It is forbidden to remove > this notice or to transfer the body without this notice. Looks to me like the mailing list needs to block your messages, lest python.org be in violation of your copyright. From rosuav at gmail.com Mon Nov 20 13:54:56 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Nov 2017 05:54:56 +1100 Subject: __hash__ and ordered vs. unordered collections In-Reply-To: References: Message-ID: On Tue, Nov 21, 2017 at 4:47 AM, Josh B. wrote: > Now for the question: Is this useful? I ask because this leads to the following behavior: > >>>> unordered = MyColl([1, 2, 3]) >>>> ordered = MyOrderedColl([3, 2, 1]) >>>> s = {ordered, unordered} >>>> len(s) > 1 >>>> s = {ordered} >>>> unordered in s > True >>>> # etc. > > In other words, sets and mappings can't tell unordered and ordered apart; they're treated like the same values. > > However, I'm less confident that this kind of behavior is useful for MyColl and MyOrderedColl. Could anyone who feels more certain one way or the other please explain the rationale and possibly even give some real-world examples? > This isn't a consequence of __hash__, it's a consequence of __eq__. You have declared that MyColl and MyOrderedColl are equal, therefore only one of them stays in the set. But what you have is the strangeness of non-transitive equality, which is likely to cause problems. >>> unordered = MyColl([1, 2, 3]) >>> ordered1 = MyColl([3, 2, 1]) >>> ordered2 = MyColl([2, 1, 3]) unordered is equal to each of the others, but they're not equal to each other. So if you put them into a set, you'll get results that depend on order. Here's a simpler form of non-transitive equality: >>> class Oddity(int): ... def __eq__(self, other): ... if other - 5 <= self <= other + 5: ... return True ... return int(self) == other ... def __hash__(self): ... return 1 ... >>> x, y, z = Oddity(5), Oddity(10), Oddity(15) >>> x == y, y == z, x == z (True, True, False) >>> {x, y, z} {5, 15} >>> {y, x, z} {10} Setting __hash__ to a constant value is safe (but inefficient); it's all based on how __eq__ works. So the question is: are you willing to accept the bizarre behaviour of non-transitive equality? ChrisA From python at mrabarnett.plus.com Mon Nov 20 14:31:07 2017 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 20 Nov 2017 19:31:07 +0000 Subject: __hash__ and ordered vs. unordered collections In-Reply-To: References: Message-ID: <8606a78e-385f-f9a5-dd04-876da0d97816@mrabarnett.plus.com> On 2017-11-20 17:47, Josh B. wrote: > Suppose we're implementing an immutable collection type that comes in unordered and ordered flavors. Let's call them MyColl and MyOrderedColl. > > We implement __eq__ such that MyColl(some_elements) == MyOrderedColl(other_elements) iff set(some_elements) == set(other_elements). > What if there are duplicate elements? Should that be MyColl(some_elements) == MyOrderedColl(other_elements) iff len(some_elements) == len(other_elements) and set(some_elements) == set(other_elements)? > But MyOrderedColl(some_elements) == MyOrderedColl(other_elements) iff list(some_elements) == list(other_elements). > > This works just like dict and collections.OrderedDict, in other words. > > Since our collection types are immutable, let's say we want to implement __hash__. > > We must ensure that our __hash__ results are consistent with __eq__. That is, we make sure that if MyColl(some_elements) == MyOrderedColl(other_elements), then hash(MyColl(some_elements)) == hash(MyOrderedColl(other_elements)). > > Now for the question: Is this useful? I ask because this leads to the following behavior: > >>>> unordered = MyColl([1, 2, 3]) >>>> ordered = MyOrderedColl([3, 2, 1]) >>>> s = {ordered, unordered} >>>> len(s) > 1 >>>> s = {ordered} >>>> unordered in s > True >>>> # etc. > > In other words, sets and mappings can't tell unordered and ordered apart; they're treated like the same values. > > This is a bit reminiscent of: > >>>> s = {1.0} >>>> True in s > True >>>> d = {1: int, 1.0: float, True: bool} >>>> len(d) > 1 >>>> # etc. > > The first time I encountered this was a bit of an "aha", but to be clear, I think this behavior is totally right. > > However, I'm less confident that this kind of behavior is useful for MyColl and MyOrderedColl. Could anyone who feels more certain one way or the other please explain the rationale and possibly even give some real-world examples? > If MyColl(some_elements) == MyOrderedColl(other_elements), then len({MyColl(some_elements), MyOrderedColl(other_elements)}) == 1 seems right. As for which one is in the set: >>> {1, 1.0} {1} >>> {1.0, 1} {1.0} So if MyColl(some_elements) == MyOrderedColl(other_elements), then {MyColl(some_elements), MyOrderedColl(other_elements)} == {MyColl(some_elements)}. From jabronson at gmail.com Mon Nov 20 14:50:34 2017 From: jabronson at gmail.com (Josh B.) Date: Mon, 20 Nov 2017 11:50:34 -0800 (PST) Subject: __hash__ and ordered vs. unordered collections In-Reply-To: References: Message-ID: On Monday, November 20, 2017 at 1:55:26 PM UTC-5, Chris Angelico wrote: > But what you have is the strangeness of non-transitive equality, which > is likely to cause problems. But this is exactly how Python's built-in dict and OrderedDict behave: >>> od = OrderedDict([(1, 0), (2, 0), (3, 0)]) >>> od2 = OrderedDict([(3, 0), (2, 0), (1, 0)]) >>> ud = dict(od) >>> od == ud True >>> od2 == ud True >>> od == od2 False Given that, it would seem wrong for our MyOrderedColl.__eq__ to not behave similarly. Or are you suggesting that OrderedDict.__eq__ should not have been implemented this way in the first place? > So the question is: are you willing to > accept the bizarre behaviour of non-transitive equality? Forget what I'm personally willing to do :) The question here actually is to tease out what Python's existing design is telling us to do. If it helps, substitute "frozenset" for "MyColl" and "FrozenOrderedSet" for "MyOrderedColl". How would you implement their __eq__ methods? What would be the correct design for our hypothetical frozen(ordered)set library? What would be more useful, intuitive, and usable for our users? Thanks very much for the good examples and for helping me clarify the question! From jabronson at gmail.com Mon Nov 20 14:52:59 2017 From: jabronson at gmail.com (Josh B.) Date: Mon, 20 Nov 2017 11:52:59 -0800 (PST) Subject: __hash__ and ordered vs. unordered collections In-Reply-To: References: <8606a78e-385f-f9a5-dd04-876da0d97816@mrabarnett.plus.com> Message-ID: On Monday, November 20, 2017 at 2:31:40 PM UTC-5, MRAB wrote: > What if there are duplicate elements? > > Should that be MyColl(some_elements) == MyOrderedColl(other_elements) > iff len(some_elements) == len(other_elements) and set(some_elements) == > set(other_elements)? Yes, that's what I meant. Thanks for catching :) Please let me know if you have any thoughts on how you would design our hypothetical frozen(ordered)set library to behave in these cases. From rosuav at gmail.com Mon Nov 20 15:13:17 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Nov 2017 07:13:17 +1100 Subject: How to Generate dynamic HTML Report using Python In-Reply-To: References: Message-ID: On Tue, Nov 21, 2017 at 5:47 AM, Michael Torrie wrote: > You also have this header set: >> X-Copyright: (C) Copyright 2017 Stefan Ram. All rights reserved. >> Distribution through any means other than regular usenet >> channels is forbidden. It is forbidden to publish this >> article in the world wide web. It is forbidden to change >> URIs of this article into links. It is forbidden to remove >> this notice or to transfer the body without this notice. > > Looks to me like the mailing list needs to block your messages, lest > python.org be in violation of your copyright. Is that kind of copyright notice even enforceable? Personally, if I saw a header like that, I'd plonk the person, because anyone who says "please don't read my messages in any way other than the way I've stipulated" might as well be saying "please don't read my messages". It's not worth the hassle. ChrisA From rosuav at gmail.com Mon Nov 20 15:17:32 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Nov 2017 07:17:32 +1100 Subject: __hash__ and ordered vs. unordered collections In-Reply-To: References: Message-ID: On Tue, Nov 21, 2017 at 6:50 AM, Josh B. wrote: > On Monday, November 20, 2017 at 1:55:26 PM UTC-5, Chris Angelico wrote: >> But what you have is the strangeness of non-transitive equality, which >> is likely to cause problems. > > But this is exactly how Python's built-in dict and OrderedDict behave: > >>>> od = OrderedDict([(1, 0), (2, 0), (3, 0)]) >>>> od2 = OrderedDict([(3, 0), (2, 0), (1, 0)]) >>>> ud = dict(od) >>>> od == ud > True >>>> od2 == ud > True >>>> od == od2 > False > > > Given that, it would seem wrong for our MyOrderedColl.__eq__ to not behave similarly. > > Or are you suggesting that OrderedDict.__eq__ should not have been implemented this way in the first place? > > >> So the question is: are you willing to >> accept the bizarre behaviour of non-transitive equality? > > Forget what I'm personally willing to do :) > The question here actually is to tease out what Python's existing design is telling us to do. > > If it helps, substitute "frozenset" for "MyColl" and "FrozenOrderedSet" for "MyOrderedColl". How would you implement their __eq__ methods? What would be the correct design for our hypothetical frozen(ordered)set library? What would be more useful, intuitive, and usable for our users? > > Thanks very much for the good examples and for helping me clarify the question! > What I'm saying is that non-transitive equality can cause a lot of confusion in sets/dicts; since OrderedDict and dict are unhashable, they won't themselves be problematic, and Python doesn't have a built-in FrozenOrderedSet. So there isn't really a precedent here, and it's up to you to decide how you want to deal with this. Basically, you're going to have to accept one of two situations: * Either your class doesn't behave the same way dict and OD do * Or your class, when put into a set, depends on ordering. Neither is perfect. You have to take your pick between them. ChrisA From marko at pacujo.net Mon Nov 20 16:34:15 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 20 Nov 2017 23:34:15 +0200 Subject: General Purpose Pipeline library? References: Message-ID: <878tf0k52g.fsf@elektro.pacujo.net> ram at zedat.fu-berlin.de (Stefan Ram): > Jason writes: >>I feel like I'm reinventing a wheel here. I was wondering if >>there's already something that exists? > > Why do you want this? Some time back Stephen D'Aprano demonstrated how the | operator can be defined to create pipelines in Python. As a hobby project, I started developing the idea further into a Python-based shell (I call it "snake"). I kinda proved to myself that it is very much doable and left it at that. For example: $ ./snake >>> ls() notes.txt .git snake notes.txt~ >>> ls() | cat() notes.txt .git snake notes.txt~ >>> ls() | grep(lambda x: "n" in x) notes.txt snake notes.txt~ >>> sleep(5) >>> sleep(5).bg() 29766 >>> [29766] Done: sleep(5) >>> X("/bin/echo hello") hello >>> X("/bin/seq 20") | grep(lambda x: "2" in x) 2 12 20 >>> So snake is just a regular Python REPL with some predefined things that implement a full-fledged Unix shell, courtesy of the amazingly complete Linux system call support by Python. The pipelines relay byte streams, line sequences or JSON arrays. The pipeline processors are either generators or processes. > Can't you just map what you want to do to plain-old Python? The above is plain Python, but it might be more pythonesque to do the pipelining using the dot notation: feed(dataset).f().g().h().output() Marko From cs at cskk.id.au Mon Nov 20 17:10:31 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 21 Nov 2017 09:10:31 +1100 Subject: "help( pi )" In-Reply-To: <5A11FC75.2040006@canterbury.ac.nz> References: <5A11FC75.2040006@canterbury.ac.nz> Message-ID: <20171120221031.GA88099@cskk.homeip.net> On 20Nov2017 10:49, Greg Ewing wrote: >Cameron Simpson wrote: >>Unless one had a misfortune and wanted another docstring. > >Good point. I guess having differing docstrings should make >otherwise equal objects ineligible for merging. > [...example...] > >I think setting the docstring of an existing immutable object >would have to be disallowed -- you need to create a new object >if you want it to have a distinct docstring, e.g. > >MAX_BUFSIZE = int(8192, __doc__ = 'Size of the hardware buffer used >for I/O on this device.') Which is painful and elaborate. In my original post I had written: Now, I accept that the "CPython coaleases some values to shared singletons" thing is an issue, but the language doesn't require it, and one could change implementations such that applying a docstring to an object _removed_ it from the magic-shared-singleton pool, avoiding conflicts with other uses of the same value by coincidence. hoping for automatic arrangement of that. Cheers, Cameron Simpson (formerly cs at zip.com.au) From duncan at invalid.invalid Mon Nov 20 18:22:08 2017 From: duncan at invalid.invalid (duncan smith) Date: Mon, 20 Nov 2017 23:22:08 +0000 Subject: General Purpose Pipeline library? In-Reply-To: References: Message-ID: On 20/11/17 15:48, Jason wrote: > a pipeline can be described as a sequence of functions that are applied to an input with each subsequent function getting the output of the preceding function: > > out = f6(f5(f4(f3(f2(f1(in)))))) > > However this isn't very readable and does not support conditionals. > > Tensorflow has tensor-focused pipepines: > fc1 = layers.fully_connected(x, 256, activation_fn=tf.nn.relu, scope='fc1') > fc2 = layers.fully_connected(fc1, 256, activation_fn=tf.nn.relu, scope='fc2') > out = layers.fully_connected(fc2, 10, activation_fn=None, scope='out') > > I have some code which allows me to mimic this, but with an implied parameter. > > def executePipeline(steps, collection_funcs = [map, filter, reduce]): > results = None > for step in steps: > func = step[0] > params = step[1] > if func in collection_funcs: > print func, params[0] > results = func(functools.partial(params[0], *params[1:]), results) > else: > print func > if results is None: > results = func(*params) > else: > results = func(*(params+(results,))) > return results > > executePipeline( [ > (read_rows, (in_file,)), > (map, (lower_row, field)), > (stash_rows, ('stashed_file', )), > (map, (lemmatize_row, field)), > (vectorize_rows, (field, min_count,)), > (evaluate_rows, (weights, None)), > (recombine_rows, ('stashed_file', )), > (write_rows, (out_file,)) > ] > ) > > Which gets me close, but I can't control where rows gets passed in. In the above code, it is always the last parameter. > > I feel like I'm reinventing a wheel here. I was wondering if there's already something that exists? > Maybe Kamaelia? http://www.kamaelia.org/Home.html Duncan From hemla21 at gmail.com Tue Nov 21 05:04:45 2017 From: hemla21 at gmail.com (Heli) Date: Tue, 21 Nov 2017 02:04:45 -0800 (PST) Subject: how to compare and check if two binary(h5) files numerically have the same contents Message-ID: Dear all, I am trying to compare the contents of two binary files. I use python 3.6 filecomp comparing same name files inside two directories. results_dummy=filecmp.cmpfiles(dir1, dir2, common, shallow=True) The above line works for *.bin file I have in both directories, but it does not work with h5 files. When comparing two hdf5 files that contain exactly the same groups/datasets and numerical data, filecmp.cmpfiles finds them as mismatch. My hdf files are not binary equal but contain the same exact data. Is there anyway to compare the contents of two hdf5 files from within Python script and without using h5diff? Thanks in Advance, From cs at cskk.id.au Tue Nov 21 06:03:21 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 21 Nov 2017 22:03:21 +1100 Subject: how to compare and check if two binary(h5) files numerically have the same contents In-Reply-To: References: Message-ID: <20171121110321.GA84602@cskk.homeip.net> On 21Nov2017 02:04, Heli wrote: >I am trying to compare the contents of two binary files. I use python 3.6 >filecomp comparing same name files inside two directories. > >results_dummy=filecmp.cmpfiles(dir1, dir2, common, shallow=True) > >The above line works for *.bin file I have in both directories, but it does not work with h5 files. > >When comparing two hdf5 files that contain exactly the same groups/datasets and numerical data, filecmp.cmpfiles finds them as mismatch. My hdf files are not binary equal but contain the same exact data. > >Is there anyway to compare the contents of two hdf5 files from within Python >script and without using h5diff? There are several packages on PyPI related to the H5 data format: https://pypi.python.org/pypi?%3Aaction=search&term=h5 I imagine what you need to do is to load your 2 H5 data files and then compare the data structures within them. Hopefully one of these packages can be used for this. This one looks promising: https://pypi.python.org/pypi/h5py/2.7.1 If you have pip, you should be able to install it thus: pip install --user h5py to make use of it. Cheers, Cameron Simpson (formerly cs at zip.com.au) From ned at nedbatchelder.com Tue Nov 21 06:57:11 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 21 Nov 2017 06:57:11 -0500 Subject: How to Generate dynamic HTML Report using Python In-Reply-To: References: Message-ID: <5b7a27e9-49ab-8840-2b96-89c5df1a20ae@nedbatchelder.com> On 11/20/17 9:50 AM, Stefan Ram wrote: > Ned Batchelder writes: >> Also, why set headers that prevent the Python-List mailing list from >> archiving your messages? > I am posting to a Usenet newsgroup. I am not aware of any > "Python-List mailing list". > > I am posting specifically to the Usenet, because I am aware > of it's rules and I like it and wish to support it. > > I do not post to a "mailing list" because I do not know which > rules apply for mailing lists and whether mailing lists in > general or any specific mailing list is an environment that I > like or wish to support. > The dual nature of this online community has long been confusing and complicated.? It's both a newsgroup and a mailing list.? Add in Google Groups, and you really have three different faces of the same content. The fact is, posting to comp.lang.python means that your words are also being distributed as a mailing list. Because of your messages' headers, they are not in the archive of that list (https://mail.python.org/pipermail/python-list/2017-November/thread.html), or in Google Groups (https://groups.google.com/forum/#!topic/comp.lang.python/0ejrtZ6ET9g). It makes for odd reading via those channels. I don't understand the motivation for limiting how words are distributed, but others on this list also do it. For example, Dennis Lee Bieber's messages are not in the Python-List archives either. If something is worth saying, why not let people find it later? --Ned. From rustompmody at gmail.com Tue Nov 21 08:36:06 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 21 Nov 2017 05:36:06 -0800 (PST) Subject: How to Generate dynamic HTML Report using Python In-Reply-To: References: <5b7a27e9-49ab-8840-2b96-89c5df1a20ae@nedbatchelder.com> Message-ID: <0a147350-0ced-45b8-b180-687c9d261e5c@googlegroups.com> On Tuesday, November 21, 2017 at 5:27:42 PM UTC+5:30, Ned Batchelder wrote: > On 11/20/17 9:50 AM, Stefan Ram wrote: > > Ned Batchelder writes: > >> Also, why set headers that prevent the Python-List mailing list from > >> archiving your messages? > > I am posting to a Usenet newsgroup. I am not aware of any > > "Python-List mailing list". > > > > I am posting specifically to the Usenet, because I am aware > > of it's rules and I like it and wish to support it. > > > > I do not post to a "mailing list" because I do not know which > > rules apply for mailing lists and whether mailing lists in > > general or any specific mailing list is an environment that I > > like or wish to support. > > > > The dual nature of this online community has long been confusing and > complicated.? It's both a newsgroup and a mailing list.? Add in Google > Groups, and you really have three different faces of the same content. > > The fact is, posting to comp.lang.python means that your words are also > being distributed as a mailing list. Because of your messages' headers, > they are not in the archive of that list > (https://mail.python.org/pipermail/python-list/2017-November/thread.html), > or in Google Groups > (https://groups.google.com/forum/#!topic/comp.lang.python/0ejrtZ6ET9g). > It makes for odd reading via those channels. > > I don't understand the motivation for limiting how words are > distributed, but others on this list also do it. For example, Dennis Lee > Bieber's messages are not in the Python-List archives either. If > something is worth saying, why not let people find it later? To which I would add: Setting headers is hardly a working method. Somebody quotes Stefan or Dennis and they are on the archives And some quote including emails some not etc From jasonhihn at gmail.com Tue Nov 21 09:10:43 2017 From: jasonhihn at gmail.com (Jason) Date: Tue, 21 Nov 2017 06:10:43 -0800 (PST) Subject: General Purpose Pipeline library? (Posting On Python-List Prohibited) In-Reply-To: <680c08e3-77b2-4556-8c07-8c49e302e2f3@googlegroups.com> References: <680c08e3-77b2-4556-8c07-8c49e302e2f3@googlegroups.com> Message-ID: <6d8d79b4-6a91-4434-bada-fa42ebe2f820@googlegroups.com> On Monday, November 20, 2017 at 4:02:31 PM UTC-5, Lawrence D?Oliveiro wrote: > On Tuesday, November 21, 2017 at 4:49:01 AM UTC+13, Jason wrote: > > a pipeline can be described as a sequence of functions that are > > applied to an input with each subsequent function getting the output > > of the preceding function: > > > > out = f6(f5(f4(f3(f2(f1(in)))))) > > > > However this isn't very readable and does not support conditionals. > > Do you want a DAG in general? If the nodes have a __call__, yes? From rustompmody at gmail.com Tue Nov 21 09:12:12 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 21 Nov 2017 06:12:12 -0800 (PST) Subject: How to Generate dynamic HTML Report using Python In-Reply-To: <0a147350-0ced-45b8-b180-687c9d261e5c@googlegroups.com> References: <5b7a27e9-49ab-8840-2b96-89c5df1a20ae@nedbatchelder.com> <0a147350-0ced-45b8-b180-687c9d261e5c@googlegroups.com> Message-ID: <04d453d8-1aa3-406d-a826-e615ca00f21b@googlegroups.com> On Tuesday, November 21, 2017 at 7:06:18 PM UTC+5:30, Rustom Mody wrote: > On Tuesday, November 21, 2017 at 5:27:42 PM UTC+5:30, Ned Batchelder wrote: > > On 11/20/17 9:50 AM, Stefan Ram wrote: > > > Ned Batchelder writes: > > >> Also, why set headers that prevent the Python-List mailing list from > > >> archiving your messages? > > > I am posting to a Usenet newsgroup. I am not aware of any > > > "Python-List mailing list". > > > > > > I am posting specifically to the Usenet, because I am aware > > > of it's rules and I like it and wish to support it. > > > > > > I do not post to a "mailing list" because I do not know which > > > rules apply for mailing lists and whether mailing lists in > > > general or any specific mailing list is an environment that I > > > like or wish to support. > > > > > > > The dual nature of this online community has long been confusing and > > complicated.? It's both a newsgroup and a mailing list.? Add in Google > > Groups, and you really have three different faces of the same content. > > > > The fact is, posting to comp.lang.python means that your words are also > > being distributed as a mailing list. Because of your messages' headers, > > they are not in the archive of that list > > (https://mail.python.org/pipermail/python-list/2017-November/thread.html), > > or in Google Groups > > (https://groups.google.com/forum/#!topic/comp.lang.python/0ejrtZ6ET9g). > > It makes for odd reading via those channels. > > > > I don't understand the motivation for limiting how words are > > distributed, but others on this list also do it. For example, Dennis Lee > > Bieber's messages are not in the Python-List archives either. If > > something is worth saying, why not let people find it later? > > To which I would add: > Setting headers is hardly a working method. > Somebody quotes Stefan or Dennis and they are on the archives > And some quote including emails some not > etc O and one more thing: If Stefan or Dennis say something to the above dont expect a response from me since I would not have seen theirs ? From jasonhihn at gmail.com Tue Nov 21 09:26:24 2017 From: jasonhihn at gmail.com (Jason) Date: Tue, 21 Nov 2017 06:26:24 -0800 (PST) Subject: General Purpose Pipeline library? In-Reply-To: References: Message-ID: <7e267598-7f21-42da-9b42-dcfd12b7ad2b@googlegroups.com> On Monday, November 20, 2017 at 10:49:01 AM UTC-5, Jason wrote: > a pipeline can be described as a sequence of functions that are applied to an input with each subsequent function getting the output of the preceding function: > > out = f6(f5(f4(f3(f2(f1(in)))))) > > However this isn't very readable and does not support conditionals. > > Tensorflow has tensor-focused pipepines: > fc1 = layers.fully_connected(x, 256, activation_fn=tf.nn.relu, scope='fc1') > fc2 = layers.fully_connected(fc1, 256, activation_fn=tf.nn.relu, scope='fc2') > out = layers.fully_connected(fc2, 10, activation_fn=None, scope='out') > > I have some code which allows me to mimic this, but with an implied parameter. > > def executePipeline(steps, collection_funcs = [map, filter, reduce]): > results = None > for step in steps: > func = step[0] > params = step[1] > if func in collection_funcs: > print func, params[0] > results = func(functools.partial(params[0], *params[1:]), results) > else: > print func > if results is None: > results = func(*params) > else: > results = func(*(params+(results,))) > return results > > executePipeline( [ > (read_rows, (in_file,)), > (map, (lower_row, field)), > (stash_rows, ('stashed_file', )), > (map, (lemmatize_row, field)), > (vectorize_rows, (field, min_count,)), > (evaluate_rows, (weights, None)), > (recombine_rows, ('stashed_file', )), > (write_rows, (out_file,)) > ] > ) > > Which gets me close, but I can't control where rows gets passed in. In the above code, it is always the last parameter. > > I feel like I'm reinventing a wheel here. I was wondering if there's already something that exists? Why do I want this? Because I'm tired of writing code that is locked away in a bespoke function. I'd have an army of functions all slightly different in functionality. I require flexibility in defining pipelines, and I don't want a custom pipeline to require any low-level coding. I just want to feed a sequence of functions to a script and have it process it. A middle ground between the shell | operator and bespoke python code. Sure, I could write many binaries bound by shell, but there are some things done far easier in python because of its extensive libraries and it can exist throughout the execution of the pipeline whereas any temporary persistence has to be though environment variables or files. Well after examining your feedback, it looks like Grapevine has 99% of the concepts that I wanted to invent, even if the | operator seems a bit clunky. I personally prefer the affluent interface convention. But this should work. Kamaelia could also work, but it seems a little bit more grandiose. Thanks everyone who chimed in! From christopher_reimer at icloud.com Tue Nov 21 09:28:24 2017 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Tue, 21 Nov 2017 06:28:24 -0800 Subject: How to Generate dynamic HTML Report using Python In-Reply-To: <0a147350-0ced-45b8-b180-687c9d261e5c@googlegroups.com> References: <5b7a27e9-49ab-8840-2b96-89c5df1a20ae@nedbatchelder.com> <0a147350-0ced-45b8-b180-687c9d261e5c@googlegroups.com> Message-ID: <63FD452A-167E-40B9-866E-08F2043E80BE@icloud.com> On Nov 21, 2017, at 5:36 AM, Rustom Mody wrote: > >> On Tuesday, November 21, 2017 at 5:27:42 PM UTC+5:30, Ned Batchelder wrote: >>> On 11/20/17 9:50 AM, Stefan Ram wrote: >>> Ned Batchelder writes: >>>> Also, why set headers that prevent the Python-List mailing list from >>>> archiving your messages? >>> I am posting to a Usenet newsgroup. I am not aware of any >>> "Python-List mailing list". >>> >>> I am posting specifically to the Usenet, because I am aware >>> of it's rules and I like it and wish to support it. >>> >>> I do not post to a "mailing list" because I do not know which >>> rules apply for mailing lists and whether mailing lists in >>> general or any specific mailing list is an environment that I >>> like or wish to support. >>> >> >> The dual nature of this online community has long been confusing and >> complicated. It's both a newsgroup and a mailing list. Add in Google >> Groups, and you really have three different faces of the same content. >> >> The fact is, posting to comp.lang.python means that your words are also >> being distributed as a mailing list. Because of your messages' headers, >> they are not in the archive of that list >> (https://mail.python.org/pipermail/python-list/2017-November/thread.html), >> or in Google Groups >> (https://groups.google.com/forum/#!topic/comp.lang.python/0ejrtZ6ET9g). >> It makes for odd reading via those channels. >> >> I don't understand the motivation for limiting how words are >> distributed, but others on this list also do it. For example, Dennis Lee >> Bieber's messages are not in the Python-List archives either. If >> something is worth saying, why not let people find it later? > > To which I would add: > Setting headers is hardly a working method. > Somebody quotes Stefan or Dennis and they are on the archives > And some quote including emails some not > etc > -- > https://mail.python.org/mailman/listinfo/python-list A troll tried to prove that I was too retarded to program in Python by claiming that I asked a question on this list in the archives that could have been answered by searching the web. The funny thing is that none of the links that the troll provided answered my question. Chris R. From ethan at stoneleaf.us Tue Nov 21 09:50:53 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 21 Nov 2017 06:50:53 -0800 Subject: Posts by Stefan Ram Message-ID: <5A143D4D.9030807@stoneleaf.us> On 11/20/2017 10:47 AM, Michael Torrie wrote:> On 11/20/2017 07:50 AM, Stefan Ram wrote: >> I am posting to a Usenet newsgroup. I am not aware of any >> "Python-List mailing list". > > As far as I'm concerned, this list is primarily a mailing list, hosted > by Mailman at python.org, and is mirrored to Usenet via a gateway as a > service by python.org. Granted, this is just a matter of perspective. > You also have this header set: >> X-Copyright: (C) Copyright 2017 Stefan Ram. All rights reserved. >> Distribution through any means other than regular usenet >> channels is forbidden. It is forbidden to publish this >> article in the world wide web. It is forbidden to change >> URIs of this article into links. It is forbidden to remove >> this notice or to transfer the body without this notice. > > Looks to me like the mailing list needs to block your messages, lest > python.org be in violation of your copyright. Stefan, please look into the Python mailing list [1], and either remove your copyright or include python.org as an exception (and let us know if you do). Until then, all your messages will be auto-discarded at the Usenet/mailing list boundary. Everyone else, please do not quote Stefan's messages as they may then end up on the mailing list possibly violating his copyright. -- ~Ethan~ [1] https://mail.python.org/mailman/listinfo/python-list From grossd18 at gmail.com Tue Nov 21 10:18:43 2017 From: grossd18 at gmail.com (Daniel Gross) Date: Tue, 21 Nov 2017 17:18:43 +0200 Subject: reading text in pdf, some working sample code Message-ID: Hi, I am new to python and jumped right into trying to read out (english) text from PDF files. I tried various libraries (including slate) out there but am running into diverse problems, such as with encoding or buffer too small errors -- deep inside some decompression code. Essentially, i want to extract all text and then do some natural language processing on the text. Is there some sample code available that works together with a clear description of the expected python installatin environment needed. In slate btw, i got the buffer error, it seems i must "guess" the right encoding of the text included in the PDF when opening the file. Still trying to figure out how to get the encoding info out of the PDF ... (if available there) thank you, Daniel From rantingrickjohnson at gmail.com Tue Nov 21 11:26:22 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 21 Nov 2017 08:26:22 -0800 (PST) Subject: How to Generate dynamic HTML Report using Python In-Reply-To: References: <5b7a27e9-49ab-8840-2b96-89c5df1a20ae@nedbatchelder.com> Message-ID: On Tuesday, November 21, 2017 at 5:57:42 AM UTC-6, Ned Batchelder wrote: [...] > [...] > I don't understand the motivation for limiting how words > are distributed, but others on this list also do it. For > example, Dennis Lee Bieber's messages are not in the > Python-List archives either. I called out Bieber years ago for his X-NO-ARCHIVE business and nobody else seemed to care. In fact, the mood at the time was more negative towards me for calling it out than towards Dennis. Sorry i don't have a link to the thread, but i'm sure a determined person could find it. It was probably somewhere between 2008 and 2010. > If something is worth saying, why not let people find it > later? That has always been my opinion as well. And if i remember correctly, Dennis said something to effect of (paraphrasing) "I don't want my words achived so that someone can leverage my words against me for nefarious reasons" "Nefarious reasons"? Paranoid or lame? You decide. From torriem at gmail.com Tue Nov 21 11:44:21 2017 From: torriem at gmail.com (Michael Torrie) Date: Tue, 21 Nov 2017 09:44:21 -0700 Subject: Posts by Stefan Ram In-Reply-To: <5A143D4D.9030807@stoneleaf.us> References: <5A143D4D.9030807@stoneleaf.us> Message-ID: <3b082335-3242-bf6b-ea1c-138a34fd4bf5@gmail.com> On 11/21/2017 07:50 AM, Ethan Furman wrote: > Everyone else, please do not quote Stefan's messages as they may then > end up on the mailing list possibly violating his copyright. The good news is, at least, that quoting his messages with attribution is certainly fair use in all jurisdictions I'm aware of. From jabronson at gmail.com Tue Nov 21 12:43:54 2017 From: jabronson at gmail.com (Josh B.) Date: Tue, 21 Nov 2017 09:43:54 -0800 (PST) Subject: __hash__ and ordered vs. unordered collections In-Reply-To: References: Message-ID: <0f4ef3f7-19be-4b41-be59-14ef52a63aca@googlegroups.com> On Monday, November 20, 2017 at 3:17:49 PM UTC-5, Chris Angelico wrote: > Neither is perfect. You have to take your pick between them. Right on, thanks for weighing in, Chris. Your responses have been very helpful. I wouldn't feel comfortable claiming the authority to make this call alone. But fortunately I reached out to Raymond Hettinger and am delighted to have his guidance, pasted below. Great to have this predicament resolved. In case of interest, I've implemented Raymond's advice in the latest release of bidict, the bidirectional map library I authored . Feedback always welcome. Thanks, Josh ---------- Forwarded message ---------- From: Raymond Hettinger Date: Mon, Nov 20, 2017 at 4:46 PM Subject: Re: __hash__ and ordered vs. unordered collections To: jab at math.brown.edu If you want to make ordered and unordered collections interoperable, I would just let equality be unordered all the time. You can always provide a separate method for an ordered_comparison. IMO, the design for __eq__ in collections.OrderedDict was a mistake. It violates the Liskov Substitution Principle which would let ordered dicts always be substituted whereever regular dicts were expected. It is simpler to have comparisons be unordered everywhere. But there are no perfect solutions. A user of an ordered collection may rightfully expect an ordered comparison, while a user of both collections may rightfully expect them to be mutually substitutable. Raymond From p.f.moore at gmail.com Tue Nov 21 14:35:29 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 21 Nov 2017 19:35:29 +0000 Subject: reading text in pdf, some working sample code In-Reply-To: References: Message-ID: I haven't tried it, but a quick Google search found PyPDF2 - https://stackoverflow.com/questions/34837707/extracting-text-from-a-pdf-file-using-python You don't give much detail about what you tried and how it failed, so if the above doesn't work for you, I'd suggest providing more detail as to what your problem is. Paul On 21 November 2017 at 15:18, Daniel Gross wrote: > Hi, > > I am new to python and jumped right into trying to read out (english) text > from PDF files. > > I tried various libraries (including slate) out there but am running into > diverse problems, such as with encoding or buffer too small errors -- deep > inside some decompression code. > > Essentially, i want to extract all text and then do some natural language > processing on the text. Is there some sample code available that works > together with a clear description of the expected python installatin > environment needed. > > In slate btw, i got the buffer error, it seems i must "guess" the right > encoding of the text included in the PDF when opening the file. Still > trying to figure out how to get the encoding info out of the PDF ... (if > available there) > > thank you, > > Daniel > -- > https://mail.python.org/mailman/listinfo/python-list From greg.ewing at canterbury.ac.nz Wed Nov 22 00:10:57 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 22 Nov 2017 18:10:57 +1300 Subject: How to Generate dynamic HTML Report using Python In-Reply-To: References: Message-ID: Michael Torrie wrote: > You also have this header set: > >>X-Copyright: (C) Copyright 2017 Stefan Ram. All rights reserved. >>... It is forbidden to change >>URIs of this article into links... What is "changing a URI into a link" meant to mean? Does it include automatically displaying something that looks like a URI as a clickable element, as many news and mail clients do nowadays? If so, a lot of people will be inadvertently violating this copyright condition, including me. It looks like I'm going to have to filter Mr. Ram's posts out of my usenet feed as well, lest I accidentally show one of his URIs as a link on my screen. -- Greg From greg.ewing at canterbury.ac.nz Wed Nov 22 00:47:46 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 22 Nov 2017 18:47:46 +1300 Subject: "help( pi )" In-Reply-To: References: <5A11FC75.2040006@canterbury.ac.nz> <20171120221031.GA88099@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > one could change implementations such that applying a docstring to an > object _removed_ it from the magic-shared-singleton pool, That's not sufficient, though. Consider: BUFFER_SIZE = 256 BUFFER_SIZE.__doc__ = "Size of the buffer" TWO_TO_THE_EIGHT = 256 TWO_TO_THE_EIGHT.__doc__ = "My favourite power of two" Before the code is even run, the compiler may have merged the two occurences of the integer literal 256 into one entry in co_consts. By the time the docstrings are assigned, it's too late to decide that they really needed to be different objects. So, an int with a docstring needs to be explicitly created as a separate object to begin with, one way or another. -- Greg From rosuav at gmail.com Wed Nov 22 01:02:11 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Nov 2017 17:02:11 +1100 Subject: "help( pi )" In-Reply-To: References: <5A11FC75.2040006@canterbury.ac.nz> <20171120221031.GA88099@cskk.homeip.net> Message-ID: On Wed, Nov 22, 2017 at 4:47 PM, Gregory Ewing wrote: > Cameron Simpson wrote: >> >> one could change implementations such that applying a docstring to an >> object _removed_ it from the magic-shared-singleton pool, > > > That's not sufficient, though. Consider: > > BUFFER_SIZE = 256 > BUFFER_SIZE.__doc__ = "Size of the buffer" > > TWO_TO_THE_EIGHT = 256 > TWO_TO_THE_EIGHT.__doc__ = "My favourite power of two" > > Before the code is even run, the compiler may have merged the > two occurences of the integer literal 256 into one entry in > co_consts. By the time the docstrings are assigned, it's too > late to decide that they really needed to be different objects. > > So, an int with a docstring needs to be explicitly created as > a separate object to begin with, one way or another. class Int(int): def __new__(cls, *a, **kw): __doc__ = kw.pop("doc", None) self = super().__new__(cls, *a, **kw) self.__doc__ = __doc__ return self BUFFER_SIZE = Int(256, doc="Size of the buffer") ChrisA From rosuav at gmail.com Wed Nov 22 01:10:12 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Nov 2017 17:10:12 +1100 Subject: How to Generate dynamic HTML Report using Python In-Reply-To: References: Message-ID: On Wed, Nov 22, 2017 at 4:10 PM, Gregory Ewing wrote: > Michael Torrie wrote: >> >> You also have this header set: >> >>> X-Copyright: (C) Copyright 2017 Stefan Ram. All rights reserved. >>> ... It is forbidden to change >>> URIs of this article into links... > > > What is "changing a URI into a link" meant to mean? Does it > include automatically displaying something that looks like > a URI as a clickable element, as many news and mail clients > do nowadays? If so, a lot of people will be inadvertently > violating this copyright condition, including me. > > It looks like I'm going to have to filter Mr. Ram's posts > out of my usenet feed as well, lest I accidentally show one > of his URIs as a link on my screen. > Or, just ignore his copyright altogether, and let him prove its defensibility in court. Can you actually enforce that EVERY usenet server carry out your wishes? What if one of them strips off the (non-standard) X-Copyright header and carries the message further? I would hope that a server admin is not liable in court years down the track for setting something up and leaving it to its own devices. Anyone can write anything. Good luck actually making it mean anything. Of course, getting all your posts plonked is the safest way to comply with copyright, so I think that's what's going to happen... ChrisA From dieter at handshake.de Wed Nov 22 02:37:20 2017 From: dieter at handshake.de (dieter) Date: Wed, 22 Nov 2017 08:37:20 +0100 Subject: reading text in pdf, some working sample code References: Message-ID: <87a7zercgf.fsf@handshake.de> Daniel Gross writes: > I am new to python and jumped right into trying to read out (english) text > from PDF files. > > I tried various libraries (including slate) You could give "pdfminer" a try. Note, however, that it may not be possible to extract the text: PDF is a generic format which works by mapping character codes to glyphs (i.e. visual symbols); if your PDF uses a special map for this (especially with non standard glyph collections (aka "font"s)), then the text extraction (which in fact extracts sequences of character codes) can give unusable results. From cs at cskk.id.au Wed Nov 22 03:20:39 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 22 Nov 2017 19:20:39 +1100 Subject: "help( pi )" In-Reply-To: References: Message-ID: <20171122082039.GA54008@cskk.homeip.net> On 22Nov2017 18:47, Greg Ewing wrote: >Cameron Simpson wrote: >>one could change implementations such that applying a docstring to >>an object _removed_ it from the magic-shared-singleton pool, > >That's not sufficient, though. Consider: > > BUFFER_SIZE = 256 > BUFFER_SIZE.__doc__ = "Size of the buffer" > > TWO_TO_THE_EIGHT = 256 > TWO_TO_THE_EIGHT.__doc__ = "My favourite power of two" > >Before the code is even run, the compiler may have merged the >two occurences of the integer literal 256 into one entry in >co_consts. By the time the docstrings are assigned, it's too >late to decide that they really needed to be different objects. > >So, an int with a docstring needs to be explicitly created as >a separate object to begin with, one way or another. Ah. Even without that it felt a little racy to me anyway. Cheers, Cameron Simpson From abiodun.ogunmolu at gmail.com Wed Nov 22 04:44:52 2017 From: abiodun.ogunmolu at gmail.com (abiodun.ogunmolu at gmail.com) Date: Wed, 22 Nov 2017 01:44:52 -0800 (PST) Subject: How to add months to a date (datetime object)? In-Reply-To: <49bd3ab8$0$510$bed64819@news.gradwell.net> References: <49bd3ab8$0$510$bed64819@news.gradwell.net> Message-ID: How about this... from dateutil.relativedelta import relativedelta myDate = datetime.date.today() + relativedelta(months=3) On Sunday, March 15, 2009 at 5:28:24 PM UTC, tin... at isbd.co.uk wrote: > I have a date in the form of a datetime object and I want to add (for > example) three months to it. At the moment I can't see any very > obvious way of doing this. I need something like:- > > myDate = datetime.date.today() > inc = datetime.timedelta(months=3) > myDate += inc > > but, of course, timedelta doesn't know about months. I had a look at > the calendar object but that didn't seem to help much. > > -- > Chris Green From anthra.norell at bluewin.ch Wed Nov 22 04:54:15 2017 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Wed, 22 Nov 2017 10:54:15 +0100 Subject: General Purpose Pipeline library? In-Reply-To: <7e267598-7f21-42da-9b42-dcfd12b7ad2b@googlegroups.com> References: <7e267598-7f21-42da-9b42-dcfd12b7ad2b@googlegroups.com> Message-ID: On 11/21/2017 03:26 PM, Jason wrote: > On Monday, November 20, 2017 at 10:49:01 AM UTC-5, Jason wrote: >> a pipeline can be described as a sequence of functions that are applied to an input with each subsequent function getting the output of the preceding function: >> >> out = f6(f5(f4(f3(f2(f1(in)))))) >> >> However this isn't very readable and does not support conditionals. >> >> Tensorflow has tensor-focused pipepines: >> fc1 = layers.fully_connected(x, 256, activation_fn=tf.nn.relu, scope='fc1') >> fc2 = layers.fully_connected(fc1, 256, activation_fn=tf.nn.relu, scope='fc2') >> out = layers.fully_connected(fc2, 10, activation_fn=None, scope='out') >> >> I have some code which allows me to mimic this, but with an implied parameter. >> >> def executePipeline(steps, collection_funcs = [map, filter, reduce]): >> results = None >> for step in steps: >> func = step[0] >> params = step[1] >> if func in collection_funcs: >> print func, params[0] >> results = func(functools.partial(params[0], *params[1:]), results) >> else: >> print func >> if results is None: >> results = func(*params) >> else: >> results = func(*(params+(results,))) >> return results >> >> executePipeline( [ >> (read_rows, (in_file,)), >> (map, (lower_row, field)), >> (stash_rows, ('stashed_file', )), >> (map, (lemmatize_row, field)), >> (vectorize_rows, (field, min_count,)), >> (evaluate_rows, (weights, None)), >> (recombine_rows, ('stashed_file', )), >> (write_rows, (out_file,)) >> ] >> ) >> >> Which gets me close, but I can't control where rows gets passed in. In the above code, it is always the last parameter. >> >> I feel like I'm reinventing a wheel here. I was wondering if there's already something that exists? > Why do I want this? Because I'm tired of writing code that is locked away in a bespoke function. I'd have an army of functions all slightly different in functionality. I require flexibility in defining pipelines, and I don't want a custom pipeline to require any low-level coding. I just want to feed a sequence of functions to a script and have it process it. A middle ground between the shell | operator and bespoke python code. Sure, I could write many binaries bound by shell, but there are some things done far easier in python because of its extensive libraries and it can exist throughout the execution of the pipeline whereas any temporary persistence has to be though environment variables or files. > > Well after examining your feedback, it looks like Grapevine has 99% of the concepts that I wanted to invent, even if the | operator seems a bit clunky. I personally prefer the affluent interface convention. But this should work. > > Kamaelia could also work, but it seems a little bit more grandiose. > > > Thanks everyone who chimed in! This looks very much like I what I have been working on of late: a generic processing paradigm based on chainable building blocks. I call them Workshops, because the base class can be thought of as a workshop that takes some raw material, processes it and delivers the product (to the next in line). Your example might look something like this: ??? >>> import workshops as WS ??? >>> Vectorizer = WS.Chain ( ??? ??? ??? WS.File_Reader (),??? ??? # WS provides ??? ??? ??? WS.Map (lower_row), ????? # WS provides (wrapped builtin) ??? ??? ??? Row_Stasher (),??? ?? ??? # You provide ??? ??? ??? WS.Map (lemmatize_row),?? # WS provides. Name for addressed Directions sending. ???? ??? ?? Row_Vectorizer (),??? ??? # Yours ???? ??? ?? Row_Evaluator (),??? ???? # Yours ??? ??? ??? Row_Recombiner (), ??? ????? ? WS.File_Writer (), ??? ??? ??? _name = 'Vectorizer' ??? ??? ) ??? Parameters are process-control settings that travel through a subscription-based mailing system separate from the payload pipe. ??? >>> Vectorizer.post (min_count = ...,? ) # Set all parameters that control the entire run. ??? >>> Vectorizer.post ("File_Writer", file_name = 'output_file_name')??? # Addressed, not meant for File_Reader ??? Run ? ? >>> Vectorizer ('input_file_name')??? # File Writer returns 0 if the Chain completes successfully. ? ? 0 ??? If you would provide a list of your functions (input, output, parameters) I'd be happy to show a functioning solution. Writing a Shop follows a simple standard pattern: Naming the subscriptions, if any, and writing a single method that reads the subscribed parameters, if any, then takes payload, processes it and returns the product. ??? I intend to share the system, provided there's an interest. I'd have to tidy it up quite a bit, though, before daring to release it. ??? There's a lot more to it . . . Frederic From anthra.norell at bluewin.ch Wed Nov 22 05:38:41 2017 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Wed, 22 Nov 2017 11:38:41 +0100 Subject: General Purpose Pipeline library? In-Reply-To: <7e267598-7f21-42da-9b42-dcfd12b7ad2b@googlegroups.com> References: <7e267598-7f21-42da-9b42-dcfd12b7ad2b@googlegroups.com> Message-ID: <0af769af-5dad-cdbe-8b64-041235e01102@bluewin.ch> On 11/21/2017 03:26 PM, Jason wrote: > On Monday, November 20, 2017 at 10:49:01 AM UTC-5, Jason wrote: >> a pipeline can be described as a sequence of functions that are applied to an input with each subsequent function getting the output of the preceding function: >> >> out = f6(f5(f4(f3(f2(f1(in)))))) >> >> However this isn't very readable and does not support conditionals. >> >> Tensorflow has tensor-focused pipepines: >> fc1 = layers.fully_connected(x, 256, activation_fn=tf.nn.relu, scope='fc1') >> fc2 = layers.fully_connected(fc1, 256, activation_fn=tf.nn.relu, scope='fc2') >> out = layers.fully_connected(fc2, 10, activation_fn=None, scope='out') >> >> I have some code which allows me to mimic this, but with an implied parameter. >> >> def executePipeline(steps, collection_funcs = [map, filter, reduce]): >> results = None >> for step in steps: >> func = step[0] >> params = step[1] >> if func in collection_funcs: >> print func, params[0] >> results = func(functools.partial(params[0], *params[1:]), results) >> else: >> print func >> if results is None: >> results = func(*params) >> else: >> results = func(*(params+(results,))) >> return results >> >> executePipeline( [ >> (read_rows, (in_file,)), >> (map, (lower_row, field)), >> (stash_rows, ('stashed_file', )), >> (map, (lemmatize_row, field)), >> (vectorize_rows, (field, min_count,)), >> (evaluate_rows, (weights, None)), >> (recombine_rows, ('stashed_file', )), >> (write_rows, (out_file,)) >> ] >> ) >> >> Which gets me close, but I can't control where rows gets passed in. In the above code, it is always the last parameter. >> >> I feel like I'm reinventing a wheel here. I was wondering if there's already something that exists? > Why do I want this? Because I'm tired of writing code that is locked away in a bespoke function. I'd have an army of functions all slightly different in functionality. I require flexibility in defining pipelines, and I don't want a custom pipeline to require any low-level coding. I just want to feed a sequence of functions to a script and have it process it. A middle ground between the shell | operator and bespoke python code. Sure, I could write many binaries bound by shell, but there are some things done far easier in python because of its extensive libraries and it can exist throughout the execution of the pipeline whereas any temporary persistence has to be though environment variables or files. > > Well after examining your feedback, it looks like Grapevine has 99% of the concepts that I wanted to invent, even if the | operator seems a bit clunky. I personally prefer the affluent interface convention. But this should work. > > Kamaelia could also work, but it seems a little bit more grandiose. > > > Thanks everyone who chimed in! From anthra.norell at bluewin.ch Wed Nov 22 05:42:20 2017 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Wed, 22 Nov 2017 11:42:20 +0100 Subject: General Purpose Pipeline library? In-Reply-To: References: <7e267598-7f21-42da-9b42-dcfd12b7ad2b@googlegroups.com> Message-ID: On 11/22/2017 10:54 AM, Friedrich Rentsch wrote: > > > On 11/21/2017 03:26 PM, Jason wrote: >> On Monday, November 20, 2017 at 10:49:01 AM UTC-5, Jason wrote: >>> a pipeline can be described as a sequence of functions that are >>> applied to an input with each subsequent function getting the output >>> of the preceding function: >>> >>> out = f6(f5(f4(f3(f2(f1(in)))))) >>> >>> However this isn't very readable and does not support conditionals. >>> >>> Tensorflow has tensor-focused pipepines: >>> ???? fc1 = layers.fully_connected(x, 256, activation_fn=tf.nn.relu, >>> scope='fc1') >>> ???? fc2 = layers.fully_connected(fc1, 256, >>> activation_fn=tf.nn.relu, scope='fc2') >>> ???? out = layers.fully_connected(fc2, 10, activation_fn=None, >>> scope='out') >>> >>> I have some code which allows me to mimic this, but with an implied >>> parameter. >>> >>> def executePipeline(steps, collection_funcs = [map, filter, reduce]): >>> ????results = None >>> ????for step in steps: >>> ??????? func = step[0] >>> ??????? params = step[1] >>> ??????? if func in collection_funcs: >>> ??????????? print func, params[0] >>> ??????????? results = func(functools.partial(params[0], >>> *params[1:]), results) >>> ??????? else: >>> ??????????? print func >>> ??????????? if results is None: >>> ??????????????? results = func(*params) >>> ??????????? else: >>> ??????????????? results = func(*(params+(results,))) >>> ????return results >>> >>> executePipeline( [ >>> ??????????????? (read_rows, (in_file,)), >>> ??????????????? (map, (lower_row, field)), >>> ??????????????? (stash_rows, ('stashed_file', )), >>> ??????????????? (map, (lemmatize_row, field)), >>> ??????????????? (vectorize_rows, (field, min_count,)), >>> ??????????????? (evaluate_rows, (weights, None)), >>> ??????????????? (recombine_rows, ('stashed_file', )), >>> ??????????????? (write_rows, (out_file,)) >>> ??????????? ] >>> ) >>> >>> Which gets me close, but I can't control where rows gets passed in. >>> In the above code, it is always the last parameter. >>> >>> I feel like I'm reinventing a wheel here.? I was wondering if >>> there's already something that exists? >> Why do I want this? Because I'm tired of writing code that is locked >> away in a bespoke function. I'd? have an army of functions all >> slightly different in functionality. I require flexibility in >> defining pipelines, and I don't want a custom pipeline to require any >> low-level coding. I just want to feed a sequence of functions to a >> script and have it process it. A middle ground between the shell | >> operator and bespoke python code. Sure, I could write many binaries >> bound by shell, but there are some things done far easier in python >> because of its extensive libraries and it can exist throughout the >> execution of the pipeline whereas any temporary persistence? has to >> be though environment variables or files. >> >> Well after examining your feedback, it looks like Grapevine has 99% >> of the concepts that I wanted to invent, even if the | operator seems >> a bit clunky. I personally prefer the affluent interface convention. >> But this should work. >> >> Kamaelia could also work, but it seems a little bit more grandiose. >> >> >> Thanks everyone who chimed in! > > This looks very much like I what I have been working on of late: a > generic processing paradigm based on chainable building blocks. I call > them Workshops, because the base class can be thought of as a workshop > that takes some raw material, processes it and delivers the product > (to the next in line). Your example might look something like this: > > ??? >>> import workshops as WS > > ??? >>> Vectorizer = WS.Chain ( > ??? ??? ??? WS.File_Reader (),??? ??? # WS provides > ??? ??? ??? WS.Map (lower_row), ????? # WS provides (wrapped builtin) > ??? ??? ??? Row_Stasher (),??? ?? ??? # You provide > ??? ??? ??? WS.Map (lemmatize_row),?? # WS provides > ???? ??? ?? Row_Vectorizer (),??? ??? # Yours > ???? ??? ?? Row_Evaluator (),??? ???? # Yours > ??? ??? ??? Row_Recombiner (), > ??? ????? ? WS.File_Writer (), > ??? ??? ??? _name = 'Vectorizer' > ??? ??? ) > > ??? Parameters are process-control settings that travel through a > subscription-based mailing system separate from the payload pipe. > > ??? >>> Vectorizer.post (min_count = ...,? ) # Set all parameters that > control the entire run. > ??? >>> Vectorizer.post ("File_Writer", file_name = > 'output_file_name')??? # Addressed, not meant for File_Reader > > ??? Run > > ? ? >>> Vectorizer ('input_file_name')??? # File Writer returns 0 if > the Chain completes successfully. > ? ? 0 > > ??? If you would provide a list of your functions (input, output, > parameters) I'd be happy to show a functioning solution. Writing a > Shop follows a simple standard pattern: Naming the subscriptions, if > any, and writing a single method that reads the subscribed parameters, > if any, then takes payload, processes it and returns the product. > > ??? I intend to share the system, provided there's an interest. I'd > have to tidy it up quite a bit, though, before daring to release it. > > ??? There's a lot more to it . . . > > Frederic > I'm sorry, I made a mistake with the "From" item. My address is obviously not "python-list". It is "anthra.norell at bluewin.ch". Frederic From rantingrickjohnson at gmail.com Wed Nov 22 08:22:16 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 22 Nov 2017 05:22:16 -0800 (PST) Subject: Student can't get if elif final statement to print for discussion post for python In-Reply-To: References: <9703860f-ca4a-b9b9-d49b-bc02b86946b0@Damon-Family.org> Message-ID: <082169bc-f09c-4c0d-a627-01198fb88402@googlegroups.com> Richard Damon wrote: > Cheri Castro wrote: > > I've tried several variations but haven't been able to > > figure out why my final if elif statement won't print. I > > tried using return, I tried using 1's and 0's rather than > > yes and no. Not sure what the issue is. Please, help. > > > > > > #This function will print how many yes answers the user has and a message > > def correctAnswers(job, house, yard, time): > > if correctAnswers == 'yes': > > print ("Congratulations! You should get a puppy!") > > else: > > return "I'm sorry, you shouldn't get a puppy." > > Why does one path print and the other return, those are > different actions. A valid point. My guess is that the OP may have wanted to explicitly exit the look on this branch (instead of allowing it fall off the end of the function) perhaps because some of the code is missing from example or perhaps because some code may be added in the future as an extension of the if clause. Setting up such a conditional structure such as this allows the intent to be clear. And any incidental code that supports the if clause can be handles after flow falls off the end of the conditional, and returns to the function body. But who knows... However, i'm more concerned that this code unapologetically discriminate against those who'd rather have a kitten! :-( I want a *KITTEN*! And a safe space! From jon+usenet at unequivocal.eu Wed Nov 22 10:02:43 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Wed, 22 Nov 2017 15:02:43 -0000 (UTC) Subject: Finding the module object in Python 3 C extensions Message-ID: In Python 2, a C extension module's global state was stored in global variables. This obviously means the state is trivially accessible to all code in the module. In Python 3, you are supposed to store the global state in an allocated memory area instead. For functions defined directly under the module, it is still trivial to find the state, because a pointer to the module object is passed as the first parameter to the function, so you just call PyModule_GetState(self). However, suppose your module defines a new type, and you define methods on that type. How do those methods get access to the module object so that they can access the module state? Unfortunately neither PEP3121 nor the "Porting Extension Modules to Python 3" documentation seem to have thought to mention this presumably extremely common situation. From kpavan30 at gmail.com Wed Nov 22 11:53:17 2017 From: kpavan30 at gmail.com (pavan kopparthi) Date: Wed, 22 Nov 2017 22:23:17 +0530 Subject: Fwd: pip3 file in Scripts folder is missing In-Reply-To: References: Message-ID: Hi, Installed Python 3.6.3 Amd64 in Windows 10 OS. But pip3 file in Scripts folder is missing. Scripts folder is empty. -- Reg, Pavan Kumar K Mob: +91 8801401789 <088014%2001789> Virus-free. www.avg.com <#m_-7513067775123038273_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> -- Reg, Pavan Kumar K Mob: +91 8801401789 From rantingrickjohnson at gmail.com Wed Nov 22 13:21:57 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 22 Nov 2017 10:21:57 -0800 (PST) Subject: How to Generate dynamic HTML Report using Python In-Reply-To: References: Message-ID: <37deb323-d7a3-4be4-b3f2-8c6143a7ffdd@googlegroups.com> Chris Angelico wrote: > Gregory Ewing > > > > It looks like I'm going to have to filter Mr. Ram's posts > > out of my usenet feed as well, lest I accidentally show > > one of his URIs as a link on my screen. > > Or, just ignore his copyright altogether, and let him prove > its defensibility in court. Can you actually enforce that > EVERY usenet server carry out your wishes? Although it's quite possible that what Stefan is doing here _might_ be in accordance with the _letter_ of copyright law -- OTOH -- this "forced distribution" that Stefan is engageing in, would seem to violate the _spirit_ of copyright law. For instance, if we consider that copyright law was created to protect intellectual property (IP), and furthermore, we consider that copyrighted material is typically made _available_ to the public[1] by IP owners, but not _forced_ on the public by IP owners, then we realize that what Stefan is doing is the latter case. So, by intentionally injecting this "licensed IP" into public discourse, Stefan is indeed violating the spirit of copyright law, and in fact, is using copyright law in a very irresponsible, and arguably very rude, manner. It would seem logical to me that Stefan's behavior should be judged as unethical[2] and would therefore undermine the contract between IP owners and the "doe-eyed consumers" of that IP, rendering it null and void. But history has proven that law is neither just nor logical. So whether a court would agree with my interpretation is yet to be determined. Of course, as is the case with tax advisers, every court seems to have it's own unique interpretation of the law. Which would lead me to the troubling conclusion that our Western legal systems are poorly designed, corrupt, or both. [1] IOW, the public consumes this IP or uses this IP _fully_ _knowing_ beforehand that they are bound by a license agreement. Which is not the cause here! Plus there are the issues that Chris brings up concerning automated dissemination. [2] As forcing people to consume your product simply so you can weild IP rights over them is a violation of individual liberty recognized by every western democracy i know of, or at least every definition of individual liberty that i am aware of. From elef at indiana.edu Wed Nov 22 19:38:11 2017 From: elef at indiana.edu (Eleftherios Garyfallidis) Date: Thu, 23 Nov 2017 00:38:11 +0000 Subject: ANN: DIPY 0.13.0 Message-ID: Hello all, We are happy to announce a new public release of DIPY. This is mostly a maintenance release with extra fixes, speedups and minor changes of dependencies. *DIPY 0.13 (Tuesday, 24 October 2017)* This release received contributions from 13 developers (the full release notes are at: http://nipy.org/dipy/release0.13.html) *Highlights of this release include:* - Faster Local PCA implementation. - Fixed different issues with OpenMP and Windows / OSX. - Replacement of cvxopt module by cvxpy. - Replacement of Pytables module by h5py. - Updated API to support latest numpy version (1.14). - New user interfaces for visualization. - Large documentation update. To upgrade, run the following command in your terminal: *pip install --upgrade dipy* or *conda install -c conda-forge dipy* For any questions go to http://dipy.org, or send an e-mail to neuroimaging at python.org We also have an instant messaging service and chat room available at https://gitter.im/nipy/dipy Expect mad features in release 0.14 (Jan 2018)!!! On behalf of the DIPY developers, Eleftherios Garyfallidis, Ariel Rokem, Serge Koudoro http://dipy.org/developers.html From jon+usenet at unequivocal.eu Wed Nov 22 19:39:48 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Thu, 23 Nov 2017 00:39:48 -0000 (UTC) Subject: reading text in pdf, some working sample code References: Message-ID: On 2017-11-21, Daniel Gross wrote: > I am new to python and jumped right into trying to read out (english) text > from PDF files. That's not a trivial task. However I just released pycpdf, which might help you out. Check out https://github.com/jribbens/pycpdf which shows an example of extracting text from PDFs. It may or may not cope with the particular PDFs you have, as there's quite a lot of variety within the format. Example: pdf = pycpdf.PDF(open("file.pdf", "rb").read()) if pdf.info and pdf.info.get('Title'): print('Title:', pdf.info['Title']) for pageno, page in enumerate(pdf.pages): print('Page', pageno + 1) print(page.text) From garyfallidis at gmail.com Wed Nov 22 19:45:19 2017 From: garyfallidis at gmail.com (Eleftherios Garyfallidis) Date: Thu, 23 Nov 2017 00:45:19 +0000 Subject: ANN: DIPY 0.13.0 Message-ID: Hello all, We are happy to announce a new public release of DIPY. This is mostly a maintenance release with extra fixes, speedups and minor changes of dependencies. *DIPY 0.13 (Tuesday, 24 October 2017)* This release received contributions from 13 developers (the full release notes are at: http://nipy.org/dipy/release0.13.html) *Highlights of this release include:* - Faster Local PCA implementation. - Fixed different issues with OpenMP and Windows / OSX. - Replacement of cvxopt module by cvxpy. - Replacement of Pytables module by h5py. - Updated API to support latest numpy version (1.14). - New user interfaces for visualization. - Large documentation update. To upgrade, run the following command in your terminal: *pip install --upgrade dipy* or *conda install -c conda-forge dipy* For any questions go to http://dipy.org, or send an e-mail to neuroimaging at python.org We also have an instant messaging service and chat room available at https://gitter.im/nipy/dipy Expect mad features in release 0.14 (Jan 2018)!!! On behalf of the DIPY developers, Eleftherios Garyfallidis, Ariel Rokem, Serge Koudoro http://dipy.org/developers.html From bob at mellowood.ca Wed Nov 22 21:07:54 2017 From: bob at mellowood.ca (Bob van der Poel) Date: Wed, 22 Nov 2017 19:07:54 -0700 Subject: reading text in pdf, some working sample code In-Reply-To: References: Message-ID: On Wed, Nov 22, 2017 at 5:39 PM, Jon Ribbens wrote: > On 2017-11-21, Daniel Gross wrote: > > I am new to python and jumped right into trying to read out (english) > text > > from PDF files. > > That's not a trivial task. However I just released pycpdf, which might > help you out. Check out https://github.com/jribbens/pycpdf which shows > an example of extracting text from PDFs. It may or may not cope with > the particular PDFs you have, as there's quite a lot of variety within > the format. > > Example: > > pdf = pycpdf.PDF(open("file.pdf", "rb").read()) > if pdf.info and pdf.info.get('Title'): > print('Title:', pdf.info['Title']) > for pageno, page in enumerate(pdf.pages): > print('Page', pageno + 1) > print(page.text) > -- > https://mail.python.org/mailman/listinfo/python-list > Sorry if I'm late to this party, but I use pdf2txt for this. Works just fine. It has options for different encodings, page range, etc. On Linux just "apt install python-pdfminer" to install. -- **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW: http://www.mellowood.ca From frank at chagford.com Thu Nov 23 02:58:58 2017 From: frank at chagford.com (Frank Millman) Date: Thu, 23 Nov 2017 09:58:58 +0200 Subject: Why does asyncio.wait_for() need a timeout? Message-ID: Hi all Below is a simple asyncio loop that runs two background tasks. They both perform a simple count. The first one counts forever, wrapped in a try/except. The second one counts up to 5, then cancels the first one and stops the loop. There are two ways of ensuring that then cancellation is complete - asyncio.wait([a sequence of futures]) asyncio.wait_for(a single future) Both take an optional timeout. If I use the first method without a timeout, the cancellation completes and the loop stops. If I use the second method without a timeout, the future is cancelled, but the program hangs. If I add a timeout to the second one, it behaves the same as the first one. Is there a reason for this? I am using version 3.6.0. Thanks Frank Millman import asyncio from itertools import count async def counter1(): cnt = count(1) try: while True: print('From 1:', next(cnt)) await asyncio.sleep(1) except asyncio.CancelledError: print('counter1 cancelled') async def counter2(): cnt = count(1) for i in range(5): print('From 2:', next(cnt)) await asyncio.sleep(1) cnt1.cancel() # await asyncio.wait([cnt1]) # works # await asyncio.wait_for(cnt1) # hangs await asyncio.wait_for(cnt1, 1) # works loop.stop() loop = asyncio.get_event_loop() cnt1 = asyncio.ensure_future(counter1()) cnt2 = asyncio.ensure_future(counter2()) loop.run_forever() From info at egenix.com Thu Nov 23 05:31:46 2017 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Thu, 23 Nov 2017 11:31:46 +0100 Subject: ANN: PyDDF Python Herbst Sprint 2017 Message-ID: [This announcement is in German since it targets a Python sprint in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG PyDDF Python Herbst Sprint 2017 in D?sseldorf Samstag, 25.11.2017, 10:00-18:00 Uhr Sonntag, 26.11.2017, 10:00-18:00 Uhr trivago GmbH, Karl-Arnold-Platz 1A, 40474 D?sseldorf Python Meeting D?sseldorf https://www.pyddf.de/sprint2017-11/ ________________________________________________________________________ INFORMATION Das Python Meeting D?sseldorf (PyDDF) veranstaltet mit freundlicher Unterst?tzung der *trivago GmbH* ein Python Sprint Wochenende im September. Der Sprint findet am Wochenende 25./26.11.2017 in der trivago Niederlassung am Karl-Arnold-Platz 1A statt (nicht am Bennigsen-Platz 1). Folgende Themengebiete haben wir als Anregung angedacht: * Willkommens-Chatbot f?r D?sseldorf mir RasaHQ * PyEditor oder django-reversion-compare * Django Autotask oder FirtzConnection * YouTube Video Manager CLI * Kivy * Formula Pi (Roboter Rennen) * Jython Nat?rlich kann jeder Teilnehmer weitere Themen vorschlagen. Alles weitere und die Anmeldung findet Ihr auf der Sprint Seite: https://www.pyddf.de/sprint2017-11/ Teilnehmer sollten sich zudem auf der PyDDF Liste anmelden, da wir uns dort koordinieren: https://www.egenix.com/mailman/listinfo/pyddf ________________________________________________________________________ ?BER UNS Das Python Meeting D?sseldorf (PyDDF) ist eine regelm??ige Veranstaltung in D?sseldorf, die sich an Python Begeisterte aus der Region wendet: * https://pyddf.de/ Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: * http://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Nov 23 2017) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> Python Database Interfaces ... http://products.egenix.com/ >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/ From jon+usenet at unequivocal.eu Thu Nov 23 06:15:37 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Thu, 23 Nov 2017 11:15:37 -0000 (UTC) Subject: Finding the module object in Python 3 C extensions (Posting On Python-List Prohibited) References: <6bc0c798-6568-40f7-901b-d6d463ce2da0@googlegroups.com> Message-ID: On 2017-11-23, Lawrence D?Oliveiro wrote: > On Thursday, November 23, 2017 at 4:03:18 AM UTC+13, Jon Ribbens wrote: >> In Python 3, you are supposed to store the global state in an >> allocated memory area instead. > > Says who? Considering that this > > example uses a global variable. Says Benjamin Peterson on docs.python.org: https://docs.python.org/3/howto/cporting.html "Python 3 has a revamped extension module initialization system. (See PEP 3121.) Instead of storing module state in globals, they should be stored in an interpreter specific structure. Creating modules that act correctly in both Python 2 and Python 3 is tricky." He's not kidding, not least because it appears that creating modules that act correctly in Python 3 at all is tricky! From zljubisic at gmail.com Thu Nov 23 09:27:03 2017 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Thu, 23 Nov 2017 06:27:03 -0800 (PST) Subject: Python loop and web server (bottle) in the same script Message-ID: I would like to have a script that collects data every minute and at the same time serve newly collected data as web pages. Timely collecting data is more important than serving web pages, so collecting data should have priority and should never be interrupted by serving web pages. My first idea was to use (while) loop and a bottle web server, so I wrote a program in which for loop simulates collecting data and bottle simulates web server that server newly collected data as web pages: from bottle import route, run, request, template, static_file import time x = 0 @route('/test') def test(): return 'x = {}'.format(x) run(host='localhost', port=8080, debug=True) for x in range(100): time.sleep(1) I hoped that run() command will be executed and script will continue bellow this line, but that is not the case, run() is the last command that is executed, and /test always shows x = 0 as output. If I put for loop before run(), than run() will be executed after for loop is completed. Looks like I need some sort of parallelization. So my goals are: collecting data (loop) has higher priority web server should serve newly collected data What would be the logic for achieving my goals? One solution is two scripts, one for web server and another one for collecting data. I am looking for an option for integration of both functionalities in one script. Regards. From mikhailwas at gmail.com Thu Nov 23 09:39:03 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Thu, 23 Nov 2017 15:39:03 +0100 Subject: Allow additional separator character in variables Message-ID: Chris A wrote: On Fri, Nov 24, 2017 at 1:10 AM, Mikhail V wrote: > > > Well, then there is some bitter irony in this, so it allows pretty > > much everything, > > but does not allow me to beautify code with hyphens. > > I can fully understand the wish to use non-latin scripts in strings or comments. > > As for identifiers, IMO, apart from latin letters and underscore, the > > first unicode candidate > > I would add is U+2010. And probably the LAST one I would add. > > > > Fortunately for the world, you're not the one who decided which > characters were permitted in Python identifiers. The ability to use > non-English words for function/variable names is of huge value; the > ability to use a hyphen is of some value, but not nearly as much. > Fortunately for the world we have Chris A. Who knows what is fortunate and of huge values. So is there any real world projects example of usage of non-latin scripts in identifiers? Or is it still only a plan for the new world? Mikhail From rosuav at gmail.com Thu Nov 23 09:40:33 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Nov 2017 01:40:33 +1100 Subject: Python loop and web server (bottle) in the same script In-Reply-To: References: Message-ID: On Fri, Nov 24, 2017 at 1:27 AM, wrote: > I would like to have a script that collects data every minute and at the same time serve newly collected data as web pages. > > Timely collecting data is more important than serving web pages, so collecting data should have priority and should never be interrupted by serving web pages. > > Looks like I need some sort of parallelization. Sounds like you want threads. Spin off a thread that collects data and sleeps, collects data and sleeps; meanwhile, serve web pages. But there's no way you can *guarantee* that the serving of pages won't interrupt data collection. With separate processes, you could potentially use OS-level prioritization to help your data collection process, but even then, it's not a guarantee. What are the consequences of mistimed data collection? ChrisA From rosuav at gmail.com Thu Nov 23 09:42:24 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Nov 2017 01:42:24 +1100 Subject: Allow additional separator character in variables In-Reply-To: References: Message-ID: On Fri, Nov 24, 2017 at 1:39 AM, Mikhail V wrote: > Chris A wrote: > > On Fri, Nov 24, 2017 at 1:10 AM, Mikhail V wrote: >> >> > Well, then there is some bitter irony in this, so it allows pretty >> > much everything, >> > but does not allow me to beautify code with hyphens. >> > I can fully understand the wish to use non-latin scripts in strings or comments. >> > As for identifiers, IMO, apart from latin letters and underscore, the >> > first unicode candidate >> > I would add is U+2010. And probably the LAST one I would add. >> > >> >> Fortunately for the world, you're not the one who decided which >> characters were permitted in Python identifiers. The ability to use >> non-English words for function/variable names is of huge value; the >> ability to use a hyphen is of some value, but not nearly as much. >> > > > Fortunately for the world we have Chris A. Who knows what is > fortunate and of huge values. > So is there any real world projects example of usage of non-latin scripts > in identifiers? Or is it still only a plan for the new world? Yes, I've used them personally. And I know other people who have. ChrisA From mikhailwas at gmail.com Thu Nov 23 13:42:11 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Thu, 23 Nov 2017 19:42:11 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) Message-ID: Chris A wrote: >> On Fri, Nov 24, 2017 at 1:10 AM, Mikhail V wrote: >> >>> Chris A wrote: >>> >>> Fortunately for the world, you're not the one who decided which >>> characters were permitted in Python identifiers. The ability to use >>> non-English words for function/variable names is of huge value; the >>> ability to use a hyphen is of some value, but not nearly as much. >> >> Fortunately for the world we have Chris A. Who knows what is >> fortunate and of huge values. >> So is there any real world projects example of usage of non-latin scripts >> in identifiers? Or is it still only a plan for the new world? > Yes, I've used them personally. And I know other people who have. Oh, I though it would be more impressive showcase for 'huge value'. If we drop the benefit of the bare fact that you can do it, or you just don't know English, how would describe the practical benefit? If you don't know english, then programming at all will be just too hard. (or one must define a new whole language specially for some local script) I mean for a real practical situation - for example for an average Python programmer or someone who seeks a programmer job. And who does not have a 500-key keyboard, and who has a not enough high threshold of vision sensitivity to bear the look of various scripts in one small text piece? Ok, I personally could find some practical usage for that, but merely for fun. I doubt though that someone with less typographical experience and overall computer literacy could really make benefits even for personal usage. So - fun is one benefit. And fun is important. But is that the idea behind it? Mikhail From rosuav at gmail.com Thu Nov 23 14:15:50 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Nov 2017 06:15:50 +1100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Fri, Nov 24, 2017 at 5:42 AM, Mikhail V wrote: > Chris A wrote: > >>> On Fri, Nov 24, 2017 at 1:10 AM, Mikhail V wrote: >>> >>>> Chris A wrote: >>>> >>>> Fortunately for the world, you're not the one who decided which >>>> characters were permitted in Python identifiers. The ability to use >>>> non-English words for function/variable names is of huge value; the >>>> ability to use a hyphen is of some value, but not nearly as much. >>> >>> Fortunately for the world we have Chris A. Who knows what is >>> fortunate and of huge values. >>> So is there any real world projects example of usage of non-latin scripts >>> in identifiers? Or is it still only a plan for the new world? > > >> Yes, I've used them personally. And I know other people who have. > > > Oh, I though it would be more impressive showcase for 'huge value'. > If we drop the benefit of the bare fact that you can do it, or you just > don't know English, how would describe the practical benefit? > If you don't know english, then programming at all will be just too hard. > (or one must define a new whole language specially for some local script) Let's start with a simpler question. Which of these is better code? # ====== Option 1 class ZipExhausted(Exception): pass def zip_longest(*args, **kwds): # zip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D- fillvalue = kwds.get('fillvalue') counter = len(args) - 1 def sentinel(): nonlocal counter if not counter: raise ZipExhausted counter -= 1 yield fillvalue fillers = repeat(fillvalue) iterators = [chain(it, sentinel(), fillers) for it in args] try: while iterators: yield tuple(map(next, iterators)) except ZipExhausted: pass # ========= Option 2 class e(Exception): pass def zl(*a, **k): f = f.get('fillvalue') c = len(a) - 1 def s(): nonlocal c if not c: raise e c -= 1 yield f ff = repeat(f) i = [chain(i, s(), ff) for i in args] try: while i: yield tuple(map(next, i)) except e: pass # ======== One of them is cribbed straight from the itertools docs. The other is the same functionality with shorter variable names. What makes one of them better than the other? Answer me that, and I'll continue. ChrisA From tjol at tjol.eu Thu Nov 23 14:46:01 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 23 Nov 2017 20:46:01 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On 23/11/17 19:42, Mikhail V wrote: > I mean for a real practical situation - for example for an average > Python programmer or someone who seeks a programmer job. > And who does not have a 500-key keyboard, I don't think it's too much to ask for a programmer to have the technology and expertise necessary to type their own language in its proper alphabet. From Karsten.Hilbert at gmx.net Thu Nov 23 15:04:07 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Thu, 23 Nov 2017 21:04:07 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> On Thu, Nov 23, 2017 at 08:46:01PM +0100, Thomas Jollans wrote: > > I mean for a real practical situation - for example for an average > > Python programmer or someone who seeks a programmer job. > > And who does not have a 500-key keyboard, > > I don't think it's too much to ask for a programmer to have the > technology and expertise necessary to type their own language in its > proper alphabet. Surely, but it can make reusing code a nightmare. Using function arguments written in Thai script ? Understanding, let alone being able to read, code written in Arabic ? No, thanks. Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 From mikhailwas at gmail.com Thu Nov 23 15:06:29 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Thu, 23 Nov 2017 21:06:29 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Thu, Nov 23, 2017 at 8:46 PM, Thomas Jollans wrote: > On 23/11/17 19:42, Mikhail V wrote: >> I mean for a real practical situation - for example for an average >> Python programmer or someone who seeks a programmer job. >> And who does not have a 500-key keyboard, > > I don't think it's too much to ask for a programmer to have the > technology and expertise necessary to type their own language in its > proper alphabet. And I don't think it is too much of benefit of using two scripts in one source to compensate the need to constantly switching. Do you have a method to input e.g. Cyrillic and Latin without switching the layout? If I just use few extra chars, then I'll bind a keyboard shortcut. but even a two-language input is annoyance. And I need to use Cyrillic and Latin constantly, so I know how it feels. Mikhail From mikhailwas at gmail.com Thu Nov 23 15:38:01 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Thu, 23 Nov 2017 21:38:01 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Thu, Nov 23, 2017 at 8:15 PM, Chris Angelico wrote: > > Let's start with a simpler question. Which of these is better code? > > # ====== Option 1 > class ZipExhausted(Exception): > pass > > def zip_longest(*args, **kwds): > # zip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D- > fillvalue = kwds.get('fillvalue') > counter = len(args) - 1 > def sentinel(): > nonlocal counter > if not counter: > raise ZipExhausted > counter -= 1 > yield fillvalue > fillers = repeat(fillvalue) > iterators = [chain(it, sentinel(), fillers) for it in args] > try: > while iterators: > yield tuple(map(next, iterators)) > except ZipExhausted: > pass > > # ========= Option 2 > > class e(Exception): > pass > > def zl(*a, **k): > f = f.get('fillvalue') > c = len(a) - 1 > def s(): > nonlocal c > if not c: > raise e > c -= 1 > yield f > ff = repeat(f) > i = [chain(i, s(), ff) for i in args] > try: > while i: > yield tuple(map(next, i)) > except e: > pass > > # ======== > > One of them is cribbed straight from the itertools docs. The other is > the same functionality with shorter variable names. What makes one of > them better than the other? Answer me that, and I'll continue. I see you manually 'optimise' the look? I personally would end with something like this: def zip_longest(*A, **K): value = K.get ('fillvalue') count = len(a) - 1 def sentinel(): nonlocal count if not count: raise ZipExhausted count -= 1 yield value fillers = repeat (value) iterators = [chain (it, sentinel(), fillers) for it in A] try: while iterators: yield tuple (map (next, iterators)) except ZipExhausted: pass So I would say, my option would be something inbetween. Note that I tweaked it for proportional font, namely Times New Roman. Particularly I find too narrow lines/words a bit eye-straining at times. Also self-explanation is important in many cases. But that depends of what context you cut the example. But if you only ask which code of two looks better for me, then, probably Second, but it has some issues for me, e.g. "c" and "e" almost homoglyhs, too loose 'sieve'-like, short lines. Mikhail From rosuav at gmail.com Thu Nov 23 15:39:49 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Nov 2017 07:39:49 +1100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Fri, Nov 24, 2017 at 7:38 AM, Mikhail V wrote: > I see you manually 'optimise' the look? > I personally would end with something like this: > > def zip_longest(*A, **K): > value = K.get ('fillvalue') > count = len(a) - 1 > def sentinel(): > nonlocal count > if not count: > raise ZipExhausted > count -= 1 > yield value > fillers = repeat (value) > iterators = [chain (it, sentinel(), fillers) for it in A] > try: > while iterators: > yield tuple (map (next, iterators)) > except ZipExhausted: > pass > > > So I would say, my option would be something inbetween. > Note that I tweaked it for proportional font, namely Times New Roman. I don't see how the font applies here, but whatever. Which is better? The one-letter names or the longer ones that tie in with what they're doing? Also, why do you have those loose spaces stuck in random places, eg before some of the open parentheses but not others? ChrisA From mikhailwas at gmail.com Thu Nov 23 16:02:01 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Thu, 23 Nov 2017 22:02:01 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Thu, Nov 23, 2017 at 9:39 PM, Chris Angelico wrote: > On Fri, Nov 24, 2017 at 7:38 AM, Mikhail V wrote: >> I see you manually 'optimise' the look? >> I personally would end with something like this: >> >> def zip_longest(*A, **K): >> value = K.get ('fillvalue') >> count = len(a) - 1 >> def sentinel(): >> nonlocal count >> if not count: >> raise ZipExhausted >> count -= 1 >> yield value >> fillers = repeat (value) >> iterators = [chain (it, sentinel(), fillers) for it in A] >> try: >> while iterators: >> yield tuple (map (next, iterators)) >> except ZipExhausted: >> pass >> >> >> So I would say, my option would be something inbetween. >> Note that I tweaked it for proportional font, namely Times New Roman. > I don't see how the font applies here, but whatever. For a different font, say CourierNew (monospaced) the tweaking strategy might be different. > Which is better? The one-letter names or the longer ones that tie in with what they're > doing? I think I have answered more or less in previous post, that you cutted off. So you were not satisfied? But now I am probably not get your 'better' meaning. Better for understanding, or purely visually, i.e. less eye-straining? > Also, why do you have those loose spaces stuck in random places, eg > before some of the open parentheses but not others? Is it not allowed? I like how it looks with Times font. Mikhail From rosuav at gmail.com Thu Nov 23 16:05:42 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Nov 2017 08:05:42 +1100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Fri, Nov 24, 2017 at 8:02 AM, Mikhail V wrote: > On Thu, Nov 23, 2017 at 9:39 PM, Chris Angelico wrote: >> On Fri, Nov 24, 2017 at 7:38 AM, Mikhail V wrote: >>> I see you manually 'optimise' the look? >>> I personally would end with something like this: >>> >>> def zip_longest(*A, **K): >>> value = K.get ('fillvalue') >>> count = len(a) - 1 >>> def sentinel(): >>> nonlocal count >>> if not count: >>> raise ZipExhausted >>> count -= 1 >>> yield value >>> fillers = repeat (value) >>> iterators = [chain (it, sentinel(), fillers) for it in A] >>> try: >>> while iterators: >>> yield tuple (map (next, iterators)) >>> except ZipExhausted: >>> pass >>> >>> >>> So I would say, my option would be something inbetween. >>> Note that I tweaked it for proportional font, namely Times New Roman. > >> I don't see how the font applies here, but whatever. > > For a different font, say CourierNew (monospaced) the tweaking strategy might > be different. If you have ANY font-specific "tweaking", you're doing it wrong. Thanks for making it look worse on everyone else's screen. >> Which is better? The one-letter names or the longer ones that tie in with what they're >> doing? > > I think I have answered more or less in previous post, that you cutted off. > So you were not satisfied? > But now I am probably not get your 'better' meaning. > Better for understanding, or purely visually, i.e. less eye-straining? Which one would you prefer to maintain? Which would you prefer in a code review? Do you want to have one- and two-letter variable names, or longer and more descriptive ones? Seriously? Do I need to wrench this part out of you? This was supposed to be the EASY question that everyone can agree on, from which I can then draw my line of argument. ChrisA From Richard at Damon-Family.org Thu Nov 23 16:19:59 2017 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 23 Nov 2017 16:19:59 -0500 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: <5dfd3eef-026e-2482-bfcd-7ce6c891502c@Damon-Family.org> On 11/23/17 2:46 PM, Thomas Jollans wrote: > On 23/11/17 19:42, Mikhail V wrote: >> I mean for a real practical situation - for example for an average >> Python programmer or someone who seeks a programmer job. >> And who does not have a 500-key keyboard, > I don't think it's too much to ask for a programmer to have the > technology and expertise necessary to type their own language in its > proper alphabet. My personal feeling is that the language needs to be fully usable with just ASCII, so the - character (HYPHEN/MINUS) is the subtraction/negation operator, not an in-name hyphen. This also means the main library should use just the ASCII character set. I do also realize that it could be very useful for programmers who are programming with other languages as their native, to be able to use words in their native language for their own symbols, and thus useful to use their own character sets. Yes, doing so may add difficulty to the programmers, as they may need to be switching keyboard layouts (especially if not using a LATIN based language), but that is THEIR decision to do so. It also may make it harder for outside programmers to hep, but again, that is the teams decision to make. The Unicode Standard provides a fairly good classification of the characters, and it would make sense to define that an character that is defined as a 'Letter' or a 'Number', and some classes of Punctuation (connector and dash) be allowed in identifiers. Fully implementing may be more complicated than it is worth. An interim simple solution would be just allow ALL (or maybe most, excluding a limited number of obvious exceptions) of the characters above the ASCII set, with a warning that only those classified as above are promised to remain valid, and that other characters, while currently not generating a syntax error, may do so in the future. It should also be stated that while currently no character normalization is being done, it may be added in the future, so identifiers that differ only by code point sequences that are defined as being equivalent, might in the future not be distinct. Since my native language is English, this isn't that important to me, but I do see it as being useful to others with different native tongues. The simple implementation shouldn't be that hard, you can just allow character codes 0x80 and above as being acceptable in identifiers, with the documented warning that the current implementation allows some forms that may generate errors in the future. If enough interest is shown, adding better classification shouldn't be that hard. -- Richard Damon From rosuav at gmail.com Thu Nov 23 16:31:12 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Nov 2017 08:31:12 +1100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: <5dfd3eef-026e-2482-bfcd-7ce6c891502c@Damon-Family.org> References: <5dfd3eef-026e-2482-bfcd-7ce6c891502c@Damon-Family.org> Message-ID: On Fri, Nov 24, 2017 at 8:19 AM, Richard Damon wrote: > On 11/23/17 2:46 PM, Thomas Jollans wrote: >> >> On 23/11/17 19:42, Mikhail V wrote: >>> >>> I mean for a real practical situation - for example for an average >>> Python programmer or someone who seeks a programmer job. >>> And who does not have a 500-key keyboard, >> >> I don't think it's too much to ask for a programmer to have the >> technology and expertise necessary to type their own language in its >> proper alphabet. > > > My personal feeling is that the language needs to be fully usable with just > ASCII, so the - character (HYPHEN/MINUS) is the subtraction/negation > operator, not an in-name hyphen. This also means the main library should use > just the ASCII character set. > > I do also realize that it could be very useful for programmers who are > programming with other languages as their native, to be able to use words in > their native language for their own symbols, and thus useful to use their > own character sets. Yes, doing so may add difficulty to the programmers, as > they may need to be switching keyboard layouts (especially if not using a > LATIN based language), but that is THEIR decision to do so. It also may make > it harder for outside programmers to hep, but again, that is the teams > decision to make. > > The Unicode Standard provides a fairly good classification of the > characters, and it would make sense to define that an character that is > defined as a 'Letter' or a 'Number', and some classes of Punctuation > (connector and dash) be allowed in identifiers. That's exactly how Python's identifiers are defined (modulo special handling of some of the ASCII set, for reasons of backward compatibility). > Fully implementing may be more complicated than it is worth. An interim > simple solution would be just allow ALL (or maybe most, excluding a limited > number of obvious exceptions) of the characters above the ASCII set, with a > warning that only those classified as above are promised to remain valid, > and that other characters, while currently not generating a syntax error, > may do so in the future. It should also be stated that while currently no > character normalization is being done, it may be added in the future, so > identifiers that differ only by code point sequences that are defined as > being equivalent, might in the future not be distinct. No, that would be a bad idea; some of those characters are more logically operators or brackets, and some are most definitely whitespace. Also, it's easier to *expand* the valid character set than to *restrict* it, so it's better to start with only those characters that you know for sure make sense, and then add more later. If the xid_start and xid_continue classes didn't exist, it might be reasonable to use "Letter, any" and "Number, any" as substitutes; but those classes DO exist, so Python uses them. But broadly speaking, yes; it's not hard to allow a bunch of characters as part of Python source code. Actual language syntax (eg keywords) is restricted to ASCII and to those symbols that can easily be typed on most keyboards, but your identifiers are your business. ChrisA From Richard at Damon-Family.org Thu Nov 23 17:15:16 2017 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 23 Nov 2017 17:15:16 -0500 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: <5dfd3eef-026e-2482-bfcd-7ce6c891502c@Damon-Family.org> Message-ID: On 11/23/17 4:31 PM, Chris Angelico wrote: > On Fri, Nov 24, 2017 at 8:19 AM, Richard Damon wrote: >> On 11/23/17 2:46 PM, Thomas Jollans wrote: >>> On 23/11/17 19:42, Mikhail V wrote: >>>> I mean for a real practical situation - for example for an average >>>> Python programmer or someone who seeks a programmer job. >>>> And who does not have a 500-key keyboard, >>> I don't think it's too much to ask for a programmer to have the >>> technology and expertise necessary to type their own language in its >>> proper alphabet. >> >> My personal feeling is that the language needs to be fully usable with just >> ASCII, so the - character (HYPHEN/MINUS) is the subtraction/negation >> operator, not an in-name hyphen. This also means the main library should use >> just the ASCII character set. >> >> I do also realize that it could be very useful for programmers who are >> programming with other languages as their native, to be able to use words in >> their native language for their own symbols, and thus useful to use their >> own character sets. Yes, doing so may add difficulty to the programmers, as >> they may need to be switching keyboard layouts (especially if not using a >> LATIN based language), but that is THEIR decision to do so. It also may make >> it harder for outside programmers to hep, but again, that is the teams >> decision to make. >> >> The Unicode Standard provides a fairly good classification of the >> characters, and it would make sense to define that an character that is >> defined as a 'Letter' or a 'Number', and some classes of Punctuation >> (connector and dash) be allowed in identifiers. > That's exactly how Python's identifiers are defined (modulo special > handling of some of the ASCII set, for reasons of backward > compatibility). > >> Fully implementing may be more complicated than it is worth. An interim >> simple solution would be just allow ALL (or maybe most, excluding a limited >> number of obvious exceptions) of the characters above the ASCII set, with a >> warning that only those classified as above are promised to remain valid, >> and that other characters, while currently not generating a syntax error, >> may do so in the future. It should also be stated that while currently no >> character normalization is being done, it may be added in the future, so >> identifiers that differ only by code point sequences that are defined as >> being equivalent, might in the future not be distinct. > No, that would be a bad idea; some of those characters are more > logically operators or brackets, and some are most definitely > whitespace. Also, it's easier to *expand* the valid character set than > to *restrict* it, so it's better to start with only those characters > that you know for sure make sense, and then add more later. If the > xid_start and xid_continue classes didn't exist, it might be > reasonable to use "Letter, any" and "Number, any" as substitutes; but > those classes DO exist, so Python uses them. > > But broadly speaking, yes; it's not hard to allow a bunch of > characters as part of Python source code. Actual language syntax (eg > keywords) is restricted to ASCII and to those symbols that can easily > be typed on most keyboards, but your identifiers are your business. > > ChrisA My thought is you define a legal only those Unicode characters that via the defined classification would be normally legal, but perhaps the first implementation doesn't diagnose many of the illegal combinations. If that isn't Pythonic, then yes, implementing a fuller classification would be needed. That might also say normalization questions would need to be decided too. -- Richard Damon From breamoreboy at gmail.com Thu Nov 23 17:42:35 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Thu, 23 Nov 2017 14:42:35 -0800 (PST) Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: <4f7e11bb-bb3c-4f45-9629-d35b7b65bd43@googlegroups.com> On Thursday, November 23, 2017 at 6:50:29 PM UTC, Mikhail V wrote: > Chris A wrote: > > >> On Fri, Nov 24, 2017 at 1:10 AM, Mikhail V wrote: > >> > >>> Chris A wrote: > >>> > >>> Fortunately for the world, you're not the one who decided which > >>> characters were permitted in Python identifiers. The ability to use > >>> non-English words for function/variable names is of huge value; the > >>> ability to use a hyphen is of some value, but not nearly as much. > >> > >> Fortunately for the world we have Chris A. Who knows what is > >> fortunate and of huge values. > >> So is there any real world projects example of usage of non-latin scripts > >> in identifiers? Or is it still only a plan for the new world? > > > > Yes, I've used them personally. And I know other people who have. > > > Oh, I though it would be more impressive showcase for 'huge value'. > If we drop the benefit of the bare fact that you can do it, or you just > don't know English, how would describe the practical benefit? > If you don't know english, then programming at all will be just too hard. > (or one must define a new whole language specially for some local script) > > I mean for a real practical situation - for example for an average > Python programmer or someone who seeks a programmer job. > And who does not have a 500-key keyboard, and who has > a not enough high threshold of vision sensitivity to bear the look > of various scripts in one small text piece? > > Ok, I personally could find some practical usage for that, but > merely for fun. I doubt though that someone with less > typographical experience and overall computer literacy could > really make benefits even for personal usage. > > So - fun is one benefit. And fun is important. But is that the > idea behind it? > > > Mikhail Your normal rubbish. Do you ever give up with wasting our time? From tjol at tjol.eu Thu Nov 23 17:45:32 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 23 Nov 2017 23:45:32 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: <5dfd3eef-026e-2482-bfcd-7ce6c891502c@Damon-Family.org> Message-ID: On 23/11/17 23:15, Richard Damon wrote: > > My thought is you define a legal only those Unicode characters that via > the defined classification would be normally legal, but perhaps the > first implementation doesn't diagnose many of the illegal combinations. > If that isn't Pythonic, then yes, implementing a fuller classification > would be needed. That might also say normalization questions would need > to be decided too. > You do realise that Python has a perfectly good definition of what's allowed in an identifier that is thoroughly grounded in the Unicode standard and works very well, right? -- Thomas From Richard at Damon-Family.org Thu Nov 23 18:18:57 2017 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 23 Nov 2017 18:18:57 -0500 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: <5dfd3eef-026e-2482-bfcd-7ce6c891502c@Damon-Family.org> Message-ID: <45d0c71d-cf81-38bc-37d6-322ab9ef1bd6@Damon-Family.org> On 11/23/17 5:45 PM, Thomas Jollans wrote: > On 23/11/17 23:15, Richard Damon wrote: >> My thought is you define a legal only those Unicode characters that via >> the defined classification would be normally legal, but perhaps the >> first implementation doesn't diagnose many of the illegal combinations. >> If that isn't Pythonic, then yes, implementing a fuller classification >> would be needed. That might also say normalization questions would need >> to be decided too. >> > You do realise that Python has a perfectly good definition of what's > allowed in an identifier that is thoroughly grounded in the Unicode > standard and works very well, right? > > > -- Thomas No, I wasn't aware that Python was already Unicode enabled in the source code set. Still fairly new with it, but the fact that people seemed to argue about doing it made me think it was allowed yet. -- Richard Damon From tjol at tjol.eu Thu Nov 23 18:26:27 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 24 Nov 2017 00:26:27 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: <45d0c71d-cf81-38bc-37d6-322ab9ef1bd6@Damon-Family.org> References: <5dfd3eef-026e-2482-bfcd-7ce6c891502c@Damon-Family.org> <45d0c71d-cf81-38bc-37d6-322ab9ef1bd6@Damon-Family.org> Message-ID: <574772dd-e5ef-0117-0c52-686f86a9cd5e@tjol.eu> On 24/11/17 00:18, Richard Damon wrote: > On 11/23/17 5:45 PM, Thomas Jollans wrote: >> On 23/11/17 23:15, Richard Damon wrote: >>> My thought is you define a legal only those Unicode characters that via >>> the defined classification would be normally legal, but perhaps the >>> first implementation doesn't diagnose many of the illegal combinations. >>> If that isn't Pythonic, then yes, implementing a fuller classification >>> would be needed. That might also say normalization questions would need >>> to be decided too. >>> >> You do realise that Python has a perfectly good definition of what's >> allowed in an identifier that is thoroughly grounded in the Unicode >> standard and works very well, right? >> >> >> -- Thomas > > No, I wasn't aware that Python was already Unicode enabled in the source > code set. Still fairly new with it, but the fact that people seemed to > argue about doing it made me think it was allowed yet. > It's an old favourite some people to shout about on slow news days... Python allows identifiers to start with any letter or an underscore, and continue with any letter or number, or an underscore. The details follow the Unicode XID_* properties. In comments and strings, anything goes. -- Thomas From rantingrickjohnson at gmail.com Thu Nov 23 18:27:25 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 23 Nov 2017 15:27:25 -0800 (PST) Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Thursday, November 23, 2017 at 3:06:00 PM UTC-6, Chris Angelico wrote: > Seriously? Do I need to wrench this part out of you? This > was supposed to be the EASY question that everyone can > agree on, from which I can then draw my line of argument. Translation: "Dag-nab-it! You're supposed to answer my false dichotomy in a way that makes you look ~really~ bad, so that i can tear your argument apart ~really~ easy. Got it? Now stop clowning around and do it right this time!" From ian.g.kelly at gmail.com Thu Nov 23 19:47:04 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 23 Nov 2017 17:47:04 -0700 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> Message-ID: On Thu, Nov 23, 2017 at 1:04 PM, Karsten Hilbert wrote: > On Thu, Nov 23, 2017 at 08:46:01PM +0100, Thomas Jollans wrote: > >> > I mean for a real practical situation - for example for an average >> > Python programmer or someone who seeks a programmer job. >> > And who does not have a 500-key keyboard, >> >> I don't think it's too much to ask for a programmer to have the >> technology and expertise necessary to type their own language in its >> proper alphabet. > > Surely, but it can make reusing code a nightmare. > > Using function arguments written in Thai script ? > > Understanding, let alone being able to read, code written in Arabic ? People are going to write code in Arabic whether you like it or not, because not everybody speaks English, and not everybody who does *wants* to use it. Now, would you prefer to read code where the variable names are written in Arabic script, or where the variable names are still in Arabic but transliterated to Latin characters? Either way, you're not going to be able to understand it, so I'm not sure why it makes a difference to you. If Arabic characters are allowed however, then it might be of use to the people who are going to code in Arabic anyway. And if it isn't, then they have the option not to use it either. From ian.g.kelly at gmail.com Thu Nov 23 19:57:03 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 23 Nov 2017 17:57:03 -0700 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: <5dfd3eef-026e-2482-bfcd-7ce6c891502c@Damon-Family.org> References: <5dfd3eef-026e-2482-bfcd-7ce6c891502c@Damon-Family.org> Message-ID: On Thu, Nov 23, 2017 at 2:19 PM, Richard Damon wrote: > The Unicode Standard provides a fairly good classification of the > characters, and it would make sense to define that an character that is > defined as a 'Letter' or a 'Number', and some classes of Punctuation > (connector and dash) be allowed in identifiers. > > Fully implementing may be more complicated than it is worth. An interim > simple solution would be just allow ALL (or maybe most, excluding a limited > number of obvious exceptions) of the characters above the ASCII set, with a > warning that only those classified as above are promised to remain valid, > and that other characters, while currently not generating a syntax error, > may do so in the future. It should also be stated that while currently no > character normalization is being done, it may be added in the future, so > identifiers that differ only by code point sequences that are defined as > being equivalent, might in the future not be distinct. It's already implemented; nothing needs to be done. Unicode Standard Annex #31 defines a recommended syntax of identifiers, which Python basically follows, except that for backward compatibility Python also allows identifiers to begin with an underscore. Compare the recommended syntax at http://unicode.org/reports/tr31/#Default_Identifier_Syntax with the Python syntax at https://docs.python.org/3/reference/lexical_analysis.html#identifiers. From mikhailwas at gmail.com Thu Nov 23 21:44:36 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Fri, 24 Nov 2017 03:44:36 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Thu, Nov 23, 2017 at 10:05 PM, Chris Angelico wrote: > On Fri, Nov 24, 2017 at 8:02 AM, Mikhail V wrote: >> On Thu, Nov 23, 2017 at 9:39 PM, Chris Angelico wrote: >>> On Fri, Nov 24, 2017 at 7:38 AM, Mikhail V wrote: >>>> I see you manually 'optimise' the look? >>>> I personally would end with something like this: >>>> >>>> def zip_longest(*A, **K): >>>> value = K.get ('fillvalue') >>>> count = len(a) - 1 >>>> def sentinel(): >>>> nonlocal count >>>> if not count: >>>> raise ZipExhausted >>>> count -= 1 >>>> yield value >>>> fillers = repeat (value) >>>> iterators = [chain (it, sentinel(), fillers) for it in A] >>>> try: >>>> while iterators: >>>> yield tuple (map (next, iterators)) >>>> except ZipExhausted: >>>> pass >>>> >>>> >>>> So I would say, my option would be something inbetween. >>>> Note that I tweaked it for proportional font, namely Times New Roman. >> >>> I don't see how the font applies here, but whatever. >> >> For a different font, say CourierNew (monospaced) the tweaking strategy might >> be different. > > If you have ANY font-specific "tweaking", you're doing it wrong. > Thanks for making it look worse on everyone else's screen. Trolling attempt counted :) No I don't have any particular font-specific strategy, it is just my wording reflecting the fact that things look different in different fonts, even among proportional fonts. > >>> Which is better? The one-letter names or the longer ones that tie in with what they're >>> doing? >> >> I think I have answered more or less in previous post, that you cutted off. >> So you were not satisfied? >> But now I am probably not get your 'better' meaning. >> Better for understanding, or purely visually, i.e. less eye-straining? > > Which one would you prefer to maintain? Which would you prefer in a code review? > > Do you want to have one- and two-letter variable names, or longer and > more descriptive ones? > > Seriously? Do I need to wrench this part out of you? This was supposed > to be the EASY question that everyone can agree on, from which I can > then draw my line of argument. >From my above example, you could probably see that I prefer somewhat middle-sized identifiers, one-two syllables. And naturally, they tend to reflect some process/meaining, it is not always achievable, but yes there is such a natural tendency, although by me personally not so strong, and quite often I use totally meaningless names, mainly to avoid visual similarity to already created names. So for very expanded names, it ends up with a lot of underscores :( Mikhail From rosuav at gmail.com Thu Nov 23 22:13:22 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Nov 2017 14:13:22 +1100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Fri, Nov 24, 2017 at 1:44 PM, Mikhail V wrote: > From my above example, you could probably see that I prefer somewhat > middle-sized identifiers, one-two syllables. And naturally, they tend to > reflect some process/meaining, it is not always achievable, > but yes there is such a natural tendency, although by me personally > not so strong, and quite often I use totally meaningless names, > mainly to avoid visual similarity to already created names. > So for very expanded names, it ends up with a lot of underscores :( Okay. So if it makes sense for you to use English words instead of individual letters, since you are fluent in English, does it stand to reason that it would make sense for other programmers to use Russian, Norwegian, Hebrew, Korean, or Japanese words the same way? ChrisA From mikhailwas at gmail.com Thu Nov 23 22:52:57 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Fri, 24 Nov 2017 04:52:57 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Fri, Nov 24, 2017 at 4:13 AM, Chris Angelico wrote: > On Fri, Nov 24, 2017 at 1:44 PM, Mikhail V wrote: >> From my above example, you could probably see that I prefer somewhat >> middle-sized identifiers, one-two syllables. And naturally, they tend to >> reflect some process/meaining, it is not always achievable, >> but yes there is such a natural tendency, although by me personally >> not so strong, and quite often I use totally meaningless names, >> mainly to avoid visual similarity to already created names. >> So for very expanded names, it ends up with a lot of underscores :( > > Okay. So if it makes sense for you to use English words instead of > individual letters, since you are fluent in English, does it stand to > reason that it would make sense for other programmers to use Russian, > Norwegian, Hebrew, Korean, or Japanese words the same way? I don't know. Probably, especially if those *programmers* don't know latin letters, then they would want to write code with their letters and their language. This target group, as I said, will have really hard time with programming, and in Python in particular, because they will be not only forced to learn some english, but also will have all 'pleasures' of multi-script editing. But wait, probably one can write python code in, say Arabic script *only*? How about such feature proposal? As for non-english speaker who know some English already, could of course want to include identifiers in those scripts. But how about libraries? Ok, so we return back to my original question: apart from ability to do so, how beneficial is it on a pragmatical basis? I mean, e.g. Cyrillic will introduce homoglyph issues. CJK and Arabic scripts are metrically and optically incompatible with latin, so such mixing will end up with messy look. So just for the experiment, yes, it's fun. Mikhail From ben+python at benfinney.id.au Thu Nov 23 22:56:41 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 24 Nov 2017 14:56:41 +1100 Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> Message-ID: <85r2souy6e.fsf_-_@benfinney.id.au> Ian Kelly writes: > On Thu, Nov 23, 2017 at 1:04 PM, Karsten Hilbert > wrote: > > Using function arguments written in Thai script ? > > > > Understanding, let alone being able to read, code written in Arabic > > ? > > People are going to write code in Arabic whether you like it or not, > because not everybody speaks English, and not everybody who does > *wants* to use it. This is, I think, a good reason to allow Unicode identifiers (at least, those Unicode subsets which encode writing systems of languages) as programming-language identifiers. > Now, would you prefer to read code where the variable names are > written in Arabic script, or where the variable names are still in > Arabic but transliterated to Latin characters? (On the ? evidently correct, in Karsten's case and mine ? assumption that the reader does not understand Arabic script.) I've thought about this, and if the quesition is which would *I* prefer, the answer is I'd prefer the identifiers transliterated to the Latin (English-writing) characters. Because if I already can't understand the words, it will be more useful to me to be able to type them reliably at a keyboard, for replication, search, discussion with others about the code, etc. Set against that, though, I want the preferences of *others* to be taken into consideration also. And there are many more people who do not natively write English/Latin characters, that I want to feel welcome in the Python community. So it's a good thing that my own reading preference *does not* have weight in this matter. I'm not the primary audience for code identifiers written in Arabic script, so my preference should matter less than those who understand it. > Either way, you're not going to be able to understand it, so I'm not > sure why it makes a difference to you. I hope you can see that it can simultaneously make a difference ? I would definitely prefer to read Latin-writing identifiers ? while also being a lesser consideration that should not outweigh the benefits of allowing non-Latin-script identifiers. > If Arabic characters are allowed however, then it might be of use to > the people who are going to code in Arabic anyway. And if it isn't, > then they have the option not to use it either. This is a necessary consequence of increasing the diversity of people able to program in Python: people will express ideas originating in their own language, in Python code. For that diversity to increase, we English-fluent folk will necessarily become a smaller proportion of the programming community than we are today. That might be uncomfortable for us, but it is a necessary adaptation the community needs to undergo. -- \ ?In any great organization it is far, far safer to be wrong | `\ with the majority than to be right alone.? ?John Kenneth | _o__) Galbraith, 1989-07-28 | Ben Finney From formisc at gmail.com Thu Nov 23 23:45:51 2017 From: formisc at gmail.com (Andrew Z) Date: Thu, 23 Nov 2017 23:45:51 -0500 Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: <85r2souy6e.fsf_-_@benfinney.id.au> References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> Message-ID: I have hard time seeing the benefits of this "necessity" , just unreasonable overcomplications for the name of "diversity". On Nov 23, 2017 22:57, "Ben Finney" wrote: > Ian Kelly writes: > > > On Thu, Nov 23, 2017 at 1:04 PM, Karsten Hilbert > > wrote: > > > Using function arguments written in Thai script ? > > > > > > Understanding, let alone being able to read, code written in Arabic > > > ? > > > > People are going to write code in Arabic whether you like it or not, > > because not everybody speaks English, and not everybody who does > > *wants* to use it. > > This is, I think, a good reason to allow Unicode identifiers (at least, > those Unicode subsets which encode writing systems of languages) as > programming-language identifiers. > > > Now, would you prefer to read code where the variable names are > > written in Arabic script, or where the variable names are still in > > Arabic but transliterated to Latin characters? > > (On the ? evidently correct, in Karsten's case and mine ? assumption > that the reader does not understand Arabic script.) > > I've thought about this, and if the quesition is which would *I* prefer, > the answer is I'd prefer the identifiers transliterated to the Latin > (English-writing) characters. > > Because if I already can't understand the words, it will be more useful > to me to be able to type them reliably at a keyboard, for replication, > search, discussion with others about the code, etc. > > Set against that, though, I want the preferences of *others* to be taken > into consideration also. And there are many more people who do not > natively write English/Latin characters, that I want to feel welcome in > the Python community. > > So it's a good thing that my own reading preference *does not* have > weight in this matter. I'm not the primary audience for code identifiers > written in Arabic script, so my preference should matter less than those > who understand it. > > > Either way, you're not going to be able to understand it, so I'm not > > sure why it makes a difference to you. > > I hope you can see that it can simultaneously make a difference ? I > would definitely prefer to read Latin-writing identifiers ? while also > being a lesser consideration that should not outweigh the benefits of > allowing non-Latin-script identifiers. > > > If Arabic characters are allowed however, then it might be of use to > > the people who are going to code in Arabic anyway. And if it isn't, > > then they have the option not to use it either. > > This is a necessary consequence of increasing the diversity of people > able to program in Python: people will express ideas originating in > their own language, in Python code. > > For that diversity to increase, we English-fluent folk will necessarily > become a smaller proportion of the programming community than we are > today. That might be uncomfortable for us, but it is a necessary > adaptation the community needs to undergo. > > -- > \ ?In any great organization it is far, far safer to be wrong | > `\ with the majority than to be right alone.? ?John Kenneth | > _o__) Galbraith, 1989-07-28 | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Fri Nov 24 02:03:02 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Nov 2017 18:03:02 +1100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Fri, Nov 24, 2017 at 2:52 PM, Mikhail V wrote: > On Fri, Nov 24, 2017 at 4:13 AM, Chris Angelico wrote: >> On Fri, Nov 24, 2017 at 1:44 PM, Mikhail V wrote: >>> From my above example, you could probably see that I prefer somewhat >>> middle-sized identifiers, one-two syllables. And naturally, they tend to >>> reflect some process/meaining, it is not always achievable, >>> but yes there is such a natural tendency, although by me personally >>> not so strong, and quite often I use totally meaningless names, >>> mainly to avoid visual similarity to already created names. >>> So for very expanded names, it ends up with a lot of underscores :( >> >> Okay. So if it makes sense for you to use English words instead of >> individual letters, since you are fluent in English, does it stand to >> reason that it would make sense for other programmers to use Russian, >> Norwegian, Hebrew, Korean, or Japanese words the same way? > > I don't know. Probably, especially if those *programmers* don't know latin > letters, then they would want to write code with their letters and their > language. This target group, as I said, will have really hard time > with programming, > and in Python in particular, because they will be not only forced to learn > some english, but also will have all 'pleasures' of multi-script editing. > But wait, probably one can write python code in, say Arabic script *only*? > How about such feature proposal? If Python supports ASCII identifiers only, people have no choice but to transliterate. As it is, people get to choose which is better for them - to transliterate or not to transliterate, that is the readability question. > As for non-english speaker who know some English already, > could of course want to include identifiers in those scripts. > But how about libraries? If you want to use numpy, you have to understand the language of numpy. That's a lot of technical jargon, so even if you understand English, you have to learn that. So there's ultimately no difference. The most popular libraries, just like the standard library, are usually going to choose to go ASCII-only as the lowest-common-denominator. But that is, again, their own choice. > Ok, so we return back to my original question: apart from > ability to do so, how beneficial is it on a pragmatical basis? > I mean, e.g. Cyrillic will introduce homoglyph issues. > CJK and Arabic scripts are metrically and optically incompatible with > latin, so such mixing will end up with messy look. So just for > the experiment, yes, it's fun. Does it really introduce homoglyph issues in real-world situations, though? Are there really cases where people can't figure out from context what's going on? I haven't seen that happening. Usually there are *entire words* (and more) in a single language, making it pretty easy to figure out. ChrisA From tjol at tjol.eu Fri Nov 24 02:28:52 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 24 Nov 2017 08:28:52 +0100 Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> Message-ID: <8aa03dd0-6065-5ede-4cc4-1e17005195ca@tjol.eu> On 24/11/17 05:45, Andrew Z wrote: > I have hard time seeing the benefits of this "necessity" , just > unreasonable overcomplications for the name of "diversity". What complications? From Karsten.Hilbert at gmx.net Fri Nov 24 04:48:13 2017 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Fri, 24 Nov 2017 10:48:13 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> Message-ID: <20171124094813.civpfybf44hydeiq@hermes.hilbert.loc> On Thu, Nov 23, 2017 at 05:47:04PM -0700, Ian Kelly wrote: > > Understanding, let alone being able to read, code written in Arabic ? > > People are going to write code in Arabic whether you like it or not, > because not everybody speaks English, and not everybody who does > *wants* to use it. Now, would you prefer to read code where the > variable names are written in Arabic script, or where the variable > names are still in Arabic but transliterated to Latin characters? > Either way, you're not going to be able to understand it, so I'm not > sure why it makes a difference to you. I can visually pattern match "words" based on Latin characters. I can't with Arabic letters. So that answers the "would you prefer" part. However, the main point has been answered - Python already does what is talked about. End of story. Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 From greg.ewing at canterbury.ac.nz Fri Nov 24 07:00:24 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 25 Nov 2017 01:00:24 +1300 Subject: Python loop and web server (bottle) in the same script (Posting On Python-List Prohibited) In-Reply-To: References: Message-ID: Lawrence D?Oliveiro wrote: > On Friday, November 24, 2017 at 3:27:17 AM UTC+13, zlju... at gmail.com wrote: > >>Looks like I need some sort of parallelization. > > This is why coroutines were added to Python. Threading is notoriously bug-prone, and is best avoided in most situations. The OP claimed that the timing of the update task is critical, and needs to take priority over serving web pages. Coroutines won't be able to achieve that. -- Greg From bc at freeuk.com Fri Nov 24 07:12:15 2017 From: bc at freeuk.com (bartc) Date: Fri, 24 Nov 2017 12:12:15 +0000 Subject: Benefits of unicode identifiers In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <20171124094813.civpfybf44hydeiq@hermes.hilbert.loc> Message-ID: On 24/11/2017 11:56, Stefan Ram wrote: > Karsten Hilbert writes: >> However, the main point has been answered - Python already >> does what is talked about. End of story. > > Java allowed Unicode in identifiers right from the get-go > (1995). I.e., one can write an assignment statement such as > > ? = 3.141; That's great. But how do I type it on my keyboard? How do I view someone else's code on my crappy ASCII text editor? > . The Java community decided to ignore this and only use > latin letters and arabic digits (i.e., ?pi1?) and English > words, to support the (international) exchange of code. > > (However, for a beginner's tutorial in German, I might use > identifiers based on German words.) German isn't very challenging apart from a couple of umlauts and that funny symbol for ss that looks like a Greek beta. And perhaps in Germany, keyboards will already take care of those. But which keyboards will have ? [copied from the one above!]? Apart perhaps from the ones in Greece, where ? might already be heavily used in the same way we use 'p'. -- bartc From tjol at tjol.eu Fri Nov 24 07:40:22 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 24 Nov 2017 13:40:22 +0100 Subject: Benefits of unicode identifiers In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <20171124094813.civpfybf44hydeiq@hermes.hilbert.loc> Message-ID: <26771560-f2eb-e6d9-19ec-90041f38c36d@tjol.eu> On 2017-11-24 13:12, bartc wrote: > On 24/11/2017 11:56, Stefan Ram wrote: >> Karsten Hilbert writes: >>> However, the main point has been answered - Python already >>> does what is talked about. End of story. >> >> ?? Java allowed Unicode in identifiers right from the get-go >> ?? (1995). I.e., one can write an assignment statement such as >> >> ? = 3.141; > > That's great. But how do I type it on my keyboard? How do I view someone > else's code on my crappy ASCII text editor? ASCII editors are not text editors. > >> ?? . The Java community decided to ignore this and only use >> ?? latin letters and arabic digits (i.e., ?pi1?) and English >> ?? words, to support the (international) exchange of code. >> >> ?? (However, for a beginner's tutorial in German, I might use >> ?? identifiers based on German words.) > > > German isn't very challenging apart from a couple of umlauts and that > funny symbol for ss that looks like a Greek beta. And perhaps in > Germany, keyboards will already take care of those. > > But which keyboards will have ? [copied from the one above!]? > > Apart perhaps from the ones in Greece, where ? might already be heavily > used in the same way we use 'p'. > -- Thomas Jollans From marko at pacujo.net Fri Nov 24 07:48:05 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 24 Nov 2017 14:48:05 +0200 Subject: Benefits of unicode identifiers References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <20171124094813.civpfybf44hydeiq@hermes.hilbert.loc> Message-ID: <87o9nrx2pm.fsf@elektro.pacujo.net> bartc : > On 24/11/2017 11:56, Stefan Ram wrote: >> Java allowed Unicode in identifiers right from the get-go >> (1995). I.e., one can write an assignment statement such as >> >> ? = 3.141; > > That's great. But how do I type it on my keyboard? How do I view someone > else's code on my crappy ASCII text editor? That's a different problem entirely. I remember the 1980's when terminals only supported 7-bit characters, but Finnish people needed to be able to type Finnish text. The solution was to ditch unneeded American punctuation characters. Thus, your first-ever C-program might have looked like this: main(argc, argv) int argc; char argv??; ? printf("Hello, world!?n"); ? > German isn't very challenging apart from a couple of umlauts and that > funny symbol for ss that looks like a Greek beta. And perhaps in > Germany, keyboards will already take care of those. > > But which keyboards will have ? [copied from the one above!]? I can map any character onto any key. In fact, my keyboard mapping is heavily personalized. I must admit, though, that I haven't mapped ? onto any key. It would be na?ve to assume, though, that the problem doesn't apply to English. You never had to type a r?sum??or use non-ASCII punctuation? If you should stray out of the USA, it wouldn't hurt to carry some ? or ?. I *have* mapped those keys onto my keyboard. Marko From zljubisic at gmail.com Fri Nov 24 08:20:26 2017 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Fri, 24 Nov 2017 05:20:26 -0800 (PST) Subject: Python loop and web server (bottle) in the same script (Posting On Python-List Prohibited) In-Reply-To: References: Message-ID: <0ee995bd-40eb-46dd-aa61-1e4b1cee10cf@googlegroups.com> That's right. Update task has precedence. Looks like it is not an easy task. Regards. From brennerx22 at gmail.com Fri Nov 24 08:31:12 2017 From: brennerx22 at gmail.com (brennerx22 at gmail.com) Date: Fri, 24 Nov 2017 05:31:12 -0800 (PST) Subject: Python para whatsapp em massa. Message-ID: <7f2319b0-0e00-4a5e-af09-2232f7432781@googlegroups.com> Bom dia. Gostaria de saber quais processos eu preciso fazer para aprender a programar em python. Preciso especificamente programar um software para envio em massa de whatsapp e n?o sei por onde come?ar. From frank at chagford.com Fri Nov 24 08:31:46 2017 From: frank at chagford.com (Frank Millman) Date: Fri, 24 Nov 2017 15:31:46 +0200 Subject: Why does asyncio.wait_for() need a timeout? In-Reply-To: References: Message-ID: "Frank Millman" wrote in message news:ov5v3s$bv7$1 at blaine.gmane.org... > Below is a simple asyncio loop that runs two background tasks. > [...] > > Both take an optional timeout. > > If I use the first method without a timeout, the cancellation completes > and the loop stops. > > If I use the second method without a timeout, the future is cancelled, but > the program hangs. > > If I add a timeout to the second one, it behaves the same as the first > one. > > Is there a reason for this? > I have figured out half of the answer. 'timeout' is an optional argument when using wait(), but a required one when using wait_for(). Therefore asyncio is raising an exception. However, I do not understand why no traceback appears. Frank From namenobodywants at gmail.com Fri Nov 24 10:33:22 2017 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Fri, 24 Nov 2017 07:33:22 -0800 (PST) Subject: connect four (game) Message-ID: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> hi all i've just finished my first excursion into artificial intelligence with a game less trivial than tictactoe, and here it is in case anybody can offer criticism/suggestions/etc peace stm ############################### #) connectfour - python 3.6.1 ############################### from tkinter import * from random import choice class infinity: def __init__(self,signum): self.signum = signum def __repr__(self): return '+oo' if self.signum > 0 else '-oo' def __lt__(self,other): return False if self.signum > 0 else True def __le__(self,other): return False if self.signum > 0 else True def __gt__(self,other): return True if self.signum > 0 else False def __ge__(self,other): return True if self.signum > 0 else False def __eq__(self,other): return isinstance(other,infinity) and self.signum == other.signum ex, oh, blank = 'red black white' .split() startboard = {(i,j):blank for i in range(6) for j in range(7)} def getlines(board): horizontal = [[(i, j+k) for k in range(4)] for i in range(6) for j in range(7)] vertical = [[(i+k, j) for k in range(4)] for i in range(6) for j in range(7)] positive = [[(i+k, j+k) for k in range(4)] for i in range(6) for j in range(7)] negative = [[(i+k, j-k) for k in range(4)] for i in range(6) for j in range(7)] linear = horizontal + vertical + positive + negative lines = [line for line in linear if all(i in range(6) and j in range(7) for (i,j) in line)] return [[board[square] for square in line] for line in lines] def getwinner(board): lines = getlines(board) return ex if [ex]*4 in lines else oh if [oh]*4 in lines else None def getmover(board): boardvalues = list(board.values()) return ex if boardvalues.count(ex)==boardvalues.count(oh) else oh def getoptimum(mover): return max if mover == ex else min def getaccessibles(board): return [j for j in range(7) if board[0,j] == blank] def getvalue(winner,accessibles): return infinity(+1) if winner == ex else infinity(-1) if winner == oh else 0 if not accessibles else None def makemove(board,column,mover): board = board.copy() empties = [row for row in range(6) if board[row,column] == blank] if not empties: return board board[max(empties),column] = mover return board def takemoveback(board,column): board = board.copy() occupied = [row for row in range(6) if board[row,column] != blank] if not occupied: return board board[min(occupied),column] = blank return board def guessvalue(board): lines = getlines(board) exs = [line for line in lines if line.count(ex)==3 and line.count(oh)==0] ohs = [line for line in lines if line.count(oh)==3 and line.count(ex)==0] return len(exs)-len(ohs) def heuristicvalue(board,depth): winner = getwinner(board) accessibles = getaccessibles(board) value = getvalue(winner,accessibles) if value != None: return value if depth == 0: return guessvalue(board) mover = getmover(board) optimum = getoptimum(mover) children = [makemove(board,column,mover) for column in accessibles] return optimum(heuristicvalue(child,depth-1) for child in children) def getmoves(board,depth): accessibles = getaccessibles(board) if not accessibles: return [] mover = getmover(board) optimum = getoptimum(mover) children = [makemove(board,column,mover) for column in accessibles] values = [heuristicvalue(child,depth) for child in children] bestvalue = optimum(values) return [accessibles[index] for index in range(len(accessibles)) if values[index] == bestvalue] class grid: def __init__(self,window): self.window = window self.boardframe = Frame(window.root) self.rowframes = [Frame(self.boardframe) for anonymous in range(6)] self.squarebuttons = [Button(self.rowframes[number//7], width=3, command=self.window.squarecommand(number), background=blank) for number in range(42)] def pack(self): self.boardframe .pack(side=TOP) [frame .pack(side=TOP) for frame in self.rowframes] [button .pack(side=LEFT) for button in self.squarebuttons] class caption: def __init__(self,window): self.window = window self.statusframe = Frame(window.root) self.statuslabel = Label(self.statusframe, height=2) def pack(self): self.statusframe .pack(side=TOP) self.statuslabel .pack(side=LEFT) class buttonpanel: def __init__(self,window,depth): self.window = window self.controlframe = Frame(window.root) self.makemoveframe = Frame(self.controlframe) self.takebackframe = Frame(self.controlframe) self.startoverframe = Frame(self.controlframe) self.makemovebutton = Button(self.makemoveframe, text='make move', command=self.window.movecommand(depth)) self.takebackbutton = Button(self.takebackframe, text='take back', command=self.window.takeback) self.startoverbutton = Button(self.startoverframe, text='start over', command=self.window.startover) def pack(self): self.controlframe .pack(side=TOP) self.makemoveframe .pack(side=LEFT) self.takebackframe .pack(side=LEFT) self.startoverframe .pack(side=RIGHT) self.makemovebutton .pack(side=TOP) self.takebackbutton .pack(side=TOP) self.startoverbutton .pack(side=TOP) class window: def __init__(self, depth=2): self.root = Tk() self.grid = grid (self) self.caption = caption (self) self.buttonpanel = buttonpanel(self, depth=2) self.grid .pack() self.caption .pack() self.buttonpanel .pack() self.startover() self.root.title('connect four') self.root.mainloop() def startover(self): self.board = startboard self.movelist = [] self.display() def display(self): winner = getwinner(self.board) mover = getmover (self.board) tie = blank not in self.board.values() status = winner + ' wins' if winner else 'tied game' if tie else mover + ' to move' [self.grid.squarebuttons[number].config(background=self.board[divmod(number,7)]) for number in range(42)] self.caption.statuslabel.config(text = status.upper() if winner or tie else status) def squarecommand(self,number): def returnvalue(): if getwinner(self.board) or blank not in self.board.values(): return column = number % 7 self.board = makemove(self.board, column, getmover(self.board)) self.display() self.grid.squarebuttons[column].flash() self.movelist += [column] return returnvalue def movecommand(self,depth): def returnvalue(): if getwinner(self.board) or blank not in self.board.values(): return column = choice(getmoves(self.board,depth)) self.board = makemove(self.board, column, getmover(self.board)) self.display() self.grid.squarebuttons[column].flash() self.movelist += [column] return returnvalue def takeback(self): if not self.movelist: return self.board = takemoveback(self.board, self.movelist[-1]) self.display() self.movelist = self.movelist[:-1] From rosuav at gmail.com Fri Nov 24 11:06:36 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Nov 2017 03:06:36 +1100 Subject: connect four (game) In-Reply-To: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> Message-ID: On Sat, Nov 25, 2017 at 2:33 AM, wrote: > hi all > > i've just finished my first excursion into artificial intelligence with a game less trivial than tictactoe, and here it is in case anybody can offer criticism/suggestions/etc > Hi! You don't have a lot of comments or docstrings or anything, so it's not going to be easy to track down bugs. (I haven't tested your code, so in theory it could be 100% bug-free, but frankly I doubt it. No code is ever perfect :) ) > class infinity: > def __init__(self,signum): self.signum = signum > def __repr__(self): return '+oo' if self.signum > 0 else '-oo' > def __lt__(self,other): return False if self.signum > 0 else True > def __le__(self,other): return False if self.signum > 0 else True > def __gt__(self,other): return True if self.signum > 0 else False > def __ge__(self,other): return True if self.signum > 0 else False > def __eq__(self,other): return isinstance(other,infinity) and self.signum == other.signum In Python, it's normal to name classes with a capital first letter, so "class Infinity" would be more normal. Instead of "True if some_condition else False", you can simply write "some_condition", and instead of "False if some_condition else True", you can write "not some_condition". > def getlines(board): > horizontal = [[(i, j+k) for k in range(4)] for i in range(6) for j in range(7)] > vertical = [[(i+k, j) for k in range(4)] for i in range(6) for j in range(7)] > positive = [[(i+k, j+k) for k in range(4)] for i in range(6) for j in range(7)] > negative = [[(i+k, j-k) for k in range(4)] for i in range(6) for j in range(7)] > linear = horizontal + vertical + positive + negative > lines = [line for line in linear if all(i in range(6) and j in range(7) for (i,j) in line)] > return [[board[square] for square in line] for line in lines] Lining up your code vertically just looks ugly if you change to a different font. I wouldn't bother, personally. This is the kind of function that needs a docstring and some comments. What exactly is this doing? What are the "lines" of the board? What's the difference between "linear" and "lines"? What exactly is it returning? > def getwinner(board): > lines = getlines(board) > return ex if [ex]*4 in lines else oh if [oh]*4 in lines else None You seem to have fallen in love with the ternary 'if' expression. While it's normal for young lovers to shower each other with affection, it tends to get awkward for those watching you. I would recommend breaking some of these into straight-forward 'if' statements. > def getmover(board): > boardvalues = list(board.values()) > return ex if boardvalues.count(ex)==boardvalues.count(oh) else oh This is a very expensive way to avoid maintaining a "whose turn is it, anyway?" variable. > def getoptimum(mover): > return max if mover == ex else min I *think* this might be a critical part of your algorithm, but again, in the absence of explanatory information, I can't be sure. Are you following a basic minimax algorithm, where you assume that your opponent will always play optimally, and you attempt to minimize your potential losses? If so, definitely needs to be stated somewhere. (Also, if that's the case, your code is probably locked down to having the AI always playing the same side. Again, that needs to be stated clearly.) > def getvalue(winner,accessibles): > return infinity(+1) if winner == ex else infinity(-1) if winner == oh else 0 if not accessibles else None Uhhhhh.... I don't even know what this is doing. Value of what? Why so much if/else in a single expression? > def heuristicvalue(board,depth): > winner = getwinner(board) > accessibles = getaccessibles(board) > value = getvalue(winner,accessibles) > if value != None: return value > if depth == 0: return guessvalue(board) > mover = getmover(board) > optimum = getoptimum(mover) > children = [makemove(board,column,mover) for column in accessibles] > return optimum(heuristicvalue(child,depth-1) for child in children) Anything with "heuristic" in the name is probably an important part of your algorithm. But I've looked at the code and I don't understand what it's doing. > def getmoves(board,depth): > accessibles = getaccessibles(board) > if not accessibles: return [] > mover = getmover(board) > optimum = getoptimum(mover) > children = [makemove(board,column,mover) for column in accessibles] > values = [heuristicvalue(child,depth) for child in children] > bestvalue = optimum(values) > return [accessibles[index] for index in range(len(accessibles)) if values[index] == bestvalue] And this looks very similar to the previous one. Or at least, there are several identical lines. Hmm. > [self.grid.squarebuttons[number].config(background=self.board[divmod(number,7)]) for number in range(42)] Hrm. If this is the whole line of code, it's a list comp that discards its result. If so, it would be far better written as a straight-forward loop. General summary of all of the above comments: Assume that you have to collaborate with another programmer, and try to make his/her life easy. You'll appreciate it six months from now, by which time you will yourself be a different programmer, with no memory of what you were doing as you wrote this :) All the best! ChrisA From mikhailwas at gmail.com Fri Nov 24 11:33:30 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Fri, 24 Nov 2017 17:33:30 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Fri, Nov 24, 2017 at 8:03 AM, Chris Angelico wrote: >> and in Python in particular, because they will be not only forced to learn >> some english, but also will have all 'pleasures' of multi-script editing. >> But wait, probably one can write python code in, say Arabic script *only*? >> How about such feature proposal? > > If Python supports ASCII identifiers only, people have no choice but > to transliterate. As it is, people get to choose which is better for > them - to transliterate or not to transliterate, that is the > readability question. Sure, let them choose. Transliteration though is way more reasonable solution. > >> As for non-english speaker who know some English already, >> could of course want to include identifiers in those scripts. >> But how about libraries? > > If you want to use numpy, you have to understand the language of > numpy. That's a lot of technical jargon, so even if you understand > English, you have to learn that. So there's ultimately no difference. That's what I'm saying. There will be anyway major parts of code in English and pretty much every already existing modules that can further help the developer will be in English, like it or not. >> Ok, so we return back to my original question: apart from >> ability to do so, how beneficial is it on a pragmatical basis? >> I mean, e.g. Cyrillic will introduce homoglyph issues. >> CJK and Arabic scripts are metrically and optically incompatible with >> latin, so such mixing will end up with messy look. So just for >> the experiment, yes, it's fun. > > Does it really introduce homoglyph issues in real-world situations, > though? Are there really cases where people can't figure out from > context what's going on? I haven't seen that happening. Usually there > are *entire words* (and more) in a single language, making it pretty > easy to figure out. The issues can be discussed long, but I have no doubt that even placing words in two different scripts on one text line is a bad idea, not only for source code. For mixing Cyrillic+Latin, yes, this also causes extra issues due to homoglyphs in many cases, I know it practically from everyday work with Cyrillic filenames, and from past experience with English-Russian textbooks. In textbooks at least I can help it by proper layout - separating them in tables, or putting in quotes or bold for inline usage. Mikhail From ian.g.kelly at gmail.com Fri Nov 24 11:35:57 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 24 Nov 2017 09:35:57 -0700 Subject: Why does asyncio.wait_for() need a timeout? In-Reply-To: References: Message-ID: On Fri, Nov 24, 2017 at 6:31 AM, Frank Millman wrote: > "Frank Millman" wrote in message news:ov5v3s$bv7$1 at blaine.gmane.org... > >> Below is a simple asyncio loop that runs two background tasks. >> > [...] >> >> >> Both take an optional timeout. >> >> If I use the first method without a timeout, the cancellation completes >> and the loop stops. >> >> If I use the second method without a timeout, the future is cancelled, but >> the program hangs. >> >> If I add a timeout to the second one, it behaves the same as the first >> one. >> >> Is there a reason for this? >> > > I have figured out half of the answer. > > 'timeout' is an optional argument when using wait(), but a required one when > using wait_for(). > > Therefore asyncio is raising an exception. > > However, I do not understand why no traceback appears. Here's the output I get when I try it and then interrupt with Ctrl-C: $ python3 test.py >From 1: 1 >From 2: 1 >From 1: 2 >From 2: 2 >From 1: 3 >From 2: 3 >From 1: 4 >From 2: 4 >From 1: 5 >From 2: 5 >From 1: 6 counter1 cancelled ^CTraceback (most recent call last): File "test.py", line 27, in loop.run_forever() File "/usr/lib/python3.5/asyncio/base_events.py", line 345, in run_forever self._run_once() File "/usr/lib/python3.5/asyncio/base_events.py", line 1276, in _run_once event_list = self._selector.select(timeout) File "/usr/lib/python3.5/selectors.py", line 441, in select fd_event_list = self._epoll.poll(timeout, max_ev) KeyboardInterrupt Task exception was never retrieved future: exception=TypeError("wait_for() missing 1 required positional argument: 'timeout'",)> Traceback (most recent call last): File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step result = coro.send(None) File "test.py", line 20, in counter2 await asyncio.wait_for(cnt1) # hangs TypeError: wait_for() missing 1 required positional argument: 'timeout' The unhandled exception is shown as a warning when the loop exits. It can't be shown prior to that because there could be some other task, even one that hasn't been scheduled yet, that might try to get the result of the counter2 task and handle the exception. From rosuav at gmail.com Fri Nov 24 11:37:40 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Nov 2017 03:37:40 +1100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Sat, Nov 25, 2017 at 3:33 AM, Mikhail V wrote: > On Fri, Nov 24, 2017 at 8:03 AM, Chris Angelico wrote: > >>> and in Python in particular, because they will be not only forced to learn >>> some english, but also will have all 'pleasures' of multi-script editing. >>> But wait, probably one can write python code in, say Arabic script *only*? >>> How about such feature proposal? >> >> If Python supports ASCII identifiers only, people have no choice but >> to transliterate. As it is, people get to choose which is better for >> them - to transliterate or not to transliterate, that is the >> readability question. > > Sure, let them choose. > Transliteration though is way more reasonable solution. That right there has settled it: you agree that identifiers have to use the broader Unicode set, not limited to ASCII. Otherwise they can't choose. Everything else is down to style guides; the language MUST support all alphabets so that people have this choice. ChrisA From ian.g.kelly at gmail.com Fri Nov 24 11:40:48 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 24 Nov 2017 09:40:48 -0700 Subject: Why does asyncio.wait_for() need a timeout? In-Reply-To: References: Message-ID: On Fri, Nov 24, 2017 at 9:35 AM, Ian Kelly wrote: > On Fri, Nov 24, 2017 at 6:31 AM, Frank Millman wrote: >> "Frank Millman" wrote in message news:ov5v3s$bv7$1 at blaine.gmane.org... >> >>> Below is a simple asyncio loop that runs two background tasks. >>> >> [...] >>> >>> >>> Both take an optional timeout. >>> >>> If I use the first method without a timeout, the cancellation completes >>> and the loop stops. >>> >>> If I use the second method without a timeout, the future is cancelled, but >>> the program hangs. >>> >>> If I add a timeout to the second one, it behaves the same as the first >>> one. >>> >>> Is there a reason for this? >>> >> >> I have figured out half of the answer. >> >> 'timeout' is an optional argument when using wait(), but a required one when >> using wait_for(). >> >> Therefore asyncio is raising an exception. >> >> However, I do not understand why no traceback appears. > > Here's the output I get when I try it and then interrupt with Ctrl-C: > > $ python3 test.py > From 1: 1 > From 2: 1 > From 1: 2 > From 2: 2 > From 1: 3 > From 2: 3 > From 1: 4 > From 2: 4 > From 1: 5 > From 2: 5 > From 1: 6 > counter1 cancelled > ^CTraceback (most recent call last): > File "test.py", line 27, in > loop.run_forever() > File "/usr/lib/python3.5/asyncio/base_events.py", line 345, in run_forever > self._run_once() > File "/usr/lib/python3.5/asyncio/base_events.py", line 1276, in _run_once > event_list = self._selector.select(timeout) > File "/usr/lib/python3.5/selectors.py", line 441, in select > fd_event_list = self._epoll.poll(timeout, max_ev) > KeyboardInterrupt > Task exception was never retrieved > future: > exception=TypeError("wait_for() missing 1 required positional > argument: 'timeout'",)> > Traceback (most recent call last): > File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step > result = coro.send(None) > File "test.py", line 20, in counter2 > await asyncio.wait_for(cnt1) # hangs > TypeError: wait_for() missing 1 required positional argument: 'timeout' > > > The unhandled exception is shown as a warning when the loop exits. It > can't be shown prior to that because there could be some other task, > even one that hasn't been scheduled yet, that might try to get the > result of the counter2 task and handle the exception. By the way, this is what you get instead when you replace run_forever() with run_until_complete(cnt2): $ python3 test.py >From 1: 1 >From 2: 1 >From 1: 2 >From 2: 2 >From 1: 3 >From 2: 3 >From 1: 4 >From 2: 4 >From 1: 5 >From 2: 5 >From 1: 6 counter1 cancelled Traceback (most recent call last): File "test.py", line 27, in loop.run_until_complete(cnt2) File "/usr/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete return future.result() File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result raise self._exception File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step result = coro.send(None) File "test.py", line 20, in counter2 await asyncio.wait_for(cnt1) # hangs TypeError: wait_for() missing 1 required positional argument: 'timeout' No need for Ctrl-C in this case because the loop notices that counter2 died and stops on its own, and you get a nice traceback explaining what happened. From skip.montanaro at gmail.com Fri Nov 24 11:41:06 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 24 Nov 2017 10:41:06 -0600 Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: <85r2souy6e.fsf_-_@benfinney.id.au> References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> Message-ID: > Because if I already can't understand the words, it will be more useful > to me to be able to type them reliably at a keyboard, for replication, > search, discussion with others about the code, etc. I am probably not alone in my Americo-centric world where I can't even easily type accented Latin-1 characters. I happen to be using Linux as I type this, but type at a Windows keyboard at work (ugh) and have long been a user of Macs (still have one or two at home). Might the problem be further multiplied by the number of different ways I have of entering text? Would Emacs running on Linux, but displaying on Windows be different than Chrome running directly on Linux? I will make a wild-ass guess and suggest that maybe, just maybe, those three major system types have different ways of typing accented characters. Consequently, I've never even tried to learn any of them. On the rare instance where I need to type an accented character, such as when typing Marc-Andr? Lemburg's name properly, I ask Google for "accented e" and copy/paste an instance. That's a PITA, but worth it on the few occasions where I need it today. I suppose I would have to break down and learn how to properly enter such text should I need to Romanized text which might contain cedillas, accents and other diacritical marks... This is all not to suggest the goal isn't worth striving for, just that there exists a huge barrier - in the form of ASCII and its limiting effect on computer keyboard entry - to attaining Unicode identifier Nirvana. Perhaps for my next computer I should choose a non-ASCII keyboard option when configuring it. Skip From Richard at Damon-Family.org Fri Nov 24 12:10:49 2017 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 24 Nov 2017 12:10:49 -0500 Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> Message-ID: <52b7d5d2-e7d5-752a-d6b8-0f3cc5d79919@Damon-Family.org> On 11/24/17 11:41 AM, Skip Montanaro wrote: >> Because if I already can't understand the words, it will be more useful >> to me to be able to type them reliably at a keyboard, for replication, >> search, discussion with others about the code, etc. > I am probably not alone in my Americo-centric world where I can't even > easily type accented Latin-1 characters. I happen to be using Linux as > I type this, but type at a Windows keyboard at work (ugh) and have > long been a user of Macs (still have one or two at home). Might the > problem be further multiplied by the number of different ways I have > of entering text? Would Emacs running on Linux, but displaying on > Windows be different than Chrome running directly on Linux? I will > make a wild-ass guess and suggest that maybe, just maybe, those three > major system types have different ways of typing accented characters. > Consequently, I've never even tried to learn any of them. On the rare > instance where I need to type an accented character, such as when > typing Marc-Andr? Lemburg's name properly, I ask Google for "accented > e" and copy/paste an instance. > > That's a PITA, but worth it on the few occasions where I need it > today. I suppose I would have to break down and learn how to properly > enter such text should I need to Romanized text which might contain > cedillas, accents and other diacritical marks... > > This is all not to suggest the goal isn't worth striving for, just > that there exists a huge barrier - in the form of ASCII and its > limiting effect on computer keyboard entry - to attaining Unicode > identifier Nirvana. Perhaps for my next computer I should choose a > non-ASCII keyboard option when configuring it. > > Skip I find it it interesting that the primary reason to want to limit the character set to ASCII is people thinking that it would make it hard for *them* to read/use the code, but no thought about how much harder it makes it on the original author/team to write code that is easily understood by THEM. Yes, code intended to be used by the broad community would be best to adhere to the community standard (and the community style guide should, if it doesn't already, have a rule about this). Code intended for internal usage is best to be as well understood by that group as possible. Some also bring up some of the issues with similar glyphs, as if we don't already have issues with things like 0 and O, 1 and l and I (depending on the font you use). This mostly comes down to self-inflicted pain, which can mostly be relieved with a style rule to avoid multi-language identifiers, perhaps checked with a special 'linter'. Since Python is white space sensitive, we already have the issue with the distinction between space and tab, which isn't normally obvious in many text editors (Though I suspect many Python programmers have their editors configured to largely avoid the issue). -- Richard Damon From skip.montanaro at gmail.com Fri Nov 24 12:19:05 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 24 Nov 2017 09:19:05 -0800 (PST) Subject: Test, test, test Message-ID: <6d7e6b7e-0492-4a89-88c5-439241dae524@googlegroups.com> Testing 1 2 3 ... (you can ignore) def gen_dotted_quad_clues(pfx, ips): for ip in ips: yield "%s:%s/32" % (pfx, ip) dottedQuadList = ip.split(".") if len(dottedQuadList) >= 1: yield "%s:%s/8" % (pfx, dottedQuadList[0]) if len(dottedQuadList) >= 2: yield "%s:%s.%s/16" % (pfx, dottedQuadList[0], dottedQuadList[1]) if len(dottedQuadList) >= 3: yield "%s:%s.%s.%s/24" % (pfx, dottedQuadList[0], dottedQuadList[1], dottedQuadList[2]) Skip From rantingrickjohnson at gmail.com Fri Nov 24 12:22:36 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 24 Nov 2017 09:22:36 -0800 (PST) Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> Message-ID: On Thursday, November 23, 2017 at 9:57:12 PM UTC-6, Ben Finney wrote: [...] > This is a necessary consequence of increasing the diversity > of people able to program in Python: people will express > ideas originating in their own language, in Python code. > For that diversity to increase, we English-fluent folk will > necessarily become a smaller proportion of the programming > community than we are today. That might be uncomfortable > for us, but it is a necessary adaptation the community > needs to undergo. Will your heroic crusade to bring equality to the shire also include Python standard library modules written in languages other than English? If so, then you'll need to contact Guido, as PEP8 will require some editing. Speaking of GvR... And even if you did managed to bring multilingualism to Python scripts and std-lib modules, wouldn't such "diversity" be merely symbolic? Hmm, because, when we consider the make-up of pydev (aka: nothing but English speaking dudes) we realize that there really isn't any diversity at all. At least, not where it matters. (aka: where the decision are being made) Furthermore, if we are to march headlong onto the glorious battlefields of diversity and equality, for the sake of all else, then, why should Guido's position be off limits? I mean, sure, he may a brilliant man. But he's surely not the most brilliant man on this planet, is he? And with that liberating thought in mind, may i offer an excerpt, for your intellectual consumption, from one of the most famous documents of all time? (emphasis mine) "Prudence, indeed, will dictate that governments long established should not be changed for light and transient causes; and accordingly, all experience hath shewn, that [humankind] are more disposed to _suffer_ while evils are _sufferable_, than to right themselves by abolishing the forms to which they are "accustomed"; but when a ~long~ train of abuses and usurpations, pursuing invariably the same object, evinces a _design_ to reduce them under absolute *DESPOTISM* -- It is their *RIGHT*! It is their *DUTY*! -- to throw off such government and to provide new guards for their future security" ...Declaration of Independence: July 4, 1776 I'm of the opinion that diversity is fine, so long as you don't make the fatal mistake of "lopping off your nose to spite your face". Take, for example, the accommodations our societies offer for handicapped people -- from wheel chair ramps, to reserved front-row parking spaces, to widened doorways, etc... -- these accommodations do *NOT*, in any way, undermine the accessability of healthy people who also utilize these same public spaces. In fact, the worst consequence of these accommodations might be that you and i must walk a few more steps from our car to the market. Big deal! But what you are suggesting is not so much an _accommodation_, as it is a fundamental fissure in our ability to communicate, one that will fracture the community far more than it is today. It would be as foolish as mandating that everyone must have their legs lopped-off, so that all will be "equal". Yes, diversity is great! But only when it welcomes outsiders without undermining the practical cohesiveness of the wider community. And if the result of your little "inclusivity project" is merely the replacement of N domestic community members with N foreign community members, foreigners who's regional dialects will muck-up the communication process, then it seems to me that what you have gained is merely a fulfillment of your _own_ emotional needs, at the expense of all. In conclusion. While a wise student of knowledge recognizes that: (1) social groups who have waxed into a homogenous block actually undermine themselves, because they lack the essential diversity of ideas required to see beyond the walls of their own "box", and the confirmation bias that infests such societies, will ensure that such a community is an evolutionary dead end. The same student _also_ recognizes that: (2) a society which resembles a jig-saw-puzzle dumped haphazardly on the floor, lacks the essential _cohesiveness_ required to maintain a strong sense of _community_, a sense which allows multiple individuals to work towards a common goal, in manner this is both practical and efficient. Something to think about. From skip.montanaro at gmail.com Fri Nov 24 12:35:01 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 24 Nov 2017 11:35:01 -0600 Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: <52b7d5d2-e7d5-752a-d6b8-0f3cc5d79919@Damon-Family.org> References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <52b7d5d2-e7d5-752a-d6b8-0f3cc5d79919@Damon-Family.org> Message-ID: > I find it it interesting that the primary reason to want to limit the > character set to ASCII is people thinking that it would make it hard for > *them* to read/use the code, but no thought about how much harder it makes > it on the original author/team to write code that is easily understood by > THEM. I think you misunderstood my post. For that I apologize that I wasn't clear. I was only pointing out that there is a ton of inertia based on the long dominance of ASCII (and before that EBCDIC) and its downstream effects on computer entry systems. I know that there are likely semi-reasonable ways to enter accented characters on my keyboard, but they are unknown to me, and will likely be different on the different systems I use, so I've not bothered to learn any of them. One thing which occurred to me as I was typing my earlier message, but which I failed to include... I wonder if when you go to Dell (for example) to configure a computer, you can easily specify a non-ASCII keyboard for a machine destined for delivery to the US. Maybe it's trivial, but maybe it's just enough more difficult (slows delivery, costs a few bucks more, which of the alternatives should you choose?) that people think, "Ah hell, might as well just go with the ASCII keyboard." I'm clearly in the old fart camp at this point. Perhaps American software engineers half my age aren't afflicted by my career-long biases. Skip From Richard at Damon-Family.org Fri Nov 24 13:00:06 2017 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 24 Nov 2017 13:00:06 -0500 Subject: Increasing the diversity of people who write Python In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <52b7d5d2-e7d5-752a-d6b8-0f3cc5d79919@Damon-Family.org> Message-ID: On 11/24/17 12:35 PM, Skip Montanaro wrote: >> I find it it interesting that the primary reason to want to limit the >> character set to ASCII is people thinking that it would make it hard for >> *them* to read/use the code, but no thought about how much harder it makes >> it on the original author/team to write code that is easily understood by >> THEM. > I think you misunderstood my post. For that I apologize that I wasn't clear. > > I was only pointing out that there is a ton of inertia based on the > long dominance of ASCII (and before that EBCDIC) and its downstream > effects on computer entry systems. I know that there are likely > semi-reasonable ways to enter accented characters on my keyboard, but > they are unknown to me, and will likely be different on the different > systems I use, so I've not bothered to learn any of them. > > One thing which occurred to me as I was typing my earlier message, but > which I failed to include... I wonder if when you go to Dell (for > example) to configure a computer, you can easily specify a non-ASCII > keyboard for a machine destined for delivery to the US. Maybe it's > trivial, but maybe it's just enough more difficult (slows delivery, > costs a few bucks more, which of the alternatives should you choose?) > that people think, "Ah hell, might as well just go with the ASCII > keyboard." > > I'm clearly in the old fart camp at this point. Perhaps American > software engineers half my age aren't afflicted by my career-long > biases. > > Skip > I doubt I am 1/2 your age (are you 120 yet?). The keyboard I normally use would be very hard to use for foreign characters, but I do understand that if I wanted to, I could easily get a keyboard designed for use in any other language. Some would take some training to learn how to use (like a Chinese keyboard). The fact that I was pointing out is that the fact that people are arguing that because *THEY* would have difficulty working with a code base (that they likely would never actually need access to) is a good reason from preventing others, who already HAVE the needed hardware/training from being able to make the code more readable to them. As far as the basic ability to enter arbitrary characters,? most OSes have a generic entry method (like windows ALT-numbers method) and I think most have a character selector app to add arbitrary characters to the clipboard. Yes, this may not be very convenient for a lot of use but is possible. Also, it is generally possible to select an alternate keyboard map for your keyboard to enter other characters, you then just need to know (or have printed) the new mapping of the keyboard. It helps if you do this to have learned the new mapping, and how to touch type on that keyboard. Generally you can also get Keyboard Stickers to place on your keyboard if you are a hunt and pecker typist. -- Richard Damon From formisc at gmail.com Fri Nov 24 14:54:01 2017 From: formisc at gmail.com (Andrew Z) Date: Fri, 24 Nov 2017 14:54:01 -0500 Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> Message-ID: Thank you Rick for well thought out argument. On Nov 24, 2017 12:44, "Rick Johnson" wrote: > On Thursday, November 23, 2017 at 9:57:12 PM UTC-6, Ben Finney wrote: > [...] > > This is a necessary consequence of increasing the diversity > > of people able to program in Python: people will express > > ideas originating in their own language, in Python code. > > For that diversity to increase, we English-fluent folk will > > necessarily become a smaller proportion of the programming > > community than we are today. That might be uncomfortable > > for us, but it is a necessary adaptation the community > > needs to undergo. > > Will your heroic crusade to bring equality to the shire also > include Python standard library modules written in languages > other than English? If so, then you'll need to contact > Guido, as PEP8 will require some editing. > > Speaking of GvR... > > And even if you did managed to bring multilingualism to > Python scripts and std-lib modules, wouldn't such > "diversity" be merely symbolic? > > Hmm, because, when we consider the make-up of pydev (aka: > nothing but English speaking dudes) we realize that there > really isn't any diversity at all. At least, not where it > matters. (aka: where the decision are being made) > > Furthermore, if we are to march headlong onto the glorious > battlefields of diversity and equality, for the sake of all > else, then, why should Guido's position be off limits? I > mean, sure, he may a brilliant man. But he's surely not the > most brilliant man on this planet, is he? > > And with that liberating thought in mind, may i offer an > excerpt, for your intellectual consumption, from one of the > most famous documents of all time? > > (emphasis mine) > > "Prudence, indeed, will dictate that governments long > established should not be changed for light and transient > causes; and accordingly, all experience hath shewn, that > [humankind] are more disposed to _suffer_ while evils are > _sufferable_, than to right themselves by abolishing the > forms to which they are "accustomed"; but when a ~long~ > train of abuses and usurpations, pursuing invariably the > same object, evinces a _design_ to reduce them under > absolute *DESPOTISM* -- It is their *RIGHT*! It is their > *DUTY*! -- to throw off such government and to provide new > guards for their future security" > > ...Declaration of Independence: July 4, 1776 > > I'm of the opinion that diversity is fine, so long as you > don't make the fatal mistake of "lopping off your nose to > spite your face". > > Take, for example, the accommodations our societies offer > for handicapped people -- from wheel chair ramps, to > reserved front-row parking spaces, to widened doorways, > etc... -- these accommodations do *NOT*, in any way, > undermine the accessability of healthy people who also utilize > these same public spaces. In fact, the worst consequence of > these accommodations might be that you and i must walk a few > more steps from our car to the market. > > Big deal! > > But what you are suggesting is not so much an > _accommodation_, as it is a fundamental fissure in our > ability to communicate, one that will fracture the community > far more than it is today. It would be as foolish as > mandating that everyone must have their legs lopped-off, so > that all will be "equal". > > Yes, diversity is great! But only when it welcomes outsiders > without undermining the practical cohesiveness of the wider > community. And if the result of your little "inclusivity > project" is merely the replacement of N domestic community > members with N foreign community members, foreigners who's > regional dialects will muck-up the communication process, > then it seems to me that what you have gained is merely a > fulfillment of your _own_ emotional needs, at the expense of > all. > > In conclusion. > > While a wise student of knowledge recognizes that: > > (1) social groups who have waxed into a homogenous block > actually undermine themselves, because they lack the > essential diversity of ideas required to see beyond the > walls of their own "box", and the confirmation bias that > infests such societies, will ensure that such a community is > an evolutionary dead end. > > The same student _also_ recognizes that: > > (2) a society which resembles a jig-saw-puzzle dumped > haphazardly on the floor, lacks the essential _cohesiveness_ > required to maintain a strong sense of _community_, a sense > which allows multiple individuals to work towards a common > goal, in manner this is both practical and efficient. > > Something to think about. > > -- > https://mail.python.org/mailman/listinfo/python-list > From mikhailwas at gmail.com Fri Nov 24 15:00:32 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Fri, 24 Nov 2017 21:00:32 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Fri, Nov 24, 2017 at 5:37 PM, Chris Angelico wrote: > On Sat, Nov 25, 2017 at 3:33 AM, Mikhail V wrote: >> On Fri, Nov 24, 2017 at 8:03 AM, Chris Angelico wrote: >> >>>> and in Python in particular, because they will be not only forced to learn >>>> some english, but also will have all 'pleasures' of multi-script editing. >>>> But wait, probably one can write python code in, say Arabic script *only*? >>>> How about such feature proposal? >>> >>> If Python supports ASCII identifiers only, people have no choice but >>> to transliterate. As it is, people get to choose which is better for >>> them - to transliterate or not to transliterate, that is the >>> readability question. >> >> Sure, let them choose. >> Transliteration though is way more reasonable solution. > > That right there has settled it: you agree that identifiers have to > use the broader Unicode set, not limited to ASCII. Otherwise they > can't choose. Everything else is down to style guides; the language > MUST support all alphabets so that people have this choice. That's a valid and somewhat obvious point. I agree that one should have more choices, but people still can't really choose many things. I can't choose hyphen, I can't choose minus sign, and many tech people would probably want more operators. It counts probably not so *big* amount of people, compared to *all* people that potentially would say "oh how wonderful is it to be able to write in various scripts", still it is just a "use it at your own risk" thing at a minimum, and merely based on emotions rather than common sense. Regardless of what Unicode decides for classifications, there simply must be careful analysis how the major *Python* code actually looks in the end of all experiments. Especially true for characters in regard identifiers versus operators. Mikhail From rosuav at gmail.com Fri Nov 24 15:08:09 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Nov 2017 07:08:09 +1100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Sat, Nov 25, 2017 at 7:00 AM, Mikhail V wrote: > I agree that one should have more choices, but > people still can't really choose many things. > I can't choose hyphen, I can't choose minus sign, > and many tech people would probably want more operators. > It counts probably not so *big* amount of people, compared to *all* > people that potentially would say "oh how wonderful is it to be able > to write in various scripts", still it is just a "use it at your own risk" > thing at a minimum, and merely based on emotions rather than > common sense. > > Regardless of what Unicode decides for classifications, there simply must > be careful analysis how the major *Python* code actually looks in the end > of all experiments. Especially true for characters in regard > identifiers versus operators. And it's the "identifiers versus operators" question that is why you can't use hyphen in an identifier. Underscore is available as an ASCII joiner, and there are various non-ASCII joiners available too. Why is hyphen so important? ChrisA From tjreedy at udel.edu Fri Nov 24 15:12:52 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 24 Nov 2017 15:12:52 -0500 Subject: connect four (game) In-Reply-To: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> Message-ID: On 11/24/2017 10:33 AM, namenobodywants at gmail.com wrote: > hi all > > i've just finished my first excursion into artificial intelligence with a game less trivial than tictactoe, and here it is in case anybody can offer criticism/suggestions/etc Since you did not start with tests or write tests as you wrote code, write a test file now. It will probably be at least as long as your current file. You will learn a lot about your code by doing so. -- Terry Jan Reedy From tjreedy at udel.edu Fri Nov 24 15:18:37 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 24 Nov 2017 15:18:37 -0500 Subject: Benefits of unicode identifiers In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <20171124094813.civpfybf44hydeiq@hermes.hilbert.loc> Message-ID: On 11/24/2017 7:12 AM, bartc wrote: >> ? = 3.141; > > That's great. But how do I type it on my keyboard? How do I view someone > else's code on my crappy ASCII text editor? Input is a problem, but for reading, Python comes with a half-way decent Unicode BMP code editor, IDLE. No one needs to use a 'crappy ASCII text editor' for such code. -- Terry Jan Reedy From mikhailwas at gmail.com Fri Nov 24 16:04:15 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Fri, 24 Nov 2017 22:04:15 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Fri, Nov 24, 2017 at 9:08 PM, Chris Angelico wrote: > On Sat, Nov 25, 2017 at 7:00 AM, Mikhail V wrote: >> I agree that one should have more choices, but >> people still can't really choose many things. >> I can't choose hyphen, I can't choose minus sign, >> and many tech people would probably want more operators. >> It counts probably not so *big* amount of people, compared to *all* >> people that potentially would say "oh how wonderful is it to be able >> to write in various scripts", still it is just a "use it at your own risk" >> thing at a minimum, and merely based on emotions rather than >> common sense. >> >> Regardless of what Unicode decides for classifications, there simply must >> be careful analysis how the major *Python* code actually looks in the end >> of all experiments. Especially true for characters in regard >> identifiers versus operators. > > And it's the "identifiers versus operators" question that is why you > can't use hyphen in an identifier. Underscore is available as an ASCII > joiner, and there are various non-ASCII joiners available too. Why is > hyphen so important? Yes I understand this, so it is how Unicode defines joiners. Yeah, debates about the classifications can be hold forever, but one should not forget about the hyphen during these debates. Hyphen is used I think more then six hundreds years as a joiner (or probably some other classification term one prefer). And just comes so it works very well. Among Unicode joiners, middledot reminds of hyphen, but it is not used in typography for this task. So it is not good option and has issues in most fonts (too small or not aligned with lowercase). Often it is used to show up whitespace in editors, so it is kind of 'reserved'. Other joiners in unicode classification - well probably ok for a 1st April proposal. About importance, it was already covered in the proposal. Why it is SO important? It is rhetorical question. Important compared to what? Compared to the question, what one will eat and where sleep tomorrow? Then it is not so important. Mikhail From torriem at gmail.com Fri Nov 24 16:07:00 2017 From: torriem at gmail.com (nospam.Michael Torrie) Date: Sat, 25 Nov 2017 09:07:00 +1200 Subject: connect four (game) Message-ID: <3860907026@f38.n261.z1.binkp.net> On 11/25/2017 06:00 AM, bartc wrote: > And there's a quite lot left of the rest of the program to worry about too! > > If you add 'window()' at the end of the program, then it seems to run on > Python 3. I'd play around with it first before thinking up strategies > for testing it. Actually, no. Unit testing ideally should be done for each and every class as they are being written (before they are written in fact), no matter how small and trivial the class. That way as you compose larger and larger units of code, the chances of things being right is greater compared to doing it the other way around. You may argue that testing doesn't matter for his small game, written for his own education and amusement. The fact is that software in general is of abysmal quality across the boards, and promoting a habit of unit testing is good, even for trivial, home-grown stuff. From torriem at gmail.com Fri Nov 24 16:07:00 2017 From: torriem at gmail.com (nospam.nospam.Michael Torrie) Date: Sat, 25 Nov 2017 09:07:00 +1200 Subject: connect four (game) Message-ID: <3714713356@f38.n261.z1.binkp.net> On 11/25/2017 06:00 AM, bartc wrote: > And there's a quite lot left of the rest of the program to worry about too! > > If you add 'window()' at the end of the program, then it seems to run on > Python 3. I'd play around with it first before thinking up strategies > for testing it. Actually, no. Unit testing ideally should be done for each and every class as they are being written (before they are written in fact), no matter how small and trivial the class. That way as you compose larger and larger units of code, the chances of things being right is greater compared to doing it the other way around. You may argue that testing doesn't matter for his small game, written for his own education and amusement. The fact is that software in general is of abysmal quality across the boards, and promoting a habit of unit testing is good, even for trivial, home-grown stuff. From greg.ewing at canterbury.ac.nz Fri Nov 24 17:06:05 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 25 Nov 2017 11:06:05 +1300 Subject: Python loop and web server (bottle) in the same script (Posting On Python-List Prohibited) In-Reply-To: References: <0ee995bd-40eb-46dd-aa61-1e4b1cee10cf@googlegroups.com> Message-ID: Lawrence D?Oliveiro wrote: > I naturally concluded that you didn?t care about > updates being momentarily held up by a web request in progress--which would > happen anyway if you used threads, at least with CPython. Not necessarily -- the web processing is probably I/O bound, in which case the GIL will likely be released a lot of the time. But if you want to be sure the GIL won't get in the way, you would need to run the web and update tasks in separate processes. -- Greg From Richard at Damon-Family.org Fri Nov 24 17:26:10 2017 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 24 Nov 2017 17:26:10 -0500 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On 11/24/17 4:04 PM, Mikhail V wrote: > On Fri, Nov 24, 2017 at 9:08 PM, Chris Angelico wrote: >> On Sat, Nov 25, 2017 at 7:00 AM, Mikhail V wrote: >>> I agree that one should have more choices, but >>> people still can't really choose many things. >>> I can't choose hyphen, I can't choose minus sign, >>> and many tech people would probably want more operators. >>> It counts probably not so *big* amount of people, compared to *all* >>> people that potentially would say "oh how wonderful is it to be able >>> to write in various scripts", still it is just a "use it at your own risk" >>> thing at a minimum, and merely based on emotions rather than >>> common sense. >>> >>> Regardless of what Unicode decides for classifications, there simply must >>> be careful analysis how the major *Python* code actually looks in the end >>> of all experiments. Especially true for characters in regard >>> identifiers versus operators. >> And it's the "identifiers versus operators" question that is why you >> can't use hyphen in an identifier. Underscore is available as an ASCII >> joiner, and there are various non-ASCII joiners available too. Why is >> hyphen so important? > Yes I understand this, so it is how Unicode defines joiners. > Yeah, debates about the classifications can be > hold forever, but one should not forget about the hyphen during > these debates. Hyphen is used I think more then six hundreds > years as a joiner (or probably some other classification term one prefer). > And just comes so it works very well. > Among Unicode joiners, middledot reminds of hyphen, > but it is not used in typography for this task. So it is not good option > and has issues in most fonts (too small or not aligned with lowercase). > Often it is used to show up whitespace in editors, > so it is kind of 'reserved'. > Other joiners in unicode classification - well probably ok for a 1st April > proposal. > > About importance, it was already covered in the proposal. > Why it is SO important? It is rhetorical question. > Important compared to what? Compared to the question, what > one will eat and where sleep tomorrow? Then it is not so important. > > > Mikhail Have you tried using U+2010 (HYPHEN) ?. It is in the class XID_CONTINUE (in fact it is in XID_START) so should be available. What isn't available is U+002D (HYPHEN-MINUS) - because that is otherwise defined as the subtraction/negation operator. It may make your code harder to read, if your font doesn't make enough of a distinction between those characters -- Richard Damon From mikhailwas at gmail.com Fri Nov 24 17:42:45 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Fri, 24 Nov 2017 23:42:45 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Fri, Nov 24, 2017 at 11:26 PM, Richard Damon wrote: > > Have you tried using U+2010 (HYPHEN) ?. It is in the class XID_CONTINUE (in > fact it is in XID_START) so should be available. > Hi Richard. U+2010 is SyntaxError. 5 days ago I made a proposal on python-ideas, and we have already discussed many aspects including straw-man arguments about fonts,etc Mikhail From ned at nedbatchelder.com Fri Nov 24 17:46:55 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 24 Nov 2017 17:46:55 -0500 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: <95d04188-8b4e-9417-b54c-fd4a4533d4e4@nedbatchelder.com> On 11/24/17 5:26 PM, Richard Damon wrote: > Have you tried using U+2010 (HYPHEN) ?. It is in the class > XID_CONTINUE (in fact it is in XID_START) so should be available. U+2010 isn't allowed in Python 3 identifiers. The rules for identifiers are here: https://docs.python.org/3/reference/lexical_analysis.html#identifiers .?? U+2010 is in category Pd (http://www.fileformat.info/info/unicode/char/2010), which isn't one of the categories allowed in identifiers.? Category Pc (http://www.fileformat.info/info/unicode/category/Pc/list.htm) is allowed, but it doesn't include anything that would look like a hyphen. --Ned. From Richard at Damon-Family.org Fri Nov 24 18:31:28 2017 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 24 Nov 2017 18:31:28 -0500 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: <95d04188-8b4e-9417-b54c-fd4a4533d4e4@nedbatchelder.com> References: <95d04188-8b4e-9417-b54c-fd4a4533d4e4@nedbatchelder.com> Message-ID: <97a566a0-c28d-34ee-d3fe-3a8901fefc36@Damon-Family.org> On 11/24/17 5:46 PM, Ned Batchelder wrote: > On 11/24/17 5:26 PM, Richard Damon wrote: > >> Have you tried using U+2010 (HYPHEN) ?. It is in the class >> XID_CONTINUE (in fact it is in XID_START) so should be available. > > U+2010 isn't allowed in Python 3 identifiers. > > The rules for identifiers are here: > https://docs.python.org/3/reference/lexical_analysis.html#identifiers > .?? U+2010 is in category Pd > (http://www.fileformat.info/info/unicode/char/2010), which isn't one > of the categories allowed in identifiers.? Category Pc > (http://www.fileformat.info/info/unicode/category/Pc/list.htm) is > allowed, but it doesn't include anything that would look like a hyphen. > > --Ned. > > Looks like the site that I looked up characters in XID_CONTINUE/START was incorrect. Looks like not only is U+2010 not in any of the character classes that are put into ID_START or ID_CONTINUE but is in Pattern_Syntax which is explicitly removed from those categories. -- Richard Damon From oladejisteph at gmail.com Fri Nov 24 18:39:34 2017 From: oladejisteph at gmail.com (STEPHINEXT TUTORIALS) Date: Sat, 25 Nov 2017 00:39:34 +0100 Subject: Issues encountered while launching the IDLE of python 3.7 64-bit I downloaded recently. In-Reply-To: References: Message-ID: On Wed, Nov 22, 2017 at 4:29 AM, STEPHINEXT TUTORIALS < oladejisteph at gmail.com> wrote: > Good morning, > I just downloaded the new version 3.7 for my windows operating system > 64-bits on your site. > The error I got while launching the IDLE is shown in the attached Picture. > I installed all the options and tried repairing it as well. > It would be appreciated if you could contact me back about the solution or > for further description. > I would love to get a response and help on the issue. > Thanks. > > I have subscribed to python-list also From nospam.namenobodywants at gmail.com Fri Nov 24 18:58:00 2017 From: nospam.namenobodywants at gmail.com (namenobodywants) Date: Sat, 25 Nov 2017 11:58:00 +1200 Subject: connect four (game) References: <3847240417@f38.n261.z1.binkp.net> Message-ID: <3685063165@f38.n261.z1.binkp.net> On Saturday, November 25, 2017 at 5:00:12 AM UTC-8, bartc wrote: > Actually I've no idea what these tests are supposed to prove. me neither; i think you guys may be getting me out of my depth now > They are to do with one class called 'infinity', which is never used in the rest > of the program apart from one line. > > I established that within a few seconds, and I would concentrate on what > 'infinity' is actually for, rather than go to considerable lengths to > test a class that may not actually be needed. my current version of "infinity" looks like this class Infinity: def __init__(self,signum): self.signum = (+1) if signum > 0 else (-1) def __repr__(self): return '+oo' if self.signum == (+1) else '-oo' def __lt__(self,other): return self.signum == (-1) def __le__(self,other): return self.signum == (-1) def __gt__(self,other): return self.signum == (+1) def __ge__(self,other): return self.signum == (+1) def __eq__(self,other): return isinstance(other,Infinity) and self.signum == other.signum the idea is that there should be exactly one object posinf (positive infinity) that compares as strictly greater than any number ever considered, and exactly one object neginf that compares as strictly less; as the code stands now there is no reason not to use +/-70 in that capacity; the "infinity" class is there so that the game-playing parts of the code (which at present are intentionally as primitive as possible) can be modified more smoothly later; the single place where "infinity" is instantiated is in the function "getvalue", which returns the value of a finished game: def getvalue(winner,accessibles): return Infinity(+1) if winner == ex else Infinity(-1) if winner == oh else 0 if not accessibles else None if ex has won then the value of the game is posinf; if oh has won then it's neginf; if the game is tied (no winner but no accessible columns remaining) then the value of the game is zero; otherwise the game is not finished and its finished value is None peace stm From nospam.nospam.namenobodywants at gmail.com Fri Nov 24 18:58:00 2017 From: nospam.nospam.namenobodywants at gmail.com (namenobodywants) Date: Sat, 25 Nov 2017 11:58:00 +1200 Subject: connect four (game) Message-ID: <1807262675@f38.n261.z1.binkp.net> On Saturday, November 25, 2017 at 5:00:12 AM UTC-8, bartc wrote: > Actually I've no idea what these tests are supposed to prove. me neither; i think you guys may be getting me out of my depth now > They are to do with one class called 'infinity', which is never used in the rest > of the program apart from one line. > > I established that within a few seconds, and I would concentrate on what > 'infinity' is actually for, rather than go to considerable lengths to > test a class that may not actually be needed. my current version of "infinity" looks like this class Infinity: def __init__(self,signum): self.signum = (+1) if signum > 0 else (-1) def __repr__(self): return '+oo' if self.signum == (+1) else '-oo' def __lt__(self,other): return self.signum == (-1) def __le__(self,other): return self.signum == (-1) def __gt__(self,other): return self.signum == (+1) def __ge__(self,other): return self.signum == (+1) def __eq__(self,other): return isinstance(other,Infinity) and self.signum == other.signum the idea is that there should be exactly one object posinf (positive infinity) that compares as strictly greater than any number ever considered, and exactly one object neginf that compares as strictly less; as the code stands now there is no reason not to use +/-70 in that capacity; the "infinity" class is there so that the game-playing parts of the code (which at present are intentionally as primitive as possible) can be modified more smoothly later; the single place where "infinity" is instantiated is in the function "getvalue", which returns the value of a finished game: def getvalue(winner,accessibles): return Infinity(+1) if winner == ex else Infinity(-1) if winner == oh else 0 if not accessibles else None if ex has won then the value of the game is posinf; if oh has won then it's neginf; if the game is tied (no winner but no accessible columns remaining) then the value of the game is zero; otherwise the game is not finished and its finished value is None peace stm From nospam.namenobodywants at gmail.com Fri Nov 24 19:26:00 2017 From: nospam.namenobodywants at gmail.com (namenobodywants) Date: Sat, 25 Nov 2017 12:26:00 +1200 Subject: connect four (game) References: <426816431@f38.n261.z1.binkp.net> Message-ID: <872004468@f38.n261.z1.binkp.net> On Friday, November 24, 2017 at 8:07:07 AM UTC-8, Chris Angelico wrote: > This is the kind of function that needs a docstring and some comments. > What exactly is this doing? What are the "lines" of the board? What's > the difference between "linear" and "lines"? What exactly is it > returning? producing documentation is an extremely difficult task for me, but i've come up with the following: """ makelines(length,numrows,numcolumns) IS THE LIST OF ALL LISTS L, WITH LENGTH length, OF COORDINATES FROM A numrows x numcolumns MATRIX, SUCH THAT THE ENTRIES OF L ALL LIE IN A LINE: LET horizontal BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN A HORIZONTAL LINE LET vertical BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN A VERTICAL LINE LET downward BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN A DOWNWARD-SLOPING DIAGONAL LINE LET upward BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN AN UPWARD-SLOPING DIAGONAL LINE THEN makelines(length,numrows,numcolumns) IS THE UNION OF ALL THE AFOREMENTIONED SETS """ def makelines(length,numrows,numcolumns): horizontal = [[(i, j+k) for k in range(length)] for i in range(numrows) for j in range(numcolumns)] vertical = [[(i+k, j) for k in range(length)] for i in range(numrows) for j in range(numcolumns)] downward = [[(i+k, j+k) for k in range(length)] for i in range(numrows) for j in range(numcolumns)] upward = [[(i+k, j-k) for k in range(length)] for i in range(numrows) for j in range(numcolumns)] linear = horizontal + vertical + downward + upward return [line for line in linear if all(i in range(6) and j in range(7) for (i,j) in line)] def getlines(board): coordlines = makelines(4,6,7) ## GLOBAL return [[board[square] for square in line] for line in coordlines i tried to remove all the superfluous spaces from that, but lining up code vertically is very helpful to me, so i don't think i can really dispense with the practice peace stm From nospam.nospam.namenobodywants at gmail.com Fri Nov 24 19:26:00 2017 From: nospam.nospam.namenobodywants at gmail.com (namenobodywants) Date: Sat, 25 Nov 2017 12:26:00 +1200 Subject: connect four (game) Message-ID: <2636970240@f38.n261.z1.binkp.net> On Friday, November 24, 2017 at 8:07:07 AM UTC-8, Chris Angelico wrote: > This is the kind of function that needs a docstring and some comments. > What exactly is this doing? What are the "lines" of the board? What's > the difference between "linear" and "lines"? What exactly is it > returning? producing documentation is an extremely difficult task for me, but i've come up with the following: """ makelines(length,numrows,numcolumns) IS THE LIST OF ALL LISTS L, WITH LENGTH length, OF COORDINATES FROM A numrows x numcolumns MATRIX, SUCH THAT THE ENTRIES OF L ALL LIE IN A LINE: LET horizontal BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN A HORIZONTAL LINE LET vertical BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN A VERTICAL LINE LET downward BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN A DOWNWARD-SLOPING DIAGONAL LINE LET upward BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN AN UPWARD-SLOPING DIAGONAL LINE THEN makelines(length,numrows,numcolumns) IS THE UNION OF ALL THE AFOREMENTIONED SETS """ def makelines(length,numrows,numcolumns): horizontal = [[(i, j+k) for k in range(length)] for i in range(numrows) for j in range(numcolumns)] vertical = [[(i+k, j) for k in range(length)] for i in range(numrows) for j in range(numcolumns)] downward = [[(i+k, j+k) for k in range(length)] for i in range(numrows) for j in range(numcolumns)] upward = [[(i+k, j-k) for k in range(length)] for i in range(numrows) for j in range(numcolumns)] linear = horizontal + vertical + downward + upward return [line for line in linear if all(i in range(6) and j in range(7) for (i,j) in line)] def getlines(board): coordlines = makelines(4,6,7) ## GLOBAL return [[board[square] for square in line] for line in coordlines i tried to remove all the superfluous spaces from that, but lining up code vertically is very helpful to me, so i don't think i can really dispense with the practice peace stm From nospam.namenobodywants at gmail.com Fri Nov 24 20:57:00 2017 From: nospam.namenobodywants at gmail.com (namenobodywants) Date: Sat, 25 Nov 2017 13:57:00 +1200 Subject: connect four (game) References: <1422173371@f38.n261.z1.binkp.net> Message-ID: <2716551586@f38.n261.z1.binkp.net> On Saturday, November 25, 2017 at 12:48:38 AM UTC-8, Terry Reedy wrote: > I did, and it looks buggy to me. The top and left frame lines are > missing. If I click a square, the bottom square in the column lights > up. But then I have no idea whether those are your intentions or not. i hadn't noticed about the frame lines, but it's the same for me; but i'm hoping you meant to write that the TOP square in a column flashes when you "drop a token" down that column; if you really meant the bottom one then i'm totally baffled that it could be the top one for me and the bottom one for you ... is that something that can happen because of a bug? sorry if you were offended by what i wrote before; i didn't understand what you meant peace stm From nospam.nospam.namenobodywants at gmail.com Fri Nov 24 20:57:00 2017 From: nospam.nospam.namenobodywants at gmail.com (namenobodywants) Date: Sat, 25 Nov 2017 13:57:00 +1200 Subject: connect four (game) Message-ID: <4238832781@f38.n261.z1.binkp.net> On Saturday, November 25, 2017 at 12:48:38 AM UTC-8, Terry Reedy wrote: > I did, and it looks buggy to me. The top and left frame lines are > missing. If I click a square, the bottom square in the column lights > up. But then I have no idea whether those are your intentions or not. i hadn't noticed about the frame lines, but it's the same for me; but i'm hoping you meant to write that the TOP square in a column flashes when you "drop a token" down that column; if you really meant the bottom one then i'm totally baffled that it could be the top one for me and the bottom one for you ... is that something that can happen because of a bug? sorry if you were offended by what i wrote before; i didn't understand what you meant peace stm From nospam.wojtek.mula at gmail.com Fri Nov 24 21:05:00 2017 From: nospam.wojtek.mula at gmail.com (wojtek mula) Date: Sat, 25 Nov 2017 14:05:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode Message-ID: <3687131076@f38.n261.z1.binkp.net> Hi, my goal is to obtain an interpreter that internally uses UCS-2. Such a simple code should print 65535: import sys print sys.maxunicode This is enabled in Windows, but I want the same in Linux. What options have I pass to the configure script? w. From nospam.nospam.wojtek.mula at gmail.com Fri Nov 24 21:05:00 2017 From: nospam.nospam.wojtek.mula at gmail.com (wojtek mula wojtek mula) Date: Sat, 25 Nov 2017 14:05:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode Message-ID: <2056671484@f38.n261.z1.binkp.net> Hi, my goal is to obtain an interpreter that internally uses UCS-2. Such a simple code should print 65535: import sys print sys.maxunicode This is enabled in Windows, but I want the same in Linux. What options have I pass to the configure script? w. From namenobodywants at gmail.com Fri Nov 24 21:05:58 2017 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Fri, 24 Nov 2017 18:05:58 -0800 (PST) Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> Message-ID: <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> On Friday, November 24, 2017 at 12:13:18 PM UTC-8, Terry Reedy wrote: > Since you did not start with tests or write tests as you wrote code, ... why on earth would you assume that? instantiate "window" and you'll see it works exactly as i intended; nobody's asking you to debug code for free; i'm looking for the kind of feedback the other respondent gave peace stm From rosuav at gmail.com Fri Nov 24 21:58:21 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Nov 2017 13:58:21 +1100 Subject: connect four (game) In-Reply-To: <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> Message-ID: On Sat, Nov 25, 2017 at 1:05 PM, wrote: > On Friday, November 24, 2017 at 12:13:18 PM UTC-8, Terry Reedy wrote: > >> Since you did not start with tests or write tests as you wrote code, ... > > why on earth would you assume that? instantiate "window" and you'll see it works exactly as i intended; nobody's asking you to debug code for free; i'm looking for the kind of feedback the other respondent gave > Tests, in this sense, means *automated* tests. Check out the "unittest" module, and perhaps read up on techniques of software testing. ChrisA From ian.g.kelly at gmail.com Fri Nov 24 23:43:09 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 24 Nov 2017 21:43:09 -0700 Subject: connect four (game) In-Reply-To: <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> Message-ID: On Fri, Nov 24, 2017 at 7:05 PM, wrote: > On Friday, November 24, 2017 at 12:13:18 PM UTC-8, Terry Reedy wrote: > >> Since you did not start with tests or write tests as you wrote code, ... > > why on earth would you assume that? instantiate "window" and you'll see it works exactly as i intended; nobody's asking you to debug code for free; i'm looking for the kind of feedback the other respondent gave Since you're being a bit of an ass about it, I took the liberty of writing some tests for you. This only covers the very first class in the file (I don't have all night). Two of the tests pass. The others don't. Since the interface is unclear (is signum allowed to be any signed number, or only +/-1? The ordered comparison methods suggest the former, but __eq__ only works with the latter) I chose to be conservative and only wrote tests with +/-1. Otherwise test_eq would also fail. Please understand the point of this is not to shame you or anything. As you said, we're not going to debug your code for you, but you asked for criticism/suggestions, and I hope to make you see that suggesting you write tests is a very valid and useful criticism of its own. ############################### #) connectfour_test - python 3.6.1 ############################### import unittest from connectfour import infinity class InfinityTest(unittest.TestCase): def test_repr(self): self.assertEqual('+oo', repr(infinity(+1))) self.assertEqual('-oo', repr(infinity(-1))) def test_lt(self): self.assertLess(infinity(-1), infinity(+1)) self.assertFalse(infinity(-1) < infinity(-1)) self.assertFalse(infinity(+1) < infinity(+1)) self.assertFalse(infinity(+1) < infinity(-1)) def test_le(self): self.assertLessEqual(infinity(-1), infinity(+1)) self.assertLessEqual(infinity(-1), infinity(-1)) self.assertLessEqual(infinity(+1), infinity(+1)) self.assertFalse(infinity(+1) <= infinity(-1)) def test_gt(self): self.assertFalse(infinity(-1) > infinity(+1)) self.assertFalse(infinity(-1) > infinity(-1)) self.assertFalse(infinity(+1) > infinity(+1)) self.assertGreater(infinity(+1), infinity(-1)) def test_ge(self): self.assertFalse(infinity(-1) >= infinity(+1)) self.assertGreaterEqual(infinity(-1), infinity(-1)) self.assertGreaterEqual(infinity(+1), infinity(+1)) self.assertGreaterEqual(infinity(+1), infinity(-1)) def test_eq(self): self.assertEqual(infinity(-1), infinity(-1)) self.assertEqual(infinity(+1), infinity(+1)) self.assertNotEqual(infinity(-1), infinity(+1)) self.assertNotEqual(infinity(+1), infinity(-1)) if __name__ == '__main__': unittest.main() From frank at chagford.com Sat Nov 25 00:14:14 2017 From: frank at chagford.com (Frank Millman) Date: Sat, 25 Nov 2017 07:14:14 +0200 Subject: Why does asyncio.wait_for() need a timeout? In-Reply-To: References: Message-ID: "Ian Kelly" wrote in message news:CALwzidmRpFrR5MrEJJyZ+BDgtqLwy-sP+A_ZC6zQ7EBaZ9GUHw at mail.gmail.com... > > On Fri, Nov 24, 2017 at 6:31 AM, Frank Millman wrote: > > "Frank Millman" wrote in message news:ov5v3s$bv7$1 at blaine.gmane.org... > > > >> Below is a simple asyncio loop that runs two background tasks. > >> > > [...] > >> > >> > >> Both take an optional timeout. > >> > >> If I use the first method without a timeout, the cancellation completes > >> and the loop stops. > >> > >> If I use the second method without a timeout, the future is cancelled, > >> but > >> the program hangs. > >> > >> If I add a timeout to the second one, it behaves the same as the first > >> one. > >> > >> Is there a reason for this? > >> > > > > I have figured out half of the answer. > > > > 'timeout' is an optional argument when using wait(), but a required one > > when > > using wait_for(). > > > > Therefore asyncio is raising an exception. > > > > However, I do not understand why no traceback appears. > > Here's the output I get when I try it and then interrupt with Ctrl-C: > > $ python3 test.py > From 1: 1 > From 2: 1 > From 1: 2 > From 2: 2 > From 1: 3 > From 2: 3 > From 1: 4 > From 2: 4 > From 1: 5 > From 2: 5 > From 1: 6 > counter1 cancelled > ^CTraceback (most recent call last): > File "test.py", line 27, in > loop.run_forever() > File "/usr/lib/python3.5/asyncio/base_events.py", line 345, in > run_forever > self._run_once() > File "/usr/lib/python3.5/asyncio/base_events.py", line 1276, in > _run_once > event_list = self._selector.select(timeout) > File "/usr/lib/python3.5/selectors.py", line 441, in select > fd_event_list = self._epoll.poll(timeout, max_ev) > KeyboardInterrupt > Task exception was never retrieved > future: > exception=TypeError("wait_for() missing 1 required positional > argument: 'timeout'",)> > Traceback (most recent call last): > File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step > result = coro.send(None) > File "test.py", line 20, in counter2 > await asyncio.wait_for(cnt1) # hangs > TypeError: wait_for() missing 1 required positional argument: 'timeout' > > > The unhandled exception is shown as a warning when the loop exits. It > can't be shown prior to that because there could be some other task, > even one that hasn't been scheduled yet, that might try to get the > result of the counter2 task and handle the exception. > Thanks, Ian. All is clear now. I was testing on Windows. I have never got Ctrl-C to work on Windows, so I use Ctrl-Pause, which crashes the interpreter and returns immediately, without showing any pending tracebacks. I have now tested my program on Linux, and I get the same result as you. Frank From tjreedy at udel.edu Sat Nov 25 01:49:00 2017 From: tjreedy at udel.edu (nospam.Terry Reedy) Date: Sat, 25 Nov 2017 18:49:00 +1200 Subject: connect four (game) Message-ID: <937017507@f38.n261.z1.binkp.net> On 11/25/2017 4:57 PM, namenobodywants at gmail.com wrote: > On Saturday, November 25, 2017 at 12:48:38 AM UTC-8, Terry Reedy wrote: > >> I did, and it looks buggy to me. The top and left frame lines are >> missing. If I click a square, the bottom square in the column lights >> up. But then I have no idea whether those are your intentions or not. > i hadn't noticed about the frame lines, but it's the same for me; but i'm hoping you meant to write that the TOP square in a column flashes when you "drop a token" down that column; All squares start white. Only the bottom square turns red or black, after perhaps a .3 second delay during which there is some jitter in white squares above, which could be the effect of white flashing white. > if you really meant the bottom one then i'm totally baffled that it could be the top one for me and the bottom one for you ... is that something that can happen because of a bug? I am running on Windows 10 from IDLE (which should not affect your code) with 3.7.0a2 with tk 8.6.6. The OS and tk version could have an effect, though top versus bottom is hard to fathom. -- Terry Jan Reedy From tjreedy at udel.edu Sat Nov 25 01:49:00 2017 From: tjreedy at udel.edu (nospam.nospam.Terry Reedy) Date: Sat, 25 Nov 2017 18:49:00 +1200 Subject: connect four (game) Message-ID: <4166889833@f38.n261.z1.binkp.net> On 11/25/2017 4:57 PM, namenobodywants at gmail.com wrote: > On Saturday, November 25, 2017 at 12:48:38 AM UTC-8, Terry Reedy wrote: > >> I did, and it looks buggy to me. The top and left frame lines are >> missing. If I click a square, the bottom square in the column lights >> up. But then I have no idea whether those are your intentions or not. > i hadn't noticed about the frame lines, but it's the same for me; but i'm hoping you meant to write that the TOP square in a column flashes when you "drop a token" down that column; All squares start white. Only the bottom square turns red or black, after perhaps a .3 second delay during which there is some jitter in white squares above, which could be the effect of white flashing white. > if you really meant the bottom one then i'm totally baffled that it could be the top one for me and the bottom one for you ... is that something that can happen because of a bug? I am running on Windows 10 from IDLE (which should not affect your code) with 3.7.0a2 with tk 8.6.6. The OS and tk version could have an effect, though top versus bottom is hard to fathom. -- Terry Jan Reedy From tjreedy at udel.edu Sat Nov 25 01:59:00 2017 From: tjreedy at udel.edu (nospam.Terry Reedy) Date: Sat, 25 Nov 2017 18:59:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode Message-ID: <1710523438@f38.n261.z1.binkp.net> On 11/25/2017 5:12 PM, Chris Angelico wrote: > On Sun, Nov 26, 2017 at 9:05 AM, wrote: >> Hi, my goal is to obtain an interpreter that internally >> uses UCS-2. Such a simple code should print 65535: >> >> import sys >> print sys.maxunicode >> >> This is enabled in Windows, but I want the same in Linux. >> What options have I pass to the configure script? You must be trying to compile 2.7. There may be Linux distributions that compile this way. If you want to use, or ever encounter, non-BMP chars, using surrogate pairs is problematical. By my reading of the official UCS-2 docs, Python's old 16-bit unicode implementation is not fully compliant. Others have claimed that is it not a UCS-2 implementation. > Why do you want to? What useful value do you have in creating this > buggy interpreter? > Ever since Python 3.3, that has simply not been an > option. The bug has been solved. If you want to seriously work with unicode, many recommend using modern Python. -- Terry Jan Reedy From tjreedy at udel.edu Sat Nov 25 01:59:00 2017 From: tjreedy at udel.edu (nospam.nospam.Terry Reedy) Date: Sat, 25 Nov 2017 18:59:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode Message-ID: <128606313@f38.n261.z1.binkp.net> On 11/25/2017 5:12 PM, Chris Angelico wrote: > On Sun, Nov 26, 2017 at 9:05 AM, wrote: >> Hi, my goal is to obtain an interpreter that internally >> uses UCS-2. Such a simple code should print 65535: >> >> import sys >> print sys.maxunicode >> >> This is enabled in Windows, but I want the same in Linux. >> What options have I pass to the configure script? You must be trying to compile 2.7. There may be Linux distributions that compile this way. If you want to use, or ever encounter, non-BMP chars, using surrogate pairs is problematical. By my reading of the official UCS-2 docs, Python's old 16-bit unicode implementation is not fully compliant. Others have claimed that is it not a UCS-2 implementation. > Why do you want to? What useful value do you have in creating this > buggy interpreter? > Ever since Python 3.3, that has simply not been an > option. The bug has been solved. If you want to seriously work with unicode, many recommend using modern Python. -- Terry Jan Reedy From tjreedy at udel.edu Sat Nov 25 02:55:48 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 25 Nov 2017 02:55:48 -0500 Subject: Issues encountered while launching the IDLE of python 3.7 64-bit I downloaded recently. In-Reply-To: References: Message-ID: On 11/24/2017 6:39 PM, STEPHINEXT TUTORIALS wrote: > On Wed, Nov 22, 2017 at 4:29 AM, STEPHINEXT TUTORIALS < > oladejisteph at gmail.com> wrote: >> I just downloaded the new version 3.7 for my windows operating system >> 64-bits on your site. Does Python itself run? >> The error I got while launching the IDLE How did you try to launch IDLE? >> is shown in the attached Picture. Python-list (and hence the gmane newsgroup mirror) is a no-attachment list. So the picture was detached. Copy and paste the text if you can or re-type the contents of a Windows error box. >> I installed all the options I don't know what this means. -- Terry Jan Reedy From ned at nedbatchelder.com Sat Nov 25 03:21:00 2017 From: ned at nedbatchelder.com (nospam.Ned Batchelder) Date: Sat, 25 Nov 2017 20:21:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode Message-ID: <1882602085@f38.n261.z1.binkp.net> On 11/25/17 5:05 PM, wojtek.mula at gmail.com wrote: > Hi, my goal is to obtain an interpreter that internally > uses UCS-2. Such a simple code should print 65535: > > import sys > print sys.maxunicode > > This is enabled in Windows, but I want the same in Linux. > What options have I pass to the configure script? > You say you want Python 3, but you also say you have maxunicode == 65535 on Windows.? That must be Python 2.? Python 3 always has maxunicode == 1114111. Can you say more about what you need to do? --Ned. From ned at nedbatchelder.com Sat Nov 25 03:21:00 2017 From: ned at nedbatchelder.com (nospam.nospam.Ned Batchelder) Date: Sat, 25 Nov 2017 20:21:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode Message-ID: <4087037947@f38.n261.z1.binkp.net> On 11/25/17 5:05 PM, wojtek.mula at gmail.com wrote: > Hi, my goal is to obtain an interpreter that internally > uses UCS-2. Such a simple code should print 65535: > > import sys > print sys.maxunicode > > This is enabled in Windows, but I want the same in Linux. > What options have I pass to the configure script? > You say you want Python 3, but you also say you have maxunicode == 65535 on Windows.? That must be Python 2.? Python 3 always has maxunicode == 1114111. Can you say more about what you need to do? --Ned. From tjreedy at udel.edu Sat Nov 25 03:48:01 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 25 Nov 2017 03:48:01 -0500 Subject: connect four (game) In-Reply-To: <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> Message-ID: On 11/24/2017 9:05 PM, namenobodywants at gmail.com wrote: > On Friday, November 24, 2017 at 12:13:18 PM UTC-8, Terry Reedy wrote: > >> Since you did not start with tests or write tests as you wrote code, ... that I could tell ... I agree that I should have stuck in a qualifier, such as 'apparently'. > why on earth would you assume that? I inferred (not assumed) that because a) people routinely post code here and on Stackoverflow without including or mentioning runnable automated tests; b) you said 'here it is' without a word about tests; c) your code has no docstrings or other function by function doc, and one can hardly write tests without them. Was I right or are you exceptional? > instantiate "window" and you'll see it works exactly as i intended; I did, and it looks buggy to me. The top and left frame lines are missing. If I click a square, the bottom square in the column lights up. But then I have no idea whether those are your intentions or not. nobody's asking you to debug code for free; i'm looking for the kind of feedback the other respondent gave. I read Chris's answer and intentionally did not repeat. Anyway, I think the best advice I could give you, based on experience writing and reviewing code, if you do not already have complete coverage, is to write (more?) automated tests. -- Terry Jan Reedy From rustompmody at gmail.com Sat Nov 25 03:53:00 2017 From: rustompmody at gmail.com (nospam.Rustom Mody) Date: Sat, 25 Nov 2017 20:53:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode References: <1306011088@f38.n261.z1.binkp.net> Message-ID: <3921711983@f38.n261.z1.binkp.net> On Sunday, November 26, 2017 at 3:43:29 AM UTC+5:30, Chris Angelico wrote: > On Sun, Nov 26, 2017 at 9:05 AM, wojtek.mula wrote: > > Hi, my goal is to obtain an interpreter that internally > > uses UCS-2. Such a simple code should print 65535: > > > > import sys > > print sys.maxunicode > > > > This is enabled in Windows, but I want the same in Linux. > > What options have I pass to the configure script? > > Why do you want to? What useful value do you have in creating this > buggy interpreter? I see that you are familiar with this bug: https://bugs.python.org/issue13153 And I see it or something very close is still buggy in python 3.5 [No it does not allow me to paste an SMP char but if I open a file containing one it crashes and rather messily ? ? no way to close the idle other than killing the shell] No thats not a diatribe against idle; just that its reasonable to want python to support work-arounds for reasonably common bugs in the current unicode-ecosystem From rustompmody at gmail.com Sat Nov 25 03:53:00 2017 From: rustompmody at gmail.com (nospam.nospam.Rustom Mody) Date: Sat, 25 Nov 2017 20:53:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode References: <3523203590@f38.n261.z1.binkp.net> Message-ID: <1777175522@f38.n261.z1.binkp.net> On Sunday, November 26, 2017 at 3:43:29 AM UTC+5:30, Chris Angelico wrote: > On Sun, Nov 26, 2017 at 9:05 AM, wojtek.mula wrote: > > Hi, my goal is to obtain an interpreter that internally > > uses UCS-2. Such a simple code should print 65535: > > > > import sys > > print sys.maxunicode > > > > This is enabled in Windows, but I want the same in Linux. > > What options have I pass to the configure script? > > Why do you want to? What useful value do you have in creating this > buggy interpreter? I see that you are familiar with this bug: https://bugs.python.org/issue13153 And I see it or something very close is still buggy in python 3.5 [No it does not allow me to paste an SMP char but if I open a file containing one it crashes and rather messily ? ? no way to close the idle other than killing the shell] No thats not a diatribe against idle; just that its reasonable to want python to support work-arounds for reasonably common bugs in the current unicode-ecosystem From rustompmody at gmail.com Sat Nov 25 03:53:00 2017 From: rustompmody at gmail.com (nospam.nospam.nospam.Rustom Mody) Date: Sat, 25 Nov 2017 20:53:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode Message-ID: <3575195180@f38.n261.z1.binkp.net> Mody) On Sunday, November 26, 2017 at 3:43:29 AM UTC+5:30, Chris Angelico wrote: > On Sun, Nov 26, 2017 at 9:05 AM, wojtek.mula wrote: > > Hi, my goal is to obtain an interpreter that internally > > uses UCS-2. Such a simple code should print 65535: > > > > import sys > > print sys.maxunicode > > > > This is enabled in Windows, but I want the same in Linux. > > What options have I pass to the configure script? > > Why do you want to? What useful value do you have in creating this > buggy interpreter? I see that you are familiar with this bug: https://bugs.python.org/issue13153 And I see it or something very close is still buggy in python 3.5 [No it does not allow me to paste an SMP char but if I open a file containing one it crashes and rather messily ? ? no way to close the idle other than killing the shell] No thats not a diatribe against idle; just that its reasonable to want python to support work-arounds for reasonably common bugs in the current unicode-ecosystem From martin.schoon at gmail.com Sat Nov 25 04:20:44 2017 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 25 Nov 2017 09:20:44 GMT Subject: Pros and cons of Python sources? Message-ID: Some time ago I was advised that having a Python installation based on several sources (pip and Debian's repos in my case) is not a good idea. I need to tidy up my installation and I don't know what to opt for and what to opt out. What are the pros and cons of the alternatives including the ones I haven't mentioned? Completeness, currency, bugs... /Martin From alister.ware at ntlworld.com Sat Nov 25 04:34:36 2017 From: alister.ware at ntlworld.com (alister) Date: Sat, 25 Nov 2017 09:34:36 GMT Subject: Pros and cons of Python sources? References: Message-ID: On Sat, 25 Nov 2017 09:20:44 +0000, Martin Sch??n wrote: > Some time ago I was advised that having a Python installation based on > several sources (pip and Debian's repos in my case) is not a good idea. > I need to tidy up my installation and I don't know what to opt for and > what to opt out. > > What are the pros and cons of the alternatives including the ones I > haven't mentioned? Completeness, currency, bugs... > > /Martin Personally i would always use the Distro repository first & only use a 3rd party option (including pip) if the package I required was not available this ensures compatibility with the OS. -- I must get out of these wet clothes and into a dry Martini. -- Alexander Woolcott From rustompmody at gmail.com Sat Nov 25 07:33:40 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 25 Nov 2017 04:33:40 -0800 (PST) Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Friday, November 24, 2017 at 12:20:29 AM UTC+5:30, Mikhail V wrote: > Ok, I personally could find some practical usage for that, but > merely for fun. I doubt though that someone with less > typographical experience and overall computer literacy could > really make benefits even for personal usage. > > So - fun is one benefit. And fun is important. But is that the > idea behind it? Are you under-estimating the fun-value? Python 3.5.3 (default, Sep 14 2017, 22:58:41) [GCC 6.3.0 20170406] on linux Type "help", "copyright", "credits" or "license" for more information. >>> python.el: native completion setup loaded >>> A = 1 >>> ? = 2 >>> ? = 3 >>> (A, ?, ?) (1, 2, 3) >>> # And there are 5 other variations on this magic trick >>> # Or if you prefer? >>> A == ? False >>> Now compare with the boring spoilsport called python 2: Python 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> python.el: native completion setup loaded >>> A = 1 >>> ? = 2 File "", line 1 ? = 2 ^ SyntaxError: invalid syntax >>> Personally I feel that there should be a law against languages that disallow the creation of magic tricks!?! From rosuav at gmail.com Sat Nov 25 07:39:27 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Nov 2017 23:39:27 +1100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: On Sat, Nov 25, 2017 at 11:33 PM, Rustom Mody wrote: > Personally I feel that there should be a law against languages that disallow > the creation of magic tricks!?! I agree. The programming language should also ensure that your program will terminate eventually, that it is bug-free (this can actually be done in Python - all you have to do is type-annotate all your functions to return the correct values), and that it is optimally implemented. ChrisA From rustompmody at gmail.com Sat Nov 25 07:41:03 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 25 Nov 2017 04:41:03 -0800 (PST) Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: <337fe31e-e9f9-4ed6-97ef-d5cfbdb381a8@googlegroups.com> On Saturday, November 25, 2017 at 6:03:52 PM UTC+5:30, Rustom Mody wrote: > On Friday, November 24, 2017 at 12:20:29 AM UTC+5:30, Mikhail V wrote: > > Ok, I personally could find some practical usage for that, but > > merely for fun. I doubt though that someone with less > > typographical experience and overall computer literacy could > > really make benefits even for personal usage. > > > > So - fun is one benefit. And fun is important. But is that the > > idea behind it? > > Are you under-estimating the fun-value? > > Python 3.5.3 (default, Sep 14 2017, 22:58:41) > [GCC 6.3.0 20170406] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> python.el: native completion setup loaded > >>> A = 1 > >>> ? = 2 > >>> ? = 3 > >>> (A, ?, ?) > (1, 2, 3) > >>> # And there are 5 other variations on this magic trick > >>> # Or if you prefer? > >>> A == ? > False > >>> > > Now compare with the boring spoilsport called python 2: > > Python 2.7.13 (default, Jan 19 2017, 14:48:08) > [GCC 6.3.0 20170118] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> python.el: native completion setup loaded > >>> A = 1 > >>> ? = 2 > File "", line 1 > ? = 2 > ^ > SyntaxError: invalid syntax > >>> > > Personally I feel that there should be a law against languages that disallow > the creation of magic tricks!?! I should mention also that some languages are even more advanced in their jovialness regarding unicode tricks Haskell: GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help Prelude> let flag = 1 Prelude> let ?ag = 2 Prelude> ?ag == flag False Prelude> (?ag, flag) (2,1) Prelude> Python3 is quite boring by contrast: Python 3.5.3 (default, Sep 14 2017, 22:58:41) [GCC 6.3.0 20170406] on linux Type "help", "copyright", "credits" or "license" for more information. >>> python.el: native completion setup loaded >>> flag = 1 >>> ?ag = 2 >>> ?ag == flag True >>> (?ag, flag) (2, 2) >>> From bc at freeuk.com Sat Nov 25 08:00:05 2017 From: bc at freeuk.com (bartc) Date: Sat, 25 Nov 2017 13:00:05 +0000 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> Message-ID: <6PdSB.41734$Mu.23897@fx02.am4> On 25/11/2017 04:43, Ian Kelly wrote: > On Fri, Nov 24, 2017 at 7:05 PM, wrote: >> On Friday, November 24, 2017 at 12:13:18 PM UTC-8, Terry Reedy wrote: >> >>> Since you did not start with tests or write tests as you wrote code, ... >> >> why on earth would you assume that? instantiate "window" and you'll see it works exactly as i intended; nobody's asking you to debug code for free; i'm looking for the kind of feedback the other respondent gave > > Since you're being a bit of an ass about it, I took the liberty of > writing some tests for you. This only covers the very first class in > the file (I don't have all night). Two of the tests pass. The others > don't. > > Since the interface is unclear (is signum allowed to be any signed > number, or only +/-1? The ordered comparison methods suggest the > former, but __eq__ only works with the latter) I chose to be > conservative and only wrote tests with +/-1. Otherwise test_eq would > also fail. > > Please understand the point of this is not to shame you or anything. > As you said, we're not going to debug your code for you, but you asked > for criticism/suggestions, and I hope to make you see that suggesting > you write tests is a very valid and useful criticism of its own. > > > ############################### > #) connectfour_test - python 3.6.1 > ############################### > > import unittest > > from connectfour import infinity > > > class InfinityTest(unittest.TestCase): > > def test_repr(self): > self.assertEqual('+oo', repr(infinity(+1))) > self.assertEqual('-oo', repr(infinity(-1))) > > def test_lt(self): > self.assertLess(infinity(-1), infinity(+1)) > self.assertFalse(infinity(-1) < infinity(-1)) > self.assertFalse(infinity(+1) < infinity(+1)) > self.assertFalse(infinity(+1) < infinity(-1)) > > def test_le(self): > self.assertLessEqual(infinity(-1), infinity(+1)) > self.assertLessEqual(infinity(-1), infinity(-1)) > self.assertLessEqual(infinity(+1), infinity(+1)) > self.assertFalse(infinity(+1) <= infinity(-1)) > > def test_gt(self): > self.assertFalse(infinity(-1) > infinity(+1)) > self.assertFalse(infinity(-1) > infinity(-1)) > self.assertFalse(infinity(+1) > infinity(+1)) > self.assertGreater(infinity(+1), infinity(-1)) > > def test_ge(self): > self.assertFalse(infinity(-1) >= infinity(+1)) > self.assertGreaterEqual(infinity(-1), infinity(-1)) > self.assertGreaterEqual(infinity(+1), infinity(+1)) > self.assertGreaterEqual(infinity(+1), infinity(-1)) > > def test_eq(self): > self.assertEqual(infinity(-1), infinity(-1)) > self.assertEqual(infinity(+1), infinity(+1)) > self.assertNotEqual(infinity(-1), infinity(+1)) > self.assertNotEqual(infinity(+1), infinity(-1)) > > > if __name__ == '__main__': > unittest.main() Where are your unittests for these unittests? Or is this kind of code immune from testing? Actually I've no idea what these tests are supposed to prove. They are to do with one class called 'infinity', which is never used in the rest of the program apart from one line. I established that within a few seconds, and I would concentrate on what 'infinity' is actually for, rather than go to considerable lengths to test a class that may not actually be needed. And there's a quite lot left of the rest of the program to worry about too! If you add 'window()' at the end of the program, then it seems to run on Python 3. I'd play around with it first before thinking up strategies for testing it. -- bartc From gtibbet27 at msn.com Sat Nov 25 08:09:00 2017 From: gtibbet27 at msn.com (nospam.Greg Tibbet) Date: Sun, 26 Nov 2017 01:09:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! Message-ID: <1412351557@f38.n261.z1.binkp.net> I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit of Java and trying to learn this new-fangled Python language! I've got a small program that uses PIL to create an image, draw some primitives (rectanges, ellipses, etc...) and save it. Works fine... no issues. I've found in the past, the best way to "really learn" the language was to "dig into the guts" and understand it,.. I thought I was making progress, but when looking into the PIL library to see what's going on behind the scenes, I find the following code in ImageDraw.py def ellipse(self, xy, fill=None, outline=None): """Draw an ellipse.""" ink, fill = self._getink(outline, fill) if fill is not None: self.draw.draw_ellipse(xy, fill, 1) <...snipped...> ellipse() uses the method self.draw.draw_ellipse() Okay, fine... but WHERE is draw_ellipse defined?? What magic is happening there? I've searched the entire PIL directory tree, and the ONLY two places draw_ellipse is mentioned are right there in the ellipse() function... WHAT am I missing?? Thanks! -Stumpy (aka Greg) From gtibbet27 at msn.com Sat Nov 25 08:09:00 2017 From: gtibbet27 at msn.com (nospam.nospam.Greg Tibbet) Date: Sun, 26 Nov 2017 01:09:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! Message-ID: <4121135281@f38.n261.z1.binkp.net> I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit of Java and trying to learn this new-fangled Python language! I've got a small program that uses PIL to create an image, draw some primitives (rectanges, ellipses, etc...) and save it. Works fine... no issues. I've found in the past, the best way to "really learn" the language was to "dig into the guts" and understand it,.. I thought I was making progress, but when looking into the PIL library to see what's going on behind the scenes, I find the following code in ImageDraw.py def ellipse(self, xy, fill=None, outline=None): """Draw an ellipse.""" ink, fill = self._getink(outline, fill) if fill is not None: self.draw.draw_ellipse(xy, fill, 1) <...snipped...> ellipse() uses the method self.draw.draw_ellipse() Okay, fine... but WHERE is draw_ellipse defined?? What magic is happening there? I've searched the entire PIL directory tree, and the ONLY two places draw_ellipse is mentioned are right there in the ellipse() function... WHAT am I missing?? Thanks! -Stumpy (aka Greg) From johnpote at jptechnical.co.uk Sat Nov 25 09:10:57 2017 From: johnpote at jptechnical.co.uk (John Pote) Date: Sat, 25 Nov 2017 14:10:57 +0000 Subject: How to shut down a TCPServer serve_forever() loop? Message-ID: Hi all, My problem in summary is that my use of the shutdown() method only shuts down a server after the next TCP request is received. I have a TCP server created in the run() method of a thread. ??? class TCPlistener( Thread ): ? ??? ? def run( self ): ??? ???? ? with socketserver.TCPServer(? ("localhost", 9999), ConnHandler ) as server: ? ??? ? ??? ??? self.server = server ??? ? ??? ? ??? print( "TCP listener on: %s:%d" % ( self.host, self.port ) ) ? ??? ? ??? ??? self.server.serve_forever() ??? ? ??? ? ??? print( "TCPlistener:run() ending" ) ConnHandler is a simple echo class with only a handle() method The main bit of the program is ??? if __name__ == "__main__": ??? ??? serverThrd = TCPlistener() ??? ??? serverThrd.start()??? ??? ??? #start TCP IP server listening ??? ??? print("server started") ??? ??? ch = getche()??? ??? ??? ??? ??? #wait for key press ??? ??? print() ??? ??? serverThrd.server.shutdown() ??? ??? print( "main ending" ) Everying works as expected, numerous connections can be made and the received text is echoed back. The issue is that if I press a key on the keyboard the key is immediately shown on the screen but then the shutdown() call blocks until another TCP connection is made, text is echoed back and only then does serve_forever()return followed by shutdown()returning as can be seen from the console session, >>python36 TCPIPserver.py server started TCP listener on: localhost:9999 q #pressed 'q' key 127.0.0.1 wrote: #Sent some text from PuTTY b'SOME TEXT' TCPlistener:run() ending main ending How can I get shutdown()to shut down the server immediately without waiting for the next TCP connection? Regards, JOhn From nospam.wxjmfauth at gmail.com Sat Nov 25 09:36:00 2017 From: nospam.wxjmfauth at gmail.com (wxjmfauth) Date: Sun, 26 Nov 2017 02:36:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode References: <3921711983@f38.n261.z1.binkp.net> Message-ID: <2250439026@f38.n261.z1.binkp.net> Le dimanche 26 novembre 2017 05:53:55 UTC+1, Rustom Mody a ?Ccrit? : > On Sunday, November 26, 2017 at 3:43:29 AM UTC+5:30, Chris Angelico wrote: > > On Sun, Nov 26, 2017 at 9:05 AM, wojtek.mula wrote: > > > Hi, my goal is to obtain an interpreter that internally > > > uses UCS-2. Such a simple code should print 65535: > > > > > > import sys > > > print sys.maxunicode > > > > > > This is enabled in Windows, but I want the same in Linux. > > > What options have I pass to the configure script? > > > > Why do you want to? What useful value do you have in creating this > > buggy interpreter? > > I see that you are familiar with this bug: https://bugs.python.org/issue13153 > > And I see it or something very close is still buggy in python 3.5 > [No it does not allow me to paste an SMP char but if I open a file containing > one it crashes and rather messily ? ? no way to close the idle other than killing > the shell] > > No thats not a diatribe against idle; just that its reasonable to want python > to support work-arounds for reasonably common bugs in the current unicode-ecosystem Yes, it's a little bit extraordinary, to see a language which is supposed to work internally in a "UCS-2/UTF-16" (very quoted) mode with a graphical toolkit also woking in a "UCS-2/UTF-16" succeeds to raise UTF-8 errors (!). Patches over patches over patches over pathches ... will never solve what is wrong by design. As semi correctly pointed, for serious Unicode works use serious tools with a correct Unicode implementation. There are even tools, where the following is printable: >>> >>> '\ud800\udc00'.isprintable() False >>> From nospam.nospam.wxjmfauth at gmail.com Sat Nov 25 09:36:00 2017 From: nospam.nospam.wxjmfauth at gmail.com (wxjmfauth wxjmfauth) Date: Sun, 26 Nov 2017 02:36:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode Message-ID: <2181834194@f38.n261.z1.binkp.net> Le dimanche 26 novembre 2017 05:53:55 UTC+1, Rustom Mody a ?Ccrit? : > On Sunday, November 26, 2017 at 3:43:29 AM UTC+5:30, Chris Angelico wrote: > > On Sun, Nov 26, 2017 at 9:05 AM, wojtek.mula wrote: > > > Hi, my goal is to obtain an interpreter that internally > > > uses UCS-2. Such a simple code should print 65535: > > > > > > import sys > > > print sys.maxunicode > > > > > > This is enabled in Windows, but I want the same in Linux. > > > What options have I pass to the configure script? > > > > Why do you want to? What useful value do you have in creating this > > buggy interpreter? > > I see that you are familiar with this bug: https://bugs.python.org/issue13153 > > And I see it or something very close is still buggy in python 3.5 > [No it does not allow me to paste an SMP char but if I open a file containing > one it crashes and rather messily ? ? no way to close the idle other than killing > the shell] > > No thats not a diatribe against idle; just that its reasonable to want python > to support work-arounds for reasonably common bugs in the current unicode-ecosystem Yes, it's a little bit extraordinary, to see a language which is supposed to work internally in a "UCS-2/UTF-16" (very quoted) mode with a graphical toolkit also woking in a "UCS-2/UTF-16" succeeds to raise UTF-8 errors (!). Patches over patches over patches over pathches ... will never solve what is wrong by design. As semi correctly pointed, for serious Unicode works use serious tools with a correct Unicode implementation. There are even tools, where the following is printable: >>> >>> '\ud800\udc00'.isprintable() False >>> From nospam.november.nihal at gmail.com Sat Nov 25 10:54:00 2017 From: nospam.november.nihal at gmail.com (november nihal) Date: Sun, 26 Nov 2017 03:54:00 +1200 Subject: Stopping an iterator and continuing later (Posting On Python-List P References: <354384038@f38.n261.z1.binkp.net> Message-ID: <3202337153@f38.n261.z1.binkp.net> On Saturday, 25 November 2017 20:59:02 UTC, Lawrence D? ?Oliveiro wrote: > On Sunday, November 26, 2017 at 6:43:05 AM UTC+13, novembe... at gmail.com wrote: > > I worked out how to use iterators to generate values one at a time > > then ran into a second problem which is time. Is it possible to > > save an iterator so that i can continue from where I stopped? > > Yes. Just stop calling it. Then, when you start again, you will get the values continuing from that point. I should have added I switch off the machine when I stop. ( I dont have options to keep it in a sleep mode or in hibernation ) NN From nospam.nospam.november.nihal at gmail.com Sat Nov 25 10:54:00 2017 From: nospam.nospam.november.nihal at gmail.com (november nihal november nihal) Date: Sun, 26 Nov 2017 03:54:00 +1200 Subject: Stopping an iterator and continuing later (Posting On Python-List P References: <4069646887@f38.n261.z1.binkp.net> Message-ID: <4036528059@f38.n261.z1.binkp.net> On Saturday, 25 November 2017 20:59:02 UTC, Lawrence D? ?Oliveiro wrote: > On Sunday, November 26, 2017 at 6:43:05 AM UTC+13, novembe... at gmail.com wrote: > > I worked out how to use iterators to generate values one at a time > > then ran into a second problem which is time. Is it possible to > > save an iterator so that i can continue from where I stopped? > > Yes. Just stop calling it. Then, when you start again, you will get the values continuing from that point. I should have added I switch off the machine when I stop. ( I dont have options to keep it in a sleep mode or in hibernation ) NN From nospam.nospam.nospam.november.nihal at gmail.com Sat Nov 25 10:54:00 2017 From: nospam.nospam.nospam.november.nihal at gmail.com (november nihal november nihal november nihal november nihal) Date: Sun, 26 Nov 2017 03:54:00 +1200 Subject: Stopping an iterator and continuing later (Posting On Python-List P Message-ID: <770701359@f38.n261.z1.binkp.net> On Saturday, 25 November 2017 20:59:02 UTC, Lawrence D? ?Oliveiro wrote: > On Sunday, November 26, 2017 at 6:43:05 AM UTC+13, novembe... at gmail.com wrote: > > I worked out how to use iterators to generate values one at a time > > then ran into a second problem which is time. Is it possible to > > save an iterator so that i can continue from where I stopped? > > Yes. Just stop calling it. Then, when you start again, you will get the values continuing from that point. I should have added I switch off the machine when I stop. ( I dont have options to keep it in a sleep mode or in hibernation ) NN From torriem at gmail.com Sat Nov 25 11:07:57 2017 From: torriem at gmail.com (Michael Torrie) Date: Sat, 25 Nov 2017 09:07:57 -0700 Subject: connect four (game) In-Reply-To: <6PdSB.41734$Mu.23897@fx02.am4> References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> Message-ID: <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> On 11/25/2017 06:00 AM, bartc wrote: > And there's a quite lot left of the rest of the program to worry about too! > > If you add 'window()' at the end of the program, then it seems to run on > Python 3. I'd play around with it first before thinking up strategies > for testing it. Actually, no. Unit testing ideally should be done for each and every class as they are being written (before they are written in fact), no matter how small and trivial the class. That way as you compose larger and larger units of code, the chances of things being right is greater compared to doing it the other way around. You may argue that testing doesn't matter for his small game, written for his own education and amusement. The fact is that software in general is of abysmal quality across the boards, and promoting a habit of unit testing is good, even for trivial, home-grown stuff. From torriem at gmail.com Sat Nov 25 11:14:36 2017 From: torriem at gmail.com (Michael Torrie) Date: Sat, 25 Nov 2017 09:14:36 -0700 Subject: Pros and cons of Python sources? In-Reply-To: References: Message-ID: On 11/25/2017 02:20 AM, Martin Sch??n wrote: > Some time ago I was advised that having a Python installation > based on several sources (pip and Debian's repos in my case) > is not a good idea. I need to tidy up my installation and I > don't know what to opt for and what to opt out. > > What are the pros and cons of the alternatives including the > ones I haven't mentioned? Completeness, currency, bugs... The problem with mixing repository-installed packages with pip-installed packages is that there's always a chance a Debian update will overwrite a pip package, possibly with an older version. Or a pip-installed package might bring in a new version that's not compatible with some debian-installed package, breaking something. One solution to this issue is to use Python the python virtualenv facility to create a special python root you can work in for your project, and pip install things you need into that place, without worrying about the issue I mentioned before. From rustompmody at gmail.com Sat Nov 25 11:34:20 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 25 Nov 2017 08:34:20 -0800 (PST) Subject: Pros and cons of Python sources? In-Reply-To: References: Message-ID: <7031295c-3341-4eb9-8737-a4a122b50672@googlegroups.com> On Saturday, November 25, 2017 at 9:45:07 PM UTC+5:30, Michael Torrie wrote: > On 11/25/2017 02:20 AM, Martin Sch??n wrote: > > Some time ago I was advised that having a Python installation > > based on several sources (pip and Debian's repos in my case) > > is not a good idea. I need to tidy up my installation and I > > don't know what to opt for and what to opt out. > > > > What are the pros and cons of the alternatives including the > > ones I haven't mentioned? Completeness, currency, bugs... > > The problem with mixing repository-installed packages with pip-installed > packages is that there's always a chance a Debian update will overwrite > a pip package, possibly with an older version. Or a pip-installed > package might bring in a new version that's not compatible with some > debian-installed package, breaking something. On (recent?) debian/ubuntu pip seems to use the 'user-scheme' which means pip runs without sudo and installs in ~/.local/lib So I dont believe literal overwriting would occur What could occur is shadowing ? two versions of package foo and an unclarity of which is in use? Alister's suggestion is what I always try first. Doesnt always work because OS packages could be stale and/or non-existent From ian.g.kelly at gmail.com Sat Nov 25 11:36:18 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 25 Nov 2017 09:36:18 -0700 Subject: connect four (game) In-Reply-To: <6PdSB.41734$Mu.23897@fx02.am4> References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> Message-ID: On Sat, Nov 25, 2017 at 6:00 AM, bartc wrote: > Where are your unittests for these unittests? Taking this question more seriously than it deserves: the tests for the unittest module itself are at https://hg.python.org/cpython/file/tip/Lib/unittest/test. Yes, unittest has tests of itself. As for tests of the tests, that's getting a bit absurd, don't you think? Then we'd have to write tests of the tests of the tests. And then those tests would need tests. It's turtles all the way down. No, the point of having unit tests is to build confidence that the code in question works correctly. It's *possible* that the code is broken, and that the test is also broken in a way that hides the brokenness of the code, but this is much less likely than the case where just the code is broken. This is also the reason why the philosophy of test-drive development stipulates that one should write the test *first*, run it and watch it fail (this ensures that the test is actually testing *something*) and then and only then write the code to make the test pass. > Or is this kind of code immune from testing? It is the production code, not the test code, that we wish to have confidence in. > Actually I've no idea what these tests are supposed to prove. They are to do > with one class called 'infinity', which is never used in the rest of the > program apart from one line. As I stated in my earlier reply, I just started at the top of the file and wrote some tests. I didn't do anything for the rest of the program because I was merely trying to demonstrate the technique, not write hundreds of lines of tests for the OP. > I established that within a few seconds, and I would concentrate on what > 'infinity' is actually for, rather than go to considerable lengths to test a > class that may not actually be needed. If the class is used, then it's needed. There is a concept in software testing called "code coverage". This represents the idea that every statement in a program should be exercised at least once by the tests. This is one of the reasons why much software testing focuses on unit testing: if we break the program apart into units, and we thoroughly test each unit, then we should end up with complete coverage of the program as a whole. > If you add 'window()' at the end of the program, then it seems to run on > Python 3. I'd play around with it first before thinking up strategies for > testing it. "Seems to run" and "works correctly" are very different things. From rustompmody at gmail.com Sat Nov 25 11:59:18 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 25 Nov 2017 08:59:18 -0800 (PST) Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> Message-ID: <11ca19bf-7ed3-48f6-bf44-630bf10a17a5@googlegroups.com> On Friday, November 24, 2017 at 10:52:47 PM UTC+5:30, Rick Johnson wrote: > Furthermore, if we are to march headlong onto the glorious > battlefields of diversity and equality? Obligatory viewing for those who underappreciate diversity, equality and such https://youtu.be/Zh3Yz3PiXZw [My old colleague, a numerical analyst pointed out to me today that the 'correct answer' is not twenty two thousand but twenty million two thousand] From rosuav at gmail.com Sat Nov 25 12:02:26 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 26 Nov 2017 04:02:26 +1100 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> Message-ID: On Sun, Nov 26, 2017 at 3:36 AM, Ian Kelly wrote: > On Sat, Nov 25, 2017 at 6:00 AM, bartc wrote: >> Where are your unittests for these unittests? > > No, the point of having unit tests is to build confidence that the > code in question works correctly. It's *possible* that the code is > broken, and that the test is also broken in a way that hides the > brokenness of the code, but this is much less likely than the case > where just the code is broken. This is also the reason why the > philosophy of test-drive development stipulates that one should write > the test *first*, run it and watch it fail (this ensures that the test > is actually testing *something*) and then and only then write the code > to make the test pass. To be fair, TDD doesn't actually prove that the test isn't broken. It only protects you against one class of error: tests that actually aren't testing anything. Proponents of TDD will argue that this class of error is quite common; true or not, it's still only one particular kind of failure. It's definitely possible for tests to be wrong in such a way that they don't detect faulty code. So what do we do? WE TEST BY HAND. Ultimately, unit testing is a tool, not a magic wand. It's up to us to actually put it to use to improve code quality. ChrisA From ian.g.kelly at gmail.com Sat Nov 25 12:16:51 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 25 Nov 2017 10:16:51 -0700 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> Message-ID: On Sat, Nov 25, 2017 at 10:02 AM, Chris Angelico wrote: > On Sun, Nov 26, 2017 at 3:36 AM, Ian Kelly wrote: >> On Sat, Nov 25, 2017 at 6:00 AM, bartc wrote: >>> Where are your unittests for these unittests? >> >> No, the point of having unit tests is to build confidence that the >> code in question works correctly. It's *possible* that the code is >> broken, and that the test is also broken in a way that hides the >> brokenness of the code, but this is much less likely than the case >> where just the code is broken. This is also the reason why the >> philosophy of test-drive development stipulates that one should write >> the test *first*, run it and watch it fail (this ensures that the test >> is actually testing *something*) and then and only then write the code >> to make the test pass. > > To be fair, TDD doesn't actually prove that the test isn't broken. It > only protects you against one class of error: tests that actually > aren't testing anything. Proponents of TDD will argue that this class > of error is quite common; true or not, it's still only one particular > kind of failure. It's definitely possible for tests to be wrong in > such a way that they don't detect faulty code. > > So what do we do? WE TEST BY HAND. Ultimately, unit testing is a tool, > not a magic wand. It's up to us to actually put it to use to improve > code quality. Certainly. I wasn't trying to advocate for TDD here, which I don't even practice regularly myself. From christopher_reimer at icloud.com Sat Nov 25 12:49:03 2017 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sat, 25 Nov 2017 09:49:03 -0800 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> Message-ID: On Nov 25, 2017, at 9:16 AM, Ian Kelly wrote: > >> On Sat, Nov 25, 2017 at 10:02 AM, Chris Angelico wrote: >>> On Sun, Nov 26, 2017 at 3:36 AM, Ian Kelly wrote: >>>> On Sat, Nov 25, 2017 at 6:00 AM, bartc wrote: >>>> Where are your unittests for these unittests? >>> >>> No, the point of having unit tests is to build confidence that the >>> code in question works correctly. It's *possible* that the code is >>> broken, and that the test is also broken in a way that hides the >>> brokenness of the code, but this is much less likely than the case >>> where just the code is broken. This is also the reason why the >>> philosophy of test-drive development stipulates that one should write >>> the test *first*, run it and watch it fail (this ensures that the test >>> is actually testing *something*) and then and only then write the code >>> to make the test pass. >> >> To be fair, TDD doesn't actually prove that the test isn't broken. It >> only protects you against one class of error: tests that actually >> aren't testing anything. Proponents of TDD will argue that this class >> of error is quite common; true or not, it's still only one particular >> kind of failure. It's definitely possible for tests to be wrong in >> such a way that they don't detect faulty code. >> >> So what do we do? WE TEST BY HAND. Ultimately, unit testing is a tool, >> not a magic wand. It's up to us to actually put it to use to improve >> code quality. > > Certainly. I wasn't trying to advocate for TDD here, which I don't > even practice regularly myself. > -- > https://mail.python.org/mailman/listinfo/python-list For anyone who is interested, "Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and JavaScript" by Harry J.W. Percival. The second edition came out this year. A good introduction to unit and function testing. Chris R. From wanderer at dialup4less.com Sat Nov 25 14:21:00 2017 From: wanderer at dialup4less.com (nospam.Wanderer) Date: Sun, 26 Nov 2017 07:21:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! References: <1412351557@f38.n261.z1.binkp.net> Message-ID: <2019444356@f38.n261.z1.binkp.net> On Sunday, November 26, 2017 at 4:10:12 AM UTC-5, Greg Tibbet wrote: > I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit > of Java and trying to learn this new-fangled Python language! > > I've got a small program that uses PIL to create an image, draw some > primitives (rectanges, ellipses, etc...) and save it. Works fine... > no issues. > > I've found in the past, the best way to "really learn" the language > was to "dig into the guts" and understand it,.. I thought I was making > progress, but when looking into the PIL library to see what's going on > behind the scenes, I find the following code in ImageDraw.py > > def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) > <...snipped...> > > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? > > Thanks! > -Stumpy (aka Greg) I'm googlesmart when it comes to Python. I used to know C. I practically knew what the assembly language would look like when it compiled. There was no internet and searching through books can be really laborious so you almost had to really know it to use it. But with Python, I don't start from first principles. I google what I want to do, download the appropriate packages and read through the examples. It can be really frustrating when you get bugs, because you don't know what's going on deep down in the code. From wanderer at dialup4less.com Sat Nov 25 14:21:00 2017 From: wanderer at dialup4less.com (nospam.nospam.Wanderer) Date: Sun, 26 Nov 2017 07:21:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! References: <4121135281@f38.n261.z1.binkp.net> Message-ID: <2697081262@f38.n261.z1.binkp.net> On Sunday, November 26, 2017 at 4:10:12 AM UTC-5, Greg Tibbet wrote: > I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit > of Java and trying to learn this new-fangled Python language! > > I've got a small program that uses PIL to create an image, draw some > primitives (rectanges, ellipses, etc...) and save it. Works fine... > no issues. > > I've found in the past, the best way to "really learn" the language > was to "dig into the guts" and understand it,.. I thought I was making > progress, but when looking into the PIL library to see what's going on > behind the scenes, I find the following code in ImageDraw.py > > def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) > <...snipped...> > > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? > > Thanks! > -Stumpy (aka Greg) I'm googlesmart when it comes to Python. I used to know C. I practically knew what the assembly language would look like when it compiled. There was no internet and searching through books can be really laborious so you almost had to really know it to use it. But with Python, I don't start from first principles. I google what I want to do, download the appropriate packages and read through the examples. It can be really frustrating when you get bugs, because you don't know what's going on deep down in the code. From wanderer at dialup4less.com Sat Nov 25 14:21:00 2017 From: wanderer at dialup4less.com (nospam.nospam.nospam.Wanderer) Date: Sun, 26 Nov 2017 07:21:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! Message-ID: <4004312866@f38.n261.z1.binkp.net> On Sunday, November 26, 2017 at 4:10:12 AM UTC-5, Greg Tibbet wrote: > I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit > of Java and trying to learn this new-fangled Python language! > > I've got a small program that uses PIL to create an image, draw some > primitives (rectanges, ellipses, etc...) and save it. Works fine... > no issues. > > I've found in the past, the best way to "really learn" the language > was to "dig into the guts" and understand it,.. I thought I was making > progress, but when looking into the PIL library to see what's going on > behind the scenes, I find the following code in ImageDraw.py > > def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) > <...snipped...> > > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? > > Thanks! > -Stumpy (aka Greg) I'm googlesmart when it comes to Python. I used to know C. I practically knew what the assembly language would look like when it compiled. There was no internet and searching through books can be really laborious so you almost had to really know it to use it. But with Python, I don't start from first principles. I google what I want to do, download the appropriate packages and read through the examples. It can be really frustrating when you get bugs, because you don't know what's going on deep down in the code. From namenobodywants at gmail.com Sat Nov 25 14:58:59 2017 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Sat, 25 Nov 2017 11:58:59 -0800 (PST) Subject: connect four (game) In-Reply-To: <6PdSB.41734$Mu.23897@fx02.am4> References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> Message-ID: <35191dce-b751-42d1-ac87-b25c648fd95c@googlegroups.com> On Saturday, November 25, 2017 at 5:00:12 AM UTC-8, bartc wrote: > Actually I've no idea what these tests are supposed to prove. me neither; i think you guys may be getting me out of my depth now > They are to do with one class called 'infinity', which is never used in the rest > of the program apart from one line. > > I established that within a few seconds, and I would concentrate on what > 'infinity' is actually for, rather than go to considerable lengths to > test a class that may not actually be needed. my current version of "infinity" looks like this class Infinity: def __init__(self,signum): self.signum = (+1) if signum > 0 else (-1) def __repr__(self): return '+oo' if self.signum == (+1) else '-oo' def __lt__(self,other): return self.signum == (-1) def __le__(self,other): return self.signum == (-1) def __gt__(self,other): return self.signum == (+1) def __ge__(self,other): return self.signum == (+1) def __eq__(self,other): return isinstance(other,Infinity) and self.signum == other.signum the idea is that there should be exactly one object posinf (positive infinity) that compares as strictly greater than any number ever considered, and exactly one object neginf that compares as strictly less; as the code stands now there is no reason not to use +/-70 in that capacity; the "infinity" class is there so that the game-playing parts of the code (which at present are intentionally as primitive as possible) can be modified more smoothly later; the single place where "infinity" is instantiated is in the function "getvalue", which returns the value of a finished game: def getvalue(winner,accessibles): return Infinity(+1) if winner == ex else Infinity(-1) if winner == oh else 0 if not accessibles else None if ex has won then the value of the game is posinf; if oh has won then it's neginf; if the game is tied (no winner but no accessible columns remaining) then the value of the game is zero; otherwise the game is not finished and its finished value is None peace stm From namenobodywants at gmail.com Sat Nov 25 15:26:52 2017 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Sat, 25 Nov 2017 12:26:52 -0800 (PST) Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> Message-ID: On Friday, November 24, 2017 at 8:07:07 AM UTC-8, Chris Angelico wrote: > This is the kind of function that needs a docstring and some comments. > What exactly is this doing? What are the "lines" of the board? What's > the difference between "linear" and "lines"? What exactly is it > returning? producing documentation is an extremely difficult task for me, but i've come up with the following: """ makelines(length,numrows,numcolumns) IS THE LIST OF ALL LISTS L, WITH LENGTH length, OF COORDINATES FROM A numrows x numcolumns MATRIX, SUCH THAT THE ENTRIES OF L ALL LIE IN A LINE: LET horizontal BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN A HORIZONTAL LINE LET vertical BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN A VERTICAL LINE LET downward BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN A DOWNWARD-SLOPING DIAGONAL LINE LET upward BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN AN UPWARD-SLOPING DIAGONAL LINE THEN makelines(length,numrows,numcolumns) IS THE UNION OF ALL THE AFOREMENTIONED SETS """ def makelines(length,numrows,numcolumns): horizontal = [[(i, j+k) for k in range(length)] for i in range(numrows) for j in range(numcolumns)] vertical = [[(i+k, j) for k in range(length)] for i in range(numrows) for j in range(numcolumns)] downward = [[(i+k, j+k) for k in range(length)] for i in range(numrows) for j in range(numcolumns)] upward = [[(i+k, j-k) for k in range(length)] for i in range(numrows) for j in range(numcolumns)] linear = horizontal + vertical + downward + upward return [line for line in linear if all(i in range(6) and j in range(7) for (i,j) in line)] def getlines(board): coordlines = makelines(4,6,7) ## GLOBAL return [[board[square] for square in line] for line in coordlines i tried to remove all the superfluous spaces from that, but lining up code vertically is very helpful to me, so i don't think i can really dispense with the practice peace stm From storchaka at gmail.com Sat Nov 25 15:54:00 2017 From: storchaka at gmail.com (nospam.Serhiy Storchaka) Date: Sun, 26 Nov 2017 08:54:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode Message-ID: <3991290825@f38.n261.z1.binkp.net> 26.11.17 01:59, Terry Reedy D?D,??D?: > On 11/25/2017 5:12 PM, Chris Angelico wrote: >> On Sun, Nov 26, 2017 at 9:05 AM,? wrote: >>> Hi, my goal is to obtain an interpreter that internally >>> uses UCS-2. Such a simple code should print 65535: >>> >>> ? ? import sys >>> ? ? print sys.maxunicode >>> >>> This is enabled in Windows, but I want the same in Linux. >>> What options have I pass to the configure script? > > You must be trying to compile 2.7.? There may be Linux distributions > that compile this way. UCS-2 is the default in 2.7. But most Linux distributions build it with UCS-4. From rosuav at gmail.com Sat Nov 25 16:12:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Sun, 26 Nov 2017 09:12:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode Message-ID: <1306011088@f38.n261.z1.binkp.net> On Sun, Nov 26, 2017 at 9:05 AM, wrote: > Hi, my goal is to obtain an interpreter that internally > uses UCS-2. Such a simple code should print 65535: > > import sys > print sys.maxunicode > > This is enabled in Windows, but I want the same in Linux. > What options have I pass to the configure script? Why do you want to? What useful value do you have in creating this buggy interpreter? Ever since Python 3.3, that has simply not been an option. The bug has been solved. ChrisA From rosuav at gmail.com Sat Nov 25 16:12:00 2017 From: rosuav at gmail.com (nospam.nospam.Chris Angelico) Date: Sun, 26 Nov 2017 09:12:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode Message-ID: <3523203590@f38.n261.z1.binkp.net> On Sun, Nov 26, 2017 at 9:05 AM, wrote: > Hi, my goal is to obtain an interpreter that internally > uses UCS-2. Such a simple code should print 65535: > > import sys > print sys.maxunicode > > This is enabled in Windows, but I want the same in Linux. > What options have I pass to the configure script? Why do you want to? What useful value do you have in creating this buggy interpreter? Ever since Python 3.3, that has simply not been an option. The bug has been solved. ChrisA From nospam.ram at zedat.fu-berlin.de Sat Nov 25 16:35:00 2017 From: nospam.ram at zedat.fu-berlin.de (Stefan Ram Stefan Ram) Date: Sun, 26 Nov 2017 09:35:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! References: <1412351557@f38.n261.z1.binkp.net> Message-ID: <2210844426@f38.n261.z1.binkp.net> Greg Tibbet writes: >I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit >of Java and trying to learn this new-fangled Python language! Which actually is older than Java. >def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) ><...snipped...> >ellipse() uses the method self.draw.draw_ellipse() Okay, fine... >but WHERE is draw_ellipse defined?? What magic is happening there? Depends on the nature of ??self??. Usually, the answer would be that it's defined in a superclass. But with Python, one could also decrypt a string and then feed the result to ??exec?? to dynamically add methods to an object whose source code is well hidden. Looking into the matter, it turns out, however, ... ??_draw_ellipse?? is defined in the language C in the file ??_imaging.c?? and then mapped to ??draw_ellipse?? via PyMethodDef which is part of Python's C API. From nospam.nospam.ram at zedat.fu-berlin.de Sat Nov 25 16:35:00 2017 From: nospam.nospam.ram at zedat.fu-berlin.de (Stefan Ram Stefan Ram Stefan Ram Stefan Ram) Date: Sun, 26 Nov 2017 09:35:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! References: <4121135281@f38.n261.z1.binkp.net> Message-ID: <3254084541@f38.n261.z1.binkp.net> Greg Tibbet writes: >I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit >of Java and trying to learn this new-fangled Python language! Which actually is older than Java. >def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) ><...snipped...> >ellipse() uses the method self.draw.draw_ellipse() Okay, fine... >but WHERE is draw_ellipse defined?? What magic is happening there? Depends on the nature of ??self??. Usually, the answer would be that it's defined in a superclass. But with Python, one could also decrypt a string and then feed the result to ??exec?? to dynamically add methods to an object whose source code is well hidden. Looking into the matter, it turns out, however, ... ??_draw_ellipse?? is defined in the language C in the file ??_imaging.c?? and then mapped to ??draw_ellipse?? via PyMethodDef which is part of Python's C API. From nospam.nospam.nospam.ram at zedat.fu-berlin.de Sat Nov 25 16:35:00 2017 From: nospam.nospam.nospam.ram at zedat.fu-berlin.de (Stefan Ram Stefan Ram) Date: Sun, 26 Nov 2017 09:35:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! Message-ID: <4177672530@f38.n261.z1.binkp.net> Ram) (Stefan Ram) Greg Tibbet writes: >I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit >of Java and trying to learn this new-fangled Python language! Which actually is older than Java. >def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) ><...snipped...> >ellipse() uses the method self.draw.draw_ellipse() Okay, fine... >but WHERE is draw_ellipse defined?? What magic is happening there? Depends on the nature of ??self??. Usually, the answer would be that it's defined in a superclass. But with Python, one could also decrypt a string and then feed the result to ??exec?? to dynamically add methods to an object whose source code is well hidden. Looking into the matter, it turns out, however, ... ??_draw_ellipse?? is defined in the language C in the file ??_imaging.c?? and then mapped to ??draw_ellipse?? via PyMethodDef which is part of Python's C API. From namenobodywants at gmail.com Sat Nov 25 16:57:09 2017 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Sat, 25 Nov 2017 13:57:09 -0800 (PST) Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> Message-ID: <196acf58-1e2c-41ea-a175-77eecb526933@googlegroups.com> On Saturday, November 25, 2017 at 12:48:38 AM UTC-8, Terry Reedy wrote: > I did, and it looks buggy to me. The top and left frame lines are > missing. If I click a square, the bottom square in the column lights > up. But then I have no idea whether those are your intentions or not. i hadn't noticed about the frame lines, but it's the same for me; but i'm hoping you meant to write that the TOP square in a column flashes when you "drop a token" down that column; if you really meant the bottom one then i'm totally baffled that it could be the top one for me and the bottom one for you ... is that something that can happen because of a bug? sorry if you were offended by what i wrote before; i didn't understand what you meant peace stm From martin.schoon at gmail.com Sat Nov 25 17:00:00 2017 From: martin.schoon at gmail.com (nospam.Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: Sun, 26 Nov 2017 10:00:00 +1200 Subject: Pros and cons of Python sources? References: <2416792280@f38.n261.z1.binkp.net> Message-ID: <2332526810@f38.n261.z1.binkp.net> Den 2017-11-26 skrev Cameron Simpson : > On 25Nov2017 08:34, rusi wrote: >>On Saturday, November 25, 2017 at 9:45:07 PM UTC+5:30, Michael Torrie wrote: >>> The problem with mixing repository-installed packages with pip-installed >>> packages is that there's always a chance a Debian update will overwrite >>> a pip package, possibly with an older version. Or a pip-installed >>> package might bring in a new version that's not compatible with some >>> debian-installed package, breaking something. >> >>On (recent?) debian/ubuntu pip seems to use the 'user-scheme' >>which means pip runs without sudo and installs in ~/.local/lib >>So I dont believe literal overwriting would occur > > Though the point should be made that one should run pip as oneself, and try to > avoid doing it as the root user (including avoiding sudo). Many UNIX/Linux/etc > users believe "installs" should be done as root, and in this case that is > easily avoided, with all its potential for damage to the vendor supplied > environment. Hmm, I seem to remember not being able to install packages with pip unless I did sudo pip. Follow-up question: Is there a way to find out which packages were installed using pip and which are from Debian's repo? pip list seems to list everything. /Martin From martin.schoon at gmail.com Sat Nov 25 17:00:00 2017 From: martin.schoon at gmail.com (nospam.nospam.Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: Sun, 26 Nov 2017 10:00:00 +1200 Subject: Pros and cons of Python sources? Message-ID: <3947785175@f38.n261.z1.binkp.net> (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Den 2017-11-26 skrev Cameron Simpson : > On 25Nov2017 08:34, rusi wrote: >>On Saturday, November 25, 2017 at 9:45:07 PM UTC+5:30, Michael Torrie wrote: >>> The problem with mixing repository-installed packages with pip-installed >>> packages is that there's always a chance a Debian update will overwrite >>> a pip package, possibly with an older version. Or a pip-installed >>> package might bring in a new version that's not compatible with some >>> debian-installed package, breaking something. >> >>On (recent?) debian/ubuntu pip seems to use the 'user-scheme' >>which means pip runs without sudo and installs in ~/.local/lib >>So I dont believe literal overwriting would occur > > Though the point should be made that one should run pip as oneself, and try to > avoid doing it as the root user (including avoiding sudo). Many UNIX/Linux/etc > users believe "installs" should be done as root, and in this case that is > easily avoided, with all its potential for damage to the vendor supplied > environment. Hmm, I seem to remember not being able to install packages with pip unless I did sudo pip. Follow-up question: Is there a way to find out which packages were installed using pip and which are from Debian's repo? pip list seems to list everything. /Martin From wojtek.mula at gmail.com Sat Nov 25 17:05:59 2017 From: wojtek.mula at gmail.com (wojtek.mula at gmail.com) Date: Sat, 25 Nov 2017 14:05:59 -0800 (PST) Subject: Compile Python 3 interpreter to force 2-byte unicode Message-ID: Hi, my goal is to obtain an interpreter that internally uses UCS-2. Such a simple code should print 65535: import sys print sys.maxunicode This is enabled in Windows, but I want the same in Linux. What options have I pass to the configure script? w. From rosuav at gmail.com Sat Nov 25 17:12:58 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 26 Nov 2017 09:12:58 +1100 Subject: Compile Python 3 interpreter to force 2-byte unicode In-Reply-To: References: Message-ID: On Sun, Nov 26, 2017 at 9:05 AM, wrote: > Hi, my goal is to obtain an interpreter that internally > uses UCS-2. Such a simple code should print 65535: > > import sys > print sys.maxunicode > > This is enabled in Windows, but I want the same in Linux. > What options have I pass to the configure script? Why do you want to? What useful value do you have in creating this buggy interpreter? Ever since Python 3.3, that has simply not been an option. The bug has been solved. ChrisA From vincent.vande.vyvre at telenet.be Sat Nov 25 17:34:00 2017 From: vincent.vande.vyvre at telenet.be (nospam.Vincent Vande Vyvre) Date: Sun, 26 Nov 2017 10:34:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! Message-ID: <3246757081@f38.n261.z1.binkp.net> Le 26/11/17 ? 10:09, Greg Tibbet a ?Ccrit? : > I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit > of Java and trying to learn this new-fangled Python language! > > I've got a small program that uses PIL to create an image, draw some > primitives (rectanges, ellipses, etc...) and save it. Works fine... > no issues. > > I've found in the past, the best way to "really learn" the language > was to "dig into the guts" and understand it,.. I thought I was making > progress, but when looking into the PIL library to see what's going on > behind the scenes, I find the following code in ImageDraw.py > > def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) > <...snipped...> > > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? > > Thanks! > -Stumpy (aka Greg) Hi, It's not defined in Python module but in Pillow-3.5/Pillow-master/libImaging/Draw.c ... line 748 Vincent From h.goebel at crazy-compilers.com Sat Nov 25 17:58:00 2017 From: h.goebel at crazy-compilers.com (nospam.Hartmut Goebel) Date: Sun, 26 Nov 2017 10:58:00 +1200 Subject: C-api: Executing several scripts as __main__: globals are gone Message-ID: <3371574778@f38.n261.z1.binkp.net> Hello, in PyInstaller we execute several Python scripts one after each other. The primary use of this is to run some setup prior to the actual appication. Up to now all scripts shared the same global variables, which worked well for 15 years, but now showed an error. The new code (scratched below) now deletes sys.modules['__main__'], so the next script will get a fresh module and fresh globals. This leads to an obscure error: If a setup-script hooks into something, this hook does not see it's own script's/module's globals. Thus running the scripts below (setup first, then main), fails with: Traceback (most recent call last): ? File "main-script", line 2, in ? File "setup-script", line 3, in do_it NameError: global name 'sys' is not defined Same effect for any other identifier defined globally in setup-script, e.g global functions (which is worse then just a missing import). I tried keeping a reference to the module (to avoid garbage-collection) both in the C-code and in the setup-script. But this did not solve the issue, the effect is the same. I also read through the CPython source but did not spot anything useful. Additionally, this issue only occurs with Python 2.7 and 3.3, Python 3.4 and up are okay. Any ideas? ....8<------ C-code scratch!! pseudo-code --- sys_modules = PyImport_GetModuleDict(); for each entry in archive { ? ? ? data = Get_data_out_of_the_archive() ? ? ? code = PyMarshal_ReadObjectFromString(data) /* execute as '__main__ for compatibility */ ? ? ? module = PyImport_ExecCodeModule("__main__", code); ? ? ? Py_DECREF(module); ? ? ? /* remove '__main__' from sys.modules */ ? ? ? PyObject_DelItem(sys_modules, "__main__"); } ......8<----------------------- Now if a have these two scripts (these are examples: ......8<---- setup-script ------ import sys def do_it() print(sys.modules) sys.do_it = do_it ......8<------------------------- and ......8<---- main-script ------ import sys sys.do_it() ......8<----------------------- -- Regards Hartmut Goebel | Hartmut Goebel | h.goebel at crazy-compilers.com | | www.crazy-compilers.com | compilers which you thought are impossible | From h.goebel at crazy-compilers.com Sat Nov 25 17:58:00 2017 From: h.goebel at crazy-compilers.com (nospam.nospam.Hartmut Goebel) Date: Sun, 26 Nov 2017 10:58:00 +1200 Subject: C-api: Executing several scripts as __main__: globals are gone Message-ID: <3914950471@f38.n261.z1.binkp.net> Hello, in PyInstaller we execute several Python scripts one after each other. The primary use of this is to run some setup prior to the actual appication. Up to now all scripts shared the same global variables, which worked well for 15 years, but now showed an error. The new code (scratched below) now deletes sys.modules['__main__'], so the next script will get a fresh module and fresh globals. This leads to an obscure error: If a setup-script hooks into something, this hook does not see it's own script's/module's globals. Thus running the scripts below (setup first, then main), fails with: Traceback (most recent call last): ? File "main-script", line 2, in ? File "setup-script", line 3, in do_it NameError: global name 'sys' is not defined Same effect for any other identifier defined globally in setup-script, e.g global functions (which is worse then just a missing import). I tried keeping a reference to the module (to avoid garbage-collection) both in the C-code and in the setup-script. But this did not solve the issue, the effect is the same. I also read through the CPython source but did not spot anything useful. Additionally, this issue only occurs with Python 2.7 and 3.3, Python 3.4 and up are okay. Any ideas? ....8<------ C-code scratch!! pseudo-code --- sys_modules = PyImport_GetModuleDict(); for each entry in archive { ? ? ? data = Get_data_out_of_the_archive() ? ? ? code = PyMarshal_ReadObjectFromString(data) /* execute as '__main__ for compatibility */ ? ? ? module = PyImport_ExecCodeModule("__main__", code); ? ? ? Py_DECREF(module); ? ? ? /* remove '__main__' from sys.modules */ ? ? ? PyObject_DelItem(sys_modules, "__main__"); } ......8<----------------------- Now if a have these two scripts (these are examples: ......8<---- setup-script ------ import sys def do_it() print(sys.modules) sys.do_it = do_it ......8<------------------------- and ......8<---- main-script ------ import sys sys.do_it() ......8<----------------------- -- Regards Hartmut Goebel | Hartmut Goebel | h.goebel at crazy-compilers.com | | www.crazy-compilers.com | compilers which you thought are impossible | From gisle.vanem at gmail.com Sat Nov 25 18:04:00 2017 From: gisle.vanem at gmail.com (nospam.Gisle Vanem) Date: Sun, 26 Nov 2017 11:04:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! Message-ID: <3595021124@f38.n261.z1.binkp.net> Greg Tibbet wrote: > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? The C sources. Not all of PIL is ritten in Python. draw_ellipse() is a thin wrapper for ImagingDrawEllips(). See PIL/_imaging.c: https://github.com/python-pillow/Pillow/_imaging.c Which again is in libimage/Draw.c: https://github.com/python-pillow/Pillow/blob/13d84993717cffd64a2e1d7e3e6edb1 85973d559/libImaging/Draw.c calling ellipse(). -- --gv From gisle.vanem at gmail.com Sat Nov 25 18:04:00 2017 From: gisle.vanem at gmail.com (nospam.nospam.Gisle Vanem) Date: Sun, 26 Nov 2017 11:04:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! Message-ID: <2723449025@f38.n261.z1.binkp.net> Greg Tibbet wrote: > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? The C sources. Not all of PIL is ritten in Python. draw_ellipse() is a thin wrapper for ImagingDrawEllips(). See PIL/_imaging.c: https://github.com/python-pillow/Pillow/_imaging.c Which again is in libimage/Draw.c: https://github.com/python-pillow/Pillow/blob/13d84993717cffd64a2e1d7e3e6edb1 85973d559/libImaging/Draw.c calling ellipse(). -- --gv From bc at freeuk.com Sat Nov 25 18:10:00 2017 From: bc at freeuk.com (nospam.bartc) Date: Sun, 26 Nov 2017 11:10:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! References: <1412351557@f38.n261.z1.binkp.net> Message-ID: <2958511397@f38.n261.z1.binkp.net> On 26/11/2017 09:09, Greg Tibbet wrote: > > I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit > of Java and trying to learn this new-fangled Python language! > > I've got a small program that uses PIL to create an image, draw some > primitives (rectanges, ellipses, etc...) and save it. Works fine... > no issues. > > I've found in the past, the best way to "really learn" the language > was to "dig into the guts" and understand it,.. I thought I was making > progress, but when looking into the PIL library to see what's going on > behind the scenes, I find the following code in ImageDraw.py > > def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) > <...snipped...> > > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? Python isn't a very pure language in that much of the functionality that looks like it should be written in Python (because you imported a module just like you import any Python module), actually is written in something else, as has been pointed out. It's reasonable that some things need to be implemented using some foreign functions. But the boundary between Python and non-Python is blurred. Take this program: import sys and try and find sys.py in your installation. (This is an obstacle if, for example, you're thinking of implementing a Python interpreter. In theory, once you have it working, it should run any .py program. But the critical modules it needs don't have .py source code. And the interface to those non-Python functions isn't defined with special byte-code instructions. (It will be done /via/ those instructions, but the magic needed is on the other side of them. Calling into sys.fn() uses the same CALL_FUNCTION byte-code as calling into a regular Python function.) As I said, it's not pure. More of a jungle as you've found out.) -- bartc From bc at freeuk.com Sat Nov 25 18:10:00 2017 From: bc at freeuk.com (nospam.nospam.bartc) Date: Sun, 26 Nov 2017 11:10:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! References: <4121135281@f38.n261.z1.binkp.net> Message-ID: <908734119@f38.n261.z1.binkp.net> On 26/11/2017 09:09, Greg Tibbet wrote: > > I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit > of Java and trying to learn this new-fangled Python language! > > I've got a small program that uses PIL to create an image, draw some > primitives (rectanges, ellipses, etc...) and save it. Works fine... > no issues. > > I've found in the past, the best way to "really learn" the language > was to "dig into the guts" and understand it,.. I thought I was making > progress, but when looking into the PIL library to see what's going on > behind the scenes, I find the following code in ImageDraw.py > > def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) > <...snipped...> > > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? Python isn't a very pure language in that much of the functionality that looks like it should be written in Python (because you imported a module just like you import any Python module), actually is written in something else, as has been pointed out. It's reasonable that some things need to be implemented using some foreign functions. But the boundary between Python and non-Python is blurred. Take this program: import sys and try and find sys.py in your installation. (This is an obstacle if, for example, you're thinking of implementing a Python interpreter. In theory, once you have it working, it should run any .py program. But the critical modules it needs don't have .py source code. And the interface to those non-Python functions isn't defined with special byte-code instructions. (It will be done /via/ those instructions, but the magic needed is on the other side of them. Calling into sys.fn() uses the same CALL_FUNCTION byte-code as calling into a regular Python function.) As I said, it's not pure. More of a jungle as you've found out.) -- bartc From bc at freeuk.com Sat Nov 25 18:10:00 2017 From: bc at freeuk.com (nospam.nospam.nospam.bartc) Date: Sun, 26 Nov 2017 11:10:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! Message-ID: <528550275@f38.n261.z1.binkp.net> On 26/11/2017 09:09, Greg Tibbet wrote: > > I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit > of Java and trying to learn this new-fangled Python language! > > I've got a small program that uses PIL to create an image, draw some > primitives (rectanges, ellipses, etc...) and save it. Works fine... > no issues. > > I've found in the past, the best way to "really learn" the language > was to "dig into the guts" and understand it,.. I thought I was making > progress, but when looking into the PIL library to see what's going on > behind the scenes, I find the following code in ImageDraw.py > > def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) > <...snipped...> > > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? Python isn't a very pure language in that much of the functionality that looks like it should be written in Python (because you imported a module just like you import any Python module), actually is written in something else, as has been pointed out. It's reasonable that some things need to be implemented using some foreign functions. But the boundary between Python and non-Python is blurred. Take this program: import sys and try and find sys.py in your installation. (This is an obstacle if, for example, you're thinking of implementing a Python interpreter. In theory, once you have it working, it should run any .py program. But the critical modules it needs don't have .py source code. And the interface to those non-Python functions isn't defined with special byte-code instructions. (It will be done /via/ those instructions, but the magic needed is on the other side of them. Calling into sys.fn() uses the same CALL_FUNCTION byte-code as calling into a regular Python function.) As I said, it's not pure. More of a jungle as you've found out.) -- bartc From rosuav at gmail.com Sat Nov 25 18:17:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Sun, 26 Nov 2017 11:17:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode Message-ID: <2823813375@f38.n261.z1.binkp.net> On Sun, Nov 26, 2017 at 10:59 AM, Terry Reedy wrote: > On 11/25/2017 5:12 PM, Chris Angelico wrote: >> >> On Sun, Nov 26, 2017 at 9:05 AM, wrote: >>> >>> Hi, my goal is to obtain an interpreter that internally >>> uses UCS-2. Such a simple code should print 65535: >>> >>> import sys >>> print sys.maxunicode >>> >>> This is enabled in Windows, but I want the same in Linux. >>> What options have I pass to the configure script? > > > You must be trying to compile 2.7. There may be Linux distributions that > compile this way. If you want to use, or ever encounter, non-BMP chars, > using surrogate pairs is problematical. By my reading of the official UCS-2 > docs, Python's old 16-bit unicode implementation is not fully compliant. > Others have claimed that is it not a UCS-2 implementation. See subject line. OP wishes to compile Python 3 (and almost certainly not 3.1 or 3.2) with the bugginess of Python 2's narrow builds. ChrisA From rosuav at gmail.com Sat Nov 25 18:17:00 2017 From: rosuav at gmail.com (nospam.nospam.Chris Angelico) Date: Sun, 26 Nov 2017 11:17:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode Message-ID: <1817927762@f38.n261.z1.binkp.net> On Sun, Nov 26, 2017 at 10:59 AM, Terry Reedy wrote: > On 11/25/2017 5:12 PM, Chris Angelico wrote: >> >> On Sun, Nov 26, 2017 at 9:05 AM, wrote: >>> >>> Hi, my goal is to obtain an interpreter that internally >>> uses UCS-2. Such a simple code should print 65535: >>> >>> import sys >>> print sys.maxunicode >>> >>> This is enabled in Windows, but I want the same in Linux. >>> What options have I pass to the configure script? > > > You must be trying to compile 2.7. There may be Linux distributions that > compile this way. If you want to use, or ever encounter, non-BMP chars, > using surrogate pairs is problematical. By my reading of the official UCS-2 > docs, Python's old 16-bit unicode implementation is not fully compliant. > Others have claimed that is it not a UCS-2 implementation. See subject line. OP wishes to compile Python 3 (and almost certainly not 3.1 or 3.2) with the bugginess of Python 2's narrow builds. ChrisA From alister.ware at ntlworld.com Sat Nov 25 18:24:00 2017 From: alister.ware at ntlworld.com (nospam.alister) Date: Sun, 26 Nov 2017 11:24:00 +1200 Subject: connect four (game) References: <872004468@f38.n261.z1.binkp.net> Message-ID: <659368024@f38.n261.z1.binkp.net> On Sat, 25 Nov 2017 12:26:52 -0800, namenobodywants wrote: > On Friday, November 24, 2017 at 8:07:07 AM UTC-8, Chris Angelico wrote: > >> This is the kind of function that needs a docstring and some comments. >> What exactly is this doing? What are the "lines" of the board? What's >> the difference between "linear" and "lines"? What exactly is it >> returning? > > producing documentation is an extremely difficult task for me, but i've > come up with the following: > > """ > makelines(length,numrows,numcolumns) IS THE LIST OF ALL LISTS L, WITH > LENGTH length, OF COORDINATES FROM A numrows x numcolumns MATRIX, SUCH > THAT THE ENTRIES OF L ALL LIE IN A LINE: > > LET horizontal BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN > A HORIZONTAL LINE LET vertical BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE > ENTRIES LIE IN A VERTICAL LINE LET downward BE ALL THE > APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN A DOWNWARD-SLOPING > DIAGONAL LINE LET upward BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE > ENTRIES LIE IN AN UPWARD-SLOPING DIAGONAL LINE THEN > makelines(length,numrows,numcolumns) IS THE UNION OF ALL THE > AFOREMENTIONED SETS """ > > def makelines(length,numrows,numcolumns): > horizontal = [[(i, j+k) for k in range(length)] for i in > range(numrows) for j in range(numcolumns)] > vertical = [[(i+k, j) for k in range(length)] for i in > range(numrows) for j in range(numcolumns)] downward = [[(i+k, j+k) > for k in range(length)] for i in range(numrows) for j in > range(numcolumns)] > upward = [[(i+k, j-k) for k in range(length)] for i in > range(numrows) for j in range(numcolumns)] linear = horizontal + > vertical + downward + upward return [line for line in linear if > all(i in range(6) and j in range(7) for (i,j) in line)] > > def getlines(board): > coordlines = makelines(4,6,7) ## GLOBAL return [[board[square] for > square in line] for line in coordlines > > > i tried to remove all the superfluous spaces from that, but lining up > code vertically is very helpful to me, so i don't think i can really > dispense with the practice > > peace stm the documentation should come after the def statement that way is becomes a "Doc String" & can be accessed using the help function you may also want to check out the recommended way of structuring a doc string, it could help you with your difficulty in writing them (a problem shared by many) -- This door is baroquen, please wiggle Handel. (If I wiggle Handel, will it wiggle Bach?) -- Found on a door in the MSU music building From alister.ware at ntlworld.com Sat Nov 25 18:24:00 2017 From: alister.ware at ntlworld.com (nospam.nospam.alister) Date: Sun, 26 Nov 2017 11:24:00 +1200 Subject: connect four (game) References: <2636970240@f38.n261.z1.binkp.net> Message-ID: <1470798945@f38.n261.z1.binkp.net> On Sat, 25 Nov 2017 12:26:52 -0800, namenobodywants wrote: > On Friday, November 24, 2017 at 8:07:07 AM UTC-8, Chris Angelico wrote: > >> This is the kind of function that needs a docstring and some comments. >> What exactly is this doing? What are the "lines" of the board? What's >> the difference between "linear" and "lines"? What exactly is it >> returning? > > producing documentation is an extremely difficult task for me, but i've > come up with the following: > > """ > makelines(length,numrows,numcolumns) IS THE LIST OF ALL LISTS L, WITH > LENGTH length, OF COORDINATES FROM A numrows x numcolumns MATRIX, SUCH > THAT THE ENTRIES OF L ALL LIE IN A LINE: > > LET horizontal BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN > A HORIZONTAL LINE LET vertical BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE > ENTRIES LIE IN A VERTICAL LINE LET downward BE ALL THE > APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN A DOWNWARD-SLOPING > DIAGONAL LINE LET upward BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE > ENTRIES LIE IN AN UPWARD-SLOPING DIAGONAL LINE THEN > makelines(length,numrows,numcolumns) IS THE UNION OF ALL THE > AFOREMENTIONED SETS """ > > def makelines(length,numrows,numcolumns): > horizontal = [[(i, j+k) for k in range(length)] for i in > range(numrows) for j in range(numcolumns)] > vertical = [[(i+k, j) for k in range(length)] for i in > range(numrows) for j in range(numcolumns)] downward = [[(i+k, j+k) > for k in range(length)] for i in range(numrows) for j in > range(numcolumns)] > upward = [[(i+k, j-k) for k in range(length)] for i in > range(numrows) for j in range(numcolumns)] linear = horizontal + > vertical + downward + upward return [line for line in linear if > all(i in range(6) and j in range(7) for (i,j) in line)] > > def getlines(board): > coordlines = makelines(4,6,7) ## GLOBAL return [[board[square] for > square in line] for line in coordlines > > > i tried to remove all the superfluous spaces from that, but lining up > code vertically is very helpful to me, so i don't think i can really > dispense with the practice > > peace stm the documentation should come after the def statement that way is becomes a "Doc String" & can be accessed using the help function you may also want to check out the recommended way of structuring a doc string, it could help you with your difficulty in writing them (a problem shared by many) -- This door is baroquen, please wiggle Handel. (If I wiggle Handel, will it wiggle Bach?) -- Found on a door in the MSU music building From alister.ware at ntlworld.com Sat Nov 25 18:24:00 2017 From: alister.ware at ntlworld.com (nospam.nospam.nospam.alister) Date: Sun, 26 Nov 2017 11:24:00 +1200 Subject: connect four (game) Message-ID: <308611567@f38.n261.z1.binkp.net> On Sat, 25 Nov 2017 12:26:52 -0800, namenobodywants wrote: > On Friday, November 24, 2017 at 8:07:07 AM UTC-8, Chris Angelico wrote: > >> This is the kind of function that needs a docstring and some comments. >> What exactly is this doing? What are the "lines" of the board? What's >> the difference between "linear" and "lines"? What exactly is it >> returning? > > producing documentation is an extremely difficult task for me, but i've > come up with the following: > > """ > makelines(length,numrows,numcolumns) IS THE LIST OF ALL LISTS L, WITH > LENGTH length, OF COORDINATES FROM A numrows x numcolumns MATRIX, SUCH > THAT THE ENTRIES OF L ALL LIE IN A LINE: > > LET horizontal BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN > A HORIZONTAL LINE LET vertical BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE > ENTRIES LIE IN A VERTICAL LINE LET downward BE ALL THE > APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN A DOWNWARD-SLOPING > DIAGONAL LINE LET upward BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE > ENTRIES LIE IN AN UPWARD-SLOPING DIAGONAL LINE THEN > makelines(length,numrows,numcolumns) IS THE UNION OF ALL THE > AFOREMENTIONED SETS """ > > def makelines(length,numrows,numcolumns): > horizontal = [[(i, j+k) for k in range(length)] for i in > range(numrows) for j in range(numcolumns)] > vertical = [[(i+k, j) for k in range(length)] for i in > range(numrows) for j in range(numcolumns)] downward = [[(i+k, j+k) > for k in range(length)] for i in range(numrows) for j in > range(numcolumns)] > upward = [[(i+k, j-k) for k in range(length)] for i in > range(numrows) for j in range(numcolumns)] linear = horizontal + > vertical + downward + upward return [line for line in linear if > all(i in range(6) and j in range(7) for (i,j) in line)] > > def getlines(board): > coordlines = makelines(4,6,7) ## GLOBAL return [[board[square] for > square in line] for line in coordlines > > > i tried to remove all the superfluous spaces from that, but lining up > code vertically is very helpful to me, so i don't think i can really > dispense with the practice > > peace stm the documentation should come after the def statement that way is becomes a "Doc String" & can be accessed using the help function you may also want to check out the recommended way of structuring a doc string, it could help you with your difficulty in writing them (a problem shared by many) -- This door is baroquen, please wiggle Handel. (If I wiggle Handel, will it wiggle Bach?) -- Found on a door in the MSU music building From __peter__ at web.de Sat Nov 25 18:33:00 2017 From: __peter__ at web.de (nospam.Peter Otten) Date: Sun, 26 Nov 2017 11:33:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! Message-ID: <1451757713@f38.n261.z1.binkp.net> Greg Tibbet wrote: > > I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit > of Java and trying to learn this new-fangled Python language! > > I've got a small program that uses PIL to create an image, draw some > primitives (rectanges, ellipses, etc...) and save it. Works fine... > no issues. > > I've found in the past, the best way to "really learn" the language > was to "dig into the guts" and understand it,.. I thought I was making > progress, but when looking into the PIL library to see what's going on > behind the scenes, I find the following code in ImageDraw.py > > def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) > <...snipped...> > > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? The first argument of ellipse(), self is a strong hint that it is a method. If you look into ImageDraw.py, located at >>> import PIL.ImageDraw >>> PIL.ImageDraw.__file__ '/usr/lib/python3/dist-packages/PIL/ImageDraw.py' on my machine, you'll find the class of the same name, ImageDraw, and in its initializer there's an assignment to the self.draw attribute: self.draw = Image.core.draw(self.im, blend) Image is another module >>> PIL.ImageDraw.Image and if you look for the name 'core' in that module you'll find from PIL import _imaging as core >>> PIL.ImageDraw.Image.core That would be the right time to say "Argh" with any number of exclamation marks for those who don't know C, but since you are familiar with that language there's nothing to stop you from downloading the PIL (or rather the pillow) source and look into the implementation. Once you have the complete code https://pypi.python.org/pypi/Pillow/4.3.0 https://python-pillow.org/ https://github.com/python-pillow/Pillow $ git clone https://github.com/python-pillow/Pillow.git ...you can use traditional tools: $ find Pillow/ -name \*.c -print0 | xargs -0 grep draw_ellipse Pillow/_imaging.c:_draw_ellipse(ImagingDrawObject* self, PyObject* args) Pillow/_imaging.c: {"draw_ellipse", (PyCFunction)_draw_ellipse, 1}, Rinse and repeat ;) From __peter__ at web.de Sat Nov 25 18:33:00 2017 From: __peter__ at web.de (nospam.nospam.Peter Otten) Date: Sun, 26 Nov 2017 11:33:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! Message-ID: <3643674676@f38.n261.z1.binkp.net> Greg Tibbet wrote: > > I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit > of Java and trying to learn this new-fangled Python language! > > I've got a small program that uses PIL to create an image, draw some > primitives (rectanges, ellipses, etc...) and save it. Works fine... > no issues. > > I've found in the past, the best way to "really learn" the language > was to "dig into the guts" and understand it,.. I thought I was making > progress, but when looking into the PIL library to see what's going on > behind the scenes, I find the following code in ImageDraw.py > > def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) > <...snipped...> > > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? The first argument of ellipse(), self is a strong hint that it is a method. If you look into ImageDraw.py, located at >>> import PIL.ImageDraw >>> PIL.ImageDraw.__file__ '/usr/lib/python3/dist-packages/PIL/ImageDraw.py' on my machine, you'll find the class of the same name, ImageDraw, and in its initializer there's an assignment to the self.draw attribute: self.draw = Image.core.draw(self.im, blend) Image is another module >>> PIL.ImageDraw.Image and if you look for the name 'core' in that module you'll find from PIL import _imaging as core >>> PIL.ImageDraw.Image.core That would be the right time to say "Argh" with any number of exclamation marks for those who don't know C, but since you are familiar with that language there's nothing to stop you from downloading the PIL (or rather the pillow) source and look into the implementation. Once you have the complete code https://pypi.python.org/pypi/Pillow/4.3.0 https://python-pillow.org/ https://github.com/python-pillow/Pillow $ git clone https://github.com/python-pillow/Pillow.git ...you can use traditional tools: $ find Pillow/ -name \*.c -print0 | xargs -0 grep draw_ellipse Pillow/_imaging.c:_draw_ellipse(ImagingDrawObject* self, PyObject* args) Pillow/_imaging.c: {"draw_ellipse", (PyCFunction)_draw_ellipse, 1}, Rinse and repeat ;) From nospam.wojtek.mula at gmail.com Sat Nov 25 18:46:00 2017 From: nospam.wojtek.mula at gmail.com (wojtek mula) Date: Sun, 26 Nov 2017 11:46:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode References: <1710523438@f38.n261.z1.binkp.net> Message-ID: <3178508485@f38.n261.z1.binkp.net> On Sunday, November 26, 2017 at 1:00:19 AM UTC+1, Terry Reedy wrote: > You must be trying to compile 2.7. There may be Linux distributions > that compile this way. You're right, I need 2.7. Any hint which distro has got these settings? > If you want to seriously work with unicode, many recommend using modern > Python. I have to fix a bug in my C extension that appears only in UCS-2 python (i.e. Windows). I can reboot to Windows and debug there, but it's pain in a neck for various reasons. w. From tjreedy at udel.edu Sat Nov 25 18:49:40 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 25 Nov 2017 18:49:40 -0500 Subject: connect four (game) In-Reply-To: <196acf58-1e2c-41ea-a175-77eecb526933@googlegroups.com> References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <196acf58-1e2c-41ea-a175-77eecb526933@googlegroups.com> Message-ID: On 11/25/2017 4:57 PM, namenobodywants at gmail.com wrote: > On Saturday, November 25, 2017 at 12:48:38 AM UTC-8, Terry Reedy wrote: > >> I did, and it looks buggy to me. The top and left frame lines are >> missing. If I click a square, the bottom square in the column lights >> up. But then I have no idea whether those are your intentions or not. > i hadn't noticed about the frame lines, but it's the same for me; but i'm hoping you meant to write that the TOP square in a column flashes when you "drop a token" down that column; All squares start white. Only the bottom square turns red or black, after perhaps a .3 second delay during which there is some jitter in white squares above, which could be the effect of white flashing white. > if you really meant the bottom one then i'm totally baffled that it could be the top one for me and the bottom one for you ... is that something that can happen because of a bug? I am running on Windows 10 from IDLE (which should not affect your code) with 3.7.0a2 with tk 8.6.6. The OS and tk version could have an effect, though top versus bottom is hard to fathom. -- Terry Jan Reedy From tjreedy at udel.edu Sat Nov 25 18:59:44 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 25 Nov 2017 18:59:44 -0500 Subject: Compile Python 3 interpreter to force 2-byte unicode In-Reply-To: References: Message-ID: On 11/25/2017 5:12 PM, Chris Angelico wrote: > On Sun, Nov 26, 2017 at 9:05 AM, wrote: >> Hi, my goal is to obtain an interpreter that internally >> uses UCS-2. Such a simple code should print 65535: >> >> import sys >> print sys.maxunicode >> >> This is enabled in Windows, but I want the same in Linux. >> What options have I pass to the configure script? You must be trying to compile 2.7. There may be Linux distributions that compile this way. If you want to use, or ever encounter, non-BMP chars, using surrogate pairs is problematical. By my reading of the official UCS-2 docs, Python's old 16-bit unicode implementation is not fully compliant. Others have claimed that is it not a UCS-2 implementation. > Why do you want to? What useful value do you have in creating this > buggy interpreter? > Ever since Python 3.3, that has simply not been an > option. The bug has been solved. If you want to seriously work with unicode, many recommend using modern Python. -- Terry Jan Reedy From rosuav at gmail.com Sat Nov 25 19:17:08 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 26 Nov 2017 11:17:08 +1100 Subject: Compile Python 3 interpreter to force 2-byte unicode In-Reply-To: References: Message-ID: On Sun, Nov 26, 2017 at 10:59 AM, Terry Reedy wrote: > On 11/25/2017 5:12 PM, Chris Angelico wrote: >> >> On Sun, Nov 26, 2017 at 9:05 AM, wrote: >>> >>> Hi, my goal is to obtain an interpreter that internally >>> uses UCS-2. Such a simple code should print 65535: >>> >>> import sys >>> print sys.maxunicode >>> >>> This is enabled in Windows, but I want the same in Linux. >>> What options have I pass to the configure script? > > > You must be trying to compile 2.7. There may be Linux distributions that > compile this way. If you want to use, or ever encounter, non-BMP chars, > using surrogate pairs is problematical. By my reading of the official UCS-2 > docs, Python's old 16-bit unicode implementation is not fully compliant. > Others have claimed that is it not a UCS-2 implementation. See subject line. OP wishes to compile Python 3 (and almost certainly not 3.1 or 3.2) with the bugginess of Python 2's narrow builds. ChrisA From nospam.ram at zedat.fu-berlin.de Sat Nov 25 19:40:00 2017 From: nospam.ram at zedat.fu-berlin.de (Stefan Ram Stefan Ram) Date: Sun, 26 Nov 2017 12:40:00 +1200 Subject: Stopping an iterator and continuing later References: <3470036897@f38.n261.z1.binkp.net> Message-ID: <2431767487@f38.n261.z1.binkp.net> ram at zedat.fu-berlin.de (Stefan Ram) writes: >Then you can use pickle or custom methods to save and >restore the object, or get the state from an iterator >and create a new iterator with that state later. One does not always have to write a custom class, for example: main.py import pickle r = range( 9 ) i = iter( r ) del r next( i ) next( i ) next( i ) bytes = pickle.dumps( i ) del i i = pickle.loads( bytes ) print( next( i )) del i del pickle transcript 3 From nospam.nospam.ram at zedat.fu-berlin.de Sat Nov 25 19:40:00 2017 From: nospam.nospam.ram at zedat.fu-berlin.de (Stefan Ram Stefan Ram Stefan Ram Stefan Ram) Date: Sun, 26 Nov 2017 12:40:00 +1200 Subject: Stopping an iterator and continuing later Message-ID: <1265117824@f38.n261.z1.binkp.net> ram at zedat.fu-berlin.de (Stefan Ram) writes: >Then you can use pickle or custom methods to save and >restore the object, or get the state from an iterator >and create a new iterator with that state later. One does not always have to write a custom class, for example: main.py import pickle r = range( 9 ) i = iter( r ) del r next( i ) next( i ) next( i ) bytes = pickle.dumps( i ) del i i = pickle.loads( bytes ) print( next( i )) del i del pickle transcript 3 From cs at cskk.id.au Sat Nov 25 20:18:00 2017 From: cs at cskk.id.au (nospam.Cameron Simpson) Date: Sun, 26 Nov 2017 13:18:00 +1200 Subject: Pros and cons of Python sources? Message-ID: <2416792280@f38.n261.z1.binkp.net> On 25Nov2017 08:34, rusi wrote: >On Saturday, November 25, 2017 at 9:45:07 PM UTC+5:30, Michael Torrie wrote: >> The problem with mixing repository-installed packages with pip-installed >> packages is that there's always a chance a Debian update will overwrite >> a pip package, possibly with an older version. Or a pip-installed >> package might bring in a new version that's not compatible with some >> debian-installed package, breaking something. > >On (recent?) debian/ubuntu pip seems to use the 'user-scheme' >which means pip runs without sudo and installs in ~/.local/lib >So I dont believe literal overwriting would occur Though the point should be made that one should run pip as oneself, and try to avoid doing it as the root user (including avoiding sudo). Many UNIX/Linux/etc users believe "installs" should be done as root, and in this case that is easily avoided, with all its potential for damage to the vendor supplied environment. Cheers, Cameron Simpson (formerly cs at zip.com.au) From ned at nedbatchelder.com Sat Nov 25 20:21:22 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 25 Nov 2017 20:21:22 -0500 Subject: Compile Python 3 interpreter to force 2-byte unicode In-Reply-To: References: Message-ID: On 11/25/17 5:05 PM, wojtek.mula at gmail.com wrote: > Hi, my goal is to obtain an interpreter that internally > uses UCS-2. Such a simple code should print 65535: > > import sys > print sys.maxunicode > > This is enabled in Windows, but I want the same in Linux. > What options have I pass to the configure script? > You say you want Python 3, but you also say you have maxunicode == 65535 on Windows.? That must be Python 2.? Python 3 always has maxunicode == 1114111. Can you say more about what you need to do? --Ned. From bc at freeuk.com Sat Nov 25 21:11:00 2017 From: bc at freeuk.com (nospam.bartc) Date: Sun, 26 Nov 2017 14:11:00 +1200 Subject: connect four (game) References: <3860907026@f38.n261.z1.binkp.net> Message-ID: <1920166871@f38.n261.z1.binkp.net> On 25/11/2017 16:07, Michael Torrie wrote: > On 11/25/2017 06:00 AM, bartc wrote: >> And there's a quite lot left of the rest of the program to worry about too! >> >> If you add 'window()' at the end of the program, then it seems to run on >> Python 3. I'd play around with it first before thinking up strategies >> for testing it. > > Actually, no. Unit testing ideally should be done for each and every > class as they are being written (before they are written in fact), no > matter how small and trivial the class. That way as you compose larger > and larger units of code, the chances of things being right is greater > compared to doing it the other way around. The way I write code isn't incrementally top down or bottom up. It's backwards and forwards. Feedback from different parts means the thing develops as a whole. Sometimes parts are split into distinct sections, sometimes different parts are merged. Sometimes you realise you're on the wrong track, and sections have to be redone or a different approach used, which can be done in the earlier stages. If I had to bother with such systematic tests as you suggest, and finish and sign off everything before proceeding further, then nothing would ever get done. (Maybe it's viable if working from an exacting specification that someone else has already worked out.) I've also found that many of the bugs that do appear, also do so in ways you never anticipated. Or in circumstances you would never have thought of. (I've always thought that programming is a bit like creating new laws. The same laws need to work for everyone and in any circumstances, but no one can foresee everything, and laws need to be tweaked and added to. Perhaps unit tests can apply there too...) > You may argue that testing doesn't matter for his small game, written > for his own education and amusement. The fact is that software in > general is of abysmal quality across the boards, and promoting a habit > of unit testing is good, even for trivial, home-grown stuff. I thought people were being hard on the OP. As for testing, I remember in a company I worked in, a complicated circuit was submitted to a company that would put it into a mass-produced chip. This company did massive numbers of emulated tests shown on a huge printout that showed that all combinations of inputs and outputs worked exactly as intended. Except the actual chip didn't work. As for the printout, the designer took it home and used it as an underlay for a new carpet. A rather expensive underlay. -- bartc From bc at freeuk.com Sat Nov 25 21:11:00 2017 From: bc at freeuk.com (nospam.nospam.bartc) Date: Sun, 26 Nov 2017 14:11:00 +1200 Subject: connect four (game) References: <3714713356@f38.n261.z1.binkp.net> Message-ID: <1992954407@f38.n261.z1.binkp.net> On 25/11/2017 16:07, Michael Torrie wrote: > On 11/25/2017 06:00 AM, bartc wrote: >> And there's a quite lot left of the rest of the program to worry about too! >> >> If you add 'window()' at the end of the program, then it seems to run on >> Python 3. I'd play around with it first before thinking up strategies >> for testing it. > > Actually, no. Unit testing ideally should be done for each and every > class as they are being written (before they are written in fact), no > matter how small and trivial the class. That way as you compose larger > and larger units of code, the chances of things being right is greater > compared to doing it the other way around. The way I write code isn't incrementally top down or bottom up. It's backwards and forwards. Feedback from different parts means the thing develops as a whole. Sometimes parts are split into distinct sections, sometimes different parts are merged. Sometimes you realise you're on the wrong track, and sections have to be redone or a different approach used, which can be done in the earlier stages. If I had to bother with such systematic tests as you suggest, and finish and sign off everything before proceeding further, then nothing would ever get done. (Maybe it's viable if working from an exacting specification that someone else has already worked out.) I've also found that many of the bugs that do appear, also do so in ways you never anticipated. Or in circumstances you would never have thought of. (I've always thought that programming is a bit like creating new laws. The same laws need to work for everyone and in any circumstances, but no one can foresee everything, and laws need to be tweaked and added to. Perhaps unit tests can apply there too...) > You may argue that testing doesn't matter for his small game, written > for his own education and amusement. The fact is that software in > general is of abysmal quality across the boards, and promoting a habit > of unit testing is good, even for trivial, home-grown stuff. I thought people were being hard on the OP. As for testing, I remember in a company I worked in, a complicated circuit was submitted to a company that would put it into a mass-produced chip. This company did massive numbers of emulated tests shown on a huge printout that showed that all combinations of inputs and outputs worked exactly as intended. Except the actual chip didn't work. As for the printout, the designer took it home and used it as an underlay for a new carpet. A rather expensive underlay. -- bartc From bc at freeuk.com Sat Nov 25 21:11:00 2017 From: bc at freeuk.com (nospam.nospam.nospam.bartc) Date: Sun, 26 Nov 2017 14:11:00 +1200 Subject: connect four (game) Message-ID: <3387368585@f38.n261.z1.binkp.net> On 25/11/2017 16:07, Michael Torrie wrote: > On 11/25/2017 06:00 AM, bartc wrote: >> And there's a quite lot left of the rest of the program to worry about too! >> >> If you add 'window()' at the end of the program, then it seems to run on >> Python 3. I'd play around with it first before thinking up strategies >> for testing it. > > Actually, no. Unit testing ideally should be done for each and every > class as they are being written (before they are written in fact), no > matter how small and trivial the class. That way as you compose larger > and larger units of code, the chances of things being right is greater > compared to doing it the other way around. The way I write code isn't incrementally top down or bottom up. It's backwards and forwards. Feedback from different parts means the thing develops as a whole. Sometimes parts are split into distinct sections, sometimes different parts are merged. Sometimes you realise you're on the wrong track, and sections have to be redone or a different approach used, which can be done in the earlier stages. If I had to bother with such systematic tests as you suggest, and finish and sign off everything before proceeding further, then nothing would ever get done. (Maybe it's viable if working from an exacting specification that someone else has already worked out.) I've also found that many of the bugs that do appear, also do so in ways you never anticipated. Or in circumstances you would never have thought of. (I've always thought that programming is a bit like creating new laws. The same laws need to work for everyone and in any circumstances, but no one can foresee everything, and laws need to be tweaked and added to. Perhaps unit tests can apply there too...) > You may argue that testing doesn't matter for his small game, written > for his own education and amusement. The fact is that software in > general is of abysmal quality across the boards, and promoting a habit > of unit testing is good, even for trivial, home-grown stuff. I thought people were being hard on the OP. As for testing, I remember in a company I worked in, a complicated circuit was submitted to a company that would put it into a mass-produced chip. This company did massive numbers of emulated tests shown on a huge printout that showed that all combinations of inputs and outputs worked exactly as intended. Except the actual chip didn't work. As for the printout, the designer took it home and used it as an underlay for a new carpet. A rather expensive underlay. -- bartc From cs at cskk.id.au Sat Nov 25 21:18:18 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 26 Nov 2017 13:18:18 +1100 Subject: Pros and cons of Python sources? In-Reply-To: <7031295c-3341-4eb9-8737-a4a122b50672@googlegroups.com> References: <7031295c-3341-4eb9-8737-a4a122b50672@googlegroups.com> Message-ID: <20171126021818.GA60833@cskk.homeip.net> On 25Nov2017 08:34, rusi wrote: >On Saturday, November 25, 2017 at 9:45:07 PM UTC+5:30, Michael Torrie wrote: >> The problem with mixing repository-installed packages with pip-installed >> packages is that there's always a chance a Debian update will overwrite >> a pip package, possibly with an older version. Or a pip-installed >> package might bring in a new version that's not compatible with some >> debian-installed package, breaking something. > >On (recent?) debian/ubuntu pip seems to use the 'user-scheme' >which means pip runs without sudo and installs in ~/.local/lib >So I dont believe literal overwriting would occur Though the point should be made that one should run pip as oneself, and try to avoid doing it as the root user (including avoiding sudo). Many UNIX/Linux/etc users believe "installs" should be done as root, and in this case that is easily avoided, with all its potential for damage to the vendor supplied environment. Cheers, Cameron Simpson (formerly cs at zip.com.au) From bc at freeuk.com Sat Nov 25 21:25:00 2017 From: bc at freeuk.com (nospam.bartc) Date: Sun, 26 Nov 2017 14:25:00 +1200 Subject: connect four (game) References: <937017507@f38.n261.z1.binkp.net> Message-ID: <2652119435@f38.n261.z1.binkp.net> On 25/11/2017 23:49, Terry Reedy wrote: > On 11/25/2017 4:57 PM, namenobodywants at gmail.com wrote: >> On Saturday, November 25, 2017 at 12:48:38 AM UTC-8, Terry Reedy wrote: >> >>> I did, and it looks buggy to me.? The top and left frame lines are >>> missing.? If I click a square, the bottom square in the column lights >>> up.? But then I have no idea whether those are your intentions or not. >> i hadn't noticed about the frame lines, but it's the same for me; but >> i'm hoping you meant to write that the TOP square in a column flashes >> when you "drop a token" down that column; > > All squares start white.? Only the bottom square turns red or black, > after perhaps a .3 second delay during which there is some jitter in > white squares above, which could be the effect of white flashing white. There are a couple of lines that look like this: self.grid.squarebuttons[column].flash() If you comment out those two lines, then the flashing disappears, and it still works. Of course, if I'd used unit tests, I'd have figured that out a lot sooner. I would just have had the somewhat bigger problem of devising a unit test that would detect this. -- bartc From bc at freeuk.com Sat Nov 25 21:25:00 2017 From: bc at freeuk.com (nospam.nospam.bartc) Date: Sun, 26 Nov 2017 14:25:00 +1200 Subject: connect four (game) References: <4166889833@f38.n261.z1.binkp.net> Message-ID: <4215648396@f38.n261.z1.binkp.net> On 25/11/2017 23:49, Terry Reedy wrote: > On 11/25/2017 4:57 PM, namenobodywants at gmail.com wrote: >> On Saturday, November 25, 2017 at 12:48:38 AM UTC-8, Terry Reedy wrote: >> >>> I did, and it looks buggy to me.? The top and left frame lines are >>> missing.? If I click a square, the bottom square in the column lights >>> up.? But then I have no idea whether those are your intentions or not. >> i hadn't noticed about the frame lines, but it's the same for me; but >> i'm hoping you meant to write that the TOP square in a column flashes >> when you "drop a token" down that column; > > All squares start white.? Only the bottom square turns red or black, > after perhaps a .3 second delay during which there is some jitter in > white squares above, which could be the effect of white flashing white. There are a couple of lines that look like this: self.grid.squarebuttons[column].flash() If you comment out those two lines, then the flashing disappears, and it still works. Of course, if I'd used unit tests, I'd have figured that out a lot sooner. I would just have had the somewhat bigger problem of devising a unit test that would detect this. -- bartc From bc at freeuk.com Sat Nov 25 21:25:00 2017 From: bc at freeuk.com (nospam.nospam.nospam.bartc) Date: Sun, 26 Nov 2017 14:25:00 +1200 Subject: connect four (game) Message-ID: <2236389504@f38.n261.z1.binkp.net> On 25/11/2017 23:49, Terry Reedy wrote: > On 11/25/2017 4:57 PM, namenobodywants at gmail.com wrote: >> On Saturday, November 25, 2017 at 12:48:38 AM UTC-8, Terry Reedy wrote: >> >>> I did, and it looks buggy to me.? The top and left frame lines are >>> missing.? If I click a square, the bottom square in the column lights >>> up.? But then I have no idea whether those are your intentions or not. >> i hadn't noticed about the frame lines, but it's the same for me; but >> i'm hoping you meant to write that the TOP square in a column flashes >> when you "drop a token" down that column; > > All squares start white.? Only the bottom square turns red or black, > after perhaps a .3 second delay during which there is some jitter in > white squares above, which could be the effect of white flashing white. There are a couple of lines that look like this: self.grid.squarebuttons[column].flash() If you comment out those two lines, then the flashing disappears, and it still works. Of course, if I'd used unit tests, I'd have figured that out a lot sooner. I would just have had the somewhat bigger problem of devising a unit test that would detect this. -- bartc From bc at freeuk.com Sat Nov 25 22:39:00 2017 From: bc at freeuk.com (nospam.bartc) Date: Sun, 26 Nov 2017 15:39:00 +1200 Subject: connect four (game) References: <2225514370@f38.n261.z1.binkp.net> Message-ID: <3028938924@f38.n261.z1.binkp.net> On 26/11/2017 14:23, Chris Angelico wrote: > On Mon, Nov 27, 2017 at 1:11 AM, bartc wrote: >> The way I write code isn't incrementally top down or bottom up. It's >> backwards and forwards. Feedback from different parts means the thing >> develops as a whole. Sometimes parts are split into distinct sections, >> sometimes different parts are merged. >> >> Sometimes you realise you're on the wrong track, and sections have to be >> redone or a different approach used, which can be done in the earlier >> stages. >> >> If I had to bother with such systematic tests as you suggest, and finish and >> sign off everything before proceeding further, then nothing would ever get >> done. (Maybe it's viable if working from an exacting specification that >> someone else has already worked out.) > > Everyone in the world has the same problem, yet many of us manage to > write useful tests. I wonder whether you're somehow special in that > testing fundamentally doesn't work for you, or that you actually don't > need to write tests. Or maybe tests would still be useful for you too. > Could go either way. Testing everything comprehensively just wouldn't be useful for me who works on whole applications, whole concepts, not just a handful of functions with well-defined inputs and outputs. And even then, it might work perfectly, but be too slow, or they take up too much space. Take one example of a small program I've mentioned in the past, a jpeg decoder. I had to port this into several languages (one of which was Python actually). It was hard because I didn't know how it was meant to work. Only as a whole when the input is a .jpeg file, and the output might be a .ppm file that ought to look like the one produced by a working program, or the original jpeg displayed by a working viewer. (Which is not possible in all applications.) How to do an automatic test? Directly doing a binary compare on the output doesn't work because in jpeg, there can be differences of +/- 1 bit in the results. And even if the test detected a mismatch, then what? I now know there is a problem, but I could figure that out by looking at the output! And actually, after it ostensibly worked, there WAS a minor problem: some types of images exhibited excessive chroma noise around sharp transitions. The problem was traced to two lines that were in the wrong order (in the original program). I can't see how unit tests can have helped in any way at all, and it would probably have taken much longer. And THIS was a small, well-defined task which had already been written. >> Except the actual chip didn't work. As for the printout, the designer took >> it home and used it as an underlay for a new carpet. A rather expensive >> underlay. > > So there was something else wrong with the chip. I'm not sure what > your point is. The extensive testing was like unit testing, but needed to be even more thorough because of the commitment involved. It failed to spot a problem. And actually I had a similar problem with a new car. I took it back to the dealer, and they said they plugged the on-board computer into their analyser, which did all sorts of tests and said there was nothing wrong with it. But there was, and the problem has persisted for a decade [to do with the central locking]. I'm saying you can rely too much on these tests, and waste too much time on them. Perhaps that is a necessity in a large organisation or in a large team, where there is a leader to look at the big picture. It doesn't work for individuals working on one project. -- bartc From bc at freeuk.com Sat Nov 25 22:39:00 2017 From: bc at freeuk.com (nospam.nospam.bartc) Date: Sun, 26 Nov 2017 15:39:00 +1200 Subject: connect four (game) Message-ID: <166991928@f38.n261.z1.binkp.net> On 26/11/2017 14:23, Chris Angelico wrote: > On Mon, Nov 27, 2017 at 1:11 AM, bartc wrote: >> The way I write code isn't incrementally top down or bottom up. It's >> backwards and forwards. Feedback from different parts means the thing >> develops as a whole. Sometimes parts are split into distinct sections, >> sometimes different parts are merged. >> >> Sometimes you realise you're on the wrong track, and sections have to be >> redone or a different approach used, which can be done in the earlier >> stages. >> >> If I had to bother with such systematic tests as you suggest, and finish and >> sign off everything before proceeding further, then nothing would ever get >> done. (Maybe it's viable if working from an exacting specification that >> someone else has already worked out.) > > Everyone in the world has the same problem, yet many of us manage to > write useful tests. I wonder whether you're somehow special in that > testing fundamentally doesn't work for you, or that you actually don't > need to write tests. Or maybe tests would still be useful for you too. > Could go either way. Testing everything comprehensively just wouldn't be useful for me who works on whole applications, whole concepts, not just a handful of functions with well-defined inputs and outputs. And even then, it might work perfectly, but be too slow, or they take up too much space. Take one example of a small program I've mentioned in the past, a jpeg decoder. I had to port this into several languages (one of which was Python actually). It was hard because I didn't know how it was meant to work. Only as a whole when the input is a .jpeg file, and the output might be a .ppm file that ought to look like the one produced by a working program, or the original jpeg displayed by a working viewer. (Which is not possible in all applications.) How to do an automatic test? Directly doing a binary compare on the output doesn't work because in jpeg, there can be differences of +/- 1 bit in the results. And even if the test detected a mismatch, then what? I now know there is a problem, but I could figure that out by looking at the output! And actually, after it ostensibly worked, there WAS a minor problem: some types of images exhibited excessive chroma noise around sharp transitions. The problem was traced to two lines that were in the wrong order (in the original program). I can't see how unit tests can have helped in any way at all, and it would probably have taken much longer. And THIS was a small, well-defined task which had already been written. >> Except the actual chip didn't work. As for the printout, the designer took >> it home and used it as an underlay for a new carpet. A rather expensive >> underlay. > > So there was something else wrong with the chip. I'm not sure what > your point is. The extensive testing was like unit testing, but needed to be even more thorough because of the commitment involved. It failed to spot a problem. And actually I had a similar problem with a new car. I took it back to the dealer, and they said they plugged the on-board computer into their analyser, which did all sorts of tests and said there was nothing wrong with it. But there was, and the problem has persisted for a decade [to do with the central locking]. I'm saying you can rely too much on these tests, and waste too much time on them. Perhaps that is a necessity in a large organisation or in a large team, where there is a leader to look at the big picture. It doesn't work for individuals working on one project. -- bartc From rosuav at gmail.com Sat Nov 25 23:00:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Sun, 26 Nov 2017 16:00:00 +1200 Subject: Compile Python 3 interpreter to force 2-byte unicode Message-ID: <2413003985@f38.n261.z1.binkp.net> On Sun, Nov 26, 2017 at 3:53 PM, Rustom Mody wrote: > On Sunday, November 26, 2017 at 3:43:29 AM UTC+5:30, Chris Angelico wrote: >> On Sun, Nov 26, 2017 at 9:05 AM, wojtek.mula wrote: >> > Hi, my goal is to obtain an interpreter that internally >> > uses UCS-2. Such a simple code should print 65535: >> > >> > import sys >> > print sys.maxunicode >> > >> > This is enabled in Windows, but I want the same in Linux. >> > What options have I pass to the configure script? >> >> Why do you want to? What useful value do you have in creating this >> buggy interpreter? > > I see that you are familiar with this bug: https://bugs.python.org/issue13153 > > And I see it or something very close is still buggy in python 3.5 > [No it does not allow me to paste an SMP char but if I open a file containing > one it crashes and rather messily ? ? no way to close the idle other than killing > the shell] > > No thats not a diatribe against idle; just that its reasonable to want python > to support work-arounds for reasonably common bugs in the current unicode-ecosystem No, that issue is about IDLE (and, AIUI, is actually a Tcl/Tk limitation). I'm talking about how Windows Pythons up to 3.2 could take a single character and treat it as two, or could reverse a string and make it actually not contain code points any more, or get all the subscripts off by one (or more than one). That didn't happen on the Linux builds. They had the lesser problem that all strings consumed large amounts of memory. As of Python 3.3, neither problem exists on either platform. You can't compile them back in. ChrisA From rustompmody at gmail.com Sat Nov 25 23:53:44 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 25 Nov 2017 20:53:44 -0800 (PST) Subject: Compile Python 3 interpreter to force 2-byte unicode In-Reply-To: References: Message-ID: <645bfee7-8ab5-439a-9a24-2a13b6597021@googlegroups.com> On Sunday, November 26, 2017 at 3:43:29 AM UTC+5:30, Chris Angelico wrote: > On Sun, Nov 26, 2017 at 9:05 AM, wojtek.mula wrote: > > Hi, my goal is to obtain an interpreter that internally > > uses UCS-2. Such a simple code should print 65535: > > > > import sys > > print sys.maxunicode > > > > This is enabled in Windows, but I want the same in Linux. > > What options have I pass to the configure script? > > Why do you want to? What useful value do you have in creating this > buggy interpreter? I see that you are familiar with this bug: https://bugs.python.org/issue13153 And I see it or something very close is still buggy in python 3.5 [No it does not allow me to paste an SMP char but if I open a file containing one it crashes and rather messily ? no way to close the idle other than killing the shell] No thats not a diatribe against idle; just that its reasonable to want python to support work-arounds for reasonably common bugs in the current unicode-ecosystem From rosuav at gmail.com Sun Nov 26 00:00:56 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 26 Nov 2017 16:00:56 +1100 Subject: Compile Python 3 interpreter to force 2-byte unicode In-Reply-To: <645bfee7-8ab5-439a-9a24-2a13b6597021@googlegroups.com> References: <645bfee7-8ab5-439a-9a24-2a13b6597021@googlegroups.com> Message-ID: On Sun, Nov 26, 2017 at 3:53 PM, Rustom Mody wrote: > On Sunday, November 26, 2017 at 3:43:29 AM UTC+5:30, Chris Angelico wrote: >> On Sun, Nov 26, 2017 at 9:05 AM, wojtek.mula wrote: >> > Hi, my goal is to obtain an interpreter that internally >> > uses UCS-2. Such a simple code should print 65535: >> > >> > import sys >> > print sys.maxunicode >> > >> > This is enabled in Windows, but I want the same in Linux. >> > What options have I pass to the configure script? >> >> Why do you want to? What useful value do you have in creating this >> buggy interpreter? > > I see that you are familiar with this bug: https://bugs.python.org/issue13153 > > And I see it or something very close is still buggy in python 3.5 > [No it does not allow me to paste an SMP char but if I open a file containing > one it crashes and rather messily ? no way to close the idle other than killing > the shell] > > No thats not a diatribe against idle; just that its reasonable to want python > to support work-arounds for reasonably common bugs in the current unicode-ecosystem No, that issue is about IDLE (and, AIUI, is actually a Tcl/Tk limitation). I'm talking about how Windows Pythons up to 3.2 could take a single character and treat it as two, or could reverse a string and make it actually not contain code points any more, or get all the subscripts off by one (or more than one). That didn't happen on the Linux builds. They had the lesser problem that all strings consumed large amounts of memory. As of Python 3.3, neither problem exists on either platform. You can't compile them back in. ChrisA From tmrsg11 at gmail.com Sun Nov 26 00:47:00 2017 From: tmrsg11 at gmail.com (nospam.C W) Date: Sun, 26 Nov 2017 17:47:00 +1200 Subject: I have anaconda, but Pycharm can't find it Message-ID: <4197600688@f38.n261.z1.binkp.net> Hello all, I am a first time PyCharm user. I have Python 3 and Anaconda installed. They work together on Sublime Text, but not on Pycharm. Pycharm tells me it cannot find modules numpy, matplotlib, etc. What should I do? I tried to set the interpreter environment, and a few other options, none seem to work. This is the typical solution, but it does not work https://stackoverflow.com/questions/35623776/import-numpy-on-pycharm Thanks, -Mike From skip.montanaro at gmail.com Sun Nov 26 01:04:00 2017 From: skip.montanaro at gmail.com (nospam.Skip Montanaro) Date: Sun, 26 Nov 2017 18:04:00 +1200 Subject: [META] Why are duplicate posts coming through? Message-ID: <812493364@f38.n261.z1.binkp.net> Chris, Please forward one or two to me. Mark Sapiro and I have been banging on the SpamBayes instance which supports the Usenet gateway. I suppose it's possible some change caused the problem you're seeing. Skip On Nov 26, 2017 5:22 PM, "Chris Angelico" wrote: Not sure whether this is an issue for -owner or not; apologies if not. I'm seeing a whole lot of reasonably-recent posts getting re-sent, with "nospam" attached to the posters' names. And they're getting re-sent multiple times. Sometimes the posts have encoding problems (small amounts of mojibake). What's going on? Is there something going haywire with the news/mail gateway? Is there a rogue client re-posting a bunch of news? Somebody testing something? ChrisA -- https://mail.python.org/mailman/listinfo/python-list From rustompmody at gmail.com Sun Nov 26 01:36:00 2017 From: rustompmody at gmail.com (nospam.Rustom Mody) Date: Sun, 26 Nov 2017 18:36:00 +1200 Subject: [META] Why are duplicate posts coming through? Message-ID: <2226933913@f38.n261.z1.binkp.net> On Monday, November 27, 2017 at 5:35:09 AM UTC+5:30, Skip Montanaro wrote: > Chris, > > Please forward one or two to me. Mark Sapiro and I have been banging on the > SpamBayes instance which supports the Usenet gateway. I suppose it's > possible some change caused the problem you're seeing. > > Skip > > On Nov 26, 2017 5:22 PM, "Chris Angelico" wrote: > > Not sure whether this is an issue for -owner or not; apologies if not. > > I'm seeing a whole lot of reasonably-recent posts getting re-sent, > with "nospam" attached to the posters' names. And they're getting > re-sent multiple times. Sometimes the posts have encoding problems > (small amounts of mojibake). > > What's going on? Is there something going haywire with the news/mail > gateway? Is there a rogue client re-posting a bunch of news? Somebody > testing something? And the spam continues unabated Except that the subject lines are changed From storchaka at gmail.com Sun Nov 26 01:54:49 2017 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sun, 26 Nov 2017 08:54:49 +0200 Subject: Compile Python 3 interpreter to force 2-byte unicode In-Reply-To: References: Message-ID: 26.11.17 01:59, Terry Reedy ????: > On 11/25/2017 5:12 PM, Chris Angelico wrote: >> On Sun, Nov 26, 2017 at 9:05 AM,? wrote: >>> Hi, my goal is to obtain an interpreter that internally >>> uses UCS-2. Such a simple code should print 65535: >>> >>> ?? import sys >>> ?? print sys.maxunicode >>> >>> This is enabled in Windows, but I want the same in Linux. >>> What options have I pass to the configure script? > > You must be trying to compile 2.7.? There may be Linux distributions > that compile this way. UCS-2 is the default in 2.7. But most Linux distributions build it with UCS-4. From skip.montanaro at gmail.com Sun Nov 26 02:14:00 2017 From: skip.montanaro at gmail.com (nospam.Skip Montanaro) Date: Sun, 26 Nov 2017 19:14:00 +1200 Subject: nospam ** infinity? Message-ID: <2537735172@f38.n261.z1.binkp.net> > There seems to be a gateway loop of some sort going on. > I'm seeing multiple versions of the same posts in > comp.lang.python with different numbers of "nospam"s > prepended to the email address. This is the second thread about this. I was thinking it might be related to recent changes to the gate_news process on mail.python.org, but this fingerprint looks nothing like what gate_news does. Looking at a somewhat long-ish thread: https://groups.google.com/d/topic/comp.lang.python/YoxLtkzlt_o/discussion I see a couple posts from Chris Angelico, only some of which have a "nospam" preface. It would seem that someone was trying to mark certain posters as "not spammy," (I'm sure Chris is flattered) and somehow posts with that private marking leaked out of the user's system starting in the past twelve hours or so. Newsreader configuration problem? Skip From torriem at gmail.com Sun Nov 26 02:55:00 2017 From: torriem at gmail.com (nospam.Michael Torrie) Date: Sun, 26 Nov 2017 19:55:00 +1200 Subject: connect four (game) Message-ID: <3250420516@f38.n261.z1.binkp.net> On 11/26/2017 07:11 AM, bartc wrote: >> You may argue that testing doesn't matter for his small game, written >> for his own education and amusement. The fact is that software in >> general is of abysmal quality across the boards, and promoting a habit >> of unit testing is good, even for trivial, home-grown stuff. > > I thought people were being hard on the OP. I wasn't being hard on the OP. My observation is about the state of *all* software. My software especially, your software, Microsoft's software. It all is of rather poor quality compared to the rigors of other industries like civil engineering, manufacturing, etc. > As for testing, I remember in a company I worked in, a complicated > circuit was submitted to a company that would put it into a > mass-produced chip. This company did massive numbers of emulated tests > shown on a huge printout that showed that all combinations of inputs and > outputs worked exactly as intended. > > Except the actual chip didn't work. As for the printout, the designer > took it home and used it as an underlay for a new carpet. A rather > expensive underlay. That's unfortunately, but seems to reinforce the notion that adequate testing is required. Clearly for a microchip, theoretically testing the chip's "software" (for lack of a better term) was not adequate. An analogy to our software situation is that someone tested the algorithm, but not the actual, in-use implementation of the algorithm. From torriem at gmail.com Sun Nov 26 03:04:00 2017 From: torriem at gmail.com (nospam.Michael Torrie) Date: Sun, 26 Nov 2017 20:04:00 +1200 Subject: connect four (game) Message-ID: <2617264369@f38.n261.z1.binkp.net> On 11/26/2017 08:39 AM, bartc wrote: > The problem was traced to two lines that were in the wrong order (in the > original program). I can't see how unit tests can have helped in any way > at all, and it would probably have taken much longer. What makes you think that? Surely other decoders were doing the right thing and you could compare your output against theirs? JPEGs may be lossy but the path through the decoder should be deterministic. Or even if every decoder is slightly unique, at least yours should output self-consistent data. In other words, once you know you fixed the chroma problem, you can use that jpeg as a unit test to make sure future big fixes and enhancements don't break something else. Regression testing is very important. Many times I've fixed a bug, only to introduce new ones that broke formerly correct behavior. Anyway, unit testing is certainly a challenging concept, and I'm no more good at it than you are. From rustompmody at gmail.com Sun Nov 26 03:04:00 2017 From: rustompmody at gmail.com (nospam.Rustom Mody) Date: Sun, 26 Nov 2017 20:04:00 +1200 Subject: connect four (game) References: <2961545766@f38.n261.z1.binkp.net> Message-ID: <3056496050@f38.n261.z1.binkp.net> On Monday, November 27, 2017 at 9:08:42 AM UTC+5:30, Chris Angelico wrote: > On Mon, Nov 27, 2017 at 1:55 PM, Michael Torrie wrote: > > On 11/26/2017 07:11 AM, bartc wrote: > >>> You may argue that testing doesn't matter for his small game, written > >>> for his own education and amusement. The fact is that software in > >>> general is of abysmal quality across the boards, and promoting a habit > >>> of unit testing is good, even for trivial, home-grown stuff. > >> > >> I thought people were being hard on the OP. > > > > I wasn't being hard on the OP. My observation is about the state of > > *all* software. My software especially, your software, Microsoft's > > software. It all is of rather poor quality compared to the rigors of > > other industries like civil engineering, manufacturing, etc. > > Not all software is poor quality compared to all examples of those > industries. You'll find the equivalent of software bugs in a lot of > hardware situations; the difference with software is that we have 100% > perfect reproduction in the end-user products, so we call it a design > flaw instead of a production artifact. (How often do you buy a box of > something and find that a couple of them just break?) Even in > large-scale civil engineering projects, there are plenty of > stupidities. The house I'm living in has a place where the tiled floor > doesn't quite align with the wall that it meets, and I can't figure > out why; somewhere, two things that ought to have been parallel just > aren't. Bridges have been known to crack, cars break down for no good > reason, your hamburger just doesn't taste right today. > > Aviators have pinned down the best solution to this, I think. A pilot > is not expected to be perfect; he is expected to follow checklists. A > preflight checklist. A departure checklist. A landing checklist. > Everything that needs to be done right is mentioned on the list, and > you just go through the list and make sure you've done everything. And thats where the analogy breaks down. Presumably a 50 person short-flight and a 600-person transcontinental may have at least something in common in their pilot-checklists What common will you find in a multi-million line OS, a thousand line script and a student prime-numbers first-program? No I am not dissing on testing and TDD; just that universality?1 of computing devices is something that our civilization is nowhere near understanding, leave alone dealing with ? ? two programs can be more far apart than a bullock cart and a jet. And yet they are both programs ?1 Ive seen CS PhDs ask a student why a student didnt incorporate some error-checking into his compiler which amounted to solving the halting problem. More mundanely I see students have a hard time seeing their phones and their laptops as 'the same' From torriem at gmail.com Sun Nov 26 03:09:00 2017 From: torriem at gmail.com (nospam.Michael Torrie) Date: Sun, 26 Nov 2017 20:09:00 +1200 Subject: connect four (game) Message-ID: <1134053142@f38.n261.z1.binkp.net> On 11/25/2017 12:58 PM, namenobodywants at gmail.com wrote: > the idea is that there should be exactly one object posinf (positive infinity) that compares as strictly greater than any number ever considered, and exactly one object neginf that compares as strictly less; as the code stands now there is no reason not to use +/-70 in that capacity; the "infinity" class is there so that the game-playing parts of the code (which at present are intentionally as primitive as possible) can be modified more smoothly later; the single place where "infinity" is instantiated is in the function "getvalue", which returns the value of a finished game: > > def getvalue(winner,accessibles): > return Infinity(+1) if winner == ex else Infinity(-1) if winner == oh else 0 if not accessibles else None > > if ex has won then the value of the game is posinf; if oh has won then it's neginf; if the game is tied (no winner but no accessible columns remaining) then the value of the game is zero; otherwise the game is not finished and its finished value is None So you are using this Infinity class as a sentinel value of some kind? Representing game state? There may be an easier way than a full on custom type. Sometimes just a sentinel object is sufficient. Or an enumeration. From cs at cskk.id.au Sun Nov 26 04:01:00 2017 From: cs at cskk.id.au (nospam.Cameron Simpson) Date: Sun, 26 Nov 2017 21:01:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! Message-ID: <1988977080@f38.n261.z1.binkp.net> On 26Nov2017 01:09, Greg Tibbet wrote: >I've got a small program that uses PIL to create an image, draw some >primitives (rectanges, ellipses, etc...) and save it. Works fine... >no issues. > >I've found in the past, the best way to "really learn" the language >was to "dig into the guts" and understand it,.. I thought I was making >progress, but when looking into the PIL library to see what's going on >behind the scenes, I find the following code in ImageDraw.py > >def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) ><...snipped...> > >ellipse() uses the method self.draw.draw_ellipse() Okay, fine... >but WHERE is draw_ellipse defined?? What magic is happening there? >I've searched the entire PIL directory tree, and the ONLY two places >draw_ellipse is mentioned are right there in the ellipse() function... >WHAT am I missing?? "ellispse()" is a method in the ImageDraw class. Looking at the __init__ method of that class we see: self.draw = Image.core.draw(self.im, blend) so "self.draw" in your code above is the result of "Image.core.draw(self.im, blend)". "Image" is the Image module imported at the top of ImageDraw.py. So we hop over to Image.py, which has this code: try: # If the _imaging C module is not present, you can still use # the "open" function to identify files, but you cannot load # them. Note that other modules should not refer to _imaging # directly; import Image and use the Image.core variable instead. import _imaging core = _imaging del _imaging except ImportError, v: core = _imaging_not_installed() if str(v)[:20] == "Module use of python" and warnings: # The _imaging C module is present, but not compiled for # the right version (windows only). Print a warning, if # possible. warnings.warn( "The _imaging extension was built for another version " "of Python; most PIL functions will be disabled", RuntimeWarning ) Now the import works (because you'd get exceptions otherwise), so code which matters is that the top of that: import _imaging core = _imaging del _imaging So "core" is a reference to the "_imaging" module (and the name "_imaging" has been discarded). So... The name Image.core is now a reference to that module. So back in ImageDraw, the call to "Image.core.draw()" called the function "draw" from the _imaging module, which presumably returns some kind of drawing object, and _that_ object has a "draw_ellispe" method. Now, dynamic languages like Python don't lend themselves to screamingly fast compute, so expensive stuff like drawing graphics is usually done by hooking into special purpose libraries written in C or something that compiles to efficient machine level code (C++, Go, what have you). You can ship C code with Python to be compiled on the target and presented to Python as a library, and by convention such modules are named with a leading underscore. So we can expect that _imaging is a C code module. And if you go up a level you'll find _imaging.c, with a draw_ellipse function inside it. Cheers, Cameron Simpson (formerly cs at zip.com.au) From cs at cskk.id.au Sun Nov 26 04:01:00 2017 From: cs at cskk.id.au (nospam.nospam.Cameron Simpson) Date: Sun, 26 Nov 2017 21:01:00 +1200 Subject: Argh!! Can't wrap my head around this Python stuff! Message-ID: <3382020374@f38.n261.z1.binkp.net> On 26Nov2017 01:09, Greg Tibbet wrote: >I've got a small program that uses PIL to create an image, draw some >primitives (rectanges, ellipses, etc...) and save it. Works fine... >no issues. > >I've found in the past, the best way to "really learn" the language >was to "dig into the guts" and understand it,.. I thought I was making >progress, but when looking into the PIL library to see what's going on >behind the scenes, I find the following code in ImageDraw.py > >def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) ><...snipped...> > >ellipse() uses the method self.draw.draw_ellipse() Okay, fine... >but WHERE is draw_ellipse defined?? What magic is happening there? >I've searched the entire PIL directory tree, and the ONLY two places >draw_ellipse is mentioned are right there in the ellipse() function... >WHAT am I missing?? "ellispse()" is a method in the ImageDraw class. Looking at the __init__ method of that class we see: self.draw = Image.core.draw(self.im, blend) so "self.draw" in your code above is the result of "Image.core.draw(self.im, blend)". "Image" is the Image module imported at the top of ImageDraw.py. So we hop over to Image.py, which has this code: try: # If the _imaging C module is not present, you can still use # the "open" function to identify files, but you cannot load # them. Note that other modules should not refer to _imaging # directly; import Image and use the Image.core variable instead. import _imaging core = _imaging del _imaging except ImportError, v: core = _imaging_not_installed() if str(v)[:20] == "Module use of python" and warnings: # The _imaging C module is present, but not compiled for # the right version (windows only). Print a warning, if # possible. warnings.warn( "The _imaging extension was built for another version " "of Python; most PIL functions will be disabled", RuntimeWarning ) Now the import works (because you'd get exceptions otherwise), so code which matters is that the top of that: import _imaging core = _imaging del _imaging So "core" is a reference to the "_imaging" module (and the name "_imaging" has been discarded). So... The name Image.core is now a reference to that module. So back in ImageDraw, the call to "Image.core.draw()" called the function "draw" from the _imaging module, which presumably returns some kind of drawing object, and _that_ object has a "draw_ellispe" method. Now, dynamic languages like Python don't lend themselves to screamingly fast compute, so expensive stuff like drawing graphics is usually done by hooking into special purpose libraries written in C or something that compiles to efficient machine level code (C++, Go, what have you). You can ship C code with Python to be compiled on the target and presented to Python as a library, and by convention such modules are named with a leading underscore. So we can expect that _imaging is a C code module. And if you go up a level you'll find _imaging.c, with a draw_ellipse function inside it. Cheers, Cameron Simpson (formerly cs at zip.com.au) From gtibbet27 at msn.com Sun Nov 26 04:09:55 2017 From: gtibbet27 at msn.com (Greg Tibbet) Date: Sun, 26 Nov 2017 01:09:55 -0800 Subject: Argh!! Can't wrap my head around this Python stuff! Message-ID: I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit of Java and trying to learn this new-fangled Python language! I've got a small program that uses PIL to create an image, draw some primitives (rectanges, ellipses, etc...) and save it. Works fine... no issues. I've found in the past, the best way to "really learn" the language was to "dig into the guts" and understand it,.. I thought I was making progress, but when looking into the PIL library to see what's going on behind the scenes, I find the following code in ImageDraw.py def ellipse(self, xy, fill=None, outline=None): """Draw an ellipse.""" ink, fill = self._getink(outline, fill) if fill is not None: self.draw.draw_ellipse(xy, fill, 1) <...snipped...> ellipse() uses the method self.draw.draw_ellipse() Okay, fine... but WHERE is draw_ellipse defined?? What magic is happening there? I've searched the entire PIL directory tree, and the ONLY two places draw_ellipse is mentioned are right there in the ellipse() function... WHAT am I missing?? Thanks! -Stumpy (aka Greg) From vincent.vande.vyvre at telenet.be Sun Nov 26 04:34:13 2017 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Sun, 26 Nov 2017 10:34:13 +0100 Subject: Argh!! Can't wrap my head around this Python stuff! In-Reply-To: References: Message-ID: <55c5e669-1635-3110-3b3a-f89767c345ef@telenet.be> Le 26/11/17 ? 10:09, Greg Tibbet a ?crit?: > I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit > of Java and trying to learn this new-fangled Python language! > > I've got a small program that uses PIL to create an image, draw some > primitives (rectanges, ellipses, etc...) and save it. Works fine... > no issues. > > I've found in the past, the best way to "really learn" the language > was to "dig into the guts" and understand it,.. I thought I was making > progress, but when looking into the PIL library to see what's going on > behind the scenes, I find the following code in ImageDraw.py > > def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) > <...snipped...> > > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? > > Thanks! > -Stumpy (aka Greg) Hi, It's not defined in Python module but in Pillow-3.5/Pillow-master/libImaging/Draw.c ... line 748 Vincent From h.goebel at crazy-compilers.com Sun Nov 26 04:58:42 2017 From: h.goebel at crazy-compilers.com (Hartmut Goebel) Date: Sun, 26 Nov 2017 10:58:42 +0100 Subject: C-api: Executing several scripts as __main__: globals are gone Message-ID: <22210c02-0c8a-d7c7-a939-6cde8c889d99@crazy-compilers.com> Hello, in PyInstaller we execute several Python scripts one after each other. The primary use of this is to run some setup prior to the actual appication. Up to now all scripts shared the same global variables, which worked well for 15 years, but now showed an error. The new code (scratched below) now deletes sys.modules['__main__'], so the next script will get a fresh module and fresh globals. This leads to an obscure error: If a setup-script hooks into something, this hook does not see it's own script's/module's globals. Thus running the scripts below (setup first, then main), fails with: Traceback (most recent call last): ? File "main-script", line 2, in ? File "setup-script", line 3, in do_it NameError: global name 'sys' is not defined Same effect for any other identifier defined globally in setup-script, e.g global functions (which is worse then just a missing import). I tried keeping a reference to the module (to avoid garbage-collection) both in the C-code and in the setup-script. But this did not solve the issue, the effect is the same. I also read through the CPython source but did not spot anything useful. Additionally, this issue only occurs with Python 2.7 and 3.3, Python 3.4 and up are okay. Any ideas? ....8<------ C-code scratch!! pseudo-code --- sys_modules = PyImport_GetModuleDict(); for each entry in archive { ??? data = Get_data_out_of_the_archive() ??? code = PyMarshal_ReadObjectFromString(data) /* execute as '__main__ for compatibility */ ??? module = PyImport_ExecCodeModule("__main__", code); ??? Py_DECREF(module); ??? /* remove '__main__' from sys.modules */ ??? PyObject_DelItem(sys_modules, "__main__"); } ......8<----------------------- Now if a have these two scripts (these are examples: ......8<---- setup-script ------ import sys def do_it() print(sys.modules) sys.do_it = do_it ......8<------------------------- and ......8<---- main-script ------ import sys sys.do_it() ......8<----------------------- -- Regards Hartmut Goebel | Hartmut Goebel | h.goebel at crazy-compilers.com | | www.crazy-compilers.com | compilers which you thought are impossible | From martin.schoon at gmail.com Sun Nov 26 05:00:29 2017 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 26 Nov 2017 10:00:29 GMT Subject: Pros and cons of Python sources? References: <7031295c-3341-4eb9-8737-a4a122b50672@googlegroups.com> <20171126021818.GA60833@cskk.homeip.net> Message-ID: Den 2017-11-26 skrev Cameron Simpson : > On 25Nov2017 08:34, rusi wrote: >>On Saturday, November 25, 2017 at 9:45:07 PM UTC+5:30, Michael Torrie wrote: >>> The problem with mixing repository-installed packages with pip-installed >>> packages is that there's always a chance a Debian update will overwrite >>> a pip package, possibly with an older version. Or a pip-installed >>> package might bring in a new version that's not compatible with some >>> debian-installed package, breaking something. >> >>On (recent?) debian/ubuntu pip seems to use the 'user-scheme' >>which means pip runs without sudo and installs in ~/.local/lib >>So I dont believe literal overwriting would occur > > Though the point should be made that one should run pip as oneself, and try to > avoid doing it as the root user (including avoiding sudo). Many UNIX/Linux/etc > users believe "installs" should be done as root, and in this case that is > easily avoided, with all its potential for damage to the vendor supplied > environment. Hmm, I seem to remember not being able to install packages with pip unless I did sudo pip. Follow-up question: Is there a way to find out which packages were installed using pip and which are from Debian's repo? pip list seems to list everything. /Martin From cs at cskk.id.au Sun Nov 26 05:01:39 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 26 Nov 2017 21:01:39 +1100 Subject: Argh!! Can't wrap my head around this Python stuff! In-Reply-To: References: Message-ID: <20171126100139.GA26788@cskk.homeip.net> On 26Nov2017 01:09, Greg Tibbet wrote: >I've got a small program that uses PIL to create an image, draw some >primitives (rectanges, ellipses, etc...) and save it. Works fine... >no issues. > >I've found in the past, the best way to "really learn" the language >was to "dig into the guts" and understand it,.. I thought I was making >progress, but when looking into the PIL library to see what's going on >behind the scenes, I find the following code in ImageDraw.py > >def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) ><...snipped...> > >ellipse() uses the method self.draw.draw_ellipse() Okay, fine... >but WHERE is draw_ellipse defined?? What magic is happening there? >I've searched the entire PIL directory tree, and the ONLY two places >draw_ellipse is mentioned are right there in the ellipse() function... >WHAT am I missing?? "ellispse()" is a method in the ImageDraw class. Looking at the __init__ method of that class we see: self.draw = Image.core.draw(self.im, blend) so "self.draw" in your code above is the result of "Image.core.draw(self.im, blend)". "Image" is the Image module imported at the top of ImageDraw.py. So we hop over to Image.py, which has this code: try: # If the _imaging C module is not present, you can still use # the "open" function to identify files, but you cannot load # them. Note that other modules should not refer to _imaging # directly; import Image and use the Image.core variable instead. import _imaging core = _imaging del _imaging except ImportError, v: core = _imaging_not_installed() if str(v)[:20] == "Module use of python" and warnings: # The _imaging C module is present, but not compiled for # the right version (windows only). Print a warning, if # possible. warnings.warn( "The _imaging extension was built for another version " "of Python; most PIL functions will be disabled", RuntimeWarning ) Now the import works (because you'd get exceptions otherwise), so code which matters is that the top of that: import _imaging core = _imaging del _imaging So "core" is a reference to the "_imaging" module (and the name "_imaging" has been discarded). So... The name Image.core is now a reference to that module. So back in ImageDraw, the call to "Image.core.draw()" called the function "draw" from the _imaging module, which presumably returns some kind of drawing object, and _that_ object has a "draw_ellispe" method. Now, dynamic languages like Python don't lend themselves to screamingly fast compute, so expensive stuff like drawing graphics is usually done by hooking into special purpose libraries written in C or something that compiles to efficient machine level code (C++, Go, what have you). You can ship C code with Python to be compiled on the target and presented to Python as a library, and by convention such modules are named with a leading underscore. So we can expect that _imaging is a C code module. And if you go up a level you'll find _imaging.c, with a draw_ellipse function inside it. Cheers, Cameron Simpson (formerly cs at zip.com.au) From gisle.vanem at gmail.com Sun Nov 26 05:04:12 2017 From: gisle.vanem at gmail.com (Gisle Vanem) Date: Sun, 26 Nov 2017 11:04:12 +0100 Subject: Argh!! Can't wrap my head around this Python stuff! In-Reply-To: References: Message-ID: Greg Tibbet wrote: > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? The C sources. Not all of PIL is ritten in Python. draw_ellipse() is a thin wrapper for ImagingDrawEllips(). See PIL/_imaging.c: https://github.com/python-pillow/Pillow/_imaging.c Which again is in libimage/Draw.c: https://github.com/python-pillow/Pillow/blob/13d84993717cffd64a2e1d7e3e6edb185973d559/libImaging/Draw.c calling ellipse(). -- --gv From __peter__ at web.de Sun Nov 26 05:33:18 2017 From: __peter__ at web.de (Peter Otten) Date: Sun, 26 Nov 2017 11:33:18 +0100 Subject: Argh!! Can't wrap my head around this Python stuff! References: Message-ID: Greg Tibbet wrote: > > I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit > of Java and trying to learn this new-fangled Python language! > > I've got a small program that uses PIL to create an image, draw some > primitives (rectanges, ellipses, etc...) and save it. Works fine... > no issues. > > I've found in the past, the best way to "really learn" the language > was to "dig into the guts" and understand it,.. I thought I was making > progress, but when looking into the PIL library to see what's going on > behind the scenes, I find the following code in ImageDraw.py > > def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) > <...snipped...> > > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? The first argument of ellipse(), self is a strong hint that it is a method. If you look into ImageDraw.py, located at >>> import PIL.ImageDraw >>> PIL.ImageDraw.__file__ '/usr/lib/python3/dist-packages/PIL/ImageDraw.py' on my machine, you'll find the class of the same name, ImageDraw, and in its initializer there's an assignment to the self.draw attribute: self.draw = Image.core.draw(self.im, blend) Image is another module >>> PIL.ImageDraw.Image and if you look for the name 'core' in that module you'll find from PIL import _imaging as core >>> PIL.ImageDraw.Image.core That would be the right time to say "Argh" with any number of exclamation marks for those who don't know C, but since you are familiar with that language there's nothing to stop you from downloading the PIL (or rather the pillow) source and look into the implementation. Once you have the complete code https://pypi.python.org/pypi/Pillow/4.3.0 https://python-pillow.org/ https://github.com/python-pillow/Pillow $ git clone https://github.com/python-pillow/Pillow.git ...you can use traditional tools: $ find Pillow/ -name \*.c -print0 | xargs -0 grep draw_ellipse Pillow/_imaging.c:_draw_ellipse(ImagingDrawObject* self, PyObject* args) Pillow/_imaging.c: {"draw_ellipse", (PyCFunction)_draw_ellipse, 1}, Rinse and repeat ;) From miki.tebeka at gmail.com Sun Nov 26 05:40:00 2017 From: miki.tebeka at gmail.com (nospam.Miki Tebeka) Date: Sun, 26 Nov 2017 22:40:00 +1200 Subject: I have anaconda, but Pycharm can't find it Message-ID: <1783215345@f38.n261.z1.binkp.net> You need to set the Python interpreter for the project to be the Anaconda one. See https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html On Monday, November 27, 2017 at 1:56:58 AM UTC+2, C W wrote: > Hello all, > > I am a first time PyCharm user. I have Python 3 and Anaconda installed. > They work together on Sublime Text, but not on Pycharm. > > Pycharm tells me it cannot find modules numpy, matplotlib, etc. > > What should I do? I tried to set the interpreter environment, and a few > other options, none seem to work. > > This is the typical solution, but it does not work > https://stackoverflow.com/questions/35623776/import-numpy-on-pycharm > > Thanks, > > -Mike From bc at freeuk.com Sun Nov 26 06:10:23 2017 From: bc at freeuk.com (bartc) Date: Sun, 26 Nov 2017 11:10:23 +0000 Subject: Argh!! Can't wrap my head around this Python stuff! In-Reply-To: References: Message-ID: On 26/11/2017 09:09, Greg Tibbet wrote: > > I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit > of Java and trying to learn this new-fangled Python language! > > I've got a small program that uses PIL to create an image, draw some > primitives (rectanges, ellipses, etc...) and save it. Works fine... > no issues. > > I've found in the past, the best way to "really learn" the language > was to "dig into the guts" and understand it,.. I thought I was making > progress, but when looking into the PIL library to see what's going on > behind the scenes, I find the following code in ImageDraw.py > > def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) > <...snipped...> > > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? Python isn't a very pure language in that much of the functionality that looks like it should be written in Python (because you imported a module just like you import any Python module), actually is written in something else, as has been pointed out. It's reasonable that some things need to be implemented using some foreign functions. But the boundary between Python and non-Python is blurred. Take this program: import sys and try and find sys.py in your installation. (This is an obstacle if, for example, you're thinking of implementing a Python interpreter. In theory, once you have it working, it should run any .py program. But the critical modules it needs don't have .py source code. And the interface to those non-Python functions isn't defined with special byte-code instructions. (It will be done /via/ those instructions, but the magic needed is on the other side of them. Calling into sys.fn() uses the same CALL_FUNCTION byte-code as calling into a regular Python function.) As I said, it's not pure. More of a jungle as you've found out.) -- bartc From alister.ware at ntlworld.com Sun Nov 26 06:24:32 2017 From: alister.ware at ntlworld.com (alister) Date: Sun, 26 Nov 2017 11:24:32 GMT Subject: connect four (game) References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> Message-ID: On Sat, 25 Nov 2017 12:26:52 -0800, namenobodywants wrote: > On Friday, November 24, 2017 at 8:07:07 AM UTC-8, Chris Angelico wrote: > >> This is the kind of function that needs a docstring and some comments. >> What exactly is this doing? What are the "lines" of the board? What's >> the difference between "linear" and "lines"? What exactly is it >> returning? > > producing documentation is an extremely difficult task for me, but i've > come up with the following: > > """ > makelines(length,numrows,numcolumns) IS THE LIST OF ALL LISTS L, WITH > LENGTH length, OF COORDINATES FROM A numrows x numcolumns MATRIX, SUCH > THAT THE ENTRIES OF L ALL LIE IN A LINE: > > LET horizontal BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN > A HORIZONTAL LINE LET vertical BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE > ENTRIES LIE IN A VERTICAL LINE LET downward BE ALL THE > APPROPRIATE-LENGTH LISTS WHOSE ENTRIES LIE IN A DOWNWARD-SLOPING > DIAGONAL LINE LET upward BE ALL THE APPROPRIATE-LENGTH LISTS WHOSE > ENTRIES LIE IN AN UPWARD-SLOPING DIAGONAL LINE THEN > makelines(length,numrows,numcolumns) IS THE UNION OF ALL THE > AFOREMENTIONED SETS """ > > def makelines(length,numrows,numcolumns): > horizontal = [[(i, j+k) for k in range(length)] for i in > range(numrows) for j in range(numcolumns)] > vertical = [[(i+k, j) for k in range(length)] for i in > range(numrows) for j in range(numcolumns)] downward = [[(i+k, j+k) > for k in range(length)] for i in range(numrows) for j in > range(numcolumns)] > upward = [[(i+k, j-k) for k in range(length)] for i in > range(numrows) for j in range(numcolumns)] linear = horizontal + > vertical + downward + upward return [line for line in linear if > all(i in range(6) and j in range(7) for (i,j) in line)] > > def getlines(board): > coordlines = makelines(4,6,7) ## GLOBAL return [[board[square] for > square in line] for line in coordlines > > > i tried to remove all the superfluous spaces from that, but lining up > code vertically is very helpful to me, so i don't think i can really > dispense with the practice > > peace stm the documentation should come after the def statement that way is becomes a "Doc String" & can be accessed using the help function you may also want to check out the recommended way of structuring a doc string, it could help you with your difficulty in writing them (a problem shared by many) -- This door is baroquen, please wiggle Handel. (If I wiggle Handel, will it wiggle Bach?) -- Found on a door in the MSU music building From november.nihal at gmail.com Sun Nov 26 06:54:18 2017 From: november.nihal at gmail.com (november.nihal at gmail.com) Date: Sun, 26 Nov 2017 03:54:18 -0800 (PST) Subject: Stopping an iterator and continuing later (Posting On Python-List Prohibited) In-Reply-To: <115e2af2-c33d-40b8-bd89-307a636fef79@googlegroups.com> References: <456414ad-ab16-46b3-8e42-0eb5d4afbd45@googlegroups.com> <115e2af2-c33d-40b8-bd89-307a636fef79@googlegroups.com> Message-ID: On Saturday, 25 November 2017 20:59:02 UTC, Lawrence D?Oliveiro wrote: > On Sunday, November 26, 2017 at 6:43:05 AM UTC+13, novembe... at gmail.com wrote: > > I worked out how to use iterators to generate values one at a time > > then ran into a second problem which is time. Is it possible to > > save an iterator so that i can continue from where I stopped? > > Yes. Just stop calling it. Then, when you start again, you will get the values continuing from that point. I should have added I switch off the machine when I stop. ( I dont have options to keep it in a sleep mode or in hibernation ) NN From rosuav at gmail.com Sun Nov 26 08:23:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Mon, 27 Nov 2017 01:23:00 +1200 Subject: connect four (game) Message-ID: <2225514370@f38.n261.z1.binkp.net> On Mon, Nov 27, 2017 at 1:11 AM, bartc wrote: > The way I write code isn't incrementally top down or bottom up. It's > backwards and forwards. Feedback from different parts means the thing > develops as a whole. Sometimes parts are split into distinct sections, > sometimes different parts are merged. > > Sometimes you realise you're on the wrong track, and sections have to be > redone or a different approach used, which can be done in the earlier > stages. > > If I had to bother with such systematic tests as you suggest, and finish and > sign off everything before proceeding further, then nothing would ever get > done. (Maybe it's viable if working from an exacting specification that > someone else has already worked out.) Everyone in the world has the same problem, yet many of us manage to write useful tests. I wonder whether you're somehow special in that testing fundamentally doesn't work for you, or that you actually don't need to write tests. Or maybe tests would still be useful for you too. Could go either way. > As for testing, I remember in a company I worked in, a complicated circuit > was submitted to a company that would put it into a mass-produced chip. This > company did massive numbers of emulated tests shown on a huge printout that > showed that all combinations of inputs and outputs worked exactly as > intended. > > Except the actual chip didn't work. As for the printout, the designer took > it home and used it as an underlay for a new carpet. A rather expensive > underlay. So there was something else wrong with the chip. I'm not sure what your point is. ChrisA From nospam.namenobodywants at gmail.com Sun Nov 26 09:01:00 2017 From: nospam.namenobodywants at gmail.com (namenobodywants) Date: Mon, 27 Nov 2017 02:01:00 +1200 Subject: connect four (game) References: <1134053142@f38.n261.z1.binkp.net> Message-ID: <149567729@f38.n261.z1.binkp.net> On Sunday, November 26, 2017 at 7:09:25 PM UTC-8, Michael Torrie wrote: > So you are using this Infinity class as a sentinel value of some kind? > Representing game state? There may be an easier way than a full on > custom type. Sometimes just a sentinel object is sufficient. Or an > enumeration. they're not sentinels; they're the maximum and minimum of the extended real numbers; the point is that, no matter how boards are evaluated (which is, of course, subject to change), a won game is always the most valuable and a lost game is always the least valuable; ordinary real numbers could be used for the purpose, but in that case i would have to figure out the maximum and minimum of the heuristic values the script assigns and then add/subtract one (for example) to get the value of a won/lost game peace stm From bc at freeuk.com Sun Nov 26 09:11:50 2017 From: bc at freeuk.com (bartc) Date: Sun, 26 Nov 2017 14:11:50 +0000 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> Message-ID: On 25/11/2017 16:07, Michael Torrie wrote: > On 11/25/2017 06:00 AM, bartc wrote: >> And there's a quite lot left of the rest of the program to worry about too! >> >> If you add 'window()' at the end of the program, then it seems to run on >> Python 3. I'd play around with it first before thinking up strategies >> for testing it. > > Actually, no. Unit testing ideally should be done for each and every > class as they are being written (before they are written in fact), no > matter how small and trivial the class. That way as you compose larger > and larger units of code, the chances of things being right is greater > compared to doing it the other way around. The way I write code isn't incrementally top down or bottom up. It's backwards and forwards. Feedback from different parts means the thing develops as a whole. Sometimes parts are split into distinct sections, sometimes different parts are merged. Sometimes you realise you're on the wrong track, and sections have to be redone or a different approach used, which can be done in the earlier stages. If I had to bother with such systematic tests as you suggest, and finish and sign off everything before proceeding further, then nothing would ever get done. (Maybe it's viable if working from an exacting specification that someone else has already worked out.) I've also found that many of the bugs that do appear, also do so in ways you never anticipated. Or in circumstances you would never have thought of. (I've always thought that programming is a bit like creating new laws. The same laws need to work for everyone and in any circumstances, but no one can foresee everything, and laws need to be tweaked and added to. Perhaps unit tests can apply there too...) > You may argue that testing doesn't matter for his small game, written > for his own education and amusement. The fact is that software in > general is of abysmal quality across the boards, and promoting a habit > of unit testing is good, even for trivial, home-grown stuff. I thought people were being hard on the OP. As for testing, I remember in a company I worked in, a complicated circuit was submitted to a company that would put it into a mass-produced chip. This company did massive numbers of emulated tests shown on a huge printout that showed that all combinations of inputs and outputs worked exactly as intended. Except the actual chip didn't work. As for the printout, the designer took it home and used it as an underlay for a new carpet. A rather expensive underlay. -- bartc From rosuav at gmail.com Sun Nov 26 09:23:33 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Nov 2017 01:23:33 +1100 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> Message-ID: On Mon, Nov 27, 2017 at 1:11 AM, bartc wrote: > The way I write code isn't incrementally top down or bottom up. It's > backwards and forwards. Feedback from different parts means the thing > develops as a whole. Sometimes parts are split into distinct sections, > sometimes different parts are merged. > > Sometimes you realise you're on the wrong track, and sections have to be > redone or a different approach used, which can be done in the earlier > stages. > > If I had to bother with such systematic tests as you suggest, and finish and > sign off everything before proceeding further, then nothing would ever get > done. (Maybe it's viable if working from an exacting specification that > someone else has already worked out.) Everyone in the world has the same problem, yet many of us manage to write useful tests. I wonder whether you're somehow special in that testing fundamentally doesn't work for you, or that you actually don't need to write tests. Or maybe tests would still be useful for you too. Could go either way. > As for testing, I remember in a company I worked in, a complicated circuit > was submitted to a company that would put it into a mass-produced chip. This > company did massive numbers of emulated tests shown on a huge printout that > showed that all combinations of inputs and outputs worked exactly as > intended. > > Except the actual chip didn't work. As for the printout, the designer took > it home and used it as an underlay for a new carpet. A rather expensive > underlay. So there was something else wrong with the chip. I'm not sure what your point is. ChrisA From bc at freeuk.com Sun Nov 26 09:25:50 2017 From: bc at freeuk.com (bartc) Date: Sun, 26 Nov 2017 14:25:50 +0000 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <196acf58-1e2c-41ea-a175-77eecb526933@googlegroups.com> Message-ID: On 25/11/2017 23:49, Terry Reedy wrote: > On 11/25/2017 4:57 PM, namenobodywants at gmail.com wrote: >> On Saturday, November 25, 2017 at 12:48:38 AM UTC-8, Terry Reedy wrote: >> >>> I did, and it looks buggy to me.? The top and left frame lines are >>> missing.? If I click a square, the bottom square in the column lights >>> up.? But then I have no idea whether those are your intentions or not. >> i hadn't noticed about the frame lines, but it's the same for me; but >> i'm hoping you meant to write that the TOP square in a column flashes >> when you "drop a token" down that column; > > All squares start white.? Only the bottom square turns red or black, > after perhaps a .3 second delay during which there is some jitter in > white squares above, which could be the effect of white flashing white. There are a couple of lines that look like this: self.grid.squarebuttons[column].flash() If you comment out those two lines, then the flashing disappears, and it still works. Of course, if I'd used unit tests, I'd have figured that out a lot sooner. I would just have had the somewhat bigger problem of devising a unit test that would detect this. -- bartc From wanderer at dialup4less.com Sun Nov 26 10:21:43 2017 From: wanderer at dialup4less.com (Wanderer) Date: Sun, 26 Nov 2017 07:21:43 -0800 (PST) Subject: Argh!! Can't wrap my head around this Python stuff! In-Reply-To: References: Message-ID: <68f49b2e-3119-4c69-9f0d-adbb9703c947@googlegroups.com> On Sunday, November 26, 2017 at 4:10:12 AM UTC-5, Greg Tibbet wrote: > I'm an old timer, have programmed in Fortran, C, C++, Perl, and a bit > of Java and trying to learn this new-fangled Python language! > > I've got a small program that uses PIL to create an image, draw some > primitives (rectanges, ellipses, etc...) and save it. Works fine... > no issues. > > I've found in the past, the best way to "really learn" the language > was to "dig into the guts" and understand it,.. I thought I was making > progress, but when looking into the PIL library to see what's going on > behind the scenes, I find the following code in ImageDraw.py > > def ellipse(self, xy, fill=None, outline=None): > """Draw an ellipse.""" > ink, fill = self._getink(outline, fill) > if fill is not None: > self.draw.draw_ellipse(xy, fill, 1) > <...snipped...> > > ellipse() uses the method self.draw.draw_ellipse() Okay, fine... > but WHERE is draw_ellipse defined?? What magic is happening there? > I've searched the entire PIL directory tree, and the ONLY two places > draw_ellipse is mentioned are right there in the ellipse() function... > WHAT am I missing?? > > Thanks! > -Stumpy (aka Greg) I'm googlesmart when it comes to Python. I used to know C. I practically knew what the assembly language would look like when it compiled. There was no internet and searching through books can be really laborious so you almost had to really know it to use it. But with Python, I don't start from first principles. I google what I want to do, download the appropriate packages and read through the examples. It can be really frustrating when you get bugs, because you don't know what's going on deep down in the code. From bc at freeuk.com Sun Nov 26 10:39:06 2017 From: bc at freeuk.com (bartc) Date: Sun, 26 Nov 2017 15:39:06 +0000 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> Message-ID: On 26/11/2017 14:23, Chris Angelico wrote: > On Mon, Nov 27, 2017 at 1:11 AM, bartc wrote: >> The way I write code isn't incrementally top down or bottom up. It's >> backwards and forwards. Feedback from different parts means the thing >> develops as a whole. Sometimes parts are split into distinct sections, >> sometimes different parts are merged. >> >> Sometimes you realise you're on the wrong track, and sections have to be >> redone or a different approach used, which can be done in the earlier >> stages. >> >> If I had to bother with such systematic tests as you suggest, and finish and >> sign off everything before proceeding further, then nothing would ever get >> done. (Maybe it's viable if working from an exacting specification that >> someone else has already worked out.) > > Everyone in the world has the same problem, yet many of us manage to > write useful tests. I wonder whether you're somehow special in that > testing fundamentally doesn't work for you, or that you actually don't > need to write tests. Or maybe tests would still be useful for you too. > Could go either way. Testing everything comprehensively just wouldn't be useful for me who works on whole applications, whole concepts, not just a handful of functions with well-defined inputs and outputs. And even then, it might work perfectly, but be too slow, or they take up too much space. Take one example of a small program I've mentioned in the past, a jpeg decoder. I had to port this into several languages (one of which was Python actually). It was hard because I didn't know how it was meant to work. Only as a whole when the input is a .jpeg file, and the output might be a .ppm file that ought to look like the one produced by a working program, or the original jpeg displayed by a working viewer. (Which is not possible in all applications.) How to do an automatic test? Directly doing a binary compare on the output doesn't work because in jpeg, there can be differences of +/- 1 bit in the results. And even if the test detected a mismatch, then what? I now know there is a problem, but I could figure that out by looking at the output! And actually, after it ostensibly worked, there WAS a minor problem: some types of images exhibited excessive chroma noise around sharp transitions. The problem was traced to two lines that were in the wrong order (in the original program). I can't see how unit tests can have helped in any way at all, and it would probably have taken much longer. And THIS was a small, well-defined task which had already been written. >> Except the actual chip didn't work. As for the printout, the designer took >> it home and used it as an underlay for a new carpet. A rather expensive >> underlay. > > So there was something else wrong with the chip. I'm not sure what > your point is. The extensive testing was like unit testing, but needed to be even more thorough because of the commitment involved. It failed to spot a problem. And actually I had a similar problem with a new car. I took it back to the dealer, and they said they plugged the on-board computer into their analyser, which did all sorts of tests and said there was nothing wrong with it. But there was, and the problem has persisted for a decade [to do with the central locking]. I'm saying you can rely too much on these tests, and waste too much time on them. Perhaps that is a necessity in a large organisation or in a large team, where there is a leader to look at the big picture. It doesn't work for individuals working on one project. -- bartc From nospam.namenobodywants at gmail.com Sun Nov 26 11:43:00 2017 From: nospam.namenobodywants at gmail.com (namenobodywants) Date: Mon, 27 Nov 2017 04:43:00 +1200 Subject: connect four (game) References: <2963061171@f38.n261.z1.binkp.net> Message-ID: <315404913@f38.n261.z1.binkp.net> On Monday, November 27, 2017 at 2:10:56 AM UTC-8, Chris Angelico wrote: > Or you could use the floating-point values for positive and negative > infinity perfecto! thank you! peace stm From gengyangcai at gmail.com Sun Nov 26 11:54:00 2017 From: gengyangcai at gmail.com (nospam.Cai Gengyang) Date: Mon, 27 Nov 2017 04:54:00 +1200 Subject: While, If, Count Statements Message-ID: <422026890@f38.n261.z1.binkp.net> Input : count = 0 if count < 5: print "Hello, I am an if statement and count is", count while count < 10: print "Hello, I am a while and count is", count count += 1 Output : Hello, I am an if statement and count is 0 Hello, I am a while and count is 0 Hello, I am a while and count is 1 Hello, I am a while and count is 2 Hello, I am a while and count is 3 Hello, I am a while and count is 4 Hello, I am a while and count is 5 Hello, I am a while and count is 6 Hello, I am a while and count is 7 Hello, I am a while and count is 8 Hello, I am a while and count is 9 The above input gives the output below. Why isn't the output instead : Hello, I am an if statement and count is 0 Hello, I am a while and count is 0 Hello, I am an if statement and count is 1 Hello, I am a while and count is 1 Hello, I am an if statement and count is 2 Hello, I am a while and count is 2 Hello, I am an if statement and count is 3 Hello, I am a while and count is 3 Hello, I am an if statement and count is 4 Hello, I am a while and count is 4 Hello, I am a while and count is 5 Hello, I am a while and count is 6 Hello, I am a while and count is 7 Hello, I am a while and count is 8 Hello, I am a while and count is 9 From nospam.jaya.birdar at gmail.com Sun Nov 26 12:13:00 2017 From: nospam.jaya.birdar at gmail.com (jaya birdar) Date: Mon, 27 Nov 2017 05:13:00 +1200 Subject: I have framework on python with pyunit, facing below issue while Message-ID: <2691586178@f38.n261.z1.binkp.net> Please let me know anyone aware about the issue Traceback (most recent call last): File "testrunner.py", line 447, in testrunner_obj.main() File "testrunner.py", line 433, in main self.result() File "testrunner.py", line 310, in result result = runner.run(self.suite) File "/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 720, in run test(result) File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ return self.run(*args, **kwds) File "/usr/lib/python2.7/unittest/suite.py", line 108, in run test(result) File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ return self.run(*args, **kwds) File "/usr/lib/python2.7/unittest/suite.py", line 108, in run test(result) File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ return self.run(*args, **kwds) File "/usr/lib/python2.7/unittest/suite.py", line 100, in run self._handleClassSetUp(test, result) File "/usr/lib/python2.7/unittest/suite.py", line 153, in _handleClassSetUp self._addClassOrModuleLevelException(result, e, errorName) File "/usr/lib/python2.7/unittest/suite.py", line 198, in _addClassOrModuleLevelException result.addError(error, sys.exc_info()) File ? ?/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 633, in addError output = self.complete_output() File ? ?/autoPyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 591, in complete_output return self.outputBuffer.getvalue() AttributeError: '_TestResult' object has no attribute 'outputBuffer' From rustompmody at gmail.com Sun Nov 26 12:18:00 2017 From: rustompmody at gmail.com (nospam.Rustom Mody) Date: Mon, 27 Nov 2017 05:18:00 +1200 Subject: Benefits of unicode identifiers (was: Allow additional separator Message-ID: <3500798388@f38.n261.z1.binkp.net> On Monday, November 27, 2017 at 3:43:20 PM UTC+5:30, Antoon Pardon wrote: > Op 23-11-17 om 19:42 schreef Mikhail V: > > Chris A wrote: > > > >>> On Fri, Nov 24, 2017 at 1:10 AM, Mikhail V wrote: > >>> > >>>> Chris A wrote: > >>>> > >>>> Fortunately for the world, you're not the one who decided which > >>>> characters were permitted in Python identifiers. The ability to use > >>>> non-English words for function/variable names is of huge value; the > >>>> ability to use a hyphen is of some value, but not nearly as much. > >>> Fortunately for the world we have Chris A. Who knows what is > >>> fortunate and of huge values. > >>> So is there any real world projects example of usage of non-latin scripts > >>> in identifiers? Or is it still only a plan for the new world? > > > >> Yes, I've used them personally. And I know other people who have. > > > > Oh, I though it would be more impressive showcase for 'huge value'. > > If we drop the benefit of the bare fact that you can do it, or you just > > don't know English, how would describe the practical benefit? > > If you don't know english, then programming at all will be just too hard. > > (or one must define a new whole language specially for some local script) > > Well maybe the value is not huge, but I really appreciate the possibility. > Being able to write something like below, makes things a lot more clear > for me. > > Po = Pc + R * Vec(cos(?,o), sin(?,o)) > Pe = Pc + R * Vec(cos(?,e), sin(?,e)) > g????, = ?,e - ?,o > g???P = Pe - Po Yeah? | This is important And Ive tried to elaborate such suggestions here http://blog.languager.org/2014/04/unicoded-python.html [includes some of your suggestions!] I should emphasize that the details there range between straightforward and facetious. The general sense of going beyond ASCII is not facetious at all In fact its ridiculous in the reverse direction: just as FORTRAN and COBOL believed that programming IN ALL UPPERCASE was somehow kosher, likewise a 2017 language believing that sticking to ASCII is sound is faintly ridiculous. But that brings me to the opposite point: I feel its important to distinguish ? ?parochial/sectarian unicode? ? from ? ?universal unicode? ?. More on the distinction http://blog.languager.org/2015/03/whimsical-unicode.htm l More on the universal aspect: http://blog.languager.org/2015/02/universal-unico de.html Having said that I should be honest to mention that I saw your post first on my phone where the ?, showed but the g??? showed as a rectangle something like ??$ I suspect that ?? OTOH would have worked? | dunno So yes, there can be non-trivial logistic problems going beyond ASCII As there are problems with errant mail-clients transmitting indentation-sensitive languages and so on! From rustompmody at gmail.com Sun Nov 26 12:35:00 2017 From: rustompmody at gmail.com (nospam.Rustom Mody) Date: Mon, 27 Nov 2017 05:35:00 +1200 Subject: connect four (game) References: <624341068@f38.n261.z1.binkp.net> Message-ID: <2416447940@f38.n261.z1.binkp.net> On Monday, November 27, 2017 at 12:12:24 PM UTC+5:30, Chris Angelico wrote: > On Mon, Nov 27, 2017 at 3:04 PM, Rustom Mody wrote: > >> Aviators have pinned down the best solution to this, I think. A pilot > >> is not expected to be perfect; he is expected to follow checklists. A > >> preflight checklist. A departure checklist. A landing checklist. > >> Everything that needs to be done right is mentioned on the list, and > >> you just go through the list and make sure you've done everything. > > > > And thats where the analogy breaks down. > > Presumably a 50 person short-flight and a 600-person transcontinental may have > > at least something in common in their pilot-checklists > > What common will you find in a multi-million line OS, a thousand line script > > and a student prime-numbers first-program? > > You locate a pure function. I can pretty much guarantee that the first > two will have a number of them, and the third one may or may not, but > almost certainly should. Pure functions are the easiest to unit-test. > Then you build up from there. > > > No I am not dissing on testing and TDD; just that universality?1 of computing devices > > is something that our civilization is nowhere near understanding, leave alone > > dealing with ? ? two programs can be more far apart than a bullock cart and a jet. > > And yet they are both programs > > ... so? I know how to drive a car? | and various two-wheelers. I not so sure of a bus/truck? | I suppose I could get one from here to there at a pinch? | without killing someone? | though not quite sure of that! Doesn't translate into knowing how to 'drive' planes or bullock-carts gcc is tested with dejagnu. Do you imagine that knowing python's unittest or nose directly translates into dejagnu expertise? And even if we stay with industry-strength programs ? ? gcc, linux-kernel, CPython, KDE ? ? do you imagine that testing one helps in testing the other? I doubt it (though I am hardly an expert with testing frameworks) Once again let me end by saying that testing and TDD are good ideas And it would be nice if there was more of it in/for python [See http://osherove.com/tdd-kata-1/ one of the first hits that google gives (me) for TDD python, and you find the python example actually shows Ruby!] From rustompmody at gmail.com Sun Nov 26 12:52:00 2017 From: rustompmody at gmail.com (nospam.Rustom Mody) Date: Mon, 27 Nov 2017 05:52:00 +1200 Subject: Benefits of unicode identifiers (was: Allow additional separator Message-ID: <2494921429@f38.n261.z1.binkp.net> On Monday, November 27, 2017 at 6:48:56 PM UTC+5:30, Rustom Mody wrote: > Having said that I should be honest to mention that I saw your post first on > my phone where the ?, showed but the g??? showed as a rectangle something like ??$ > > I suspect that ?? OTOH would have worked? | dunno Yeah ?? shows whereas g??? doesn't (on my phone) And ??$ does show but much squatter than the replacement char the phone shows when it cant display a char From rustompmody at gmail.com Sun Nov 26 13:25:00 2017 From: rustompmody at gmail.com (nospam.Rustom Mody) Date: Mon, 27 Nov 2017 06:25:00 +1200 Subject: Increasing the diversity of people who write Python (was: Message-ID: <1914648010@f38.n261.z1.binkp.net> On Friday, November 24, 2017 at 10:11:24 PM UTC+5:30, Skip Montanaro wrote: > > Because if I already can't understand the words, it will be more useful > > to me to be able to type them reliably at a keyboard, for replication, > > search, discussion with others about the code, etc. > > I am probably not alone in my Americo-centric world where I can't even > easily type accented Latin-1 characters. I happen to be using Linux as > I type this, but type at a Windows keyboard at work (ugh) and have > long been a user of Macs (still have one or two at home). Might the > problem be further multiplied by the number of different ways I have > of entering text? Would Emacs running on Linux, but displaying on > Windows be different than Chrome running directly on Linux? I strongly suspect that any recent emacs will have M-x insert-char (earlier it was called ucs-insert) default bound C-x 8 RET (yeah thats clunky) which will accept at the minibuffer input At which point the hex for ?C which is e9 can be entered ? ? yeah its unreasonable to expect to remember that! Its more reasonable to remember that that is an e acute; And e itself is a latin lower case letter All of which becomes entering (in the minibuffer) LATIN SMALL LETTER E ACUTE - upper case not required; emacs will upcase it for you - And will also provide some tab/star expansion help ie *letter e acuteTAB expands to LATIN *L LETTER E ACUTE Further TAB-prodding will give you these choices LATIN CAPITAL LETTER E ACUTE (??) LATIN CAPITAL LETTER E WITH ACUTE (??) LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND ACUTE (??1) LATIN CAPITAL LETTER E WITH MACRON AND ACUTE (?,?) LATIN SMALL LETTER E ACUTE (?C) LATIN SMALL LETTER E WITH ACUTE (?C) LATIN SMALL LETTER E WITH CIRCUMFLEX AND ACUTE (???) LATIN SMALL LETTER E WITH MACRON AND ACUTE (?,?) You could go one step more sophisticated and use TeX-input method (C-x RET C-\) After which \'e will collapse as ?C ? ?Yeah ok but how the ^)*^$# am I to remember the mantra \'e?!? ? you may ask True? | So as you rightly do, - pick it up from google - put emacs into tex input mode - paste from google into emacs - place point on the new char and type C-u C-x = Among other things emacs will helpfully inform you (among other things) to input: type "\'{e}" or "\'e" with TeX input method From rustompmody at gmail.com Sun Nov 26 13:55:00 2017 From: rustompmody at gmail.com (nospam.Rustom Mody) Date: Mon, 27 Nov 2017 06:55:00 +1200 Subject: Increasing the diversity of people who write Python (was: Message-ID: <14580638@f38.n261.z1.binkp.net> On Monday, November 27, 2017 at 8:07:47 PM UTC+5:30, Chris Angelico wrote: > On Tue, Nov 28, 2017 at 1:25 AM, Rustom Mody wrote: > > You could go one step more sophisticated and use TeX-input method > > (C-x RET C-\) > > After which \'e will collapse as ?C > > ? ?Yeah ok but how the ^)*^$# am I to remember the mantra \'e?!? ? you may ask > > True? | So as you rightly do, > > - pick it up from google > > - put emacs into tex input mode > > - paste from google into emacs > > - place point on the new char and type C-u C-x = > > Among other things emacs will helpfully inform you (among other things) > > to input: type "\'{e}" or "\'e" with TeX input method > > Which is closely related to the Compose key input method that I use. > First, you assign a key on your keyboard to be Compose (at least on > all my systems, there isn't one by default); I use the key between > left Ctrl and left Alt. Ha Ha So you wont speak the unspeakable???!?? I also have my compose set (to Capslock) And I entered those chars above with C?? and C!! where C is Capslock I most frequently use that for ??? (C=>) ??? (C->) ?1 (C^1) ??? (C_1) etc One can find other goodies at /usr/share/X11/locale/en_US.UTF-8/Compose I didn't start with mentioning that to Skip because his basic requirement (as I got it) was that - input method should be OS-neutral - emacs can be assumed And so the only OS-non-neutrality that I am aware of is that sometimes Alt works as Meta (gui-emacsen) and sometimes not terminal/text emacsen (typically, though I believe some ppl successfully tweak this also) And so M-x can mean Alt-x (chord) or ESC-x (sequence) and a few such anomalies But beyond that emacsen should be same for all OSes (modulo versions) From nospam.wxjmfauth at gmail.com Sun Nov 26 14:00:00 2017 From: nospam.wxjmfauth at gmail.com (wxjmfauth) Date: Mon, 27 Nov 2017 07:00:00 +1200 Subject: Benefits of unicode identifiers (was: Allow additional separator Message-ID: <1049068218@f38.n261.z1.binkp.net> Le lundi 27 novembre 2017 14:52:19 UTC+1, Rustom Mody a ?Ccrit? : > On Monday, November 27, 2017 at 6:48:56 PM UTC+5:30, Rustom Mody wrote: > > Having said that I should be honest to mention that I saw your post first on > > my phone where the ?, showed but the g??? showed as a rectangle something like ??$ > > > > I suspect that ?? OTOH would have worked? | dunno > > Yeah ?? shows whereas g??? doesn't (on my phone) > And ??$ does show but much squatter than the replacement char the phone shows > when it cant display a char It is a least unicode. Much better than what this idotic and buggy Flexible String Representation is presenting to the eyes of users. From wojtek.mula at gmail.com Sun Nov 26 14:46:07 2017 From: wojtek.mula at gmail.com (wojtek.mula at gmail.com) Date: Sun, 26 Nov 2017 11:46:07 -0800 (PST) Subject: Compile Python 3 interpreter to force 2-byte unicode In-Reply-To: References: Message-ID: <7a976d89-bb3a-4854-a5be-d606def3c86c@googlegroups.com> On Sunday, November 26, 2017 at 1:00:19 AM UTC+1, Terry Reedy wrote: > You must be trying to compile 2.7. There may be Linux distributions > that compile this way. You're right, I need 2.7. Any hint which distro has got these settings? > If you want to seriously work with unicode, many recommend using modern > Python. I have to fix a bug in my C extension that appears only in UCS-2 python (i.e. Windows). I can reboot to Windows and debug there, but it's pain in a neck for various reasons. w. From ian.g.kelly at gmail.com Sun Nov 26 14:51:00 2017 From: ian.g.kelly at gmail.com (nospam.Ian Kelly) Date: Mon, 27 Nov 2017 07:51:00 +1200 Subject: connect four (game) Message-ID: <31433456@f38.n261.z1.binkp.net> On Nov 27, 2017 7:08 AM, "Chris Angelico" wrote: In every compiler, interpreter, and CPU that I've ever used, the remainder has been well-defined. In what situation was it ill-defined, such that different compilers could do different things? In C89 the result of integer division and modulo with negative operands were implementation-defined -- the result of division could be either floored or truncated, and the modulo result also varied to match. This was fixed in C99, with division results always being truncated (whereas Python uses the floor). From ned at nedbatchelder.com Sun Nov 26 15:25:00 2017 From: ned at nedbatchelder.com (nospam.Ned Batchelder) Date: Mon, 27 Nov 2017 08:25:00 +1200 Subject: I have framework on python with pyunit, facing below issue while Message-ID: <3056807227@f38.n261.z1.binkp.net> On 11/27/17 8:13 AM, jaya.birdar at gmail.com wrote: > Please let me know anyone aware about the issue > > > Traceback (most recent call last): > File "testrunner.py", line 447, in > testrunner_obj.main() > File "testrunner.py", line 433, in main > self.result() > File "testrunner.py", line 310, in result > result = runner.run(self.suite) > File "/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 720, in run > test(result) > File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ > return self.run(*args, **kwds) > File "/usr/lib/python2.7/unittest/suite.py", line 108, in run > test(result) > File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ > return self.run(*args, **kwds) > File "/usr/lib/python2.7/unittest/suite.py", line 108, in run > test(result) > File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ > return self.run(*args, **kwds) > File "/usr/lib/python2.7/unittest/suite.py", line 100, in run > self._handleClassSetUp(test, result) > File "/usr/lib/python2.7/unittest/suite.py", line 153, in _handleClassSetUp > self._addClassOrModuleLevelException(result, e, errorName) > File "/usr/lib/python2.7/unittest/suite.py", line 198, in _addClassOrModuleLevelException > result.addError(error, sys.exc_info()) > File ? ?/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 633, in addError > output = self.complete_output() > File ? ?/autoPyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 591, in complete_output > return self.outputBuffer.getvalue() > AttributeError: '_TestResult' object has no attribute 'outputBuffer' It's hard to say without seeing all your code, but I notice PyUnit 0.3 in your traceback.? If that's the PyUnit I think it is, PyUnit 1.4.1 was released 16(!) years ago, and has been in the standard library as unittest since version 2.1.? Are you running ancient versions of your test infrastructure? --Ned. From rosuav at gmail.com Sun Nov 26 16:53:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Mon, 27 Nov 2017 09:53:00 +1200 Subject: [META] Why are duplicate posts coming through? Message-ID: <3855286398@f38.n261.z1.binkp.net> Not sure whether this is an issue for -owner or not; apologies if not. I'm seeing a whole lot of reasonably-recent posts getting re-sent, with "nospam" attached to the posters' names. And they're getting re-sent multiple times. Sometimes the posts have encoding problems (small amounts of mojibake). What's going on? Is there something going haywire with the news/mail gateway? Is there a rogue client re-posting a bunch of news? Somebody testing something? ChrisA From cs at cskk.id.au Sun Nov 26 17:09:00 2017 From: cs at cskk.id.au (nospam.Cameron Simpson) Date: Mon, 27 Nov 2017 10:09:00 +1200 Subject: Pros and cons of Python sources? Message-ID: <1298626743@f38.n261.z1.binkp.net> On 26Nov2017 10:00, nospam.Martin Sch????n wrote: >Den 2017-11-26 skrev Cameron Simpson : >> On 25Nov2017 08:34, rusi wrote: >>>On Saturday, November 25, 2017 at 9:45:07 PM UTC+5:30, Michael Torrie wrote: >>>> The problem with mixing repository-installed packages with pip-installed >>>> packages is that there's always a chance a Debian update will overwrite >>>> a pip package, possibly with an older version. Or a pip-installed >>>> package might bring in a new version that's not compatible with some >>>> debian-installed package, breaking something. >>> >>>On (recent?) debian/ubuntu pip seems to use the 'user-scheme' >>>which means pip runs without sudo and installs in ~/.local/lib >>>So I dont believe literal overwriting would occur >> >> Though the point should be made that one should run pip as oneself, and try >to >> avoid doing it as the root user (including avoiding sudo). Many >UNIX/Linux/etc >> users believe "installs" should be done as root, and in this case that is >> easily avoided, with all its potential for damage to the vendor supplied >> environment. > >Hmm, I seem to remember not being able to install packages with pip unless I >did sudo pip. And this is exactly what I'm warning about. Many Linux users see some kind of failure and just stick sudo on the front of the command. It is almost always the wrong things to do, leading to effects in the OS install area instead of being safely contained within one's home directory or work area. Instead of reaching straight for sudo, look at pip's manual or help. You will find that: pip install --user ... installs modules local to your home directory, avoiding troublesome installs into the OS area. Cheers, Cameron Simpson (formerly cs at zip.com.au) From rosuav at gmail.com Sun Nov 26 17:12:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Mon, 27 Nov 2017 10:12:00 +1200 Subject: connect four (game) Message-ID: <2431172161@f38.n261.z1.binkp.net> On Mon, Nov 27, 2017 at 10:08 AM, Gregory Ewing wrote: > Chris Angelico wrote: > >> On Mon, Nov 27, 2017 at 1:11 AM, bartc wrote: > >> >>> >>> If I had to bother with such systematic tests as you suggest, and finish >>> and >>> sign off everything before proceeding further, then nothing would ever >>> get >>> done. (Maybe it's viable if working from an exacting specification that >>> someone else has already worked out.) >> >> >> I wonder whether you're somehow special in that >> testing fundamentally doesn't work for you, or that you actually don't >> need to write tests. > > > I think the point is that a strict test-first discipline goes > against the grain of exploratory programming. > > When you're not sure how to approach a problem, it's useful > to be able to quickly try things out. If you have to write a > bunch of tests for every little thing before you can write > the code for it, you can end up writing a lot of tests for > code that never ends up getting used. That's a good way to > kill all your enthusiasm for a project. I agree, and that's why I don't tend to go for TDD. But writing tests afterwards is a good thing, something I think bartc seems to disagree with. ChrisA From dvl at psu.edu Sun Nov 26 17:27:00 2017 From: dvl at psu.edu (nospam. ROGER GRAYDON CHRISTMAN) Date: Mon, 27 Nov 2017 10:27:00 +1200 Subject: Python-list Digest, Vol 170, Issue 34 Message-ID: <1871898189@f38.n261.z1.binkp.net> I'll answer your question with a couple questions: Why do you expect to get the results you seem to expect? What part of your code should repeat (and why)? A key factor in recognizing the difference between 'if' and 'while' is knowing what effect they have on the indented statements that follow them. Roger Christman Pennsylvania State University On Mon, Nov 27, 2017 Cai Gengyang wrote: > >Message: 38 >Date: Mon, 27 Nov 2017 04:54:21 -0800 (PST) >From: Cai Gengyang >Subject: While, If, Count Statements >Message-ID: >Content-Type: text/plain; charset="UTF-8" > > >Input : > >count = 0 > >if count < 5: > print "Hello, I am an if statement and count is", count > >while count < 10: > print "Hello, I am a while and count is", count > count += 1 > >Output : > >Hello, I am an if statement and count is 0 >Hello, I am a while and count is 0 >Hello, I am a while and count is 1 >Hello, I am a while and count is 2 >Hello, I am a while and count is 3 >Hello, I am a while and count is 4 >Hello, I am a while and count is 5 >Hello, I am a while and count is 6 >Hello, I am a while and count is 7 >Hello, I am a while and count is 8 >Hello, I am a while and count is 9 > >The above input gives the output below. Why isn't the output instead : > >Hello, I am an if statement and count is 0 >Hello, I am a while and count is 0 >Hello, I am an if statement and count is 1 >Hello, I am a while and count is 1 >Hello, I am an if statement and count is 2 >Hello, I am a while and count is 2 >Hello, I am an if statement and count is 3 >Hello, I am a while and count is 3 >Hello, I am an if statement and count is 4 >Hello, I am a while and count is 4 >Hello, I am a while and count is 5 >Hello, I am a while and count is 6 >Hello, I am a while and count is 7 >Hello, I am a while and count is 8 >Hello, I am a while and count is 9 > > From greg.ewing at canterbury.ac.nz Sun Nov 26 17:31:35 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 27 Nov 2017 11:31:35 +1300 Subject: Stopping an iterator and continuing later In-Reply-To: <3202337153@f38.n261.z1.binkp.net> References: <354384038@f38.n261.z1.binkp.net> <3202337153@f38.n261.z1.binkp.net> Message-ID: november nihal wrote: > I should have added I switch off the machine when I stop. ( I dont have options > to keep it in a sleep mode or in hibernation ) The iterator returned by itertools.combinations is pickleable: >>> from pickle import dumps, loads >>> from itertools import combinations >>> c = combinations([1,2,3,4,5], 2) >>> next(c) (1, 2) >>> next(c) (1, 3) >>> next(c) (1, 4) >>> s = dumps(c) >>> d = loads(s) >>> next(d) (1, 5) -- Greg From tmrsg11 at gmail.com Sun Nov 26 17:47:45 2017 From: tmrsg11 at gmail.com (C W) Date: Sun, 26 Nov 2017 17:47:45 -0500 Subject: I have anaconda, but Pycharm can't find it Message-ID: Hello all, I am a first time PyCharm user. I have Python 3 and Anaconda installed. They work together on Sublime Text, but not on Pycharm. Pycharm tells me it cannot find modules numpy, matplotlib, etc. What should I do? I tried to set the interpreter environment, and a few other options, none seem to work. This is the typical solution, but it does not work https://stackoverflow.com/questions/35623776/import-numpy-on-pycharm Thanks, -Mike From greg.ewing at canterbury.ac.nz Sun Nov 26 17:52:52 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 27 Nov 2017 11:52:52 +1300 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> Message-ID: bartc wrote: > (Maybe it's viable if working from an exacting > specification that someone else has already worked out.) In my experience, for anything non-trivial that hasn't been done before, these "exacting specifications" never exist. Even if someone handles wnat they *think* are exact and complete specifications, they're not. :-) -- Greg From rosuav at gmail.com Sun Nov 26 17:53:51 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Nov 2017 09:53:51 +1100 Subject: [META] Why are duplicate posts coming through? Message-ID: Not sure whether this is an issue for -owner or not; apologies if not. I'm seeing a whole lot of reasonably-recent posts getting re-sent, with "nospam" attached to the posters' names. And they're getting re-sent multiple times. Sometimes the posts have encoding problems (small amounts of mojibake). What's going on? Is there something going haywire with the news/mail gateway? Is there a rogue client re-posting a bunch of news? Somebody testing something? ChrisA From ned at nedbatchelder.com Sun Nov 26 17:59:00 2017 From: ned at nedbatchelder.com (nospam.Ned Batchelder) Date: Mon, 27 Nov 2017 10:59:00 +1200 Subject: While, If, Count Statements Message-ID: <1236202728@f38.n261.z1.binkp.net> On 11/27/17 7:54 AM, Cai Gengyang wrote: > Input : > > count = 0 > > if count < 5: > print "Hello, I am an if statement and count is", count > > while count < 10: > print "Hello, I am a while and count is", count > count += 1 > > Output : > > Hello, I am an if statement and count is 0 > Hello, I am a while and count is 0 > Hello, I am a while and count is 1 > Hello, I am a while and count is 2 > Hello, I am a while and count is 3 > Hello, I am a while and count is 4 > Hello, I am a while and count is 5 > Hello, I am a while and count is 6 > Hello, I am a while and count is 7 > Hello, I am a while and count is 8 > Hello, I am a while and count is 9 > > The above input gives the output below. Why isn't the output instead : > > Hello, I am an if statement and count is 0 > Hello, I am a while and count is 0 > Hello, I am an if statement and count is 1 > Hello, I am a while and count is 1 > Hello, I am an if statement and count is 2 > Hello, I am a while and count is 2 > Hello, I am an if statement and count is 3 > Hello, I am a while and count is 3 > Hello, I am an if statement and count is 4 > Hello, I am a while and count is 4 > Hello, I am a while and count is 5 > Hello, I am a while and count is 6 > Hello, I am a while and count is 7 > Hello, I am a while and count is 8 > Hello, I am a while and count is 9 It's easy to imagine that this sets up a rule that remains in effect for the rest of the program: ? ? ? if count < 5: ? ? ? ? ? ? ? print "Hello, I am an if statement and count is", count But that's not how Python (and most other programming languages) works.? Python reads statements one after another, and executes them as it encounters them.? When it finds the if-statement, it evaluates the condition, and if it is true *at that moment*, it executes the contained statements.? Then it forgets all about that if-statement, and moves on to the next statement. --Ned. From greg.ewing at canterbury.ac.nz Sun Nov 26 18:08:02 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 27 Nov 2017 12:08:02 +1300 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> Message-ID: Chris Angelico wrote: > On Mon, Nov 27, 2017 at 1:11 AM, bartc wrote: > >>If I had to bother with such systematic tests as you suggest, and finish and >>sign off everything before proceeding further, then nothing would ever get >>done. (Maybe it's viable if working from an exacting specification that >>someone else has already worked out.) > > I wonder whether you're somehow special in that > testing fundamentally doesn't work for you, or that you actually don't > need to write tests. I think the point is that a strict test-first discipline goes against the grain of exploratory programming. When you're not sure how to approach a problem, it's useful to be able to quickly try things out. If you have to write a bunch of tests for every little thing before you can write the code for it, you can end up writing a lot of tests for code that never ends up getting used. That's a good way to kill all your enthusiasm for a project. Also, stopping to write tests all the time interrupts your flow of thought. You're deep into details of the solution, you realise you need class X, then you have to stop and write tests for X. That makes you think a lot about all the details of X, and by the time you're finished you've lost track of the big picture. I don't think anyone disputes that having a reasonably complete set of tests is a good thing. The argument is about whether it's strictly necessary to write the tests *first* in all cases. Maybe you find it's a useful discipline that helps ensure the tests get written. That's fine, but it doesn't mean that *everyone* should be forced to do it that way all the time, even if they're just programming for a hobby. That's confusing the desired end result with a particular means of achieving it. -- Greg From cs at cskk.id.au Sun Nov 26 18:09:02 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 27 Nov 2017 10:09:02 +1100 Subject: Pros and cons of Python sources? In-Reply-To: <2332526810@f38.n261.z1.binkp.net> References: <2332526810@f38.n261.z1.binkp.net> Message-ID: <20171126230902.GA78877@cskk.homeip.net> On 26Nov2017 10:00, nospam.Martin Sch??n wrote: >Den 2017-11-26 skrev Cameron Simpson : >> On 25Nov2017 08:34, rusi wrote: >>>On Saturday, November 25, 2017 at 9:45:07 PM UTC+5:30, Michael Torrie wrote: >>>> The problem with mixing repository-installed packages with pip-installed >>>> packages is that there's always a chance a Debian update will overwrite >>>> a pip package, possibly with an older version. Or a pip-installed >>>> package might bring in a new version that's not compatible with some >>>> debian-installed package, breaking something. >>> >>>On (recent?) debian/ubuntu pip seems to use the 'user-scheme' >>>which means pip runs without sudo and installs in ~/.local/lib >>>So I dont believe literal overwriting would occur >> >> Though the point should be made that one should run pip as oneself, and try >to >> avoid doing it as the root user (including avoiding sudo). Many >UNIX/Linux/etc >> users believe "installs" should be done as root, and in this case that is >> easily avoided, with all its potential for damage to the vendor supplied >> environment. > >Hmm, I seem to remember not being able to install packages with pip unless I >did sudo pip. And this is exactly what I'm warning about. Many Linux users see some kind of failure and just stick sudo on the front of the command. It is almost always the wrong things to do, leading to effects in the OS install area instead of being safely contained within one's home directory or work area. Instead of reaching straight for sudo, look at pip's manual or help. You will find that: pip install --user ... installs modules local to your home directory, avoiding troublesome installs into the OS area. Cheers, Cameron Simpson (formerly cs at zip.com.au) From antoon.pardon at vub.be Sun Nov 26 18:11:00 2017 From: antoon.pardon at vub.be (nospam.Antoon Pardon) Date: Mon, 27 Nov 2017 11:11:00 +1200 Subject: Benefits of unicode identifiers (was: Allow additional separator Message-ID: <1401384858@f38.n261.z1.binkp.net> Op 23-11-17 om 19:42 schreef Mikhail V: > Chris A wrote: > >>> On Fri, Nov 24, 2017 at 1:10 AM, Mikhail V wrote: >>> >>>> Chris A wrote: >>>> >>>> Fortunately for the world, you're not the one who decided which >>>> characters were permitted in Python identifiers. The ability to use >>>> non-English words for function/variable names is of huge value; the >>>> ability to use a hyphen is of some value, but not nearly as much. >>> Fortunately for the world we have Chris A. Who knows what is >>> fortunate and of huge values. >>> So is there any real world projects example of usage of non-latin scripts >>> in identifiers? Or is it still only a plan for the new world? > >> Yes, I've used them personally. And I know other people who have. > > Oh, I though it would be more impressive showcase for 'huge value'. > If we drop the benefit of the bare fact that you can do it, or you just > don't know English, how would describe the practical benefit? > If you don't know english, then programming at all will be just too hard. > (or one must define a new whole language specially for some local script) Well maybe the value is not huge, but I really appreciate the possibility. Being able to write something like below, makes things a lot more clear for me. Po = Pc + R * Vec(cos(?,o), sin(?,o)) Pe = Pc + R * Vec(cos(?,e), sin(?,e)) g????, = ?,e - ?,o g???P = Pe - Po -- Antoon Pardon. From rosuav at gmail.com Sun Nov 26 18:12:52 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Nov 2017 10:12:52 +1100 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> Message-ID: On Mon, Nov 27, 2017 at 10:08 AM, Gregory Ewing wrote: > Chris Angelico wrote: > >> On Mon, Nov 27, 2017 at 1:11 AM, bartc wrote: > >> >>> >>> If I had to bother with such systematic tests as you suggest, and finish >>> and >>> sign off everything before proceeding further, then nothing would ever >>> get >>> done. (Maybe it's viable if working from an exacting specification that >>> someone else has already worked out.) >> >> >> I wonder whether you're somehow special in that >> testing fundamentally doesn't work for you, or that you actually don't >> need to write tests. > > > I think the point is that a strict test-first discipline goes > against the grain of exploratory programming. > > When you're not sure how to approach a problem, it's useful > to be able to quickly try things out. If you have to write a > bunch of tests for every little thing before you can write > the code for it, you can end up writing a lot of tests for > code that never ends up getting used. That's a good way to > kill all your enthusiasm for a project. I agree, and that's why I don't tend to go for TDD. But writing tests afterwards is a good thing, something I think bartc seems to disagree with. ChrisA From skip.montanaro at gmail.com Sun Nov 26 18:18:00 2017 From: skip.montanaro at gmail.com (nospam.Skip Montanaro) Date: Mon, 27 Nov 2017 11:18:00 +1200 Subject: Increasing the diversity of people who write Python (was: Message-ID: <2378687452@f38.n261.z1.binkp.net> > I strongly suspect that any recent emacs will have M-x insert-char > (earlier it was called ucs-insert) default bound C-x 8 RET (yeah thats clunky) > which will accept at the minibuffer input I tried C-x 8 e acute TAB and was prompted with "E-acute". I don't know why it would have capitalized the "e". Still, I plowed ahead and hit RET which yielded an "Invalid character" message in the minibuffer. Skip From greg.ewing at canterbury.ac.nz Sun Nov 26 18:31:00 2017 From: greg.ewing at canterbury.ac.nz (nospam.Gregory Ewing) Date: Mon, 27 Nov 2017 11:31:00 +1200 Subject: Stopping an iterator and continuing later References: <4036528059@f38.n261.z1.binkp.net> Message-ID: <1952649508@f38.n261.z1.binkp.net> november nihal wrote: > I should have added I switch off the machine when I stop. ( I dont have options > to keep it in a sleep mode or in hibernation ) The iterator returned by itertools.combinations is pickleable: >>> from pickle import dumps, loads >>> from itertools import combinations >>> c = combinations([1,2,3,4,5], 2) >>> next(c) (1, 2) >>> next(c) (1, 3) >>> next(c) (1, 4) >>> s = dumps(c) >>> d = loads(s) >>> next(d) (1, 5) -- Greg From bc at freeuk.com Sun Nov 26 18:38:00 2017 From: bc at freeuk.com (nospam.bartc) Date: Mon, 27 Nov 2017 11:38:00 +1200 Subject: connect four (game) References: <2617264369@f38.n261.z1.binkp.net> Message-ID: <4114523388@f38.n261.z1.binkp.net> On 27/11/2017 03:04, Michael Torrie wrote: > On 11/26/2017 08:39 AM, bartc wrote: >> The problem was traced to two lines that were in the wrong order (in the >> original program). I can't see how unit tests can have helped in any way >> at all, and it would probably have taken much longer. > > What makes you think that? Surely other decoders were doing the right > thing and you could compare your output against theirs? JPEGs may be > lossy but the path through the decoder should be deterministic. > > Or even if every decoder is slightly unique, at least yours should > output self-consistent data. The original used some floating point code, I changed that to use integer code (eg a combination of multiplying and shifting; it make a difference on compiled version, perhaps not so much in .py). But also (IIRC) there was a difference in taking the remainder of negative integer division, where different compilers may round up or down. So there can easily be differences when compared at the binary level, but which shouldn't be noticeable with the human eye. (https://pastebin.com/P7V1Bvkk https://pastebin.com/raw/P7V1Bvkk raw version with no ads, or colour) In other words, once you know you fixed > the chroma problem, you can use that jpeg as a unit test to make sure > future big fixes and enhancements don't break something else. > Regression testing is very important. Many times I've fixed a bug, only > to introduce new ones that broke formerly correct behavior. > > Anyway, unit testing is certainly a challenging concept, and I'm no more > good at it than you are. Some people are obsessed with having unit tests. Others are the same about using debuggers, especially in compiled code. I've never used either, but I do alright. Some of the stuff I do is unsuitable for those for technical reasons, but also some of the problems I've come across just don't fit into such patterns. People should use what works best for them, unless they're in a team where the have to use certain tools and working methods. -- bartc From greg.ewing at canterbury.ac.nz Sun Nov 26 18:46:35 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 27 Nov 2017 12:46:35 +1300 Subject: Merits of otherwise of test-first (Re: connect four (game)) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> Message-ID: bartc wrote: > Testing everything comprehensively just wouldn't be useful for me who > works on whole applications, whole concepts, not just a handful of > functions with well-defined inputs and outputs. I had this experience with Pyrex (the precursor to Cython). The various parts are so interdependent that it doesn't really make sense to test individual classes or methods on their own. It would require a huge amount of scaffolding and wouldn't really prove much. Instead, what I did was write tests for units of *functionality*. (Can it compile an assignment statement? An expression that adds two things? Subtracts them? etc.) I wrote a very large number of them, plus a test framework to run them and compare the output with known good output. I can't claim that I always wrote the tests *first* (sometimes I did, sometimes I didn't). But I never had any trouble motivating myself to write the tests. Partly this is because the way my test framework worked, there was very little difference between a manual test and an automated one. I had to write a test file to test it at all, and having done that, it was just as easy to save it away together with its output so that it became part of the automated test suite. It was also partly because the benefits of having a comprehensive automatic test suite were so blindingly obvious in that project. Its complexity meant that it was particularly easy to break something accidentally when adding a new feature. If that happened, the tests would almost certainly pick it up immediately. Without those tests, I would never have been able to develop it to the point I did. >> So there was something else wrong with the chip. I'm not sure what >> your point is. > > The extensive testing was like unit testing, but needed to be even more > thorough because of the commitment involved. It failed to spot a problem. Testing obviously isn't guaranteed to find all problems in a system with complex behaviour, but that doesn't mean testing is useless. It would have been hugely more risky to go ahead and build the chip without testing the design at all! BTW, hardware is a bit different from software. It's possible for a design to be *logically* correct and pass all the simulations, but for the hardware to fail for messy physics- related reasons. (Charles Moore tells a story like that about one of his Forth chips. A transistor driving a particular signal was too small, and if you executed a particular instruction too many times in too short a time interval, it would overheat and produce incorrect results.) -- Greg From greg.ewing at canterbury.ac.nz Sun Nov 26 18:52:00 2017 From: greg.ewing at canterbury.ac.nz (nospam.Gregory Ewing) Date: Mon, 27 Nov 2017 11:52:00 +1200 Subject: connect four (game) References: <1920166871@f38.n261.z1.binkp.net> Message-ID: <787071073@f38.n261.z1.binkp.net> bartc wrote: > (Maybe it's viable if working from an exacting > specification that someone else has already worked out.) In my experience, for anything non-trivial that hasn't been done before, these "exacting specifications" never exist. Even if someone handles wnat they *think* are exact and complete specifications, they're not. :-) -- Greg From greg.ewing at canterbury.ac.nz Sun Nov 26 18:55:36 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 27 Nov 2017 12:55:36 +1300 Subject: nospam ** infinity? Message-ID: There seems to be a gateway loop of some sort going on. I'm seeing multiple versions of the same posts in comp.lang.python with different numbers of "nospam"s prepended to the email address. -- Greg From rosuav at gmail.com Sun Nov 26 19:04:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Mon, 27 Nov 2017 12:04:00 +1200 Subject: [META] Why are duplicate posts coming through? Message-ID: <1912608769@f38.n261.z1.binkp.net> On Mon, Nov 27, 2017 at 11:04 AM, Skip Montanaro wrote: > Chris, > > Please forward one or two to me. Mark Sapiro and I have been banging on the > SpamBayes instance which supports the Usenet gateway. I suppose it's > possible some change caused the problem you're seeing. > > Skip Sent a couple through. ChrisA From skip.montanaro at gmail.com Sun Nov 26 19:04:49 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 26 Nov 2017 18:04:49 -0600 Subject: [META] Why are duplicate posts coming through? In-Reply-To: References: Message-ID: Chris, Please forward one or two to me. Mark Sapiro and I have been banging on the SpamBayes instance which supports the Usenet gateway. I suppose it's possible some change caused the problem you're seeing. Skip On Nov 26, 2017 5:22 PM, "Chris Angelico" wrote: Not sure whether this is an issue for -owner or not; apologies if not. I'm seeing a whole lot of reasonably-recent posts getting re-sent, with "nospam" attached to the posters' names. And they're getting re-sent multiple times. Sometimes the posts have encoding problems (small amounts of mojibake). What's going on? Is there something going haywire with the news/mail gateway? Is there a rogue client re-posting a bunch of news? Somebody testing something? ChrisA -- https://mail.python.org/mailman/listinfo/python-list From greg.ewing at canterbury.ac.nz Sun Nov 26 19:08:00 2017 From: greg.ewing at canterbury.ac.nz (nospam.Gregory Ewing) Date: Mon, 27 Nov 2017 12:08:00 +1200 Subject: connect four (game) References: <2225514370@f38.n261.z1.binkp.net> Message-ID: <837138654@f38.n261.z1.binkp.net> Chris Angelico wrote: > On Mon, Nov 27, 2017 at 1:11 AM, bartc wrote: > >>If I had to bother with such systematic tests as you suggest, and finish and >>sign off everything before proceeding further, then nothing would ever get >>done. (Maybe it's viable if working from an exacting specification that >>someone else has already worked out.) > > I wonder whether you're somehow special in that > testing fundamentally doesn't work for you, or that you actually don't > need to write tests. I think the point is that a strict test-first discipline goes against the grain of exploratory programming. When you're not sure how to approach a problem, it's useful to be able to quickly try things out. If you have to write a bunch of tests for every little thing before you can write the code for it, you can end up writing a lot of tests for code that never ends up getting used. That's a good way to kill all your enthusiasm for a project. Also, stopping to write tests all the time interrupts your flow of thought. You're deep into details of the solution, you realise you need class X, then you have to stop and write tests for X. That makes you think a lot about all the details of X, and by the time you're finished you've lost track of the big picture. I don't think anyone disputes that having a reasonably complete set of tests is a good thing. The argument is about whether it's strictly necessary to write the tests *first* in all cases. Maybe you find it's a useful discipline that helps ensure the tests get written. That's fine, but it doesn't mean that *everyone* should be forced to do it that way all the time, even if they're just programming for a hobby. That's confusing the desired end result with a particular means of achieving it. -- Greg From skip.montanaro at gmail.com Sun Nov 26 19:13:00 2017 From: skip.montanaro at gmail.com (nospam.Skip Montanaro) Date: Mon, 27 Nov 2017 12:13:00 +1200 Subject: Increasing the diversity of people who write Python (was: Message-ID: <1312833261@f38.n261.z1.binkp.net> > If you have a Windows key, you can assign it to be > the Compose key. Would this be true on a machine running Windows? My work environment has me developing on Linux, with a Windows desktop. It's not clear to me that any sort of xmodmap shennanigans would work. Won't Windows itself always gobble up that key? Skip From rosuav at gmail.com Sun Nov 26 19:19:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Mon, 27 Nov 2017 12:19:00 +1200 Subject: nospam ** infinity? Message-ID: <3069634946@f38.n261.z1.binkp.net> On Mon, Nov 27, 2017 at 12:14 PM, Skip Montanaro wrote: >> There seems to be a gateway loop of some sort going on. >> I'm seeing multiple versions of the same posts in >> comp.lang.python with different numbers of "nospam"s >> prepended to the email address. > > This is the second thread about this. I was thinking it might be > related to recent changes to the gate_news process on mail.python.org, > but this fingerprint looks nothing like what gate_news does. > > Looking at a somewhat long-ish thread: > > https://groups.google.com/d/topic/comp.lang.python/YoxLtkzlt_o/discussion > > I see a couple posts from Chris Angelico, only some of which have a > "nospam" preface. It would seem that someone was trying to mark > certain posters as "not spammy," (I'm sure Chris is flattered) and > somehow posts with that private marking leaked out of the user's > system starting in the past twelve hours or so. > > Newsreader configuration problem? More likely, someone was trying to obscure the email addresses, but managed to tag my name instead. Definitely looks like some sort of automation failure. The only question is, whose? If it's not from gate_news, there's someone here on the list/ng that is (probably accidentally) reposting everything. ChrisA From greg.ewing at canterbury.ac.nz Sun Nov 26 19:46:00 2017 From: greg.ewing at canterbury.ac.nz (nospam.Gregory Ewing) Date: Mon, 27 Nov 2017 12:46:00 +1200 Subject: Merits of otherwise of test-first (Re: connect four (game)) References: <3028938924@f38.n261.z1.binkp.net> Message-ID: <3637100186@f38.n261.z1.binkp.net> bartc wrote: > Testing everything comprehensively just wouldn't be useful for me who > works on whole applications, whole concepts, not just a handful of > functions with well-defined inputs and outputs. I had this experience with Pyrex (the precursor to Cython). The various parts are so interdependent that it doesn't really make sense to test individual classes or methods on their own. It would require a huge amount of scaffolding and wouldn't really prove much. Instead, what I did was write tests for units of *functionality*. (Can it compile an assignment statement? An expression that adds two things? Subtracts them? etc.) I wrote a very large number of them, plus a test framework to run them and compare the output with known good output. I can't claim that I always wrote the tests *first* (sometimes I did, sometimes I didn't). But I never had any trouble motivating myself to write the tests. Partly this is because the way my test framework worked, there was very little difference between a manual test and an automated one. I had to write a test file to test it at all, and having done that, it was just as easy to save it away together with its output so that it became part of the automated test suite. It was also partly because the benefits of having a comprehensive automatic test suite were so blindingly obvious in that project. Its complexity meant that it was particularly easy to break something accidentally when adding a new feature. If that happened, the tests would almost certainly pick it up immediately. Without those tests, I would never have been able to develop it to the point I did. >> So there was something else wrong with the chip. I'm not sure what >> your point is. > > The extensive testing was like unit testing, but needed to be even more > thorough because of the commitment involved. It failed to spot a problem. Testing obviously isn't guaranteed to find all problems in a system with complex behaviour, but that doesn't mean testing is useless. It would have been hugely more risky to go ahead and build the chip without testing the design at all! BTW, hardware is a bit different from software. It's possible for a design to be *logically* correct and pass all the simulations, but for the hardware to fail for messy physics- related reasons. (Charles Moore tells a story like that about one of his Forth chips. A transistor driving a particular signal was too small, and if you executed a particular instruction too many times in too short a time interval, it would overheat and produce incorrect results.) -- Greg From greg.ewing at canterbury.ac.nz Sun Nov 26 19:55:00 2017 From: greg.ewing at canterbury.ac.nz (nospam.Gregory Ewing) Date: Mon, 27 Nov 2017 12:55:00 +1200 Subject: nospam ** infinity? Message-ID: <835019426@f38.n261.z1.binkp.net> There seems to be a gateway loop of some sort going on. I'm seeing multiple versions of the same posts in comp.lang.python with different numbers of "nospam"s prepended to the email address. -- Greg From rosuav at gmail.com Sun Nov 26 20:04:30 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Nov 2017 12:04:30 +1100 Subject: [META] Why are duplicate posts coming through? In-Reply-To: References: Message-ID: On Mon, Nov 27, 2017 at 11:04 AM, Skip Montanaro wrote: > Chris, > > Please forward one or two to me. Mark Sapiro and I have been banging on the > SpamBayes instance which supports the Usenet gateway. I suppose it's > possible some change caused the problem you're seeing. > > Skip Sent a couple through. ChrisA From skip.montanaro at gmail.com Sun Nov 26 20:14:15 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 26 Nov 2017 19:14:15 -0600 Subject: nospam ** infinity? In-Reply-To: References: Message-ID: > There seems to be a gateway loop of some sort going on. > I'm seeing multiple versions of the same posts in > comp.lang.python with different numbers of "nospam"s > prepended to the email address. This is the second thread about this. I was thinking it might be related to recent changes to the gate_news process on mail.python.org, but this fingerprint looks nothing like what gate_news does. Looking at a somewhat long-ish thread: https://groups.google.com/d/topic/comp.lang.python/YoxLtkzlt_o/discussion I see a couple posts from Chris Angelico, only some of which have a "nospam" preface. It would seem that someone was trying to mark certain posters as "not spammy," (I'm sure Chris is flattered) and somehow posts with that private marking leaked out of the user's system starting in the past twelve hours or so. Newsreader configuration problem? Skip From rosuav at gmail.com Sun Nov 26 20:19:17 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Nov 2017 12:19:17 +1100 Subject: nospam ** infinity? In-Reply-To: References: Message-ID: On Mon, Nov 27, 2017 at 12:14 PM, Skip Montanaro wrote: >> There seems to be a gateway loop of some sort going on. >> I'm seeing multiple versions of the same posts in >> comp.lang.python with different numbers of "nospam"s >> prepended to the email address. > > This is the second thread about this. I was thinking it might be > related to recent changes to the gate_news process on mail.python.org, > but this fingerprint looks nothing like what gate_news does. > > Looking at a somewhat long-ish thread: > > https://groups.google.com/d/topic/comp.lang.python/YoxLtkzlt_o/discussion > > I see a couple posts from Chris Angelico, only some of which have a > "nospam" preface. It would seem that someone was trying to mark > certain posters as "not spammy," (I'm sure Chris is flattered) and > somehow posts with that private marking leaked out of the user's > system starting in the past twelve hours or so. > > Newsreader configuration problem? More likely, someone was trying to obscure the email addresses, but managed to tag my name instead. Definitely looks like some sort of automation failure. The only question is, whose? If it's not from gate_news, there's someone here on the list/ng that is (probably accidentally) reposting everything. ChrisA From nospam.ram at zedat.fu-berlin.de Sun Nov 26 20:26:00 2017 From: nospam.ram at zedat.fu-berlin.de (Stefan Ram Stefan Ram) Date: Mon, 27 Nov 2017 13:26:00 +1200 Subject: While, If, Count Statements References: <422026890@f38.n261.z1.binkp.net> Message-ID: <1428530442@f38.n261.z1.binkp.net> Cai Gengyang writes: Statement 0: >count = 0 Statement 1: >if count < 5: > print "Hello, I am an if statement and count is", count Statement 2: >while count < 10: > print "Hello, I am a while and count is", count > count += 1 There are three statements here. They are executed in the given sequence. First, statement 0 binds the name ??count?? to an object which has the int-value ??0??. Next, statement 1 prints ??am an if??. Now statement 1 was executed. It will never be revisited. It's history. Next, statement 2 will print "am a while" several times. It is separated from statement 2, like, totally. The statement 1 is in the remote past from where it never will return to be executed while the while loop is happily printing aways its "am a while" :-). Statement 1 is sad :-(, because it will never print no more. Never more. From bc at freeuk.com Sun Nov 26 20:26:00 2017 From: bc at freeuk.com (nospam.bartc) Date: Mon, 27 Nov 2017 13:26:00 +1200 Subject: While, If, Count Statements References: <422026890@f38.n261.z1.binkp.net> Message-ID: <3790119431@f38.n261.z1.binkp.net> On 27/11/2017 12:54, Cai Gengyang wrote: > > Input : > > count = 0 > > if count < 5: > print "Hello, I am an if statement and count is", count > > while count < 10: > print "Hello, I am a while and count is", count > count += 1 > > Output : > > Hello, I am an if statement and count is 0 > Hello, I am a while and count is 0 > Hello, I am a while and count is 1 > Hello, I am a while and count is 2 > Hello, I am a while and count is 3 > Hello, I am a while and count is 4 > Hello, I am a while and count is 5 > Hello, I am a while and count is 6 > Hello, I am a while and count is 7 > Hello, I am a while and count is 8 > Hello, I am a while and count is 9 > > The above input gives the output below. Why isn't the output instead : > > Hello, I am an if statement and count is 0 > Hello, I am a while and count is 0 > Hello, I am an if statement and count is 1 > Hello, I am a while and count is 1 > Hello, I am an if statement and count is 2 > Hello, I am a while and count is 2 > Hello, I am an if statement and count is 3 > Hello, I am a while and count is 3 > Hello, I am an if statement and count is 4 > Hello, I am a while and count is 4 > Hello, I am a while and count is 5 > Hello, I am a while and count is 6 > Hello, I am a while and count is 7 > Hello, I am a while and count is 8 > Hello, I am a while and count is 9 Because the if-statement is only executed once, then it does the loop. Try: count = 0 while count < 10: if count < 5: print "Hello, I am an if statement and count is", count print "Hello, I am a while and count is", count count += 1 From ned at nedbatchelder.com Sun Nov 26 21:15:00 2017 From: ned at nedbatchelder.com (nospam.Ned Batchelder) Date: Mon, 27 Nov 2017 14:15:00 +1200 Subject: connect four (game) Message-ID: <1460935530@f38.n261.z1.binkp.net> On 11/27/17 1:57 PM, bartc wrote: > On 27/11/2017 17:41, Chris Angelico wrote: >> On Tue, Nov 28, 2017 at 2:14 AM, bartc wrote: >>> JPEG uses lossy compression. The resulting recovered data is an >>> approximation of the original. >> >> Ah but it is a perfect representation of the JPEG stream. Any given >> compressed stream must always decode to the same output. The lossiness >> is on the ENcoding, not the DEcoding. > > You make it sound as bad as currency calculations where different > software must produce results that always match to the nearest cent. > > We're talking about perhaps +1 or -1 difference in the least > significant bit of one channel of one pixels. If the calculation is > consistent, then you will not know anything is amiss. > > By +1 or -1, I mean compared with the same jpeg converted by > independent means. > > I also passed the same jpeg through another C program (not mine) using > its own algorithms. There some pixels varied by up to +/- 9 from the > others (looking at the first 512 bytes of the conversion to ppm). > > Here's my test image: > https://github.com/bartg/langs/blob/master/card2.jpg (nothing naughty). > > Tell me what the definitive values of the pixels in this part of the > image should be (I believe this corresponds to roughly the leftmost > 180 pixels of the top line; there are two million pixels in all). And > tell me WHY you think those are the definitive ones. > > Bear in mind also that this is not intended to be the world's most > perfect software. But it does do a good enough job. And the other two > Python versions I have, at the minute don't work at all. > > Surely the details of JPEG decompression, and the possible presence of flaws in certain decoders, is beyond the scope of this thread? --Ned. From rustompmody at gmail.com Sun Nov 26 21:36:37 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 26 Nov 2017 18:36:37 -0800 (PST) Subject: [META] Why are duplicate posts coming through? In-Reply-To: References: Message-ID: <1ba9a5d8-4677-4289-96cc-f5392d834d0b@googlegroups.com> On Monday, November 27, 2017 at 5:35:09 AM UTC+5:30, Skip Montanaro wrote: > Chris, > > Please forward one or two to me. Mark Sapiro and I have been banging on the > SpamBayes instance which supports the Usenet gateway. I suppose it's > possible some change caused the problem you're seeing. > > Skip > > On Nov 26, 2017 5:22 PM, "Chris Angelico" wrote: > > Not sure whether this is an issue for -owner or not; apologies if not. > > I'm seeing a whole lot of reasonably-recent posts getting re-sent, > with "nospam" attached to the posters' names. And they're getting > re-sent multiple times. Sometimes the posts have encoding problems > (small amounts of mojibake). > > What's going on? Is there something going haywire with the news/mail > gateway? Is there a rogue client re-posting a bunch of news? Somebody > testing something? And the spam continues unabated Except that the subject lines are changed From rosuav at gmail.com Sun Nov 26 21:38:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Mon, 27 Nov 2017 14:38:00 +1200 Subject: connect four (game) Message-ID: <2961545766@f38.n261.z1.binkp.net> On Mon, Nov 27, 2017 at 1:55 PM, Michael Torrie wrote: > On 11/26/2017 07:11 AM, bartc wrote: >>> You may argue that testing doesn't matter for his small game, written >>> for his own education and amusement. The fact is that software in >>> general is of abysmal quality across the boards, and promoting a habit >>> of unit testing is good, even for trivial, home-grown stuff. >> >> I thought people were being hard on the OP. > > I wasn't being hard on the OP. My observation is about the state of > *all* software. My software especially, your software, Microsoft's > software. It all is of rather poor quality compared to the rigors of > other industries like civil engineering, manufacturing, etc. Not all software is poor quality compared to all examples of those industries. You'll find the equivalent of software bugs in a lot of hardware situations; the difference with software is that we have 100% perfect reproduction in the end-user products, so we call it a design flaw instead of a production artifact. (How often do you buy a box of something and find that a couple of them just break?) Even in large-scale civil engineering projects, there are plenty of stupidities. The house I'm living in has a place where the tiled floor doesn't quite align with the wall that it meets, and I can't figure out why; somewhere, two things that ought to have been parallel just aren't. Bridges have been known to crack, cars break down for no good reason, your hamburger just doesn't taste right today. Aviators have pinned down the best solution to this, I think. A pilot is not expected to be perfect; he is expected to follow checklists. A preflight checklist. A departure checklist. A landing checklist. Everything that needs to be done right is mentioned on the list, and you just go through the list and make sure you've done everything. Interestingly enough, that approximately corresponds to unit testing (or maybe integration testing) - you design a suite of tests, and every time you do something, you make sure all the tests pass. Neither test suites nor checklists can prevent all problems - but they CAN prevent the same problems from cropping up again and again. (Which is kinda important when you're dealing with airliners carrying hundreds of people. They crash very rarely because the crew follow their checklists religiously, and when they do, there's an investigation that can result in new tests being added.) ChrisA From torriem at gmail.com Sun Nov 26 21:55:22 2017 From: torriem at gmail.com (Michael Torrie) Date: Sun, 26 Nov 2017 19:55:22 -0700 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> Message-ID: On 11/26/2017 07:11 AM, bartc wrote: >> You may argue that testing doesn't matter for his small game, written >> for his own education and amusement. The fact is that software in >> general is of abysmal quality across the boards, and promoting a habit >> of unit testing is good, even for trivial, home-grown stuff. > > I thought people were being hard on the OP. I wasn't being hard on the OP. My observation is about the state of *all* software. My software especially, your software, Microsoft's software. It all is of rather poor quality compared to the rigors of other industries like civil engineering, manufacturing, etc. > As for testing, I remember in a company I worked in, a complicated > circuit was submitted to a company that would put it into a > mass-produced chip. This company did massive numbers of emulated tests > shown on a huge printout that showed that all combinations of inputs and > outputs worked exactly as intended. > > Except the actual chip didn't work. As for the printout, the designer > took it home and used it as an underlay for a new carpet. A rather > expensive underlay. That's unfortunately, but seems to reinforce the notion that adequate testing is required. Clearly for a microchip, theoretically testing the chip's "software" (for lack of a better term) was not adequate. An analogy to our software situation is that someone tested the algorithm, but not the actual, in-use implementation of the algorithm. From torriem at gmail.com Sun Nov 26 22:04:42 2017 From: torriem at gmail.com (Michael Torrie) Date: Sun, 26 Nov 2017 20:04:42 -0700 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> Message-ID: <3e61c073-1bc1-1e87-0abe-952ff23fcf19@gmail.com> On 11/26/2017 08:39 AM, bartc wrote: > The problem was traced to two lines that were in the wrong order (in the > original program). I can't see how unit tests can have helped in any way > at all, and it would probably have taken much longer. What makes you think that? Surely other decoders were doing the right thing and you could compare your output against theirs? JPEGs may be lossy but the path through the decoder should be deterministic. Or even if every decoder is slightly unique, at least yours should output self-consistent data. In other words, once you know you fixed the chroma problem, you can use that jpeg as a unit test to make sure future big fixes and enhancements don't break something else. Regression testing is very important. Many times I've fixed a bug, only to introduce new ones that broke formerly correct behavior. Anyway, unit testing is certainly a challenging concept, and I'm no more good at it than you are. From torriem at gmail.com Sun Nov 26 22:09:09 2017 From: torriem at gmail.com (Michael Torrie) Date: Sun, 26 Nov 2017 20:09:09 -0700 Subject: connect four (game) In-Reply-To: <35191dce-b751-42d1-ac87-b25c648fd95c@googlegroups.com> References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <35191dce-b751-42d1-ac87-b25c648fd95c@googlegroups.com> Message-ID: On 11/25/2017 12:58 PM, namenobodywants at gmail.com wrote: > the idea is that there should be exactly one object posinf (positive infinity) that compares as strictly greater than any number ever considered, and exactly one object neginf that compares as strictly less; as the code stands now there is no reason not to use +/-70 in that capacity; the "infinity" class is there so that the game-playing parts of the code (which at present are intentionally as primitive as possible) can be modified more smoothly later; the single place where "infinity" is instantiated is in the function "getvalue", which returns the value of a finished game: > > def getvalue(winner,accessibles): > return Infinity(+1) if winner == ex else Infinity(-1) if winner == oh else 0 if not accessibles else None > > if ex has won then the value of the game is posinf; if oh has won then it's neginf; if the game is tied (no winner but no accessible columns remaining) then the value of the game is zero; otherwise the game is not finished and its finished value is None So you are using this Infinity class as a sentinel value of some kind? Representing game state? There may be an easier way than a full on custom type. Sometimes just a sentinel object is sufficient. Or an enumeration. From bc at freeuk.com Sun Nov 26 22:14:00 2017 From: bc at freeuk.com (nospam.bartc) Date: Mon, 27 Nov 2017 15:14:00 +1200 Subject: connect four (game) References: <3513593611@f38.n261.z1.binkp.net> Message-ID: <1156313661@f38.n261.z1.binkp.net> On 27/11/2017 13:57, Chris Angelico wrote: > On Mon, Nov 27, 2017 at 10:38 PM, bartc wrote: > Your decoder was straight-up buggy, and tests would have proven this. I created my Python version after the abysmal results from other Python decoders I tried which didn't work at all, gave the wrong results, didn't support other subsampling ratios, or hung. Or if they did work, they took forever. I suggest you compare my version with some of those. The first time I looked at a jpeg decoder, it was a massive C library of about 30 different source files. Sometimes you need to take short-cuts. My version generates images which are indistinguishable from those derived via other decoders. >> But also (IIRC) there was a difference in taking the remainder of negative >> integer division, where different compilers may round up or down. > > In every compiler, interpreter, and CPU that I've ever used, the > remainder has been well-defined. In what situation was it ill-defined, > such that different compilers could do different things? In certain C implementations, rounding the results of integer division could go up or down. This is a post from comp.lang.c from 2008: "Nate Eldredge" wrote in message news:8663mf144q.fsf at vulcan.lan... > Mr. Burns writes: > >> Hi group, >> >> suppose I have a grid of cells of size (R,C) and coordinates >> (0..R-1,0..C-1) and >> I'm translating pixel coordinates to grid coordinates by dividing by cell >> size. >> >> Now, all works well for values >= 0, but for values < 0 I'm getting >> inconsistent results. >> >> On one platform, division of negative numbers rounds towards negative >> infinity, i.e., (-1 / 10) gives -1. (this is what I want) >> >> On another platform (solaris), rounding is towards zero, and (-1 / 10) is >> 0! >> >> All numbers are plain ints. > > The C99 standard specifies truncation towards zero (like your Solaris > compiler). However, the previous C90 standard left it up to the > implementation to decide which way to round when one of the operands is > negative, as long as it is consistent with the % operator. Exactly what the problem was with my jpeg program where a number from my language and compiler ended up as 187, but on C compiled with gcc as 186, I can't remember. I /think/ it was to do with such rounding. This is not a big deal: one program ends up with a pixel value of 186 (in a range of 0 to 255), and another with 187. The true value in the original photo may have required a value somewhere between 186 and 187, so both values could be considered wrong! > Which, if I'm not misunderstanding the specs, is the case for pretty > much every compression scheme in current use - including JPEG. JPEG uses lossy compression. The resulting recovered data is an approximation of the original. > For myself, I don't write as many tests as I should. But I'm not going > to go around telling people that tests are a waste of time. I'm fairly certain the OP's program didn't work perfectly first time. So some procedure had to be followed to try it and decide if it behaved according to the specification they had in mind. I believe that process can also be called 'testing'. And in this case, involving a visual GUI, it really demands tests verified by a human rather than spending the next six months writing automatic test procedures that simulate mouse input and examine the pixels on the screen to see if they correspond to what should happen. > Your decoder was straight-up buggy, and tests would have proven this. How did YOU determine it was buggy; unit-tests? And did you just do what everyone else does? -- Bartc From rosuav at gmail.com Sun Nov 26 22:38:24 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Nov 2017 14:38:24 +1100 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> Message-ID: On Mon, Nov 27, 2017 at 1:55 PM, Michael Torrie wrote: > On 11/26/2017 07:11 AM, bartc wrote: >>> You may argue that testing doesn't matter for his small game, written >>> for his own education and amusement. The fact is that software in >>> general is of abysmal quality across the boards, and promoting a habit >>> of unit testing is good, even for trivial, home-grown stuff. >> >> I thought people were being hard on the OP. > > I wasn't being hard on the OP. My observation is about the state of > *all* software. My software especially, your software, Microsoft's > software. It all is of rather poor quality compared to the rigors of > other industries like civil engineering, manufacturing, etc. Not all software is poor quality compared to all examples of those industries. You'll find the equivalent of software bugs in a lot of hardware situations; the difference with software is that we have 100% perfect reproduction in the end-user products, so we call it a design flaw instead of a production artifact. (How often do you buy a box of something and find that a couple of them just break?) Even in large-scale civil engineering projects, there are plenty of stupidities. The house I'm living in has a place where the tiled floor doesn't quite align with the wall that it meets, and I can't figure out why; somewhere, two things that ought to have been parallel just aren't. Bridges have been known to crack, cars break down for no good reason, your hamburger just doesn't taste right today. Aviators have pinned down the best solution to this, I think. A pilot is not expected to be perfect; he is expected to follow checklists. A preflight checklist. A departure checklist. A landing checklist. Everything that needs to be done right is mentioned on the list, and you just go through the list and make sure you've done everything. Interestingly enough, that approximately corresponds to unit testing (or maybe integration testing) - you design a suite of tests, and every time you do something, you make sure all the tests pass. Neither test suites nor checklists can prevent all problems - but they CAN prevent the same problems from cropping up again and again. (Which is kinda important when you're dealing with airliners carrying hundreds of people. They crash very rarely because the crew follow their checklists religiously, and when they do, there's an investigation that can result in new tests being added.) ChrisA From rustompmody at gmail.com Sun Nov 26 23:04:21 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 26 Nov 2017 20:04:21 -0800 (PST) Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> Message-ID: <105e5518-4e2f-44b1-a57b-4f818f44c41a@googlegroups.com> On Monday, November 27, 2017 at 9:08:42 AM UTC+5:30, Chris Angelico wrote: > On Mon, Nov 27, 2017 at 1:55 PM, Michael Torrie wrote: > > On 11/26/2017 07:11 AM, bartc wrote: > >>> You may argue that testing doesn't matter for his small game, written > >>> for his own education and amusement. The fact is that software in > >>> general is of abysmal quality across the boards, and promoting a habit > >>> of unit testing is good, even for trivial, home-grown stuff. > >> > >> I thought people were being hard on the OP. > > > > I wasn't being hard on the OP. My observation is about the state of > > *all* software. My software especially, your software, Microsoft's > > software. It all is of rather poor quality compared to the rigors of > > other industries like civil engineering, manufacturing, etc. > > Not all software is poor quality compared to all examples of those > industries. You'll find the equivalent of software bugs in a lot of > hardware situations; the difference with software is that we have 100% > perfect reproduction in the end-user products, so we call it a design > flaw instead of a production artifact. (How often do you buy a box of > something and find that a couple of them just break?) Even in > large-scale civil engineering projects, there are plenty of > stupidities. The house I'm living in has a place where the tiled floor > doesn't quite align with the wall that it meets, and I can't figure > out why; somewhere, two things that ought to have been parallel just > aren't. Bridges have been known to crack, cars break down for no good > reason, your hamburger just doesn't taste right today. > > Aviators have pinned down the best solution to this, I think. A pilot > is not expected to be perfect; he is expected to follow checklists. A > preflight checklist. A departure checklist. A landing checklist. > Everything that needs to be done right is mentioned on the list, and > you just go through the list and make sure you've done everything. And thats where the analogy breaks down. Presumably a 50 person short-flight and a 600-person transcontinental may have at least something in common in their pilot-checklists What common will you find in a multi-million line OS, a thousand line script and a student prime-numbers first-program? No I am not dissing on testing and TDD; just that universality? of computing devices is something that our civilization is nowhere near understanding, leave alone dealing with ? two programs can be more far apart than a bullock cart and a jet. And yet they are both programs ? Ive seen CS PhDs ask a student why a student didnt incorporate some error-checking into his compiler which amounted to solving the halting problem. More mundanely I see students have a hard time seeing their phones and their laptops as 'the same' From rosuav at gmail.com Mon Nov 27 00:41:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Mon, 27 Nov 2017 17:41:00 +1200 Subject: connect four (game) Message-ID: <624341068@f38.n261.z1.binkp.net> On Mon, Nov 27, 2017 at 3:04 PM, Rustom Mody wrote: >> Aviators have pinned down the best solution to this, I think. A pilot >> is not expected to be perfect; he is expected to follow checklists. A >> preflight checklist. A departure checklist. A landing checklist. >> Everything that needs to be done right is mentioned on the list, and >> you just go through the list and make sure you've done everything. > > And thats where the analogy breaks down. > Presumably a 50 person short-flight and a 600-person transcontinental may have > at least something in common in their pilot-checklists > What common will you find in a multi-million line OS, a thousand line script > and a student prime-numbers first-program? You locate a pure function. I can pretty much guarantee that the first two will have a number of them, and the third one may or may not, but almost certainly should. Pure functions are the easiest to unit-test. Then you build up from there. > No I am not dissing on testing and TDD; just that universality?1 of computing devices > is something that our civilization is nowhere near understanding, leave alone > dealing with ? ? two programs can be more far apart than a bullock cart and a jet. > And yet they are both programs ... so? > ?1 Ive seen CS PhDs ask a student why a student didnt incorporate some error-checking > into his compiler which amounted to solving the halting problem. > More mundanely I see students have a hard time seeing their phones and their > laptops as 'the same' Again: so? Testing methodologies don't require that. ChrisA From miki.tebeka at gmail.com Mon Nov 27 01:40:08 2017 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sun, 26 Nov 2017 22:40:08 -0800 (PST) Subject: I have anaconda, but Pycharm can't find it In-Reply-To: References: Message-ID: You need to set the Python interpreter for the project to be the Anaconda one. See https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html On Monday, November 27, 2017 at 1:56:58 AM UTC+2, C W wrote: > Hello all, > > I am a first time PyCharm user. I have Python 3 and Anaconda installed. > They work together on Sublime Text, but not on Pycharm. > > Pycharm tells me it cannot find modules numpy, matplotlib, etc. > > What should I do? I tried to set the interpreter environment, and a few > other options, none seem to work. > > This is the typical solution, but it does not work > https://stackoverflow.com/questions/35623776/import-numpy-on-pycharm > > Thanks, > > -Mike From rosuav at gmail.com Mon Nov 27 01:41:48 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Nov 2017 17:41:48 +1100 Subject: connect four (game) In-Reply-To: <105e5518-4e2f-44b1-a57b-4f818f44c41a@googlegroups.com> References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> <105e5518-4e2f-44b1-a57b-4f818f44c41a@googlegroups.com> Message-ID: On Mon, Nov 27, 2017 at 3:04 PM, Rustom Mody wrote: >> Aviators have pinned down the best solution to this, I think. A pilot >> is not expected to be perfect; he is expected to follow checklists. A >> preflight checklist. A departure checklist. A landing checklist. >> Everything that needs to be done right is mentioned on the list, and >> you just go through the list and make sure you've done everything. > > And thats where the analogy breaks down. > Presumably a 50 person short-flight and a 600-person transcontinental may have > at least something in common in their pilot-checklists > What common will you find in a multi-million line OS, a thousand line script > and a student prime-numbers first-program? You locate a pure function. I can pretty much guarantee that the first two will have a number of them, and the third one may or may not, but almost certainly should. Pure functions are the easiest to unit-test. Then you build up from there. > No I am not dissing on testing and TDD; just that universality? of computing devices > is something that our civilization is nowhere near understanding, leave alone > dealing with ? two programs can be more far apart than a bullock cart and a jet. > And yet they are both programs ... so? > ? Ive seen CS PhDs ask a student why a student didnt incorporate some error-checking > into his compiler which amounted to solving the halting problem. > More mundanely I see students have a hard time seeing their phones and their > laptops as 'the same' Again: so? Testing methodologies don't require that. ChrisA From bc at freeuk.com Mon Nov 27 01:57:00 2017 From: bc at freeuk.com (nospam.bartc) Date: Mon, 27 Nov 2017 18:57:00 +1200 Subject: connect four (game) References: <3718425985@f38.n261.z1.binkp.net> Message-ID: <2745088580@f38.n261.z1.binkp.net> On 27/11/2017 17:41, Chris Angelico wrote: > On Tue, Nov 28, 2017 at 2:14 AM, bartc wrote: >> JPEG uses lossy compression. The resulting recovered data is an >> approximation of the original. > > Ah but it is a perfect representation of the JPEG stream. Any given > compressed stream must always decode to the same output. The lossiness > is on the ENcoding, not the DEcoding. You make it sound as bad as currency calculations where different software must produce results that always match to the nearest cent. We're talking about perhaps +1 or -1 difference in the least significant bit of one channel of one pixels. If the calculation is consistent, then you will not know anything is amiss. By +1 or -1, I mean compared with the same jpeg converted by independent means. I also passed the same jpeg through another C program (not mine) using its own algorithms. There some pixels varied by up to +/- 9 from the others (looking at the first 512 bytes of the conversion to ppm). Here's my test image: https://github.com/bartg/langs/blob/master/card2.jpg (nothing naughty). Tell me what the definitive values of the pixels in this part of the image should be (I believe this corresponds to roughly the leftmost 180 pixels of the top line; there are two million pixels in all). And tell me WHY you think those are the definitive ones. Bear in mind also that this is not intended to be the world's most perfect software. But it does do a good enough job. And the other two Python versions I have, at the minute don't work at all. -- bartc From p.f.moore at gmail.com Mon Nov 27 02:05:00 2017 From: p.f.moore at gmail.com (nospam.Paul Moore) Date: Mon, 27 Nov 2017 19:05:00 +1200 Subject: Increasing the diversity of people who write Python (was: Message-ID: <937102950@f38.n261.z1.binkp.net> On 27 November 2017 at 18:13, Skip Montanaro wrote: >> If you have a Windows key, you can assign it to be >> the Compose key. > > Would this be true on a machine running Windows? My work environment > has me developing on Linux, with a Windows desktop. It's not clear to > me that any sort of xmodmap shennanigans would work. Won't Windows > itself always gobble up that key? Programs can access the Windows key. IIRC, there is a utility that provides compose-key functionality on Windows. I can't recall the name right now and it's on my other PC, not this one, but I'll try to remember to post the name tomorrow... Paul From rosuav at gmail.com Mon Nov 27 04:10:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Mon, 27 Nov 2017 21:10:00 +1200 Subject: connect four (game) Message-ID: <2963061171@f38.n261.z1.binkp.net> On Mon, Nov 27, 2017 at 9:01 PM, wrote: > On Sunday, November 26, 2017 at 7:09:25 PM UTC-8, Michael Torrie wrote: > >> So you are using this Infinity class as a sentinel value of some kind? >> Representing game state? There may be an easier way than a full on >> custom type. Sometimes just a sentinel object is sufficient. Or an >> enumeration. > > they're not sentinels; they're the maximum and minimum of the extended real numbers; the point is that, no matter how boards are evaluated (which is, of course, subject to change), a won game is always the most valuable and a lost game is always the least valuable; ordinary real numbers could be used for the purpose, but in that case i would have to figure out the maximum and minimum of the heuristic values the script assigns and then add/subtract one (for example) to get the value of a won/lost game > Or you could use the floating-point values for positive and negative infinity, which already compare as you need with all integers and floats. But that's up to you. ChrisA From namenobodywants at gmail.com Mon Nov 27 05:01:48 2017 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Mon, 27 Nov 2017 02:01:48 -0800 (PST) Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <35191dce-b751-42d1-ac87-b25c648fd95c@googlegroups.com> Message-ID: <44a75ef3-684e-48ea-8349-9afcb10c0f7d@googlegroups.com> On Sunday, November 26, 2017 at 7:09:25 PM UTC-8, Michael Torrie wrote: > So you are using this Infinity class as a sentinel value of some kind? > Representing game state? There may be an easier way than a full on > custom type. Sometimes just a sentinel object is sufficient. Or an > enumeration. they're not sentinels; they're the maximum and minimum of the extended real numbers; the point is that, no matter how boards are evaluated (which is, of course, subject to change), a won game is always the most valuable and a lost game is always the least valuable; ordinary real numbers could be used for the purpose, but in that case i would have to figure out the maximum and minimum of the heuristic values the script assigns and then add/subtract one (for example) to get the value of a won/lost game peace stm From rosuav at gmail.com Mon Nov 27 05:10:24 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Nov 2017 21:10:24 +1100 Subject: connect four (game) In-Reply-To: <44a75ef3-684e-48ea-8349-9afcb10c0f7d@googlegroups.com> References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <35191dce-b751-42d1-ac87-b25c648fd95c@googlegroups.com> <44a75ef3-684e-48ea-8349-9afcb10c0f7d@googlegroups.com> Message-ID: On Mon, Nov 27, 2017 at 9:01 PM, wrote: > On Sunday, November 26, 2017 at 7:09:25 PM UTC-8, Michael Torrie wrote: > >> So you are using this Infinity class as a sentinel value of some kind? >> Representing game state? There may be an easier way than a full on >> custom type. Sometimes just a sentinel object is sufficient. Or an >> enumeration. > > they're not sentinels; they're the maximum and minimum of the extended real numbers; the point is that, no matter how boards are evaluated (which is, of course, subject to change), a won game is always the most valuable and a lost game is always the least valuable; ordinary real numbers could be used for the purpose, but in that case i would have to figure out the maximum and minimum of the heuristic values the script assigns and then add/subtract one (for example) to get the value of a won/lost game > Or you could use the floating-point values for positive and negative infinity, which already compare as you need with all integers and floats. But that's up to you. ChrisA From antoon.pardon at vub.be Mon Nov 27 05:11:37 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 27 Nov 2017 11:11:37 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: <4d9a590e-58a1-f84c-9f16-9471ebb60c4f@vub.be> Op 23-11-17 om 19:42 schreef Mikhail V: > Chris A wrote: > >>> On Fri, Nov 24, 2017 at 1:10 AM, Mikhail V wrote: >>> >>>> Chris A wrote: >>>> >>>> Fortunately for the world, you're not the one who decided which >>>> characters were permitted in Python identifiers. The ability to use >>>> non-English words for function/variable names is of huge value; the >>>> ability to use a hyphen is of some value, but not nearly as much. >>> Fortunately for the world we have Chris A. Who knows what is >>> fortunate and of huge values. >>> So is there any real world projects example of usage of non-latin scripts >>> in identifiers? Or is it still only a plan for the new world? > >> Yes, I've used them personally. And I know other people who have. > > Oh, I though it would be more impressive showcase for 'huge value'. > If we drop the benefit of the bare fact that you can do it, or you just > don't know English, how would describe the practical benefit? > If you don't know english, then programming at all will be just too hard. > (or one must define a new whole language specially for some local script) Well maybe the value is not huge, but I really appreciate the possibility. Being able to write something like below, makes things a lot more clear for me. Po = Pc + R * Vec(cos(?o), sin(?o)) Pe = Pc + R * Vec(cos(?e), sin(?e)) ?? = ?e - ?o ?P = Pe - Po -- Antoon Pardon. From bc at freeuk.com Mon Nov 27 06:38:24 2017 From: bc at freeuk.com (bartc) Date: Mon, 27 Nov 2017 11:38:24 +0000 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> <3e61c073-1bc1-1e87-0abe-952ff23fcf19@gmail.com> Message-ID: On 27/11/2017 03:04, Michael Torrie wrote: > On 11/26/2017 08:39 AM, bartc wrote: >> The problem was traced to two lines that were in the wrong order (in the >> original program). I can't see how unit tests can have helped in any way >> at all, and it would probably have taken much longer. > > What makes you think that? Surely other decoders were doing the right > thing and you could compare your output against theirs? JPEGs may be > lossy but the path through the decoder should be deterministic. > > Or even if every decoder is slightly unique, at least yours should > output self-consistent data. The original used some floating point code, I changed that to use integer code (eg a combination of multiplying and shifting; it make a difference on compiled version, perhaps not so much in .py). But also (IIRC) there was a difference in taking the remainder of negative integer division, where different compilers may round up or down. So there can easily be differences when compared at the binary level, but which shouldn't be noticeable with the human eye. (https://pastebin.com/P7V1Bvkk https://pastebin.com/raw/P7V1Bvkk raw version with no ads, or colour) In other words, once you know you fixed > the chroma problem, you can use that jpeg as a unit test to make sure > future big fixes and enhancements don't break something else. > Regression testing is very important. Many times I've fixed a bug, only > to introduce new ones that broke formerly correct behavior. > > Anyway, unit testing is certainly a challenging concept, and I'm no more > good at it than you are. Some people are obsessed with having unit tests. Others are the same about using debuggers, especially in compiled code. I've never used either, but I do alright. Some of the stuff I do is unsuitable for those for technical reasons, but also some of the problems I've come across just don't fit into such patterns. People should use what works best for them, unless they're in a team where the have to use certain tools and working methods. -- bartc From namenobodywants at gmail.com Mon Nov 27 07:43:07 2017 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Mon, 27 Nov 2017 04:43:07 -0800 (PST) Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <35191dce-b751-42d1-ac87-b25c648fd95c@googlegroups.com> <44a75ef3-684e-48ea-8349-9afcb10c0f7d@googlegroups.com> Message-ID: On Monday, November 27, 2017 at 2:10:56 AM UTC-8, Chris Angelico wrote: > Or you could use the floating-point values for positive and negative > infinity perfecto! thank you! peace stm From gengyangcai at gmail.com Mon Nov 27 07:54:21 2017 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 27 Nov 2017 04:54:21 -0800 (PST) Subject: While, If, Count Statements Message-ID: Input : count = 0 if count < 5: print "Hello, I am an if statement and count is", count while count < 10: print "Hello, I am a while and count is", count count += 1 Output : Hello, I am an if statement and count is 0 Hello, I am a while and count is 0 Hello, I am a while and count is 1 Hello, I am a while and count is 2 Hello, I am a while and count is 3 Hello, I am a while and count is 4 Hello, I am a while and count is 5 Hello, I am a while and count is 6 Hello, I am a while and count is 7 Hello, I am a while and count is 8 Hello, I am a while and count is 9 The above input gives the output below. Why isn't the output instead : Hello, I am an if statement and count is 0 Hello, I am a while and count is 0 Hello, I am an if statement and count is 1 Hello, I am a while and count is 1 Hello, I am an if statement and count is 2 Hello, I am a while and count is 2 Hello, I am an if statement and count is 3 Hello, I am a while and count is 3 Hello, I am an if statement and count is 4 Hello, I am a while and count is 4 Hello, I am a while and count is 5 Hello, I am a while and count is 6 Hello, I am a while and count is 7 Hello, I am a while and count is 8 Hello, I am a while and count is 9 From rosuav at gmail.com Mon Nov 27 07:57:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Tue, 28 Nov 2017 00:57:00 +1200 Subject: connect four (game) Message-ID: <3513593611@f38.n261.z1.binkp.net> On Mon, Nov 27, 2017 at 10:38 PM, bartc wrote: > On 27/11/2017 03:04, Michael Torrie wrote: >> >> On 11/26/2017 08:39 AM, bartc wrote: >>> >>> The problem was traced to two lines that were in the wrong order (in the >>> original program). I can't see how unit tests can have helped in any way >>> at all, and it would probably have taken much longer. >> >> >> What makes you think that? Surely other decoders were doing the right >> thing and you could compare your output against theirs? JPEGs may be >> lossy but the path through the decoder should be deterministic. >> >> Or even if every decoder is slightly unique, at least yours should >> output self-consistent data. > > > The original used some floating point code, I changed that to use integer > code (eg a combination of multiplying and shifting; it make a difference on > compiled version, perhaps not so much in .py). The JPEG spec says what a given file should decode to. So you can use a reference implementation to confirm that your code is correctly decoding. Even if you might legitimately encode the same image in different ways, each of those encoded files should decode to one exact image, regardless of which decoder is used. Your decoder was straight-up buggy, and tests would have proven this. > But also (IIRC) there was a difference in taking the remainder of negative > integer division, where different compilers may round up or down. In every compiler, interpreter, and CPU that I've ever used, the remainder has been well-defined. In what situation was it ill-defined, such that different compilers could do different things? > Some people are obsessed with having unit tests. Others are the same about > using debuggers, especially in compiled code. > > I've never used either, but I do alright. Some of the stuff I do is > unsuitable for those for technical reasons, but also some of the problems > I've come across just don't fit into such patterns. > > People should use what works best for them, unless they're in a team where > the have to use certain tools and working methods. Yep, and if "producing buggy code that fails to comply with the spec" is what works best for you, then please don't tell us that we're advocating the wrong thing. Testing might not fix everything, but it does help, especially in those easy cases where you're working with a pure function that has a single correct output for a given input. Which, if I'm not misunderstanding the specs, is the case for pretty much every compression scheme in current use - including JPEG. For myself, I don't write as many tests as I should. But I'm not going to go around telling people that tests are a waste of time. ChrisA From jaya.birdar at gmail.com Mon Nov 27 08:13:24 2017 From: jaya.birdar at gmail.com (jaya.birdar at gmail.com) Date: Mon, 27 Nov 2017 05:13:24 -0800 (PST) Subject: I have framework on python with pyunit, facing below issue while executing test case Message-ID: <8de2d624-713b-4760-9cb1-471f3b395f6c@googlegroups.com> Please let me know anyone aware about the issue Traceback (most recent call last): File "testrunner.py", line 447, in testrunner_obj.main() File "testrunner.py", line 433, in main self.result() File "testrunner.py", line 310, in result result = runner.run(self.suite) File "/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 720, in run test(result) File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ return self.run(*args, **kwds) File "/usr/lib/python2.7/unittest/suite.py", line 108, in run test(result) File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ return self.run(*args, **kwds) File "/usr/lib/python2.7/unittest/suite.py", line 108, in run test(result) File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ return self.run(*args, **kwds) File "/usr/lib/python2.7/unittest/suite.py", line 100, in run self._handleClassSetUp(test, result) File "/usr/lib/python2.7/unittest/suite.py", line 153, in _handleClassSetUp self._addClassOrModuleLevelException(result, e, errorName) File "/usr/lib/python2.7/unittest/suite.py", line 198, in _addClassOrModuleLevelException result.addError(error, sys.exc_info()) File ?/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 633, in addError output = self.complete_output() File ?/autoPyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 591, in complete_output return self.outputBuffer.getvalue() AttributeError: '_TestResult' object has no attribute 'outputBuffer' From rustompmody at gmail.com Mon Nov 27 08:18:46 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Nov 2017 05:18:46 -0800 (PST) Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: <4d9a590e-58a1-f84c-9f16-9471ebb60c4f@vub.be> Message-ID: <68cf377d-edaf-4c11-8820-21bf84dc6e3f@googlegroups.com> On Monday, November 27, 2017 at 3:43:20 PM UTC+5:30, Antoon Pardon wrote: > Op 23-11-17 om 19:42 schreef Mikhail V: > > Chris A wrote: > > > >>> On Fri, Nov 24, 2017 at 1:10 AM, Mikhail V wrote: > >>> > >>>> Chris A wrote: > >>>> > >>>> Fortunately for the world, you're not the one who decided which > >>>> characters were permitted in Python identifiers. The ability to use > >>>> non-English words for function/variable names is of huge value; the > >>>> ability to use a hyphen is of some value, but not nearly as much. > >>> Fortunately for the world we have Chris A. Who knows what is > >>> fortunate and of huge values. > >>> So is there any real world projects example of usage of non-latin scripts > >>> in identifiers? Or is it still only a plan for the new world? > > > >> Yes, I've used them personally. And I know other people who have. > > > > Oh, I though it would be more impressive showcase for 'huge value'. > > If we drop the benefit of the bare fact that you can do it, or you just > > don't know English, how would describe the practical benefit? > > If you don't know english, then programming at all will be just too hard. > > (or one must define a new whole language specially for some local script) > > Well maybe the value is not huge, but I really appreciate the possibility. > Being able to write something like below, makes things a lot more clear > for me. > > Po = Pc + R * Vec(cos(?o), sin(?o)) > Pe = Pc + R * Vec(cos(?e), sin(?e)) > ?? = ?e - ?o > ?P = Pe - Po Yeah? This is important And Ive tried to elaborate such suggestions here http://blog.languager.org/2014/04/unicoded-python.html [includes some of your suggestions!] I should emphasize that the details there range between straightforward and facetious. The general sense of going beyond ASCII is not facetious at all In fact its ridiculous in the reverse direction: just as FORTRAN and COBOL believed that programming IN ALL UPPERCASE was somehow kosher, likewise a 2017 language believing that sticking to ASCII is sound is faintly ridiculous. But that brings me to the opposite point: I feel its important to distinguish ?parochial/sectarian unicode? from ?universal unicode?. More on the distinction http://blog.languager.org/2015/03/whimsical-unicode.html More on the universal aspect: http://blog.languager.org/2015/02/universal-unicode.html Having said that I should be honest to mention that I saw your post first on my phone where the ? showed but the ? showed as a rectangle something like ? I suspect that ? OTOH would have worked? dunno So yes, there can be non-trivial logistic problems going beyond ASCII As there are problems with errant mail-clients transmitting indentation-sensitive languages and so on! From ned at nedbatchelder.com Mon Nov 27 08:25:52 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 27 Nov 2017 08:25:52 -0500 Subject: I have framework on python with pyunit, facing below issue while executing test case In-Reply-To: <8de2d624-713b-4760-9cb1-471f3b395f6c@googlegroups.com> References: <8de2d624-713b-4760-9cb1-471f3b395f6c@googlegroups.com> Message-ID: <60dda82a-48ce-0dd1-50c7-4786a21a3db1@nedbatchelder.com> On 11/27/17 8:13 AM, jaya.birdar at gmail.com wrote: > Please let me know anyone aware about the issue > > > Traceback (most recent call last): > File "testrunner.py", line 447, in > testrunner_obj.main() > File "testrunner.py", line 433, in main > self.result() > File "testrunner.py", line 310, in result > result = runner.run(self.suite) > File "/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 720, in run > test(result) > File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ > return self.run(*args, **kwds) > File "/usr/lib/python2.7/unittest/suite.py", line 108, in run > test(result) > File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ > return self.run(*args, **kwds) > File "/usr/lib/python2.7/unittest/suite.py", line 108, in run > test(result) > File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ > return self.run(*args, **kwds) > File "/usr/lib/python2.7/unittest/suite.py", line 100, in run > self._handleClassSetUp(test, result) > File "/usr/lib/python2.7/unittest/suite.py", line 153, in _handleClassSetUp > self._addClassOrModuleLevelException(result, e, errorName) > File "/usr/lib/python2.7/unittest/suite.py", line 198, in _addClassOrModuleLevelException > result.addError(error, sys.exc_info()) > File ?/auto/PyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 633, in addError > output = self.complete_output() > File ?/autoPyUnit/PyUnit-0.3/utils/framework/HTMLTestRunner.py", line 591, in complete_output > return self.outputBuffer.getvalue() > AttributeError: '_TestResult' object has no attribute 'outputBuffer' It's hard to say without seeing all your code, but I notice PyUnit 0.3 in your traceback.? If that's the PyUnit I think it is, PyUnit 1.4.1 was released 16(!) years ago, and has been in the standard library as unittest since version 2.1.? Are you running ancient versions of your test infrastructure? --Ned. From bc at freeuk.com Mon Nov 27 08:26:29 2017 From: bc at freeuk.com (bartc) Date: Mon, 27 Nov 2017 13:26:29 +0000 Subject: While, If, Count Statements In-Reply-To: References: Message-ID: <6oUSB.134377$E01.43133@fx09.am4> On 27/11/2017 12:54, Cai Gengyang wrote: > > Input : > > count = 0 > > if count < 5: > print "Hello, I am an if statement and count is", count > > while count < 10: > print "Hello, I am a while and count is", count > count += 1 > > Output : > > Hello, I am an if statement and count is 0 > Hello, I am a while and count is 0 > Hello, I am a while and count is 1 > Hello, I am a while and count is 2 > Hello, I am a while and count is 3 > Hello, I am a while and count is 4 > Hello, I am a while and count is 5 > Hello, I am a while and count is 6 > Hello, I am a while and count is 7 > Hello, I am a while and count is 8 > Hello, I am a while and count is 9 > > The above input gives the output below. Why isn't the output instead : > > Hello, I am an if statement and count is 0 > Hello, I am a while and count is 0 > Hello, I am an if statement and count is 1 > Hello, I am a while and count is 1 > Hello, I am an if statement and count is 2 > Hello, I am a while and count is 2 > Hello, I am an if statement and count is 3 > Hello, I am a while and count is 3 > Hello, I am an if statement and count is 4 > Hello, I am a while and count is 4 > Hello, I am a while and count is 5 > Hello, I am a while and count is 6 > Hello, I am a while and count is 7 > Hello, I am a while and count is 8 > Hello, I am a while and count is 9 Because the if-statement is only executed once, then it does the loop. Try: count = 0 while count < 10: if count < 5: print "Hello, I am an if statement and count is", count print "Hello, I am a while and count is", count count += 1 From rustompmody at gmail.com Mon Nov 27 08:35:09 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Nov 2017 05:35:09 -0800 (PST) Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> <105e5518-4e2f-44b1-a57b-4f818f44c41a@googlegroups.com> Message-ID: <6c0aeb1d-8751-4c27-be4d-dd2d27ebbc67@googlegroups.com> On Monday, November 27, 2017 at 12:12:24 PM UTC+5:30, Chris Angelico wrote: > On Mon, Nov 27, 2017 at 3:04 PM, Rustom Mody wrote: > >> Aviators have pinned down the best solution to this, I think. A pilot > >> is not expected to be perfect; he is expected to follow checklists. A > >> preflight checklist. A departure checklist. A landing checklist. > >> Everything that needs to be done right is mentioned on the list, and > >> you just go through the list and make sure you've done everything. > > > > And thats where the analogy breaks down. > > Presumably a 50 person short-flight and a 600-person transcontinental may have > > at least something in common in their pilot-checklists > > What common will you find in a multi-million line OS, a thousand line script > > and a student prime-numbers first-program? > > You locate a pure function. I can pretty much guarantee that the first > two will have a number of them, and the third one may or may not, but > almost certainly should. Pure functions are the easiest to unit-test. > Then you build up from there. > > > No I am not dissing on testing and TDD; just that universality? of computing devices > > is something that our civilization is nowhere near understanding, leave alone > > dealing with ? two programs can be more far apart than a bullock cart and a jet. > > And yet they are both programs > > ... so? I know how to drive a car? and various two-wheelers. I not so sure of a bus/truck? I suppose I could get one from here to there at a pinch? without killing someone? though not quite sure of that! Doesn't translate into knowing how to 'drive' planes or bullock-carts gcc is tested with dejagnu. Do you imagine that knowing python's unittest or nose directly translates into dejagnu expertise? And even if we stay with industry-strength programs ? gcc, linux-kernel, CPython, KDE ? do you imagine that testing one helps in testing the other? I doubt it (though I am hardly an expert with testing frameworks) Once again let me end by saying that testing and TDD are good ideas And it would be nice if there was more of it in/for python [See http://osherove.com/tdd-kata-1/ one of the first hits that google gives (me) for TDD python, and you find the python example actually shows Ruby!] From rosuav at gmail.com Mon Nov 27 08:37:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Tue, 28 Nov 2017 01:37:00 +1200 Subject: Increasing the diversity of people who write Python (was: Message-ID: <2430088877@f38.n261.z1.binkp.net> On Tue, Nov 28, 2017 at 1:25 AM, Rustom Mody wrote: > You could go one step more sophisticated and use TeX-input method > (C-x RET C-\) > After which \'e will collapse as ?C > ? ?Yeah ok but how the ^)*^$# am I to remember the mantra \'e?!? ? you may ask > True? | So as you rightly do, > - pick it up from google > - put emacs into tex input mode > - paste from google into emacs > - place point on the new char and type C-u C-x = > Among other things emacs will helpfully inform you (among other things) > to input: type "\'{e}" or "\'e" with TeX input method Which is closely related to the Compose key input method that I use. First, you assign a key on your keyboard to be Compose (at least on all my systems, there isn't one by default); I use the key between left Ctrl and left Alt. Then you have certain key sequences available that involve holding Compose and pressing something, and then pressing something else. In the same way that you might press Ctrl-X, Q to do something, you could press Compose-T, M to produce ???. Sounds complicated, but it's not. It's right enough. All your accented letters can be created with Compose-accent, letter - eg Compose-apostrophe, e => ?C, or Compose-backtick, a => ? . Not sure what systems that's supported on. I use Debian GNU/Linux with Xfce; I believe the Compose key handling is all done by X11, so it should be fairly widely available at least on Linux-derived systems. ChrisA From breamoreboy at gmail.com Mon Nov 27 08:45:48 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Mon, 27 Nov 2017 05:45:48 -0800 (PST) Subject: nospam ** infinity? In-Reply-To: References: Message-ID: On Monday, November 27, 2017 at 1:19:38 AM UTC, Chris Angelico wrote: > On Mon, Nov 27, 2017 at 12:14 PM, Skip Montanaro wrote: > >> There seems to be a gateway loop of some sort going on. > >> I'm seeing multiple versions of the same posts in > >> comp.lang.python with different numbers of "nospam"s > >> prepended to the email address. > > > > This is the second thread about this. I was thinking it might be > > related to recent changes to the gate_news process on mail.python.org, > > but this fingerprint looks nothing like what gate_news does. > > > > Looking at a somewhat long-ish thread: > > > > https://groups.google.com/d/topic/comp.lang.python/YoxLtkzlt_o/discussion > > > > I see a couple posts from Chris Angelico, only some of which have a > > "nospam" preface. It would seem that someone was trying to mark > > certain posters as "not spammy," (I'm sure Chris is flattered) and > > somehow posts with that private marking leaked out of the user's > > system starting in the past twelve hours or so. > > > > Newsreader configuration problem? > > More likely, someone was trying to obscure the email addresses, but > managed to tag my name instead. Definitely looks like some sort of > automation failure. The only question is, whose? If it's not from > gate_news, there's someone here on the list/ng that is (probably > accidentally) reposting everything. > > ChrisA I suspect that it's a big own goal as even stuff from the RUE is getting through. -- Kindest regards. Mark Lawrence From rustompmody at gmail.com Mon Nov 27 08:52:07 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Nov 2017 05:52:07 -0800 (PST) Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: <68cf377d-edaf-4c11-8820-21bf84dc6e3f@googlegroups.com> References: <4d9a590e-58a1-f84c-9f16-9471ebb60c4f@vub.be> <68cf377d-edaf-4c11-8820-21bf84dc6e3f@googlegroups.com> Message-ID: On Monday, November 27, 2017 at 6:48:56 PM UTC+5:30, Rustom Mody wrote: > Having said that I should be honest to mention that I saw your post first on > my phone where the ? showed but the ? showed as a rectangle something like ? > > I suspect that ? OTOH would have worked? dunno Yeah ? shows whereas ? doesn't (on my phone) And ? does show but much squatter than the replacement char the phone shows when it cant display a char From rosuav at gmail.com Mon Nov 27 08:57:57 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Nov 2017 00:57:57 +1100 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> <3e61c073-1bc1-1e87-0abe-952ff23fcf19@gmail.com> Message-ID: On Mon, Nov 27, 2017 at 10:38 PM, bartc wrote: > On 27/11/2017 03:04, Michael Torrie wrote: >> >> On 11/26/2017 08:39 AM, bartc wrote: >>> >>> The problem was traced to two lines that were in the wrong order (in the >>> original program). I can't see how unit tests can have helped in any way >>> at all, and it would probably have taken much longer. >> >> >> What makes you think that? Surely other decoders were doing the right >> thing and you could compare your output against theirs? JPEGs may be >> lossy but the path through the decoder should be deterministic. >> >> Or even if every decoder is slightly unique, at least yours should >> output self-consistent data. > > > The original used some floating point code, I changed that to use integer > code (eg a combination of multiplying and shifting; it make a difference on > compiled version, perhaps not so much in .py). The JPEG spec says what a given file should decode to. So you can use a reference implementation to confirm that your code is correctly decoding. Even if you might legitimately encode the same image in different ways, each of those encoded files should decode to one exact image, regardless of which decoder is used. Your decoder was straight-up buggy, and tests would have proven this. > But also (IIRC) there was a difference in taking the remainder of negative > integer division, where different compilers may round up or down. In every compiler, interpreter, and CPU that I've ever used, the remainder has been well-defined. In what situation was it ill-defined, such that different compilers could do different things? > Some people are obsessed with having unit tests. Others are the same about > using debuggers, especially in compiled code. > > I've never used either, but I do alright. Some of the stuff I do is > unsuitable for those for technical reasons, but also some of the problems > I've come across just don't fit into such patterns. > > People should use what works best for them, unless they're in a team where > the have to use certain tools and working methods. Yep, and if "producing buggy code that fails to comply with the spec" is what works best for you, then please don't tell us that we're advocating the wrong thing. Testing might not fix everything, but it does help, especially in those easy cases where you're working with a pure function that has a single correct output for a given input. Which, if I'm not misunderstanding the specs, is the case for pretty much every compression scheme in current use - including JPEG. For myself, I don't write as many tests as I should. But I'm not going to go around telling people that tests are a waste of time. ChrisA From rustompmody at gmail.com Mon Nov 27 09:25:10 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Nov 2017 06:25:10 -0800 (PST) Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> Message-ID: <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> On Friday, November 24, 2017 at 10:11:24 PM UTC+5:30, Skip Montanaro wrote: > > Because if I already can't understand the words, it will be more useful > > to me to be able to type them reliably at a keyboard, for replication, > > search, discussion with others about the code, etc. > > I am probably not alone in my Americo-centric world where I can't even > easily type accented Latin-1 characters. I happen to be using Linux as > I type this, but type at a Windows keyboard at work (ugh) and have > long been a user of Macs (still have one or two at home). Might the > problem be further multiplied by the number of different ways I have > of entering text? Would Emacs running on Linux, but displaying on > Windows be different than Chrome running directly on Linux? I strongly suspect that any recent emacs will have M-x insert-char (earlier it was called ucs-insert) default bound C-x 8 RET (yeah thats clunky) which will accept at the minibuffer input At which point the hex for ? which is e9 can be entered ? yeah its unreasonable to expect to remember that! Its more reasonable to remember that that is an e acute; And e itself is a latin lower case letter All of which becomes entering (in the minibuffer) LATIN SMALL LETTER E ACUTE - upper case not required; emacs will upcase it for you - And will also provide some tab/star expansion help ie *letter e acuteTAB expands to LATIN *L LETTER E ACUTE Further TAB-prodding will give you these choices LATIN CAPITAL LETTER E ACUTE (?) LATIN CAPITAL LETTER E WITH ACUTE (?) LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND ACUTE (?) LATIN CAPITAL LETTER E WITH MACRON AND ACUTE (?) LATIN SMALL LETTER E ACUTE (?) LATIN SMALL LETTER E WITH ACUTE (?) LATIN SMALL LETTER E WITH CIRCUMFLEX AND ACUTE (?) LATIN SMALL LETTER E WITH MACRON AND ACUTE (?) You could go one step more sophisticated and use TeX-input method (C-x RET C-\) After which \'e will collapse as ? ?Yeah ok but how the ^)*^$# am I to remember the mantra \'e?!? you may ask True? So as you rightly do, - pick it up from google - put emacs into tex input mode - paste from google into emacs - place point on the new char and type C-u C-x = Among other things emacs will helpfully inform you (among other things) to input: type "\'{e}" or "\'e" with TeX input method From rosuav at gmail.com Mon Nov 27 09:37:12 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Nov 2017 01:37:12 +1100 Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> Message-ID: On Tue, Nov 28, 2017 at 1:25 AM, Rustom Mody wrote: > You could go one step more sophisticated and use TeX-input method > (C-x RET C-\) > After which \'e will collapse as ? > ?Yeah ok but how the ^)*^$# am I to remember the mantra \'e?!? you may ask > True? So as you rightly do, > - pick it up from google > - put emacs into tex input mode > - paste from google into emacs > - place point on the new char and type C-u C-x = > Among other things emacs will helpfully inform you (among other things) > to input: type "\'{e}" or "\'e" with TeX input method Which is closely related to the Compose key input method that I use. First, you assign a key on your keyboard to be Compose (at least on all my systems, there isn't one by default); I use the key between left Ctrl and left Alt. Then you have certain key sequences available that involve holding Compose and pressing something, and then pressing something else. In the same way that you might press Ctrl-X, Q to do something, you could press Compose-T, M to produce ?. Sounds complicated, but it's not. It's right enough. All your accented letters can be created with Compose-accent, letter - eg Compose-apostrophe, e => ?, or Compose-backtick, a => ?. Not sure what systems that's supported on. I use Debian GNU/Linux with Xfce; I believe the Compose key handling is all done by X11, so it should be fairly widely available at least on Linux-derived systems. ChrisA From ian.g.kelly at gmail.com Mon Nov 27 09:51:57 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 27 Nov 2017 07:51:57 -0700 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> <3e61c073-1bc1-1e87-0abe-952ff23fcf19@gmail.com> Message-ID: On Nov 27, 2017 7:08 AM, "Chris Angelico" wrote: In every compiler, interpreter, and CPU that I've ever used, the remainder has been well-defined. In what situation was it ill-defined, such that different compilers could do different things? In C89 the result of integer division and modulo with negative operands were implementation-defined -- the result of division could be either floored or truncated, and the modulo result also varied to match. This was fixed in C99, with division results always being truncated (whereas Python uses the floor). From rustompmody at gmail.com Mon Nov 27 09:55:29 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Nov 2017 06:55:29 -0800 (PST) Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> Message-ID: <5eac0c8f-07f8-4a84-bf6f-b04db1b101c9@googlegroups.com> On Monday, November 27, 2017 at 8:07:47 PM UTC+5:30, Chris Angelico wrote: > On Tue, Nov 28, 2017 at 1:25 AM, Rustom Mody wrote: > > You could go one step more sophisticated and use TeX-input method > > (C-x RET C-\) > > After which \'e will collapse as ? > > ?Yeah ok but how the ^)*^$# am I to remember the mantra \'e?!? you may ask > > True? So as you rightly do, > > - pick it up from google > > - put emacs into tex input mode > > - paste from google into emacs > > - place point on the new char and type C-u C-x = > > Among other things emacs will helpfully inform you (among other things) > > to input: type "\'{e}" or "\'e" with TeX input method > > Which is closely related to the Compose key input method that I use. > First, you assign a key on your keyboard to be Compose (at least on > all my systems, there isn't one by default); I use the key between > left Ctrl and left Alt. Ha Ha So you wont speak the unspeakable??!? I also have my compose set (to Capslock) And I entered those chars above with C?? and C!! where C is Capslock I most frequently use that for ? (C=>) ? (C->) ? (C^1) ? (C_1) etc One can find other goodies at /usr/share/X11/locale/en_US.UTF-8/Compose I didn't start with mentioning that to Skip because his basic requirement (as I got it) was that - input method should be OS-neutral - emacs can be assumed And so the only OS-non-neutrality that I am aware of is that sometimes Alt works as Meta (gui-emacsen) and sometimes not terminal/text emacsen (typically, though I believe some ppl successfully tweak this also) And so M-x can mean Alt-x (chord) or ESC-x (sequence) and a few such anomalies But beyond that emacsen should be same for all OSes (modulo versions) From bc at freeuk.com Mon Nov 27 10:14:10 2017 From: bc at freeuk.com (bartc) Date: Mon, 27 Nov 2017 15:14:10 +0000 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> <3e61c073-1bc1-1e87-0abe-952ff23fcf19@gmail.com> Message-ID: <4ZVSB.55738$321.38548@fx12.am4> On 27/11/2017 13:57, Chris Angelico wrote: > On Mon, Nov 27, 2017 at 10:38 PM, bartc wrote: > Your decoder was straight-up buggy, and tests would have proven this. I created my Python version after the abysmal results from other Python decoders I tried which didn't work at all, gave the wrong results, didn't support other subsampling ratios, or hung. Or if they did work, they took forever. I suggest you compare my version with some of those. The first time I looked at a jpeg decoder, it was a massive C library of about 30 different source files. Sometimes you need to take short-cuts. My version generates images which are indistinguishable from those derived via other decoders. >> But also (IIRC) there was a difference in taking the remainder of negative >> integer division, where different compilers may round up or down. > > In every compiler, interpreter, and CPU that I've ever used, the > remainder has been well-defined. In what situation was it ill-defined, > such that different compilers could do different things? In certain C implementations, rounding the results of integer division could go up or down. This is a post from comp.lang.c from 2008: "Nate Eldredge" wrote in message news:8663mf144q.fsf at vulcan.lan... > Mr. Burns writes: > >> Hi group, >> >> suppose I have a grid of cells of size (R,C) and coordinates >> (0..R-1,0..C-1) and >> I'm translating pixel coordinates to grid coordinates by dividing by cell >> size. >> >> Now, all works well for values >= 0, but for values < 0 I'm getting >> inconsistent results. >> >> On one platform, division of negative numbers rounds towards negative >> infinity, i.e., (-1 / 10) gives -1. (this is what I want) >> >> On another platform (solaris), rounding is towards zero, and (-1 / 10) is >> 0! >> >> All numbers are plain ints. > > The C99 standard specifies truncation towards zero (like your Solaris > compiler). However, the previous C90 standard left it up to the > implementation to decide which way to round when one of the operands is > negative, as long as it is consistent with the % operator. Exactly what the problem was with my jpeg program where a number from my language and compiler ended up as 187, but on C compiled with gcc as 186, I can't remember. I /think/ it was to do with such rounding. This is not a big deal: one program ends up with a pixel value of 186 (in a range of 0 to 255), and another with 187. The true value in the original photo may have required a value somewhere between 186 and 187, so both values could be considered wrong! > Which, if I'm not misunderstanding the specs, is the case for pretty > much every compression scheme in current use - including JPEG. JPEG uses lossy compression. The resulting recovered data is an approximation of the original. > For myself, I don't write as many tests as I should. But I'm not going > to go around telling people that tests are a waste of time. I'm fairly certain the OP's program didn't work perfectly first time. So some procedure had to be followed to try it and decide if it behaved according to the specification they had in mind. I believe that process can also be called 'testing'. And in this case, involving a visual GUI, it really demands tests verified by a human rather than spending the next six months writing automatic test procedures that simulate mouse input and examine the pixels on the screen to see if they correspond to what should happen. > Your decoder was straight-up buggy, and tests would have proven this. How did YOU determine it was buggy; unit-tests? And did you just do what everyone else does? -- Bartc From dvl at psu.edu Mon Nov 27 10:27:34 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Mon, 27 Nov 2017 10:27:34 -0500 Subject: Python-list Digest, Vol 170, Issue 34 In-Reply-To: mailman.277.1511789156.2897.python-list@python.org References: Message-ID: <1511796454l.18284556l.0l@psu.edu> I'll answer your question with a couple questions: Why do you expect to get the results you seem to expect? What part of your code should repeat (and why)? A key factor in recognizing the difference between 'if' and 'while' is knowing what effect they have on the indented statements that follow them. Roger Christman Pennsylvania State University On Mon, Nov 27, 2017 Cai Gengyang wrote: > >Message: 38 >Date: Mon, 27 Nov 2017 04:54:21 -0800 (PST) >From: Cai Gengyang >Subject: While, If, Count Statements >Message-ID: >Content-Type: text/plain; charset="UTF-8" > > >Input : > >count = 0 > >if count < 5: > print "Hello, I am an if statement and count is", count > >while count < 10: > print "Hello, I am a while and count is", count > count += 1 > >Output : > >Hello, I am an if statement and count is 0 >Hello, I am a while and count is 0 >Hello, I am a while and count is 1 >Hello, I am a while and count is 2 >Hello, I am a while and count is 3 >Hello, I am a while and count is 4 >Hello, I am a while and count is 5 >Hello, I am a while and count is 6 >Hello, I am a while and count is 7 >Hello, I am a while and count is 8 >Hello, I am a while and count is 9 > >The above input gives the output below. Why isn't the output instead : > >Hello, I am an if statement and count is 0 >Hello, I am a while and count is 0 >Hello, I am an if statement and count is 1 >Hello, I am a while and count is 1 >Hello, I am an if statement and count is 2 >Hello, I am a while and count is 2 >Hello, I am an if statement and count is 3 >Hello, I am a while and count is 3 >Hello, I am an if statement and count is 4 >Hello, I am a while and count is 4 >Hello, I am a while and count is 5 >Hello, I am a while and count is 6 >Hello, I am a while and count is 7 >Hello, I am a while and count is 8 >Hello, I am a while and count is 9 > > From ned at nedbatchelder.com Mon Nov 27 10:59:35 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 27 Nov 2017 10:59:35 -0500 Subject: While, If, Count Statements In-Reply-To: References: Message-ID: <2d858822-401a-6bf8-dbbc-b8707e17f11b@nedbatchelder.com> On 11/27/17 7:54 AM, Cai Gengyang wrote: > Input : > > count = 0 > > if count < 5: > print "Hello, I am an if statement and count is", count > > while count < 10: > print "Hello, I am a while and count is", count > count += 1 > > Output : > > Hello, I am an if statement and count is 0 > Hello, I am a while and count is 0 > Hello, I am a while and count is 1 > Hello, I am a while and count is 2 > Hello, I am a while and count is 3 > Hello, I am a while and count is 4 > Hello, I am a while and count is 5 > Hello, I am a while and count is 6 > Hello, I am a while and count is 7 > Hello, I am a while and count is 8 > Hello, I am a while and count is 9 > > The above input gives the output below. Why isn't the output instead : > > Hello, I am an if statement and count is 0 > Hello, I am a while and count is 0 > Hello, I am an if statement and count is 1 > Hello, I am a while and count is 1 > Hello, I am an if statement and count is 2 > Hello, I am a while and count is 2 > Hello, I am an if statement and count is 3 > Hello, I am a while and count is 3 > Hello, I am an if statement and count is 4 > Hello, I am a while and count is 4 > Hello, I am a while and count is 5 > Hello, I am a while and count is 6 > Hello, I am a while and count is 7 > Hello, I am a while and count is 8 > Hello, I am a while and count is 9 It's easy to imagine that this sets up a rule that remains in effect for the rest of the program: ??? if count < 5: ??????? print "Hello, I am an if statement and count is", count But that's not how Python (and most other programming languages) works.? Python reads statements one after another, and executes them as it encounters them.? When it finds the if-statement, it evaluates the condition, and if it is true *at that moment*, it executes the contained statements.? Then it forgets all about that if-statement, and moves on to the next statement. --Ned. From rosuav at gmail.com Mon Nov 27 11:41:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Tue, 28 Nov 2017 04:41:00 +1200 Subject: connect four (game) Message-ID: <3718425985@f38.n261.z1.binkp.net> On Tue, Nov 28, 2017 at 2:14 AM, bartc wrote: > JPEG uses lossy compression. The resulting recovered data is an > approximation of the original. Ah but it is a perfect representation of the JPEG stream. Any given compressed stream must always decode to the same output. The lossiness is on the ENcoding, not the DEcoding. ChrisA From rosuav at gmail.com Mon Nov 27 11:46:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Tue, 28 Nov 2017 04:46:00 +1200 Subject: Increasing the diversity of people who write Python (was: Message-ID: <3452594465@f38.n261.z1.binkp.net> On Tue, Nov 28, 2017 at 1:55 AM, Rustom Mody wrote: > On Monday, November 27, 2017 at 8:07:47 PM UTC+5:30, Chris Angelico wrote: >> On Tue, Nov 28, 2017 at 1:25 AM, Rustom Mody wrote: >> > You could go one step more sophisticated and use TeX-input method >> > (C-x RET C-\) >> > After which \'e will collapse as ?C >> > ? ?Yeah ok but how the ^)*^$# am I to remember the mantra \'e?!? ? you may ask >> > True? | So as you rightly do, >> > - pick it up from google >> > - put emacs into tex input mode >> > - paste from google into emacs >> > - place point on the new char and type C-u C-x = >> > Among other things emacs will helpfully inform you (among other things) >> > to input: type "\'{e}" or "\'e" with TeX input method >> >> Which is closely related to the Compose key input method that I use. >> First, you assign a key on your keyboard to be Compose (at least on >> all my systems, there isn't one by default); I use the key between >> left Ctrl and left Alt. > > Ha Ha So you wont speak the unspeakable???!?? Heh, you mean the term "Windows key"? It's not appropriate on keyboards that don't have an actual Windows logo on it. There are other names for it, but I figured the easiest way was to describe its location :D But yes, that key. If you have a Windows key, you can assign it to be the Compose key. Or, of course, you could redefine left control, so that Ctrl-X is with the right key and Compose-X is with the left one. Or any other key you like. ChrisA From rosuav at gmail.com Mon Nov 27 12:15:00 2017 From: rosuav at gmail.com (nospam.Chris Angelico) Date: Tue, 28 Nov 2017 05:15:00 +1200 Subject: Increasing the diversity of people who write Python (was: Message-ID: <3280470786@f38.n261.z1.binkp.net> On Tue, Nov 28, 2017 at 5:13 AM, Skip Montanaro wrote: >> If you have a Windows key, you can assign it to be >> the Compose key. > > Would this be true on a machine running Windows? My work environment > has me developing on Linux, with a Windows desktop. It's not clear to > me that any sort of xmodmap shennanigans would work. Won't Windows > itself always gobble up that key? Now that, I can't tell you about. As mentioned, the specific system I was using was provided by X11, so it wouldn't work on anything else. (Don't know about Wayland; I think it might have an equivalent.) For other window managers, you'd have to find some alternative. ChrisA From skip.montanaro at gmail.com Mon Nov 27 12:18:53 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 27 Nov 2017 11:18:53 -0600 Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> Message-ID: > I strongly suspect that any recent emacs will have M-x insert-char > (earlier it was called ucs-insert) default bound C-x 8 RET (yeah thats clunky) > which will accept at the minibuffer input I tried C-x 8 e acute TAB and was prompted with "E-acute". I don't know why it would have capitalized the "e". Still, I plowed ahead and hit RET which yielded an "Invalid character" message in the minibuffer. Skip From rosuav at gmail.com Mon Nov 27 12:41:50 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Nov 2017 04:41:50 +1100 Subject: connect four (game) In-Reply-To: <4ZVSB.55738$321.38548@fx12.am4> References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> <3e61c073-1bc1-1e87-0abe-952ff23fcf19@gmail.com> <4ZVSB.55738$321.38548@fx12.am4> Message-ID: On Tue, Nov 28, 2017 at 2:14 AM, bartc wrote: > JPEG uses lossy compression. The resulting recovered data is an > approximation of the original. Ah but it is a perfect representation of the JPEG stream. Any given compressed stream must always decode to the same output. The lossiness is on the ENcoding, not the DEcoding. ChrisA From rosuav at gmail.com Mon Nov 27 12:46:02 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Nov 2017 04:46:02 +1100 Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: <5eac0c8f-07f8-4a84-bf6f-b04db1b101c9@googlegroups.com> References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> <5eac0c8f-07f8-4a84-bf6f-b04db1b101c9@googlegroups.com> Message-ID: On Tue, Nov 28, 2017 at 1:55 AM, Rustom Mody wrote: > On Monday, November 27, 2017 at 8:07:47 PM UTC+5:30, Chris Angelico wrote: >> On Tue, Nov 28, 2017 at 1:25 AM, Rustom Mody wrote: >> > You could go one step more sophisticated and use TeX-input method >> > (C-x RET C-\) >> > After which \'e will collapse as ? >> > ?Yeah ok but how the ^)*^$# am I to remember the mantra \'e?!? you may ask >> > True? So as you rightly do, >> > - pick it up from google >> > - put emacs into tex input mode >> > - paste from google into emacs >> > - place point on the new char and type C-u C-x = >> > Among other things emacs will helpfully inform you (among other things) >> > to input: type "\'{e}" or "\'e" with TeX input method >> >> Which is closely related to the Compose key input method that I use. >> First, you assign a key on your keyboard to be Compose (at least on >> all my systems, there isn't one by default); I use the key between >> left Ctrl and left Alt. > > Ha Ha So you wont speak the unspeakable??!? Heh, you mean the term "Windows key"? It's not appropriate on keyboards that don't have an actual Windows logo on it. There are other names for it, but I figured the easiest way was to describe its location :D But yes, that key. If you have a Windows key, you can assign it to be the Compose key. Or, of course, you could redefine left control, so that Ctrl-X is with the right key and Compose-X is with the left one. Or any other key you like. ChrisA From skip.montanaro at gmail.com Mon Nov 27 13:13:50 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 27 Nov 2017 12:13:50 -0600 Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> <5eac0c8f-07f8-4a84-bf6f-b04db1b101c9@googlegroups.com> Message-ID: > If you have a Windows key, you can assign it to be > the Compose key. Would this be true on a machine running Windows? My work environment has me developing on Linux, with a Windows desktop. It's not clear to me that any sort of xmodmap shennanigans would work. Won't Windows itself always gobble up that key? Skip From rosuav at gmail.com Mon Nov 27 13:15:57 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Nov 2017 05:15:57 +1100 Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> <5eac0c8f-07f8-4a84-bf6f-b04db1b101c9@googlegroups.com> Message-ID: On Tue, Nov 28, 2017 at 5:13 AM, Skip Montanaro wrote: >> If you have a Windows key, you can assign it to be >> the Compose key. > > Would this be true on a machine running Windows? My work environment > has me developing on Linux, with a Windows desktop. It's not clear to > me that any sort of xmodmap shennanigans would work. Won't Windows > itself always gobble up that key? Now that, I can't tell you about. As mentioned, the specific system I was using was provided by X11, so it wouldn't work on anything else. (Don't know about Wayland; I think it might have an equivalent.) For other window managers, you'd have to find some alternative. ChrisA From bc at freeuk.com Mon Nov 27 13:57:08 2017 From: bc at freeuk.com (bartc) Date: Mon, 27 Nov 2017 18:57:08 +0000 Subject: connect four (game) In-Reply-To: References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <67bcda27-8de8-49ab-870b-9a893aadf8c7@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> <3e61c073-1bc1-1e87-0abe-952ff23fcf19@gmail.com> <4ZVSB.55738$321.38548@fx12.am4> Message-ID: <5eZSB.48782$Gc2.11425@fx13.am4> On 27/11/2017 17:41, Chris Angelico wrote: > On Tue, Nov 28, 2017 at 2:14 AM, bartc wrote: >> JPEG uses lossy compression. The resulting recovered data is an >> approximation of the original. > > Ah but it is a perfect representation of the JPEG stream. Any given > compressed stream must always decode to the same output. The lossiness > is on the ENcoding, not the DEcoding. You make it sound as bad as currency calculations where different software must produce results that always match to the nearest cent. We're talking about perhaps +1 or -1 difference in the least significant bit of one channel of one pixels. If the calculation is consistent, then you will not know anything is amiss. By +1 or -1, I mean compared with the same jpeg converted by independent means. I also passed the same jpeg through another C program (not mine) using its own algorithms. There some pixels varied by up to +/- 9 from the others (looking at the first 512 bytes of the conversion to ppm). Here's my test image: https://github.com/bartg/langs/blob/master/card2.jpg (nothing naughty). Tell me what the definitive values of the pixels in this part of the image should be (I believe this corresponds to roughly the leftmost 180 pixels of the top line; there are two million pixels in all). And tell me WHY you think those are the definitive ones. Bear in mind also that this is not intended to be the world's most perfect software. But it does do a good enough job. And the other two Python versions I have, at the minute don't work at all. -- bartc From p.f.moore at gmail.com Mon Nov 27 14:05:38 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 27 Nov 2017 19:05:38 +0000 Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> <5eac0c8f-07f8-4a84-bf6f-b04db1b101c9@googlegroups.com> Message-ID: On 27 November 2017 at 18:13, Skip Montanaro wrote: >> If you have a Windows key, you can assign it to be >> the Compose key. > > Would this be true on a machine running Windows? My work environment > has me developing on Linux, with a Windows desktop. It's not clear to > me that any sort of xmodmap shennanigans would work. Won't Windows > itself always gobble up that key? Programs can access the Windows key. IIRC, there is a utility that provides compose-key functionality on Windows. I can't recall the name right now and it's on my other PC, not this one, but I'll try to remember to post the name tomorrow... Paul From abrault at mapgears.com Mon Nov 27 14:09:46 2017 From: abrault at mapgears.com (Alexandre Brault) Date: Mon, 27 Nov 2017 14:09:46 -0500 Subject: Increasing the diversity of people who write Python In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> <5eac0c8f-07f8-4a84-bf6f-b04db1b101c9@googlegroups.com> Message-ID: A quick Google search turned up WinCompose. It defaults to Right-Alt for its compose key, but that's configurable On 2017-11-27 02:05 PM, Paul Moore wrote: > On 27 November 2017 at 18:13, Skip Montanaro wrote: >>> If you have a Windows key, you can assign it to be >>> the Compose key. >> Would this be true on a machine running Windows? My work environment >> has me developing on Linux, with a Windows desktop. It's not clear to >> me that any sort of xmodmap shennanigans would work. Won't Windows >> itself always gobble up that key? > Programs can access the Windows key. IIRC, there is a utility that > provides compose-key functionality on Windows. I can't recall the name > right now and it's on my other PC, not this one, but I'll try to > remember to post the name tomorrow... > > Paul From ned at nedbatchelder.com Mon Nov 27 14:15:23 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 27 Nov 2017 14:15:23 -0500 Subject: connect four (game) In-Reply-To: <5eZSB.48782$Gc2.11425@fx13.am4> References: <37299c43-479b-4636-92be-9fde2ba4819b@googlegroups.com> <6PdSB.41734$Mu.23897@fx02.am4> <5f3e5404-3300-aa03-016c-047d42a3b4e4@gmail.com> <3e61c073-1bc1-1e87-0abe-952ff23fcf19@gmail.com> <4ZVSB.55738$321.38548@fx12.am4> <5eZSB.48782$Gc2.11425@fx13.am4> Message-ID: On 11/27/17 1:57 PM, bartc wrote: > On 27/11/2017 17:41, Chris Angelico wrote: >> On Tue, Nov 28, 2017 at 2:14 AM, bartc wrote: >>> JPEG uses lossy compression. The resulting recovered data is an >>> approximation of the original. >> >> Ah but it is a perfect representation of the JPEG stream. Any given >> compressed stream must always decode to the same output. The lossiness >> is on the ENcoding, not the DEcoding. > > You make it sound as bad as currency calculations where different > software must produce results that always match to the nearest cent. > > We're talking about perhaps +1 or -1 difference in the least > significant bit of one channel of one pixels. If the calculation is > consistent, then you will not know anything is amiss. > > By +1 or -1, I mean compared with the same jpeg converted by > independent means. > > I also passed the same jpeg through another C program (not mine) using > its own algorithms. There some pixels varied by up to +/- 9 from the > others (looking at the first 512 bytes of the conversion to ppm). > > Here's my test image: > https://github.com/bartg/langs/blob/master/card2.jpg (nothing naughty). > > Tell me what the definitive values of the pixels in this part of the > image should be (I believe this corresponds to roughly the leftmost > 180 pixels of the top line; there are two million pixels in all). And > tell me WHY you think those are the definitive ones. > > Bear in mind also that this is not intended to be the world's most > perfect software. But it does do a good enough job. And the other two > Python versions I have, at the minute don't work at all. > > Surely the details of JPEG decompression, and the possible presence of flaws in certain decoders, is beyond the scope of this thread? --Ned. From hjp at hjp.at Mon Nov 27 14:35:44 2017 From: hjp at hjp.at (Peter J. Holzer) Date: Mon, 27 Nov 2017 20:35:44 +0100 Subject: Benefits of unicode identifiers (was: Allow additional separator in identifiers) In-Reply-To: References: Message-ID: <20171127193544.mw3bfelk5vffknpe@hjp.at> On 2017-11-24 04:52:57 +0100, Mikhail V wrote: > On Fri, Nov 24, 2017 at 4:13 AM, Chris Angelico wrote: > > On Fri, Nov 24, 2017 at 1:44 PM, Mikhail V wrote: > >> From my above example, you could probably see that I prefer somewhat > >> middle-sized identifiers, one-two syllables. And naturally, they tend to > >> reflect some process/meaining, it is not always achievable, > >> but yes there is such a natural tendency, although by me personally > >> not so strong, and quite often I use totally meaningless names, > >> mainly to avoid visual similarity to already created names. > >> So for very expanded names, it ends up with a lot of underscores :( > > > > Okay. So if it makes sense for you to use English words instead of > > individual letters, since you are fluent in English, does it stand to > > reason that it would make sense for other programmers to use Russian, > > Norwegian, Hebrew, Korean, or Japanese words the same way? > > I don't know. Probably, especially if those *programmers* don't know latin > letters, then they would want to write code with their letters and their > language. This target group, as I said, will have really hard time > with programming, I don't think that's the target group. As you say, if you don't know latin letters you'll have a hard time with Python (or almost any programming language). You can't read the keywords or the standard library function names. I think the target group is people who can read the latin alphabet and probably also at least a bit of English, but who are working on in-house projects. As a very simple example, many years ago, when I was still at the university, we decided that we needed a program to manage our students. So we got some students to write one ;-). As a general rule, identifiers and comments for all projects had to be in English, which generally made a lot of sense since we collaborated with institutes in other countries. But for that project that rule wasn't really appropriate, as we noticed when one of the students asked us what "Matrikelnummer" is in English. Nobody knew, so we consulted a dictionary and apparently it's "enrollment number". Simple enough, but is that intelligible to all English speakers or is it specific to British universities? And even worse - whoever is going to maintain that code would be either a staff member or a student of our institute - they would certainly know what a "Matrikelnummer" is, but would they understand that enrollment_number is supposed to contain that? So we decided that domain specific jargon should not be translated. A bit of bilingual mishmash (first_name and course_title, but matrikelnummer and kennummer) was better than using words that knowbody understood. Now that particular word doesn't contain any non-ASCII characters and German has only 4 letters not in ASCII, and for all of them there are official ASCII substitutes, so writing German words in ASCII isn't a problem. But for languages with non-latin alphabets (or just a higher density of accented letters) that's different. If my native language was Russian and I was writing some in-house application for a Russian company which contained a lot of Russian company jargon which can't be easily translated to English (and back), I'm quite sure that I would prefer to write that jargon in cyrillic and not in some transliteration. > and in Python in particular, because they will be not only forced to learn > some english, but also will have all 'pleasures' of multi-script editing. > But wait, probably one can write python code in, say Arabic script *only*? > How about such feature proposal? There is source filter which lets you write Perl in traditional Chinese. This even changes the syntax to be closer to Chinese syntax. There is also one which lets you write Perl in Latin (obviously that uses the Latin alphabet, but it changes the syntax even more). Don't know whether something like this is possible in Python, but arguably the result wouldn't be Python any more (just like Lingua::Romana::Perligata isn't really Perl - it just happens to be implemented using the Perl interpreter). > Ok, so we return back to my original question: apart from > ability to do so, how beneficial is it on a pragmatical basis? When I use German identifiers (which I generally don't) I do use umlauts. When I need to do some physical computations, I might use greek letters (or maybe not - as a vim user I can type ?t easily enough, but can the colleague using PyCharm on Windows? I have no idea). So for me the benefit is rather small. But as I said, German is almost ASCII-compatible. 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 martin.schoon at gmail.com Mon Nov 27 15:20:50 2017 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 27 Nov 2017 20:20:50 GMT Subject: Pros and cons of Python sources? References: <2332526810@f38.n261.z1.binkp.net> <20171126230902.GA78877@cskk.homeip.net> Message-ID: Den 2017-11-26 skrev Cameron Simpson : > On 26Nov2017 10:00, nospam.Martin Sch??n wrote: >> >>Hmm, I seem to remember not being able to install packages with pip unless I >>did sudo pip. > > And this is exactly what I'm warning about. Many Linux users see some kind of > failure and just stick sudo on the front of the command. It is almost always > the wrong things to do, leading to effects in the OS install area instead of > being safely contained within one's home directory or work area. > > Instead of reaching straight for sudo, look at pip's manual or help. You will > find that: > > pip install --user ... > > installs modules local to your home directory, avoiding troublesome installs > into the OS area. > Guilty as charged. So, how do I restore order in my Python 2.7 installation? Uninstall everything that looks, smells and tastes like Python 2.7 and then re-install? /Martin From cs at cskk.id.au Mon Nov 27 16:14:12 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 28 Nov 2017 08:14:12 +1100 Subject: Pros and cons of Python sources? In-Reply-To: References: Message-ID: <20171127211412.GA79125@cskk.homeip.net> On 27Nov2017 20:20, Martin Sch??n wrote: >Den 2017-11-26 skrev Cameron Simpson : >> On 26Nov2017 10:00, nospam.Martin Sch??n wrote: >>>Hmm, I seem to remember not being able to install packages with pip unless I >>>did sudo pip. >> >> And this is exactly what I'm warning about. Many Linux users see some kind of >> failure and just stick sudo on the front of the command. It is almost always >> the wrong things to do, leading to effects in the OS install area instead of >> being safely contained within one's home directory or work area. >> >> Instead of reaching straight for sudo, look at pip's manual or help. You will >> find that: >> >> pip install --user ... >> >> installs modules local to your home directory, avoiding troublesome installs >> into the OS area. >> >Guilty as charged. > >So, how do I restore order in my Python 2.7 installation? Uninstall >everything that looks, smells and tastes like Python 2.7 and then >re-install? Depeneds on your OS/distro. Redhat's RPM used to have some kind of --verify option to compare package definitions aginst what was physically present. But if the package is mainstream you're probably ok? You could just live with it and do no more damage. Otherwise, look to see what python packages are installed which you think you may have pipped, and reinstall those. But also, pip tends not to install things that are already present, so you might be fine. Cheers, Cameron Simpson (formerly cs at zip.com.au) From p.f.moore at gmail.com Mon Nov 27 16:14:46 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 27 Nov 2017 21:14:46 +0000 Subject: Pros and cons of Python sources? In-Reply-To: References: <2332526810@f38.n261.z1.binkp.net> <20171126230902.GA78877@cskk.homeip.net> Message-ID: On 27 November 2017 at 20:20, Martin Sch??n wrote: > Den 2017-11-26 skrev Cameron Simpson : >> On 26Nov2017 10:00, nospam.Martin Sch??n wrote: >>> >>>Hmm, I seem to remember not being able to install packages with pip unless I >>>did sudo pip. >> >> And this is exactly what I'm warning about. Many Linux users see some kind of >> failure and just stick sudo on the front of the command. It is almost always >> the wrong things to do, leading to effects in the OS install area instead of >> being safely contained within one's home directory or work area. >> >> Instead of reaching straight for sudo, look at pip's manual or help. You will >> find that: >> >> pip install --user ... >> >> installs modules local to your home directory, avoiding troublesome installs >> into the OS area. >> > Guilty as charged. > > So, how do I restore order in my Python 2.7 installation? Uninstall > everything that looks, smells and tastes like Python 2.7 and then > re-install? Or just accept that everything's probably fine, but be prepared to deal with the fact that something like that is what you should do if you find a problem you can't resolve yourself and need to ask for help from upstream (e.g., your distro provider or the pip maintainers). It's not so much that anyone's forcing you to do anything a particular way - just setting the boundaries on what they are willing to support if you need help. Paul From formisc at gmail.com Mon Nov 27 16:34:07 2017 From: formisc at gmail.com (Andrew Z) Date: Mon, 27 Nov 2017 16:34:07 -0500 Subject: Pros and cons of Python sources? In-Reply-To: References: <2332526810@f38.n261.z1.binkp.net> <20171126230902.GA78877@cskk.homeip.net> Message-ID: Martin, Im Late to the party, but my (newbish) .02 I learned hard way not to mix rpm and pip (im on fedora). Yes, pip ...-user is what i use now exclusively. I doubt you can _easily_ clean everything up..especially considering that a few linux core utils depend on python nowadays. Maybe you can try to "brute-force" it , by using : dnf/rpm --whatprovides ..| sort -u And comparing with pip list.. (just a general idea). You may also try to stand up a vm and compare lists from there too... ( agly, but will get the work done) I have same mess as you do, but with python3. In my situation, i know i messed something, because matplot would not graph anything despite my best efforts. One day (in next e-6 months) when i get very annoyed with this problem, ill wipe clean the machine and reinstall from scratch. On Nov 27, 2017 15:25, "Martin Sch??n" wrote: Den 2017-11-26 skrev Cameron Simpson : > On 26Nov2017 10:00, nospam.Martin Sch??n wrote: >> >>Hmm, I seem to remember not being able to install packages with pip unless I >>did sudo pip. > > And this is exactly what I'm warning about. Many Linux users see some kind of > failure and just stick sudo on the front of the command. It is almost always > the wrong things to do, leading to effects in the OS install area instead of > being safely contained within one's home directory or work area. > > Instead of reaching straight for sudo, look at pip's manual or help. You will > find that: > > pip install --user ... > > installs modules local to your home directory, avoiding troublesome installs > into the OS area. > Guilty as charged. So, how do I restore order in my Python 2.7 installation? Uninstall everything that looks, smells and tastes like Python 2.7 and then re-install? /Martin -- https://mail.python.org/mailman/listinfo/python-list From ian.g.kelly at gmail.com Mon Nov 27 17:44:30 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 27 Nov 2017 15:44:30 -0700 Subject: How to shut down a TCPServer serve_forever() loop? In-Reply-To: References: Message-ID: On Sat, Nov 25, 2017 at 7:10 AM, John Pote wrote: > Hi all, > > My problem in summary is that my use of the shutdown() method only shuts > down a server after the next TCP request is received. > > I have a TCP server created in the run() method of a thread. > > class TCPlistener( Thread ): > def run( self ): > with socketserver.TCPServer( ("localhost", 9999), ConnHandler ) > as server: > self.server = server > print( "TCP listener on: %s:%d" % ( self.host, self.port ) ) > self.server.serve_forever() > > print( "TCPlistener:run() ending" ) > > ConnHandler is a simple echo class with only a handle() method > > The main bit of the program is > > if __name__ == "__main__": > serverThrd = TCPlistener() > serverThrd.start() #start TCP IP server listening > print("server started") > > ch = getche() #wait for key press > print() > serverThrd.server.shutdown() > > print( "main ending" ) > > Everying works as expected, numerous connections can be made and the > received text is echoed back. > > The issue is that if I press a key on the keyboard the key is immediately > shown on the screen but then the shutdown() call blocks until another TCP > connection is made, text is echoed back and only then does > serve_forever()return followed by shutdown()returning as can be seen from > the console session, > >>>python36 TCPIPserver.py > server started > TCP listener on: localhost:9999 > q #pressed 'q' key > 127.0.0.1 wrote: #Sent some text from PuTTY > b'SOME TEXT' > TCPlistener:run() ending > main ending > > How can I get shutdown()to shut down the server immediately without waiting > for the next TCP connection? Make a connection to the server after calling shutdown to wake up the server's event loop? I'm guessing it only checks the shutdown flag after responding to an event, so there's probably not much else you could do. From ben+python at benfinney.id.au Mon Nov 27 17:55:40 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 28 Nov 2017 09:55:40 +1100 Subject: I have framework on python with pyunit, facing below issue while References: <2691586178@f38.n261.z1.binkp.net> Message-ID: <85efojuyab.fsf@benfinney.id.au> nospam.jaya.birdar at gmail.com (jaya birdar) writes: > Please let me know anyone aware about the issue Please let us know about the issue. * What Python is this? Installed how? Running on what platform? * What code base is this? What is a simple complete, executable example that *we* can run to see the same behaviour? * What expectation did you have for the code when you run it? What is the behaviour it should show, and how is that different from what you got? * What other possibly unusual context does this code have, that we might need to know about to understand what's happening? -- \ ?If you're not part of the solution, you're part of the | `\ precipitate.? ?Steven Wright | _o__) | Ben Finney From grant.b.edwards at gmail.com Mon Nov 27 18:00:52 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 27 Nov 2017 23:00:52 +0000 (UTC) Subject: I guess I'd better plonk anything From: nospam.* Message-ID: At least the phase delay through the feedback loop appears to be many hours. That should postpone disaster for a few days... -- Grant Edwards grant.b.edwards Yow! I'm sitting on my at SPEED QUEEN ... To me, gmail.com it's ENJOYABLE ... I'm WARM ... I'm VIBRATORY ... From ben+python at benfinney.id.au Mon Nov 27 18:25:28 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 28 Nov 2017 10:25:28 +1100 Subject: Please disable =?utf-8?B?4oCcZGlnZXN04oCd?= mode to participate (was: Python-list Digest, Vol 170, Issue 34) In-Reply-To: <1871898189@f38.n261.z1.binkp.net> (nospam.'s message of "Mon, 27 Nov 2017 10:27:00 +1200") References: <1871898189@f38.n261.z1.binkp.net> Message-ID: <85609vuwwn.fsf@benfinney.id.au> nospam."ROGER GRAYDON CHRISTMAN" (ROGER GRAYDON CHRISTMAN) writes: > I'll answer your question with a couple questions: Roger, your messages often are not replies to the original message, but replies to a ?digest? composed by the mailing list. The digest messages are useful, but only for the recipient as a read-only digest. Enabling ?digest? mode is only for when you are *certain* that you will never at any point need to respond to any message from the forum. That's not true, so should be turned off. Message digests are not useful if you want to participate in the forum: your replies are to messages we've never seen, they do not thread correctly, and you have a lot of additional clean-up to do in the quoted material. This is all making it harder for you to participate in the forum. Instead: go to your settings in the mailing list subscription, and disable ?digest? mode. You will then be able to respond directly to specific messages when they arrive, the same ones the rest of us see and have in threaded discussions. -- \ ?I went to a fancy French restaurant called ?D?j? Vu?. The head | `\ waiter said, ?Don't I know you??? ?Steven Wright | _o__) | Ben Finney From breamoreboy at gmail.com Mon Nov 27 18:36:47 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Mon, 27 Nov 2017 15:36:47 -0800 (PST) Subject: Benefits of unicode identifiers (was: Allow additional separator In-Reply-To: <1049068218@f38.n261.z1.binkp.net> References: <1049068218@f38.n261.z1.binkp.net> Message-ID: On Monday, November 27, 2017 at 10:08:06 PM UTC, wxjmfauth wrote: > Le lundi 27 novembre 2017 14:52:19 UTC+1, Rustom Mody a ?Ccrit? : > > On Monday, November 27, 2017 at 6:48:56 PM UTC+5:30, Rustom Mody wrote: > > > Having said that I should be honest to mention that I saw your post first > on > > > my phone where the ?, showed but the g??? showed as a rectangle something > like ??$ > > > > > > I suspect that ?? OTOH would have worked? | dunno > > > > Yeah ?? shows whereas g??? doesn't (on my phone) > > And ??$ does show but much squatter than the replacement char the phone shows > > when it cant display a char > > It is a least unicode. > > Much better than what this idotic and buggy Flexible String Representation is > presenting to the eyes of users. Why is this drivel now getting through onto the main mailing list/gmane? -- Kindest regards. Mark Lawrence. From skip.montanaro at gmail.com Mon Nov 27 19:59:36 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 27 Nov 2017 18:59:36 -0600 Subject: nospam ** infinity? In-Reply-To: <3069634946@f38.n261.z1.binkp.net> References: <3069634946@f38.n261.z1.binkp.net> Message-ID: >> Newsreader configuration problem? > > More likely, someone was trying to obscure the email addresses, but managed to > tag my name instead. Definitely looks like some sort of automation failure. The > only question is, whose? If it's not from gate_news, there's someone here on > the list/ng that is (probably accidentally) reposting everything. I'm 99.5% certain it's not gate_news. It's always been running. The only thing Mark and I changed was to get SpamBayes running again as part of gate_news. Its only effect on a message is to add relevant headers (typically X-Spam-Evidence and X-Spam-Status). It never modifies existing headers. Skip From skip.montanaro at gmail.com Mon Nov 27 20:14:35 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 27 Nov 2017 19:14:35 -0600 Subject: nospam ** infinity? In-Reply-To: References: <3069634946@f38.n261.z1.binkp.net> Message-ID: > I'm 99.5% certain it's not gate_news. A funny thing. All messages I have looked at so far with the "nospam" thing have a Message-ID from binkp.net. (They are also all Usenet posts.) For example: Newsgroups: comp.lang.python Subject: Re: I have anaconda, but Pycharm can't find it Date: Sun, 26 Nov 2017 22:40:00 +1200 Organization: Agency BBS, Dunedin - New Zealand | bbs.geek.nz Message-ID: <1783215345 at f38.n261.z1.binkp.net> Mime-Version: 1.0 Any ideas how to investigate further? Skip From mikhailwas at gmail.com Mon Nov 27 21:33:39 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Tue, 28 Nov 2017 03:33:39 +0100 Subject: Increasing the diversity of people who write Python In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> <5eac0c8f-07f8-4a84-bf6f-b04db1b101c9@googlegroups.com> Message-ID: On Mon, Nov 27, 2017 at 8:09 PM, Alexandre Brault wrote: > A quick Google search turned up WinCompose. It defaults to Right-Alt for > its compose key, but that's configurable > > On 2017-11-27 02:05 PM, Paul Moore wrote: >> On 27 November 2017 at 18:13, Skip Montanaro wrote: >>>> If you have a Windows key, you can assign it to be >>>> the Compose key. >>> Would this be true on a machine running Windows? My work environment >>> has me developing on Linux, with a Windows desktop. It's not clear to >>> me that any sort of xmodmap shennanigans would work. Won't Windows >>> itself always gobble up that key? >> Programs can access the Windows key. IIRC, there is a utility that >> provides compose-key functionality on Windows. I can't recall the name >> right now and it's on my other PC, not this one, but I'll try to >> remember to post the name tomorrow... >> >> Paul On Windows people usually use AHK (Autohotkey). It is a programming language, so you can do anything you want. For example, here is a script that converts two characters to the left of current cursor position: if it is "e" followed by apostrophe then it replaces it with ?, ;--------------------------- #NoEnv SendMode Input SetWorkingDir %A_ScriptDir% parse_clip(str) { firstchar := substr(str, 1,1) lastchar := substr(str, 2,2) if (lastchar = "'") { if (firstchar = "e") { Send, {raw}? } if (firstchar = "a") { Send, {raw}? } } else { Send, {right} } } Esc:: ExitApp !c:: clipboard := "" Send, {Shift down}{left}{left}{Shift up} Send, ^c Clipwait, 1 gettext := clipboard parse_clip(gettext) return ;--------------------------- So here the command is bound to Alt-C, it selects two previus chars (shift+arrow commands), copies to clipboard and parses the contents. It works system-wide, but can be programmed to specific app as well. Best thing is, you can program it youself as you like. However if you want to program with AHK, be prepared to invest time, it is not the easiest programming language out there, only built-ins probably more than hundred, so better not try to code without syntax highlighting :) . From rustompmody at gmail.com Mon Nov 27 22:44:37 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 27 Nov 2017 19:44:37 -0800 (PST) Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> Message-ID: On Monday, November 27, 2017 at 10:49:35 PM UTC+5:30, Skip Montanaro wrote: > > I strongly suspect that any recent emacs will have M-x insert-char > > (earlier it was called ucs-insert) default bound C-x 8 RET (yeah thats clunky) > > which will accept at the minibuffer input > > I tried C-x 8 e acute TAB > > and was prompted with "E-acute". I don't know why it would have > capitalized the "e". Unicode codepoint names are (evidently) ALLCAPS-ASCII Still, I plowed ahead and hit RET > > which yielded an "Invalid character" message in the minibuffer. Unicode is a million+ codepoints Hundred thousand+ of which are assigned This means that (as an analogy) emacs is fishing around in a 100,000 line file which contains lines like LATIN SMALL LETTER A:a:0x61 LATIN CAPITAL LETTER A:A:0x41 DIGIT ONE:1:0x31 ... 100,000 such lines? one of which is LATIN SMALL LETTER E WITH ACUTE:?:0xe9 [Just now fishing around I find its worse than that C-u C-x = tells me: character: ? (displayed as ?) (codepoint 233, #o351, #xe9) name: LATIN SMALL LETTER E WITH ACUTE old-name: LATIN SMALL LETTER E ACUTE general-category: Ll (Letter, Lowercase) So those hundred thousand chars can have multiple names!! And that constitutes the search space ] So now coming to your attempt: [ Writing this mail, Ive finally done: (global-set-key (kbd "") 'insert-char) which allows me to use F9 instead of the clunky C-x 8 RET I'll assume that binding following ] If I type F9*e acuteTAB I get 121 possibilities: CANADIAN SYLLABICS FINAL DOUBLE ACUTE (?) COMBINING DOTTED ACUTE ACCENT (?) COMBINING DOUBLE ACUTE ACCENT (?) CYRILLIC CAPITAL LETTER U WITH DOUBLE ACUTE (?) CYRILLIC SMALL LETTER U WITH DOUBLE ACUTE (?) DEVANAGARI ACUTE ACCENT (?) DOUBLE ACUTE ACCENT (?) GREEK UPSILON WITH ACUTE AND HOOK SYMBOL (?) LATIN CAPITAL LETTER A ACUTE (?) LATIN CAPITAL LETTER A WITH ACUTE (?) LATIN CAPITAL LETTER A WITH BREVE AND ACUTE (?) LATIN CAPITAL LETTER A WITH CIRCUMFLEX AND ACUTE (?) LATIN CAPITAL LETTER A WITH RING ABOVE AND ACUTE (?) LATIN CAPITAL LETTER AE WITH ACUTE (?) LATIN CAPITAL LETTER C ACUTE (?) LATIN CAPITAL LETTER C WITH ACUTE (?) LATIN CAPITAL LETTER C WITH CEDILLA AND ACUTE (?) LATIN CAPITAL LETTER E ACUTE (?) LATIN CAPITAL LETTER E WITH ACUTE (?) LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND ACUTE (?) LATIN CAPITAL LETTER E WITH MACRON AND ACUTE (?) LATIN CAPITAL LETTER G WITH ACUTE (?) LATIN CAPITAL LETTER I ACUTE (?) LATIN CAPITAL LETTER I WITH ACUTE (?) LATIN CAPITAL LETTER I WITH DIAERESIS AND ACUTE (?) LATIN CAPITAL LETTER K WITH ACUTE (?) LATIN CAPITAL LETTER L ACUTE (?) LATIN CAPITAL LETTER L WITH ACUTE (?) LATIN CAPITAL LETTER M WITH ACUTE (?) LATIN CAPITAL LETTER N ACUTE (?) LATIN CAPITAL LETTER N WITH ACUTE (?) LATIN CAPITAL LETTER O ACUTE (?) LATIN CAPITAL LETTER O DOUBLE ACUTE (?) LATIN CAPITAL LETTER O WITH ACUTE (?) LATIN CAPITAL LETTER O WITH CIRCUMFLEX AND ACUTE (?) LATIN CAPITAL LETTER O WITH DOUBLE ACUTE (?) LATIN CAPITAL LETTER O WITH HORN AND ACUTE (?) LATIN CAPITAL LETTER O WITH MACRON AND ACUTE (?) LATIN CAPITAL LETTER O WITH STROKE AND ACUTE (?) LATIN CAPITAL LETTER O WITH TILDE AND ACUTE (?) LATIN CAPITAL LETTER P WITH ACUTE (?) LATIN CAPITAL LETTER R ACUTE (?) LATIN CAPITAL LETTER R WITH ACUTE (?) LATIN CAPITAL LETTER S ACUTE (?) LATIN CAPITAL LETTER S WITH ACUTE (?) LATIN CAPITAL LETTER S WITH ACUTE AND DOT ABOVE (?) LATIN CAPITAL LETTER U ACUTE (?) LATIN CAPITAL LETTER U DIAERESIS ACUTE (?) LATIN CAPITAL LETTER U DOUBLE ACUTE (?) LATIN CAPITAL LETTER U WITH ACUTE (?) LATIN CAPITAL LETTER U WITH DIAERESIS AND ACUTE (?) LATIN CAPITAL LETTER U WITH DOUBLE ACUTE (?) LATIN CAPITAL LETTER U WITH HORN AND ACUTE (?) LATIN CAPITAL LETTER U WITH TILDE AND ACUTE (?) LATIN CAPITAL LETTER W WITH ACUTE (?) LATIN CAPITAL LETTER Y ACUTE (?) LATIN CAPITAL LETTER Y WITH ACUTE (?) LATIN CAPITAL LETTER Z ACUTE (?) LATIN CAPITAL LETTER Z WITH ACUTE (?) LATIN SMALL LETTER A ACUTE (?) LATIN SMALL LETTER A WITH ACUTE (?) LATIN SMALL LETTER A WITH BREVE AND ACUTE (?) LATIN SMALL LETTER A WITH CIRCUMFLEX AND ACUTE (?) LATIN SMALL LETTER A WITH RING ABOVE AND ACUTE (?) LATIN SMALL LETTER AE WITH ACUTE (?) LATIN SMALL LETTER C ACUTE (?) LATIN SMALL LETTER C WITH ACUTE (?) LATIN SMALL LETTER C WITH CEDILLA AND ACUTE (?) LATIN SMALL LETTER E ACUTE (?) LATIN SMALL LETTER E WITH ACUTE (?) LATIN SMALL LETTER E WITH CIRCUMFLEX AND ACUTE (?) LATIN SMALL LETTER E WITH MACRON AND ACUTE (?) LATIN SMALL LETTER G WITH ACUTE (?) LATIN SMALL LETTER I ACUTE (?) LATIN SMALL LETTER I WITH ACUTE (?) LATIN SMALL LETTER I WITH DIAERESIS AND ACUTE (?) LATIN SMALL LETTER K WITH ACUTE (?) LATIN SMALL LETTER L ACUTE (?) LATIN SMALL LETTER L WITH ACUTE (?) LATIN SMALL LETTER M WITH ACUTE (?) LATIN SMALL LETTER N ACUTE (?) LATIN SMALL LETTER N WITH ACUTE (?) LATIN SMALL LETTER O ACUTE (?) LATIN SMALL LETTER O DOUBLE ACUTE (?) LATIN SMALL LETTER O WITH ACUTE (?) LATIN SMALL LETTER O WITH CIRCUMFLEX AND ACUTE (?) LATIN SMALL LETTER O WITH DOUBLE ACUTE (?) LATIN SMALL LETTER O WITH HORN AND ACUTE (?) LATIN SMALL LETTER O WITH MACRON AND ACUTE (?) LATIN SMALL LETTER O WITH STROKE AND ACUTE (?) LATIN SMALL LETTER O WITH TILDE AND ACUTE (?) LATIN SMALL LETTER P WITH ACUTE (?) LATIN SMALL LETTER R ACUTE (?) LATIN SMALL LETTER R WITH ACUTE (?) LATIN SMALL LETTER S ACUTE (?) LATIN SMALL LETTER S WITH ACUTE (?) LATIN SMALL LETTER S WITH ACUTE AND DOT ABOVE (?) LATIN SMALL LETTER U ACUTE (?) LATIN SMALL LETTER U DIAERESIS ACUTE (?) LATIN SMALL LETTER U DOUBLE ACUTE (?) LATIN SMALL LETTER U WITH ACUTE (?) LATIN SMALL LETTER U WITH DIAERESIS AND ACUTE (?) LATIN SMALL LETTER U WITH DOUBLE ACUTE (?) LATIN SMALL LETTER U WITH HORN AND ACUTE (?) LATIN SMALL LETTER U WITH TILDE AND ACUTE (?) LATIN SMALL LETTER W WITH ACUTE (?) LATIN SMALL LETTER Y ACUTE (?) LATIN SMALL LETTER Y WITH ACUTE (?) LATIN SMALL LETTER Z ACUTE (?) LATIN SMALL LETTER Z WITH ACUTE (?) MODIFIER LETTER ACUTE (?) MODIFIER LETTER ACUTE ACCENT (?) MODIFIER LETTER LOW ACUTE (?) MODIFIER LETTER LOW ACUTE ACCENT (?) MODIFIER LETTER MIDDLE DOUBLE ACUTE ACCENT (?) NON-SPACING DOUBLE ACUTE (?) SPACING DOUBLE ACUTE (?) Clearly reducing the search space seems called for! Adding a latin in front to now search for latin*e acute And then Tab expanding gives LATIN *L LETTER ACUTE [Why did the E disappear?? Dunno] Put it back and TAB gives LATIN *AL LETTER E ACUTE Tab once more the choices now are these 7 and more manageable?? LATIN CAPITAL LETTER E ACUTE (?) LATIN CAPITAL LETTER E WITH ACUTE (?) LATIN CAPITAL LETTER E WITH CIRCUMFLEX AND ACUTE (?) LATIN CAPITAL LETTER E WITH MACRON AND ACUTE (?) LATIN SMALL LETTER E ACUTE (?) LATIN SMALL LETTER E WITH ACUTE (?) LATIN SMALL LETTER E WITH CIRCUMFLEX AND ACUTE (?) LATIN SMALL LETTER E WITH MACRON AND ACUTE (?) From marko at pacujo.net Tue Nov 28 01:03:49 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 28 Nov 2017 08:03:49 +0200 Subject: Pros and cons of Python sources? References: <2332526810@f38.n261.z1.binkp.net> <20171126230902.GA78877@cskk.homeip.net> Message-ID: <878terym62.fsf@elektro.pacujo.net> Cameron Simpson : > And this is exactly what I'm warning about. Many Linux users see some > kind of failure and just stick sudo on the front of the command. It is > almost always the wrong things to do, leading to effects in the OS > install area instead of being safely contained within one's home > directory or work area. I can see the idea of installing software in a particular work area, but have a harder time seeing how installing software in a user's home directory is usually a good idea. Often your home directory is more sacrosanct than the rest of the machine. After all, your precious, unique, private data is in your home directory while the OS is just a generic, reproducible installation. Marko From marko at pacujo.net Tue Nov 28 01:04:10 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 28 Nov 2017 08:04:10 +0200 Subject: How to shut down a TCPServer serve_forever() loop? References: Message-ID: <87tvxfx7l1.fsf@elektro.pacujo.net> Ian Kelly : > On Sat, Nov 25, 2017 at 7:10 AM, John Pote wrote: >> The issue is that if I press a key on the keyboard the key is >> immediately shown on the screen but then the shutdown() call blocks >> until another TCP connection is made, text is echoed back and only >> then does serve_forever()return followed by shutdown()returning as >> can be seen from the console session, > [...] > Make a connection to the server after calling shutdown to wake up the > server's event loop? I'm guessing it only checks the shutdown flag > after responding to an event, so there's probably not much else you > could do. Seems to be one of the fundamental multithreading issues: each thread is blocked on precisely one event. Asyncio is more flexible: you can multiplex on a number of events. Marko From cs at cskk.id.au Tue Nov 28 01:18:17 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 28 Nov 2017 17:18:17 +1100 Subject: Pros and cons of Python sources? In-Reply-To: <878terym62.fsf@elektro.pacujo.net> References: <878terym62.fsf@elektro.pacujo.net> Message-ID: <20171128061817.GA1612@cskk.homeip.net> On 28Nov2017 08:03, Marko Rauhamaa wrote: >Cameron Simpson : >> And this is exactly what I'm warning about. Many Linux users see some >> kind of failure and just stick sudo on the front of the command. It is >> almost always the wrong things to do, leading to effects in the OS >> install area instead of being safely contained within one's home >> directory or work area. > >I can see the idea of installing software in a particular work area, but >have a harder time seeing how installing software in a user's home >directory is usually a good idea. > >Often your home directory is more sacrosanct than the rest of the >machine. After all, your precious, unique, private data is in your home >directory while the OS is just a generic, reproducible installation. Well, that is true, but on a personal basis my work areas are in well defined places within my home directory. Also, it is traditionally easier to repair one's home directory that the do a clean full OS install without accidentally trashing one's home directory. The "pip install --user" incantation installs packages in a very well defined location within your home directory accessed by the default python sys.path. And there's always virtualenv to make per-project areas for distinct pip activities; I keep mine in ~/var/venv/BLAH to keep my home directory pristine. The core idea is to keep away from the OS to avoid trouble, and one's home directory is a presupplied are where one has a free hand. Keeping it tidy and organised is of course desirable. Cheers, Cameron Simpson (formerly cs at zip.com.au) From gengyangcai at gmail.com Tue Nov 28 02:50:03 2017 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 27 Nov 2017 23:50:03 -0800 (PST) Subject: While, If, Count Statements In-Reply-To: <1236202728@f38.n261.z1.binkp.net> References: <1236202728@f38.n261.z1.binkp.net> Message-ID: On Tuesday, November 28, 2017 at 6:09:17 AM UTC+8, Ned Batchelder wrote: > On 11/27/17 7:54 AM, Cai Gengyang wrote: > > Input : > > > > count = 0 > > > > if count < 5: > > print "Hello, I am an if statement and count is", count > > > > while count < 10: > > print "Hello, I am a while and count is", count > > count += 1 > > > > Output : > > > > Hello, I am an if statement and count is 0 > > Hello, I am a while and count is 0 > > Hello, I am a while and count is 1 > > Hello, I am a while and count is 2 > > Hello, I am a while and count is 3 > > Hello, I am a while and count is 4 > > Hello, I am a while and count is 5 > > Hello, I am a while and count is 6 > > Hello, I am a while and count is 7 > > Hello, I am a while and count is 8 > > Hello, I am a while and count is 9 > > > > The above input gives the output below. Why isn't the output instead : > > > > Hello, I am an if statement and count is 0 > > Hello, I am a while and count is 0 > > Hello, I am an if statement and count is 1 > > Hello, I am a while and count is 1 > > Hello, I am an if statement and count is 2 > > Hello, I am a while and count is 2 > > Hello, I am an if statement and count is 3 > > Hello, I am a while and count is 3 > > Hello, I am an if statement and count is 4 > > Hello, I am a while and count is 4 > > Hello, I am a while and count is 5 > > Hello, I am a while and count is 6 > > Hello, I am a while and count is 7 > > Hello, I am a while and count is 8 > > Hello, I am a while and count is 9 > > It's easy to imagine that this sets up a rule that remains in effect for the > rest of the program: > > ? ? ? if count < 5: > ? ? ? ? ? ? ? print "Hello, I am an if statement and count is", count > > But that's not how Python (and most other programming languages) works.? Python > reads statements one after another, and executes them as it encounters them.? > When it finds the if-statement, it evaluates the condition, and if it is true > *at that moment*, it executes the contained statements.? Then it forgets all > about that if-statement, and moves on to the next statement. > > --Ned. Sure, so how would the code look like if I want the "if" statement to be nested inside the "while" loop and give me the result : Hello, I am an if statement and count is 0 Hello, I am a while and count is 0 Hello, I am an if statement and count is 1 Hello, I am a while and count is 1 Hello, I am an if statement and count is 2 Hello, I am a while and count is 2 Hello, I am an if statement and count is 3 Hello, I am a while and count is 3 Hello, I am an if statement and count is 4 Hello, I am a while and count is 4 Hello, I am a while and count is 5 Hello, I am a while and count is 6 Hello, I am a while and count is 7 Hello, I am a while and count is 8 Hello, I am a while and count is 9 From jglobocnik37 at gmail.com Tue Nov 28 03:14:17 2017 From: jglobocnik37 at gmail.com (jglobocnik37 at gmail.com) Date: Tue, 28 Nov 2017 00:14:17 -0800 (PST) Subject: How do I send keystrokes to a console window in Windows XP? In-Reply-To: References: <1121361775.974232.302560@g44g2000cwa.googlegroups.com> Message-ID: On Saturday, July 16, 2005 at 2:46:34 PM UTC+2, Benji York wrote: > GoogleGroups at garringer.net wrote: > > How do I use Python to send keystrokes to a console window in Windows > > XP? > > import win32com.client > > shell = win32com.client.Dispatch("WScript.Shell") > shell.AppActivate("Command Prompt") > > shell.SendKeys("cls{ENTER}") > shell.SendKeys("dir{ENTER}") > shell.SendKeys("echo Hi There{ENTER}") > -- > Benji York Hey! Do you have any idea on how to open 2 command panels at the same time and that every command would write to 1 command panel and other command to 2 command panel, when i tried to do something like this: shell.run("cmd") shell2.run("cmd") shell.AppActivate("cmd") time.sleep(5) shell.SendKeys('ffmpeg -y -f dshow -i video="Logitech HD Webcam C270" kamera'+datestring+'.mp4') shell2.SendKeys("xxxccccccccccccc{ENTER}") time.sleep(1) shell.SendKeys("{ENTER}") time.sleep(2) ffmpeg -y -f dshow -i ffmpeg -y -f dshow -i video="Logitech HD Webcam C270" kamera.mp4video="Logitech HD Webcam C270" kamera.mp4 shell.SendKeys('^c') time.sleep(2) shell.SendKeys('exit') time.sleep(1) shell.SendKeys("{ENTER}")''' everything gets in random places From frank at chagford.com Tue Nov 28 03:17:10 2017 From: frank at chagford.com (Frank Millman) Date: Tue, 28 Nov 2017 10:17:10 +0200 Subject: While, If, Count Statements In-Reply-To: References: <1236202728@f38.n261.z1.binkp.net> Message-ID: "Cai Gengyang" wrote in message news:c2dfc9c4-3e16-480c-aebf-55308177510f at googlegroups.com... > Sure, so how would the code look like if I want the "if" statement to be > nested inside the "while" loop Have you tried putting the 'if' statement inside the 'while' loop? If not, give it a shot and see what happens. Frank Millman From p.f.moore at gmail.com Tue Nov 28 03:41:00 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 28 Nov 2017 08:41:00 +0000 Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> <5eac0c8f-07f8-4a84-bf6f-b04db1b101c9@googlegroups.com> Message-ID: On 27 November 2017 at 19:05, Paul Moore wrote: > On 27 November 2017 at 18:13, Skip Montanaro wrote: >>> If you have a Windows key, you can assign it to be >>> the Compose key. >> >> Would this be true on a machine running Windows? My work environment >> has me developing on Linux, with a Windows desktop. It's not clear to >> me that any sort of xmodmap shennanigans would work. Won't Windows >> itself always gobble up that key? > > Programs can access the Windows key. IIRC, there is a utility that > provides compose-key functionality on Windows. I can't recall the name > right now and it's on my other PC, not this one, but I'll try to > remember to post the name tomorrow... WinCompose was the program - https://github.com/samhocevar/wincompose Paul From mail at timgolden.me.uk Tue Nov 28 03:46:06 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 28 Nov 2017 08:46:06 +0000 Subject: Increasing the diversity of people who write Python In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> <5eac0c8f-07f8-4a84-bf6f-b04db1b101c9@googlegroups.com> Message-ID: On 28/11/2017 08:41, Paul Moore wrote: > On 27 November 2017 at 19:05, Paul Moore wrote: >> On 27 November 2017 at 18:13, Skip Montanaro wrote: >>>> If you have a Windows key, you can assign it to be >>>> the Compose key. >>> >>> Would this be true on a machine running Windows? My work environment >>> has me developing on Linux, with a Windows desktop. It's not clear to >>> me that any sort of xmodmap shennanigans would work. Won't Windows >>> itself always gobble up that key? >> >> Programs can access the Windows key. IIRC, there is a utility that >> provides compose-key functionality on Windows. I can't recall the name >> right now and it's on my other PC, not this one, but I'll try to >> remember to post the name tomorrow... > > WinCompose was the program - https://github.com/samhocevar/wincompose And, if you wanted a Python-y solution: http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.html TJG From rosebk1989 at gmail.com Tue Nov 28 04:13:14 2017 From: rosebk1989 at gmail.com (rosebk1989 at gmail.com) Date: Tue, 28 Nov 2017 01:13:14 -0800 (PST) Subject: python training in chennai & bangalore Message-ID: Besant Technologies Chennai & Bangalore you will be able to get vast experience by transforming your ideas into actual new application and software controls for the websites and the entire computing enterprise. To make it easier for you Besant Technologies at Chennai & Bangalore is visualizing all the materials you want.Start brightening your career with us!!!! https://www.besanttechnologies.com/training-courses/python-training-institute-in-bangalore https://www.besanttechnologies.com/training-courses/python-training-institute-in-chennai From rosuav at gmail.com Tue Nov 28 04:21:45 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Nov 2017 20:21:45 +1100 Subject: How to shut down a TCPServer serve_forever() loop? In-Reply-To: <87tvxfx7l1.fsf@elektro.pacujo.net> References: <87tvxfx7l1.fsf@elektro.pacujo.net> Message-ID: On Tue, Nov 28, 2017 at 5:04 PM, Marko Rauhamaa wrote: > Ian Kelly : > >> On Sat, Nov 25, 2017 at 7:10 AM, John Pote wrote: >>> The issue is that if I press a key on the keyboard the key is >>> immediately shown on the screen but then the shutdown() call blocks >>> until another TCP connection is made, text is echoed back and only >>> then does serve_forever()return followed by shutdown()returning as >>> can be seen from the console session, >> [...] >> Make a connection to the server after calling shutdown to wake up the >> server's event loop? I'm guessing it only checks the shutdown flag >> after responding to an event, so there's probably not much else you >> could do. > > Seems to be one of the fundamental multithreading issues: each thread is > blocked on precisely one event. Asyncio is more flexible: you can > multiplex on a number of events. Not really, no. Unless select() counts as "precisely one event", of course. http://man7.org/linux/man-pages/man2/select.2.html https://en.wikipedia.org/wiki/Select_(Unix) That's the normal way for a thread to block on multiple events on a Unix system. Windows has its own approximate equivalent. Surprise, surprise, that's also how event loops often implemented. Including ones used in packages like asyncio. ChrisA From tjol at tjol.eu Tue Nov 28 04:43:46 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 28 Nov 2017 10:43:46 +0100 Subject: Increasing the diversity of people who write Python (was: Benefits of unicode identifiers) In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> Message-ID: <0a8b118c-fead-2fd9-cec9-6c0b16d40ba3@tjol.eu> On 2017-11-24 17:41, Skip Montanaro wrote: > Perhaps for my next computer I should choose a > non-ASCII keyboard option when configuring it. > > Skip > I'm quite fond of the US international keyboard layout. It lets you type most Latin-lettered languages with relative ease (including, obviously, the few accented letters used in English). It's conveniently available (and almost identical) on all (major) operating systems, but alas Windows only has a dead-keys variant built in. (But I believe you can download a no-dead-keys variant somewhere) It's nice because (with a no-dead-keys version) unless you press AltGr, everything's the same as with a traditional US keyboard (which is not entirely suitable for the English language on its own). On Windows machines I only use occasionally (and may not have admin rights on) I tend to set up both "US" and "US international" keyboard layouts and switch between them depending on what I'm typing. It's not ideal, but it's better than either programming being a pain in the arse (with all the dead keys) or not being able to type natural-language words properly. -- Thomas Jollans From breamoreboy at gmail.com Tue Nov 28 04:52:53 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Tue, 28 Nov 2017 01:52:53 -0800 (PST) Subject: nospam ** infinity? In-Reply-To: References: <3069634946@f38.n261.z1.binkp.net> Message-ID: <6ac2fb66-685e-42d7-88f2-b932aa478fa8@googlegroups.com> On Tuesday, November 28, 2017 at 1:14:51 AM UTC, Skip Montanaro wrote: > > I'm 99.5% certain it's not gate_news. > > A funny thing. All messages I have looked at so far with the "nospam" > thing have a Message-ID from binkp.net. (They are also all Usenet > posts.) For example: > > Newsgroups: comp.lang.python > Subject: Re: I have anaconda, but Pycharm can't find it > Date: Sun, 26 Nov 2017 22:40:00 +1200 > Organization: Agency BBS, Dunedin - New Zealand | bbs.geek.nz > Message-ID: <1783215345 at f38.n261.z1.binkp.net> > Mime-Version: 1.0 > > Any ideas how to investigate further? Sorry, hardly my area of expertise :-( > > Skip If it's any help there's now a message on the announce list/group subject "TatSu v4.2.5. released" with a nospam entry. -- Kindest regards. Mark Lawrence. From tjol at tjol.eu Tue Nov 28 05:17:39 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 28 Nov 2017 11:17:39 +0100 Subject: nospam ** infinity? In-Reply-To: References: <3069634946@f38.n261.z1.binkp.net> Message-ID: <5e6b4f18-1714-38f1-c2b6-f12b07343d81@tjol.eu> On 2017-11-28 02:14, Skip Montanaro wrote: >> I'm 99.5% certain it's not gate_news. > > A funny thing. All messages I have looked at so far with the "nospam" > thing have a Message-ID from binkp.net. (They are also all Usenet > posts.) For example: > > Newsgroups: comp.lang.python > Subject: Re: I have anaconda, but Pycharm can't find it > Date: Sun, 26 Nov 2017 22:40:00 +1200 > Organization: Agency BBS, Dunedin - New Zealand | bbs.geek.nz > Message-ID: <1783215345 at f38.n261.z1.binkp.net> > Mime-Version: 1.0 > > Any ideas how to investigate further? No, but with this information they should be relatively easy to filter out at the mail/news boundary, right? (It's not ideal, I know) -- Thomas Jollans From mail at timgolden.me.uk Tue Nov 28 05:57:51 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 28 Nov 2017 10:57:51 +0000 Subject: nospam ** infinity? In-Reply-To: <5e6b4f18-1714-38f1-c2b6-f12b07343d81@tjol.eu> References: <3069634946@f38.n261.z1.binkp.net> <5e6b4f18-1714-38f1-c2b6-f12b07343d81@tjol.eu> Message-ID: <78ba5429-8c1e-ac51-21b9-b94c77435b4f@timgolden.me.uk> On 28/11/2017 10:17, Thomas Jollans wrote: > On 2017-11-28 02:14, Skip Montanaro wrote: >>> I'm 99.5% certain it's not gate_news. >> >> A funny thing. All messages I have looked at so far with the "nospam" >> thing have a Message-ID from binkp.net. (They are also all Usenet >> posts.) For example: >> >> Newsgroups: comp.lang.python >> Subject: Re: I have anaconda, but Pycharm can't find it >> Date: Sun, 26 Nov 2017 22:40:00 +1200 >> Organization: Agency BBS, Dunedin - New Zealand | bbs.geek.nz >> Message-ID: <1783215345 at f38.n261.z1.binkp.net> >> Mime-Version: 1.0 >> >> Any ideas how to investigate further? > > No, but with this information they should be relatively easy to filter > out at the mail/news boundary, right? (It's not ideal, I know) I've just added a block with a regex; they seem to come in batches, so I won't know until the next batch arrives whether I've been successful. TJG From __peter__ at web.de Tue Nov 28 06:14:53 2017 From: __peter__ at web.de (Peter Otten) Date: Tue, 28 Nov 2017 12:14:53 +0100 Subject: nospam ** infinity? References: <3069634946@f38.n261.z1.binkp.net> Message-ID: Skip Montanaro wrote: >> I'm 99.5% certain it's not gate_news. > > A funny thing. All messages I have looked at so far with the "nospam" > thing have a Message-ID from binkp.net. (They are also all Usenet > posts.) For example: > > Newsgroups: comp.lang.python > Subject: Re: I have anaconda, but Pycharm can't find it > Date: Sun, 26 Nov 2017 22:40:00 +1200 > Organization: Agency BBS, Dunedin - New Zealand | bbs.geek.nz > Message-ID: <1783215345 at f38.n261.z1.binkp.net> > Mime-Version: 1.0 > > Any ideas how to investigate further? Try to contact them, or, more likely him. They seem to be into retro-computing, and there is a line X-MailConverter: SoupGate-Win32 v1.05 According to http://software.tomsweb.net/soupgate.html development of that software ended around 2000. There is a bugfix """ * Fixed bug in SoupGate that would cause hosted mailing list messages and commands to be processed normally even if they were detected as being junk mail; this could cause quite an interesting game of virtual tennis between SoupGate and "Mail Delivery Subsystem"... """ While not exactly the same, "virtual tennis" seems to be a good description of what we see now, only 17 years later... From gengyangcai at gmail.com Tue Nov 28 06:52:04 2017 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 28 Nov 2017 03:52:04 -0800 (PST) Subject: While, If, Count Statements In-Reply-To: References: <1236202728@f38.n261.z1.binkp.net> Message-ID: On Tuesday, November 28, 2017 at 4:18:04 PM UTC+8, Frank Millman wrote: > "Cai Gengyang" wrote in message > news:c2dfc9c4-3e16-480c-aebf-55308177510f at googlegroups.com... > > > Sure, so how would the code look like if I want the "if" statement to be > > nested inside the "while" loop > > Have you tried putting the 'if' statement inside the 'while' loop? > > If not, give it a shot and see what happens. > > Frank Millman I tried this : count = 0 while count < 10: if count < 5: print "Hello, I am an if statement and count is", count print "Hello, I am a while and count is", count count += 1 but it gives an "indentation error: expected an indented block" with an arrow pointing at the count after the 3rd statement. Indentation error is supposed to be an error about tabs and spaces right ? But I can't find any mistakes with it ... From frank at chagford.com Tue Nov 28 07:11:19 2017 From: frank at chagford.com (Frank Millman) Date: Tue, 28 Nov 2017 14:11:19 +0200 Subject: While, If, Count Statements In-Reply-To: References: <1236202728@f38.n261.z1.binkp.net> Message-ID: "Cai Gengyang" wrote in message news:a8335d2c-1fb9-4ba9-b752-418d19e57b01 at googlegroups.com... > > On Tuesday, November 28, 2017 at 4:18:04 PM UTC+8, Frank Millman wrote: > > "Cai Gengyang" wrote in message > > news:c2dfc9c4-3e16-480c-aebf-55308177510f at googlegroups.com... > > > > > Sure, so how would the code look like if I want the "if" statement to > > > be > > > nested inside the "while" loop > > > > Have you tried putting the 'if' statement inside the 'while' loop? > > > > If not, give it a shot and see what happens. > > > > Frank Millman > > I tried this : > > count = 0 > > while count < 10: > if count < 5: > print "Hello, I am an if statement and count is", count > print "Hello, I am a while and count is", count > count += 1 > > but it gives an "indentation error: expected an indented block" with an > arrow pointing at the count after the 3rd statement. Indentation error is > supposed to be an error about tabs and spaces right ? But I can't find any > mistakes with it ... You are almost there. An 'if' statement always requires that the following statements are indented. This applies even if you are already at one level of indentation. You could have, for example - if a == 'something': if b == 'something else': if c == 'and another one': do_something_if_a_and_b_and_c_are_true() Or in your case - while condition: if a == 'something': do_something_if_a_is_true() continue with while clause Indentation is fundamental to the way Python works, so if anything above is not clear, query it now. It is essential that you have a firm grasp of this. HTH Frank From marko at pacujo.net Tue Nov 28 07:52:20 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 28 Nov 2017 14:52:20 +0200 Subject: How to shut down a TCPServer serve_forever() loop? References: <87tvxfx7l1.fsf@elektro.pacujo.net> Message-ID: <87lgiqk1kr.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Nov 28, 2017 at 5:04 PM, Marko Rauhamaa wrote: >> Seems to be one of the fundamental multithreading issues: each thread >> is blocked on precisely one event. Asyncio is more flexible: you can >> multiplex on a number of events. > > Not really, no. Unless select() counts as "precisely one event", of > course. Select() counts as asyncio. > That's the normal way for a thread to block on multiple events on a > Unix system. Windows has its own approximate equivalent. > > Surprise, surprise, that's also how event loops often implemented. > Including ones used in packages like asyncio. The original poster's problem seems to be caused by blocking APIs that cannot be multiplexed using select(). A good many Python facilities are the same way. Such blocknoxious APIs are at the core of the multithreading programming paradigm. Marko From rosuav at gmail.com Tue Nov 28 08:00:56 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Nov 2017 00:00:56 +1100 Subject: How to shut down a TCPServer serve_forever() loop? In-Reply-To: <87lgiqk1kr.fsf@elektro.pacujo.net> References: <87tvxfx7l1.fsf@elektro.pacujo.net> <87lgiqk1kr.fsf@elektro.pacujo.net> Message-ID: On Tue, Nov 28, 2017 at 11:52 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Tue, Nov 28, 2017 at 5:04 PM, Marko Rauhamaa wrote: >>> Seems to be one of the fundamental multithreading issues: each thread >>> is blocked on precisely one event. Asyncio is more flexible: you can >>> multiplex on a number of events. >> >> Not really, no. Unless select() counts as "precisely one event", of >> course. > > Select() counts as asyncio. Hmm. So what DOESN'T count as asyncio? Because I can use multithreading with select, and in fact have done so on many occasions. It's a perfectly normal Unix kernel function. >> That's the normal way for a thread to block on multiple events on a >> Unix system. Windows has its own approximate equivalent. >> >> Surprise, surprise, that's also how event loops often implemented. >> Including ones used in packages like asyncio. > > The original poster's problem seems to be caused by blocking APIs that > cannot be multiplexed using select(). A good many Python facilities are > the same way. > > Such blocknoxious APIs are at the core of the multithreading programming > paradigm. Some things are fundamentally not multiplexable, at the lower levels. (On Linux, and I believe most other Unix-like operating systems, there's no non-blocking way to open a file, nor to gethostbyname.) How do you propose to solve those in Python? Do you have one thread that uses select() and another that does a blocking call? Do you spin off a thread to do the blocking call and then have that thread notify your main thread via a file descriptor? I don't understand why you keep insisting that asyncio and threads are somehow incompatible, or that they're a dichotomy. They're not. They work together very nicely. ChrisA From gengyangcai at gmail.com Tue Nov 28 08:56:20 2017 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 28 Nov 2017 05:56:20 -0800 (PST) Subject: While, If, Count Statements In-Reply-To: References: <1236202728@f38.n261.z1.binkp.net> Message-ID: On Tuesday, November 28, 2017 at 8:12:09 PM UTC+8, Frank Millman wrote: > "Cai Gengyang" wrote in message > news:a8335d2c-1fb9-4ba9-b752-418d19e57b01 at googlegroups.com... > > > > On Tuesday, November 28, 2017 at 4:18:04 PM UTC+8, Frank Millman wrote: > > > "Cai Gengyang" wrote in message > > > news:c2dfc9c4-3e16-480c-aebf-55308177510f at googlegroups.com... > > > > > > > Sure, so how would the code look like if I want the "if" statement to > > > > be > > > > nested inside the "while" loop > > > > > > Have you tried putting the 'if' statement inside the 'while' loop? > > > > > > If not, give it a shot and see what happens. > > > > > > Frank Millman > > > > I tried this : > > > > count = 0 > > > > while count < 10: > > if count < 5: > > print "Hello, I am an if statement and count is", count > > print "Hello, I am a while and count is", count > > count += 1 > > > > but it gives an "indentation error: expected an indented block" with an > > arrow pointing at the count after the 3rd statement. Indentation error is > > supposed to be an error about tabs and spaces right ? But I can't find any > > mistakes with it ... > > You are almost there. > > An 'if' statement always requires that the following statements are > indented. This applies even if you are already at one level of indentation. > > You could have, for example - > > if a == 'something': > if b == 'something else': > if c == 'and another one': > do_something_if_a_and_b_and_c_are_true() > > Or in your case - > > while condition: > if a == 'something': > do_something_if_a_is_true() > continue with while clause > > Indentation is fundamental to the way Python works, so if anything above is > not clear, query it now. It is essential that you have a firm grasp of this. > > HTH > > Frank It works now ! All I had to shift the 2nd "print" statement up a few spaces and it worked --- This is my code: count = 0 while count < 10: if count < 5: print "Hello, I am an if statement and count is", count print "Hello, I am a while and count is", count count += 1 Output : Hello, I am an if statement and count is 0 Hello, I am a while and count is 0 Hello, I am an if statement and count is 1 Hello, I am a while and count is 1 Hello, I am an if statement and count is 2 Hello, I am a while and count is 2 Hello, I am an if statement and count is 3 Hello, I am a while and count is 3 Hello, I am an if statement and count is 4 Hello, I am a while and count is 4 Hello, I am a while and count is 5 Hello, I am a while and count is 6 Hello, I am a while and count is 7 Hello, I am a while and count is 8 Hello, I am a while and count is 9 From nomail at com.invalid Tue Nov 28 10:30:40 2017 From: nomail at com.invalid (ast) Date: Tue, 28 Nov 2017 16:30:40 +0100 Subject: asyncio loop.call_soon() Message-ID: <5a1d8125$0$4841$426a34cc@news.free.fr> Hello Python's doc says about loop.call_soon(callback, *arg): Arrange for a callback to be called as soon as possible. The callback is called after call_soon() returns, when control returns to the event loop. But it doesn't seem to be true; see this program: import asyncio async def task_func(): print("Entering task_func") def callback(): print("Entering callback") async def main(): print("Entering main") task = loop.create_task(task_func()) loop.call_soon(callback) await task loop = asyncio.get_event_loop() loop.run_until_complete(main()) Execution provides following output: Entering main Entering task_func Entering callback callback is executed AFTER task_func, I expected it to be executed BEFORE. When "main()" coroutine reach line "await task", it let the control to the event loop, and it seems that the loop starts to execute task instead of callback. Then, when task is over the loop runs callback This is not what the doc says: callback should be called as soon as possible when the loop has control, with a priority over other tasks pending in the loop From ian.g.kelly at gmail.com Tue Nov 28 11:02:59 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 28 Nov 2017 09:02:59 -0700 Subject: asyncio loop.call_soon() In-Reply-To: <5a1d8125$0$4841$426a34cc@news.free.fr> References: <5a1d8125$0$4841$426a34cc@news.free.fr> Message-ID: On Tue, Nov 28, 2017 at 8:30 AM, ast wrote: > Hello > > Python's doc says about loop.call_soon(callback, *arg): > > Arrange for a callback to be called as soon as possible. The callback is > called after call_soon() returns, when control returns to the event loop. > > But it doesn't seem to be true; see this program: > > import asyncio > > async def task_func(): > print("Entering task_func") > > def callback(): > print("Entering callback") > > async def main(): > print("Entering main") > task = loop.create_task(task_func()) > loop.call_soon(callback) > await task > > loop = asyncio.get_event_loop() > loop.run_until_complete(main()) > > Execution provides following output: > > Entering main > Entering task_func > Entering callback > > callback is executed AFTER task_func, I expected it > to be executed BEFORE. > > When "main()" coroutine reach line "await task", it let the control to the > event loop, and it seems that the loop starts to execute task instead of > callback. Then, when task is over the loop runs callback > > This is not what the doc says: callback should be called as soon > as possible when the loop has control, with a priority over other > tasks pending in the loop You omitted this part of the documentation: "This operates as a FIFO queue, callbacks are called in the order in which they are registered. Each callback will be called exactly once." This documents the ordering of call_soon callbacks. It doesn't say anything about how the callback will be ordered with respect to tasks or other events that are also immediately ready to be handled. Also, if you look at the implementation of create_task, it invokes call_soon. This is therefore consistent with the doc, as call_soon was actually called twice: first for task_func(), and then for callback. From cloverobert at gmail.com Tue Nov 28 12:10:17 2017 From: cloverobert at gmail.com (Robert Clove) Date: Tue, 28 Nov 2017 22:40:17 +0530 Subject: Has anyone worked on docker with windows Message-ID: Hi, what am i trying to achieve is, container of windows with an application like slack on it. Does window container has an UI? Has anyone worked on it, is it feasible? From marko at pacujo.net Tue Nov 28 12:22:35 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 28 Nov 2017 19:22:35 +0200 Subject: How to shut down a TCPServer serve_forever() loop? References: <87tvxfx7l1.fsf@elektro.pacujo.net> <87lgiqk1kr.fsf@elektro.pacujo.net> Message-ID: <87k1yaxqqs.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Nov 28, 2017 at 11:52 PM, Marko Rauhamaa wrote: >> The original poster's problem seems to be caused by blocking APIs that >> cannot be multiplexed using select(). A good many Python facilities are >> the same way. >> >> Such blocknoxious APIs are at the core of the multithreading programming >> paradigm. > > Some things are fundamentally not multiplexable, at the lower levels. Said function is not. Neither are, say, database methods or web operations. Yet, they are commonly implemented in a blocking fashion. > (On Linux, and I believe most other Unix-like operating systems, > there's no non-blocking way to open a file, nor to gethostbyname.) The file access problem is a fundamental glitch in Linux, but gethostbyname() is just a silly POSIX API. > How do you propose to solve those in Python? I have solved the gethostbyname() problem by implementing the DNS protocol myself (in Python). The file access issue is philosophically somewhat deep; Linux essentially treats files as memory and vice versa. If it became an issue, I'd have to launch a file server process. > I don't understand why you keep insisting that asyncio and threads are > somehow incompatible, Where did I say that? Marko From rosuav at gmail.com Tue Nov 28 12:29:36 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Nov 2017 04:29:36 +1100 Subject: How to shut down a TCPServer serve_forever() loop? In-Reply-To: <87k1yaxqqs.fsf@elektro.pacujo.net> References: <87tvxfx7l1.fsf@elektro.pacujo.net> <87lgiqk1kr.fsf@elektro.pacujo.net> <87k1yaxqqs.fsf@elektro.pacujo.net> Message-ID: On Wed, Nov 29, 2017 at 4:22 AM, Marko Rauhamaa wrote: > I have solved the gethostbyname() problem by implementing the DNS > protocol myself (in Python). Do you respect /etc/nsswitch.conf? >> I don't understand why you keep insisting that asyncio and threads are >> somehow incompatible, > > Where did I say that? You talk about them as if they're fundamentally different. ChrisA From marko at pacujo.net Tue Nov 28 13:03:50 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 28 Nov 2017 20:03:50 +0200 Subject: How to shut down a TCPServer serve_forever() loop? References: <87tvxfx7l1.fsf@elektro.pacujo.net> <87lgiqk1kr.fsf@elektro.pacujo.net> <87k1yaxqqs.fsf@elektro.pacujo.net> Message-ID: <87a7z6xou1.fsf@elektro.pacujo.net> Chris Angelico : > On Wed, Nov 29, 2017 at 4:22 AM, Marko Rauhamaa wrote: >> I have solved the gethostbyname() problem by implementing the DNS >> protocol myself (in Python). > > Do you respect /etc/nsswitch.conf? No, but I don't need to. >>> I don't understand why you keep insisting that asyncio and threads >>> are somehow incompatible, >> >> Where did I say that? > > You talk about them as if they're fundamentally different. In this discussion I was referring to the fact that you can interrupt a coroutine while that is generally not possible to do to a blocking thread. Marko From rosuav at gmail.com Tue Nov 28 13:11:50 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Nov 2017 05:11:50 +1100 Subject: How to shut down a TCPServer serve_forever() loop? In-Reply-To: <87a7z6xou1.fsf@elektro.pacujo.net> References: <87tvxfx7l1.fsf@elektro.pacujo.net> <87lgiqk1kr.fsf@elektro.pacujo.net> <87k1yaxqqs.fsf@elektro.pacujo.net> <87a7z6xou1.fsf@elektro.pacujo.net> Message-ID: On Wed, Nov 29, 2017 at 5:03 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Wed, Nov 29, 2017 at 4:22 AM, Marko Rauhamaa wrote: >>> I have solved the gethostbyname() problem by implementing the DNS >>> protocol myself (in Python). >> >> Do you respect /etc/nsswitch.conf? > > No, but I don't need to. Ah, right. Until the day you're wrestling with "why doesn't /etc/hosts apply to this program". Yep, you totally don't need nsswitch. >>>> I don't understand why you keep insisting that asyncio and threads >>>> are somehow incompatible, >>> >>> Where did I say that? >> >> You talk about them as if they're fundamentally different. > > In this discussion I was referring to the fact that you can interrupt a > coroutine while that is generally not possible to do to a blocking > thread. I'm not sure what you mean by a "blocking thread". Whether it's a coroutine or not, you can't interrupt gethostbyname(); and whether it's a coroutine or not, you CAN interrupt any syscall that responds to signals (that's the whole point of EINTR). ChrisA From marko at pacujo.net Tue Nov 28 13:32:45 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 28 Nov 2017 20:32:45 +0200 Subject: How to shut down a TCPServer serve_forever() loop? References: <87tvxfx7l1.fsf@elektro.pacujo.net> <87lgiqk1kr.fsf@elektro.pacujo.net> <87k1yaxqqs.fsf@elektro.pacujo.net> <87a7z6xou1.fsf@elektro.pacujo.net> Message-ID: <87609uxnhu.fsf@elektro.pacujo.net> Chris Angelico : > On Wed, Nov 29, 2017 at 5:03 AM, Marko Rauhamaa wrote: >> Chris Angelico : >>> Do you respect /etc/nsswitch.conf? >> >> No, but I don't need to. > > Ah, right. Until the day you're wrestling with "why doesn't /etc/hosts > apply to this program". Yep, you totally don't need nsswitch. Don't you worry about my programs. >> In this discussion I was referring to the fact that you can interrupt >> a coroutine while that is generally not possible to do to a blocking >> thread. > > I'm not sure what you mean by a "blocking thread". Whether it's a > coroutine or not, you can't interrupt gethostbyname(); and whether > it's a coroutine or not, you CAN interrupt any syscall that responds > to signals (that's the whole point of EINTR). Please reread the original poster's question. It was about a blocking TCP listener call that another thread couldn't interrupt. Marko From rosuav at gmail.com Tue Nov 28 13:39:32 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Nov 2017 05:39:32 +1100 Subject: How to shut down a TCPServer serve_forever() loop? In-Reply-To: <87609uxnhu.fsf@elektro.pacujo.net> References: <87tvxfx7l1.fsf@elektro.pacujo.net> <87lgiqk1kr.fsf@elektro.pacujo.net> <87k1yaxqqs.fsf@elektro.pacujo.net> <87a7z6xou1.fsf@elektro.pacujo.net> <87609uxnhu.fsf@elektro.pacujo.net> Message-ID: On Wed, Nov 29, 2017 at 5:32 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Wed, Nov 29, 2017 at 5:03 AM, Marko Rauhamaa wrote: >>> Chris Angelico : >>>> Do you respect /etc/nsswitch.conf? >>> >>> No, but I don't need to. >> >> Ah, right. Until the day you're wrestling with "why doesn't /etc/hosts >> apply to this program". Yep, you totally don't need nsswitch. > > Don't you worry about my programs. Okay, but you can't claim that problems are solvable if you cheat them. >>> In this discussion I was referring to the fact that you can interrupt >>> a coroutine while that is generally not possible to do to a blocking >>> thread. >> >> I'm not sure what you mean by a "blocking thread". Whether it's a >> coroutine or not, you can't interrupt gethostbyname(); and whether >> it's a coroutine or not, you CAN interrupt any syscall that responds >> to signals (that's the whole point of EINTR). > > Please reread the original poster's question. It was about a blocking > TCP listener call that another thread couldn't interrupt. Yet a SIGINT would successfully interrupt it. I'm not sure what your point is. Would the OP have been trivially able to switch to asyncio? Maybe. Would the OP have been trivially able to send a signal to the process? Yes. I'm done arguing. You're clearly not listening. ChrisA From marko at pacujo.net Tue Nov 28 13:54:53 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 28 Nov 2017 20:54:53 +0200 Subject: How to shut down a TCPServer serve_forever() loop? References: <87tvxfx7l1.fsf@elektro.pacujo.net> <87lgiqk1kr.fsf@elektro.pacujo.net> <87k1yaxqqs.fsf@elektro.pacujo.net> <87a7z6xou1.fsf@elektro.pacujo.net> <87609uxnhu.fsf@elektro.pacujo.net> Message-ID: <871skixmgy.fsf@elektro.pacujo.net> Chris Angelico : > On Wed, Nov 29, 2017 at 5:32 AM, Marko Rauhamaa wrote: >> Don't you worry about my programs. > > Okay, but you can't claim that problems are solvable if you cheat them. What I'm saying is that there's no particular reason why glibc couldn't offer a solution. There *is* getaddrinfo_a(), but that's suboptimal because it uses signals and (probably) a subsidiary thread. Instead, it should offer a file descriptor for the application to monitor. >> Please reread the original poster's question. It was about a blocking >> TCP listener call that another thread couldn't interrupt. > > Yet a SIGINT would successfully interrupt it. A keyboard interrupt? That your magic bullet? How does that work in practice? > Would the OP have been trivially able to send a signal to the > process? Yes. Python signal handlers are always executed in the main Python thread, even if the signal was received in another thread. This means that signals can?t be used as a means of inter-thread communication. Marko From ian.g.kelly at gmail.com Tue Nov 28 14:04:10 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 28 Nov 2017 12:04:10 -0700 Subject: How to shut down a TCPServer serve_forever() loop? In-Reply-To: <871skixmgy.fsf@elektro.pacujo.net> References: <87tvxfx7l1.fsf@elektro.pacujo.net> <87lgiqk1kr.fsf@elektro.pacujo.net> <87k1yaxqqs.fsf@elektro.pacujo.net> <87a7z6xou1.fsf@elektro.pacujo.net> <87609uxnhu.fsf@elektro.pacujo.net> <871skixmgy.fsf@elektro.pacujo.net> Message-ID: On Tue, Nov 28, 2017 at 11:54 AM, Marko Rauhamaa wrote: > Chris Angelico : >> Would the OP have been trivially able to send a signal to the >> process? Yes. > > Python signal handlers are always executed in the main Python thread, > even if the signal was received in another thread. This means that > signals can?t be used as a means of inter-thread communication. > > Being received in the other thread, it would still interrupt the system call however, wouldn't it? Quoting from the doc: "However, if the target thread is executing the Python interpreter, the Python signal handlers will be executed by the main thread. Therefore, the only point of sending a signal to a particular Python thread would be to force a running system call to fail with InterruptedError." From tjreedy at udel.edu Tue Nov 28 14:25:52 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 28 Nov 2017 14:25:52 -0500 Subject: asyncio loop.call_soon() In-Reply-To: References: <5a1d8125$0$4841$426a34cc@news.free.fr> Message-ID: On 11/28/2017 11:02 AM, Ian Kelly wrote: > On Tue, Nov 28, 2017 at 8:30 AM, ast wrote: >> Hello >> >> Python's doc says about loop.call_soon(callback, *arg): >> >> Arrange for a callback to be called as soon as possible. The callback is >> called after call_soon() returns, when control returns to the event loop. >> >> But it doesn't seem to be true; see this program: >> >> import asyncio >> >> async def task_func(): >> print("Entering task_func") >> >> def callback(): >> print("Entering callback") >> >> async def main(): >> print("Entering main") >> task = loop.create_task(task_func()) >> loop.call_soon(callback) >> await task >> >> loop = asyncio.get_event_loop() >> loop.run_until_complete(main()) >> >> Execution provides following output: >> >> Entering main >> Entering task_func >> Entering callback >> >> callback is executed AFTER task_func, I expected it >> to be executed BEFORE. >> >> When "main()" coroutine reach line "await task", it let the control to the >> event loop, and it seems that the loop starts to execute task instead of >> callback. Then, when task is over the loop runs callback >> >> This is not what the doc says: callback should be called as soon >> as possible when the loop has control, with a priority over other >> tasks pending in the loop > > You omitted this part of the documentation: > > "This operates as a FIFO queue, callbacks are called in the order in > which they are registered. Each callback will be called exactly once." > > This documents the ordering of call_soon callbacks. It doesn't say > anything about how the callback will be ordered with respect to tasks > or other events that are also immediately ready to be handled. > > Also, if you look at the implementation of create_task, it invokes > call_soon. This is therefore consistent with the doc, as call_soon was > actually called twice: first for task_func(), and then for callback. I believe that this means that any code in the coroutine *before* the first await is run immediately. This is what I experienced in my experiments yesterday. -- Terry Jan Reedy From martin.schoon at gmail.com Tue Nov 28 16:23:28 2017 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 28 Nov 2017 21:23:28 GMT Subject: Pros and cons of Python sources? References: <20171127211412.GA79125@cskk.homeip.net> Message-ID: Den 2017-11-27 skrev Cameron Simpson : > > But if the package is mainstream you're probably ok? You could just live with > it and do no more damage. > > Otherwise, look to see what python packages are installed which you think you > may have pipped, and reinstall those. But also, pip tends not to install things > that are already present, so you might be fine. > The reason I think all is not well is the fact that pip list no only results in a list of packages but at the end of the list (which does not look complete) there is a bunch of error messages. Running Python scripts has worked without issues so far. /Martin From cs at cskk.id.au Tue Nov 28 16:29:55 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 29 Nov 2017 08:29:55 +1100 Subject: Pros and cons of Python sources? In-Reply-To: References: Message-ID: <20171128212955.GA77940@cskk.homeip.net> On 28Nov2017 21:23, Martin Sch??n wrote: >Den 2017-11-27 skrev Cameron Simpson : >> But if the package is mainstream you're probably ok? You could just live >> with it and do no more damage. >> >> Otherwise, look to see what python packages are installed which you think you >> may have pipped, and reinstall those. But also, pip tends not to install things >> that are already present, so you might be fine. >> >The reason I think all is not well is the fact that pip list no only >results in a list of packages but at the end of the list (which does >not look complete) there is a bunch of error messages. Please post them. Maybe someone has some insight. (Also post the pip command itself producing the messages.) >Running Python scripts has worked without issues so far. Fingers crossed. Cheers, Cameron Simpson (formerly cs at zip.com.au) Real computer scientists don't comment their code. The identifiers are so long they can't afford the disk space. From greg.ewing at canterbury.ac.nz Tue Nov 28 23:44:25 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 29 Nov 2017 17:44:25 +1300 Subject: Increasing the diversity of people who write Python In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> <5eac0c8f-07f8-4a84-bf6f-b04db1b101c9@googlegroups.com> Message-ID: Chris Angelico wrote: > Heh, you mean the term "Windows key"? It's not appropriate on > keyboards that don't have an actual Windows logo on it. There are > other names for it, but I figured the easiest way was to describe its > location :D That doesn't work for all keyboards, though. The one I'm using right now doesn't have any key between the left alt and left control keys. (It does have another key just to the right of the alt key that might have roughly analogous functionality in some circumstances.) -- Greg From rosuav at gmail.com Wed Nov 29 00:25:31 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Nov 2017 16:25:31 +1100 Subject: Increasing the diversity of people who write Python In-Reply-To: References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> <5eac0c8f-07f8-4a84-bf6f-b04db1b101c9@googlegroups.com> Message-ID: On Wed, Nov 29, 2017 at 3:44 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> Heh, you mean the term "Windows key"? It's not appropriate on >> keyboards that don't have an actual Windows logo on it. There are >> other names for it, but I figured the easiest way was to describe its >> location :D > > > That doesn't work for all keyboards, though. The one I'm using > right now doesn't have any key between the left alt and left > control keys. (It does have another key just to the right of > the alt key that might have roughly analogous functionality in > some circumstances.) > Yeah, which is why it's completely configurable. I was just saying which key *I* use, on my particular layout. ChrisA From pjh at nanoworks.com Wed Nov 29 01:52:32 2017 From: pjh at nanoworks.com (Percival John Hackworth) Date: Tue, 28 Nov 2017 22:52:32 -0800 Subject: Has anyone worked on docker with windows References: Message-ID: <0001HW.1FCE90B00107AF3D14E0E52CF@news.individual.net> On 28-Nov-2017, Robert Clove wrote (in article): > Hi, > > what am i trying to achieve is, container of windows with an application > like slack on it. > Does window container has an UI? > > Has anyone worked on it, is it feasible? AFAIK, docker is linux/CoreOS only. Ask docker.com this question. AFAIK, the only way to get docker to run on Windows is to run docker-machine with virtual box. That's a coreOS VM. From auriocus at gmx.de Wed Nov 29 01:52:45 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 29 Nov 2017 07:52:45 +0100 Subject: Increasing the diversity of people who write Python In-Reply-To: <7f75ff28-38e4-41c9-85a0-42c0190d3669@googlegroups.com> References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> <7f75ff28-38e4-41c9-85a0-42c0190d3669@googlegroups.com> Message-ID: Am 28.11.17 um 20:24 schrieb wxjmfauth at gmail.com: > Le mardi 28 novembre 2017 04:44:51 UTC+1, Rustom Mody a ?crit?: >> ... >> >> Unicode codepoint names are (evidently) ALLCAPS-ASCII >> > > Are you sure ? ;-) > > > ; Standard Unicode 10.0.0 ou > ; Norme internationale ISO/CEI 10646:2017 > > ... > > 00FF LETTRE MINUSCULE LATINE Y TR?MA WTF is this? The character is correctly called "LATIN SMALL LETTER Y WITH DIAERESIS". There is no non-ASCII character in this description. Of course, if I translated the Unicode mapping to Polish, there would be an even larger number of non-ASCII letters - but what good would that be for an IT standard, if the identifiers were written in different languages? Christian From cloverobert at gmail.com Wed Nov 29 02:05:25 2017 From: cloverobert at gmail.com (Robert Clove) Date: Wed, 29 Nov 2017 12:35:25 +0530 Subject: Has anyone worked on docker with windows In-Reply-To: <0001HW.1FCE90B00107AF3D14E0E52CF@news.individual.net> References: <0001HW.1FCE90B00107AF3D14E0E52CF@news.individual.net> Message-ID: i was also of the same opinion , but docker is available on windows too https://www.docker.com/docker-windows On Wed, Nov 29, 2017 at 12:22 PM, Percival John Hackworth wrote: > On 28-Nov-2017, Robert Clove wrote > (in article): > > > Hi, > > > > what am i trying to achieve is, container of windows with an application > > like slack on it. > > Does window container has an UI? > > > > Has anyone worked on it, is it feasible? > > AFAIK, docker is linux/CoreOS only. Ask docker.com this question. AFAIK, > the > only way to get docker to run on Windows is to run docker-machine with > virtual box. That's a coreOS VM. > > -- > https://mail.python.org/mailman/listinfo/python-list > From marko at pacujo.net Wed Nov 29 02:33:58 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 29 Nov 2017 09:33:58 +0200 Subject: Increasing the diversity of people who write Python References: <20171123200406.wzyv4ffhynz7jqqz@hermes.hilbert.loc> <85r2souy6e.fsf_-_@benfinney.id.au> <9970e8b0-47cb-4b7e-b1be-ff2a6cbdc5e0@googlegroups.com> <7f75ff28-38e4-41c9-85a0-42c0190d3669@googlegroups.com> Message-ID: <87shcxwnbt.fsf@elektro.pacujo.net> Christian Gollwitzer : > Am 28.11.17 um 20:24 schrieb wxjmfauth at gmail.com: >> 00FF LETTRE MINUSCULE LATINE Y TR?MA > > WTF is this? The character is correctly called > "LATIN SMALL LETTER Y WITH DIAERESIS". There is no non-ASCII character > in this description. Of course, if I translated the Unicode mapping to > Polish, there would be an even larger number of non-ASCII letters - > but what good would that be for an IT standard, if the identifiers > were written in different languages? The ISO/IEC standards are issued in many languages. French and English have the strongest footing; French is maybe slightly more primary than English. Marko From m at funkyhat.org Wed Nov 29 09:01:41 2017 From: m at funkyhat.org (Matt Wheeler) Date: Wed, 29 Nov 2017 14:01:41 +0000 (UTC) Subject: Compile Python 3 interpreter to force 2-byte unicode In-Reply-To: <7a976d89-bb3a-4854-a5be-d606def3c86c@googlegroups.com> References: <7a976d89-bb3a-4854-a5be-d606def3c86c@googlegroups.com> Message-ID: On Sun, 26 Nov 2017, 19:46 , wrote: > On Sunday, November 26, 2017 at 1:00:19 AM UTC+1, Terry Reedy wrote: > I have to fix a bug in my C extension that appears only in UCS-2 python > (i.e. Windows). I can reboot to Windows and debug there, but it's pain > in a neck for various reasons. > In my opinion if you want to fix a bug that shows up only on Windows, you need to test it on Windows. It's likely that you're right and a narrow build of python 2 on Linux will expose and enable you to debug the same issue, but have you ruled out the possibility of any other cross-platform incompatibilities playing a part? > -- -- Matt Wheeler http://funkyh.at From storchaka at gmail.com Wed Nov 29 09:57:11 2017 From: storchaka at gmail.com (Serhiy Storchaka) Date: Wed, 29 Nov 2017 16:57:11 +0200 Subject: Compile Python 3 interpreter to force 2-byte unicode In-Reply-To: <7a976d89-bb3a-4854-a5be-d606def3c86c@googlegroups.com> References: <7a976d89-bb3a-4854-a5be-d606def3c86c@googlegroups.com> Message-ID: 26.11.17 21:46, wojtek.mula at gmail.com ????: > On Sunday, November 26, 2017 at 1:00:19 AM UTC+1, Terry Reedy wrote: >> You must be trying to compile 2.7. There may be Linux distributions >> that compile this way. > > You're right, I need 2.7. Any hint which distro has got these settings? UCS-2 is used by default. Most Linux distributions build Python with UCS-4, but you don't need to change the defaults for building a narrow Unicode build. From zljubisic at gmail.com Wed Nov 29 15:26:29 2017 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Wed, 29 Nov 2017 12:26:29 -0800 (PST) Subject: Python loop and web server (bottle) in the same script (Posting On Python-List Prohibited) In-Reply-To: References: <0ee995bd-40eb-46dd-aa61-1e4b1cee10cf@googlegroups.com> Message-ID: <01e612aa-8a00-485c-a028-3d3707cb3531@googlegroups.com> Processing is I/O and CPU bound. :( From martin.schoon at gmail.com Wed Nov 29 15:46:26 2017 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 29 Nov 2017 20:46:26 GMT Subject: Pros and cons of Python sources? References: <20171128212955.GA77940@cskk.homeip.net> Message-ID: Den 2017-11-28 skrev Cameron Simpson : > On 28Nov2017 21:23, Martin Sch??n wrote: >>The reason I think all is not well is the fact that pip list no only >>results in a list of packages but at the end of the list (which does >>not look complete) there is a bunch of error messages. > > Please post them. Maybe someone has some insight. (Also post the pip command > itself producing the messages.) > >From pip.log: /usr/bin/pip run on Tue Nov 28 22:54:09 2017 apptools (4.2.1) apt-xapian-index (0.47) arandr (0.1.7.1) argparse (1.2.1) pip (1.5.6) Pivy (0.5.0) ply (3.4) Pmw (1.3.2) pyalsaaudio (0.7) pyasn1 (0.1.7) Exception: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main status = self.run(options, args) File "/usr/lib/python2.7/dist-packages/pip/commands/list.py", line 80, in run self.run_listing(options) File "/usr/lib/python2.7/dist-packages/pip/commands/list.py", line 142, in run_listing self.output_package_listing(installed_packages) File "/usr/lib/python2.7/dist-packages/pip/commands/list.py", line 151, in output_package_listing if dist_is_editable(dist): File "/usr/lib/python2.7/dist-packages/pip/util.py", line 367, in dist_is_editable req = FrozenRequirement.from_dist(dist,[]) File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 299, in from_dist assert len(specs) == 1 and specs[0][0] == '==' AssertionError The line breaks of the error messages are mangled but I hope it makes sense. >>Running Python scripts has worked without issues so far. > > Fingers crossed. Indeed. /Martin From irving.duran at gmail.com Wed Nov 29 16:52:44 2017 From: irving.duran at gmail.com (Irving Duran) Date: Wed, 29 Nov 2017 15:52:44 -0600 Subject: Has anyone worked on docker with windows In-Reply-To: References: <0001HW.1FCE90B00107AF3D14E0E52CF@news.individual.net> Message-ID: I attempted configuring docker on Win, but quit. This was like six months ago, I will assume that the install and integration with the VM is smoother now, but still not native to Win. Thank You, Irving Duran On Wed, Nov 29, 2017 at 1:05 AM, Robert Clove wrote: > i was also of the same opinion , but docker is available on windows too > https://www.docker.com/docker-windows > > > On Wed, Nov 29, 2017 at 12:22 PM, Percival John Hackworth < > pjh at nanoworks.com > > wrote: > > > On 28-Nov-2017, Robert Clove wrote > > (in article): > > > > > Hi, > > > > > > what am i trying to achieve is, container of windows with an > application > > > like slack on it. > > > Does window container has an UI? > > > > > > Has anyone worked on it, is it feasible? > > > > AFAIK, docker is linux/CoreOS only. Ask docker.com this question. AFAIK, > > the > > only way to get docker to run on Windows is to run docker-machine with > > virtual box. That's a coreOS VM. > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > From fabiofz at gmail.com Wed Nov 29 19:41:48 2017 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Wed, 29 Nov 2017 22:41:48 -0200 Subject: PyDev 6.2.0 released Message-ID: PyDev 6.2.0 Release Highlights - *Interactive Console* - It's possible to use word-wrapping in the PyDev interactive console ( *#PyDev-862*). - *Code Completion* - Checking list unpacking with user specified types. - Code completion aware of variable typing from Python 3.6 ( *#PyDev-866*). - *Others* - Properly terminating child processes of launched python processes on Linux with Java 9 (*#PyDev-871*). - Comments with 3 dashes properly appear in outline in all cases ( *#PyDev-868*). - Properly hyperlinking pytest output. - Accepting *noqa* as a way to skip errors (*#PyDev-814*). - If there's a *flake8: noqa* in the first 3 lines of the file, don't analyze it (*#PyDev-814*). - Fixed issue where a closing peer character was skiped when it was actually not a matching closing peer (*#PyDev-869*). - Fixed issue where line indentation was not correct on a new line with multiple open parenthesis. What is PyDev? PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com What is LiClipse? LiClipse is a PyDev standalone with goodies such as support for Multiple cursors, theming, TextMate bundles and a number of other languages such as Django Templates, Jinja2, Kivy Language, Mako Templates, Html, Javascript, etc. It's also a commercial counterpart which helps supporting the development of PyDev. Details on LiClipse: http://www.liclipse.com/ Cheers, -- Fabio Zadrozny ------------------------------ Software Developer LiClipse http://www.liclipse.com PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com PyVmMonitor - Python Profiler http://www.pyvmmonitor.com/? From waylan.limberg at icloud.com Wed Nov 29 20:06:05 2017 From: waylan.limberg at icloud.com (waylan) Date: Wed, 29 Nov 2017 17:06:05 -0800 (PST) Subject: How to upload to Pythonhosted.org Message-ID: <5a949de0-9fdd-4637-adf4-22c3535d4c54@googlegroups.com> I've been hosting documentation for many years on pythonhosted.org. However, I can't seem to upload any updates recently. The homepage at http://pythonhosted.org states: > To upload documentation, go to your package edit page (http://pypi.python.org/pypi?%3Aaction=pkg_edit&name=yourpackage), and fill out the form at the bottom of the page. However, there is no longer a form at the bottom of the edit page for uploading documentation. Instead I only see: > If you would like to DESTROY any existing documentation hosted at http://pythonhosted.org/ProjectName Use this button, There is no undo. > > [Destroy Documentation] I also went to pypi.org and logged in there. But I don't see any options for editing my projects or uploading documentation on that site. So, how do I upload an update to my documentation? Waylan From irmen.NOSPAM at xs4all.nl Wed Nov 29 20:41:13 2017 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Thu, 30 Nov 2017 02:41:13 +0100 Subject: How to upload to Pythonhosted.org In-Reply-To: <5a949de0-9fdd-4637-adf4-22c3535d4c54@googlegroups.com> References: <5a949de0-9fdd-4637-adf4-22c3535d4c54@googlegroups.com> Message-ID: <5a1f61b9$0$10045$e4fe514c@news.xs4all.nl> On 11/30/2017 02:06 AM, waylan wrote: > I've been hosting documentation for many years on pythonhosted.org. However, I can't seem to upload any updates recently. The homepage at http://pythonhosted.org states: > >> To upload documentation, go to your package edit page (http://pypi.python.org/pypi?%3Aaction=pkg_edit&name=yourpackage), and fill out the form at the bottom of the page. > > However, there is no longer a form at the bottom of the edit page for uploading documentation. Instead I only see: > >> If you would like to DESTROY any existing documentation hosted at http://pythonhosted.org/ProjectName Use this button, There is no undo. >> >> [Destroy Documentation] > > I also went to pypi.org and logged in there. But I don't see any options for editing my projects or uploading documentation on that site. > > So, how do I upload an update to my documentation? > > Waylan > I ran into the same issue. From what I gathered, Pythonhosted.org is in the process of being dismantled and it hasn't allowed new doc uploads for quite some time now. I switched to using readthedocs.io instead. That one is faster and has the additional benefit that you can configure it in such a way that you don't have to upload docs yourself anymore; it can rebuild them on the fly when it detects a change in your github repo Irmen From ben+python at benfinney.id.au Wed Nov 29 21:31:06 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 30 Nov 2017 13:31:06 +1100 Subject: How to upload to Pythonhosted.org References: <5a949de0-9fdd-4637-adf4-22c3535d4c54@googlegroups.com> <5a1f61b9$0$10045$e4fe514c@news.xs4all.nl> Message-ID: <851skgv6ol.fsf@benfinney.id.au> Irmen de Jong writes: > On 11/30/2017 02:06 AM, waylan wrote: > > So, how do I upload an update to my documentation? > > I ran into the same issue. From what I gathered, Pythonhosted.org is > in the process of being dismantled and it hasn't allowed new doc > uploads for quite some time now. I switched to using readthedocs.io > instead. The issue that many are facing is how to update the pages *at the existing URL* to tell visitors where to go next. Cool URIs don't change but, when they do, we are obliged to update the existing pages to point to the new ones. So, if pythonhosted.org is indeed being dismantled, there should be a way to update the pages there for informing visitor where they should go next. If that's not possible and instead the service is just locked down, that's IMO a mistake. -- \ ?You can't have everything; where would you put it?? ?Steven | `\ Wright | _o__) | Ben Finney From pjh at nanoworks.com Wed Nov 29 23:03:02 2017 From: pjh at nanoworks.com (Percival John Hackworth) Date: Wed, 29 Nov 2017 20:03:02 -0800 Subject: Has anyone worked on docker with windows References: <0001HW.1FCE90B00107AF3D14E0E52CF@news.individual.net> Message-ID: <0001HW.1FCFBA76014D790414BB022CF@news.individual.net> On 28-Nov-2017, Robert Clove wrote (in article): > i was also of the same opinion , but docker is available on windows too > https://www.docker.com/docker-windows > > On Wed, Nov 29, 2017 at 12:22 PM, Percival John Hackworth > wrote: > > > On 28-Nov-2017, Robert Clove wrote > > (in article): > > > > > Hi, > > > > > > what am i trying to achieve is, container of windows with an application > > > like slack on it. > > > Does window container has an UI? > > > > > > Has anyone worked on it, is it feasible? > > > > AFAIK, docker is linux/CoreOS only. Ask docker.com this question. AFAIK, > > the > > only way to get docker to run on Windows is to run docker-machine with > > virtual box. That's a coreOS VM. > > > > -- > > https://mail.python.org/mailman/listinfo/python-list To clarify, I think the OP was asking if they could Windows inside a Docker container. Since Docker uses the kernel of the OS it's running on, that would mean it would have to run natively on Windows. Back in January, it didn't run on Windows. Now apparently you can run a Windows 10 or Server 2016 environment in a container. I would think, given the architecture of Docker, that you can only do this on a Windows machine, not a Linux box. So the ability to containerize an application on Linux and run it anywhere Docker is installed (even MacOS) only applicable to Linux apps. From pjh at nanoworks.com Wed Nov 29 23:06:09 2017 From: pjh at nanoworks.com (Percival John Hackworth) Date: Wed, 29 Nov 2017 20:06:09 -0800 Subject: Has anyone worked on docker with windows References: <0001HW.1FCE90B00107AF3D14E0E52CF@news.individual.net> Message-ID: <0001HW.1FCFBB31014DA4F814BB022CF@news.individual.net> On 29-Nov-2017, Irving Duran wrote (in article): > I attempted configuring docker on Win, but quit. This was like six months > ago, I will assume that the install and integration with the VM is smoother > now, but still not native to Win. > > Thank You, > > Irving Duran > > On Wed, Nov 29, 2017 at 1:05 AM, Robert Clove wrote: > > > i was also of the same opinion , but docker is available on windows too > > https://www.docker.com/docker-windows > > > > > > On Wed, Nov 29, 2017 at 12:22 PM, Percival John Hackworth< > > pjh at nanoworks.com > > > wrote: > > > > > On 28-Nov-2017, Robert Clove wrote > > > (in article): > > > > > > > Hi, > > > > > > > > what am i trying to achieve is, container of windows with an > > application > > > > like slack on it. > > > > Does window container has an UI? > > > > > > > > Has anyone worked on it, is it feasible? > > > > > > AFAIK, docker is linux/CoreOS only. Ask docker.com this question. AFAIK, > > > the > > > only way to get docker to run on Windows is to run docker-machine with > > > virtual box. That's a coreOS VM. > > > > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > -- > > https://mail.python.org/mailman/listinfo/python-list According to the Docker.io web site, Docker on Windows is native, like the MacOS version of docker. But you can probably only run Windows containers on a windows machine, not a Linux machine. I don't know if you can build a Linux container on Windows and have it work on a Linux box. If Docker for Windows only works on Windows 10 or Server 2016, that may work. I read that there's a linux that runs under Windows 10, so Docker is probably using that. From irmen.NOSPAM at xs4all.nl Thu Nov 30 13:47:04 2017 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Thu, 30 Nov 2017 19:47:04 +0100 Subject: How to upload to Pythonhosted.org In-Reply-To: References: <5a949de0-9fdd-4637-adf4-22c3535d4c54@googlegroups.com> <5a1f61b9$0$10045$e4fe514c@news.xs4all.nl> <851skgv6ol.fsf@benfinney.id.au> Message-ID: <5a205228$0$10072$e4fe514c@news.xs4all.nl> On 11/30/2017 03:31 AM, Ben Finney wrote: > Irmen de Jong writes: > >> On 11/30/2017 02:06 AM, waylan wrote: >>> So, how do I upload an update to my documentation? >> >> I ran into the same issue. From what I gathered, Pythonhosted.org is >> in the process of being dismantled and it hasn't allowed new doc >> uploads for quite some time now. I switched to using readthedocs.io >> instead. > > The issue that many are facing is how to update the pages *at the > existing URL* to tell visitors where to go next. Cool URIs don't change > but, when they do, we > are obliged to update the existing pages to point to the new ones. Sorry, yes, that is the problem I experience as well. My library's old version documentation is somehow frozen on Pythonhosted.org (and obviously still pops up as the first few google hits). > So, if pythonhosted.org is indeed being dismantled, there should be a > way to update the pages there for informing visitor where they should go > next. > > If that's not possible and instead the service is just locked down, > that's IMO a mistake. I agree with that. I think it's an unsolved issue until now, that gets some discussion in this github issue https://github.com/pypa/warehouse/issues/582 Irmen From torriem at gmail.com Thu Nov 30 13:49:16 2017 From: torriem at gmail.com (Michael Torrie) Date: Thu, 30 Nov 2017 11:49:16 -0700 Subject: [OT] - Re: Has anyone worked on docker with windows In-Reply-To: <0001HW.1FCFBA76014D790414BB022CF@news.individual.net> References: <0001HW.1FCE90B00107AF3D14E0E52CF@news.individual.net> <0001HW.1FCFBA76014D790414BB022CF@news.individual.net> Message-ID: <1fdb9932-dba6-8cb8-5eeb-f9237b4212e6@gmail.com> Marking this message as off topic, since it has nothing much to do with Python and Python programming. In fact this whole thread should have been started on a Docker-specific forum, mailing list, or USENET group. To the original poster: you should visit the Docker web site and access the community resources they have there: https://www.docker.com/docker-community On 11/29/2017 09:03 PM, Percival John Hackworth wrote: > To clarify, I think the OP was asking if they could Windows inside a Docker > container. Since Docker uses the kernel of the OS it's running on, that would > mean it would have to run natively on Windows. Unless things have changed Docker has always been about running Linux software in Linux containers on all supported OSes, which includes Mac and Windows. On Mac and Windows this requires running a VM, although now with Docker for Windows it can run the Linux containers on the integrated HyperV virtualization system, so you don't necessarily need to install VirtualBox or VMWare. https://www.microsoft.com/en-ca/cloud-platform/containers > Back in January, it didn't run on Windows. Now apparently you can run a > Windows 10 or Server 2016 environment in a container. I would think, given > the architecture of Docker, that you can only do this on a Windows machine, > not a Linux box. So the ability to containerize an application on Linux and > run it anywhere Docker is installed (even MacOS) only applicable to Linux > apps. Docker has run on Windows since very early on. Not quite sure why you say it didn't run on Windows back in January. As for running Windows applications in a Windows container, this is not possible using any container technology I'm aware of. I'm sure MS could one day build Windows-centric containerization into Windows, but there's no support now. I guess they haven't figured out how to work out the licensing. Proprietary licensing and containers would be complex. From p.f.moore at gmail.com Thu Nov 30 14:25:07 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 30 Nov 2017 19:25:07 +0000 Subject: [OT] - Re: Has anyone worked on docker with windows In-Reply-To: <1fdb9932-dba6-8cb8-5eeb-f9237b4212e6@gmail.com> References: <0001HW.1FCE90B00107AF3D14E0E52CF@news.individual.net> <0001HW.1FCFBA76014D790414BB022CF@news.individual.net> <1fdb9932-dba6-8cb8-5eeb-f9237b4212e6@gmail.com> Message-ID: On 30 November 2017 at 18:49, Michael Torrie wrote: > As for running Windows applications in a Windows container, this is not > possible using any container technology I'm aware of. I'm sure MS could > one day build Windows-centric containerization into Windows, but there's > no support now. I guess they haven't figured out how to work out the > licensing. Proprietary licensing and containers would be complex. Way off topic certainly, but I just installed Docker for Windows yesterday, and it has an option on the menu "Switch to Windows containers". From a very quick Google search, it looks like there is support for running Windows-based containers in docker now. There's an image microsoft/windowsservercore available, which suggests this is a supported solution. Paul From brian.j.oney at googlemail.com Thu Nov 30 16:19:33 2017 From: brian.j.oney at googlemail.com (Brian J. Oney) Date: Thu, 30 Nov 2017 22:19:33 +0100 Subject: advice for inventory software Message-ID: <1512076773.4868.0.camel@gmail.com> Dear Python scripters, I am writing modules for my insectary (for food), the processes of which I plan to mostly automate. Currently, inventory and the traceability of material flows is my focus. My best idea (yet) for making things as simple as possible consists of a debian server hooked up to a barcode scanner. The input of information would consist of scanning barcode sequences (Start process, item1, ..., stop process). For this, I plan to implement a listener to the usb port, which takes the input and knows what to do with it. Later on, there will be multiple simultaneous input sources. For now, I imagine a simple flask app capturing the input and feeding it into an SQL database. Certainly, someone has had the opportunity to something similar if not identical. I would be particularly greatful for advice on design and work already done. For those interested, I have my progress on github.com/oneyb. I almost done with the basic inventory barcode printing functionality I need. You may think I am reinventing the wheel. If so, why would I ask for advice? Also, the highly closed nature of the insect breeding business, my slim budget, and the desire to easy extend functionality in the near future (plus a mild case of 'I wanna code' [aka NIH] syndrome), push me to learn and implement this myself. Thanks in advance! Cheers Brian From rxjwg98 at gmail.com Thu Nov 30 18:16:35 2017 From: rxjwg98 at gmail.com (Robert) Date: Thu, 30 Nov 2017 15:16:35 -0800 (PST) Subject: Is it useful to set a fraction number here to the mask value? Message-ID: <1aea5010-ee97-4485-a0c6-5e98ef899ee2@googlegroups.com> Hi, I am new to Python. Now I follow a thread on mask array usage on line: https://stackoverflow.com/questions/31563970/fitting-a-binomial-distribution-with-pymc-raises-zeroprobability-error-for-certa I understand the problem, but I don't understand the answer follow the link. Because the 'mask' array is composed of integer, if it is assigned a fraction number as suggested a 1.5, it will be formatted to an integer 1. observed_values = sp.random.binomial(n = 10.0, p = 0.1, size = 100) ... mask = sp.zeros_like(observed_values) Are you clear the answer's meaning? "You can give it a non-integer value in order to avoid the problem that you cite. For example, if you fill with, say, 1.5 that should work." Thanks in advance From rxjwg98 at gmail.com Thu Nov 30 20:43:23 2017 From: rxjwg98 at gmail.com (Robert) Date: Thu, 30 Nov 2017 17:43:23 -0800 (PST) Subject: Is it useful to set a fraction number here to the mask value? In-Reply-To: <1aea5010-ee97-4485-a0c6-5e98ef899ee2@googlegroups.com> References: <1aea5010-ee97-4485-a0c6-5e98ef899ee2@googlegroups.com> Message-ID: <9bb48495-0c0a-463d-aa75-2390dff66007@googlegroups.com> On Thursday, November 30, 2017 at 6:17:05 PM UTC-5, Robert wrote: > Hi, > > I am new to Python. Now I follow a thread on mask array usage on line: > > > https://stackoverflow.com/questions/31563970/fitting-a-binomial-distribution-with-pymc-raises-zeroprobability-error-for-certa > > > I understand the problem, but I don't understand the answer follow the link. > > Because the 'mask' array is composed of integer, if it is assigned a fraction > number as suggested a 1.5, it will be formatted to an integer 1. > > > observed_values = sp.random.binomial(n = 10.0, p = 0.1, size = 100) > ... > mask = sp.zeros_like(observed_values) > > > Are you clear the answer's meaning? > > > "You can give it a non-integer value in order to avoid the problem that you cite. > For example, if you fill with, say, 1.5 that should work." > > > > > Thanks in advance Excuse me for the top post. Now I find the more specific question from the below link: https://pymc-devs.github.io/pymc/tutorial.html At almost the bottom part of the web page, when I run the script "masked_values = masked_array(disasters_array, mask=disasters_array==-999)" has an error: ... masked_values = masked_array(disasters_array, mask=disasters_array==-999) Traceback (most recent call last): File "", line 7, in NameError: name 'masked_array' is not defined I use Python 2.7 on Ubuntu 16.04, 64-bit. Is there an error in the pymc tutorial web page? Can you tell me what is wrong? Thanks, =========================== # Switchpoint switch = DiscreteUniform('switch', lower=0, upper=110) # Early mean early_mean = Exponential('early_mean', beta=1) # Late mean late_mean = Exponential('late_mean', beta=1) @deterministic(plot=False) def rate(s=switch, e=early_mean, l=late_mean): """Allocate appropriate mean to time series""" out = np.empty(len(disasters_array)) # Early mean prior to switchpoint out[:s] = e # Late mean following switchpoint out[s:] = l return out # The inefficient way, using the Impute function: # D = Impute('D', Poisson, disasters_array, mu=r) # # The efficient way, using masked arrays: # Generate masked array. Where the mask is true, # the value is taken as missing. masked_values = masked_array(disasters_array, mask=disasters_array==-999) # Pass masked array to data stochastic, and it does the right thing disasters = Poisson('disasters', mu=rate, value=masked_values, observed=True) From python at mrabarnett.plus.com Thu Nov 30 22:03:31 2017 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 1 Dec 2017 03:03:31 +0000 Subject: Is it useful to set a fraction number here to the mask value? In-Reply-To: <9bb48495-0c0a-463d-aa75-2390dff66007@googlegroups.com> References: <1aea5010-ee97-4485-a0c6-5e98ef899ee2@googlegroups.com> <9bb48495-0c0a-463d-aa75-2390dff66007@googlegroups.com> Message-ID: <14615837-b47c-c031-999a-a04427fe770e@mrabarnett.plus.com> On 2017-12-01 01:43, Robert wrote: > On Thursday, November 30, 2017 at 6:17:05 PM UTC-5, Robert wrote: >> Hi, >> >> I am new to Python. Now I follow a thread on mask array usage on line: >> >> >> https://stackoverflow.com/questions/31563970/fitting-a-binomial-distribution-with-pymc-raises-zeroprobability-error-for-certa >> >> >> I understand the problem, but I don't understand the answer follow the link. >> >> Because the 'mask' array is composed of integer, if it is assigned a fraction >> number as suggested a 1.5, it will be formatted to an integer 1. >> >> >> observed_values = sp.random.binomial(n = 10.0, p = 0.1, size = 100) >> ... >> mask = sp.zeros_like(observed_values) >> >> >> Are you clear the answer's meaning? >> >> >> "You can give it a non-integer value in order to avoid the problem that you cite. >> For example, if you fill with, say, 1.5 that should work." >> >> >> >> >> Thanks in advance > > Excuse me for the top post. Now I find the more specific question from the below > link: > > https://pymc-devs.github.io/pymc/tutorial.html > > > At almost the bottom part of the web page, when I run the script > > "masked_values = masked_array(disasters_array, mask=disasters_array==-999)" > > has an error: > > ... masked_values = masked_array(disasters_array, mask=disasters_array==-999) > Traceback (most recent call last): > File "", line 7, in > NameError: name 'masked_array' is not defined > > I use Python 2.7 on Ubuntu 16.04, 64-bit. Is there an error in the pymc > tutorial web page? > > Can you tell me what is wrong? > > Thanks, > > =========================== > # Switchpoint > switch = DiscreteUniform('switch', lower=0, upper=110) > # Early mean > early_mean = Exponential('early_mean', beta=1) > # Late mean > late_mean = Exponential('late_mean', beta=1) > > @deterministic(plot=False) > def rate(s=switch, e=early_mean, l=late_mean): > """Allocate appropriate mean to time series""" > out = np.empty(len(disasters_array)) > # Early mean prior to switchpoint > out[:s] = e > # Late mean following switchpoint > out[s:] = l > return out > > > # The inefficient way, using the Impute function: > # D = Impute('D', Poisson, disasters_array, mu=r) > # > # The efficient way, using masked arrays: > # Generate masked array. Where the mask is true, > # the value is taken as missing. > masked_values = masked_array(disasters_array, mask=disasters_array==-999) > > # Pass masked array to data stochastic, and it does the right thing > disasters = Poisson('disasters', mu=rate, value=masked_values, observed=True) > Earlier in the tutorial there was: >>> masked_values = np.ma.masked_equal(x, value=None) >>> masked_values masked_array(# etc This shows that 'masked_values' is a 'masked_array' object. A quick Google shows that it's numpy.ma.masked_array, i.e. defined in numpy.ma.