From hjp-python at hjp.at Mon Oct 28 04:14:47 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 28 Oct 2019 09:14:47 +0100 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: <20191028081447.GA3427@hjp.at> On 2019-10-20 19:31:43 +0200, Steve White wrote: > The point is, I don't think __eq__() is ever called in a situation as > described in my post, This is only guaranteed if the hash is actually stored within the dict. This seems to be the case in the CPython implementation, but there are other ways to implement a hash table which don't store the hashes explicitely (in fact, I don't think any of the variants we learned about at university 30 years ago did this). So your code may work with CPython, but not other Python implementations. Worse, it may stop working with future CPython versions if the dict implementation is changed. But even if you are fine with that, by using a different equality criterion for dicts than for everything else, your code is violating one of every Python programmer's core assumptions. This will very likely trip somebody up (maybe yourself in two years). 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 stevan.white at gmail.com Mon Oct 28 04:34:39 2019 From: stevan.white at gmail.com (Steve White) Date: Mon, 28 Oct 2019 09:34:39 +0100 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: Hi Chris, I'm afraid you've missed my point. As I said in the initial post, I have read the documentation. I think the documentation does not adequately explain how the hashtable (or hashtables generally) work internally. I think that in fact, if __hash__() returns a unique integer for each key, __eq__() is in fact *never* called. There is a reason for this: as I explained, this situation results in a "perfect hash", in which no key collision can occur, the bucket never needs to be searched. The experiment provided in the initial post seems to back this up. If you can shed light on the internals of dict and set and their design goals, please do so! Thanks! On Sun, Oct 27, 2019 at 9:04 AM Chris Angelico wrote: > > On Sun, Oct 27, 2019 at 6:26 PM Steve White wrote: > > As near as I can tell, returning the id() in __hash__() results in a > > perfect hash key. I really want to know if that is true. > > Because if it is true, any further layer is simply covering for a > > failing in the documentation. > > Only if your __eq__() does not return True for anything other than > itself. That is the entire definition of __hash__ - it needs to return > the same value for two objects that are equal. This is exactly what > the documentation said, as multiple people have posted here. > > If your object is equal only to itself, then its hash can be its > identity. Otherwise it should not. It is that simple. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Mon Oct 28 04:46:29 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 28 Oct 2019 19:46:29 +1100 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: On Mon, Oct 28, 2019 at 7:34 PM Steve White wrote: > > Hi Chris, > > I'm afraid you've missed my point. As I said in the initial post, I > have read the documentation. > > I think the documentation does not adequately explain how the > hashtable (or hashtables generally) work internally. > > I think that in fact, if __hash__() returns a unique integer for each > key, __eq__() is in fact *never* called. > There is a reason for this: as I explained, this situation results in > a "perfect hash", in which no key collision can occur, > the bucket never needs to be searched. > The experiment provided in the initial post seems to back this up. > > If you can shed light on the internals of dict and set and their > design goals, please do so! Yes, eq will never be called, because it is assumed that any objects that have different hashes must not compare equal. That is the entire point of the hash. So if your objects might compare equal to each other, they MUST have the same hash. That is what the documentation says. If you don't define EITHER hash OR eq, then you will get a hash based on the object's identity, and it will be equal only to itself. That is the default behaviour. ChrisA From p.f.moore at gmail.com Mon Oct 28 06:12:50 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 28 Oct 2019 10:12:50 +0000 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: On Mon, 28 Oct 2019 at 10:01, Steve White wrote: > > Hi Chris, > > I'm afraid you've missed my point. As I said in the initial post, I > have read the documentation. > > I think the documentation does not adequately explain how the > hashtable (or hashtables generally) work internally. As stated in the docs, "The only required property is that objects which compare equal have the same hash value". The docs do *not* explain how dictionaries work internally, and that's deliberate. You should not rely on the internal workings of dictionaries, because your code may then not work on other Python implementations (or even on later versions of CPython). Of course, if you're only interested in working on CPython, then you can rely on the details of the dictionary implementation, but in that case you;re expected to look at the implementation (and be prepared for it to change over time!) Paul From PythonList at DancesWithMice.info Tue Oct 1 01:03:39 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 1 Oct 2019 18:03:39 +1300 Subject: pathlib In-Reply-To: <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> Message-ID: <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> On 30/09/19 9:28 PM, Barry Scott wrote: >> On 30 Sep 2019, at 05:40, DL Neil via Python-list wrote: >> >> Should pathlib reflect changes it has made to the file-system? > > I think it should not. The term "concrete" is applied to Path(), PosixPath(), and WindowsPath() - whereas the others are differentiated with the prefix "Pure". I take "concrete" to mean 'existing in reality or real experience'. Thus, I saw the Pure* entities as supporting abstract paths, but the concrete entities as representing (and reflecting) real-world (file system) entities. Thus, there is no need for .exists() to be available in the Pure paths, but there is when utilising their concrete implementations. NB .name however is inherited from PurePath()! > A Path() is the name of a file it is not the file itself. Why should it > track changes in the file system for the name? BUT... Path() does keep track of changes in the file system for other attributes! So, why not also name? (remember that Python (in our code examples) does not know the file by its file-name (before OR after rename) but by the instance name, eg "save_file", below) > Here is code to show why following the rename will break logic: > > save_file = pathlib.Path('my-data.txt') > > def save( data ): > # backup file > if save_file.exists(): > save_file.rename('my-data.backup') > > # save data > with save_file.open() as f: > f.write( data ) > > while True: > save( generate_data() ) > time.sleep( interval ) > > If the rename of the file changed the path the above code will fail. That is one use-case, but in the use-case which led to the original post, the logic was: iterate directory-entries, if fileNM follows an out-of-date naming-convention, rename the file, then process further (logging observations along the way). Here's a code-snippet illustrating both of the above points: import pathlib p = pathlib.Path( "data-file" ) p # PosixPath('data-file') p.stat() os.stat_result(... st_mtime=1569898467, st_ctime=1569898467) # ... = excised results, leaving two data-points worth observing with p.open("w") as f: f.write("new stuff") # 9 p.stat() os.stat_result(... st_mtime=1569898572, st_ctime=1569898572) # hey look, this reflects REAL and CHANGED data from the FS # using input logic, cf previous example's output logic p.rename( "new-name" ) with p.open( "r" ) as f: f.readline() ... Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python3.7/pathlib.py", line 1193, in open opener=self._opener) File "/usr/lib64/python3.7/pathlib.py", line 1046, in _opener return self._accessor.open(self, flags, mode) FileNotFoundError: [Errno 2] No such file or directory: 'data-file' # hence we cannot follow the use-case # why? Because .name == 'data-file' but the real-world file is (now) called "new-name". NB I would not attempt to suggest that the logic of the 'write' use-case is any more, or any less, valid that that of the 'read' use-case; and I'm not arguing with you personally! Looking at the PEP, it didn't alleviate my confusion because: (a) <<< Why an object-oriented API ... form of filesystem handling abstraction >>> (b) <<< Immutability Path objects are immutable, which makes them hashable and also prevents a class of programming errors. >>> (c) <<< Concrete paths API In addition to the operations of the pure API, concrete paths provide additional methods which actually access the filesystem to query or mutate information. >>> I liked the OOP aims in point (a) but it clearly says "filesystem". Whereas the logic (mentioned above) of the inherent 'safety' of immutable objects is inescapable - point (b), that is incompatible with the usage and behavior of a file system. [which is a point made (by others), elsewhere)] Point (c) appears to suggest (as written above) that whereas the Pure API can be immutable and separate from any physical file system, the Concrete paths will perform actions and thus mutate with the real FS. Further to my (personal) point about use-cases and debate, if we follow the 'recommended' code snippet in the (PSL) manual, the logic is that there should be separate paths/Paths (whether for the two (physical) files or not) - their close relationship notwithstanding: >>> p = Path('foo') >>> p.open('w').write('some text') 9 >>> target = Path('bar') >>> p.rename(target) >>> target.open().read() 'some text' NB utilising two Path instances (cf allowing a string to 'intrude') will enrich both of the use-cases we have illustrated! Also, in subscribing to the rationale that it is better to represent paths/file-names with a semantic object, then the above makes good sense. (historically there has been debate about whether paths are a sub-class of string (a path is a string, but a string may not be a class - indeed a string intended to be a path may not be legal within a file system) or if paths are collections (which can be seen in PurePath.parts and the special operator). I think this point surfaces in a later contribution to this thread. Rule for self: don't mix Path() classes with non-semantic string representations! Sadly, help( ...Path ) does not match the (fine) manual's explanation/illustration, so perhaps RTFM applies... -- Regards =dn From PythonList at DancesWithMice.info Tue Oct 1 01:24:20 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 1 Oct 2019 18:24:20 +1300 Subject: pathlib In-Reply-To: References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <4233b002-ec5a-b00f-41d4-76cde37a77b9@potatochowder.com> Message-ID: <0b9f6c61-80ec-7166-7730-973dad5794e8@DancesWithMice.info> On 1/10/19 1:09 AM, Chris Angelico wrote: > On Mon, Sep 30, 2019 at 9:54 PM Dan Sommers > <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: >> I would have said the same thing, but the docs? disagree: a >> PurePath represents the name of (or the path to) a file, but a >> Path represents the actual file. >> >> >> ? https://docs.python.org/3/library/pathlib.html > > I don't think it represents the actual file. If it did, equality would > be defined by samefile, NOT by the file name. > >>>> from pathlib import Path >>>> import os >>>> open("file1", "w").close() >>>> os.link("file1", "file2") >>>> Path("file1") == Path("file2") > False >>>> Path("file1").samefile(Path("file2")) > True >>>> Path("file1") == Path("file1") > True This example involves a "hard link" in Linux - can't recall if it applies under MS-Win... On a Linux system the 'two' files share the same inode, and thus the same 'patch of disk', but one can be deleted without affecting the other. Thus, borrowing from the above snippet: >>> import os >>> open("file1", "w").close() >>> os.link("file1", "file2") >>> f1 = pathlib.Path( "file1" ) >>> f2 = pathlib.Path( "file2" ) >>> f1 == f2 False ### they are not the same path (by name) - due only to the last character >>> f1.stat() os.stat_result(st_mode=33204, st_ino=1049466, st_dev=64769, st_nlink=2, st_uid=1000, st_gid=1000, st_size=0, st_atime=1569903409, st_mtime=1569903409, st_ctime=1569903410) >>> f2.stat() os.stat_result(st_mode=33204, st_ino=1049466, st_dev=64769, st_nlink=2, st_uid=1000, st_gid=1000, st_size=0, st_atime=1569903409, st_mtime=1569903409, st_ctime=1569903410) >>> f1.samefile( f2 ) True ### but they do 'label' the same file when the path is applied to the FS. Let's try something similar, but the other-way-around: >>> f1 = pathlib.Path( "file1" ) >>> f1.stat() os.stat_result(st_mode=33204, st_ino=1049466, st_dev=64769, st_nlink=1, st_uid=1000, st_gid=1000, st_size=0, st_atime=1569903409, st_mtime=1569903409, st_ctime=1569903851) ### this path exists in the FS >>> f2 = pathlib.Path( "not-file1" ) >>> f2.stat() Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python3.7/pathlib.py", line 1168, in stat return self._accessor.stat(self) FileNotFoundError: [Errno 2] No such file or directory: 'not-file1' ### this path does not describe a file in the FS >>> f1.rename( f2 ) ### here's a rename operation per the manual! >>> f1.stat() Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python3.7/pathlib.py", line 1168, in stat return self._accessor.stat(self) FileNotFoundError: [Errno 2] No such file or directory: 'file1' ### but f1 does not represent a 'real file' any more >>> f2.stat() os.stat_result(st_mode=33204, st_ino=1049466, st_dev=64769, st_nlink=1, st_uid=1000, st_gid=1000, st_size=0, st_atime=1569903409, st_mtime=1569903409, st_ctime=1569904293) ### f2 is a path which represents a real-world file though ### where have we seen those numbers before? > It still represents the path to the file, not the file itself, and if > you move something over it, it will see the new file. I like this description. Thanks! That said, maybe pathlib should have stuck with paths/PurePaths, and we should have something else (logically separate, but closely-related) which manipulates the files themselves? (preferably OO, and tidying-up/offering an alternative to the morass of os, os.path, sys, shutil, and ?others) -- Regards =dn From PythonList at DancesWithMice.info Tue Oct 1 01:39:21 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 1 Oct 2019 18:39:21 +1300 Subject: pathlib In-Reply-To: <2AE351E4-E23D-44C5-AC82-8741DA63ABA9@barrys-emacs.org> References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <4233b002-ec5a-b00f-41d4-76cde37a77b9@potatochowder.com> <2AE351E4-E23D-44C5-AC82-8741DA63ABA9@barrys-emacs.org> Message-ID: <71577d4f-b53e-619e-67e5-ee21ccc9ff49@DancesWithMice.info> On 1/10/19 1:40 AM, Barry Scott wrote: > > >> On 30 Sep 2019, at 12:51, Dan Sommers <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: >> >> On 9/30/19 4:28 AM, Barry Scott wrote: >>>> On 30 Sep 2019, at 05:40, DL Neil via Python-list wrote: >>>> Should pathlib reflect changes it has made to the file-system? >>> I think it should not. >>> A Path() is the name of a file it is not the file itself. Why should it >>> track changes in the file system for the name? >> >> I would have said the same thing, but the docs? disagree: a >> PurePath represents the name of (or the path to) a file, but a >> Path represents the actual file. > > I'm not seeing that wording in the python 3.7 pathlib documentation. > Can you quote the exact wording please? > > I do see this: > > "Pure path objects provide path-handling operations which don?t actually access a filesystem." > > And: > > "Concrete paths are subclasses of the pure path classes. In addition to operations provided > by the latter, they also provide methods to do system calls on path objects." > > There is no requirement that a Path() names a file that exists even. That is true - of a "path". However, as soon as said path is applied to the file system, eg .open( "r" ) it had better exist or we will disappear into OSError-country. If we use .open( "w" ) then the very real file is created within the FS, at that path. So, the file does not need to exist for a path to be legal - which is a (to me sounds like) PurePath. However, don't we have to suspend such 'purity' in the "concrete" classes... >> That said, why doesn't your argument apply to read and write? I >> would certainly expect that writing to a path and then reading >> from that same path would return the newly written data. If I >> squint funny, the Path object is tracking the operations on the >> file system. > > I do not expect that. Consider the time line: > > 1. with p.open('w') write data > 2. external process changes file on disk > 3. with p.open('r') read data > > How would (3) get the data written at (1) guaranteed? > It will lead to bugs to assume that. > > The path object is allowing system calls that need a file's path to be called, > that is all. Beyond that there is no relationship between the pathlib.Path() > objects and files. In theory one can separate paths and files. In practice, if Python is to access a file it must pass a path to the OpSys/FS. To be fair, the temporal argument (race condition) applies to any IO method unless "locking" is available (it is not, either in pathlib or the os and sys libraries. You cannot .open( 'r' ) unless the actual file exists. You (probably) won't want to .open( 'w' ) if the actual file exists. Wouldn't we like a library which helps, in both cases! >> I think I'm actually arguing against some long since made (and >> forgotten?) design decisions that can't be changed (dare I say >> fixed?) because changing them would break backwards >> compatibility. +1 >> Yuck. :-) And I can absolutely see all sorts of different >> expecations not being met and having to be explained by saying >> "well, that's the way it works." > > I'd suggest that the design is reasonable and If there is misunderstanding that its > something that docs could address. Design: +1 Misunderstanding: +1 Docs: +1 Perhaps pathlib encourages one/some to believe that it has been designed to do more than it does/set out to do? Perhaps it does more than it should (by implementing some closer relationships with the underlying file system, but not others)? Perhaps it makes sense for .name to be a data-attribute in the Pure classes, but it should be name(), ie a method-attribute in the concrete classes? (per other methods subject to change/mutation - see .stat() examples in earlier responses) -- Regards =dn From PythonList at DancesWithMice.info Tue Oct 1 02:08:57 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 1 Oct 2019 19:08:57 +1300 Subject: pathlib In-Reply-To: <7d6579d3-f28e-c73b-8b9a-7338f67355af@potatochowder.com> References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <4233b002-ec5a-b00f-41d4-76cde37a77b9@potatochowder.com> <2AE351E4-E23D-44C5-AC82-8741DA63ABA9@barrys-emacs.org> <7d6579d3-f28e-c73b-8b9a-7338f67355af@potatochowder.com> Message-ID: <2a250cb5-9f7e-154b-6d4b-c8bfa08a901c@DancesWithMice.info> On 1/10/19 3:21 AM, Dan Sommers wrote: > On 9/30/19 8:40 AM, Barry Scott wrote: > ?>> On 30 Sep 2019, at 12:51, Dan Sommers > <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > ?>> On 9/30/19 4:28 AM, Barry Scott wrote: > ?>>>> On 30 Sep 2019, at 05:40, DL Neil via Python-list > wrote: > ?>>>> Should pathlib reflect changes it has made to the file-system? > ?>>> I think it should not. > ?>>> A Path() is the name of a file it is not the file itself. Why > should it > ?>>> track changes in the file system for the name? > ?>> > ?>> I would have said the same thing, but the docs? disagree:? a > ?>> PurePath represents the name of (or the path to) a file, but a > ?>> Path represents the actual file. > ?> > ?> I'm not seeing that wording in the python 3.7 pathlib documentation. > ?> Can you quote the exact wording please? > ?> > ?> I do see this: > ?> > ?> "Pure path objects provide path-handling operations which don?t > actually access a filesystem." > ?> > ?> And: > ?> > ?> "Concrete paths are subclasses of the pure path classes. In addition > to operations provided > ?> by the latter, they also provide methods to do system calls on path > objects." > > That's the wording I read.? I inferred that "path-handling operations > which don't actually access a filesystem" meant an object that didn't > necessarily represent an actual file, and that "provide methods to do > system calls on path objects" did indicate an actual file.? From the > existence of Path.read_bytes, I inferred that at least some Path objects > represent (and operate on) actual existing files.? I've been doing this > for a long time, and I may have read my expecations into those words. +1 "Pure" cf "concrete". The mixture makes it difficult to insist that a Path does not represent a file if (some) operations are included. > ?> There is no requirement that a Path() names a file that exists even. > Agreed. > > ?>> That said, why doesn't your argument apply to read and write?? I > ?>> would certainly expect that writing to a path and then reading > ?>> from that same path would return the newly written data.? If I > ?>> squint funny, the Path object is tracking the operations on the > ?>> file system. > ?> > ?> I do not expect that. Consider the time line: > ?> > ?> 1. with p.open('w') write data > ?> 2. external process changes file on disk > ?> 3. with p.open('r') read data > ?> > ?> How would (3) get the data written at (1) guaranteed? > ?> It will lead to bugs to assume that. > > I didn't say anything about a guarantee, or about an external processes. > If I have a single process that writes data to a file and then reads > from that file, I would expect to read what I just wrote.? See the > documentation of Path.read_bytes and Path.write_bytes.? If I throw an > external process, or a networked file system, or multiple layers of > buffering and/or caching into the mix, then all such bets are off. > > I think you're making my point about expectations.? :-) +1 > ?> The path object is allowing system calls that need a file's path to > be called, > ?> that is all. Beyond that there is no relationship between the > pathlib.Path() > ?> objects and files. > > The documentation of Path.read_bytes and Path.write_bytes say otherwise. +1 > ?>> I think I'm actually arguing against some long since made (and > ?>> forgotten?) design decisions that can't be changed (dare I say > ?>> fixed?) because changing them would break backwards > ?>> compatibility. > ?>> > ?>> Yuck.? :-)? And I can absolutely see all sorts of different > ?>> expecations not being met and having to be explained by saying > ?>> "well, that's the way it works." > ?> > ?> I'd suggest that the design is reasonable and If there is > misunderstanding that its > ?> something that docs could address. > > I'm not disagreeing.? I suspect that we've both worked on enough > different systems to know that not all OSes, file systems, libraries, > and versions and combinations thereof work the same way under all > circumstances (multiple threads, multiple processes, caching, buffering, > etc.).? It's the epitome of YMMV. > > Rename is a particularly thorny case because renaming a file, at least > on a POSIX system, is an operation on the directory containing the file > rather than the file itself. Thank you @Dan for keeping the conversation going during my night-hours. -- Regards =dn From none at gmail.com Tue Oct 1 03:37:16 2019 From: none at gmail.com (ast) Date: Tue, 1 Oct 2019 09:37:16 +0200 Subject: Recursive method in class In-Reply-To: References: <5d8df86e$0$3370$426a74cc@news.free.fr> <5d91b46f$0$15197$426a74cc@news.free.fr> Message-ID: <5d93022d$0$14378$426a74cc@news.free.fr> Le 30/09/2019 ? 13:11, Anders M?rak Leffler a ?crit?: > What do you mean by transformed? This is probably your understanding > already, but a further consequence of when arguments are evaluated > plus what you said about data attributes is that the fib(self, n - 1) > call will follow the standard LEGB-lookup of whatever "fib" is, from > the point of view of the function object. As far as I know, there is > no transformation of these scopes - either when it comes to creating > the class, or creating the instances. (self is just the instance, > passed as an argument.) > > Cf when you change a binding: > >>>> def factorial(self, n): > ... if not n: > ... return 1 > ... else: > ... return n * factorial(self, n - 1) > ... >>>> Dummy = type("DummyObject", (object, ), {"factorial" : factorial}) >>>> instance = Dummy() >>>> def factorial(self, n): > ... print("Hello!") > ... return 999 > ... >>>> instance.factorial(5) # Where will the call go ("old" or "new" factorial?)? Where will possible recursive calls go (and why)? > Hello! > 4995 > > Oh, and as others have pointed out on this list - you/whoever runs the > system sending the mail might want to change the return address. > none at gmail.com is somewhat consistently classed as spam. > > > > //Anders > > PS. We could further complicate this by adding a call to > self.factorial in the new function, but let's not go there. :) > I understood your example, but it doesn't answer my initial question. I try to rewrite my question: The following code is working well and I don't really understand why def factorial(self, n): if not n: return 1 else: return n * factorial(self, n - 1) Dummy = type("DummyObject", (object, ), {"factorial" : factorial}) instance = Dummy() instance.factorial(3) 6 # correct The problem is that "factorial" in line "return n * factorial(self, n - 1)" should not have been found because there is no factorial function defined in the current scope. if you use "class" keyword to define the class class Dummy: def factorial(self, n): if not n: return 1 else: return n * factorial(self, n - 1) instance = Dummy() instance.factorial(3) It generate an error because "factorial" in line "return n * factorial(self, n - 1)" is not found. Traceback (most recent call last): File "", line 1, in instance.factorial(3) File "", line 7, in factorial return n * factorial(self, n - 1) NameError: name 'factorial' is not defined This is OK to me The correct way is to write: class Dummy: def factorial(self, n): if not n: return 1 else: return n * self.factorial(n - 1) instance = Dummy() instance.factorial(3) 6 # correct So, to summarize, if you create a class with type(name, bases, dict_) or with the "class" keyword, recursive methods can't be writen in the same way. This is what puzzle me. From rosuav at gmail.com Tue Oct 1 03:45:34 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Oct 2019 17:45:34 +1000 Subject: pathlib In-Reply-To: <0b9f6c61-80ec-7166-7730-973dad5794e8@DancesWithMice.info> References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <4233b002-ec5a-b00f-41d4-76cde37a77b9@potatochowder.com> <0b9f6c61-80ec-7166-7730-973dad5794e8@DancesWithMice.info> Message-ID: On Tue, Oct 1, 2019 at 3:26 PM DL Neil via Python-list wrote: > > On 1/10/19 1:09 AM, Chris Angelico wrote: > > I don't think it represents the actual file. If it did, equality would > > be defined by samefile, NOT by the file name. > > > >>>> from pathlib import Path > >>>> import os > >>>> open("file1", "w").close() > >>>> os.link("file1", "file2") > >>>> Path("file1") == Path("file2") > > False > >>>> Path("file1").samefile(Path("file2")) > > True > >>>> Path("file1") == Path("file1") > > True > > >>> f1 = pathlib.Path( "file1" ) > >>> f2 = pathlib.Path( "file2" ) > >>> f1 == f2 > False > ### they are not the same path (by name) - due only to the last character Correct. The paths are not equal, regardless of whether they represent the same file. > Let's try something similar, but the other-way-around: > > >>> f1 = pathlib.Path( "file1" ) > >>> f1.stat() > os.stat_result(st_mode=33204, st_ino=1049466, st_dev=64769, st_nlink=1, > st_uid=1000, st_gid=1000, st_size=0, st_atime=1569903409, > st_mtime=1569903409, st_ctime=1569903851) > ### this path exists in the FS > > >>> f1.rename( f2 ) > ### here's a rename operation per the manual! > >>> f2.stat() > os.stat_result(st_mode=33204, st_ino=1049466, st_dev=64769, st_nlink=1, > st_uid=1000, st_gid=1000, st_size=0, st_atime=1569903409, > st_mtime=1569903409, st_ctime=1569904293) > ### f2 is a path which represents a real-world file though > ### where have we seen those numbers before? And as you see, f2 now points to that file. So the Path objects haven't changed, but the underlying file has moved from one to the other. The Path does not represent the file; it represents one means of locating it. One thing that might be nice - although it'd probably be a nightmare to try to work with across platforms - would be a Path that, rather than being either absolute (anchored at the root) or relative to the current directory (not anchored), is relative to a specific other directory. It'd be described something like "<142857>/path/to/file" and would reference an open FD. That would give a Path power that a normal string doesn't have - the power to combine both the arguments of openat. ChrisA From rosuav at gmail.com Tue Oct 1 03:55:09 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Oct 2019 17:55:09 +1000 Subject: pathlib In-Reply-To: <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> Message-ID: On Tue, Oct 1, 2019 at 3:05 PM DL Neil via Python-list wrote: > BUT... Path() does keep track of changes in the file system for other > attributes! So, why not also name? Does it actually track changes? > Here's a code-snippet illustrating both of the above points: > > import pathlib > p = pathlib.Path( "data-file" ) > p > # PosixPath('data-file') > p.stat() > os.stat_result(... st_mtime=1569898467, st_ctime=1569898467) > # ... = excised results, leaving two data-points worth observing > > with p.open("w") as f: > f.write("new stuff") > # 9 > > p.stat() > os.stat_result(... st_mtime=1569898572, st_ctime=1569898572) > # hey look, this reflects REAL and CHANGED data from the FS This is a method. And it is implemented with an actual call to the OS. $ strace python3 -c 'from pathlib import Path; p = Path("asdfasdf.py"); print("111111111"); p.stat(); print("2222222222"); p.stat(); print("3333333333")' [ chomp tons of strace output ] write(1, "111111111\n", 10111111111 ) = 10 stat("asdfasdf.py", {st_mode=S_IFREG|0644, st_size=146, ...}) = 0 write(1, "2222222222\n", 112222222222 ) = 11 stat("asdfasdf.py", {st_mode=S_IFREG|0644, st_size=146, ...}) = 0 write(1, "3333333333\n", 113333333333 ) = 11 Every time you check p.stat(), there is a system call to actually stat the file. The Path object is not tracking anything. It is not in any way "reflecting changes", other than the same way that a string literal can reflect changes in the FS. > Looking at the PEP, it didn't alleviate my confusion because: > (a) <<< > Why an object-oriented API > ... form of filesystem handling abstraction > >>> > (b) <<< > Immutability > Path objects are immutable, which makes them hashable and also prevents > a class of programming errors. > >>> > (c) <<< > Concrete paths API > In addition to the operations of the pure API, concrete paths provide > additional methods which actually access the filesystem to query or > mutate information. > >>> > > I liked the OOP aims in point (a) but it clearly says "filesystem". Yes - a pathlib.Path is designed for a file system path, not a UUCP bang path, not a URI path, not a yellow brick road, but a file system path. So it clearly says this. > Point (c) appears to suggest (as written above) that whereas the Pure > API can be immutable and separate from any physical file system, the > Concrete paths will perform actions and thus mutate with the real FS. No, concrete paths are simply bound to your current FS. It doesn't make sense, on my Linux system, to have a concrete path of "c:/foo/bar". I *am* allowed to instantiate an abstract WindowsPath, but it doesn't make sense to ask if that's the same file as "c:/quux", since I don't have a file system. I think you're assuming far too much from the word "concrete". It's not tracking an actual file. It's still just a path - it just now has some methods attached to it. ChrisA From gisle.vanem at gmail.com Tue Oct 1 05:09:22 2019 From: gisle.vanem at gmail.com (Gisle Vanem) Date: Tue, 1 Oct 2019 11:09:22 +0200 Subject: Announcing colour-text and colour-print In-Reply-To: <7460D86A-CEAE-4C3B-AAE1-955F81299FF5@barrys-emacs.org> References: <7460D86A-CEAE-4C3B-AAE1-955F81299FF5@barrys-emacs.org> Message-ID: Barry Scott wrote: > Here is an example: > > from colour_text import ColourText > ct = ColourText() > ct.initTerminal() > > print( ct( "The next section is in green: <>green example<>." ) ) Looking at the sources, it seems 'win32' should be supported. But no; with the above example: c:\>py -3 example.py The next section is in green: ?[32mexample?[m. No colours, just the pesky SGI-codes. BTW. it fails completely in Python 2.7. -- --gv From PythonList at DancesWithMice.info Tue Oct 1 05:20:50 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 1 Oct 2019 22:20:50 +1300 Subject: pathlib In-Reply-To: References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <4233b002-ec5a-b00f-41d4-76cde37a77b9@potatochowder.com> <2AE351E4-E23D-44C5-AC82-8741DA63ABA9@barrys-emacs.org> <826a715b-6191-d3c8-555d-76f6e71865c7@potatochowder.com> <77fc603e-8cdb-1d9a-cf92-32bbc13397a4@potatochowder.com> <59D0D1C8-F0E8-4152-BD59-72377100C2A7@barrys-emacs.org> Message-ID: On 1/10/19 2:58 PM, Dan Sommers wrote: > On 9/30/19 3:56 PM, Barry Scott wrote: >>> On 30 Sep 2019, at 16:49, Dan Sommers >>> <2QdxY4RzWzUUiLuE at potatochowder.com >>> > wrote: > >>> In the totality of a Path object that claims to represent paths >>> to files, >> >> It represents string that *should* in most cases work in the APIs >> that work on files. Not the same idea. > > I'm not sure the documentation supports your view.? Components > of paths are strings, but IMO the Path object represents a file. Worse! There may be an argument for suggesting that the documentation supports both descriptions... >>> including the arguably troublesome read_bytes and >>> write_bytes methods, and a rename method, however, it's not >>> unreasonable expect the object to track *itself* when I use *its* >>> own rename method (backwards compatibility restraints >>> notwithstanding). >> >> "the object" did track the changes its just that "the object" is not >> the Path object, it's in the operating system and/or the file system. >> For the rename it's the directory that the name is recorded in. > > So which is it?? Does the Path object represent a string, the > name of a file (whether that file exists or not), or the file > itself?? A moment ago, you claimed that a Path object represents > a string that should work in the APIs that work on files.? Now, > you're claiming that the Path object is a proxy for something in > the filesystem.? I don't mean to be combative or confrontational, > but I think that this fuzziness/inconsistency is at or near the > root of the differing expectations. Yes, see earlier comment about "confusion" - in both the minds of learners/newcomers and those who are 'experienced'. >> There was an interest talk at this years PYCON UK about the >> the errors that people new to python make. Misunderstand syntax >> is about 1/3 of the problems, but 2/3 was having the wrong model. >> >> This discussion seems to fall into the "wrong model" world that >> leads to a expectation failure. > > On this (that there's something about the model of Path objects > that leads to expectation failures) we agree.? :-) Are we talking about "Here's Your Mistake" (https://www.youtube.com/watch?v=7gMOaWdzDSw)? You've strayed into my research area: cognitive psychology - understanding how people learn. Whilst we do indeed talk about "models" - a person's understanding of how things work and/or how they fit together. "Models" in the computing world are more often called "abstractions". Every?most computer program(mes) are, by definition, an abstraction of some real-world event, calculation, or whatever. A Person() class might have the name of a real-person, but it is definitely not that (or any other) person. It is an abstraction (and likely only of 'part' of that person). That said, if the person changes his/her name by Deed Poll (legal process) to "Slinky Python", then it would be insulting to use the previous name(s)! (and if someone has divorced and re-married, never, never, NEVER use the names of the original him+her when referring to the 'new' him+her!!!) (PC alert: traditional pairing described) You will observe that the original post attempts to paint a picture of the model I expected. Since then, several folk have taken me up on the request for "good reasons ... why not", and thus, as you say, enabled the replacement (education) of my "wrong model", with "the real thing". From where do people acquire their models? The YouTube video briefly touched-on this. Most commonly: previous experience - thus math students write formulae as description, and can come to grief when Python code insists upon a sequence of instructions. So, next time someone tells you to 'read the code' you will wonder why the built-in 'documentation' isn't up-to-snuff; and when someone says RTFM you'll also realise that you've invited the person to construct their own model - an error-prone process at best; and that is why, if one examines the rate of adoption for (open source) languages and libraries, the greatest influence is the presence/absence of quality tutorials - materials designed to encourage the building of congruent mental models! In this discussion we've heard people comparing pathlib with previous facilities in os and sys. That's unfortunate because reading the PEP shows an intention to diverge. At the same time, and again reviewing this discussion, you can observe two models: one more abstract ("Pure") and the other more oriented to reflecting the FS ("concrete"). The gap between is the importance one places on each of the two models. Favoring the abstract means seeing the Pure constructs as important and the concrete as lesser. The more practical view asking for a means to access the file system, sees the Pure model as a foundation. >> Have we moved on to how we can improve the situation? > > Absolutely. > > Documenting the fact that calling rename on a Path object does > not update that object, and at least an acknowledgement of the > backwards compatibility issues, would be a good start.? Does the > same sort of thing happen with Path.chmod as well? > > Clarifying what a Path object represents is also in order.? Again, > I note that the top of https://docs.python.org/3/library/pathlib.html > talks about filesystem paths, but a lot of the method descriptions > (e.g., rename) use the phrase "this file," as if Path objects > represent (or are actually proxies for) actual files or an actual > filesystem. +1 I'm hoping that the snippet taken directly from 'the manual' (see earlier post) showing that if the .rename()'s argument is a Path rather than a str, the author's intentions (and his model) become easier to follow. (help() docs don't though) That said, if pathlib is not really 'for' file system operations, or only handles some of such (and not other(s) that I would like), then I'll happily go back/go elsewhere; and the great thing is that we are free to make up our own minds and to do things differently from each-other, if we want. ie YMMV! I've learned a lot from this discussion. Thanks! -- Regards =dn From mal at europython.eu Tue Oct 1 05:28:14 2019 From: mal at europython.eu (M.-A. Lemburg) Date: Tue, 1 Oct 2019 11:28:14 +0200 Subject: EuroPython 2019 - Videos for Friday available Message-ID: <57ae5169-2c95-6ab7-fe39-d6507a72167e@europython.eu> We are pleased to announce the third and final batch of cut videos from EuroPython 2019 in Basel, Switzerland, with another 49 videos. * EuroPython 2019 on our YouTube Channel * http://europython.tv/ In this batch, we have included all videos for Friday, July 12 2019, the third conference day. In total, we now have 133 videos available for you to watch. All EuroPython videos, including the ones from previous conferences, are available on our EuroPython YouTube Channel. Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/post/188061778527/europython-2019-videos-for-friday-available Tweet: https://twitter.com/europython/status/1178961272261545984 Enjoy, -- EuroPython 2019 Team https://ep2019.europython.eu/ https://www.europython-society.org/ From Richard at Damon-Family.org Tue Oct 1 06:43:00 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Tue, 1 Oct 2019 06:43:00 -0400 Subject: pathlib In-Reply-To: <0b9f6c61-80ec-7166-7730-973dad5794e8@DancesWithMice.info> References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <4233b002-ec5a-b00f-41d4-76cde37a77b9@potatochowder.com> <0b9f6c61-80ec-7166-7730-973dad5794e8@DancesWithMice.info> Message-ID: <163028ba-bc41-cdb6-ec2d-f11ac3df816e@Damon-Family.org> On 10/1/19 1:24 AM, DL Neil via Python-list wrote: > On 1/10/19 1:09 AM, Chris Angelico wrote: >> On Mon, Sep 30, 2019 at 9:54 PM Dan Sommers >> <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: >>> I would have said the same thing, but the docs? disagree:? a >>> PurePath represents the name of (or the path to) a file, but a >>> Path represents the actual file. >>> >>> >>> ? https://docs.python.org/3/library/pathlib.html >> >> I don't think it represents the actual file. If it did, equality would >> be defined by samefile, NOT by the file name. >> >>>>> from pathlib import Path >>>>> import os >>>>> open("file1", "w").close() >>>>> os.link("file1", "file2") >>>>> Path("file1") == Path("file2") >> False >>>>> Path("file1").samefile(Path("file2")) >> True >>>>> Path("file1") == Path("file1") >> True > > > This example involves a "hard link" in Linux - can't recall if it > applies under MS-Win... > > On a Linux system the 'two' files share the same inode, and thus the > same 'patch of disk', but one can be deleted without affecting the > other. Thus, borrowing from the above snippet: This is sort of like in Python we have a = [] b = a now a and b refer to the same list, On Linux, a file name is NOT a file, but a reference to it. A file may have many names (or even no names after you unlink the last name with the file still open), You can also have a file name (aka a path) that created multiple files that exist at the same time (create the file and keep it open, unlink or rename the file, and you can create another with the original name). We also have relative paths, relative paths specify a file path relative to something, but don't keep track of that something, and as such may truly represent multiple real files. These show that these paths CAN'T actually represent the files, -- Richard Damon From none at gmail.com Tue Oct 1 06:44:16 2019 From: none at gmail.com (ast) Date: Tue, 1 Oct 2019 12:44:16 +0200 Subject: "Regular Expression Objects" scanner method Message-ID: <5d932e01$0$15186$426a34cc@news.free.fr> Hello I am trying to understand a program which use a method named scanner on a re compiled object. This program is named "Simple compiler" here: https://www.pythonsheets.com/notes/python-generator.html But unfortunately it is not documented nor here: https://docs.python.org/3.7/library/re.html#regular-expression-objects nor with help import re lex = re.compile("foo") help(lex.scanner) Help on built-in function scanner: scanner(string, pos=0, endpos=2147483647) method of _sre.SRE_Pattern instance Does anybody know where to find a doc ? From tjreedy at udel.edu Tue Oct 1 07:45:44 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 1 Oct 2019 07:45:44 -0400 Subject: Recursive method in class In-Reply-To: <5d93022d$0$14378$426a74cc@news.free.fr> References: <5d8df86e$0$3370$426a74cc@news.free.fr> <5d91b46f$0$15197$426a74cc@news.free.fr> <5d93022d$0$14378$426a74cc@news.free.fr> Message-ID: On 10/1/2019 3:37 AM, ast wrote: > The following code is working well and I don't really understand why > > def factorial(self, n): > ??? if not n: > ??????? return 1 > ??? else: > ??????? return n * factorial(self, n - 1) This creates a function that looks up 'factorial' in the global (module) scope when called. > Dummy = type("DummyObject", (object, ), {"factorial" : factorial}) This creates a reference to the function in the class dict. There is now one function object with 2 references. > instance = Dummy() > instance.factorial(3) instance.factorial still looks up 'factorial' in the global scope, and finds it there. If you delete the global reference after creating the class, the lookup will fail, as when > > 6? # correct > The problem is that "factorial" in line > "return n * factorial(self, n - 1)" should not have been found > because there is no factorial function defined in the current > scope. Yes there is. the 'current' scope always includes globals, and globals has a reference to the function. -- Terry Jan Reedy From rhodri at kynesim.co.uk Tue Oct 1 07:52:47 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 1 Oct 2019 12:52:47 +0100 Subject: pathlib In-Reply-To: <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> Message-ID: On 01/10/2019 06:03, DL Neil via Python-list wrote: > On 30/09/19 9:28 PM, Barry Scott wrote: >>> On 30 Sep 2019, at 05:40, DL Neil via Python-list >>> wrote: >>> >>> Should pathlib reflect changes it has made to the file-system? >> >> I think it should not. > > The term "concrete" is applied to Path(), PosixPath(), and WindowsPath() > - whereas the others are differentiated with the prefix "Pure". > > I take "concrete" to mean 'existing in reality or real experience'. > Thus, I saw the Pure* entities as supporting abstract paths, but the > concrete entities as representing (and reflecting) real-world (file > system) entities. > > Thus, there is no need for .exists() to be available in the Pure paths, > but there is when utilising their concrete implementations. Sorry but your logic is inconsistent here. For starters, it's not that there's no need for .exists() in Pure paths, it's that .exists() is meaningless. Pure paths aren't related to any actual filing system (to paraphrase you), so existence isn't an option. However if you insist that "concrete" means "existing in reality", then .exists() is unnecessary because by your very definition the path must exist. The very act of creating the Path object would create the corresponding file or directory. So either pathlib does something horrific, or your definition is wrong. Consider for a moment: rhodri at scrote:~$ cat /home/rhodri/foo.txt cat: /home/rhodri/foo.txt: No such file or directory cat "concatenates files" to quote its man page. Does that mean it creates them if they don't exist, just because I typed the name into the command? No. I wouldn't expect it either. In exactly the same way I don't expect a concrete file*name* to necessarily refer to an actual file. -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Tue Oct 1 07:18:38 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 1 Oct 2019 12:18:38 +0100 Subject: Recursive method in class In-Reply-To: <5d93022d$0$14378$426a74cc@news.free.fr> References: <5d8df86e$0$3370$426a74cc@news.free.fr> <5d91b46f$0$15197$426a74cc@news.free.fr> <5d93022d$0$14378$426a74cc@news.free.fr> Message-ID: <4b62716b-b5d2-2cbb-b7f9-e307178526be@kynesim.co.uk> On 01/10/2019 08:37, ast wrote: > I understood your example, but it doesn't answer my initial question. > I try to rewrite my question: > > The following code is working well and I don't really understand why > > def factorial(self, n): > ??? if not n: > ??????? return 1 > ??? else: > ??????? return n * factorial(self, n - 1) > > Dummy = type("DummyObject", (object, ), {"factorial" : factorial}) > instance = Dummy() > instance.factorial(3) > > 6? # correct > > The problem is that "factorial" in line > "return n * factorial(self, n - 1)" should not have been found > because there is no factorial function defined in the current > scope. Not so. "factorial" is in the global scope of your module, which is always available. > > if you use "class" keyword to define the class > > class Dummy: > > ??? def factorial(self, n): > ??????? if not n: > ??????????? return 1 > ??????? else: > ??????????? return n * factorial(self, n - 1) > > instance = Dummy() > instance.factorial(3) > > It generate an error because "factorial" in line > "return n * factorial(self, n - 1)" is not found. > > Traceback (most recent call last): > ? File "", line 1, in > ??? instance.factorial(3) > ? File "", line 7, in factorial > ??? return n * factorial(self, n - 1) > NameError: name 'factorial' is not defined > > This is OK to me Here, "factorial" is *not* in scope. It's an attribute of the Dummy class, which is in scope, so you have to access it via Dummy (or more usually "self", because "self" is an instance of Dummy so has access). > > The correct way is to write: > > class Dummy: > > ??? def factorial(self, n): > ??????? if not n: > ??????????? return 1 > ??????? else: > ??????????? return n * self.factorial(n - 1) > > instance = Dummy() > instance.factorial(3) > > 6 # correct > > So, to summarize, if you create a class with type(name, bases, dict_) > or with the "class" keyword, recursive methods can't be writen > in the same way. This is what puzzle me. On the contrary, recursive methods are written in exactly the same way. What you aren't getting at the moment is what scope names exist in. -- Rhodri James *-* Kynesim Ltd From spencerdu at hotmail.co.uk Tue Oct 1 11:51:35 2019 From: spencerdu at hotmail.co.uk (Spencer Du) Date: Tue, 1 Oct 2019 08:51:35 -0700 (PDT) Subject: How can I set the value of the textedit box and slider of ui with the value from a config file when it has been created? Message-ID: <6dd37ddd-3d9d-4bdb-b015-6e42808701c2@googlegroups.com> Hi How can I set the value of the textedit box and slider of ui with the value from a config file when it has been created meaning if a configuration file exists then set the UI with value from the config file otherwise load ui with nothing set to any value. ui.py import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QSlider, QLineEdit, QPushButton from PyQt5.QtCore import Qt import myconfig config=myconfig.Config() import os import configparser ui.py class Example(QMainWindow): def __init__(self): super().__init__() self.textbox = QLineEdit(self) self.textbox.move(20, 25) self.textbox.resize(60,30) button = QPushButton('Button', self) button.setToolTip('This is an example button') button.clicked.connect(self.printValue) button.move(100,25) self.mySlider = QSlider(Qt.Horizontal, self) self.mySlider.setGeometry(30, 140, 200, 30) self.mySlider.setMinimum(0) self.mySlider.setMaximum(100) # self.textbox.setText(str(config.getminValue())) # textboxValue = self.textbox.text() # self.mySlider.setValue(int(textboxValue) + 30) self.setGeometry(50,50,320,200) self.setWindowTitle("Checkbox Example") self.show() #def changeValue(self, value): #print(value) def printValue(self): if not os.path.exists('445nm.ini'): textboxValue = self.textbox.text() print(textboxValue) f = open('445nm.ini', 'w+') config = configparser.RawConfigParser() config.add_section('445nm') config.set('445nm', 'intensity', textboxValue) config.write(f) if self.textbox.text() == "": self.mySlider.setValue(0) else: self.mySlider.setValue(int(textboxValue)) else: self.mySlider.setValue(config.get('445nm', 'intensity')) # if self.textbox.text() == "": # self.mySlider.setValue(0) # else: # self.mySlider.setValue(config.get('445nm', 'intensity')) if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) config.py [445nm] intensity = 4 Thanks Spencer From none at gmail.com Tue Oct 1 12:52:01 2019 From: none at gmail.com (ast) Date: Tue, 1 Oct 2019 18:52:01 +0200 Subject: Recursive method in class In-Reply-To: References: <5d8df86e$0$3370$426a74cc@news.free.fr> <5d91b46f$0$15197$426a74cc@news.free.fr> <5d93022d$0$14378$426a74cc@news.free.fr> <4b62716b-b5d2-2cbb-b7f9-e307178526be@kynesim.co.uk> Message-ID: <5d938431$0$21586$426a34cc@news.free.fr> Le 01/10/2019 ? 13:18, Rhodri James a ?crit?: > On 01/10/2019 08:37, ast wrote: >> The problem is that "factorial" in line >> "return n * factorial(self, n - 1)" should not have been found >> because there is no factorial function defined in the current >> scope. > > Not so.? "factorial" is in the global scope of your module, which is > always available. > yes, you rae right. It is clear now From torriem at gmail.com Tue Oct 1 15:11:01 2019 From: torriem at gmail.com (Michael Torrie) Date: Tue, 1 Oct 2019 13:11:01 -0600 Subject: How can I set the value of the textedit box and slider of ui with the value from a config file when it has been created? In-Reply-To: <6dd37ddd-3d9d-4bdb-b015-6e42808701c2@googlegroups.com> References: <6dd37ddd-3d9d-4bdb-b015-6e42808701c2@googlegroups.com> Message-ID: <33aace0f-8449-1f1f-1130-6807bb443602@gmail.com> On 10/1/19 9:51 AM, Spencer Du wrote: > Hi > How can I set the value of the textedit box and slider of ui with the value from a config file when it has been created meaning if a configuration file exists then set the UI with value from the config file otherwise load ui with nothing set to any value. Your code appears to try to do all this in the printValue() method of your class, however nothing calls that method. Most likely you'd want to move that code to the __init__() initializer. I can't really comment further since your code cannot be run as posted, since it imports a "myconfig" module that is not provided. More specific help regarding PyQt perhaps may be found at the PyQt mailing list that Riverbank Software (the makers of PyQt) host). From lukasz at langa.pl Tue Oct 1 15:35:06 2019 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Tue, 1 Oct 2019 21:35:06 +0200 Subject: [RELEASE] Python 3.8.0rc1 is now available Message-ID: Python 3.8.0 is almost ready. After a rather tumultuous few days, we are very happy to announce the availability of the release candidate: https://www.python.org/downloads/release/python-380rc1/ This release, 3.8.0rc1, is the final planned release preview. Assuming no critical problems are found prior to 2019-10-14, the scheduled release date for 3.8.0, no code changes are planned between this release candidate and the final release. Please keep in mind that this is not the gold release yet and as such its use is not recommended for production environments. Major new features of the 3.8 series, compared to 3.7 Some of the new major new features and changes in Python 3.8 are: PEP 572 , Assignment expressions PEP 570 , Positional-only arguments PEP 587 , Python Initialization Configuration (improved embedding) PEP 590 , Vectorcall: a fast calling protocol for CPython PEP 578 , Runtime audit hooks PEP 574 , Pickle protocol 5 with out-of-band data Typing-related: PEP 591 (Final qualifier), PEP 586 (Literal types), and PEP 589 (TypedDict) Parallel filesystem cache for compiled bytecode Debug builds share ABI as release builds f-strings support a handy = specifier for debugging continue is now legal in finally: blocks on Windows, the default asyncio event loop is now ProactorEventLoop on macOS, the spawn start method is now used by default in multiprocessing multiprocessing can now use shared memory segments to avoid pickling costs between processes typed_ast is merged back to CPython LOAD_GLOBAL is now 40% faster pickle now uses Protocol 4 by default, improving performance (Hey, fellow core developer, if a feature you find important is missing from this list, let ?ukasz know .) Call to action: focus on the docs now Are all your changes properly documented? Did you notice other changes you know of to have insufficient documentation? Can you help with the ?What?s New ? document? - ? -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: Message signed with OpenPGP URL: From timur at kernel.org Tue Oct 1 14:56:30 2019 From: timur at kernel.org (Timur Tabi) Date: Tue, 1 Oct 2019 13:56:30 -0500 Subject: Recursive method in class In-Reply-To: <5d8df86e$0$3370$426a74cc@news.free.fr> References: <5d8df86e$0$3370$426a74cc@news.free.fr> Message-ID: Could you please fix your email software so that it shows a legitimate email address in the From: line? Your emails all show this: From: ast All of your emails are being caught in my spam filter because of this address. I would email you privately, but I know none at gmail.com isn't your real email address. From barry at barrys-emacs.org Tue Oct 1 17:11:07 2019 From: barry at barrys-emacs.org (Barry) Date: Tue, 1 Oct 2019 22:11:07 +0100 Subject: Announcing colour-text and colour-print In-Reply-To: References: Message-ID: <1DED2409-2A51-4173-859B-AFE755F6813D@barrys-emacs.org> > On 1 Oct 2019, at 10:12, Gisle Vanem wrote: > > ?Barry Scott wrote: > >> Here is an example: >> from colour_text import ColourText >> ct = ColourText() >> ct.initTerminal() >> print( ct( "The next section is in green: <>green example<>." ) ) > > Looking at the sources, it seems 'win32' should be > supported. But no; with the above example: > c:\>py -3 example.py > The next section is in green: ?[32mexample?[m. That are two posibility. 1. You did not call initTerminal 2. You are on an old version of windows that does not understand SGI. Barry > > No colours, just the pesky SGI-codes. > > BTW. it fails completely in Python 2.7. > > -- > --gv > -- > https://mail.python.org/mailman/listinfo/python-list From grant.b.edwards at gmail.com Tue Oct 1 17:19:11 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 1 Oct 2019 21:19:11 -0000 (UTC) Subject: Recursive method in class References: <5d8df86e$0$3370$426a74cc@news.free.fr> Message-ID: On 2019-10-01, Timur Tabi wrote: > Could you please fix your email software so that it shows a legitimate > email address in the From: line? Your emails all show this: > > From: ast > > All of your emails are being caught in my spam filter because of this > address. I would email you privately, but I know none at gmail.com isn't > your real email address. Worse yet, it's probably _somebody_else's_real_email_address_ -- Grant Edwards grant.b.edwards Yow! In Newark the at laundromats are open 24 gmail.com hours a day! From hongyi.zhao at gmail.com Wed Oct 2 00:27:14 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Wed, 2 Oct 2019 04:27:14 +0000 (UTC) Subject: python socket dns query will get the correct result while the dig will not. Message-ID: Hi, See my following test: With ipython: In [1]: import socket In [2]: socket.gethostbyname ('www.vpngate.net') Out[2]: '130.158.75.44' With dig: $ dig www.vpngate.net @114.114.114.114 +short 31.13.65.1 $ dig www.vpngate.net @8.8.8.8 +short 46.82.174.68 Any hints? From nad at python.org Wed Oct 2 00:40:52 2019 From: nad at python.org (Ned Deily) Date: Wed, 2 Oct 2019 00:40:52 -0400 Subject: [RELEASE] Python 3.7.5rc1 is now available for testing Message-ID: <9CC88853-B37D-4D55-B5C6-9AF6978CDD29@python.org> Python 3.7.5rc1 is now available for testing. 3.7.5rc1 is the release preview of the next maintenance release of Python 3.7, the latest feature release of Python. Assuming no critical problems are found prior to 2019-10-14, no code changes are planned between now and the final release. This release candidate is intended to give you the opportunity to test the new security and bug fixes in 3.7.5. We strongly encourage you to test your projects and report issues found to bugs.python.org as soon as possible. Please keep in mind that this is a preview release and, thus, its use is not recommended for production environments. You can find the release files, a link to the changelog, and more information here: https://www.python.org/downloads/release/python-375rc1/ -- Ned Deily nad at python.org -- [] From vergos.nikolas at gmail.com Wed Oct 2 01:11:38 2019 From: vergos.nikolas at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Tue, 1 Oct 2019 22:11:38 -0700 (PDT) Subject: pymysql.err.InterfaceError after some hours of usage Message-ID: Hello, i use 'module pymysql' for connectivity in my wsgi scripts. For some reason after some hours of i.e. 'http://superhost.gr/files' i get the following error when the script tries to run: Do you know why this is happening?! Error: 500 Internal Server Error Sorry, the requested URL 'http://superhost.gr/files/' caused an error: Internal Server Error Exception: InterfaceError("(0, '')",) Traceback: Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/bottle.py", line 862, in _handle return route.call(**args) File "/usr/lib/python3.6/site-packages/bottle.py", line 1740, in wrapper rv = callback(*a, **ka) File "/home/nikos/wsgi/files.py", line 143, in displayall convert() File "/home/nikos/wsgi/files.py", line 93, in convert cur.execute('''SELECT file FROM files''') File "/usr/lib64/python3.6/site-packages/pymysql/cursors.py", line 170, in execute result = self._query(query) File "/usr/lib64/python3.6/site-packages/pymysql/cursors.py", line 328, in _query conn.query(q) File "/usr/lib64/python3.6/site-packages/pymysql/connections.py", line 516, in query self._execute_command(COMMAND.COM_QUERY, sql) File "/usr/lib64/python3.6/site-packages/pymysql/connections.py", line 750, in _execute_command raise err.InterfaceError("(0, '')") pymysql.err.InterfaceError: (0, '') I only use this opening statement in the beginning of my scripts. conn = pymysql.connect( host='localhost', user='user', password='pass', db='counters' ) cur = conn.cursor() Then i execute insert and update sql statements but i never close the connection. I presume python closes the connection when the script ends. Doesn't it? From ast.donotanswer at gmail.com Wed Oct 2 01:12:50 2019 From: ast.donotanswer at gmail.com (ast) Date: Wed, 2 Oct 2019 07:12:50 +0200 Subject: Recursive method in class In-Reply-To: References: <5d8df86e$0$3370$426a74cc@news.free.fr> Message-ID: <5d9431d4$0$31407$426a74cc@news.free.fr> Le 01/10/2019 ? 20:56, Timur Tabi a ?crit?: > Could you please fix your email software so that it shows a legitimate > email address in the From: line? Your emails all show this: > > From: ast > > All of your emails are being caught in my spam filter because of this > address. I would email you privately, but I know none at gmail.com isn't > your real email address. > Do "legitimate" means and address with a dot ? But your own email address doesn't have a dot. I don't want to show my real email address because I don't want to be flooded with spam. I choose: ast.donotanswer at gmail.com Hope it will convenient for you From songofacandy at gmail.com Wed Oct 2 01:25:54 2019 From: songofacandy at gmail.com (Inada Naoki) Date: Wed, 2 Oct 2019 14:25:54 +0900 Subject: pymysql.err.InterfaceError after some hours of usage In-Reply-To: References: Message-ID: MySQL connection can be closed automatically by various reasons. For example, `wait_timeout` is the most common but not only reason for closing the connection. You should connect and close MySQL connection for each HTTP request. Or you can use more smart connection pool (e.g. Engine in SQLAlchemy). It provides `pool_recycle` and `pool_pre_ping` options. https://docs.sqlalchemy.org/en/13/core/pooling.html#setting-pool-recycle https://docs.sqlalchemy.org/en/13/core/engines.html#sqlalchemy.create_engine.params.pool_pre_ping On Wed, Oct 2, 2019 at 2:16 PM ????? ?????? wrote: > > Hello, i use 'module pymysql' for connectivity in my wsgi scripts. For some reason after some hours of i.e. 'http://superhost.gr/files' i get the following error when the script tries to run: > Do you know why this is happening?! > > > Error: 500 Internal Server Error > Sorry, the requested URL 'http://superhost.gr/files/' caused an error: > > Internal Server Error > Exception: > InterfaceError("(0, '')",) > Traceback: > Traceback (most recent call last): > File "/usr/lib/python3.6/site-packages/bottle.py", line 862, in _handle > return route.call(**args) > File "/usr/lib/python3.6/site-packages/bottle.py", line 1740, in wrapper > rv = callback(*a, **ka) > File "/home/nikos/wsgi/files.py", line 143, in displayall > convert() > File "/home/nikos/wsgi/files.py", line 93, in convert > cur.execute('''SELECT file FROM files''') > File "/usr/lib64/python3.6/site-packages/pymysql/cursors.py", line 170, in execute > result = self._query(query) > File "/usr/lib64/python3.6/site-packages/pymysql/cursors.py", line 328, in _query > conn.query(q) > File "/usr/lib64/python3.6/site-packages/pymysql/connections.py", line 516, in query > self._execute_command(COMMAND.COM_QUERY, sql) > File "/usr/lib64/python3.6/site-packages/pymysql/connections.py", line 750, in _execute_command > raise err.InterfaceError("(0, '')") > pymysql.err.InterfaceError: (0, '') > > > > I only use this opening statement in the beginning of my scripts. > > conn = pymysql.connect( host='localhost', user='user', password='pass', db='counters' ) > cur = conn.cursor() > > Then i execute insert and update sql statements but i never close the connection. I presume python closes the connection when the script ends. Doesn't it? > -- > https://mail.python.org/mailman/listinfo/python-list -- Inada Naoki From rosuav at gmail.com Wed Oct 2 02:28:40 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Oct 2019 16:28:40 +1000 Subject: python socket dns query will get the correct result while the dig will not. In-Reply-To: References: Message-ID: On Wed, Oct 2, 2019 at 2:31 PM Hongyi Zhao wrote: > > Hi, > > See my following test: > > With ipython: > > In [1]: import > socket > > In [2]: socket.gethostbyname > ('www.vpngate.net') > Out[2]: '130.158.75.44' > > > With dig: > > $ dig www.vpngate.net @114.114.114.114 +short > 31.13.65.1 > $ dig www.vpngate.net @8.8.8.8 +short > 46.82.174.68 > > Any hints? When you ask dig, you are always asking for a DNS lookup. But gethostbyname does a lot of other things too. My guess is that your /etc/hosts has an entry for that domain. It's also possible that your DNS resolver is misconfigured, especially since the authoritative servers for that domain disagree with your dig results. ChrisA From hongyi.zhao at gmail.com Wed Oct 2 02:36:58 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Wed, 2 Oct 2019 06:36:58 +0000 (UTC) Subject: python socket dns query will get the correct result while the dig will not. References: Message-ID: On Wed, 02 Oct 2019 16:28:40 +1000, Chris Angelico wrote: > When you ask dig, you are always asking for a DNS lookup. But > gethostbyname does a lot of other things too. What other things, could you please give more detailed hints? > My guess is that your > /etc/hosts has an entry for that domain. No. > It's also possible that your > DNS resolver is misconfigured, especially since the authoritative > servers for that domain disagree with your dig results. As you can see, I use the public dns servers for the dig, and I cannot do any config on these dns resolvers. > > ChrisA From rosuav at gmail.com Wed Oct 2 02:45:55 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Oct 2019 16:45:55 +1000 Subject: python socket dns query will get the correct result while the dig will not. In-Reply-To: References: Message-ID: On Wed, Oct 2, 2019 at 4:41 PM Hongyi Zhao wrote: > > On Wed, 02 Oct 2019 16:28:40 +1000, Chris Angelico wrote: > > > When you ask dig, you are always asking for a DNS lookup. But > > gethostbyname does a lot of other things too. > > What other things, could you please give more detailed hints? Start with /etc/nsswitch.conf and see how far down the rabbit hole you want to go... http://man7.org/linux/man-pages/man5/nsswitch.conf.5.html > > My guess is that your > > /etc/hosts has an entry for that domain. > > No. > > > It's also possible that your > > DNS resolver is misconfigured, especially since the authoritative > > servers for that domain disagree with your dig results. > > As you can see, I use the public dns servers for the dig, and I cannot do > any config on these dns resolvers. > Actually I'm not sure that you are, since you're getting completely different results to mine. It's possible you have something intercepting your DNS requests. Hmm. The first IP you posted (which purportedly came back from 114.114.114.114) belongs to Facebook. That's pretty suspicious. ChrisA From ml_news at posteo.de Wed Oct 2 03:17:18 2019 From: ml_news at posteo.de (Manfred Lotz) Date: Wed, 2 Oct 2019 09:17:18 +0200 Subject: python socket dns query will get the correct result while the dig will not. References: Message-ID: <20191002091718.2066d592@arcor.com> On Wed, 2 Oct 2019 04:27:14 +0000 (UTC) Hongyi Zhao wrote: > Hi, > > See my following test: > > With ipython: > > In [1]: import > socket > > In [2]: socket.gethostbyname > ('www.vpngate.net') > Out[2]: '130.158.75.44' > I get '130.158.75.39' which is ok. > > With dig: > > $ dig www.vpngate.net @114.114.114.114 +short This gives here: 130.158.75.48 130.158.75.42 130.158.75.35 130.158.75.36 130.158.75.44 130.158.75.40 130.158.75.39 130.158.75.38 -- Manfred From hongyi.zhao at gmail.com Wed Oct 2 03:37:16 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Wed, 2 Oct 2019 07:37:16 +0000 (UTC) Subject: ipython in different loctions. Message-ID: Hi, I noticed that the ipython on my Debian box located in the following locations: werner at localhost:~$ ls .local/bin/ipython* .local/bin/ipython .local/bin/ipython3 werner at localhost:~$ ls .pyenv/shims/ipython* .pyenv/shims/ipython .pyenv/shims/ipython3 And, they are different: -------- werner at localhost:~$ diff .pyenv/shims/ipython3 .local/bin/ipython3 1,3c1 < #!/usr/bin/env bash < set -e < [ -n "$PYENV_DEBUG" ] && set -x --- > #!/usr/bin/python3 5,18c3,5 < program="${0##*/}" < if [[ "$program" = "python"* ]]; then < for arg; do < case "$arg" in < -c* | -- ) break ;; < */* ) < if [ -f "$arg" ]; then < export PYENV_FILE_ARG="$arg" < break < fi < ;; < esac < done < fi --- > # -*- coding: utf-8 -*- > import re > import sys 20,21c7,11 < export PYENV_ROOT="/home/werner/.pyenv" < exec "/home/werner/.pyenv/libexec/pyenv" exec "$program" "$@" --- > from IPython import start_ipython > > if __name__ == '__main__': > sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) > sys.exit(start_ipython()) ---------- Any hints on this issue? From PythonList at DancesWithMice.info Wed Oct 2 04:14:33 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 2 Oct 2019 21:14:33 +1300 Subject: pathlib In-Reply-To: References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> Message-ID: <0b717cf2-5b84-a150-09ce-4d50c8175fa3@DancesWithMice.info> On 2/10/19 12:52 AM, Rhodri James wrote: > On 01/10/2019 06:03, DL Neil via Python-list wrote: >> On 30/09/19 9:28 PM, Barry Scott wrote: >>>> On 30 Sep 2019, at 05:40, DL Neil via Python-list >>>> wrote: >>>> >>>> Should pathlib reflect changes it has made to the file-system? >>> >>> I think it should not. >> >> The term "concrete" is applied to Path(), PosixPath(), and >> WindowsPath() - whereas the others are differentiated with the prefix >> "Pure". >> >> I take "concrete" to mean 'existing in reality or real experience'. >> Thus, I saw the Pure* entities as supporting abstract paths, but the >> concrete entities as representing (and reflecting) real-world (file >> system) entities. >> >> Thus, there is no need for .exists() to be available in the Pure >> paths, but there is when utilising their concrete implementations. > > Sorry but your logic is inconsistent here.? For starters, it's not that > there's no need for .exists() in Pure paths, it's that .exists() is > meaningless.? Pure paths aren't related to any actual filing system (to > paraphrase you), so existence isn't an option. > > However if you insist that "concrete" means "existing in reality", then > .exists() is unnecessary because by your very definition the path must > exist.? The very act of creating the Path object would create the > corresponding file or directory.? So either pathlib does something > horrific, or your definition is wrong. Very good! Yes, I'd picked-on .exists() purely (hah!) because it does not appear in PurePaths, but does in concrete Paths. That said, it is one of the ways that a path can be shown to transition from some 'pure' state to become 'concrete'. However, A.N.Other has suggested that I might be mis-applying the word "concrete", so maybe not. On which topic, I went looking for a decent technical definition of the word, but instead of coming-out smiling, I've been left somewhat stony-faced (hah, hah!). A definition/description would be useful. Any pointers? > Consider for a moment: > > rhodri at scrote:~$ cat /home/rhodri/foo.txt > cat: /home/rhodri/foo.txt: No such file or directory > > cat "concatenates files" to quote its man page. Does that mean it > creates them if they don't exist, just because I typed the name into the > command? No. I wouldn't expect it either. In exactly the same way I > don't expect a concrete file*name* to necessarily refer to an actual file. I haven't followed this point: throwing a non-existent file at cat produces an err.msg. Neither of us are surprised! However, we know exactly which path was/paths were used, and where (at least the first) error was found. In the case that sparked this enquiry, and in most others, there is no need for a path that doesn't actually lead somewhere. The paths that are used, identify files, open them, rename them, create directories, etc. The idea of a path that just 'exists' (sorry!), without being part of some purpose, seems odd. At this time (and assuming that after two (separate) incidents dragging me away to solve other people's problems, I intend to stick with trying to get my head around pathlib - even if I have to sub-class it (which my reading shows is another 'can of worms'). So, 'reading' is about all I've accomplished since the original post. Sadly, the majority of posts seem to have come from other confused-minds - many of whom seemed to be giving-up in disgust. If true, such represents TWO failures! I'm sure that the designer(s) had a clear vision (having watched previous attempts rise-and-fall), but per earlier in this discussion, maybe the explanation and 'vision' could be better communicated to us simple-boys? Regarding this discussion: I've been able to take points-raised and learn, even to decide on some tactics for future use. Thanks to all who have contributed wisdom... -- Regards =dn From Richard at Damon-Family.org Wed Oct 2 06:22:29 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Wed, 2 Oct 2019 06:22:29 -0400 Subject: Recursive method in class In-Reply-To: <5d9431d4$0$31407$426a74cc@news.free.fr> References: <5d8df86e$0$3370$426a74cc@news.free.fr> <5d9431d4$0$31407$426a74cc@news.free.fr> Message-ID: <7448d9ca-29e8-54df-68a0-8b449447c16a@Damon-Family.org> On 10/2/19 1:12 AM, ast wrote: > Le 01/10/2019 ? 20:56, Timur Tabi a ?crit?: >> Could you please fix your email software so that it shows a legitimate >> email address in the From: line?? Your emails all show this: >> >> ???? From: ast >> >> All of your emails are being caught in my spam filter because of this >> address.? I would email you privately, but I know none at gmail.com isn't >> your real email address. >> > > Do "legitimate" means and address with a dot ? > But your own email address doesn't have a dot. > > I don't want to show my real email address > because I don't want to be flooded with spam. > > I choose: ast.donotanswer at gmail.com > Hope it will convenient for you > Legitimate means one that you 'own' or are authorized to use. If you have not registered with gmail this email address, then your use of it qualifies as abuse (as it may well be impersonation of someone else), and may be enough grounds for the service you are using for posting to permanently ban you from ever posting again. There are some domains specifically reserved so that purpose, like invalid. If you want to use an invalid email address, then you could use something like 'ast at invalid' or 'ast at email.invalid' and then you know that you can't be accidentally impersonating someone else. -- Richard Damon From bouncingcats at gmail.com Wed Oct 2 07:00:16 2019 From: bouncingcats at gmail.com (David) Date: Wed, 2 Oct 2019 21:00:16 +1000 Subject: Recursive method in class In-Reply-To: <5d9431d4$0$31407$426a74cc@news.free.fr> References: <5d8df86e$0$3370$426a74cc@news.free.fr> <5d9431d4$0$31407$426a74cc@news.free.fr> Message-ID: On Wed, 2 Oct 2019 at 15:15, ast wrote: > Le 01/10/2019 ? 20:56, Timur Tabi a ?crit : > > Could you please fix your email software so that it shows a legitimate > > email address in the From: line? > I choose: ast.donotanswer at gmail.com Hi ast, Please look here to see how your email looks on gmail: https://imgur.com/a/jqBNhLu This is how gmail shows you to everyone. gmail says: "ast uses a fake email address on our domain. It is a lie. So not trust him." The problem is that you use ........ at gmail.com that is not owned by you and gmail tells the world about that. It makes you look bad. You should use ..... at invalid for this purpose. It will do what you want without making you look bad and annoying everyone that you try to talk with. From rosuav at gmail.com Wed Oct 2 07:06:56 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Oct 2019 21:06:56 +1000 Subject: Recursive method in class In-Reply-To: References: <5d8df86e$0$3370$426a74cc@news.free.fr> <5d9431d4$0$31407$426a74cc@news.free.fr> Message-ID: On Wed, Oct 2, 2019 at 9:01 PM David wrote: > > On Wed, 2 Oct 2019 at 15:15, ast wrote: > > Le 01/10/2019 ? 20:56, Timur Tabi a ?crit : > > > > Could you please fix your email software so that it shows a legitimate > > > email address in the From: line? > > > I choose: ast.donotanswer at gmail.com > > Hi ast, > > Please look here to see how your email looks on gmail: > https://imgur.com/a/jqBNhLu > > This is how gmail shows you to everyone. gmail says: > "ast uses a fake email address on our domain. > It is a lie. So not trust him." > > The problem is that you use ........ at gmail.com > > that is not owned by you and gmail tells the world > about that. It makes you look bad. > > You should use ..... at invalid for this purpose. > > It will do what you want without making you look > bad and annoying everyone that you try to > talk with. ... or, more likely: "without having all your posts silently discarded so people only notice when other people reply to you", which is how your posts appear - or don't - to me. ChrisA From ast at invalid Wed Oct 2 07:26:06 2019 From: ast at invalid (ast) Date: Wed, 2 Oct 2019 13:26:06 +0200 Subject: Recursive method in class In-Reply-To: References: <5d8df86e$0$3370$426a74cc@news.free.fr> <5d9431d4$0$31407$426a74cc@news.free.fr> <7448d9ca-29e8-54df-68a0-8b449447c16a@Damon-Family.org> Message-ID: <5d94894f$0$15483$426a74cc@news.free.fr> Le 02/10/2019 ? 12:22, Richard Damon a ?crit?: > On 10/2/19 1:12 AM, ast wrote: >> Le 01/10/2019 ? 20:56, Timur Tabi a ?crit?: >>> Could you please fix your email software so that it shows a legitimate >>> email address in the From: line?? Your emails all show this: >>> >>> ???? From: ast >>> >>> All of your emails are being caught in my spam filter because of this >>> address.? I would email you privately, but I know none at gmail.com isn't >>> your real email address. >>> >> >> Do "legitimate" means and address with a dot ? >> But your own email address doesn't have a dot. >> >> I don't want to show my real email address >> because I don't want to be flooded with spam. >> >> I choose: ast.donotanswer at gmail.com >> Hope it will convenient for you >> > Legitimate means one that you 'own' or are authorized to use. If you > have not registered with gmail this email address, then your use of it > qualifies as abuse (as it may well be impersonation of someone else), > and may be enough grounds for the service you are using for posting to > permanently ban you from ever posting again. There are some domains > specifically reserved so that purpose, like invalid. > > If you want to use an invalid email address, then you could use > something like 'ast at invalid' or 'ast at email.invalid' and then you know > that you can't be accidentally impersonating someone else. > understood From 2QdxY4RzWzUUiLuE at potatochowder.com Wed Oct 2 07:42:23 2019 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Wed, 2 Oct 2019 07:42:23 -0400 Subject: pathlib In-Reply-To: <0b717cf2-5b84-a150-09ce-4d50c8175fa3@DancesWithMice.info> References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> <0b717cf2-5b84-a150-09ce-4d50c8175fa3@DancesWithMice.info> Message-ID: On 10/2/19 4:14 AM, DL Neil via Python-list wrote: > In the case that sparked this enquiry, and in most others, there is no > need for a path that doesn't actually lead somewhere. The paths that are > used, identify files, open them, rename them, create directories, etc. > The idea of a path that just 'exists' (sorry!), without being part of > some purpose, seems odd. Think about preferences. Users can put preferences in (e.g.) ~/.config/prefs, admins might provide "local" preferences in /etc/prefs, and the developers might provide fallback preferences in /etc/prefs. When the application starts up, it could have a list of paths to files that may or may not exist. Or think about the shell in that failed "cat" command. It's possible that cat created a path from what the user typed and then tried to open it. For that brief moment, cat had a path to a file that didn't exist, however un-useful it may have been. > At this time (and assuming that after two (separate) incidents dragging > me away to solve other people's problems, I intend to stick with trying > to get my head around pathlib - even if I have to sub-class it (which my > reading shows is another 'can of worms'). So, 'reading' is about all > I've accomplished since the original post. Sadly, the majority of posts > seem to have come from other confused-minds - many of whom seemed to be > giving-up in disgust. If true, such represents TWO failures! I'm sure > that the designer(s) had a clear vision (having watched previous > attempts rise-and-fall), but per earlier in this discussion, maybe the > explanation and 'vision' could be better communicated to us simple-boys? I don't think anyone gave up in disgust. Yes, there was some disagreement, and now the discussion has slowed or stopped, but I think your original question was answered: Path objects, apparently by an arguably questionable design, fail to meet your expecation, and some simple changes end up breaking backwards compatibility. Maybe a documentation change could prevent others from experiencing the same expectation failure. Maybe you could implement one of the proposed changes in a private library function as a workaround? From rhodri at kynesim.co.uk Wed Oct 2 10:07:59 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 2 Oct 2019 15:07:59 +0100 Subject: pathlib In-Reply-To: <0b717cf2-5b84-a150-09ce-4d50c8175fa3@DancesWithMice.info> References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> <0b717cf2-5b84-a150-09ce-4d50c8175fa3@DancesWithMice.info> Message-ID: <37227e80-117d-f281-e5da-146099af38bb@kynesim.co.uk> On 02/10/2019 09:14, DL Neil via Python-list wrote: > That said, it is one of the ways that a path can be shown to transition > from some 'pure' state to become 'concrete'. > > However, A.N.Other has suggested that I might be mis-applying the word > "concrete", so maybe not. On which topic, I went looking for a decent > technical definition of the word, but instead of coming-out smiling, > I've been left somewhat stony-faced (hah, hah!). > > A definition/description would be useful. Any pointers? I think we're looking at a philosophical split, so I'd look in that direction rather than for technical terminology. My rough and ready definition *in this instance* relies on observing that we are supposed to contrast "pure" and "concrete" and going from there. The overriding thing for me is that paths are names. Just names. They have a particular syntax, but that's all. This is obviously true for pure paths, which are clearly abstractions. PurePath("/home/rhodri/foo.txt") cannot refer to a real file because it has no mechanisms for relating to reality. It can only be a name, and all the PurePath class gives us is convenient mechanisms for manipulating that name within its syntactic rules. Concrete paths are not pure paths. Literally, in logic terms. Pure paths cannot refer to real file, concrete paths can refer to real files. They don't necessarily do so otherwise we have a massive excluded middle. Path("/home/rhodri/foo.txt") may or may not actually exist on any computer. It may refer to a file, and by the end of this sentence it may refer to a different file to what it was at the start. The only sensible interpretation I can see is that it is still a name, just one that may transiently be related to a real object. Concrete may not be the best term for this, but I can't think of a better one. -- Rhodri James *-* Kynesim Ltd From vergos.nikolas at gmail.com Wed Oct 2 01:33:16 2019 From: vergos.nikolas at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Tue, 1 Oct 2019 22:33:16 -0700 (PDT) Subject: pymysql.err.InterfaceError after some hours of usage In-Reply-To: References: Message-ID: <5a32dd0a-59b1-481f-aa63-a7b269df2eb3@googlegroups.com> ?? ???????, 2 ????????? 2019 - 8:26:38 ?.?. UTC+3, ? ??????? Inada Naoki ??????: > MySQL connection can be closed automatically by various reasons. > For example, `wait_timeout` is the most common but not only reason for > closing the connection. > > You should connect and close MySQL connection for each HTTP request. > > Or you can use more smart connection pool (e.g. Engine in SQLAlchemy). > It provides `pool_recycle` and `pool_pre_ping` options. > > https://docs.sqlalchemy.org/en/13/core/pooling.html#setting-pool-recycle You mean that every time i insrt/update and in general having a cur.execute() i then need to close the pymysql connection in order to not have this error? From songofacandy at gmail.com Wed Oct 2 12:11:22 2019 From: songofacandy at gmail.com (Inada Naoki) Date: Thu, 3 Oct 2019 01:11:22 +0900 Subject: pymysql.err.InterfaceError after some hours of usage In-Reply-To: <5a32dd0a-59b1-481f-aa63-a7b269df2eb3@googlegroups.com> References: <5a32dd0a-59b1-481f-aa63-a7b269df2eb3@googlegroups.com> Message-ID: 2019?10?3?(?) 0:56 ????? ?????? : > ?? ???????, 2 ????????? 2019 - 8:26:38 ?.?. UTC+3, ? ??????? Inada Naoki > ??????: > > MySQL connection can be closed automatically by various reasons. > > For example, `wait_timeout` is the most common but not only reason for > > closing the connection. > > > > You should connect and close MySQL connection for each HTTP request. > > > > Or you can use more smart connection pool (e.g. Engine in SQLAlchemy). > > It provides `pool_recycle` and `pool_pre_ping` options. > > > > https://docs.sqlalchemy.org/en/13/core/pooling.html#setting-pool-recycle > > You mean that every time i insrt/update and in general having a > cur.execute() i then need to close the pymysql connection in order to not > have this error? > No, I meant one new DB connection for each HTTP request, not for each DB query. -- > https://mail.python.org/mailman/listinfo/python-list > From vergos.nikolas at gmail.com Wed Oct 2 12:38:13 2019 From: vergos.nikolas at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Wed, 2 Oct 2019 09:38:13 -0700 (PDT) Subject: pymysql.err.InterfaceError after some hours of usage In-Reply-To: References: <5a32dd0a-59b1-481f-aa63-a7b269df2eb3@googlegroups.com> Message-ID: ?? ???????, 2 ????????? 2019 - 7:11:52 ?.?. UTC+3, ? ??????? Inada Naoki ??????: > 2019?10?3?(?) 0:56 ????? ?????? : > > > ?? ???????, 2 ????????? 2019 - 8:26:38 ?.?. UTC+3, ? ??????? Inada Naoki > > ??????: > > > MySQL connection can be closed automatically by various reasons. > > > For example, `wait_timeout` is the most common but not only reason for > > > closing the connection. > > > > > > You should connect and close MySQL connection for each HTTP request. > > > > > > Or you can use more smart connection pool (e.g. Engine in SQLAlchemy). > > > It provides `pool_recycle` and `pool_pre_ping` options. > > > > > > https://docs.sqlalchemy.org/en/13/core/pooling.html#setting-pool-recycle > > > > You mean that every time i insrt/update and in general having a > > cur.execute() i then need to close the pymysql connection in order to not > > have this error? > > > > No, I meant one new DB connection for each HTTP request, not for each DB > query. After seeing a stackoverflow link, it was stating that: This is caused by a global cursor. Try creating and closing the cursor within each method a raw query is needed. cursor = connection.cursor() cursor.execute(query) cursor.close() Does that mean that i have to create a cursor then execute the SQL statement and the close the cursor? And i must do that before and after executing each SQL statement in all of my scripts? Doesn't the DB Connection have a directive to autoclose the resources? From barry at barrys-emacs.org Wed Oct 2 13:25:18 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Wed, 2 Oct 2019 18:25:18 +0100 Subject: pathlib In-Reply-To: <0b717cf2-5b84-a150-09ce-4d50c8175fa3@DancesWithMice.info> References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> <0b717cf2-5b84-a150-09ce-4d50c8175fa3@DancesWithMice.info> Message-ID: <6A3FC430-2822-4174-9320-E3ED022C1B9F@barrys-emacs.org> > On 2 Oct 2019, at 09:14, DL Neil via Python-list wrote: > > On 2/10/19 12:52 AM, Rhodri James wrote: >> On 01/10/2019 06:03, DL Neil via Python-list wrote: >>> On 30/09/19 9:28 PM, Barry Scott wrote: >>>>> On 30 Sep 2019, at 05:40, DL Neil via Python-list wrote: >>>>> >>>>> Should pathlib reflect changes it has made to the file-system? >>>> >>>> I think it should not. >>> >>> The term "concrete" is applied to Path(), PosixPath(), and WindowsPath() - whereas the others are differentiated with the prefix "Pure". >>> >>> I take "concrete" to mean 'existing in reality or real experience'. Thus, I saw the Pure* entities as supporting abstract paths, but the concrete entities as representing (and reflecting) real-world (file system) entities. >>> >>> Thus, there is no need for .exists() to be available in the Pure paths, but there is when utilising their concrete implementations. >> Sorry but your logic is inconsistent here. For starters, it's not that there's no need for .exists() in Pure paths, it's that .exists() is meaningless. Pure paths aren't related to any actual filing system (to paraphrase you), so existence isn't an option. >> However if you insist that "concrete" means "existing in reality", then .exists() is unnecessary because by your very definition the path must exist. The very act of creating the Path object would create the corresponding file or directory. So either pathlib does something horrific, or your definition is wrong. > > > Very good! Yes, I'd picked-on .exists() purely (hah!) because it does not appear in PurePaths, but does in concrete Paths. > > On which topic, I went looking for a decent technical definition of the word, but instead of coming-out smiling, I've been left somewhat stony-faced (hah, hah!). "concrete adj. Of or relating to an actual, specific thing or instance; particular. " > That said, it is one of the ways that a path can be shown to transition from some 'pure' state to become 'concrete'. > > However, A.N.Other has suggested that I might be mis-applying the word "concrete", so maybe not. Concrete means a specific operating system's filesystem rules, Windows or Posix. > > A definition/description would be useful. Any pointers? Barry From PythonList at DancesWithMice.info Wed Oct 2 18:24:05 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 3 Oct 2019 11:24:05 +1300 Subject: pathlib In-Reply-To: <6A3FC430-2822-4174-9320-E3ED022C1B9F@barrys-emacs.org> References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> <0b717cf2-5b84-a150-09ce-4d50c8175fa3@DancesWithMice.info> <6A3FC430-2822-4174-9320-E3ED022C1B9F@barrys-emacs.org> Message-ID: <95b88a59-8386-e730-8c8a-0944d4c96cb2@DancesWithMice.info> On 3/10/19 6:25 AM, Barry Scott wrote: >> On 2 Oct 2019, at 09:14, DL Neil via Python-list >> > wrote: >> On 2/10/19 12:52 AM, Rhodri James wrote: >>> On 01/10/2019 06:03, DL Neil via Python-list wrote: >>>> On 30/09/19 9:28 PM, Barry Scott wrote: >>>>>> On 30 Sep 2019, at 05:40, DL Neil via Python-list >>>>>> > wrote: >>>>>> >>>>>> Should pathlib reflect changes it has made to the file-system? >>>>> >>>>> I think it should not. >>>> >>>> The term "concrete" is applied to Path(), PosixPath(), and >>>> WindowsPath() - whereas the others are differentiated with the >>>> prefix "Pure". >>>> >>>> I take "concrete" to mean 'existing in reality or real experience'. >>>> Thus, I saw the Pure* entities as supporting abstract paths, but the >>>> concrete entities as representing (and reflecting) real-world (file >>>> system) entities. >>>> >>>> Thus, there is no need for .exists() to be available in the Pure >>>> paths, but there is when utilising their concrete implementations. >>> Sorry but your logic is inconsistent here.? For starters, it's not >>> that there's no need for .exists() in Pure paths, it's that .exists() >>> is meaningless.? Pure paths aren't related to any actual filing >>> system (to paraphrase you), so existence isn't an option. >>> However if you insist that "concrete" means "existing in reality", >>> then .exists() is unnecessary because by your very definition the >>> path must exist.? The very act of creating the Path object would >>> create the corresponding file or directory.? So either pathlib does >>> something horrific, or your definition is wrong. >> >> >> Very good! Yes, I'd picked-on .exists() purely (hah!) because it does >> not appear in PurePaths, but does in concrete Paths. >> > > >> On which topic, I went looking for a decent technical definition of >> the word, but instead of coming-out smiling, I've been left somewhat >> stony-faced (hah, hah!). > > "concrete > > * > adj. > Of or relating to an actual, specific thing or instance; particular. > " > > >> That said, it is one of the ways that a path can be shown to >> transition from some 'pure' state to become 'concrete'. >> >> However, A.N.Other has suggested that I might be mis-applying the word >> "concrete", so maybe not. > > Concrete means a specific operating system's filesystem rules, Windows > or Posix. At last the gears have stopped grinding! (cement dust?) The distinction of "pure", as distinct from "concrete", was readily grasped. The idea that "concrete" refers to FS rules, cf files on the FS, has been what so many have been battling to lodge between my ears. Well done! Also, nicely stated. In view of my not being the only one to arrive with similar expectations, do you/we feel that this is carefully and sufficiently conveyed within the (PSL) documentation? -- Regards =dn From PythonList at DancesWithMice.info Wed Oct 2 18:27:47 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 3 Oct 2019 11:27:47 +1300 Subject: pathlib In-Reply-To: <37227e80-117d-f281-e5da-146099af38bb@kynesim.co.uk> References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> <0b717cf2-5b84-a150-09ce-4d50c8175fa3@DancesWithMice.info> <37227e80-117d-f281-e5da-146099af38bb@kynesim.co.uk> Message-ID: <91905a00-0fbd-8e56-85f8-f73778428ebe@DancesWithMice.info> On 3/10/19 3:07 AM, Rhodri James wrote: > On 02/10/2019 09:14, DL Neil via Python-list wrote: >> That said, it is one of the ways that a path can be shown to >> transition from some 'pure' state to become 'concrete'. >> >> However, A.N.Other has suggested that I might be mis-applying the word >> "concrete", so maybe not. On which topic, I went looking for a decent >> technical definition of the word, but instead of coming-out smiling, >> I've been left somewhat stony-faced (hah, hah!). >> >> A definition/description would be useful. Any pointers? > > I think we're looking at a philosophical split, so I'd look in that > direction rather than for technical terminology. > > My rough and ready definition *in this instance* relies on observing > that we are supposed to contrast "pure" and "concrete" and going from > there. > > The overriding thing for me is that paths are names.? Just names.? They > have a particular syntax, but that's all.? This is obviously true for > pure paths, which are clearly abstractions. > PurePath("/home/rhodri/foo.txt") cannot refer to a real file because it > has no mechanisms for relating to reality.? It can only be a name, and > all the PurePath class gives us is convenient mechanisms for > manipulating that name within its syntactic rules. > > Concrete paths are not pure paths.? Literally, in logic terms.? Pure > paths cannot refer to real file, concrete paths can refer to real files. > ?They don't necessarily do so otherwise we have a massive excluded > middle.? Path("/home/rhodri/foo.txt") may or may not actually exist on > any computer.? It may refer to a file, and by the end of this sentence > it may refer to a different file to what it was at the start.? The only > sensible interpretation I can see is that it is still a name, just one > that may transiently be related to a real object. > > Concrete may not be the best term for this, but I can't think of a > better one. Nor I, but had assumed (having seen it before) that it was a generally-accepted term in OOP that I have yet to learn. Was slightly surprised not to find it in any of the/my usual tech.dictionaries. Obviously, my assumptions/expectations of its meaning were inaccurate or incomplete, but I appreciate your efforts to straighten-out it (and me)! -- Regards =dn From PythonList at DancesWithMice.info Wed Oct 2 18:58:59 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 3 Oct 2019 11:58:59 +1300 Subject: pathlib In-Reply-To: References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> <0b717cf2-5b84-a150-09ce-4d50c8175fa3@DancesWithMice.info> Message-ID: <977ce549-6b1e-650e-e575-cd6ea6924daa@DancesWithMice.info> On 3/10/19 12:42 AM, Dan Sommers wrote: > On 10/2/19 4:14 AM, DL Neil via Python-list wrote: > >> In the case that sparked this enquiry, and in most others, there is no >> need for a path that doesn't actually lead somewhere. The paths that are >> used, identify files, open them, rename them, create directories, etc. >> The idea of a path that just 'exists' (sorry!), without being part of >> some purpose, seems odd. > > Think about preferences.? Users can put preferences in (e.g.) > ~/.config/prefs, admins might provide "local" preferences in > /etc/prefs, and the developers might provide fallback preferences > in /etc/prefs. > > When the application starts up, it could have a list of paths to files > that may or may not exist. This is an excellent example. Without thinking I would have left such as-is. However, what I'm taking-in, is that in order to gain advantage from the semantic meaning inherent in the Path class(es), I shouldn't leave these as strings (the way they arrive from (current) config files*) but they should be defined as (Pure) Paths in the same way that numbers will probably be converted from string inputs. As you say, because system-defaults may be over-ridden by user-prefs, there's no point in 'proving' that such a file exists - such can wait until we actually issue the .open() That said, surely we would still use a 'concrete' class, in case? * in the case of YAML files, might we even be able to define those values as Path()-s... > Or think about the shell in that failed "cat" command.? It's > possible that cat created a path from what the user typed and > then tried to open it.? For that brief moment, cat had a path > to a file that didn't exist, however un-useful it may have been. >> At this time (and assuming that after two (separate) incidents dragging >> me away to solve other people's problems, I intend to stick with trying >> to get my head around pathlib - even if I have to sub-class it (which my >> reading shows is another 'can of worms'). So, 'reading' is about all >> I've accomplished since the original post. Sadly, the majority of posts >> seem to have come from other confused-minds - many of whom seemed to be >> giving-up in disgust. If true, such represents TWO failures! I'm sure >> that the designer(s) had a clear vision (having watched previous >> attempts rise-and-fall), but per earlier in this discussion, maybe the >> explanation and 'vision' could be better communicated to us simple-boys? > > I don't think anyone gave up in disgust.? Yes, there was some Late at night: I used the word "posts" twice, to describe two quite different communications. Apologies The subject of that comment was the (other) research/reading I've been doing. No-one on THIS list has given the impression of wanting to dump pathlib (which encourages my persisting). Certainly, although some may have quietly given-up talking to a non-OOP native - and one so 'slow', I am appreciative of all help-given! > disagreement, and now the discussion has slowed or stopped, but > think your original question was answered:? Path objects, > apparently by an arguably questionable design, fail to meet your > expecation, and some simple changes end up breaking backwards > compatibility.? Maybe a documentation change could prevent others > from experiencing the same expectation failure. As discussed previously, and elsewhere (just now). > Maybe you could implement one of the proposed changes in a private > library function as a workaround? In my mind, I'm wondering if it will come to that (having 'got past' the original observation/issue, I'm concerned by .rename()'s silent errors, for example). However, that 'outside' research, eg StackOverflow, shows that sub-classing pathlib is problematic, and quite possibly not part of the design (this is repeating 'gossip' - I'm not going to try to justify the comment or the claim). That said, last night my code sub-classing Path() seemed to work quite happily (albeit only tested on a 'Posix' box). The yawning chasm/gaping jaws below, however, are that I've probably made yet another 'assumption' about how things 'should' work. Run for the hills! This was supposed to be a simple, down-time task; a learning-opportunity re-factoring code to use a new (er, um, as of v3.4) library... Thanks again! -- Regards =dn From cs at cskk.id.au Wed Oct 2 20:19:23 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 3 Oct 2019 10:19:23 +1000 Subject: ipython in different loctions. In-Reply-To: References: Message-ID: <20191003001923.GA54548@cskk.homeip.net> On 02Oct2019 07:37, Hongyi Zhao wrote: >I noticed that the ipython on my Debian box located in the following >locations: > >werner at localhost:~$ ls .local/bin/ipython* >.local/bin/ipython .local/bin/ipython3 > >werner at localhost:~$ ls .pyenv/shims/ipython* >.pyenv/shims/ipython .pyenv/shims/ipython3 I would guess that the former came from "pip install ipython" and that the latter came from an an environment set up with pyenv. >And, they are different: > >-------- >werner at localhost:~$ diff .pyenv/shims/ipython3 .local/bin/ipython3 >1,3c1 >< #!/usr/bin/env bash This is a small shell script wrapper, presumably hooking into your pyenv setup to find the "real" ipython. >> from IPython import start_ipython >> if __name__ == '__main__': >> sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) >> sys.exit(start_ipython()) This is the Python boilerplate wrapper with pip uses to install an ipython executable script in a bin directory. You may find that the shell script from .pyenv/shims eventually executes a python script like the one from .local/bin. Try going: bash -x ~/.pyenv/shims/ipython3 and see what its final command does. Cheers, Cameron Simpson From hongyi.zhao at gmail.com Wed Oct 2 20:45:24 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Thu, 3 Oct 2019 00:45:24 +0000 (UTC) Subject: ipython in different loctions. References: <20191003001923.GA54548@cskk.homeip.net> Message-ID: On Thu, 03 Oct 2019 10:19:23 +1000, Cameron Simpson wrote: > bash -x ~/.pyenv/shims/ipython3 > > and see what its final command does. Tried as follows: ----------------- werner at localhost:~$ bash -x ~/.pyenv/shims/ipython3 + set -e + '[' -n '' ']' + program=ipython3 + [[ ipython3 = \p\y\t\h\o\n* ]] + export PYENV_ROOT=/home/werner/.pyenv + PYENV_ROOT=/home/werner/.pyenv + exec /home/werner/.pyenv/libexec/pyenv exec ipython3 Python 3.7.4 (default, Aug 29 2019, 06:59:32) Type 'copyright', 'credits' or 'license' for more information IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: ----------------- Also tried the follows: werner at localhost:~$ bash -x ~/.local/bin/ipython3 + import re + import sys + from IPython import start_ipython from: can't read /var/mail/IPython /home/werner/.local/bin/ipython3: line 10: syntax error near unexpected token `(' /home/werner/.local/bin/ipython3: line 10: ` sys.argv[0] = re.sub(r'(- script\.pyw?|\.exe)?$', '', sys.argv[0])' werner at localhost:~$ The former can start the ipython, while the latter will fail. From jagga13 at gmail.com Wed Oct 2 22:48:07 2019 From: jagga13 at gmail.com (Jagga Soorma) Date: Wed, 2 Oct 2019 19:48:07 -0700 Subject: Basic python question Message-ID: Hello, I am new to python and trying to do some basic things with python. I am writing a script that runs a df command and I need parts of that output saved in 2 different variables. Is this something that can be done? I can do this by running multiple df commands but would prefer to make only one call: -- inode_cmd = "/bin/df --output=pcent,ipcent /var| grep -v Use | tr '%' ' '" output = subprocess.check_output( inode_cmd, stderr=subprocess.STDOUT, shell=True ) -- But this would end up giving me the following: #df --output=pcent,ipcent /var | grep -v Use | tr '%' ' ' 5 1 I would like variable x to be 5 and variable y to be 1. Is there a easier way to do this? Thanks in advance for your guidance. From aldwinaldwindev at gmail.com Wed Oct 2 23:49:25 2019 From: aldwinaldwindev at gmail.com (Aldwin Pollefeyt) Date: Thu, 3 Oct 2019 11:49:25 +0800 Subject: Basic python question In-Reply-To: References: Message-ID: You could use: >>> x, y = set(output.split()) On Thu, Oct 3, 2019 at 11:44 AM Jagga Soorma wrote: > Hello, > > I am new to python and trying to do some basic things with python. I > am writing a script that runs a df command and I need parts of that > output saved in 2 different variables. Is this something that can be > done? I can do this by running multiple df commands but would prefer > to make only one call: > > -- > inode_cmd = "/bin/df --output=pcent,ipcent /var| grep -v Use | tr '%' ' '" > output = subprocess.check_output( inode_cmd, > stderr=subprocess.STDOUT, shell=True ) > -- > > But this would end up giving me the following: > > #df --output=pcent,ipcent /var | grep -v Use | tr '%' ' ' > 5 1 > > I would like variable x to be 5 and variable y to be 1. Is there a > easier way to do this? > > Thanks in advance for your guidance. > -- > https://mail.python.org/mailman/listinfo/python-list > From jagga13 at gmail.com Thu Oct 3 00:11:32 2019 From: jagga13 at gmail.com (Jagga Soorma) Date: Wed, 2 Oct 2019 21:11:32 -0700 Subject: Basic python question In-Reply-To: References: Message-ID: Thanks Aldwin that helps but it looks like it is reversing the numbers for some reason: the df command returns the following: 7 2 I used your example and did: x,y = set(output.split()) My assumption would be that x should be 7 and y should be 2. However, when I print x and y it seems to be reversed (x is 2 and y is 7). Am I missing something? Thanks On Wed, Oct 2, 2019 at 8:49 PM Aldwin Pollefeyt wrote: > > You could use: > > >>> x, y = set(output.split()) > > On Thu, Oct 3, 2019 at 11:44 AM Jagga Soorma wrote: >> >> Hello, >> >> I am new to python and trying to do some basic things with python. I >> am writing a script that runs a df command and I need parts of that >> output saved in 2 different variables. Is this something that can be >> done? I can do this by running multiple df commands but would prefer >> to make only one call: >> >> -- >> inode_cmd = "/bin/df --output=pcent,ipcent /var| grep -v Use | tr '%' ' '" >> output = subprocess.check_output( inode_cmd, >> stderr=subprocess.STDOUT, shell=True ) >> -- >> >> But this would end up giving me the following: >> >> #df --output=pcent,ipcent /var | grep -v Use | tr '%' ' ' >> 5 1 >> >> I would like variable x to be 5 and variable y to be 1. Is there a >> easier way to do this? >> >> Thanks in advance for your guidance. >> -- >> https://mail.python.org/mailman/listinfo/python-list From aldwinaldwindev at gmail.com Thu Oct 3 00:17:21 2019 From: aldwinaldwindev at gmail.com (Aldwin Pollefeyt) Date: Thu, 3 Oct 2019 12:17:21 +0800 Subject: Basic python question In-Reply-To: References: Message-ID: Oh, sorry .. please try this: >>> x,y = tuple(output.split()) On Thu, Oct 3, 2019 at 12:11 PM Jagga Soorma wrote: > Thanks Aldwin that helps but it looks like it is reversing the numbers > for some reason: > > the df command returns the following: > 7 2 > > I used your example and did: > x,y = set(output.split()) > > My assumption would be that x should be 7 and y should be 2. However, > when I print x and y it seems to be reversed (x is 2 and y is 7). Am > I missing something? > > Thanks > > On Wed, Oct 2, 2019 at 8:49 PM Aldwin Pollefeyt > wrote: > > > > You could use: > > > > >>> x, y = set(output.split()) > > > > On Thu, Oct 3, 2019 at 11:44 AM Jagga Soorma wrote: > >> > >> Hello, > >> > >> I am new to python and trying to do some basic things with python. I > >> am writing a script that runs a df command and I need parts of that > >> output saved in 2 different variables. Is this something that can be > >> done? I can do this by running multiple df commands but would prefer > >> to make only one call: > >> > >> -- > >> inode_cmd = "/bin/df --output=pcent,ipcent /var| grep -v Use | tr '%' ' > '" > >> output = subprocess.check_output( inode_cmd, > >> stderr=subprocess.STDOUT, shell=True ) > >> -- > >> > >> But this would end up giving me the following: > >> > >> #df --output=pcent,ipcent /var | grep -v Use | tr '%' ' ' > >> 5 1 > >> > >> I would like variable x to be 5 and variable y to be 1. Is there a > >> easier way to do this? > >> > >> Thanks in advance for your guidance. > >> -- > >> https://mail.python.org/mailman/listinfo/python-list > From aldwinaldwindev at gmail.com Thu Oct 3 00:19:31 2019 From: aldwinaldwindev at gmail.com (Aldwin Pollefeyt) Date: Thu, 3 Oct 2019 12:19:31 +0800 Subject: Basic python question In-Reply-To: References: Message-ID: Seems to work also: >>> [x,y] = output.split() On Thu, Oct 3, 2019 at 12:17 PM Aldwin Pollefeyt wrote: > Oh, sorry .. please try this: > > >>> x,y = tuple(output.split()) > > On Thu, Oct 3, 2019 at 12:11 PM Jagga Soorma wrote: > >> Thanks Aldwin that helps but it looks like it is reversing the numbers >> for some reason: >> >> the df command returns the following: >> 7 2 >> >> I used your example and did: >> x,y = set(output.split()) >> >> My assumption would be that x should be 7 and y should be 2. However, >> when I print x and y it seems to be reversed (x is 2 and y is 7). Am >> I missing something? >> >> Thanks >> >> On Wed, Oct 2, 2019 at 8:49 PM Aldwin Pollefeyt >> wrote: >> > >> > You could use: >> > >> > >>> x, y = set(output.split()) >> > >> > On Thu, Oct 3, 2019 at 11:44 AM Jagga Soorma wrote: >> >> >> >> Hello, >> >> >> >> I am new to python and trying to do some basic things with python. I >> >> am writing a script that runs a df command and I need parts of that >> >> output saved in 2 different variables. Is this something that can be >> >> done? I can do this by running multiple df commands but would prefer >> >> to make only one call: >> >> >> >> -- >> >> inode_cmd = "/bin/df --output=pcent,ipcent /var| grep -v Use | tr '%' >> ' '" >> >> output = subprocess.check_output( inode_cmd, >> >> stderr=subprocess.STDOUT, shell=True ) >> >> -- >> >> >> >> But this would end up giving me the following: >> >> >> >> #df --output=pcent,ipcent /var | grep -v Use | tr '%' ' ' >> >> 5 1 >> >> >> >> I would like variable x to be 5 and variable y to be 1. Is there a >> >> easier way to do this? >> >> >> >> Thanks in advance for your guidance. >> >> -- >> >> https://mail.python.org/mailman/listinfo/python-list >> > From jagga13 at gmail.com Thu Oct 3 00:26:36 2019 From: jagga13 at gmail.com (Jagga Soorma) Date: Wed, 2 Oct 2019 21:26:36 -0700 Subject: Basic python question In-Reply-To: References: Message-ID: Thanks again Aldwin. This seems to work, guess it is the set that is flipping the numbers: x,y = (output.split()) Much appreciated! On Wed, Oct 2, 2019 at 9:19 PM Aldwin Pollefeyt wrote: > > Seems to work also: > > >>> [x,y] = output.split() > > On Thu, Oct 3, 2019 at 12:17 PM Aldwin Pollefeyt wrote: >> >> Oh, sorry .. please try this: >> >> >>> x,y = tuple(output.split()) >> >> On Thu, Oct 3, 2019 at 12:11 PM Jagga Soorma wrote: >>> >>> Thanks Aldwin that helps but it looks like it is reversing the numbers >>> for some reason: >>> >>> the df command returns the following: >>> 7 2 >>> >>> I used your example and did: >>> x,y = set(output.split()) >>> >>> My assumption would be that x should be 7 and y should be 2. However, >>> when I print x and y it seems to be reversed (x is 2 and y is 7). Am >>> I missing something? >>> >>> Thanks >>> >>> On Wed, Oct 2, 2019 at 8:49 PM Aldwin Pollefeyt >>> wrote: >>> > >>> > You could use: >>> > >>> > >>> x, y = set(output.split()) >>> > >>> > On Thu, Oct 3, 2019 at 11:44 AM Jagga Soorma wrote: >>> >> >>> >> Hello, >>> >> >>> >> I am new to python and trying to do some basic things with python. I >>> >> am writing a script that runs a df command and I need parts of that >>> >> output saved in 2 different variables. Is this something that can be >>> >> done? I can do this by running multiple df commands but would prefer >>> >> to make only one call: >>> >> >>> >> -- >>> >> inode_cmd = "/bin/df --output=pcent,ipcent /var| grep -v Use | tr '%' ' '" >>> >> output = subprocess.check_output( inode_cmd, >>> >> stderr=subprocess.STDOUT, shell=True ) >>> >> -- >>> >> >>> >> But this would end up giving me the following: >>> >> >>> >> #df --output=pcent,ipcent /var | grep -v Use | tr '%' ' ' >>> >> 5 1 >>> >> >>> >> I would like variable x to be 5 and variable y to be 1. Is there a >>> >> easier way to do this? >>> >> >>> >> Thanks in advance for your guidance. >>> >> -- >>> >> https://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Thu Oct 3 03:40:04 2019 From: __peter__ at web.de (Peter Otten) Date: Thu, 03 Oct 2019 09:40:04 +0200 Subject: Basic python question References: Message-ID: Jagga Soorma wrote: > Thanks again Aldwin. This seems to work, guess it is the set that is > flipping the numbers: > > x,y = (output.split()) The parens on the right are superfluous: >>> a, b = "foo bar".split() >>> a 'foo' >>> b 'bar' > inode_cmd = "/bin/df --output=pcent,ipcent /var| grep -v Use | tr '%' ' '" > output = subprocess.check_output( inode_cmd, > stderr=subprocess.STDOUT, shell=True ) You may also do the post-processing in Python, which allows you to avoid the shell completely: >>> output = subprocess.check_output(["/bin/df", "--output=pcent,ipcent", "/var"]) >>> output b'Use% IUse%\n 85% 16%\n' >>> a, b = output.replace(b"%", b"").split()[-2:] >>> a b'85' >>> b b'16' If you want integers: >>> a, b = [int(v) for v in output.replace(b"%", b"").split()[-2:]] >>> a 85 >>> b 16 From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Oct 3 07:27:09 2019 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Thu, 3 Oct 2019 07:27:09 -0400 Subject: pathlib In-Reply-To: <977ce549-6b1e-650e-e575-cd6ea6924daa@DancesWithMice.info> References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> <0b717cf2-5b84-a150-09ce-4d50c8175fa3@DancesWithMice.info> <977ce549-6b1e-650e-e575-cd6ea6924daa@DancesWithMice.info> Message-ID: <2185ede6-ba1a-538e-d883-f441c7010562@potatochowder.com> On 10/2/19 6:58 PM, DL Neil via Python-list wrote: > On 3/10/19 12:42 AM, Dan Sommers wrote: > Certainly, although some may have quietly given-up talking to a > non-OOP native - and one so 'slow', I am appreciative of all > help-given! I also speak OO as a second language (usually kicking, screaming, and spouting expletives, but that's my personal perspective and a separate issue). Hold this thought. >> Maybe you could implement one of the proposed changes in a private >> library function as a workaround? > In my mind, I'm wondering if it will come to that (having 'got past' > the original observation/issue, I'm concerned by .rename()'s silent > errors, for example). However, that 'outside' research, eg > StackOverflow, shows that sub-classing pathlib is problematic, and > quite possibly not part of the design (this is repeating 'gossip' - > I'm not going to try to justify the comment or the claim) ... So don't subclass anything. :-) One non-OO option would be to write a function that takes a Path instance and a new name, calls Path.rename, and returns a new Path instance with the new name, something like this (untested): def path_rename(path, target): new_path = pathlib.Path(target) path.rename(new_path) return new_path Because it returns a new Path instance rather than mutating an existing one, you may have to re-think parts of your application that depend on a specific Path instance being mutated. The usual OO option that doesn't involve subclassing is Delegation, with a capital D. See , and see Mhttps://softwareengineering.stackexchange.com/questions/381140> for python-specific objections. > ... That said, last night my code sub-classing Path() seemed to work > quite happily (albeit only tested on a 'Posix' box). The yawning > chasm/gaping jaws below, however, are that I've probably made yet > another 'assumption' about how things 'should' work. Run for the > hills! Your caution regarding an assumption is a Good Thing. Tests, tests, and more tests. Document (in large, friendly lettering) that you haven't tested in a non-Posix environment. > This was supposed to be a simple, down-time task; a > learning-opportunity re-factoring code to use a new (er, um, as of > v3.4) library... The best laid plans.... :-) From Richard at Damon-Family.org Thu Oct 3 08:04:57 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 3 Oct 2019 08:04:57 -0400 Subject: pathlib In-Reply-To: <91905a00-0fbd-8e56-85f8-f73778428ebe@DancesWithMice.info> References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> <0b717cf2-5b84-a150-09ce-4d50c8175fa3@DancesWithMice.info> <37227e80-117d-f281-e5da-146099af38bb@kynesim.co.uk> <91905a00-0fbd-8e56-85f8-f73778428ebe@DancesWithMice.info> Message-ID: On 10/2/19 6:27 PM, DL Neil via Python-list wrote: > On 3/10/19 3:07 AM, Rhodri James wrote: >> On 02/10/2019 09:14, DL Neil via Python-list wrote: >>> That said, it is one of the ways that a path can be shown to >>> transition from some 'pure' state to become 'concrete'. >>> >>> However, A.N.Other has suggested that I might be mis-applying the >>> word "concrete", so maybe not. On which topic, I went looking for a >>> decent technical definition of the word, but instead of coming-out >>> smiling, I've been left somewhat stony-faced (hah, hah!). >>> >>> A definition/description would be useful. Any pointers? >> >> I think we're looking at a philosophical split, so I'd look in that >> direction rather than for technical terminology. >> >> My rough and ready definition *in this instance* relies on observing >> that we are supposed to contrast "pure" and "concrete" and going from >> there. >> >> The overriding thing for me is that paths are names.? Just names.? >> They have a particular syntax, but that's all.? This is obviously >> true for pure paths, which are clearly abstractions. >> PurePath("/home/rhodri/foo.txt") cannot refer to a real file because >> it has no mechanisms for relating to reality.? It can only be a name, >> and all the PurePath class gives us is convenient mechanisms for >> manipulating that name within its syntactic rules. >> >> Concrete paths are not pure paths.? Literally, in logic terms.? Pure >> paths cannot refer to real file, concrete paths can refer to real >> files. ??They don't necessarily do so otherwise we have a massive >> excluded middle.? Path("/home/rhodri/foo.txt") may or may not >> actually exist on any computer.? It may refer to a file, and by the >> end of this sentence it may refer to a different file to what it was >> at the start.? The only sensible interpretation I can see is that it >> is still a name, just one that may transiently be related to a real >> object. >> >> Concrete may not be the best term for this, but I can't think of a >> better one. > > > Nor I, but had assumed (having seen it before) that it was a > generally-accepted term in OOP that I have yet to learn. Was slightly > surprised not to find it in any of the/my usual tech.dictionaries. > > Obviously, my assumptions/expectations of its meaning were inaccurate > or incomplete, but I appreciate your efforts to straighten-out it (and > me)! My experience is that Concrete is generally thought of as the opposite of Abstract, you can make an object of a Concrete type, but not one of an Abstract type. That doesn't quite apply here as PurePath isn't an Abstract class in this sense, as you CAN create objects of type PurePath. An Abstract class would be something like Iterable which is (as far as I know) an Abstract Base Class which objects can have as a 'base' but can't be just of that type. I am not sure that Concrete is really the right term here, but the beginning of the documentation for Pathlib does sort of define what it means here: Path classes are divided between pure paths , which provide purely computational operations without I/O, and concrete paths , which inherit from pure paths but also provide I/O operations. So for Pathlib, Concrete means that it provides access to I/O operations and thus can only handle paths of the flavor of the OS the program is running on. -- Richard Damon From hongyi.zhao at gmail.com Thu Oct 3 08:48:48 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Thu, 3 Oct 2019 12:48:48 +0000 (UTC) Subject: uses both shell and python codes in one script. Message-ID: See this file: https://github.com/hongyi-zhao/dotbot/blob/master/bin/dotbot It uses both shell and python codes in one script, is this good practice? From rosuav at gmail.com Thu Oct 3 09:12:45 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Oct 2019 23:12:45 +1000 Subject: uses both shell and python codes in one script. In-Reply-To: References: Message-ID: On Thu, Oct 3, 2019 at 10:51 PM Hongyi Zhao wrote: > > See this file: > > https://github.com/hongyi-zhao/dotbot/blob/master/bin/dotbot > > It uses both shell and python codes in one script, is this good practice? Seems fine. Most of the code is elsewhere, and presumably has been written to support both Py2 and Py3; the file you're linking to is *just* a wrapper that finds an interpreter to use. Though this should be unnecessary. A simple shebang of "/usr/bin/env python3" will suffice for many many situations (and then if someone specifically wants to run it in a legacy interpreter, an explicit "python2 scriptname.py" or "python scriptname.py" will work). ChrisA From hongyi.zhao at gmail.com Thu Oct 3 09:36:11 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Thu, 3 Oct 2019 13:36:11 +0000 (UTC) Subject: uses both shell and python codes in one script. References: Message-ID: On Thu, 03 Oct 2019 23:12:45 +1000, Chris Angelico wrote: > Seems fine. Most of the code is elsewhere, and presumably has been > written to support both Py2 and Py3; the file you're linking to is > *just* a wrapper that finds an interpreter to use. > > Though this should be unnecessary. A simple shebang of "/usr/bin/env > python3" will suffice for many many situations (and then if someone > specifically wants to run it in a legacy interpreter, an explicit > "python2 scriptname.py" or "python scriptname.py" will work). I'm very confusing on the following part in this script: ---- ''':' # begin python string; this line is interpreted by the shell as `:` which python >/dev/null 2>&1 && exec python "$0" "$@" which python3 >/dev/null 2>&1 && exec python3 "$0" "$@" which python2 >/dev/null 2>&1 && exec python2 "$0" "$@" >&2 echo "error: cannot find python" exit 1 ''' ---- Any hints for the meaning of several ' used above? From rosuav at gmail.com Thu Oct 3 09:55:21 2019 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Oct 2019 23:55:21 +1000 Subject: uses both shell and python codes in one script. In-Reply-To: References: Message-ID: On Thu, Oct 3, 2019 at 11:41 PM Hongyi Zhao wrote: > > On Thu, 03 Oct 2019 23:12:45 +1000, Chris Angelico wrote: > > > > Seems fine. Most of the code is elsewhere, and presumably has been > > written to support both Py2 and Py3; the file you're linking to is > > *just* a wrapper that finds an interpreter to use. > > > > Though this should be unnecessary. A simple shebang of "/usr/bin/env > > python3" will suffice for many many situations (and then if someone > > specifically wants to run it in a legacy interpreter, an explicit > > "python2 scriptname.py" or "python scriptname.py" will work). > > I'm very confusing on the following part in this script: > > ---- > ''':' # begin python string; this line is interpreted by the shell as `:` > which python >/dev/null 2>&1 && exec python "$0" "$@" > which python3 >/dev/null 2>&1 && exec python3 "$0" "$@" > which python2 >/dev/null 2>&1 && exec python2 "$0" "$@" > >&2 echo "error: cannot find python" > exit 1 > ''' > ---- > > Any hints for the meaning of several ' used above? > The hint is there in that line, and stems from the way two different parsers (Python and sh) interpret the line. In Python, three single quote characters start a triple-quoted string, which doesn't end till you get three more; since nothing is done with this string, Python parses it and then ignores it. In the shell, the first two are an empty string, then ':' is a colon, which introduces a label (the fact that it's in quotes is irrelevant to the shell). So there's an empty label followed by a shell comment. The shell parses this line and does nothing with it. Then it moves on to the next lines, and runs the shell script. Since this shell script ends with 'exit 1', it's guaranteed to halt execution (and usually it'll exec to python, which also halts execution), so the Python code won't be executed. This is a common trick when writing polyglot code. You make the relevant code for one language appear as a comment or string literal in another. For instance, you can open a C program with "#if 0", which will cause the following text to be ignored by the C preprocessor; but since that line begins with a hash, Python will ignore it (but continue executing). ChrisA From jamtlu at gmail.com Thu Oct 3 10:15:09 2019 From: jamtlu at gmail.com (James Lu) Date: Thu, 3 Oct 2019 10:15:09 -0400 Subject: uses both shell and python codes in one script. In-Reply-To: References: Message-ID: I would use IPython as a scripting language. It has a slow startup time though. On Thu, Oct 3, 2019 at 9:59 AM Chris Angelico wrote: > On Thu, Oct 3, 2019 at 11:41 PM Hongyi Zhao wrote: > > > > On Thu, 03 Oct 2019 23:12:45 +1000, Chris Angelico wrote: > > > > > > > Seems fine. Most of the code is elsewhere, and presumably has been > > > written to support both Py2 and Py3; the file you're linking to is > > > *just* a wrapper that finds an interpreter to use. > > > > > > Though this should be unnecessary. A simple shebang of "/usr/bin/env > > > python3" will suffice for many many situations (and then if someone > > > specifically wants to run it in a legacy interpreter, an explicit > > > "python2 scriptname.py" or "python scriptname.py" will work). > > > > I'm very confusing on the following part in this script: > > > > ---- > > ''':' # begin python string; this line is interpreted by the shell as `:` > > which python >/dev/null 2>&1 && exec python "$0" "$@" > > which python3 >/dev/null 2>&1 && exec python3 "$0" "$@" > > which python2 >/dev/null 2>&1 && exec python2 "$0" "$@" > > >&2 echo "error: cannot find python" > > exit 1 > > ''' > > ---- > > > > Any hints for the meaning of several ' used above? > > > > The hint is there in that line, and stems from the way two different > parsers (Python and sh) interpret the line. In Python, three single > quote characters start a triple-quoted string, which doesn't end till > you get three more; since nothing is done with this string, Python > parses it and then ignores it. In the shell, the first two are an > empty string, then ':' is a colon, which introduces a label (the fact > that it's in quotes is irrelevant to the shell). So there's an empty > label followed by a shell comment. The shell parses this line and does > nothing with it. Then it moves on to the next lines, and runs the > shell script. Since this shell script ends with 'exit 1', it's > guaranteed to halt execution (and usually it'll exec to python, which > also halts execution), so the Python code won't be executed. > > This is a common trick when writing polyglot code. You make the > relevant code for one language appear as a comment or string literal > in another. For instance, you can open a C program with "#if 0", which > will cause the following text to be ignored by the C preprocessor; but > since that line begins with a hash, Python will ignore it (but > continue executing). > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From torriem at gmail.com Thu Oct 3 10:54:23 2019 From: torriem at gmail.com (Michael Torrie) Date: Thu, 3 Oct 2019 08:54:23 -0600 Subject: uses both shell and python codes in one script. In-Reply-To: References: Message-ID: <4b21c3e7-dbd6-27ab-c7dc-b55106d3084b@gmail.com> On 10/3/19 8:15 AM, James Lu wrote: > I would use IPython as a scripting language. It has a slow startup time > though. Lately I've been using Xonsh, which is a much more comfortable application of Python to shell scripting than anything else I've tried. Occasionally subprocess mode selection vs Python mode might seem a bit magical, and that bothers me a bit. But overall I've begun using it for many of my shell scripts now. I don't find startup to be any slower than any other python script I've written. I've thought about using Xonsh as my main shell, but for now I'm still using Zsh. From rosuav at gmail.com Thu Oct 3 13:34:49 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Oct 2019 03:34:49 +1000 Subject: uses both shell and python codes in one script. In-Reply-To: References: Message-ID: On Fri, Oct 4, 2019 at 12:15 AM James Lu wrote: > > I would use IPython as a scripting language. It has a slow startup time though. > And how, in the messy world of cross-platform scripting, would you locate the interpreter? The whole point of this script is to attempt three different shebangs, effectively. ChrisA From dorismarca at outlook.es Thu Oct 3 15:10:33 2019 From: dorismarca at outlook.es (Doris Marca Guaraca) Date: Thu, 3 Oct 2019 19:10:33 +0000 Subject: how can i run python script in spamassassin Message-ID: Hello, I'm sorry to bother you, I just reviewed this post, the Python beginner, the Linux beginner, needs to run spamassassin, and now I'm trying to do something very similar with a Python script is for a project, maybe you can help me thanks. I appreciate it a lot. Regards Doris From torriem at gmail.com Thu Oct 3 15:20:13 2019 From: torriem at gmail.com (Michael Torrie) Date: Thu, 3 Oct 2019 13:20:13 -0600 Subject: how can i run python script in spamassassin In-Reply-To: References: Message-ID: <52100887-5457-8cfb-7c2f-e7d3e10670e9@gmail.com> On 10/3/19 1:10 PM, Doris Marca Guaraca wrote: > > Hello, I'm sorry to bother you, I just reviewed this post, the Python beginner, the Linux beginner, needs to run spamassassin, and now I'm trying to do something very similar with a Python script is for a project, maybe you can help me thanks. I haven't looked deeply at Spamassassin for a long time (nearly 10 years), but last time I worked with it, it was written entirely in Perl and at that time there was no built-in facility to call out to external programs or scripts. The only way to do that would be to write an extension module for Spamassassin in Perl that would run the external script and communicate with it somehow. Actually I'm not even sure what you're asking. Are you trying to run a python script from Spamassassin? If so, what are you trying to accomplish? From skip.montanaro at gmail.com Thu Oct 3 16:46:43 2019 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 3 Oct 2019 15:46:43 -0500 Subject: how can i run python script in spamassassin In-Reply-To: References: Message-ID: Check out SpamBayes. It runs on Linux and is written in Python. Like Spamassasin, it has no plugin architecture, but perhaps you'll discover you don't need it, or can more easily tweak SpamBayes to call your external script. Skip On Thu, Oct 3, 2019, 2:15 PM Doris Marca Guaraca wrote: > > Hello, I'm sorry to bother you, I just reviewed this post, the Python > beginner, the Linux beginner, needs to run spamassassin, and now I'm trying > to do something very similar with a Python script is for a project, maybe > you can help me thanks. > > I appreciate it a lot. > > Regards > Doris > > -- > https://mail.python.org/mailman/listinfo/python-list > From cs at cskk.id.au Thu Oct 3 19:08:49 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 4 Oct 2019 09:08:49 +1000 Subject: uses both shell and python codes in one script. In-Reply-To: References: Message-ID: <20191003230849.GA62680@cskk.homeip.net> On 03Oct2019 23:55, Chris Angelico wrote: >On Thu, Oct 3, 2019 at 11:41 PM Hongyi Zhao wrote: >> I'm very confusing on the following part in this script: >> >> ---- >> ''':' # begin python string; this line is interpreted by the shell as `:` >> which python >/dev/null 2>&1 && exec python "$0" "$@" >> which python3 >/dev/null 2>&1 && exec python3 "$0" "$@" >> which python2 >/dev/null 2>&1 && exec python2 "$0" "$@" >> >&2 echo "error: cannot find python" >> exit 1 >> ''' >> ---- >> >> Any hints for the meaning of several ' used above? > >The hint is there in that line, and stems from the way two different >parsers (Python and sh) interpret the line. [...] > >In the shell, the first two are an >empty string, then ':' is a colon, which introduces a label (the fact >that it's in quotes is irrelevant to the shell). So there's an empty >label followed by a shell comment. No. ":" is a synonym for "true". (Like "[" is a synonym for "test".) There aren't labels in the shell. This is just a dummy "true" command, with a comment. Since I'm here, I'll seize the opportunity to endorse Chris' earlier statement: just use "#!/usr/bin/env python3" as the opening shebang line and don't worry about embedding complex shell to "locate" python. Instead, expect the caller's environment to be correctly set up, and therefore for the "python3" command to find the preferred python interpreter. Cheers, Cameron Simpson From cs at cskk.id.au Thu Oct 3 19:13:05 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 4 Oct 2019 09:13:05 +1000 Subject: uses both shell and python codes in one script. In-Reply-To: References: Message-ID: <20191003231305.GA74151@cskk.homeip.net> On 04Oct2019 03:34, Chris Angelico wrote: >On Fri, Oct 4, 2019 at 12:15 AM James Lu wrote: >> I would use IPython as a scripting language. It has a slow startup >> time though. >> >And how, in the messy world of cross-platform scripting, would you >locate the interpreter? The whole point of this script is to attempt >three different shebangs, effectively. Well, yes, but personally I'd prefer to just run with "#!/usr/bin/env python3". Then the command line will say "python3: not found" or similar, I can fix my environment, and thereafter everything works better. Rather than complex magic inside a script. If we're going to accept the approach though, I'd rather the shebang was just "#!/bin/sh". There's _always_ a /bin/sh, and a number of BSDish systems do not have a /usr/bin/env (it tends to land in /bin instead). Cheers, Cameron Simpson From rosuav at gmail.com Thu Oct 3 19:15:41 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Oct 2019 09:15:41 +1000 Subject: uses both shell and python codes in one script. In-Reply-To: <20191003230849.GA62680@cskk.homeip.net> References: <20191003230849.GA62680@cskk.homeip.net> Message-ID: On Fri, Oct 4, 2019 at 9:08 AM Cameron Simpson wrote: > > On 03Oct2019 23:55, Chris Angelico wrote: > >On Thu, Oct 3, 2019 at 11:41 PM Hongyi Zhao wrote: > >> I'm very confusing on the following part in this script: > >> > >> ---- > >> ''':' # begin python string; this line is interpreted by the shell as `:` > >> which python >/dev/null 2>&1 && exec python "$0" "$@" > >> which python3 >/dev/null 2>&1 && exec python3 "$0" "$@" > >> which python2 >/dev/null 2>&1 && exec python2 "$0" "$@" > >> >&2 echo "error: cannot find python" > >> exit 1 > >> ''' > >> ---- > >> > >> Any hints for the meaning of several ' used above? > > > >The hint is there in that line, and stems from the way two different > >parsers (Python and sh) interpret the line. [...] > > > >In the shell, the first two are an > >empty string, then ':' is a colon, which introduces a label (the fact > >that it's in quotes is irrelevant to the shell). So there's an empty > >label followed by a shell comment. > > No. ":" is a synonym for "true". (Like "[" is a synonym for "test".) > > There aren't labels in the shell. This is just a dummy "true" command, > with a comment. My bad. I remember using a leading colon-space as a multi-shell comment, and in at least some of them, it's a label (probably old MS-DOS batch files or something, given what my background is). In any case, that one line does nothing, but the subsequent lines are meaningful. ChrisA From rosuav at gmail.com Thu Oct 3 19:17:10 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Oct 2019 09:17:10 +1000 Subject: uses both shell and python codes in one script. In-Reply-To: <20191003231305.GA74151@cskk.homeip.net> References: <20191003231305.GA74151@cskk.homeip.net> Message-ID: On Fri, Oct 4, 2019 at 9:13 AM Cameron Simpson wrote: > > On 04Oct2019 03:34, Chris Angelico wrote: > >On Fri, Oct 4, 2019 at 12:15 AM James Lu wrote: > >> I would use IPython as a scripting language. It has a slow startup > >> time though. > >> > >And how, in the messy world of cross-platform scripting, would you > >locate the interpreter? The whole point of this script is to attempt > >three different shebangs, effectively. > > Well, yes, but personally I'd prefer to just run with "#!/usr/bin/env > python3". Then the command line will say "python3: not found" or > similar, I can fix my environment, and thereafter everything works > better. Rather than complex magic inside a script. > > If we're going to accept the approach though, I'd rather the shebang was > just "#!/bin/sh". There's _always_ a /bin/sh, and a number of BSDish > systems do not have a /usr/bin/env (it tends to land in /bin instead). My point was that ipython solves nothing. The whole point of merging shell and Python was to prepare the environment for the REAL app, which is pure Python; so using ipython would add a costly dependency without actually helping in any way. Just run it in Python and that's that. ChrisA From cs at cskk.id.au Thu Oct 3 19:54:35 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 4 Oct 2019 09:54:35 +1000 Subject: uses both shell and python codes in one script. In-Reply-To: References: Message-ID: <20191003235435.GA90922@cskk.homeip.net> On 04Oct2019 09:17, Chris Angelico wrote: >On Fri, Oct 4, 2019 at 9:13 AM Cameron Simpson wrote: >> If we're going to accept the approach though, I'd rather the shebang >> was >> just "#!/bin/sh". There's _always_ a /bin/sh, and a number of BSDish >> systems do not have a /usr/bin/env (it tends to land in /bin instead). > >My point was that ipython solves nothing. The whole point of merging >shell and Python was to prepare the environment for the REAL app, >which is pure Python; so using ipython would add a costly dependency >without actually helping in any way. Just run it in Python and that's >that. +1 Cheers, Cameron Simpson From hongyi.zhao at gmail.com Fri Oct 4 04:57:31 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 4 Oct 2019 08:57:31 +0000 (UTC) Subject: a &= b Message-ID: Hi, Could you please give me some more hints on: a &= b It's very difficult for me to understand. From joel.goldstick at gmail.com Fri Oct 4 05:18:25 2019 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 4 Oct 2019 05:18:25 -0400 Subject: a &= b In-Reply-To: References: Message-ID: On Fri, Oct 4, 2019 at 5:01 AM Hongyi Zhao wrote: > > Hi, > > Could you please give me some more hints on: > > a &= b > > It's very difficult for me to understand. > -- > https://mail.python.org/mailman/listinfo/python-list & is bitwise And. a &= b is equivalent to a = a & b -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From bouncingcats at gmail.com Fri Oct 4 06:32:00 2019 From: bouncingcats at gmail.com (David) Date: Fri, 4 Oct 2019 20:32:00 +1000 Subject: a &= b In-Reply-To: References: Message-ID: On Fri, 4 Oct 2019 at 19:02, Hongyi Zhao wrote: > > Could you please give me some more hints on: > > a &= b $ python3 Python 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. >>> >>> a = 15 >>> b = 3 >>> c = a & b >>> d = a >>> d &= b >>> for i in [a, b, c, d]: ... print('{:04b}'.format(i)) ... 1111 0011 0011 0011 >>> From hongyi.zhao at gmail.com Fri Oct 4 09:01:18 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Fri, 4 Oct 2019 13:01:18 +0000 (UTC) Subject: from ./.. import Message-ID: Hi, See this file: https://github.com/hongyi-zhao/dotbot/blob/master/dotbot/messenger/ messenger.py It has the following codes: from ..util.singleton import Singleton from ..util.compat import with_metaclass from .color import Color from .level import Level I just cannot figure out why they using the ``from ./.. import'' to import modules. Any hints? From jon+usenet at unequivocal.eu Fri Oct 4 09:15:15 2019 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 4 Oct 2019 13:15:15 -0000 (UTC) Subject: from ./.. import References: Message-ID: On 2019-10-04, Hongyi Zhao wrote: > See this file: > https://github.com/hongyi-zhao/dotbot/blob/master/dotbot/messenger/ > messenger.py > > It has the following codes: > > from ..util.singleton import Singleton > from ..util.compat import with_metaclass > from .color import Color > from .level import Level > > I just cannot figure out why they using the ``from ./.. import'' to > import modules. Why wouldn't they be? That's how you import things from the current/parent package. From barry at barrys-emacs.org Fri Oct 4 10:15:21 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Fri, 4 Oct 2019 15:15:21 +0100 Subject: pathlib In-Reply-To: References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> <0b717cf2-5b84-a150-09ce-4d50c8175fa3@DancesWithMice.info> <37227e80-117d-f281-e5da-146099af38bb@kynesim.co.uk> <91905a00-0fbd-8e56-85f8-f73778428ebe@DancesWithMice.info> Message-ID: > On 3 Oct 2019, at 13:04, Richard Damon wrote: > > I am not sure that Concrete is really the right term here, but the > beginning of the documentation for Pathlib does sort of define what it > means here: There is a need to describe three ideas. The PurePath The OS Specific PurePath's, WindowPurePath and PosixPurePath. The OS Specific Path's with IO operations. WindowsPath and PosixPath. And lets not forget the Path is a factory for for one of OS Specific objects. Barry From barry at barrys-emacs.org Fri Oct 4 10:17:15 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Fri, 4 Oct 2019 15:17:15 +0100 Subject: pathlib In-Reply-To: <977ce549-6b1e-650e-e575-cd6ea6924daa@DancesWithMice.info> References: <699641c7-b16a-a239-e760-068a6a5b41d2@etelligence.info> <25BFF716-8D88-4533-AE47-80725D2A0294@barrys-emacs.org> <8ff80bf1-514c-a312-3479-04616f258485@DancesWithMice.info> <0b717cf2-5b84-a150-09ce-4d50c8175fa3@DancesWithMice.info> <977ce549-6b1e-650e-e575-cd6ea6924daa@DancesWithMice.info> Message-ID: > On 2 Oct 2019, at 23:58, DL Neil via Python-list wrote: > > In my mind, I'm wondering if it will come to that (having 'got past' the original observation/issue, I'm concerned by .rename()'s silent errors, for example). However, that 'outside' research, eg StackOverflow, shows that sub-classing pathlib is problematic, and quite possibly not part of the design (this is repeating 'gossip' - I'm not going to try to justify the comment or the claim). That said, last night my code sub-classing Path() seemed to work quite happily (albeit only tested on a 'Posix' box). The yawning chasm/gaping jaws below, however, are that I've probably made yet another 'assumption' about how things 'should' work. Run for the hills! What silent error? It raise expects if the rename does not work. Or do you mean it does not mutate the path on a rename? Thats a feature not a bug. Barry From piet-l at vanoostrum.org Fri Oct 4 11:43:28 2019 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Fri, 04 Oct 2019 17:43:28 +0200 Subject: Print to Paper References: Message-ID: Daniel writes: > How to do a code to print to paper? please post here a "Hello World" > code to be printed on paper with an inkjet. > Thanks > Daniel It depends on the Operating System. Python doesn't have a standard, system-independent way to print to paper. On most Unix-like systems (like my MacOS) the following works: from subprocess import Popen, PIPE p = Popen('lpr', stdin=PIPE) p.communicate(b'Hello World') p.stdin.close() p.wait() In a production system error checking should be added. Also if a nice layout is desired, you should probably want to generate a PDF file and send that to the printer, possibly with the use of LaTeX. -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From duram at terra.com.br Fri Oct 4 10:59:40 2019 From: duram at terra.com.br (Daniel) Date: Fri, 4 Oct 2019 11:59:40 -0300 Subject: Print to Paper Message-ID: How to do a code to print to paper? please post here a "Hello World" code to be printed on paper with an inkjet. Thanks Daniel --- Este email foi escaneado pelo Avast antiv?rus. https://www.avast.com/antivirus From geoff.bache at gmail.com Fri Oct 4 15:32:33 2019 From: geoff.bache at gmail.com (Geoff Bache) Date: Fri, 4 Oct 2019 21:32:33 +0200 Subject: Access violation in Python garbage collector (visit_decref) - how to debug? In-Reply-To: References: Message-ID: Hi all, We are running Python embedded in our C++ product and are now experiencing crashes (access violation reading 0xffffffffff on Windows) in the Python garbage collector. We got this on Python 3.6.4 originally, but I can reproduce it with both Python 3.6.8 and Python 3.7.4. The chances of producing a minimal example that reproduces it reliably are currently small I would say. All attempts to simplify the set up seem to cause the problem to go away. Indeed I can only reproduce it by sending a fairly large amount of data 2 or 3 times to our server - sending either half of the data does not reproduce it. I note that there have been a lot of crashes in this method reported over the years, and that efforts are underway in Python 3.8 to make it easier to find issues like this, i.e. https://bugs.python.org/issue36389. I won't be able to use Python 3.8 yet but I could potentially use it as a debugging tool I guess, if there was documentation available how to use these new features. I tried setting PYTHONMALLOC=debug but didn't get any more information that way. The python code is calling "json.loads" on a fairly large json unicode string with plenty of Swedish characters in it. It works at least once, and then crashes on the second or third send of the same data. I paste the stacktrace from Python 3.7.4 below. Please let me know how I can debug this further. I'm using Visual Studio 2017 on Windows 10 if that helps. Regards, Geoff Bache > [Inline Frame] python37.dll!visit_decref(_object *) Line 271 C python37.dll!dict_traverse(_object * op, int(*)(_object *, void *) visit, void * arg) Line 2982 C python37.dll!subtract_refs(_gc_head * containers) Line 296 C python37.dll!collect(int generation, __int64 * n_collected, __int64 * n_uncollectable, int nofail) Line 861 C python37.dll!collect_with_callback(int generation) Line 1029 C python37.dll!collect_generations() Line 1051 C [Inline Frame] python37.dll!_PyObject_GC_Alloc(int) Line 1708 C [Inline Frame] python37.dll!_PyObject_GC_Malloc(unsigned __int64 basicsize) Line 1718 C python37.dll!_PyObject_GC_New(_typeobject * tp) Line 1730 C python37.dll!new_dict(_dictkeysobject * keys, _object * * values) Line 584 C python37.dll!PyDict_New() Line 678 C python37.dll!_parse_object_unicode(_PyScannerObject * s, _object * pystr, __int64 idx, __int64 * next_idx_ptr) Line 730 C python37.dll!scan_once_unicode(_PyScannerObject * s, _object * pystr, __int64 idx, __int64 * next_idx_ptr) Line 1162 C python37.dll!_parse_array_unicode(_PyScannerObject * s, _object * pystr, __int64 idx, __int64 * next_idx_ptr) Line 869 C python37.dll!scan_once_unicode(_PyScannerObject * s, _object * pystr, __int64 idx, __int64 * next_idx_ptr) Line 1101 C python37.dll!scanner_call(_object * self, _object * args, _object * kwds) Line 1188 C python37.dll!_PyObject_FastCallKeywords(_object * callable, _object * const * stack, __int64 nargs, _object * kwnames) Line 199 C python37.dll!call_function(_object * * * pp_stack, __int64 oparg, _object * kwnames) Line 4619 C python37.dll!_PyEval_EvalFrameDefault(_frame * f, int throwflag) Line 3095 C [Inline Frame] python37.dll!PyEval_EvalFrameEx(_frame *) Line 547 C python37.dll!_PyEval_EvalCodeWithName(_object * _co, _object * globals, _object * locals, _object * const * args, __int64 argcount, _object * const * kwnames, _object * const * kwargs, __int64 kwcount, int kwstep, _object * const * defs, __int64 defcount, _object * kwdefs, _object * closure, _object * name, _object * qualname) Line 3930 C [Inline Frame] python37.dll!_PyFunction_FastCallKeywords(_object * stack, _object * const *) Line 433 C python37.dll!call_function(_object * * * pp_stack, __int64 oparg, _object * kwnames) Line 4621 C python37.dll!_PyEval_EvalFrameDefault(_frame * f, int throwflag) Line 3140 C [Inline Frame] python37.dll!PyEval_EvalFrameEx(_frame *) Line 547 C python37.dll!_PyEval_EvalCodeWithName(_object * _co, _object * globals, _object * locals, _object * const * args, __int64 argcount, _object * const * kwnames, _object * const * kwargs, __int64 kwcount, int kwstep, _object * const * defs, __int64 defcount, _object * kwdefs, _object * closure, _object * name, _object * qualname) Line 3930 C [Inline Frame] python37.dll!_PyFunction_FastCallKeywords(_object * stack, _object * const *) Line 433 C python37.dll!call_function(_object * * * pp_stack, __int64 oparg, _object * kwnames) Line 4621 C python37.dll!_PyEval_EvalFrameDefault(_frame * f, int throwflag) Line 3111 C [Inline Frame] python37.dll!PyEval_EvalFrameEx(_frame *) Line 547 C python37.dll!_PyEval_EvalCodeWithName(_object * _co, _object * globals, _object * locals, _object * const * args, __int64 argcount, _object * const * kwnames, _object * const * kwargs, __int64 kwcount, int kwstep, _object * const * defs, __int64 defcount, _object * kwdefs, _object * closure, _object * name, _object * qualname) Line 3930 C [Inline Frame] python37.dll!_PyFunction_FastCallKeywords(_object * stack, _object * const *) Line 433 C python37.dll!call_function(_object * * * pp_stack, __int64 oparg, _object * kwnames) Line 4621 C python37.dll!_PyEval_EvalFrameDefault(_frame * f, int throwflag) Line 3095 C [Inline Frame] python37.dll!PyEval_EvalFrameEx(_frame *) Line 547 C [Inline Frame] python37.dll!function_code_fastcall(PyCodeObject * args, _object * const *) Line 283 C [Inline Frame] python37.dll!_PyFunction_FastCallKeywords(_object * stack, _object * const *) Line 408 C python37.dll!call_function(_object * * * pp_stack, __int64 oparg, _object * kwnames) Line 4616 C python37.dll!_PyEval_EvalFrameDefault(_frame * f, int throwflag) Line 3125 C [Inline Frame] python37.dll!PyEval_EvalFrameEx(_frame *) Line 547 C [Inline Frame] python37.dll!function_code_fastcall(PyCodeObject * args, _object * const *) Line 283 C [Inline Frame] python37.dll!_PyFunction_FastCallKeywords(_object * stack, _object * const *) Line 408 C python37.dll!call_function(_object * * * pp_stack, __int64 oparg, _object * kwnames) Line 4616 C python37.dll!_PyEval_EvalFrameDefault(_frame * f, int throwflag) Line 3125 C [Inline Frame] python37.dll!PyEval_EvalFrameEx(_frame *) Line 547 C [Inline Frame] python37.dll!function_code_fastcall(PyCodeObject * args, _object * const *) Line 283 C [Inline Frame] python37.dll!_PyFunction_FastCallKeywords(_object * stack, _object * const *) Line 408 C python37.dll!call_function(_object * * * pp_stack, __int64 oparg, _object * kwnames) Line 4616 C python37.dll!_PyEval_EvalFrameDefault(_frame * f, int throwflag) Line 3125 C [Inline Frame] python37.dll!PyEval_EvalFrameEx(_frame *) Line 547 C [Inline Frame] python37.dll!function_code_fastcall(PyCodeObject * args, _object * const *) Line 283 C python37.dll!_PyFunction_FastCallDict(_object * func, _object * const * args, __int64 nargs, _object * kwargs) Line 322 C python37.dll!PyObject_Call(_object * callable, _object * args, _object * kwargs) Line 226 C estx.exe!PyObject_CallObject(_object * obj, _object * args) Line 191 C++ .....our server's C++ code in stack frames above this From rosuav at gmail.com Fri Oct 4 15:52:27 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Oct 2019 05:52:27 +1000 Subject: Access violation in Python garbage collector (visit_decref) - how to debug? In-Reply-To: References: Message-ID: On Sat, Oct 5, 2019 at 5:38 AM Geoff Bache wrote: > > Hi all, > > We are running Python embedded in our C++ product and are now experiencing > crashes (access violation reading 0xffffffffff on Windows) in the Python > garbage collector. > > We got this on Python 3.6.4 originally, but I can reproduce it with both > Python 3.6.8 and Python 3.7.4. > > The chances of producing a minimal example that reproduces it reliably are > currently small I would say. All attempts to simplify the set up seem to > cause the problem to go away. > Indeed I can only reproduce it by sending a fairly large amount of data 2 > or 3 times to our server - sending either half of the data does not > reproduce it. Have you tried to reproduce the issue outside of your application? Even if it means creating a gigantic Python script with a whopping triple-quoted string for the input data, it'd be helpful to try this. If you CAN repro the problem, it'd be way easier to diagnose (since we don't need your code, just your test case); and if you CAN'T, it may mean an issue with the embedding aspects. What's your definition of "fairly large" here? How many kilobytes/megabytes/gigabytes, and how deeply nested is the JSON object? ChrisA From python at mrabarnett.plus.com Fri Oct 4 15:53:50 2019 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 4 Oct 2019 20:53:50 +0100 Subject: Access violation in Python garbage collector (visit_decref) - how to debug? In-Reply-To: References: Message-ID: <55af1f79-4168-b356-19c9-84a5832d0c5c@mrabarnett.plus.com> On 2019-10-04 20:32, Geoff Bache wrote: > Hi all, > > We are running Python embedded in our C++ product and are now experiencing > crashes (access violation reading 0xffffffffff on Windows) in the Python > garbage collector. > > We got this on Python 3.6.4 originally, but I can reproduce it with both > Python 3.6.8 and Python 3.7.4. > > The chances of producing a minimal example that reproduces it reliably are > currently small I would say. All attempts to simplify the set up seem to > cause the problem to go away. > Indeed I can only reproduce it by sending a fairly large amount of data 2 > or 3 times to our server - sending either half of the data does not > reproduce it. > [snip] In my experience, it's most likely caused by incorrect refcounting, DECREFing too many times. From arequipeno at gmail.com Fri Oct 4 17:30:56 2019 From: arequipeno at gmail.com (Ian Pilcher) Date: Fri, 4 Oct 2019 16:30:56 -0500 Subject: Using a logging.Logger in a C extension Message-ID: I am working my way through writing a C extension, and I've realized that I need to log a few messages from the C code. Ideally, I would pass my existing Logging.logger object into my C function and use PyObject_CallMethod to call the appropriate method on it (info, debug, etc.). PyArg_ParseTuple should be able to handle this with an "O!" format unit, but I can't figure out how to retrieve the type object for logging.Logger. Any hints, links, etc. appreciated. Thanks! -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From grant.b.edwards at gmail.com Fri Oct 4 19:40:06 2019 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 4 Oct 2019 23:40:06 -0000 (UTC) Subject: Print to Paper References: Message-ID: On 2019-10-04, Daniel wrote: > How to do a code to print to paper? please post here a "Hello World" > code to be printed on paper with an inkjet. os.popen('lpr','w').write('Hello World\n') That's a bit old-school -- you should probably use subprocess.Popen instead. From torriem at gmail.com Fri Oct 4 20:12:31 2019 From: torriem at gmail.com (Michael Torrie) Date: Fri, 4 Oct 2019 18:12:31 -0600 Subject: Print to Paper In-Reply-To: References: Message-ID: On 10/4/19 8:59 AM, Daniel wrote: > How to do a code to print to paper? please post here a "Hello World" > code to be printed on paper with an inkjet. What operating system? Are you using a graphical UI toolkit or is this a command-line program you're making? From dieter at handshake.de Sat Oct 5 01:21:45 2019 From: dieter at handshake.de (dieter) Date: Sat, 05 Oct 2019 07:21:45 +0200 Subject: Access violation in Python garbage collector (visit_decref) - how to debug? References: Message-ID: <87pnjbydg6.fsf@handshake.de> Geoff Bache writes: > ... > We are running Python embedded in our C++ product and are now experiencing > crashes (access violation reading 0xffffffffff on Windows) in the Python > garbage collector. Errors like this are very difficult to analyse. The main reason: the memory corruption is likely far away from the point when it is finally detected (by an access violation in your case). Python can be built in a special way to add marks to its allocated memory blocks and verify their validity. This increases the chance to detect a memory corruption earlier and thereby facilitates the detection of the root cause. There are tools for the analysis of memory management problems (e.g. "valgrind", though this may be for Linux). In my experience, even with those tools, the analysis is very difficult. I have several times successfully analysed memory corruption problems. In those cases, I have been lucky that the corruption was reproducible and affected typically the same address. Thus, I could put a (hardware) memory breakpoint at this address stopping the program as soon as this address was written and then analyse the state in the debugger. This way, I could detect precisely which code caused the corruption. However, this was quite a long time ago; nowadays, modern operating systems employ address randomization thus reducing significantly that the corruption affects the same address (which may mean that you need to deactivate address randomization to get a better chance for this kind of analysis. From dieter at handshake.de Sat Oct 5 01:23:58 2019 From: dieter at handshake.de (dieter) Date: Sat, 05 Oct 2019 07:23:58 +0200 Subject: Using a logging.Logger in a C extension References: Message-ID: <87imp3ydch.fsf@handshake.de> Ian Pilcher writes: > I am working my way through writing a C extension, and I've realized > that I need to log a few messages from the C code. Have a look at "cython". It significantly facilitates the realisation of C extensions, drastically reduces risks to make something wrong and makes it very easy to call back to Python. From tjreedy at udel.edu Sat Oct 5 01:47:02 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 5 Oct 2019 01:47:02 -0400 Subject: from ./.. import In-Reply-To: References: Message-ID: On 10/4/2019 9:01 AM, Hongyi Zhao wrote: > Hi, > > See this file: > https://github.com/hongyi-zhao/dotbot/blob/master/dotbot/messenger/ > messenger.py > > It has the following codes: > > from ..util.singleton import Singleton > from ..util.compat import with_metaclass > from .color import Color > from .level import Level > > I just cannot figure out why they using the ``from ./.. import'' to > import modules. These are 'relative imports'. Read the doc for import statements. -- Terry Jan Reedy From anthra.norell at bluewin.ch Sat Oct 5 07:48:35 2019 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Sat, 5 Oct 2019 13:48:35 +0200 Subject: pre-edit stuff persists in a reloaded a module Message-ID: Hi all, Python 2.7. I habitually work interactively in an Idle window. Occasionally I correct code, reload and find that edits fail to load. I understand that reloading is not guaranteed to reload everything, but I don't understand the exact mechanism and would appreciate some illumination. Right now I am totally bewildered, having deleted and garbage collected a module and an object, reloaded the module and remade the object and when I inspect the corrected source (inspect.getsource (Object.run)) I see the uncorrected source, which isn't even on the disk anymore. The command 'reload' correctly displays the name of the source, ending '.py', indicating that it recognizes the source being newer than the compile ending '.pyc'. After the reload, the pyc-file is newer, indicating that it has been recompiled. But the runtime error persist. So the recompile must have used the uncorrected old code. I could kill python with signal 15, but would prefer a targeted purge that doesn't wipe clean my Idle workbench. (I know I should upgrade to version 3. I will as soon as I get around to it. Hopefully that will fix the problem.) Thanks for comments Frederic From __peter__ at web.de Sat Oct 5 08:48:30 2019 From: __peter__ at web.de (Peter Otten) Date: Sat, 05 Oct 2019 14:48:30 +0200 Subject: pre-edit stuff persists in a reloaded a module References: Message-ID: Friedrich Rentsch wrote: > Hi all, > > Python 2.7. I habitually work interactively in an Idle window. > Occasionally I correct code, reload and find that edits fail to load. I > understand that reloading is not guaranteed to reload everything, but I > don't understand the exact mechanism and would appreciate some > illumination. Right now I am totally bewildered, having deleted and > garbage collected a module and an object, reloaded the module and remade > the object and when I inspect the corrected source (inspect.getsource > (Object.run)) I see the uncorrected source, which isn't even on the disk > anymore. The command 'reload' correctly displays the name of the source, > ending '.py', indicating that it recognizes the source being newer than > the compile ending '.pyc'. After the reload, the pyc-file is newer, > indicating that it has been recompiled. But the runtime error persist. > So the recompile must have used the uncorrected old code. I could kill > python with signal 15, but would prefer a targeted purge that doesn't > wipe clean my Idle workbench. (I know I should upgrade to version 3. I > will as soon as I get around to it. Hopefully that will fix the problem.) > > Thanks for comments (1) stay away from reload() (2) inspect.getsource() uses a cache that you should be able to clear with linecache.clear(): $ echo 'def f(): return "old"' > tmp.py $ python [...] >>> import inspect, tmp >>> inspect.getsource(tmp.f) 'def f(): return "old"\n' >>> [1]+ Angehalten python $ echo 'def f(): return "new"' > tmp.py $ fg python reload(tmp) reload(tmp) >>> inspect.getsource(tmp.f) 'def f(): return "old"\n' >>> import linecache; linecache.clearcache() >>> inspect.getsource(tmp.f) 'def f(): return "new"\n' (3) see 1 ;) From anthra.norell at bluewin.ch Sat Oct 5 10:24:14 2019 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Sat, 5 Oct 2019 16:24:14 +0200 Subject: pre-edit stuff persists in a reloaded a module In-Reply-To: References: Message-ID: <036129fe-791c-d558-2d40-02ab7ea470a6@bluewin.ch> On 10/5/19 2:48 PM, Peter Otten wrote: > Friedrich Rentsch wrote: > >> Hi all, >> >> Python 2.7. I habitually work interactively in an Idle window. >> Occasionally I correct code, reload and find that edits fail to load. I >> understand that reloading is not guaranteed to reload everything, but I >> don't understand the exact mechanism and would appreciate some >> illumination. Right now I am totally bewildered, having deleted and >> garbage collected a module and an object, reloaded the module and remade >> the object and when I inspect the corrected source (inspect.getsource >> (Object.run)) I see the uncorrected source, which isn't even on the disk >> anymore. The command 'reload' correctly displays the name of the source, >> ending '.py', indicating that it recognizes the source being newer than >> the compile ending '.pyc'. After the reload, the pyc-file is newer, >> indicating that it has been recompiled. But the runtime error persist. >> So the recompile must have used the uncorrected old code. I could kill >> python with signal 15, but would prefer a targeted purge that doesn't >> wipe clean my Idle workbench. (I know I should upgrade to version 3. I >> will as soon as I get around to it. Hopefully that will fix the problem.) >> >> Thanks for comments > (1) stay away from reload() > (2) inspect.getsource() uses a cache that you should be able to clear with > linecache.clear(): > > $ echo 'def f(): return "old"' > tmp.py > $ python > [...] >>>> import inspect, tmp >>>> inspect.getsource(tmp.f) > 'def f(): return "old"\n' > [1]+ Angehalten python > $ echo 'def f(): return "new"' > tmp.py > $ fg > python > reload(tmp) > reload(tmp) > >>>> inspect.getsource(tmp.f) > 'def f(): return "old"\n' >>>> import linecache; linecache.clearcache() >>>> inspect.getsource(tmp.f) > 'def f(): return "new"\n' > > (3) see 1 ;) > Thank you, Peter. I guess, then, that not only 'inspect', but the compiler as well reads source off the line cache and clearing the latter would make 'reload' work as expected. Are there other snags lurking, that you advise against using 'reload'? What are the alternatives for developing iteratively, alternating between running and editing? Frederic From __peter__ at web.de Sat Oct 5 12:53:57 2019 From: __peter__ at web.de (Peter Otten) Date: Sat, 05 Oct 2019 18:53:57 +0200 Subject: pre-edit stuff persists in a reloaded a module References: <036129fe-791c-d558-2d40-02ab7ea470a6@bluewin.ch> Message-ID: Friedrich Rentsch wrote: > > > On 10/5/19 2:48 PM, Peter Otten wrote: >> Friedrich Rentsch wrote: >> >>> Hi all, >>> >>> Python 2.7. I habitually work interactively in an Idle window. >>> Occasionally I correct code, reload and find that edits fail to load. I >>> understand that reloading is not guaranteed to reload everything, but I >>> don't understand the exact mechanism and would appreciate some >>> illumination. Right now I am totally bewildered, having deleted and >>> garbage collected a module and an object, reloaded the module and remade >>> the object and when I inspect the corrected source (inspect.getsource >>> (Object.run)) I see the uncorrected source, which isn't even on the disk >>> anymore. The command 'reload' correctly displays the name of the source, >>> ending '.py', indicating that it recognizes the source being newer than >>> the compile ending '.pyc'. After the reload, the pyc-file is newer, >>> indicating that it has been recompiled. But the runtime error persist. >>> So the recompile must have used the uncorrected old code. I could kill >>> python with signal 15, but would prefer a targeted purge that doesn't >>> wipe clean my Idle workbench. (I know I should upgrade to version 3. I >>> will as soon as I get around to it. Hopefully that will fix the >>> problem.) >>> >>> Thanks for comments >> (1) stay away from reload() >> (2) inspect.getsource() uses a cache that you should be able to clear >> with linecache.clear(): >> >> $ echo 'def f(): return "old"' > tmp.py >> $ python >> [...] >>>>> import inspect, tmp >>>>> inspect.getsource(tmp.f) >> 'def f(): return "old"\n' >> [1]+ Angehalten python >> $ echo 'def f(): return "new"' > tmp.py >> $ fg >> python >> reload(tmp) >> reload(tmp) >> >>>>> inspect.getsource(tmp.f) >> 'def f(): return "old"\n' >>>>> import linecache; linecache.clearcache() >>>>> inspect.getsource(tmp.f) >> 'def f(): return "new"\n' >> >> (3) see 1 ;) >> > Thank you, Peter. I guess, then, that not only 'inspect', but the > compiler as well reads source off the line cache and clearing the latter > would make 'reload' work as expected. I don't think so. My understanding may be incomplete, but my working assumption is that the module is reloaded from file, compiled, and new bindings overwrite old ones. However, every name bound to something from the old version will not be updated, i. e. import module obj = module.obj reload(module) assert obj is not module.obj > Are there other snags lurking, > that you advise against using 'reload'? The above scenario is enough for me to forego reload(). You are actually lucky when something fails as an apparently successful change may fail in a fresh interpreter. > What are the alternatives for > developing iteratively, alternating between running and editing? Keep the part under development small so that is doesn't hurt to rerun. From tjreedy at udel.edu Sat Oct 5 12:54:12 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 5 Oct 2019 12:54:12 -0400 Subject: pre-edit stuff persists in a reloaded a module In-Reply-To: <036129fe-791c-d558-2d40-02ab7ea470a6@bluewin.ch> References: <036129fe-791c-d558-2d40-02ab7ea470a6@bluewin.ch> Message-ID: On 10/5/2019 10:24 AM, Friedrich Rentsch wrote: > Thank you, Peter. I guess, then, that not only 'inspect', but the > compiler as well reads source off the line cache and clearing the latter > would make 'reload' work as expected. Are there other snags lurking, > that you advise against using 'reload'? Existing references to objects may continue to refer to old versions after loading new definitions. I never use reload. > What are the alternatives for > developing iteratively, alternating between running and editing? IDLE used properly is great for this. Edit and hit F5 to save and run. I personally recommend changing the Option Settings General tab 'At Start of Run (F5)' to (*) No Prompt. Note that if you get an exception (in the Shell), right click on appropriate line of the traceback and click 'Goto File/line' to go to the line in the editor. And IDLE (and Python) for 3.7+ has multiple improvements over IDLE for 2.7, so unless you need to specifically edit 2.7 code, do upgrade. -- Terry Jan Reedy From tjreedy at udel.edu Sat Oct 5 13:12:17 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 5 Oct 2019 13:12:17 -0400 Subject: pre-edit stuff persists in a reloaded a module In-Reply-To: <92bhpe5b6sv07u32of96e2i86sj4cpn9el@4ax.com> References: <036129fe-791c-d558-2d40-02ab7ea470a6@bluewin.ch> <92bhpe5b6sv07u32of96e2i86sj4cpn9el@4ax.com> Message-ID: On 10/5/2019 10:49 AM, Dennis Lee Bieber wrote: > On Sat, 5 Oct 2019 16:24:14 +0200, Friedrich Rentsch > declaimed the following: > > >> Thank you, Peter. I guess, then, that not only 'inspect', but the >> compiler as well reads source off the line cache and clearing the latter >> would make 'reload' work as expected. Are there other snags lurking, >> that you advise against using 'reload'? What are the alternatives for >> developing iteratively, alternating between running and editing? >> > > The simplest is to open a separate shell/console for running, and save > from the editor before doing each run. > > Or try something other than IDLE, though pretty much any IDE that > provides interactive access could fall a foul of this problem (the > execute-in-separate console means a clean interpreter for each run; Actually running from the IDLE editor, as opposed to reloading in the shell, gives a clean interpreter, in a new subprocess, for each run. Plus it has some advantages over separated editor and console REPL. The first is that it compile()s the code to check syntax before starting the subprocess. If there is an error, IDLE highlights the error location and puts the cursor there so one can correct it. The last, which I mentioned in response to Friedrich, is the ability to jump back to the location of runtime exceptions. -- Terry Jan Reedy From arequipeno at gmail.com Sat Oct 5 13:55:28 2019 From: arequipeno at gmail.com (Ian Pilcher) Date: Sat, 5 Oct 2019 12:55:28 -0500 Subject: Get __name__ in C extension module In-Reply-To: References: Message-ID: On 10/4/19 4:30 PM, Ian Pilcher wrote: > Ideally, I would pass my existing Logging.logger object into my C > function and use PyObject_CallMethod to call the appropriate method on > it (info, debug, etc.). As I've researched this further, I've realized that this isn't the correct approach. My extension should be doing the C equivalent of: logger = logging.getLogger(__name__) This is straightforward, except that I cannot figure out how to retrieve the __name__. I can get it from the module object with PyModule_GetName, but that requires that I have a reference to the module object in order to do so. I would have thought that this would be easy for a module function to access, but I haven't been able to find any API which does this. (Module functions get NULL as their 'self' argument.) Any pointers appreciated. Thanks! -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From cs at cskk.id.au Sat Oct 5 21:07:21 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 6 Oct 2019 12:07:21 +1100 Subject: ipython in different loctions. In-Reply-To: References: Message-ID: <20191006010721.GA90243@cskk.homeip.net> On 03Oct2019 00:45, Hongyi Zhao wrote: >On Thu, 03 Oct 2019 10:19:23 +1000, Cameron Simpson wrote: >> bash -x ~/.pyenv/shims/ipython3 >> and see what its final command does. > >Tried as follows: > >----------------- >werner at localhost:~$ bash -x ~/.pyenv/shims/ipython3 [...] >+ exec /home/werner/.pyenv/libexec/pyenv exec ipython3 >Python 3.7.4 (default, Aug 29 2019, 06:59:32) [...] >In [1]: >----------------- > >Also tried the follows: >werner at localhost:~$ bash -x ~/.local/bin/ipython3 >+ import re >+ import sys >+ from IPython import start_ipython >from: can't read /var/mail/IPython >/home/werner/.local/bin/ipython3: line 10: syntax error near unexpected >token `(' >/home/werner/.local/bin/ipython3: line 10: ` sys.argv[0] = re.sub(r'(- >script\.pyw?|\.exe)?$', '', sys.argv[0])' >werner at localhost:~$ > >The former can start the ipython, while the latter will fail. That is because ~/.local/bin/ipython3 is not a shell script (thus syntax errors). It is directly a python script. Cheers, Cameron Simpson From arequipeno at gmail.com Sun Oct 6 10:48:23 2019 From: arequipeno at gmail.com (Ian Pilcher) Date: Sun, 6 Oct 2019 09:48:23 -0500 Subject: Get __name__ in C extension module In-Reply-To: References: Message-ID: On 10/5/19 12:55 PM, Ian Pilcher wrote: > This is straightforward, except that I cannot figure out how to retrieve > the __name__. Making progress. I can get a __name__ value with: PyDict_GetItemString(PyEval_GetGlobals(), "__name__") I say "a __name__ value" because the returned value is actually that of the calling module, not the name of my extension. Is this normal? Thanks! -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From python at mrabarnett.plus.com Sun Oct 6 12:55:14 2019 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 6 Oct 2019 17:55:14 +0100 Subject: Get __name__ in C extension module In-Reply-To: References: Message-ID: <8a8c39c0-d9e7-a02b-f7e0-4155ad89d2b1@mrabarnett.plus.com> On 2019-10-06 15:48, Ian Pilcher wrote: > On 10/5/19 12:55 PM, Ian Pilcher wrote: >> This is straightforward, except that I cannot figure out how to retrieve >> the __name__. > > Making progress. I can get a __name__ value with: > > PyDict_GetItemString(PyEval_GetGlobals(), "__name__") > > I say "a __name__ value" because the returned value is actually that of > the calling module, not the name of my extension. > > Is this normal? > Don't you already have the module's name? You have to specify it in the PyModuleDef struct that you pass to PyModule_Create. Calling PyModule_Create returns a reference to the module, and you can get its namespace dict with PyModule_GetDict(...). From singhkrishna1994 at gmail.com Sun Oct 6 13:46:46 2019 From: singhkrishna1994 at gmail.com (krishna singh) Date: Sun, 6 Oct 2019 10:46:46 -0700 (PDT) Subject: Anyone has good understanding of how model base agents work in 2D array? --AIMA repository Message-ID: <71f52d5f-f90c-4cae-8569-405e45fddae3@googlegroups.com> Hi, I have started learning artificial intelligence and currently going through AIMA repository https://github.com/aimacode/aima-python but I am stucked at model base reflex agent implementation in the 2D environment. Does anyone have a good understanding of how model base agents work in 2D array? From barry at barrys-emacs.org Sun Oct 6 13:55:04 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Sun, 6 Oct 2019 18:55:04 +0100 Subject: Get __name__ in C extension module In-Reply-To: References: Message-ID: <6D08C484-863C-41EF-A987-0A69EF1D4AA6@barrys-emacs.org> > On 5 Oct 2019, at 18:55, Ian Pilcher wrote: > > On 10/4/19 4:30 PM, Ian Pilcher wrote: >> Ideally, I would pass my existing Logging.logger object into my C >> function and use PyObject_CallMethod to call the appropriate method on >> it (info, debug, etc.). > > As I've researched this further, I've realized that this isn't the > correct approach. > > My extension should be doing the C equivalent of: > > logger = logging.getLogger(__name__) The way I build extension modules is to split the work between python code and C++ code. You only need the C++ for the difficult stuff. For the "foo" module I would create a foo.py that imports a _foo extension. Then the answer to your question is simple. Do it in python and passt logger into the C++ module. Next I would never code directly against the C API. Its a pain to use and get right, get the ref counts wrong and you get memory leaks of worse crash python. There are lots of good alternative. Personal I use PyCXX, but then I'm the maintainer :-) https://sourceforge.net/projects/cxx/ Barry > > This is straightforward, except that I cannot figure out how to retrieve > the __name__. I can get it from the module object with > PyModule_GetName, but that requires that I have a reference to the > module object in order to do so. > > I would have thought that this would be easy for a module function to > access, but I haven't been able to find any API which does this. > (Module functions get NULL as their 'self' argument.) > > Any pointers appreciated. Thanks! > > -- > ======================================================================== > Ian Pilcher arequipeno at gmail.com > -------- "I grew up before Mark Zuckerberg invented friendship" -------- > ======================================================================== > > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sun Oct 6 16:17:49 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Oct 2019 07:17:49 +1100 Subject: Strange tab completion oddity with enums? Message-ID: I'm not sure what's going on here, and it's probably not actually enum-specific, but that's where I saw it. If you create a plain class and have an attribute with an annotation, you can see that: >>> class Foo: ... spam: "ham" = 1 ... >>> Foo.__a Foo.__abstractmethods__ Foo.__annotations__ >>> Foo.__annotations__ {'spam': 'ham'} Note that __annotations__ shows up when tab-completing "__a". Now consider an enumeration: >>> from enum import Flag, auto >>> class Bar(Flag): ... quux: "asdf" = auto() ... >>> Bar.__ Bar.__abstractmethods__ Bar.__getattr__( Bar.__ne__( Bar.__base__( Bar.__getattribute__( Bar.__new__( Bar.__bases__ Bar.__getitem__( Bar.__prepare__( Bar.__basicsize__ Bar.__gt__( Bar.__qualname__ Bar.__bool__( Bar.__hash__( Bar.__reduce__( Bar.__call__( Bar.__init__( Bar.__reduce_ex__( Bar.__class__( Bar.__init_subclass__( Bar.__repr__( Bar.__contains__( Bar.__instancecheck__( Bar.__reversed__( Bar.__delattr__( Bar.__itemsize__ Bar.__setattr__( Bar.__dict__ Bar.__iter__( Bar.__sizeof__( Bar.__dictoffset__ Bar.__le__( Bar.__str__( Bar.__dir__( Bar.__len__( Bar.__subclasscheck__( Bar.__doc__ Bar.__lt__( Bar.__subclasses__( Bar.__eq__( Bar.__members__ Bar.__subclasshook__( Bar.__flags__ Bar.__module__ Bar.__text_signature__ Bar.__format__( Bar.__mro__ Bar.__weakrefoffset__ Bar.__ge__( Bar.__name__ >>> Bar.__annotations__ {'quux': 'asdf'} Double-tabbing "__" shows everything but, and double-tabbing "__ann" has nothing... but the attribute is most definitely there. Perhaps notable is dir(): >>> dir(Foo) ['__annotations__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'spam'] >>> dir(Bar) ['__class__', '__doc__', '__members__', '__module__', 'quux'] But that's not the whole story, since tab completing "Bar.__" will still show "__class__" and "__init__" that aren't in dir(). Tested with the default REPL CPython 3.6, 3.7, 3.8, and 3.9. Tested also in IDLE on 3.9 but tab completion of dunders behaves differently there (it ONLY seems to want to tab complete __class__, for some reason) so it's not comparable. What's actually going on here? ChrisA From vergun.alx at gmail.com Sun Oct 6 11:11:46 2019 From: vergun.alx at gmail.com (Alexander Vergun) Date: Sun, 6 Oct 2019 17:11:46 +0200 Subject: Mouse control Message-ID: <58519cc4-0c96-e018-a5b7-43d2011719de@gmail.com> Hello all, I am coding a voice assistant under Python 3.7, Windows 7. I am using PYcharm and libraries such as PYSimpleGUI, mouse, keyboard etc.? Everything works except for the mouse control and probably keyboard, the problem is following, when I run the script under PYcharm, the script can control mouse only within PYcharm editor, but when the other window is on the top, the script cannot control the mouse, and the same happens when the script runs under the Python console. There is only one way to make script control the mouse - I have to manually click on the window which was opened by the script only then the script controls the mouse. I tried to call win32gui.SetCapture without any effect. Does anyone have an idea how to handle this? Thank you very much, Alexander -- Ing. Alexander Vergun tel.: +421905167381 From arequipeno at gmail.com Sun Oct 6 19:38:19 2019 From: arequipeno at gmail.com (Ian Pilcher) Date: Sun, 6 Oct 2019 18:38:19 -0500 Subject: Get __name__ in C extension module In-Reply-To: <8a8c39c0-d9e7-a02b-f7e0-4155ad89d2b1@mrabarnett.plus.com> References: <8a8c39c0-d9e7-a02b-f7e0-4155ad89d2b1@mrabarnett.plus.com> Message-ID: <59367367-c892-6acf-da8d-da74556257c4@gmail.com> On 10/6/19 11:55 AM, MRAB wrote: > Don't you already have the module's name? You have to specify it in the > PyModuleDef struct that you pass to PyModule_Create. I do. Perhaps I'm trying to be too Pythonic, but there's so much advice out there about using getLogger(__name__) in Python code, rather than hardcoding the name. I've been trying to follow that pattern in my extension module. > Calling PyModule_Create returns a reference to the module, and you can > get its namespace dict with PyModule_GetDict(...). Right. I have that in my module init function, but how do I access that later in one of my extension functions? The only thing I can think of would be to save it in a static variable, but static variables seem to be a no-no in extensions. -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From arequipeno at gmail.com Sun Oct 6 19:38:19 2019 From: arequipeno at gmail.com (Ian Pilcher) Date: Sun, 6 Oct 2019 18:38:19 -0500 Subject: Get __name__ in C extension module In-Reply-To: <8a8c39c0-d9e7-a02b-f7e0-4155ad89d2b1@mrabarnett.plus.com> References: <8a8c39c0-d9e7-a02b-f7e0-4155ad89d2b1@mrabarnett.plus.com> Message-ID: <59367367-c892-6acf-da8d-da74556257c4@gmail.com> On 10/6/19 11:55 AM, MRAB wrote: > Don't you already have the module's name? You have to specify it in the > PyModuleDef struct that you pass to PyModule_Create. I do. Perhaps I'm trying to be too Pythonic, but there's so much advice out there about using getLogger(__name__) in Python code, rather than hardcoding the name. I've been trying to follow that pattern in my extension module. > Calling PyModule_Create returns a reference to the module, and you can > get its namespace dict with PyModule_GetDict(...). Right. I have that in my module init function, but how do I access that later in one of my extension functions? The only thing I can think of would be to save it in a static variable, but static variables seem to be a no-no in extensions. -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From arequipeno at gmail.com Sun Oct 6 19:44:10 2019 From: arequipeno at gmail.com (Ian Pilcher) Date: Sun, 6 Oct 2019 18:44:10 -0500 Subject: Get __name__ in C extension module In-Reply-To: <6D08C484-863C-41EF-A987-0A69EF1D4AA6@barrys-emacs.org> References: <6D08C484-863C-41EF-A987-0A69EF1D4AA6@barrys-emacs.org> Message-ID: On 10/6/19 12:55 PM, Barry Scott wrote: > Then the answer to your question is simple. Do it in python and passt > logger into the C++ module. Funny thing, that's exactly where I started this journey. I couldn't figure out how to get the logging.Logger type object, so that I could use a "O!" format string unit. This led me to read a bit more about the logging framework, which led me to the advice to get loggers by name, rather than passing them around, etc., etc. > Next I would never code directly against the C API. Its a pain to use > and get right, get the ref counts wrong and you get memory leaks of > worse crash python. Well, I like driving cars with manual transmissions, so ... -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From arequipeno at gmail.com Sun Oct 6 19:44:10 2019 From: arequipeno at gmail.com (Ian Pilcher) Date: Sun, 6 Oct 2019 18:44:10 -0500 Subject: Get __name__ in C extension module In-Reply-To: <6D08C484-863C-41EF-A987-0A69EF1D4AA6@barrys-emacs.org> References: <6D08C484-863C-41EF-A987-0A69EF1D4AA6@barrys-emacs.org> Message-ID: On 10/6/19 12:55 PM, Barry Scott wrote: > Then the answer to your question is simple. Do it in python and passt > logger into the C++ module. Funny thing, that's exactly where I started this journey. I couldn't figure out how to get the logging.Logger type object, so that I could use a "O!" format string unit. This led me to read a bit more about the logging framework, which led me to the advice to get loggers by name, rather than passing them around, etc., etc. > Next I would never code directly against the C API. Its a pain to use > and get right, get the ref counts wrong and you get memory leaks of > worse crash python. Well, I like driving cars with manual transmissions, so ... -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From python at mrabarnett.plus.com Sun Oct 6 23:34:21 2019 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 7 Oct 2019 04:34:21 +0100 Subject: Get __name__ in C extension module In-Reply-To: <59367367-c892-6acf-da8d-da74556257c4@gmail.com> References: <8a8c39c0-d9e7-a02b-f7e0-4155ad89d2b1@mrabarnett.plus.com> <59367367-c892-6acf-da8d-da74556257c4@gmail.com> Message-ID: <61e15f2a-e569-ab7d-8e92-23470416f39e@mrabarnett.plus.com> On 2019-10-07 00:38, Ian Pilcher wrote: > On 10/6/19 11:55 AM, MRAB wrote: > > Don't you already have the module's name? You have to specify it in the > > PyModuleDef struct that you pass to PyModule_Create. > > I do. Perhaps I'm trying to be too Pythonic, but there's so much advice > out there about using getLogger(__name__) in Python code, rather than > hardcoding the name. I've been trying to follow that pattern in my > extension module. > > > Calling PyModule_Create returns a reference to the module, and you can > > get its namespace dict with PyModule_GetDict(...). > > Right. I have that in my module init function, but how do I access that > later in one of my extension functions? The only thing I can think of > would be to save it in a static variable, but static variables seem to > be a no-no in extensions. > Can an extension module be instantiated twice? If so, would they share static variables? If they don't, then it's not a problem. From __peter__ at web.de Mon Oct 7 02:58:20 2019 From: __peter__ at web.de (Peter Otten) Date: Mon, 07 Oct 2019 08:58:20 +0200 Subject: Strange tab completion oddity with enums? References: Message-ID: Chris Angelico wrote: > I'm not sure what's going on here, and it's probably not actually > enum-specific, but that's where I saw it. > > If you create a plain class and have an attribute with an annotation, > you can see that: > >>>> class Foo: > ... spam: "ham" = 1 > ... >>>> Foo.__a > Foo.__abstractmethods__ Foo.__annotations__ >>>> Foo.__annotations__ > {'spam': 'ham'} > > Note that __annotations__ shows up when tab-completing "__a". > > Now consider an enumeration: > >>>> from enum import Flag, auto >>>> class Bar(Flag): > ... quux: "asdf" = auto() > ... >>>> Bar.__ > Bar.__abstractmethods__ Bar.__getattr__( Bar.__ne__( > Bar.__base__( Bar.__getattribute__( Bar.__new__( > Bar.__bases__ Bar.__getitem__( Bar.__prepare__( > Bar.__basicsize__ Bar.__gt__( Bar.__qualname__ > Bar.__bool__( Bar.__hash__( Bar.__reduce__( > Bar.__call__( Bar.__init__( Bar.__reduce_ex__( > Bar.__class__( Bar.__init_subclass__( Bar.__repr__( > Bar.__contains__( Bar.__instancecheck__( Bar.__reversed__( > Bar.__delattr__( Bar.__itemsize__ Bar.__setattr__( > Bar.__dict__ Bar.__iter__( Bar.__sizeof__( > Bar.__dictoffset__ Bar.__le__( Bar.__str__( > Bar.__dir__( Bar.__len__( Bar.__subclasscheck__( > Bar.__doc__ Bar.__lt__( Bar.__subclasses__( > Bar.__eq__( Bar.__members__ Bar.__subclasshook__( > Bar.__flags__ Bar.__module__ Bar.__text_signature__ > Bar.__format__( Bar.__mro__ Bar.__weakrefoffset__ > Bar.__ge__( Bar.__name__ >>>> Bar.__annotations__ > {'quux': 'asdf'} > > Double-tabbing "__" shows everything but, and double-tabbing "__ann" > has nothing... but the attribute is most definitely there. > > Perhaps notable is dir(): > >>>> dir(Foo) > ['__annotations__', '__class__', '__delattr__', '__dict__', '__dir__', > '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', > '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', > '__lt__', '__module__', '__ne__', '__new__', '__reduce__', > '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', > '__subclasshook__', '__weakref__', 'spam'] >>>> dir(Bar) > ['__class__', '__doc__', '__members__', '__module__', 'quux'] > > But that's not the whole story, since tab completing "Bar.__" will > still show "__class__" and "__init__" that aren't in dir(). > > Tested with the default REPL CPython 3.6, 3.7, 3.8, and 3.9. Tested > also in IDLE on 3.9 but tab completion of dunders behaves differently > there (it ONLY seems to want to tab complete __class__, for some > reason) so it's not comparable. > > What's actually going on here? With Python 3.7: >>> from enum import Flag >>> import inspect >>> print(inspect.getsource(Flag.__dir__)) def __dir__(self): added_behavior = [ m for cls in self.__class__.mro() for m in cls.__dict__ if m[0] != '_' and m not in self._member_map_ ] return (['__class__', '__doc__', '__module__'] + added_behavior) Looks like everything starting with an underscore (except class, doc, and module) is suppressed, probably to suppress some noise... From barry at barrys-emacs.org Mon Oct 7 03:06:07 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 7 Oct 2019 08:06:07 +0100 Subject: Get __name__ in C extension module In-Reply-To: <61e15f2a-e569-ab7d-8e92-23470416f39e@mrabarnett.plus.com> References: <8a8c39c0-d9e7-a02b-f7e0-4155ad89d2b1@mrabarnett.plus.com> <59367367-c892-6acf-da8d-da74556257c4@gmail.com> <61e15f2a-e569-ab7d-8e92-23470416f39e@mrabarnett.plus.com> Message-ID: > On 7 Oct 2019, at 04:34, MRAB wrote: > > On 2019-10-07 00:38, Ian Pilcher wrote: >> On 10/6/19 11:55 AM, MRAB wrote: >> > Don't you already have the module's name? You have to specify it in the > PyModuleDef struct that you pass to PyModule_Create. >> >> I do. Perhaps I'm trying to be too Pythonic, but there's so much advice >> out there about using getLogger(__name__) in Python code, rather than >> hardcoding the name. I've been trying to follow that pattern in my >> extension module. >> >> > Calling PyModule_Create returns a reference to the module, and you can > get its namespace dict with PyModule_GetDict(...). >> >> Right. I have that in my module init function, but how do I access that >> later in one of my extension functions? The only thing I can think of >> would be to save it in a static variable, but static variables seem to >> be a no-no in extensions. >> > Can an extension module be instantiated twice? If so, would they share static variables? If they don't, then it's not a problem. You could have 2 modules that share code. But you cannot init the same module twice. Barry > > -- > https://mail.python.org/mailman/listinfo/python-list From barry at barrys-emacs.org Mon Oct 7 03:09:34 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 7 Oct 2019 08:09:34 +0100 Subject: Get __name__ in C extension module In-Reply-To: References: <6D08C484-863C-41EF-A987-0A69EF1D4AA6@barrys-emacs.org> Message-ID: <0044EAAD-BA1B-4103-ADDD-A457AB21D0D9@barrys-emacs.org> > On 7 Oct 2019, at 00:44, Ian Pilcher wrote: > > On 10/6/19 12:55 PM, Barry Scott wrote: >> Then the answer to your question is simple. Do it in python and passt >> logger into the C++ module. > > Funny thing, that's exactly where I started this journey. I couldn't > figure out how to get the logging.Logger type object, so that I could > use a "O!" format string unit. This led me to read a bit more about > the logging framework, which led me to the advice to get loggers by > name, rather than passing them around, etc., etc. I meant pass in the specific named logger that you C code will use. > >> Next I would never code directly against the C API. Its a pain to use >> and get right, get the ref counts wrong and you get memory leaks of >> worse crash python. > > Well, I like driving cars with manual transmissions, so ... You are clearly aware of the risks. Barry > > -- > ======================================================================== > Ian Pilcher arequipeno at gmail.com > -------- "I grew up before Mark Zuckerberg invented friendship" -------- > ======================================================================== > From rosuav at gmail.com Mon Oct 7 03:21:20 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Oct 2019 18:21:20 +1100 Subject: Strange tab completion oddity with enums? In-Reply-To: References: Message-ID: On Mon, Oct 7, 2019 at 6:00 PM Peter Otten <__peter__ at web.de> wrote: > > Chris Angelico wrote: > > > I'm not sure what's going on here, and it's probably not actually > > enum-specific, but that's where I saw it. > > > > If you create a plain class and have an attribute with an annotation, > > you can see that: > > > >>>> class Foo: > > ... spam: "ham" = 1 > > ... > >>>> Foo.__a > > Foo.__abstractmethods__ Foo.__annotations__ > >>>> Foo.__annotations__ > > {'spam': 'ham'} > > > > Note that __annotations__ shows up when tab-completing "__a". > > > > Now consider an enumeration: > > > >>>> from enum import Flag, auto > >>>> class Bar(Flag): > > ... quux: "asdf" = auto() > > ... > >>>> Bar.__ > > Bar.__abstractmethods__ Bar.__getattr__( Bar.__ne__( > > Bar.__base__( Bar.__getattribute__( Bar.__new__( > > Bar.__bases__ Bar.__getitem__( Bar.__prepare__( > > Bar.__basicsize__ Bar.__gt__( Bar.__qualname__ > > Bar.__bool__( Bar.__hash__( Bar.__reduce__( > > Bar.__call__( Bar.__init__( Bar.__reduce_ex__( > > Bar.__class__( Bar.__init_subclass__( Bar.__repr__( > > Bar.__contains__( Bar.__instancecheck__( Bar.__reversed__( > > Bar.__delattr__( Bar.__itemsize__ Bar.__setattr__( > > Bar.__dict__ Bar.__iter__( Bar.__sizeof__( > > Bar.__dictoffset__ Bar.__le__( Bar.__str__( > > Bar.__dir__( Bar.__len__( Bar.__subclasscheck__( > > Bar.__doc__ Bar.__lt__( Bar.__subclasses__( > > Bar.__eq__( Bar.__members__ Bar.__subclasshook__( > > Bar.__flags__ Bar.__module__ Bar.__text_signature__ > > Bar.__format__( Bar.__mro__ Bar.__weakrefoffset__ > > Bar.__ge__( Bar.__name__ > >>>> Bar.__annotations__ > > {'quux': 'asdf'} > > > > Double-tabbing "__" shows everything but, and double-tabbing "__ann" > > has nothing... but the attribute is most definitely there. > > > > Perhaps notable is dir(): > > > >>>> dir(Foo) > > ['__annotations__', '__class__', '__delattr__', '__dict__', '__dir__', > > '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', > > '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', > > '__lt__', '__module__', '__ne__', '__new__', '__reduce__', > > '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', > > '__subclasshook__', '__weakref__', 'spam'] > >>>> dir(Bar) > > ['__class__', '__doc__', '__members__', '__module__', 'quux'] > > > > But that's not the whole story, since tab completing "Bar.__" will > > still show "__class__" and "__init__" that aren't in dir(). > > > > Tested with the default REPL CPython 3.6, 3.7, 3.8, and 3.9. Tested > > also in IDLE on 3.9 but tab completion of dunders behaves differently > > there (it ONLY seems to want to tab complete __class__, for some > > reason) so it's not comparable. > > > > What's actually going on here? > > With Python 3.7: > > >>> from enum import Flag > >>> import inspect > >>> print(inspect.getsource(Flag.__dir__)) > def __dir__(self): > added_behavior = [ > m > for cls in self.__class__.mro() > for m in cls.__dict__ > if m[0] != '_' and m not in self._member_map_ > ] > return (['__class__', '__doc__', '__module__'] + added_behavior) > > Looks like everything starting with an underscore (except class, doc, and > module) is suppressed, probably to suppress some noise... > That's why dir() shows what it does, but tab completion seems to have some other source, as it's able to find a lot of other attributes but not __annotations__. Very strange. ChrisA From __peter__ at web.de Mon Oct 7 04:11:12 2019 From: __peter__ at web.de (Peter Otten) Date: Mon, 07 Oct 2019 10:11:12 +0200 Subject: Strange tab completion oddity with enums? References: Message-ID: Chris Angelico wrote: >> Looks like everything starting with an underscore (except class, doc, and >> module) is suppressed, probably to suppress some noise... >> > > That's why dir() shows what it does, but tab completion seems to have > some other source, as it's able to find a lot of other attributes but > not __annotations__. Very strange. If I'm reading rlcompleter.py correctly words = set(dir(thisobject)) words.discard("__builtins__") if hasattr(thisobject, '__class__'): words.add('__class__') words.update(get_class_members(thisobject.__class__)) def get_class_members(klass): ret = dir(klass) if hasattr(klass,'__bases__'): for base in klass.__bases__: ret = ret + get_class_members(base) return ret it implements its own way to walk the class tree, and type being the base class of EnumMeta those additional attributes should be the result of dir(type) From hongyi.zhao at gmail.com Mon Oct 7 07:15:59 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Mon, 7 Oct 2019 11:15:59 +0000 (UTC) Subject: python -m pip install and pip install Message-ID: Hi, What's the diff: python -m pip install mod and pip install mod From rosuav at gmail.com Mon Oct 7 07:36:08 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Oct 2019 22:36:08 +1100 Subject: python -m pip install and pip install In-Reply-To: References: Message-ID: On Mon, Oct 7, 2019 at 10:21 PM Hongyi Zhao wrote: > > Hi, > > What's the diff: > > python -m pip install mod > and > pip install mod I presume from your series of posts that you either do not have access to a web browser, or do not trust search engines, because all of these questions can be answered easily and simply by a quick search of Google/DuckDuckGo/Bing/etc/etc/etc. Please, make some effort to research things yourself before asking questions. ChrisA From arequipeno at gmail.com Mon Oct 7 10:03:57 2019 From: arequipeno at gmail.com (Ian Pilcher) Date: Mon, 7 Oct 2019 09:03:57 -0500 Subject: Get __name__ in C extension module In-Reply-To: <0044EAAD-BA1B-4103-ADDD-A457AB21D0D9@barrys-emacs.org> References: <6D08C484-863C-41EF-A987-0A69EF1D4AA6@barrys-emacs.org> <0044EAAD-BA1B-4103-ADDD-A457AB21D0D9@barrys-emacs.org> Message-ID: <0b252a79-973f-066b-8692-a13154751e7a@gmail.com> On 10/7/19 2:09 AM, Barry Scott wrote: > I meant pass in the specific named logger that you C code will use. Right, but I'm assuming that your C/C++ code will receive the logger object by calling PyArg_ParseTuple (or similar), and I further assume that you want to validate that the object actually is a logger. Doing that validation (by using an "O!" unit in the PyArg_ParseTuple format string) requires access to the logging.Logger type object, and I was unable to find a way to access that object by name. -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From geoff.bache at gmail.com Mon Oct 7 02:54:52 2019 From: geoff.bache at gmail.com (Geoff Bache) Date: Mon, 7 Oct 2019 08:54:52 +0200 Subject: Access violation in Python garbage collector (visit_decref) - how to debug? In-Reply-To: References: Message-ID: I've so far only tried within my application, but I'm aware it would be easier if I could reproduce it outside. Even simplifying the context within the application has proved difficult though, so I suspect this will be hard. But I can try a bit more... The file isn't "large" by production standards, only by test data standards. It's about 500kb and not at all deeply nested, basically a long list of dictionaries. But I don't seem to be able to reduce it further either. /Geoff On Fri, Oct 4, 2019 at 9:53 PM Chris Angelico wrote: > On Sat, Oct 5, 2019 at 5:38 AM Geoff Bache wrote: > > > > Hi all, > > > > We are running Python embedded in our C++ product and are now > experiencing > > crashes (access violation reading 0xffffffffff on Windows) in the Python > > garbage collector. > > > > We got this on Python 3.6.4 originally, but I can reproduce it with both > > Python 3.6.8 and Python 3.7.4. > > > > The chances of producing a minimal example that reproduces it reliably > are > > currently small I would say. All attempts to simplify the set up seem to > > cause the problem to go away. > > Indeed I can only reproduce it by sending a fairly large amount of data 2 > > or 3 times to our server - sending either half of the data does not > > reproduce it. > > Have you tried to reproduce the issue outside of your application? > Even if it means creating a gigantic Python script with a whopping > triple-quoted string for the input data, it'd be helpful to try this. > If you CAN repro the problem, it'd be way easier to diagnose (since we > don't need your code, just your test case); and if you CAN'T, it may > mean an issue with the embedding aspects. > > What's your definition of "fairly large" here? How many > kilobytes/megabytes/gigabytes, and how deeply nested is the JSON > object? > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From geoff.bache at gmail.com Mon Oct 7 03:04:09 2019 From: geoff.bache at gmail.com (Geoff Bache) Date: Mon, 7 Oct 2019 09:04:09 +0200 Subject: Access violation in Python garbage collector (visit_decref) - how to debug? In-Reply-To: <55af1f79-4168-b356-19c9-84a5832d0c5c@mrabarnett.plus.com> References: <55af1f79-4168-b356-19c9-84a5832d0c5c@mrabarnett.plus.com> Message-ID: It's possible. Our embedding code is fairly simple and we've tried to encapsulate all the DECREFing in resource objects, i.e. that do DECREF in their destructor when they go out of scope. We hoped this would minimise this sort of problem. The C++ calling code essentially tries to call progwrapper.prog with a dictionary as arguments, and looks like GilStateHolder pyStateHolder; PyRefHolder module(PyImport_ImportModule("progwrapper")); if (module._ref) { PyXRefHolder func(PyObject_GetAttrString(module._ref, "prog")); PyXRefHolder pyArgs(PyTuple_New(1)); PyXRefHolder pyDict(convertDictForPython(dictIn)); PyTuple_SetItem(pyArgs._ref, 0, pyDict._ref); PyRefHolder pyRet(PyObject_CallObject(func._ref, pyArgs._ref)); if (pyRet._ref != NULL) { addPythonValuesToDict(pyRet._ref, theDict); ... where GilStateHolder, PyRefHolder etc are such resource objects as described above, wrapping round the PyObject pointers etc. /Geoff On Fri, Oct 4, 2019 at 9:56 PM MRAB wrote: > On 2019-10-04 20:32, Geoff Bache wrote: > > Hi all, > > > > We are running Python embedded in our C++ product and are now > experiencing > > crashes (access violation reading 0xffffffffff on Windows) in the Python > > garbage collector. > > > > We got this on Python 3.6.4 originally, but I can reproduce it with both > > Python 3.6.8 and Python 3.7.4. > > > > The chances of producing a minimal example that reproduces it reliably > are > > currently small I would say. All attempts to simplify the set up seem to > > cause the problem to go away. > > Indeed I can only reproduce it by sending a fairly large amount of data 2 > > or 3 times to our server - sending either half of the data does not > > reproduce it. > > > [snip] > In my experience, it's most likely caused by incorrect refcounting, > DECREFing too many times. > -- > https://mail.python.org/mailman/listinfo/python-list > From geoff.bache at gmail.com Mon Oct 7 03:07:30 2019 From: geoff.bache at gmail.com (Geoff Bache) Date: Mon, 7 Oct 2019 09:07:30 +0200 Subject: Access violation in Python garbage collector (visit_decref) - how to debug? In-Reply-To: <87pnjbydg6.fsf@handshake.de> References: <87pnjbydg6.fsf@handshake.de> Message-ID: Yes, this is hard, that's why I'm here :) I've enabled the equivalent tools to valgrind in Visual Studio, and tried setting PYTHONMALLOC=debug, but neither of those seem to be showing anything either. I don't really know what else to try in this direction. /Geoff On Sat, Oct 5, 2019 at 7:22 AM dieter wrote: > Geoff Bache writes: > > ... > > We are running Python embedded in our C++ product and are now > experiencing > > crashes (access violation reading 0xffffffffff on Windows) in the Python > > garbage collector. > > Errors like this are very difficult to analyse. The main reason: > the memory corruption is likely far away from the point when > it is finally detected (by an access violation in your case). > > Python can be built in a special way to add marks to > its allocated memory blocks and verify their validity. > This increases the chance to detect a memory corruption earlier > and thereby facilitates the detection of the root cause. > > There are tools for the analysis of memory management problems > (e.g. "valgrind", though this may be for Linux). In my > experience, even with those tools, the analysis is very difficult. > > I have several times successfully analysed memory corruption > problems. In those cases, I have been lucky that the corruption > was reproducible and affected typically the same address. > Thus, I could put a (hardware) memory breakpoint at this address > stopping the program as soon as this address was written and > then analyse the state in the debugger. This way, I could detect > precisely which code caused the corruption. However, > this was quite a long time ago; nowadays, modern operating systems > employ address randomization thus reducing significantly that > the corruption affects the same address (which may mean that > you need to deactivate address randomization to get a better chance > for this kind of analysis. > > -- > https://mail.python.org/mailman/listinfo/python-list > From boffi at format.org Mon Oct 7 11:04:15 2019 From: boffi at format.org (boffi) Date: Mon, 07 Oct 2019 17:04:15 +0200 Subject: Formatting floating point References: Message-ID: <87h84kppg0.fsf@debian> DL Neil writes: > Agreed: there's ton(ne)s of information 'out there', much of it old, > eg Python2, "formatter" (deprecated since v3.4) ? are you referring to the `string.Formatter`[*] class? $ python Python 3.7.4 (default, Aug 13 2019, 20:35:49) [GCC 7.3.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information. >>> from string import Formatter >>> if not, what else? g [*] https://docs.python.org/2/library/string.html#string.Formatter https://docs.python.org/3.7/library/string.html#string.Formatter From sjeik_appie at hotmail.com Mon Oct 7 11:30:57 2019 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Mon, 7 Oct 2019 15:30:57 +0000 Subject: sqlalchemy & #temp tables Message-ID: Hi, I am using sqlalchemy (SA) to access a MS SQL Server database (python 3.5, Win 10). I would like to use a temporary table (preferably #local, but ##global would also be an option) to store results of a time-consuming query. In other queries I'd like to access the temporary table again in various places in my Flask app. How do I do that, given that SA closes the connection after each request? I can do: with engine.connect() as con: con.execute('select * into #tmp from tbl') con.execute('select * from #tmp') ... but that's limited to the scope of the context manager. Oh, I don't have rights to create a 'real' table. :-( Thanks! Albert-Jan From python at mrabarnett.plus.com Mon Oct 7 13:30:53 2019 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 7 Oct 2019 18:30:53 +0100 Subject: Access violation in Python garbage collector (visit_decref) - how to debug? In-Reply-To: References: <55af1f79-4168-b356-19c9-84a5832d0c5c@mrabarnett.plus.com> Message-ID: <451ffcc2-4366-5e04-406f-b1669f3ec6bd@mrabarnett.plus.com> On 2019-10-07 08:04, Geoff Bache wrote: > It's possible. Our embedding code is fairly simple and we've tried to > encapsulate all the DECREFing in resource objects, i.e. that do DECREF > in their destructor when they go out of scope. We hoped this would > minimise this sort of problem. > The C++ calling code essentially tries to call progwrapper.prog with a > dictionary as arguments, and looks like > > GilStateHolder pyStateHolder; > PyRefHolder module(PyImport_ImportModule("progwrapper")); > > ? if (module._ref) > ? { > ? ? PyXRefHolder func(PyObject_GetAttrString(module._ref, "prog")); > ? ? PyXRefHolder pyArgs(PyTuple_New(1)); > ? ? PyXRefHolder pyDict(convertDictForPython(dictIn)); > ? ? PyTuple_SetItem(pyArgs._ref, 0, pyDict._ref); |Do you DECREF pyDict._ref later on? I ask because PyTuple_SetItem steals a reference.| |Many other functions that "store" an object, such as PyList_Append, INCREF to retain the stored object, but PyTuple_SetItem doesn't.| || > ? ? PyRefHolder pyRet(PyObject_CallObject(func._ref, pyArgs._ref)); > > ? ? if (pyRet._ref != NULL) > ? ? { > ? ? ? addPythonValuesToDict(pyRet._ref, theDict); > ????? ... > > where GilStateHolder, PyRefHolder etc are such resource objects as > described above, wrapping round the PyObject pointers etc. > > [snip] From anthra.norell at bluewin.ch Mon Oct 7 14:56:51 2019 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Mon, 7 Oct 2019 20:56:51 +0200 Subject: pre-edit stuff persists in a reloaded a module In-Reply-To: References: Message-ID: <3cd18791-e6d0-b6a2-b1b1-8c7b8222faee@bluewin.ch> On 10/5/19 1:48 PM, Friedrich Rentsch wrote: > Hi all, > > Python 2.7. I habitually work interactively in an Idle window. > Occasionally I correct code, reload and find that edits fail to load. > I understand that reloading is not guaranteed to reload everything, > but I don't understand the exact mechanism and would appreciate some > illumination. Right now I am totally bewildered, having deleted and > garbage collected a module and an object, reloaded the module and > remade the object and when I inspect the corrected source > (inspect.getsource (Object.run)) I see the uncorrected source, which > isn't even on the disk anymore. The command 'reload' correctly > displays the name of the source, ending '.py', indicating that it > recognizes the source being newer than the compile ending '.pyc'. > After the reload, the pyc-file is newer, indicating that it has been > recompiled. But the runtime error persist. So the recompile must have > used the uncorrected old code. I could kill python with signal 15, but > would prefer a targeted purge that doesn't wipe clean my Idle > workbench. (I know I should upgrade to version 3. I will as soon as I > get around to it. Hopefully that will fix the problem.) > > Thanks for comments > > Frederic > Closing the thread with thanks to all who responded, offering excellent advice. Frederic From PythonList at DancesWithMice.info Mon Oct 7 16:23:55 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 8 Oct 2019 09:23:55 +1300 Subject: Formatting floating point In-Reply-To: <87h84kppg0.fsf@debian> References: <87h84kppg0.fsf@debian> Message-ID: On 8/10/19 4:04 AM, boffi wrote: > DL Neil writes: > >> Agreed: there's ton(ne)s of information 'out there', much of it old, >> eg Python2, "formatter" (deprecated since v3.4) > ? > are you referring to the `string.Formatter`[*] class? > $ python > Python 3.7.4 (default, Aug 13 2019, 20:35:49) > [GCC 7.3.0] :: Anaconda, Inc. on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> from string import Formatter > if not, what else? > g > [*] https://docs.python.org/2/library/string.html#string.Formatter > https://docs.python.org/3.7/library/string.html#string.Formatter As mentioned, there is a wealth of information, but I must admit it took a moment-or-two before I re-located the 'official' reference to f-strings: 2.4.3. Formatted string literals https://docs.python.org/3/reference/lexical_analysis.html#f-strings (and please 'read-around' this section for more valuable data!) FYI the original PEP is at https://www.python.org/dev/peps/pep-0498/ It is worth reading about string formatters (per (your) ref, above), because many elements of the 'Formatting mini-language' are also available within f-strings! As you have probably observed, there are now (v3.6+) several methods which can be applied to the formatting of data. Each has its advantages, and whilst I have a preference for, and thus recommended, WRITING code to use f-strings, it is also (likely to be) important that we READ and comprehend the older/alternatives! NB politesse suggests that I should apologise, but I no-longer wish to work with Python2; hence only mentioning Py3 'here'. -- Regards =dn From DomainAdmin at DancesWithMice.info Mon Oct 7 17:12:09 2019 From: DomainAdmin at DancesWithMice.info (David L Neil) Date: Tue, 8 Oct 2019 10:12:09 +1300 Subject: Mouse control In-Reply-To: <58519cc4-0c96-e018-a5b7-43d2011719de@gmail.com> References: <58519cc4-0c96-e018-a5b7-43d2011719de@gmail.com> Message-ID: On 7/10/19 4:11 AM, Alexander Vergun wrote: > I am coding a voice assistant under Python 3.7, Windows 7. I am using > PYcharm and libraries such as PYSimpleGUI, mouse, keyboard etc. > Everything works except for the mouse control and probably keyboard, the > problem is following, when I run the script under PYcharm, the script > can control mouse only within PYcharm editor, but when the other window > is on the top, the script cannot control the mouse, and the same happens > when the script runs under the Python console. There is only one way to > make script control the mouse - I have to manually click on the window > which was opened by the script only then the script controls the mouse. > I tried to call win32gui.SetCapture without any effect. > Does anyone have an idea how to handle this? Thank you very much, Are you asking to be able to start a Python application in one window, which will control the mouse and keyboard in other concurrent applications' windows? I don't use MS-Windows, but don't think this is possible (under any OpSys). As you say "and probably keyboard": imagine typing and having the text appear in every open window/application? If you don't want that, how do you indicate which one should accept the input? Answer: "focus" = the 'target' for any typing is the application/window which currently has focus. Extending those thoughts to the mouse doesn't quite ring-true, because I'm currently in 'this' window writing an email message, yet the mouse will cheerfully scroll the window 'below'. Is that the sort of action you wish? In my experience, the Python application, including "mouse", only operates in "user space" and within the one window. If we can extend Python's power and dominion, I'll be interested to learn... Meantime, there are demo snippets which follow the mouse, printing its coordinates. Using one of those, what happens to the coordinates when the mouse is moved outside of the Python application's window? BTW you may like to take a look at PyAutoGUI, if only because it has been more recently updated. It may also help by bringing 'everything' under one import rather than the multiple packages (listed above): https://pypi.org/project/PyAutoGUI/ https://pyautogui.readthedocs.io/en/latest/mouse.html https://automatetheboringstuff.com/chapter18/ -- Regards =dn From pankaj.jangid at gmail.com Mon Oct 7 20:58:05 2019 From: pankaj.jangid at gmail.com (Pankaj Jangid) Date: Tue, 08 Oct 2019 06:28:05 +0530 Subject: python -m pip install and pip install References: Message-ID: Hongyi Zhao writes: > Hi, > > What's the diff: > > python -m pip install mod > and > pip install mod A very good use-case is when you have both, python2 and python3 installed. python2 -m pip install mod and python3 -m pip install mod will install the package in the corresponding PYTHONPATH. -- Regards Pankaj From jfong at ms4.hinet.net Mon Oct 7 22:45:24 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 7 Oct 2019 19:45:24 -0700 (PDT) Subject: How to handle '-' in the 'from' part in a "from import" statement? Message-ID: <333d5f3a-6e77-4899-90aa-63ee3940be4c@googlegroups.com> For example: from my-dir import test I know it can be solved by renaming, but any alternative? --Jach From hongyi.zhao at gmail.com Mon Oct 7 22:49:50 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Tue, 8 Oct 2019 02:49:50 +0000 (UTC) Subject: python -m pip install and pip install References: Message-ID: On Tue, 08 Oct 2019 06:28:05 +0530, Pankaj Jangid wrote: > A very good use-case is when you have both, python2 and python3 > installed. > > python2 -m pip install mod If so, why not just: pip2 install mod > > and > > python3 -m pip install mod and using: pip3 install mod > > will install the package in the corresponding PYTHONPATH. From PythonList at DancesWithMice.info Mon Oct 7 23:01:55 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 8 Oct 2019 16:01:55 +1300 Subject: How to handle '-' in the 'from' part in a "from import" statement? In-Reply-To: <333d5f3a-6e77-4899-90aa-63ee3940be4c@googlegroups.com> References: <333d5f3a-6e77-4899-90aa-63ee3940be4c@googlegroups.com> Message-ID: <8e244a4d-7368-2419-14cc-aae22dc8a86a@DancesWithMice.info> On 8/10/19 3:45 PM, jfong at ms4.hinet.net wrote: > For example: > from my-dir import test > > I know it can be solved by renaming, but any alternative? The manual is your friend: - import - importlib (the latter allows modules to be identified by strings) However, Pythons has naming rules. If you try to get around them, sooner or later you'll 'forget' and trip yourself up. Recommend your first idea! -- Regards =dn From jfong at ms4.hinet.net Mon Oct 7 23:42:14 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 7 Oct 2019 20:42:14 -0700 (PDT) Subject: How to handle '-' in the 'from' part in a "from import" statement? In-Reply-To: References: <333d5f3a-6e77-4899-90aa-63ee3940be4c@googlegroups.com> <8e244a4d-7368-2419-14cc-aae22dc8a86a@DancesWithMice.info> Message-ID: DL Neil? 2019?10?8???? UTC+8??11?02?20???? > On 8/10/19 3:45 PM, jfong at ms4.hinet.net wrote: > > For example: > > from my-dir import test > > > > I know it can be solved by renaming, but any alternative? > > > The manual is your friend: > - import > - importlib > > (the latter allows modules to be identified by strings) > > However, Pythons has naming rules. If you try to get around them, sooner > or later you'll 'forget' and trip yourself up. Recommend your first idea! > -- > Regards =dn Yes, I had noticed the naming rules. Thank you. But most of the download from Github has a directory named 'xxxx-master' which causes a trouble sometimes. --Jach From cs at cskk.id.au Mon Oct 7 23:48:01 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 8 Oct 2019 14:48:01 +1100 Subject: python -m pip install and pip install In-Reply-To: References: Message-ID: <20191008034801.GA77035@cskk.homeip.net> On 08Oct2019 02:49, Hongyi Zhao wrote: >On Tue, 08 Oct 2019 06:28:05 +0530, Pankaj Jangid wrote: >> A very good use-case is when you have both, python2 and python3 >> installed. >> python2 -m pip install mod >> python3 -m pip install mod >> will install the package in the corresponding PYTHONPATH. >> > >If so, why not just: >pip2 install mod >and using: >pip3 install mod Because of the slight disconnect between "pip2" and "python2", etc. Do you _know_ they both use the same Python install? With "pythonX -m pip" you're using the same python executable which will be accessing what you just installed. It isn't a deal breaker, but preferred: one less moving part. Cheers, Cameron Simpson From dieter at handshake.de Tue Oct 8 01:26:26 2019 From: dieter at handshake.de (dieter) Date: Tue, 08 Oct 2019 07:26:26 +0200 Subject: Access violation in Python garbage collector (visit_decref) - how to debug? References: <87pnjbydg6.fsf@handshake.de> Message-ID: <87lftvbyf1.fsf@handshake.de> Geoff Bache writes: > Yes, this is hard, that's why I'm here :) > > I've enabled the equivalent tools to valgrind in Visual Studio, and tried > setting PYTHONMALLOC=debug, but neither of those seem to be showing > anything either. I don't really know what else to try in this direction. It likely is too hard to be solved remotely (in this list). When I had analysed a similar problem (a long time ago), I had the chance that the problem was quite easily reproducible -- is this the case for you? This allowed me to run the program under debugger ("gdb") control with the debugger getting control as soon as the access violation occured. The "gdb" allows debugging both at C as well as at machine code level. Using machine code level debugging allowed me to determine the address where the wrong pointer came from. Setting a (hardware) watchpoint for this address stopped the program when the wrong pointer was written to this address. This gave me two important pieces of information: which code writes the wrong pointer and what was in the memory region before the memory corruption (which type of Python object was involved). In my case, reproducibility, machine level debugging, hardware write watchpoints and a detailed knowledge of Python's runtime data structures have been necessary to resolve the problem. > On Sat, Oct 5, 2019 at 7:22 AM dieter wrote: > >> Geoff Bache writes: >> > ... >> > We are running Python embedded in our C++ product and are now >> experiencing >> > crashes (access violation reading 0xffffffffff on Windows) in the Python >> > garbage collector. >> >> Errors like this are very difficult to analyse. The main reason: >> the memory corruption is likely far away from the point when >> it is finally detected (by an access violation in your case). >> >> Python can be built in a special way to add marks to >> its allocated memory blocks and verify their validity. >> This increases the chance to detect a memory corruption earlier >> and thereby facilitates the detection of the root cause. >> >> There are tools for the analysis of memory management problems >> (e.g. "valgrind", though this may be for Linux). In my >> experience, even with those tools, the analysis is very difficult. >> >> I have several times successfully analysed memory corruption >> problems. In those cases, I have been lucky that the corruption >> was reproducible and affected typically the same address. >> Thus, I could put a (hardware) memory breakpoint at this address >> stopping the program as soon as this address was written and >> then analyse the state in the debugger. This way, I could detect >> precisely which code caused the corruption. However, >> this was quite a long time ago; nowadays, modern operating systems >> employ address randomization thus reducing significantly that >> the corruption affects the same address (which may mean that >> you need to deactivate address randomization to get a better chance >> for this kind of analysis. >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> From dieter at handshake.de Tue Oct 8 01:32:54 2019 From: dieter at handshake.de (dieter) Date: Tue, 08 Oct 2019 07:32:54 +0200 Subject: How to handle '-' in the 'from' part in a "from import" statement? References: <333d5f3a-6e77-4899-90aa-63ee3940be4c@googlegroups.com> <8e244a4d-7368-2419-14cc-aae22dc8a86a@DancesWithMice.info> Message-ID: <87h84jby49.fsf@handshake.de> jfong at ms4.hinet.net writes: > ... > But most of the download from Github has a directory named 'xxxx-master' which causes a trouble sometimes. Those are likely not meant to be imported directly. Typically, you have a "setup" step which installs (in some way) a "distribution". This step usually ensures that you can use "normal" Python import syntax to access all associated packages. The "setup" step is typically performed with "python setup.py develop" or "python setup.py install" -- with the "distribution" providing the "setup.py". From frank at chagford.com Tue Oct 8 01:49:00 2019 From: frank at chagford.com (Frank Millman) Date: Tue, 8 Oct 2019 07:49:00 +0200 Subject: sqlalchemy & #temp tables In-Reply-To: References: Message-ID: <8f8402a4-2529-bffd-13b7-db6e231eb2eb@chagford.com> On 2019-10-07 5:30 PM, Albert-Jan Roskam wrote: > Hi, > > I am using sqlalchemy (SA) to access a MS SQL Server database (python 3.5, Win 10). I would like to use a temporary table (preferably #local, but ##global would also be an option) to store results of a time-consuming query. In other queries I'd like to access the temporary table again in various places in my Flask app. How do I do that, given that SA closes the connection after each request? > > I can do: > with engine.connect() as con: > con.execute('select * into #tmp from tbl') > con.execute('select * from #tmp') > > ... but that's limited to the scope of the context manager. > > Oh, I don't have rights to create a 'real' table. :-( > > Thanks! > > Albert-Jan > This does not answer your question directly, but FWIW this is what I do. I do not use SA, but I have written my app to support Sql Server, PostgreSQL and sqlite3 as backend databases. However, no matter which one is in use, I also use sqlite3 as an in-memory database to store temporary information. It took me a little while to get it all working smoothly, but now it works well. Of course this may not work for you if you have a large volume of temp data, but it may be worth trying. Frank Millman From frank at chagford.com Tue Oct 8 01:49:00 2019 From: frank at chagford.com (Frank Millman) Date: Tue, 8 Oct 2019 07:49:00 +0200 Subject: sqlalchemy & #temp tables In-Reply-To: References: Message-ID: <8f8402a4-2529-bffd-13b7-db6e231eb2eb@chagford.com> On 2019-10-07 5:30 PM, Albert-Jan Roskam wrote: > Hi, > > I am using sqlalchemy (SA) to access a MS SQL Server database (python 3.5, Win 10). I would like to use a temporary table (preferably #local, but ##global would also be an option) to store results of a time-consuming query. In other queries I'd like to access the temporary table again in various places in my Flask app. How do I do that, given that SA closes the connection after each request? > > I can do: > with engine.connect() as con: > con.execute('select * into #tmp from tbl') > con.execute('select * from #tmp') > > ... but that's limited to the scope of the context manager. > > Oh, I don't have rights to create a 'real' table. :-( > > Thanks! > > Albert-Jan > This does not answer your question directly, but FWIW this is what I do. I do not use SA, but I have written my app to support Sql Server, PostgreSQL and sqlite3 as backend databases. However, no matter which one is in use, I also use sqlite3 as an in-memory database to store temporary information. It took me a little while to get it all working smoothly, but now it works well. Of course this may not work for you if you have a large volume of temp data, but it may be worth trying. Frank Millman From piet-l at vanoostrum.org Tue Oct 8 02:09:58 2019 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Tue, 08 Oct 2019 08:09:58 +0200 Subject: Strange tab completion oddity with enums? References: Message-ID: Chris Angelico writes: > I'm not sure what's going on here, and it's probably not actually > enum-specific, but that's where I saw it. > > If you create a plain class and have an attribute with an annotation, > you can see that: > >>>> class Foo: > ... spam: "ham" = 1 > ... >>>> Foo.__a > Foo.__abstractmethods__ Foo.__annotations__ >>>> Foo.__annotations__ > {'spam': 'ham'} Also strange: It shows Foo.__abstractmethods__ but there is no such attribute. What's going on? >>> Foo.__abstractmethods__ Traceback (most recent call last): File "", line 1, in AttributeError: __abstractmethods__ -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From __peter__ at web.de Tue Oct 8 03:06:45 2019 From: __peter__ at web.de (Peter Otten) Date: Tue, 08 Oct 2019 09:06:45 +0200 Subject: Strange tab completion oddity with enums? References: Message-ID: Piet van Oostrum wrote: > Chris Angelico writes: > >> I'm not sure what's going on here, and it's probably not actually >> enum-specific, but that's where I saw it. >> >> If you create a plain class and have an attribute with an annotation, >> you can see that: >> >>>>> class Foo: >> ... spam: "ham" = 1 >> ... >>>>> Foo.__a >> Foo.__abstractmethods__ Foo.__annotations__ >>>>> Foo.__annotations__ >> {'spam': 'ham'} > > Also strange: > > It shows Foo.__abstractmethods__ but there is no such attribute. > What's going on? > >>>> Foo.__abstractmethods__ > Traceback (most recent call last): > File "", line 1, in > AttributeError: __abstractmethods__ An AttributeError doesn't generally doesn't mean that the attribute doesn't exist. Consider: >>> class Foo: ... @property ... def bar(self): raise AttributeError ... >>> foo = Foo() >>> "bar" in dir(foo) True >>> foo.bar Traceback (most recent call last): File "", line 1, in File "", line 3, in bar AttributeError So __abstractmethods__ might be a property of Foo's metaclass (type). Let's see: >>> type.__dict__["__abstractmethods__"] >>> type.__dict__["__abstractmethods__"].__get__(Foo) Traceback (most recent call last): File "", line 1, in AttributeError: __abstractmethods__ From scopensource at gmail.com Tue Oct 8 06:22:14 2019 From: scopensource at gmail.com (Simon Connah) Date: Tue, 8 Oct 2019 11:22:14 +0100 Subject: Would you be interested in this Python open source project? Message-ID: <3645f1e6-08f6-5cad-a53e-764df7f865af@gmail.com> I'm posting this message as a way to gauge interest in the project and to see if it is worth moving forward with. There are probably hundreds of CI/CD tools out there and many more general devops tools but what I want to build is a CI/CD tool that ONLY supports Python 3.6 or greater and only runs on one Linux distribution (my preference is Ubuntu). This way configuration would be much more simple than the vast majority of devops tools which try to support every programming language that is popular (or so it seems) on many different Linux distributions and even Windows and macOS. My theory is that if you limit the devops tool to a very limited subsection of the available options the system will be easier to configure for users, more stable, easier to patch bugs in and generally just be a better all around things for Python developers. I'd love to hear some feedback on the idea. From rhodri at kynesim.co.uk Tue Oct 8 08:17:07 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 8 Oct 2019 13:17:07 +0100 Subject: Would you be interested in this Python open source project? In-Reply-To: <3645f1e6-08f6-5cad-a53e-764df7f865af@gmail.com> References: <3645f1e6-08f6-5cad-a53e-764df7f865af@gmail.com> Message-ID: <10b13903-3f1e-87b8-4255-1303d943feda@kynesim.co.uk> On 08/10/2019 11:22, Simon Connah wrote: > I'm posting this message as a way to gauge interest in the project and > to see if it is worth moving forward with. There are probably hundreds > of CI/CD tools out there and many more general devops tools but what I > want to build is a CI/CD tool that ONLY supports Python 3.6 or greater > and only runs on one Linux distribution (my preference is Ubuntu). This > way configuration would be much more simple than the vast majority of > devops tools which try to support every programming language that is > popular (or so it seems) on many different Linux distributions and even > Windows and macOS. > > My theory is that if you limit the devops tool to a very limited > subsection of the available options the system will be easier to > configure for users, more stable, easier to patch bugs in and generally > just be a better all around things for Python developers. > > I'd love to hear some feedback on the idea. > I think your reasoning is sound. I probably wouldn't make a lot of use of it, but I live in Embedded Systems land where it's notoriously hard to do CI off the target silicon. Other people living in more tractable problem spaces will probably be more enthusiastic. -- Rhodri James *-* Kynesim Ltd From bill at baddogconsulting.com Tue Oct 8 10:05:13 2019 From: bill at baddogconsulting.com (Bill Deegan) Date: Tue, 8 Oct 2019 10:05:13 -0400 Subject: Would you be interested in this Python open source project? In-Reply-To: <10b13903-3f1e-87b8-4255-1303d943feda@kynesim.co.uk> References: <3645f1e6-08f6-5cad-a53e-764df7f865af@gmail.com> <10b13903-3f1e-87b8-4255-1303d943feda@kynesim.co.uk> Message-ID: You might just consider working with the BuildBot project to add support for lighter weight build workers. Re-Re-Re-inventing the wheel is almost always wasted effort. On Tue, Oct 8, 2019 at 8:33 AM Rhodri James wrote: > On 08/10/2019 11:22, Simon Connah wrote: > > I'm posting this message as a way to gauge interest in the project and > > to see if it is worth moving forward with. There are probably hundreds > > of CI/CD tools out there and many more general devops tools but what I > > want to build is a CI/CD tool that ONLY supports Python 3.6 or greater > > and only runs on one Linux distribution (my preference is Ubuntu). This > > way configuration would be much more simple than the vast majority of > > devops tools which try to support every programming language that is > > popular (or so it seems) on many different Linux distributions and even > > Windows and macOS. > > > > My theory is that if you limit the devops tool to a very limited > > subsection of the available options the system will be easier to > > configure for users, more stable, easier to patch bugs in and generally > > just be a better all around things for Python developers. > > > > I'd love to hear some feedback on the idea. > > > > I think your reasoning is sound. I probably wouldn't make a lot of use > of it, but I live in Embedded Systems land where it's notoriously hard > to do CI off the target silicon. Other people living in more tractable > problem spaces will probably be more enthusiastic. > > -- > Rhodri James *-* Kynesim Ltd > -- > https://mail.python.org/mailman/listinfo/python-list > From geoff.bache at gmail.com Tue Oct 8 02:44:30 2019 From: geoff.bache at gmail.com (Geoff Bache) Date: Tue, 8 Oct 2019 08:44:30 +0200 Subject: Access violation in Python garbage collector (visit_decref) - how to debug? In-Reply-To: <451ffcc2-4366-5e04-406f-b1669f3ec6bd@mrabarnett.plus.com> References: <55af1f79-4168-b356-19c9-84a5832d0c5c@mrabarnett.plus.com> <451ffcc2-4366-5e04-406f-b1669f3ec6bd@mrabarnett.plus.com> Message-ID: Thankyou!!! That was it. Saved me a lot of time debugging no doubt and potential nasty problems at customer sites etc. I must admit I had just pattern-matched with these functions but had no idea that some of them stole references. I still don't really understand why, the docs say it is a "common idiom", but not common enough to be familiar to me and tricky to be inconsistent. But now I know, and the crash is gone :) Regards and many thanks again, /Geoff On Mon, Oct 7, 2019 at 7:32 PM MRAB wrote: > On 2019-10-07 08:04, Geoff Bache wrote: > > It's possible. Our embedding code is fairly simple and we've tried to > > encapsulate all the DECREFing in resource objects, i.e. that do DECREF > > in their destructor when they go out of scope. We hoped this would > > minimise this sort of problem. > > The C++ calling code essentially tries to call progwrapper.prog with a > > dictionary as arguments, and looks like > > > > GilStateHolder pyStateHolder; > > PyRefHolder module(PyImport_ImportModule("progwrapper")); > > > > if (module._ref) > > { > > PyXRefHolder func(PyObject_GetAttrString(module._ref, "prog")); > > PyXRefHolder pyArgs(PyTuple_New(1)); > > PyXRefHolder pyDict(convertDictForPython(dictIn)); > > PyTuple_SetItem(pyArgs._ref, 0, pyDict._ref); > > |Do you DECREF pyDict._ref later on? I ask because PyTuple_SetItem > steals a reference.| > > |Many other functions that "store" an object, such as PyList_Append, > INCREF to retain the stored object, but PyTuple_SetItem doesn't.| > > || > > > PyRefHolder pyRet(PyObject_CallObject(func._ref, pyArgs._ref)); > > > > if (pyRet._ref != NULL) > > { > > addPythonValuesToDict(pyRet._ref, theDict); > > ... > > > > where GilStateHolder, PyRefHolder etc are such resource objects as > > described above, wrapping round the PyObject pointers etc. > > > > [snip] > > -- > https://mail.python.org/mailman/listinfo/python-list > From geoff.bache at gmail.com Tue Oct 8 02:46:17 2019 From: geoff.bache at gmail.com (Geoff Bache) Date: Tue, 8 Oct 2019 08:46:17 +0200 Subject: Access violation in Python garbage collector (visit_decref) - how to debug? In-Reply-To: <87lftvbyf1.fsf@handshake.de> References: <87pnjbydg6.fsf@handshake.de> <87lftvbyf1.fsf@handshake.de> Message-ID: On Tue, Oct 8, 2019 at 7:27 AM dieter wrote: > Geoff Bache writes: > > Yes, this is hard, that's why I'm here :) > > > > I've enabled the equivalent tools to valgrind in Visual Studio, and tried > > setting PYTHONMALLOC=debug, but neither of those seem to be showing > > anything either. I don't really know what else to try in this direction. > > It likely is too hard to be solved remotely (in this list). > > On the contrary, MRAB just solved it :) Thanks for your replies. /Geoff From hongyi.zhao at gmail.com Tue Oct 8 04:53:51 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Tue, 8 Oct 2019 16:53:51 +0800 Subject: python -m pip install and pip install In-Reply-To: <20191008034801.GA77035@cskk.homeip.net> References: <20191008034801.GA77035@cskk.homeip.net> Message-ID: Cameron Simpson ?2019?10?8??? ??12:25??? > > On 08Oct2019 02:49, Hongyi Zhao wrote: > >On Tue, 08 Oct 2019 06:28:05 +0530, Pankaj Jangid wrote: > >> A very good use-case is when you have both, python2 and python3 > >> installed. > >> python2 -m pip install mod > >> python3 -m pip install mod > >> will install the package in the corresponding PYTHONPATH. > >> > > > >If so, why not just: > >pip2 install mod > >and using: > >pip3 install mod > > Because of the slight disconnect between "pip2" and "python2", etc. Do > you _know_ they both use the same Python install? With "pythonX -m pip" > you're using the same python executable which will be accessing what you > just installed. I use pyenv + pip, which will do the trick. > > It isn't a deal breaker, but preferred: one less moving part. > > Cheers, > Cameron Simpson -- Hongsheng Zhao Institute of Semiconductors, Chinese Academy of Sciences GnuPG DSA: 0xD108493 From hongyi.zhao at gmail.com Tue Oct 8 04:59:06 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Tue, 8 Oct 2019 16:59:06 +0800 Subject: python -m pip install and pip install In-Reply-To: References: <20191008034801.GA77035@cskk.homeip.net> Message-ID: Hongyi Zhao ?2019?10?8??? ??4:53??? > > Cameron Simpson ?2019?10?8??? ??12:25??? > > > > On 08Oct2019 02:49, Hongyi Zhao wrote: > > >On Tue, 08 Oct 2019 06:28:05 +0530, Pankaj Jangid wrote: > > >> A very good use-case is when you have both, python2 and python3 > > >> installed. > > >> python2 -m pip install mod > > >> python3 -m pip install mod > > >> will install the package in the corresponding PYTHONPATH. > > >> > > > > > >If so, why not just: > > >pip2 install mod > > >and using: > > >pip3 install mod > > > > Because of the slight disconnect between "pip2" and "python2", etc. Do > > you _know_ they both use the same Python install? With "pythonX -m pip" > > you're using the same python executable which will be accessing what you > > just installed. > > I use pyenv + pip, which will do the trick. And nowadays, the pyenv + vurtualenv + pip + pipenv is the suggested env management method for python. In this way, the pipenv will solve the version dependence of the underlying tool chain and corresponding used packages/modules. > > > > > It isn't a deal breaker, but preferred: one less moving part. > > > > Cheers, > > Cameron Simpson > > > > -- > Hongsheng Zhao > Institute of Semiconductors, Chinese Academy of Sciences > GnuPG DSA: 0xD108493 -- Hongsheng Zhao Institute of Semiconductors, Chinese Academy of Sciences GnuPG DSA: 0xD108493 From vergos.nikolas at gmail.com Tue Oct 8 12:51:42 2019 From: vergos.nikolas at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Tue, 8 Oct 2019 09:51:42 -0700 (PDT) Subject: WHY it compains about the missing argument is WHAT i don't understand Message-ID: <6598feed-924f-4c94-bcc4-189b86b5547b@googlegroups.com> plugin = bottle_pymysql.Plugin( dbuser='user', dbpass='pass', dbname='counters', dictrows=False ) app.install(plugin) ....... ....... @app.route( '/' ) @auth_basic( counters.is_authenticated_user ) def listall( pymydb ): But when i try to load the app's URL like http://superhost.gr/clientele as you can see i get this error: Exception: TypeError("listall() missing 1 required positional argument: 'pymydb'",) Traceback: Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/bottle.py", line 862, in _handle return route.call(**args) File "/usr/lib/python3.6/site-packages/bottle.py", line 1740, in wrapper rv = callback(*a, **ka) File "/usr/lib/python3.6/site-packages/bottle.py", line 2690, in wrapper return func(*a, **ka) TypeError: listall() missing 1 required positional argument: 'pymydb' listall() is `/` route's callback function and i never inside my script i call listall( pymydb ). Why it compains about the missing argument is WHAT i don't understand. From barry at barrys-emacs.org Tue Oct 8 13:36:56 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Tue, 8 Oct 2019 18:36:56 +0100 Subject: Get __name__ in C extension module In-Reply-To: References: <6D08C484-863C-41EF-A987-0A69EF1D4AA6@barrys-emacs.org> Message-ID: <2C9A526A-727A-4B13-B5B7-14DF2F1F5214@barrys-emacs.org> > On 7 Oct 2019, at 00:44, Ian Pilcher wrote: > > On 10/6/19 12:55 PM, Barry Scott wrote: >> Then the answer to your question is simple. Do it in python and passt >> logger into the C++ module. > > Funny thing, that's exactly where I started this journey. I couldn't > figure out how to get the logging.Logger type object, so that I could > use a "O!" format string unit. This led me to read a bit more about > the logging framework, which led me to the advice to get loggers by > name, rather than passing them around, etc., etc. In PyCXX I never need to use the "O!" stuff. I write something like this (untested): // function in foo module Py::Object function( const Py::Tuple &args, const Py::Dict &kws ) { Py::Object logger( args[0] ); Py::Tuple log_args( 1 ); args[0] = Py::String( "log message" ); logger.callMemberFunction( "info", log_args ); return Py::None(); } I'd call from Python something like: import foo import logging logger = logging.getLogger(__name__) foo.function( logger ) > >> Next I would never code directly against the C API. Its a pain to use >> and get right, get the ref counts wrong and you get memory leaks of >> worse crash python. > > Well, I like driving cars with manual transmissions, so ... Understood. Barry > > -- > ======================================================================== > Ian Pilcher arequipeno at gmail.com > -------- "I grew up before Mark Zuckerberg invented friendship" -------- > ======================================================================== > From jfong at ms4.hinet.net Tue Oct 8 21:12:26 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Tue, 8 Oct 2019 18:12:26 -0700 (PDT) Subject: How to handle '-' in the 'from' part in a "from import" statement? In-Reply-To: References: <333d5f3a-6e77-4899-90aa-63ee3940be4c@googlegroups.com> <8e244a4d-7368-2419-14cc-aae22dc8a86a@DancesWithMice.info> <87h84jby49.fsf@handshake.de> Message-ID: <20d55af8-337e-40e4-bb05-39fedec02829@googlegroups.com> dieter? 2019?10?8???? UTC+8??1?33?20???? > jfong at ms4.hinet.net writes: > > ... > > But most of the download from Github has a directory named 'xxxx-master' which causes a trouble sometimes. > > Those are likely not meant to be imported directly. > > Typically, you have a "setup" step which installs (in some way) > a "distribution". This step usually ensures that you can use > "normal" Python import syntax to access all associated packages. > > The "setup" step is typically performed with > "python setup.py develop" or "python setup.py install" -- > with the "distribution" providing the "setup.py". Yes, I understand the normal procedure on using a package, but it's not always the case. --Jach From benjamin at python.org Tue Oct 8 21:29:39 2019 From: benjamin at python.org (Benjamin Peterson) Date: Tue, 08 Oct 2019 18:29:39 -0700 Subject: [RELEASE] Python 2.7.17 release candidate 1 Message-ID: <77a49d69-991b-4e01-b67b-165830b64a89@www.fastmail.com> The first release candidate of Python 2.7.17 is now available for download and testing. Python 2.7.17 includes 80 fixes over Python 2.7.16. Downloads may be found on python.org: https://www.python.org/downloads/release/python-2717rc1/ Read the full changelog at: https://raw.githubusercontent.com/python/cpython/1c7b14197b10924e2efc1e6c99c720958be1f681/Misc/NEWS.d/2.7.17rc1.rst As always with prereleases, please test your applications and libraries and report bugs to: https://bugs.python.org/ A final release is scheduled to follow in 12 days. PEP 373, the Python 2.7 release schedule, calls for 2.7.17 to be the penultimate bug fix release of the Python 2.7 series. Time for Python 2 is running low! Regards, Benjamin 2.7 release manager From PythonList at DancesWithMice.info Tue Oct 8 21:30:30 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 9 Oct 2019 14:30:30 +1300 Subject: How to handle '-' in the 'from' part in a "from import" statement? In-Reply-To: <20d55af8-337e-40e4-bb05-39fedec02829@googlegroups.com> References: <333d5f3a-6e77-4899-90aa-63ee3940be4c@googlegroups.com> <8e244a4d-7368-2419-14cc-aae22dc8a86a@DancesWithMice.info> <87h84jby49.fsf@handshake.de> <20d55af8-337e-40e4-bb05-39fedec02829@googlegroups.com> Message-ID: On 9/10/19 2:12 PM, jfong at ms4.hinet.net wrote: > dieter? 2019?10?8???? UTC+8??1?33?20???? >> jfong at ms4.hinet.net writes: >>> ... >>> But most of the download from Github has a directory named 'xxxx-master' which causes a trouble sometimes. >> >> Those are likely not meant to be imported directly. >> >> Typically, you have a "setup" step which installs (in some way) >> a "distribution". This step usually ensures that you can use >> "normal" Python import syntax to access all associated packages. >> >> The "setup" step is typically performed with >> "python setup.py develop" or "python setup.py install" -- >> with the "distribution" providing the "setup.py". > > Yes, I understand the normal procedure on using a package, but it's not always the case. I'm curious - if this is the correct way to do things, and the original author intends the package/module for you to download, why does (s)he choose to follow an non-Pythonic naming convention? Does this say something about the author? - something about his/her abilities in Python? - the Python-friendliness (or otherwise) of GitHub? (cf PyPi) -- Regards =dn From rosuav at gmail.com Tue Oct 8 21:46:19 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Oct 2019 12:46:19 +1100 Subject: How to handle '-' in the 'from' part in a "from import" statement? In-Reply-To: References: <333d5f3a-6e77-4899-90aa-63ee3940be4c@googlegroups.com> <8e244a4d-7368-2419-14cc-aae22dc8a86a@DancesWithMice.info> <87h84jby49.fsf@handshake.de> <20d55af8-337e-40e4-bb05-39fedec02829@googlegroups.com> Message-ID: On Wed, Oct 9, 2019 at 12:36 PM DL Neil via Python-list wrote: > > On 9/10/19 2:12 PM, jfong at ms4.hinet.net wrote: > > dieter? 2019?10?8???? UTC+8??1?33?20???? > >> jfong at ms4.hinet.net writes: > >>> ... > >>> But most of the download from Github has a directory named 'xxxx-master' which causes a trouble sometimes. > >> > >> Those are likely not meant to be imported directly. > >> > >> Typically, you have a "setup" step which installs (in some way) > >> a "distribution". This step usually ensures that you can use > >> "normal" Python import syntax to access all associated packages. > >> > >> The "setup" step is typically performed with > >> "python setup.py develop" or "python setup.py install" -- > >> with the "distribution" providing the "setup.py". > > > > Yes, I understand the normal procedure on using a package, but it's not always the case. > > I'm curious - if this is the correct way to do things, and the original > author intends the package/module for you to download, why does (s)he > choose to follow an non-Pythonic naming convention? > > Does this say something about the author? > - something about his/her abilities in Python? > - the Python-friendliness (or otherwise) of GitHub? (cf PyPi) > It looks like the OP asked GitHub for a zip download instead of doing what would be far more generally common: cloning the repository. (Or just using pip to install directly from GitHub, although not everyone knows that that's possible.) ChrisA From PythonList at DancesWithMice.info Tue Oct 8 21:55:19 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 9 Oct 2019 14:55:19 +1300 Subject: How to handle '-' in the 'from' part in a "from import" statement? In-Reply-To: References: <333d5f3a-6e77-4899-90aa-63ee3940be4c@googlegroups.com> <8e244a4d-7368-2419-14cc-aae22dc8a86a@DancesWithMice.info> <87h84jby49.fsf@handshake.de> <20d55af8-337e-40e4-bb05-39fedec02829@googlegroups.com> Message-ID: On 9/10/19 2:46 PM, Chris Angelico wrote: > On Wed, Oct 9, 2019 at 12:36 PM DL Neil via Python-list > wrote: ... > (Or just using pip to install directly from GitHub, although not > everyone knows that that's possible.) Come on, you just knew I was going to ask how... -- Regards =dn From rosuav at gmail.com Tue Oct 8 22:09:25 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Oct 2019 13:09:25 +1100 Subject: How to handle '-' in the 'from' part in a "from import" statement? In-Reply-To: References: <333d5f3a-6e77-4899-90aa-63ee3940be4c@googlegroups.com> <8e244a4d-7368-2419-14cc-aae22dc8a86a@DancesWithMice.info> <87h84jby49.fsf@handshake.de> <20d55af8-337e-40e4-bb05-39fedec02829@googlegroups.com> Message-ID: On Wed, Oct 9, 2019 at 12:56 PM DL Neil via Python-list wrote: > > On 9/10/19 2:46 PM, Chris Angelico wrote: > > On Wed, Oct 9, 2019 at 12:36 PM DL Neil via Python-list > > wrote: > ... > > > (Or just using pip to install directly from GitHub, although not > > everyone knows that that's possible.) > > Come on, you just knew I was going to ask how... > https://pip.pypa.io/en/stable/reference/pip_install/#git It should be as easy as: pip install git+https://github.com/USER/REPO There are lots of other options if you need them (eg "@branchname") but if you just want to grab the latest unversioned code, it should be that simple. ChrisA From jfong at ms4.hinet.net Tue Oct 8 23:34:07 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Tue, 8 Oct 2019 20:34:07 -0700 (PDT) Subject: How to handle '-' in the 'from' part in a "from import" statement? In-Reply-To: <333d5f3a-6e77-4899-90aa-63ee3940be4c@googlegroups.com> References: <333d5f3a-6e77-4899-90aa-63ee3940be4c@googlegroups.com> Message-ID: jf... at ms4.hinet.net? 2019?10?8???? UTC+8??10?45?36???? > For example: > from my-dir import test > > I know it can be solved by renaming, but any alternative? > > --Jach Maybe another (better?) solution is: import sys sys.path.append(r'my-dir') import test --Jach From PythonList at DancesWithMice.info Tue Oct 8 23:50:01 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 9 Oct 2019 16:50:01 +1300 Subject: How to handle '-' in the 'from' part in a "from import" statement? In-Reply-To: References: <333d5f3a-6e77-4899-90aa-63ee3940be4c@googlegroups.com> Message-ID: <53ac67d4-1796-6c48-025d-6cb12f260504@DancesWithMice.info> On 9/10/19 4:34 PM, jfong at ms4.hinet.net wrote: > jf... at ms4.hinet.net? 2019?10?8???? UTC+8??10?45?36???? >> For example: >> from my-dir import test >> >> I know it can be solved by renaming, but any alternative? >> >> --Jach > > Maybe another (better?) solution is: > import sys > sys.path.append(r'my-dir') > import test Another option might be to add a symlink* from the application's directory to wherever you've downloaded and expanded the GitHub .zip archive. * Linux terminology, other OpSys may use different. Both are somewhat unattractive (IMHO). -- Regards =dn From cs at cskk.id.au Wed Oct 9 00:08:55 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 9 Oct 2019 15:08:55 +1100 Subject: How to handle '-' in the 'from' part in a "from import" statement? In-Reply-To: <53ac67d4-1796-6c48-025d-6cb12f260504@DancesWithMice.info> References: <53ac67d4-1796-6c48-025d-6cb12f260504@DancesWithMice.info> Message-ID: <20191009040855.GA93452@cskk.homeip.net> On 09Oct2019 16:50, DL Neil wrote: >Another option might be to add a symlink* from the application's >directory to wherever you've downloaded and expanded the GitHub .zip >archive. I do this. A current project is using Spectra's ds3 Python library. The project itself has a directory for the additional source code beyond what comes from the venv, and that directory is in the sys.path. In the directory is a symlink to the specific vendor checkout of the ds3 library: ds3 -> ../../vendor/spectra/ds3_python3_sdk/ds3 So the project tree has: vendor/spectra/ds3_python3_sdk/ds3 where the vendor library is kept (from their github repo) and: lib/python containing the above symlink and the non-venv additional libraries (i.e. the project's own Python code as a package). The ...../lib/python path in in sys.path (from the environment's $PYTHONPATH). So the symlink thing is not unreasonable at all. Cheers, Cameron Simpson From dieter at handshake.de Wed Oct 9 00:52:07 2019 From: dieter at handshake.de (dieter) Date: Wed, 09 Oct 2019 06:52:07 +0200 Subject: WHY it compains about the missing argument is WHAT i don't understand References: <6598feed-924f-4c94-bcc4-189b86b5547b@googlegroups.com> Message-ID: <874l0i4j2g.fsf@handshake.de> ????? ?????? writes: > plugin = bottle_pymysql.Plugin( dbuser='user', dbpass='pass', dbname='counters', dictrows=False ) > app.install(plugin) > > ....... > ....... > > @app.route( '/' ) > @auth_basic( counters.is_authenticated_user ) > def listall( pymydb ): ^^^^^^^^ This declares `listall` to have one mandatory positional argument "pymydb". > But when i try to load the app's URL like http://superhost.gr/clientele as you can see i get this error: > > > Exception: > TypeError("listall() missing 1 required positional argument: 'pymydb'",) > Traceback: > Traceback (most recent call last): > File "/usr/lib/python3.6/site-packages/bottle.py", line 862, in _handle > return route.call(**args) > File "/usr/lib/python3.6/site-packages/bottle.py", line 1740, in wrapper > rv = callback(*a, **ka) > File "/usr/lib/python3.6/site-packages/bottle.py", line 2690, in wrapper > return func(*a, **ka) > TypeError: listall() missing 1 required positional argument: 'pymydb' This error indicates that `listall` is called by the `bottle` function wrapper without positional argument. > listall() is `/` route's callback function and i never inside my script i call listall( pymydb ). > Why it compains about the missing argument is WHAT i don't understand. Your definition of `listall` does not match the expectations of `bottle` with regard to this function. Reread the corresponding documentation and adapt your `listall`. From antoon.pardon at vub.be Wed Oct 9 06:50:52 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 9 Oct 2019 12:50:52 +0200 Subject: decorator needs access to variables where it is used. Message-ID: I have some logging utilities so that when I write library code, I just use the following. from logutil import Logger log = Logger(__name__) And from then on I just use log, to do the logging of that module. But now I would like to write a decorator trace, so that a decorated function would log, its arguments and result. Something like: def trace(func): def wrapper(*args): log(DEBUG, "=> %s%s" % (func.__name__, args)) result = func(*args) log(DEBUG, "%s => %s" (func.__name__, result)) return wrapper The problem is that with this decorater, the log function used, will be the log function defined where the decorator is written and I would prefer it to use the log function where it is used, so that it uses the same log function as the function it decorates. From rosuav at gmail.com Wed Oct 9 07:02:32 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Oct 2019 22:02:32 +1100 Subject: decorator needs access to variables where it is used. In-Reply-To: References: Message-ID: On Wed, Oct 9, 2019 at 9:53 PM Antoon Pardon wrote: > > I have some logging utilities so that when I write library code, I just use the following. > > from logutil import Logger > > log = Logger(__name__) Are you always absolutely consistent with this? Do you always have it as a module-level variable and always called "log", and you never use the name "log" for anything else? (Namespaced usage like "math.log" is fine, but you never have a function-local "log" or anything.) > And from then on I just use log, to do the logging of that module. > > But now I would like to write a decorator trace, so that a decorated > function would log, its arguments and result. > > Something like: > > def trace(func): > > def wrapper(*args): > log(DEBUG, "=> %s%s" % (func.__name__, args)) > result = func(*args) > log(DEBUG, "%s => %s" (func.__name__, result)) > > return wrapper > > The problem is that with this decorater, the log function > used, will be the log function defined where the decorator > is written and I would prefer it to use the log function > where it is used, so that it uses the same log function > as the function it decorates. > The decorator has full access to the function object, including a reference to that function's module globals. def trace(func): log = func.__globals__["log"] ... proceed as before As long as you can depend on "log" always being a module-level (global) name, and not (for instance) a closure variable, this should work. It's a bit ugly, but it should be fine since it's buried away in the decorator. ChrisA From __peter__ at web.de Wed Oct 9 07:52:47 2019 From: __peter__ at web.de (Peter Otten) Date: Wed, 09 Oct 2019 13:52:47 +0200 Subject: decorator needs access to variables where it is used. References: Message-ID: Antoon Pardon wrote: > I have some logging utilities so that when I write library code, I just > use the following. > > from logutil import Logger > > log = Logger(__name__) If logutil is under your control you can make log a callable object with a tracing method: [logutil.py] class Logger: def __call__(self, ...): # what log() currently does def traced(self, func): def trace(*args): self(DEBUG, "=> %s%s" % (func.__name__, args)) result = func(*args) self(DEBUG, "%s => %s" (func.__name__, result)) return result return trace [useit.py] from logutil import Logger log = Logger(__name__) @log.traced def some_func(...): ... But yes, Chris' suggestion is more straight-forward ;) > And from then on I just use log, to do the logging of that module. > > But now I would like to write a decorator trace, so that a decorated > function would log, its arguments and result. > > Something like: > > def trace(func): > > def wrapper(*args): > log(DEBUG, "=> %s%s" % (func.__name__, args)) > result = func(*args) > log(DEBUG, "%s => %s" (func.__name__, result)) > > return wrapper > > The problem is that with this decorater, the log function > used, will be the log function defined where the decorator > is written and I would prefer it to use the log function > where it is used, so that it uses the same log function > as the function it decorates. From scopensource at gmail.com Wed Oct 9 08:32:17 2019 From: scopensource at gmail.com (Simon Connah) Date: Wed, 9 Oct 2019 13:32:17 +0100 Subject: Would you be interested in this Python open source project? In-Reply-To: <10b13903-3f1e-87b8-4255-1303d943feda@kynesim.co.uk> References: <3645f1e6-08f6-5cad-a53e-764df7f865af@gmail.com> <10b13903-3f1e-87b8-4255-1303d943feda@kynesim.co.uk> Message-ID: <7d1fb615-35ce-258d-38e6-1d766e7aabe5@gmail.com> On 08/10/2019 13:17, Rhodri James wrote: > On 08/10/2019 11:22, Simon Connah wrote: >> I'm posting this message as a way to gauge interest in the project >> and to see if it is worth moving forward with. There are probably >> hundreds of CI/CD tools out there and many more general devops tools >> but what I want to build is a CI/CD tool that ONLY supports Python >> 3.6 or greater and only runs on one Linux distribution (my preference >> is Ubuntu). This way configuration would be much more simple than the >> vast majority of devops tools which try to support every programming >> language that is popular (or so it seems) on many different Linux >> distributions and even Windows and macOS. >> >> My theory is that if you limit the devops tool to a very limited >> subsection of the available options the system will be easier to >> configure for users, more stable, easier to patch bugs in and >> generally just be a better all around things for Python developers. >> >> I'd love to hear some feedback on the idea. >> > > I think your reasoning is sound.? I probably wouldn't make a lot of > use of it, but I live in Embedded Systems land where it's notoriously > hard to do CI off the target silicon.? Other people living in more > tractable problem spaces will probably be more enthusiastic. > Thank you for your reply. I'll keep working on this project and see how it turns out. I'm quite excited about it actually as I find that most CI/CD systems are so complicated when it comes to simple tasks. I want to build something where the developer spends 10 minutes reading the documentation and then can do 90% of what he needs with no more hand holding or Googling. From scopensource at gmail.com Wed Oct 9 08:34:08 2019 From: scopensource at gmail.com (Simon Connah) Date: Wed, 9 Oct 2019 13:34:08 +0100 Subject: Would you be interested in this Python open source project? In-Reply-To: References: <3645f1e6-08f6-5cad-a53e-764df7f865af@gmail.com> <10b13903-3f1e-87b8-4255-1303d943feda@kynesim.co.uk> Message-ID: <59774fac-6e7b-fa90-579f-1e1887d957f4@gmail.com> On 08/10/2019 15:05, Bill Deegan wrote: > You might just consider working with the BuildBot project to add support > for lighter weight build workers. > Re-Re-Re-inventing the wheel is almost always wasted effort. Buildbot looks good. I'll check to make sure its open source license is compatible with the Affero General Public License version 3. On the other hand I do have a desire to build something similar myself just to get the hang of things like this. Thank you for your reply. > On Tue, Oct 8, 2019 at 8:33 AM Rhodri James wrote: > >> On 08/10/2019 11:22, Simon Connah wrote: >>> I'm posting this message as a way to gauge interest in the project and >>> to see if it is worth moving forward with. There are probably hundreds >>> of CI/CD tools out there and many more general devops tools but what I >>> want to build is a CI/CD tool that ONLY supports Python 3.6 or greater >>> and only runs on one Linux distribution (my preference is Ubuntu). This >>> way configuration would be much more simple than the vast majority of >>> devops tools which try to support every programming language that is >>> popular (or so it seems) on many different Linux distributions and even >>> Windows and macOS. >>> >>> My theory is that if you limit the devops tool to a very limited >>> subsection of the available options the system will be easier to >>> configure for users, more stable, easier to patch bugs in and generally >>> just be a better all around things for Python developers. >>> >>> I'd love to hear some feedback on the idea. >>> >> I think your reasoning is sound. I probably wouldn't make a lot of use >> of it, but I live in Embedded Systems land where it's notoriously hard >> to do CI off the target silicon. Other people living in more tractable >> problem spaces will probably be more enthusiastic. >> >> -- >> Rhodri James *-* Kynesim Ltd >> -- >> https://mail.python.org/mailman/listinfo/python-list >> From info at wingware.com Wed Oct 9 08:45:14 2019 From: info at wingware.com (Wingware) Date: Wed, 09 Oct 2019 08:45:14 -0400 Subject: ANN: Wing Python IDE 7.1.2 has been released Message-ID: <5D9DD65A.2080009@wingware.com> Wing Python IDE version 7.1.2 has been released. It adds a How-To for using Wing with Docker, allows disabling code warnings from the tooltip displayed over the editor, adds support for macOS 10.15 (Catalina), supports code folding in JSON files, adds optional word wrapping for output in the Testing tool, and fixes about 25 minor usability issues. == Some Highlights of Wing 7.1 == * Support for Python 3.8: Wing 7.1 supports editing, testing, and debugging code written for Python 3.8, so you can take advantage of assignment expressions and other improvements introduced in this new version of Python. * Improved Code Warnings: Wing 7.1 adds unused symbol warnings for imports, variables, and arguments found in Python code. This release also improves code warnings configuration, making it easier to disable unwanted warnings. * Cosmetic Improvements: Wing 7.1 improves the auto-completer, project tool, and code browser with redesigned icons that make use of Wing's icon color configuration. This release also improves text display on some Linux systems, supports Dark Mode on macOS, and improves display of Python code and icons found in documentation. * And More: Wing 7.1 also adds a How-To for using Wing with Docker, the ability to disable code warnings from tooltips on the editor, support for macOS 10.15 (Catalina), code folding in JSON files, word wrapping for output in the Testing tool, support for Windows 10 native OpenSSH installations for remote development, and many minor improvements. This release drops support for macOS 10.11. System requirements remain unchanged on Windows and Linux. For details see the change log: https://wingware.com/pub/wingpro/7.1.2.0/CHANGELOG.txt For a complete list of new features in Wing 7, see What's New in Wing 7: https://wingware.com/wingide/whatsnew For general product information: https://wingware.com/ == Downloads == Wing Pro: https://wingware.com/downloads/wing-pro/7.1/binaries Wing Personal: https://wingware.com/downloads/wing-personal/7.1/binaries Wing 101: https://wingware.com/downloads/wing-101/7.1/binaries Compare Products: https://wingware.com/downloads See Upgrading https://wingware.com/doc/install/upgrading for details on upgrading from Wing 6 and earlier, and Migrating from Older Versions https://wingware.com/doc/install/migrating for a list of compatibility notes. From theology at gmail.com Tue Oct 8 18:43:32 2019 From: theology at gmail.com (Zeth) Date: Tue, 8 Oct 2019 23:43:32 +0100 Subject: Next Meeting: 9th November Message-ID: Hello all, We are rebooting the original Python user group, Python West Midlands, yay! Our first event is on Saturday 9th November 2019 in Birmingham city centre. The event is open to all levels, from never programmed before through to professional developers and Python core developers. Bring your laptop if you have one. We will have short Talks in the morning by some of the leading Python developers in the West Midlands followed by a collaborative project in the afternoon. The event is free but we require a RSVP at meetup.com here: https://www.meetup.com/pythonwm/events/264889992/ Knowing numbers makes it easier for us to organise things so get on with it! 10:00-16:00 (with optional pub dinner trip afterwards for the diehard fans). We have a space limit of 40 so please register at the meetup link above. Best Wishes from the PyWM team: Zeth, Dani and Steve From python at bdurham.com Wed Oct 9 12:34:22 2019 From: python at bdurham.com (Malcolm Greene) Date: Wed, 09 Oct 2019 10:34:22 -0600 Subject: =?UTF-8?Q?Python_3.6_on_Windows_-_does_a_python3_alias_get_created_by_in?= =?UTF-8?Q?stallation=3F?= Message-ID: <2e3f5255-dda5-416b-8403-b0777854227c@www.fastmail.com> I'm jumping between Linux, Mac and Windows environments. On Linux and Mac we can invoke Python via python3 but on Windows it appears that only python works. Interestingly, Windows supports both pip and pip3 flavors. Am I missing something? And yes, I know I can manually create a python3 alias by copying python.exe to python3.exe but that approach has its own set of nuances on locked down servers plus the hassle of keeping these python3 copies up-to-date across Python updates. Also curious: Do the Windows versions of Python 3.7 and 3.8 provide a python3 alias to start Python? Thanks! Malcolm From dan at djph.net Wed Oct 9 12:42:56 2019 From: dan at djph.net (Dan Purgert) Date: Wed, 9 Oct 2019 16:42:56 -0000 (UTC) Subject: Python 3.6 on Windows - does a python3 alias get created by installation? References: <2e3f5255-dda5-416b-8403-b0777854227c@www.fastmail.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Malcolm Greene wrote: > I'm jumping between Linux, Mac and Windows environments. On Linux and > Mac we can invoke Python via python3 but on Windows it appears that > only python works. Interestingly, Windows supports both pip and pip3 > flavors. Am I missing something? And yes, I know I can manually create > a python3 alias by copying python.exe to python3.exe but that approach > has its own set of nuances on locked down servers plus the hassle of > keeping these python3 copies up-to-date across Python updates. > > Also curious: Do the Windows versions of Python 3.7 and 3.8 provide a > python3 alias to start Python?. > > Thanks! > Malcolm Linux (and presumably Mac) just set "python" and "python3" as symlinks to various flavors of python2.x or 3.x. Setting up a couple of links / shortcuts should be equally possible on a windows box. -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEBcqaUD8uEzVNxUrujhHd8xJ5ooEFAl2eDg8ACgkQjhHd8xJ5 ooHYxggAsozJWO9OQtXApE0AeG9H1HW7y3cRUyXIX7OxrgnAKxusnPq5uiyZYFEs c1pYlwi1xkO2m0dDL9sB1BF3fOQn3h6HjH2jsdN5M/qTK4EiZ5sIiWXy/VyeN6Sf PzjLx8a8n4qt53yifKN7YBdnPIgyKLY1FSpyvpwc0hWndX70soapU2J4NJtNoIuj MxnKr3KJGynr5XemBiMWNtzv9bPWxPaA5kytaSzOXpVS8Dc7I9ToJe2Dtb/nNGDu nI3nYa3GnGGDN/HEaVbEq5Jq+oj7vtYiR9lUoqxn+Jes8D+Ga6Dg5zBvMQ3DTVac 53m4B9VaPop1mpm8Ba3mW/x2Cvp9nw== =yPoj -----END PGP SIGNATURE----- -- |_|O|_| |_|_|O| Github: https://github.com/dpurgert |O|O|O| PGP: 05CA 9A50 3F2E 1335 4DC5 4AEE 8E11 DDF3 1279 A281 From p.f.moore at gmail.com Wed Oct 9 12:48:05 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 9 Oct 2019 17:48:05 +0100 Subject: Python 3.6 on Windows - does a python3 alias get created by installation? In-Reply-To: <2e3f5255-dda5-416b-8403-b0777854227c@www.fastmail.com> References: <2e3f5255-dda5-416b-8403-b0777854227c@www.fastmail.com> Message-ID: No, the Windows builds do not provide versioned executables (python3.exe or python3.7.exe). Generally, the recommended way to launch Python on Windows is via the py.exe launcher (py -3.7, or just py for the default), but if you have Python on your PATH then python works. The reason pip has versioned executables is because that's how pip defines its entry points. It's cross-platform and unrelated to the conventions the Python core installers follow. Yes, it's all a bit confusing :-) Paul On Wed, 9 Oct 2019 at 17:37, Malcolm Greene wrote: > > I'm jumping between Linux, Mac and Windows environments. On Linux and Mac we can invoke Python via python3 but on Windows it appears that only python works. Interestingly, Windows supports both pip and pip3 flavors. Am I missing something? And yes, I know I can manually create a python3 alias by copying python.exe to python3.exe but that approach has its own set of nuances on locked down servers plus the hassle of keeping these python3 copies up-to-date across Python updates. > > Also curious: Do the Windows versions of Python 3.7 and 3.8 provide a python3 alias to start Python? > > Thanks! > Malcolm > -- > https://mail.python.org/mailman/listinfo/python-list From python at bdurham.com Wed Oct 9 13:14:29 2019 From: python at bdurham.com (Malcolm Greene) Date: Wed, 09 Oct 2019 11:14:29 -0600 Subject: =?UTF-8?Q?Re:_Python_3.6_on_Windows_-_does_a_python3_alias_get_created_b?= =?UTF-8?Q?y_installation=3F?= In-Reply-To: References: <2e3f5255-dda5-416b-8403-b0777854227c@www.fastmail.com> Message-ID: Thanks Paul and Dan. @Paul: Yes, it *IS* a bit confusing . Your pip explanation hit the spot. @Dan: Yes, symlinks would be a good work around. Malcolm From eryksun at gmail.com Wed Oct 9 17:07:20 2019 From: eryksun at gmail.com (Eryk Sun) Date: Wed, 9 Oct 2019 16:07:20 -0500 Subject: Python 3.6 on Windows - does a python3 alias get created by installation? In-Reply-To: References: <2e3f5255-dda5-416b-8403-b0777854227c@www.fastmail.com> Message-ID: On 10/9/19, Malcolm Greene wrote: > > @Dan: Yes, symlinks would be a good work around. Assuming the file system supports symlinks (e.g. NTFS, but not FAT32), a relative symlink in the directory beside python.exe works fine, e.g. "python3.exe" -> "python.exe". Putting the symlink in another directory will not work unless you also symlink "python36.dll", "python3.dll", and "vcruntime140.dll". The problem is that loader doesn't resolve the application directory as the final path, so these DLLs won't be found unless they're all symlinked together. Symlinks can be created via Python's os.symlink, CMD's mklink, or PowerShell's new-item with "SymbolicLink" as the ItemType and the target as its Value. Typically you need SeCreateSymbolicLinkPrivilege, which can be granted to you or one of your groups (e.g. the Authenticated Users group). When the privilege is obtained this way, an administrator doesn't have to elevate to create symlinks. If the target is in another directory, the better solution in Windows is a shell link (i.e. a ".lnk" file), aka a "shortcut". Shell links work via the Windows shell API ShellExecuteExW. Console shells such as CMD and PowerShell fall back on ShellexecuteExW if CreateProcessW fails. The simplest way to create a shell link is via the Windows GUI shell, Explorer. To inherit the working directory of the parent process, leave the link's "start in" field empty. Also, add ".LNK" to the system PATHEXT environment variable to allow finding link files without having to include the ".lnk" file extension, i.e. to be able to run "python3.lnk <...>" as just "python3 <...>". From antoon.pardon at vub.be Thu Oct 10 06:00:23 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 10 Oct 2019 12:00:23 +0200 Subject: decorator needs access to variables where it is used. In-Reply-To: References: Message-ID: <2e532860-cd17-7e10-1f15-660d43dee932@vub.be> On 9/10/19 13:02, Chris Angelico wrote: > On Wed, Oct 9, 2019 at 9:53 PM Antoon Pardon wrote: >> I have some logging utilities so that when I write library code, I just use the following. >> >> from logutil import Logger >> >> log = Logger(__name__) > Are you always absolutely consistent with this? Do you always have it > as a module-level variable and always called "log", and you never use > the name "log" for anything else? (Namespaced usage like "math.log" is > fine, but you never have a function-local "log" or anything.) I have been up to now, but I will take this under consideration when thinking about how to proceed. >> And from then on I just use log, to do the logging of that module. >> >> But now I would like to write a decorator trace, so that a decorated >> function would log, its arguments and result. >> >> Something like: >> >> def trace(func): >> >> def wrapper(*args): >> log(DEBUG, "=> %s%s" % (func.__name__, args)) >> result = func(*args) >> log(DEBUG, "%s => %s" (func.__name__, result)) >> >> return wrapper >> >> The problem is that with this decorater, the log function >> used, will be the log function defined where the decorator >> is written and I would prefer it to use the log function >> where it is used, so that it uses the same log function >> as the function it decorates. >> > The decorator has full access to the function object, including a > reference to that function's module globals. > > def trace(func): > log = func.__globals__["log"] > ... proceed as before > > As long as you can depend on "log" always being a module-level > (global) name, and not (for instance) a closure variable, this should > work. It's a bit ugly, but it should be fine since it's buried away in > the decorator. Nice idea, I can work with that. Antoon. From antoon.pardon at vub.be Thu Oct 10 06:23:46 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 10 Oct 2019 12:23:46 +0200 Subject: Curious about library inclusion Message-ID: I was wondering how likely it would be that piped-iterators like shown in http://code.activestate.com/recipes/580625-collection-pipeline-in-python/ would make it into a future python version. Once I started using them (and included some more) I found I really liked working with them. For instance I used to write the following a lot: for line in some_file: lst = line.strip().split(':') do_stuff(lst) Now I seem to drift into writing: for lst in some_file | Strip | Split(':'): do_stuff(lst) Where Strip and Split are defined as follows: Strip = Map(methodcaller('strip')) def Split(st): return Map(methodcaller('split', st)) I also found that Apply can be used as a decorator, that easily turns an iterator into a piped version. So what are the odds? -- Antoon. From antoon.pardon at vub.be Thu Oct 10 06:34:45 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 10 Oct 2019 12:34:45 +0200 Subject: Curious about library inclusion In-Reply-To: References: Message-ID: That seems to have been thoruoghly garbled so I start again. I was wondering how likely it would be that piped iterators like shown in http://code.activestate.com/recipes/580625-collection-pipeline-in-python/ would make it into a future python version/ Once I started using them (and included some more) I found I really liked using them. For instance I used to write the following a lot: for line in some_file: line = line.strip() lst = line.split(':') do_stuff(lst) Now I seem to drift into writing: for lst in some_file | Strip | Split(':'): do_stuff(lst) where Strip and Split are defined as follows: Strip = Map(methodcaller('strip')) def Split(st): return Map(methodcaller('split', st)) I also found that Apply can be used as a decorator, that easily turns a generator into a piped version. So what are the odds? -- Antoon. From p.f.moore at gmail.com Thu Oct 10 07:00:59 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 10 Oct 2019 12:00:59 +0100 Subject: Curious about library inclusion In-Reply-To: References: Message-ID: Probably low. There would need to be a clear justification as to why having the library in the stdlib (and hence tied to Python's release schedule for updates/bug fixes etc - which is typically a really severe limitation for a newish library) would be better than having it available as a 3rd party library on PyPI. It would also mean that it would only be available in Python 3.9+, unless a parallel backport module was maintained on PyPI, making the argument for inclusion in the stdlib even weaker. Basically, someone needs to explain the benefits of having *this* library in the stdlib, and demonstrate that they are compelling. (Generic arguments like "being in the stdlib means no need for a 3rd party dependency" don't count because they would apply to any library on PyPI equally...) That's a pretty high bar to reach. Not impossible, by any means, but it needs a lot more than "this is a neat library". As another measure, look at various other libraries on PyPI and ask yourself why *this* library needs to be in the stdlib more than those others. The answer to that question would be a good start for an argument to include the library. Paul On Thu, 10 Oct 2019 at 11:37, Antoon Pardon wrote: > > That seems to have been thoruoghly garbled so I start again. > > I was wondering how likely it would be that piped iterators like shown > in http://code.activestate.com/recipes/580625-collection-pipeline-in-python/ > would make it into a future python version/ Once I started using them > (and included some more) I found I really liked using them. For instance > I used to write the following a lot: for line in some_file: line = > line.strip() lst = line.split(':') do_stuff(lst) Now I seem to drift > into writing: for lst in some_file | Strip | Split(':'): do_stuff(lst) > where Strip and Split are defined as follows: Strip = > Map(methodcaller('strip')) def Split(st): return > Map(methodcaller('split', st)) I also found that Apply can be used as a > decorator, that easily turns a generator into a piped version. So what > are the odds? -- Antoon. > > -- > https://mail.python.org/mailman/listinfo/python-list From antoon.pardon at vub.be Thu Oct 10 07:40:37 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 10 Oct 2019 13:40:37 +0200 Subject: Curious about library inclusion In-Reply-To: References: Message-ID: <334de038-4319-f12f-e39b-c3161bf2ec4e@vub.be> About including piped iterators: http://code.activestate.com/recipes/580625-collection-pipeline-in-python/ On 10/10/19 13:00, Paul Moore wrote: > As another measure, look at various other libraries on PyPI and ask > yourself why *this* library needs to be in the stdlib more than those > others. The answer to that question would be a good start for an > argument to include the library. Well my answer would be that this library wouldn't add functionality but rather would allow IMO for a more readable coding style. If you split the work to be done over mulitple generators I find it easier to understand when I read something like: for item in some_file | gen1 | gen2 | gen3: ... than when I read something like: for item in gen3(gen2(gen1(somefile))): ... or than when I have to include the work in the for suite for line in somefile: tmp1 = fun1(line) tmp2 = fun2(tmp1) item = fun3(tmp2) ... or for line in somefile: item = fun3(fun2(fun1(line))) I also would include these in the itertools module instead of adding an extra module. -- Antoon. From phamp at mindspring.com Thu Oct 10 11:47:07 2019 From: phamp at mindspring.com (pyotr filipivich) Date: Thu, 10 Oct 2019 08:47:07 -0700 Subject: question about making an App for Android Message-ID: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> What I want is a "simple" program to calculate and display the "natural time", and do so on my phone. "A simple program" to divide the amount of "today's" daylight into 12 even '"hours", so that Dawn begins the First hour, the third hour is mid-morning, noon is the middle of the day, the ninth hour mid after noon, and the twelfth hour ends at sunset. Is simple, no? {no.} But getting from the development environment (the desktop) to the phone is something I am clueless about. Any clues on the matter? tschus pyotr -- APL is a mistake, carried through to perfection. It is the language of the future for the programming techniques of the past: it creates a new generation of coding bums. -- Edsger W. Dijkstra, SIGPLAN Notices, Volume 17, Number 5 From pankaj.jangid at gmail.com Thu Oct 10 03:21:26 2019 From: pankaj.jangid at gmail.com (Pankaj Jangid) Date: Thu, 10 Oct 2019 12:51:26 +0530 Subject: python -m pip install and pip install In-Reply-To: (Hongyi Zhao's message of "Tue, 8 Oct 2019 16:59:06 +0800") References: <20191008034801.GA77035@cskk.homeip.net> Message-ID: Hongyi Zhao writes: > Hongyi Zhao ?2019?10?8??? ??4:53??? >> >> Cameron Simpson ?2019?10?8??? ??12:25??? >> > >> > On 08Oct2019 02:49, Hongyi Zhao wrote: >> > >On Tue, 08 Oct 2019 06:28:05 +0530, Pankaj Jangid wrote: >> > >> A very good use-case is when you have both, python2 and python3 >> > >> installed. >> > >> python2 -m pip install mod >> > >> python3 -m pip install mod >> > >> will install the package in the corresponding PYTHONPATH. >> > >> >> > > >> > >If so, why not just: >> > >pip2 install mod >> > >and using: >> > >pip3 install mod >> > >> > Because of the slight disconnect between "pip2" and "python2", etc. Do >> > you _know_ they both use the same Python install? With "pythonX -m pip" >> > you're using the same python executable which will be accessing what you >> > just installed. >> >> I use pyenv + pip, which will do the trick. > > And nowadays, the pyenv + vurtualenv + pip + pipenv is the suggested > env management method for python. > In this way, the pipenv will solve the version dependence of the > underlying tool chain and corresponding used packages/modules. > Exactly. So the scripts will just work fine if you simply use ~import pip~ and work with it. Suppose you were writing bash scripts around python programs. Then what will be the behaviour of, pip2 install mod under a python3 environment. Similarly, there may be other commands specific to python2 and python3. All of them work flawlessly if you just replace python2 with python3. -- Regards, Pankaj Jangid From tjreedy at udel.edu Thu Oct 10 13:11:28 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 10 Oct 2019 13:11:28 -0400 Subject: question about making an App for Android In-Reply-To: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> References: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> Message-ID: On 10/10/2019 11:47 AM, pyotr filipivich wrote: > What I want is a "simple" program to calculate and display the > "natural time", and do so on my phone. > > "A simple program" to divide the amount of "today's" daylight into 12 > even '"hours", so that Dawn begins the First hour, the third hour is > mid-morning, noon is the middle of the day, the ninth hour mid after > noon, and the twelfth hour ends at sunset. Is simple, no? {no.} > > But getting from the development environment (the desktop) to the > phone is something I am clueless about. > > Any clues on the matter? Search "python android app" with Google. -- Terry Jan Reedy From torriem at gmail.com Thu Oct 10 13:51:54 2019 From: torriem at gmail.com (Michael Torrie) Date: Thu, 10 Oct 2019 11:51:54 -0600 Subject: question about making an App for Android In-Reply-To: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> References: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> Message-ID: <5a5e6c6d-33b4-1de3-a1bb-94c37e58b8b9@gmail.com> On 10/10/19 9:47 AM, pyotr filipivich wrote: > What I want is a "simple" program to calculate and display the > "natural time", and do so on my phone. > > "A simple program" to divide the amount of "today's" daylight into 12 > even '"hours", so that Dawn begins the First hour, the third hour is > mid-morning, noon is the middle of the day, the ninth hour mid after > noon, and the twelfth hour ends at sunset. Is simple, no? {no.} > > But getting from the development environment (the desktop) to the > phone is something I am clueless about. > > Any clues on the matter? As much as I like Python, it's probably easiest nor the best choice to make a simple app like this with a hybrid development toolkit. For example, the Qt5-based system called VPlay. Your app would be a simple UI file and a tiny bit of javascript to do the calculations. In the Python world, there's a project called Kivy that lets you build mobile Python-based applications. From torriem at gmail.com Thu Oct 10 13:54:33 2019 From: torriem at gmail.com (Michael Torrie) Date: Thu, 10 Oct 2019 11:54:33 -0600 Subject: python -m pip install and pip install In-Reply-To: References: <20191008034801.GA77035@cskk.homeip.net> Message-ID: <4c37d7ae-697a-cfea-70a9-4d5b1009529f@gmail.com> On 10/10/19 1:21 AM, Pankaj Jangid wrote: > So the scripts will just work fine if you simply use ~import pip~ > and work with it. > > Suppose you were writing bash scripts around python programs. Then > what will be the behaviour of, > > pip2 install mod > > under a python3 environment. If Python 2 wasn't installed, pip2 wouldn't be found at all. If Python 2 was available, it would happily install mod under the default/current Python 2 environment. > Similarly, there may be other commands specific to python2 and > python3. All of them work flawlessly if you just replace python2 with > python3. Not sure what you're getting at there. From rosuav at gmail.com Thu Oct 10 18:49:03 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Oct 2019 09:49:03 +1100 Subject: question about making an App for Android In-Reply-To: References: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> Message-ID: On Fri, Oct 11, 2019 at 9:41 AM Dennis Lee Bieber wrote: > > On Thu, 10 Oct 2019 08:47:07 -0700, pyotr filipivich > declaimed the following: > > > >"A simple program" to divide the amount of "today's" daylight into 12 > >even '"hours", so that Dawn begins the First hour, the third hour is > >mid-morning, noon is the middle of the day, the ninth hour mid after > >noon, and the twelfth hour ends at sunset. Is simple, no? {no.} > > > Even ignoring "phone" this is anything but simple. It relies upon > knowing one's latitude and date to allow computing the angle of the sun. > And you'll need to handle the fact that above/below arctic/antarctic > circles you will run into "zeros" where there is either 24 hours of > daylight or 24 hours of night. > Or.... maybe it's really simple, because there's an HTTP API that gives you the information. There's an API for everything these days. A quick web search showed up this: https://sunrise-sunset.org/api Which means the project is a matter of taking the data and formatting it. (Also probably getting lat/long from the phone's location API.) I'd say this is a good-fun project - a one-week project for a student, a weekend project for an expert. And yes, there WILL be edge cases to deal with, but for the most part, it shouldn't be too hard. ChrisA From phamp at mindspring.com Thu Oct 10 19:30:32 2019 From: phamp at mindspring.com (pyotr filipivich) Date: Thu, 10 Oct 2019 16:30:32 -0700 Subject: question about making an App for Android References: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> Message-ID: <4jfvpeh59k193u0anp4rqiesamutpe5t8f@4ax.com> Dennis Lee Bieber on Thu, 10 Oct 2019 18:39:55 -0400 typed in comp.lang.python the following: >On Thu, 10 Oct 2019 08:47:07 -0700, pyotr filipivich >declaimed the following: > > >>"A simple program" to divide the amount of "today's" daylight into 12 >>even '"hours", so that Dawn begins the First hour, the third hour is >>mid-morning, noon is the middle of the day, the ninth hour mid after >>noon, and the twelfth hour ends at sunset. Is simple, no? {no.} >> > Even ignoring "phone" this is anything but simple. Which is why it was in quote marks. Yes, it is a simple concept, it is the bloody implementation which gets complex. > It relies upon >knowing one's latitude and date to allow computing the angle of the sun. >And you'll need to handle the fact that above/below arctic/antarctic >circles you will run into "zeros" where there is either 24 hours of >daylight or 24 hours of night. I figure to initially set it for 48 degrees north, which will be close enough for my purposes. > > Properly speaking, "transit" (noon) may NOT be midway between rising >and setting. > >Astronomical Formulae for Calculators (4th Ed, Jean Meeus, 1988 >Willmann-Bell) > Chapter 21 Equation of Time > Chapter 41 Ephemeris for Physical Observations of the Sun > Chapter 42 Rising, Transit, and Setting > >Astronomy With Your Personal Computer (2nd Ed, Petter Duffett-Smith, 1990 >Cambridge University Press) (Chapters are named by BASIC subroutine) > RISET for rising and setting time > SUN (maybe of use) > SUNRS for civil time sunrise/sunset, along with beginning/end of >civil, nautical, and astronomical twilight. > >Practical Astronomy with your Calculator or Spreadsheet (4th Ed, P. >Duffett-Smith & J. Zwart, 1989 Cambridge University Press) > Chapter 49 Sunrise and Sunset > Chapter 50 Twilight > Chapter 41 The Equation of Time > > > The phone GPS services, if available, may provide the local latitude to >the application. > >>But getting from the development environment (the desktop) to the >>phone is something I am clueless about. >> > > Getting anything that is not written in Java onto an Android phone is >likely going to be a pain. You will most likely need an environment that >runs on ARM architecture. And I have no idea what iOS requires. Thanks. Not necessarily what I wanted to hear, but what I did need to hear. -- pyotr filipivich Next month's Panel: Graft - Boon or blessing? From phamp at mindspring.com Thu Oct 10 19:34:43 2019 From: phamp at mindspring.com (pyotr filipivich) Date: Thu, 10 Oct 2019 16:34:43 -0700 Subject: question about making an App for Android References: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> Message-ID: Chris Angelico on Fri, 11 Oct 2019 09:49:03 +1100 typed in comp.lang.python the following: >On Fri, Oct 11, 2019 at 9:41 AM Dennis Lee Bieber wrote: >> >> On Thu, 10 Oct 2019 08:47:07 -0700, pyotr filipivich >> declaimed the following: >> >"A simple program" to divide the amount of "today's" daylight into 12 >> >even '"hours", so that Dawn begins the First hour, the third hour is >> >mid-morning, noon is the middle of the day, the ninth hour mid after >> >noon, and the twelfth hour ends at sunset. Is simple, no? {no.} >> > >> Even ignoring "phone" this is anything but simple. It relies upon >> knowing one's latitude and date to allow computing the angle of the sun. >> And you'll need to handle the fact that above/below arctic/antarctic >> circles you will run into "zeros" where there is either 24 hours of >> daylight or 24 hours of night. >> > >Or.... maybe it's really simple, because there's an HTTP API that >gives you the information. There's an API for everything these days. A >quick web search showed up this: > >https://sunrise-sunset.org/api Thanks. > >Which means the project is a matter of taking the data and formatting >it. (Also probably getting lat/long from the phone's location API.) >I'd say this is a good-fun project - a one-week project for a student, >a weekend project for an expert. And yes, there WILL be edge cases to >deal with, but for the most part, it shouldn't be too hard. A one week project for a student. or Longer for a non-student. Oh well, as I say a lot: this wild be easy if I was doing it forty hours a week. And this part is a spin off of a larger mess, trying to understand how astronomy was done before the invention of mechanical clocks. I get some off the wall inspirations. -- pyotr filipivich Next month's Panel: Graft - Boon or blessing? From rosuav at gmail.com Thu Oct 10 19:43:53 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Oct 2019 10:43:53 +1100 Subject: question about making an App for Android In-Reply-To: References: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> Message-ID: On Fri, Oct 11, 2019 at 10:40 AM pyotr filipivich wrote: > > Chris Angelico on Fri, 11 Oct 2019 09:49:03 +1100 > typed in comp.lang.python the following: > >On Fri, Oct 11, 2019 at 9:41 AM Dennis Lee Bieber wrote: > >> > >> On Thu, 10 Oct 2019 08:47:07 -0700, pyotr filipivich > >> declaimed the following: > >> >"A simple program" to divide the amount of "today's" daylight into 12 > >> >even '"hours", so that Dawn begins the First hour, the third hour is > >> >mid-morning, noon is the middle of the day, the ninth hour mid after > >> >noon, and the twelfth hour ends at sunset. Is simple, no? {no.} > >> > > >> Even ignoring "phone" this is anything but simple. It relies upon > >> knowing one's latitude and date to allow computing the angle of the sun. > >> And you'll need to handle the fact that above/below arctic/antarctic > >> circles you will run into "zeros" where there is either 24 hours of > >> daylight or 24 hours of night. > >> > > > >Or.... maybe it's really simple, because there's an HTTP API that > >gives you the information. There's an API for everything these days. A > >quick web search showed up this: > > > >https://sunrise-sunset.org/api > > Thanks. > > > >Which means the project is a matter of taking the data and formatting > >it. (Also probably getting lat/long from the phone's location API.) > >I'd say this is a good-fun project - a one-week project for a student, > >a weekend project for an expert. And yes, there WILL be edge cases to > >deal with, but for the most part, it shouldn't be too hard. > > A one week project for a student. or Longer for a non-student. > > Oh well, as I say a lot: this wild be easy if I was doing it forty > hours a week. And this part is a spin off of a larger mess, trying to > understand how astronomy was done before the invention of mechanical > clocks. I get some off the wall inspirations. Sure, you can gauge your own skill level to get some idea of an actual timeframe. I'd recommend starting with a simple non-phone version of the idea, and then think about porting it to a phone. That should reduce the problem's complexity significantly. ChrisA From pankaj.jangid at gmail.com Thu Oct 10 23:08:09 2019 From: pankaj.jangid at gmail.com (Pankaj Jangid) Date: Fri, 11 Oct 2019 08:38:09 +0530 Subject: python -m pip install and pip install References: <20191008034801.GA77035@cskk.homeip.net> <4c37d7ae-697a-cfea-70a9-4d5b1009529f@gmail.com> Message-ID: Michael Torrie writes: > On 10/10/19 1:21 AM, Pankaj Jangid wrote: >> So the scripts will just work fine if you simply use ~import pip~ >> and work with it. >> >> Suppose you were writing bash scripts around python programs. Then >> what will be the behaviour of, >> >> pip2 install mod >> >> under a python3 environment. > > If Python 2 wasn't installed, pip2 wouldn't be found at all. If Python 2 > was available, it would happily install mod under the default/current > Python 2 environment. > I am talking about environments where both python2 and python3 installed. >> Similarly, there may be other commands specific to python2 and >> python3. All of them work flawlessly if you just replace python2 with >> python3. > > Not sure what you're getting at there. I am just trying to think about scenarios where one approach is better than other. Nothing more. -- Pankaj Jangid From uri at speedy.net Fri Oct 11 00:35:23 2019 From: uri at speedy.net (=?UTF-8?B?15DXldeo15k=?=) Date: Fri, 11 Oct 2019 07:35:23 +0300 Subject: python -m pip install and pip install In-Reply-To: References: Message-ID: When you upgrade pip, you have to write: python -m pip install --upgrade pip When you install or upgrade anything else, you can write "pip install". You can't upgrade pip using "pip install --upgrade pip". ???? uri at speedy.net On Mon, Oct 7, 2019 at 2:21 PM Hongyi Zhao wrote: > Hi, > > What's the diff: > > python -m pip install mod > and > pip install mod > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Fri Oct 11 01:16:56 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Oct 2019 16:16:56 +1100 Subject: python -m pip install and pip install In-Reply-To: References: Message-ID: ?On Fri, Oct 11, 2019 at 3:37 PM ??????? wrote:? > > When you upgrade pip, you have to write: > > python -m pip install --upgrade pip > > When you install or upgrade anything else, you can write "pip install". > > You can't upgrade pip using "pip install --upgrade pip". > Only a consideration on Windows. Other platforms are absolutely fine upgrading pip either way. ChrisA From pankaj.jangid at gmail.com Fri Oct 11 03:32:26 2019 From: pankaj.jangid at gmail.com (Pankaj Jangid) Date: Fri, 11 Oct 2019 13:02:26 +0530 Subject: python -m pip install and pip install In-Reply-To: (Chris Angelico's message of "Fri, 11 Oct 2019 16:16:56 +1100") References: Message-ID: Chris Angelico writes: > ?On Fri, Oct 11, 2019 at 3:37 PM ??????? wrote:? >> >> When you upgrade pip, you have to write: >> >> python -m pip install --upgrade pip >> >> When you install or upgrade anything else, you can write "pip install". >> >> You can't upgrade pip using "pip install --upgrade pip". >> > > Only a consideration on Windows. Other platforms are absolutely fine > upgrading pip either way. > Oh! I wasn't aware of this Windows thing. Thanks. -- Pankaj Jangid From prabakaranbigdata at gmail.com Fri Oct 11 06:27:23 2019 From: prabakaranbigdata at gmail.com (prabakaranbigdata at gmail.com) Date: Fri, 11 Oct 2019 03:27:23 -0700 (PDT) Subject: Error: thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable t Message-ID: <36ed0fc8-508c-4a4a-8424-0b5e5916c0cb@googlegroups.com> python> conn = hive.Connection(host="xx.xx.xxx.xxx",port=8889,username='hadoop') C:\Users\Nova15>python Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from pyhive import hive >>> conn = hive.Connection(host="54.169.219.144",port=8889,username='hadoop') Traceback (most recent call last): File "", line 1, in File "c:\users\nova15\appdata\local\programs\python\python37\lib\site-packages\pyhive\hive.py", line 192, in __init__ self._transport.open() File "c:\users\nova15\appdata\local\programs\python\python37\lib\site-packages\thrift_sasl\__init__.py", line 79, in open message=("Could not start SASL: %s" % self.sasl.getError())) thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2' I am trying to connect from windows 10 local to Prestodb in AWS. From specially at processed.almost.meat Fri Oct 11 08:46:10 2019 From: specially at processed.almost.meat (Roy Hann) Date: Fri, 11 Oct 2019 12:46:10 +0000 (UTC) Subject: Suppress tooltips in Pygal charts Message-ID: Following up on Elijah's suggestion responding to my earlier question about drawing gauges in a mobile (i.e. not normally internet connected) application on a Raspberry Pi I am using Pygal and rendering to SVG. I have found no way to stop Pygal from generating SVG that downloads and invokes JavaScript for various roll-over effects like tooltips. Happily the requests to download JS fail fast and silent when there is no network connection so it is sorta-kinda usable. I am worried however about when I do have a mobile data connection enabled. I don't need the tooltips and I don't want the risk of mobile data charges. Is there any way to tell Pygal not to generate references to on-line resources? Roy From rhodri at kynesim.co.uk Fri Oct 11 09:54:40 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 11 Oct 2019 14:54:40 +0100 Subject: Error: thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable t In-Reply-To: <36ed0fc8-508c-4a4a-8424-0b5e5916c0cb@googlegroups.com> References: <36ed0fc8-508c-4a4a-8424-0b5e5916c0cb@googlegroups.com> Message-ID: <1a687db1-d466-192f-4ce0-3d1745569685@kynesim.co.uk> On 11/10/2019 11:27, prabakaranbigdata at gmail.com wrote: > python> conn = hive.Connection(host="xx.xx.xxx.xxx",port=8889,username='hadoop') > > C:\Users\Nova15>python > Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> from pyhive import hive >>>> conn = hive.Connection(host="54.169.219.144",port=8889,username='hadoop') > Traceback (most recent call last): > File "", line 1, in > File "c:\users\nova15\appdata\local\programs\python\python37\lib\site-packages\pyhive\hive.py", line 192, in __init__ > self._transport.open() > File "c:\users\nova15\appdata\local\programs\python\python37\lib\site-packages\thrift_sasl\__init__.py", line 79, in open > message=("Could not start SASL: %s" % self.sasl.getError())) > thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2' > > > I am trying to connect from windows 10 local to Prestodb in AWS. > There is an open issue about this on the PyHive GitHub: https://github.com/dropbox/PyHive/issues/161 -- Rhodri James *-* Kynesim Ltd From prabakaranbigdata at gmail.com Fri Oct 11 10:13:00 2019 From: prabakaranbigdata at gmail.com (Prabakaran Hadoop) Date: Fri, 11 Oct 2019 07:13:00 -0700 (PDT) Subject: Error: thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable t In-Reply-To: References: <36ed0fc8-508c-4a4a-8424-0b5e5916c0cb@googlegroups.com> <1a687db1-d466-192f-4ce0-3d1745569685@kynesim.co.uk> Message-ID: <3d8d3163-7cac-4d8d-91fd-a81ca26beeb3@googlegroups.com> > Rhodri James *-* Kynesim Ltd Thanks for your reply. Any work around or any other way to achieve from python to prestosql . From rhodri at kynesim.co.uk Fri Oct 11 09:48:32 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 11 Oct 2019 14:48:32 +0100 Subject: Curious about library inclusion In-Reply-To: <334de038-4319-f12f-e39b-c3161bf2ec4e@vub.be> References: <334de038-4319-f12f-e39b-c3161bf2ec4e@vub.be> Message-ID: <63ff2313-04ec-82ab-eaa6-b2c581024e17@kynesim.co.uk> On 10/10/2019 12:40, Antoon Pardon wrote: > About including piped iterators: > http://code.activestate.com/recipes/580625-collection-pipeline-in-python/ > > On 10/10/19 13:00, Paul Moore wrote: >> As another measure, look at various other libraries on PyPI and ask >> yourself why *this* library needs to be in the stdlib more than those >> others. The answer to that question would be a good start for an >> argument to include the library. > > Well my answer would be that this library wouldn't add functionality > but rather would allow IMO for a more readable coding style. > > If you split the work to be done over mulitple generators I find it > easier to understand when I read something like: > > for item in some_file | gen1 | gen2 | gen3: > ... > > than when I read something like: > > for item in gen3(gen2(gen1(somefile))): > ... With my ever-so-reactionary hat on, I have to say I'm the other way round. With "gen3(gen2(gen1(somefile)))" it's pretty obvious what's going on -- nested function or generator calls, probably the latter from the name. With "somefile|gen1|gen2|gen3" I need more context to kick my expectations out of the more common meaning of "|" as "or". Yes, context demands that the "|" in your first example can't actually be an "or". It still causes a moment of logical disconnect (currently a long moment) that throws me out of understanding what your code is doing overall into what this line means in particular. It's exactly like coming across an unusual phrasing or iffy grammar in a piece of writing; you get thrown out of the reading experience by having to concentrate on the individual words. Heh. Literary criticism as applied to programming. Only in Python... -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Fri Oct 11 10:48:47 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 11 Oct 2019 15:48:47 +0100 Subject: Error: thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable t In-Reply-To: <3d8d3163-7cac-4d8d-91fd-a81ca26beeb3@googlegroups.com> References: <36ed0fc8-508c-4a4a-8424-0b5e5916c0cb@googlegroups.com> <1a687db1-d466-192f-4ce0-3d1745569685@kynesim.co.uk> <3d8d3163-7cac-4d8d-91fd-a81ca26beeb3@googlegroups.com> Message-ID: <67558978-a6da-8c45-e251-501f17406556@kynesim.co.uk> On 11/10/2019 15:13, Prabakaran Hadoop wrote: > Thanks for your reply. Any work around or any other way to achieve from python to prestosql . If there is, it'll be in the GitHub issue I linked to. I just applied Google to your question. -- Rhodri James *-* Kynesim Ltd From phamp at mindspring.com Fri Oct 11 12:18:00 2019 From: phamp at mindspring.com (pyotr filipivich) Date: Fri, 11 Oct 2019 09:18:00 -0700 Subject: question about making an App for Android References: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> Message-ID: Chris Angelico on Fri, 11 Oct 2019 10:43:53 +1100 typed in comp.lang.python the following: >On Fri, Oct 11, 2019 at 10:40 AM pyotr filipivich wrote: >> Chris Angelico on Fri, 11 Oct 2019 09:49:03 +1100 >> typed in comp.lang.python the following: >> >On Fri, Oct 11, 2019 at 9:41 AM Dennis Lee Bieber wrote: >> >> On Thu, 10 Oct 2019 08:47:07 -0700, pyotr filipivich >> >> declaimed the following: >> >> >"A simple program" to divide the amount of "today's" daylight into 12 >> >> >even '"hours", so that Dawn begins the First hour, the third hour is >> >> >mid-morning, noon is the middle of the day, the ninth hour mid after >> >> >noon, and the twelfth hour ends at sunset. Is simple, no? {no.} >> >> Even ignoring "phone" this is anything but simple. It relies upon >> >> knowing one's latitude and date to allow computing the angle of the sun. >> >> And you'll need to handle the fact that above/below arctic/antarctic >> >> circles you will run into "zeros" where there is either 24 hours of >> >> daylight or 24 hours of night. >> >Or.... maybe it's really simple, because there's an HTTP API that >> >gives you the information. There's an API for everything these days. A >> >quick web search showed up this: >> >https://sunrise-sunset.org/api >> Thanks. >> >Which means the project is a matter of taking the data and formatting >> >it. (Also probably getting lat/long from the phone's location API.) >> >I'd say this is a good-fun project - a one-week project for a student, >> >a weekend project for an expert. And yes, there WILL be edge cases to >> >deal with, but for the most part, it shouldn't be too hard. >> A one week project for a student. or Longer for a non-student. >> Oh well, as I say a lot: this wild be easy if I was doing it forty >> hours a week. And this part is a spin off of a larger mess, trying to >> understand how astronomy was done before the invention of mechanical >> clocks. I get some off the wall inspirations. > >Sure, you can gauge your own skill level to get some idea of an actual >timeframe. The programming skills have grown rusty. > >I'd recommend starting with a simple non-phone version of the idea, >and then think about porting it to a phone. That should reduce the >problem's complexity significantly. Or I could just "cheat" and make a mechanical clock which does the same thing. Maybe not as elaborate as the Japanese Myriad Year clock. Something along the lines of what Masahiro Kikuno did with his wristwatch. (18 million Yen, custom fitted to your latitude.) but adapted for "western" hours. The making is "easy", it is the engineering which is hard. -- pyotr filipivich Next month's Panel: Graft - Boon or blessing? From akkana at shallowsky.com Fri Oct 11 13:01:13 2019 From: akkana at shallowsky.com (Akkana Peck) Date: Fri, 11 Oct 2019 11:01:13 -0600 Subject: question about making an App for Android In-Reply-To: References: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> Message-ID: <20191011170113.GB21037@shallowsky.com> > pyotr filipivich > >"A simple program" to divide the amount of "today's" daylight into 12 > >even '"hours", so that Dawn begins the First hour, the third hour is > >mid-morning, noon is the middle of the day, the ninth hour mid after > >noon, and the twelfth hour ends at sunset. Is simple, no? {no.} Dennis Lee Bieber writes: > Even ignoring "phone" this is anything but simple. It relies upon > knowing one's latitude and date to allow computing the angle of the sun. [Details of some excellent references -- I like Duffett-Smith's calculator book best for readability). But if you don't need it to be a phone app, if you use PyEphem, it's all simple and you don't need to know any of the equations behind it. So it really depends on your goals and what you want to learn. > >But getting from the development environment (the desktop) to the > >phone is something I am clueless about. > > Getting anything that is not written in Java onto an Android phone is > likely going to be a pain. You will most likely need an environment that > runs on ARM architecture. And I have no idea what iOS requires. For an app with a relatively simple user interface, you can write a web page in HTML/Javascript and make it installable on both Android and iOS. Google "Progressive Web App" for details. Although it means you can't use Python (alas!), it's *much* simpler than dealing with either an Android Java devkit or a cross-platform setup like Kivy. I've used PWAs for simple astronomy programs like showing Jupiter's or Saturn's moons. ...Akkana From toby at tobiah.org Fri Oct 11 13:56:32 2019 From: toby at tobiah.org (Tobiah) Date: Fri, 11 Oct 2019 10:56:32 -0700 Subject: Odd delays when cwd is on a network mount Message-ID: I have a directory mounted with sshfs over a 5mb connection. It's quite usable under most circumstances. When I run python from a directory under that mount, imports from local directories are quite slow: $ python2.7 >>> import my_module ## takes 25 seconds to complete >>> my_module.__file__ >>> /local/dir/not/on/mount/my_module.py When I do the same thing from my home directory there is no delay. $ wc -l /local/dir/not/on/mount/my_module.py 156 /local/dir/not/on/mount/my_module.py Thanks for any help. Tobiah From toby at tobiah.org Fri Oct 11 14:06:26 2019 From: toby at tobiah.org (Tobiah) Date: Fri, 11 Oct 2019 11:06:26 -0700 Subject: Odd delays when cwd is on a network mount References: Message-ID: On 10/11/19 10:56 AM, Tobiah wrote: > I have a directory mounted with sshfs over a 5mb connection. > It's quite usable under most circumstances. > > When I run python from a directory under that mount, imports from local > directories are quite slow: > > $ python2.7 >>>> import my_module ## takes 25 seconds to complete >>>> my_module.__file__ >>>> /local/dir/not/on/mount/my_module.py > > When I do the same thing from my home directory > there is no delay. > > $ wc -l /local/dir/not/on/mount/my_module.py > 156 /local/dir/not/on/mount/my_module.py > > Thanks for any help. > > > Tobiah > > > Another way: $ cd ~ $ python2.7 >>> import os >>> os.chdir('/remote/mount/point') >>> import my_module ## 25 seconds again >>>> my_module.__file__ >>>> /local/dir/not/on/mount/my_module.py Without the os.chdir() the import is instantaneous. From jelphick at onetechnologies.net Fri Oct 11 12:02:40 2019 From: jelphick at onetechnologies.net (Jim Elphick) Date: Fri, 11 Oct 2019 16:02:40 +0000 Subject: 3.7.4 (latest) install changes python to py and removes pip support Message-ID: I upgraded my Python 3.7.3 windows install to 3.7.4 using the windows download from python.org. After the install, the keyword "python" will no longer invoke python. "python3" also fails. "py" is now the only access to python. py -version returns Python 3.7.4 python -version returns the following. The first is bash. The second is from powershell bash: python: command not found python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. Previous to the upgrade, "python -version" returned 3.7.3. This is much more than an inconvenience. Pip has stopped working because it expects to find "python.exe". pipenv also no longer executes. Pip -version returns (second is again powershell) nothing in bash (empty string, no error) Fatal error in launcher: Unable to create process using '"c:\program files\python37\python.exe" Attempting to re-install pip from python fails to help. I used the installer to completely remove python 3.7.4. My version reverted to 3.6.6. However, the problem with "py" instead of "python" persists. Attempting to re-install pip (using 3.6.6) through "py -m pip install pip" claims "Requirement already satisfied". But, pip continues to fail. 3.6.6 was also installed using download from python.org. So ... I attempted to re-install 3.7.3 downloaded from python.org. All of the above continues. "python" is no longer available. And pip is no longer available. c:\program files\python37\python.exe does not exist. Also, py.exe does not exist in that directory. I had a similar problem with my MacOS install, but I did not lose access to pip and pipenv. Any help would be appreciated for restoring my python 3.7 install. Thank you for any help you can provide. Jim From jelphick at onetechnologies.net Fri Oct 11 12:49:55 2019 From: jelphick at onetechnologies.net (Jim Elphick) Date: Fri, 11 Oct 2019 16:49:55 +0000 Subject: 3.7.4 (latest) install changes python to py and removes pip support In-Reply-To: References: Message-ID: Follow up to previous email. I was able to get a working version of python 3.7.4 on Windows. Steps to resolve: 1. Uninstalled Python Launcher from my Windows machine 2. Uninstalled Python 3.7.3 ( many uninstalls and re-installs) 3. Deleted Python37 folder 4. Using python installer from python.org, reinstalled using Custom 5. Deselected PythonLauncher (i.e. do NOT install Python Launcher). Kept all other options. Now "python -version" returns python 3.7.4. And, importantly, I am able to access and upgrade pip and pipenv. Pip still threw an error when I attempted to upgrade to pip 19.2.3, but it actually installed it successfully. Pipenv upgraded with no issue. Python is back! Thank you. Jim From: Jim Elphick Sent: Friday, October 11, 2019 11:03 AM To: python-list at python.org Subject: 3.7.4 (latest) install changes python to py and removes pip support I upgraded my Python 3.7.3 windows install to 3.7.4 using the windows download from python.org. After the install, the keyword "python" will no longer invoke python. "python3" also fails. "py" is now the only access to python. py -version returns Python 3.7.4 python -version returns the following. The first is bash. The second is from powershell bash: python: command not found python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. Previous to the upgrade, "python -version" returned 3.7.3. This is much more than an inconvenience. Pip has stopped working because it expects to find "python.exe". pipenv also no longer executes. Pip -version returns (second is again powershell) nothing in bash (empty string, no error) Fatal error in launcher: Unable to create process using '"c:\program files\python37\python.exe" Attempting to re-install pip from python fails to help. I used the installer to completely remove python 3.7.4. My version reverted to 3.6.6. However, the problem with "py" instead of "python" persists. Attempting to re-install pip (using 3.6.6) through "py -m pip install pip" claims "Requirement already satisfied". But, pip continues to fail. 3.6.6 was also installed using download from python.org. So ... I attempted to re-install 3.7.3 downloaded from python.org. All of the above continues. "python" is no longer available. And pip is no longer available. c:\program files\python37\python.exe does not exist. Also, py.exe does not exist in that directory. I had a similar problem with my MacOS install, but I did not lose access to pip and pipenv. Any help would be appreciated for restoring my python 3.7 install. Thank you for any help you can provide. Jim From * at eli.users.panix.com Fri Oct 11 14:44:31 2019 From: * at eli.users.panix.com (Eli the Bearded) Date: Fri, 11 Oct 2019 18:44:31 +0000 (UTC) Subject: question about making an App for Android References: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> Message-ID: In comp.lang.python, Dennis Lee Bieber wrote: > pyotr filipivich declaimed the following: >> "A simple program" to divide the amount of "today's" daylight into 12 >> even '"hours", so that Dawn begins the First hour, the third hour is >> mid-morning, noon is the middle of the day, the ninth hour mid after >> noon, and the twelfth hour ends at sunset. Is simple, no? {no.} How antique. > Even ignoring "phone" this is anything but simple. It relies upon > knowing one's latitude and date to allow computing the angle of the sun. That sounds like one "hard" input, one easy input, and a bunch of already solved math. >> But getting from the development environment (the desktop) to the >> phone is something I am clueless about. > Getting anything that is not written in Java onto an Android phone is > likely going to be a pain. You will most likely need an environment that > runs on ARM architecture. And I have no idea what iOS requires. Running Python on Android is trivial. Install Termux: https://f-droid.org/en/packages/com.termux/ (Or via Google's app store.) Run Termux then type: pkg up pkg install python To read GPS directly from Termux, you'll need Termux:Api which has an app part and a package part: https://f-droid.org/en/packages/com.termux.api/ pkg install termux-api Then use the shell command `termux-location -p gps -f last` (or `-f once`) to get location. To get the python onto the phone you may wish to install curl or wget or git and use them to fetch over the network. For output you could show text in termux or compose a PNG and use `termux-wallpaper -f`. I, myself, have just gotten "cron" like functionality in Termux with Tasker and the Termux:Task plugin. Every five minutes Tasker runs a shell script that collects data (`termux-sensor`), simplifies the JSON output (`|jq`) and writes it to a file on my phone. https://f-droid.org/en/packages/com.termux.tasker/ https://tasker.joaoapps.com/ This happens completely in the background. Using a script like that to change wallpaper to show solar hours would, I think, be pretty cool. Elijah ------ has also compiled code (clang) on Termux From sjeik_appie at hotmail.com Fri Oct 11 15:13:58 2019 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Fri, 11 Oct 2019 19:13:58 +0000 Subject: sqlalchemy & #temp tables In-Reply-To: <8f8402a4-2529-bffd-13b7-db6e231eb2eb@chagford.com> Message-ID: On 8 Oct 2019 07:49, Frank Millman wrote: On 2019-10-07 5:30 PM, Albert-Jan Roskam wrote: > Hi, > > I am using sqlalchemy (SA) to access a MS SQL Server database (python 3.5, Win 10). I would like to use a temporary table (preferably #local, but ##global would also be an option) to store results of a time-consuming query. In other queries I'd like to access the temporary table again in various places in my Flask app. How do I do that, given that SA closes the connection after each request? > > I can do: > with engine.connect() as con: > con.execute('select * into #tmp from tbl') > con.execute('select * from #tmp') > > ... but that's limited to the scope of the context manager. > > Oh, I don't have rights to create a 'real' table. :-( > > Thanks! > > Albert-Jan > >I do not use SA, but I have written my app to >support Sql Server, >PostgreSQL and sqlite3 as backend >databases. However, no matter which >one is in use, I also use sqlite3 as an in->memory database to store >temporary information. Hi, I tried your approach today but I ran into problems due to differences between the MS SQL and Sqlite dialect. However, I just came across this page: https://docs.sqlalchemy.org/en/13/dialects/sqlite.html#using-temporary-tables-with-sqlite. I haven't tried it yey, but using a StaticPool might work. # maintain the same connection across all threads from sqlalchemy.pool import StaticPool engine = create_engine('sqlite:///mydb.db', poolclass=StaticPool) From cs at cskk.id.au Fri Oct 11 19:13:43 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 12 Oct 2019 10:13:43 +1100 Subject: Odd delays when cwd is on a network mount In-Reply-To: References: Message-ID: <20191011231343.GA38770@cskk.homeip.net> On 11Oct2019 11:06, Tobiah wrote: >On 10/11/19 10:56 AM, Tobiah wrote: >>I have a directory mounted with sshfs over a 5mb connection. >>It's quite usable under most circumstances. >>When I run python from a directory under that mount, imports from >>local >>directories are quite slow: >>$ python2.7 >>>>>import my_module ## takes 25 seconds to complete >>>>>my_module.__file__ >>>>>/local/dir/not/on/mount/my_module.py [...] >Another way: > >$ cd ~ >$ python2.7 >>>>import os >>>>os.chdir('/remote/mount/point') >>>>import my_module ## 25 seconds again >>>>>my_module.__file__ >>>>>/local/dir/not/on/mount/my_module.py > >Without the os.chdir() the import is instantaneous. Python's default sys.path includes the current working directory. (Worse: at the front!) So it is loooking for my_module in the sshfs directory before your standard places. Thus the slowness. Personally I consider this a misfeature. Cheers, Cameron Simpson From greg.ewing at canterbury.ac.nz Fri Oct 11 21:04:15 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 12 Oct 2019 14:04:15 +1300 Subject: Odd delays when cwd is on a network mount In-Reply-To: References: <20191011231343.GA38770@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > Python's default sys.path includes the current working directory. Only in an interactive session, where it usually makes sense. -- Greg From eryksun at gmail.com Fri Oct 11 22:30:42 2019 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 11 Oct 2019 21:30:42 -0500 Subject: 3.7.4 (latest) install changes python to py and removes pip support In-Reply-To: References: Message-ID: On 10/11/19, Jim Elphick wrote: > I upgraded my Python 3.7.3 windows install to 3.7.4 using the windows > download from python.org. > > After the install, the keyword "python" will no longer invoke python. > "python3" also fails. "py" is now the only access to python. "python3" would normally fail, unless it's Windows 10 and you installed the app distribution from the Microsoft Store. Apps execute via special links that get created in "%LocalAppData%\Microsoft\WindowsApps". The store distribution of Python creates a bunch of these links, including versioned names such as "python3.exe" and "python3.7.exe". > py -version returns Python 3.7.4 > python -version returns the following. The first is bash. > The second is from powershell > bash: python: command not found > python : The term 'python' is not recognized as the name of a cmdlet, You forgot to include the option to add Python to the environment variables. This can be fixed in the programs list in the control panel. Right-click the version that you want to change and select "change". Choose to modify the installation and click "next". Enable "add Python to environment variables". Note that this dialog also shows you where you installed Python in the greyed-out "customize install location" text box. The installer probably won't remove invalid paths that no longer work. So open the system environment variable editor and remove Python installation directories and "Scripts" subdirectories that are no longer valid or that you simply don't need in PATH. For good measure, also select the "Python Launcher" installation and choose to repair it. This will rewrite the Python.File progid and registered ".py" file association. That's not enough on its own, however. "Python.File" is not necessarily your user choice in the shell, which overrides the registered file association. So, to finish out, right-click a .py file; select the "open with" menu; and click on "choose another app". Select the Python app with a rocket in the icon and enable the toggle to "always use this app". Select ok. This should ensure that "Python.File" controls the open action and right-click actions for .py scripts, including the shell extension for drag-and-drop support and the "Edit with IDLE" menu. > This is much more than an inconvenience. Pip has stopped working because it > expects to find "python.exe". pipenv also no longer executes. > Pip -version returns (second is again powershell) > nothing in bash (empty string, no error) > Fatal error in launcher: Unable to create process using '"c:\program > files\python37\python.exe" The new installation was probably not an in-place upgrade but instead installed somewhere else, probably for the current user in "%LocalAppData%\Programs\Python\Python37". However files were left in the original "C:\Program Files\Python37\Scripts" directory, including a stale pip.exe, which was still in PATH. pip.exe is just a frozen script that's embedded in a scaled-down version of the py.exe launcher. The embedded script includes the path to python.exe in a shebang. That path was no longer valid. To confirm this in a case like this, run `where.exe pip` to determine what `pip` executes. You know from the installer where the current Python installation is located. Or you can determine it by running Python from the start menu and printing the value of sys.prefix. The correct pip.exe is in its "Scripts" subdirectory. From eryksun at gmail.com Fri Oct 11 22:45:54 2019 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 11 Oct 2019 21:45:54 -0500 Subject: Odd delays when cwd is on a network mount In-Reply-To: <20191011231343.GA38770@cskk.homeip.net> References: <20191011231343.GA38770@cskk.homeip.net> Message-ID: On 10/11/19, Cameron Simpson wrote: > > Python's default sys.path includes the current working directory. > (Worse: at the front!) Python normally sets the script directory at the front of sys.path to allow a script to override site paths and the standard library. If you're running the REPL, there's no script directory, so the working directory is used. I think that's fine, but I'd prefer it to use the absolute path of the working directory at startup instead of dynamically tracking the current working directory. From phamp at mindspring.com Fri Oct 11 23:41:47 2019 From: phamp at mindspring.com (pyotr filipivich) Date: Fri, 11 Oct 2019 20:41:47 -0700 Subject: question about making an App for Android References: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> <20191011170113.GB21037@shallowsky.com> Message-ID: Dennis Lee Bieber on Fri, 11 Oct 2019 20:05:03 -0400 typed in comp.lang.python the following: > >* To support my practically unused 8" SCT {especially in cloudy Michigan}{I >also need to find some sort of battery holders that will fit the fork arms >-- the originals have cracked at the ends and don't make contact} > ># Started with an interest producing ephemerides for comets -- back when >Sky&Telescope used to produce element sets for comets [and when it was >thought comets might be elliptical, parabolic, or hyperbolic -- I think >modern thought is that they are all elliptical, but may be of such a long >period that no one would ever prove it]; now they just provide finder >charts. Also, in a former life I was a programmer at a firm that did >satellite work -- even if I couldn't follow all the math [one book had >equations that lost me on page three!] it helped to have some understanding >of things like perturbations and gravitational models of the earth. I've been hacking around with what needs to be computed. As in "okay,the orbits have different speed at different points on said ellipse, and so ummm, what does that do to sidereal time?" And so forth. And as I've said, "How did they do this without a mechanical clock?" I really need to look that part up _first._ > -- pyotr filipivich Next month's Panel: Graft - Boon or blessing? From cs at cskk.id.au Sat Oct 12 00:03:27 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 12 Oct 2019 15:03:27 +1100 Subject: Odd delays when cwd is on a network mount In-Reply-To: References: Message-ID: <20191012040327.GA96680@cskk.homeip.net> On 12Oct2019 14:04, Greg Ewing wrote: >Cameron Simpson wrote: >>Python's default sys.path includes the current working directory. > >Only in an interactive session, where it usually makes sense. Personally, I would not consider this: % python3 -c 'import sys;print(repr(sys.path))' ['', '/Users/cameron/lib/python', '/Users/cameron/rc/python', '/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/cameron/var/venv/3.7.1/lib/python3.7/site-packages'] to be interactive. It is at a terminal, but that seems a very low bar. I see that plain "python filename.py" does not include the current directory though. Cheers, Cameron Simpson From gisle.vanem at gmail.com Sat Oct 12 00:19:03 2019 From: gisle.vanem at gmail.com (Gisle Vanem) Date: Sat, 12 Oct 2019 06:19:03 +0200 Subject: Python 3.6 on Windows - does a python3 alias get created by installation? In-Reply-To: References: <2e3f5255-dda5-416b-8403-b0777854227c@www.fastmail.com> Message-ID: <2d6aa59c-5f4d-6a62-c367-0bb60bc79c28@gmail.com> Eryk Sun wrote: > The simplest way to create a shell link is via the Windows GUI shell, > Explorer. To inherit the working directory of the parent process, > leave the link's "start in" field empty. Also, add ".LNK" to the > system PATHEXT environment variable to allow finding link files > without having to include the ".lnk" file extension, i.e. to be able > to run "python3.lnk <...>" as just "python3 <...>". An "alias" could also simply be created using: doskey python3=f:\ProgramFiles\Python36\python.exe -- --gv From eryksun at gmail.com Sat Oct 12 00:40:50 2019 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 11 Oct 2019 23:40:50 -0500 Subject: Python 3.6 on Windows - does a python3 alias get created by installation? In-Reply-To: <2d6aa59c-5f4d-6a62-c367-0bb60bc79c28@gmail.com> References: <2e3f5255-dda5-416b-8403-b0777854227c@www.fastmail.com> <2d6aa59c-5f4d-6a62-c367-0bb60bc79c28@gmail.com> Message-ID: On 10/11/19, Gisle Vanem wrote: > > An "alias" could also simply be created using: > doskey python3=f:\ProgramFiles\Python36\python.exe That's a console alias [1], which gets evaluated by the console host process (conhost.exe) when the target process does a normal read via ReadConsoleW or ReadFile. By default doskey.exe creates an alias for "cmd.exe" processes. In the above case, if you enter a line in CMD's prompt that starts with "python3" (ignoring initial whitespace), CMD will instead read "f:\ProgramFiles\Python36\python.exe" from the console input buffer. There are obvious limitations. Since it matches at the start of a line of input, we can't pipe to an alias; or run it on the right-hand side of the &, &&, or || operators; or use it as a command in a `FOR /f` loop; or control how it executes via the START command. Also, since it's only implemented for reads from the current console, it can't be used as a command in a batch script, i.e. CMD will read "python3" from the batch file, not "f:\ProgramFiles\Python36\python.exe". [1] https://docs.microsoft.com/en-us/windows/console/addconsolealias From specially at processed.almost.meat Sat Oct 12 05:55:38 2019 From: specially at processed.almost.meat (Roy Hann) Date: Sat, 12 Oct 2019 09:55:38 +0000 (UTC) Subject: Suppress tooltips in Pygal charts References: Message-ID: Dennis Lee Bieber wrote: > On Fri, 11 Oct 2019 12:46:10 +0000 (UTC), Roy Hann > declaimed the following: > >>Following up on Elijah's suggestion responding to my earlier question >>about drawing gauges in a mobile (i.e. not normally internet connected) >>application on a Raspberry Pi I am using Pygal and rendering to SVG. >> >>I have found no way to stop Pygal from generating SVG that >>downloads and invokes JavaScript for various roll-over effects like >>tooltips. >> > > Sample code would be useful... What form are you using for output? > .render() or .render_to_file(). Note that if you install enough, pygal has > .render_to_png() Thank you for your very extensive answer Dennis. Roy From specially at processed.almost.meat Sat Oct 12 06:35:31 2019 From: specially at processed.almost.meat (Roy Hann) Date: Sat, 12 Oct 2019 10:35:31 +0000 (UTC) Subject: Suppress tooltips in Pygal charts (solved) References: Message-ID: Roy Hann wrote: > Is there any way to tell Pygal not to generate references to on-line > resources? I can now answer my own question. The solution was not obvious from reading the documentation but a glance at the pygal code uncovered the answer. The js configuration parameter specifies where to look for JavaScript resources. The scant documentation on js hints (wrongly) that it has to be a URI reference with no specified scheme. Reading the code it is clear a local file reference is allowed as the scheme, so this works: g=pygal.SolidGauge(half_pie=True,js=['file:///tmp/pygal-tooltips.min.js']) The solution is to download the .js file ahead of time and store it locally on my device. Roy PS: I know; /tmp is a silly place to put it. That's not the location I'm really using. From larry at hastings.org Sat Oct 12 08:06:07 2019 From: larry at hastings.org (Larry Hastings) Date: Sat, 12 Oct 2019 13:06:07 +0100 Subject: [RELEASED] Python 3.5.8rc2 is released In-Reply-To: References: Message-ID: <7fab166b-48d4-2805-bd4c-8dbbc07d7e63@hastings.org> On behalf of the Python development community, I'm relieved to announce the availability of Python 3.5.8rc2.? It's been a month after Python 3.5.8rc1, and since then we've added a small amount of new code to fix an API-level regression in http client, updated expat to 2.2.8, and upgraded the required version of Sphinx from 1.2 to 1.8.? This is enough change that I feel a second rc is indicated.? Assuming all is quiet, 3.5.8 final should come out in about two weeks. This new version is a source-only release. You can find Python 3.5.8rc2 here: ??? https://www.python.org/downloads/release/python-358rc2/ Hullo from PyCon IE, /arry From oliver.schoenborn at gmail.com Sat Oct 12 09:19:47 2019 From: oliver.schoenborn at gmail.com (oliver) Date: Sat, 12 Oct 2019 09:19:47 -0400 Subject: Would you be interested in this Python open source project? In-Reply-To: <59774fac-6e7b-fa90-579f-1e1887d957f4@gmail.com> References: <3645f1e6-08f6-5cad-a53e-764df7f865af@gmail.com> <10b13903-3f1e-87b8-4255-1303d943feda@kynesim.co.uk> <59774fac-6e7b-fa90-579f-1e1887d957f4@gmail.com> Message-ID: There are tons of projects that need help, I recommend that instead of re-inventing the wheel as there are enough choices out there re cicd and very likely you will find that your goal of 10/90 is unrealistic. Have a look at codetriage.com, and github has a feature that allows you to search for projects that need help. Another major advantage of helping an existing project is that you will be seeing how others write python code so you will learn best practices faster (dont kid yourself, if you do it on your own the code you write now you will find horrible in a year, and you certainly will not be interested in rewriting it!). Keep up the good work! On Wed., Oct. 9, 2019, 08:35 Simon Connah, wrote: > > On 08/10/2019 15:05, Bill Deegan wrote: > > You might just consider working with the BuildBot project to add support > > for lighter weight build workers. > > Re-Re-Re-inventing the wheel is almost always wasted effort. > > Buildbot looks good. I'll check to make sure its open source license is > compatible with the Affero General Public License version 3. On the > other hand I do have a desire to build something similar myself just to > get the hang of things like this. Thank you for your reply. > > > On Tue, Oct 8, 2019 at 8:33 AM Rhodri James > wrote: > > > >> On 08/10/2019 11:22, Simon Connah wrote: > >>> I'm posting this message as a way to gauge interest in the project and > >>> to see if it is worth moving forward with. There are probably hundreds > >>> of CI/CD tools out there and many more general devops tools but what I > >>> want to build is a CI/CD tool that ONLY supports Python 3.6 or greater > >>> and only runs on one Linux distribution (my preference is Ubuntu). This > >>> way configuration would be much more simple than the vast majority of > >>> devops tools which try to support every programming language that is > >>> popular (or so it seems) on many different Linux distributions and even > >>> Windows and macOS. > >>> > >>> My theory is that if you limit the devops tool to a very limited > >>> subsection of the available options the system will be easier to > >>> configure for users, more stable, easier to patch bugs in and generally > >>> just be a better all around things for Python developers. > >>> > >>> I'd love to hear some feedback on the idea. > >>> > >> I think your reasoning is sound. I probably wouldn't make a lot of use > >> of it, but I live in Embedded Systems land where it's notoriously hard > >> to do CI off the target silicon. Other people living in more tractable > >> problem spaces will probably be more enthusiastic. > >> > >> -- > >> Rhodri James *-* Kynesim Ltd > >> -- > >> https://mail.python.org/mailman/listinfo/python-list > >> > -- > https://mail.python.org/mailman/listinfo/python-list > From phamp at mindspring.com Sat Oct 12 12:53:22 2019 From: phamp at mindspring.com (pyotr filipivich) Date: Sat, 12 Oct 2019 09:53:22 -0700 Subject: question about making an App for Android References: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> <20191011170113.GB21037@shallowsky.com> <1gu3qe1lftiirgthcm6min5ol81o35v586@4ax.com> Message-ID: <1614qehl3gb5gi29b1g6l9dk4qnatbqbcn@4ax.com> Dennis Lee Bieber on Sat, 12 Oct 2019 12:26:43 -0400 typed in comp.lang.python the following: >On Fri, 11 Oct 2019 20:41:47 -0700, pyotr filipivich >declaimed the following: > > >> I've been hacking around with what needs to be computed. As in >>"okay,the orbits have different speed at different points on said >>ellipse, and so ummm, what does that do to sidereal time?" And so >>forth. >> >> And as I've said, "How did they do this without a mechanical >>clock?" I really need to look that part up _first._ >>> > > Water clocks go back centuries >https://en.wikipedia.org/wiki/Water_clock and sundials were used for >daylight (since noon is when the shadow is shortest it is an easily >determined point, and one could then calibrate a 24+hour water clock by >comparing noon to noon). > > But that said, those ancients also believed in a geocentric universe, >and started adding epicycles to the cycles of the planets to account for >the apparent retrograde motions -- their idea of the planet orbits begin to >look like things created with spirographs. > > For more advanced (heliocentric orbits)... Like comets, say... One did >angular measurements against the "fixed stars" and sidereal time (what star >is overhead "now" measured from some declared 0 point -- first point of >Aries, say, which is overhead at night in September [in April the /sun/ is >overhead when it is in Aries]) cf: Angles-Only Orbit Determination (vs >range-only, or range&angle, both of which need either radar or multiple >observations from different locations on the earth [parallax computation to >determine range]) > > The star XYZ is at zenith and the wanderer is x-deg west and y-deg >south of it. Next night star XYZ is at zenith and wanderer is x2-deg west >and y2-deg south. Though one may not need to wait for zenith, if one also >measures the east/west angle for star XYZ relative to the observer zenith >[to determine time relative to the zenith passing]. Thanks, that clarifies things a bit. I'd figured that was some thing on how it would go. -- pyotr filipivich The question was asked: "Is Hindsight overrated?" In retrospect, it appears to be. From ekopalypse at gmail.com Sat Oct 12 14:08:34 2019 From: ekopalypse at gmail.com (Eko palypse) Date: Sat, 12 Oct 2019 11:08:34 -0700 (PDT) Subject: python3, regular expression and bytes text Message-ID: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> What needs to be set in order to be able to use a re search within utf8 encoded bytes? My test, being on a windows PC with cp1252 setup, looks like this import re import locale cp1252 = '?rger im Paradies'.encode('cp1252') utf8 = '?rger im Paradies'.encode('utf-8') print('cp1252:', cp1252) print('utf8 :', utf8) print('-'*80) print("search for '?rger'.encode('cp1252') in cp1252 encoded text") for m in re.finditer('?rger'.encode('cp1252'), cp1252): print(m) print('-'*80) print("search for '?rger'.encode('') in utf8 encoded text") for m in re.finditer('?rger'.encode(), utf8): print(m) print('-'*80) print("search for '\\w+'.encode('cp1252') in cp1252 encoded text") for m in re.finditer('\\w+'.encode('cp1252'), cp1252): print(m) print('-'*80) print("search for '\\w+'.encode('') in utf8 encoded text") for m in re.finditer('\\w+'.encode(), utf8): print(m) locale.setlocale(locale.LC_ALL, '') print('-'*80) print("search for '\\w+'.encode('cp1252') using re.LOCALE in cp1252 encoded text") for m in re.finditer('\\w+'.encode('cp1252'), cp1252, re.LOCALE): print(m) print('-'*80) print("search for '\\w+'.encode('') using ??? in utf8 encoded text") for m in re.finditer('\\w+'.encode(), utf8): print(m) if you run this you will get something like cp1252: b'\xc4rger im Paradies' utf8 : b'\xc3\x84rger im Paradies' -------------------------------------------------------------------------------- search for '?rger'.encode('cp1252') in cp1252 encoded text -------------------------------------------------------------------------------- search for '?rger'.encode('') in utf8 encoded text -------------------------------------------------------------------------------- these two are ok BUT the result for \w+ shows a difference search for '\w+'.encode('cp1252') in cp1252 encoded text -------------------------------------------------------------------------------- search for '\w+'.encode('') in utf8 encoded text -------------------------------------------------------------------------------- it doesn't find the ?, which from documentation point of view is expected and a hint to use locale is given, so let's do it and the results are search for '\w+'.encode('cp1252') using re.LOCALE in cp1252 encoded text -------------------------------------------------------------------------------- works for cp1252 BUT does not work for utf8 search for '\w+'.encode('') using ??? in utf8 encoded text So how can I make it work with utf8 encoded text? Note, decoding it to a string isn't preferred as this would mean allocating the bytes buffer a 2nd time and it might be that a buffer is several 100MBs, even GBs. Thank you Eren From rosuav at gmail.com Sat Oct 12 15:29:50 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 13 Oct 2019 06:29:50 +1100 Subject: python3, regular expression and bytes text In-Reply-To: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> References: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> Message-ID: On Sun, Oct 13, 2019 at 5:11 AM Eko palypse wrote: > > What needs to be set in order to be able to use a re search within > utf8 encoded bytes? You have to be able to match bytes, not strings. > So how can I make it work with utf8 encoded text? > Note, decoding it to a string isn't preferred as this would mean > allocating the bytes buffer a 2nd time and it might be that a > buffer is several 100MBs, even GBs. I don't think you'll be able to 100% reliably match bytes in this way. You're asking it to make analysis of multiple bytes and to interpret them according to which character they would represent if decoded from UTF-8. My recommendation: Even if your buffer is multiple gigabytes, just decode it anyway. Maybe you can decode your buffer in chunks, but otherwise, just bite the bullet and do the decode. You may be pleasantly surprised at how little you suffer as a result; Python is quite decent at memory management, and even if you DO get pushed into the swapper by this, it's still likely to be faster than trying to code around all the possible problems that come from mismatching your text search. ChrisA From storchaka at gmail.com Sat Oct 12 15:48:29 2019 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sat, 12 Oct 2019 22:48:29 +0300 Subject: python3, regular expression and bytes text In-Reply-To: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> References: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> Message-ID: 12.10.19 21:08, Eko palypse ????: > So how can I make it work with utf8 encoded text? You cannot. First, \w in re.LOCALE works only when the text is encoded with the locale encoding (cp1252 in your case). Second, re.LOCALE supports only 8-bit charsets. So even if you set the utf-8 locale, it would not help. Regular expressions with re.LOCALE are slow. It may be more efficient to decode text and use Unicode regular expression. From ekopalypse at gmail.com Sat Oct 12 15:46:47 2019 From: ekopalypse at gmail.com (Eko palypse) Date: Sat, 12 Oct 2019 12:46:47 -0700 (PDT) Subject: python3, regular expression and bytes text In-Reply-To: References: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> Message-ID: <6caf67cd-2678-420c-9485-2815ed31a086@googlegroups.com> Thank you very much for your answer. > You have to be able to match bytes, not strings. May I ask you to elaborate on this, sorry non-native English speaker. The buffer I receive is a byte-like buffer. > I don't think you'll be able to 100% reliably match bytes in this way. > You're asking it to make analysis of multiple bytes and to interpret > them according to which character they would represent if decoded from > UTF-8. > > My recommendation: Even if your buffer is multiple gigabytes, just > decode it anyway. Maybe you can decode your buffer in chunks, but > otherwise, just bite the bullet and do the decode. You may be > pleasantly surprised at how little you suffer as a result; Python is > quite decent at memory management, and even if you DO get pushed into > the swapper by this, it's still likely to be faster than trying to > code around all the possible problems that come from mismatching your > text search. > > ChrisA That's what I was afraid of. It would be nice if the "world" could commit itself to one standard, but I'm afraid that won't happen in my life anymore, I guess. :-( Thx Eren From storchaka at gmail.com Sat Oct 12 15:55:18 2019 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sat, 12 Oct 2019 22:55:18 +0300 Subject: decorator needs access to variables where it is used. In-Reply-To: References: Message-ID: 09.10.19 14:02, Chris Angelico ????: > The decorator has full access to the function object, including a > reference to that function's module globals. > > def trace(func): > log = func.__globals__["log"] > ... proceed as before > > As long as you can depend on "log" always being a module-level > (global) name, and not (for instance) a closure variable, this should > work. It's a bit ugly, but it should be fine since it's buried away in > the decorator. It may be better to not rely on global variable "log", but get the logger by the module name. def trace(func): log = logging.getLogger(func.__module__) ... From ekopalypse at gmail.com Sat Oct 12 15:57:06 2019 From: ekopalypse at gmail.com (Eko palypse) Date: Sat, 12 Oct 2019 12:57:06 -0700 (PDT) Subject: python3, regular expression and bytes text In-Reply-To: References: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> Message-ID: <08a6ace1-9ac6-40bd-a0b5-997c58c1da1b@googlegroups.com> > You cannot. First, \w in re.LOCALE works only when the text is encoded > with the locale encoding (cp1252 in your case). Second, re.LOCALE > supports only 8-bit charsets. So even if you set the utf-8 locale, it > would not help. > > Regular expressions with re.LOCALE are slow. It may be more efficient to > decode text and use Unicode regular expression. Thank you, I guess I'm convinced to always decode everything (re pattern and text) to utf8 internally and then do the re search but then I would need to figure out the correct position, hmm - some ongoing investigation needed, I guess. Thx Eren From dorismarca at outlook.es Sat Oct 12 16:06:54 2019 From: dorismarca at outlook.es (Doris Marca Guaraca) Date: Sat, 12 Oct 2019 20:06:54 +0000 Subject: Mailscanner Message-ID: Hi sorry to bother you maybe you can help me, could you tell me which is the path that contains the main file of the bayes filter, I can't find it, or, I'm not sure this is the file / opt / zimbra / zimbramon /lib/Mail/Filter.pm Thank you in advance for your help. Regards Doris From rosuav at gmail.com Sat Oct 12 16:10:11 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 13 Oct 2019 07:10:11 +1100 Subject: python3, regular expression and bytes text In-Reply-To: <6caf67cd-2678-420c-9485-2815ed31a086@googlegroups.com> References: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> <6caf67cd-2678-420c-9485-2815ed31a086@googlegroups.com> Message-ID: On Sun, Oct 13, 2019 at 6:54 AM Eko palypse wrote: > > Thank you very much for your answer. > > > You have to be able to match bytes, not strings. > > May I ask you to elaborate on this, sorry non-native English speaker. > The buffer I receive is a byte-like buffer. When you're matching text (the normal way you use a regular expression), every element in the RE matches a character (or emptiness). For instance, the regular expression "^[bc]at$" has these elements: "^" matches emptiness at the start "[bc]" matches either "b" or "c", nothing else "a" matches "a", exactly "t" matches "t" "$" matches emptiness at the end. When you're working with bytes, the same has to be true of the bytes. But that means you can't match against b"\xc3\x84" - you have to match b"\xc3" and b"\x84" separately. That's fine if all you need to do is match a single specific character (in the same way that the "at" in my text example will match "a" followed by "t"), but you can't ask questions like "does the next few bytes represent a word character". All you can do is ask "does the next ONE BYTE represent a word character?". > > I don't think you'll be able to 100% reliably match bytes in this way. > > You're asking it to make analysis of multiple bytes and to interpret > > them according to which character they would represent if decoded from > > UTF-8. > > > > My recommendation: Even if your buffer is multiple gigabytes, just > > decode it anyway. Maybe you can decode your buffer in chunks, but > > otherwise, just bite the bullet and do the decode. You may be > > pleasantly surprised at how little you suffer as a result; Python is > > quite decent at memory management, and even if you DO get pushed into > > the swapper by this, it's still likely to be faster than trying to > > code around all the possible problems that come from mismatching your > > text search. > > > > ChrisA > > That's what I was afraid of. > It would be nice if the "world" could commit itself to one standard, > but I'm afraid that won't happen in my life anymore, I guess. :-( > The world HAS committed to one standard - or one that matters. That standard is Unicode text. Not UTF-8, but Unicode text. Decode your bytes to text, *then* do your searches. ChrisA From Richard at Damon-Family.org Sat Oct 12 16:14:30 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 12 Oct 2019 16:14:30 -0400 Subject: python3, regular expression and bytes text In-Reply-To: <6caf67cd-2678-420c-9485-2815ed31a086@googlegroups.com> References: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> <6caf67cd-2678-420c-9485-2815ed31a086@googlegroups.com> Message-ID: <020c3f51-a134-9ec6-a909-ed415164932a@Damon-Family.org> On 10/12/19 3:46 PM, Eko palypse wrote: > Thank you very much for your answer. > >> You have to be able to match bytes, not strings. > May I ask you to elaborate on this, sorry non-native English speaker. > The buffer I receive is a byte-like buffer. > >> I don't think you'll be able to 100% reliably match bytes in this way. >> You're asking it to make analysis of multiple bytes and to interpret >> them according to which character they would represent if decoded from >> UTF-8. >> >> My recommendation: Even if your buffer is multiple gigabytes, just >> decode it anyway. Maybe you can decode your buffer in chunks, but >> otherwise, just bite the bullet and do the decode. You may be >> pleasantly surprised at how little you suffer as a result; Python is >> quite decent at memory management, and even if you DO get pushed into >> the swapper by this, it's still likely to be faster than trying to >> code around all the possible problems that come from mismatching your >> text search. >> >> ChrisA > That's what I was afraid of. > It would be nice if the "world" could commit itself to one standard, > but I'm afraid that won't happen in my life anymore, I guess. :-( > > Thx > Eren Current 'best practices' are in my opinion to convert data (if needed) to some version of Unicode (UTF-8, UTF-16, or UCS-4) at input (if needed) and process in that domain. You do need to be prepared to run into files which are encoded in some locally defined 8-bit code page. In Python3,? strings are unicode encoded, and you don't need to worry about the details of which encoding is used internally, Python will deal with that itself. -- Richard Damon From python at mrabarnett.plus.com Sat Oct 12 16:15:26 2019 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 12 Oct 2019 21:15:26 +0100 Subject: python3, regular expression and bytes text In-Reply-To: References: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> Message-ID: <33561cc9-c799-5a19-00a8-1c58324d8ce8@mrabarnett.plus.com> On 2019-10-12 20:48, Serhiy Storchaka wrote: > 12.10.19 21:08, Eko palypse ????: >> So how can I make it work with utf8 encoded text? > > You cannot. First, \w in re.LOCALE works only when the text is encoded > with the locale encoding (cp1252 in your case). Second, re.LOCALE > supports only 8-bit charsets. So even if you set the utf-8 locale, it > would not help. > > Regular expressions with re.LOCALE are slow. It may be more efficient to > decode text and use Unicode regular expression. > +1 It's best to treat re.LOCALE as being for old legacy encodings that use/used 8 bits per character. Wherever possible, decode to Unicode and work with that instead. From python at mrabarnett.plus.com Sat Oct 12 16:20:25 2019 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 12 Oct 2019 21:20:25 +0100 Subject: Mailscanner In-Reply-To: References: Message-ID: On 2019-10-12 21:06, Doris Marca Guaraca wrote: > > Hi sorry to bother you maybe you can help me, could you tell me which is the path that contains the main file of the bayes filter, I can't find it, or, I'm not sure this is the file / opt / zimbra / zimbramon /lib/Mail/Filter.pm > > Thank you in advance for your help. > Are you referring to the software described here: https://www.mailscanner.info/ If so, that's written in Perl, not in Python. From rosuav at gmail.com Sat Oct 12 16:23:44 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 13 Oct 2019 07:23:44 +1100 Subject: python3, regular expression and bytes text In-Reply-To: <020c3f51-a134-9ec6-a909-ed415164932a@Damon-Family.org> References: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> <6caf67cd-2678-420c-9485-2815ed31a086@googlegroups.com> <020c3f51-a134-9ec6-a909-ed415164932a@Damon-Family.org> Message-ID: On Sun, Oct 13, 2019 at 7:16 AM Richard Damon wrote: > > On 10/12/19 3:46 PM, Eko palypse wrote: > > Thank you very much for your answer. > > > >> You have to be able to match bytes, not strings. > > May I ask you to elaborate on this, sorry non-native English speaker. > > The buffer I receive is a byte-like buffer. > > > >> I don't think you'll be able to 100% reliably match bytes in this way. > >> You're asking it to make analysis of multiple bytes and to interpret > >> them according to which character they would represent if decoded from > >> UTF-8. > >> > >> My recommendation: Even if your buffer is multiple gigabytes, just > >> decode it anyway. Maybe you can decode your buffer in chunks, but > >> otherwise, just bite the bullet and do the decode. You may be > >> pleasantly surprised at how little you suffer as a result; Python is > >> quite decent at memory management, and even if you DO get pushed into > >> the swapper by this, it's still likely to be faster than trying to > >> code around all the possible problems that come from mismatching your > >> text search. > >> > >> ChrisA > > That's what I was afraid of. > > It would be nice if the "world" could commit itself to one standard, > > but I'm afraid that won't happen in my life anymore, I guess. :-( > > > > Thx > > Eren > > Current 'best practices' are in my opinion to convert data (if needed) > to some version of Unicode (UTF-8, UTF-16, or UCS-4) at input (if > needed) and process in that domain. Specifically, convert to abstract Unicode text, not to any of those byte encodings. > You do need to be prepared to run > into files which are encoded in some locally defined 8-bit code page. In > Python3, strings are unicode encoded, and you don't need to worry about > the details of which encoding is used internally, Python will deal with > that itself. > Yes. A Python 3 string consists of Unicode characters (technically, it's a sequence of Unicode code points), and you don't have to worry about encodings any more than you need to worry about the details of the IEEE 754 packed formats in order to use floating-point numbers. You should be able to just use the abstract "text string" as a fundamental concept. ChrisA From python at mrabarnett.plus.com Sat Oct 12 16:25:13 2019 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 12 Oct 2019 21:25:13 +0100 Subject: python3, regular expression and bytes text In-Reply-To: <08a6ace1-9ac6-40bd-a0b5-997c58c1da1b@googlegroups.com> References: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> <08a6ace1-9ac6-40bd-a0b5-997c58c1da1b@googlegroups.com> Message-ID: <2cec69a5-e50b-66ad-26b9-9d361c404ca4@mrabarnett.plus.com> On 2019-10-12 20:57, Eko palypse wrote: >> You cannot. First, \w in re.LOCALE works only when the text is encoded >> with the locale encoding (cp1252 in your case). Second, re.LOCALE >> supports only 8-bit charsets. So even if you set the utf-8 locale, it >> would not help. >> >> Regular expressions with re.LOCALE are slow. It may be more efficient to >> decode text and use Unicode regular expression. > > Thank you, I guess I'm convinced to always decode everything (re pattern and text) to utf8 internally and then do the re search but then I would need to figure out the correct position, hmm - some ongoing investigation needed, I guess. > You don't _decode_ to UTF-8, you _decode_ to Unicode and _encode_ to UTF-8: Decode: UTF-8 => Unicode Encode: Unicode => UTF-8 How the Unicode is stored internally is a detail of the implementation. From ekopalypse at gmail.com Sat Oct 12 17:04:35 2019 From: ekopalypse at gmail.com (Eko palypse) Date: Sat, 12 Oct 2019 14:04:35 -0700 (PDT) Subject: python3, regular expression and bytes text In-Reply-To: References: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> <08a6ace1-9ac6-40bd-a0b5-997c58c1da1b@googlegroups.com> <2cec69a5-e50b-66ad-26b9-9d361c404ca4@mrabarnett.plus.com> Message-ID: <30e5e9ca-9abf-4fe8-9aaf-4a5201e8938e@googlegroups.com> First of all many thanks to everyone for the active participation. @Chris Angelico I think I understand what you illustrated with the byte example, makes sense. As it was developed for 8-bit encoding only, it cannot be used for mulitbyte encoding. @Richard Damon and @MRAB thank you very much for the information too, very much appreciated. I think I understand what you all mean but I am not sure how to put this all together. Maybe a little bit more information about what I wanted to do. Using notepad++ and scintilla. Scintilla passes a readonly pointer with SCI_GETCHARACTERPOINTER of the current buffer to me. The problem is that the buffer can have all possible encodings. cp1251, cp1252, utf8, ucs-2 ... but scintilla informs me about which encoding is currently used. I wanted to realize a regular expression tester with Python3, and mark the text that has been matched by regular expressions. After testing to treat everything as python3 str I found out that the positions of the matched text are not correctly reported. E.g say, if I want to find the word "?rger", assumed encoded in utf8, with the regex \w+. If I decode it, it would return the length of 5, whereas it is of length 6 within the document, so marking the match would be wrong, wouldn't it? I understand the reason of the difference. If I use the builtin find dialog of notepad++, which uses internally the boost::regex engine, I can use \w+ to find the word. So that's where I'm stuck at the moment. How can I find and mark those matches correctly. Wrapping boost:regex with ICU support? Thx Eren From DomainAdmin at DancesWithMice.info Sun Oct 13 01:41:13 2019 From: DomainAdmin at DancesWithMice.info (David L Neil) Date: Sun, 13 Oct 2019 18:41:13 +1300 Subject: Mouse control In-Reply-To: <58519cc4-0c96-e018-a5b7-43d2011719de@gmail.com> References: <58519cc4-0c96-e018-a5b7-43d2011719de@gmail.com> Message-ID: <18e91314-52b9-18e8-09b3-a6c1ead9d4d7@DancesWithMice.info> On 7/10/19 4:11 AM, Alexander Vergun wrote: > Hello all, > > I am coding a voice assistant under Python 3.7, Windows 7. I am using > PYcharm and libraries such as PYSimpleGUI, mouse, keyboard etc. > Everything works except for the mouse control and probably keyboard, the > problem is following, when I run the script under PYcharm, the script > can control mouse only within PYcharm editor, but when the other window > is on the top, the script cannot control the mouse, and the same happens > when the script runs under the Python console. There is only one way to > make script control the mouse - I have to manually click on the window > which was opened by the script only then the script controls the mouse. > I tried to call win32gui.SetCapture without any effect. Of possible interest: python-catalin Catalin George Festila. Thursday, October 10, 2019 Python 3.7.4 : Testing the PyUSB python module. https://python-catalin.blogspot.com/2019/10/python-374-testing-pyusb-python-module.html (via PlanetPython) -- Regards =dn From wesp at outrelay.com Sat Oct 12 21:53:45 2019 From: wesp at outrelay.com (Wesley Peng) Date: Sun, 13 Oct 2019 01:53:45 +0000 (UTC) Subject: Python 3.6 on Windows - does a python3 alias get created by installation? In-Reply-To: <2d6aa59c-5f4d-6a62-c367-0bb60bc79c28@gmail.com> References: <2e3f5255-dda5-416b-8403-b0777854227c@www.fastmail.com> <2d6aa59c-5f4d-6a62-c367-0bb60bc79c28@gmail.com> Message-ID: smart.thanks. On 2019/10/12 12:19 ??, Gisle Vanem wrote: > > An "alias" could also simply be created using: > ? doskey python3=f:\ProgramFiles\Python36\python.exe From piet-l at vanoostrum.org Sun Oct 13 10:34:46 2019 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Sun, 13 Oct 2019 16:34:46 +0200 Subject: Jupyter Notebook -> PDF with A4 pages? References: Message-ID: Martin Sch??n writes: > Is there a way to do "Download as PDF" and get A4 pages instead > of Letter? Yes, I know I can do "Download as LaTeX" and edit the > result to get A4 but if there is a setting I have missed I save > work and time. > > Yes, I have looked through the documentation and searched the > Internet but so far to no avail. > Make a directory ~/.jupyter/templates and put a file A4article.tplx inside it: ############# ((=- Default to the notebook output style -=)) ((* if not cell_style is defined *)) ((* set cell_style = 'style_jupyter.tplx' *)) ((* endif *)) ((=- Inherit from the specified cell style. -=)) ((* extends cell_style *)) %=============================================================================== % Latex Article %=============================================================================== ((* block docclass *)) \documentclass[a4paper,11pt]{article} ((* endblock docclass *)) ############# Make a file ~/.jupyter/jupyter_notebook_config.py ############## import os custom_path = os.path.expanduser("~/.jupyter/templates") c = get_config() c.TemplateExporter.template_path.append(custom_path) c.LatexExporter.template_file = 'A4article' c.PDFExporter.latex_count = 3 c.PDFExporter.template_file = 'A4article' c.PDFExporter.latex_command = ['pdflatex', '{filename}'] ############# Replace 'pdflatex' with 'xelatex' if you prefer that. You can leave out the c.LatexExporter.template_file line if you don't want the LaTeX exporter to generate A4. -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From martin.schoon at gmail.com Sun Oct 13 05:48:23 2019 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 13 Oct 2019 09:48:23 GMT Subject: Jupyter Notebook -> PDF with A4 pages? Message-ID: Is there a way to do "Download as PDF" and get A4 pages instead of Letter? Yes, I know I can do "Download as LaTeX" and edit the result to get A4 but if there is a setting I have missed I save work and time. Yes, I have looked through the documentation and searched the Internet but so far to no avail. /Martin From gheskett at shentel.net Sun Oct 13 05:41:19 2019 From: gheskett at shentel.net (Gene Heskett) Date: Sun, 13 Oct 2019 05:41:19 -0400 Subject: upgrading python on raspbian Message-ID: <201910130541.19512.gheskett@shentel.net> I'm not a python expert by a long ways. I have built the linuxcnc-master, which is the development branch of linuxcnc, a machine control program to run most metal carving machines. Lathes, milling machines, anything you can motorize, LinuxCNC can run. This requires a preempt-rt kernel which I've managed to build and install, all on a pi-4b running raspbian buster, the armfh-v7l version of debian 10.1. But linuxcnc is quite elderly code, some of it going back to before there was a linux, so despite being actively developed right now for x86 type hardware but has quite a list of missing dependencies I cannot satisfy from the raspbian repos. They are: The following packages have unmet dependencies: linuxcnc-uspace : Depends: python2.7-glade2 but it is not installable or python-glade2 but it is not going to be installed Depends: python-gtksourceview2 but it is not going to be installed Depends: python-vte but it is not installable Depends: python-gst0.10 but it is not installable Depends: python-xlib but it is not going to be installed Depends: python-gtkglext1 but it is not going to be installed Depends: python-configobj but it is not going to be installed Recommends: hostmot2-firmware-all but it is not installable Can anyone supply a list of python3 packages that will cover the functions contained in the above list?, and I will attempt to edit the linuxcnc srcs to use the more modern code base? Ignore the hostmot2-firmware-all package as its available, and may not be actually required with the interface card in actual use. It has its own fpga firmware already installed. Thank you all. 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) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From rosuav at gmail.com Sun Oct 13 16:22:33 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 Oct 2019 07:22:33 +1100 Subject: upgrading python on raspbian In-Reply-To: <201910130541.19512.gheskett@shentel.net> References: <201910130541.19512.gheskett@shentel.net> Message-ID: On Mon, Oct 14, 2019 at 6:38 AM Gene Heskett wrote: > > I'm not a python expert by a long ways. > > I have built the linuxcnc-master, which is the development branch of > linuxcnc, a machine control program to run most metal carving machines. > Lathes, milling machines, anything you can motorize, LinuxCNC can run. > > This requires a preempt-rt kernel which I've managed to build and > install, all on a pi-4b running raspbian buster, the armfh-v7l version > of debian 10.1. > > But linuxcnc is quite elderly code, some of it going back to before there > was a linux, so despite being actively developed right now for x86 type > hardware but has quite a list of missing dependencies I cannot satisfy > from the raspbian repos. > > They are: > > The following packages have unmet dependencies: > linuxcnc-uspace : Depends: python2.7-glade2 but it is not installable or > > Can anyone supply a list of python3 packages that will cover the > functions contained in the above list?, and I will attempt to edit the > linuxcnc srcs to use the more modern code base? So if I understand you correctly, you're not worried about actually supplying these apt packages, but you want equivalents so you can port the code itself to Py3? My recommendation would be to start with "sudo apt build-dep linuxcnc-uspace" and see if it can get any, but otherwise, just replace "python-" with "python3-" and see if that works. You may need to dig up dev packages of them though. Another option may be to just use pip to install your dependencies. That might work out easier. ChrisA From kamaldeepgupta0 at gmail.com Mon Oct 14 04:52:38 2019 From: kamaldeepgupta0 at gmail.com (KAMALDEEP GUPTA) Date: Mon, 14 Oct 2019 05:52:38 -0300 Subject: my python is not working Message-ID: From ekopalypse at gmail.com Mon Oct 14 07:37:43 2019 From: ekopalypse at gmail.com (Eko palypse) Date: Mon, 14 Oct 2019 04:37:43 -0700 (PDT) Subject: python3, regular expression and bytes text In-Reply-To: <015b2b00-342e-4f3e-9388-dde8071c8def@googlegroups.com> References: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> <015b2b00-342e-4f3e-9388-dde8071c8def@googlegroups.com> Message-ID: <68d1a5e1-198f-4c3f-878d-e97ddc48730b@googlegroups.com> Am Sonntag, 13. Oktober 2019 21:20:26 UTC+2 schrieb moi: > [Do not know why I spent hours with this...] > > To answer you question. > Yes, I confirm. > It seems that as soon as one works with bytes and when > a char is encoded in more than 1 byte, "re" goes into > troubles. > First, sorry for answering so late but I double checked my mail inbox and there is no notification that you have answered, whereas I got a notification for each of the other posts. Not sure what happened. Thx for confirmation. > Something else. > I do not like to use "\w". One can rapidly be confronted with > annoying boundary limits. A while loop can be much more "fine > grained" and it works with everything, bytes, encoded chars, > code points... As the whole idea is, maybe I should use "was" by now, to build a regex tester script, it seems to be logical to use regular expressions, isn't it. :-) Thx Eren From rosuav at gmail.com Mon Oct 14 07:55:42 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 Oct 2019 22:55:42 +1100 Subject: python3, regular expression and bytes text In-Reply-To: <68d1a5e1-198f-4c3f-878d-e97ddc48730b@googlegroups.com> References: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> <015b2b00-342e-4f3e-9388-dde8071c8def@googlegroups.com> <68d1a5e1-198f-4c3f-878d-e97ddc48730b@googlegroups.com> Message-ID: On Mon, Oct 14, 2019 at 10:41 PM Eko palypse wrote: > > Am Sonntag, 13. Oktober 2019 21:20:26 UTC+2 schrieb moi: > > [Do not know why I spent hours with this...] > > > > To answer you question. > > Yes, I confirm. > > It seems that as soon as one works with bytes and when > > a char is encoded in more than 1 byte, "re" goes into > > troubles. > > > > First, sorry for answering so late but I double checked my mail inbox and there is no notification that you have answered, whereas I got a notification for each of the other posts. Not sure what happened. > Thx for confirmation. > Is this the person who uses a forged Gmail address as his posting address? For utterly unsurprising reasons, those posts simply ARE NOT VISIBLE to a large number of people, including anyone who is themselves using Gmail. Don't use a forged address. If you want to use a fake address, use a *legitimate* fake address, such as one ending ".invalid". Or use an address at a domain that you own and control, and make sure that the appropriate security information is set (eg don't have an SPF record that says "-all"). There are lots of options. Stop abusing Gmail addresses. (My apologies for saying this in reply to an unrelated post, but I also don't see those posts, so it's not easy to reply to them.) ChrisA From ekopalypse at gmail.com Mon Oct 14 08:43:02 2019 From: ekopalypse at gmail.com (Eko palypse) Date: Mon, 14 Oct 2019 05:43:02 -0700 (PDT) Subject: python3, regular expression and bytes text In-Reply-To: References: <8d010247-8710-43d0-b49b-f205c4a4b378@googlegroups.com> <015b2b00-342e-4f3e-9388-dde8071c8def@googlegroups.com> <68d1a5e1-198f-4c3f-878d-e97ddc48730b@googlegroups.com> Message-ID: <4f0ad739-6c7e-4871-ab9a-f9edd136ac2f@googlegroups.com> Am Montag, 14. Oktober 2019 13:56:09 UTC+2 schrieb Chris Angelico: > > (My apologies for saying this in reply to an unrelated post, but I > also don't see those posts, so it's not easy to reply to them.) > > ChrisA Nothing to apologize and thank you for clarification, I was already checking my settings to see if I could have set some kind of filtering which I wasn't aware. Eren From ikorot01 at gmail.com Sun Oct 13 21:58:55 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Sun, 13 Oct 2019 20:58:55 -0500 Subject: my python is not working In-Reply-To: References: Message-ID: Hi, On Mon, Oct 14, 2019 at 5:41 AM KAMALDEEP GUPTA wrote: > > What did yu do differently than all other people Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list From lists at vanderhoff.org Mon Oct 14 10:05:47 2019 From: lists at vanderhoff.org (Tony van der Hoff) Date: Mon, 14 Oct 2019 15:05:47 +0100 Subject: my python is not working In-Reply-To: References: Message-ID: <14e23059-61ba-831b-a9e3-9495ecea5098@vanderhoff.org> On 14/10/2019 09:52, KAMALDEEP GUPTA wrote: > Mine is! -- Tony van der Hoff | mailto:tony at vanderhoff.org Buckinghamshire, England | From gheskett at shentel.net Mon Oct 14 10:52:14 2019 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 14 Oct 2019 10:52:14 -0400 Subject: upgrading python on raspbian In-Reply-To: References: <201910130541.19512.gheskett@shentel.net> Message-ID: <201910141052.14761.gheskett@shentel.net> On Sunday 13 October 2019 16:22:33 Chris Angelico wrote: > On Mon, Oct 14, 2019 at 6:38 AM Gene Heskett wrote: > > I'm not a python expert by a long ways. > > > > I have built the linuxcnc-master, which is the development branch of > > linuxcnc, a machine control program to run most metal carving > > machines. Lathes, milling machines, anything you can motorize, > > LinuxCNC can run. > > > > This requires a preempt-rt kernel which I've managed to build and > > install, all on a pi-4b running raspbian buster, the armfh-v7l > > version of debian 10.1. > > > > But linuxcnc is quite elderly code, some of it going back to before > > there was a linux, so despite being actively developed right now for > > x86 type hardware but has quite a list of missing dependencies I > > cannot satisfy from the raspbian repos. > > > > They are: > > > > The following packages have unmet dependencies: > > linuxcnc-uspace : Depends: python2.7-glade2 but it is not > > installable or > > > > Can anyone supply a list of python3 packages that will cover the > > functions contained in the above list?, and I will attempt to edit > > the linuxcnc srcs to use the more modern code base? > > So if I understand you correctly, you're not worried about actually > supplying these apt packages, but you want equivalents so you can port > the code itself to Py3? I think thats the obvious path forward. Once ported, we don't have to worry about that legacy stuff for two or 3 generations of linux. I have it building on raspbian buster-10.1 for a rpi4b right now in "uspace" mode, but missing stuff has cost us a couple of the pretty gui-faces we use with it, and I'd like to find a way around that if I could. > My recommendation would be to start with "sudo apt build-dep > linuxcnc-uspace" and see if it can get any, but otherwise, just > replace "python-" with "python3-" and see if that works. You may need > to dig up dev packages of them though. The 2 packages that are missing right now are python-gtksourceview2, and python-vte. Do they have python3 equ's? Finding python3 replacements for those 2 would take some pressure off its forward march. as far as build dep detection, dpkg-checkbuilddeps is as dumb as a rock. I've had to add at least ten packages now to get it to build, that were never detected by dpkg-checkbuilddeps. And its major stuff, like inkscape and imagemagick. checkbuilddeps is ok before a 1st build, finding 50 or so things it needed, but for major stuff, a waste of time after the first session. > Another option may be to just use pip to install your dependencies. > That might work out easier. There seems to be an underground effort to throw pip and pip3 under the bus of late. I'm wonder why? Thanks ChrisA. 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) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From rosuav at gmail.com Mon Oct 14 11:02:48 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Oct 2019 02:02:48 +1100 Subject: upgrading python on raspbian In-Reply-To: <201910141052.14761.gheskett@shentel.net> References: <201910130541.19512.gheskett@shentel.net> <201910141052.14761.gheskett@shentel.net> Message-ID: On Tue, Oct 15, 2019 at 1:53 AM Gene Heskett wrote: > > On Sunday 13 October 2019 16:22:33 Chris Angelico wrote: > > My recommendation would be to start with "sudo apt build-dep > > linuxcnc-uspace" and see if it can get any, but otherwise, just > > replace "python-" with "python3-" and see if that works. You may need > > to dig up dev packages of them though. > > The 2 packages that are missing right now are python-gtksourceview2, and > python-vte. Do they have python3 equ's? Finding python3 replacements > for those 2 would take some pressure off its forward march. Hmm. The GTK SourceView control has been a bit of a pain in previous porting jobs. You may end up needing to build something from source. Sorry :( > > Another option may be to just use pip to install your dependencies. > > That might work out easier. > > There seems to be an underground effort to throw pip and pip3 under the > bus of late. I'm wonder why? > No idea. If you're talking about the way that "python3 -m pip install ..." is preferred over "pip3 install ...", then that's due to the possibility of having multiple Pythons installed; but if you're using a virtual environment, or you're confident you have full control over your setup, you can just use the shorthand. That's still using pip, though. Just not using /usr/local/bin/pip (or equiv) to invoke it. ChrisA From torriem at gmail.com Mon Oct 14 12:00:42 2019 From: torriem at gmail.com (Michael Torrie) Date: Mon, 14 Oct 2019 10:00:42 -0600 Subject: upgrading python on raspbian In-Reply-To: <201910141052.14761.gheskett@shentel.net> References: <201910130541.19512.gheskett@shentel.net> <201910141052.14761.gheskett@shentel.net> Message-ID: <755429e7-73f5-31e5-7b1e-af96c6a5a081@gmail.com> On 10/14/19 8:52 AM, Gene Heskett wrote: > I think thats the obvious path forward. Once ported, we don't have to > worry about that legacy stuff for two or 3 generations of linux. A worthy goal and I'm sure the LinuxCNC folk would be grateful for contributions. Be aware that porting the python code is only half the problem, though. In order to make it work with Python 3, you'll have to also address the embedding issue. Python is interconnected with LinuxCNC through some generated bindings to C and also C++ code. I'm not sure what they used for the C++ bindings, maybe boost? There was some discussion of this on the bug tracker and it looks like a fairly major undertaking. See this year-old discussion: https://github.com/LinuxCNC/linuxcnc/issues/403 Whatever you do, you probably will want to discuss it on the github issue tracker to make sure efforts aren't duplicated. From ysuluhan at gmail.com Mon Oct 14 07:32:31 2019 From: ysuluhan at gmail.com (Yasin Suluhan) Date: Mon, 14 Oct 2019 13:32:31 +0200 Subject: my python is not working In-Reply-To: References: Message-ID: Thank god for that. -- Thank You. Best Regards. Yasin SULUHAN Contact Information Mobile: +31 6 86107491 On Mon, Oct 14, 2019 at 12:41 PM KAMALDEEP GUPTA wrote: > > -- > https://mail.python.org/mailman/listinfo/python-list > From torriem at gmail.com Mon Oct 14 12:21:44 2019 From: torriem at gmail.com (Michael Torrie) Date: Mon, 14 Oct 2019 10:21:44 -0600 Subject: upgrading python on raspbian In-Reply-To: <755429e7-73f5-31e5-7b1e-af96c6a5a081@gmail.com> References: <201910130541.19512.gheskett@shentel.net> <201910141052.14761.gheskett@shentel.net> <755429e7-73f5-31e5-7b1e-af96c6a5a081@gmail.com> Message-ID: <8eb7dcc9-6a4d-0978-5d3f-bfad69c32b89@gmail.com> On 10/14/19 10:00 AM, Michael Torrie wrote: > https://github.com/LinuxCNC/linuxcnc/issues/403 > > Whatever you do, you probably will want to discuss it on the github > issue tracker to make sure efforts aren't duplicated. Reading further, it appears that the binding and embedding python 3 has been worked on and functions to a certain degree, which you probably already knew. From gheskett at shentel.net Mon Oct 14 12:56:22 2019 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 14 Oct 2019 12:56:22 -0400 Subject: upgrading python on raspbian In-Reply-To: <755429e7-73f5-31e5-7b1e-af96c6a5a081@gmail.com> References: <201910130541.19512.gheskett@shentel.net> <201910141052.14761.gheskett@shentel.net> <755429e7-73f5-31e5-7b1e-af96c6a5a081@gmail.com> Message-ID: <201910141256.22208.gheskett@shentel.net> On Monday 14 October 2019 12:00:42 Michael Torrie wrote: > On 10/14/19 8:52 AM, Gene Heskett wrote: > > I think thats the obvious path forward. Once ported, we don't have > > to worry about that legacy stuff for two or 3 generations of linux. > > A worthy goal and I'm sure the LinuxCNC folk would be grateful for > contributions. Be aware that porting the python code is only half the > problem, though. In order to make it work with Python 3, you'll have > to also address the embedding issue. Python is interconnected with > LinuxCNC through some generated bindings to C and also C++ code. I'm > not sure what they used for the C++ bindings, maybe boost? I saw some of that go by in the latest builds. So I'm aware there is that, and some c++ being used here and there, but not how its all interconnected. > There was > some discussion of this on the bug tracker and it looks like a fairly > major undertaking. See this year-old discussion: > https://github.com/LinuxCNC/linuxcnc/issues/403 > > Whatever you do, you probably will want to discuss it on the github > issue tracker to make sure efforts aren't duplicated. True too. But so far, I get the feeling progress has slowed because folks are busier than in years past. But I'm not the new blood they need, mines already 85 years old, but I currently have a machine dead in the water until I at least make it work for me. I used a pi3 two years ago to run the machine, which it does that quite well but the video is best described as glacial. Now with buster we have 40x faster video, and I'm trying to upgrade to a pi4b in hopes of haveing something resembling realtime video. 1.7 fps from the pi3's framebuffer, just isn't "it". At the instant, it appears our ability to control the spi drivers com speeds, has been lost in adding 2 or more new cards that Mesa has since developed at the same time its being adapted to run on either a pi3 or a pi4. But that driver developer is a busy college prof 1/3rd of the way around this damp rock, so we're out of synch in our coms. Plus I'm also the care-giver for an injured and dying of COPD wife. Not looking for sympathy, just saying. Avoid getting old if you can, Michael, its not all its cracked up to be. 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) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From toby at tobiah.org Mon Oct 14 13:06:30 2019 From: toby at tobiah.org (Tobiah) Date: Mon, 14 Oct 2019 10:06:30 -0700 Subject: Odd delays when cwd is on a network mount References: <20191011231343.GA38770@cskk.homeip.net> Message-ID: On 10/11/19 6:04 PM, Gregory Ewing wrote: > Cameron Simpson wrote: >> Python's default sys.path includes the current working directory. > > Only in an interactive session, where it usually makes sense. > I was only using the REPL for demonstration. The same delay happens when I import a module in a script. The module file is on the local drive. I only have to have a CWD on the mounted drive to experience the 25 second delay. As I said, the mount is over a 5mb connection - it's not wildly quick but it's quite usable normally. From skip.montanaro at gmail.com Mon Oct 14 14:18:19 2019 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 14 Oct 2019 13:18:19 -0500 Subject: Odd delays when cwd is on a network mount In-Reply-To: References: <20191011231343.GA38770@cskk.homeip.net> Message-ID: > > The module file > is on the local drive. I only have to have a CWD on the mounted > drive to experience the 25 second delay. > Coming late to the party, but it sounds like the directory is further down sys.path than your current working directory (and possibly other network-mounted directories). Skip > From martin.schoon at gmail.com Mon Oct 14 15:57:06 2019 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 14 Oct 2019 19:57:06 GMT Subject: Jupyter Notebook -> PDF with A4 pages? References: Message-ID: Den 2019-10-13 skrev Piet van Oostrum : > Martin Sch??n writes: > >> Is there a way to do "Download as PDF" and get A4 pages instead >> of Letter? Yes, I know I can do "Download as LaTeX" and edit the > < snip > > Make a directory ~/.jupyter/templates and put a file A4article.tplx inside it: > > ############# > ((=- Default to the notebook output style -=)) > ((* if not cell_style is defined *)) > ((* set cell_style = 'style_jupyter.tplx' *)) > ((* endif *)) > < snip > > c.LatexExporter.template_file = 'A4article' > c.PDFExporter.latex_count = 3 > c.PDFExporter.template_file = 'A4article' > c.PDFExporter.latex_command = ['pdflatex', '{filename}'] > ############# > Replace 'pdflatex' with 'xelatex' if you prefer that. > You can leave out the c.LatexExporter.template_file line if > you don't want the LaTeX exporter to generate A4. > Thanks a lot. That worked right away -- at home but not at work. Both are Linux systems but there are differences in both Python and LaTeX installations. Shouldn't be too hard to figure out -- I hope. /Martin From lukasz at langa.pl Mon Oct 14 16:23:57 2019 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Mon, 14 Oct 2019 22:23:57 +0200 Subject: [RELEASE] Python 3.8.0 is now available Message-ID: <8D9CCDF3-9D1B-49D1-BBC1-76D13AA5074F@langa.pl> On behalf of the Python development community and the Python 3.8 release team, I?m pleased to announce the availability of Python 3.8.0. Python 3.8.0 is the newest feature release of the Python language, and it contains many new features and optimizations. You can find Python 3.8.0 here: https://www.python.org/downloads/release/python-380/ Most third-party distributors of Python should be making 3.8.0 packages available soon. See the ?What?s New in Python 3.8 ? document for more information about features included in the 3.8 series. Detailed information about all changes made in 3.8.0 can be found in its change log. Maintenance releases for the 3.8 series will follow at regular bi-monthly intervals starting in December of 2019. We hope you enjoy Python 3.8! Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation. https://www.python.org/psf/ - ? -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: Message signed with OpenPGP URL: From PythonList at DancesWithMice.info Mon Oct 14 16:55:05 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 15 Oct 2019 09:55:05 +1300 Subject: Instantiating sub-class from super Message-ID: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> Is there a technique or pattern for taking a (partially-) populated instance of a class, and re-creating it as an instance of one of its sub-classes? In a medically-oriented situation, we have a Person() class, and start collecting information within an instance (person = Person(), etc). During the data-collection process the person's sex may become obvious, eg few males have become/been pregnant. We could stick with Person() and implement specific methods therein, rather than separate Man and Woman sub-classes, but... It seemed better (at the design-level) to have Man( Person ) and Woman( Person ) sub-classes to contain the pertinent attributes, source more detailed and specific questions, and collect such data; by gender. In coding-practice, once gender becomes apparent, how should the instance of the Man() or Woman() sub-class be created - and established with the ID and other attributes previously collected as a Person instance? This attempt seems hack-y: man = Man() man.__dict__.update( person.__dict__ ) Is there a pythonic tool for such, or is the task outlined fundamentally-inappropriate? -- Regards, =dn From cs at cskk.id.au Mon Oct 14 17:52:06 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 15 Oct 2019 08:52:06 +1100 Subject: Odd delays when cwd is on a network mount In-Reply-To: References: Message-ID: <20191014215206.GA49645@cskk.homeip.net> On 14Oct2019 10:06, Tobiah wrote: >On 10/11/19 6:04 PM, Gregory Ewing wrote: >>Cameron Simpson wrote: >>>Python's default sys.path includes the current working directory. >> >>Only in an interactive session, where it usually makes sense. > >I was only using the REPL for demonstration. The same delay >happens when I import a module in a script. The module file >is on the local drive. I only have to have a CWD on the mounted >drive to experience the 25 second delay. As I said, the mount >is over a 5mb connection - it's not wildly quick but it's quite >usable normally. If it is that slow, try (assumes linux): strace python your_script It is possible you will get to see where the script stalls. May make things more obvious. It the least it will show you where the script is looking for things. Cheers, Cameron Simpson From david at lowryduda.com Mon Oct 14 18:29:11 2019 From: david at lowryduda.com (David Lowry-Duda) Date: Mon, 14 Oct 2019 18:29:11 -0400 Subject: Jupyter Notebook -> PDF with A4 pages? In-Reply-To: References: Message-ID: <20191014222911.GA1513@mail.lowryduda.com> > Is there a way to do "Download as PDF" and get A4 pages instead > of Letter? Yes, I know I can do "Download as LaTeX" and edit the > result to get A4 but if there is a setting I have missed I save > work and time. I typically use the "nbconvert" tool (that one typically installs at the same time as installing jupyter). Behind the scenes, this goes through latex (and through pandoc in particular). It seems most natural to convert to latex. One can specify a template to be used in nbconvert. See https://nbconvert.readthedocs.io/en/latest/usage.html for a bit more on this. The template is really used in the same way that templates are passed with pandoc. Alternately, if you didn't want to muck around with figuring out how to specify your own template, you could just modify the first line of the generated tex file to something like \documentclass[12pt, a4paper]{article} If you wanted a completely different (and perhaps lackluster) approach, you could just view the notebook in your favorite browser and print-to-pdf. Good luck! DLD -- David Lowry-Duda From greg.ewing at canterbury.ac.nz Mon Oct 14 18:37:09 2019 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 15 Oct 2019 11:37:09 +1300 Subject: Instantiating sub-class from super In-Reply-To: References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> Message-ID: DL Neil wrote: > Is there a technique or pattern for taking a (partially-) populated > instance of a class, and re-creating it as an instance of one of its > sub-classes? Often you can assign to the __class__ attribute of an instance to change its class. Python 3.7.3 (default, Apr 8 2019, 22:20:19) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class Person: ... pass ... >>> class Male(Person): ... pass ... >>> p = Person() >>> p.__class__ = Male >>> isinstance(p, Male) True >>> You would then be responsible for initialising any attributes of Male that Person didn't have. -- Greg From PythonList at DancesWithMice.info Mon Oct 14 20:43:59 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 15 Oct 2019 13:43:59 +1300 Subject: Instantiating sub-class from super In-Reply-To: References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> Message-ID: <6d55d3e3-8ca5-d78a-8169-5a6861cc6306@DancesWithMice.info> Hi Greg, On 15/10/19 11:37 AM, Gregory Ewing wrote: > DL Neil wrote: >> Is there a technique or pattern for taking a (partially-) populated >> instance of a class, and re-creating it as an instance of one of its >> sub-classes? > > Often you can assign to the __class__ attribute of an instance > to change its class. > > Python 3.7.3 (default, Apr? 8 2019, 22:20:19) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> class Person: > ...? pass > ... > >>> class Male(Person): > ...? pass > ... > >>> p = Person() > >>> p.__class__ = Male > >>> isinstance(p, Male) > True > >>> Brilliantly easy. Thanks! Is this manipulation documented/explained anywhere? Would you describe it as 'good practice', or even: sensible? > You would then be responsible for initialising any attributes of > Male that Person didn't have. Understood. The contents of Person.__init__( -whatever- ) are executed at instantiation. The contents of Male.__init__( - whatever- ) will be executed during a 'normal' instantiation. If, however, a Person-instance is 'converted'* into a Male-instance, then Male.__init__() will not be executed. (haven't bothered to experiment with an explicit call, because...) In this case, that is not an issue, because apart from the value of "sex", the __init__() actions are all provided by super(). Further experimentation revealed something I wasn't sure to expect. Thus although: class Male( Person ): etc class Person(): etc won't work, because Person has yet to be defined; in the correct sequence, we *can* 'anticipate' names within the super-class: class Person(): etc def convert( self ): self.__class__ = Male class Male( Person ): etc Agreed, better is: def convert( self, sub_class ): self.__class__ = sub_class ... p = Person() p.convert( Male ) Amusingly enough, could "convert"* the p-instance again-and-again. * careful terminology! PoC code: class Person(): def __init__( self ): self.ID = "Respondent" self.converter = { "M":Male, "F":Female } def questionnaire( self, sex ): self.sex = sex def super_function( self ): print( "Pulling on tights and donning cape..." ) def convert( self ): self.__class__ = self.converter[ self.sex ] class Male( Person ): def male_only( self ): print( "I am secure in my man-hood" ) class Female( Person ): def female_only( self ): print( "Thy name is vanity" ) p = Person() print( "PersonOBJ ~", p ) print( "Person __class__ ~", p.__class__ ) print( "PersonID ~", p.ID ) p.questionnaire( "M" ) print( "M, MaleOBJ ~", p.sex, p.converter[ p.sex ] ) p.convert() print( "PersonOBJ ~", p ) print( "Person __class__ ~", p.__class__ ) print( "PersonID ~", p.ID ) p.male_only() p.super_function() p.questionnaire( "F" ) print( "F, FemaleOBJ ~", p.sex, p.converter[ p.sex ] ) p.convert() print( "PersonOBJ ~", p ) print( "Person __class__ ~", p.__class__ ) print( "PersonID ~", p.ID ) p.female_only() p.super_function() p.male_only() # Exception Output: Showing that: - the object remains the same, even as its type/class is 'converted' - the object retains any value established before 'conversion' or, the 'conversion' process carries-across all data-attributes - after conversion the sub-class's methods become available - after conversion the super-class's methods remain available - after a further 'conversion', the same experience but methods particular to the first conversion have been 'lost'. (as expected) [~]$ python3 person.py PersonOBJ ~ <__main__.Person object at 0x7f014085bdd0> Person __class__ ~ PersonID ~ Respondent M, MaleOBJ ~ M PersonOBJ ~ <__main__.Male object at 0x7f014085bdd0> Person __class__ ~ PersonID ~ Respondent I am secure in my man-hood Pulling on tights and donning cape... F, FemaleOBJ ~ F PersonOBJ ~ <__main__.Female object at 0x7f014085bdd0> Person __class__ ~ PersonID ~ Respondent Thy name is vanity Pulling on tights and donning cape... Traceback (most recent call last): File "person.py", line 58, in p.male_only() # Exception AttributeError: 'Female' object has no attribute 'male_only' -- Regards =dn From wesp at outrelay.com Mon Oct 14 21:45:22 2019 From: wesp at outrelay.com (Wesley Peng) Date: Tue, 15 Oct 2019 01:45:22 +0000 (UTC) Subject: [RELEASE] Python 3.8.0 is now available In-Reply-To: <8D9CCDF3-9D1B-49D1-BBC1-76D13AA5074F@langa.pl> References: <8D9CCDF3-9D1B-49D1-BBC1-76D13AA5074F@langa.pl> Message-ID: <3f7c65c6-947d-5c9b-a1bf-4750b9e731cd@outrelay.com> awesome news. thanks for all the hard work. on 2019/10/15 4:23, ?ukasz Langa wrote: > We hope you enjoy Python 3.8! > > Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation. From gheskett at shentel.net Tue Oct 15 01:30:59 2019 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 15 Oct 2019 01:30:59 -0400 Subject: upgrading python on raspbian In-Reply-To: <201910141256.22208.gheskett@shentel.net> References: <201910130541.19512.gheskett@shentel.net> <755429e7-73f5-31e5-7b1e-af96c6a5a081@gmail.com> <201910141256.22208.gheskett@shentel.net> Message-ID: <201910150130.59464.gheskett@shentel.net> On Monday 14 October 2019 12:56:22 Gene Heskett wrote: Continueing this thread, I now have a missing function by name, "units", that is preventing LinuxCNC from running. Where in the python 3 world do I find that function?, which in this case controls what it is fed on to a pyvcp display according to a logic signal that tells it whether the machine is in inches mode, or mm mode? Its in some of the gingerbread video code I do in the after postgui.hal file, that takes the number of degrees that the spindle has overshot the stop and reverse command due to the inertia of a 50 lb chuck, and converts that into either inches or mm's of carriage (z axis) overtravel, so I can subtract that when I am tapping a hole, and not subtracting it from the depth of threads I'm programming would run the tap into the bottom of the hole breaking it off in the hole. Thats an expense no one needs. Not only is the tap broken, it takes a good part of a day to setup an EDM lashup and EDM the central core of tap out, leaving the teeth strips to be picked out of the hole with tweezers. The hole is still tapped and won't be damaged, and a part that may cost hundreds of dollars is saved. But its far better to not make that mistake in the first place. So where do I find a new "units"? Thanks all. 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) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From piet-l at vanoostrum.org Tue Oct 15 03:51:39 2019 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Tue, 15 Oct 2019 09:51:39 +0200 Subject: Jupyter Notebook -> PDF with A4 pages? References: Message-ID: Martin Sch??n writes: > Den 2019-10-13 skrev Piet van Oostrum : >> Martin Sch??n writes: >> >>> Is there a way to do "Download as PDF" and get A4 pages instead >>> of Letter? Yes, I know I can do "Download as LaTeX" and edit the >> > < snip > > >> Make a directory ~/.jupyter/templates and put a file A4article.tplx inside it: >> >> ############# >> ((=- Default to the notebook output style -=)) >> ((* if not cell_style is defined *)) >> ((* set cell_style = 'style_jupyter.tplx' *)) >> ((* endif *)) >> > < snip > > >> c.LatexExporter.template_file = 'A4article' >> c.PDFExporter.latex_count = 3 >> c.PDFExporter.template_file = 'A4article' >> c.PDFExporter.latex_command = ['pdflatex', '{filename}'] >> ############# >> Replace 'pdflatex' with 'xelatex' if you prefer that. >> You can leave out the c.LatexExporter.template_file line if >> you don't want the LaTeX exporter to generate A4. >> > Thanks a lot. > > That worked right away -- at home but not at work. Both are > Linux systems but there are differences in both Python and > LaTeX installations. Shouldn't be too hard to figure out -- > I hope. > > /Martin What does this report? Compare if there is a difference between home and work. from jupyter_core.paths import jupyter_path print(jupyter_path('notebook','templates')) And maybe also print(jupyter_path('nbconvert','templates')) -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From antoon.pardon at vub.be Tue Oct 15 07:38:28 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 15 Oct 2019 13:38:28 +0200 Subject: Curious about library inclusion In-Reply-To: <63ff2313-04ec-82ab-eaa6-b2c581024e17@kynesim.co.uk> References: <334de038-4319-f12f-e39b-c3161bf2ec4e@vub.be> <63ff2313-04ec-82ab-eaa6-b2c581024e17@kynesim.co.uk> Message-ID: On 11/10/19 15:48, Rhodri James wrote: > On 10/10/2019 12:40, Antoon Pardon wrote: >> About including piped iterators: >> ???? >> http://code.activestate.com/recipes/580625-collection-pipeline-in-python/ >> >> On 10/10/19 13:00, Paul Moore wrote: >>> As another measure, look at various other libraries on PyPI and ask >>> yourself why *this* library needs to be in the stdlib more than those >>> others. The answer to that question would be a good start for an >>> argument to include the library. >> >> Well my answer would be that this library wouldn't add functionality >> but rather would allow IMO for a more readable coding style. >> >> If you split the work to be done over mulitple generators I find it >> easier to understand when I read something like: >> >> ???? for item in some_file | gen1 | gen2 | gen3: >> ???????? ... >> >> than when I read something like: >> >> ???? for item in gen3(gen2(gen1(somefile))): >> ???????? ... > > With my ever-so-reactionary hat on, I have to say I'm the other way > round.? With "gen3(gen2(gen1(somefile)))" it's pretty obvious what's > going on -- nested function or generator calls, probably the latter > from the name.? With "somefile|gen1|gen2|gen3" I need more context to > kick my expectations out of the more common meaning of "|" as "or". > > Yes, context demands that the "|" in your first example can't actually > be an "or".? It still causes a moment of logical disconnect (currently > a long moment) that throws me out of understanding what your code is > doing overall into what this line means in particular.? It's exactly > like coming across an unusual phrasing or iffy grammar in a piece of > writing; you get thrown out of the reading experience by having to > concentrate on the individual words. But isn't this just a matter of experience? For example does it still causes a moment of logical disconnect when you see a '+' used for concatenation? For me the use of '|' is very similar to how it is used by unix shells. Would the use of an other operator ease this disconnect for you, maybe '>>', or wouldn't that make a difference? -- Antoon. From rhodri at kynesim.co.uk Tue Oct 15 07:59:58 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 15 Oct 2019 12:59:58 +0100 Subject: Curious about library inclusion In-Reply-To: References: <334de038-4319-f12f-e39b-c3161bf2ec4e@vub.be> <63ff2313-04ec-82ab-eaa6-b2c581024e17@kynesim.co.uk> Message-ID: On 15/10/2019 12:38, Antoon Pardon wrote: > On 11/10/19 15:48, Rhodri James wrote: >> On 10/10/2019 12:40, Antoon Pardon wrote: >>> About including piped iterators: >>> >>> http://code.activestate.com/recipes/580625-collection-pipeline-in-python/ >>> >>> On 10/10/19 13:00, Paul Moore wrote: >>>> As another measure, look at various other libraries on PyPI and ask >>>> yourself why *this* library needs to be in the stdlib more than those >>>> others. The answer to that question would be a good start for an >>>> argument to include the library. >>> >>> Well my answer would be that this library wouldn't add functionality >>> but rather would allow IMO for a more readable coding style. >>> >>> If you split the work to be done over mulitple generators I find it >>> easier to understand when I read something like: >>> >>> ???? for item in some_file | gen1 | gen2 | gen3: >>> ???????? ... >>> >>> than when I read something like: >>> >>> ???? for item in gen3(gen2(gen1(somefile))): >>> ???????? ... >> >> With my ever-so-reactionary hat on, I have to say I'm the other way >> round.? With "gen3(gen2(gen1(somefile)))" it's pretty obvious what's >> going on -- nested function or generator calls, probably the latter >> from the name.? With "somefile|gen1|gen2|gen3" I need more context to >> kick my expectations out of the more common meaning of "|" as "or". >> >> Yes, context demands that the "|" in your first example can't actually >> be an "or".? It still causes a moment of logical disconnect (currently >> a long moment) that throws me out of understanding what your code is >> doing overall into what this line means in particular.? It's exactly >> like coming across an unusual phrasing or iffy grammar in a piece of >> writing; you get thrown out of the reading experience by having to >> concentrate on the individual words. > > But isn't this just a matter of experience? For example does it still > causes a moment of logical disconnect when you see a '+' used for > concatenation? For me the use of '|' is very similar to how it is used > by unix shells. Would the use of an other operator ease this disconnect > for you, maybe '>>', or wouldn't that make a difference? I *could* get used to any syntax, but why should I? We have syntax that works perfectly well already. Making me go to the extra effort of importing shell-style pipes or C++-style streams into my mental construct of Python doesn't really seem necessary. (As it happens, I don't think the use of "+" for concatenation did cause me a moment of disconnection, because it already fitted into my mental model. I do recall that's Perl's choice of "." as the concatenation operator *did* cause me to stop and reevaluate quite a lot. People are weird :-) -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Tue Oct 15 07:38:39 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 15 Oct 2019 12:38:39 +0100 Subject: Instantiating sub-class from super In-Reply-To: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> Message-ID: <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> On 14/10/2019 21:55, DL Neil via Python-list wrote: > Is there a technique or pattern for taking a (partially-) populated > instance of a class, and re-creating it as an instance of one of its > sub-classes? > > > In a medically-oriented situation, we have a Person() class, and start > collecting information within an instance (person = Person(), etc). > > During the data-collection process the person's sex may become obvious, > eg few males have become/been pregnant. > > We could stick with Person() and implement specific methods therein, > rather than separate Man and Woman sub-classes, but... > > It seemed better (at the design-level) to have Man( Person ) and Woman( > Person ) sub-classes to contain the pertinent attributes, source more > detailed and specific questions, and collect such data; by gender. Knowing a lot of Trans people as I do, may I gently suggest that this solution will find many and varied ways of coming back to bite you? -- Rhodri James *-* Kynesim Ltd From dml.cn.8 at gmail.com Tue Oct 15 11:57:04 2019 From: dml.cn.8 at gmail.com (Damla Pehlivan) Date: Tue, 15 Oct 2019 18:57:04 +0300 Subject: Hello, I need help. Message-ID: Dear Python Team, First, I would like to introduce myself. My name is Damla Pehlivan, and I live in Ankara/Turkey. I am a university student at Ankara University. My major is Biology; therefore, I want to learn Python to use for Data Science. When I researched and asked my professors, they suggested me to learn Python. Sadly, I am quite a beginner but I downloaded the python program, and I also downloaded Pycharm to use it. To be fair, I do not know what I am doing, but I made some progress last night and I was happy about it. Today when I came back from university, I realised the program was updated, I updated it and now I cannot use it. When I clicked on it, it kept opening the modify tab. I did modify it and repaired it. But it kept not opening the actual program. I am writing this mail quite emotionally. I asked a new "friend" for help, but he laughed. He said it was because I am a girl and this is why I could not do it. I want to prove to him and the whole world that I can do it. I have a lesson next Monday, so could you please help me with my problem? With kindest regards From ikorot01 at gmail.com Tue Oct 15 13:04:05 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 15 Oct 2019 12:04:05 -0500 Subject: Hello, I need help. In-Reply-To: References: Message-ID: Hi, Are you trying to run your program, PyCharm, or the python console? Thank you. On Tue, Oct 15, 2019 at 12:01 PM Damla Pehlivan wrote: > > Dear Python Team, > First, I would like to introduce myself. My name is Damla Pehlivan, and I > live in Ankara/Turkey. I am a university student at Ankara University. My > major is Biology; therefore, I want to learn Python to use for Data > Science. When I researched and asked my professors, they suggested me to > learn Python. > Sadly, I am quite a beginner but I downloaded the python program, and I > also downloaded Pycharm to use it. To be fair, I do not know what I am > doing, but I made some progress last night and I was happy about it. Today > when I came back from university, I realised the program was updated, I > updated it and now I cannot use it. When I clicked on it, it kept opening > the modify tab. I did modify it and repaired it. But it kept not opening > the actual program. > I am writing this mail quite emotionally. I asked a new "friend" for help, > but he laughed. He said it was because I am a girl and this is why I could > not do it. I want to prove to him and the whole world that I can do it. I > have a lesson next Monday, so could you please help me with my problem? > With > kindest regards > -- > https://mail.python.org/mailman/listinfo/python-list From gheskett at shentel.net Tue Oct 15 13:16:42 2019 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 15 Oct 2019 13:16:42 -0400 Subject: upgrading python on raspbian In-Reply-To: <3tnbqe1urmhk04uug6bffeh58r9jneq292@4ax.com> References: <201910130541.19512.gheskett@shentel.net> <201910150130.59464.gheskett@shentel.net> <3tnbqe1urmhk04uug6bffeh58r9jneq292@4ax.com> Message-ID: <201910151316.42442.gheskett@shentel.net> On Tuesday 15 October 2019 11:10:41 Dennis Lee Bieber wrote: > On Tue, 15 Oct 2019 01:30:59 -0400, Gene Heskett > > > declaimed the following: > >On Monday 14 October 2019 12:56:22 Gene Heskett wrote: > > > >Continueing this thread, I now have a missing function by name, > > "units", that is preventing LinuxCNC from running. > > > >Where in the python 3 world do I find that function?, which in this > > case controls what it is fed on to a pyvcp display according to a > > logic signal that tells it whether the machine is in inches mode, or > > mm mode? > > Well, search your sources for where it is first referenced... > > There can only be three "hiding places" for a bare units() function. > > Local file: > > def units(...): > ... > > Imported module: > > from module import units > or > import module > units = module.units > > Any other usage should be qualified... > > something.units(...) > > I think the hal interpretor hides all that from the user. I've since discovered the raspbian-10.1 repo has a "units" but I don't think its what hal is looking for when it encounters a "loadusr units" command in the config file, and apparently its a silent error. I've now installed the repo's version, and am rebuilding LinuxCNC right now just to see if it now finds it. > > I'd suspect you have the "from m import f" form somewhere, in which > case you now need to find out what has changed in module "m" that > resulted in removing the function. > > NOTE: "from m import *" would not explicitly list it -- which means > you need to compare any module using such a * import for changes from > the version that used to work. > Sounds like not fun. :) Thanks Dennis. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ 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) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From pkpearson at nowhere.invalid Tue Oct 15 13:48:33 2019 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 15 Oct 2019 17:48:33 GMT Subject: Hello, I need help. References: Message-ID: On Tue, 15 Oct 2019 18:57:04 +0300, Damla Pehlivan wrote: [snip] > . . . I downloaded the python program, and I > also downloaded Pycharm to use it. To be fair, I do not know what I am > doing, but I made some progress last night and I was happy about it. Today > when I came back from university, I realised the program was updated, I > updated it and now I cannot use it. When I clicked on it, it kept opening > the modify tab. I did modify it and repaired it. But it kept not opening > the actual program. A clearer description of your situation would improve your odds of getting a useful result. For starters, what operating system are you using? What application presents the "modify tab" that you mention? Is this perhaps a problem with your software-installing process, rather than with Python or with Pycharm? Have you found a good Python tutorial? -- To email me, substitute nowhere->runbox, invalid->com. From noah at pycon.or.tz Tue Oct 15 13:59:12 2019 From: noah at pycon.or.tz (Noah .) Date: Tue, 15 Oct 2019 20:59:12 +0300 Subject: UG Announcement - Python Tanzania Community Message-ID: Dear Listers, As per requirements, we are pleased to announce the existence of the Python language community in Tanzania. Please find below some information and the current developments. *User Group Details;* Name: Python Community Tanzania Mailing list: https://mail.python.org/mailman3/lists/tanzania.python.org/ Under Other: Africa First Local Meetings Held: Yes *Meetings and Events;* Name: PyCon Tanzania Website: pycon.or.tz Github: https://github.com/pycontanzania Under Other: Africa Organizing Members: 5 - 10 Goal and motivation: To build and sustain while bringing together and growing the Python language users and community in Tanzania through Python related meetups, workshops and annual events. FWIW, Tanzania is a peaceful nation formed out of the political union between (Tanganyika and Zanzibar ) in the East African Region. The land of the Serengeti Game Park and the tallest mountain in Africa, the Kilimanjaro. For more about Tanzania [1] http://www.tanzania.go.tz/home/pages/68 Cheers, Noah Community Moderator https://twitter.com/PyconTanzania From piet-l at vanoostrum.org Tue Oct 15 14:32:46 2019 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Tue, 15 Oct 2019 20:32:46 +0200 Subject: Hello, I need help. References: Message-ID: Damla Pehlivan writes: > Dear Python Team, [...] > I am writing this mail quite emotionally. I asked a new "friend" for help, > but he laughed. He said it was because I am a girl and this is why I could > not do it. I want to prove to him and the whole world that I can do it. I > have a lesson next Monday, so could you please help me with my problem? That is very nasty. Fortunately Python is not gender-sensitive. What Operating system do you use? I suppose it probably is Windows or Linux. And did you use the installer from www.python.org? These have an IDE that is called IDLE. It is simpler than Pycharm, but it can do the job. So you can try that. If that also gives an error you could try to reinstall Python. If you are familiar with the command line, then that is also a possibility. -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From nad at python.org Tue Oct 15 16:06:01 2019 From: nad at python.org (Ned Deily) Date: Tue, 15 Oct 2019 16:06:01 -0400 Subject: [RELEASE] Python 3.7.5 is now available Message-ID: Python 3.7.5 is now available, the next maintenance release of Python 3.7. You can find the release files, a link to the changelog, and more information here: https://www.python.org/downloads/release/python-375/ Note that the next feature release of Python 3, Python 3.8.0, is also now available. Python 3.8 contains many new features and optimizations. You should consider upgrading to it. We plan to continue regular bugfix releases of Python 3.7.x through mid-year 2020 and provide security fixes for it until mid-year 2023. More details are available in PEP 537, the Python 3.7 Release Schedule (https://www.python.org/dev/peps/pep-0537/). Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation. -- Ned Deily nad at python.org -- [] From PythonList at DancesWithMice.info Tue Oct 15 16:36:21 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 16 Oct 2019 09:36:21 +1300 Subject: Instantiating sub-class from super In-Reply-To: <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> Message-ID: <4106c84e-ab10-e50c-6f23-70998c871b7a@DancesWithMice.info> On 16/10/19 12:38 AM, Rhodri James wrote: > On 14/10/2019 21:55, DL Neil via Python-list wrote: ... >> It seemed better (at the design-level) to have Man( Person ) and >> Woman( Person ) sub-classes to contain the pertinent attributes, >> source more detailed and specific questions, and collect such data; by >> gender. > > Knowing a lot of Trans people as I do, may I gently suggest that this > solution will find many and varied ways of coming back to bite you? [with more respect than the previous humor] You are absolutely correct. The use-case was (over-)simplified, per list-advice. That said, if a "trans" person has ovaries or testes (for example) then a non-traditional sexual identification is irrelevant - for medical purposes. Diseases in those areas (and now I'm a long way from a research questionnaire and from Python - but this is roughly how it was explained to me) still apply, and sadly, may in-fact be considerably complicated by any medical processes that may have contributed to a transition. So, yes, the "label" is unimportant - except to politicians and statisticians, who want precise answers from vague collections of data... (sigh!) FYI: This country has been leading the way, to the point where even asking such questions is no longer allowed under many circumstances. Back to Python: yes, the model is considerably complicated because there are no 'straight lines' to divide - that, and the rather arcane DB-structure we've inherited (which contributed to pilot-ing the sub-class route) are leading us back to the idea of a 'monolithic' Person class* with loads of data-points/flags and conditional-executions, to take care of individual differences and meeting the (medical) objectives of the questionnaire. Perhaps one of the physicians will prescribe a head-ache remedy? * without denigrating the generosity of those who helped with the OP -- Regards =dn From cousinstanley at gmail.com Tue Oct 15 20:02:58 2019 From: cousinstanley at gmail.com (Cousin Stanley) Date: Tue, 15 Oct 2019 17:02:58 -0700 Subject: question about making an App for Android References: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> Message-ID: Chris Angelico wrote: > Or.... maybe it's really simple, because there's an HTTP API >that > gives you the information. > > There's an API for everything these days. > > A quick web search showed up this: > > https://sunrise-sunset.org/api > .... There is also a useful python package called sunset which I fouund a reference to on stackoverflow .... https://stackoverflow.com/questions/38986527/sunrise-and-sunset-time-in-python/38986561 # pip3 install sunset # pip 3 show sunset os pip3 show suntime Name: suntime Version: 1.2.5 Summary: Simple sunset and sunrise time calculation python library Home-page: https://github.com/SatAgro/suntime Author: Krzysztof Stopa Author-email: None License: LGPLv3 Location: /usr/local/lib/python3.7/dist-packages Requires: python-dateutil Required-by: If latidude and longitude are known sunrise and sunset times are available .... $ cat daylight_phoenix.py #!/usr/bin/env python3 ''' NewsGroup .... comp.lang.python Subject ...... question about maiking an App for Android Date ......... 2019-10-10 Post_By ...... pyotr filipivich Code_By ...... Stanley C. Kitching Code_Date .... 2019-10-10 ''' import time import datetime as dt from suntime import Sun , SunTimeException # Phoenix, Arizona latitude = 33.4484 # ? N longitude = 112.0740 # ? W sun = Sun( latitude , longitude ) # Get today's sunrise and sunset in UTC sunrise = sun.get_sunrise_time() sunset = sun.get_sunset_time() sse_sunrise = sunrise.timestamp() # sunrise seconds since epoch sse_sunset = sunset.timestamp() # sunset seconds since epoch d_sse = sse_sunset - sse_sunrise # seconds of daylight print( '\n Today in Phoenix ....' ) print( '\n sunrise : ' , sunrise , ' ' , sse_sunrise ) print( '\n sunset : ' , sunset , ' ' , sse_sunset ) print( '\n daylight : {} seconds '.format( d_sse ) ) # ----------------------------------------------------------------- -- Stanley C. Kitching Human Being Phoenix, Arizona From cousinstanley at gmail.com Tue Oct 15 20:14:40 2019 From: cousinstanley at gmail.com (Cousin Stanley) Date: Tue, 15 Oct 2019 17:14:40 -0700 Subject: question about making an App for Android References: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> Message-ID: Cousin Stanley wrote: > .... > d_sse = sse_sunset - sse_sunrise # seconds of daylight > .... I think it might be required to convert utc time to local time for the difference in sunrise and sunset times to make sense in local time .... -- Stanley C. Kitching Human Being Phoenix, Arizona From HooDunnit at didly42KahZidly.net Tue Oct 15 20:18:30 2019 From: HooDunnit at didly42KahZidly.net (Cousin Stanley) Date: Tue, 15 Oct 2019 17:18:30 -0700 Subject: question about making an App for Android References: <49kupe93m53gr8diocon3dttptcsb7ufqd@4ax.com> Message-ID: Cousin Stanley wrote: > There is also a useful python package > called sunset which I fouund a reference to > on stackoverflow .... Maybe I'll wake up some time today :-) The python package is called suntime not sunset .... # pip3 show suntime -- Stanley C. Kitching Human Being Phoenix, Arizona From duncan at invalid.invalid Tue Oct 15 20:55:27 2019 From: duncan at invalid.invalid (duncan smith) Date: Wed, 16 Oct 2019 01:55:27 +0100 Subject: Instantiating sub-class from super In-Reply-To: References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> <4106c84e-ab10-e50c-6f23-70998c871b7a@DancesWithMice.info> Message-ID: <4UtpF.44322$KB2.25487@fx02.iad> On 15/10/2019 21:36, DL Neil wrote: > On 16/10/19 12:38 AM, Rhodri James wrote: >> On 14/10/2019 21:55, DL Neil via Python-list wrote: > ... > >>> It seemed better (at the design-level) to have Man( Person ) and >>> Woman( Person ) sub-classes to contain the pertinent attributes, >>> source more detailed and specific questions, and collect such data; >>> by gender. >> >> Knowing a lot of Trans people as I do, may I gently suggest that this >> solution will find many and varied ways of coming back to bite you? > > > [with more respect than the previous humor] > > > You are absolutely correct. The use-case was (over-)simplified, per > list-advice. > > That said, if a "trans" person has ovaries or testes (for example) then > a non-traditional sexual identification is irrelevant - for medical > purposes. Diseases in those areas (and now I'm a long way from a > research questionnaire and from Python - but this is roughly how it was > explained to me) still apply, and sadly, may in-fact be considerably > complicated by any medical processes that may have contributed to a > transition. > > So, yes, the "label" is unimportant - except to politicians and > statisticians, who want precise answers from vague collections of > data... (sigh!) > [snip] No not (real) statisticians. People often want us to provide precise answers, but they don't often get them. "It ain?t what you don?t know that gets you into trouble. It?s what you know for sure that just ain?t so." (Mark Twain - perhaps) Duncan From PythonList at DancesWithMice.info Tue Oct 15 23:41:19 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 16 Oct 2019 16:41:19 +1300 Subject: Instantiating sub-class from super In-Reply-To: <4UtpF.44322$KB2.25487@fx02.iad> References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> <4106c84e-ab10-e50c-6f23-70998c871b7a@DancesWithMice.info> <4UtpF.44322$KB2.25487@fx02.iad> Message-ID: <43e5875d-88a2-154e-7716-d39f40f6dd0a@DancesWithMice.info> On 16/10/19 1:55 PM, duncan smith wrote: > On 15/10/2019 21:36, DL Neil wrote: >> On 16/10/19 12:38 AM, Rhodri James wrote: >>> On 14/10/2019 21:55, DL Neil via Python-list wrote: >> ... >> So, yes, the "label" is unimportant - except to politicians and >> statisticians, who want precise answers from vague collections of >> data... (sigh!) >> > > [snip] > > No not (real) statisticians. People often want us to provide precise > answers, but they don't often get them. > > "It ain?t what you don?t know that gets you into trouble. It?s what you > know for sure that just ain?t so." (Mark Twain - perhaps) +1 Although, you've undoubtedly heard people attempt to make claims of having 'accurate figures' (even, "that came from Stats") when you told them that the limitations and variations rendered the exercise laughable... My favorite (of the moment) is a local computer store who regularly offer such gems as: (underneath the sales (web-) page for an upmarket *desktop* computer) "people who bought this also bought" followed by at least two portable PC carry cases. They must be rather large carry-bags! (along with such surprises as keyboard, mouse, ...) This morning I turned-down a study for a political group. One study has already been completed and presented. The antagonist wanted an A/B comparison (backing his 'side', of course). I mildly suggested that I would do it, if he'd also pay me to do an A/B/C study, where 'C' was a costing - the economic opportunity cost of 'the people' waiting for 'the government' to make a decision - (and delaying that decision by waiting for "study" after "study" - The UK and their (MPs') inability to decide "Brexit" a particularly disastrous illustration of such) Sorry, don't want to incur the anger of the list-gods - such calculations would be performed in Python (of course) -- Regards =dn From frank at chagford.com Wed Oct 16 01:33:38 2019 From: frank at chagford.com (Frank Millman) Date: Wed, 16 Oct 2019 07:33:38 +0200 Subject: Instantiating sub-class from super In-Reply-To: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> Message-ID: <35ce3570-9473-c128-9a21-27d1873320d3@chagford.com> On 2019-10-14 10:55 PM, DL Neil via Python-list wrote: > Is there a technique or pattern for taking a (partially-) populated > instance of a class, and re-creating it as an instance of one of its > sub-classes? > > > In a medically-oriented situation, we have a Person() class, and start > collecting information within an instance (person = Person(), etc). > > During the data-collection process the person's sex may become obvious, > eg few males have become/been pregnant. > > We could stick with Person() and implement specific methods therein, > rather than separate Man and Woman sub-classes, but... > > It seemed better (at the design-level) to have Man( Person ) and Woman( > Person ) sub-classes to contain the pertinent attributes, source more > detailed and specific questions, and collect such data; by gender. > > In coding-practice, once gender becomes apparent, how should the > instance of the Man() or Woman() sub-class be created - and established > with the ID and other attributes previously collected as a Person instance? > > This attempt seems hack-y: > > ????man = Man() > ????man.__dict__.update( person.__dict__ ) > > > Is there a pythonic tool for such, or is the task outlined > fundamentally-inappropriate? > Here is a link to an article entitled 'Understanding Hidden Subtypes'. It dates back to 2004, but I think it is still relevant. It addresses precisely the issues that you raise, but from a data-modelling perspective, not a programming one. http://tdan.com/understanding-hidden-subtypes/5193 I found it invaluable, and applied the concepts in my own business/accounting application. Having created the ability to make subtypes visible and explicit, I found all kinds of unexpected uses for them. The article seems to be missing a couple of images (Figure 1 and Figure 2) showing the data relationships. I downloaded the original article onto my computer years ago, and my local copy does have the images, so if you would like to see them let me know and I will upload my version somewhere to make it accessible. Frank Millman From frank at chagford.com Wed Oct 16 01:33:38 2019 From: frank at chagford.com (Frank Millman) Date: Wed, 16 Oct 2019 07:33:38 +0200 Subject: Instantiating sub-class from super In-Reply-To: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> Message-ID: <35ce3570-9473-c128-9a21-27d1873320d3@chagford.com> On 2019-10-14 10:55 PM, DL Neil via Python-list wrote: > Is there a technique or pattern for taking a (partially-) populated > instance of a class, and re-creating it as an instance of one of its > sub-classes? > > > In a medically-oriented situation, we have a Person() class, and start > collecting information within an instance (person = Person(), etc). > > During the data-collection process the person's sex may become obvious, > eg few males have become/been pregnant. > > We could stick with Person() and implement specific methods therein, > rather than separate Man and Woman sub-classes, but... > > It seemed better (at the design-level) to have Man( Person ) and Woman( > Person ) sub-classes to contain the pertinent attributes, source more > detailed and specific questions, and collect such data; by gender. > > In coding-practice, once gender becomes apparent, how should the > instance of the Man() or Woman() sub-class be created - and established > with the ID and other attributes previously collected as a Person instance? > > This attempt seems hack-y: > > ????man = Man() > ????man.__dict__.update( person.__dict__ ) > > > Is there a pythonic tool for such, or is the task outlined > fundamentally-inappropriate? > Here is a link to an article entitled 'Understanding Hidden Subtypes'. It dates back to 2004, but I think it is still relevant. It addresses precisely the issues that you raise, but from a data-modelling perspective, not a programming one. http://tdan.com/understanding-hidden-subtypes/5193 I found it invaluable, and applied the concepts in my own business/accounting application. Having created the ability to make subtypes visible and explicit, I found all kinds of unexpected uses for them. The article seems to be missing a couple of images (Figure 1 and Figure 2) showing the data relationships. I downloaded the original article onto my computer years ago, and my local copy does have the images, so if you would like to see them let me know and I will upload my version somewhere to make it accessible. Frank Millman From antoon.pardon at vub.be Wed Oct 16 03:25:03 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 16 Oct 2019 09:25:03 +0200 Subject: Curious about library inclusion In-Reply-To: References: <334de038-4319-f12f-e39b-c3161bf2ec4e@vub.be> <63ff2313-04ec-82ab-eaa6-b2c581024e17@kynesim.co.uk> Message-ID: On 15/10/19 13:59, Rhodri James wrote: > On 15/10/2019 12:38, Antoon Pardon wrote: >> On 11/10/19 15:48, Rhodri James wrote: >>> On 10/10/2019 12:40, Antoon Pardon wrote: >>>> About including piped iterators: >>>> ???? >>>> http://code.activestate.com/recipes/580625-collection-pipeline-in-python/ >>>> >>>> On 10/10/19 13:00, Paul Moore wrote: >>>>> As another measure, look at various other libraries on PyPI and ask >>>>> yourself why *this* library needs to be in the stdlib more than those >>>>> others. The answer to that question would be a good start for an >>>>> argument to include the library. >>>> >>>> Well my answer would be that this library wouldn't add functionality >>>> but rather would allow IMO for a more readable coding style. >>>> >>>> If you split the work to be done over mulitple generators I find it >>>> easier to understand when I read something like: >>>> >>>> ????? for item in some_file | gen1 | gen2 | gen3: >>>> ????????? ... >>>> >>>> than when I read something like: >>>> >>>> ????? for item in gen3(gen2(gen1(somefile))): >>>> ????????? ... >>> >>> With my ever-so-reactionary hat on, I have to say I'm the other way >>> round.? With "gen3(gen2(gen1(somefile)))" it's pretty obvious what's >>> going on -- nested function or generator calls, probably the latter >>> from the name.? With "somefile|gen1|gen2|gen3" I need more context to >>> kick my expectations out of the more common meaning of "|" as "or". >>> >>> Yes, context demands that the "|" in your first example can't actually >>> be an "or".? It still causes a moment of logical disconnect (currently >>> a long moment) that throws me out of understanding what your code is >>> doing overall into what this line means in particular.? It's exactly >>> like coming across an unusual phrasing or iffy grammar in a piece of >>> writing; you get thrown out of the reading experience by having to >>> concentrate on the individual words. >> >> But isn't this just a matter of experience? For example does it still >> causes a moment of logical disconnect when you see a '+' used for >> concatenation? For me the use of '|' is very similar to how it is used >> by unix shells. Would the use of an other operator ease this disconnect >> for you, maybe '>>', or wouldn't that make a difference? > > I *could* get used to any syntax, but why should I?? We have syntax > that works perfectly well already.? Making me go to the extra effort > of importing shell-style pipes or C++-style streams into my mental > construct of Python doesn't really seem necessary. In light of Python's history, I find this a strange argument. A lot of the features in current Python are inspired by things from other languages and where not necessary. We had syntax and semantics that worked perfectly well. That didn't stop anyone from introducing things they thought could benefit the language. But it seems that at this moment there is little enthusiasm for this idea, so this was my final contribution in this thread. -- Antoon. From atesfalem at gmail.com Wed Oct 16 06:19:27 2019 From: atesfalem at gmail.com (Tesfalem Abraham) Date: Wed, 16 Oct 2019 03:19:27 -0700 (PDT) Subject: installing libraries Message-ID: <6e9c8b4d-a13c-4def-a721-13ee1a02412e@googlegroups.com> hello users, Here, I tried to start python 2.7 (spider) but I could not install or add my lib to the working area. I do appreciate your suggestions for me. thanks. From bluebox03 at gmail.com Wed Oct 16 08:17:25 2019 From: bluebox03 at gmail.com (tommy yama) Date: Wed, 16 Oct 2019 21:17:25 +0900 Subject: installing libraries In-Reply-To: <6e9c8b4d-a13c-4def-a721-13ee1a02412e@googlegroups.com> References: <6e9c8b4d-a13c-4def-a721-13ee1a02412e@googlegroups.com> Message-ID: You can use python 3 spider probably. On Wed, Oct 16, 2019 at 7:22 PM Tesfalem Abraham wrote: > hello users, > > Here, I tried to start python 2.7 (spider) but I could not install or add > my lib to the working area. > > I do appreciate your suggestions for me. > > thanks. > -- > https://mail.python.org/mailman/listinfo/python-list > From antoon.pardon at vub.be Wed Oct 16 10:03:12 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 16 Oct 2019 16:03:12 +0200 Subject: Except with empty tuple Message-ID: <15670c26-02f3-c521-41fe-b4a3633132d5@vub.be> I would like to verify I understand correctly. It is about the following construct: try: statement1 statement2 ... except (): pass As far as I understand and my tests seem to confirm this, this is equivallent to just statement1 statement2 ... Am I correct or did I miss something? -- Antoon. From HooDunnit at didly42KahZidly.net Wed Oct 16 10:20:38 2019 From: HooDunnit at didly42KahZidly.net (Cousin Stanley) Date: Wed, 16 Oct 2019 07:20:38 -0700 Subject: upgrading python on raspbian References: <201910130541.19512.gheskett@shentel.net> <755429e7-73f5-31e5-7b1e-af96c6a5a081@gmail.com> <201910141256.22208.gheskett@shentel.net> <201910150130.59464.gheskett@shentel.net> Message-ID: Gene Heskett wrote: > Continueing this thread, I now have a missing function by name, "units", > that is preventing LinuxCNC from running. > > Where in the python 3 world do I find that function?, > .... Under debian buster there is a python 2 package called python-quantities that apparently deals with units via numpy dependencies. $ apt-cache show python-quantities Package: python-quantities Version: 0.12.1-1 Priority: optional Section: python Maintainer: Debian Science Maintainers Installed-Size: 358 kB Depends: python (<< 2.8), python (>= 2.7), python:any (>= 2.6.6-7~), python-numpy Suggests: python-unittest2 Description-en: Library for computation of physical quantities with units, based on numpy Quantities is designed to handle arithmetic and conversions of physical quantities, which have a magnitude, dimensionality specified by various units, and possibly an uncertainty. Quantities builds on the popular numpy library and is designed to work with numpy ufuncs, many of which are already supported. .... Also .... $ apt-files list python-quantities Shows a units sub-directory under /usr/lib/python2.7/dist-packages with several individual modules such as force, length, mass, pressue, temperature, etc. Seems to be also available throug the python package index .... https://pypi.org/project/quantities/ $ pip install quantities I have no personal expeience with this package. -- Stanley C. Kitching Human Being Phoenix, Arizona From piet-l at vanoostrum.org Wed Oct 16 11:08:32 2019 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Wed, 16 Oct 2019 17:08:32 +0200 Subject: Instantiating sub-class from super References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> <4106c84e-ab10-e50c-6f23-70998c871b7a@DancesWithMice.info> Message-ID: DL Neil writes: > That said, if a "trans" person has ovaries or testes (for example) then > a non-traditional sexual identification is irrelevant - for medical > purposes. Diseases in those areas (and now I'm a long way from a > research questionnaire and from Python - but this is roughly how it was > explained to me) still apply, and sadly, may in-fact be considerably > complicated by any medical processes that may have contributed to a > transition. So what if a person has both ovaries and testes? It is better to keep all options open rather than making hasty subdivisions. In this context that means attributes (that can be None) rather than subclasses. -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From python at mrabarnett.plus.com Wed Oct 16 13:18:52 2019 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 16 Oct 2019 18:18:52 +0100 Subject: Except with empty tuple In-Reply-To: <15670c26-02f3-c521-41fe-b4a3633132d5@vub.be> References: <15670c26-02f3-c521-41fe-b4a3633132d5@vub.be> Message-ID: <30beab86-8c73-e96d-8428-f1acefe15d35@mrabarnett.plus.com> On 2019-10-16 15:03, Antoon Pardon wrote: > I would like to verify I understand correctly. > > It is about the following construct: > > try: > statement1 > statement2 > ... > except (): > pass > > As far as I understand and my tests seem to confirm this, this > is equivallent to just > > statement1 > statement2 > ... > > Am I correct or did I miss something? > What if there's an exception? >>> def test_1(): ... try: ... print('statement1') ... raise ValueError() ... print('statement2') ... except (): ... pass ... print('statement3') ... >>> def test_2(): ... print('statement1') ... print('statement2') ... print('statement3') ... >>> test_1() statement1 Traceback (most recent call last): File "", line 1, in File "", line 4, in test_1 ValueError >>> test_2() statement1 statement2 statement3 So, no, it's not equivalent. From tjreedy at udel.edu Wed Oct 16 13:56:18 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 16 Oct 2019 13:56:18 -0400 Subject: Except with empty tuple In-Reply-To: <30beab86-8c73-e96d-8428-f1acefe15d35@mrabarnett.plus.com> References: <15670c26-02f3-c521-41fe-b4a3633132d5@vub.be> <30beab86-8c73-e96d-8428-f1acefe15d35@mrabarnett.plus.com> Message-ID: On 10/16/2019 1:18 PM, MRAB wrote: > On 2019-10-16 15:03, Antoon Pardon wrote: >> I would like to verify I understand correctly. >> >> It is about the following construct: >> >> ???? try: >> ???????? statement1 >> ???????? statement2 >> ???????? ... >> ???? except (): >> ???????? pass >> >> As far as I understand and my tests seem to confirm this, this >> is equivallent to just >> >> ???? statement1 >> ???? statement2 >> ???? ... >> >> Am I correct or did I miss something? Since except (): cannot catch anything, the two are externally equivalent given a particular behavior of the statements. Internally, the first takes a bit longer unless the irrelevant try-except is optimized away, but checking for this case would be a waste of time. > What if there's an exception? Antoon is asking whether the two snippets are equivalent for any particular behavior of the sequence of statements. > >>> def test_1(): > ...???? try: > ...???????? print('statement1') > ...???????? raise ValueError() > ...???????? print('statement2') > ...???? except (): > ...???????? pass > ...???? print('statement3') > ... > >>> def test_2(): > ...???? print('statement1') If you add raise ValueError() to test with the same snippet behavior > ...???? print('statement2') > ...???? print('statement3') > ... > >>> test_1() > statement1 > Traceback (most recent call last): > ? File "", line 1, in > ? File "", line 4, in test_1 > ValueError The point is that except (): cannot not catch any exception. > >>> test_2() Then you get the same output. -- Terry Jan Reedy From duncan at invalid.invalid Wed Oct 16 14:43:20 2019 From: duncan at invalid.invalid (duncan smith) Date: Wed, 16 Oct 2019 19:43:20 +0100 Subject: Instantiating sub-class from super In-Reply-To: References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> <4106c84e-ab10-e50c-6f23-70998c871b7a@DancesWithMice.info> <4UtpF.44322$KB2.25487@fx02.iad> <43e5875d-88a2-154e-7716-d39f40f6dd0a@DancesWithMice.info> Message-ID: On 16/10/2019 04:41, DL Neil wrote: > On 16/10/19 1:55 PM, duncan smith wrote: >> On 15/10/2019 21:36, DL Neil wrote: >>> On 16/10/19 12:38 AM, Rhodri James wrote: >>>> On 14/10/2019 21:55, DL Neil via Python-list wrote: >>> ... >>> So, yes, the "label" is unimportant - except to politicians and >>> statisticians, who want precise answers from vague collections of >>> data... (sigh!) >>> >> >> [snip] >> >> No not (real) statisticians. People often want us to provide precise >> answers, but they don't often get them. >> >> "It ain?t what you don?t know that gets you into trouble. It?s what you >> know for sure that just ain?t so." (Mark Twain - perhaps) > > +1 > > Although, you've undoubtedly heard people attempt to make claims of > having 'accurate figures' (even, "that came from Stats") when you told > them that the limitations and variations rendered the exercise laughable... > > My favorite (of the moment) is a local computer store who regularly > offer such gems as: (underneath the sales (web-) page for an upmarket > *desktop* computer)? "people who bought this also bought" followed by at > least two portable PC carry cases. They must be rather large carry-bags! > (along with such surprises as keyboard, mouse, ...) > > This morning I turned-down a study for a political group. One study has > already been completed and presented. The antagonist wanted an A/B > comparison (backing his 'side', of course). I mildly suggested that I > would do it, if he'd also pay me to do an A/B/C study, where 'C' was a > costing - the economic opportunity cost of 'the people' waiting for 'the > government' to make a decision - (and delaying that decision by waiting > for "study" after "study" - The UK and their (MPs') inability to decide > "Brexit" a particularly disastrous illustration of such) > > > Sorry, don't want to incur the anger of the list-gods - such > calculations would be performed in Python (of course) Clearly, all such analyses should be done in Python. Thank God for rpy2, otherwise I'd have to write R code. It's bad enough having to read it occasionally to figure out what's going on under the hood (I like everything about R - except the syntax). I have too many examples of people ignoring random variation, testing hypotheses on the data that generated the hypotheses, shifting the goalposts, using cum / post hoc ergo propter hoc reasoning, assuming monocausality etc. In some areas these things have become almost standard practice (and they don't really hinder publication as long as they are even moderately well hidden). Of course, it's often about policy promotion, and the economic analyses can be just as bad (e.g. comparing the negative impacts of a policy on the individual with the positive impacts aggregated over a very large population). And if it's about policy promotion a press release is inevitable. So we just need to survey the news media for specific examples. Unfortunately there's no reliable service for telling us what's crap and what isn't. (Go on, somebody pay me, all my data processing / re-analysis will be in Python ;-).) Duncan From python at mrabarnett.plus.com Wed Oct 16 14:52:50 2019 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 16 Oct 2019 19:52:50 +0100 Subject: Instantiating sub-class from super In-Reply-To: References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> <4106c84e-ab10-e50c-6f23-70998c871b7a@DancesWithMice.info> <4UtpF.44322$KB2.25487@fx02.iad> <43e5875d-88a2-154e-7716-d39f40f6dd0a@DancesWithMice.info> Message-ID: <1f650b8a-5576-79fa-977f-8b9027c0a13f@mrabarnett.plus.com> On 2019-10-16 19:43, duncan smith wrote: > On 16/10/2019 04:41, DL Neil wrote: >> On 16/10/19 1:55 PM, duncan smith wrote: >>> On 15/10/2019 21:36, DL Neil wrote: >>>> On 16/10/19 12:38 AM, Rhodri James wrote: >>>>> On 14/10/2019 21:55, DL Neil via Python-list wrote: >>>> ... >>>> So, yes, the "label" is unimportant - except to politicians and >>>> statisticians, who want precise answers from vague collections of >>>> data... (sigh!) >>>> >>> >>> [snip] >>> >>> No not (real) statisticians. People often want us to provide precise >>> answers, but they don't often get them. >>> >>> "It ain?t what you don?t know that gets you into trouble. It?s what you >>> know for sure that just ain?t so." (Mark Twain - perhaps) >> >> +1 >> >> Although, you've undoubtedly heard people attempt to make claims of >> having 'accurate figures' (even, "that came from Stats") when you told >> them that the limitations and variations rendered the exercise laughable... >> >> My favorite (of the moment) is a local computer store who regularly >> offer such gems as: (underneath the sales (web-) page for an upmarket >> *desktop* computer)? "people who bought this also bought" followed by at >> least two portable PC carry cases. They must be rather large carry-bags! >> (along with such surprises as keyboard, mouse, ...) >> >> This morning I turned-down a study for a political group. One study has >> already been completed and presented. The antagonist wanted an A/B >> comparison (backing his 'side', of course). I mildly suggested that I >> would do it, if he'd also pay me to do an A/B/C study, where 'C' was a >> costing - the economic opportunity cost of 'the people' waiting for 'the >> government' to make a decision - (and delaying that decision by waiting >> for "study" after "study" - The UK and their (MPs') inability to decide >> "Brexit" a particularly disastrous illustration of such) >> >> >> Sorry, don't want to incur the anger of the list-gods - such >> calculations would be performed in Python (of course) > > Clearly, all such analyses should be done in Python. Thank God for rpy2, > otherwise I'd have to write R code. It's bad enough having to read it > occasionally to figure out what's going on under the hood (I like > everything about R - except the syntax). > > I have too many examples of people ignoring random variation, testing > hypotheses on the data that generated the hypotheses, shifting the > goalposts, using cum / post hoc ergo propter hoc reasoning, assuming > monocausality etc. In some areas these things have become almost > standard practice (and they don't really hinder publication as long as > they are even moderately well hidden). Of course, it's often about > policy promotion, and the economic analyses can be just as bad (e.g. > comparing the negative impacts of a policy on the individual with the > positive impacts aggregated over a very large population). And if it's > about policy promotion a press release is inevitable. So we just need to > survey the news media for specific examples. Unfortunately there's no > reliable service for telling us what's crap and what isn't. (Go on, > somebody pay me, all my data processing / re-analysis will be in Python > ;-).) > Even when using Python, you have to be careful: Researchers find bug in Python script may have affected hundreds of studies https://arstechnica.com/information-technology/2019/10/chemists-discover-cross-platform-python-scripts-not-so-cross-platform/ From martin.schoon at gmail.com Wed Oct 16 16:00:36 2019 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 16 Oct 2019 20:00:36 GMT Subject: Jupyter Notebook -> PDF with A4 pages? References: Message-ID: Den 2019-10-15 skrev Piet van Oostrum : > > What does this report? Compare if there is a difference between home and work. > > from jupyter_core.paths import jupyter_path > print(jupyter_path('notebook','templates')) > In both cases I get (with different usernames): /home/username/.local/share/jupyter/notebook/templates /usr/local/share/jupyter/notebook/templates /usr/share/jupyter/notebook/templates > And maybe also > print(jupyter_path('nbconvert','templates')) Same as above but with "nbconvert" substituting "notebook". Pretty much all jupyter components are of older versions at work. pip is version 8.1.1 which is what Ubuntu 16.04 comes with. I have learnt -- the hard way -- that pip should be used with the --user option. Does this mean I am stuck with pip version 8.1.1? I mean, pip install --user pip seams like cheating... For a moment I thought that maybe pdflatex was missing at work but not so. Disclaimer: I only had a few minutes to spend on this today. /Martin From barry at barrys-emacs.org Wed Oct 16 16:43:12 2019 From: barry at barrys-emacs.org (Barry Scott) Date: Wed, 16 Oct 2019 21:43:12 +0100 Subject: Instantiating sub-class from super In-Reply-To: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> Message-ID: <575D3660-1D17-4CD5-BE09-E5AA80439A68@barrys-emacs.org> > On 14 Oct 2019, at 21:55, DL Neil via Python-list wrote: > > Is there a technique or pattern for taking a (partially-) populated instance of a class, and re-creating it as an instance of one of its sub-classes? The pattern I know is to use a factory function to choose between a number of concrete classes based on some information. In this case it seems that after collecting enough information you could create such a class. The other thought is to have the classes support a method that returns a "better" class. x.setProp(...) x = x.upgradeInstance() I have seen code that messes around with __class__ but I think that its a maintenance issue to do that. Apart from the person who writes that code would have a clue what it's doing. Barry > > > In a medically-oriented situation, we have a Person() class, and start collecting information within an instance (person = Person(), etc). > > During the data-collection process the person's sex may become obvious, eg few males have become/been pregnant. > > We could stick with Person() and implement specific methods therein, rather than separate Man and Woman sub-classes, but... > > It seemed better (at the design-level) to have Man( Person ) and Woman( Person ) sub-classes to contain the pertinent attributes, source more detailed and specific questions, and collect such data; by gender. > > In coding-practice, once gender becomes apparent, how should the instance of the Man() or Woman() sub-class be created - and established with the ID and other attributes previously collected as a Person instance? > > This attempt seems hack-y: > > man = Man() > man.__dict__.update( person.__dict__ ) > > > Is there a pythonic tool for such, or is the task outlined fundamentally-inappropriate? > > -- > Regards, > =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From piet-l at vanoostrum.org Wed Oct 16 17:47:20 2019 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Wed, 16 Oct 2019 23:47:20 +0200 Subject: Jupyter Notebook -> PDF with A4 pages? References: Message-ID: Martin Sch??n writes: > Den 2019-10-15 skrev Piet van Oostrum : >> >> What does this report? Compare if there is a difference between home and work. >> >> from jupyter_core.paths import jupyter_path >> print(jupyter_path('notebook','templates')) >> > In both cases I get (with different usernames): > > /home/username/.local/share/jupyter/notebook/templates > /usr/local/share/jupyter/notebook/templates > /usr/share/jupyter/notebook/templates > >> And maybe also >> print(jupyter_path('nbconvert','templates')) > > Same as above but with "nbconvert" substituting "notebook". > > Pretty much all jupyter components are of older versions at > work. Could that be a version where the configuration is done differently? > pip is version 8.1.1 which is what Ubuntu 16.04 comes > with. I have learnt -- the hard way -- that pip should be > used with the --user option. Does this mean I am stuck with > pip version 8.1.1? I mean, pip install --user pip seams like > cheating... Why should that not work? > For a moment I thought that maybe pdflatex was missing at work > but not so. > > Disclaimer: I only had a few minutes to spend on this today. > > /Martin Please also try the following command at the shell: jupyter notebook --generate-config and see where it generates the config file (this will overwrite the one that you made yourself). Also in the shell where the notebook server is started lokk if the are error messages if you generate a PDF from a notebook. -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From duncan at invalid.invalid Wed Oct 16 19:40:48 2019 From: duncan at invalid.invalid (duncan smith) Date: Thu, 17 Oct 2019 00:40:48 +0100 Subject: Instantiating sub-class from super In-Reply-To: References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> <4106c84e-ab10-e50c-6f23-70998c871b7a@DancesWithMice.info> <4UtpF.44322$KB2.25487@fx02.iad> <43e5875d-88a2-154e-7716-d39f40f6dd0a@DancesWithMice.info> <1f650b8a-5576-79fa-977f-8b9027c0a13f@mrabarnett.plus.com> Message-ID: <5UNpF.49480$hB2.19054@fx42.iad> On 16/10/2019 19:52, MRAB wrote: > On 2019-10-16 19:43, duncan smith wrote: >> On 16/10/2019 04:41, DL Neil wrote: >>> On 16/10/19 1:55 PM, duncan smith wrote: >>>> On 15/10/2019 21:36, DL Neil wrote: >>>>> On 16/10/19 12:38 AM, Rhodri James wrote: >>>>>> On 14/10/2019 21:55, DL Neil via Python-list wrote: >>>>> ... >>>>> So, yes, the "label" is unimportant - except to politicians and >>>>> statisticians, who want precise answers from vague collections of >>>>> data... (sigh!) >>>>> >>>> >>>> [snip] >>>> >>>> No not (real) statisticians. People often want us to provide precise >>>> answers, but they don't often get them. >>>> >>>> "It ain?t what you don?t know that gets you into trouble. It?s what you >>>> know for sure that just ain?t so." (Mark Twain - perhaps) >>> >>> +1 >>> >>> Although, you've undoubtedly heard people attempt to make claims of >>> having 'accurate figures' (even, "that came from Stats") when you told >>> them that the limitations and variations rendered the exercise >>> laughable... >>> >>> My favorite (of the moment) is a local computer store who regularly >>> offer such gems as: (underneath the sales (web-) page for an upmarket >>> *desktop* computer)? "people who bought this also bought" followed by at >>> least two portable PC carry cases. They must be rather large carry-bags! >>> (along with such surprises as keyboard, mouse, ...) >>> >>> This morning I turned-down a study for a political group. One study has >>> already been completed and presented. The antagonist wanted an A/B >>> comparison (backing his 'side', of course). I mildly suggested that I >>> would do it, if he'd also pay me to do an A/B/C study, where 'C' was a >>> costing - the economic opportunity cost of 'the people' waiting for 'the >>> government' to make a decision - (and delaying that decision by waiting >>> for "study" after "study" - The UK and their (MPs') inability to decide >>> "Brexit" a particularly disastrous illustration of such) >>> >>> >>> Sorry, don't want to incur the anger of the list-gods - such >>> calculations would be performed in Python (of course) >> >> Clearly, all such analyses should be done in Python. Thank God for rpy2, >> otherwise I'd have to write R code. It's bad enough having to read it >> occasionally to figure out what's going on under the hood (I like >> everything about R - except the syntax). >> ?> I have too many examples of people ignoring random variation, testing >> hypotheses on the data that generated the hypotheses, shifting the >> goalposts, using cum / post hoc ergo propter hoc reasoning, assuming >> monocausality etc. In some areas these things have become almost >> standard practice (and they don't really hinder publication as long as >> they are even moderately well hidden). Of course, it's often about >> policy promotion, and the economic analyses can be just as bad (e.g. >> comparing the negative impacts of a policy on the individual with the >> positive impacts aggregated over a very large population). And if it's >> about policy promotion a press release is inevitable. So we just need to >> survey the news media for specific examples. Unfortunately there's no >> reliable service for telling us what's crap and what isn't. (Go on, >> somebody pay me, all my data processing / re-analysis will be in Python >> ;-).) >> > Even when using Python, you have to be careful: > > Researchers find bug in Python script may have affected hundreds of studies > https://arstechnica.com/information-technology/2019/10/chemists-discover-cross-platform-python-scripts-not-so-cross-platform/ > Yes, the problem of standing on the shoulders of others (not necessarily giants). I assume the problematic code was tested on an OS that happened to sort the results as required. Years ago I had a similar issue with a race condition, but we caught it because I developed the code under Linux and everybody else on the project ran it under Windows (where the bug surfaced). Note to self: before I do any more parallel programming check out how to test for race conditions. Duncan From frank at chagford.com Thu Oct 17 02:08:43 2019 From: frank at chagford.com (Frank Millman) Date: Thu, 17 Oct 2019 08:08:43 +0200 Subject: Instantiating sub-class from super In-Reply-To: <35ce3570-9473-c128-9a21-27d1873320d3@chagford.com> References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <35ce3570-9473-c128-9a21-27d1873320d3@chagford.com> Message-ID: <0eef02c2-6919-c53b-c675-571fa8853819@chagford.com> On 2019-10-16 7:33 AM, Frank Millman wrote: > > Here is a link to an article entitled 'Understanding Hidden Subtypes'. > It dates back to 2004, but I think it is still relevant. It addresses > precisely the issues that you raise, but from a data-modelling > perspective, not a programming one. > > http://tdan.com/understanding-hidden-subtypes/5193 > > I found it invaluable, and applied the concepts in my own > business/accounting application. Having created the ability to make > subtypes visible and explicit, I found all kinds of unexpected uses for > them. > > The article seems to be missing a couple of images (Figure 1 and Figure > 2) showing the data relationships. I downloaded the original article > onto my computer years ago, and my local copy does have the images, so > if you would like to see them let me know and I will upload my version > somewhere to make it accessible. > I received a couple of requests for a link to the original article, so I uploaded it to filebin. Here is the link - https://filebin.net/1ia5kcq2sbp57t1o The file will be deleted automatically in one week. I don't know if that is good netiquette. Should I use a site where it never expires? Google Drive? Recommendations welcome. Frank From frank at chagford.com Thu Oct 17 02:08:43 2019 From: frank at chagford.com (Frank Millman) Date: Thu, 17 Oct 2019 08:08:43 +0200 Subject: Instantiating sub-class from super In-Reply-To: <35ce3570-9473-c128-9a21-27d1873320d3@chagford.com> References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <35ce3570-9473-c128-9a21-27d1873320d3@chagford.com> Message-ID: <0eef02c2-6919-c53b-c675-571fa8853819@chagford.com> On 2019-10-16 7:33 AM, Frank Millman wrote: > > Here is a link to an article entitled 'Understanding Hidden Subtypes'. > It dates back to 2004, but I think it is still relevant. It addresses > precisely the issues that you raise, but from a data-modelling > perspective, not a programming one. > > http://tdan.com/understanding-hidden-subtypes/5193 > > I found it invaluable, and applied the concepts in my own > business/accounting application. Having created the ability to make > subtypes visible and explicit, I found all kinds of unexpected uses for > them. > > The article seems to be missing a couple of images (Figure 1 and Figure > 2) showing the data relationships. I downloaded the original article > onto my computer years ago, and my local copy does have the images, so > if you would like to see them let me know and I will upload my version > somewhere to make it accessible. > I received a couple of requests for a link to the original article, so I uploaded it to filebin. Here is the link - https://filebin.net/1ia5kcq2sbp57t1o The file will be deleted automatically in one week. I don't know if that is good netiquette. Should I use a site where it never expires? Google Drive? Recommendations welcome. Frank From hongyi.zhao at gmail.com Thu Oct 17 06:36:49 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Thu, 17 Oct 2019 10:36:49 +0000 (UTC) Subject: python -m pip install and pip install References: Message-ID: On Fri, 11 Oct 2019 07:35:23 +0300, ???? wrote: > When you upgrade pip, you have to write: > > python -m pip install --upgrade pip > > When you install or upgrade anything else, you can write "pip install". > > You can't upgrade pip using "pip install --upgrade pip". No, see the following: werner at debian-01:~$ pip install --upgrade pip Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting pip Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4a/ 08/6ca123073af4ebc4c5488a5bc8a010ac57aa39ce4d3c8a931ad504de4185/pip-19.3- py2.py3-none-any.whl (1.4MB) |????????????????????????????????| 1.4MB 2.2MB/s Installing collected packages: pip Found existing installation: pip 19.2.3 Uninstalling pip-19.2.3: Successfully uninstalled pip-19.2.3 Successfully installed pip-19.3 From hongyi.zhao at gmail.com Thu Oct 17 06:38:29 2019 From: hongyi.zhao at gmail.com (Hongyi Zhao) Date: Thu, 17 Oct 2019 10:38:29 +0000 (UTC) Subject: python -m pip install and pip install References: Message-ID: On Fri, 11 Oct 2019 13:02:26 +0530, Pankaj Jangid wrote: > Oh! I wasn't aware of this Windows thing. Thanks. Windows is suck, don't use it at all. From eryksun at gmail.com Thu Oct 17 15:06:38 2019 From: eryksun at gmail.com (Eryk Sun) Date: Thu, 17 Oct 2019 14:06:38 -0500 Subject: Instantiating sub-class from super In-Reply-To: References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> <4106c84e-ab10-e50c-6f23-70998c871b7a@DancesWithMice.info> <4UtpF.44322$KB2.25487@fx02.iad> <43e5875d-88a2-154e-7716-d39f40f6dd0a@DancesWithMice.info> <1f650b8a-5576-79fa-977f-8b9027c0a13f@mrabarnett.plus.com> Message-ID: On 10/17/19, Dennis Lee Bieber wrote: > On Wed, 16 Oct 2019 19:52:50 +0100, MRAB > declaimed the following: > >>Researchers find bug in Python script may have affected hundreds of >> studies >>https://arstechnica.com/information-technology/2019/10/chemists-discover-cross-platform-python-scripts-not-so-cross-platform/ > > That article bugs me... > > As I understand it, the results are affected by the ORDER in which, > otherwise independent, file NAMES were returned by the OS. > > Fine: manually ordering the names by some algorithm produces consistent > results across various OSs -- but what evidence is there that this file > name sort is producing "correct" results? What is the sorting criteria -- > it is not mentioned in the article. Are the file names time-stamped (in > which case a time-ordered sort does make sense)? I'm bugged by how the article mis-characterizes the fundamental problem. The operating system has nothing to do with the order of a directory listing, which varies even with an OS, depending on the file system. The latter could store each entry in a tree structure that's sorted by filename, or it could use a mapping with hash values, or it could simply use the first available slot in a list, based on the order of past create and delete operations. From python at mrabarnett.plus.com Thu Oct 17 16:05:08 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 17 Oct 2019 21:05:08 +0100 Subject: Instantiating sub-class from super In-Reply-To: References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> <4106c84e-ab10-e50c-6f23-70998c871b7a@DancesWithMice.info> <4UtpF.44322$KB2.25487@fx02.iad> <43e5875d-88a2-154e-7716-d39f40f6dd0a@DancesWithMice.info> <1f650b8a-5576-79fa-977f-8b9027c0a13f@mrabarnett.plus.com> Message-ID: <18924c95-f89a-b709-9b7d-51b32df3a353@mrabarnett.plus.com> On 2019-10-17 20:06, Eryk Sun wrote: > On 10/17/19, Dennis Lee Bieber wrote: >> On Wed, 16 Oct 2019 19:52:50 +0100, MRAB >> declaimed the following: >> >>>Researchers find bug in Python script may have affected hundreds of >>> studies >>>https://arstechnica.com/information-technology/2019/10/chemists-discover-cross-platform-python-scripts-not-so-cross-platform/ >> >> That article bugs me... >> >> As I understand it, the results are affected by the ORDER in which, >> otherwise independent, file NAMES were returned by the OS. >> >> Fine: manually ordering the names by some algorithm produces consistent >> results across various OSs -- but what evidence is there that this file >> name sort is producing "correct" results? What is the sorting criteria -- >> it is not mentioned in the article. Are the file names time-stamped (in >> which case a time-ordered sort does make sense)? > > I'm bugged by how the article mis-characterizes the fundamental > problem. The operating system has nothing to do with the order of a > directory listing, which varies even with an OS, depending on the file > system. The latter could store each entry in a tree structure that's > sorted by filename, or it could use a mapping with hash values, or it > could simply use the first available slot in a list, based on the > order of past create and delete operations. > "The operating system has nothing to do with the order of a directory listing"? Well, that depends on the operating system. It might guarantee the order. From eryksun at gmail.com Thu Oct 17 16:27:23 2019 From: eryksun at gmail.com (Eryk Sun) Date: Thu, 17 Oct 2019 15:27:23 -0500 Subject: Instantiating sub-class from super In-Reply-To: <18924c95-f89a-b709-9b7d-51b32df3a353@mrabarnett.plus.com> References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> <4106c84e-ab10-e50c-6f23-70998c871b7a@DancesWithMice.info> <4UtpF.44322$KB2.25487@fx02.iad> <43e5875d-88a2-154e-7716-d39f40f6dd0a@DancesWithMice.info> <1f650b8a-5576-79fa-977f-8b9027c0a13f@mrabarnett.plus.com> <18924c95-f89a-b709-9b7d-51b32df3a353@mrabarnett.plus.com> Message-ID: On 10/17/19, MRAB wrote: > On 2019-10-17 20:06, Eryk Sun wrote: > >> I'm bugged by how the article mis-characterizes the fundamental >> problem. The operating system has nothing to do with the order of a >> directory listing, which varies even with an OS, depending on the file >> system. The latter could store each entry in a tree structure that's >> sorted by filename, or it could use a mapping with hash values, or it >> could simply use the first available slot in a list, based on the >> order of past create and delete operations. >> > "The operating system has nothing to do with the order of a directory > listing"? > > Well, that depends on the operating system. It might guarantee the order. That would be typically provide no benefit and be an unnecessary expense in the kernel, especially for directories that contain thousands of entries, considering applications typically need a particular sort order anyway. Also, while such a system could make this default order cheap for its own platform-restricted file systems, supporting other file systems such as NTFS and ext3 would bear the cost of having to dynamically sort directory listings instead of just listing the entries as they're naturally stored in the file-system data structures. From doganadres at gmail.com Fri Oct 18 04:35:51 2019 From: doganadres at gmail.com (doganadres at gmail.com) Date: Fri, 18 Oct 2019 01:35:51 -0700 (PDT) Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 Message-ID: Here is my question: I am using the numpy.std formula to calculate the standart deviation. However, the result comes as a number in scientific notation. Therefore I am asking, How to convert a scientific notation to decimal number, and still keep the data format as float64 ? Or is there any workaround to get the initial standart deviation result as a decimal number? Here is my code: stdev=numpy.std(dataset) print(stdev) Result: 4.999999999999449e-05 print(stdev.dtype) Result: float64 Solutions such as this: stdev=format(stdev, '.10f') converts the data into a string object! which I don't want. Expected result: I am willing to have a result as a decimal number in a float64 format. System: (Python 3.7.4 running on Win10) Regards, From Richard at Damon-Family.org Fri Oct 18 07:21:14 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 18 Oct 2019 07:21:14 -0400 Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: References: Message-ID: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> On 10/18/19 4:35 AM, doganadres at gmail.com wrote: > Here is my question: > > > I am using the numpy.std formula to calculate the standart deviation. However, the result comes as a number in scientific notation. > Therefore I am asking, How to convert a scientific notation to decimal number, and still keep the data format as float64 ? > > Or is there any workaround to get the initial standart deviation result as a decimal number? > > > Here is my code: > > stdev=numpy.std(dataset) > print(stdev) > Result: 4.999999999999449e-05 > > > print(stdev.dtype) > Result: float64 > > > Solutions such as this: > > stdev=format(stdev, '.10f') > converts the data into a string object! which I don't want. > > > Expected result: I am willing to have a result as a decimal number in a float64 format. > > System: (Python 3.7.4 running on Win10) > > > Regards, The number itself isn't in scientific notation or a fixed point number, but is a floating point number that is expressed internally as an integer times a power of 2 (that is the basic representation format for floating point). Scientific notation vs fixed point notation is purely an OUTPUT configuration, not a function on how the number is stored (so in one sense IS more closely linked to a string than the float itself). -- Richard Damon From invalid at invalid.com Fri Oct 18 07:46:19 2019 From: invalid at invalid.com (Gys) Date: Fri, 18 Oct 2019 13:46:19 +0200 Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: References: Message-ID: On 10/18/19 10:35 AM, doganadres at gmail.com wrote: > > Here is my question: > > > I am using the numpy.std formula to calculate the standart deviation. However, the result comes as a number in scientific notation. > Therefore I am asking, How to convert a scientific notation to decimal number, and still keep the data format as float64 ? > > Or is there any workaround to get the initial standart deviation result as a decimal number? > > > Here is my code: > > stdev=numpy.std(dataset) > print(stdev) > Result: 4.999999999999449e-05 > > > print(stdev.dtype) > Result: float64 > > > Solutions such as this: > > stdev=format(stdev, '.10f') > converts the data into a string object! which I don't want. > > > Expected result: I am willing to have a result as a decimal number in a float64 format. > > System: (Python 3.7.4 running on Win10) > > > Regards, > Hi, doganadres at gmail.com why don't you use print("{0:10.5f}".format(x)) The only thing you want is a specific form of the human readable representation of the number. For this it is not necessary the convert the *number* itself definitely to a string. You only have to make a temp copy of x for printing purposes. Linux Mint Tara in Spyder(Python 3.6) : x=4.999999999999449e-05 print(x) 4.999999999999449e-05 print("{0:8.5f}".format(x)) 0.00005 print(x) 4.999999999999449e-05 hth Gys From doganadres at gmail.com Fri Oct 18 08:52:16 2019 From: doganadres at gmail.com (doganadres at gmail.com) Date: Fri, 18 Oct 2019 05:52:16 -0700 (PDT) Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: References: Message-ID: <2ec08566-6496-4219-b88a-d3538391f619@googlegroups.com> On Friday, October 18, 2019 at 2:46:42 PM UTC+3, Gys wrote: > On 10/18/19 10:35 AM, doganadres at gmail.com wrote: > > > > Here is my question: > > > > > > I am using the numpy.std formula to calculate the standart deviation. However, the result comes as a number in scientific notation. > > Therefore I am asking, How to convert a scientific notation to decimal number, and still keep the data format as float64 ? > > > > Or is there any workaround to get the initial standart deviation result as a decimal number? > > > > > > Here is my code: > > > > stdev=numpy.std(dataset) > > print(stdev) > > Result: 4.999999999999449e-05 > > > > > > print(stdev.dtype) > > Result: float64 > > > > > > Solutions such as this: > > > > stdev=format(stdev, '.10f') > > converts the data into a string object! which I don't want. > > > > > > Expected result: I am willing to have a result as a decimal number in a float64 format. > > > > System: (Python 3.7.4 running on Win10) > > > > > > Regards, > > > > Hi, doganadres at gmail.com > > why don't you use > > print("{0:10.5f}".format(x)) > > The only thing you want is a specific form of the human readable > representation of the number. For this it is not necessary the convert > the *number* itself definitely to a string. You only have to make a > temp copy of x for printing purposes. > > Linux Mint Tara in Spyder(Python 3.6) : > > x=4.999999999999449e-05 > > print(x) > 4.999999999999449e-05 > > print("{0:8.5f}".format(x)) > 0.00005 > > print(x) > 4.999999999999449e-05 > > hth > Gys Hello, I don't only need a human readable representation of number, I need to use it further, do things such as putting it in a pandas object and saving it to an excel file. Doing things such as x="{0:10.5f}".format(x) gives a str object as a result: From doganadres at gmail.com Fri Oct 18 09:03:40 2019 From: doganadres at gmail.com (doganadres at gmail.com) Date: Fri, 18 Oct 2019 06:03:40 -0700 (PDT) Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> Message-ID: <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> On Friday, October 18, 2019 at 2:21:34 PM UTC+3, Richard Damon wrote: > On 10/18/19 4:35 AM, doganadres at gmail.com wrote: > > Here is my question: > > > > > > I am using the numpy.std formula to calculate the standart deviation. However, the result comes as a number in scientific notation. > > Therefore I am asking, How to convert a scientific notation to decimal number, and still keep the data format as float64 ? > > > > Or is there any workaround to get the initial standart deviation result as a decimal number? > > > > > > Here is my code: > > > > stdev=numpy.std(dataset) > > print(stdev) > > Result: 4.999999999999449e-05 > > > > > > print(stdev.dtype) > > Result: float64 > > > > > > Solutions such as this: > > > > stdev=format(stdev, '.10f') > > converts the data into a string object! which I don't want. > > > > > > Expected result: I am willing to have a result as a decimal number in a float64 format. > > > > System: (Python 3.7.4 running on Win10) > > > > > > Regards, > > The number itself isn't in scientific notation or a fixed point number, > but is a floating point number that is expressed internally as an > integer times a power of 2 (that is the basic representation format for > floating point). > > Scientific notation vs fixed point notation is purely an OUTPUT > configuration, not a function on how the number is stored (so in one > sense IS more closely linked to a string than the float itself). > > -- > Richard Damon Hello Richard, You seem so right. But what will we do with those strings with 'e' in it? There are ways to present those in a 'normal' way with formatting. However, the result of those formatting turns them into str object and which limits you to do any further numerical things with them. Another thing which I have observed, while doing some experimental thing is that: >>> 0.0 0.0 >>> 0.1 0.1 >>> 0.01 0.01 >>> 0.001 0.001 >>> 0.0001 0.0001 >>> 0.00001 1e-05 Again another thing with 1e-05! instead of 0.00001 , Is there anything I can do about it? From Richard at Damon-Family.org Fri Oct 18 09:10:44 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 18 Oct 2019 09:10:44 -0400 Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: <2ec08566-6496-4219-b88a-d3538391f619@googlegroups.com> References: <2ec08566-6496-4219-b88a-d3538391f619@googlegroups.com> Message-ID: On 10/18/19 8:52 AM, doganadres at gmail.com wrote: > On Friday, October 18, 2019 at 2:46:42 PM UTC+3, Gys wrote: >> On 10/18/19 10:35 AM, doganadres at gmail.com wrote: >>> Here is my question: >>> >>> >>> I am using the numpy.std formula to calculate the standart deviation. However, the result comes as a number in scientific notation. >>> Therefore I am asking, How to convert a scientific notation to decimal number, and still keep the data format as float64 ? >>> >>> Or is there any workaround to get the initial standart deviation result as a decimal number? >>> >>> >>> Here is my code: >>> >>> stdev=numpy.std(dataset) >>> print(stdev) >>> Result: 4.999999999999449e-05 >>> >>> >>> print(stdev.dtype) >>> Result: float64 >>> >>> >>> Solutions such as this: >>> >>> stdev=format(stdev, '.10f') >>> converts the data into a string object! which I don't want. >>> >>> >>> Expected result: I am willing to have a result as a decimal number in a float64 format. >>> >>> System: (Python 3.7.4 running on Win10) >>> >>> >>> Regards, >>> >> Hi, doganadres at gmail.com >> >> why don't you use >> >> print("{0:10.5f}".format(x)) >> >> The only thing you want is a specific form of the human readable >> representation of the number. For this it is not necessary the convert >> the *number* itself definitely to a string. You only have to make a >> temp copy of x for printing purposes. >> >> Linux Mint Tara in Spyder(Python 3.6) : >> >> x=4.999999999999449e-05 >> >> print(x) >> 4.999999999999449e-05 >> >> print("{0:8.5f}".format(x)) >> 0.00005 >> >> print(x) >> 4.999999999999449e-05 >> >> hth >> Gys > Hello, > > I don't only need a human readable representation of number, I need to use it further, do things such as putting it in a pandas object and saving it to an excel file. > > Doing things such as > x="{0:10.5f}".format(x) > gives a str object as a result: > If you are going to use it further as a floating point binary number, why do you need to do ANYTHING to it. As I said, the exponential format is just a string representation of the binary value (just like the 0.0005 is). If you put it into something that stores the float64 representation, that doesn't have anything like an exponential vs decimal format. (Depending on how you put it into excel, that may actually use a string representation if something like a CSV file.) -- Richard Damon From Richard at Damon-Family.org Fri Oct 18 09:17:32 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 18 Oct 2019 09:17:32 -0400 Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> Message-ID: <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> On 10/18/19 9:03 AM, doganadres at gmail.com wrote: > On Friday, October 18, 2019 at 2:21:34 PM UTC+3, Richard Damon wrote: >> On 10/18/19 4:35 AM, doganadres at gmail.com wrote: >>> Here is my question: >>> >>> >>> I am using the numpy.std formula to calculate the standart deviation. However, the result comes as a number in scientific notation. >>> Therefore I am asking, How to convert a scientific notation to decimal number, and still keep the data format as float64 ? >>> >>> Or is there any workaround to get the initial standart deviation result as a decimal number? >>> >>> >>> Here is my code: >>> >>> stdev=numpy.std(dataset) >>> print(stdev) >>> Result: 4.999999999999449e-05 >>> >>> >>> print(stdev.dtype) >>> Result: float64 >>> >>> >>> Solutions such as this: >>> >>> stdev=format(stdev, '.10f') >>> converts the data into a string object! which I don't want. >>> >>> >>> Expected result: I am willing to have a result as a decimal number in a float64 format. >>> >>> System: (Python 3.7.4 running on Win10) >>> >>> >>> Regards, >> The number itself isn't in scientific notation or a fixed point number, >> but is a floating point number that is expressed internally as an >> integer times a power of 2 (that is the basic representation format for >> floating point). >> >> Scientific notation vs fixed point notation is purely an OUTPUT >> configuration, not a function on how the number is stored (so in one >> sense IS more closely linked to a string than the float itself). >> >> -- >> Richard Damon > > Hello Richard, > > You seem so right. But what will we do with those strings with 'e' in it? > > There are ways to present those in a 'normal' way with formatting. However, the result of those formatting turns them into str object and which limits you to do any further numerical things with them. > > Another thing which I have observed, while doing some experimental thing is that: > >>>> 0.0 > 0.0 > >>>> 0.1 > 0.1 > >>>> 0.01 > 0.01 > >>>> 0.001 > 0.001 > >>>> 0.0001 > 0.0001 > >>>> 0.00001 > 1e-05 > > Again another thing with 1e-05! instead of 0.00001 , Is there anything I can do about it? The 'e' is only part of the string representation presentation of the value. By default, python decides to present small numbers in exponential format.? If you don't like that, when you print the numbers specify the format YOU want, rather than taking the default. Note, that print() by necessity converts an objects value to a string, and this conversion for floats uses exponential notation by default for small numbers. If you don't like it, then use an explicit format for the conversion. An alternative might be to change from using a float64 to making it something like a Decimal. -- Richard Damon From doganadres at gmail.com Fri Oct 18 09:45:36 2019 From: doganadres at gmail.com (doganadres at gmail.com) Date: Fri, 18 Oct 2019 06:45:36 -0700 (PDT) Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> Message-ID: <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> On Friday, October 18, 2019 at 4:17:51 PM UTC+3, Richard Damon wrote: > On 10/18/19 9:03 AM, doganadres at gmail.com wrote: > > On Friday, October 18, 2019 at 2:21:34 PM UTC+3, Richard Damon wrote: > >> On 10/18/19 4:35 AM, doganadres at gmail.com wrote: > >>> Here is my question: > >>> > >>> > >>> I am using the numpy.std formula to calculate the standart deviation. However, the result comes as a number in scientific notation. > >>> Therefore I am asking, How to convert a scientific notation to decimal number, and still keep the data format as float64 ? > >>> > >>> Or is there any workaround to get the initial standart deviation result as a decimal number? > >>> > >>> > >>> Here is my code: > >>> > >>> stdev=numpy.std(dataset) > >>> print(stdev) > >>> Result: 4.999999999999449e-05 > >>> > >>> > >>> print(stdev.dtype) > >>> Result: float64 > >>> > >>> > >>> Solutions such as this: > >>> > >>> stdev=format(stdev, '.10f') > >>> converts the data into a string object! which I don't want. > >>> > >>> > >>> Expected result: I am willing to have a result as a decimal number in a float64 format. > >>> > >>> System: (Python 3.7.4 running on Win10) > >>> > >>> > >>> Regards, > >> The number itself isn't in scientific notation or a fixed point number, > >> but is a floating point number that is expressed internally as an > >> integer times a power of 2 (that is the basic representation format for > >> floating point). > >> > >> Scientific notation vs fixed point notation is purely an OUTPUT > >> configuration, not a function on how the number is stored (so in one > >> sense IS more closely linked to a string than the float itself). > >> > >> -- > >> Richard Damon > > > > Hello Richard, > > > > You seem so right. But what will we do with those strings with 'e' in it? > > > > There are ways to present those in a 'normal' way with formatting. However, the result of those formatting turns them into str object and which limits you to do any further numerical things with them. > > > > Another thing which I have observed, while doing some experimental thing is that: > > > >>>> 0.0 > > 0.0 > > > >>>> 0.1 > > 0.1 > > > >>>> 0.01 > > 0.01 > > > >>>> 0.001 > > 0.001 > > > >>>> 0.0001 > > 0.0001 > > > >>>> 0.00001 > > 1e-05 > > > > Again another thing with 1e-05! instead of 0.00001 , Is there anything I can do about it? > > The 'e' is only part of the string representation presentation of the > value. By default, python decides to present small numbers in > exponential format.? If you don't like that, when you print the numbers > specify the format YOU want, rather than taking the default. > > Note, that print() by necessity converts an objects value to a string, > and this conversion for floats uses exponential notation by default for > small numbers. If you don't like it, then use an explicit format for the > conversion. > > An alternative might be to change from using a float64 to making it > something like a Decimal. > > -- > Richard Damon By taking the default OUTPUT of a numpy formula, in my case standart deviation, I am using the advantage of saving the result into an excel file without any problems.(they come as numpy.float64) From there, The excel takes all the things as they are and some of my small numbers are shown with the 'e' on the excel sheet. Which I am trying to avoid. I don't need 100 numbers after the comma. What I need is a reasonable amount of decimal numbers to show that the number is small enough, also keeping them in float64, in my case to save them into excel file. One important thing to say is that, if I convert them into string and save them on excel they come with 'dot' instead of comma. And If try to translate the 'dot' manually into 'comma' the excel gives warning message to turn those inputs into numbers. Which I also avoid. If this is Python default, showing all numbers smaller than 0.0001 with 'e' and there is no way to have them in both a human readable and excel savable form. what sould I do? Should I consider using another programming language? If yes, then this language could be callable from within python and I might do things I can. From rosuav at gmail.com Fri Oct 18 09:55:05 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Oct 2019 00:55:05 +1100 Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> Message-ID: On Sat, Oct 19, 2019 at 12:51 AM wrote: > By taking the default OUTPUT of a numpy formula, in my case standart deviation, I am using the advantage of saving the result into an excel file without any problems.(they come as numpy.float64) From there, The excel takes all the things as they are and some of my small numbers are shown with the 'e' on the excel sheet. Which I am trying to avoid. > > I don't need 100 numbers after the comma. What I need is a reasonable amount of decimal numbers to show that the number is small enough, also keeping them in float64, in my case to save them into excel file. One important thing to say is that, if I convert them into string and save them on excel they come with 'dot' instead of comma. And If try to translate the 'dot' manually into 'comma' the excel gives warning message to turn those inputs into numbers. Which I also avoid. > > If this is Python default, showing all numbers smaller than 0.0001 with 'e' and there is no way to have them in both a human readable and excel savable form. > You're conflating the number with its representation. Whenever you display a number, you need a set of digits. The number itself is exactly the same whether it's written as 0.00000001 or 1e-8 or any other form, just as you can write a fraction as 3 1/7 or as 22/7 and it's the same number. Look at the way you're "saving the result into an Excel file". Firstly, is it CSV or actually saved into Excel format? Then look at the way you actually display the number there. In a CSV file, once again, you need a series of digits, so you simply need to format the number the way that people have been advising you. ChrisA From Richard at Damon-Family.org Fri Oct 18 10:53:07 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 18 Oct 2019 10:53:07 -0400 Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> Message-ID: On 10/18/19 9:45 AM, doganadres at gmail.com wrote: > On Friday, October 18, 2019 at 4:17:51 PM UTC+3, Richard Damon wrote: >> On 10/18/19 9:03 AM, doganadres at gmail.com wrote: >>> On Friday, October 18, 2019 at 2:21:34 PM UTC+3, Richard Damon wrote: >>>> On 10/18/19 4:35 AM, doganadres at gmail.com wrote: >>>>> Here is my question: >>>>> >>>>> >>>>> I am using the numpy.std formula to calculate the standart deviation. However, the result comes as a number in scientific notation. >>>>> Therefore I am asking, How to convert a scientific notation to decimal number, and still keep the data format as float64 ? >>>>> >>>>> Or is there any workaround to get the initial standart deviation result as a decimal number? >>>>> >>>>> >>>>> Here is my code: >>>>> >>>>> stdev=numpy.std(dataset) >>>>> print(stdev) >>>>> Result: 4.999999999999449e-05 >>>>> >>>>> >>>>> print(stdev.dtype) >>>>> Result: float64 >>>>> >>>>> >>>>> Solutions such as this: >>>>> >>>>> stdev=format(stdev, '.10f') >>>>> converts the data into a string object! which I don't want. >>>>> >>>>> >>>>> Expected result: I am willing to have a result as a decimal number in a float64 format. >>>>> >>>>> System: (Python 3.7.4 running on Win10) >>>>> >>>>> >>>>> Regards, >>>> The number itself isn't in scientific notation or a fixed point number, >>>> but is a floating point number that is expressed internally as an >>>> integer times a power of 2 (that is the basic representation format for >>>> floating point). >>>> >>>> Scientific notation vs fixed point notation is purely an OUTPUT >>>> configuration, not a function on how the number is stored (so in one >>>> sense IS more closely linked to a string than the float itself). >>>> >>>> -- >>>> Richard Damon >>> Hello Richard, >>> >>> You seem so right. But what will we do with those strings with 'e' in it? >>> >>> There are ways to present those in a 'normal' way with formatting. However, the result of those formatting turns them into str object and which limits you to do any further numerical things with them. >>> >>> Another thing which I have observed, while doing some experimental thing is that: >>> >>>>>> 0.0 >>> 0.0 >>> >>>>>> 0.1 >>> 0.1 >>> >>>>>> 0.01 >>> 0.01 >>> >>>>>> 0.001 >>> 0.001 >>> >>>>>> 0.0001 >>> 0.0001 >>> >>>>>> 0.00001 >>> 1e-05 >>> >>> Again another thing with 1e-05! instead of 0.00001 , Is there anything I can do about it? >> The 'e' is only part of the string representation presentation of the >> value. By default, python decides to present small numbers in >> exponential format.? If you don't like that, when you print the numbers >> specify the format YOU want, rather than taking the default. >> >> Note, that print() by necessity converts an objects value to a string, >> and this conversion for floats uses exponential notation by default for >> small numbers. If you don't like it, then use an explicit format for the >> conversion. >> >> An alternative might be to change from using a float64 to making it >> something like a Decimal. >> >> -- >> Richard Damon > > By taking the default OUTPUT of a numpy formula, in my case standart deviation, I am using the advantage of saving the result into an excel file without any problems.(they come as numpy.float64) From there, The excel takes all the things as they are and some of my small numbers are shown with the 'e' on the excel sheet. Which I am trying to avoid. > > I don't need 100 numbers after the comma. What I need is a reasonable amount of decimal numbers to show that the number is small enough, also keeping them in float64, in my case to save them into excel file. One important thing to say is that, if I convert them into string and save them on excel they come with 'dot' instead of comma. And If try to translate the 'dot' manually into 'comma' the excel gives warning message to turn those inputs into numbers. Which I also avoid. > > If this is Python default, showing all numbers smaller than 0.0001 with 'e' and there is no way to have them in both a human readable and excel savable form. > > what sould I do? > > Should I consider using another programming language? > > If yes, then this language could be callable from within python and I might do things I can. The problem is you are thinking of your floating point number as storing something like 5e-5 or 0.00005, it doesn't. it store something more like 1.6384 x 2**15 (or some really big 50 some bit integer time a different power of 2). As your words said, it SHOWS it with an e, but that isn't what is in the number. The number is just a number represented as a float. If you don't what to print them with the e, then format them when you print to be the way you want. As to the excel, you aren't being very clear about how you are generating the excel file. If you are directly generating an .xls file, then I believe you want to store the float64 value directly into it, and their is no dot/comma as the decimal separator issue. More like it seems, you are generating a 'CSV' file, which is a textual representation, and if you are doing that then you need to be careful to follow the rules for the CSV format you are using (and if you are using the European format which uses comma as the decimal point,? that raises other issues). Agian here, it isn't how the number is stored, but how it is formatted for output. print(x) is a quick and dirty method to display values, and isn't always the right way. Sometimes you need to be more careful and explicitly define the format to output the value. Keep values internally in the right internal format, which here seems to be float64. When outputting them (to user or file for another program) be sure to handle any needed formatting if the defaults are suitable. -- Richard Damon From sio.wtf at gmail.com Fri Oct 18 05:19:26 2019 From: sio.wtf at gmail.com (Vitaly Potyarkin) Date: Fri, 18 Oct 2019 12:19:26 +0300 Subject: Asking for feedback: Mirror GitHub issues with a static site generator Message-ID: Hello, I'm looking to get some feedback on my project. It's a backup mechanism for GitHub issues and pull requests that creates human-readable issue archives in HTML - ready to be served as a static web site. The project is written in Python and works by extending Pelican static site generator, it provides Makefiles for quickly starting with demo configuration. Here are the links: - Home page and documentation: https://issyours.ml/ - Source code: https://github.com/sio/issyours - Demo output: https://issyours.ml/demo/issues/ - Some rationale on why this project was started: https://issyours.ml/design/ What do you think of the project idea? Would that be useful to you or anyone you know? How is documentation? Is it good enough for new users to get started? What about demo instance? Does it show enough to spark interest? Also, if you have time, any feedback on code/architecture would be very appreciated! Thanks! -- Vitaly From doganadres at gmail.com Fri Oct 18 12:07:45 2019 From: doganadres at gmail.com (doganadres at gmail.com) Date: Fri, 18 Oct 2019 09:07:45 -0700 (PDT) Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> Message-ID: <84c1e168-2b05-4a84-ad22-c5e07d593a33@googlegroups.com> On Friday, October 18, 2019 at 4:55:33 PM UTC+3, Chris Angelico wrote: > On Sat, Oct 19, 2019 at 12:51 AM wrote: > > By taking the default OUTPUT of a numpy formula, in my case standart deviation, I am using the advantage of saving the result into an excel file without any problems.(they come as numpy.float64) From there, The excel takes all the things as they are and some of my small numbers are shown with the 'e' on the excel sheet. Which I am trying to avoid. > > > > I don't need 100 numbers after the comma. What I need is a reasonable amount of decimal numbers to show that the number is small enough, also keeping them in float64, in my case to save them into excel file. One important thing to say is that, if I convert them into string and save them on excel they come with 'dot' instead of comma. And If try to translate the 'dot' manually into 'comma' the excel gives warning message to turn those inputs into numbers. Which I also avoid. > > > > If this is Python default, showing all numbers smaller than 0.0001 with 'e' and there is no way to have them in both a human readable and excel savable form. > > > > You're conflating the number with its representation. Whenever you > display a number, you need a set of digits. The number itself is > exactly the same whether it's written as 0.00000001 or 1e-8 or any > other form, just as you can write a fraction as 3 1/7 or as 22/7 and > it's the same number. > > Look at the way you're "saving the result into an Excel file". > Firstly, is it CSV or actually saved into Excel format? Then look at > the way you actually display the number there. In a CSV file, once > again, you need a series of digits, so you simply need to format the > number the way that people have been advising you. > > ChrisA Thank you Chris, I will answer down below, on Richard's From doganadres at gmail.com Fri Oct 18 12:17:21 2019 From: doganadres at gmail.com (doganadres at gmail.com) Date: Fri, 18 Oct 2019 09:17:21 -0700 (PDT) Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> Message-ID: <6f4e13d8-df88-435d-9dbd-30bf018b11b6@googlegroups.com> On Friday, October 18, 2019 at 5:53:24 PM UTC+3, Richard Damon wrote: > On 10/18/19 9:45 AM, doganadres at gmail.com wrote: > > On Friday, October 18, 2019 at 4:17:51 PM UTC+3, Richard Damon wrote: > >> On 10/18/19 9:03 AM, doganadres at gmail.com wrote: > >>> On Friday, October 18, 2019 at 2:21:34 PM UTC+3, Richard Damon wrote: > >>>> On 10/18/19 4:35 AM, doganadres at gmail.com wrote: > >>>>> Here is my question: > >>>>> > >>>>> > >>>>> I am using the numpy.std formula to calculate the standart deviation. However, the result comes as a number in scientific notation. > >>>>> Therefore I am asking, How to convert a scientific notation to decimal number, and still keep the data format as float64 ? > >>>>> > >>>>> Or is there any workaround to get the initial standart deviation result as a decimal number? > >>>>> > >>>>> > >>>>> Here is my code: > >>>>> > >>>>> stdev=numpy.std(dataset) > >>>>> print(stdev) > >>>>> Result: 4.999999999999449e-05 > >>>>> > >>>>> > >>>>> print(stdev.dtype) > >>>>> Result: float64 > >>>>> > >>>>> > >>>>> Solutions such as this: > >>>>> > >>>>> stdev=format(stdev, '.10f') > >>>>> converts the data into a string object! which I don't want. > >>>>> > >>>>> > >>>>> Expected result: I am willing to have a result as a decimal number in a float64 format. > >>>>> > >>>>> System: (Python 3.7.4 running on Win10) > >>>>> > >>>>> > >>>>> Regards, > >>>> The number itself isn't in scientific notation or a fixed point number, > >>>> but is a floating point number that is expressed internally as an > >>>> integer times a power of 2 (that is the basic representation format for > >>>> floating point). > >>>> > >>>> Scientific notation vs fixed point notation is purely an OUTPUT > >>>> configuration, not a function on how the number is stored (so in one > >>>> sense IS more closely linked to a string than the float itself). > >>>> > >>>> -- > >>>> Richard Damon > >>> Hello Richard, > >>> > >>> You seem so right. But what will we do with those strings with 'e' in it? > >>> > >>> There are ways to present those in a 'normal' way with formatting. However, the result of those formatting turns them into str object and which limits you to do any further numerical things with them. > >>> > >>> Another thing which I have observed, while doing some experimental thing is that: > >>> > >>>>>> 0.0 > >>> 0.0 > >>> > >>>>>> 0.1 > >>> 0.1 > >>> > >>>>>> 0.01 > >>> 0.01 > >>> > >>>>>> 0.001 > >>> 0.001 > >>> > >>>>>> 0.0001 > >>> 0.0001 > >>> > >>>>>> 0.00001 > >>> 1e-05 > >>> > >>> Again another thing with 1e-05! instead of 0.00001 , Is there anything I can do about it? > >> The 'e' is only part of the string representation presentation of the > >> value. By default, python decides to present small numbers in > >> exponential format.? If you don't like that, when you print the numbers > >> specify the format YOU want, rather than taking the default. > >> > >> Note, that print() by necessity converts an objects value to a string, > >> and this conversion for floats uses exponential notation by default for > >> small numbers. If you don't like it, then use an explicit format for the > >> conversion. > >> > >> An alternative might be to change from using a float64 to making it > >> something like a Decimal. > >> > >> -- > >> Richard Damon > > > > By taking the default OUTPUT of a numpy formula, in my case standart deviation, I am using the advantage of saving the result into an excel file without any problems.(they come as numpy.float64) From there, The excel takes all the things as they are and some of my small numbers are shown with the 'e' on the excel sheet. Which I am trying to avoid. > > > > I don't need 100 numbers after the comma. What I need is a reasonable amount of decimal numbers to show that the number is small enough, also keeping them in float64, in my case to save them into excel file. One important thing to say is that, if I convert them into string and save them on excel they come with 'dot' instead of comma. And If try to translate the 'dot' manually into 'comma' the excel gives warning message to turn those inputs into numbers. Which I also avoid. > > > > If this is Python default, showing all numbers smaller than 0.0001 with 'e' and there is no way to have them in both a human readable and excel savable form. > > > > what sould I do? > > > > Should I consider using another programming language? > > > > If yes, then this language could be callable from within python and I might do things I can. > > The problem is you are thinking of your floating point number as storing > something like 5e-5 or 0.00005, it doesn't. it store something more like > 1.6384 x 2**15 (or some really big 50 some bit integer time a different > power of 2). As your words said, it SHOWS it with an e, but that isn't > what is in the number. The number is just a number represented as a float. > > If you don't what to print them with the e, then format them when you > print to be the way you want. > > As to the excel, you aren't being very clear about how you are > generating the excel file. If you are directly generating an .xls file, > then I believe you want to store the float64 value directly into it, and > their is no dot/comma as the decimal separator issue. More like it > seems, you are generating a 'CSV' file, which is a textual > representation, and if you are doing that then you need to be careful to > follow the rules for the CSV format you are using (and if you are using > the European format which uses comma as the decimal point,? that raises > other issues). Agian here, it isn't how the number is stored, but how it > is formatted for output. > > print(x) is a quick and dirty method to display values, and isn't always > the right way. Sometimes you need to be more careful and explicitly > define the format to output the value. > > Keep values internally in the right internal format, which here seems to > be float64. When outputting them (to user or file for another program) > be sure to handle any needed formatting if the defaults are suitable. > > -- > Richard Damon Richard, as a note: the method I was using to save on excel is by using pandas. But more importantly , I have decided to take the default formats as they are. In that situation the representation of the numbers on excel remains with 'e' which is now ok, as long as I can do further calculations with them. In the meanwhile I have checked Scala , and it's more limited then Python. As an example: 0.0001 1.0E-4: Double thank you Richard and Chris for sharing knowledge. and I hope to meet you in a another problem. From jagga13 at gmail.com Fri Oct 18 13:03:26 2019 From: jagga13 at gmail.com (Jagga Soorma) Date: Fri, 18 Oct 2019 10:03:26 -0700 Subject: Print formatting Message-ID: Hello, I am new to python and trying to write a script that outputs some data about users. I was able to write it and dump the data but can't seem to align the output in column 2 correctly. Here is what I am trying to do: -- output: user1 data1 username2 data2 user3 data3 snip from script: print(str(temp_list[0]) + "\t\t" + str(temp_list[1])) -- Adding the tabs does not seem to work and I am sure there is a better way to do this. Any help would be appreciated. Thanks, -J From python at mrabarnett.plus.com Fri Oct 18 13:35:25 2019 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 18 Oct 2019 18:35:25 +0100 Subject: Print formatting In-Reply-To: References: Message-ID: On 2019-10-18 18:03, Jagga Soorma wrote: > Hello, > > I am new to python and trying to write a script that outputs some data > about users. I was able to write it and dump the data but can't seem > to align the output in column 2 correctly. Here is what I am trying > to do: > > -- > output: > user1 data1 > username2 data2 > user3 data3 > > snip from script: > print(str(temp_list[0]) + "\t\t" + str(temp_list[1])) > -- > > Adding the tabs does not seem to work and I am sure there is a better > way to do this. Any help would be appreciated. > A tab advances the output position to the next tab stop, but there's no universal standard for where those tab stops are, although they're commonly at every 8 characters, assuming a monospaced (fixed-width) font. In your example, if the tabs are at every 8 characters then you'll get: | | <= The tab positions user1 data1 username2 data2 user3 data3 "username2" has already passed the first tab, so it advances to the second tab, causing the misalignment. The simplest solution, if you're using a monospaced font, is to use spaces instead. Find the width of the first column (the longest entry in the first column is 9 characters) and then pad all of the first entries with spaces to that width (use string formatting or the .just method) when outputting each line. From jagga13 at gmail.com Fri Oct 18 14:21:52 2019 From: jagga13 at gmail.com (Jagga Soorma) Date: Fri, 18 Oct 2019 11:21:52 -0700 Subject: Print formatting In-Reply-To: References: Message-ID: I seem to have found a way to do this with the following: print('{:<12s}{:>12s}'.format((temp_list[0]),(temp_list[3]))) Still let me know if there is a better way to format this output :) Thanks, -J On Fri, Oct 18, 2019 at 10:03 AM Jagga Soorma wrote: > > Hello, > > I am new to python and trying to write a script that outputs some data > about users. I was able to write it and dump the data but can't seem > to align the output in column 2 correctly. Here is what I am trying > to do: > > -- > output: > user1 data1 > username2 data2 > user3 data3 > > snip from script: > print(str(temp_list[0]) + "\t\t" + str(temp_list[1])) > -- > > Adding the tabs does not seem to work and I am sure there is a better > way to do this. Any help would be appreciated. > > Thanks, > -J From jagga13 at gmail.com Fri Oct 18 14:27:57 2019 From: jagga13 at gmail.com (Jagga Soorma) Date: Fri, 18 Oct 2019 11:27:57 -0700 Subject: python2 vs python3 Message-ID: Hello, I am writing my second python script and got it to work using python2.x. However, realized that I should be using python3 and it seems to fail with the following message: -- Traceback (most recent call last): File "test_script.py", line 29, in test_cmd = ("diskcmd -u " + x + " | grep -v '\*' | awk '{print $1, $3, $4, $9, $10}'" ) TypeError: Can't convert 'bytes' object to str implicitly -- I then run this command and save the output like this: -- test_info = (subprocess.check_output( test_cmd, stderr=subprocess.STDOUT, shell=True )).splitlines() -- Looks like the command output is in bytes and I can't simply wrap that around str(). Thanks in advance for your help with this. From rosuav at gmail.com Fri Oct 18 14:31:19 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Oct 2019 05:31:19 +1100 Subject: Asking for feedback: Mirror GitHub issues with a static site generator In-Reply-To: References: Message-ID: On Sat, Oct 19, 2019 at 2:25 AM Vitaly Potyarkin wrote: > It's a backup mechanism for GitHub issues and pull requests that creates > human-readable issue archives in HTML - ready to be served as a static web > site. The project is written in Python and works by extending Pelican > static site generator, it provides Makefiles for quickly starting with demo > configuration. A good plan. I'm personally (and currently) happy with GitHub, but I'm aware that not everyone is, and of course we don't know what the future holds. > What do you think of the project idea? Would that be useful to you or > anyone you know? Merely by existing, it has value. (Although it would have to be perpetually maintained in order to retain that.) It proves that use of GitHub Issues does not imply that you're locked into the platform, and as such, it's the elimination of an argument against the platform. > Also, if you have time, any feedback on code/architecture would be very > appreciated! You mention a persistent Storage, merely in passing. I want to see more about that. If that storage format is a nice easy thing to work with (eg a set of JSON files), and is a documented and forward/backward-compatible format, it could become a de facto interchange format. Even though THIS project never claims to be able to push back into any issue tracker, some OTHER project could pick up that side of it, and voila, you have a straight-forward backup or transfer format. What are the consequences of using the AGPL for this? If this project is used to create a viewable/searchable issue display, does that mean that the issues themselves are covered by the AGPL, or are they counted as data? I'm hoping it's the latter, but IANAL and I wouldn't want to get bitten by something unexpected. ChrisA From rosuav at gmail.com Fri Oct 18 14:36:22 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Oct 2019 05:36:22 +1100 Subject: python2 vs python3 In-Reply-To: References: Message-ID: On Sat, Oct 19, 2019 at 5:29 AM Jagga Soorma wrote: > > Hello, > > I am writing my second python script and got it to work using > python2.x. However, realized that I should be using python3 and it > seems to fail with the following message: > > -- > Traceback (most recent call last): > File "test_script.py", line 29, in > test_cmd = ("diskcmd -u " + x + " | grep -v '\*' | awk '{print $1, > $3, $4, $9, $10}'" ) > TypeError: Can't convert 'bytes' object to str implicitly > -- > > I then run this command and save the output like this: > > -- > test_info = (subprocess.check_output( test_cmd, > stderr=subprocess.STDOUT, shell=True )).splitlines() > -- > > Looks like the command output is in bytes and I can't simply wrap that > around str(). Thanks in advance for your help with this. That's correct. The output of the command is, by default, given to you in bytes. But most likely, they're bytes in some well-known encoding - probably UTF-8 - so you should be able to just tell check_output this, and it'll give you text back. Just add another parameter: subprocess.check_output(test_cmd, stderr=subprocess.STDOUT, shell=True, encoding="utf8") In general, the way to turn bytes into text is to decode them, using some named encoding. ChrisA From tjol at tjol.eu Fri Oct 18 06:47:22 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 18 Oct 2019 12:47:22 +0200 Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: References: Message-ID: <246c9f34-c699-4e85-2329-f084a5e0ecee@tjol.eu> On 18/10/2019 10:35, doganadres at gmail.com wrote: > Here is my question: > > > I am using the numpy.std formula to calculate the standart deviation. However, the result comes as a number in scientific notation. > Therefore I am asking, How to convert a scientific notation to decimal number, and still keep the data format as float64 ? > > Or is there any workaround to get the initial standart deviation result as a decimal number? > > > Here is my code: > > stdev=numpy.std(dataset) > print(stdev) > Result: 4.999999999999449e-05 > > > print(stdev.dtype) > Result: float64 > > > Solutions such as this: > > stdev=format(stdev, '.10f') > converts the data into a string object! which I don't want. > > > Expected result: I am willing to have a result as a decimal number in a float64 format. Float64 is a binary number format, not a decimal format. What you ask can't be done. As to what you want: For most purposes, you can think of the float64 object storing the Platonic ideal of the number, not any particular representation of it. 0.00005 and 5E-5 are the same number. End of story. If you want to work with the number, you don't care what it looks like. If you want to display the number, you do care what it looks like, and you want a str rather than a float. > > System: (Python 3.7.4 running on Win10) > > > Regards, From darcy at VybeNetworks.com Fri Oct 18 17:00:02 2019 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Fri, 18 Oct 2019 17:00:02 -0400 Subject: Print formatting In-Reply-To: References: Message-ID: <38852ad8-e54d-8f26-c995-8a99f36975db@VybeNetworks.com> On 10/18/19 2:21 PM, Jagga Soorma wrote: > I seem to have found a way to do this with the following: > > print('{:<12s}{:>12s}'.format((temp_list[0]),(temp_list[3]))) > > Still let me know if there is a better way to format this output :) I would start with removing the redundant parens. print('{:<12s}{:>12s}'.format(temp_list[0],temp_list[3])) But then I would simplify it further. print('{0[0]:<12s}{0[3]:>12s}'.format(temp_list)) You can do a similar thing with dictionaries. print('{0[data0]:<12s}{0[data3]:>12s}'.format(temp_dict)) You can even mix and match. print('{0[0]:<12s}{1[data3]:>12s}'.format(temp_list, temp_dict)) Finally, if this is in a loop do this. FMT = '{0[0]:<12s}{0[3]:>12s}'.format for temp_list in GetLists(): print FMT(temp_list) Cheers. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From darcy at VybeNetworks.com Fri Oct 18 17:27:35 2019 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Fri, 18 Oct 2019 17:27:35 -0400 Subject: Print formatting In-Reply-To: <38852ad8-e54d-8f26-c995-8a99f36975db@VybeNetworks.com> References: <38852ad8-e54d-8f26-c995-8a99f36975db@VybeNetworks.com> Message-ID: <94fa3737-e1ba-f0b3-33d9-1fea1832ad57@VybeNetworks.com> On 10/18/19 5:00 PM, D'Arcy Cain wrote: > Finally, if this is in a loop do this. > > FMT = '{0[0]:<12s}{0[3]:>12s}'.format > for temp_list in GetLists(): print FMT(temp_list) Oops. Time warp. I meant "print(FMT(temp_list)) -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From PythonList at DancesWithMice.info Fri Oct 18 18:37:28 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 19 Oct 2019 11:37:28 +1300 Subject: Instantiating sub-class from super In-Reply-To: <35ce3570-9473-c128-9a21-27d1873320d3@chagford.com> References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <35ce3570-9473-c128-9a21-27d1873320d3@chagford.com> Message-ID: On 16/10/19 6:33 PM, Frank Millman wrote: > On 2019-10-14 10:55 PM, DL Neil via Python-list wrote: >> Is there a technique or pattern for taking a (partially-) populated >> instance of a class, and re-creating it as an instance of one of its >> sub-classes? > Here is a link to an article entitled 'Understanding Hidden Subtypes'. > It dates back to 2004, but I think it is still relevant. It addresses > precisely the issues that you raise, but from a data-modelling > perspective, not a programming one. > > http://tdan.com/understanding-hidden-subtypes/5193 > > I found it invaluable, and applied the concepts in my own > business/accounting application. Having created the ability to make > subtypes visible and explicit, I found all kinds of unexpected uses for > them. > > The article seems to be missing a couple of images (Figure 1 and Figure > 2) showing the data relationships. I downloaded the original article > onto my computer years ago, and my local copy does have the images, so > if you would like to see them let me know and I will upload my version > somewhere to make it accessible. Superb! Yes please Frank - I've also approached it from the data/DB side, and thus presumably why I was puzzling over how one implements in Python. (alternatively, email a PDF/similar directly) -- Regards =dn From PythonList at DancesWithMice.info Fri Oct 18 18:40:25 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 19 Oct 2019 11:40:25 +1300 Subject: Instantiating sub-class from super In-Reply-To: References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> <4106c84e-ab10-e50c-6f23-70998c871b7a@DancesWithMice.info> Message-ID: <5703750b-b973-9678-f3d6-5e19f4925656@DancesWithMice.info> On 17/10/19 4:08 AM, Piet van Oostrum wrote: > DL Neil writes: > >> That said, if a "trans" person has ovaries or testes (for example) then >> a non-traditional sexual identification is irrelevant - for medical >> purposes. Diseases in those areas (and now I'm a long way from a >> research questionnaire and from Python - but this is roughly how it was >> explained to me) still apply, and sadly, may in-fact be considerably >> complicated by any medical processes that may have contributed to a >> transition. > > So what if a person has both ovaries and testes? > It is better to keep all options open rather than making hasty subdivisions. Exactly! The objective is not to sub-divide, but to ensure that those to whom various questions are relevant have their answers recorded, but those for whom the section is irrelevant are not over-burdened. > In this context that means attributes (that can be None) rather than subclasses. Which seems to be the way we're headed... Thanks! -- Regards =dn From PythonList at DancesWithMice.info Fri Oct 18 18:57:07 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 19 Oct 2019 11:57:07 +1300 Subject: Instantiating sub-class from super In-Reply-To: <1f650b8a-5576-79fa-977f-8b9027c0a13f@mrabarnett.plus.com> References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> <4106c84e-ab10-e50c-6f23-70998c871b7a@DancesWithMice.info> <4UtpF.44322$KB2.25487@fx02.iad> <43e5875d-88a2-154e-7716-d39f40f6dd0a@DancesWithMice.info> <1f650b8a-5576-79fa-977f-8b9027c0a13f@mrabarnett.plus.com> Message-ID: <37158847-4dca-996a-cd01-1fd388c7b371@DancesWithMice.info> On 17/10/19 7:52 AM, MRAB wrote: > On 2019-10-16 19:43, duncan smith wrote: >> On 16/10/2019 04:41, DL Neil wrote: >>> On 16/10/19 1:55 PM, duncan smith wrote: >>>> On 15/10/2019 21:36, DL Neil wrote: >>>>> On 16/10/19 12:38 AM, Rhodri James wrote: >>>>>> On 14/10/2019 21:55, DL Neil via Python-list wrote: >>>>> ... >>>>> So, yes, the "label" is unimportant - except to politicians and >>>>> statisticians, who want precise answers from vague collections of >>>>> data... (sigh!) >>>>> >>>> >>>> [snip] >>>> >>>> No not (real) statisticians. People often want us to provide precise >>>> answers, but they don't often get them. >>>> >>>> "It ain?t what you don?t know that gets you into trouble. It?s what you >>>> know for sure that just ain?t so." (Mark Twain - perhaps) >>> >>> +1 >>> >>> Although, you've undoubtedly heard people attempt to make claims of >>> having 'accurate figures' (even, "that came from Stats") when you told >>> them that the limitations and variations rendered the exercise >>> laughable... >>> >>> My favorite (of the moment) is a local computer store who regularly >>> offer such gems as: (underneath the sales (web-) page for an upmarket >>> *desktop* computer)? "people who bought this also bought" followed by at >>> least two portable PC carry cases. They must be rather large carry-bags! >>> (along with such surprises as keyboard, mouse, ...) >>> >>> This morning I turned-down a study for a political group. One study has >>> already been completed and presented. The antagonist wanted an A/B >>> comparison (backing his 'side', of course). I mildly suggested that I >>> would do it, if he'd also pay me to do an A/B/C study, where 'C' was a >>> costing - the economic opportunity cost of 'the people' waiting for 'the >>> government' to make a decision - (and delaying that decision by waiting >>> for "study" after "study" - The UK and their (MPs') inability to decide >>> "Brexit" a particularly disastrous illustration of such) >>> >>> >>> Sorry, don't want to incur the anger of the list-gods - such >>> calculations would be performed in Python (of course) >> >> Clearly, all such analyses should be done in Python. Thank God for rpy2, >> otherwise I'd have to write R code. It's bad enough having to read it >> occasionally to figure out what's going on under the hood (I like >> everything about R - except the syntax). >> ?> I have too many examples of people ignoring random variation, testing >> hypotheses on the data that generated the hypotheses, shifting the >> goalposts, using cum / post hoc ergo propter hoc reasoning, assuming >> monocausality etc. In some areas these things have become almost >> standard practice (and they don't really hinder publication as long as >> they are even moderately well hidden). Of course, it's often about >> policy promotion, and the economic analyses can be just as bad (e.g. >> comparing the negative impacts of a policy on the individual with the >> positive impacts aggregated over a very large population). And if it's >> about policy promotion a press release is inevitable. So we just need to >> survey the news media for specific examples. Unfortunately there's no >> reliable service for telling us what's crap and what isn't. (Go on, >> somebody pay me, all my data processing / re-analysis will be in Python >> ;-).) >> > Even when using Python, you have to be careful: > > Researchers find bug in Python script may have affected hundreds of studies > https://arstechnica.com/information-technology/2019/10/chemists-discover-cross-platform-python-scripts-not-so-cross-platform/ I think both of our 'Python' comments were made tongue-in-cheek. Sadly the tool won't guarantee the result... At my first research project, before I'd even completed my first degree, I noticed a similar fault in some code*. There was I, the youngest, newest, least-est member of staff, telling the prof/boss and all the other researchers that they'd made a serious error, upon which various papers had been based plus a white-paper for government consideration. Oops! (Basic-Plus on DEC PDP/Vax-en introduced a 'virtual storage array', ie on-disk cf in-RAM. However, it did not wipe the disk-space prior to use (whereas arrays were zero-ed, IIRC). Thus, random data purporting to be valid data-entered. Once corrected and re-run "my results" (as they were termed - not sure if insult or compliment) were not hugely different from the originals). All we can do, is add some checks-and-balances rather than relying on 'the computer'. Upon which point: those of us who learned 'complicated math' with the aid of a slide-rule, employ a technique of mentally estimating the result in both the first first few digits and scale - and thus noticing any completely incongruous 'result'. Even with lessons in "The Scientific Approach" am not aware that the 'calculator' or 'computer generations' were/are taught such 'common sense'... -- Regards =dn From PythonList at DancesWithMice.info Fri Oct 18 19:15:30 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 19 Oct 2019 12:15:30 +1300 Subject: Instantiating sub-class from super In-Reply-To: References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> <4106c84e-ab10-e50c-6f23-70998c871b7a@DancesWithMice.info> <4UtpF.44322$KB2.25487@fx02.iad> <43e5875d-88a2-154e-7716-d39f40f6dd0a@DancesWithMice.info> <1f650b8a-5576-79fa-977f-8b9027c0a13f@mrabarnett.plus.com> <18924c95-f89a-b709-9b7d-51b32df3a353@mrabarnett.plus.com> Message-ID: <46678592-767d-4324-57f1-f8b0255b814f@DancesWithMice.info> On 18/10/19 9:27 AM, Eryk Sun wrote: > On 10/17/19, MRAB wrote: >> On 2019-10-17 20:06, Eryk Sun wrote: >> >>> I'm bugged by how the article mis-characterizes the fundamental >>> problem. The operating system has nothing to do with the order of a >>> directory listing, which varies even with an OS, depending on the file >>> system. The latter could store each entry in a tree structure that's >>> sorted by filename, or it could use a mapping with hash values, or it >>> could simply use the first available slot in a list, based on the >>> order of past create and delete operations. >>> >> "The operating system has nothing to do with the order of a directory >> listing"? >> >> Well, that depends on the operating system. It might guarantee the order. > > That would be typically provide no benefit and be an unnecessary > expense in the kernel, especially for directories that contain > thousands of entries, considering applications typically need a > particular sort order anyway. Also, while such a system could make > this default order cheap for its own platform-restricted file systems, > supporting other file systems such as NTFS and ext3 would bear the > cost of having to dynamically sort directory listings instead of just > listing the entries as they're naturally stored in the file-system > data structures. To be fair to the original developers, not many people develop with multiple platforms in-mind. Perhaps more *nix devs do think 'platform' because the user-community may be MS-Win-based... When building an application, if it works for you, that's great. If others then want to use it, there is an amount of "caveat emptor" - particularly when jumping platforms. With the gift of hind-sight, some ideas may seem weak, even reprehensible; but they worked at the time. Just this morning I was reading about 'legal' Linux file/path syntax, and saw an article which recounted that Bourne (as in -Shell) had a series of files - one for each of the legal characters, which could be used as some sort of lookup. Are there easier ways once RAM has become cheap(er)? NB have no idea of the veracity of this claim. I've been working on a consolidation of personal file/dir-manipulation utilities (as many 'here' know, and have kindly guided/assisted) but have not given any thought to non-Posix systems at all (contrary to the aims of importlib, for example). If someone takes *my* code and tries to run it on MS-Win Python, they'll soon find-out! That said, I'm not expecting to publish any results with the expectation of world-domination... -- Regards =dn From sebastian.steins at gmail.com Fri Oct 18 20:23:44 2019 From: sebastian.steins at gmail.com (Sebastian Steins) Date: Sat, 19 Oct 2019 02:23:44 +0200 Subject: A news aggregator for the Python community Message-ID: Hi! Over the last few weeks I've build a hacker news clone for the Python community: https://news.python.sc The source is at github.com/sebst/pythonic-news I thought that might be of interest to you and I'd be more than happy to hear your thoughts on this. Best, --Sebastian From jfong at ms4.hinet.net Sat Oct 19 07:11:21 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sat, 19 Oct 2019 04:11:21 -0700 (PDT) Subject: What's the purpose the hook method showing in a class definition? Message-ID: <7d2efed5-054c-4e8b-93dd-b39b025ac18d@googlegroups.com> For the two examples below: (1) >>> class A: ... def foo(self): ... self.goo() ... >>> class B(A): ... def goo(self): ... print(1) ... (2) >>> class A: ... def foo(self): ... self.goo() ... def goo(self): pass ... >>> class B(A): ... def goo(self): ... print(1) ... Both can get the same result: >>> b = B() >>> b.foo() 1 >>> What's the benefit of having the hook method goo() in class A in example 2? --Jach From sio.wtf at gmail.com Sat Oct 19 08:31:03 2019 From: sio.wtf at gmail.com (Vitaly Potyarkin) Date: Sat, 19 Oct 2019 15:31:03 +0300 Subject: Asking for feedback: Mirror GitHub issues with a static site generator In-Reply-To: References: Message-ID: On Fri, Oct 18, 2019 at 9:31 PM Chris Angelico wrote: > You mention a persistent Storage, merely in passing. I want to see > more about that. If that storage format is a nice easy thing to work > with (eg a set of JSON files), and is a documented and > forward/backward-compatible format, it could become a de facto > interchange format. Not defining Storage is intentional. Since the application is layered Storage may take any form you want as long as Fetcher and Reader agree on what it is. Currently implemented Fetcher and Reader for GitHub issues use JSON files for Storage. The format is almost the same as raw API response (the only added key is timestamp that API returns via HTTP headers). That does not mean all Fetchers and Readers have to use the same format. Someone else might want to store data in SQLite file, another person would like MongoDB instance - all is possible if they write their own Fetcher and Reader for such Storage (Issyours provides base class for Reader that simplifies adding support new storage mechanisms). In fact, you might even not need to implement the Fetcher to add another data source - some issue trackers already provide "Export all my data" mechanisms. In that case only Reader must be created. I've chosen this approach because I think it's almost impossible to create a storage format that would become "a de facto interchange format". At least not for a project run by a single developer. Defining an agreeable dataset for visual representation is easier because it does not impose any limits on those who want to store extra data - they get to store anything they want any way they want. The limitations apply only to the presentation layer. If they don't like my approach - their data is still intact, in machine readable format. > What are the consequences of using the AGPL for this? If this project > is used to create a viewable/searchable issue display, does that mean > that the issues themselves are covered by the AGPL, or are they > counted as data? Oh, no! Of course issues and comments are data and are not covered by AGPL. Only the application itself is covered, even though AGPL for a static site generator is almost unenforceable, because of the middleware loophole. Pelican - static site generator I base my work on - uses AGPL for their source code, and no one is going around claiming all the blog posts are now copyleft. From rosuav at gmail.com Sat Oct 19 08:49:06 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Oct 2019 23:49:06 +1100 Subject: Asking for feedback: Mirror GitHub issues with a static site generator In-Reply-To: References: Message-ID: On Sat, Oct 19, 2019 at 11:31 PM Vitaly Potyarkin wrote: > > On Fri, Oct 18, 2019 at 9:31 PM Chris Angelico wrote: > > You mention a persistent Storage, merely in passing. I want to see > > more about that. If that storage format is a nice easy thing to work > > with (eg a set of JSON files), and is a documented and > > forward/backward-compatible format, it could become a de facto > > interchange format. > > I've chosen this approach because I think it's almost impossible to create a > storage format that would become "a de facto interchange format". At least not > for a project run by a single developer. Defining an agreeable dataset for > visual representation is easier because it does not impose any limits on those > who want to store extra data - they get to store anything they want any way > they want. The limitations apply only to the presentation layer. If they don't > like my approach - their data is still intact, in machine readable format. Hmm. Fair point. Still, I think maybe there could be a compromise here - eg a partially-defined JSON format that allows extensions. That way, you can export something with additional information that the Reader ignores, safely retain it, and yet still maintain this compatibility. > > What are the consequences of using the AGPL for this? If this project > > is used to create a viewable/searchable issue display, does that mean > > that the issues themselves are covered by the AGPL, or are they > > counted as data? > > Oh, no! Of course issues and comments are data and are not covered by AGPL. > Only the application itself is covered, even though AGPL for a static site > generator is almost unenforceable, because of the middleware loophole. > Pelican - static site generator I base my work on - uses AGPL for their source > code, and no one is going around claiming all the blog posts are now copyleft. Good to know. I'm always a bit leery of anything that could potentially slap a GPL onto arbitrary text or code - it's too much of a pain to go around asking people if they're okay with their content being relicensed. (It's hard enough to get that kind of permission from just TWO additional people. I speak from experience here.) ChrisA From duncan at invalid.invalid Sat Oct 19 10:59:34 2019 From: duncan at invalid.invalid (duncan smith) Date: Sat, 19 Oct 2019 15:59:34 +0100 Subject: Instantiating sub-class from super In-Reply-To: References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <6672ae2d-4139-82cd-ba64-87117bd7ed40@kynesim.co.uk> <4106c84e-ab10-e50c-6f23-70998c871b7a@DancesWithMice.info> <4UtpF.44322$KB2.25487@fx02.iad> <43e5875d-88a2-154e-7716-d39f40f6dd0a@DancesWithMice.info> <1f650b8a-5576-79fa-977f-8b9027c0a13f@mrabarnett.plus.com> <37158847-4dca-996a-cd01-1fd388c7b371@DancesWithMice.info> Message-ID: On 18/10/2019 23:57, DL Neil wrote: > On 17/10/19 7:52 AM, MRAB wrote: >> On 2019-10-16 19:43, duncan smith wrote: >>> On 16/10/2019 04:41, DL Neil wrote: >>>> On 16/10/19 1:55 PM, duncan smith wrote: >>>>> On 15/10/2019 21:36, DL Neil wrote: >>>>>> On 16/10/19 12:38 AM, Rhodri James wrote: >>>>>>> On 14/10/2019 21:55, DL Neil via Python-list wrote: >>>>>> ... >>>>>> So, yes, the "label" is unimportant - except to politicians and >>>>>> statisticians, who want precise answers from vague collections of >>>>>> data... (sigh!) >>>>>> >>>>> >>>>> [snip] >>>>> >>>>> No not (real) statisticians. People often want us to provide precise >>>>> answers, but they don't often get them. >>>>> >>>>> "It ain?t what you don?t know that gets you into trouble. It?s what >>>>> you >>>>> know for sure that just ain?t so." (Mark Twain - perhaps) >>>> >>>> +1 >>>> >>>> Although, you've undoubtedly heard people attempt to make claims of >>>> having 'accurate figures' (even, "that came from Stats") when you told >>>> them that the limitations and variations rendered the exercise >>>> laughable... >>>> >>>> My favorite (of the moment) is a local computer store who regularly >>>> offer such gems as: (underneath the sales (web-) page for an upmarket >>>> *desktop* computer)? "people who bought this also bought" followed >>>> by at >>>> least two portable PC carry cases. They must be rather large >>>> carry-bags! >>>> (along with such surprises as keyboard, mouse, ...) >>>> >>>> This morning I turned-down a study for a political group. One study has >>>> already been completed and presented. The antagonist wanted an A/B >>>> comparison (backing his 'side', of course). I mildly suggested that I >>>> would do it, if he'd also pay me to do an A/B/C study, where 'C' was a >>>> costing - the economic opportunity cost of 'the people' waiting for >>>> 'the >>>> government' to make a decision - (and delaying that decision by waiting >>>> for "study" after "study" - The UK and their (MPs') inability to decide >>>> "Brexit" a particularly disastrous illustration of such) >>>> >>>> >>>> Sorry, don't want to incur the anger of the list-gods - such >>>> calculations would be performed in Python (of course) >>> >>> Clearly, all such analyses should be done in Python. Thank God for rpy2, >>> otherwise I'd have to write R code. It's bad enough having to read it >>> occasionally to figure out what's going on under the hood (I like >>> everything about R - except the syntax). >>> ?> I have too many examples of people ignoring random variation, testing >>> hypotheses on the data that generated the hypotheses, shifting the >>> goalposts, using cum / post hoc ergo propter hoc reasoning, assuming >>> monocausality etc. In some areas these things have become almost >>> standard practice (and they don't really hinder publication as long as >>> they are even moderately well hidden). Of course, it's often about >>> policy promotion, and the economic analyses can be just as bad (e.g. >>> comparing the negative impacts of a policy on the individual with the >>> positive impacts aggregated over a very large population). And if it's >>> about policy promotion a press release is inevitable. So we just need to >>> survey the news media for specific examples. Unfortunately there's no >>> reliable service for telling us what's crap and what isn't. (Go on, >>> somebody pay me, all my data processing / re-analysis will be in Python >>> ;-).) >>> >> Even when using Python, you have to be careful: >> >> Researchers find bug in Python script may have affected hundreds of >> studies >> https://arstechnica.com/information-technology/2019/10/chemists-discover-cross-platform-python-scripts-not-so-cross-platform/ > > > > I think both of our 'Python' comments were made tongue-in-cheek. Sadly > the tool won't guarantee the result... > > > At my first research project, before I'd even completed my first degree, > I noticed a similar fault in some code*. There was I, the youngest, > newest, least-est member of staff, telling the prof/boss and all the > other researchers that they'd made a serious error, upon which various > papers had been based plus a white-paper for government consideration. > Oops! > > (Basic-Plus on DEC PDP/Vax-en introduced a 'virtual storage array', ie > on-disk cf in-RAM. However, it did not wipe the disk-space prior to use > (whereas arrays were zero-ed, IIRC). Thus, random data purporting to be > valid data-entered. Once corrected and re-run "my results" (as they were > termed - not sure if insult or compliment) were not hugely different > from the originals). > > All we can do, is add some checks-and-balances rather than relying on > 'the computer'. > > Upon which point: those of us who learned 'complicated math' with the > aid of a slide-rule, employ a technique of mentally estimating the > result in both the first first few digits and scale - and thus noticing > any completely incongruous 'result'. Even with lessons in "The > Scientific Approach" am not aware that the 'calculator' or 'computer > generations' were/are taught such 'common sense'... I always remember the Hubble mirror fiasco, where the problem could have been detected using a tape measure. Also, from my days in the building industry "measure twice, cut once". As far as claims in (social) scientific publications are concerned I always tell e.g. PhD students to assume nothing and check everything. I only recently discovered that this is pretty much the same as the ABC of policing, "assume nothing, believe no-one, challenge everything". Duncan From stevan.white at gmail.com Sat Oct 19 07:31:24 2019 From: stevan.white at gmail.com (Steve White) Date: Sat, 19 Oct 2019 13:31:24 +0200 Subject: keying by identity in dict and set Message-ID: Hi, I have an application that would benefit from object instances distinguished by identity being used in dict's and set's. To do this, the __hash__ method must be overridden, the obvious return value being the instance's id. This works flawlessly in extensive tests on several platforms, and on a couple of different Python versions and implementations. The documentation seems to preclude a second requirement, however. I also want to use the == operator on these objects to mean a natural comparison of values, different from identity, so that two instances comparing equivalent does not imply that they are identical. But the documentation for __hash__ has: "The only required property is that objects which compare equal have the same hash value" Yet it seems something more is going on, because as near as I can tell, it just works, perfectly, every time, despite this requirement. If the the __hash__ method returns the object's id, the __eq__ method of the *never* called when the object is added to a dict. (See examples below.) It would appear that if __hash__ returns the id, then that id is used internally as the key, and since the id is by definition unique, no key collision ever occurs -- at least in every Python implementation I've tried. It also seems that, for a class instance obj, hash( hash( obj ) ) == hash( obj ) hash( id( obj ) ) == id( obj ) These are very strong and useful properties. Where are they documented? It looks like the existing Python built-in containers do exactly what I need, but the documentation suggests that they may not. Taking the documentation at face value, I'm in the position of choosing between abandoning the natural use of operator '==', or of introducing an unfamiliar container implementation. As my package is intended for the use by other people, neither option is attractive. Questions: Is all this apparent behaviour documented somewhere that I have missed? Is there some fatal reason that this approach must never be used, besides the lack of documentary support for it? Is it in fact safe to assume that __eq__ is never called under these circumstances? =============================================================== from __future__ import print_function from sys import stdout class A( object ): # minimal hashable object def __init__( self, v1, v2 ): self.v = ( v1, v2 ) def __eq__( self, b ): #return self.v[0] == b.v[0] and self.v[1] == b.v[1] raise Exception( "CALLED __eq__" ) def __hash__( self ): # instances distinguished by identity return id( self ) # It was suggested that set and dict internally use some representation # of keys that contains less information than the id() value returned by # __hash__, thus causing key collisions, which are resolved by calls to # __eq__. # In that case, one would expect __eq__ to be called eventually if enough # objects were added to a set. I don't see that, though. NINSTANCES = 3000000 # play with this number -- carefully! STATUS_INTERVAL = 100000 def test(): """ hammer the set algorithms """ s = set() instances = [] for i in range( 0, NINSTANCES ): p = A( 1, 0 ) s.add( p ) instances.append( p ) if not i % STATUS_INTERVAL: stdout.write( str( i // STATUS_INTERVAL ) + " " ) stdout.flush() stdout.write( "\n" ) print( "length of set", len( s ) ) print( "number of instances", len( instances ) ) for i in instances: if not i in s: print( "INSTANCE DROPPED OUT!" ) test() From nulla.epistola at web.de Sat Oct 19 14:04:24 2019 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sat, 19 Oct 2019 20:04:24 +0200 Subject: What's the purpose the hook method showing in a class definition? In-Reply-To: <7d2efed5-054c-4e8b-93dd-b39b025ac18d@googlegroups.com> References: <7d2efed5-054c-4e8b-93dd-b39b025ac18d@googlegroups.com> Message-ID: Am 19.10.2019 um 13:11 schrieb jfong at ms4.hinet.net: > For the two examples below: > (1) >>>> class A: > ... def foo(self): > ... self.goo() > ... >>>> class B(A): > ... def goo(self): > ... print(1) > ... > > (2) >>>> class A: > ... def foo(self): > ... self.goo() > ... def goo(self): pass > ... >>>> class B(A): > ... def goo(self): > ... print(1) > ... > > Both can get the same result: >>>> b = B() >>>> b.foo() > 1 >>>> > > What's the benefit of having the hook method goo() in class A in example 2? > > --Jach > None - as long as nobody tries one of those: a = A() a.foo() or class C(A): def foo(self): super().foo() print(2) c = C() c.foo() From nulla.epistola at web.de Sat Oct 19 14:04:24 2019 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sat, 19 Oct 2019 20:04:24 +0200 Subject: What's the purpose the hook method showing in a class definition? In-Reply-To: <7d2efed5-054c-4e8b-93dd-b39b025ac18d@googlegroups.com> References: <7d2efed5-054c-4e8b-93dd-b39b025ac18d@googlegroups.com> Message-ID: Am 19.10.2019 um 13:11 schrieb jfong at ms4.hinet.net: > For the two examples below: > (1) >>>> class A: > ... def foo(self): > ... self.goo() > ... >>>> class B(A): > ... def goo(self): > ... print(1) > ... > > (2) >>>> class A: > ... def foo(self): > ... self.goo() > ... def goo(self): pass > ... >>>> class B(A): > ... def goo(self): > ... print(1) > ... > > Both can get the same result: >>>> b = B() >>>> b.foo() > 1 >>>> > > What's the benefit of having the hook method goo() in class A in example 2? > > --Jach > None - as long as nobody tries one of those: a = A() a.foo() or class C(A): def foo(self): super().foo() print(2) c = C() c.foo() From rosuav at gmail.com Sat Oct 19 15:00:06 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 20 Oct 2019 06:00:06 +1100 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: On Sun, Oct 20, 2019 at 3:08 AM Steve White wrote: > It would appear that if __hash__ returns the id, then that id is used > internally as the key, and since the id is by definition unique, no > key collision ever occurs -- at least in every Python implementation > I've tried. It also seems that, for a class instance obj, > hash( hash( obj ) ) == hash( obj ) > hash( id( obj ) ) == id( obj ) > These are very strong and useful properties. Where are they documented? There are two rules that come into play here. One is that smallish integers use their own value as their hash (so hash(1)==1 etc); the other is that dictionaries actually look for something that matches on identity OR equality. That's why using identity instead of equality will appear to work, even though it can cause other problems when you mismatch them. ChrisA From benjamin at python.org Sat Oct 19 18:55:11 2019 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 19 Oct 2019 15:55:11 -0700 Subject: [RELEASE] Python 2.7.17 Message-ID: Greetings, I'm wealful to announce the immediate availability of Python 2.7.17, another bugfix release in the Python 2.7 series. Downloads are on python.org: https://www.python.org/downloads/release/python-2717/ No code changes occurred between the 2.7.17 release candidate and the final release, but there were some documentation changes. See the 2.7.17rc1 changelog for changes between 2.7.16 and 2.7.17: https://raw.githubusercontent.com/python/cpython/c2f86d86e6c8f5fd1ef602128b537a48f3f5c063/Misc/NEWS.d/2.7.17rc1.rst PEP 373, the Python 2.7 releases schedule, designates 2.7.17 as the penultimate Python 2.7 release. So, be aware that the upstream demise of Python 2 is not far away. For the time being, bugs may be reported to https://bugs.python.org. See you soon for The End, Benjamin From ml_news at posteo.de Sun Oct 20 00:40:34 2019 From: ml_news at posteo.de (Manfred Lotz) Date: Sun, 20 Oct 2019 06:40:34 +0200 Subject: Type checking Message-ID: <20191020064034.65ecb611@arcor.com> I had a look into type checking and tried a very simple example like the following: #!/usr/bin/env python3 def greeting(name: str) -> str: return 'Hello ' + name def main(): print(greeting(1)) if __name__ == "__main__": main() pytype complained as expected. BUT mypy says; Success: no issues found in 1 source file This is a Fedora 31 systems with: Python 3.7.4 mypy 0.730 Any idea why mypy doesn't detect anything? -- Manfred From ml_news at posteo.de Sun Oct 20 01:05:21 2019 From: ml_news at posteo.de (Manfred Lotz) Date: Sun, 20 Oct 2019 07:05:21 +0200 Subject: Type checking References: <20191020064034.65ecb611@arcor.com> <87lftg6mj4.fsf@nightsong.com> Message-ID: <20191020070521.518669e6@arcor.com> On Sat, 19 Oct 2019 21:58:23 -0700 Paul Rubin wrote: > Manfred Lotz writes: > > def main(): > > print(greeting(1)) > > > > Any idea why mypy doesn't detect anything? > > > "main" doesn't have a type signature so it doesn't get checked. The > mypy docs explain this. Try: > > def main() -> None: > print(greeting(1)) Aah, such easy. As pytype did it I didn't assume something like this. Thanks a lot. -- Manfred From wesp at outrelay.com Sun Oct 20 02:40:11 2019 From: wesp at outrelay.com (Wesley Peng) Date: Sun, 20 Oct 2019 06:40:11 +0000 (UTC) Subject: A news aggregator for the Python community In-Reply-To: References: Message-ID: <52bea8b8-fea8-7e5e-0946-1bcdcdc033ec@outrelay.com> Sebastian Steins wrote: > Over the last few weeks I've build a hacker news clone for the Python community: > > https://news.python.sc > > The source is at github.com/sebst/pythonic-news that looks interesting. thanks. From jfong at ms4.hinet.net Sun Oct 20 04:34:51 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sun, 20 Oct 2019 01:34:51 -0700 (PDT) Subject: What's the purpose the hook method showing in a class definition? In-Reply-To: References: <7d2efed5-054c-4e8b-93dd-b39b025ac18d@googlegroups.com> Message-ID: <52d2a80a-9310-43bb-9651-e3edc017a747@googlegroups.com> Sibylle Koczian? 2019?10?20???? UTC+8??2?04?54???? > Am 19.10.2019 um 13:11 schrieb jfong at ms4.hinet.net: > > For the two examples below: > > (1) > >>>> class A: > > ... def foo(self): > > ... self.goo() > > ... > >>>> class B(A): > > ... def goo(self): > > ... print(1) > > ... > > > > (2) > >>>> class A: > > ... def foo(self): > > ... self.goo() > > ... def goo(self): pass > > ... > >>>> class B(A): > > ... def goo(self): > > ... print(1) > > ... > > > > Both can get the same result: > >>>> b = B() > >>>> b.foo() > > 1 > >>>> > > > > What's the benefit of having the hook method goo() in class A in example 2? > > > > --Jach > > > None - as long as nobody tries one of those: > > a = A() > a.foo() > > or > > class C(A): > def foo(self): > super().foo() > print(2) > > c = C() > c.foo() Yes, there will be an attribute error if no goo() was defined. What puzzles me is how a parent's method foo() can find its child's method goo(), no matter it was overwrote or not? MRO won't explain this and I can't find document about it also:-( --Jach From hobson42 at gmail.com Sun Oct 20 06:04:53 2019 From: hobson42 at gmail.com (Ian Hobson) Date: Sun, 20 Oct 2019 11:04:53 +0100 Subject: What's the purpose the hook method showing in a class definition? In-Reply-To: <52d2a80a-9310-43bb-9651-e3edc017a747@googlegroups.com> References: <7d2efed5-054c-4e8b-93dd-b39b025ac18d@googlegroups.com> <52d2a80a-9310-43bb-9651-e3edc017a747@googlegroups.com> Message-ID: Hi Jach, On 20/10/2019 09:34, jfong at ms4.hinet.net wrote: > What puzzles me is how a parent's method foo() can find its child's method goo(), no matter it was overwrote or not? MRO won't explain this and I can't find document about it also:-( This is a generalised description - Python may be slightly different. When foo invokes goo the search for goo starts at the class of the object (which is B), not the class of the executing method (i.e not A). It then proceeds to look for goo up the class hierarchy - first in B, then A then Object. If that fails the RTS modifies the call, to look for a magic method, and starts again at B. When the magic method is found in Object, you get the "not found" error. If you implement the magic method in A or B it will be run instead. Regards Ian -- This email has been checked for viruses by AVG. https://www.avg.com From rosuav at gmail.com Sun Oct 20 06:32:13 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 20 Oct 2019 21:32:13 +1100 Subject: What's the purpose the hook method showing in a class definition? In-Reply-To: References: <7d2efed5-054c-4e8b-93dd-b39b025ac18d@googlegroups.com> <52d2a80a-9310-43bb-9651-e3edc017a747@googlegroups.com> Message-ID: On Sun, Oct 20, 2019 at 9:06 PM Ian Hobson wrote: > > Hi Jach, > > On 20/10/2019 09:34, jfong at ms4.hinet.net wrote: > > What puzzles me is how a parent's method foo() can find its child's method goo(), no matter it was overwrote or not? MRO won't explain this and I can't find document about it also:-( > > This is a generalised description - Python may be slightly different. > > When foo invokes goo the search for goo starts at the class of the > object (which is B), not the class of the executing method (i.e not A). > It then proceeds to look for goo up the class hierarchy - first in B, > then A then Object. > Yeah, pretty much. In a simple case of linear inheritance, that's how it works in Python. There are complexities with multiple inheritance and different languages will do things differently, but that doesn't affect this example. ChrisA From Richard at Damon-Family.org Sun Oct 20 07:26:16 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 20 Oct 2019 07:26:16 -0400 Subject: What's the purpose the hook method showing in a class definition? In-Reply-To: <52d2a80a-9310-43bb-9651-e3edc017a747@googlegroups.com> References: <7d2efed5-054c-4e8b-93dd-b39b025ac18d@googlegroups.com> <52d2a80a-9310-43bb-9651-e3edc017a747@googlegroups.com> Message-ID: On 10/20/19 4:34 AM, jfong at ms4.hinet.net wrote: > Yes, there will be an attribute error if no goo() was defined. > > What puzzles me is how a parent's method foo() can find its child's method goo(), no matter it was overwrote or not? MRO won't explain this and I can't find document about it also:-( > > --Jach The simple answer is that the attribute lookup happens at run time, not compile time (unlike some other languages). Thus attributes/member functions can be added by sub-classes, or even just to that instance at run time and be found. -- Richard Damon From stevan.white at gmail.com Sun Oct 20 10:00:38 2019 From: stevan.white at gmail.com (Steve White) Date: Sun, 20 Oct 2019 16:00:38 +0200 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: Hi Chris, Yes, I am aware of the hash of small integers. But I am not keying with small integers here: I am keying with id() values of class instances. Precisely what my example shows is that the dict/set algorithms in fact *never* call __eq__, when the id() of a class instance is returned by __hash__ (in the implementations of Python I have tested). Please try the code yourself. Tell me what I am missing. What "other problems"? Please provide an example! Thanks! On Sat, Oct 19, 2019 at 9:02 PM Chris Angelico wrote: > > On Sun, Oct 20, 2019 at 3:08 AM Steve White wrote: > > It would appear that if __hash__ returns the id, then that id is used > > internally as the key, and since the id is by definition unique, no > > key collision ever occurs -- at least in every Python implementation > > I've tried. It also seems that, for a class instance obj, > > hash( hash( obj ) ) == hash( obj ) > > hash( id( obj ) ) == id( obj ) > > These are very strong and useful properties. Where are they documented? > > There are two rules that come into play here. One is that smallish > integers use their own value as their hash (so hash(1)==1 etc); the > other is that dictionaries actually look for something that matches on > identity OR equality. That's why using identity instead of equality > will appear to work, even though it can cause other problems when you > mismatch them. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Sun Oct 20 11:14:02 2019 From: __peter__ at web.de (Peter Otten) Date: Sun, 20 Oct 2019 17:14:02 +0200 Subject: keying by identity in dict and set References: Message-ID: Steve White wrote: > Hi Chris, > > Yes, I am aware of the hash of small integers. But I am not keying > with small integers here: I am keying with id() values of class > instances. The id() values /are/ smallish integers though. (I would guess that this is baked into the CPython source, but did not actually check.) > Precisely what my example shows is that the dict/set algorithms in > fact *never* call __eq__, when the id() of a class instance is > returned by __hash__ (in the implementations of Python I have tested). > Please try the code yourself. Tell me what I am missing. I'd state that a bit differently: (0) Key objects in dicts/sets are only compared if they have the same hash value. The comparison works in two steps: (1) Are both objects the same (a is b --> True)? Then assume they are equal. (2) Are they different objects (a is b --> False)? Take the slow path and actually invoke __eq__ With a sufficiently weird equality: >>> class A: ... def __eq__(self, other): return False ... >>> a = A() >>> items = [a] >>> a in items True >>> [v for v in items if v == a] [] As you can see the hash is not involved (not even defined). > What "other problems"? Please provide an example! > > Thanks! > > On Sat, Oct 19, 2019 at 9:02 PM Chris Angelico wrote: >> >> On Sun, Oct 20, 2019 at 3:08 AM Steve White >> wrote: >> > It would appear that if __hash__ returns the id, then that id is used >> > internally as the key, and since the id is by definition unique, no >> > key collision ever occurs -- at least in every Python implementation >> > I've tried. It also seems that, for a class instance obj, >> > hash( hash( obj ) ) == hash( obj ) >> > hash( id( obj ) ) == id( obj ) >> > These are very strong and useful properties. Where are they >> > documented? >> >> There are two rules that come into play here. One is that smallish >> integers use their own value as their hash (so hash(1)==1 etc); the >> other is that dictionaries actually look for something that matches on >> identity OR equality. That's why using identity instead of equality >> will appear to work, even though it can cause other problems when you >> mismatch them. >> >> ChrisA >> -- >> https://mail.python.org/mailman/listinfo/python-list From ethan at stoneleaf.us Sun Oct 20 12:15:20 2019 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 20 Oct 2019 09:15:20 -0700 Subject: tri.token compared to Enum Message-ID: <089a16e3-8f15-e7ff-b63e-20952de82004@stoneleaf.us> On 10/20/2019 04:16 AM, Anders Hovm?ller wrote: > On 20 Oct 2019, at 12:41, Steve Jorgensen wrote: >> ?Anders Hovm?ller wrote: >>> We try to do the same thing in various libraries. We've settled on using existing >>> python and end up with syntax like: >>> >>> class MyForm(Form): >>> field = Field() >>> >>> or in your case >>> >>> class Colors(TokenContainer): >>> red = Token() >>> green = Token() >>> blue = Token() >>> >>> (this is using tri.token). >> >> This seems like a good approach and is similar to the strategy Enum uses. > > Site note: When we saw enums landing we hoped we could ditch tri.token but unfortunately enums have a bunch of limitations and restrictions that make them quite unusable for our more general use case :( Out of curiosity, which limitations? -- ~Ethan~ From stevan.white at gmail.com Sun Oct 20 13:31:43 2019 From: stevan.white at gmail.com (Steve White) Date: Sun, 20 Oct 2019 19:31:43 +0200 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: Hi Peter, Yes you are right. In fact, I shouldn't even have mentioned the hash() function... it came from a line of reasoning about what an implementation might do if very large integers were returned by __hash__(), and some remarks about the value returned by id() applied to small integers. The point is, I don't think __eq__() is ever called in a situation as described in my post, yet the Python documentation states that if instances are to be used as keys, it must not be used to determine if non-identical instances are equivalent. This puts developers like me in a rather bad position. The code seems to work as it is --- but we don't want to put out code that contravenes the documentation. The options for following the documentation in this situation are: either subject users to unfamiliar, custom-made container classes, or give up the semantics of the "==" operator. It seems so unnecessary, given (my understanding of) how the classes actually function. What can be done? I would be willing to consider a technical solution. I would like to see the documentation revised to reflect the actual workings of the existing container classes. A couple of sentences in the documentation of __hash__ could fix the problem. Is that too much to hope for? How would I proceed to get somebody to look at this? Thanks! On Sun, Oct 20, 2019 at 5:16 PM Peter Otten <__peter__ at web.de> wrote: > > Steve White wrote: > > > Hi Chris, > > > > Yes, I am aware of the hash of small integers. But I am not keying > > with small integers here: I am keying with id() values of class > > instances. > > The id() values /are/ smallish integers though. > > (I would guess that this is baked into the CPython source, but did not > actually check.) > > > Precisely what my example shows is that the dict/set algorithms in > > fact *never* call __eq__, when the id() of a class instance is > > returned by __hash__ (in the implementations of Python I have tested). > > Please try the code yourself. Tell me what I am missing. > > I'd state that a bit differently: > > (0) Key objects in dicts/sets are only compared if they have the same hash > value. > > The comparison works in two steps: > > (1) Are both objects the same (a is b --> True)? Then assume they are equal. > > (2) Are they different objects (a is b --> False)? Take the slow path and > actually invoke __eq__ > > With a sufficiently weird equality: > > >>> class A: > ... def __eq__(self, other): return False > ... > >>> a = A() > >>> items = [a] > >>> a in items > True > >>> [v for v in items if v == a] > [] > > As you can see the hash is not involved (not even defined). > > > What "other problems"? Please provide an example! > > > > Thanks! > > > > On Sat, Oct 19, 2019 at 9:02 PM Chris Angelico wrote: > >> > >> On Sun, Oct 20, 2019 at 3:08 AM Steve White > >> wrote: > >> > It would appear that if __hash__ returns the id, then that id is used > >> > internally as the key, and since the id is by definition unique, no > >> > key collision ever occurs -- at least in every Python implementation > >> > I've tried. It also seems that, for a class instance obj, > >> > hash( hash( obj ) ) == hash( obj ) > >> > hash( id( obj ) ) == id( obj ) > >> > These are very strong and useful properties. Where are they > >> > documented? > >> > >> There are two rules that come into play here. One is that smallish > >> integers use their own value as their hash (so hash(1)==1 etc); the > >> other is that dictionaries actually look for something that matches on > >> identity OR equality. That's why using identity instead of equality > >> will appear to work, even though it can cause other problems when you > >> mismatch them. > >> > >> ChrisA > >> -- > >> https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Sun Oct 20 13:54:26 2019 From: __peter__ at web.de (Peter Otten) Date: Sun, 20 Oct 2019 19:54:26 +0200 Subject: keying by identity in dict and set References: Message-ID: Steve White wrote: > Hi Peter, > > Yes you are right. In fact, I shouldn't even have mentioned the > hash() function... it came from a line of reasoning about what an > implementation might do if very large integers were returned by > __hash__(), and some remarks about the value returned by id() applied > to small integers. > > The point is, I don't think __eq__() is ever called in a situation as > described in my post, yet the Python documentation states that if > instances are to be used as keys, it must not be used to determine if > non-identical instances are equivalent. What else should be used if not __eq__()? Where in the docs did you you see such a statement? The only limitation for a working dict or set is that for its keys or elements (1) a == b implies hash(a) == hash(b) (2) a == a Does your custom class violate one of the above? From stevan.white at gmail.com Sun Oct 20 14:29:00 2019 From: stevan.white at gmail.com (Steve White) Date: Sun, 20 Oct 2019 20:29:00 +0200 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: On Sun, Oct 20, 2019 at 7:57 PM Peter Otten <__peter__ at web.de> wrote: > > Steve White wrote: > > > > The point is, I don't think __eq__() is ever called in a situation as > > described in my post, yet the Python documentation states that if > > instances are to be used as keys, it must not be used to determine if > > non-identical instances are equivalent. > > What else should be used if not __eq__()? Where in the docs did you you see > such a statement? > Nothing. Nowhere. As I said, it appears that if __hash__ returns values from the id() function, no collision ever occurs, so there is tie to break in a lookup, so in particular there is no need for the heuristic of calling __eq__. And again, the problem here is that the documentation is a little weak on just how these things really interact. We're having to guess, experiment, and even look at C code of the Python implementations. > The only limitation for a working dict or set is that for its keys or > elements > > (1) a == b implies hash(a) == hash(b) > (2) a == a > > Does your custom class violate one of the above? > Yes. It's all in the original post, including code. Give it a shot! Thanks! From rosuav at gmail.com Sun Oct 20 14:35:17 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Oct 2019 05:35:17 +1100 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: On Mon, Oct 21, 2019 at 4:33 AM Steve White wrote: > The options for following the documentation in this situation are: > either subject users to unfamiliar, custom-made container classes, or > give up the semantics of the "==" operator. > > It seems so unnecessary, given (my understanding of) how the classes > actually function. > > What can be done? I would be willing to consider a technical solution. > > I would like to see the documentation revised to reflect the actual > workings of the existing container classes. A couple of sentences in > the documentation of __hash__ could fix the problem. The definition of __hash__ is still correct. What you're looking at is a very specific situation wherein an object is not equal to itself - that's incredibly rare (in the core language, the ONLY thing that can ever be like this is a NaN). The dictionary's rule is that it finds any object that is either identical to, or equal to, the thing you asked for. ChrisA From __peter__ at web.de Sun Oct 20 16:12:27 2019 From: __peter__ at web.de (Peter Otten) Date: Sun, 20 Oct 2019 22:12:27 +0200 Subject: keying by identity in dict and set References: Message-ID: Steve White wrote: > On Sun, Oct 20, 2019 at 7:57 PM Peter Otten <__peter__ at web.de> wrote: >> >> Steve White wrote: >> > >> > The point is, I don't think __eq__() is ever called in a situation as >> > described in my post, yet the Python documentation states that if >> > instances are to be used as keys, it must not be used to determine if >> > non-identical instances are equivalent. >> >> What else should be used if not __eq__()? Where in the docs did you you >> see such a statement? >> > Nothing. Nowhere. > > As I said, it appears that if __hash__ returns values from the id() > function, no collision ever occurs, so there is tie to break in a lookup, > so in particular there is no need for the heuristic of calling __eq__. > > And again, the problem here is that the documentation is a little weak > on just how these things really interact. We're having to guess, > experiment, and even look at C code of the Python implementations. > >> The only limitation for a working dict or set is that for its keys or >> elements >> >> (1) a == b implies hash(a) == hash(b) >> (2) a == a >> >> Does your custom class violate one of the above? >> > Yes. It's all in the original post, including code. > Give it a shot! > > Thanks! OK. $ cat tmp.py class A: def __init__(self, hash): self._hash = hash def __eq__(self, other ): raise Exception("__eq__") def __hash__(self): return self._hash def same_hash(x): return hash(A(x)) == x $ python3 -i tmp.py >>> same_hash(2**63) False >>> same_hash(2**63-1) True The limit for smallish integers seems to be 2**63 for 64-bit CPython. As id() in CPython is the object's memory address you need data allocated above and below that limit to produce a hash collision and trigger __eq__. That appears to be rather unlikely. But even if I have this right it looks like you are relying on internals and I lack the fantasy to imagine a compelling use case. From piet-l at vanoostrum.org Sun Oct 20 17:27:34 2019 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Sun, 20 Oct 2019 23:27:34 +0200 Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> <6f4e13d8-df88-435d-9dbd-30bf018b11b6@googlegroups.com> Message-ID: doganadres at gmail.com writes: > > In the meanwhile I have checked Scala , and it's more limited then Python. > As an example: > 0.0001 > 1.0E-4: Double > Why do you think this means Scala is more limited than Python? -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From stevan.white at gmail.com Sun Oct 20 17:40:49 2019 From: stevan.white at gmail.com (Steve White) Date: Sun, 20 Oct 2019 23:40:49 +0200 Subject: Fwd: keying by identity in dict and set In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Steve White Date: Sun, Oct 20, 2019 at 11:38 PM Subject: Re: keying by identity in dict and set To: Peter Otten <__peter__ at web.de> Hi Peter, Thanks, that does seem to indicate something. (But there was no need to define a class... you're basically saying >>> hash(2**63-1) == 2**63-1 True >>> hash(2**63) == 2**63 False } As was pointed out in a previous posting though, hash() really doesn't come into the question. It was perhaps a mistake of me to bring it up... As to fantasy... I am a little surprised that some people find such a thing surprising. In other environments, I've often refereed to objects directly by their identity... in C and C++ this is often handled simply by using pointers. Anyway... does anybody have a suggestion of how best to bring this up to the powers that be? A little further explanation would have saved me a great deal of time (even if the answer is that for some reason one must never never do such a thing.) Thanks! On Sun, Oct 20, 2019 at 10:15 PM Peter Otten <__peter__ at web.de> wrote: > > Steve White wrote: > > > On Sun, Oct 20, 2019 at 7:57 PM Peter Otten <__peter__ at web.de> wrote: > >> > >> Steve White wrote: > >> > > >> > The point is, I don't think __eq__() is ever called in a situation as > >> > described in my post, yet the Python documentation states that if > >> > instances are to be used as keys, it must not be used to determine if > >> > non-identical instances are equivalent. > >> > >> What else should be used if not __eq__()? Where in the docs did you you > >> see such a statement? > >> > > Nothing. Nowhere. > > > > As I said, it appears that if __hash__ returns values from the id() > > function, no collision ever occurs, so there is tie to break in a lookup, > > so in particular there is no need for the heuristic of calling __eq__. > > > > And again, the problem here is that the documentation is a little weak > > on just how these things really interact. We're having to guess, > > experiment, and even look at C code of the Python implementations. > > > >> The only limitation for a working dict or set is that for its keys or > >> elements > >> > >> (1) a == b implies hash(a) == hash(b) > >> (2) a == a > >> > >> Does your custom class violate one of the above? > >> > > Yes. It's all in the original post, including code. > > Give it a shot! > > > > Thanks! > > OK. > > $ cat tmp.py > class A: > def __init__(self, hash): > self._hash = hash > def __eq__(self, other ): > raise Exception("__eq__") > def __hash__(self): > return self._hash > > def same_hash(x): > return hash(A(x)) == x > $ python3 -i tmp.py > >>> same_hash(2**63) > False > >>> same_hash(2**63-1) > True > > The limit for smallish integers seems to be 2**63 for 64-bit CPython. As > id() in CPython is the object's memory address you need data allocated above > and below that limit to produce a hash collision and trigger __eq__. That > appears to be rather unlikely. > > But even if I have this right it looks like you are relying on internals and > I lack the fantasy to imagine a compelling use case. > > -- > https://mail.python.org/mailman/listinfo/python-list From phoenix1987 at gmail.com Sun Oct 20 17:58:12 2019 From: phoenix1987 at gmail.com (Gabriele) Date: Sun, 20 Oct 2019 21:58:12 GMT Subject: [ANN] Austin -- CPython frame stack sampler v1.0.0 is now available Message-ID: I am delighted to announce the release 1.0.0 of Austin. If you haven't heard of Austin before, it is a frame stack sampler for CPython. It can be used to obtain statistical profiling data out of a running Python application without a single line of instrumentation. This means that you can start profiling a Python application straightaway, even while it's running on a production environment, with minimal impact on performance. The simplest way of using Austin is by piping its output to FlameGraph for a quick and detailed representation of the collected samples. The latest release introduces a memory profiling mode which allows you to profile memory usage. Austin is a pure C application that has no other dependencies other than the C standard library. Its source code is hosted on GitHub at https://github.com/P403n1x87/austin The README contains installation and usage details, as well as some examples of Austin in action. Details on how to contribute to Austin's development can be found at the bottom of the page. All the best, Gabriele What's New ========== - Added support for multi-process Python applications. - Added support for Python 3.8. Bugfixes ======== - Fixed support for WSL on Windows. From doganadres at gmail.com Sun Oct 20 18:03:35 2019 From: doganadres at gmail.com (doganadres at gmail.com) Date: Sun, 20 Oct 2019 15:03:35 -0700 (PDT) Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> <6f4e13d8-df88-435d-9dbd-30bf018b11b6@googlegroups.com> Message-ID: <65e845d6-e039-4e10-8cb7-2784283edaa8@googlegroups.com> my statement may seem unlogical while evaluating and comparing the languages as a whole.. I thought when I give a small number into the programme , the more decimals I can see after the dot as an output, the more human readable it is. when I see a bunch of numbers with 'e' s I know the numbers are small but it is hard for me to compare it to other numbers with 'e'. , specially with the human eye. I dont know much about scala actually. I have just have tried to give 0.0001 and it returned a presentation with an 'e' .whereas python takes 0.0001 and gives 0.0001 . it made me think python is better in that specific subject. However, python though starts to give 'e' number when 5 decimals are given as input. Although there can be systems around which are better in this subject other things I can achieve in python overrides some disadvantages. From jfong at ms4.hinet.net Sun Oct 20 19:57:54 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Sun, 20 Oct 2019 16:57:54 -0700 (PDT) Subject: What's the purpose the hook method showing in a class definition? In-Reply-To: References: <7d2efed5-054c-4e8b-93dd-b39b025ac18d@googlegroups.com> <52d2a80a-9310-43bb-9651-e3edc017a747@googlegroups.com> Message-ID: <3dd48d6a-838d-41d4-8324-d7757fca2192@googlegroups.com> Ian Hobson? 2019?10?20???? UTC+8??6?05?11???? > Hi Jach, > > On 20/10/2019 09:34, jfong at ms4.hinet.net wrote: > > What puzzles me is how a parent's method foo() can find its child's method goo(), no matter it was overwrote or not? MRO won't explain this and I can't find document about it also:-( > > This is a generalised description - Python may be slightly different. > > When foo invokes goo the search for goo starts at the class of the > object (which is B), not the class of the executing method (i.e not A). > It then proceeds to look for goo up the class hierarchy - first in B, > then A then Object. > > If that fails the RTS modifies the call, to look for a magic method, and > starts again at B. When the magic method is found in Object, you get the > "not found" error. If you implement the magic method in A or B it will > be run instead. > > Regards > > Ian > > -- > This email has been checked for viruses by AVG. > https://www.avg.com I see. An obj.method will be resolved according to the MRO of the obj's class, no matter where it is located. Thank you. --Jach From joel.goldstick at gmail.com Sun Oct 20 22:30:40 2019 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 20 Oct 2019 22:30:40 -0400 Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: <65e845d6-e039-4e10-8cb7-2784283edaa8@googlegroups.com> References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> <6f4e13d8-df88-435d-9dbd-30bf018b11b6@googlegroups.com> <65e845d6-e039-4e10-8cb7-2784283edaa8@googlegroups.com> Message-ID: On Sun, Oct 20, 2019 at 6:06 PM wrote: > > > my statement may seem unlogical while evaluating and comparing the languages as a whole.. > > I thought when I give a small number into the programme , the more decimals I can see after the dot as an output, the more human readable it is. > > when I see a bunch of numbers with 'e' s I know the numbers are small but it is hard for me to compare it to other numbers with 'e'. , specially with the human eye. > > I dont know much about scala actually. I have just have tried to give 0.0001 and it returned a presentation with an 'e' .whereas python takes 0.0001 and gives 0.0001 . it made me think python is better in that specific subject. > > However, python though starts to give 'e' number when 5 decimals are given as input. Although there can be systems around which are better in this subject other things I can achieve in python overrides some disadvantages. > -- > https://mail.python.org/mailman/listinfo/python-list The question here has nothing to do with a programming language. As a bystander, this thread is interesting in a strange way. We have a poster who has no programming experience, no background to understand floating point numbers, no concept of the difference between an internal computer usable representation of a number, and a human readable representation. I am sure I am much older than many people here. When I first learned about computers, and programming, and number formats, I also learned about binary numbers, how computers perform arithmetic calculations at a bit level, and lots of things no one really cares about today. Fast forward and we have a person who (I'm guessing) is trying to write a program to complete some schoolwork in a subject far afield for learning about computer programming. Although the problem to be solved seems to be statistical or somehow numeric, the poster doesn't seem to understand so much about the math either, having gone haywire over exponential notation. It is great that computers are so commonplace that problems can be studied and solved with them when the problem solver has so little basic understanding of the tool he is using. But the thread shows the downside to lacking the basics about the tool. I don't mean any negative connotation toward to original poster. The problem he poses is legitimate, and confounding for him and for those who have tried to answer him here since there are these hard disconnects about concepts that are required to understand the question. Its a problem that everyone confronts daily -- No one really knows how anything works under the hood. Think: car, toaster, microwave oven, Facebook algorithms, light bulbs, and on and on.... -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From rosuav at gmail.com Mon Oct 21 00:51:40 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Oct 2019 15:51:40 +1100 Subject: In praise of triple-quoted strings Message-ID: Python's triple-quoted multiline string is a wonderful feature. It vastly simplifies the writing of polyglot scripts (where the same file contains multiple different languages of code in it), hiding any non-Python code inside a triple quoted string. Had need of a Makefile+Python setup today... (Note that if the formatting is messed up, just make sure the "@python3 Makefile" line is indented with exactly one tab.) # Makefile+Python script hide_from_python = """ " all: README.md @python3 Makefile define now_hide_from_make = " """ # At this point, it's all Python. :) import this print("Hello, world") # Postscript to clean everything up. """ " endef end_all_hiding = " """ ----------- The same trick can be done with quite a few other languages. The non-Python part might be a shell script that locates an interpreter, an Markdown file that explains what to do if you accidentally displayed this file instead of downloading it, a Pike server that runs a supporting server (that one's easy since Pike has a multiline string spelled #" ... ", which looks like a comment to Python), a systemd service file to symlink into your jobs directory... you name it. The only hard part is making the OTHER language ignore the parts it needs to ignore! :) ChrisA From piet-l at vanoostrum.org Mon Oct 21 04:42:10 2019 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Mon, 21 Oct 2019 10:42:10 +0200 Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> <6f4e13d8-df88-435d-9dbd-30bf018b11b6@googlegroups.com> <65e845d6-e039-4e10-8cb7-2784283edaa8@googlegroups.com> Message-ID: doganadres at gmail.com writes: > I dont know much about scala actually. I have just have tried to give > 0.0001 and it returned a presentation with an 'e' .whereas python takes > 0.0001 and gives 0.0001 . it made me think python is better in that > specific subject. > > However, python though starts to give 'e' number when 5 decimals are > given as input. Although there can be systems around which are better in > this subject other things I can achieve in python overrides some > disadvantages. Yes, I would say Python is more user-friendly in this particular example, although both outputs are correct. If I remember correctly, Python had an update in the area several years ago to make the output for floating-point numbers more user-friendly, (and at the same time maybe even more correct). But these are just choices of the implementers of the language, not characteristics of the language itself. -- Pieter van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From piet-l at vanoostrum.org Mon Oct 21 09:09:09 2019 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Mon, 21 Oct 2019 15:09:09 +0200 Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> <6f4e13d8-df88-435d-9dbd-30bf018b11b6@googlegroups.com> <65e845d6-e039-4e10-8cb7-2784283edaa8@googlegroups.com> Message-ID: Piet van Oostrum writes: > doganadres at gmail.com writes: > >> I dont know much about scala actually. I have just have tried to give >> 0.0001 and it returned a presentation with an 'e' .whereas python takes >> 0.0001 and gives 0.0001 . it made me think python is better in that >> specific subject. >> >> However, python though starts to give 'e' number when 5 decimals are >> given as input. Although there can be systems around which are better in >> this subject other things I can achieve in python overrides some >> disadvantages. > > Yes, I would say Python is more user-friendly in this particular > example, although both outputs are correct. If I remember correctly, > Python had an update in the area several years ago to make the output > for floating-point numbers more user-friendly, (and at the same time > maybe even more correct). > > But these are just choices of the implementers of the language, not > characteristics of the language itself. In Python 0.00001 => 1e-05, so it just chooses a different point to switch from pure decimal to scientific notation. -- Pieter van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From lizhollinshead5 at gmail.com Mon Oct 21 10:18:13 2019 From: lizhollinshead5 at gmail.com (lizhollinshead5 at gmail.com) Date: Mon, 21 Oct 2019 07:18:13 -0700 (PDT) Subject: Black Message-ID: What do people think about black? I'm asking because one of my personal preferences is to use spaces for clarity: 1. right = mystr[ start : ] black version right=mystr[start:] 2. mtime = time.asctime( time.localtime( info.st_mtime ) ) black version mtime = time.asctime(time.localtime(info.st_mtime)) Is there a reason why PEP8 doesn't like these spaces? From rhodri at kynesim.co.uk Mon Oct 21 10:47:28 2019 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 21 Oct 2019 15:47:28 +0100 Subject: Black In-Reply-To: References: Message-ID: On 21/10/2019 15:18, lizhollinshead5 at gmail.com wrote: > What do people think about black? It's the new orange? Seriously, some context would be good. I take it from a quick Google that black is a Python code formatter that makes some frankly rather dubious claims for what it will do to your coding. > I'm asking because one of my personal preferences is to use spaces for clarity: If your personal preference is not the same as black's, it looks like you shouldn't use black. Just asking the question indicates that you are intending to fight with it, and that's bound to be a waste of energy. > > 1. right = mystr[ start : ] > > black version right=mystr[start:] > > 2. mtime = time.asctime( time.localtime( info.st_mtime ) ) > > black version mtime = time.asctime(time.localtime(info.st_mtime)) > > Is there a reason why PEP8 doesn't like these spaces? All I can offer is my personal opinion that brackets of all sorts are their own spacing, and additional spaces reduce clarity rather than increase it. On the other hand I do put extra spaces around everything other than ":" and ".". But like I said, that's my personal preference. (Which indicates that I too shouldn't consider using black!) -- Rhodri James *-* Kynesim Ltd From p.f.moore at gmail.com Mon Oct 21 10:49:03 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 21 Oct 2019 15:49:03 +0100 Subject: Black In-Reply-To: References: Message-ID: IMO, if you care enough to not like black's formatting choices, you probably shouldn't use it. The point of black is to *not* care about formatting, but leave the decisions to the tool. If you're not doing that, then it's probably the wrong tool for you. There may be other code formatters that are more configurable - I honestly don't know - and which therefore may be more useful to you once configured to your liking. But black is (as I understand it) about *not* worrying about formatting choices, so you can get on to other more important decisions. Personally, I don't really like some of black's choices. So I only use it on projects where I'm tired of worrying about formatting and readability and just want something that's OK. Over time, I'm finding that's true of more and more of my projects :-) Regarding your question on spaces, I like some of your spacing choices, but not all of them. So we could have a debate over precisely which spaces I agree with and which I don't. But I'm not really interested in doing that. Black would probably help if we had to work together, but unless we do, you can do what you want and I won't mind :-) Paul On Mon, 21 Oct 2019 at 15:22, wrote: > > What do people think about black? > > I'm asking because one of my personal preferences is to use spaces for clarity: > > 1. right = mystr[ start : ] > > black version right=mystr[start:] > > 2. mtime = time.asctime( time.localtime( info.st_mtime ) ) > > black version mtime = time.asctime(time.localtime(info.st_mtime)) > > Is there a reason why PEP8 doesn't like these spaces? > -- > https://mail.python.org/mailman/listinfo/python-list From PythonList at DancesWithMice.info Mon Oct 21 14:23:32 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 22 Oct 2019 07:23:32 +1300 Subject: Black In-Reply-To: References: Message-ID: <0c9e60f8-d8d0-7660-8ff7-8d4527e4b550@DancesWithMice.info> Top posting? Agreed. As my eyes age (they're even older than my teeth!) I find the additional horizontal white space improves (my) comprehension, particularly when dealing with a dense nesting of structures. Of course the more 'across' the text stretches, the more likely a vertical expansion will also result. Some folk dislike the spaces, and claim the opposite effect. Strangely-enough, when I linked their coding views to their clothing choices (gaps, over-laps, ...) then it became a matter of 'personal freedom' and a cant that others/employers should not confuse outward appearance with (inner) competence. Then again, notice my (optional) parentheses here, and how there's no spaces 'inside' them - which do appear in my Python. Inconsistency is a human condition. We are not machines. A tool is something which will make one's life easier, but harmony within a team is an intangible value and much under-rated - until experienced! On 22/10/19 3:49 AM, Paul Moore wrote: > IMO, if you care enough to not like black's formatting choices, you > probably shouldn't use it. The point of black is to *not* care about > formatting, but leave the decisions to the tool. If you're not doing > that, then it's probably the wrong tool for you. There may be other > code formatters that are more configurable - I honestly don't know - > and which therefore may be more useful to you once configured to your > liking. But black is (as I understand it) about *not* worrying about > formatting choices, so you can get on to other more important > decisions. > > Personally, I don't really like some of black's choices. So I only use > it on projects where I'm tired of worrying about formatting and > readability and just want something that's OK. Over time, I'm finding > that's true of more and more of my projects :-) > > Regarding your question on spaces, I like some of your spacing > choices, but not all of them. So we could have a debate over precisely > which spaces I agree with and which I don't. But I'm not really > interested in doing that. Black would probably help if we had to work > together, but unless we do, you can do what you want and I won't mind > :-) > > Paul > > On Mon, 21 Oct 2019 at 15:22, wrote: >> >> What do people think about black? >> >> I'm asking because one of my personal preferences is to use spaces for clarity: >> >> 1. right = mystr[ start : ] >> >> black version right=mystr[start:] >> >> 2. mtime = time.asctime( time.localtime( info.st_mtime ) ) >> >> black version mtime = time.asctime(time.localtime(info.st_mtime)) >> >> Is there a reason why PEP8 doesn't like these spaces? >> -- >> https://mail.python.org/mailman/listinfo/python-list -- Regards =dn From doganadres at gmail.com Mon Oct 21 16:36:59 2019 From: doganadres at gmail.com (doganadres at gmail.com) Date: Mon, 21 Oct 2019 13:36:59 -0700 (PDT) Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> <6f4e13d8-df88-435d-9dbd-30bf018b11b6@googlegroups.com> <65e845d6-e039-4e10-8cb7-2784283edaa8@googlegroups.com> Message-ID: <02fc0e0e-1744-4048-822c-ca29c42f74ad@googlegroups.com> On Monday, October 21, 2019 at 4:09:23 PM UTC+3, Piet van Oostrum wrote: > Piet van Oostrum writes: > > > doganadres at gmail.com writes: > > > >> I dont know much about scala actually. I have just have tried to give > >> 0.0001 and it returned a presentation with an 'e' .whereas python takes > >> 0.0001 and gives 0.0001 . it made me think python is better in that > >> specific subject. > >> > >> However, python though starts to give 'e' number when 5 decimals are > >> given as input. Although there can be systems around which are better in > >> this subject other things I can achieve in python overrides some > >> disadvantages. > > > > Yes, I would say Python is more user-friendly in this particular > > example, although both outputs are correct. If I remember correctly, > > Python had an update in the area several years ago to make the output > > for floating-point numbers more user-friendly, (and at the same time > > maybe even more correct). > > > > But these are just choices of the implementers of the language, not > > characteristics of the language itself. > > In Python 0.00001 => 1e-05, so it just chooses a different point to > switch from pure decimal to scientific notation. > -- > Pieter van Oostrum > WWW: http://piet.vanoostrum.org/ > PGP key: [8DAE142BE17999C4] They ought to have a reason to make the program switch from pure decimal to scientific notation representation. I don't know that reason. Getting along with it. From rosuav at gmail.com Mon Oct 21 16:57:34 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Oct 2019 07:57:34 +1100 Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: <02fc0e0e-1744-4048-822c-ca29c42f74ad@googlegroups.com> References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> <6f4e13d8-df88-435d-9dbd-30bf018b11b6@googlegroups.com> <65e845d6-e039-4e10-8cb7-2784283edaa8@googlegroups.com> <02fc0e0e-1744-4048-822c-ca29c42f74ad@googlegroups.com> Message-ID: On Tue, Oct 22, 2019 at 7:41 AM wrote: > > They ought to have a reason to make the program switch from pure decimal to scientific notation representation. I don't know that reason. Getting along with it. > This is JUST a default display representation. Nothing more. If you care about how something is displayed, just use a formatting tool. That's all you need to do. ChrisA From sjeik_appie at hotmail.com Mon Oct 21 17:16:12 2019 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Mon, 21 Oct 2019 21:16:12 +0000 Subject: python2 vs python3 In-Reply-To: Message-ID: On 18 Oct 2019 20:36, Chris Angelico wrote: On Sat, Oct 19, 2019 at 5:29 AM Jagga Soorma wrote: > > Hello, > > I am writing my second python script and got it to work using > python2.x. However, realized that I should be using python3 and it > seems to fail with the following message: > > -- > Traceback (most recent call last): > File "test_script.py", line 29, in > test_cmd = ("diskcmd -u " + x + " | grep -v '\*' | awk '{print $1, > $3, $4, $9, $10}'" ) > TypeError: Can't convert 'bytes' object to str implicitly > -- > > I then run this command and save the output like this: > > -- > test_info = (subprocess.check_output( test_cmd, > stderr=subprocess.STDOUT, shell=True )).splitlines() > -- > > Looks like the command output is in bytes and I can't simply wrap that > around str(). Thanks in advance for your help with this. >That's correct. The output of the command >is, by default, given to you >in bytes. Do you happen to know why this is the default? And is there a reliable way to figure out the encoding? On posix, it's probably utf8, but on windows I usually use cp437, but knowing windows, it could be any codepage (you can even change it with chcp.exe) From rosuav at gmail.com Mon Oct 21 17:22:35 2019 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Oct 2019 08:22:35 +1100 Subject: python2 vs python3 In-Reply-To: References: Message-ID: On Tue, Oct 22, 2019 at 8:16 AM Albert-Jan Roskam wrote: > > > > On 18 Oct 2019 20:36, Chris Angelico wrote: > > On Sat, Oct 19, 2019 at 5:29 AM Jagga Soorma wrote: > > > > Hello, > > > > I am writing my second python script and got it to work using > > python2.x. However, realized that I should be using python3 and it > > seems to fail with the following message: > > > > -- > > Traceback (most recent call last): > > File "test_script.py", line 29, in > > test_cmd = ("diskcmd -u " + x + " | grep -v '\*' | awk '{print $1, > > $3, $4, $9, $10}'" ) > > TypeError: Can't convert 'bytes' object to str implicitly > > -- > > > > I then run this command and save the output like this: > > > > -- > > test_info = (subprocess.check_output( test_cmd, > > stderr=subprocess.STDOUT, shell=True )).splitlines() > > -- > > > > Looks like the command output is in bytes and I can't simply wrap that > > around str(). Thanks in advance for your help with this. > > >That's correct. The output of the command >is, by default, given to you > >in bytes. > > > Do you happen to know why this is the default? Because at the OS level, it's all bytes. > And is there a reliable way to figure out the encoding? On posix, it's probably utf8, but on windows I usually use cp437, but knowing windows, it could be any codepage (you can even change it with chcp.exe) > Reliable? Nope. You can guess at what your local console would expect, but there's no way to be certain what a program will produce. You can't even be sure that the program will produce text - for instance, I have quite often piped data into or out of FFMPEG, which means the encoding isn't "UTF-8" or "Windows-1252", but is something like "16-bit 44KHz WAV". If you're uncertain, I would recommend attempting to decode the data as either ASCII or UTF-8. Most of the encodings you'll come across will be ASCII-compatible, meaning that decoding as ASCII will either succeed and give the right result, or fail with a clear exception. UTF-8 is designed to be similarly reliable, so you should generally be able to assume that a successful UTF-8 decode will give you the correct result. ChrisA From joel.goldstick at gmail.com Mon Oct 21 17:27:03 2019 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 21 Oct 2019 17:27:03 -0400 Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> <6f4e13d8-df88-435d-9dbd-30bf018b11b6@googlegroups.com> <65e845d6-e039-4e10-8cb7-2784283edaa8@googlegroups.com> <02fc0e0e-1744-4048-822c-ca29c42f74ad@googlegroups.com> Message-ID: On Mon, Oct 21, 2019 at 4:59 PM Chris Angelico wrote: > > On Tue, Oct 22, 2019 at 7:41 AM wrote: > > > > They ought to have a reason to make the program switch from pure decimal to scientific notation representation. I don't know that reason. Getting along with it. > > > > This is JUST a default display representation. Nothing more. If you > care about how something is displayed, just use a formatting tool. > That's all you need to do. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list Exactly! -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From doganadres at gmail.com Mon Oct 21 17:30:38 2019 From: doganadres at gmail.com (doganadres at gmail.com) Date: Mon, 21 Oct 2019 14:30:38 -0700 (PDT) Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> <6f4e13d8-df88-435d-9dbd-30bf018b11b6@googlegroups.com> <65e845d6-e039-4e10-8cb7-2784283edaa8@googlegroups.com> <02fc0e0e-1744-4048-822c-ca29c42f74ad@googlegroups.com> Message-ID: For me. The problem is solved. Thank you for your participation. From barry at barrys-emacs.org Mon Oct 21 17:37:09 2019 From: barry at barrys-emacs.org (Barry) Date: Mon, 21 Oct 2019 22:37:09 +0100 Subject: [ANN] Austin -- CPython frame stack sampler v1.0.0 is now available In-Reply-To: References: Message-ID: <352E42CB-1D36-49A7-94A2-3EFFC165620B@barrys-emacs.org> > On 20 Oct 2019, at 23:12, Gabriele wrote: > > The > latest release introduces a memory profiling mode which allows you to > profile memory usage. I am curious how do you determine used memory for Python Program? What is you definition of ?memory?? The reason I am asking is that I have looked into this for a production server app and found only approximations. Barry From eryksun at gmail.com Mon Oct 21 18:21:15 2019 From: eryksun at gmail.com (Eryk Sun) Date: Mon, 21 Oct 2019 17:21:15 -0500 Subject: python2 vs python3 In-Reply-To: References: Message-ID: On 10/21/19, Albert-Jan Roskam wrote: > On 18 Oct 2019 20:36, Chris Angelico wrote: > >> That's correct. The output of the command is, by default, given to you >> in bytes. > > Do you happen to know why this is the default? And is there a reliable way > to figure out the encoding? On posix, it's probably utf8, but on windows I > usually use cp437, but knowing windows, it could be any codepage In Python 3.6+ on Windows, use "oem" instead of assuming OEM is codepage 437. In Western Europe, OEM is 850, and in Windows 10 it can even be set to 65001 (i.e. UTF-8). Python also supports "ansi" ("mbcs"). These two are implemented via codecs.code_page_encode and codecs.code_page_decode, so, for better or worse, they use the Windows best-fit 'replace' error handling instead of just "?". For example: >>> c = '\N{GREEK SMALL LETTER BETA}' >>> c_oem = c.encode('oem', 'replace').decode('oem') >>> c_oem '?' >>> unicodedata.name(c_oem) 'LATIN SMALL LETTER SHARP S' I'd like to also have something like "conin" and "conout" encodings that use the attached console's current input and output codepages. But at least it's simple to a write a little ctypes-based function that implements this. When writing to a pipe, almost all Windows command-line programs default to one of OEM, ANSI, the current console input or output codepage, UTF-8, or UTF-16. The latter two may also write a UTF byte order mark (BOM). Sometimes the output encoding can be configured via command-line options or environment variables (e.g. ipconfig.exe supports an "OutputEncoding" environment variable). > (you can even change it with chcp.exe) It's actually "chcp.com". Thus subprocess.Popen('chcp') fails because CreateProcessW only adds ".EXE" when looking for the executable. This binary uses the ".com" extension for compatibility with legacy batch scripts. But don't let the extension fool you. It's just a regular Windows PE binary, not a 16-bit MS-DOS binary. As mentioned above, some programs use either the console input or output codepage when writing to a pipe. This does not include Windows Python, however, which instead defaults to ANSI. This can be overridden via environment variables and command-line options that set the standard I/O encoding or force UTF-8 mode. From cs at cskk.id.au Mon Oct 21 18:46:19 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 22 Oct 2019 09:46:19 +1100 Subject: Black In-Reply-To: References: Message-ID: <20191021224619.GA90189@cskk.homeip.net> On 21Oct2019 07:18, lizhollinshead5 at gmail.com wrote: >What do people think about black? Personally, I prefer yapf. Details below. >I'm asking because one of my personal preferences is to use spaces for clarity: > >1. right = mystr[ start : ] > > black version right=mystr[start:] > >2. mtime = time.asctime( time.localtime( info.st_mtime ) ) > > black version mtime = time.asctime(time.localtime(info.st_mtime)) > >Is there a reason why PEP8 doesn't like these spaces? Probably compactness and the personal opinions of the python devs at the time. Also, PEP8 is for the stdlib. It is certainly a reasonable style for other code, but you're under no obligation to use it, either rigidly or at all). I was asked this question back in June (I prefer yapf to black, more tunable), and I'll repost my reply here: On 29Jun2019 10:19, Malcolm Greene wrote: > > I've also taken to having my files auto-formatted with yapf on save > > ... > > @Cameron: Have you considered black at all and if so, what are your > thoughts? I did consider black. Its core selling point was its total inflexibility. Use this and stop _caring_ about the formatting: it will be PEP8 compliant and readable. It is like "go fmt" in that regard (Which I use with Go, when I use Go - you can see that in the "format" script I posted). The target here is: all code uses the same style, the chosen style is good (readable, reasonable, acceptable to most people), let's just use it and spent our time worrying about coding instead of style. However, I want flexibility. Like the OP, I use 2 spece indentation and have my own foibles. Here is the .style.yapf file I use in my personal code: [style] based_on_style = pep8 blank_line_before_module_docstring = True blank_line_before_nested_class_or_def = True blank_lines_around_top_level_definition = 1 dedent_closing_brackets = True #indent_dictionary_value = True indent_width = 2 split_before_expression_after_opening_paren = True split_before_first_argument = True split_complex_comprehension = True space_between_ending_comma_and_closing_bracket = False split_before_dot = true use_tabs = False This comes remarkably close to the style I was hand applying before biting the bullet and putting in the work required to get my editor to autoformat on save. [ Aside: another nice thing about autoformatting, over the "nice!" feeling one gets seeing the code shuffle around in front of one's face, is that if there's a syntax error the code _doesn't_ shuffle around and one can go "whoops" and eyeball the code more closely. ] Cheers, Cameron Simpson From phoenix1987 at gmail.com Mon Oct 21 18:40:22 2019 From: phoenix1987 at gmail.com (Gabriele) Date: Mon, 21 Oct 2019 23:40:22 +0100 Subject: [ANN] Austin -- CPython frame stack sampler v1.0.0 is now available In-Reply-To: <352E42CB-1D36-49A7-94A2-3EFFC165620B@barrys-emacs.org> References: <352E42CB-1D36-49A7-94A2-3EFFC165620B@barrys-emacs.org> Message-ID: Austin computes the deltas of resident memory between samples. That's because resident memory is the closest to the actual space occupied in physical memory. I hope this answers your question! Best, G On Mon, 21 Oct 2019, 22:37 Barry, wrote: > > > > On 20 Oct 2019, at 23:12, Gabriele wrote: > > > > The > > latest release introduces a memory profiling mode which allows you to > > profile memory usage. > > I am curious how do you determine used memory for Python > Program? > What is you definition of ?memory?? > > The reason I am asking is that I have looked into this for a production > server app and found only approximations. > > Barry > > > From joepareti54 at gmail.com Tue Oct 22 04:44:48 2019 From: joepareti54 at gmail.com (joseph pareti) Date: Tue, 22 Oct 2019 10:44:48 +0200 Subject: issue with regular expressions Message-ID: the following code ends in an exception: import re pattern = 'Sottoscrizione unica soluzione' mylines = [] # Declare an empty list. with open ('tmp.txt', 'rt') as myfile: # Open tmp.txt for reading text. for myline in myfile: # For each line in the file, mylines.append(myline.rstrip('\n')) # strip newline and add to list. for element in mylines: # For each element in the list, # print(element) match = re.search(pattern, element) s = match.start() e = match.end() print(element[s:e]) F:\October20-2019-RECOVERY\Unicredit_recovery\tmp_re_search>c:\Users\joepareti\Miniconda3\pkgs\python-3.7.1-h8c8aaf0_6\python.exe search_0.py Traceback (most recent call last): File "search_0.py", line 10, in s = match.start() AttributeError: 'NoneType' object has no attribute 'start' any help? Thanks -- Regards, Joseph Pareti - Artificial Intelligence consultant Joseph Pareti's AI Consulting Services https://www.joepareti54-ai.com/ cell +49 1520 1600 209 cell +39 339 797 0644 From antoon.pardon at vub.be Tue Oct 22 04:58:26 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 22 Oct 2019 10:58:26 +0200 Subject: problem with curring in python Message-ID: Using python 3.5 I have been experimenting with curried functions. A bit like in Haskell. So I can write the following function: def sum4(a, b, c, d): return a + b + c + d summing = curry(sum4) print summing(1)(2)(3)(4) # this prints 10. The problem is I need the signature of the original function in order to know when to finally call the function and return the actual result. However buildin functions don't have a signature. Here below is my current experimental implementation. Any ideas for an other approach? def curry(func, *args): arg_len = len(signature(func).parameters) if arg_len <= len(args): return func(*args) else: return CurryType(func, arg_len, args) class CurryType: def __init__(self, func, arg_len, args): self.func = func self.arg_len = arg_len self.args = list(args) def __call__(self, *args): args = self.args + list(args) if self.arg_len <= len(args): return self.func(*args) else: return CurryType(self.func, self.arg_len, args) From gerrit.muller at gmail.com Tue Oct 22 05:23:06 2019 From: gerrit.muller at gmail.com (GerritM) Date: Tue, 22 Oct 2019 02:23:06 -0700 (PDT) Subject: Win32api problems Message-ID: <8cae5b22-88de-4c2c-9027-13dfff282737@googlegroups.com> I recently installed IPython, Pandas, Altair, Jupyter, MatPlotLib, and Numpy on my Windows 10, Python27 installation to explore what it can do. When I tried to run my normal scripts a few days later, I discovered that win32com and related modules like win32ami give problems: Traceback (most recent call last): ? File "D:\gaudi\src\PythonTools\generateDocumentsPdf.py", line 10, in ? ? from win32com.client.dynamic import Dispatch ? File "C:\Python27\lib\site-packages\win32com\__init__.py", line 5, in ? ? import win32api, sys, os ImportError: DLL load failed: The specified procedure could not be found. after trying out several tips on Internet, like copying dll and pyd files, I re-installed my entire ActiveState installation. Luckily it works again. However, question is what culprit of my initial list damaged the Python-win32 configuration? Gerrit From m at funkyhat.org Tue Oct 22 05:29:27 2019 From: m at funkyhat.org (Matt Wheeler) Date: Tue, 22 Oct 2019 09:29:27 +0000 (UTC) Subject: issue with regular expressions In-Reply-To: References: Message-ID: On Tue, 22 Oct 2019, 09:44 joseph pareti, wrote: > the following code ends in an exception: > > import re > pattern = 'Sottoscrizione unica soluzione' > mylines = [] # Declare an empty list. with open ('tmp.txt', 'rt') as myfile: # Open tmp.txt for reading text. > for myline in myfile: # For each line in the file, > mylines.append(myline.rstrip('\n')) # strip newline and add to > list. > for element in mylines: # For each element in the list, > # print(element) > match = re.search(pattern, element) > s = match.start() > e = match.end() > print(element[s:e]) > > > > F:\October20-2019-RECOVERY\Unicredit_recovery\tmp_re_search>c:\Users\joepareti\Miniconda3\pkgs\python-3.7.1-h8c8aaf0_6\python.exe > search_0.py > Traceback (most recent call last): > File "search_0.py", line 10, in > s = match.start() > AttributeError: 'NoneType' object has no attribute 'start' > > any help? Thanks > Check over the docs for re.match again, you'll see it returns either a Match object (which is always truthy), or None. So a simple solution is to wrap your attempts to use the Match object in ``` if match: ... ``` > From joepareti54 at gmail.com Tue Oct 22 05:49:28 2019 From: joepareti54 at gmail.com (joseph pareti) Date: Tue, 22 Oct 2019 11:49:28 +0200 Subject: issue with regular expressions In-Reply-To: References: Message-ID: Ok, thanks. It works for me. regards, Am Di., 22. Okt. 2019 um 11:29 Uhr schrieb Matt Wheeler : > > > On Tue, 22 Oct 2019, 09:44 joseph pareti, wrote: > >> the following code ends in an exception: >> >> import re >> pattern = 'Sottoscrizione unica soluzione' >> mylines = [] # Declare an empty list. > > with open ('tmp.txt', 'rt') as myfile: # Open tmp.txt for reading >> text. >> for myline in myfile: # For each line in the file, >> mylines.append(myline.rstrip('\n')) # strip newline and add to >> list. >> for element in mylines: # For each element in the >> list, >> # print(element) >> match = re.search(pattern, element) >> s = match.start() >> e = match.end() >> print(element[s:e]) >> >> >> >> F:\October20-2019-RECOVERY\Unicredit_recovery\tmp_re_search>c:\Users\joepareti\Miniconda3\pkgs\python-3.7.1-h8c8aaf0_6\python.exe >> search_0.py >> Traceback (most recent call last): >> File "search_0.py", line 10, in >> s = match.start() >> AttributeError: 'NoneType' object has no attribute 'start' >> >> any help? Thanks >> > > Check over the docs for re.match again, you'll see it returns either a > Match object (which is always truthy), or None. > > So a simple solution is to wrap your attempts to use the Match object in > > ``` > if match: > ... > ``` > >> -- Regards, Joseph Pareti - Artificial Intelligence consultant Joseph Pareti's AI Consulting Services https://www.joepareti54-ai.com/ cell +49 1520 1600 209 cell +39 339 797 0644 From tjreedy at udel.edu Tue Oct 22 06:02:29 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 22 Oct 2019 06:02:29 -0400 Subject: problem with curring in python In-Reply-To: References: Message-ID: On 10/22/2019 4:58 AM, Antoon Pardon wrote: > Using python 3.5 > > I have been experimenting with curried functions. A bit like in Haskell. > So I can write the following function: > > def sum4(a, b, c, d): > return a + b + c + d > > summing = curry(sum4) > > print summing(1)(2)(3)(4) # this prints 10. > > The problem is I need the signature of the original function in order to > know when to finally call the function and return the actual result. > However buildin functions don't have a I believe most do. >>> help(abs) Help on built-in function abs in module builtins: abs(x, /) Return the absolute value of the argument. >>> abs.__text_signature__ '($module, x, /)' >>> import inspect >>> inspect.signature(abs) The exceptions are those with complicated signatures still given in multiple lines in the docstring since the true signature would be too complicated for humans to digest. Example: >>> help(bytes) Help on class bytes in module builtins: class bytes(object) | bytes(iterable_of_ints) -> bytes | bytes(string, encoding[, errors]) -> bytes | bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer | bytes(int) -> bytes object of size given by the parameter initialized with null bytes | bytes() -> empty bytes object The latter 5 lines are from bytes.__doc__. signature(bytes) raises ValueError. Note that parameter 1 is the union of 4 types, 3 iterable_of_ints, bytes_or_buffer, int, and string (str_or_bytes), 2 of which are unions themselves and 2 of which are non-disjoint. Furthermore, the presence of 1 or 2 more args is only valid if the 1st arg is a string. The concept of currying does not really apply to this situation very well. In other words, the cases without signatures should probably not be curried. > signature. Here below is my > current experimental implementation. Any ideas for an other approach? > > def curry(func, *args): > arg_len = len(signature(func).parameters) > if arg_len <= len(args): > return func(*args) > else: > return CurryType(func, arg_len, args) > > class CurryType: > def __init__(self, func, arg_len, args): > self.func = func > self.arg_len = arg_len > self.args = list(args) > > def __call__(self, *args): > args = self.args + list(args) > if self.arg_len <= len(args): > return self.func(*args) > else: > return CurryType(self.func, self.arg_len, args) -- Terry Jan Reedy From tjreedy at udel.edu Tue Oct 22 06:09:20 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 22 Oct 2019 06:09:20 -0400 Subject: Win32api problems In-Reply-To: <8cae5b22-88de-4c2c-9027-13dfff282737@googlegroups.com> References: <8cae5b22-88de-4c2c-9027-13dfff282737@googlegroups.com> Message-ID: On 10/22/2019 5:23 AM, GerritM wrote: > I recently installed IPython, Pandas, Altair, Jupyter, MatPlotLib, and Numpy on my Windows 10, Python27 installation to explore what it can do. All of those 5 packages either have or will stop supporting 2.x. See https://python3statement.org/. > When I tried to run my normal scripts a few days later, I discovered that win32com and related modules like win32ami give problems: > > Traceback (most recent call last): > ? File "D:\gaudi\src\PythonTools\generateDocumentsPdf.py", line 10, in > ? ? from win32com.client.dynamic import Dispatch > ? File "C:\Python27\lib\site-packages\win32com\__init__.py", line 5, in > ? ? import win32api, sys, os > ImportError: DLL load failed: The specified procedure could not be found. > > after trying out several tips on Internet, like copying dll and pyd files, I re-installed my entire ActiveState installation. Luckily it works again. > > However, question is what culprit of my initial list damaged the Python-win32 configuration? Install 1 at a time and try your normal scripts? Or try them with 3.7. -- Terry Jan Reedy From antoon.pardon at vub.be Tue Oct 22 06:15:46 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 22 Oct 2019 12:15:46 +0200 Subject: problem with curring in python In-Reply-To: References: Message-ID: <99117df5-ee13-cf7e-e752-631c7f0a8cc3@vub.be> On 22/10/19 12:02, Terry Reedy wrote: > On 10/22/2019 4:58 AM, Antoon Pardon wrote: >> Using python 3.5 >> >> I have been experimenting with curried functions. A bit like in Haskell. >> So I can write the following function: >> >> def sum4(a, b, c, d): >> ???? return a + b + c + d >> >> summing = curry(sum4) >> >> print summing(1)(2)(3)(4) # this prints 10. >> >> The problem is I need the signature of the original function in order to >> know when to finally call the function and return the actual result. >> However buildin functions don't have a > > I believe most do. Well I may have jumped to my conclusion, but those in operator don't seem to have a signature. >>> inspect.signature(operator.mul) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.5/inspect.py", line 2988, in signature return Signature.from_callable(obj, follow_wrapped=follow_wrapped) File "/usr/lib/python3.5/inspect.py", line 2738, in from_callable follow_wrapper_chains=follow_wrapped) File "/usr/lib/python3.5/inspect.py", line 2231, in _signature_from_callable skip_bound_arg=skip_bound_arg) File "/usr/lib/python3.5/inspect.py", line 2061, in _signature_from_builtin raise ValueError("no signature found for builtin {!r}".format(func)) ValueError: no signature found for builtin -- Antoon. From __peter__ at web.de Tue Oct 22 06:53:39 2019 From: __peter__ at web.de (Peter Otten) Date: Tue, 22 Oct 2019 12:53:39 +0200 Subject: problem with curring in python References: <99117df5-ee13-cf7e-e752-631c7f0a8cc3@vub.be> Message-ID: Antoon Pardon wrote: > On 22/10/19 12:02, Terry Reedy wrote: >> On 10/22/2019 4:58 AM, Antoon Pardon wrote: >>> Using python 3.5 >>> >>> I have been experimenting with curried functions. A bit like in Haskell. >>> So I can write the following function: >>> >>> def sum4(a, b, c, d): >>> return a + b + c + d >>> >>> summing = curry(sum4) >>> >>> print summing(1)(2)(3)(4) # this prints 10. >>> >>> The problem is I need the signature of the original function in order to >>> know when to finally call the function and return the actual result. >>> However buildin functions don't have a >> >> I believe most do. > > Well I may have jumped to my conclusion, but those in operator don't seem > to have a signature. > >>>> inspect.signature(operator.mul) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python3.5/inspect.py", line 2988, in signature > return Signature.from_callable(obj, follow_wrapped=follow_wrapped) > File "/usr/lib/python3.5/inspect.py", line 2738, in from_callable > follow_wrapper_chains=follow_wrapped) > File "/usr/lib/python3.5/inspect.py", line 2231, in > _signature_from_callable > skip_bound_arg=skip_bound_arg) > File "/usr/lib/python3.5/inspect.py", line 2061, in > _signature_from_builtin > raise ValueError("no signature found for builtin {!r}".format(func)) > ValueError: no signature found for builtin > New in Python 3.7: $ python3.5 -c 'from operator import mul; print(mul.__text_signature__)' None $ python3.6 -c 'from operator import mul; print(mul.__text_signature__)' None $ python3.7 -c 'from operator import mul; print(mul.__text_signature__)' ($module, a, b, /) From svbhargavareddy1 at gmail.com Tue Oct 22 01:02:19 2019 From: svbhargavareddy1 at gmail.com (svenkatabhargava reddy) Date: Tue, 22 Oct 2019 10:32:19 +0530 Subject: System error while Installing Python 3.7.4 (64 bit). Message-ID: Hi Team Python, Getting system error while trying to install python 3.7.4 version, also attaching the screen shot of error along with the message. Hoping team will come back soon with the solution. [image: image.png] Thanks and Regards, S.V.Bhargava Reddy. From joel.goldstick at gmail.com Tue Oct 22 10:44:12 2019 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 22 Oct 2019 10:44:12 -0400 Subject: System error while Installing Python 3.7.4 (64 bit). In-Reply-To: References: Message-ID: On Tue, Oct 22, 2019 at 10:33 AM svenkatabhargava reddy wrote: > > Hi Team Python, > > Getting system error while trying to install python 3.7.4 version, also > attaching the screen shot of error along with the message. Hoping team will > come back soon with the solution. > [image: image.png] > > > Thanks and Regards, > S.V.Bhargava Reddy. > -- > https://mail.python.org/mailman/listinfo/python-list Images don't make it through on this mailing list. Try to cut and paste complete error message. What OS -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From gerrit.muller at gmail.com Tue Oct 22 11:42:56 2019 From: gerrit.muller at gmail.com (GerritM) Date: Tue, 22 Oct 2019 08:42:56 -0700 (PDT) Subject: Win32api problems In-Reply-To: References: <8cae5b22-88de-4c2c-9027-13dfff282737@googlegroups.com> Message-ID: <280e1755-3fd7-42cb-bc83-2f64305b1bdc@googlegroups.com> On Tuesday, October 22, 2019 at 12:09:46 PM UTC+2, Terry Reedy wrote: > On 10/22/2019 5:23 AM, GerritM wrote: <...snip...> > > Install 1 at a time and try your normal scripts? Or try them with 3.7. > > -- > Terry Jan Reedy I am working on the Python 2 to Python 3 transition. I found on Internet many people struggling with Win32 over the years. It served me without problems for decades. So, I was wondering, whether somewhere in the growth of modules and options a weak spot is appearing... Gerrit From sjeik_appie at hotmail.com Tue Oct 22 12:31:01 2019 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Tue, 22 Oct 2019 16:31:01 +0000 Subject: Win32api problems In-Reply-To: <8cae5b22-88de-4c2c-9027-13dfff282737@googlegroups.com> Message-ID: On 22 Oct 2019 11:23, GerritM wrote: > ImportError: DLL load failed: The specified > procedure could not be found. I've had the same error before and I solved it by adding the location where the win32 dlls live to PATH. Maybe PATH gets messed up during the installation of something. From tjreedy at udel.edu Tue Oct 22 13:18:00 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 22 Oct 2019 13:18:00 -0400 Subject: problem with curring in python In-Reply-To: <99117df5-ee13-cf7e-e752-631c7f0a8cc3@vub.be> References: <99117df5-ee13-cf7e-e752-631c7f0a8cc3@vub.be> Message-ID: On 10/22/2019 6:15 AM, Antoon Pardon wrote: > On 22/10/19 12:02, Terry Reedy wrote: >> On 10/22/2019 4:58 AM, Antoon Pardon wrote: >>> Using python 3.5 >>> >>> I have been experimenting with curried functions. A bit like in Haskell. >>> So I can write the following function: >>> >>> def sum4(a, b, c, d): >>> ???? return a + b + c + d >>> >>> summing = curry(sum4) >>> >>> print summing(1)(2)(3)(4) # this prints 10. >>> >>> The problem is I need the signature of the original function in order to >>> know when to finally call the function and return the actual result. >>> However buildin functions don't have a >> >> I believe most do. > > Well I may have jumped to my conclusion, but those in operator don't seem > to have a signature. > >>>> inspect.signature(operator.mul) By default, 'python', to me, refers to the current, most recent version, now 3.8. As Peter Otten said, this now has a proper signature, added with Argument Clinic. I read 'buildin functions' as 'builtins functions', functions in the builtins module, bound to '__builtins__' in the main module. Of the 69 functions listed in https://docs.python.org/3/library/functions.html, 43 have a proper signature (non-None __text_signature__) and 26 do not. A majority if not 'most'. For the alternate reading of 'built-in functions' (in the stdlib), the ratio of conversions to a proper signature may be lower. The process is on-going. -- Terry Jan Reedy From tjreedy at udel.edu Tue Oct 22 13:19:43 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 22 Oct 2019 13:19:43 -0400 Subject: System error while Installing Python 3.7.4 (64 bit). In-Reply-To: References: Message-ID: On 10/22/2019 10:44 AM, Joel Goldstick wrote: > On Tue, Oct 22, 2019 at 10:33 AM svenkatabhargava reddy > wrote: >> >> Hi Team Python, >> >> Getting system error while trying to install python 3.7.4 version, also >> attaching the screen shot of error along with the message. Hoping team will >> come back soon with the solution. >> [image: image.png] >> >> >> Thanks and Regards, >> S.V.Bhargava Reddy. >> -- >> https://mail.python.org/mailman/listinfo/python-list > > Images don't make it through on this mailing list. Try to cut and > paste complete error message. What OS 3.7.5 was just released with bug fixes. Try that also or instead. -- Terry Jan Reedy From tjreedy at udel.edu Tue Oct 22 13:24:14 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 22 Oct 2019 13:24:14 -0400 Subject: Win32api problems In-Reply-To: <280e1755-3fd7-42cb-bc83-2f64305b1bdc@googlegroups.com> References: <8cae5b22-88de-4c2c-9027-13dfff282737@googlegroups.com> <280e1755-3fd7-42cb-bc83-2f64305b1bdc@googlegroups.com> Message-ID: On 10/22/2019 11:42 AM, GerritM wrote: > On Tuesday, October 22, 2019 at 12:09:46 PM UTC+2, Terry Reedy wrote: >> On 10/22/2019 5:23 AM, GerritM wrote: > <...snip...> >> >> Install 1 at a time and try your normal scripts? Starting from a state of ignorance about interactions between Win32 and other modules, this is what I would do. > I found on Internet many people struggling with Win32 over the years. It served me without problems for decades. So, I was wondering, whether somewhere in the growth of modules and options a weak spot is appearing... Is there a win32 list where people might have more knowledge of such? -- Terry Jan Reedy From python at mrabarnett.plus.com Tue Oct 22 13:59:11 2019 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 22 Oct 2019 18:59:11 +0100 Subject: Win32api problems In-Reply-To: References: Message-ID: <85d2da54-33b8-d2d9-4563-37cac01b242c@mrabarnett.plus.com> On 2019-10-22 17:31, Albert-Jan Roskam wrote: > > > On 22 Oct 2019 11:23, GerritM wrote: > >> ImportError: DLL load failed: The specified > procedure could not be found. > > I've had the same error before and I solved it by adding the location where the win32 dlls live to PATH. Maybe PATH gets messed up during the installation of something. > I recently had a problem when I tried win32 on a newly-installed Python 3.8 and I couldn't import win32clipboard. The solution in that case was to copy pywintypes38.dll and pythoncom38.dll from site-packages/pywin32_system32 into site-packages/win32. (Note: those names had "38" for Python 3.8.) From nulla.epistola at web.de Tue Oct 22 14:09:38 2019 From: nulla.epistola at web.de (Sibylle Koczian) Date: Tue, 22 Oct 2019 20:09:38 +0200 Subject: Win32api problems In-Reply-To: References: <8cae5b22-88de-4c2c-9027-13dfff282737@googlegroups.com> <280e1755-3fd7-42cb-bc83-2f64305b1bdc@googlegroups.com> Message-ID: <8f75b80e-0501-cf9b-7964-124fca600ce0@web.de> Am 22.10.2019 um 19:24 schrieb Terry Reedy: > ... > Is there a win32 list where people might have more knowledge of such? > There is: python-win32 at python.org https://mail.python.org/mailman/listinfo/python-win32 If you prefer Gmane: news://news.gmane.org/gmane.comp.python.windows HTH From nulla.epistola at web.de Tue Oct 22 14:09:38 2019 From: nulla.epistola at web.de (Sibylle Koczian) Date: Tue, 22 Oct 2019 20:09:38 +0200 Subject: Win32api problems In-Reply-To: References: <8cae5b22-88de-4c2c-9027-13dfff282737@googlegroups.com> <280e1755-3fd7-42cb-bc83-2f64305b1bdc@googlegroups.com> Message-ID: <8f75b80e-0501-cf9b-7964-124fca600ce0@web.de> Am 22.10.2019 um 19:24 schrieb Terry Reedy: > ... > Is there a win32 list where people might have more knowledge of such? > There is: python-win32 at python.org https://mail.python.org/mailman/listinfo/python-win32 If you prefer Gmane: news://news.gmane.org/gmane.comp.python.windows HTH From eryksun at gmail.com Tue Oct 22 14:25:45 2019 From: eryksun at gmail.com (Eryk Sun) Date: Tue, 22 Oct 2019 13:25:45 -0500 Subject: Win32api problems In-Reply-To: References: <8cae5b22-88de-4c2c-9027-13dfff282737@googlegroups.com> Message-ID: On 10/22/19, Albert-Jan Roskam wrote: > On 22 Oct 2019 11:23, GerritM wrote: > >> ImportError: DLL load failed: The specified > procedure could not be >> found. Many of the PyWin32 extensions depend on pywintypesXX.dll, and some depend on pythoncomXX.dll. There's a post-installation script that copies them either to the System32 directory or to Python's installation directory (i.e. the location of python.exe). The latter is better if you're doing this manually. There's no reason to pollute System32. If you're developing a service, pythonerservice.exe depends on pythonXX.dll, so copy pythonservice.exe to Python's installation directory as well if pythonXX.dll is located there instead of in System32. You can use relative symlinks instead of copies if Python is installed on a file system that supports reparse points, such as the system volume (NTFS). For example: >>> print(os.readlink(os.path.join(sys.prefix, 'pywintypes37.dll'))) Lib\site-packages\pywin32_system32\pywintypes37.dll Then if you upgrade PyWin32, you won't have to remember to replace the old copies. > I've had the same error before and I solved it by adding the location where > the win32 dlls live to PATH. Maybe PATH gets messed up during the > installation of something. In Python 3.8, PATH isn't used when loading extension modules. It's also not used when loading DLLs via ctypes. In many cases this change isn't an issue since dependendent DLLs are in the same directory as the extension module. If not, add the directory that has the dependencies via os.add_dll_directory(). From Richard at Damon-Family.org Tue Oct 22 16:47:32 2019 From: Richard at Damon-Family.org (Richard Damon) Date: Tue, 22 Oct 2019 16:47:32 -0400 Subject: Convert a scientific notation to decimal number, and still keeping the data format as float64 In-Reply-To: <02fc0e0e-1744-4048-822c-ca29c42f74ad@googlegroups.com> References: <5e1fbe22-ae5b-9e32-e00e-186b4d772e28@Damon-Family.org> <902e7a6d-3f79-4cd9-aebc-122a2286103b@googlegroups.com> <20cde234-7202-6e6d-a46e-5c109a352fa7@Damon-Family.org> <3dbc8816-f5f1-4691-a73c-487ed2e8c967@googlegroups.com> <6f4e13d8-df88-435d-9dbd-30bf018b11b6@googlegroups.com> <65e845d6-e039-4e10-8cb7-2784283edaa8@googlegroups.com> <02fc0e0e-1744-4048-822c-ca29c42f74ad@googlegroups.com> Message-ID: <689d8ffb-4533-5934-896c-44cf8c33ca63@Damon-Family.org> On 10/21/19 4:36 PM, doganadres at gmail.com wrote: > On Monday, October 21, 2019 at 4:09:23 PM UTC+3, Piet van Oostrum wrote: >> Piet van Oostrum writes: >> >>> doganadres at gmail.com writes: >>> >>>> I dont know much about scala actually. I have just have tried to give >>>> 0.0001 and it returned a presentation with an 'e' .whereas python takes >>>> 0.0001 and gives 0.0001 . it made me think python is better in that >>>> specific subject. >>>> >>>> However, python though starts to give 'e' number when 5 decimals are >>>> given as input. Although there can be systems around which are better in >>>> this subject other things I can achieve in python overrides some >>>> disadvantages. >>> Yes, I would say Python is more user-friendly in this particular >>> example, although both outputs are correct. If I remember correctly, >>> Python had an update in the area several years ago to make the output >>> for floating-point numbers more user-friendly, (and at the same time >>> maybe even more correct). >>> >>> But these are just choices of the implementers of the language, not >>> characteristics of the language itself. >> In Python 0.00001 => 1e-05, so it just chooses a different point to >> switch from pure decimal to scientific notation. >> -- >> Pieter van Oostrum >> WWW: http://piet.vanoostrum.org/ >> PGP key: [8DAE142BE17999C4] > > They ought to have a reason to make the program switch from pure decimal to scientific notation representation. I don't know that reason. Getting along with it. The basic reason is readability. A number like 0.0000000000000001 is obviously fairly hard to read a see exactly what the value is. A number like 0.1 isn't. So somewhere you need to change from fixed point to exponential notation. A common criteria is about when the fixed point number takes more space to represent than the exponential. 1.2E-05 takes 7 characters, 0.000015 takes 8 so the exponential is shorter. As an aside, I would be very leery of numbers like 0.00001 or 1e-05 as they only show 1 significant digit, so unless I have good reason to believe that they are exact numbers, I would have concern of them being very imprecise, and possibly just noise. -- Richard Damon From abhishekkumarthakur042 at gmail.com Tue Oct 22 17:02:06 2019 From: abhishekkumarthakur042 at gmail.com (Dragon Kumar Thakur) Date: Wed, 23 Oct 2019 02:32:06 +0530 Subject: Sir I can't able to install python In-Reply-To: References: Message-ID: Help On Wed 23 Oct, 2019, 1:41 AM Dragon Kumar Thakur, < abhishekkumarthakur042 at gmail.com> wrote: > Sir I can't able to install python it's showing error > From ikorot01 at gmail.com Tue Oct 22 07:07:49 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 22 Oct 2019 06:07:49 -0500 Subject: Sir I can't able to install python In-Reply-To: References: Message-ID: Hi, On Tue, Oct 22, 2019 at 5:30 PM Dragon Kumar Thakur wrote: > > Help What did you do and what didn't work? Thank you. > > On Wed 23 Oct, 2019, 1:41 AM Dragon Kumar Thakur, < > abhishekkumarthakur042 at gmail.com> wrote: > > > Sir I can't able to install python it's showing error > > > -- > https://mail.python.org/mailman/listinfo/python-list From joepareti54 at gmail.com Wed Oct 23 03:51:47 2019 From: joepareti54 at gmail.com (joseph pareti) Date: Wed, 23 Oct 2019 09:51:47 +0200 Subject: TypeError: unhashable type: 'list' Message-ID: I am experimnenting with this (reproducer) code: pattern_eur = ['Total amount'] mylines = [] # Declare an empty list. with open ('tmp0.txt', 'rt') as myfile: # Open tmp.txt for reading text. for myline in myfile: # For each line in the file, mylines.append(myline.rstrip('\n')) # strip newline and add to list. for element in mylines: # For each element in the list, match_C = re.search(pattern_eur, element) if match_C: element = element + 2 print(element) -------------- the input file being: $ cat tmp0.txt line 0 line 1 Total amount 50000.00 linex line z line c Total amount 43598 linekkkk line m Total amount 32000 line end -1 line end 0 line end 1 line end 2 ------ My intent is to locate the line containing "Total amount", skip the next line, then print the eur value. The program terminates as follows: Traceback (most recent call last): File "search_then_advance.py", line 8, in match_C = re.search(pattern_eur, element) File "c:\Users\joepareti\Miniconda3\pkgs\python-3.7.1-h8c8aaf0_6\lib\re.py", line 183, in search return _compile(pattern, flags).search(string) File "c:\Users\joepareti\Miniconda3\pkgs\python-3.7.1-h8c8aaf0_6\lib\re.py", line 276, in _compile return _cache[type(pattern), pattern, flags] TypeError: unhashable type: 'list' Thanks for any insigths -- -- Regards, Joseph Pareti - Artificial Intelligence consultant Joseph Pareti's AI Consulting Services https://www.joepareti54-ai.com/ cell +49 1520 1600 209 cell +39 339 797 0644 From joel.goldstick at gmail.com Wed Oct 23 04:10:32 2019 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 23 Oct 2019 04:10:32 -0400 Subject: TypeError: unhashable type: 'list' In-Reply-To: References: Message-ID: On Wed, Oct 23, 2019 at 3:54 AM joseph pareti wrote: > > I am experimnenting with this (reproducer) code: > pattern_eur = ['Total amount'] the above line can't contain a list -- just a string see help(re.search) > mylines = [] # Declare an empty list. > with open ('tmp0.txt', 'rt') as myfile: # Open tmp.txt for reading text. > for myline in myfile: # For each line in the file, > mylines.append(myline.rstrip('\n')) # strip newline and add to list. > for element in mylines: # For each element in the list, > match_C = re.search(pattern_eur, element) > if match_C: > element = element + 2 > print(element) > -------------- > the input file being: > $ cat tmp0.txt > line 0 > line 1 > Total amount > > 50000.00 > linex > line z > line c > Total amount > > 43598 > linekkkk > line m > > Total amount > > 32000 > line end -1 > line end 0 > line end 1 > line end 2 > > ------ > > My intent is to locate the line containing "Total amount", skip the next > line, then print the eur value. The program terminates as follows: > Traceback (most recent call last): > File "search_then_advance.py", line 8, in > match_C = re.search(pattern_eur, element) > File > "c:\Users\joepareti\Miniconda3\pkgs\python-3.7.1-h8c8aaf0_6\lib\re.py", > line 183, in search > return _compile(pattern, flags).search(string) > File > "c:\Users\joepareti\Miniconda3\pkgs\python-3.7.1-h8c8aaf0_6\lib\re.py", > line 276, in _compile > return _cache[type(pattern), pattern, flags] > TypeError: unhashable type: 'list' > > Thanks for any insigths -- > -- > Regards, > Joseph Pareti - Artificial Intelligence consultant > Joseph Pareti's AI Consulting Services > https://www.joepareti54-ai.com/ > cell +49 1520 1600 209 > cell +39 339 797 0644 > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From __peter__ at web.de Wed Oct 23 04:11:56 2019 From: __peter__ at web.de (Peter Otten) Date: Wed, 23 Oct 2019 10:11:56 +0200 Subject: TypeError: unhashable type: 'list' References: Message-ID: joseph pareti wrote: > I am experimnenting with this (reproducer) code: > pattern_eur = ['Total amount'] Make that pattern_eur = 'Total amount' > match_C = re.search(pattern_eur, element) The first argument to re.search() should be a string, not a list of strings: >>> import re >>> re.search("foo", "bar") >>> re.search(["foo"], "bar") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/re.py", line 170, in search return _compile(pattern, flags).search(string) File "/usr/lib/python3.4/re.py", line 282, in _compile p, loc = _cache[type(pattern), pattern, flags] TypeError: unhashable type: 'list' > element = element + 2 This will be your next problem; you are adding 2 to a string. From PythonList at DancesWithMice.info Wed Oct 23 04:23:42 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 23 Oct 2019 21:23:42 +1300 Subject: TypeError: unhashable type: 'list' In-Reply-To: References: Message-ID: <3ccd889e-468a-afd8-5b3b-8d11c56d036a@DancesWithMice.info> On 23/10/19 8:51 PM, joseph pareti wrote: > I am experimnenting with this (reproducer) code: > pattern_eur = ['Total amount'] > mylines = [] # Declare an empty list. > with open ('tmp0.txt', 'rt') as myfile: # Open tmp.txt for reading text. > for myline in myfile: # For each line in the file, > mylines.append(myline.rstrip('\n')) # strip newline and add to list. > for element in mylines: # For each element in the list, > match_C = re.search(pattern_eur, element) > if match_C: > element = element + 2 > print(element) > -------------- > the input file being: > $ cat tmp0.txt > line 0 > line 1 > Total amount > > 50000.00 > linex ... > My intent is to locate the line containing "Total amount", skip the next > line, then print the eur value. The program terminates as follows: ... > Thanks for any insigths -- The first observation is that the two for loops are essentially identical, so why not condense? However, what is described may be calling for a solution called "a finite state machine": state 1: ignore unwanted data, until "Total amount" is found state 2: skip blank line state 3: grab the Euro value, and return to state 1 Being a simple-boy, I would avoid any reg-ex, because: myline[ :11 ] == "Total amount" is easier (and faster). Similarly, there is no need for rstrip-ping except at "state 3" (unless there are particular rules for the formatting of the total). Another thought is that the problem is being visualised as a series of lines and this may complicate things. If instead, a "buffer" or indeed the entire file, could be read at a time (which is current code, per first comment above), the string.find() method could be employed (replacing "state 1"), and then (implicit assumption about spacing here) "state 2" becomes a matter of moving a few characters 'along', before grabbing the total; rinse and repeat... Web-ref: https://en.wikipedia.org/wiki/Finite-state_machine -- Regards =dn From DomainAdmin at DancesWithMice.info Wed Oct 23 04:11:45 2019 From: DomainAdmin at DancesWithMice.info (David L Neil) Date: Wed, 23 Oct 2019 21:11:45 +1300 Subject: TypeError: unhashable type: 'list' In-Reply-To: References: Message-ID: On 23/10/19 8:51 PM, joseph pareti wrote: > I am experimnenting with this (reproducer) code: > pattern_eur = ['Total amount'] > mylines = [] # Declare an empty list. > with open ('tmp0.txt', 'rt') as myfile: # Open tmp.txt for reading text. > for myline in myfile: # For each line in the file, > mylines.append(myline.rstrip('\n')) # strip newline and add to list. > for element in mylines: # For each element in the list, > match_C = re.search(pattern_eur, element) > if match_C: > element = element + 2 > print(element) > -------------- > the input file being: > $ cat tmp0.txt > line 0 > line 1 > Total amount > > 50000.00 > linex ... > My intent is to locate the line containing "Total amount", skip the next > line, then print the eur value. The program terminates as follows: ... > Thanks for any insigths -- The first observation is that the two for loops are essentially identical, so why not condense? However, what is described may be calling for a solution called "a finite state machine": state 1: ignore unwanted data, until "Total amount" is found state 2: skip blank line state 3: grab the Euro value, and return to state 1 Being a simple-boy, I would avoid any reg-ex, because: myline[ :11 ] == "Total amount" is easier (and faster). Similarly, there is no need for rstrip-ping except at "state 3" (unless there are particular rules for the formatting of the total). Another thought is that the problem is being visualised as a series of lines and this may complicate things. If instead, a "buffer" or indeed the entire file, could be read at a time (which is current code, per first comment above), the string.find() method could be employed (replacing "state 1"), and then (implicit assumption about spacing here) "state 2" becomes a matter of moving a few characters 'along', before grabbing the total; rinse and repeat... Web-ref: https://en.wikipedia.org/wiki/Finite-state_machine -- Regards =dn From edgar at openmail.cc Wed Oct 23 14:43:58 2019 From: edgar at openmail.cc (edgar at openmail.cc) Date: Wed, 23 Oct 2019 18:43:58 +0000 Subject: Unpickle patch: cannot instantiate 'WindowsPath' on your system In-Reply-To: <483f7cbb5ca7d822cdb91747c1d0e651@openmail.cc> References: <483f7cbb5ca7d822cdb91747c1d0e651@openmail.cc> Message-ID: Hello, I hope that I am writing to the right list. Python 3.7.4 on GNU/Linux Parabola 5.3.1-gnu-1 x86_64 AMD Issue: I got a .pickle which had some WindowsPath inside. I was unable to unpickle like this: ????? ? import pickle as pkl ? from pathlib import Path, PureWindowsPath, PurePath, PurePosixPath, WindowsPath, PosixPath ? fname = "ohw_analysis.pickle" ? # fpath = PureWindowsPath(fname) ? fpath = Path(fname) ? with open(fpath, "rb") as fd: ? # Works in Winbug$ only ? ohw_analysis = pkl.load(fd) ????? I tried to create my own class to override =_new= in =Path=, but that did not work, because (I assume that) the pickle data was pointing to =pathlib=. I did not know how to solve this, so I modified the code for pathlib.py Solution: The modification allowed me to unpickle the file, and I think that it would not break =pathlib=. I have seen this issue reported elsewhere, and I thought that it could be useful to others. Extra: I really hope that this is useful. Although I am not asking for help, if there was a better solution, let me know. I don't want a Github account (Micro$oft). Thanks! From PythonList at DancesWithMice.info Wed Oct 23 16:04:09 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 24 Oct 2019 09:04:09 +1300 Subject: Black In-Reply-To: References: Message-ID: On 22/10/19 3:18 AM, lizhollinshead5 at gmail.com wrote: > What do people think about black? > > I'm asking because one of my personal preferences is to use spaces for clarity: > > 1. right = mystr[ start : ] > > black version right=mystr[start:] > > 2. mtime = time.asctime( time.localtime( info.st_mtime ) ) > > black version mtime = time.asctime(time.localtime(info.st_mtime)) > > Is there a reason why PEP8 doesn't like these spaces? FYI: Python Bytes pod-cast "Episode #153: Auto format my Python please!" https://pythonbytes.fm/episodes/show/153/auto-format-my-python-please (topic nr6) NB I have not listened to it. [via PlanetPython] Apparently informed by blog article: "written on 06/02/2018 Auto formatters for Python ????" https://www.kevinpeters.net/auto-formatters-for-python -- Regards =dn From PythonList at DancesWithMice.info Wed Oct 23 16:14:11 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 24 Oct 2019 09:14:11 +1300 Subject: Fursday Flippancy: American Py Message-ID: <8d1f0b08-1220-a9da-9925-d38a9b51f2c1@etelligence.info> [via PlanetPython] The "American Py" song. Lyrics which amused me, at https://www.reddit.com/r/Python/comments/dfm2zv/american_py/ 'Multi-taskers' may like to read and listen-along to: https://www.youtube.com/watch?v=uAsV5-Hv-7U For the benefit of us silver-surfers reliving our youth (or for those condemned to repeat history): https://en.wikipedia.org/wiki/American_Pie_%28song%29 -- Regards, =dn From faajabbari at gmail.com Wed Oct 23 19:47:04 2019 From: faajabbari at gmail.com (fateme jbr) Date: Wed, 23 Oct 2019 16:47:04 -0700 Subject: installation problem Message-ID: Dear Python team I have installed Python 3.7.4 on windows 10. I have access to IDLE and I can run simple programs, but when I type python in command window nothing happens. I wanna install pip and afterward some libraries and it is when the problem occurs. why doesn't prompt window recognize python. What shall I do? Best regards From python at mrabarnett.plus.com Wed Oct 23 21:43:21 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 24 Oct 2019 02:43:21 +0100 Subject: installation problem In-Reply-To: References: Message-ID: <4bef001b-3110-b7e6-16b7-336aa8e64358@mrabarnett.plus.com> On 2019-10-24 00:47, fateme jbr wrote: > Dear Python team > > I have installed Python 3.7.4 on windows 10. I have access to IDLE and I > can run simple programs, but when I type python in command window nothing > happens. I wanna install pip and afterward some libraries and it is when > the problem occurs. > > why doesn't prompt window recognize python. What shall I do? > what do you mean by "nothing happens"? It should either start Python or show an error. Python 3.7 comes with pip; it should be installed already. The recommended way of starting Python on Windows these days is to use the Python launcher "py". You can use it run to pip: py -m pip install library_name From p.f.moore at gmail.com Thu Oct 24 03:48:57 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 24 Oct 2019 08:48:57 +0100 Subject: installation problem In-Reply-To: References: Message-ID: On Thu, 24 Oct 2019 at 00:50, fateme jbr wrote: > > Dear Python team > > I have installed Python 3.7.4 on windows 10. I have access to IDLE and I > can run simple programs, but when I type python in command window nothing > happens. I wanna install pip and afterward some libraries and it is when > the problem occurs. > > why doesn't prompt window recognize python. What shall I do? You probably didn't choose "add Python to your PATH" when installing (it's an option, that's off by default). You can manually add Python to your PATH (if you don't know how to do this, there are plenty of resources that can help - it's a fairly basic thing you need to be aware of if you're using the command line), or you can reinstall, or "repair" your installation and select the option. Or you can use the Python launcher, py.exe, which is on PATH and which will launch Python for you: * Run python: py * Run pip: py -m pip Paul From rothmq at gmail.com Thu Oct 24 04:06:21 2019 From: rothmq at gmail.com (Maggie Q Roth) Date: Thu, 24 Oct 2019 16:06:21 +0800 Subject: graphics with python Message-ID: Hello Can you show me the correct way to programming with graphics? I want to take some action detection, for instance, recognize dancing etc. Thanks, Maggie From yu.cai.2005 at gmail.com Thu Oct 24 04:18:36 2019 From: yu.cai.2005 at gmail.com (Yu Cai) Date: Thu, 24 Oct 2019 19:18:36 +1100 Subject: Pytthon 3.8.0 Installation failed Message-ID: Hi, I got an issues while installing python 3.8.0. If I choose to install Python 3.8.0 using default configuration, then everything is going well. However, if I choose to install it using customized settings, e.g., installation folder being ?c:\python38?, and ?Download debugging symbols? and ?Download debug binaries?, then it failed. I have attached the log file for your reference. Could you please help me out of this issue? Thank you very much. Kind Regards, Richard From pkpearson at nowhere.invalid Thu Oct 24 11:07:51 2019 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 24 Oct 2019 15:07:51 GMT Subject: graphics with python References: Message-ID: On Thu, 24 Oct 2019 16:06:21 +0800, Maggie Q Roth wrote: [snip] > Can you show me the correct way to programming with graphics? > > I want to take some action detection, for instance, recognize dancing etc. That description of your goals is very vague. The more specific you can be about what you want to do, the more likely you are to get a helpful response. "Programming with graphics" sounds like drawing charts, or graphs, or pictures, or games. "Recognize dancing etc." sounds like image processing, maybe involving huge neural networks. The most useful thing you could provide would be a statement of the form, "I want to produce software that will take X as input and produce output Y." -- To email me, substitute nowhere->runbox, invalid->com. From frank at chagford.com Thu Oct 24 11:29:14 2019 From: frank at chagford.com (Frank Millman) Date: Thu, 24 Oct 2019 17:29:14 +0200 Subject: Instantiating sub-class from super In-Reply-To: References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <35ce3570-9473-c128-9a21-27d1873320d3@chagford.com> Message-ID: <248c1b78-562e-f549-66d2-73b3682e0eb0@chagford.com> On 2019-10-19 12:37 AM, DL Neil via Python-list wrote: > On 16/10/19 6:33 PM, Frank Millman wrote: >> On 2019-10-14 10:55 PM, DL Neil via Python-list wrote: >>> Is there a technique or pattern for taking a (partially-) populated >>> instance of a class, and re-creating it as an instance of one of its >>> sub-classes? > >> Here is a link to an article entitled 'Understanding Hidden Subtypes'. >> It dates back to 2004, but I think it is still relevant. It addresses >> precisely the issues that you raise, but from a data-modelling >> perspective, not a programming one. >> >> http://tdan.com/understanding-hidden-subtypes/5193 >> >> I found it invaluable, and applied the concepts in my own >> business/accounting application. Having created the ability to make >> subtypes visible and explicit, I found all kinds of unexpected uses >> for them. >> >> The article seems to be missing a couple of images (Figure 1 and >> Figure 2) showing the data relationships. I downloaded the original >> article onto my computer years ago, and my local copy does have the >> images, so if you would like to see them let me know and I will upload >> my version somewhere to make it accessible. > > Superb! > > Yes please Frank - I've also approached it from the data/DB side, and > thus presumably why I was puzzling over how one implements in Python. > > (alternatively, email a PDF/similar directly) Hi I have just got back from a few days break and have only seen your message now. Did you see the message I posted on the 17th with a download link? If not, would you like me to post it again? Frank From frank at chagford.com Thu Oct 24 11:29:14 2019 From: frank at chagford.com (Frank Millman) Date: Thu, 24 Oct 2019 17:29:14 +0200 Subject: Instantiating sub-class from super In-Reply-To: References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <35ce3570-9473-c128-9a21-27d1873320d3@chagford.com> Message-ID: <248c1b78-562e-f549-66d2-73b3682e0eb0@chagford.com> On 2019-10-19 12:37 AM, DL Neil via Python-list wrote: > On 16/10/19 6:33 PM, Frank Millman wrote: >> On 2019-10-14 10:55 PM, DL Neil via Python-list wrote: >>> Is there a technique or pattern for taking a (partially-) populated >>> instance of a class, and re-creating it as an instance of one of its >>> sub-classes? > >> Here is a link to an article entitled 'Understanding Hidden Subtypes'. >> It dates back to 2004, but I think it is still relevant. It addresses >> precisely the issues that you raise, but from a data-modelling >> perspective, not a programming one. >> >> http://tdan.com/understanding-hidden-subtypes/5193 >> >> I found it invaluable, and applied the concepts in my own >> business/accounting application. Having created the ability to make >> subtypes visible and explicit, I found all kinds of unexpected uses >> for them. >> >> The article seems to be missing a couple of images (Figure 1 and >> Figure 2) showing the data relationships. I downloaded the original >> article onto my computer years ago, and my local copy does have the >> images, so if you would like to see them let me know and I will upload >> my version somewhere to make it accessible. > > Superb! > > Yes please Frank - I've also approached it from the data/DB side, and > thus presumably why I was puzzling over how one implements in Python. > > (alternatively, email a PDF/similar directly) Hi I have just got back from a few days break and have only seen your message now. Did you see the message I posted on the 17th with a download link? If not, would you like me to post it again? Frank From PythonList at DancesWithMice.info Thu Oct 24 16:18:20 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Fri, 25 Oct 2019 09:18:20 +1300 Subject: Congratulations to @Chris Message-ID: <120f075d-9854-94e8-3fa2-3afa7d8a9b33@etelligence.info> Chris Angelico: [PSF's] 2019 Q2 Community Service Award Winner http://pyfound.blogspot.com/2019/10/chris-angelico-2019-q2-community.html ...and for the many assistances and pearls of wisdom he has contributed 'here'! -- Regards, =dn From rosuav at gmail.com Thu Oct 24 16:29:27 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Oct 2019 07:29:27 +1100 Subject: Congratulations to @Chris In-Reply-To: <120f075d-9854-94e8-3fa2-3afa7d8a9b33@etelligence.info> References: <120f075d-9854-94e8-3fa2-3afa7d8a9b33@etelligence.info> Message-ID: On Fri, Oct 25, 2019 at 7:20 AM DL Neil via Python-list wrote: > > Chris Angelico: [PSF's] 2019 Q2 Community Service Award Winner > http://pyfound.blogspot.com/2019/10/chris-angelico-2019-q2-community.html > > ...and for the many assistances and pearls of wisdom he has contributed > 'here'! Thanks! It's been great hanging out on these channels/lists/whatever you call 'here'. I originally joined python-list in relation to a project that moved away from Python, then got badly bogged down in everyone's favourite problem, scope creep. And then it died. But in the meantime, I was very much appreciating the community here, and both learning and contributing. It's been an awesome ride, and I've learned so much from so many people here. So, a big thank you to all the regulars here - you know who you are - and also to the occasional contributors too. (I feel like I'm thanking everyone at the end of a live stream or something, but it's true - lurkers are important too.) ChrisA From me at jgardner.tech Thu Oct 24 16:32:28 2019 From: me at jgardner.tech (Joshua Gardner) Date: Thu, 24 Oct 2019 14:32:28 -0600 Subject: How to debug asyncio.exceptions.CancelledError? Message-ID: <875zkd28bn.fsf@jgardner.tech> I'm using a library for Django Channels that I've somehow misconfigured and is causing asyncio.exceptions.CancelledError when trying to connect a websocket. Because of how the stack isn't particularly straightforward with asyncio I'm at a loss to debug this. Any tips to find out what's going on? Reference to other questions in other fora that are related: GitHub issue: https://github.com/datadvance/DjangoChannelsGraphqlWs/issues/28 Django-Users: https://groups.google.com/forum/#!topic/django-users/lSBYzKZ3sFE From marek.mosiewicz at jotel.com.pl Thu Oct 24 16:26:11 2019 From: marek.mosiewicz at jotel.com.pl (Marek Mosiewicz) Date: Thu, 24 Oct 2019 22:26:11 +0200 Subject: Blasphemy Message-ID: <3839a02c099230cd910bc41fb715c83e4f18a4e2.camel@jotel.com.pl> What about, if Python would have optional end keyword. In fact most of blocks have starting : sign. What if you would have also keyword to optionaly mark end of block. That would be big win for IDEs to format code and ensure that there is no problems with intendation. There could be some keyword to mark script as strictly marking blocks and then it would have this kind of validation. Cheers, Marek Mosiewicz From formisc at gmail.com Thu Oct 24 18:58:15 2019 From: formisc at gmail.com (Andrew Z) Date: Thu, 24 Oct 2019 18:58:15 -0400 Subject: Blasphemy In-Reply-To: <3839a02c099230cd910bc41fb715c83e4f18a4e2.camel@jotel.com.pl> References: <3839a02c099230cd910bc41fb715c83e4f18a4e2.camel@jotel.com.pl> Message-ID: Space. On Thu, Oct 24, 2019, 18:53 Marek Mosiewicz wrote: > What about, if Python would have optional end keyword. In fact most of > blocks have starting : sign. What if you would have also keyword to > optionaly mark end of block. > > That would be big win for IDEs to format code and ensure that there is > no problems with intendation. There could be some keyword to mark > script as strictly marking blocks and then it would have this kind of > validation. > > Cheers, > Marek Mosiewicz > > > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Thu Oct 24 18:58:59 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Oct 2019 09:58:59 +1100 Subject: Blasphemy In-Reply-To: <3839a02c099230cd910bc41fb715c83e4f18a4e2.camel@jotel.com.pl> References: <3839a02c099230cd910bc41fb715c83e4f18a4e2.camel@jotel.com.pl> Message-ID: On Fri, Oct 25, 2019 at 9:54 AM Marek Mosiewicz wrote: > > What about, if Python would have optional end keyword. In fact most of > blocks have starting : sign. What if you would have also keyword to > optionaly mark end of block. > > That would be big win for IDEs to format code and ensure that there is > no problems with intendation. There could be some keyword to mark > script as strictly marking blocks and then it would have this kind of > validation. Python already actually HAS support for an optional end keyword. It does make your code uglier when you use it, though. for factor in (2, 3, 4, 8): audio.frame_data = (data * factor).tobytes() try: sphinxamp = r.recognize_sphinx(audio) # end except (sr.UnknownValueError, sr.RequestError): continue # end if sphinxamp != sphinx: print("Sphinx*%d:" % factor, sphinxamp, file=log, flush=True) # end # end Fully supported by all current versions of Python. ChrisA From stevan.white at gmail.com Fri Oct 25 01:35:01 2019 From: stevan.white at gmail.com (Steve White) Date: Fri, 25 Oct 2019 07:35:01 +0200 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: Regarding my question "Is there some fatal reason that this approach must never be used, besides the lack of documentary support for it?" If finally dawned on me that there is a use-case for containers that would preclude using object identity for keys. That is, if the object is to be serialized, or otherwise stored past the run-time of the program. Of course, all the identities (all the id() values) will be meaningless once the current run ends. That is not my use-case, however. My containers are already stored by completely different means. As to my other questions, I am now fairly convinced that, at least in CPython and PyPy, on both 32 bit and 64 bit machines, it is safe to assume that __eq__() is never called if __hash__() returns id(), and that this results in a perfect hash. It works splendidly. That leads me to the problem of the documentation. I hope to pursue a change in the documentation, at least to provide a little more explanation of the reason for the requirements of __hash__() and __eq__(). I would like to first discuss it with somebody who understands the history and internals of Python, to make sure I have all my facts straight. Cheers! On Sat, Oct 19, 2019 at 1:31 PM Steve White wrote: > > Hi, > > I have an application that would benefit from object instances > distinguished by identity being used in dict's and set's. To do this, > the __hash__ method must be overridden, the obvious return value being > the instance's id. > > This works flawlessly in extensive tests on several platforms, and on > a couple of different Python versions and implementations. > > The documentation seems to preclude a second requirement, however. > > I also want to use the == operator on these objects to mean a natural > comparison of values, different from identity, so that two instances > comparing equivalent does not imply that they are identical. > > But the documentation for __hash__ has: > "The only required property is that objects which compare equal > have the same hash value" > > Yet it seems something more is going on, because as near as I can > tell, it just works, perfectly, every time, despite this requirement. > If the the __hash__ method returns the object's id, the __eq__ method > of the *never* called when the object is added to a dict. (See > examples below.) > > It would appear that if __hash__ returns the id, then that id is used > internally as the key, and since the id is by definition unique, no > key collision ever occurs -- at least in every Python implementation > I've tried. It also seems that, for a class instance obj, > hash( hash( obj ) ) == hash( obj ) > hash( id( obj ) ) == id( obj ) > These are very strong and useful properties. Where are they documented? > > It looks like the existing Python built-in containers do exactly what > I need, but the documentation suggests that they may not. > > Taking the documentation at face value, I'm in the position of > choosing between abandoning the natural use of operator '==', or of > introducing an unfamiliar container implementation. As my package is > intended for the use by other people, neither option is attractive. > > Questions: > > Is all this apparent behaviour documented somewhere that I have missed? > > Is there some fatal reason that this approach must never be used, > besides the lack of documentary support for it? > > Is it in fact safe to assume that __eq__ is never called under these > circumstances? > > =============================================================== > from __future__ import print_function > from sys import stdout > > class A( object ): # minimal hashable object > def __init__( self, v1, v2 ): > self.v = ( v1, v2 ) > > def __eq__( self, b ): > #return self.v[0] == b.v[0] and self.v[1] == b.v[1] > raise Exception( "CALLED __eq__" ) > > def __hash__( self ): # instances distinguished by identity > return id( self ) > > # It was suggested that set and dict internally use some representation > # of keys that contains less information than the id() value returned by > # __hash__, thus causing key collisions, which are resolved by calls to > # __eq__. > # In that case, one would expect __eq__ to be called eventually if enough > # objects were added to a set. I don't see that, though. > > NINSTANCES = 3000000 # play with this number -- carefully! > STATUS_INTERVAL = 100000 > > def test(): > """ hammer the set algorithms """ > s = set() > instances = [] > for i in range( 0, NINSTANCES ): > p = A( 1, 0 ) > s.add( p ) > instances.append( p ) > if not i % STATUS_INTERVAL: > stdout.write( str( i // STATUS_INTERVAL ) + " " ) > stdout.flush() > stdout.write( "\n" ) > > print( "length of set", len( s ) ) > print( "number of instances", len( instances ) ) > > for i in instances: > if not i in s: > print( "INSTANCE DROPPED OUT!" ) > test() From PythonList at DancesWithMice.info Fri Oct 25 01:38:08 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Fri, 25 Oct 2019 18:38:08 +1300 Subject: Instantiating sub-class from super In-Reply-To: <248c1b78-562e-f549-66d2-73b3682e0eb0@chagford.com> References: <3b5443cd-8dec-9159-45f8-621dedb41c72@etelligence.info> <35ce3570-9473-c128-9a21-27d1873320d3@chagford.com> <248c1b78-562e-f549-66d2-73b3682e0eb0@chagford.com> Message-ID: <713bb095-057f-649b-8756-d93ee32bcdab@DancesWithMice.info> On 25/10/19 4:29 AM, Frank Millman wrote: > On 2019-10-19 12:37 AM, DL Neil via Python-list wrote: >> On 16/10/19 6:33 PM, Frank Millman wrote: >>> On 2019-10-14 10:55 PM, DL Neil via Python-list wrote: >>>> Is there a technique or pattern for taking a (partially-) populated >>>> instance of a class, and re-creating it as an instance of one of its >>>> sub-classes? >> >>> Here is a link to an article entitled 'Understanding Hidden >>> Subtypes'. It dates back to 2004, but I think it is still relevant. >>> It addresses precisely the issues that you raise, but from a >>> data-modelling perspective, not a programming one. >>> >>> http://tdan.com/understanding-hidden-subtypes/5193 >>> >>> I found it invaluable, and applied the concepts in my own >>> business/accounting application. Having created the ability to make >>> subtypes visible and explicit, I found all kinds of unexpected uses >>> for them. >>> >>> The article seems to be missing a couple of images (Figure 1 and >>> Figure 2) showing the data relationships. I downloaded the original >>> article onto my computer years ago, and my local copy does have the >>> images, so if you would like to see them let me know and I will >>> upload my version somewhere to make it accessible. >> >> Superb! >> >> Yes please Frank - I've also approached it from the data/DB side, and >> thus presumably why I was puzzling over how one implements in Python. >> >> (alternatively, email a PDF/similar directly) > > Hi > > I have just got back from a few days break and have only seen your > message now. > > Did you see the message I posted on the 17th with a download link? If > not, would you like me to post it again? I did spot the later post - but only after I'd written the above. I've been amused by the similarities between their case and ours, and enjoyed learning a lesson (or two?). Thanks and apologies. -- Regards =dn From tjreedy at udel.edu Fri Oct 25 02:36:53 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 25 Oct 2019 02:36:53 -0400 Subject: installation problem In-Reply-To: <4bef001b-3110-b7e6-16b7-336aa8e64358@mrabarnett.plus.com> References: <4bef001b-3110-b7e6-16b7-336aa8e64358@mrabarnett.plus.com> Message-ID: On 10/23/2019 9:43 PM, MRAB wrote: > On 2019-10-24 00:47, fateme jbr wrote: >> Dear Python team >> >> I have installed Python 3.7.4 on windows 10. I have access to IDLE and I >> can run simple programs, but when I type python in command window nothing >> happens. What 'command window' do you mean? Windows' Command Prompt? or IDLE's Shell? If the latter, you will get a NameError. I wanna install pip and afterward some libraries and it is when >> the problem occurs. >> >> why doesn't prompt window recognize python. What shall I do? >> > what do you mean by "nothing happens"? It should either start Python or > show an error. > > Python 3.7 comes with pip; it should be installed already. > > The recommended way of starting Python on Windows these days is to use > the Python launcher "py". You can use it run to pip: > > py -m pip install library_name Do this in Command Prompt, with a 'path>' prompt. -- Terry Jan Reedy From rothmq at gmail.com Fri Oct 25 06:22:44 2019 From: rothmq at gmail.com (Maggie Q Roth) Date: Fri, 25 Oct 2019 18:22:44 +0800 Subject: a regex question Message-ID: Hello There are two primary types of lines in the log: 60.191.38.xx / 42.120.161.xx /archives/1005 I know how to write regex to match each line, but don't get the good result with one regex to match both lines. Can you help? Thanks, Maggie From brian.j.oney at googlemail.com Fri Oct 25 07:12:56 2019 From: brian.j.oney at googlemail.com (Brian Oney) Date: Fri, 25 Oct 2019 13:12:56 +0200 Subject: a regex question In-Reply-To: References: Message-ID: On October 25, 2019 12:22:44 PM GMT+02:00, Maggie Q Roth wrote: >Hello > >There are two primary types of lines in the log: > >60.191.38.xx / >42.120.161.xx /archives/1005 > >I know how to write regex to match each line, but don't get the good >result >with one regex to match both lines. What is a good result? The is an re.MULTILINE flag. Did you try that? What does that do? From antoon.pardon at vub.be Fri Oct 25 07:31:04 2019 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 25 Oct 2019 13:31:04 +0200 Subject: a regex question In-Reply-To: References: Message-ID: <26fc40f1-51d4-f75b-be3b-6227a0a3de13@vub.be> On 25/10/19 12:22, Maggie Q Roth wrote: > Hello > > There are two primary types of lines in the log: > > 60.191.38.xx / > 42.120.161.xx /archives/1005 > > I know how to write regex to match each line, but don't get the good result > with one regex to match both lines. Could you provide the regexes that you have for each line? -- Antoon. From amadiebuka042 at gmail.com Fri Oct 25 02:35:06 2019 From: amadiebuka042 at gmail.com (Ebuka Amadi) Date: Thu, 24 Oct 2019 23:35:06 -0700 Subject: Fwd: python 8.0 In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Ebuka Amadi Date: Thu, 24 Oct 2019 at 22:31 Subject: python 8.0 To: Dear team i downloaded python 8.0 am finding it hard to install it i hope to get a step by stem instructions to do this on my PC its a core i5 From vr at labstack.com Thu Oct 24 23:05:23 2019 From: vr at labstack.com (Vishal Rana) Date: Thu, 24 Oct 2019 20:05:23 -0700 Subject: Multi-language programing playground Message-ID: Folks, I wanted to share a multi-language programming playground that I created recently. I hope you will find it useful. https://code.labstack.com/program Thanks From ikorot01 at gmail.com Fri Oct 25 10:25:07 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Fri, 25 Oct 2019 09:25:07 -0500 Subject: python 8.0 In-Reply-To: References: Message-ID: Hi, On Fri, Oct 25, 2019 at 9:19 AM Ebuka Amadi wrote: > > ---------- Forwarded message --------- > From: Ebuka Amadi > Date: Thu, 24 Oct 2019 at 22:31 > Subject: python 8.0 > To: > > > Dear team i downloaded python 8.0 am finding it hard to install it i hope > to get a step by stem instructions to do this on my PC its a core i5 Where did you download it from? How are you trying it to install? What error message do you get? What OS do you run on you PC? Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list From gheskett at shentel.net Fri Oct 25 11:16:35 2019 From: gheskett at shentel.net (Gene Heskett) Date: Fri, 25 Oct 2019 11:16:35 -0400 Subject: Fwd: python 8.0 In-Reply-To: References: Message-ID: <201910251116.35488.gheskett@shentel.net> On Friday 25 October 2019 02:35:06 Ebuka Amadi wrote: > ---------- Forwarded message --------- > From: Ebuka Amadi > Date: Thu, 24 Oct 2019 at 22:31 > Subject: python 8.0 > To: > > > Dear team i downloaded python 8.0 am finding it hard to install it i > hope to get a step by stem instructions to do this on my PC its a core > i5 I am just a lurker here, but python is only up to version 3.8. If that is python 8, I would wipe it off the system and go get the real thing from a genuine python site. If you paid for it (its free), take whatever actions you have to, to get your money back. 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) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From isidentical at gmail.com Fri Oct 25 12:59:15 2019 From: isidentical at gmail.com (Batuhan Taskaya) Date: Fri, 25 Oct 2019 19:59:15 +0300 Subject: Fwd: python 8.0 In-Reply-To: <201910251116.35488.gheskett@shentel.net> References: <201910251116.35488.gheskett@shentel.net> Message-ID: > but python is only up to version 3.8 He probably meant 3.8.0 but there was a python 8 (as an april 1 joke by victor stinner) https://mail.python.org/archives/list/python-dev at python.org/thread/4P46WYJTZUKJ2EABQSASI7CD643YY5QL/ On Fri, Oct 25, 2019, 6:32 PM Gene Heskett wrote: > On Friday 25 October 2019 02:35:06 Ebuka Amadi wrote: > > > ---------- Forwarded message --------- > > From: Ebuka Amadi > > Date: Thu, 24 Oct 2019 at 22:31 > > Subject: python 8.0 > > To: > > > > > > Dear team i downloaded python 8.0 am finding it hard to install it i > > hope to get a step by stem instructions to do this on my PC its a core > > i5 > > I am just a lurker here, but python is only up to version 3.8. If that is > python 8, I would wipe it off the system and go get the real thing from > a genuine python site. If you paid for it (its free), take whatever > actions you have to, to get your money back. > > 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) > If we desire respect for the law, we must first make the law respectable. > - Louis D. Brandeis > Genes Web page > -- > https://mail.python.org/mailman/listinfo/python-list > From arne at vajhoej.dk Fri Oct 25 22:10:23 2019 From: arne at vajhoej.dk (=?UTF-8?Q?Arne_Vajh=c3=b8j?=) Date: Fri, 25 Oct 2019 22:10:23 -0400 Subject: How to decode UTF strings? References: <5gJsF.89999$rR2.25558@fx23.iad> Message-ID: On 10/25/2019 4:52 PM, DFS wrote: > =?iso-8859-9?b?T/B1eg==?= > =?utf-8?Q?=EB=AF=B8?= > =?GBK?B?0Pu66A==?= > =?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?= How does something like: from email.header import decode_header def test(s): print(s) s2 = decode_header(s) print(s2[0][0]) print(s2[1][0].strip()) test('=?iso-8859-9?b?T/B1eg==?= ') test('=?utf-8?Q?=EB=AF=B8?= ') test('=?GBK?B?0Pu66A==?= ') test('=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?= ') work? Arne From python at mrabarnett.plus.com Fri Oct 25 22:57:17 2019 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 26 Oct 2019 03:57:17 +0100 Subject: How to decode UTF strings? In-Reply-To: References: <5gJsF.89999$rR2.25558@fx23.iad> Message-ID: On 2019-10-26 03:10, Arne Vajh?j wrote: > On 10/25/2019 4:52 PM, DFS wrote: >> =?iso-8859-9?b?T/B1eg==?= >> =?utf-8?Q?=EB=AF=B8?= >> =?GBK?B?0Pu66A==?= >> =?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?= > > How does something like: > > from email.header import decode_header > > def test(s): > print(s) > s2 = decode_header(s) > print(s2[0][0]) > print(s2[1][0].strip()) > > test('=?iso-8859-9?b?T/B1eg==?= ') > test('=?utf-8?Q?=EB=AF=B8?= ') > test('=?GBK?B?0Pu66A==?= ') > test('=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?= > ') > > work? > When you decode the header you get a number of parts, each with its own encoding. Here's a simple example, based in your code: from email.header import decode_header def test(header, default_encoding='utf-8'): parts = [] for data, encoding in decode_header(header): if isinstance(data, str): parts.append(data) else: parts.append(data.decode(encoding or default_encoding)) print(''.join(parts)) test('=?iso-8859-9?b?T/B1eg==?= ') test('=?utf-8?Q?=EB=AF=B8?= ') test('=?GBK?B?0Pu66A==?= ') test('=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?= ') From dieter at handshake.de Sat Oct 26 01:14:36 2019 From: dieter at handshake.de (dieter) Date: Sat, 26 Oct 2019 07:14:36 +0200 Subject: keying by identity in dict and set References: Message-ID: <87mudo6qbn.fsf@handshake.de> Steve White writes: > Regarding my question > "Is there some fatal reason that this approach must never be > used, besides the lack of documentary support for it?" > If finally dawned on me that there is a use-case for containers that > would preclude using object identity for keys. That is, if the object > is to be serialized, or otherwise stored past the run-time of the > program. Of course, all the identities (all the id() values) will be > meaningless once the current run ends. One motivation to base dict key management on equality (rather than identity) are literals: Consider a dict "d" with at some place `d["my example key"] = 1` and at a different place (maybe another function, another module) you access `d["my example key"]`. You would expect to get `1` as result as for your eyes the two literals are equal. Would the key management be based on identity, then you could get either the expected `1` or a `KeyError`. The reason: Python does not manage (most) literals globally; this means, if you use the same literal in different places you may (or may not) have non-identical objects. Basing on equality, you are also more flexibal than with identity, because can can change the equality rules for a class while you cannot change the identity rules. Thus, if you need identity based key management, define your `__eq__` accordingly. From dieter at handshake.de Sat Oct 26 01:27:15 2019 From: dieter at handshake.de (dieter) Date: Sat, 26 Oct 2019 07:27:15 +0200 Subject: a regex question References: Message-ID: <87imoc6pqk.fsf@handshake.de> Maggie Q Roth writes: > There are two primary types of lines in the log: > > 60.191.38.xx / > 42.120.161.xx /archives/1005 > > I know how to write regex to match each line, but don't get the good result > with one regex to match both lines. > > Can you help? When I look at these lines, I see 2 fields separated by whitespace (note that two example lines are very very few to guess the proper pattern). I would not use a regular expression in this case, but the `split` string method. A regular expression for this pattern could be `(\S+)\s+(.*)` which reads a non-empty sequences of none whitespace (assigned to group 1), whitespace, any sequence (assigned to group 2) (note that the regular expression above is given on the regex level. The string in your Python code may look slightly different). From stevan.white at gmail.com Sat Oct 26 04:17:05 2019 From: stevan.white at gmail.com (Steve White) Date: Sat, 26 Oct 2019 10:17:05 +0200 Subject: Fwd: keying by identity in dict and set In-Reply-To: References: <87mudo6qbn.fsf@handshake.de> Message-ID: Hi Dieter, I'm sure that 99% of all use of 'dict' in Python is exactly this. The vast majority of my own Python code is such, and that is as it should be. Here I have an application where I can do something really cool and useful, by keying on identity. The built-in Python structures are pretty limited, but I'm making a package for use by other people, and I strongly prefer them to use familitar Python structures with it, rather than having to learn something new, and I strongly prefer to use off-the-shelf, tested structures, rather than rolling my own. I spent some days trying to make it work in more conventional ways --- nothing worked as well, as cleanly. I am not advocating this style of programming. I want the flexibility to use it, when it is called for. Yes, it has its limitations, but limitations are to be understood and worked with. And it is now obvious to me that somebody went to great pains to make sure the Python 'dict' does in fact support this. It works splendidly. This is no accident. It's instructive to compare Python's containers to the container libraries of other languages, Java for instance. In Java, there are many kinds of container classes, which permits finding one that is optimal for a given application. In contrast, Python has only a handfull. But they are meant to be very flexible, and fairly well optimized for most applcations. Yet the documentation *not only* suggests that 'dict' and 'set' cannot be used for keying by identity, it gives no insight whatever into how their internal hash algorithms use __hash__() and __eq__(). This results in hundreds of postings by people who want to just do the right thing, or who want to do something a little different, often being answered by people who themselves scarcely understand what is really going on. While researching this question, I found several places where somebody asked about doing something like what I described here, but they never got a useful answer. I also found post that advocate returning the value of id() in __hash__(), without explaining how __eq__() should then be overloaded. A little documentation would have saved me personally days of work. It would be helpful to know: * under what conditions can one expect a "perfect hash", that is, one where __eq__() will never be called? * is it sufficient to return the value of the key object's id() function to produce a perfect hash? * when might it be useful to consider keying by identity? * what are the limitations of programming this way? Thanks! On Sat, Oct 26, 2019 at 7:17 AM dieter wrote: > > Steve White writes: > > Regarding my question > > "Is there some fatal reason that this approach must never be > > used, besides the lack of documentary support for it?" > > If finally dawned on me that there is a use-case for containers that > > would preclude using object identity for keys. That is, if the object > > is to be serialized, or otherwise stored past the run-time of the > > program. Of course, all the identities (all the id() values) will be > > meaningless once the current run ends. > > One motivation to base dict key management on equality > (rather than identity) are literals: > > Consider a dict "d" with at some place > `d["my example key"] = 1` and at a different place > (maybe another function, another module) you access > `d["my example key"]`. You would expect to get `1` > as result as for your eyes the two literals are equal. > Would the key management be based on identity, then > you could get either the expected `1` or a `KeyError`. > The reason: Python does not manage (most) literals globally; > this means, if you use the same literal in different places > you may (or may not) have non-identical objects. > > Basing on equality, you are also more flexibal than > with identity, because can can change the equality > rules for a class while you cannot change the identity rules. > Thus, if you need identity based key management, > define your `__eq__` accordingly. > > -- > https://mail.python.org/mailman/listinfo/python-list From xuanwu348 at 163.com Sat Oct 26 10:51:31 2019 From: xuanwu348 at 163.com (xuanwu348) Date: Sat, 26 Oct 2019 22:51:31 +0800 (CST) Subject: syntax for ellipsis like as "net.blobs['data'].data[...] = transformed_image" In-Reply-To: <639b7d96.83da.1651f42d0e1.Coremail.xuanwu348@163.com> References: <639b7d96.83da.1651f42d0e1.Coremail.xuanwu348@163.com> Message-ID: <51c89253.7ddf.16e088d09d9.Coremail.xuanwu348@163.com> Hi buddies Have a good weekend! I have read some code in caffe, but I confused at "net.blobs['data'].data[...] = transformed_image". The code can be find in this link:https://github.com/BVLC/caffe/blob/master/examples/00-classification.ipynb import caffe model_def = os.path.join(caffe_root, "models/bvlc_alexnet/deploy.prototxt") model_weights = os.path.join(caffe_root, "models/bvlc_alexnet/bvlc_alexnet.caffemodel") net = caffe.Net(model_def, model_weights, caffe.TEST) net.blobs['data'].reshape(50, 3, 227,227) net.blobs['data'].data[...] = transformed_image 1. For ellipsis, is there syntax in python like this " net.blobs['data'].data[...]"? I have checked it which the type is "" 2. Could you provide some samples in which need to use ellipsis. But in python, ellipsis define as below, I did not find the relationship to "net.blobs['data'].data[...]": Help on ellipsis object: class ellipsis(object) | Methods defined here: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __new__(*args, **kwargs) from builtins.type | Create and return a new object. See help(type) for accurate signature. | | __reduce__(...) | helper for pickle | | __repr__(self, /) | Return repr(self). Thanks for your help! Best Regards From jsf80238 at gmail.com Fri Oct 25 11:02:31 2019 From: jsf80238 at gmail.com (Jason Friedman) Date: Fri, 25 Oct 2019 09:02:31 -0600 Subject: Congratulations to @Chris In-Reply-To: <120f075d-9854-94e8-3fa2-3afa7d8a9b33@etelligence.info> References: <120f075d-9854-94e8-3fa2-3afa7d8a9b33@etelligence.info> Message-ID: > > Chris Angelico: [PSF's] 2019 Q2 Community Service Award Winner > http://pyfound.blogspot.com/2019/10/chris-angelico-2019-q2-community.html > > ...and for the many assistances and pearls of wisdom he has contributed > 'here'! > -- > Regards, > =dn > > Agreed. From joepareti54 at gmail.com Fri Oct 25 11:19:29 2019 From: joepareti54 at gmail.com (joseph pareti) Date: Fri, 25 Oct 2019 17:19:29 +0200 Subject: web scraper Message-ID: Thank you so much for your very valuable guidance on my python experiment. Meanwhile the problems I reported before have been solved. This is part of a program that extracts specific information from bank transaction records, and one functionality I still need to implement is a *web scraper*: The eureka / guide "web scraping with python" provides some insights, that are however linked to a specific website: by associating the "inspected" web page with the code shown in the Eureka page, one can build the algorithm, but can it be generalized? Not all tags are in the form of
contains all the needed data, while my case requires a lookup of one item at a time, namely: (i) loop over a bunch of ISIN codes (ii) access a specific website (=morningstar?), that does the ISIN-to-fund-name translation (iii) "inspect" that page containing the result and grab the fund name. I would appreciate any advice on how to program all this. Thanks. -- Regards, Joseph Pareti - Artificial Intelligence consultant Joseph Pareti's AI Consulting Services https://www.joepareti54-ai.com/ cell +49 1520 1600 209 cell +39 339 797 0644 From patatetom at gmail.com Fri Oct 25 16:12:23 2019 From: patatetom at gmail.com (Pascal) Date: Fri, 25 Oct 2019 22:12:23 +0200 Subject: fileinput Message-ID: I have a small python (3.7.4) script that should open a log file and display its content but as you can see, an encoding error occurs : ----------------------- import fileinput import sys try: source = sys.argv[1:] except IndexError: source = None for line in fileinput.input(source): print(line.strip()) ----------------------- python3.7.4 myscript.py myfile.log Traceback (most recent call last): ... UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: invalid continuation byte python3.7.4 myscript.py < myfile.log Traceback (most recent call last): ... UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: invalid continuation byte ----------------------- I add the encoding hook to overcome the error but this time, the script reacts differently depending on the input used : ----------------------- import fileinput import sys try: source = sys.argv[1:] except IndexError: source = None for line in fileinput.input(source, openhook=fileinput.hook_encoded("utf-8", "ignore")): print(line.strip()) ----------------------- python3.7.4 myscript.py myfile.log first line of myfile.log ... last line of myfile.log python3.7.4 myscript.py < myfile.log Traceback (most recent call last): ... UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: invalid continuation byte python3.7.4 myscript.py /dev/stdin < myfile.log first line of myfile.log ... last line of myfile.log python3.7.4 myscript.py - < myfile.log Traceback (most recent call last): ... UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: invalid continuation byte ----------------------- does anyone have an explanation and/or solution ? From __peter__ at web.de Sat Oct 26 11:49:21 2019 From: __peter__ at web.de (Peter Otten) Date: Sat, 26 Oct 2019 17:49:21 +0200 Subject: fileinput References: Message-ID: Pascal wrote: > I have a small python (3.7.4) script that should open a log file and > display its content but as you can see, an encoding error occurs : > > ----------------------- > > import fileinput > import sys > try: > source = sys.argv[1:] > except IndexError: > source = None > for line in fileinput.input(source): > print(line.strip()) > > ----------------------- > > python3.7.4 myscript.py myfile.log > Traceback (most recent call last): > ... > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: > invalid continuation byte > > python3.7.4 myscript.py < myfile.log > Traceback (most recent call last): > ... > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: > invalid continuation byte > > ----------------------- > > I add the encoding hook to overcome the error but this time, the script > reacts differently depending on the input used : > > ----------------------- > > import fileinput > import sys > try: > source = sys.argv[1:] > except IndexError: > source = None > for line in fileinput.input(source, > openhook=fileinput.hook_encoded("utf-8", "ignore")): > print(line.strip()) > > ----------------------- > > python3.7.4 myscript.py myfile.log > first line of myfile.log > ... > last line of myfile.log > > python3.7.4 myscript.py < myfile.log > Traceback (most recent call last): > ... > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: > invalid continuation byte > > python3.7.4 myscript.py /dev/stdin < myfile.log > first line of myfile.log > ... > last line of myfile.log > > python3.7.4 myscript.py - < myfile.log > Traceback (most recent call last): > ... > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: > invalid continuation byte > > ----------------------- > > does anyone have an explanation and/or solution ? '-' or no argument tell fileinput to use sys.stdin. This is already text decoded using Python's default io-encoding, and the open hook is not called. You can override the default encoding by setting the environment variable PYTHONIOENCODING=UTF8:ignore From torriem at gmail.com Sat Oct 26 20:24:11 2019 From: torriem at gmail.com (Michael Torrie) Date: Sat, 26 Oct 2019 18:24:11 -0600 Subject: web scraper In-Reply-To: References: Message-ID: <6afbda52-e83a-c13d-f1b8-15380d6a4b0f@gmail.com> On 10/25/19 9:19 AM, joseph pareti wrote: > but can it be generalized? > Not all tags are in the form of
to just replace those tags in the code, should > one process a different website? Not really, no. There is not an easy way to generalize this sort of web scraping. There are many different ways to use html tags. And each web site is going to use a different scheme for defining CSS ids and classes. Really web scraping is customized to each website, and it's prone to breaking as the website can change itself at any time. The only reliable way to access and process information is if a web site offers a nice stable web services API you can use. From xuanwu348 at 163.com Sat Oct 26 23:01:46 2019 From: xuanwu348 at 163.com (xuanwu348) Date: Sun, 27 Oct 2019 11:01:46 +0800 (CST) Subject: syntax for ellipsis like as "net.blobs['data'].data[...] = transformed_image" In-Reply-To: <51c89253.7ddf.16e088d09d9.Coremail.xuanwu348@163.com> References: <639b7d96.83da.1651f42d0e1.Coremail.xuanwu348@163.com> <51c89253.7ddf.16e088d09d9.Coremail.xuanwu348@163.com> Message-ID: <5f742786.40bd.16e0b299c63.Coremail.xuanwu348@163.com> Thanks too, I have find the answer from "https://stackoverflow.com/questions/772124/what-does-the-python-ellipsis-object-do" This came up in another question recently. I'll elaborate on my answer from there: Ellipsis is an object that can appear in slice notation. For example: myList[1:2, ..., 0] Its interpretation is purely up to whatever implements the __getitem__ function and sees Ellipsis objects there, but its main (and intended) use is in the numeric python extension, which adds a multidimensional array type. Since there are more than one dimensions, slicing becomes more complex than just a start and stop index; it is useful to be able to slice in multiple dimensions as well. E.g., given a 4x4 array, the top left area would be defined by the slice [:2,:2]: >>> a array([[ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12], [13, 14, 15, 16]]) >>> a[:2,:2] # top left array([[1, 2], [5, 6]]) Extending this further, Ellipsis is used here to indicate a placeholder for the rest of the array dimensions not specified. Think of it as indicating the full slice [:] for all the dimensions in the gap it is placed, so for a 3d array, a[...,0] is the same as a[:,:,0] and for 4d, a[:,:,:,0], similarly, a[0,...,0] is a[0,:,:,0] (with however many colons in the middle make up the full number of dimensions in the array). Interestingly, in python3, the Ellipsis literal (...) is usable outside the slice syntax, so you can actually write: >>> ... Ellipsis Other than the various numeric types, no, I don't think it's used. As far as I'm aware, it was added purely for numpy use and has no core support other than providing the object and corresponding syntax. The object being there didn't require this, but the literal "..." support for slices did. ? 2019-10-26 22:51:31?"xuanwu348" ??? Hi buddies Have a good weekend! I have read some code in caffe, but I confused at "net.blobs['data'].data[...] = transformed_image". The code can be find in this link:https://github.com/BVLC/caffe/blob/master/examples/00-classification.ipynb import caffe model_def = os.path.join(caffe_root, "models/bvlc_alexnet/deploy.prototxt") model_weights = os.path.join(caffe_root, "models/bvlc_alexnet/bvlc_alexnet.caffemodel") net = caffe.Net(model_def, model_weights, caffe.TEST) net.blobs['data'].reshape(50, 3, 227,227) net.blobs['data'].data[...] = transformed_image 1. For ellipsis, is there syntax in python like this " net.blobs['data'].data[...]"? I have checked it which the type is "" 2. Could you provide some samples in which need to use ellipsis. But in python, ellipsis define as below, I did not find the relationship to "net.blobs['data'].data[...]": Help on ellipsis object: class ellipsis(object) | Methods defined here: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __new__(*args, **kwargs) from builtins.type | Create and return a new object. See help(type) for accurate signature. | | __reduce__(...) | helper for pickle | | __repr__(self, /) | Return repr(self). Thanks for your help! Best Regards From random832 at fastmail.com Sat Oct 26 23:52:01 2019 From: random832 at fastmail.com (Random832) Date: Sat, 26 Oct 2019 23:52:01 -0400 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: On Sat, Oct 19, 2019, at 07:31, Steve White wrote: > Hi, > > I have an application that would benefit from object instances > distinguished by identity being used in dict's and set's. To do this, > the __hash__ method must be overridden, the obvious return value being > the instance's id. > > This works flawlessly in extensive tests on several platforms, and on > a couple of different Python versions and implementations. > > The documentation seems to preclude a second requirement, however. > > I also want to use the == operator on these objects to mean a natural > comparison of values, different from identity, so that two instances > comparing equivalent does not imply that they are identical. I'd like to jump in to this thread to note that while this is reasonably easily achieved with a custom mapping class that uses a dict along with a wrapper class that stores the identity... I once tried to make a WeakKeyDictionary that was keyed by identity and had no end of trouble. From * at eli.users.panix.com Sun Oct 27 01:36:39 2019 From: * at eli.users.panix.com (Eli the Bearded) Date: Sun, 27 Oct 2019 05:36:39 +0000 (UTC) Subject: How to decode UTF strings? References: <5gJsF.89999$rR2.25558@fx23.iad> Message-ID: In comp.lang.python, DFS wrote: > On 10/25/2019 10:57 PM, MRAB wrote: >> Here's a simple example, based in your code: >> >> from email.header import decode_header >> >> def test(header, default_encoding='utf-8'): >> parts = [] >> >> for data, encoding in decode_header(header): >> if isinstance(data, str): >> parts.append(data) >> else: >> parts.append(data.decode(encoding or default_encoding)) >> >> print(''.join(parts)) >> >> test('=?iso-8859-9?b?T/B1eg==?= ') >> test('=?utf-8?Q?=EB=AF=B8?= ') >> test('=?GBK?B?0Pu66A==?= ') >> test('=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?= >> ') > I don't think it's working: It's close. Just ''.join should be ' '.join. > $ python decode_utf.py > O?uz > ??? > ???? > ?????????? ???????????? Is your terminal UTF-8? I think not. Elijah ------ answered with C code to do this in comp.lang.c From bluebox03 at gmail.com Sun Oct 27 02:10:08 2019 From: bluebox03 at gmail.com (tommy yama) Date: Sun, 27 Oct 2019 15:10:08 +0900 Subject: pip3 install keyboard did not work in my environment Message-ID: Hi, keyboard module can be installed with pip3? Regards, From stevan.white at gmail.com Sun Oct 27 03:24:33 2019 From: stevan.white at gmail.com (Steve White) Date: Sun, 27 Oct 2019 08:24:33 +0100 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: Hi, Yes, there are several options, but they all involve an extra layer that detracts between the interface I am building and my user's code. In this situation, the objects being used as keys are conceptually the unique entities that the user deals with, even if their data is non-unique. And I do not want to subject the user to the un-pythonic use of some operator other than '==' to determine their equivalence. As near as I can tell, returning the id() in __hash__() results in a perfect hash key. I really want to know if that is true. Because if it is true, any further layer is simply covering for a failing in the documentation. Thanks! On Sun, Oct 27, 2019 at 4:54 AM Random832 wrote: > > On Sat, Oct 19, 2019, at 07:31, Steve White wrote: > > Hi, > > > > I have an application that would benefit from object instances > > distinguished by identity being used in dict's and set's. To do this, > > the __hash__ method must be overridden, the obvious return value being > > the instance's id. > > > > This works flawlessly in extensive tests on several platforms, and on > > a couple of different Python versions and implementations. > > > > The documentation seems to preclude a second requirement, however. > > > > I also want to use the == operator on these objects to mean a natural > > comparison of values, different from identity, so that two instances > > comparing equivalent does not imply that they are identical. > > I'd like to jump in to this thread to note that while this is reasonably easily achieved with a custom mapping class that uses a dict along with a wrapper class that stores the identity... > > I once tried to make a WeakKeyDictionary that was keyed by identity and had no end of trouble. > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sun Oct 27 04:02:14 2019 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 27 Oct 2019 19:02:14 +1100 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: On Sun, Oct 27, 2019 at 6:26 PM Steve White wrote: > As near as I can tell, returning the id() in __hash__() results in a > perfect hash key. I really want to know if that is true. > Because if it is true, any further layer is simply covering for a > failing in the documentation. Only if your __eq__() does not return True for anything other than itself. That is the entire definition of __hash__ - it needs to return the same value for two objects that are equal. This is exactly what the documentation said, as multiple people have posted here. If your object is equal only to itself, then its hash can be its identity. Otherwise it should not. It is that simple. ChrisA From patatetom at gmail.com Sun Oct 27 04:12:51 2019 From: patatetom at gmail.com (patatetom at gmail.com) Date: Sun, 27 Oct 2019 01:12:51 -0700 (PDT) Subject: fileinput In-Reply-To: References: Message-ID: <9f7d83d1-72da-433e-b050-27847f85558f@googlegroups.com> Le samedi 26 octobre 2019 17:49:57 UTC+2, Peter Otten a ?crit?: > Pascal wrote: > > > I have a small python (3.7.4) script that should open a log file and > > display its content but as you can see, an encoding error occurs : > > > > ----------------------- > > > > import fileinput > > import sys > > try: > > source = sys.argv[1:] > > except IndexError: > > source = None > > for line in fileinput.input(source): > > print(line.strip()) > > > > ----------------------- > > > > python3.7.4 myscript.py myfile.log > > Traceback (most recent call last): > > ... > > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: > > invalid continuation byte > > > > python3.7.4 myscript.py < myfile.log > > Traceback (most recent call last): > > ... > > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: > > invalid continuation byte > > > > ----------------------- > > > > I add the encoding hook to overcome the error but this time, the script > > reacts differently depending on the input used : > > > > ----------------------- > > > > import fileinput > > import sys > > try: > > source = sys.argv[1:] > > except IndexError: > > source = None > > for line in fileinput.input(source, > > openhook=fileinput.hook_encoded("utf-8", "ignore")): > > print(line.strip()) > > > > ----------------------- > > > > python3.7.4 myscript.py myfile.log > > first line of myfile.log > > ... > > last line of myfile.log > > > > python3.7.4 myscript.py < myfile.log > > Traceback (most recent call last): > > ... > > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: > > invalid continuation byte > > > > python3.7.4 myscript.py /dev/stdin < myfile.log > > first line of myfile.log > > ... > > last line of myfile.log > > > > python3.7.4 myscript.py - < myfile.log > > Traceback (most recent call last): > > ... > > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: > > invalid continuation byte > > > > ----------------------- > > > > does anyone have an explanation and/or solution ? > > '-' or no argument tell fileinput to use sys.stdin. This is already text > decoded using Python's default io-encoding, and the open hook is not called. > You can override the default encoding by setting the environment variable > > PYTHONIOENCODING=UTF8:ignore yes, I just found this about it : https://bugs.python.org/issue26756 this modified script is ok in all cases : import io import fileinput import sys try: source = sys.argv[1:] except IndexError: source = None sys.stdin = io.TextIOWrapper(sys.stdin.buffer, errors='ignore') for line in fileinput.input(source, openhook=fileinput.hook_encoded('utf-8', 'ignore')): print(line.strip()) thanks for the tip ! From hjp-python at hjp.at Mon Oct 28 04:14:47 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 28 Oct 2019 09:14:47 +0100 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: <20191028081447.GA3427@hjp.at> On 2019-10-20 19:31:43 +0200, Steve White wrote: > The point is, I don't think __eq__() is ever called in a situation as > described in my post, This is only guaranteed if the hash is actually stored within the dict. This seems to be the case in the CPython implementation, but there are other ways to implement a hash table which don't store the hashes explicitely (in fact, I don't think any of the variants we learned about at university 30 years ago did this). So your code may work with CPython, but not other Python implementations. Worse, it may stop working with future CPython versions if the dict implementation is changed. But even if you are fine with that, by using a different equality criterion for dicts than for everything else, your code is violating one of every Python programmer's core assumptions. This will very likely trip somebody up (maybe yourself in two years). 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 stevan.white at gmail.com Mon Oct 28 04:34:39 2019 From: stevan.white at gmail.com (Steve White) Date: Mon, 28 Oct 2019 09:34:39 +0100 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: Hi Chris, I'm afraid you've missed my point. As I said in the initial post, I have read the documentation. I think the documentation does not adequately explain how the hashtable (or hashtables generally) work internally. I think that in fact, if __hash__() returns a unique integer for each key, __eq__() is in fact *never* called. There is a reason for this: as I explained, this situation results in a "perfect hash", in which no key collision can occur, the bucket never needs to be searched. The experiment provided in the initial post seems to back this up. If you can shed light on the internals of dict and set and their design goals, please do so! Thanks! On Sun, Oct 27, 2019 at 9:04 AM Chris Angelico wrote: > > On Sun, Oct 27, 2019 at 6:26 PM Steve White wrote: > > As near as I can tell, returning the id() in __hash__() results in a > > perfect hash key. I really want to know if that is true. > > Because if it is true, any further layer is simply covering for a > > failing in the documentation. > > Only if your __eq__() does not return True for anything other than > itself. That is the entire definition of __hash__ - it needs to return > the same value for two objects that are equal. This is exactly what > the documentation said, as multiple people have posted here. > > If your object is equal only to itself, then its hash can be its > identity. Otherwise it should not. It is that simple. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Mon Oct 28 04:46:29 2019 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 28 Oct 2019 19:46:29 +1100 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: On Mon, Oct 28, 2019 at 7:34 PM Steve White wrote: > > Hi Chris, > > I'm afraid you've missed my point. As I said in the initial post, I > have read the documentation. > > I think the documentation does not adequately explain how the > hashtable (or hashtables generally) work internally. > > I think that in fact, if __hash__() returns a unique integer for each > key, __eq__() is in fact *never* called. > There is a reason for this: as I explained, this situation results in > a "perfect hash", in which no key collision can occur, > the bucket never needs to be searched. > The experiment provided in the initial post seems to back this up. > > If you can shed light on the internals of dict and set and their > design goals, please do so! Yes, eq will never be called, because it is assumed that any objects that have different hashes must not compare equal. That is the entire point of the hash. So if your objects might compare equal to each other, they MUST have the same hash. That is what the documentation says. If you don't define EITHER hash OR eq, then you will get a hash based on the object's identity, and it will be equal only to itself. That is the default behaviour. ChrisA From p.f.moore at gmail.com Mon Oct 28 06:12:50 2019 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 28 Oct 2019 10:12:50 +0000 Subject: keying by identity in dict and set In-Reply-To: References: Message-ID: On Mon, 28 Oct 2019 at 10:01, Steve White wrote: > > Hi Chris, > > I'm afraid you've missed my point. As I said in the initial post, I > have read the documentation. > > I think the documentation does not adequately explain how the > hashtable (or hashtables generally) work internally. As stated in the docs, "The only required property is that objects which compare equal have the same hash value". The docs do *not* explain how dictionaries work internally, and that's deliberate. You should not rely on the internal workings of dictionaries, because your code may then not work on other Python implementations (or even on later versions of CPython). Of course, if you're only interested in working on CPython, then you can rely on the details of the dictionary implementation, but in that case you;re expected to look at the implementation (and be prepared for it to change over time!) Paul From hjp-python at hjp.at Mon Oct 28 06:48:11 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 28 Oct 2019 11:48:11 +0100 Subject: fileinput In-Reply-To: References: Message-ID: <20191028104811.GB3427@hjp.at> On 2019-10-25 22:12:23 +0200, Pascal wrote: > for line in fileinput.input(source): > print(line.strip()) > > ----------------------- > > python3.7.4 myscript.py myfile.log > Traceback (most recent call last): > ... > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: > invalid continuation byte [...] > for line in fileinput.input(source, > openhook=fileinput.hook_encoded("utf-8", "ignore")): > print(line.strip()) The file you were trying to read was obviously not encoded in UTF-8, since you got a decode error. So the first question you should ask is: Is it supposed to be encoded in UTF-8 (and just corrupted) or is in supposed to be encoded in something else (e.g. iso-8859-1 or win-1252)? If it is supposed to be in UTF-8 but may contain errors, ignoring errors may be reasonable. If is supposed to be something else, determine what that "something else" actually is, and use that. 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 nashrahmehar11 at gmail.com Sat Oct 26 12:32:34 2019 From: nashrahmehar11 at gmail.com (nashrahmehar11) Date: Sat, 26 Oct 2019 22:02:34 +0530 Subject: Fwd: Sudden changes in idle python and my laptop Message-ID: Sent from my Samsung Galaxy smartphone. -------- Original message --------From: NASHRAH RAZA Date: 26/10/2019 7:32 p.m. (GMT+05:30) To: python-list at python.org Subject: Sudden changes in idle python and my laptop Suddenly,my idle python started to behave abnormally and when i closed and tried to start it again,then it gave the above message.After this when i clicked the yes option in this above box then the setup box appeared and the three options appeared which are-modify,repair,and uninstall.I clicked the modify option and it was successful,but again when i tried to open the application,then the same thing happened.Then i clicked the repair option and it was also successful but again the same thing happened.I dont know what to do,shall i uninstall it and again install it,but there is no guarantee if the same thing will be repeated or not.Please help me out and also tell me about the changes it asks for being made.I remember that before i installed the idle python,it has asked for the changes and as i clicked yes,it got installed,but i dont know why suddenly such thing had happened.I am suspicious about the fact that maybe this program has brought virus with it or not.Also my laptop is also behaving in an abnormal manner,i.e. whatever i am typing in the search option in start button,it is not being typed.I dont know what had happened.Please help me,so that i am able to learn this programming language without any problems.It is 3.7.4 version and my laptop is dell inspiron 15 3000 series.Please help me. From mandala.pavan at gmail.com Sat Oct 26 21:14:08 2019 From: mandala.pavan at gmail.com (Kishore m) Date: Sun, 27 Oct 2019 06:44:08 +0530 Subject: Internal Server Error when trying to access WebTours (an Application built in Strawberry perl) Message-ID: Hi Team, I have installed Python 64 bit 2 days back and had to uninstall Python as I got below error with webtours application built in Strawberry Perl which im using from an year without any issue. *Problem Statement:* Internal Server Error when trying to access WebTours *Error message in webtours server logs:* [Sun Oct 27 06:20:11 2019] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified. : couldn't create child process: 720002: welcome.pl, referer: http://127.0.0.1:1080/WebTours/index.htm [Sun Oct 27 06:20:11 2019] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified. : couldn't spawn child process: C:/Users/Pavan Kishore/Downloads/Web Tours 1.0/WebTours/cgi-bin/welcome.pl, referer: http://127.0.0.1:1080/WebTours/index.htm *Possible steps which caused Issues:* (This Issue came up after below changes on system) 1. Installed Python 2 days back after which it prompted for changes regarding path limit in last step of installation. Also, this is the only software which I installed recently after which I started getting above error. Could you please verify to determine the root cause and help us resolve the issue asap. Thanks & Regards, Pavan Mandala, Performance Test Engineer, +91 96520 29399, linkedin.com/in/pavanmandala SkypeID: pavanmandala From ugo.donini at gmail.com Sun Oct 27 14:37:04 2019 From: ugo.donini at gmail.com (Dott. Ugo Donini) Date: Sun, 27 Oct 2019 19:37:04 +0100 Subject: Installing Python 3.8 on PC with Python 3.7. How to do with version conflicts? Message-ID: <5db5e3d0.1c69fb81.6e2f5.68a0@mx.google.com> I cannot use Python 3.8 on my PC with installed Python 3.7. Is it possible to update the existing Python 3.7 without reinstalling Python 3.8. Conflicts problems. Thankyou Ugo Donini Inviato da Posta per Windows 10 From ehteshamul.haque086 at gmail.com Mon Oct 28 04:19:02 2019 From: ehteshamul.haque086 at gmail.com (Ehtesham Ul Haque) Date: Mon, 28 Oct 2019 13:49:02 +0530 Subject: IDLE is not working Message-ID: From adey2461 at gmail.com Sun Oct 27 01:15:56 2019 From: adey2461 at gmail.com (ankur) Date: Sun, 27 Oct 2019 10:45:56 +0530 Subject: how fix the error no2 mange.py Message-ID: <5db52808.1c69fb81.fca44.6f05@mx.google.com> Please sir reply me how to fix this problem. Python is very good language .at I install Django Poperly (dijango.admin) is work but not run server. Sent from Mail for Windows 10 From ferzans97 at gmail.com Mon Oct 28 09:42:46 2019 From: ferzans97 at gmail.com (ferzan saglam) Date: Mon, 28 Oct 2019 06:42:46 -0700 (PDT) Subject: (New to Python) Shopping List Code Message-ID: How can I stop this code when -1 is typed or at a maximum item count of ten. At the moment the code seems to be in a infinite loop meaning it keeps on asking for an entry until -1 is typed total = 0 while True: print('Cost of item') item = input() if item != -1: total = total + item if item == -1: break print(total) From countryone77 at gmail.com Mon Oct 28 10:04:54 2019 From: countryone77 at gmail.com (Bev In TX) Date: Mon, 28 Oct 2019 09:04:54 -0500 Subject: (New to Python) Shopping List Code In-Reply-To: References: Message-ID: Bev > On Oct 28, 2019, at 8:42 AM, ferzan saglam wrote: > > How can I stop this code when -1 is typed or at a maximum item count of ten. > At the moment the code seems to be in a infinite loop meaning it keeps on asking for an entry until -1 is typed > > > total = 0 > while True: > > print('Cost of item') > > item = input() > > if item != -1: > total = total + item > if item == -1: > > break > > print(total) From countryone77 at gmail.com Mon Oct 28 10:13:22 2019 From: countryone77 at gmail.com (Bev In TX) Date: Mon, 28 Oct 2019 09:13:22 -0500 Subject: (New to Python) Shopping List Code In-Reply-To: References: Message-ID: > On Oct 28, 2019, at 8:42 AM, ferzan saglam wrote: > > How can I stop this code when -1 is typed or at a maximum item count of ten. > At the moment the code seems to be in a infinite loop meaning it keeps on asking for an entry until -1 is typed > > > total = 0 > while True: > > print('Cost of item') > > item = input() > > if item != -1: > total = total + item > if item == -1: > > break > > print(total) > -- Sorry about the blank post? I attempted to scroll down, but instead of doing that,it sent the message. From the documentation (emphasis is mine): ?input([prompt]) If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised. So you don?t have a number; you have a string. Presuming that the string contains an integer, You can convert that string to an integer number with the built in int() function. Bev in TX From ikorot01 at gmail.com Mon Oct 28 10:36:29 2019 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 28 Oct 2019 09:36:29 -0500 Subject: IDLE is not working In-Reply-To: References: Message-ID: Hi, On Mon, Oct 28, 2019 at 8:01 AM Ehtesham Ul Haque wrote: > > It works for me and 99.99999% of people that uses Python! What exactly doesn't work? Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list From hjp-python at hjp.at Mon Oct 28 12:53:52 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 28 Oct 2019 17:53:52 +0100 Subject: (New to Python) Shopping List Code In-Reply-To: References: Message-ID: <20191028165352.GA9785@hjp.at> On 2019-10-28 06:42:46 -0700, ferzan saglam wrote: > How can I stop this code when -1 is typed or at a maximum item count of ten. I'm just rewriting that sentence in Python: > At the moment the code seems to be in a infinite loop meaning it keeps on asking for an entry until -1 is typed > > > total = 0 > while True: > > print('Cost of item') > > item = input() > > if item != -1: > total = total + item > if item == -1: if item == -1 or count > 10: > > break > > print(total) Now it is up to you increment the variable count for each item. Does that help? 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 PythonList at DancesWithMice.info Mon Oct 28 14:27:13 2019 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 29 Oct 2019 07:27:13 +1300 Subject: Installing Python 3.8 on PC with Python 3.7. How to do with version conflicts? In-Reply-To: <5db5e3d0.1c69fb81.6e2f5.68a0@mx.google.com> References: <5db5e3d0.1c69fb81.6e2f5.68a0@mx.google.com> Message-ID: Dottore, On 28/10/19 7:37 AM, Dott. Ugo Donini wrote: > I cannot use Python 3.8 on my PC with installed Python 3.7. > Is it possible to update the existing Python 3.7 without reinstalling Python 3.8. > Conflicts problems. > Thankyou > Ugo Donini > Inviato da Posta per Windows 10 If the question is about updating Python 3.7 'in place' (and not upsetting any applications or systems programs which use Python), then "yes, this is possible": you may be able to update r3.7.0 to r3.7.4, for example (only the last digit changes). I see few compelling reasons to do-so, but YMMV (you have your own reasons). If the question is a desire to run both Python 3.7 AND Python 3.8 on the same machine, then the PSL's (Python Standard Library) answer is "venv". Which you will find described in the docs (documentation) at "12. Virtual Environments and Packages". For my own reasons, instead of Python virtual environments, I prefer to separate different clients/projects by keeping them in their own VirtualBox VM. Some dislike this particular solution as it lacks "open source" principles. There are other "container" technologies worth review. However, I suggest that this type of solution is the preserve of the more advanced programmer/computer user. WebRefs: https://docs.python.org/3/tutorial/venv.html https://www.virtualbox.org/ -- Ciao =dn From python at mrabarnett.plus.com Mon Oct 28 14:47:06 2019 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 28 Oct 2019 18:47:06 +0000 Subject: Installing Python 3.8 on PC with Python 3.7. How to do with version conflicts? In-Reply-To: References: <5db5e3d0.1c69fb81.6e2f5.68a0@mx.google.com> Message-ID: <8d9d35fe-5204-5efa-0e47-6642912c1b24@mrabarnett.plus.com> On 2019-10-28 18:27, DL Neil via Python-list wrote: > Dottore, > > > On 28/10/19 7:37 AM, Dott. Ugo Donini wrote: >> I cannot use Python 3.8 on my PC with installed Python 3.7. >> Is it possible to update the existing Python 3.7 without reinstalling Python 3.8. >> Conflicts problems. >> Thankyou >> Ugo Donini >> Inviato da Posta per Windows 10 > > > If the question is about updating Python 3.7 'in place' (and not > upsetting any applications or systems programs which use Python), then > "yes, this is possible": you may be able to update r3.7.0 to r3.7.4, for > example (only the last digit changes). I see few compelling reasons to > do-so, but YMMV (you have your own reasons). > > If the question is a desire to run both Python 3.7 AND Python 3.8 on the > same machine, then the PSL's (Python Standard Library) answer is "venv". > Which you will find described in the docs (documentation) at "12. > Virtual Environments and Packages". > > For my own reasons, instead of Python virtual environments, I prefer to > separate different clients/projects by keeping them in their own > VirtualBox VM. Some dislike this particular solution as it lacks "open > source" principles. There are other "container" technologies worth > review. However, I suggest that this type of solution is the preserve of > the more advanced programmer/computer user. > > > WebRefs: > https://docs.python.org/3/tutorial/venv.html > https://www.virtualbox.org/ > If you're using Windows, you'd just install the different Python versions into different folders: Python37 for Python 3.7 and Python38 for Python 3.8. The installer doesn't that by default. From and.damore at gmail.com Mon Oct 28 10:28:31 2019 From: and.damore at gmail.com (Andrea D'Amore) Date: Mon, 28 Oct 2019 15:28:31 +0100 Subject: (New to Python) Shopping List Code In-Reply-To: References: Message-ID: On Mon, 28 Oct 2019 at 14:42, ferzan saglam wrote: > How can I stop this code when -1 is typed or at a maximum item count of ten. > At the moment the code seems to be in a infinite loop meaning it keeps on asking for an entry until -1 is typed > item = input() > item != -1: Try these two in REPL and see how the break condition you are using in your code is evaluated, then check each of the comparison operands. -- Andrea From tjreedy at udel.edu Mon Oct 28 15:38:39 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 28 Oct 2019 15:38:39 -0400 Subject: Installing Python 3.8 on PC with Python 3.7. How to do with version conflicts? In-Reply-To: References: <5db5e3d0.1c69fb81.6e2f5.68a0@mx.google.com> Message-ID: On 10/28/2019 2:27 PM, DL Neil via Python-list wrote: > Dottore, > > > On 28/10/19 7:37 AM, Dott. Ugo Donini wrote: >> I cannot use Python 3.8 on my PC with installed Python 3.7. >> Is it possible to update the existing Python 3.7 without reinstalling >> Python 3.8. >> Conflicts problems. >> Thankyou >> Ugo Donini >> Inviato da Posta per Windows 10 > > > If the question is about updating Python 3.7 'in place' (and not > upsetting any applications or systems programs which use Python), then > "yes, this is possible": you may be able to update r3.7.0 to r3.7.4, for > example (only the last digit changes). I see few compelling reasons to > do-so, but YMMV (you have your own reasons). The reason to update 3.7 or any x.y is to get the bugfixes, which eventually number in the hundreds. > If the question is a desire to run both Python 3.7 AND Python 3.8 on the > same machine, then the PSL's (Python Standard Library) answer is "venv". On Windows, the answer is to install 3.7 and 3.8 into separate directories and use the py launcher, installed by the Windows python installer, to select which to run. -- Terry Jan Reedy From tjreedy at udel.edu Mon Oct 28 15:42:21 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 28 Oct 2019 15:42:21 -0400 Subject: Installing Python 3.8 on PC with Python 3.7. How to do with version conflicts? In-Reply-To: <8d9d35fe-5204-5efa-0e47-6642912c1b24@mrabarnett.plus.com> References: <5db5e3d0.1c69fb81.6e2f5.68a0@mx.google.com> <8d9d35fe-5204-5efa-0e47-6642912c1b24@mrabarnett.plus.com> Message-ID: On 10/28/2019 2:47 PM, MRAB wrote: >> On 28/10/19 7:37 AM, Dott. Ugo Donini wrote: >>> I cannot use Python 3.8 on my PC with installed Python 3.7. >>> Is it possible to update the existing Python 3.7 without reinstalling > If you're using Windows, you'd just install the different Python > versions into different folders: Python37 for Python 3.7 and Python38 > for Python 3.8. The installer doesn't that by default. The installer puts them into separate directories by default. The default path depends on whether one installs for all users or just one. Or one can select the path preceeding 'pythonxy'. In any case, one can use the 'py' launcher to chose which PSF installed python to run. -- Terry Jan Reedy From hjp-python at hjp.at Mon Oct 28 16:22:23 2019 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 28 Oct 2019 21:22:23 +0100 Subject: uses both shell and python codes in one script. In-Reply-To: References: <20191003230849.GA62680@cskk.homeip.net> Message-ID: <20191028202223.GA24499@hjp.at> On 2019-10-04 09:15:41 +1000, Chris Angelico wrote: > On Fri, Oct 4, 2019 at 9:08 AM Cameron Simpson wrote: > > On 03Oct2019 23:55, Chris Angelico wrote: > > >In the shell, the first two are an empty string, then ':' is a > > >colon, which introduces a label (the fact that it's in quotes is > > >irrelevant to the shell). So there's an empty label followed by a > > >shell comment. > > > > No. ":" is a synonym for "true". (Like "[" is a synonym for "test".) > > > > There aren't labels in the shell. This is just a dummy "true" command, > > with a comment. > > My bad. I remember using a leading colon-space as a multi-shell > comment, and in at least some of them, it's a label You may actually be onto something here. I came across this interesting[1] paper: http://doc.cat-v.org/unix/unix-reader/A.Research.UNIX.Reader.complete.pdf which mentions: GOTO, : (v2 pages 37-38) Goto manipulated the standard input to give the illusion of a programmable shell (Thompson, v2) The associated : command, which thanks to ASCII collating sequence boasted the first page in the manual, was a big nop. It doesn't explicitely say what : was used for, but since it was associated with goto, it was very likely used to mark a label. The Bourne shell, introduced with v7, doesn't have goto, but retained : as a no-op. hp [1] To Unix history afficionados. -- _ | 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 python at mrabarnett.plus.com Mon Oct 28 16:44:18 2019 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 28 Oct 2019 20:44:18 +0000 Subject: Installing Python 3.8 on PC with Python 3.7. How to do with version conflicts? In-Reply-To: References: <5db5e3d0.1c69fb81.6e2f5.68a0@mx.google.com> <8d9d35fe-5204-5efa-0e47-6642912c1b24@mrabarnett.plus.com> Message-ID: On 2019-10-28 19:42, Terry Reedy wrote: > On 10/28/2019 2:47 PM, MRAB wrote: > >>> On 28/10/19 7:37 AM, Dott. Ugo Donini wrote: >>>> I cannot use Python 3.8 on my PC with installed Python 3.7. >>>> Is it possible to update the existing Python 3.7 without reinstalling > >> If you're using Windows, you'd just install the different Python >> versions into different folders: Python37 for Python 3.7 and Python38 >> for Python 3.8. The installer doesn't that by default. > Oops! Should've been "does that by default". > The installer puts them into separate directories by default. The > default path depends on whether one installs for all users or just one. > Or one can select the path preceeding 'pythonxy'. In any case, one can > use the 'py' launcher to chose which PSF installed python to run. > From larry at hastings.org Tue Oct 29 02:48:17 2019 From: larry at hastings.org (Larry Hastings) Date: Mon, 28 Oct 2019 23:48:17 -0700 Subject: [RELEASED] Python 3.5.8 is (finally) released Message-ID: <3be17817-81ce-a6de-6ffe-7bddd0fa5ec9@hastings.org> On behalf of the Python development community, I'm relieved to announce the availability of Python 3.5.8. Python 3.5 is in "security fixes only" mode.? This new version only contains security fixes, not conventional bug fixes, and it is a source-only release. You can find Python 3.5.8 here: https://www.python.org/downloads/release/python-358/ Oh what fun, //arry/ From patatetom at gmail.com Tue Oct 29 05:27:56 2019 From: patatetom at gmail.com (patatetom at gmail.com) Date: Tue, 29 Oct 2019 02:27:56 -0700 (PDT) Subject: fileinput In-Reply-To: References: <20191028104811.GB3427@hjp.at> Message-ID: <3441b98d-d83d-4cab-a82f-db5572c2fa0d@googlegroups.com> Le lundi 28 octobre 2019 11:48:29 UTC+1, Peter J. Holzer a ?crit?: > On 2019-10-25 22:12:23 +0200, Pascal wrote: > > for line in fileinput.input(source): > > print(line.strip()) > > > > ----------------------- > > > > python3.7.4 myscript.py myfile.log > > Traceback (most recent call last): > > ... > > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: > > invalid continuation byte > [...] > > for line in fileinput.input(source, > > openhook=fileinput.hook_encoded("utf-8", "ignore")): > > print(line.strip()) > > The file you were trying to read was obviously not encoded in UTF-8, > since you got a decode error. > > So the first question you should ask is: > > Is it supposed to be encoded in UTF-8 (and just corrupted) or is in > supposed to be encoded in something else (e.g. iso-8859-1 or win-1252)? > > If it is supposed to be in UTF-8 but may contain errors, ignoring errors > may be reasonable. > > If is supposed to be something else, determine what that "something > else" actually is, and use that. > > 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 you're right, the log file came from Windows and was encoded in iso-8859-1, but my question was about the difference in result between reading a file and reading from stdin. From songofacandy at gmail.com Tue Oct 29 05:33:38 2019 From: songofacandy at gmail.com (Inada Naoki) Date: Tue, 29 Oct 2019 18:33:38 +0900 Subject: fileinput In-Reply-To: <3441b98d-d83d-4cab-a82f-db5572c2fa0d@googlegroups.com> References: <20191028104811.GB3427@hjp.at> <3441b98d-d83d-4cab-a82f-db5572c2fa0d@googlegroups.com> Message-ID: When you are reading file from stdin, fileinput doesn't open the file. Python open the stdin. So openhook doesn't affect to stdin. You can use stdin.reconfigure() to change encoding and error handler of the stdin. On Tue, Oct 29, 2019 at 6:31 PM wrote: > > Le lundi 28 octobre 2019 11:48:29 UTC+1, Peter J. Holzer a ?crit : > > On 2019-10-25 22:12:23 +0200, Pascal wrote: > > > for line in fileinput.input(source): > > > print(line.strip()) > > > > > > ----------------------- > > > > > > python3.7.4 myscript.py myfile.log > > > Traceback (most recent call last): > > > ... > > > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: > > > invalid continuation byte > > [...] > > > for line in fileinput.input(source, > > > openhook=fileinput.hook_encoded("utf-8", "ignore")): > > > print(line.strip()) > > > > The file you were trying to read was obviously not encoded in UTF-8, > > since you got a decode error. > > > > So the first question you should ask is: > > > > Is it supposed to be encoded in UTF-8 (and just corrupted) or is in > > supposed to be encoded in something else (e.g. iso-8859-1 or win-1252)? > > > > If it is supposed to be in UTF-8 but may contain errors, ignoring errors > > may be reasonable. > > > > If is supposed to be something else, determine what that "something > > else" actually is, and use that. > > > > 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 > > you're right, the log file came from Windows and was encoded in iso-8859-1, but my question was about the difference in result between reading a file and reading from stdin. > -- > https://mail.python.org/mailman/listinfo/python-list -- Inada Naoki From patatetom at gmail.com Tue Oct 29 05:44:32 2019 From: patatetom at gmail.com (patatetom at gmail.com) Date: Tue, 29 Oct 2019 02:44:32 -0700 (PDT) Subject: fileinput In-Reply-To: References: <20191028104811.GB3427@hjp.at> <3441b98d-d83d-4cab-a82f-db5572c2fa0d@googlegroups.com> Message-ID: Le mardi 29 octobre 2019 10:34:22 UTC+1, Inada Naoki a ?crit?: > When you are reading file from stdin, fileinput doesn't open the file. > Python open the stdin. So openhook doesn't affect to stdin. > > You can use stdin.reconfigure() to change encoding and error handler > of the stdin. > > On Tue, Oct 29, 2019 at 6:31 PM wrote: > > > > Le lundi 28 octobre 2019 11:48:29 UTC+1, Peter J. Holzer a ?crit : > > > On 2019-10-25 22:12:23 +0200, Pascal wrote: > > > > for line in fileinput.input(source): > > > > print(line.strip()) > > > > > > > > ----------------------- > > > > > > > > python3.7.4 myscript.py myfile.log > > > > Traceback (most recent call last): > > > > ... > > > > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 799: > > > > invalid continuation byte > > > [...] > > > > for line in fileinput.input(source, > > > > openhook=fileinput.hook_encoded("utf-8", "ignore")): > > > > print(line.strip()) > > > > > > The file you were trying to read was obviously not encoded in UTF-8, > > > since you got a decode error. > > > > > > So the first question you should ask is: > > > > > > Is it supposed to be encoded in UTF-8 (and just corrupted) or is in > > > supposed to be encoded in something else (e.g. iso-8859-1 or win-1252)? > > > > > > If it is supposed to be in UTF-8 but may contain errors, ignoring errors > > > may be reasonable. > > > > > > If is supposed to be something else, determine what that "something > > > else" actually is, and use that. > > > > > > 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 > > > > you're right, the log file came from Windows and was encoded in iso-8859-1, but my question was about the difference in result between reading a file and reading from stdin. > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > -- > Inada Naoki thanks for the tip ! From vinay_sajip at yahoo.co.uk Tue Oct 29 12:53:49 2019 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 29 Oct 2019 16:53:49 +0000 (UTC) Subject: ANN: distlib 0.3.0 released on PyPI References: <388461902.3126681.1572368029556.ref@mail.yahoo.com> Message-ID: <388461902.3126681.1572368029556@mail.yahoo.com> I've recently released version 0.3.0 of distlib on PyPI [1]. For newcomers,distlib is a library of packaging functionality which is intended to beusable as the basis for third-party packaging tools. The main changes in this release are as follows: * Partially addressed #102: modules attribute of InstalledDistribution was? incorrectly computed as a list of bytes, rather than a list of str. This? has now been corrected. * Updated Locator._get_digest to check PyPI JSON responses for a "digests"? dictionary before trying "algo_digest" keys. Thanks to Jeffery To for the? patch. * Fixed #123: Improved error message if a resource isn't found. * Fixed #124: Stopped norm-casing the executable written into shebangs, as? it doesn't work for some non-ASCII paths. * Fixed #125: Updated launchers with versions that correctly report errors? containing non-ASCII characters. The updated launchers now also support? relative paths (see http://bit.ly/2JxmOoi for more information). * Fixed #127: Allowed hyphens in flags in export specifications. * Changed Python version handling to accommodate versions like e.g. 3.10? (no longer assume a version X.Y where X and Y are single digits). A more detailed change log is available at [2]. Please try it out, and if you find any problems or have any suggestions for improvements,please give some feedback using the issue tracker! [3] Regards, Vinay Sajip [1] https://pypi.org/project/distlib/0.3.0/[2] https://distlib.readthedocs.io/en/0.3.0/[3] https://bitbucket.org/pypa/distlib/issues/new From dieter at handshake.de Wed Oct 30 01:49:22 2019 From: dieter at handshake.de (dieter) Date: Wed, 30 Oct 2019 06:49:22 +0100 Subject: keying by identity in dict and set References: Message-ID: <87zhhi236l.fsf@handshake.de> Steve White writes: > Yes, there are several options, but they all involve an extra layer > that detracts between the interface I am building and my user's code. Do the wrapping behind the application interface. And in a private email you told me that this is for a very special case -- which likely means "rarely used". For such cases, a bit "detraction" might be acceptable (much more acceptable than a counter-intuitive behaviour of a standard data type). > In this situation, the objects being used as keys are conceptually the > unique entities that the user deals with, even if their data is > non-unique. And I do not want to subject the user to the un-pythonic > use of some operator other than '==' to determine their equivalence. One possibility would be to have a special class for those objects which implements both "__eq__" and "__hash__" via the "id" function. > As near as I can tell, returning the id() in __hash__() results in a > perfect hash key. I really want to know if that is true. Such a "__hash__" implementation is almost surely perfect (unless your objects' lifetime exceeds the process lifetime) **BUT** nevertheless define "__eq__" in the same way. This is because the hash value is not directly used to determine a "dict" slot; to conserve space, the "dict" size determines the number of available slots; therefore, even with a perfect hash, two keys (with different hash values) may end up in the same "dict" slot. It is an implementation details whether Python distinguishes keys in the same slot using only "__eg__" or "__hash__" and "__eq__" (implementation detail means that different Python implementations may behave differently). Thus, follow the documentation and define "__eq__" and "__hash__" in a compatible way. From dieter at handshake.de Wed Oct 30 02:05:40 2019 From: dieter at handshake.de (dieter) Date: Wed, 30 Oct 2019 07:05:40 +0100 Subject: Fwd: keying by identity in dict and set References: <87mudo6qbn.fsf@handshake.de> Message-ID: <87v9s622ff.fsf@handshake.de> Steve White writes: > ... > A little documentation would have saved me personally days of work. > It would be helpful to know: > * under what conditions can one expect a "perfect hash", that is, > one where __eq__() will never be called? Never expect it: keys with different hash values may end up in the same "dict" slot - and then "__eq__" may be used for disambiguation even with a perfect hash function. > * is it sufficient to return the value of the key object's id() > function to produce a perfect hash? Usually. Exceptions are (maybe among others): persistent objects (i.e. objects which live longer than a process), situations during shutdown (during shutdown, an object may be released even if there are still references to it; it might be possible that during this phase the same address is reused even if at some other place there is still an implicit use of the old object). > * when might it be useful to consider keying by identity? Suboptimal question. Follow Python's standard "dict" key management paradigm (which is equality based). If this does not fit, then look for the approach that fits your **special** case. > * what are the limitations of programming this way? With "this way", you mean "identity based dicts"? Then, you have already got several limitations in this thread. From dieter at handshake.de Wed Oct 30 02:11:12 2019 From: dieter at handshake.de (dieter) Date: Wed, 30 Oct 2019 07:11:12 +0100 Subject: Fwd: Sudden changes in idle python and my laptop References: Message-ID: <87r22u2267.fsf@handshake.de> nashrahmehar11 writes: > Suddenly,my idle python started to behave abnormally and when i closed and tried to start it again,then it gave the above message. This is a text only mailing list. You must therefore provide all information in text - you cannot refer to attachments. You might consider uploading images to an appropriate site (maybe "pastebin") and add a corresponding link to your message. But it usually is much preferable to you extract the important information as text and include it explicitly into your message. From dieter at handshake.de Wed Oct 30 02:17:54 2019 From: dieter at handshake.de (dieter) Date: Wed, 30 Oct 2019 07:17:54 +0100 Subject: Internal Server Error when trying to access WebTours (an Application built in Strawberry perl) References: Message-ID: <87mudi21v1.fsf@handshake.de> Kishore m writes: > I have installed Python 64 bit 2 days back and had to uninstall Python as I > got below error with webtours application built in Strawberry Perl which im > using from an year without any issue. > > *Problem Statement:* > Internal Server Error when trying to access WebTours "Internal Server Error" is a server side ("WebTours" in your case) error. It might have been triggered by the client side (that is likely your application) by some bad use. > *Error message in webtours server logs:* > > [Sun Oct 27 06:20:11 2019] [error] [client 127.0.0.1] (OS 2)The system > cannot find the file specified. : couldn't create child process: 720002: > welcome.pl, referer: http://127.0.0.1:1080/WebTours/index.htm This error indicates the "WebTours" has not been set up properly. This is not a Python problem. You likely will get better help somewhere else. From emanbanerjee at gmail.com Wed Oct 30 03:34:14 2019 From: emanbanerjee at gmail.com (eman banerjee) Date: Wed, 30 Oct 2019 00:34:14 -0700 (PDT) Subject: Help on Code logic to remove duplicate mails from webapp mail box In-Reply-To: References: Message-ID: On Wednesday, 30 October 2019 12:40:06 UTC+5:30, eman banerjee wrote: > Hi > > I am working on a project where we make connections to webapp mail and extract subject, sender,body etc from mails and save it in dataframe and insert it n SQL DB. > > My next challenge is to remove any duplicate mails from mailbox. > Could you kindly help me. > It can be a new mail which is entering the mailbox is first checked , if its a duplicate email,it will not be inserted to mail box > > > Thanks code is below class EmailAnalysis: '''Method help to communicate with outlook''' def emailExchangeCredentials(self): try: cipher = Fernet(b'***************') account_details = b'*****************' user_details = b'****************' sec_details = b'*****************' account_details_decrypt = cipher.decrypt(account_details).decode('utf-8') user_details_decrypt = cipher.decrypt(user_details).decode('utf-8') sec_details_decrypt = cipher.decrypt(sec_details).decode('utf-8') credentials = Credentials(user_details_decrypt, sec_details_decrypt) account = Account(account_details_decrypt, credentials=credentials, autodiscover=True) return account except: account = 'Failure' return account def createDBConn(self): cipher = Fernet(b'*********************') ip = b'*******************' port = **** service_name = b'*************' attuid = b'**********************' password = b'********************' ip_decrypt = cipher.decrypt(ip).decode('utf-8') service_name_decrypt = cipher.decrypt(service_name).decode('utf-8') attuid_decrypt = cipher.decrypt(attuid).decode('utf-8') password_decrypt = cipher.decrypt(password).decode('utf-8') dsn_tns = ora.makedsn(ip_decrypt, port,service_name_decrypt) conn = ora.connect(attuid_decrypt,password_decrypt,dsn_tns) return conn def extractEmail(self, account, Email_Data, conn): self.Email_Data = Email_Data SUBJECT = [] SENDER = [] JOB_NAME = [] EMAIL_DATE = [] EMAIL_BODY = [] REMEDIATION_ID = [] PRIORITY = [] i = 0 to_folder = account.inbox / 'Read-Mail' cursor = conn.cursor() #print("Type.......................:",type(account.inbox.all())) for item in account.inbox.all().order_by('-datetime_received')[:20]: if len(item.sender.email_address.split('*****.com'))>1: if len(item.subject.split('GREEN'))<2: SUBJECT.append(item.subject) SENDER.append(item.sender.email_address) find_Job = item.sender.email_address.split('@') job_name = find_Job[0] JOB_NAME.append(str(job_name)) #print("Date time received: ",item.datetime_received.date()) EMAIL_DATE.append(item.datetime_received.date()) date = item.datetime_received.date() date_ = date.strftime('%Y-%m-%d') print("Date:",date_) soup = BeautifulSoup(item.body) email_body_unfor = soup.get_text() #print("Emain Body Ori:- ",email_body_unfor) email_body_unfor_arr = email_body_unfor.split('-->') if len(email_body_unfor_arr) > 1: email_body_unfor_foot = email_body_unfor_arr[1] #print("Emain Body Ori2:- ",email_body_unfor_foot) email_body_unfor_sp_arr = email_body_unfor_foot.split("This message is for the designated recipient only") if len(email_body_unfor_sp_arr) > 1: email_body_unfor_sp = email_body_unfor_sp_arr[0] #print("Emain Body Ori3:- ",email_body_unfor_sp) email_body_1 = email_body_unfor_sp.strip() email_body_2 = email_body_1.rstrip() email_body = email_body_2.lstrip() #print("Email Body: ",email_body) EMAIL_BODY.append(email_body) else: email_body_1 = email_body_unfor.strip() email_body_2 = email_body_1.rstrip() email_body = email_body_2.lstrip() EMAIL_BODY.append(email_body) i = i+1 i = 1000+i Issue_ID = i PROCESS_NAME = str(find_Job[0]) MESSAGE_1 = '' MESSAGE_2 = '' MESSAGE = email_body sql = "INSERT INTO ***DBname** (SENDER,SUBJECT,EMAIL_BODY,EMAIL_DATE) VALUES ("+"'"+str(item.sender.email_address)+"',"+"'"+str(item.subject)+"',"+"'"+str(email_body)+"',"+"'"+str(date_)+"')" print('SQL :- ',sql) result = cursor.execute(sql.encode('utf-8')) conn.commit() #print('to folder:-',to_folder) item.move(to_folder) else: item.move(to_folder) else: item.move(to_folder) cursor.close() conn.close() Email_Data = pd.DataFrame(list(zip(SUBJECT, SENDER,EMAIL_DATE, EMAIL_BODY)),columns =['SUBJECT', 'SENDER', 'EMAIL_DATE', 'EMAIL_BODY']) return Email_Data def emailAnalysisController(self,Task_Details): try: #print('inside controller') self.Task_Details = Task_Details acc = self.emailExchangeCredentials(self) if acc == 'Failure': acc = self.emailExchangeCredentials(self) Email_Data = pd.DataFrame(columns=['EMAIL_DATE','SENDER','EMAIL_BODY','SUBJECT']) Email_Data['EMAIL_DATE'] = pd.to_datetime(Email_Data['EMAIL_DATE']) conn = self.createDBConn(self) Email_Data = self.extractEmail(self, acc,Email_Data, conn) exection_status = 'Success' return exection_status except: exection_status = 'Failure' return exection_status From rosuav at gmail.com Wed Oct 30 03:57:42 2019 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Oct 2019 18:57:42 +1100 Subject: Help on Code logic to remove duplicate mails from webapp mail box In-Reply-To: References: Message-ID: On Wed, Oct 30, 2019 at 6:36 PM eman banerjee wrote: > > On Wednesday, 30 October 2019 12:40:06 UTC+5:30, eman banerjee wrote: > > Hi > > > > I am working on a project where we make connections to webapp mail and extract subject, sender,body etc from mails and save it in dataframe and insert it n SQL DB. > > > > My next challenge is to remove any duplicate mails from mailbox. > > Could you kindly help me. > > It can be a new mail which is entering the mailbox is first checked , if its a duplicate email,it will not be inserted to mail box > > > > > > Thanks > > > code is below > > class EmailAnalysis: > > '''Method help to communicate with outlook''' > > def emailExchangeCredentials(self): > try: > except: > account = 'Failure' > return account This is hiding useful exception messages. Don't do this. > def extractEmail(self, account, Email_Data, conn): > > self.Email_Data = Email_Data > SUBJECT = [] > SENDER = [] > JOB_NAME = [] > EMAIL_DATE = [] > EMAIL_BODY = [] > REMEDIATION_ID = [] > PRIORITY = [] Usually, all-caps names indicate constants, so this is potentially confusing. > sql = "INSERT INTO ***DBname** (SENDER,SUBJECT,EMAIL_BODY,EMAIL_DATE) VALUES ("+"'"+str(item.sender.email_address)+"',"+"'"+str(item.subject)+"',"+"'"+str(email_body)+"',"+"'"+str(date_)+"')" > print('SQL :- ',sql) > result = cursor.execute(sql.encode('utf-8')) This is a VERY VERY bad idea. Don't do this. Use parameterized queries. > item.move(to_folder) > else: > item.move(to_folder) > > else: > item.move(to_folder) Not sure what the logic is here or when you wouldn't move the item to the folder. > def emailAnalysisController(self,Task_Details): > try: > exection_status = 'Success' > return exection_status > except: > exection_status = 'Failure' > return exection_status Python already has a very good mechanism for reporting failures. It's called exception handling. I recommend using it, rather than absorbing exceptions to give a generic return value. Once these issues are sorted out, you'll be able to think about duplicate detection. ChrisA From arnaud at sphaero.org Wed Oct 30 04:32:16 2019 From: arnaud at sphaero.org (Arnaud Loonstra) Date: Wed, 30 Oct 2019 09:32:16 +0100 Subject: return a ctypes object to C Message-ID: <3a846468-b53a-eb1b-17ec-587cc8115ce0@sphaero.org> Hi all, I'm trying to wrap my head around the ctypes API. I have a C structure I wish to create in Python and then return from python to C. So a python method is called from C and needs to return an object which we then process in C again. I have a binding to access and create the C methods and structures so in Python I can call the Zmsg() constructor. I now need to return this. My python test method is simply: def actor_test( *args, **kwargs): print("test") msg = Zmsg() frame = Zframe(b"Hello", 5) msg.prepend(frame) return msg the method is called from C as follows: PyObject *pReturn = PyObject_CallObject(pFunc, NULL); This correctly calls the method. However the returned object is of course a PyObject*. The debugger says it's "" PyObject [class] "" [super class] "" [meta type] "" ob_refcnt 1 Py_ssize_t However how I can I get it back to the original C type (zmsg_t *) Any help really appreciated. Rg, Arnaud From tjreedy at udel.edu Wed Oct 30 06:00:12 2019 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 30 Oct 2019 06:00:12 -0400 Subject: Fwd: Sudden changes in idle python and my laptop In-Reply-To: <87r22u2267.fsf@handshake.de> References: <87r22u2267.fsf@handshake.de> Message-ID: On 10/30/2019 2:11 AM, dieter wrote: > nashrahmehar11 writes: >> Suddenly,my idle python started to behave abnormally Possibility 1: a cosmic ray or a power surge scrambled some bits and you need to run chkdsk (on Windows) or equivalent to repair them. Possibility 2: you altered the system some way, such as by installing other python-related software, that affected the operation of IDLE. > and when i closed and tried to start it again,then it gave the above message. I might be more specific when you copy and paste the message. > This is a text only mailing list. > You must therefore provide all information in text - you cannot refer > to attachments. > > You might consider uploading images to an appropriate site > (maybe "pastebin") and add a corresponding link to your message. Please don't unless it is the ***only*** way to convey the information -- which is very unlikely. > But it usually is much preferable to you extract the important > information as text and include it explicitly into your message. Please do. -- Terry Jan Reedy From ferzans97 at gmail.com Wed Oct 30 07:55:15 2019 From: ferzans97 at gmail.com (ferzan saglam) Date: Wed, 30 Oct 2019 04:55:15 -0700 (PDT) Subject: How can i stop this Infinite While Loop - Python Message-ID: I have tried many ways to stop the infinite loop but my program doesn't seem to stop after 10 items! It keeps going...!) --------------------------- total = 0 while True: print('Cost of item') item = input() if item != -1: total += int(item) else: break print(total) --------------------------- The output I am aiming for is for the code to stop asking 'Cost of item' after 10 inputs or until -1 is typed, but the code repeats itself on an infinite loop. I cannot seem to stop the infinite loop. Thanks for any help in advance. From ekopalypse at gmail.com Wed Oct 30 08:28:30 2019 From: ekopalypse at gmail.com (Eko palypse) Date: Wed, 30 Oct 2019 13:28:30 +0100 Subject: How can i stop this Infinite While Loop - Python In-Reply-To: References: Message-ID: >From what I understand you want to give the user the possibility to try 10 times or enter -1 to end the script, right? If so, you need to check if item is -1 or total tries are already 10 and in such a case break the loop. No need for an else branch. Note, input returns an str object but you compare against an integer -> item != -1 This total += int(item) should be raised by one as you don't know what item actually is, it might be a text Eren Am Mi., 30. Okt. 2019 um 13:01 Uhr schrieb ferzan saglam < ferzans97 at gmail.com>: > I have tried many ways to stop the infinite loop but my program doesn't > seem to stop after 10 items! It keeps going...!) > > --------------------------- > total = 0 > while True: > > print('Cost of item') > item = input() > > if item != -1: > total += int(item) > else: > break > > print(total) > --------------------------- > > > The output I am aiming for is for the code to stop asking 'Cost of item' > after 10 inputs or until -1 is typed, but the code repeats itself on an > infinite loop. I cannot seem to stop the infinite loop. > > Thanks for any help in advance. > -- > https://mail.python.org/mailman/listinfo/python-list > From matheus.saraiva at gmail.com Wed Oct 30 08:13:30 2019 From: matheus.saraiva at gmail.com (Matheus Saraiva) Date: Wed, 30 Oct 2019 09:13:30 -0300 Subject: How can i stop this Infinite While Loop - Python In-Reply-To: References: Message-ID: <47f95611-3e93-6a6a-d5b3-b203469b8ee4@gmail.com> m 30/10/2019 08:55, ferzan saglam escreveu: > total = 0 > while True: > > print('Cost of item') > item = input() > > if item != -1: > total += int(item) > else: > break > > print(total) The program does not stop because its code does not contain any deals that make the loop stop after 10 rounds. You can simply implement a counter that counts the number of times the loop has passed. You also did not convert item to int to make the comparison. total = 0 rounds = 0 while rounds <= 10: ? print('Cost of item') ? item = input() ? if int(item) > -1: ??? total += int(item) ??? rounds += 1 ? else: ??? break print(total) From gunnar at magnusson.io Wed Oct 30 08:29:01 2019 From: gunnar at magnusson.io (Gunnar =?utf-8?B?w57Ds3IgTWFnbsO6c3Nvbg==?=) Date: Wed, 30 Oct 2019 13:29:01 +0100 Subject: How can i stop this Infinite While Loop - Python In-Reply-To: References: Message-ID: <85tv7qju2a.fsf@magnusson.io> > item = input() > if item != -1: If you try this in the REPL, you'll see that 'item' is a string. You're trying to compare it to an integer, which will always fail. The cheapest way to fix this is probably: if item != '-1': Best, G From emanbanerjee at gmail.com Wed Oct 30 03:09:50 2019 From: emanbanerjee at gmail.com (emanbanerjee at gmail.com) Date: Wed, 30 Oct 2019 00:09:50 -0700 (PDT) Subject: Help on Code logic to remove duplicate mails from webapp mail box Message-ID: Hi I am working on a project where we make connections to webapp mail and extract subject, sender,body etc from mails and save it in dataframe and insert it n SQL DB. My next challenge is to remove any duplicate mails from mailbox. Could you kindly help me. It can be a new mail which is entering the mailbox is first checked , if its a duplicate email,it will not be inserted to mail box Thanks From Irv at furrypants.com Wed Oct 30 11:28:37 2019 From: Irv at furrypants.com (Irv Kalb) Date: Wed, 30 Oct 2019 08:28:37 -0700 Subject: How can i stop this Infinite While Loop - Python In-Reply-To: References: Message-ID: <87E48691-61BF-4051-9EEB-FDE398950266@furrypants.com> > On Oct 30, 2019, at 4:55 AM, ferzan saglam wrote: > > I have tried many ways to stop the infinite loop but my program doesn't seem to stop after 10 items! It keeps going...!) > > --------------------------- > total = 0 > while True: > > print('Cost of item') > item = input() > > if item != -1: > total += int(item) > else: > break > > print(total) > --------------------------- > > > The output I am aiming for is for the code to stop asking 'Cost of item' after 10 inputs or until -1 is typed, but the code repeats itself on an infinite loop. I cannot seem to stop the infinite loop. > > Thanks for any help in advance. > -- > https://mail.python.org/mailman/listinfo/python-list > Perhaps some pseudo-code will help. The basic problem involves a loop, as you recognized, but there are two ways to exit the loop: 1) if the user types "-1" 2) if the user gets to 10 items Your code needs to account for both. Here's an description of the solution: Initialize a total at zero Initialize a counter at zero # the user has entered zero prices Loop forever Ask the user to enter a price or type a -1 to indicate that they are finished Convert the user's answer to an integer (assuming all values are integers here) if the user's answer was -1 exit the loop here Add the user's answer to your total Since the user has given you another answer, increment the counter if the user has given you the maximum number of answers exit the loop here Report the total (and perhaps the number of prices entered) Hope that helps, Irv From ferzans97 at gmail.com Wed Oct 30 12:38:29 2019 From: ferzans97 at gmail.com (ferzan saglam) Date: Wed, 30 Oct 2019 09:38:29 -0700 (PDT) Subject: How can i stop this Infinite While Loop - Python In-Reply-To: References: <47f95611-3e93-6a6a-d5b3-b203469b8ee4@gmail.com> Message-ID: <48b7730d-3ec6-43e3-aacd-0a3a16d0835f@googlegroups.com> On Wednesday, October 30, 2019 at 2:19:32 PM UTC, Matheus Saraiva wrote: > m 30/10/2019 08:55, ferzan saglam escreveu: > > total = 0 > > while True: > > > > print('Cost of item') > > item = input() > > > > if item != -1: > > total += int(item) > > else: > > break > > > > print(total) > The program does not stop because its code does not contain any deals > that make the loop stop after 10 rounds. You can simply implement a > counter that counts the number of times the loop has passed. > > You also did not convert item to int to make the comparison. > > total = 0 > rounds = 0 > while rounds <= 10: > > ? print('Cost of item') > ? item = input() > > ? if int(item) > -1: > ??? total += int(item) > ??? rounds += 1 > ? else: > ??? break > > print(total) Thanks, it Works superbly. To get the limit of 10 i wanted, i had to make a slight change: while rounds <= 9 . From __peter__ at web.de Wed Oct 30 13:19:48 2019 From: __peter__ at web.de (Peter Otten) Date: Wed, 30 Oct 2019 18:19:48 +0100 Subject: How can i stop this Infinite While Loop - Python References: <47f95611-3e93-6a6a-d5b3-b203469b8ee4@gmail.com> <48b7730d-3ec6-43e3-aacd-0a3a16d0835f@googlegroups.com> Message-ID: ferzan saglam wrote: > On Wednesday, October 30, 2019 at 2:19:32 PM UTC, Matheus Saraiva wrote: >> rounds = 0 >> while rounds <= 10: ... > Thanks, it Works superbly. > To get the limit of 10 i wanted, i had to make a slight change: > while rounds <= 9 . That's the (in)famous "off by one" bug ;) To stay consistent with Python's range() and slices it's best to always use "half-open" intervals which include the lower, but not the upper bound. In your case you would keep the start value of 0 and the limit of 10, but change the comparison: rounds = 0 while rounds < 10: ... rounds += 1 From arequipeno at gmail.com Wed Oct 30 17:35:55 2019 From: arequipeno at gmail.com (Ian Pilcher) Date: Wed, 30 Oct 2019 16:35:55 -0500 Subject: Distutils - bdist_rpm - specify python interpretter location Message-ID: I am trying to use Distutils "bdist_rpm" function on Fedora 30. It is failing, because Fedora does not provide a "python" executable; it provides /usr/bin/python2 and /usr/bin/python3. The error message is: env: 'python': No such file or directory error: Bad exit status from /var/tmp/rpm-tmp.a3xWMd (%build) When run with the --spec-only option, one can see where 'python' is used in the generated SPEC file: %build env CFLAGS="$RPM_OPT_FLAGS" python setup.py build %install python setup.py install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES Is there a way to tell Distutils to use 'python2'? Thanks! -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From larry at hastings.org Wed Oct 30 19:17:49 2019 From: larry at hastings.org (Larry Hastings) Date: Wed, 30 Oct 2019 16:17:49 -0700 Subject: [WARNING] Some users who downloaded the Python 3.5.8 .xz tarball got the wrong version Message-ID: <853f6aa4-a4c1-73d6-4de4-b8712ccb89c7@hastings.org> Due to awkward CDN caching, some users who downloaded the source code tarballs of Python 3.5.8 got a preliminary version instead of the final version.? As best as we can tell, this only affects the .xz release; there are no known instances of users downloading an incorrect version of the .tgz file. If you downloaded "Python-3.5.8.tar.xz" during the first twelve hours of its release, you might be affected.? It's easy to determine this for yourself.? The file size (15,382,140 bytes) and MD5 checksum (4464517ed6044bca4fc78ea9ed086c36) published on the release page have always matched the correct version.? Also, the GPG signature file will only report a "Good signature" for the correct .xz file (using "gpg --verify"). What's the difference between the two?? The only difference is that the final version also merges a fix for Python issue tracker #38243: https://bugs.python.org/issue38243 The fix adds a call to "html.escape" at a judicious spot, line 896 in Lib/xmlrpc/server.py.? The only other changes are one new test, to ensure this new code is working, and an entry in the NEWS file.? You can see the complete list of changes here: https://github.com/python/cpython/pull/16516/files What should you do?? It's up to you. * If you and your users aren't using the XMLRPC library built in to Python, you don't need to worry about which version of 3.5.8 you downloaded. * If you downloaded the .tgz tarball or the Git repo, you already have the correct version. * If you downloaded the xz file and want to make sure you have the fix, check the MD5 sum, and if it's wrong download a fresh copy (and make sure that one matches the known good MD5 sum!). To smooth over this whole sordid mess, I plan to make a 3.5.9 release in the next day or so.? It'll be identical to the 3.5.8 release; its only purpose is to ensure that all users have the same updated source code, including the fix for #38243. Sorry for the mess, everybody, //arry/ From vverteletskyi at gmail.com Wed Oct 30 15:25:48 2019 From: vverteletskyi at gmail.com (Vladyslav Verteletskyi) Date: Wed, 30 Oct 2019 21:25:48 +0200 Subject: Issue with running programs in Python and imports, probably directories messed up Message-ID: Dear developers, I have stuck upon a problem with all of my attempts to import libraries to Python. PyCharm and Anaconda both fail, as well as terminal. Find the screenshots enclosed. I have tried reinstalling both several times, of no help. All of the libraries I tried to import are already downloaded and were used successfully before something has messed up all Python in my system. Bests, Vlad [image: ??????????.png] [image: ??????????.png] -------------- next part -------------- Traceback (most recent call last): File "C:\ProgramData\Anaconda\Scripts\jupyter-notebook-script.py", line 6, in from notebook.notebookapp import main File "C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\notebook\notebookapp.py", line 47, in from zmq.eventloop import ioloop File "C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\zmq\__init__.py", line 47, in from zmq import backend File "C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\zmq\backend\__init__.py", line 40, in reraise(*exc_info) File "C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\zmq\utils\sixcerpt.py", line 34, in reraise raise value File "C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\zmq\backend\__init__.py", line 27, in _ns = select_backend(first) File "C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\zmq\backend\select.py", line 28, in select_backend mod = __import__(name, fromlist=public_api) File "C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\__init__.py", line 6, in from . import (constants, error, message, context, ImportError: cannot import name 'constants' from 'zmq.backend.cython' (C:\Users\Drake\AppData\Roaming\Python\Python37\site-packages\zmq\backend\cython\__init__.py) From thodorisdoultsinos at gmail.com Wed Oct 30 20:42:25 2019 From: thodorisdoultsinos at gmail.com (thodoris doultsinos) Date: Thu, 31 Oct 2019 02:42:25 +0200 Subject: error with installing a package(matplotlib) Message-ID: Hello, I have been encountering problems with installing packages on python. I am using windows 10, pycharm and pip install order in command prompt to install packages.At first I had an error with installing numpy (something with visual c++ so i downloaded them and it worked).Now i want to download matplotlib and i have this error: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DFREETYPE_BUILD_TYPE=system -DPY_ARRAY_UNIQUE_SYMBOL=MPL_matplotlib_ft2font_ARRAY_API -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -D__STDC_FORMAT_MACROS=1 -Iextern/agg24-svn/include -Ic:\users\tdoults\appdata\local\programs\python\python38-32\lib\site-packages\numpy\core\include -Ic:\users\tdoults\appdata\local\programs\python\python38-32\include -Ic:\users\tdoults\appdata\local\programs\python\python38-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /Tcsrc/checkdep_freetype2.c /Fobuild\temp.win32-3.8\Release\src/checkdep_freetype2.obj checkdep_freetype2.c src/checkdep_freetype2.c(1): fatal error C1083: Cannot open include file: 'ft2build.h': No such file or directory error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.23.28105\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2 ---------------------------------------- ERROR: Command errored out with exit status 1: 'c:\users\tdoults\appdata\local\programs\python\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\tdoults\\AppData\\Local\\Temp\\pip-install-dl4grek0\\matplotlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\tdoults\\AppData\\Local\\Temp\\pip-install-dl4grek0\\matplotlib\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\tdoults\AppData\Local\Temp\pip-record-8431q_7r\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output. If there is a solution it would be very helpful for me.Thank you nevertheless! Theodor Doultsinos From arnaud at sphaero.org Thu Oct 31 09:13:57 2019 From: arnaud at sphaero.org (Arnaud Loonstra) Date: Thu, 31 Oct 2019 14:13:57 +0100 Subject: return a ctypes object to C In-Reply-To: <3a846468-b53a-eb1b-17ec-587cc8115ce0@sphaero.org> References: <3a846468-b53a-eb1b-17ec-587cc8115ce0@sphaero.org> Message-ID: <44acf750-13eb-4049-1568-4ab43a95658a@sphaero.org> On 30-10-2019 09:32, Arnaud Loonstra wrote: > Hi all, > > I'm trying to wrap my head around the ctypes API. I have a C structure I > wish to create in Python and then return from python to C. > > So a python method is called from C and needs to return an object which > we then process in C again. > > I have a binding to access and create the C methods and structures so in > Python I can call the Zmsg() constructor. I now need to return this. > > My python test method is simply: > > def actor_test( *args, **kwargs): > ??? print("test") > ??? msg = Zmsg() > ??? frame = Zframe(b"Hello", 5) > ??? msg.prepend(frame) > ??? return msg > > the method is called from C as follows: > > PyObject *pReturn = PyObject_CallObject(pFunc, NULL); > > This correctly calls the method. However the returned object is of > course a PyObject*. The debugger says it's > > ""??? PyObject > ??????????? [class]??? "" > ??????????? [super class]??? "" > ??????????? [meta type]??? "" > ??????????? ob_refcnt??? 1??? Py_ssize_t > > However how I can I get it back to the original C type (zmsg_t *) > > Any help really appreciated. > What I've found so far is that I can return the address of the ctypes object. msg = Zmsg() frame = Zframe(b"Hello", 5) msg.prepend(frame) return addressof(msg._as_parameter_.contents) In C I can then cast it back to the original type. PyObject *pReturn = PyObject_CallObject(pFunc, NULL); assert(pReturn); long bla = PyLong_AsLong(pReturn); zmsg_t* test = (zmsg_t *)bla; assert(test); char *hello = zmsg_popstr(test); assert(hello); assert(streq(hello, "Hello")); This works, I'm not sure if this is the right way. It also creates a complicated setup with the garbage collector. Anybody better ideas? Rg, Arnaud From tjol at tjol.eu Thu Oct 31 09:44:30 2019 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 31 Oct 2019 14:44:30 +0100 Subject: return a ctypes object to C In-Reply-To: <44acf750-13eb-4049-1568-4ab43a95658a@sphaero.org> References: <3a846468-b53a-eb1b-17ec-587cc8115ce0@sphaero.org> <44acf750-13eb-4049-1568-4ab43a95658a@sphaero.org> Message-ID: <296dd104-0039-c162-1f68-429464505465@tjol.eu> On 31/10/2019 14.13, Arnaud Loonstra wrote: > On 30-10-2019 09:32, Arnaud Loonstra wrote: >> Hi all, >> >> I'm trying to wrap my head around the ctypes API. I have a C >> structure I wish to create in Python and then return from python to C. >> >> So a python method is called from C and needs to return an object >> which we then process in C again. >> >> I have a binding to access and create the C methods and structures so >> in Python I can call the Zmsg() constructor. I now need to return this. >> >> My python test method is simply: >> >> def actor_test( *args, **kwargs): >> ???? print("test") >> ???? msg = Zmsg() >> ???? frame = Zframe(b"Hello", 5) >> ???? msg.prepend(frame) >> ???? return msg >> >> the method is called from C as follows: >> >> PyObject *pReturn = PyObject_CallObject(pFunc, NULL); >> >> This correctly calls the method. However the returned object is of >> course a PyObject*. The debugger says it's >> >> ""??? PyObject >> ???????????? [class]??? "" >> ???????????? [super class]??? "" >> ???????????? [meta type]??? "" >> ???????????? ob_refcnt??? 1??? Py_ssize_t >> >> However how I can I get it back to the original C type (zmsg_t *) >> >> Any help really appreciated. >> > > What I've found so far is that I can return the address of the ctypes > object. > > msg = Zmsg() > frame = Zframe(b"Hello", 5) > msg.prepend(frame) > return addressof(msg._as_parameter_.contents) > > In C I can then cast it back to the original type. > > PyObject *pReturn = PyObject_CallObject(pFunc, NULL); > assert(pReturn); > long bla = PyLong_AsLong(pReturn); > zmsg_t* test = (zmsg_t *)bla; > assert(test); > char *hello = zmsg_popstr(test); > assert(hello); > assert(streq(hello, "Hello")); > > This works, I'm not sure if this is the right way. It also creates a > complicated setup with the garbage collector. > > Anybody better ideas? You've already got a complicated setup with your ctypes objects... If you're using the Python C API anyway, why would you use ctypes at all? You can create custom Python types in C to wrap your C pointers. Alternatively: if you're using ctypes anyway, why use the Python C API at all? You can create C function pointers from Python functions with ctypes. If you're mixing two different ways of interfacing Python and C, the result will ALWAYS be messy. Better to stick to one. Personally, I prefer cffi or cython depending on the situation, as I find them clearer and easier to use than ctypes. Using the Python C API directly is usually the hardest to understand and the easiest to get wrong. -- Thomas From arnaud at sphaero.org Thu Oct 31 10:39:53 2019 From: arnaud at sphaero.org (Arnaud Loonstra) Date: Thu, 31 Oct 2019 15:39:53 +0100 Subject: return a ctypes object to C In-Reply-To: <296dd104-0039-c162-1f68-429464505465@tjol.eu> References: <3a846468-b53a-eb1b-17ec-587cc8115ce0@sphaero.org> <44acf750-13eb-4049-1568-4ab43a95658a@sphaero.org> <296dd104-0039-c162-1f68-429464505465@tjol.eu> Message-ID: <7fcc81f2-c53c-e9c2-4fe5-1371b3bbea67@sphaero.org> On 31-10-2019 14:44, Thomas Jollans wrote: > On 31/10/2019 14.13, Arnaud Loonstra wrote: >> On 30-10-2019 09:32, Arnaud Loonstra wrote: >>> Hi all, >>> >>> I'm trying to wrap my head around the ctypes API. I have a C >>> structure I wish to create in Python and then return from python to C. >>> >>> So a python method is called from C and needs to return an object >>> which we then process in C again. >>> >>> I have a binding to access and create the C methods and structures so >>> in Python I can call the Zmsg() constructor. I now need to return this. >>> >>> My python test method is simply: >>> >>> def actor_test( *args, **kwargs): >>> ???? print("test") >>> ???? msg = Zmsg() >>> ???? frame = Zframe(b"Hello", 5) >>> ???? msg.prepend(frame) >>> ???? return msg >>> >>> the method is called from C as follows: >>> >>> PyObject *pReturn = PyObject_CallObject(pFunc, NULL); >>> >>> This correctly calls the method. However the returned object is of >>> course a PyObject*. The debugger says it's >>> >>> ""??? PyObject >>> ???????????? [class]??? "" >>> ???????????? [super class]??? "" >>> ???????????? [meta type]??? "" >>> ???????????? ob_refcnt??? 1??? Py_ssize_t >>> >>> However how I can I get it back to the original C type (zmsg_t *) >>> >>> Any help really appreciated. >>> >> >> What I've found so far is that I can return the address of the ctypes >> object. >> >> msg = Zmsg() >> frame = Zframe(b"Hello", 5) >> msg.prepend(frame) >> return addressof(msg._as_parameter_.contents) >> >> In C I can then cast it back to the original type. >> >> PyObject *pReturn = PyObject_CallObject(pFunc, NULL); >> assert(pReturn); >> long bla = PyLong_AsLong(pReturn); >> zmsg_t* test = (zmsg_t *)bla; >> assert(test); >> char *hello = zmsg_popstr(test); >> assert(hello); >> assert(streq(hello, "Hello")); >> >> This works, I'm not sure if this is the right way. It also creates a >> complicated setup with the garbage collector. >> >> Anybody better ideas? > > You've already got a complicated setup with your ctypes objects... > > If you're using the Python C API anyway, why would you use ctypes at > all? You can create custom Python types in C to wrap your C pointers. > > Alternatively: if you're using ctypes anyway, why use the Python C API > at all? You can create C function pointers from Python functions with > ctypes. > > If you're mixing two different ways of interfacing Python and C, the > result will ALWAYS be messy. Better to stick to one. Personally, I > prefer cffi or cython depending on the situation, as I find them clearer > and easier to use than ctypes. Using the Python C API directly is > usually the hardest to understand and the easiest to get wrong. > > -- Thomas Hi Thomas, I have an engine running which can call handlers. These handlers return a zmsg_t (a message) which the engine then can process. In this engine we have Python embedded and I want to use a Python method as a handler. To embed Python we need to use the Python C API. To construct a zmsg_t type in Python we need to call the corresponding C method and we use ctypes to do that. I'm using a ctypes binding because it already exists, it's here: https://github.com/zeromq/czmq/blob/d6283985ba52fd8c3f8fbdc7cd5c08372ff69ca1/bindings/python/czmq/_czmq_ctypes.py#L4392 I know I can use cffi for example but that's IMHO just a ctypes alternative. Are you saying it's better to create some approach to create a zmsg_t using the Python C API? Please enlighten me if this should be done differently. Rg, Arnaud From info at dantalion.nl Thu Oct 31 06:38:37 2019 From: info at dantalion.nl (info at dantalion.nl) Date: Thu, 31 Oct 2019 11:38:37 +0100 Subject: Main threads waits indefinitely on futures if single future calls condition.wait() Message-ID: <14ddc312-1785-91d9-fa21-684234a9658f@dantalion.nl> Hello, Recently I have been trying to use a reantrant read write lock in my project but discovered several problems when writing test cases. All the relevant material can be found on the following locations https://stackoverflow.com/questions/58410610/calling-condition-wait-inside-thread-causes-retrieval-of-any-future-to-block-o https://bugs.launchpad.net/futurist/+bug/1848457 https://github.com/Dantali0n/bug1848457 But let me describe it here as well. I am using the futurist library maintained by the OpenStack foundation. This library provides concurrency constructs similar to those of Python itself. Among the functionality is a wait_for_any method which waits on a list of futures and continuous once one of them is done(). However, when I submit two tasks to a threadpool which both attempt to get a reantrant read write lock this wait_for_any method behaves unexpectedly. Since both tasks attempt to get the lock concurrently one will succeed and the other will not. The behavior of this lock is to call condition.wait() if it does not succeed. The unexpected behavior of the wait_for_any method is that in this scenario it will block indefinitely when called even though one of the futures is done() and finished successfully. In https://github.com/Dantali0n/bug1848457 I have created a spin_for_any using the same lock but with 'native' Python concurrency and here calling future.done() does not block. I was hoping someone had any clue as to what could cause this and how it can be resolved. As mentioned before the question is also over on stackoverflow, I have been struggling with this for a month now. I hope someone has time to provide some help on this matter. Kind regards, Corne Lukken (Dantali0n) From aixtools at felt.demon.nl Thu Oct 31 08:30:46 2019 From: aixtools at felt.demon.nl (Michael) Date: Thu, 31 Oct 2019 13:30:46 +0100 Subject: [Python-Dev] [WARNING] Some users who downloaded the Python 3.5.8 .xz tarball got the wrong version In-Reply-To: <853f6aa4-a4c1-73d6-4de4-b8712ccb89c7@hastings.org> References: <853f6aa4-a4c1-73d6-4de4-b8712ccb89c7@hastings.org> Message-ID: <7c83c447-eae9-e167-729c-64e5a19d8f61@felt.demon.nl> On 31/10/2019 00:17, Larry Hastings wrote: > > > Due to awkward CDN caching, some users who downloaded the source code > tarballs of Python 3.5.8 got a preliminary version instead of the > final version.? As best as we can tell, this only affects the .xz > release; there are no known instances of users downloading an > incorrect version of the .tgz file. > > If you downloaded "Python-3.5.8.tar.xz" during the first twelve hours > of its release, you might be affected.? It's easy to determine this > for yourself.? The file size (15,382,140 bytes) and MD5 checksum > (4464517ed6044bca4fc78ea9ed086c36) published on the release page have > always matched the correct version.? Also, the GPG signature file will > only report a "Good signature" for the correct .xz file (using "gpg > --verify"). > > What's the difference between the two?? The only difference is that > the final version also merges a fix for Python issue tracker #38243: > > https://bugs.python.org/issue38243 > > The fix adds a call to "html.escape" at a judicious spot, line 896 in > Lib/xmlrpc/server.py.? The only other changes are one new test, to > ensure this new code is working, and an entry in the NEWS file.? You > can see the complete list of changes here: > > https://github.com/python/cpython/pull/16516/files > > What should you do?? It's up to you. > > * If you and your users aren't using the XMLRPC library built in to > Python, you don't need to worry about which version of 3.5.8 you > downloaded. > * If you downloaded the .tgz tarball or the Git repo, you already > have the correct version. > * If you downloaded the xz file and want to make sure you have the > fix, check the MD5 sum, and if it's wrong download a fresh copy > (and make sure that one matches the known good MD5 sum!). > > To smooth over this whole sordid mess, I plan to make a 3.5.9 release > in the next day or so.? It'll be identical to the 3.5.8 release; its > only purpose is to ensure that all users have the same updated source > code, including the fix for #38243. > > > Sorry for the mess, everybody, > a) "Congratulations" on the 3.5.8 release b) excellent solution - to up the release number! c) Thanks!! > > //arry/ > > > _______________________________________________ > Python-Dev mailing list -- python-dev at python.org > To unsubscribe send an email to python-dev-leave at python.org > https://mail.python.org/mailman3/lists/python-dev.python.org/ > Message archived at https://mail.python.org/archives/list/python-dev at python.org/message/OYNQS2BZYABXACBRHBHV4RCEPQU5R6EP/ > Code of Conduct: http://python.org/psf/codeofconduct/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From drsalists at gmail.com Thu Oct 31 12:59:23 2019 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 31 Oct 2019 09:59:23 -0700 Subject: Artifact repository? Message-ID: Hi folks. Can anyone please recommend an opensource "Artifact Repository" suitable for use with CPython, including dozens of wheels, tar.gz's and .py's? By an Artifact Repository, I mean something that can version largish binaries that are mostly produced by a build process. It doesn't necessarily have to be written in Python, but it does need to cooperate with Python well. I'm thinking of something like Artifactory or Archiva or similar - but I have zero experience with these tools, so a recommendation would be really helpful. Thanks! From marko at pacujo.net Thu Oct 31 13:24:10 2019 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 31 Oct 2019 19:24:10 +0200 Subject: Artifact repository? References: Message-ID: <874kzoygjp.fsf@elektro.pacujo.net> Dan Stromberg : > Can anyone please recommend an opensource "Artifact Repository" suitable > for use with CPython, including dozens of wheels, tar.gz's and .py's? > > By an Artifact Repository, I mean something that can version largish > binaries that are mostly produced by a build process. > > It doesn't necessarily have to be written in Python, but it does need to > cooperate with Python well. > > I'm thinking of something like Artifactory or Archiva or similar - but I > have zero experience with these tools, so a recommendation would be really > helpful. This question doesn't seem to have much to do with Python. Anyway, at work, we use an in-house component system (written using Python) that uses Artifactory as an artifact store. The system works well. Artifactory's role in the system is to just be a "dumb disk" with a REST API. It supports a nice feature that you can allow developers to read and write *but not delete* from it. Marko From ferzans97 at gmail.com Thu Oct 31 14:46:23 2019 From: ferzans97 at gmail.com (ferzan saglam) Date: Thu, 31 Oct 2019 11:46:23 -0700 (PDT) Subject: Calculations and Variables Message-ID: The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 44.44. bill = (input("Enter the total cost of the meal: \n")) tip = (input("Enter how much the tip is: \n")) split = (input("Enter how many people there are: \n")) total = bill + (bill / tip) eachPay = total / split print("Each person will have to pay %.2f" % eachPay) I am aiming for the result of 43.6, but somehow get the result of 44.44. (meal cost: 200) (Tip: 9) (people: 5) I seem to do the calculation below, but get different results each time. Total * Percentage Amount / 100 From David.Raymond at tomtom.com Thu Oct 31 15:12:43 2019 From: David.Raymond at tomtom.com (David Raymond) Date: Thu, 31 Oct 2019 19:12:43 +0000 Subject: Calculations and Variables In-Reply-To: References: Message-ID: How are you getting any value at all? You are trying to do math on string values just like in your infinite loop question. This should raise TypeError: unsupported operand type(s) for /: 'str' and 'str' Also, tips are usually given as percentages. Here with a tip value of 9 you're saying that the tip is 1/9 th of the bill, which is where the number difference is coming from. If someone entered 50 this is saying the tip is 1/50 th of the bill, etc. -----Original Message----- From: Python-list On Behalf Of ferzan saglam Sent: Thursday, October 31, 2019 2:46 PM To: python-list at python.org Subject: Calculations and Variables The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 44.44. bill = (input("Enter the total cost of the meal: \n")) tip = (input("Enter how much the tip is: \n")) split = (input("Enter how many people there are: \n")) total = bill + (bill / tip) eachPay = total / split print("Each person will have to pay %.2f" % eachPay) I am aiming for the result of 43.6, but somehow get the result of 44.44. (meal cost: 200) (Tip: 9) (people: 5) I seem to do the calculation below, but get different results each time. Total * Percentage Amount / 100 -- https://mail.python.org/mailman/listinfo/python-list From gherron at digipen.edu Thu Oct 31 15:08:19 2019 From: gherron at digipen.edu (Gary Herron) Date: Thu, 31 Oct 2019 12:08:19 -0700 Subject: Calculations and Variables In-Reply-To: References: Message-ID: On 10/31/19 11:46 AM, ferzans97 at gmail.com wrote: > The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 44.44. > > > bill = (input("Enter the total cost of the meal: \n")) > tip = (input("Enter how much the tip is: \n")) > split = (input("Enter how many people there are: \n")) > total = bill + (bill / tip) Don't you mean ?total = bill + (bill * tip) ? > > eachPay = total / split > print("Each person will have to pay %.2f" % eachPay) > > > > I am aiming for the result of 43.6, but somehow get the result of 44.44. > (meal cost: 200) (Tip: 9) (people: 5) > > I seem to do the calculation below, but get different results each time. > Total * Percentage Amount / 100 -- Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology (425) 895-4418 From python at mrabarnett.plus.com Thu Oct 31 16:14:16 2019 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 31 Oct 2019 20:14:16 +0000 Subject: Calculations and Variables In-Reply-To: References: Message-ID: <41a661ca-49f6-b5cb-4df2-719c4610dc77@mrabarnett.plus.com> On 2019-10-31 18:46, ferzan saglam wrote: > The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 44.44. > > > bill = (input("Enter the total cost of the meal: \n")) > tip = (input("Enter how much the tip is: \n")) > split = (input("Enter how many people there are: \n")) Why are there parentheses around the inputs? Have you omitted the conversion to numbers? > total = bill + (bill / tip) That adds a 1/9 of the bill. It should add 9% of the bill. > eachPay = total / split > print("Each person will have to pay %.2f" % eachPay) > > > > I am aiming for the result of 43.6, but somehow get the result of 44.44. > (meal cost: 200) (Tip: 9) (people: 5) > > I seem to do the calculation below, but get different results each time. > Total * Percentage Amount / 100 > From ferzans97 at gmail.com Thu Oct 31 16:45:29 2019 From: ferzans97 at gmail.com (ferzan saglam) Date: Thu, 31 Oct 2019 13:45:29 -0700 (PDT) Subject: Restaurant Bill Message-ID: <92eac54d-7083-4559-9cd9-6d210528ec95@googlegroups.com> The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 44.44. print('Enter the total cost of the meal') Total_cost= input() print('Enter how much the tip is') Tip= input() print('Enter how many people there are') People= input() Total_cost = (Tip + Total_cost) / People print('Each person will have to pay') print(Total_cost) (Total_cost * 9) / 100 I am aiming for the result of 43.6, but somehow get the result of 41.8. (meal cost: 200) (Tip: 9) (people: 5) I seem to do the calculation below, but get different results each time. Total * Percentage Amount / 100 From ferzans97 at gmail.com Thu Oct 31 16:50:53 2019 From: ferzans97 at gmail.com (ferzan saglam) Date: Thu, 31 Oct 2019 13:50:53 -0700 (PDT) Subject: Restaurant Bill Message-ID: <4f9782ab-43b5-4d48-9263-2a7d9bcc13e6@googlegroups.com> The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 41.8. print('Enter the total cost of the meal') Total_cost= input() print('Enter how much the tip is') Tip= input() print('Enter how many people there are') People= input() Total_cost = (Tip + Total_cost) / People print('Each person will have to pay') print(Total_cost) Total_cost = (Total_cost * 9) / 100 I am aiming for the result of 41.8, but somehow get the result of 44.44. (meal cost: 200) (Tip: 9) (people: 5) (Equation: Total * Percentage Amount / 100) I seem to be implementing the correct equation, but instead of 43.6, I am getting the result of 41.8?. From rosuav at gmail.com Thu Oct 31 16:59:11 2019 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Nov 2019 07:59:11 +1100 Subject: Restaurant Bill In-Reply-To: <92eac54d-7083-4559-9cd9-6d210528ec95@googlegroups.com> References: <92eac54d-7083-4559-9cd9-6d210528ec95@googlegroups.com> Message-ID: On Fri, Nov 1, 2019 at 7:51 AM ferzan saglam wrote: > > The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 44.44. > You're posting multiple threads with the same question and different code. Are you reading the responses people give you? Are you learning from them? ChrisA From ferzans97 at gmail.com Thu Oct 31 16:55:41 2019 From: ferzans97 at gmail.com (ferzan saglam) Date: Thu, 31 Oct 2019 13:55:41 -0700 (PDT) Subject: Restaurant Bill Message-ID: The code below which I have written should print the result of 43.6 with the given values I have included at the end of this question, but for some odd reason I get the result of 41.8. print('Enter the total cost of the meal') Total_cost= input() print('Enter how much the tip is') Tip= input() print('Enter how many people there are') People= input() Total_cost = (Tip + Total_cost) / People print('Each person will have to pay') print(Total_cost) Total_cost = (Total_cost * 9) / 100 I am aiming for the result of 43.6, but somehow get the result of 41.8. (meal cost: 200) (Tip: 9) (people: 5) (Total * Percentage Amount / 100) I seem to be implementing the correct equation, but instead of obtaining the result of 43.6, I get the result of 41.8. From martin.schoon at gmail.com Thu Oct 31 17:08:55 2019 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 31 Oct 2019 21:08:55 GMT Subject: Jupyter Notebook -> PDF with A4 pages? References: Message-ID: Den 2019-10-16 skrev Piet van Oostrum : > Martin Sch??n writes: > >> Den 2019-10-15 skrev Piet van Oostrum : >>> >> pip is version 8.1.1 which is what Ubuntu 16.04 comes >> with. I have learnt -- the hard way -- that pip should be >> used with the --user option. Does this mean I am stuck with >> pip version 8.1.1? I mean, pip install --user pip seams like >> cheating... > > Why should that not work? > I have been too busy to look into this but today I did and found that pip install --user pip broke pip. I have not been able to repair pip but then I only had some ten minutes to spend on it. /Martin From * at eli.users.panix.com Thu Oct 31 17:13:07 2019 From: * at eli.users.panix.com (Eli the Bearded) Date: Thu, 31 Oct 2019 21:13:07 +0000 (UTC) Subject: Artifact repository? References: <87r22saeeq.fsf@nightsong.com> Message-ID: In comp.lang.python, Paul Rubin wrote: > Dan Stromberg writes: >> By an Artifact Repository, I mean something that can version largish >> binaries that are mostly produced by a build process. > I'm not familiar with the term "artifact repository" and hadn't heard of > the ones you mentioned, but have you looked at git-annex ? Git-annex solves a different problem. Use git-annex for the problem of "revision control with git for binary files not suitable for normal git storage". Use Artifactory for the problem of "store the binary product of source code at a particular revision point". They are kinda related, but: git doesn't magically know that when you update foo.c that lib/libfoo.a linked into bin/projectfoo are now obsolete. Artifactory, doesn't either, but it doesn't slide files forward to new revisions the way git would unless you specifically replace or delete them. After you `make` your code, you can `make archive` (or whatever) to copy the compiled results to your artifact repository and your deploy code elsewhere can look to the artifact repository to get "latest" or a specific revision. git-annex is good for things like images used in a project that you do want to automatically persist into the next revision. Say if you have screenshots in your documentation and want the next `make pdfs` to have access to them. Or if you have a blog in source code control. Elijah ------ the cheapest artifact repository is a webserver with zips / tars From eryksun at gmail.com Thu Oct 31 18:24:44 2019 From: eryksun at gmail.com (Eryk Sun) Date: Thu, 31 Oct 2019 17:24:44 -0500 Subject: return a ctypes object to C In-Reply-To: <3a846468-b53a-eb1b-17ec-587cc8115ce0@sphaero.org> References: <3a846468-b53a-eb1b-17ec-587cc8115ce0@sphaero.org> Message-ID: On 10/30/19, Arnaud Loonstra wrote: > > I have a binding to access and create the C methods and structures so in > Python I can call the Zmsg() constructor. I now need to return this. > > My python test method is simply: > > def actor_test( *args, **kwargs): > print("test") > msg = Zmsg() > frame = Zframe(b"Hello", 5) > msg.prepend(frame) > return msg > > the method is called from C as follows: > > PyObject *pReturn = PyObject_CallObject(pFunc, NULL); > > This correctly calls the method. However the returned object is of > course a PyObject*. The debugger says it's > > "" PyObject > [class] "" > [super class] "" > [meta type] "" > ob_refcnt 1 Py_ssize_t > > However how I can I get it back to the original C type (zmsg_t *) I don't know what this Zmsg type is. It doesn't appear to be a ctypes type such as a Structure. Either way, I'd wager that it supports the buffer protocol. https://docs.python.org/3/c-api/buffer.html Call PyObject_GetBuffer to get a simple view, and try casting the `buf` pointer to a zmsg_t pointer. From jfong at ms4.hinet.net Thu Oct 31 23:44:25 2019 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Thu, 31 Oct 2019 20:44:25 -0700 (PDT) Subject: What's the difference between running a script under command box and interpreter? Message-ID: <68894b06-edfe-4b10-86f8-ab62005960a1@googlegroups.com> The script test.py is something like this: -------test.py from pyeds import fsm ... ... class Rule_Parse: def __init__(self): ... self.current_char = '' ... ... def main(input_str): for c in input_str: ... rule.current_char = c ... if __name__ == '__main__': input_str = '(NNS(acoustics) & RB(not)) | JJ(muted)' rule = Rule_Parse() main(input_str) ... ----------- The test.py can run correctly under command box: D:\Works\Python\pyeds-master\src>py test.py but fails when running under interpreter: D:\Works\Python\pyeds-master\src>py Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from test import * >>> input_str = "(NNS(acoustics) & RB(not)) | JJ(muted)" >>> rule = Rule_Parse() >>> main(input_str) Traceback (most recent call last): File "", line 1, in File "D:\Works\Python\pyeds-master\src\test.py", line 229, in main rule.current_char = c NameError: name 'rule' is not defined >>> I did check the globals using dir() and the 'rule' is there, no doubt. I also tried "py -m pdb test.py" and step through it, no problem too. Why? --Jach From originallmoney at gmail.com Thu Oct 31 23:47:01 2019 From: originallmoney at gmail.com (originallmoney at gmail.com) Date: Thu, 31 Oct 2019 20:47:01 -0700 (PDT) Subject: Trouble trying to get started with pygame Message-ID: It's been years since I've done anything with Python, and it wasn't a language I was terribly familiar with even then. I'm using Python 3.8 on my Windows 7 laptop. Python itself works so far as I can tell. I can get it to import pip without problems, but, when I try to get going with pygame, I hit a roadblock. I have pygame 1.9.6.tar.gz. Apparently, I don't have the means of unzipping it, yet, I think I've seen things on other forums suggesting that Python can do that for me. Is that true? I've been trying to use "pip install" (Written just like that, minus the quotes, of course), yet, it tells me that's a syntax error. Is there a way of inputting this that I'm not aware of? I've seen various versions of people calling the command, with things like "pip.install" or "-m pip install -U pygame -user" or something like that, are THOSE what I should be trying or...am I completely off-base right now? Any help would be appreciated, as I'm losing patience with it at the moment.