From jonas.thornvall at gmail.com Fri Jun 1 03:16:31 2018 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Fri, 1 Jun 2018 00:16:31 -0700 (PDT) Subject: Output not defined Message-ID: Can any web programmer tell me why output is not defined? I know this is python group but my code is so rudimentary that probably any sufficient good webprogrammer can figure it out, but i am lost."I've tried comp.lang.javascript" Problem is I've looked upon this for a week or two, and i just can't figure out why output is not defined. My hangup is probably because it works without problem when i run it in under windows XP browser, and that make me confused."I started program it in XP but now i want to transition into more modern browsers, Linux and windows 10" https://3d16zci4vuzyxt8hxvovrg-on.drv.tw/Website/midi.html Any help or even suggestion would be greatly appreciated. From greg.ewing at canterbury.ac.nz Fri Jun 1 03:54:14 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 01 Jun 2018 19:54:14 +1200 Subject: Problem with OrderedDict - progress report In-Reply-To: References: Message-ID: Chris Angelico wrote: > It is an error to mutate the dictionary *and then continue to iterate over it*. But if you're processing the last key, and you add one so that it's no longer the last key, what should happen? My feeling is that this should be an error, because it's not clear whether iteration should stop at that point or not. -- Greg From rosuav at gmail.com Fri Jun 1 04:01:25 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Jun 2018 18:01:25 +1000 Subject: Problem with OrderedDict - progress report In-Reply-To: References: Message-ID: On Fri, Jun 1, 2018 at 5:54 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> It is an error to mutate the dictionary *and then continue to iterate over >> it*. > > > But if you're processing the last key, and you add one so > that it's no longer the last key, what should happen? > > My feeling is that this should be an error, because it's > not clear whether iteration should stop at that point > or not. > Right, but if you 'break' immediately after a mutation, that isn't continuing to iterate. Even though you're inside the loop, there's no further action taken to process the loop, and no problem. If it so happens that mutating the last one and then continuing the loop doesn't cause a problem, it's because you got lucky, not because the language guarantees it. ChrisA From songofacandy at gmail.com Fri Jun 1 04:02:46 2018 From: songofacandy at gmail.com (INADA Naoki) Date: Fri, 1 Jun 2018 17:02:46 +0900 Subject: Problem with OrderedDict - progress report In-Reply-To: References: Message-ID: On Fri, Jun 1, 2018 at 4:56 PM Gregory Ewing wrote: > Chris Angelico wrote: > > It is an error to mutate the dictionary *and then continue to iterate > over it*. > > But if you're processing the last key, and you add one so > that it's no longer the last key, what should happen? > > My feeling is that this should be an error, because it's > not clear whether iteration should stop at that point > or not. > > -- > Greg > -- > https://mail.python.org/mailman/listinfo/python-list > ?Regardless how CPython works, it's prohibited, and behavior is **undefined**.? There are no "what should happen". Python interpreters may or may not raise error. And any error (RuntimeError, MemoryError, interpreter freeze) may happen. Python programmer shouldn't rely on the behavior. ?Regards,? -- INADA Naoki From greg.ewing at canterbury.ac.nz Fri Jun 1 04:02:49 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 01 Jun 2018 20:02:49 +1200 Subject: Indented multi-line strings In-Reply-To: References: <9bf0783c8b044b348769942bda950043@F5.com> <20180523162535.xbtqnxi7yqv4ijlg@hjp.at> <20180529091919.xxr7rt5yoplwdge6@hjp.at> <20180530224733.6qai7jsw4bknkukr@hjp.at> <48620ae1be64499abf9baf065273e4c3@F5.com> <20180531210535.pbgtlwtgsbk6fh3c@hjp.at> Message-ID: Here's my take on what an indented multi-line string syntax should look like. string foo: | This is a multi-line indented string declaration. | Note that it's a statement, not an expression. In | this example, each line of the final string starts | with two spaces. -- Greg From frank at chagford.com Fri Jun 1 04:04:30 2018 From: frank at chagford.com (Frank Millman) Date: Fri, 1 Jun 2018 10:04:30 +0200 Subject: Problem with OrderedDict - progress report In-Reply-To: References: Message-ID: "Gregory Ewing" wrote in message news:fnccd8Ff3s1U1 at mid.individual.net... > > Chris Angelico wrote: > > It is an error to mutate the dictionary *and then continue to iterate > > over it*. > > But if you're processing the last key, and you add one so > that it's no longer the last key, what should happen? > > My feeling is that this should be an error, because it's > not clear whether iteration should stop at that point > or not. > I agree. A normal dictionary raises an exception. I think that an OrderedDict should do so as well. In fact this was the reason for my intermittent error. I was adding a key while iterating, which was an error. But if I happened to be on the last key at the time, it did not raise an exception. If I was on a previous key, it did raise an exception. Frank From steve+comp.lang.python at pearwood.info Fri Jun 1 07:22:04 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 1 Jun 2018 11:22:04 +0000 (UTC) Subject: Problem with OrderedDict - progress report References: Message-ID: On Thu, 31 May 2018 16:37:39 +0200, Frank Millman wrote: [...] > Agreed, but my gut feel, and the following example, suggest that when > processing the last key in a dictionary while iterating over it, you > have not yet stopped iterating. > >>>> d = {} >>>> d[1] = 'one' >>>> d[2] = 'two' Before Python 3.7, regular dicts are unordered. Just because you add 2 last, doesn't mean that 2 is the last item. The position of each item is unpredictable, and 2 could end up in the first position. In this example: >>>> for k in d: > ... if k == 2: > ... d[3] = 'three' > ... > Traceback (most recent call last): > File "", line 1, in > RuntimeError: dictionary changed size during iteration just because k == 2 does not mean this matches on the last iteration. It could be the first. > OrderedDict seems to behave differently in this regard - Neither OrderedDict nor dict guarantee to detect all mutations. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From barry at barrys-emacs.org Fri Jun 1 08:15:38 2018 From: barry at barrys-emacs.org (Barry Scott) Date: Fri, 01 Jun 2018 13:15:38 +0100 Subject: Why exception from os.path.exists()? In-Reply-To: <87o9gwgepm.fsf@elektro.pacujo.net> References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> Message-ID: <6342113.ZVQNR0knA0@varric.chelsea.private> On Thursday, 31 May 2018 14:03:01 BST Marko Rauhamaa wrote: > Chris Angelico : > > On Thu, May 31, 2018 at 10:03 PM, Marko Rauhamaa wrote: > >> This surprising exception can even be a security issue: > >> >>> os.path.exists("\0") > >> > >> Traceback (most recent call last): > >> File "", line 1, in > >> File "/usr/lib64/python3.6/genericpath.py", line 19, in exists > >> > >> os.stat(path) > >> > >> ValueError: embedded null byte > > > > [...] > > > > A Unix path name cannot contain a null byte, so what you have is a > > fundamentally invalid name. ValueError is perfectly acceptable. > > At the very least, that should be emphasized in the documentation. The > pathname may come from an external source. It is routine to check for > "/", "." and ".." but most developers (!?) would not think of checking > for "\0". That means few test suites would catch this issue and few > developers would think of catching ValueError here. The end result is > unpredictable. I think the reason for the \0 check is that if the string is passed to the operating system with the \0 you can get surprising results. If \0 was not checked for you would be able to get True from: os.file.exists('/home\0ignore me') This is because a posix system only sees '/home'. Surely ValueError is reasonable? Once you know that all of the string you provided is given to the operating system it can then do whatever checks it sees fit to and return a suitable result. As an aside Windows has lots of special filenames that you have to know about if you are writting robust file handling. AUX, COM1, \this\is\also\COM1 etc. Barry > > > Marko From wafflesouffle at gmail.com Fri Jun 1 08:56:20 2018 From: wafflesouffle at gmail.com (WaffleSouffle) Date: Fri, 1 Jun 2018 05:56:20 -0700 (PDT) Subject: pex console_scripts unavailable Message-ID: <510debee-061d-4e4d-9b28-f611ec94bf6e@googlegroups.com> I'd like to embed console_scripts in a pex file and be able to use them by specifying them when invoking the pex file. The details are... Python module with the following file structure: . ??? mefoo ??? ??? __init__.py ??? ??? bar.py ??? ??? command_line ??? ??? __init__.py ??? ??? cli1.py ??? ??? cli2.py ??? setup.py Stripped down `setup.py` is #!/usr/bin/env python3 import setuptools setuptools.setup( name='mefoo', version='0.0.1', entry_points={ 'console_scripts' : [ 'mefoo1 = mefoo.command_line.cli1:main', 'mefoo2 = mefoo.command_line.cli2:main' ] }, scripts=['scripts/mefooscript1'], packages=setuptools.find_packages() ) Build a wheel with `python3 setup.py sdist bdist_wheel` which outputs to `dist` directory. Install wheel with `pip install --no-index dist/mefoo-0.0.1-py3-none-any.whl` This correctly creates my `console_script` entry point so from command prompt I can call: > mefoo1 Could not open mefoo1 in the environment [./themefoo.pex]: [Errno 2] No such file or directory: 'mefoo1' Then I move on and create a pex file: pex --python=python3 --disable-cache --no-index --find-links=./dist mefoo --output-file themefoo.pex -v This creates a pex file, but attempts to use the `console_script` entry point fails. > ./themefoo.pex mefoo1 *How do I make this work ?* What I can do is specify the `console_script` entry point as an entry point to pex

    pex --python=python3 --disable-cache --no-index --find-links=./dist -c mefoo1 mefoo --output-file themefoo.pex -v
Unzipping the pex file doesn't shows it doesn't contain any extra archived content, so I'm guessing there's some extra config embedded in the file itself which is interpreted appropriately. The [wheel documentation](https://wheel.readthedocs.io/en/stable/) talks about `install-scripts`, but I cannot work out how to use it. The docs mention: > If the scripts are needed, use a real installer like pip. The wheel > tool python -m wheel install-scripts package [package ?] can also be > used at any time to call setuptools to write the appropriate scripts > wrappers. I'm not sure what writing the appropriate script wrappers means. There's some discussion leading to `install-scripts` being implemented [here](https://github.com/pypa/pip/issues/1067), and I had a look at the code but couldn't work out whether this addresses my problem. From wafflesouffle at gmail.com Fri Jun 1 08:58:31 2018 From: wafflesouffle at gmail.com (WaffleSouffle) Date: Fri, 1 Jun 2018 05:58:31 -0700 (PDT) Subject: pex console_scripts unavailable Message-ID: <7ba7e3e6-b375-4bc4-b756-50831a9ea305@googlegroups.com> Python module with the following file structure: . ??? mefoo ??? ??? __init__.py ??? ??? bar.py ??? ??? command_line ??? ??? __init__.py ??? ??? cli1.py ??? ??? cli2.py ??? setup.py Stripped down `setup.py` is #!/usr/bin/env python3 import setuptools setuptools.setup( name='mefoo', version='0.0.1', entry_points={ 'console_scripts' : [ 'mefoo1 = mefoo.command_line.cli1:main', 'mefoo2 = mefoo.command_line.cli2:main' ] }, scripts=['scripts/mefooscript1'], packages=setuptools.find_packages() ) Build a wheel with `python3 setup.py sdist bdist_wheel` which outputs to `dist` directory. Install wheel with `pip install --no-index dist/mefoo-0.0.1-py3-none-any.whl` This correctly creates my `console_script` entry point so from command prompt I can call: > mefoo1 Then I move on and create a pex file: pex --python=python3 --disable-cache --no-index --find-links=./dist mefoo --output-file themefoo.pex -v This creates a pex file, but attempts to use the `console_script` entry point fails. > ./themefoo.pex mefoo1 Could not open mefoo1 in the environment [./themefoo.pex]: [Errno 2] No such file or directory: 'mefoo1' *How do I make this work ?* What I can do is specify the `console_script` entry point as an entry point to pex

    pex --python=python3 --disable-cache --no-index --find-links=./dist -c mefoo1 mefoo --output-file themefoo.pex -v
Unzipping the pex file doesn't shows it doesn't contain any extra archived content, so I'm guessing there's some extra config embedded in the file itself which is interpreted appropriately. The [wheel documentation](https://wheel.readthedocs.io/en/stable/) talks about `install-scripts`, but I cannot work out how to use it. The docs mention: > If the scripts are needed, use a real installer like pip. The wheel > tool python -m wheel install-scripts package [package ?] can also be > used at any time to call setuptools to write the appropriate scripts > wrappers. I'm not sure what writing the appropriate script wrappers means. There's some discussion leading to `install-scripts` being implemented [here](https://github.com/pypa/pip/issues/1067), and I had a look at the code but couldn't work out whether this addresses my problem. From p.f.moore at gmail.com Fri Jun 1 09:23:42 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 1 Jun 2018 14:23:42 +0100 Subject: Why exception from os.path.exists()? In-Reply-To: <6342113.ZVQNR0knA0@varric.chelsea.private> References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: On 1 June 2018 at 13:15, Barry Scott wrote: > I think the reason for the \0 check is that if the string is passed to the > operating system with the \0 you can get surprising results. > > If \0 was not checked for you would be able to get True from: > > os.file.exists('/home\0ignore me') > > This is because a posix system only sees '/home'. So because the OS API can't handle filenames with \0 in (because that API uses null-terminated strings) Python has to special case its handling of the check. That's fine. > Surely ValueError is reasonable? Well, if the OS API can't handle filenames with embedded \0, we can be sure that such a file doesn't exist - so returning False is reasonable. > Once you know that all of the string you provided is given to the operating > system it can then do whatever checks it sees fit to and return a suitable > result. As the programmer, I don't care. The Python interpreter should take care of that for me, and if I say "does file 'a\0b' exist?" I want an answer. And I don't see how anything other than "no it doesn't" is correct. Python allows strings with embedded \0 characters, so it's possible to express that question in Python - os.path.exists('a\0b'). What can be expressed in terms of the low-level (C-based) operating system API shouldn't be relevant. Disclaimer - the Python "os" module *does* expose low-level OS-dependent functionality, so it's not necessarily reasonable to extend this argument to other functions in os. But it seems like a pretty solid argument in this particular case. > As an aside Windows has lots of special filenames that you have to know about > if you are writting robust file handling. AUX, COM1, \this\is\also\COM1 etc. I don't think that's relevant in this context. Paul From bruceg113355 at gmail.com Fri Jun 1 09:28:45 2018 From: bruceg113355 at gmail.com (bruceg113355 at gmail.com) Date: Fri, 1 Jun 2018 06:28:45 -0700 (PDT) Subject: How do I list only the methods I define in a class? In-Reply-To: References: <36e40db6-c962-4f92-80ae-ecd41b02007c@googlegroups.com> Message-ID: <888e689e-b6f9-46e9-9ab6-ed86107617b2@googlegroups.com> On Thursday, May 31, 2018 at 10:18:53 PM UTC-4, bob gailer wrote: > On 5/31/2018 3:49 PM, bruceg113355 at gmail.com wrote: > > How do I list only the methods I define in a class? > Here's a class with some method, defined in various ways: > > >>> class x(): > ...???? a=3 > ...???? def f():pass > ...???? g = lambda: None > ... > > >>> l=[v for v in x.__dict__.items()]; print(l) > [('a', 3), ('f', ), ('__module__', > '__main__'), ('__dict__', ), > ('__doc__', None), ('__weakref__', objects>)] > > >>> import inspect > >>> [(key, value) for key, value in l if inspect.isfunction(i[1])] > [('f', ), ('g', > at 0x000001DEDD693620>)] > > HTH After more researching, I found the below code that works for me. https://stackoverflow.com/questions/1911281/how-do-i-get-list-of-methods-in-a-python-class from types import FunctionType class Foo: def bar(self): pass def baz(self): pass def methods(cls): return [x for x, y in cls.__dict__.items() if type(y) == FunctionType] Using the above code, I now get the following. ['__init__', 'apples', 'peaches', 'pumpkin'] Bruce From marko at pacujo.net Fri Jun 1 09:38:01 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 01 Jun 2018 16:38:01 +0300 Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: <87d0xahbk6.fsf@elektro.pacujo.net> Paul Moore : > On 1 June 2018 at 13:15, Barry Scott wrote: >> Once you know that all of the string you provided is given to the >> operating system it can then do whatever checks it sees fit to and >> return a suitable result. > > As the programmer, I don't care. The Python interpreter should take > care of that for me, and if I say "does file 'a\0b' exist?" I want an > answer. And I don't see how anything other than "no it doesn't" is > correct. Python allows strings with embedded \0 characters, so it's > possible to express that question in Python - os.path.exists('a\0b'). > What can be expressed in terms of the low-level (C-based) operating > system API shouldn't be relevant. Interestingly, you get a False even for existing files if you don't have permissions to access the file. Arguably, that answer is misleading, and an exception would be justified. But since os.path.exists() returns a False even in that situation, it definitely should return False for a string containing a NUL character. Marko From Richard at Damon-Family.org Fri Jun 1 09:41:04 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 1 Jun 2018 09:41:04 -0400 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: <3bce65d7-e21d-1521-6fea-67ecb79f4a89@Damon-Family.org> On 5/31/18 1:43 PM, Grant Edwards wrote: > On 2018-05-31, Paul Moore wrote: >> On 31 May 2018 at 15:01, Chris Angelico wrote: >> >> Honestly, I think the OP's point is correct. os.path.exists should >> simply return False if the filename has an embedded \0 - at least on >> Unix. > Except on the platform in quetion filenames _don't_ contain an > embedded \0. What was passed was _not_ a path/filename. > > You might as well have passed a floating point number or a dict. > > I think this is a key point. os.path.exists needs to pass a null terminated string to the system to ask it about the file. The question comes what should we do if we pass it a value that can't (or we won't) represent as such a string. The confusion is that in python, a string with an embedded null is something pretty much like a string without an embedded null, so the programmer might not think of it as being the wrong type. Thus we have several options. 1) we can treat os.path.exists('foo\0bar') the same as os.path.exists(1.5) and raise the exception. 2) we can treat os.path.exists('foo\0bar') as specifying a file that can never exists and bypass the system call are return false. 3) we can process os.path.exists('foo\0bar') by just passing the string to the system call, making it the same as os.path.exists('foo') The last is probably the one that we can say is likely wrong, but arguments could be made for either of the first two. -- Richard Damon From rosuav at gmail.com Fri Jun 1 09:58:58 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Jun 2018 23:58:58 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: <3bce65d7-e21d-1521-6fea-67ecb79f4a89@Damon-Family.org> References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> <3bce65d7-e21d-1521-6fea-67ecb79f4a89@Damon-Family.org> Message-ID: On Fri, Jun 1, 2018 at 11:41 PM, Richard Damon wrote: > The confusion is that in python, a string with an embedded null is > something pretty much like a string without an embedded null, so the > programmer might not think of it as being the wrong type. Thus we have > several options. > > 1) we can treat os.path.exists('foo\0bar') the same as > os.path.exists(1.5) and raise the exception. 1.5 raises TypeError, which is correct. But the type of "foo\0bar" is str, which is a perfectly valid type. ValueError is more correct here. And that's what currently happens. Possibly more confusing, though, is this: >>> os.path.exists(1) True >>> os.path.exists(2) True >>> os.path.exists(3) False I think it's testing that the file descriptors exist, because os.path.exists is defined in terms of os.stat, which can stat a path or an FD. So os.path.exists(fd) is True if that fd is open, and False if it isn't. But os.path.exists is not documented as accepting FDs. Accident of implementation or undocumented feature? Or maybe accidental feature? > 2) we can treat os.path.exists('foo\0bar') as specifying a file that can > never exists and bypass the system call are return false. That's what's being proposed. > 3) we can process os.path.exists('foo\0bar') by just passing the string > to the system call, making it the same as os.path.exists('foo') > > The last is probably the one that we can say is likely wrong, but > arguments could be made for either of the first two. More than "likely wrong"; it's definitely wrong, and deceptively so. I don't think anyone would support this case. ChrisA From marko at pacujo.net Fri Jun 1 10:18:21 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 01 Jun 2018 17:18:21 +0300 Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> <3bce65d7-e21d-1521-6fea-67ecb79f4a89@Damon-Family.org> Message-ID: <876032h9oy.fsf@elektro.pacujo.net> Chris Angelico : > Possibly more confusing, though, is this: > >>>> os.path.exists(1) > True >>>> os.path.exists(2) > True >>>> os.path.exists(3) > False > > I think it's testing that the file descriptors exist, because > os.path.exists is defined in terms of os.stat, which can stat a path > or an FD. So os.path.exists(fd) is True if that fd is open, and False > if it isn't. But os.path.exists is not documented as accepting FDs. > Accident of implementation or undocumented feature? Or maybe > accidental feature? What's more: >>> os.path.exists(-100) False >>> os.path.exists(-1000000000000) Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python3.6/genericpath.py", line 19, in exists os.stat(path) OverflowError: fd is less than minimum One could argue -100 is less than minimum... The common denominator is that "\0" and -1000000000000 are caught by Python's standard library while "" and -100 are caught by the OS. Marko From D.Strohl at F5.com Fri Jun 1 10:36:15 2018 From: D.Strohl at F5.com (Dan Strohl) Date: Fri, 1 Jun 2018 14:36:15 +0000 Subject: Indented multi-line strings In-Reply-To: <20180531211610.mafcf6kjfadog777@hjp.at> References: <9bf0783c8b044b348769942bda950043@F5.com> <20180523162535.xbtqnxi7yqv4ijlg@hjp.at> <20180529091919.xxr7rt5yoplwdge6@hjp.at> <20180530224733.6qai7jsw4bknkukr@hjp.at> <48620ae1be64499abf9baf065273e4c3@F5.com> <889761ba-616e-7825-bbbe-a026e2853820@mrabarnett.plus.com> <20180531211610.mafcf6kjfadog777@hjp.at> Message-ID: > > I would prefer to remove the padding, like this: > > Test = """ > | Hello, this is a > | Multiline indented > |String > """.outdent(padding='|') > > Or write it like this? > > Test = """| Hello, this is a > | Multiline indented > |String > """.outdent(padding='|') > > Hmm, the sign of Zorro! :-) > > I'm starting to like outdent(), but that may be my TIMTOWTDIism speaking. > I can see both outdent(padding="|") and outdent(size=4) being useful in various cases. If this ends up being the recommendation, I would also suggest adding str.indent(), it evens out the methods and most of the time I use the textwrap functions it is either indent or outdent, so this would clean up those pieces. So... how does one go about suggesting changes to the built in types? I could take a whack at the code for it, but my C skills are no where near what should probably be needed for something this close to the core of the language. I'm not sure if adding a couple of methods is a PEP type of thing. Dan Strohl From grant.b.edwards at gmail.com Fri Jun 1 10:38:56 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 1 Jun 2018 14:38:56 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: On 2018-06-01, Paul Moore wrote: > Python allows strings with embedded \0 characters, so it's possible > to express that question in Python - os.path.exists('a\0b'). What > can be expressed in terms of the low-level (C-based) operating > system API shouldn't be relevant. Python allows floating point numbers, so it is possible to express this question in python: os.path.exists(3.14159). Is the fact that the underlying OS/filesystem can't identify files via a floating point number relevent? Should it return False or raise ValueError? -- Grant Edwards grant.b.edwards Yow! How do I get HOME? at gmail.com From p.f.moore at gmail.com Fri Jun 1 10:57:58 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 1 Jun 2018 15:57:58 +0100 Subject: Indented multi-line strings In-Reply-To: References: <9bf0783c8b044b348769942bda950043@F5.com> <20180523162535.xbtqnxi7yqv4ijlg@hjp.at> <20180529091919.xxr7rt5yoplwdge6@hjp.at> <20180530224733.6qai7jsw4bknkukr@hjp.at> <48620ae1be64499abf9baf065273e4c3@F5.com> <889761ba-616e-7825-bbbe-a026e2853820@mrabarnett.plus.com> <20180531211610.mafcf6kjfadog777@hjp.at> Message-ID: On 1 June 2018 at 15:36, Dan Strohl via Python-list wrote: > So... how does one go about suggesting changes to the built in types? I could take a whack at the code for it, but my C skills are no where near what should probably be needed for something this close to the core of the language. I'm not sure if adding a couple of methods is a PEP type of thing. It would probably have to go via python-ideas, but if it gets the OK there I doubt it would need a PEP. There are a few key questions I'd expect to see come up. Why does this need to be a string method? Why can't it be a standalone function? Maybe you should publish an implementation on PyPI, collect some data on how popular it is, and then if it's widely used, propose it for inclusion in the stdlib at that point? By making it a string method, you're also restricting its use to users of recent versions of Python, whereas a PyPI implementation would work for everyone. None of these are showstoppers - many proposals have got past them - but it's worth having at least thought through your answers to them, so you can present the idea in the best light. Paul From mike.junk.46 at att.net Fri Jun 1 11:02:27 2018 From: mike.junk.46 at att.net (Mike McClain) Date: Fri, 1 Jun 2018 08:02:27 -0700 Subject: version In-Reply-To: <20180601024435.GA32258@playground> References: <20180601024435.GA32258@playground> Message-ID: <20180601150227.GA20853@playground> On Thu, May 31, 2018 at 07:44:35PM -0700, Mike McClain wrote: > Is there a way in a script to know which version of python is being > run so I can write: > If (version == 2.7): > do it this way > elsif (version == 3.2): > do it another way > Thanks for the responses, Mike -- The depression won't end till we grow a generation that knows how to live on what they got. - Will Rogers From p.f.moore at gmail.com Fri Jun 1 11:02:58 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 1 Jun 2018 16:02:58 +0100 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: On 1 June 2018 at 15:38, Grant Edwards wrote: > On 2018-06-01, Paul Moore wrote: > >> Python allows strings with embedded \0 characters, so it's possible >> to express that question in Python - os.path.exists('a\0b'). What >> can be expressed in terms of the low-level (C-based) operating >> system API shouldn't be relevant. > > Python allows floating point numbers, so it is possible to express > this question in python: os.path.exists(3.14159). Is the fact that > the underlying OS/filesystem can't identify files via a floating point > number relevent? Should it return False or raise ValueError? I'm not sure if you're asking a serious question here, or trying to make some sort of point, but os.path.exists is documented as taking a string, so passing a float should be a TypeError. And it is. But as I already said, this is a huge amount of effort spent on a pretty trivial corner case, so I'll duck out of this thread now. Paul From mike.junk.46 at att.net Fri Jun 1 11:04:53 2018 From: mike.junk.46 at att.net (Mike McClain) Date: Fri, 1 Jun 2018 08:04:53 -0700 Subject: ... (ellipsis) In-Reply-To: References: <20180601022648.GA32039@playground> Message-ID: <20180601150453.GB20853@playground> On Thu, May 31, 2018 at 11:00:13PM -0400, Terry Reedy wrote: > On 5/31/2018 10:26 PM, Mike McClain wrote: > > I'm having understanding the use if the ellipsis. > >I keep reading that it is used in slices > > By numpy for numpy multidimensional arrays, which have their own > __getitem__, which recognizes and gives meaning to ... > Thank you Mr. Reedy I've not yet looked at numpy but no doubt will get there. Mike -- The depression won't end till we grow a generation that knows how to live on what they got. - Will Rogers From D.Strohl at F5.com Fri Jun 1 11:20:19 2018 From: D.Strohl at F5.com (Dan Strohl) Date: Fri, 1 Jun 2018 15:20:19 +0000 Subject: Indented multi-line strings In-Reply-To: References: <9bf0783c8b044b348769942bda950043@F5.com> <20180523162535.xbtqnxi7yqv4ijlg@hjp.at> <20180529091919.xxr7rt5yoplwdge6@hjp.at> <20180530224733.6qai7jsw4bknkukr@hjp.at> <48620ae1be64499abf9baf065273e4c3@F5.com> <889761ba-616e-7825-bbbe-a026e2853820@mrabarnett.plus.com> <20180531211610.mafcf6kjfadog777@hjp.at> Message-ID: <45c0dfb1017642c8aa22f99eea5dc473@F5.com> > > It would probably have to go via python-ideas, but if it gets the OK there I > doubt it would need a PEP. > Cool, thanks! > There are a few key questions I'd expect to see come up. > > Why does this need to be a string method? Why can't it be a standalone > function? Maybe you should publish an implementation on PyPI, collect some > data on how popular it is, and then if it's widely used, propose it for inclusion > in the stdlib at that point? By making it a string method, you're also restricting > its use to users of recent versions of Python, whereas a PyPI implementation > would work for everyone. Good point, so, basically, there already is a function for this built in textwrap.dedent() and textwrap.indent(), I would think (hope) that that would answer that question. From rosuav at gmail.com Fri Jun 1 11:36:56 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 01:36:56 +1000 Subject: Indented multi-line strings In-Reply-To: References: <9bf0783c8b044b348769942bda950043@F5.com> <20180523162535.xbtqnxi7yqv4ijlg@hjp.at> <20180529091919.xxr7rt5yoplwdge6@hjp.at> <20180530224733.6qai7jsw4bknkukr@hjp.at> <48620ae1be64499abf9baf065273e4c3@F5.com> <889761ba-616e-7825-bbbe-a026e2853820@mrabarnett.plus.com> <20180531211610.mafcf6kjfadog777@hjp.at> Message-ID: On Sat, Jun 2, 2018 at 12:57 AM, Paul Moore wrote: > On 1 June 2018 at 15:36, Dan Strohl via Python-list > wrote: >> So... how does one go about suggesting changes to the built in types? I could take a whack at the code for it, but my C skills are no where near what should probably be needed for something this close to the core of the language. I'm not sure if adding a couple of methods is a PEP type of thing. > > It would probably have to go via python-ideas, but if it gets the OK > there I doubt it would need a PEP. Yeah, take it to -ideas but don't worry about a PEP. > There are a few key questions I'd expect to see come up. > > Why does this need to be a string method? Why can't it be a standalone > function? Maybe you should publish an implementation on PyPI, collect > some data on how popular it is, and then if it's widely used, propose > it for inclusion in the stdlib at that point? By making it a string > method, you're also restricting its use to users of recent versions of > Python, whereas a PyPI implementation would work for everyone. The biggest reason to make it a string method is to give the possibility of optimization. Python cannot optimize int(1.2) down to the constant 1 because you might have shadowed int; but a method on a string literal cannot be shadowed, and could potentially be constant-folded. Include that in the initial post to preempt this recommendation. ChrisA From Richard at Damon-Family.org Fri Jun 1 11:58:42 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 1 Jun 2018 11:58:42 -0400 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> <3bce65d7-e21d-1521-6fea-67ecb79f4a89@Damon-Family.org> Message-ID: <0cf8d61b-067a-4419-bceb-88ab06649941@Damon-Family.org> On 6/1/18 9:58 AM, Chris Angelico wrote: > On Fri, Jun 1, 2018 at 11:41 PM, Richard Damon wrote: >> The confusion is that in python, a string with an embedded null is >> something pretty much like a string without an embedded null, so the >> programmer might not think of it as being the wrong type. Thus we have >> several options. >> >> 1) we can treat os.path.exists('foo\0bar') the same as >> os.path.exists(1.5) and raise the exception. > 1.5 raises TypeError, which is correct. But the type of "foo\0bar" is > str, which is a perfectly valid type. ValueError is more correct here. > And that's what currently happens. > > Possibly more confusing, though, is this: > >>>> os.path.exists(1) > True >>>> os.path.exists(2) > True >>>> os.path.exists(3) > False > > I think it's testing that the file descriptors exist, because > os.path.exists is defined in terms of os.stat, which can stat a path > or an FD. So os.path.exists(fd) is True if that fd is open, and False > if it isn't. But os.path.exists is not documented as accepting FDs. > Accident of implementation or undocumented feature? Or maybe > accidental feature? > >> 2) we can treat os.path.exists('foo\0bar') as specifying a file that can >> never exists and bypass the system call are return false. > That's what's being proposed. > >> 3) we can process os.path.exists('foo\0bar') by just passing the string >> to the system call, making it the same as os.path.exists('foo') >> >> The last is probably the one that we can say is likely wrong, but >> arguments could be made for either of the first two. > More than "likely wrong"; it's definitely wrong, and deceptively so. I > don't think anyone would support this case. > > ChrisA I would say that one way to look at it is that os.path.exists fundamentally (at the OS level) expects a parameter of the 'type' of either a nul terminated string or a file descriptor (aka fixed width integer). One issue we have is that these 'types' don't directly map to Python types. We can basically make a call to os.path.exists with 4 different types of parameter: 1) The parameter has a totally wrong type of type that just doesn't map to one of the expected type. This gives a TypeError exeception. 2) The parameter has a Python type that maps to right OS 'type' but has a value that prevents us from properly converting it to a corresponding value of that type. This could be a integral value out of range for the fixed width type used, or a string which contains an embedded nul. Currently these generate an OverflowError for out of range integer and a ValueError for a bad string 3) The parameter can be mapped to the proper type but the value is somehow illegal (the number fits the type, but isn't legal for a file descriptor, or a string has a value that can't represent a real file). In this case, os.path.exists doesn't try to validate the parameter but just passes it along and returns a value based on the answer it gets. 4) The parameter represents a legal value of a right type, so as above we pass the value and get back the answer. The fundamental question is about case 2. Should os.path.exist, having been give a value of the right 'Python Type' but not matching the type of the operating system parameter identify this as an error (as it currently does), or should it be changed to decide that if it could somehow get that parameter to the os, then it would say that the file doesn't exist, and so return false. I would say that if you accept that, should we also say that if we pass a totally wrong type, why shouldn't we again return false instead of a TypeError, after all, if we pass it a dictionary, they certainly is no file like that in existence, The real question comes which method is more useful, which is most apt to be the one we want, and which one is the better building block for a program. One thing to note as an advantage for the current method, it is trivial with the current decision to write a mypathexists that would accept strings with nuls embedded and return false, just call os.path.exists inside a try, and catch the ValueError and return false. You could also extend it to catch OverflowError and/or TypeError. On the other hand, if os.path.exists swallows these errors and just returns false, then it is a lot more work to make a wrapper that throws the errors, you basically would need to precheck for bad values and throw, and then if you move to a system that happened to allow nuls in the file name (and the python code knew that), your wrapper code now is wrong as you had to build in implementation knowledge into the user code. -- Richard Damon From p.f.moore at gmail.com Fri Jun 1 12:10:34 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 1 Jun 2018 17:10:34 +0100 Subject: Indented multi-line strings In-Reply-To: References: <9bf0783c8b044b348769942bda950043@F5.com> <20180523162535.xbtqnxi7yqv4ijlg@hjp.at> <20180529091919.xxr7rt5yoplwdge6@hjp.at> <20180530224733.6qai7jsw4bknkukr@hjp.at> <48620ae1be64499abf9baf065273e4c3@F5.com> <889761ba-616e-7825-bbbe-a026e2853820@mrabarnett.plus.com> <20180531211610.mafcf6kjfadog777@hjp.at> Message-ID: On 1 June 2018 at 16:36, Chris Angelico wrote: > On Sat, Jun 2, 2018 at 12:57 AM, Paul Moore wrote: >> Why does this need to be a string method? Why can't it be a standalone >> function? Maybe you should publish an implementation on PyPI, collect >> some data on how popular it is, and then if it's widely used, propose >> it for inclusion in the stdlib at that point? By making it a string >> method, you're also restricting its use to users of recent versions of >> Python, whereas a PyPI implementation would work for everyone. > > The biggest reason to make it a string method is to give the > possibility of optimization. Python cannot optimize int(1.2) down to > the constant 1 because you might have shadowed int; but a method on a > string literal cannot be shadowed, and could potentially be > constant-folded. Include that in the initial post to preempt this > recommendation. So the optimisation should probably be an explicit part of the proposal. Without the optimisation, factors like "won't be usable in code that wants to support older Python", "why not just make it a standalone function", etc. will probably result in the proposal not getting accepted. On 1 June 2018 at 16:20, Dan Strohl wrote: > > Good point, so, basically, there already is a function for this built in textwrap.dedent() and textwrap.indent(), I would think (hope) that that would answer that question. OK, so unless the argument is "provide a string method, that's guaranteed to be constant folded"[1] I suspect that it's pretty unlikely that a proposal to add a string method that simply replicated the textwrap functions would get very far. But regardless, there's no point in me trying to second guess what might come up on python-ideas, you should just post there and see what reception you get. Paul [1] There's two possibilities here, of course. First, provide an implementation for CPython that includes the constant folding, or second, make constant folding a language guarantee that other implementations also have to implement. I doubt the second option is going to be practical, though. From rosuav at gmail.com Fri Jun 1 13:34:54 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 03:34:54 +1000 Subject: Indented multi-line strings In-Reply-To: References: <9bf0783c8b044b348769942bda950043@F5.com> <20180523162535.xbtqnxi7yqv4ijlg@hjp.at> <20180529091919.xxr7rt5yoplwdge6@hjp.at> <20180530224733.6qai7jsw4bknkukr@hjp.at> <48620ae1be64499abf9baf065273e4c3@F5.com> <889761ba-616e-7825-bbbe-a026e2853820@mrabarnett.plus.com> <20180531211610.mafcf6kjfadog777@hjp.at> Message-ID: On Sat, Jun 2, 2018 at 2:10 AM, Paul Moore wrote: > On 1 June 2018 at 16:36, Chris Angelico wrote: >> On Sat, Jun 2, 2018 at 12:57 AM, Paul Moore wrote: > >>> Why does this need to be a string method? Why can't it be a standalone >>> function? Maybe you should publish an implementation on PyPI, collect >>> some data on how popular it is, and then if it's widely used, propose >>> it for inclusion in the stdlib at that point? By making it a string >>> method, you're also restricting its use to users of recent versions of >>> Python, whereas a PyPI implementation would work for everyone. >> >> The biggest reason to make it a string method is to give the >> possibility of optimization. Python cannot optimize int(1.2) down to >> the constant 1 because you might have shadowed int; but a method on a >> string literal cannot be shadowed, and could potentially be >> constant-folded. Include that in the initial post to preempt this >> recommendation. > > So the optimisation should probably be an explicit part of the > proposal. Without the optimisation, factors like "won't be usable in > code that wants to support older Python", "why not just make it a > standalone function", etc. will probably result in the proposal not > getting accepted. There's already an existing function, albeit not the most discoverable. But people avoid it because it's a run-time cost, and deleting the leading spaces in the source code eliminates that run-time cost. > OK, so unless the argument is "provide a string method, that's > guaranteed to be constant folded"[1] I suspect that it's pretty > unlikely that a proposal to add a string method that simply replicated > the textwrap functions would get very far. > > [1] There's two possibilities here, of course. First, provide an > implementation for CPython that includes the constant folding, or > second, make constant folding a language guarantee that other > implementations also have to implement. I doubt the second option is > going to be practical, though. I wouldn't make it an actual guarantee. As long as CPython has the optimization, people will start using it; if Jython or MicroPython or Brython does a run-time method call, so be it. It's still likely to be faster than importing a module, but most importantly, people's code will look better this way than manually unindented. ChrisA From pkpearson at nowhere.invalid Fri Jun 1 17:00:13 2018 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 1 Jun 2018 21:00:13 GMT Subject: Indented multi-line strings References: <9bf0783c8b044b348769942bda950043@F5.com> <20180523162535.xbtqnxi7yqv4ijlg@hjp.at> <20180529091919.xxr7rt5yoplwdge6@hjp.at> <20180530224733.6qai7jsw4bknkukr@hjp.at> <48620ae1be64499abf9baf065273e4c3@F5.com> <889761ba-616e-7825-bbbe-a026e2853820@mrabarnett.plus.com> <20180531211610.mafcf6kjfadog777@hjp.at> Message-ID: On Fri, 1 Jun 2018 15:57:58 +0100, Paul Moore wrote: > On 1 June 2018 at 15:36, Dan Strohl via Python-list > wrote: >> So... how does one go about suggesting changes to the built in types? [snip] > > Why does this need to be a string method? Why can't it be a standalone > function? Yes, please, let's content ourselves with a standalone function. Adding features to a language imposes costs in several ways, including hindering newcomers and making code version-dependent. To full-time Python developers, these costs appear small, because they are amortized over a lot of Python activity; but they are encumbrances to the spread and casual use of the language. It seems as if the destiny of every language is to be adorned by its enthusiasts with so many arcane and specialized optimizations -- every one an obvious improvement -- that the world's interest drifts to something newer and cleaner. From hjp-python at hjp.at Fri Jun 1 17:03:19 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 1 Jun 2018 23:03:19 +0200 Subject: Attachments? Re: Indented multi-line strings (was: "Data blocks" syntax specification draft) In-Reply-To: References: Message-ID: <20180601210319.kx556ly4dxpr7dzk@hjp.at> On 2018-05-31 14:42:39 -0700, Paul wrote: > I have heard that attachments to messages are not allowed on this list, > which makes sense. However I notice that messages from Peter do have an > attachment, i.e., a signature.asc file. No this is isn't an attachment. It's a signature. Your MUA probably displays everything it can't handle as an "attachment". > > I'm just curious; why and how do those particular attachments get through? > And should they get through, I guess? E.G., what if I attach a malicious > file labeled as .asc? The mailinglist software can probably distinguish between multipart/signed and multipart/mixed. 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 rosuav at gmail.com Fri Jun 1 17:57:43 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 07:57:43 +1000 Subject: Indented multi-line strings In-Reply-To: References: <9bf0783c8b044b348769942bda950043@F5.com> <20180523162535.xbtqnxi7yqv4ijlg@hjp.at> <20180529091919.xxr7rt5yoplwdge6@hjp.at> <20180530224733.6qai7jsw4bknkukr@hjp.at> <48620ae1be64499abf9baf065273e4c3@F5.com> <889761ba-616e-7825-bbbe-a026e2853820@mrabarnett.plus.com> <20180531211610.mafcf6kjfadog777@hjp.at> Message-ID: On Sat, Jun 2, 2018 at 7:00 AM, Peter Pearson wrote: > On Fri, 1 Jun 2018 15:57:58 +0100, Paul Moore wrote: >> On 1 June 2018 at 15:36, Dan Strohl via Python-list >> wrote: >>> So... how does one go about suggesting changes to the built in types? > [snip] >> >> Why does this need to be a string method? Why can't it be a standalone >> function? > > Yes, please, let's content ourselves with a standalone function. > > Adding features to a language imposes costs in several ways, including > hindering newcomers and making code version-dependent. To full-time > Python developers, these costs appear small, because they are amortized > over a lot of Python activity; but they are encumbrances to the spread > and casual use of the language. It seems as if the destiny of every > language is to be adorned by its enthusiasts with so many arcane and > specialized optimizations -- every one an obvious improvement -- that > the world's interest drifts to something newer and cleaner. How will a method be worse than a standalone function? Please explain this. A method is a lot easier to discover than a stdlib module function, which is in turn IMMENSELY more discoverable than anything on pypi. If you dislike adding features to a language on the basis that it makes the language harder to learn, remember that you instead force one of three even worse options: 1) Messy code because people unindent inside their source code, creating wonky indentation (which Python usually avoids) 2) Forcing readers to look up the third-party module you're using before they can understand your code 3) Forcing readers to look up your ad-hoc function before understanding your code. All of these make it harder to understand your code, specifically BECAUSE the language doesn't have the requisite feature. Well-written language features are good, not bad, for readability. ChrisA From rosuav at gmail.com Fri Jun 1 17:59:07 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 07:59:07 +1000 Subject: Attachments? Re: Indented multi-line strings (was: "Data blocks" syntax specification draft) In-Reply-To: <20180601210319.kx556ly4dxpr7dzk@hjp.at> References: <20180601210319.kx556ly4dxpr7dzk@hjp.at> Message-ID: On Sat, Jun 2, 2018 at 7:03 AM, Peter J. Holzer wrote: > On 2018-05-31 14:42:39 -0700, Paul wrote: >> I have heard that attachments to messages are not allowed on this list, >> which makes sense. However I notice that messages from Peter do have an >> attachment, i.e., a signature.asc file. > > No this is isn't an attachment. It's a signature. Your MUA probably > displays everything it can't handle as an "attachment". Which, I might point out, is a decent way to handle unknown parts. The user is shown that there's an extra part, and can view it as an external file. ChrisA From steve+comp.lang.python at pearwood.info Fri Jun 1 18:10:38 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 1 Jun 2018 22:10:38 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> <3bce65d7-e21d-1521-6fea-67ecb79f4a89@Damon-Family.org> Message-ID: On Fri, 01 Jun 2018 09:41:04 -0400, Richard Damon wrote: > I think this is a key point. os.path.exists needs to pass a null > terminated string to the system to ask it about the file. That's an implementation detail utterly irrelevant to Python programmers. If the OS expects a pointer to a block of UTF-16 bytes, would you say "oh well, since Python doesn't have low level pointers, we simply can't provide this functionality?" No of course we would not. os.path.exists should take a regular Python string and adapt it to whatever the implementation requires. > The question > comes what should we do if we pass it a value that can't (or we won't) > represent as such a string. You get a TypeError: py> os.path.exists([]) Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.5/genericpath.py", line 19, in exists os.stat(path) TypeError: argument should be string, bytes or integer, not list > The confusion is that in python, a string with an embedded null is > something pretty much like a string without an embedded null, so the > programmer might not think of it as being the wrong type. But it *isn't* the wrong type. It is the same type: py> type("abc") is type("a\0c") True So TypeError is out, since the type is right, only the value is wrong. But ValueError is wrong too: What does os.path.exists return when given "the wrong value" (i.e. a string that doesn't match an existing path)? It returns False, not raise an exception. > Thus we have several options. Only one of which is consistent with the rest of os.path.exist()'s behaviour, only one of which is sensible. Return False, like every other pathname that doesn't exist. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Fri Jun 1 18:50:38 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 08:50:38 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> <3bce65d7-e21d-1521-6fea-67ecb79f4a89@Damon-Family.org> Message-ID: On Sat, Jun 2, 2018 at 8:10 AM, Steven D'Aprano wrote: > But it *isn't* the wrong type. It is the same type: > > > py> type("abc") is type("a\0c") > True > > > So TypeError is out, since the type is right, only the value is wrong. I agree with you so far. This parallels the fact that math.asin(5) doesn't raise TypeError, since an integer is perfectly valid input to the arcsine function. > But ValueError is wrong too: > > What does os.path.exists return when given "the wrong value" (i.e. a > string that doesn't match an existing path)? It returns False, not raise > an exception. Hang on, how is "a string that doesn't match an existing path" the wrong value? The point is to ask if a path exists. A path that doesn't exist is still valid. There are four possibilities: 1) You're asking a question that doesn't even make sense, like os.path.exists(Ellipsis) 2) You're asking about a path that exists and you can prove that it does. Return True. 3) You're asking about a path that doesn't exist and you can prove that it doesn't. Return False. 4) You're asking about a path that you can't be sure about - maybe there's a permissions error. With perms errors, it's less clear what's the right thing to do. I think letting an OSError bubble up would be appropriate here, but others may disagree. Similarly if you try to access a network mount that is currently disconnected, a device that has crashed, etc. Returning False (as in the current implementation) is plausible; I don't think it's the ideal, but since it would break backward compatibility to change it now, I'm not advocating making that change. The real question is whether os.path.exists("a\0c") is more akin to os.path.exists(Ellipsis) or to os.path.exists("/mnt/broken/spam"). It is never going to be valid to ask whether Ellipsis exists, and it is never going to be valid to ask whether a\0c exists. The broken mount might potentially become valid, and the same path name could change in meaning if you are chrooted, so it is a sane question to ask. My ideal preference would be for True to mean "we know for certain that this exists" and False "we know for certain that this doesn't exist" (which might be because one of its parent components doesn't exist - if /spam doesn't exist, then /spam/ham doesn't either, and that's just straight False). Everything else should raise an exception. That said, though, I'm not hugely fussed and don't have actual use-cases here, beyond the back-of-the-mind feeling that saying "no that doesn't exist" is deceptively confident about something that isn't actually certain. ChrisA From greg.ewing at canterbury.ac.nz Fri Jun 1 19:09:05 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 02 Jun 2018 11:09:05 +1200 Subject: Why exception from os.path.exists()? In-Reply-To: <87d0xahbk6.fsf@elektro.pacujo.net> References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <87d0xahbk6.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > Interestingly, you get a False even for existing files if you don't have > permissions to access the file. Obviously in that case, instead of True or False it should return FileNotFound. :-) https://thedailywtf.com/articles/What_Is_Truth_0x3f_ -- Greg From greg.ewing at canterbury.ac.nz Fri Jun 1 19:10:52 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 02 Jun 2018 11:10:52 +1200 Subject: Problem with OrderedDict - progress report In-Reply-To: References: Message-ID: Chris Angelico wrote: > if you 'break' immediately after a mutation, that isn't > continuing to iterate. Even though you're inside the loop, there's no > further action taken to process the loop, and no problem. Yes, but you're also not calling next() again, so no exception would be triggered. My point is that I don't see a justification for treating the last next() call (the one that notices you've reached the end and raises StopIteration) any differently from the others. It seems like either a bug or a misfeature to me. -- Greg From steve+comp.lang.python at pearwood.info Fri Jun 1 19:16:32 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 1 Jun 2018 23:16:32 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: On Fri, 01 Jun 2018 14:38:56 +0000, Grant Edwards wrote: > On 2018-06-01, Paul Moore wrote: > >> Python allows strings with embedded \0 characters, so it's possible to >> express that question in Python - os.path.exists('a\0b'). What can be >> expressed in terms of the low-level (C-based) operating system API >> shouldn't be relevant. > > Python allows floating point numbers, so it is possible to express this > question in python: os.path.exists(3.14159). Is the fact that the > underlying OS/filesystem can't identify files via a floating point > number relevent? Should it return False or raise ValueError? Certainly not a ValueError, that would be silly. The fact that it is an illegal value is subordinate to the fact that it is the wrong type. It should either return False, or raise TypeError. Of the two, since 3.14159 cannot represent a file on any known OS, TypeError would be more appropriate. But since "\0" is the correct type (a string), and the fact that it happens to be illegal on POSIX is a platform-dependent detail of no more importance than the fact that "?" is illegal on Windows, it should be treated as any other platform-dependent illegal file and return False. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Fri Jun 1 19:37:04 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 1 Jun 2018 23:37:04 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On Thu, 31 May 2018 17:43:28 +0000, Grant Edwards wrote: > Except on the platform in quetion filenames _don't_ contain an embedded > \0. What was passed was _not_ a path/filename. "/wibble/rubbish/nobodyexpectsthespanishinquistion" is not a pathname on my system either, and os.path.exists() returns False for that. As it is supposed to. I'd be willing to bet that: import secrets # Python 3.6+ s = "/" + secrets.token_hex(1024) + "/spam" is not a pathname on any computer in the world. (If it is even legal.) And yet os.path.exists(s) returns False. The maximum number of file components under POSIX is (I believe) 256. And yet: py> os.path.exists("/a"*1000000) False "/a" by one million cannot possibly be a path under POSIX. > the thread will continue for months and generate hundreds of followup. Only because some people insist on exercising their right to be wrong. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From greg.ewing at canterbury.ac.nz Fri Jun 1 19:37:27 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 02 Jun 2018 11:37:27 +1200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: Grant Edwards wrote: > Python allows floating point numbers, so it is possible to express > this question in python: os.path.exists(3.14159). Is the fact that > the underlying OS/filesystem can't identify files via a floating point > number relevent? Should it return False or raise ValueError? I don't know about that, but it's clear that os.path.exists(1j) shoud raise OnlyInYourDreamsError. -- Greg From eryksun at gmail.com Fri Jun 1 19:45:57 2018 From: eryksun at gmail.com (eryk sun) Date: Fri, 1 Jun 2018 23:45:57 +0000 Subject: Why exception from os.path.exists()? In-Reply-To: <0cf8d61b-067a-4419-bceb-88ab06649941@Damon-Family.org> References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> <3bce65d7-e21d-1521-6fea-67ecb79f4a89@Damon-Family.org> <0cf8d61b-067a-4419-bceb-88ab06649941@Damon-Family.org> Message-ID: On Fri, Jun 1, 2018 at 3:58 PM, Richard Damon wrote: > > The fundamental question is about case 2. Should os.path.exist, having > been give a value of the right 'Python Type' but not matching the type > of the operating system parameter identify this as an error (as it > currently does), or should it be changed to decide that if it could > somehow get that parameter to the os, then it would say that the file > doesn't exist, and so return false. AFAIK, this behavior hasn't been documented. So it can either be documented, and thus never allow NUL in paths, or else every call that currently raises ValueError for this case should raise a pretend FileNotFoundError. No change to exists(), isdir(), and isfile() would be required. For Windows, there's another case that's in more of a grey area. Python 3.6+ uses UTF-8 as the file-system encoding in Windows. Internally it transcodes between UTF-8 and the native UTF-16 encoding. The "surrogatepass" error handler is used in order to faithfully handle invalid surrogates, which the system allows. This leaves no simple way to smuggle invalid UTF-8 sequences into the filename and rountrip back to bytes, so UnicodeDecodeError (a subclass of ValueError) is raised. The same invalid UTF-8 would pass silently in POSIX, which uses bytes paths and the "surrogateescape" handler. Trivia: The native NT API of Windows can use device names that contain NUL characters because it uses counted strings in the OBJECT_ATTRIBUTES record that's used to access named objects (e.g. Device, Section, Job, Event, Semaphore, etc). I've tested that this works. A file system could also allow NUL in names, but Microsoft's drivers reserve NUL as an invalid character, as would any driver that uses the file-system runtime library. That said, native NT applications have a limited scope, so it's almost pointless to speculate. From steve+comp.lang.python at pearwood.info Fri Jun 1 19:48:44 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 1 Jun 2018 23:48:44 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> <3bce65d7-e21d-1521-6fea-67ecb79f4a89@Damon-Family.org> <0cf8d61b-067a-4419-bceb-88ab06649941@Damon-Family.org> Message-ID: On Fri, 01 Jun 2018 11:58:42 -0400, Richard Damon wrote: > I would say that one way to look at it is that os.path.exists > fundamentally (at the OS level) expects a parameter of the 'type' of > either a nul terminated string or a file descriptor (aka fixed width > integer). One issue we have is that these 'types' don't directly map to > Python types. What a strange and unhelpful way to look at it. When calling os.path.exists() from Python, are you interacting directly with the OS in low-level C or assembly, or using a high-level language like Python? That's not a rhetorical question. I would like to know what you think we are doing when we type into the Python interpreter import os os.path.exists("pathname") Well actually no I lie. Of course its a rhetorical question: I'm sure you know full well that you're using Python, a high-level language. > We can basically make a call to os.path.exists with 4 different types of > parameter: > > 1) The parameter has a totally wrong type of type that just doesn't map > to one of the expected type. This gives a TypeError exeception. > > 2) The parameter has a Python type that maps to right OS 'type' but has > a value that prevents us from properly converting it to a corresponding > value of that type. This could be a integral value out of range for the > fixed width type used, That is a reasonable case for either ValueError or OverflowError, OverflowError being a more specific (and therefore useful) exception to raise. Being a low-level detail, file descriptors are inherently limited to a fixed width and it truly is an error to supply something outside of that width. > or a string which contains an embedded nul. The fact that this is illegal under POSIX is an irrelevant platform- dependent detail. Irrelevant in the sense that it shouldn't change the API of the function. "<" doesn't raise ValueError on Windows, and "" doesn't raise ValueError on any platform. Why should POSIX nulls be treated as special? > Currently these generate an OverflowError for out of range integer and a > ValueError for a bad string Incorrect: as Paul and MRAB (and myself) have pointed out, bad strings return False, with the surprising exception of null-embedded strings under POSIX. Illegal strings like "<" on Windows return False. Excessive long strings, or strings with too many path components, return False. The empty string returns False. There is no good reason to raise ValueError on strings with null in them. > 3) The parameter can be mapped to the proper type but the value is > somehow illegal (the number fits the type, but isn't legal for a file > descriptor, or a string has a value that can't represent a real file). > In this case, os.path.exists doesn't try to validate the parameter but > just passes it along and returns a value based on the answer it gets. Right. And if the answer it gets is "illegal value", it returns False. > 4) The parameter represents a legal value of a right type, so as above > we pass the value and get back the answer. > > The fundamental question is about case 2. Should os.path.exist, having > been give a value of the right 'Python Type' but not matching the type > of the operating system parameter identify this as an error (as it > currently does), That's wrong, that is not what it does, except in the surprising case of nulls under POSIX. > or should it be changed to decide that if it could > somehow get that parameter to the os, then it would say that the file > doesn't exist, and so return false. Of course. > I would say that if you accept that, > should we also say that if we pass a totally wrong type, why shouldn't > we again return false instead of a TypeError, after all, if we pass it a > dictionary, they certainly is no file like that in existence, Because os.path.exists is documented as accepting strings, bytes and ints, and everything else is a TypeError. If you want to make a case for relaxing the type restrictions on os.path.exists, go right ahead, but I won't be supporting you. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Fri Jun 1 19:54:06 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 1 Jun 2018 23:54:06 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> <3bce65d7-e21d-1521-6fea-67ecb79f4a89@Damon-Family.org> Message-ID: On Sat, 02 Jun 2018 08:50:38 +1000, Chris Angelico wrote: > My ideal preference would be for True to mean "we know for certain that > this exists" and False "we know for certain that this doesn't exist" We cannot make that promise, because we might not have permission to view the file. Since we don't have a three-state True/False/Maybe flag, os.path.exists() just returns False. > (which might be because one of its parent components doesn't exist - if > /spam doesn't exist, then /spam/ham doesn't either, and that's just > straight False). And if the path is an illegal value, it also straight doesn't exist. Like the empty string, like "<" on Windows, like strings with too many path components. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Fri Jun 1 19:56:58 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 09:56:58 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On Sat, Jun 2, 2018 at 9:37 AM, Steven D'Aprano wrote: > On Thu, 31 May 2018 17:43:28 +0000, Grant Edwards wrote: > >> Except on the platform in quetion filenames _don't_ contain an embedded >> \0. What was passed was _not_ a path/filename. > > "/wibble/rubbish/nobodyexpectsthespanishinquistion" is not a pathname on > my system either, and os.path.exists() returns False for that. As it is > supposed to. > > I'd be willing to bet that: > > import secrets # Python 3.6+ > s = "/" + secrets.token_hex(1024) + "/spam" > > is not a pathname on any computer in the world. (If it is even legal.) > And yet os.path.exists(s) returns False. With both of these, the path cannot exist because its first component does not exist. Absent a /wibble on your system, the entire long path is unable to exist. That is a natural consequence of the hierarchical structure of file systems. I'm fairly sure 2KB of path is valid on all major OSes today, which means that it's exactly the same as /wibble - the first component doesn't exist, ergo the path doesn't exist. > The maximum number of file components under POSIX is (I believe) 256. And > yet: > > py> os.path.exists("/a"*1000000) > False > > "/a" by one million cannot possibly be a path under POSIX. I can't actually find that listed anywhere. Citation needed. But assuming you're right, POSIX is still a set of minimum requirements - not maximums, to my knowledge. If some operating system permits longer paths with more components, it won't be non-compliant on that basis. So it's still plausible to ask "does this path exist", and it's perfectly correct to look at the first "/a/" and check if there's anything named "a" in your root directory, and return False upon finding none. The question is sane, unlike os.path.exists([]). ChrisA From rosuav at gmail.com Fri Jun 1 20:05:15 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 10:05:15 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> <3bce65d7-e21d-1521-6fea-67ecb79f4a89@Damon-Family.org> Message-ID: On Sat, Jun 2, 2018 at 9:54 AM, Steven D'Aprano wrote: > On Sat, 02 Jun 2018 08:50:38 +1000, Chris Angelico wrote: > >> My ideal preference would be for True to mean "we know for certain that >> this exists" and False "we know for certain that this doesn't exist" > > We cannot make that promise, because we might not have permission to view > the file. Since we don't have a three-state True/False/Maybe flag, > os.path.exists() just returns False. Being unable to view the file is insignificant, but presumably you mean we might not have permission to view the containing directory. And we do get that information: >>> os.stat("/root/.bashrc") Traceback (most recent call last): File "", line 1, in PermissionError: [Errno 13] Permission denied: '/root/.bashrc' >>> os.stat("/var/.bashrc") Traceback (most recent call last): File "", line 1, in FileNotFoundError: [Errno 2] No such file or directory: '/var/.bashrc' The permissions error is reported differently by stat, but then exists() just says "oh that's an OS error so we're going to say it doesn't exist". If you truly want the reliable form of os.path.exists, it would be this: try: os.stat(path) return True except FileNotFoundError: return False Anything that ISN'T "this file exists" or "this file doesn't exist" will be signalled with an exception. ChrisA From steve+comp.lang.python at pearwood.info Fri Jun 1 20:14:43 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 2 Jun 2018 00:14:43 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On Sat, 02 Jun 2018 09:56:58 +1000, Chris Angelico wrote: > On Sat, Jun 2, 2018 at 9:37 AM, Steven D'Aprano > wrote: >> On Thu, 31 May 2018 17:43:28 +0000, Grant Edwards wrote: >> >>> Except on the platform in quetion filenames _don't_ contain an >>> embedded \0. What was passed was _not_ a path/filename. >> >> "/wibble/rubbish/nobodyexpectsthespanishinquistion" is not a pathname >> on my system either, and os.path.exists() returns False for that. As it >> is supposed to. >> >> I'd be willing to bet that: >> >> import secrets # Python 3.6+ >> s = "/" + secrets.token_hex(1024) + "/spam" >> >> is not a pathname on any computer in the world. (If it is even legal.) >> And yet os.path.exists(s) returns False. > > With both of these, the path cannot exist because its first component > does not exist. Since /wibble doesn't exist, neither does /wibble/a\0b py> os.path.exists("/wibble") False py> os.path.exists("/wibble/a\0b") Traceback (most recent call last): File "", line 1, in File "/storage/torrents/torrents/python/Python-3.6.4/Lib/ genericpath.py", line 19, in exists os.stat(path) ValueError: embedded null byte Oops. > Absent a /wibble on your system, the entire long path is > unable to exist. That is a natural consequence of the hierarchical > structure of file systems. I'm fairly sure 2KB of path is valid on all > major OSes today, But probably not 2K in a single path component. But that's not really my point: I was responding to Grant, who claimed that \0 is not a pathname (or filename) and therefore ValueError is the correct response. But there are lots of things which aren't pathnames, or even which *cannot be* pathnames, and yet they return False. What makes \0 so special? > which means that it's exactly the same as /wibble - > the first component doesn't exist, ergo the path doesn't exist. > >> The maximum number of file components under POSIX is (I believe) 256. >> And yet: >> >> py> os.path.exists("/a"*1000000) >> False >> >> "/a" by one million cannot possibly be a path under POSIX. > > I can't actually find that listed anywhere. Citation needed. https://eklitzke.org/path-max-is-tricky > But > assuming you're right, POSIX is still a set of minimum requirements - > not maximums, to my knowledge. It isn't even a set of minimum requirements. "<" is legal under POSIX, but not Windows. > If some operating system permits longer > paths with more components, it won't be non-compliant on that basis. So > it's still plausible to ask "does this path exist", and it's perfectly > correct to look at the first "/a/" and check if there's anything named > "a" in your root directory, and return False upon finding none. The > question is sane, unlike os.path.exists([]). Correct. Just as it is sane to ask if path "a\0b" exists. If it happens to be illegal on POSIX, just as "<" is illegal under Windows, it is still sane to ask, and you should get False returned. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Fri Jun 1 20:17:20 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 10:17:20 +1000 Subject: Problem with OrderedDict - progress report In-Reply-To: References: Message-ID: On Sat, Jun 2, 2018 at 9:10 AM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> if you 'break' immediately after a mutation, that isn't >> continuing to iterate. Even though you're inside the loop, there's no >> further action taken to process the loop, and no problem. > > > Yes, but you're also not calling next() again, so no > exception would be triggered. > > My point is that I don't see a justification for treating > the last next() call (the one that notices you've reached > the end and raises StopIteration) any differently from > the others. It seems like either a bug or a misfeature > to me. > I'm guessing it's pure chance, and that certain types of mutation would still trigger the exception. A bit of background: These exceptions exist to prevent interpreter crashes. I believe originally you'd only get an exception if the mutation triggered a dictionary resize; in other words, if NOT giving an exception would have actually segfaulted the interpreter right then and there. (I'm talking CPython here, obviously. No idea what other Pythons did at the time.) It's more consistent now; but it looks like you may have come across a residual inconsistency. ISTM it would indeed be more logical to raise for this situation too. ChrisA From rosuav at gmail.com Fri Jun 1 20:32:55 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 10:32:55 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On Sat, Jun 2, 2018 at 10:14 AM, Steven D'Aprano wrote: >> But >> assuming you're right, POSIX is still a set of minimum requirements - >> not maximums, to my knowledge. > > It isn't even a set of minimum requirements. "<" is legal under POSIX, > but not Windows. Windows isn't POSIX compliant. Anyhow, I've come to the conclusion that we're all about equally wrong here, so I'm going to just stop arguing. Anyone who wants the behaviour I described can get it easily enough via os.stat; and if you want ValueError to turn into False, that's also easy enough. ChrisA From eryksun at gmail.com Fri Jun 1 20:48:17 2018 From: eryksun at gmail.com (eryk sun) Date: Sat, 2 Jun 2018 00:48:17 +0000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On Sat, Jun 2, 2018 at 12:14 AM, Steven D'Aprano wrote: > > It isn't even a set of minimum requirements. "<" is legal under POSIX, > but not Windows. "<" (i.e. the DOS_STAR wildcard character) is valid in device and stream names. It's only invalid in filenames, since it's reserved for wildcard matching in file-system calls. For example, in the following we have a device named ':' (note the name contains a forward slash) and a stream named ''. The stream component requires NTFS, ReFS, or CDFS; FAT doesn't support it. Stream names also allow ASCII control characters, except NUL. >>> DefineDosDevice(0, ':', 'C:\\Temp') >>> f = open(r'\\?\:\FILENAME.TXT:', 'w') >>> os.path.exists(r'\\?\:\FILENAME.TXT:') True From mike.junk.46 at att.net Fri Jun 1 21:34:07 2018 From: mike.junk.46 at att.net (Mike McClain) Date: Fri, 1 Jun 2018 18:34:07 -0700 Subject: version In-Reply-To: <20180601150227.GA20853@playground> References: <20180601024435.GA32258@playground> <20180601150227.GA20853@playground> Message-ID: <20180602013407.GA21768@playground> On Fri, Jun 01, 2018 at 08:02:27AM -0700, Mike McClain wrote: > On Thu, May 31, 2018 at 07:44:35PM -0700, Mike McClain wrote: > > > Is there a way in a script to know which version of python is being > > run so I can write: > > If (version == 2.7): > > do it this way > > elsif (version == 3.2): > > do it another way > > > > Thanks for the responses, Those responses were sys.version_info.major and the module 'six'. The first works here: if( sys.version_info.major == 3 ): choice = input(" to continue, or to abort") else: choice = raw_input(" to continue, or to abort") # OK in 2.7 but not here: if( sys.version_info.major == 3 ): print( row, sep=', ') else: print ', '.join(row) # failing in 3.2 Both of the above print statements throw syntax errors, one under 2.7 the other under 3.2. I looked at 'six' and it putting wrappers around calls would mean a rewrite of what is basically just a playground for exploring what python is and certainly not worth the trouble to rewrite much. It looks like what I was wanting is something like 'C's #if, a compiler conditional. Does python have anything like that to tell the interpreter to ignore a line that is not a comment or a quoted string? Thanks, Mike -- The depression won't end till we grow a generation that knows how to live on what they got. - Will Rogers From grant.b.edwards at gmail.com Fri Jun 1 21:51:07 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 2 Jun 2018 01:51:07 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: On 2018-06-01, Steven D'Aprano wrote: > But since "\0" is the correct type (a string), and the fact that it > happens to be illegal on POSIX is a platform-dependent detail of no more > importance than the fact that "?" is illegal on Windows, it should be > treated as any other platform-dependent illegal file and return False. That sounds reasonable. What about the case where somebody calls os.path.exists("/tmp/foo\x00bar") If /tmp/foo exists should it return True? That's what would happen if you passed that string directly to the libc call. -- Grant From grant.b.edwards at gmail.com Fri Jun 1 21:53:11 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 2 Jun 2018 01:53:11 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On 2018-06-01, Steven D'Aprano wrote: > On Thu, 31 May 2018 17:43:28 +0000, Grant Edwards wrote: > >> Except on the platform in quetion filenames _don't_ contain an embedded >> \0. What was passed was _not_ a path/filename. > > "/wibble/rubbish/nobodyexpectsthespanishinquistion" is not a pathname on > my system either, I disagree. On Unix systems that _is_ a path. There may or may not be a file that exists with that path. OTOH "/wibble\x00/whatever" is not a Unix path. -- Grant From rosuav at gmail.com Fri Jun 1 21:54:40 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 11:54:40 +1000 Subject: version In-Reply-To: <20180602013407.GA21768@playground> References: <20180601024435.GA32258@playground> <20180601150227.GA20853@playground> <20180602013407.GA21768@playground> Message-ID: On Sat, Jun 2, 2018 at 11:34 AM, Mike McClain wrote: > On Fri, Jun 01, 2018 at 08:02:27AM -0700, Mike McClain wrote: >> On Thu, May 31, 2018 at 07:44:35PM -0700, Mike McClain wrote: >> >> > Is there a way in a script to know which version of python is being >> > run so I can write: >> > If (version == 2.7): >> > do it this way >> > elsif (version == 3.2): >> > do it another way >> > >> >> Thanks for the responses, > > Those responses were sys.version_info.major and the module 'six'. > The first works here: > if( sys.version_info.major == 3 ): > choice = input(" to continue, or to abort") > else: > choice = raw_input(" to continue, or to abort") # OK in 2.7 Even better: try: input = raw_input except NameError: pass and then just use input() everywhere. > but not here: > if( sys.version_info.major == 3 ): > print( row, sep=', ') > else: > print ', '.join(row) # failing in 3.2 > > Both of the above print statements throw syntax errors, one under 2.7 > the other under 3.2. Even better: from __future__ import print_function and then use the version 3 style everywhere. > I looked at 'six' and it putting wrappers around calls would mean a > rewrite of what is basically just a playground for exploring what > python is and certainly not worth the trouble to rewrite much. > > It looks like what I was wanting is something like 'C's #if, a > compiler conditional. > > Does python have anything like that to tell the interpreter to ignore > a line that is not a comment or a quoted string? No, but for each potential problem where you'd need it, you should have an alternative that works within the current syntax. At least so long as the oldest version you need to support is 2.7, anyway. I would recommend upgrading to an even newer version of Python, incidentally. Python 3.2 is itself extremely old. I'm not sure if there are any Wheezy backports of newer versions of Python, but when I was using Wheezy, I just compiled my own Python 3.x from source; the Debian-provided /usr/bin/python3 isn't touched (and probably isn't used anyway - on Wheezy, system scripts are all using 2.7 IIRC), and you have a new /usr/local/bin/python3 that would be a lot newer. The newer Python versions make cross-version compatibility a LOT easier. ChrisA From drsalists at gmail.com Fri Jun 1 23:59:07 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 1 Jun 2018 20:59:07 -0700 Subject: version In-Reply-To: <20180602013407.GA21768@playground> References: <20180601024435.GA32258@playground> <20180601150227.GA20853@playground> <20180602013407.GA21768@playground> Message-ID: On Fri, Jun 1, 2018 at 6:34 PM, Mike McClain wrote: > On Fri, Jun 01, 2018 at 08:02:27AM -0700, Mike McClain wrote: > > On Thu, May 31, 2018 at 07:44:35PM -0700, Mike McClain wrote: > > > > > Is there a way in a script to know which version of python is being > > > run so I can write: > > > If (version == 2.7): > > > do it this way > > > elsif (version == 3.2): > > > do it another way > > I looked at 'six' and it putting wrappers around calls would mean a > rewrite of what is basically just a playground for exploring what > python is and certainly not worth the trouble to rewrite much. > > It looks like what I was wanting is something like 'C's #if, a > compiler conditional. > > Does python have anything like that to tell the interpreter to ignore > a line that is not a comment or a quoted string? > I've had some luck using m4 for preprocessing Python and Cython from the same .py file. However, it's often better to have 2 different files, as evidenced by some of C's #ifdef'd files that get really complicated and hard to test. You're probably better off using 3.x at this point. BTW, if you just want a simplistic way of doing print's that works on 2.x and 3.x, there are some options: 1) sys.stdout.write(string) 2) print(string) 3) from __future__ import print_function #2 is a bit of a trick/shenanigan that can be useful; it works because for single-argument print's, the print function and the print statement both work with parentheses. You can even: print('abc %s def %s' % ('123', 456)) On both. Two 2.x, that's a parenthesized string passed to the print statement, and to 3.x it's a single-argument print function. HTH From storchaka at gmail.com Sat Jun 2 00:54:21 2018 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sat, 2 Jun 2018 07:54:21 +0300 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> <3bce65d7-e21d-1521-6fea-67ecb79f4a89@Damon-Family.org> Message-ID: 01.06.18 16:58, Chris Angelico ????: > Possibly more confusing, though, is this: > >>>> os.path.exists(1) > True >>>> os.path.exists(2) > True >>>> os.path.exists(3) > False > > I think it's testing that the file descriptors exist, because > os.path.exists is defined in terms of os.stat, which can stat a path > or an FD. So os.path.exists(fd) is True if that fd is open, and False > if it isn't. But os.path.exists is not documented as accepting FDs. > Accident of implementation or undocumented feature? Or maybe > accidental feature? Accident of implementation. In Python 3.3 os.stat() became accepting integer file descriptors (as os.fstat()). os.path.exists() just passes its argument to os.stat(). From storchaka at gmail.com Sat Jun 2 01:04:19 2018 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sat, 2 Jun 2018 08:04:19 +0300 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> <3bce65d7-e21d-1521-6fea-67ecb79f4a89@Damon-Family.org> Message-ID: 02.06.18 03:05, Chris Angelico ????: > The permissions error is reported differently by stat, but then > exists() just says "oh that's an OS error so we're going to say it > doesn't exist". If you truly want the reliable form of os.path.exists, > it would be this: > > try: > os.stat(path) > return True > except FileNotFoundError: > return False > > Anything that ISN'T "this file exists" or "this file doesn't exist" > will be signalled with an exception. And this is how pathlib.Path.exists() was implemented. But for os.path.exists() we are limited by backward compatibility. From hjp-python at hjp.at Sat Jun 2 03:06:44 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 2 Jun 2018 09:06:44 +0200 Subject: Attachments? Re: Indented multi-line strings (was: "Data blocks" syntax specification draft) In-Reply-To: References: <20180601210319.kx556ly4dxpr7dzk@hjp.at> Message-ID: <20180602070644.wb7ekhcuas2q7ajx@hjp.at> On 2018-06-02 07:59:07 +1000, Chris Angelico wrote: > On Sat, Jun 2, 2018 at 7:03 AM, Peter J. Holzer wrote: > > On 2018-05-31 14:42:39 -0700, Paul wrote: > >> I have heard that attachments to messages are not allowed on this list, > >> which makes sense. However I notice that messages from Peter do have an > >> attachment, i.e., a signature.asc file. > > > > No this is isn't an attachment. It's a signature. Your MUA probably > > displays everything it can't handle as an "attachment". > > Which, I might point out, is a decent way to handle unknown parts. The > user is shown that there's an extra part, and can view it as an > external file. Which makes very little sense with a signature. By itself it is useless, it is only useful together with the content part. I consider this very poor UI design. There are only a handful multipart types defined in MIME, each with clear semantics. For multipart/signed, there are basically 2 things you can do if you don't support the signature algorithm: Ignore the signature completely, or display an indication that this part is signed but you can't verify the signature (the latter might also offer a way to pass the entire multipart/signed to an external program). But offering to view/save the signature alone is useless and only confuses the user. (This is especially baffling for programs which already support multipart/signed, but not the specific signature type. What was the developer thinking?) 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 hjp-python at hjp.at Sat Jun 2 03:32:05 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 2 Jun 2018 09:32:05 +0200 Subject: Sorting NaNs Message-ID: <20180602073205.67ihzu52mdan2fqm@hjp.at> Browsing through older messages I came upon a thread discussing the treatment of NaNs by median(). Since you have to (partially) sort the values to compute the median, I played around with sorted(): Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170118] on linux Type "help", "copyright", "credits" or "license" for more information. >>> sorted([3, 5, float('NaN'), 1]) [3, 5, nan, 1] What? Does NaN cause sorted to return the original list? >>> sorted([3, 5, float('NaN'), 1, 0.5]) [3, 5, nan, 0.5, 1] Nope. Does it partition the list into sublists, which are sorted individually? >>> sorted([3, 5, -8, float('NaN'), 1, 0.5]) [-8, 0.5, 1, 3, 5, nan] >>> sorted([3, 5, -8, float('NaN'), 1, 0.5, 33]) [-8, 0.5, 1, 3, 5, nan, 33] Also nope. It looks like NaNs just mess up sorting in an unpredictable way. Is this the intended behaviour or just an accident of implementation? (I think it's the latter: I can see how a sort algorithm which doesn't treat NaN specially would produce such results.) 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 p.f.moore at gmail.com Sat Jun 2 05:10:34 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Sat, 2 Jun 2018 10:10:34 +0100 Subject: Indented multi-line strings In-Reply-To: References: <9bf0783c8b044b348769942bda950043@F5.com> <20180523162535.xbtqnxi7yqv4ijlg@hjp.at> <20180529091919.xxr7rt5yoplwdge6@hjp.at> <20180530224733.6qai7jsw4bknkukr@hjp.at> <48620ae1be64499abf9baf065273e4c3@F5.com> <889761ba-616e-7825-bbbe-a026e2853820@mrabarnett.plus.com> <20180531211610.mafcf6kjfadog777@hjp.at> Message-ID: On 1 June 2018 at 22:57, Chris Angelico wrote: > How will a method be worse than a standalone function? Please explain > this. Because the standalone function already exists (in the textwrap module). There's nothing wrong with adding string methods, but where they don't add anything that can't be done already within the core language and stdlib, then they have to get past the hurdle of "status quo wins". > A method is a lot easier to discover than a stdlib module > function, If you're using Google or the python docs, I'm not sure it is easier, and I'm certain it's not a *lot* easier. If you're using the REPL, then yes, finding a string method is easier than hunting out a random function that takes a string argument. > which is in turn IMMENSELY more discoverable than anything > on pypi. True. But discoverability of anything gets a lot better when it's more widely used, so if this is a common need, I'd hope that discoverability of any approach would improve over time. > If you dislike adding features to a language on the basis that it > makes the language harder to learn, remember that you instead force > one of three even worse options: > > 1) Messy code because people unindent inside their source code, > creating wonky indentation (which Python usually avoids) > > 2) Forcing readers to look up the third-party module you're using > before they can understand your code > > 3) Forcing readers to look up your ad-hoc function before > understanding your code. > > All of these make it harder to understand your code, specifically > BECAUSE the language doesn't have the requisite feature. Well-written > language features are good, not bad, for readability. You missed the option that's actually the case: 0) Expecting readers to look up a stdlib module in order to understand your code. And you aren't comparing like with like, if this were a string method users would have to look up that method, just as much as they would have to look up a stdlib function. But honestly, if someone needs to look up the definition a function or method called "dedent", then either there is something more than normally complex going on, or they are not a native English speaker and this is the least of their worries, or something similar. No-one is saying a method is *worse* than a standalone function - they are just saying it's *not sufficiently better* to justify creating a string method that replicates an existing stdlib function. Paul From p.f.moore at gmail.com Sat Jun 2 05:16:07 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Sat, 2 Jun 2018 10:16:07 +0100 Subject: version In-Reply-To: <20180602013407.GA21768@playground> References: <20180601024435.GA32258@playground> <20180601150227.GA20853@playground> <20180602013407.GA21768@playground> Message-ID: On 2 June 2018 at 02:34, Mike McClain wrote: > It looks like what I was wanting is something like 'C's #if, a > compiler conditional. > > Does python have anything like that to tell the interpreter to ignore > a line that is not a comment or a quoted string? No, it doesn't. Honestly, if you are writing "play" scripts as you say, I wouldn't bother trying to make them cross-version compatible. Move all your old scripts to a "python2" subdirectory and forget them. Write new scripts as Python 3 only. As an exercise in understanding the differences between Python 2 and 3, porting some of the scripts in your "python2" directory to Python 3 would possibly be a useful thing to do. If you have important scripts that you use a lot that are in Python 2 form, continue running them under Python 2 until you have some time (and maybe the understanding, if they are complex) to port them, and then switch. Paul From p.f.moore at gmail.com Sat Jun 2 05:31:37 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Sat, 2 Jun 2018 10:31:37 +0100 Subject: Sorting NaNs In-Reply-To: <20180602073205.67ihzu52mdan2fqm@hjp.at> References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On 2 June 2018 at 08:32, Peter J. Holzer wrote: > Browsing through older messages I came upon a thread discussing the > treatment of NaNs by median(). Since you have to (partially) sort the > values to compute the median, I played around with sorted(): > > Python 3.5.3 (default, Jan 19 2017, 14:11:04) > [GCC 6.3.0 20170118] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>>> sorted([3, 5, float('NaN'), 1]) > [3, 5, nan, 1] > > What? Does NaN cause sorted to return the original list? > >>>> sorted([3, 5, float('NaN'), 1, 0.5]) > [3, 5, nan, 0.5, 1] > > Nope. Does it partition the list into sublists, which are sorted > individually? > >>>> sorted([3, 5, -8, float('NaN'), 1, 0.5]) > [-8, 0.5, 1, 3, 5, nan] >>>> sorted([3, 5, -8, float('NaN'), 1, 0.5, 33]) > [-8, 0.5, 1, 3, 5, nan, 33] > > Also nope. It looks like NaNs just mess up sorting in an unpredictable > way. Is this the intended behaviour or just an accident of > implementation? (I think it's the latter: I can see how a sort algorithm > which doesn't treat NaN specially would produce such results.) I'd simply assume it's the result of two factors: 1. The behaviour of comparisons involving NaN values is weird (not undefined, as far as I know NaN behaviour is very well defined, but violates a number of normally fundamental properties of comparisons) 2. The precise behaviour of the sort algorithm use by Python is not mandated by the language. A consequence of (1) is that there is no meaningful definition of "a sorted list of numbers" if that list includes NaN, as the definition "being sorted" relies on properties like "only one of a < b and b < a is true" (precisely which properties depend on how you define "sorted" which no-one normally cares about because under normal assumptions they are all equivalent). A list including NaNs therefore cannot be permuted into a sorted order (which is the basic language-mandated detail of sorted() - there are others, but this is what matters here). So call it an accident of implementation of you like. Or "sorting a list with NaNs in it is meaningless" if you prefer. Or "undefined behaviour" if you're a fan of the language in the C standard. Paul From rosuav at gmail.com Sat Jun 2 05:42:08 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 19:42:08 +1000 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On Sat, Jun 2, 2018 at 7:31 PM, Paul Moore wrote: > On 2 June 2018 at 08:32, Peter J. Holzer wrote: >> Browsing through older messages I came upon a thread discussing the >> treatment of NaNs by median(). Since you have to (partially) sort the >> values to compute the median, I played around with sorted(): >> >> Python 3.5.3 (default, Jan 19 2017, 14:11:04) >> [GCC 6.3.0 20170118] on linux >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> sorted([3, 5, float('NaN'), 1]) >> [3, 5, nan, 1] >> >> What? Does NaN cause sorted to return the original list? >> >>>>> sorted([3, 5, float('NaN'), 1, 0.5]) >> [3, 5, nan, 0.5, 1] >> >> Nope. Does it partition the list into sublists, which are sorted >> individually? >> >>>>> sorted([3, 5, -8, float('NaN'), 1, 0.5]) >> [-8, 0.5, 1, 3, 5, nan] >>>>> sorted([3, 5, -8, float('NaN'), 1, 0.5, 33]) >> [-8, 0.5, 1, 3, 5, nan, 33] >> >> Also nope. It looks like NaNs just mess up sorting in an unpredictable >> way. Is this the intended behaviour or just an accident of >> implementation? (I think it's the latter: I can see how a sort algorithm >> which doesn't treat NaN specially would produce such results.) > > I'd simply assume it's the result of two factors: > > 1. The behaviour of comparisons involving NaN values is weird (not > undefined, as far as I know NaN behaviour is very well defined, but > violates a number of normally fundamental properties of comparisons) > 2. The precise behaviour of the sort algorithm use by Python is not > mandated by the language. > > A consequence of (1) is that there is no meaningful definition of "a > sorted list of numbers" if that list includes NaN, as the definition > "being sorted" relies on properties like "only one of a < b and b < a > is true" (precisely which properties depend on how you define "sorted" > which no-one normally cares about because under normal assumptions > they are all equivalent). A list including NaNs therefore cannot be > permuted into a sorted order (which is the basic language-mandated > detail of sorted() - there are others, but this is what matters here). > > So call it an accident of implementation of you like. Or "sorting a > list with NaNs in it is meaningless" if you prefer. Or "undefined > behaviour" if you're a fan of the language in the C standard. Sorting a list of uncomparable objects is meaningless (though not undefined). I believe that a list of floats with some NaNs in it should have all the other values sort correctly, with the NaNs doing whatever they feel like doing (they're like cats - have you ever tried to sort an array of cats?); but that's hard to do with the vanilla sorting operation. If you want some sort of predictable behaviour, it's not too hard; all you need is a comparison function that puts all the NaNs together: >>> sorted([3, 5, -8, float('NaN'), 1, 0.5, 33], key=lambda x: (x!=x, x)) [-8, 0.5, 1, 3, 5, 33, nan] Or if you'd rather shove them all to the beginning: >>> sorted([3, 5, -8, float('NaN'), 1, 0.5, 33], key=lambda x: (x==x, x)) [nan, -8, 0.5, 1, 3, 5, 33] With that change, you have a guarantee that all finite and infinite values will be correctly sorted, and the NaNs will be grouped (but in no particular order within that group). ChrisA From steve+comp.lang.python at pearwood.info Sat Jun 2 06:27:12 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 2 Jun 2018 10:27:12 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On Sat, 02 Jun 2018 10:32:55 +1000, Chris Angelico wrote: > On Sat, Jun 2, 2018 at 10:14 AM, Steven D'Aprano > wrote: >>> But >>> assuming you're right, POSIX is still a set of minimum requirements - >>> not maximums, to my knowledge. >> >> It isn't even a set of minimum requirements. "<" is legal under POSIX, >> but not Windows. > > Windows isn't POSIX compliant. Technically, Windows is POSIX compliant. You have to turn off a bunch of features, turn on another bunch of features, and what you get is the bare minimum POSIX compliance possible, but it's enough to tick the check box for POSIX compliance. What what of it? POSIX is not a minimum set of requirements for Python. POSIX is a set of standards that describes how Linux/Unix/MacOS systems are expected to behave. Adhering to the POSIX standard isn't a requirement for Python. > Anyhow, I've come to the conclusion that we're all about equally wrong > here To paraphrase Isaac Asimov, "People who say the earth is flat are wrong, and people who say the earth is a sphere are wrong, but if you say that those two groups of people are equally wrong, you are more wrong than both of them put together." -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sat Jun 2 06:40:48 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 2 Jun 2018 10:40:48 +0000 (UTC) Subject: Sorting NaNs References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On Sat, 02 Jun 2018 09:32:05 +0200, Peter J. Holzer wrote: > Also nope. It looks like NaNs just mess up sorting in an unpredictable > way. Is this the intended behaviour or just an accident of > implementation? (I think it's the latter: I can see how a sort algorithm > which doesn't treat NaN specially would produce such results.) Neither -- it is a deliberate decision to ignore the possibility of such pathological objects when sorting. Feature requests to reconsider this decision in statistics.median will be considered seriously :-) NANs are unordered values. ALL of these ought to return False, for ANY float value x: NAN < x NAN <= x NAN > x NAN >= x NAN == x Regardless of the value of x, NAN x is always false (apart from != which is always true). Python's sort algorithm assumes that objects have consistent, sensible comparisons. If you write an object like this: class Rubbish: def __eq__(self, other): return random.random() > 0.5 def __lt__(self, other): return random.random() > 0.5 def __gt__(self, other): return random.random() > 0.5 it too will mess up sorting in unpredictable ways. So don't do that. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sat Jun 2 06:58:43 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 20:58:43 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On Sat, Jun 2, 2018 at 8:27 PM, Steven D'Aprano wrote: > On Sat, 02 Jun 2018 10:32:55 +1000, Chris Angelico wrote: > >> On Sat, Jun 2, 2018 at 10:14 AM, Steven D'Aprano >> wrote: >>>> But >>>> assuming you're right, POSIX is still a set of minimum requirements - >>>> not maximums, to my knowledge. >>> >>> It isn't even a set of minimum requirements. "<" is legal under POSIX, >>> but not Windows. >> >> Windows isn't POSIX compliant. > > Technically, Windows is POSIX compliant. You have to turn off a bunch of > features, turn on another bunch of features, and what you get is the bare > minimum POSIX compliance possible, but it's enough to tick the check box > for POSIX compliance. Really? I didn't know that Windows path names were POSIX compliant. Or do you have to use the Cygwin fudge to count Windows as POSIX? And what about POSIX signal handling? Citation needed, big-time. ChrisA From rosuav at gmail.com Sat Jun 2 07:02:14 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 21:02:14 +1000 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On Sat, Jun 2, 2018 at 8:40 PM, Steven D'Aprano wrote: > Python's sort algorithm assumes that objects have consistent, sensible > comparisons. If you write an object like this: > > > class Rubbish: > def __eq__(self, other): > return random.random() > 0.5 > def __lt__(self, other): > return random.random() > 0.5 > def __gt__(self, other): > return random.random() > 0.5 > > it too will mess up sorting in unpredictable ways. So don't do that. > Point of curiosity: Why "> 0.5"? Normally when I want a fractional chance, I write the comparison the other way: "random.random() < 0.5" has exactly a 50% chance of occurring (presuming that random.random() follows its correct documented distribution). I've no idea what the probability of random.random() returning exactly 0.5 is, but since it can return 0.0 and cannot return 1.0, I've just always used less-than. (Also because it works nicely with other values - there's a 30% chance that random.random() is less than 0.3, etc.) Is there a reason for going greater-than, or is it simply that it doesn't matter? ChrisA From steve+comp.lang.python at pearwood.info Sat Jun 2 07:02:45 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 2 Jun 2018 11:02:45 +0000 (UTC) Subject: Sorting NaNs References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On Sat, 02 Jun 2018 10:31:37 +0100, Paul Moore wrote: > 1. The behaviour of comparisons involving NaN values is weird (not > undefined, as far as I know NaN behaviour is very well defined, but > violates a number of normally fundamental properties of comparisons) Not so much weird. They're just *unordered* -- no order is defined on NANs, so if you ask whether one NAN is less than something, the answer is always False. Some maths libraries provide a separate set of comparison functions which return a NAN instead of True/False on NAN comparisons, but Python doesn't do that. The violation of reflexivity is weird though :-) x = float(NAN) x == x # returns False Don't argue, just accept it :-) > 2. The precise behaviour of the sort algorithm use by Python is not > mandated by the language. I don't think that is quite right: Python's sort is defined to be a stable, lexicographical sort. That's quite well-defined, for values which define a total ordering. http://mathworld.wolfram.com/TotallyOrderedSet.html The floats excluding NANs are totally ordered; the floats including NANs are not. For values which are not totally ordered, no guarantees can be made. The result of sorting will depend on the precise details of the sort algorithm, the semantics of how the values compare, and the initial order of the values. > A consequence of (1) is that there is no meaningful definition of "a > sorted list of numbers" if that list includes NaN, Correct. [...] > So call it an accident of implementation of you like. Or "sorting a list > with NaNs in it is meaningless" if you prefer. Or "undefined behaviour" > if you're a fan of the language in the C standard. While sorting NANs will return in some unpredictable or arbitrary order, that last one does not apply. If the C definition of undefined behaviour applied, you could write a two-line script like this: print("Hello") result = sorted([1, float("nan"), 2]) and the compiler could *legally* generate code to erase your hard disk instead of printing "Hello". -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sat Jun 2 07:05:28 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 2 Jun 2018 11:05:28 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: On Sat, 02 Jun 2018 01:51:07 +0000, Grant Edwards wrote: > What about the case where somebody calls > > os.path.exists("/tmp/foo\x00bar") > > If /tmp/foo exists should it return True? That depends on whether /tmp/foo is a directory containing a file \0bar or not. Since that is not a legal file name on POSIX systems, it should return False. On Windows, I don't know whether such a file could exist or not. > That's what would happen if > you passed that string directly to the libc call. Fortunately, as Python programmers, we're not passing the string directly to the libc call. We're passing a Python string to a Python function. Nor are we receiving the result directly back from the libc call, since it neither returns bool objects, nor raises exceptions on error. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From sharan.basappa at gmail.com Sat Jun 2 07:08:31 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 2 Jun 2018 04:08:31 -0700 (PDT) Subject: syntax question Message-ID: <57512c69-aa5b-4f23-96f0-b7d07cbc6d1e@googlegroups.com> Can anyone please tell me what the following line in a python program does: line = lambda x: x + 3 I have pasted the entire code below for reference: from scipy.optimize import fsolve import numpy as np line = lambda x: x + 3 solution = fsolve(line, -2) print solution From steve+comp.lang.python at pearwood.info Sat Jun 2 07:13:51 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 2 Jun 2018 11:13:51 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On Sat, 02 Jun 2018 20:58:43 +1000, Chris Angelico wrote: >>> Windows isn't POSIX compliant. >> >> Technically, Windows is POSIX compliant. You have to turn off a bunch >> of features, turn on another bunch of features, and what you get is the >> bare minimum POSIX compliance possible, but it's enough to tick the >> check box for POSIX compliance. > > Really? I didn't know that Windows path names were POSIX compliant. Or > do you have to use the Cygwin fudge to count Windows as POSIX? And what > about POSIX signal handling? > > Citation needed, big-time. https://en.wikipedia.org/wiki/Microsoft_POSIX_subsystem https://technet.microsoft.com/en-us/library/bb463220.aspx https://brianreiter.org/2010/08/24/the-sad-history-of-the-microsoft-posix- subsystem/ -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sat Jun 2 07:20:42 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 21:20:42 +1000 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On Sat, Jun 2, 2018 at 9:02 PM, Steven D'Aprano wrote: > The violation of reflexivity is weird though :-) > > x = float(NAN) > x == x # returns False > > Don't argue, just accept it :-) The way I learned it was: there are (of course) a finite number of bit patterns that can represent NaN, but conceptually, there are an infinite number of things that are not numbers, and so two different NaN values could actually represent different non-numbers. Thus, for consistency, we assume that no two non-numbers are equal, regardless of trivial things like bit pattern or identity. (The IEEE standard doesn't have anything about identity, AFAIK, so it's just the bit pattern.) Whether that helps or not is up to you. :) Violating reflexivity truly is weird, especially since some comparisons are described as "x == y" but implemented as "x is y or x == y". But trying to maintain reflexivity would make other things even more weird... ChrisA From tuxtimo at gmail.com Sat Jun 2 07:21:06 2018 From: tuxtimo at gmail.com (Timo Furrer) Date: Sat, 2 Jun 2018 13:21:06 +0200 Subject: syntax question In-Reply-To: <57512c69-aa5b-4f23-96f0-b7d07cbc6d1e@googlegroups.com> References: <57512c69-aa5b-4f23-96f0-b7d07cbc6d1e@googlegroups.com> Message-ID: >From the Python documentation at https://docs.python.org/3/tutorial/controlflow.html#lambda-expressions > Small anonymous functions can be created with the lambda keyword. This function returns the sum of its two arguments: lambda a, b: a+b. Lambda functions can be used wherever function objects are required. They are syntactically restricted to a single expression. Semantically, they are just syntactic sugar for a normal function definition. Thus, in your case the lambda is equivalent to: def line(x): return x + 3 Cheers, Timo On Sat, Jun 2, 2018 at 1:12 PM Sharan Basappa wrote: > Can anyone please tell me what the following line in a python program does: > > line = lambda x: x + 3 > > I have pasted the entire code below for reference: > > from scipy.optimize import fsolve > import numpy as np > line = lambda x: x + 3 > solution = fsolve(line, -2) > print solution > -- > https://mail.python.org/mailman/listinfo/python-list > -- *Timo Furrer* https://github.com/timofurrer tuxtimo at gmail.com From rosuav at gmail.com Sat Jun 2 07:22:40 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 21:22:40 +1000 Subject: syntax question In-Reply-To: <57512c69-aa5b-4f23-96f0-b7d07cbc6d1e@googlegroups.com> References: <57512c69-aa5b-4f23-96f0-b7d07cbc6d1e@googlegroups.com> Message-ID: On Sat, Jun 2, 2018 at 9:08 PM, Sharan Basappa wrote: > Can anyone please tell me what the following line in a python program does: > > line = lambda x: x + 3 > > I have pasted the entire code below for reference: > > from scipy.optimize import fsolve > import numpy as np > line = lambda x: x + 3 > solution = fsolve(line, -2) > print solution That creates a function. It's basically equivalent to: def line(x): return x + 3 Normally you won't take a lambda function and immediately assign it to a name. The point of a lambda function is that, unlike a def function, it can be used directly in a function call - so you might do something like this: solution = fsolve(lambda x: x + 3, -2) which will have the same effect as the code you showed. If you want it to have a name, like this, just use 'def'. ChrisA From rosuav at gmail.com Sat Jun 2 07:28:41 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2018 21:28:41 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On Sat, Jun 2, 2018 at 9:13 PM, Steven D'Aprano wrote: > On Sat, 02 Jun 2018 20:58:43 +1000, Chris Angelico wrote: > >>>> Windows isn't POSIX compliant. >>> >>> Technically, Windows is POSIX compliant. You have to turn off a bunch >>> of features, turn on another bunch of features, and what you get is the >>> bare minimum POSIX compliance possible, but it's enough to tick the >>> check box for POSIX compliance. >> >> Really? I didn't know that Windows path names were POSIX compliant. Or >> do you have to use the Cygwin fudge to count Windows as POSIX? And what >> about POSIX signal handling? >> >> Citation needed, big-time. > > https://en.wikipedia.org/wiki/Microsoft_POSIX_subsystem > > https://technet.microsoft.com/en-us/library/bb463220.aspx > > https://brianreiter.org/2010/08/24/the-sad-history-of-the-microsoft-posix- > subsystem/ Can someone confirm whether or not all the listed signals are actually supported? We know that Ctrl-C maps to the internal Windows interrupt handler, and "kill process" maps to the internal Windows "terminate", but can you send a different process all the different signals and handle them differently? I also can't find anything about path names there. What does POSIX say about the concept of relative paths? Does Windows comply with that? "Windows has some features which are compatible with the equivalent POSIX features" is not the same as "Technically, Windows is POSIX compliant". ChrisA From p.f.moore at gmail.com Sat Jun 2 07:41:57 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Sat, 2 Jun 2018 12:41:57 +0100 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On 2 June 2018 at 12:28, Chris Angelico wrote: > On Sat, Jun 2, 2018 at 9:13 PM, Steven D'Aprano > wrote: >> On Sat, 02 Jun 2018 20:58:43 +1000, Chris Angelico wrote: >> >>>>> Windows isn't POSIX compliant. >>>> >>>> Technically, Windows is POSIX compliant. You have to turn off a bunch >>>> of features, turn on another bunch of features, and what you get is the >>>> bare minimum POSIX compliance possible, but it's enough to tick the >>>> check box for POSIX compliance. >>> >>> Really? I didn't know that Windows path names were POSIX compliant. Or >>> do you have to use the Cygwin fudge to count Windows as POSIX? And what >>> about POSIX signal handling? >>> >>> Citation needed, big-time. >> >> https://en.wikipedia.org/wiki/Microsoft_POSIX_subsystem >> >> https://technet.microsoft.com/en-us/library/bb463220.aspx >> >> https://brianreiter.org/2010/08/24/the-sad-history-of-the-microsoft-posix- >> subsystem/ > > Can someone confirm whether or not all the listed signals are actually > supported? We know that Ctrl-C maps to the internal Windows interrupt > handler, and "kill process" maps to the internal Windows "terminate", > but can you send a different process all the different signals and > handle them differently? > > I also can't find anything about path names there. What does POSIX say > about the concept of relative paths? Does Windows comply with that? > > "Windows has some features which are compatible with the equivalent > POSIX features" is not the same as "Technically, Windows is POSIX > compliant". My apologies, I don't have time to hunt out complete references now, but my recollection is that Windows (the OS) is POSIX compliant (as noted, with certain configurations, etc). However, the Win32 API (which is what most people think of when they say "Windows") is not POSIX compatible. As an example, Windows (the kernel) has the capability to implement fork(), but this isn't exposed via the Win32 API. To implement fork() you need to go to the raw kernel layer. Which is basically what the Windows Linux subsystem (bash on Windows 10) does - it's a user-level implementation of the POSIX API using Win32 kernel calls. Paul From sshsrn at gmail.com Sat Jun 2 09:08:31 2018 From: sshsrn at gmail.com (S Srihari) Date: Sat, 2 Jun 2018 18:38:31 +0530 Subject: Fwd: QUERY In-Reply-To: References: Message-ID: To: python-list at python.org I AM UNABLE TO INSTALL PYTHON. KINDLY HELP ME. From grant.b.edwards at gmail.com Sat Jun 2 10:02:55 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 2 Jun 2018 14:02:55 +0000 (UTC) Subject: Fwd: QUERY References: Message-ID: On 2018-06-02, S Srihari wrote: > I AM UNABLE TO INSTALL PYTHON. > KINDLY HELP ME. You're not doing it wrong. To fix this, do it right instead. From ned at nedbatchelder.com Sat Jun 2 10:16:27 2018 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 2 Jun 2018 10:16:27 -0400 Subject: Fwd: QUERY In-Reply-To: References: Message-ID: On 6/2/18 9:08 AM, S Srihari wrote: > To: python-list at python.org > > > I AM UNABLE TO INSTALL PYTHON. > KINDLY HELP ME. Put yourself in our shoes: how can we help you with so little information?? We don't know what operating system you are on, we don't know what you have tried, we don't know what has gone wrong. Go to http://python.org and click the Downloads menu. --Ned. From python.list at tim.thechases.com Sat Jun 2 11:19:05 2018 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 2 Jun 2018 10:19:05 -0500 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: <20180602101905.5633abbe@bigbox.christie.dr> On 2018-06-02 00:14, Steven D'Aprano wrote: > Since /wibble doesn't exist, neither does /wibble/a\0b > > > py> os.path.exists("/wibble") > False > py> os.path.exists("/wibble/a\0b") > Traceback (most recent call last): > File "", line 1, in > File "/storage/torrents/torrents/python/Python-3.6.4/Lib/ > genericpath.py", line 19, in exists > os.stat(path) > ValueError: embedded null byte > > Oops. Existence is a sketchy sort of thing. For example, sometimes the OS hides certain directory entries from some syscalls while allowing visibility from others. The following comes as on the FreeBSD system I have at hand: >>> import os >>> '.bashrc' in os.listdir() # yes, it sees hidden dot-files True >>> '.zfs' in os.listdir() # but the OS hides .zfs/ from listings False >>> os.path.exists('.zfs') # yet it exists and can cd into it True >>> os.chdir('.zfs') # and you can chdir into it >>> os.listdir() # but you can't listdir in it Traceback (most recent call last): File "", line 1, in OSError: [Errno 22] Invalid argument From hjp-python at hjp.at Sat Jun 2 11:20:59 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 2 Jun 2018 17:20:59 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: <20180602152059.7vsrpvnn7kkuhotp@hjp.at> On 2018-06-02 01:51:07 +0000, Grant Edwards wrote: > On 2018-06-01, Steven D'Aprano wrote: > > But since "\0" is the correct type (a string), and the fact that it > > happens to be illegal on POSIX is a platform-dependent detail of no more > > importance than the fact that "?" is illegal on Windows, it should be > > treated as any other platform-dependent illegal file and return False. > > That sounds reasonable. > > What about the case where somebody calls > > os.path.exists("/tmp/foo\x00bar") > > If /tmp/foo exists should it return True? No. > That's what would happen if you passed that string directly to the > libc call. You can't really pass that string directly to the libc call. The libc calling convention uses \0 as the string delimiter, so you are really passing "/tmp/foo" to the libc (there happen to be more bytes after the terminator, but they are not part of the string as far as libc is concerned), which is not the same as "/tmp/foo\x00bar". So that has to be handled by Python before calling libc. 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 hjp-python at hjp.at Sat Jun 2 11:28:28 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 2 Jun 2018 17:28:28 +0200 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: <20180602152828.morhwizcuqdmi7sv@hjp.at> On 2018-06-02 10:40:48 +0000, Steven D'Aprano wrote: > On Sat, 02 Jun 2018 09:32:05 +0200, Peter J. Holzer wrote: > > Also nope. It looks like NaNs just mess up sorting in an unpredictable > > way. Is this the intended behaviour or just an accident of > > implementation? (I think it's the latter: I can see how a sort algorithm > > which doesn't treat NaN specially would produce such results.) > > > Neither -- it is a deliberate decision If it was a deliberate decicion I would say it was intentional. 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 drsalists at gmail.com Sat Jun 2 12:52:19 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 2 Jun 2018 09:52:19 -0700 Subject: Indented multi-line strings In-Reply-To: References: <9bf0783c8b044b348769942bda950043@F5.com> <20180523162535.xbtqnxi7yqv4ijlg@hjp.at> <20180529091919.xxr7rt5yoplwdge6@hjp.at> <20180530224733.6qai7jsw4bknkukr@hjp.at> <48620ae1be64499abf9baf065273e4c3@F5.com> <889761ba-616e-7825-bbbe-a026e2853820@mrabarnett.plus.com> <20180531211610.mafcf6kjfadog777@hjp.at> Message-ID: On Fri, Jun 1, 2018 at 2:57 PM, Chris Angelico wrote: > If you dislike adding features to a language on the basis that it > makes the language harder to learn, remember that you instead force > one of three even worse options: > > 1) Messy code because people unindent inside their source code, > creating wonky indentation (which Python usually avoids) > > 2) Forcing readers to look up the third-party module you're using > before they can understand your code > > 3) Forcing readers to look up your ad-hoc function before > understanding your code. > > All of these make it harder to understand your code, specifically > BECAUSE the language doesn't have the requisite feature. Well-written > language features are good, not bad, for readability. > > A well designed language has a small core, and large libraries. Please don't make Python into a big language. Almost anytime you can do something in a library instead of in the core language, it's better to do it in a library. Looking things up in a library isn't onerous. From moideen50 at gmail.com Sat Jun 2 13:00:57 2018 From: moideen50 at gmail.com (moideen50 at gmail.com) Date: Sat, 2 Jun 2018 10:00:57 -0700 (PDT) Subject: How to move the scrollbar to inside the text widget Message-ID: <396cffe2-4441-4358-8294-7f57e2e03eb4@googlegroups.com> I am a Newbie I have this code from tkinter import * root = Tk() root.geometry("1200x1000+30+30") # width x height + x_offset + y_offset: T = Text(root, height=10, width=100) T.place(x=20, y=30) for i in range(40): T.insert(END, "This is line %d\n" % i) # create a vertical scrollbar to the right of the listbox yscroll = Scrollbar(command=T.yview, orient=VERTICAL) T.configure(yscrollcommand=yscroll.set) yscroll.pack(side="right", fill="y", expand=False) root.mainloop() The srollbar is on the window frame, is there a way I can move it to inside and right edge of text area? Thanks From drsalists at gmail.com Sat Jun 2 14:29:19 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 2 Jun 2018 11:29:19 -0700 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On Sat, Jun 2, 2018 at 4:28 AM, Chris Angelico wrote: > On Sat, Jun 2, 2018 at 9:13 PM, Steven D'Aprano > wrote: > > On Sat, 02 Jun 2018 20:58:43 +1000, Chris Angelico wrote: > Can someone confirm whether or not all the listed signals are actually > supported? We know that Ctrl-C maps to the internal Windows interrupt > handler, and "kill process" maps to the internal Windows "terminate", > but can you send a different process all the different signals and > handle them differently? > > I also can't find anything about path names there. What does POSIX say > about the concept of relative paths? Does Windows comply with that? > > "Windows has some features which are compatible with the equivalent > POSIX features" is not the same as "Technically, Windows is POSIX > compliant". > The way I heard it, some (US government?) contracts required POSIX compliance, so Microsoft added just enough of a mostly-useless POSIX layer to Windows to be able to win the contracts, without actually being a useful POSIX system. From rosuav at gmail.com Sat Jun 2 14:43:07 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jun 2018 04:43:07 +1000 Subject: Indented multi-line strings In-Reply-To: References: <9bf0783c8b044b348769942bda950043@F5.com> <20180523162535.xbtqnxi7yqv4ijlg@hjp.at> <20180529091919.xxr7rt5yoplwdge6@hjp.at> <20180530224733.6qai7jsw4bknkukr@hjp.at> <48620ae1be64499abf9baf065273e4c3@F5.com> <889761ba-616e-7825-bbbe-a026e2853820@mrabarnett.plus.com> <20180531211610.mafcf6kjfadog777@hjp.at> Message-ID: On Sun, Jun 3, 2018 at 2:52 AM, Dan Stromberg wrote: > > On Fri, Jun 1, 2018 at 2:57 PM, Chris Angelico wrote: >> >> If you dislike adding features to a language on the basis that it >> makes the language harder to learn, remember that you instead force >> one of three even worse options: >> >> 1) Messy code because people unindent inside their source code, >> creating wonky indentation (which Python usually avoids) >> >> 2) Forcing readers to look up the third-party module you're using >> before they can understand your code >> >> 3) Forcing readers to look up your ad-hoc function before >> understanding your code. >> >> All of these make it harder to understand your code, specifically >> BECAUSE the language doesn't have the requisite feature. Well-written >> language features are good, not bad, for readability. >> > A well designed language has a small core, and large libraries. > > Please don't make Python into a big language. > > Almost anytime you can do something in a library instead of in the core > language, it's better to do it in a library. > > Looking things up in a library isn't onerous. > How small is small, though? And how is a method worse than a library function? People keep asserting this about the language needing to be smaller, but never backing it up. Was Python 1.0 better than Python 3.7 due to having fewer features? ChrisA From ben.usenet at bsb.me.uk Sat Jun 2 16:51:16 2018 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Sat, 02 Jun 2018 21:51:16 +0100 Subject: Sorting NaNs References: <20180602073205.67ihzu52mdan2fqm@hjp.at> <87k1rh2bcz.fsf@nightsong.com> Message-ID: <87o9gsud2z.fsf@bsb.me.uk> Paul Rubin writes: > Steven D'Aprano writes: >> it too will mess up sorting in unpredictable ways. So don't do that. > > Hmm. GHCi 7.4.2: > > Prelude> let x = 0.0 / 0.0 > Prelude> x > NaN > Prelude> x==x > False > Prelude> :m Data.List > Prelude Data.List> sort [1,2,x,4,5] > [1.0,2.0,4.0,5.0,NaN] But Prelude Data.List> sort [1,x,2,4,5] [2.0,4.0,5.0,NaN,1.0] and Prelude Data.List> sort [1,2,x,4,5,x] [NaN,1.0,2.0,4.0,5.0,NaN] and Prelude Data.List> sort [1,2,x,4,5,x,1/0] [1.0,2.0,4.0,Infinity,NaN,5.0,NaN] > Not sure what to make of this but at least sorting seems to give a > predictable result. I suspect it is predictable if you know the algorithm, but I doubt it's specified nor easily guessable from "outside". (GHCi, version 8.0.2 here) -- Ben. From Richard at Damon-Family.org Sat Jun 2 18:16:44 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 2 Jun 2018 18:16:44 -0400 Subject: Sorting NaNs In-Reply-To: <87o9gsud2z.fsf@bsb.me.uk> References: <20180602073205.67ihzu52mdan2fqm@hjp.at> <87k1rh2bcz.fsf@nightsong.com> <87o9gsud2z.fsf@bsb.me.uk> Message-ID: On 6/2/18 4:51 PM, Ben Bacarisse wrote: > Paul Rubin writes: > >> Steven D'Aprano writes: >>> it too will mess up sorting in unpredictable ways. So don't do that. >> Hmm. GHCi 7.4.2: >> >> Prelude> let x = 0.0 / 0.0 >> Prelude> x >> NaN >> Prelude> x==x >> False >> Prelude> :m Data.List >> Prelude Data.List> sort [1,2,x,4,5] >> [1.0,2.0,4.0,5.0,NaN] > But > > Prelude Data.List> sort [1,x,2,4,5] > [2.0,4.0,5.0,NaN,1.0] > > and > > Prelude Data.List> sort [1,2,x,4,5,x] > [NaN,1.0,2.0,4.0,5.0,NaN] > > and > > Prelude Data.List> sort [1,2,x,4,5,x,1/0] > [1.0,2.0,4.0,Infinity,NaN,5.0,NaN] > >> Not sure what to make of this but at least sorting seems to give a >> predictable result. > I suspect it is predictable if you know the algorithm, but I doubt it's > specified nor easily guessable from "outside". > > (GHCi, version 8.0.2 here) > The sorting algorithm is almost certainly deterministic (as is the comparisons with Nan), so given the same input you will get the same output, which says you could predict the output by effectively running the sort and look at the results and predict it will happen the same, this presumes you know the exact implementation of the sort (which you could get from the implementation source code). This could be called 'predictable' but that is a real stretch. Because the sort is stable, I would expect that away from the Nans in the output the results are likely to be at least mostly sorted, as the algorithm should mostly be working right except where a NaN is moving through. -- Richard Damon From steve+comp.lang.python at pearwood.info Sat Jun 2 19:35:53 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 2 Jun 2018 23:35:53 +0000 (UTC) Subject: Sorting NaNs References: <20180602073205.67ihzu52mdan2fqm@hjp.at> <20180602152828.morhwizcuqdmi7sv@hjp.at> Message-ID: On Sat, 02 Jun 2018 17:28:28 +0200, Peter J. Holzer wrote: > On 2018-06-02 10:40:48 +0000, Steven D'Aprano wrote: >> On Sat, 02 Jun 2018 09:32:05 +0200, Peter J. Holzer wrote: >> > Also nope. It looks like NaNs just mess up sorting in an >> > unpredictable way. Is this the intended behaviour or just an accident >> > of implementation? (I think it's the latter: I can see how a sort >> > algorithm which doesn't treat NaN specially would produce such >> > results.) >> >> >> Neither -- it is a deliberate decision > > If it was a deliberate decicion I would say it was intentional. As the author of the statistics module, I can absolutely and categorically tell you without even the tiniest doubt that the behavour of statistics.median with NANs is certainly not intentional. The behaviour of median with NANs is unspecified. It is whatever the implementation happens to do. If it gives the right answer, great, and if it doesn't, it doesn't. If somebody cares about this use case enough to suggest an alternative behaviour, I'm willing to consider it. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From greg.ewing at canterbury.ac.nz Sat Jun 2 19:37:16 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 03 Jun 2018 11:37:16 +1200 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> <20180602152828.morhwizcuqdmi7sv@hjp.at> Message-ID: Peter J. Holzer wrote: > If it was a deliberate decicion I would say it was intentional. It was a deliberate decision not to define an ordering for NaNs, but the particular behaviour of sorting them is accidental. -- Greg From greg.ewing at canterbury.ac.nz Sat Jun 2 19:47:40 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 03 Jun 2018 11:47:40 +1200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: Paul Moore wrote: > Windows (the kernel) has the > capability to implement fork(), but this isn't exposed via the Win32 > API. To implement fork() you need to go to the raw kernel layer. Which > is basically what the Windows Linux subsystem (bash on Windows 10) > does What people usually mean by "POSIX compliant" is not "it's possible to implement the POSIX API on top of it". By that definition, a raw PC without any software is POSIX compliant. -- Greg From ned at nedbatchelder.com Sat Jun 2 19:50:55 2018 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 2 Jun 2018 19:50:55 -0400 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> <87k1rh2bcz.fsf@nightsong.com> <87o9gsud2z.fsf@bsb.me.uk> Message-ID: <532a19a3-8a18-fc51-72ed-ae4381858cae@nedbatchelder.com> On 6/2/18 6:16 PM, Richard Damon wrote: > On 6/2/18 4:51 PM, Ben Bacarisse wrote: >> Paul Rubin writes: >> >>> Steven D'Aprano writes: >>>> it too will mess up sorting in unpredictable ways. So don't do that. >>> Hmm. GHCi 7.4.2: >>> >>> Prelude> let x = 0.0 / 0.0 >>> Prelude> x >>> NaN >>> Prelude> x==x >>> False >>> Prelude> :m Data.List >>> Prelude Data.List> sort [1,2,x,4,5] >>> [1.0,2.0,4.0,5.0,NaN] >> But >> >> Prelude Data.List> sort [1,x,2,4,5] >> [2.0,4.0,5.0,NaN,1.0] >> >> and >> >> Prelude Data.List> sort [1,2,x,4,5,x] >> [NaN,1.0,2.0,4.0,5.0,NaN] >> >> and >> >> Prelude Data.List> sort [1,2,x,4,5,x,1/0] >> [1.0,2.0,4.0,Infinity,NaN,5.0,NaN] >> >>> Not sure what to make of this but at least sorting seems to give a >>> predictable result. >> I suspect it is predictable if you know the algorithm, but I doubt it's >> specified nor easily guessable from "outside". >> >> (GHCi, version 8.0.2 here) >> > The sorting algorithm is almost certainly deterministic (as is the > comparisons with Nan), so given the same input you will get the same > output, Careful, "same input" is vague.? In Python2, object() instances are compared based on their id, in other words, their memory location. It would be easy to overlook the idea that the layout in memory is part of whether two inputs are "the same". I have no idea what factors determine the result of comparing NaNs. --Ned. From Richard at Damon-Family.org Sat Jun 2 20:06:32 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 2 Jun 2018 20:06:32 -0400 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On 6/2/18 7:47 PM, Gregory Ewing wrote: > Paul Moore wrote: >> Windows (the kernel) has the >> capability to implement fork(), but this isn't exposed via the Win32 >> API. To implement fork() you need to go to the raw kernel layer. Which >> is basically what the Windows Linux subsystem (bash on Windows 10) >> does > > What people usually mean by "POSIX compliant" is not "it's > possible to implement the POSIX API on top of it". By that > definition, a raw PC without any software is POSIX compliant. > But it isn't just that it is possible, Microsoft provides that layer, it just isn't the normal API they suggest using and needs to be explicitly enabled. -- Richard Damon From steve+comp.lang.python at pearwood.info Sat Jun 2 20:08:08 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 3 Jun 2018 00:08:08 +0000 (UTC) Subject: Sorting NaNs References: <20180602073205.67ihzu52mdan2fqm@hjp.at> <87k1rh2bcz.fsf@nightsong.com> <87o9gsud2z.fsf@bsb.me.uk> Message-ID: On Sat, 02 Jun 2018 21:51:16 +0100, Ben Bacarisse wrote: > Paul Rubin writes: > >> Steven D'Aprano writes: >>> it too will mess up sorting in unpredictable ways. So don't do that. >> >> Hmm. GHCi 7.4.2: >> >> Prelude> let x = 0.0 / 0.0 >> Prelude> x >> NaN >> Prelude> x==x >> False >> Prelude> :m Data.List >> Prelude Data.List> sort [1,2,x,4,5] >> [1.0,2.0,4.0,5.0,NaN] > > But > > Prelude Data.List> sort [1,x,2,4,5] > [2.0,4.0,5.0,NaN,1.0] Thanks Ben, and Paul (unfortunately I don't see Paul's messages for some reason). If users of the statistics library would like to see better or different support for NANs, I urge you to let me know. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sat Jun 2 20:08:40 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 3 Jun 2018 00:08:40 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On Sat, 02 Jun 2018 21:28:41 +1000, Chris Angelico wrote: > On Sat, Jun 2, 2018 at 9:13 PM, Steven D'Aprano > wrote: >> On Sat, 02 Jun 2018 20:58:43 +1000, Chris Angelico wrote: >> >>>>> Windows isn't POSIX compliant. >>>> >>>> Technically, Windows is POSIX compliant. You have to turn off a bunch >>>> of features, turn on another bunch of features, and what you get is >>>> the bare minimum POSIX compliance possible, but it's enough to tick >>>> the check box for POSIX compliance. >>> >>> Really? I didn't know that Windows path names were POSIX compliant. Or >>> do you have to use the Cygwin fudge to count Windows as POSIX? And >>> what about POSIX signal handling? >>> >>> Citation needed, big-time. >> >> https://en.wikipedia.org/wiki/Microsoft_POSIX_subsystem >> >> https://technet.microsoft.com/en-us/library/bb463220.aspx >> >> https://brianreiter.org/2010/08/24/the-sad-history-of-the-microsoft- posix- >> subsystem/ > > Can someone confirm whether or not all the listed signals are actually > supported? Unless people do their testing under Windows with the POSIX subsystem installed, such testing is likely to fail. > We know that Ctrl-C maps to the internal Windows interrupt > handler, and "kill process" maps to the internal Windows "terminate", > but can you send a different process all the different signals and > handle them differently? > > I also can't find anything about path names there. What does POSIX say > about the concept of relative paths? Does Windows comply with that? That's a curious question to ask. If you don't know what POSIX says about a feature, why would you question whether Windows complies with it? > "Windows has some features which are compatible with the equivalent > POSIX features" is not the same as "Technically, Windows is POSIX > compliant". Chris, you seem to be labouring under the misapprehension that the claim is that a stock standard Windows installation complies with the latest version of the POSIX standard. That's not the case. The claim (and fact) is that Windows NT with the POSIX subsystem installed (and possibly other changes made) is technically compliant with version 1 of the POSIX standard, which even in 1997 was only a fraction of what most Unix systems provided. https://en.wikipedia.org/wiki/POSIX#Versions Just enough to allow bean counters to tick the box that says "POSIX compliant" in a government requirements form, provided the technical people involved either don't get a say, or do get a say and actually want Windows but have to satisfy some bureaucratic requirement for POSIX. Nobody thinks that standard Windows counts as a Unix. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From Richard at Damon-Family.org Sat Jun 2 20:11:30 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 2 Jun 2018 20:11:30 -0400 Subject: Sorting NaNs In-Reply-To: <532a19a3-8a18-fc51-72ed-ae4381858cae@nedbatchelder.com> References: <20180602073205.67ihzu52mdan2fqm@hjp.at> <87k1rh2bcz.fsf@nightsong.com> <87o9gsud2z.fsf@bsb.me.uk> <532a19a3-8a18-fc51-72ed-ae4381858cae@nedbatchelder.com> Message-ID: <82b8aed1-b019-86dd-2ed9-be9569367e6d@Damon-Family.org> On 6/2/18 7:50 PM, Ned Batchelder wrote: > Careful, "same input" is vague.? In Python2, object() instances are > compared based on their id, in other words, their memory location. It > would be easy to overlook the idea that the layout in memory is part > of whether two inputs are "the same". > > I have no idea what factors determine the result of comparing NaNs. > > --Ned. NaNs have VERY defined comparison results, they are just strange. If you compare a NaN to another floating point value (even another NaN) all comparisons except 'not equals' are false, and 'not equals' are true. Thus all NaNs are unequal to all numbers, including themselves, but are neither greater than or than than any of them. -- Richard Damon From Richard at Damon-Family.org Sat Jun 2 20:16:36 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 2 Jun 2018 20:16:36 -0400 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> <20180602152828.morhwizcuqdmi7sv@hjp.at> Message-ID: On 6/2/18 7:35 PM, Steven D'Aprano wrote: > On Sat, 02 Jun 2018 17:28:28 +0200, Peter J. Holzer wrote: > >> On 2018-06-02 10:40:48 +0000, Steven D'Aprano wrote: >>> On Sat, 02 Jun 2018 09:32:05 +0200, Peter J. Holzer wrote: >>>> Also nope. It looks like NaNs just mess up sorting in an >>>> unpredictable way. Is this the intended behaviour or just an accident >>>> of implementation? (I think it's the latter: I can see how a sort >>>> algorithm which doesn't treat NaN specially would produce such >>>> results.) >>> >>> Neither -- it is a deliberate decision >> If it was a deliberate decicion I would say it was intentional. > > As the author of the statistics module, I can absolutely and > categorically tell you without even the tiniest doubt that the behavour > of statistics.median with NANs is certainly not intentional. > > The behaviour of median with NANs is unspecified. It is whatever the > implementation happens to do. If it gives the right answer, great, and if > it doesn't, it doesn't. > > If somebody cares about this use case enough to suggest an alternative > behaviour, I'm willing to consider it. > The two behaviors that I have heard suggested are: 1) If any of the inputs are a NaN, the median should be a NaN. (Propagating the NaN as indicator of a numeric error) 2) Remove the NaNs from the input set and process what is left. If nothing, then return a NaN (treating NaN as a 'No Data' placeholder). These are very different in interpretation, and not hard to create as a wrapper to the function, so maybe not worth adding to the core function and make it a bit slower. -- Richard Damon From drsalists at gmail.com Sat Jun 2 20:24:30 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 2 Jun 2018 17:24:30 -0700 Subject: Indented multi-line strings In-Reply-To: References: <9bf0783c8b044b348769942bda950043@F5.com> <20180523162535.xbtqnxi7yqv4ijlg@hjp.at> <20180529091919.xxr7rt5yoplwdge6@hjp.at> <20180530224733.6qai7jsw4bknkukr@hjp.at> <48620ae1be64499abf9baf065273e4c3@F5.com> <889761ba-616e-7825-bbbe-a026e2853820@mrabarnett.plus.com> <20180531211610.mafcf6kjfadog777@hjp.at> Message-ID: On Sat, Jun 2, 2018 at 11:43 AM, Chris Angelico wrote: > >> 1) Messy code because people unindent inside their source code, > >> creating wonky indentation (which Python usually avoids) > >> > >> 2) Forcing readers to look up the third-party module you're using > >> before they can understand your code > >> > >> 3) Forcing readers to look up your ad-hoc function before > >> understanding your code. > >> > >> All of these make it harder to understand your code, specifically > >> BECAUSE the language doesn't have the requisite feature. Well-written > >> language features are good, not bad, for readability. > >> > > A well designed language has a small core, and large libraries. > > > > Please don't make Python into a big language. > > > > Almost anytime you can do something in a library instead of in the core > > language, it's better to do it in a library. > > > > Looking things up in a library isn't onerous. > > How small is small, though? And how is a method worse than a library > function? People keep asserting this about the language needing to be > smaller, but never backing it up. It should be small enough to facilitate multiple, compatible implementations. It should be small enough that you don't have to learn a lot to start writing programs. It should be small enough that you don't have to learn 10 languages to read someone else's code. It should not be perl, where anything that seemed a little helpful was dumped in. Was Python 1.0 better than Python 3.7 due to having fewer features? No, generators pretty much rock. And comprehensions are OK, despite the obvious duplication with map and filter. And I like true booleans too. But there's a reason why so many other implementations of Python are still stuck on 2.x. The pace of change in Python, the core language, has just been too fast. From steve+comp.lang.python at pearwood.info Sat Jun 2 20:33:20 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 3 Jun 2018 00:33:20 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On Sun, 03 Jun 2018 11:47:40 +1200, Gregory Ewing wrote: > Paul Moore wrote: >> Windows (the kernel) has the >> capability to implement fork(), but this isn't exposed via the Win32 >> API. To implement fork() you need to go to the raw kernel layer. Which >> is basically what the Windows Linux subsystem (bash on Windows 10) does > > What people usually mean by "POSIX compliant" is not "it's possible to > implement the POSIX API on top of it". What people usually mean by "POSIX compliant" is "Unix or Linux". But that's not what the POSIX standard requires. It requires a set of APIs. I doubt it cares where or how they are implemented. > By that definition, a raw PC without any software is POSIX compliant. Do you really mean to say that a computer that won't boot is POSIX compliant? Yeah, good luck getting that one past the user acceptance testing. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sat Jun 2 20:38:34 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jun 2018 10:38:34 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On Sun, Jun 3, 2018 at 10:08 AM, Steven D'Aprano wrote: > Chris, you seem to be labouring under the misapprehension that the claim > is that a stock standard Windows installation complies > with the latest version of the POSIX standard. > > That's not the case. > > The claim (and fact) is that Windows NT with the POSIX subsystem > installed (and possibly other changes made) is technically compliant with > version 1 of the POSIX standard, which even in 1997 was only a fraction > of what most Unix systems provided. > > https://en.wikipedia.org/wiki/POSIX#Versions > > Just enough to allow bean counters to tick the box that says "POSIX > compliant" in a government requirements form, provided the technical > people involved either don't get a say, or do get a say and actually want > Windows but have to satisfy some bureaucratic requirement for POSIX. > > Nobody thinks that standard Windows counts as a Unix. Let's just rewind this subthread a little bit. YOU said that the behaviour of os.path.exists on Unix systems should be "return False for invalid things" on the basis that the Windows invalid paths return False. Remember? Or are you just too het up about arguing this point that you don't care why you're arguing? I said that Windows isn't POSIX, and pointed out just a couple of ways in which, to a programmer, Windows behaves very differently to POSIX-compliant systems. The two examples I gave were signals and relative paths. Now, if you want to tell me that we can completely ignore drive letters on Windows, then sure. Go ahead. Tell me that relative paths behave sanely on Windows just as long as you have only a single drive. Or tell me that the POSIX standard permits three different types of relative path. And with signals, can you show me that a process can send another process a variety of different signals, and that the receiving process can handle them differently? Claiming that Windows technically ticks some box is utterly meaningless to that. ChrisA From greg.ewing at canterbury.ac.nz Sat Jun 2 22:25:17 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 03 Jun 2018 14:25:17 +1200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: Steven D'Aprano wrote: > Do you really mean to say that a computer that won't boot is POSIX > compliant? No, I was pointing out the absurdity of saying that the Windows kernel layer is POSIX compliant, which is what the post I was replying to seemed to be saying. -- Greg From jfong at ms4.hinet.net Sat Jun 2 22:55:04 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Sun, 3 Jun 2018 10:55:04 +0800 Subject: How can an int be '+' with a tuple? Message-ID: The attached is a script which can run under Python 3.4/Windows Vista correctly. One thing make me puzzled is that the "any + context" at line 18. The "any" was passed as an integer from line 43 and the "context" was defined as a tuple at line 35. This concatenation works! how? Best Regards, Jach Fong --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus -------------- next part -------------- import _thread as thread import queue threadQueue = queue.Queue(maxsize=0) def queueChecker(widget, delayMsecs=100): try: (callback, args) = threadQueue.get(block=False) except queue.Empty: pass else: callback(*args) widget.after(delayMsecs, lambda: queueChecker(widget, delayMsecs)) # back to event loop def threaded(action, args, context, onExit, onProgress): def progress(*any): threadQueue.put((onProgress, any + context)) action(progress=progress, *args) threadQueue.put((onExit, context)) def startThread(action, args, context, onExit, onProgress): thread.start_new_thread( threaded, (action, args, context, onExit, onProgress)) if __name__ == '__main__': import time import tkinter as tk def onEvent(i): # code that spawns thread myname = 'thread-%s' % i startThread( action = threadaction, args = (i, 3), context = (myname,), onExit = threadexit, onProgress = threadprogress) # thread's main action def threadaction(id, reps, progress): for i in range(reps): time.sleep(1) progress(i) # progress callback: queued # thread exit/progress callbacks: dispatched off queue in main thread def threadexit(myname): print('%s\texit' % myname) def threadfail(exc_info, myname): print('%s\tfail\t%s' % (myname, exc_info[0])) def threadprogress(count, myname): print('%s\tprog\t%s' % (myname, count)) # make enclosing GUI and start timer loop in main thread # spawn batch of worker threads on each mouse click: may overlap root = tk.Tk() queueChecker(root) root.bind('', # 3.x need list for map, range ok lambda event: list(map(onEvent, range(2))) ) root.mainloop() From rosuav at gmail.com Sat Jun 2 23:53:23 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jun 2018 13:53:23 +1000 Subject: How can an int be '+' with a tuple? In-Reply-To: References: Message-ID: On Sun, Jun 3, 2018 at 12:55 PM, Jach Fong wrote: > The attached is a script which can run under Python 3.4/Windows Vista > correctly. One thing make me puzzled is that the "any + context" at line > 18. The "any" was passed as an integer from line 43 and the "context" > was defined as a tuple at line 35. This concatenation works! how? > If In Doubt, Print It Out. Try adding some print calls to see exactly what those values really are. You may be surprised. ChrisA From ben+python at benfinney.id.au Sat Jun 2 23:57:26 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 03 Jun 2018 13:57:26 +1000 Subject: How can an int be '+' with a tuple? References: Message-ID: <85zi0cikt5.fsf@benfinney.id.au> Jach Fong writes: > The attached is a script Thanks for making an example script. Instead of attaching it, please post it along with your message so that everyone can read it. You can make scripts suitable for posting in your message, by keeping them short and simple . (For good reasons, attachments are dropped when messages are distributed on the forum.) > One thing make me puzzled is that the "any + context" at line > 18. The "any" was passed as an integer from line 43 and the "context" > was defined as a tuple at line 35. This concatenation works! how? If the values are actually as you say, then Python should raise a TypeError. For example:: >>> 1 + ("foo", "bar") Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'int' and 'tuple' What makes me suspect that's different from your code, is that you say ?defined as a tuple?. Names in Python have no defined type; only an object has a type, and operations (like ?+? only take effect on the object, not the name. -- \ ?I went to the cinema, it said ?Adults: $5.00, Children $2.50?. | `\ So I said ?Give me two boys and a girl.?? ?Steven Wright | _o__) | Ben Finney From gherron at digipen.edu Sun Jun 3 00:05:19 2018 From: gherron at digipen.edu (Gary Herron) Date: Sat, 2 Jun 2018 21:05:19 -0700 Subject: How can an int be '+' with a tuple? In-Reply-To: References: Message-ID: In fact, the value of *any* is *not* an integer.? The *any notation causes Python to pack all the arguments into a tuple. This feature is usually used when there are multiple (and an unknown number) of parameters, but it works perfectly well with a single parameter. Here's an example: >>> def progress(*any): ??? print(any) >>> progress(1) (1,) >>> progress(1,2,3) (1, 2, 3) >>> On 06/02/2018 07:55 PM, jfong at ms4.hinet.net wrote: > The attached is a script which can run under Python 3.4/Windows Vista > correctly. One thing make me puzzled is that the "any + context" at line > 18. The "any" was passed as an integer from line 43 and the "context" > was defined as a tuple at line 35. This concatenation works! how? > > Best Regards, > Jach Fong > > > > > > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus > > -- Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology (425) 895-4418 From jfong at ms4.hinet.net Sun Jun 3 00:32:07 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Sun, 3 Jun 2018 12:32:07 +0800 Subject: How can an int be '+' with a tuple? In-Reply-To: <85zi0cikt5.fsf@benfinney.id.au> References: <85zi0cikt5.fsf@benfinney.id.au> Message-ID: <87de815d-331a-c4ad-9411-cba3103bbd95@ms4.hinet.net> > (For good reasons, attachments are dropped when messages are distributed > on the forum.) For whom who can not get the attachment:-) ###a simplified version of "Programming Python 4ed, Example 10-20. import _thread as thread import queue threadQueue = queue.Queue(maxsize=0) def queueChecker(widget, delayMsecs=100): try: (callback, args) = threadQueue.get(block=False) except queue.Empty: pass else: callback(*args) widget.after(delayMsecs, lambda: queueChecker(widget, delayMsecs)) # back to event loop def threaded(action, args, context, onExit, onProgress): def progress(*any): threadQueue.put((onProgress, any + context)) # <--line 18 action(progress=progress, *args) threadQueue.put((onExit, context)) def startThread(action, args, context, onExit, onProgress): thread.start_new_thread( threaded, (action, args, context, onExit, onProgress)) if __name__ == '__main__': import time import tkinter as tk def onEvent(i): # code that spawns thread myname = 'thread-%s' % i startThread( action = threadaction, args = (i, 3), context = (myname,), # <-- line 35 onExit = threadexit, onProgress = threadprogress) # thread's main action def threadaction(id, reps, progress): for i in range(reps): time.sleep(1) progress(i) # <--line 43, progress callback: queued # thread exit/progress callbacks: dispatched off queue in main thread def threadexit(myname): print('%s\texit' % myname) def threadfail(exc_info, myname): print('%s\tfail\t%s' % (myname, exc_info[0])) def threadprogress(count, myname): print('%s\tprog\t%s' % (myname, count)) # make enclosing GUI and start timer loop in main thread # spawn batch of worker threads on each mouse click: may overlap root = tk.Tk() queueChecker(root) root.bind('', # 3.x need list for map, range ok lambda event: list(map(onEvent, range(2))) ) root.mainloop() Ben Finney ? 2018/6/3 ?? 11:57 ??: > Jach Fong writes: > >> The attached is a script > > Thanks for making an example script. Instead of attaching it, please > post it along with your message so that everyone can read it. You can > make scripts suitable for posting in your message, by keeping them short > and simple . > > (For good reasons, attachments are dropped when messages are distributed > on the forum.) > >> One thing make me puzzled is that the "any + context" at line >> 18. The "any" was passed as an integer from line 43 and the "context" >> was defined as a tuple at line 35. This concatenation works! how? > > If the values are actually as you say, then Python should raise a > TypeError. For example:: > > >>> 1 + ("foo", "bar") > Traceback (most recent call last): > File "", line 1, in > TypeError: unsupported operand type(s) for +: 'int' and 'tuple' > > What makes me suspect that's different from your code, is that you say > ?defined as a tuple?. Names in Python have no defined type; only an > object has a type, and operations (like ?+? only take effect on the > object, not the name. > --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From jfong at ms4.hinet.net Sun Jun 3 00:35:27 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Sun, 3 Jun 2018 12:35:27 +0800 Subject: How can an int be '+' with a tuple? In-Reply-To: References: Message-ID: Yes, (I think) I know the *any usage, but don't know their type will be changed after unpack? Gary Herron ? 2018/6/3 ?? 12:05 ??: > In fact, the value of *any* is *not* an integer.? The *any notation > causes Python to pack all the arguments into a tuple. This feature is > usually used when there are multiple (and an unknown number) of > parameters, but it works perfectly well with a single parameter. > > Here's an example: > > >>> def progress(*any): > ??? print(any) > > >>> progress(1) > (1,) > >>> progress(1,2,3) > (1, 2, 3) > >>> > > > On 06/02/2018 07:55 PM, jfong at ms4.hinet.net wrote: >> The attached is a script which can run under Python 3.4/Windows Vista >> correctly. One thing make me puzzled is that the "any + context" at line >> 18. The "any" was passed as an integer from line 43 and the "context" >> was defined as a tuple at line 35. This concatenation works! how? >> >> Best Regards, >> Jach Fong >> >> >> >> >> >> --- >> This email has been checked for viruses by Avast antivirus software. >> https://www.avast.com/antivirus >> >> > From steve+comp.lang.python at pearwood.info Sun Jun 3 00:59:34 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 3 Jun 2018 04:59:34 +0000 (UTC) Subject: How can an int be '+' with a tuple? References: Message-ID: On Sun, 03 Jun 2018 10:55:04 +0800, Jach Fong wrote: > The attached is a script which can run under Python 3.4/Windows Vista > correctly. One thing make me puzzled is that the "any + context" at line > 18. The "any" was passed as an integer from line 43 and the "context" > was defined as a tuple at line 35. This concatenation works! how? 90% of the script you attached is irrelevant to your question. None of the tkinter or threading code is important. The only important parts are: def threaded(action, args, context, onExit, onProgress): def progress(*any): threadQueue.put((onProgress, any + context)) Here we can tell that ``any`` is a tuple. But what is context? Following it backwards, we find: context = (myname,), which is not an int, but a tuple. Try it for yourself: py> value = ("Steven",), py> print(value) (('Steven',),) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sun Jun 3 01:08:08 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 3 Jun 2018 05:08:08 +0000 (UTC) Subject: How can an int be '+' with a tuple? References: Message-ID: On Sun, 03 Jun 2018 04:59:34 +0000, Steven D'Aprano wrote: > On Sun, 03 Jun 2018 10:55:04 +0800, Jach Fong wrote: > >> The attached is a script which can run under Python 3.4/Windows Vista >> correctly. One thing make me puzzled is that the "any + context" at >> line 18. The "any" was passed as an integer from line 43 and the >> "context" was defined as a tuple at line 35. This concatenation works! >> how? > > 90% of the script you attached is irrelevant to your question. None of > the tkinter or threading code is important. The only important parts > are: > > def threaded(action, args, context, onExit, onProgress): > def progress(*any): > threadQueue.put((onProgress, any + context)) > > Here we can tell that ``any`` is a tuple. Oops, I misread your question. You thought any was an int. But the * (star) notation in function parameters makes the parameter collect any unnamed arguments into a single tuple. def test(first, *args): print(args) test(1, 2, 3, "hello", 99) => prints the tuple (2, 3, "hello", 99) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From jfong at ms4.hinet.net Sun Jun 3 01:12:28 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Sun, 3 Jun 2018 13:12:28 +0800 Subject: How can an int be '+' with a tuple? In-Reply-To: References: Message-ID: <9c15e33c-21fb-2748-90dd-be8f5465479c@ms4.hinet.net> After a quick check I got: D:\Works\Python\PP4E-Examples-1.4\Examples\PP4E>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. >>> t = ('myname',) >>> n = (3,) >>> n + t (3, 'myname') >>> I may overlook Gary's reply. The "any" has not unpacked yet at that time:-) My fault, sorry. ---------------- Yes, (I think) I know the *any usage, but don't know their type will be changed after unpack? Gary Herron ? 2018/6/3 ?? 12:05 ??: > In fact, the value of *any* is *not* an integer.? The *any notation > causes Python to pack all the arguments into a tuple. This feature is > usually used when there are multiple (and an unknown number) of > parameters, but it works perfectly well with a single parameter. > > Here's an example: > > >>> def progress(*any): > ??? print(any) > > >>> progress(1) > (1,) > >>> progress(1,2,3) > (1, 2, 3) > >>> > > > On 06/02/2018 07:55 PM, jfong at ms4.hinet.net wrote: >> The attached is a script which can run under Python 3.4/Windows Vista >> correctly. One thing make me puzzled is that the "any + context" at line >> 18. The "any" was passed as an integer from line 43 and the "context" >> was defined as a tuple at line 35. This concatenation works! how? >> >> Best Regards, >> Jach Fong >> >> >> >> >> >> --- >> This email has been checked for viruses by Avast antivirus software. >> https://www.avast.com/antivirus >> >> > From steve+comp.lang.python at pearwood.info Sun Jun 3 01:48:32 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 3 Jun 2018 05:48:32 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On Sun, 03 Jun 2018 10:38:34 +1000, Chris Angelico wrote: > Let's just rewind this subthread a little bit. YOU said that the > behaviour of os.path.exists on Unix systems should be "return False for > invalid things" on the basis that the Windows invalid paths return > False. Remember? No, invalid paths on Linux return False too: py> os.path.exists("") False I can make a VFAT partition under Linux: [steve at ando ~]$ dd if=/dev/zero of=fat.fs bs=1024 count=48 48+0 records in 48+0 records out 49152 bytes (49 kB) copied, 0.0149677 seconds, 3.3 MB/s [steve at ando ~]$ /sbin/mkfs.vfat fat.fs mkfs.vfat 2.11 (12 Mar 2005) [steve at ando ~]$ mkdir dos [steve at ando ~]$ sudo mount -o loop fat.fs ./dos [sudo] password for steve: I can write to it (as root), but not all file names are valid: [steve at ando ~]$ sudo touch ./dos/foo [steve at ando ~]$ sudo touch ./dos/"foo?" touch: setting times of `./dos/foo?': No such file or directory [steve at ando ~]$ ls ./dos foo And even though I'm using Linux, I get the right answer, legal file name or not legal file name. [steve at ando ~]$ python3.5 -c "import os; \ > print(os.path.exists('./dos/foo'))" True [steve at ando ~]$ python3.5 -c "import os; \ > print(os.path.exists('./dos/foo?'))" False > I said that Windows isn't POSIX, And I said, as a by-the-by, that technically Windows is POSIX compliant, for a very pedantically true but dubious in practice value of compliant. > and pointed out just a couple of ways in which, to a programmer, Windows > behaves very differently to POSIX-compliant systems. Is that Windows out of the box, or Windows with the POSIX subsystem installed and active? You keep talking about "POSIX-compliant", but POSIX is a family of standards. A system can be compliant with one POSIX standard without being compliant to the others. And ironically, neither Linux, OpenBSD, FreeBSD nor Darwin are fully POSIX compliant, merely "mostly" compliant. (Or at least, they haven't been certified as such.) Not that it matters much in practice. In any case, the minutia of POSIX versus Windows, the availability of drive letters and signals etc are utterly irrelevant to the question of what os.path.exists should do. Just as it ought to be utterly irrelevant that on Linux native C strings are null terminated. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From jfong at ms4.hinet.net Sun Jun 3 01:56:16 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Sun, 3 Jun 2018 13:56:16 +0800 Subject: How can an int be '+' with a tuple? In-Reply-To: References: Message-ID: <594f0110-26ca-e5a0-f61e-b51db2208b88@ms4.hinet.net> Forgive my ignorance of "*any" notation. I don't have real experience of using it in my codes so far, and didn't know those parameters were packed as a tuple:-( Steven D'Aprano ? 2018/6/3 ?? 01:08 ??: > On Sun, 03 Jun 2018 04:59:34 +0000, Steven D'Aprano wrote: > >> On Sun, 03 Jun 2018 10:55:04 +0800, Jach Fong wrote: >> >>> The attached is a script which can run under Python 3.4/Windows Vista >>> correctly. One thing make me puzzled is that the "any + context" at >>> line 18. The "any" was passed as an integer from line 43 and the >>> "context" was defined as a tuple at line 35. This concatenation works! >>> how? >> >> 90% of the script you attached is irrelevant to your question. None of >> the tkinter or threading code is important. The only important parts >> are: >> >> def threaded(action, args, context, onExit, onProgress): >> def progress(*any): >> threadQueue.put((onProgress, any + context)) >> >> Here we can tell that ``any`` is a tuple. > > Oops, I misread your question. You thought any was an int. But the * > (star) notation in function parameters makes the parameter collect any > unnamed arguments into a single tuple. > > def test(first, *args): > print(args) > > test(1, 2, 3, "hello", 99) > => prints the tuple (2, 3, "hello", 99) > > > --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From ben+python at benfinney.id.au Sun Jun 3 03:18:45 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 03 Jun 2018 17:18:45 +1000 Subject: How can an int be '+' with a tuple? References: Message-ID: <85tvqkibhm.fsf@benfinney.id.au> Jach Fong writes: > Yes, (I think) I know the *any usage, but don't know their type will be > changed after unpack? You are exhibiting a (very common! this is not a criticism) misunderstanding of how Python's data model and assignment work. An object in Python never changes type. Any name can be bound to any object, which may be why you are seeing changes in type; instead, follow the object, not the name. Leave behind anything you have brought from other languages about ?variables? or passing parameters to function parameters. Instead, understand how Python does them. You should work through the Python tutorial, from beginning to end, . ?Work through? means do the work of experimenting with the exercises until you understand them. To better understand names, type of an object, and binding a name to an object, see Ned Batchelder's presentation ?Facts and myths about Python names and values? . -- \ ?Our urge to trust our senses overpowers what our measuring | `\ devices tell us about the actual nature of reality.? ?Ann | _o__) Druyan, _Cosmos_, 2014 | Ben Finney From Cecil at decebal.nl Sun Jun 3 04:25:50 2018 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sun, 03 Jun 2018 10:25:50 +0200 Subject: ipython does not work with latest version of prompt-toolkit Message-ID: <87wovgz375.fsf@munus.decebal.nl> When executing: pip3 list --no-cache-dir --outdated I got: prompt-toolkit 1.0.15 2.0.1 wheel PyGObject 3.28.2 3.28.3 sdist youtube-dl 2018.5.30 2018.6.2 wheel So I executed: pip3 install --upgrade prompt-toolkit PyGObject youtube-dl This gave: Successfully installed PyGObject-3.28.3 prompt-toolkit-2.0.1 youtube-dl-2018.6.2 ipython 6.4.0 has requirement prompt-toolkit<2.0.0,>=1.0.15, but you'll have prompt-toolkit 2.0.1 which is incompatible. And when I now execute ipython3, I get: Traceback (most recent call last): File "/usr/local/bin/ipython3", line 7, in from IPython import start_ipython File "/usr/local/lib/python3.5/dist-packages/IPython/__init__.py", line 55, in from .terminal.embed import embed File "/usr/local/lib/python3.5/dist-packages/IPython/terminal/embed.py", line 16, in from IPython.terminal.interactiveshell import TerminalInteractiveShell File "/usr/local/lib/python3.5/dist-packages/IPython/terminal/interactiveshell.py", line 22, in from prompt_toolkit.shortcuts import create_prompt_application, create_eventloop, create_prompt_layout, create_output ImportError: cannot import name 'create_prompt_application' When I now execute: pip3 list --no-cache-dir --outdated I do not get output. So pip3 thinks everything is OK. How do I fix this? Or is the expected that ipython3 will be updated shortly? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From gamesland5108 at gmail.com Sun Jun 3 05:12:38 2018 From: gamesland5108 at gmail.com (gamesland5108 at gmail.com) Date: Sun, 3 Jun 2018 02:12:38 -0700 (PDT) Subject: add me Message-ID: <1f615fc7-2e99-4c51-ae13-4a4c45783371@googlegroups.com> i am saran. i want to learn python programming. From kwpolska at gmail.com Sun Jun 3 05:49:00 2018 From: kwpolska at gmail.com (Chris Warrick) Date: Sun, 3 Jun 2018 11:49:00 +0200 Subject: ipython does not work with latest version of prompt-toolkit In-Reply-To: <87wovgz375.fsf@munus.decebal.nl> References: <87wovgz375.fsf@munus.decebal.nl> Message-ID: On Sun, 3 Jun 2018 at 10:32, Cecil Westerhof wrote: > > When executing: > pip3 list --no-cache-dir --outdated > > I got: > prompt-toolkit 1.0.15 2.0.1 wheel > PyGObject 3.28.2 3.28.3 sdist > youtube-dl 2018.5.30 2018.6.2 wheel > > So I executed: > pip3 install --upgrade prompt-toolkit PyGObject youtube-dl > > This gave: > Successfully installed PyGObject-3.28.3 prompt-toolkit-2.0.1 youtube-dl-2018.6.2 > ipython 6.4.0 has requirement prompt-toolkit<2.0.0,>=1.0.15, but you'll have prompt-toolkit 2.0.1 which is incompatible. > > And when I now execute ipython3, I get: > Traceback (most recent call last): > File "/usr/local/bin/ipython3", line 7, in > from IPython import start_ipython > File "/usr/local/lib/python3.5/dist-packages/IPython/__init__.py", line 55, in > from .terminal.embed import embed > File "/usr/local/lib/python3.5/dist-packages/IPython/terminal/embed.py", line 16, in > from IPython.terminal.interactiveshell import TerminalInteractiveShell > File "/usr/local/lib/python3.5/dist-packages/IPython/terminal/interactiveshell.py", line 22, in > from prompt_toolkit.shortcuts import create_prompt_application, create_eventloop, create_prompt_layout, create_output > ImportError: cannot import name 'create_prompt_application' > > When I now execute: > pip3 list --no-cache-dir --outdated > > I do not get output. So pip3 thinks everything is OK. > > How do I fix this? Or is the expected that ipython3 will be updated > shortly? Start by reading the warning from pip: > ipython 6.4.0 has requirement prompt-toolkit<2.0.0,>=1.0.15, but you'll have prompt-toolkit 2.0.1 which is incompatible. To fix this, downgrade prompt-toolkit. `pip list --outdated` (not) having output isn?t a ?good? or ?bad? thing. prompt-toolkit v2 has changed its API from v1, and ipython doesn?t support the new one yet. Don?t randomly upgrade pip packages without knowing what the upgrade entails, especially if the version changed from 1.x to 2.x (x.y ? x+1.y) ? that usually means an API change and possible incompatibilities in dependent packages. Upgrading a tool like youtube-dl should be fine, and so should be a x.y.z ? x.y.z+1 upgrade, but it?s still best to know what you?re doing. -- Chris Warrick PGP: 5EAAEA16 From Cecil at decebal.nl Sun Jun 3 06:58:14 2018 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sun, 03 Jun 2018 12:58:14 +0200 Subject: ipython does not work with latest version of prompt-toolkit References: <87wovgz375.fsf@munus.decebal.nl> Message-ID: <87sh64yw55.fsf@munus.decebal.nl> Chris Warrick writes: > On Sun, 3 Jun 2018 at 10:32, Cecil Westerhof wrote: >> >> When executing: >> pip3 list --no-cache-dir --outdated >> >> I got: >> prompt-toolkit 1.0.15 2.0.1 wheel >> PyGObject 3.28.2 3.28.3 sdist >> youtube-dl 2018.5.30 2018.6.2 wheel >> >> So I executed: >> pip3 install --upgrade prompt-toolkit PyGObject youtube-dl >> >> This gave: >> Successfully installed PyGObject-3.28.3 prompt-toolkit-2.0.1 youtube-dl-2018.6.2 >> ipython 6.4.0 has requirement prompt-toolkit<2.0.0,>=1.0.15, but you'll have prompt-toolkit 2.0.1 which is incompatible. >> >> And when I now execute ipython3, I get: >> Traceback (most recent call last): >> File "/usr/local/bin/ipython3", line 7, in >> from IPython import start_ipython >> File "/usr/local/lib/python3.5/dist-packages/IPython/__init__.py", line 55, in >> from .terminal.embed import embed >> File "/usr/local/lib/python3.5/dist-packages/IPython/terminal/embed.py", line 16, in >> from IPython.terminal.interactiveshell import TerminalInteractiveShell >> File "/usr/local/lib/python3.5/dist-packages/IPython/terminal/interactiveshell.py", line 22, in >> from prompt_toolkit.shortcuts import create_prompt_application, create_eventloop, create_prompt_layout, create_output >> ImportError: cannot import name 'create_prompt_application' >> >> When I now execute: >> pip3 list --no-cache-dir --outdated >> >> I do not get output. So pip3 thinks everything is OK. >> >> How do I fix this? Or is the expected that ipython3 will be updated >> shortly? > > Start by reading the warning from pip: > >> ipython 6.4.0 has requirement prompt-toolkit<2.0.0,>=1.0.15, but >> you'll have prompt-toolkit 2.0.1 which is incompatible. > > To fix this, downgrade prompt-toolkit. `pip list --outdated` (not) > having output isn?t a ?good? or ?bad? thing. prompt-toolkit v2 has > changed its API from v1, and ipython doesn?t support the new one yet. I did not find a command to get all the existing versions. I solved it with uninstalling and then installing with: pip3 install 'prompt-toolkit>=1.0.15,<2.0.0' Is there a way to find the versions? It would be handy to install the 1.0.16 version if it comes out. > Don?t randomly upgrade pip packages without knowing what the upgrade > entails, especially if the version changed from 1.x to 2.x (x.y ? > x+1.y) ? that usually means an API change and possible > incompatibilities in dependent packages. Upgrading a tool like > youtube-dl should be fine, and so should be a x.y.z ? x.y.z+1 upgrade, > but it?s still best to know what you?re doing. Always checking would be a lot of work: I get several times a week several packages to update. If I would check them all I need a few hours more a week. I am used to systems that do not update when there is a conflict. But sadly pip does not work that way. :'-( But I could do the 'automatic' update only when x does not change. Or for specific packages like youtube-dl. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From tkadm30 at yandex.com Sun Jun 3 07:35:15 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Sun, 3 Jun 2018 07:35:15 -0400 Subject: Problem with pickle in zodb Message-ID: <300b486c-5085-9801-3be2-72ee424b9d79@yandex.com> Hi, Any ideas why this is happening ? erob at marina:/home/www/open-neurosecurity.org/trunk$ schevo editor zodb://127.0.0.1:4545 07:32:16 environ????????????? No en_CA translation found for domain kiwi 07:32:16 environ????????????? No en_CA translation found for domain gazpacho libschevo 4.0.1 :: Database Navigator () () > /home/erob/src/libschevo/lib/schevo/gtk2/window.py(295)database_open() -> self._db = schevo.database.open(db_alias) (Pdb) n zodb://127.0.0.1:4545 127.0.0.1:4545 Found epoll library, good! /home/erob/src/libschevo/lib/schevo/backends/zodb.py:7: RuntimeWarning: Patching more than once will result in the union of all True parameters being patched ? patch_all(thread=True) 07:32:23 ZEO.asyncio.marshal? can't decode message: '\x80\x03(K\x01K\x00U\x06.replyU\x08\x03\xc7\xf6]\xe0\xd...' 07:32:23 ZEO.asyncio.base???? data_received 4 0 True Traceback (most recent call last): ? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/base.py", line 128, in data_received ??? self.message_received(collected) ? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", line 206, in message_received ??? msgid, async, name, args = self.decode(data) ? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/marshal.py", line 91, in pickle_decode ??? return unpickler.load() # msgid, flags, name, args ValueError: unsupported pickle protocol: 3 07:32:52 ZEO.asyncio.client?? Registration or cache validation failed, Closed Traceback (most recent call last): ? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", line 188, in finish_connect ??? *credentials) ClientDisconnected: Closed ClientDisconnected: ClientDi...ection',) Thank you in advance, Etienne From cousinstanley at gmail.com Sun Jun 3 10:08:14 2018 From: cousinstanley at gmail.com (Cousin Stanley) Date: Sun, 03 Jun 2018 07:08:14 -0700 Subject: How to move the scrollbar to inside the text widget References: <396cffe2-4441-4358-8294-7f57e2e03eb4@googlegroups.com> Message-ID: moideen50 at gmail.com wrote: > I am a Newbie > > I have this code > > from tkinter import * > > root = Tk() > root.geometry("1200x1000+30+30") > # width x height + x_offset + y_offset: > T = Text(root, height=10, width=100) > T.place(x=20, y=30) > for i in range(40): > T.insert(END, "This is line %d\n" % i) > > # create a vertical scrollbar to the right of the listbox > yscroll = Scrollbar(command=T.yview, orient=VERTICAL) > T.configure(yscrollcommand=yscroll.set) > yscroll.pack(side="right", fill="y", expand=False) > > root.mainloop() > > > The srollbar is on the window frame, is there a way I can move it to inside and right edge of > text area? > > Thanks You might try the tkinter ScrolledText widget .... .................................................... from tkinter import * from tkinter import scrolledtext as ST root = Tk() root.geometry( "1200x1000+30+30" ) # width x height + x_offset + y_offset T = ST.ScrolledText( root, height=40, width=100, font=( 'Fixed' , 14 ) ) T.place( x = 20 , y = 30 ) for i in range( 101 ) : T.insert( END , " This is line %03d\n" % i ) ..................................... include the rest of your orignal code ..................................... -- Stanley C. Kitching Human Being Phoenix, Arizona From hjp-python at hjp.at Sun Jun 3 14:20:32 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 3 Jun 2018 20:20:32 +0200 Subject: Attachments (was: How can an int be '+' with a tuple?) In-Reply-To: <85zi0cikt5.fsf@benfinney.id.au> References: <85zi0cikt5.fsf@benfinney.id.au> Message-ID: <20180603182032.i4k7x47bdteuntg2@hjp.at> On 2018-06-03 13:57:26 +1000, Ben Finney wrote: > (For good reasons, attachments are dropped when messages are distributed > on the forum.) By "the forum" you mean Gmane? (I got the attachment over the mailing list) 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 jlee54 at gmail.com Sun Jun 3 15:54:51 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 3 Jun 2018 12:54:51 -0700 Subject: tkinter (ttk) combobox dropdown text is white on white Message-ID: <645f9cc9-4bac-010f-460c-941160f575a4@gmail.com> Given the following snippet (Python 3.6.5, Tk 8.6.8): import tkinter as tk from tkinter import ttk root = tk.Tk() cb = ttk.Combobox(root) cb.grid(row=0, column=0, sticky='NSEW') cb['values'] = ['one', 'two', 'three', 'four'] root.mainloop() The text of the values in the combobox dropdown list is white on white.?? The *selected* item in the list is white on light grey, but all the unselected items are invisible (white on white).? I have played with themes and styles, and can alter the foreground and background colors of the combobox itself, but I cannot figure out how to alter the appearance of entries in the dropdown list. Any pointers? Thanks, -Jim Lee From auriocus at gmx.de Sun Jun 3 17:01:40 2018 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 3 Jun 2018 23:01:40 +0200 Subject: tkinter (ttk) combobox dropdown text is white on white In-Reply-To: References: <645f9cc9-4bac-010f-460c-941160f575a4@gmail.com> Message-ID: Am 03.06.18 um 21:54 schrieb Jim Lee:> import tkinter as tk > from tkinter import ttk > > root = tk.Tk() > cb = ttk.Combobox(root) > cb.grid(row=0, column=0, sticky='NSEW') > cb['values'] = ['one', 'two', 'three', 'four'] > root.mainloop() > > The text of the values in the combobox dropdown list is white on > white.?? The *selected* item in the list is white on light grey, but all > the unselected items are invisible (white on white). Which platform are you on, i.e. which operating system? I guess it is Linux. In that case the default colors are read by Tk from the X11 options database, which is some cruft from the past to set options for X11 applications. Try to run xrdb -query That should give you a list of default values, and maybe you can see something. The dropdown list is actually a popdown menu, so look for Menu colors. For instance, if you use a dark theme in your desktop environment, it could be that the foreground is correctly set to white, but the background is hardcoded white for some reason e.g. Christian From bellcanadardp at gmail.com Sun Jun 3 19:36:12 2018 From: bellcanadardp at gmail.com (bellcanadardp at gmail.com) Date: Sun, 3 Jun 2018 16:36:12 -0700 (PDT) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <27ef2bfb-e3ed-495c-bb98-f71e502d412a@googlegroups.com> <20180520134354.GB2192@hermes.hilbert.loc> <20180522212337.cvtbh32tydvaft4r@hjp.at> Message-ID: On Tuesday, 22 May 2018 17:23:55 UTC-4, Peter J. Holzer wrote: > On 2018-05-20 15:43:54 +0200, Karsten Hilbert wrote: > > On Sun, May 20, 2018 at 04:59:12AM -0700, bellcanadardp at gmail.com wrote: > > > > > On Saturday, 19 May 2018 19:48:20 UTC-4, Skip Montanaro wrote: > > > > As Chris indicated, you'll have to figure out the correct encoding. You > > > > might want to check out the chardet module (available on PyPI, I believe) > > > > and see if it can come up with a better guess. I imagine there are other > > > > encoding guessers out there. That's just one I'm familiar with. > > > > > > thank you for the reply, but how exactly am i supposed to find oout what is the correct encodeing?? > > > > One CAN NOT. > > > > The best you can do is to go ask the canonical source of the > > file what encoding the file is _supposed_ to be in. > > I disagree on both counts. > > 1) For any given file it is almost always possible to find the correct > encoding (or *a* correct encoding, as there may be more than one). > > This may require domain-specific knowledge (e.g. it may be necessary > to recognize the human language and know at least some distinctive > words, or to know some special symbols likely to be used in a data > file), and it almost always takes a bit of detective work and trial > and error. But I don't think I ever encountered a file where I > couldn't figure out the encoding. > > (If you have several files in the same encoding, it may not be > possible to figure out the encoding from a subset of them. For > example, the files may all be in ISO-8859-2, but the subset you have > contains only characters <= 0x7F. But if you have several files, they > may not all be the same encoding, either). > > 2) The canonical source of the file may not know. This is quite frequent > when the source is some non-technical person. Then you get answers > like "it's ASCII" (although the file contains umlauts, which aren't > in ASCII) or "it's ANSI" (which isn't an encoding, although Windows > pretends it is). Or they may not be aware that the file is converted > somewhere in the pipeline, to that the file they generated isn't > actually the file you received. So ask (or check the docs), but > verify! > > 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 hello peter ...how exactly would i solve this issue .....i have a script that works in python 2 but not pytho3..i did 2 to 3.py ...but i still get the errro...character undefieed..unicode decode error cant decode byte 1x09 in line 7414 from cp 1252..like would you have a sraright solution answer??..i cant get a straight answer..it was ported from ansi to python...so its utf-8 as far asi can see From steve+comp.lang.python at pearwood.info Sun Jun 3 20:09:01 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 4 Jun 2018 00:09:01 +0000 (UTC) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <27ef2bfb-e3ed-495c-bb98-f71e502d412a@googlegroups.com> <20180520134354.GB2192@hermes.hilbert.loc> <20180522212337.cvtbh32tydvaft4r@hjp.at> Message-ID: On Sun, 03 Jun 2018 16:36:12 -0700, bellcanadardp wrote: > hello peter ...how exactly would i solve this issue .....i have a script > that works in python 2 but not pytho3..i did 2 to 3.py ...but i still > get the errro...character undefieed..unicode decode error cant decode > byte 1x09 in line 7414 from cp 1252..like would you have a sraright > solution answer??..i cant get a straight answer..it was ported from ansi > to python...so its utf-8 as far asi can see You won't get a straight answer because you won't tell us *precisely* what is happening. Don't retype a summary of what you think the error is. "character undefieed" is not a thing, and there is no such thing as "byte 1x09". You need to COPY AND PASTE the EXACT error that you get. Not just the last line, the error message, but the FULL TRACEBACK starting from the line "Traceback" and going to the end. Until you do that, we cannot give you a straight answer. You also need to COPY AND PASTE the EXACT line of code that gives the error, plus enough code so that it works. For a file read error, that probably means code that opens the file, and then tries to read from it. Until you do that, we cannot give you a straight answer. You need to tell us what version of Python you are using, and the operating system. You should read this: http://sscce.org/ Even though it is written for Java programmers, it applies to Python to. If you think that your file is UTF-8, why are you using CP-1252 to read the file? https://en.wikipedia.org/wiki/Windows-1252 https://en.wikipedia.org/wiki/UTF-8 I recommend you start with reading this if you haven't already: https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every- software-developer-absolutely-positively-must-know-about-unicode-and- character-sets-no-excuses/ Sorry for the huge URL, try this if your mail client breaks it: https://tinyurl.com/h8yg9d7 Until you read that, you will probably remain confused about text encodings and Unicode and will probably not understand the straight answer we give you. Also read: https://nedbatchelder.com/text/unipain.html -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From jfong at ms4.hinet.net Sun Jun 3 20:18:42 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Mon, 4 Jun 2018 08:18:42 +0800 Subject: What is the "Unpacking Arguments List" rule? Message-ID: <961e9bc2-59c3-f4fd-c35c-b6893988963f@ms4.hinet.net> I had read "More on Defining Functions" sections of "The Python Tutorial" carefully yesterday. One thing in the example code(Re: How can an int be '+' with a tuple?) puzzles me again. It's the line 19: .... def progress(*any): threadQueue.put((onProgress, any + context)) action(progress=progress, *args) # line 19, it calls threadaction function .... def threadaction(id, reps, progress): .... """ below was quoted from the document 4.7.2. Keyword Arguments ... def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'): ... but all the following calls would be invalid: ... parrot(voltage=5.0, 'dead') # non-keyword argument after a keyword argument ... 4.7.3. Arbitrary Argument Lists ... def write_multiple_items(file, separator, *args): ... Normally, these variadic arguments will be last in the list of formal parameters, because they scoop up all remaining input arguments that are passed to the function. ... 4.7.4. Unpacking Argument Lists The reverse situation occurs when the arguments are already in a list or tuple but need to be unpacked for a function call requiring separate positional arguments. ... >>> args = [3, 6] >>> list(range(*args)) """ I can't understand why line 19 works? Didn't it violate the rule of "# non-keyword argument after a keyword argument"? and why a more reasonable look syntax gets an error? action(*args, progress) ^ SyntaxError: only named arguments may follow *expression File "test.py", line 19 The only reason I can guess is that it checks with the rule in 4.7.3 which is really unrelated. The "*any" notation used in different places with different meaning, such as defining arbitrary argument, unpacking argument or even in an assignment(a,*b=any). Maybe it will be better to stop this syntax checking and lets both statements below valid:-) action(progress=progress, *args) action(*args, progress) Best Regards, Jach Fong --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From tkadm30 at yandex.com Mon Jun 4 04:24:35 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Mon, 4 Jun 2018 04:24:35 -0400 Subject: [ZODB] Problem with pickle in zodb In-Reply-To: <5289914C-745F-4374-8905-9CB31D6457ED@nextthought.com> References: <300b486c-5085-9801-3be2-72ee424b9d79@yandex.com> <5289914C-745F-4374-8905-9CB31D6457ED@nextthought.com> Message-ID: Yup, that is correct! Thanks. :-) Etienne Le 2018-06-03 ? 07:39, Jason Madden a ?crit?: > You appear to have mismatched versions of ZEO on the client and server, 5.2 on one side and 5.1.0 on the other. Both need to be 5.2. > >> On Jun 3, 2018, at 06:35, Etienne Robillard wrote: >> >> Hi, >> >> Any ideas why this is happening ? >> >> erob at marina:/home/www/open-neurosecurity.org/trunk$ schevo editor zodb://127.0.0.1:4545 >> 07:32:16 environ No en_CA translation found for domain kiwi >> 07:32:16 environ No en_CA translation found for domain gazpacho >> libschevo 4.0.1 :: Database Navigator () >> () >>> /home/erob/src/libschevo/lib/schevo/gtk2/window.py(295)database_open() >> -> self._db = schevo.database.open(db_alias) >> (Pdb) n >> zodb://127.0.0.1:4545 >> 127.0.0.1:4545 >> Found epoll library, good! >> /home/erob/src/libschevo/lib/schevo/backends/zodb.py:7: RuntimeWarning: Patching more than once will result in the union of all True parameters being patched >> patch_all(thread=True) >> 07:32:23 ZEO.asyncio.marshal can't decode message: '\x80\x03(K\x01K\x00U\x06.replyU\x08\x03\xc7\xf6]\xe0\xd...' >> 07:32:23 ZEO.asyncio.base data_received 4 0 True >> Traceback (most recent call last): >> File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/base.py", line 128, in data_received >> self.message_received(collected) >> File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", line 206, in message_received >> msgid, async, name, args = self.decode(data) >> File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/marshal.py", line 91, in pickle_decode >> return unpickler.load() # msgid, flags, name, args >> ValueError: unsupported pickle protocol: 3 >> 07:32:52 ZEO.asyncio.client Registration or cache validation failed, Closed >> Traceback (most recent call last): >> File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", line 188, in finish_connect >> *credentials) >> ClientDisconnected: Closed >> ClientDisconnected: ClientDi...ection',) >> >> > -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From barry at barrys-emacs.org Mon Jun 4 06:16:21 2018 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 4 Jun 2018 11:16:21 +0100 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: > On 1 Jun 2018, at 14:23, Paul Moore wrote: > > On 1 June 2018 at 13:15, Barry Scott wrote: >> I think the reason for the \0 check is that if the string is passed to the >> operating system with the \0 you can get surprising results. >> >> If \0 was not checked for you would be able to get True from: >> >> os.file.exists('/home\0ignore me') >> >> This is because a posix system only sees '/home'. Turns out that this is a limitation on Windows as well. The \0 is not allowed for Windows, macOS and Posix. > > So because the OS API can't handle filenames with \0 in (because that > API uses null-terminated strings) Python has to special case its > handling of the check. That's fine. > >> Surely ValueError is reasonable? > > Well, if the OS API can't handle filenames with embedded \0, we can be > sure that such a file doesn't exist - so returning False is > reasonable. I think most of the file APIs check for \0 and raise ValueError on python3 and TypeError on python2. os.path.exists() is not special and I don't think should be be changed. > >> Once you know that all of the string you provided is given to the operating >> system it can then do whatever checks it sees fit to and return a suitable >> result. > > As the programmer, I don't care. The Python interpreter should take > care of that for me, and if I say "does file 'a\0b' exist?" I want an > answer. And I don't see how anything other than "no it doesn't" is > correct. Python allows strings with embedded \0 characters, so it's > possible to express that question in Python - os.path.exists('a\0b'). > What can be expressed in terms of the low-level (C-based) operating > system API shouldn't be relevant. > > Disclaimer - the Python "os" module *does* expose low-level > OS-dependent functionality, so it's not necessarily reasonable to > extend this argument to other functions in os. But it seems like a > pretty solid argument in this particular case. > >> As an aside Windows has lots of special filenames that you have to know about >> if you are writting robust file handling. AUX, COM1, \this\is\also\COM1 etc. > > I don't think that's relevant in this context. I think it is. This started because the OP was surprised that they needed to check for \0. There are related surprised waiting. I'm point out that its more then \0 a robust piece of code will need to consider. Barry From hjp-python at hjp.at Mon Jun 4 06:26:13 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 4 Jun 2018 12:26:13 +0200 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <27ef2bfb-e3ed-495c-bb98-f71e502d412a@googlegroups.com> <20180520134354.GB2192@hermes.hilbert.loc> <20180522212337.cvtbh32tydvaft4r@hjp.at> Message-ID: <20180604102613.3eumk55f3h7hzoaq@hjp.at> On 2018-06-03 16:36:12 -0700, bellcanadardp at gmail.com wrote: > On Tuesday, 22 May 2018 17:23:55 UTC-4, Peter J. Holzer wrote: > > On 2018-05-20 15:43:54 +0200, Karsten Hilbert wrote: > > > On Sun, May 20, 2018 at 04:59:12AM -0700, bellcanadardp at gmail.com wrote: > > > > thank you for the reply, but how exactly am i supposed to find > > > > oout what is the correct encodeing?? > > > > > > One CAN NOT. > > > > > > The best you can do is to go ask the canonical source of the > > > file what encoding the file is _supposed_ to be in. > > > > I disagree on both counts. > > > > 1) For any given file it is almost always possible to find the correct > > encoding (or *a* correct encoding, as there may be more than one). > > > > This may require domain-specific knowledge (e.g. it may be necessary > > to recognize the human language and know at least some distinctive > > words, or to know some special symbols likely to be used in a data > > file), and it almost always takes a bit of detective work and trial > > and error. But I don't think I ever encountered a file where I > > couldn't figure out the encoding. [...] > > hello peter ...how exactly would i solve this issue ..... There is no "exactly" here. Determining the encoding of a file depends on experience and trial and error. However, I can give you some general guide lines: Preparation: Make sure you have a way to reliably display files: 1) As a stream of bytes. On Linux hd works well for this purpose, although a hex editor might be even better 2) As a unicode text. On Linux terminal emulators usually use UTF-8 encoding, so viewing a file with less should be sufficient. Beware of programs which try to guess the encoding. They can fool you. If you don't have anything which works reliably you might want to have a look at my utf8dump script (https://www.hjp.at/programs/utf8dump/ (Perl code, sorry ;-)). First guess: As has already been mentioned, chardet usually does a good job. So first let chardet guess the encoding. Then use iconv to convert from this encoding to UTF-8 (or any other UTF you can reliably read) and open it in your text reader (preparation step 2 above) to check whether the result makes sense. If it does, you are done. Checking other encodings: This is where it gets tedious. You could systematically try all encodings supported by iconv, but there are a lot of them (over 1000!). So you should try to narrow it down: What language is the file in? On what OS was the file (probably) created? If most of the non-ascii characters are already correct, but a few are wrong, what other encodings are there in the same family? But however you determined the list of candidate encodings, the actual check is the same as above: Use iconv to convert from the candidate encoding and check the result for plausibility. Use the encoding in your program: When you are done, open the file in your with open(..., encoding='...') with the encoding you determined above. > i have a script that works in python 2 but not pytho3..i did 2 to 3.py > ...but i still get the errro...character undefieed..unicode decode > error cant decode byte 1x09 in line 7414 from cp 1252..like would you > have a sraright solution answer??..i cant get a straight answer..it > was ported from ansi to python...so its utf-8 as far asi can see If it is utf-8, just open the file with open(filename, encoding="utf-8") (or open(filename, encoding="utf-8-sig"), if it starts with a BOM). And follow Steven's advice and read all the stuff he mentioned. It is important to have a firm understanding of what "character", "byte", "encoding" etc. mean. If you understand that, the rest is easy (sometimes tedious, but not difficult). If you don't understand that, you can only resort to try and error and will be continuously baffled by unexpected results. 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 steve+comp.lang.python at pearwood.info Mon Jun 4 08:01:17 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 4 Jun 2018 12:01:17 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: On Mon, 04 Jun 2018 11:16:21 +0100, Barry Scott wrote: [...] > Turns out that this is a limitation on Windows as well. The \0 is not > allowed for Windows, macOS and Posix. We -- all of us, including myself -- have been terribly careless all through this discussion. The fact is, this should not be an OS limitation at all. It is a *file system* limitation. If I can mount a HFS or HFS-Plus disk on Linux, it can include file names with embedded NULs or slashes. (Only the : character is illegal in HFS file names.) It shouldn't matter what the OS is, if I have drivers for HFS and can mount a HFS disk, I ought to be able to sensibly ask for file names including NUL. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From marko at pacujo.net Mon Jun 4 08:26:10 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 04 Jun 2018 15:26:10 +0300 Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: <87po16g2l9.fsf@elektro.pacujo.net> Barry Scott : > os.path.exists() is not special and I don't think should be be changed. You are right that os.path.exists() might be logically tied to other os.* facilities. The question is, should the application be cognizant of the seam between the standard library and the operating system kernel? When a Linux system call contains an illegal value, it responds with errno=EINVAL. In Python, that's represented by the OSError exception with e.errno=EINVAL. However, when Python encounters an illegal value itself, it usually raises a ValueError. Is it useful for the application to have to be prepared for OSError/EINVAL and ValueError separately? Or should the difference be paved over by Python? As it stands, os.path.exists() really means: the operating system doesn't have a reason to fail os.stat() on the pathname. Python intercedes with an exception if it can't even ask the operating system for its opinion. That dichotomy is not suggested by the os.path.exists() documentation. In fact, the whole point of os.path.* is to provide for an abstraction to isolate the application from the intricacies of the operating system specifics. BTW, I challenge you to find a test case that tests the proper behavior of an application if it encounters a pathname with a NUL in it. Or code that gracefully catches a ValueError from os.path.exists(). Marko From p.f.moore at gmail.com Mon Jun 4 08:33:28 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 4 Jun 2018 13:33:28 +0100 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: On 4 June 2018 at 13:01, Steven D'Aprano wrote: >> Turns out that this is a limitation on Windows as well. The \0 is not >> allowed for Windows, macOS and Posix. > > We -- all of us, including myself -- have been terribly careless all > through this discussion. The fact is, this should not be an OS limitation > at all. It is a *file system* limitation. > > If I can mount a HFS or HFS-Plus disk on Linux, it can include file names > with embedded NULs or slashes. (Only the : character is illegal in HFS > file names.) It shouldn't matter what the OS is, if I have drivers for > HFS and can mount a HFS disk, I ought to be able to sensibly ask for file > names including NUL. Agreed, being completely precise in this situation is both pretty complicated, and essential. The question of what are legal characters in a filename is, as you say, a filesystem related issue. People traditionally forget this point, but in these days of cross-platform filesystem mounting, networked filesystems[1], etc, it's more and more relevant, and thankfully people are getting more aware of the point. But there's also the question of what capability the kernel API has to express the queries. The fact that the Unix API (and the Windows one, in most cases - although as Eryk Sun pointed out there are exceptions in the Windows kernel API) uses NUL-terminated strings means that querying the filesystem about filenames with embedded \0 characters isn't possible *at the OS level*. (As another example, the fact that the Unix kernel treats filenames as byte strings means that there are translation issues querying an NTFS filesystem that uses Unicode (UTF-16) natively - and vice versa when Windows queries a Unix-native filesystem). So "it's complicated" is about the best we can say :-) Paul [1] And of course if you mount (say) an NTFS filesystem over NFS, you have *two* filesystems involved, each adding its own layer of restrictions and capabilities. From mal at europython.eu Mon Jun 4 09:21:20 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Mon, 4 Jun 2018 15:21:20 +0200 Subject: EuroPython 2018: Looking for a photographer Message-ID: <1c3720c7-4ae0-7eb1-ff6b-e89922cae592@europython.eu> At last year?s event, we had a professional conference photographer, Alessia Peviani, from our community, help us cover the event in pictures. https://ep2017.europython.eu/en/europython/photos/ This year she unfortunately cannot attend, so we?re looking for help from other photographers in the community. Here?s what we can offer: ------------------------- * recognition and publicity by listing you as the official EuroPython conference photographer * free tickets for the conference and trainings * refund for travel and accommodation up to EUR 500 * gratitude by our attendees who really appreciate having this kind of documentation available What we are asking for: ----------------------- * cover all aspects of the conference in photos * photos licensed under the CC BY-NC license, with a special exception for the EPS, so that we can use the photos for promoting the conference * self-management and help with administering the Flickr group, uploads by other community photographers and discussions If you are interested in helping us, please write to media at europython.eu. 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/174564294432/europython-2018-looking-for-a-photographer Tweet: https://twitter.com/europython/status/1003627195460390914 Enjoy, -- EuroPython 2018 Team https://ep2018.europython.eu/ https://www.europython-society.org/ From steve+comp.lang.python at pearwood.info Mon Jun 4 09:23:59 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 4 Jun 2018 13:23:59 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: On Mon, 04 Jun 2018 13:33:28 +0100, Paul Moore wrote: > But there's also the question of what capability the kernel API has to > express the queries. The fact that the Unix API (and the Windows one, in > most cases - although as Eryk Sun pointed out there are exceptions in > the Windows kernel API) uses NUL-terminated strings means that querying > the filesystem about filenames with embedded \0 characters isn't > possible *at the OS level*. I don't know whether or not the Linux OS is capable of accessing files with embedded NULs in the file name. But Mac OS is capable of doing so, so it should be possible. Wikipedia says: "HFS Plus mandates support for an escape sequence to allow arbitrary Unicode. Users of older software might see the escape sequences instead of the desired characters." Apple File System is an even more modern FS (it replaced HFS Plus in 2017 as Apple's preferred OS) which supports all Unicode code points, including NUL. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From D.Strohl at F5.com Mon Jun 4 09:54:27 2018 From: D.Strohl at F5.com (Dan Strohl) Date: Mon, 4 Jun 2018 13:54:27 +0000 Subject: Indented multi-line strings In-Reply-To: References: <9bf0783c8b044b348769942bda950043@F5.com> <20180523162535.xbtqnxi7yqv4ijlg@hjp.at> <20180529091919.xxr7rt5yoplwdge6@hjp.at> <20180530224733.6qai7jsw4bknkukr@hjp.at> <48620ae1be64499abf9baf065273e4c3@F5.com> <889761ba-616e-7825-bbbe-a026e2853820@mrabarnett.plus.com> <20180531211610.mafcf6kjfadog777@hjp.at> Message-ID: <6921a59d6f3a4e7fba040b8c3cb8c4a4@F5.com> > > > No-one is saying a method is *worse* than a standalone function - they are > just saying it's *not sufficiently better* to justify creating a string method that > replicates an existing stdlib function. > What about performance? I would expect a string method to perform better than a stdlib function. (no?) Especially if it's something that could be used commonly it seems like having that function be of higher performance would be a benefit? At least for me, when I do use this, it's often in places like logging where it could well be called a lot. Dan From bgailer at gmail.com Mon Jun 4 10:05:53 2018 From: bgailer at gmail.com (Bob Gailer) Date: Mon, 4 Jun 2018 10:05:53 -0400 Subject: add me In-Reply-To: <1f615fc7-2e99-4c51-ae13-4a4c45783371@googlegroups.com> References: <1f615fc7-2e99-4c51-ae13-4a4c45783371@googlegroups.com> Message-ID: On Jun 3, 2018 10:12 AM, wrote: > > i am saran. i want to learn python programming. Welcome. In future please use the python tutor email list - it is there to provide guidance. Go to the python. Org website - look for tutorials. That's the best place to start. From grant.b.edwards at gmail.com Mon Jun 4 10:11:19 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 4 Jun 2018 14:11:19 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On 2018-06-03, Gregory Ewing wrote: > Steven D'Aprano wrote: >> Do you really mean to say that a computer that won't boot is POSIX >> compliant? > > No, I was pointing out the absurdity of saying that the Windows > kernel layer is POSIX compliant, which is what the post I was > replying to seemed to be saying. The normal Win32 API that all Windows apps use is not Posix compliant. However, there is an API layer Microsoft provides (or provided) that is/was Posix compliant. At one point, I think it was an add-on that had to be purchased seperately. I've never heard of anybody actually _using_ it, but it allowed some US government purchasing droid to check the "Posix Compliant" box on an acquisition checklist back in the 90's. -- Grant Edwards grant.b.edwards Yow! But they went to MARS at around 1953!! gmail.com From rosuav at gmail.com Mon Jun 4 10:14:12 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jun 2018 00:14:12 +1000 Subject: Indented multi-line strings In-Reply-To: <6921a59d6f3a4e7fba040b8c3cb8c4a4@F5.com> References: <9bf0783c8b044b348769942bda950043@F5.com> <20180523162535.xbtqnxi7yqv4ijlg@hjp.at> <20180529091919.xxr7rt5yoplwdge6@hjp.at> <20180530224733.6qai7jsw4bknkukr@hjp.at> <48620ae1be64499abf9baf065273e4c3@F5.com> <889761ba-616e-7825-bbbe-a026e2853820@mrabarnett.plus.com> <20180531211610.mafcf6kjfadog777@hjp.at> <6921a59d6f3a4e7fba040b8c3cb8c4a4@F5.com> Message-ID: On Mon, Jun 4, 2018 at 11:54 PM, Dan Strohl wrote: >> > >> No-one is saying a method is *worse* than a standalone function - they are >> just saying it's *not sufficiently better* to justify creating a string method that >> replicates an existing stdlib function. >> > > What about performance? I would expect a string method to perform better than a stdlib function. (no?) Especially if it's something that could be used commonly it seems like having that function be of higher performance would be a benefit? > > At least for me, when I do use this, it's often in places like logging where it could well be called a lot. > Considering that a method on a string literal is a plausible candidate for constant folding, it most definitely could perform better; it could perform as well as the string literal itself does. ChrisA From pkpearson at nowhere.invalid Mon Jun 4 12:34:08 2018 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 4 Jun 2018 16:34:08 GMT Subject: Attachments (was: How can an int be '+' with a tuple?) References: <85zi0cikt5.fsf@benfinney.id.au> <20180603182032.i4k7x47bdteuntg2@hjp.at> Message-ID: On Sun, 3 Jun 2018 20:20:32 +0200, Peter J. Holzer wrote: [snip] > On 2018-06-03 13:57:26 +1000, Ben Finney wrote: >> (For good reasons, attachments are dropped when messages are distributed >> on the forum.) > > By "the forum" you mean Gmane? (I got the attachment over the mailing > list) Comp.lang.python is a usenet newsgroup, also accessible through a mailing list (and, I think, a web interface). NNTP, the Network News Transfer Protocol, does not provide for attachments. From hjp-python at hjp.at Mon Jun 4 16:13:47 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 4 Jun 2018 22:13:47 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: <20180604201347.c56ffpeezycoo6ij@hjp.at> On 2018-06-04 13:23:59 +0000, Steven D'Aprano wrote: > On Mon, 04 Jun 2018 13:33:28 +0100, Paul Moore wrote: > > But there's also the question of what capability the kernel API has to > > express the queries. The fact that the Unix API (and the Windows one, in > > most cases - although as Eryk Sun pointed out there are exceptions in > > the Windows kernel API) uses NUL-terminated strings means that querying > > the filesystem about filenames with embedded \0 characters isn't > > possible *at the OS level*. > > I don't know whether or not the Linux OS is capable of accessing files > with embedded NULs in the file name. But Mac OS is capable of doing so, > so it should be possible. Wikipedia says: > > "HFS Plus mandates support for an escape sequence to allow arbitrary > Unicode. Users of older software might see the escape sequences instead > of the desired characters." I don't know about MacOS. In Linux there is no way to pass a filename with an embedded '\0' (or a '/' which is not path separator) between the kernel and user space. So if a filesystem contained such a filename, the kernel would have to map it (via an escape sequence or some other mechanism) to a different file name. Which of course means that - from the perspective of any user space process - the filename doesn't contain a '\0' or '/'. Theoretically that mapping could be reversed in the standard library of a language which allows '\0' in strings (like Python), but since that would mean that programs written in that language see different filenames than programs written in other languages (especially C, which covers the majority of the GNU command line tools), this would be a very bad idea. Much better to have strange but consistent filenames if you mount a "foreign" file system. (This is btw also what Samba does, although it does a spectacularly bad job). 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 hjp-python at hjp.at Mon Jun 4 16:37:16 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 4 Jun 2018 22:37:16 +0200 Subject: Attachments In-Reply-To: References: <85zi0cikt5.fsf@benfinney.id.au> <20180603182032.i4k7x47bdteuntg2@hjp.at> Message-ID: <20180604203716.iq4v5hhfstgj734v@hjp.at> On 2018-06-04 16:34:08 +0000, Peter Pearson wrote: > On Sun, 3 Jun 2018 20:20:32 +0200, Peter J. Holzer wrote: > > On 2018-06-03 13:57:26 +1000, Ben Finney wrote: > >> (For good reasons, attachments are dropped when messages are distributed > >> on the forum.) > > > > By "the forum" you mean Gmane? (I got the attachment over the mailing > > list) > > Comp.lang.python is a usenet newsgroup, also accessible through a mailing > list (and, I think, a web interface). NNTP, the Network News Transfer > Protocol, does not provide for attachments. This is not true. NNTP doesn't care about the content of the message at all (as long as it contains the few mandatory headers). As a case in point, Jach Fong's message got here fine (including the attachment) via this path: news.luga.at!news.albasani.net!eternal-september.org!feeder.eternal-september.org!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail So it was 6 or 7 times transmitted via NNTP with the attachment intact. There is a rather strong *convention* to avoid attachments in many news hierarchies (comp.* being one of them), and some newsservers may filter them. But clearly none of the 7 newsservers mentioned above does this, at least not for *text* attachments (they might do it for binary attachments). So we have determined that "the forum" is not the mailing list and not the newsgroup (Jach's message appeared on both with the attachment). Ben uses Gmane, which makes it likely that he is talking about a (mis)feature of Gmane, hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From __peter__ at web.de Mon Jun 4 16:59:52 2018 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Jun 2018 22:59:52 +0200 Subject: Attachments References: <85zi0cikt5.fsf@benfinney.id.au> <20180603182032.i4k7x47bdteuntg2@hjp.at> <20180604203716.iq4v5hhfstgj734v@hjp.at> Message-ID: Peter J. Holzer wrote: > On 2018-06-04 16:34:08 +0000, Peter Pearson wrote: >> On Sun, 3 Jun 2018 20:20:32 +0200, Peter J. Holzer >> wrote: >> > On 2018-06-03 13:57:26 +1000, Ben Finney wrote: >> >> (For good reasons, attachments are dropped when messages are >> >> distributed on the forum.) >> > >> > By "the forum" you mean Gmane? (I got the attachment over the mailing >> > list) >> >> Comp.lang.python is a usenet newsgroup, also accessible through a mailing >> list (and, I think, a web interface). NNTP, the Network News Transfer >> Protocol, does not provide for attachments. > > This is not true. NNTP doesn't care about the content of the message at > all (as long as it contains the few mandatory headers). As a case in > point, Jach Fong's message got here fine (including the attachment) via > this path: > news.luga.at!news.albasani.net!eternal-september.org!feeder.eternal- september.org!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail > So it was 6 or 7 times transmitted via NNTP with the attachment intact. > > There is a rather strong *convention* to avoid attachments in many news > hierarchies (comp.* being one of them), and some newsservers may filter > them. But clearly none of the 7 newsservers mentioned above does this, > at least not for *text* attachments (they might do it for binary > attachments). > > So we have determined that "the forum" is not the mailing list and not > the newsgroup (Jach's message appeared on both with the attachment). Ben > uses Gmane, which makes it likely that he is talking about a > (mis)feature of Gmane, However, I did see that particular particular attachment, test.py in Jach's original post, and I'm reading c.l.py via gmane. > > hp > From hjp-python at hjp.at Mon Jun 4 17:14:35 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 4 Jun 2018 23:14:35 +0200 Subject: Attachments In-Reply-To: References: <85zi0cikt5.fsf@benfinney.id.au> <20180603182032.i4k7x47bdteuntg2@hjp.at> <20180604203716.iq4v5hhfstgj734v@hjp.at> Message-ID: <20180604211435.ngdmlt2mfvda53mg@hjp.at> On 2018-06-04 22:59:52 +0200, Peter Otten wrote: > Peter J. Holzer wrote: > > On 2018-06-04 16:34:08 +0000, Peter Pearson wrote: > >> On Sun, 3 Jun 2018 20:20:32 +0200, Peter J. Holzer > >> wrote: > >> > On 2018-06-03 13:57:26 +1000, Ben Finney wrote: > >> >> (For good reasons, attachments are dropped when messages are > >> >> distributed on the forum.) > >> > > >> > By "the forum" you mean Gmane? (I got the attachment over the mailing > >> > list) > >> > >> Comp.lang.python is a usenet newsgroup, also accessible through a mailing > >> list (and, I think, a web interface). NNTP, the Network News Transfer > >> Protocol, does not provide for attachments. > > > > This is not true. NNTP doesn't care about the content of the message at > > all (as long as it contains the few mandatory headers). As a case in > > point, Jach Fong's message got here fine (including the attachment) via [...] > > So we have determined that "the forum" is not the mailing list and not > > the newsgroup (Jach's message appeared on both with the attachment). Ben > > uses Gmane, which makes it likely that he is talking about a > > (mis)feature of Gmane, > > However, I did see that particular particular attachment, test.py in Jach's > original post, and I'm reading c.l.py via gmane. comp.lang.python or gmane.comp.python.general? (I see the latter but not the former on gmane, but I'm accessing it anonymously which might make a difference.) But yes, I also just checked gmane and the attachment is there. So we don't know why Ben didn't see the attachment (or thought that others might not see it). 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 eman_no1 at yahoo.com Mon Jun 4 18:36:35 2018 From: eman_no1 at yahoo.com (Erik Martinson) Date: Mon, 4 Jun 2018 22:36:35 +0000 (UTC) Subject: Help with 'site' package. References: <1759196148.61252.1528151795876.ref@mail.yahoo.com> Message-ID: <1759196148.61252.1528151795876@mail.yahoo.com> I am trying to dynamically add a site-package to a script that is run as a cron job. The method adduseristepackages does not seem to do anything. import sys import site print('-------------------------')print(site.getusersitepackages()) print('add', site.addusersitepackages('/home/erik/.local/lib/python3.6/site-packages')) print(site.getusersitepackages()) print(site.getsitepackages()) print(site.check_enableusersite()) output:------------------------- /root/.local/lib/python3.6/site-packages add /home/erik/.local/lib/python3.6/site-packages /root/.local/lib/python3.6/site-packages ['/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.6/dist-packages'] True Thanks, Erik "To error is human ... and to blame it on a computer is even more so." From eryksun at gmail.com Mon Jun 4 19:26:19 2018 From: eryksun at gmail.com (eryk sun) Date: Mon, 4 Jun 2018 23:26:19 +0000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <87k1rkgd2k.fsf@elektro.pacujo.net> Message-ID: On Sat, Jun 2, 2018 at 11:28 AM, Chris Angelico wrote: > > I also can't find anything about path names there. What does POSIX say > about the concept of relative paths? Does Windows comply with that? Certainly Windows file-system paths are not POSIX compatible. Seven path types are supported: * Extended Local Device (\\?\) * Local Device (\\.\) * UNC * Drive Absolute * Drive Relative * Rooted * Relative Extended local-device paths only allow backslash as a path separator. The others allow either backslash or slash. I doubt POSIX would allow magically reserved DOS device names in every directory or stripping of trailing dots and spaces from filenames. But this isn't relevant to NT's POSIX compatibility. A POSIX process links with psxdll.dll, which connects to the POSIX environment subsystem (psxss.exe). It gets run from Windows via posix.exe (console) or psxrun.exe. In the 00s, Microsoft acquired Interix, which extended the original POSIX subsystem, and integrated it as the Subsystem for UNIX Applications (SUA). Notably SUA adds a kernel driver, psxdrv.sys, which facilitates implementing system calls and signals. There used to be a community website with overviews [1], a FAQ [2], a forum [3], tool downloads [4], and various documentation [5]. However, NT's environment subsystems never really had mass appeal, probably because existing programs had to be ported and recompiled. SUA is no longer supported as of Windows 8.1 and Server 2012 R2. The community website was closed, and the domain is now held by a squatter. Regarding file-system paths, SUA has a single root directory and uses "/dev/fs/C" for drive "C:" and "/net/server/share" for "\\server\share". [1]: http://www.suacommunity.com/SUA_Tools_Env_Start.htm https://archive.li/45JG [2]: http://www.suacommunity.com/FAQs.htm https://archive.li/5LFw [3]: http://www.suacommunity.com/forum2 https://archive.li/LzZxS [4]: http://www.suacommunity.com/tool_warehouse.aspx https://archive.li/0luI9 [5]: http://www.suacommunity.com/dictionary/fork-entry.php https://archive.li/5k8vW Windows 10 has a Linux subsystem (WSL), but this is not an NT environment subsystem. WSL processes do not load ntdll.dll. They're lightweight pico processes with an associated pico provider in the kernel (lxss.sys, lxcore.sys), and they directly execute native Linux binaries (no porting and recompiling from source). WSL only supports the console, but at least the console was upgraded to support virtual-terminal mode. > We know that Ctrl-C maps to the internal Windows interrupt > handler, and "kill process" maps to the internal Windows "terminate", > but can you send a different process all the different signals and > handle them differently? IIRC, the original POSIX subsystem supported only single-threaded processes, and SIGKILL called NtTerminateThread. Of course the subsystem has its own client bookkeeping to handle here as well. (For the Windows subsystem, csrss.exe also maintains shadow process and thread structures for clients. This is how an environment subsystem supplements base NT behavior.) Regarding Ctrl+C, a console session is started by posix.exe, which is a Windows console application. It translates console control events to signals, e.g. CTRL_C_EVENT to SIGINT, CTRL_BREAK_EVENT to SIGQUIT, and otherwise SIGKILL (e.g. closing the console, logoff, shutdown). It sends the signal number and session ID to the subsystem, which signals the processes in the given session. One way for the subsystem to implement signal delivery is via NT's runtime library function RtlRemoteCall (i.e. suspend the target thread, get its CPU context and copy it to the stack, modify the context and stack, and resume). Make a remote call to a known client function (i.e. in psxdll.dll), which delivers the signal and then continues the thread's original context via NtContinue. This approach isn't really efficient, but it's basically how the original POSIX subsystem worked. SUA probably uses NT asynchronous procedure calls (APCs). --- Appendix: NT APCs NT doesn't have anything exactly like POSIX signals. It has exceptions, which are handled using either Vectored Exception Handling or Structured Exception Handling (i.e. MSVC __try, __except, __finally), and asynchronous procedure calls (APCs). Some POSIX signals correspond to NT exceptions (e.g. SIGSEGV corresponds to a STATUS_ACCESS_VIOLATION). But APCs are what a POSIX subsystem would likely use to implement signals. There are two types of APC: kernel and user. A thread has an APC queue for each type. User APCs can be queued from user mode via NtQueueApcThread, or via WinAPI QueueUserAPC. Some APIs such as ReadFileEx take an optional completion or notification APC routine, for which a kernel component queues the user APC. All APCs have a "kernel routine" and most also have a "normal" routine. The kernel routine is called first, with the CPU in kernel mode and its interrupt request level (IRQL) at APC_LEVEL (1). The kernel routine is passed a pointer to the normal routine, which allows it to set a different function or none at all (i.e. a NULL pointer). If it's not NULL, the normal routine is called with the CPU IRQL at PASSIVE_LEVEL (0), either in kernel mode or user mode, depending on the APC type. Kernel APCs are "special" if they're inserted in the queue without a normal routine. Special APCs get placed ahead of normal APCs in the queue and can preempt the execution of normal APCs. They're used for high priority operations. For example, completion of an I/O request queues a special kernel APC to the thread that originated the request. Queueing a kernel APC either raises an APC interrupt if the thread is currently running or awakens the thread if it's currently waiting and has APC delivery enabled. Queueing a user APC does not raise an interrupt but may awaken the thread if it's currently in a user-mode wait and either the wait is alertable or the user APC pending flag is set. Kernel APC delivery is triggered either by the APC interrupt handler or immediately after a context switch to a thread (e.g. when awakened). User APCs are delivered when returning to user mode, but only if the thread's user APC pending flag is set. Normally this flag gets set when the thread does an alertable user-mode delay/wait and its APC queue isn't empty. It's also set by the NtTestAlert system call, and also specially set for the user APC that initiates cross-thread termination. A thread automatically resumes a delay or wait if it's awakened to deliver a kernel APC. On the other hand, if a thread is awakened by queueing a user APC, the wait returns with the status code STATUS_USER_APC. This is the normal way user APCs are delivered, i.e. upon returning from an alertable delay or wait system call (e.g. NtDelayExecution, NtWaitForSingleObject). As mentioned above, NtTestAlert can also be used to pump the user APC queue. The APC delivery function first drains the kernel APC queue completely. If delivering user APCs is enabled (i.e. the user APC pending flag is set and the previous CPU mode is user mode), it also delivers the first user APC from the head of the queue. Only one user APC is delivered because it requires switching to the user-mode APC dispatcher in ntdll.dll. This can't process the whole queue because, as discussed above, all APCs have a kernel-mode routine that gets called first. Thus, with user APCs, the pattern is to call the kernel routine from the APC delivery function; transition to user-mode to call the normal routine if the kernel routine didn't set it to NULL; and then return back to kernel mode via the NtContinue system call. The latter sets the user APC pending flag to deliver the next user APC, if any. This cycle continues until the user APC queue is empty. From ben+python at benfinney.id.au Mon Jun 4 19:33:03 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 05 Jun 2018 09:33:03 +1000 Subject: Attachments References: <85zi0cikt5.fsf@benfinney.id.au> <20180603182032.i4k7x47bdteuntg2@hjp.at> <20180604203716.iq4v5hhfstgj734v@hjp.at> Message-ID: <85lgbui0uo.fsf@benfinney.id.au> "Peter J. Holzer" writes: > So we have determined that "the forum" is not the mailing list and not > the newsgroup (Jach's message appeared on both with the attachment). By ?the forum? I don't mean any specific server to the exclusion of others. I mean the aggregate forum in which we are having this discussion: comp.lang.python and python-list are a single discussion forum, distributed across many servers. -- \ ?If you go parachuting, and your parachute doesn't open, and | `\ you friends are all watching you fall, I think a funny gag | _o__) would be to pretend you were swimming.? ?Jack Handey | Ben Finney From jlee54 at gmail.com Mon Jun 4 22:09:07 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 4 Jun 2018 19:09:07 -0700 Subject: tkinter (ttk) combobox dropdown text is white on white In-Reply-To: References: <645f9cc9-4bac-010f-460c-941160f575a4@gmail.com> Message-ID: Oops, I hit "reply" instead of "reply-list" last time.? Trying again... On 06/03/2018 02:01 PM, Christian Gollwitzer wrote: > Am 03.06.18 um 21:54 schrieb Jim Lee:> import tkinter as tk >> from tkinter import ttk >> >> root = tk.Tk() >> cb = ttk.Combobox(root) >> cb.grid(row=0, column=0, sticky='NSEW') >> cb['values'] = ['one', 'two', 'three', 'four'] >> root.mainloop() >> >> The text of the values in the combobox dropdown list is white on >> white.?? The *selected* item in the list is white on light grey, but >> all the unselected items are invisible (white on white). > > Which platform are you on, i.e. which operating system? I guess it is > Linux. In that case the default colors are read by Tk from the X11 > options database, which is some cruft from the past to set options for > X11 applications. Try to run > > ????xrdb -query > > That should give you a list of default values, and maybe you can see > something. The dropdown list is actually a popdown menu, so look for > Menu colors. For instance, if you use a dark theme in your desktop > environment, it could be that the foreground is correctly set to > white, but the background is hardcoded white for some reason e.g. > > > ????Christian Thanks.? Yes, I am on Linux (Fedora 28, MATE desktop).? Yes, I am using a dark theme - however, xrdb does not show #ffffff for *any* background color, so I have no idea where ttk is picking it up from.? Even if I change to a light desktop theme, the ttk widget still displays white on white.? The only solution I have found so far is rather hackish, but it works: class MyCombobox(ttk.Combobox): ??? def __init__(self, *args, **kwargs): ??????? super().__init__(*args, **kwargs) ??????? self.bind('', self._change_popdown_color) ??? def _change_popdown_color(self, *args): ??????? popdown = self.tk.eval('ttk::combobox::PopdownWindow {}'.format(self)) ??????? self.tk.call('{}.f.l'.format(popdown), 'configure', '-foreground', 'black') However, I am still looking for a more elegant solution that preferably doesn't hardcode colors... -Jim From mike.junk.46 at att.net Mon Jun 4 22:13:35 2018 From: mike.junk.46 at att.net (Mike McClain) Date: Mon, 4 Jun 2018 19:13:35 -0700 Subject: How can an int be '+' with a tuple? In-Reply-To: <85tvqkibhm.fsf@benfinney.id.au> References: <85tvqkibhm.fsf@benfinney.id.au> Message-ID: <20180605021335.GA23978@playground> On Sun, Jun 03, 2018 at 05:18:45PM +1000, Ben Finney wrote: > > To better understand names, type of an object, and binding a name to an > object, see Ned Batchelder's presentation ???Facts and myths about Python > names and values??? . > This answers in a little more detail a question I asked a week or two ago. Thanks for posting it. Mike McClain -- Take your campaign contribution, and send it to the Red Cross, and let the election be decided on its merit. - Will Rogers From Richard at Damon-Family.org Mon Jun 4 22:40:55 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Mon, 4 Jun 2018 22:40:55 -0400 Subject: Attachments (was: How can an int be '+' with a tuple?) In-Reply-To: References: <85zi0cikt5.fsf@benfinney.id.au> <20180603182032.i4k7x47bdteuntg2@hjp.at> Message-ID: <1b990edc-2f3e-217c-f8a6-2ed8210a1244@Damon-Family.org> On 6/4/18 12:34 PM, Peter Pearson wrote: > On Sun, 3 Jun 2018 20:20:32 +0200, Peter J. Holzer wrote: > [snip] >> On 2018-06-03 13:57:26 +1000, Ben Finney wrote: >>> (For good reasons, attachments are dropped when messages are distributed >>> on the forum.) >> By "the forum" you mean Gmane? (I got the attachment over the mailing >> list) > Comp.lang.python is a usenet newsgroup, also accessible through a mailing > list (and, I think, a web interface). NNTP, the Network News Transfer > Protocol, does not provide for attachments. > NNTP most certainly can provide for attachments, and I would guess that well over 90% of the traffic (might even be 99%) on usenet is carried in attachments. Just wander over to the swamp of alt.binaries.* Now, most news servers are configured to discard most attachments on messages (or the whole message if it has an attachment) if posted to a group not specifically marked as a 'binary' newsgroup, just like a lot of mailing list are similarly setup. -- Richard Damon From sharan.basappa at gmail.com Mon Jun 4 23:13:32 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Mon, 4 Jun 2018 20:13:32 -0700 (PDT) Subject: user defined modules Message-ID: Is there a specific location where user defined modules need to be kept? If not, do we need to specify search location so that Python interpreter can find it? Also, when does Python interpreter compile the module code? When it is imported? From __peter__ at web.de Tue Jun 5 03:21:58 2018 From: __peter__ at web.de (Peter Otten) Date: Tue, 05 Jun 2018 09:21:58 +0200 Subject: tkinter (ttk) combobox dropdown text is white on white References: <645f9cc9-4bac-010f-460c-941160f575a4@gmail.com> Message-ID: Jim Lee wrote: > Oops, I hit "reply" instead of "reply-list" last time. Trying again... > > > On 06/03/2018 02:01 PM, Christian Gollwitzer wrote: >> Am 03.06.18 um 21:54 schrieb Jim Lee:> import tkinter as tk >>> from tkinter import ttk >>> >>> root = tk.Tk() >>> cb = ttk.Combobox(root) >>> cb.grid(row=0, column=0, sticky='NSEW') >>> cb['values'] = ['one', 'two', 'three', 'four'] >>> root.mainloop() >>> >>> The text of the values in the combobox dropdown list is white on >>> white. The *selected* item in the list is white on light grey, but >>> all the unselected items are invisible (white on white). >> >> Which platform are you on, i.e. which operating system? I guess it is >> Linux. In that case the default colors are read by Tk from the X11 >> options database, which is some cruft from the past to set options for >> X11 applications. Try to run >> >> xrdb -query >> >> That should give you a list of default values, and maybe you can see >> something. The dropdown list is actually a popdown menu, so look for >> Menu colors. For instance, if you use a dark theme in your desktop >> environment, it could be that the foreground is correctly set to >> white, but the background is hardcoded white for some reason e.g. >> >> >> Christian > > Thanks. Yes, I am on Linux (Fedora 28, MATE desktop). Yes, I am using > a dark theme - however, xrdb does not show #ffffff for *any* background > color, so I have no idea where ttk is picking it up from. Even if I > change to a light desktop theme, the ttk widget still displays white on > white. The only solution I have found so far is rather hackish, but it > works: > > class MyCombobox(ttk.Combobox): > def __init__(self, *args, **kwargs): > super().__init__(*args, **kwargs) > self.bind('', self._change_popdown_color) > > def _change_popdown_color(self, *args): > popdown = self.tk.eval('ttk::combobox::PopdownWindow > {}'.format(self)) > self.tk.call('{}.f.l'.format(popdown), 'configure', > '-foreground', 'black') > > However, I am still looking for a more elegant solution that preferably > doesn't hardcode colors... import tkinter as tk from tkinter import ttk root = tk.Tk() root.option_add('*TCombobox*Listbox.foreground', "black") cb = ttk.Combobox(root) cb.grid(row=0, column=0, sticky='NSEW') cb['values'] = ['one', 'two', 'three', 'four'] root.mainloop() The foreground color is still hardcoded, but the extra code is a little less invasive. From __peter__ at web.de Tue Jun 5 03:25:36 2018 From: __peter__ at web.de (Peter Otten) Date: Tue, 05 Jun 2018 09:25:36 +0200 Subject: Attachments References: <85zi0cikt5.fsf@benfinney.id.au> <20180603182032.i4k7x47bdteuntg2@hjp.at> <20180604203716.iq4v5hhfstgj734v@hjp.at> <20180604211435.ngdmlt2mfvda53mg@hjp.at> Message-ID: Peter J. Holzer wrote: >> However, I did see that particular particular attachment, test.py in >> Jach's original post, and I'm reading c.l.py via gmane. > > comp.lang.python or gmane.comp.python.general? (I see the latter but not > the former on gmane, but I'm accessing it anonymously which might make a > difference.) gmane.comp.python.general. I thought that was their alias for comp.lang.python, for whatever reason. From steve+comp.lang.python at pearwood.info Tue Jun 5 03:32:09 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 5 Jun 2018 07:32:09 +0000 (UTC) Subject: user defined modules References: Message-ID: On Mon, 04 Jun 2018 20:13:32 -0700, Sharan Basappa wrote: > Is there a specific location where user defined modules need to be kept? > If not, do we need to specify search location so that Python interpreter > can find it? Python modules used as scripts can be run from anywhere, by pointing the interpreter at the script: python /path/to/my/script.py But Python modules uses as libraries, to be imported by other modules, have to be on the Python search path. You can add extra paths to the Python search path from the shell by setting the environment variable PYTHONPATH to a colon-separated list of paths. On Linux, I do this in my .bashrc config file: export PYTHONPATH="paths:to:add" In the Python interpreter, you can query and modify the search path by importing sys and looking at sys.path. (But you should not do so unless you really know what you are doing.) The default search path is set by the site module: https://docs.python.org/3/library/site.html but again, you should not mess with this unless you know what you are doing. There are some per-user directories which are automatically added to the search path. I can't find the existing documentation for them, but a good place to start is the PEP that introduced the feature: https://www.python.org/dev/peps/pep-0370/ Apart from setting the PYTHONPATH environment variable, the best way to add extra paths to is to install a .pth file. See here: https://pymotw.com/2/site/#path-configuration-files > Also, when does Python interpreter compile the module code? When it is > imported? Yes. Executing a module as a script does not compile it. But when it is imported, it will be compiled to byte-code the first time, and then the byte-code will be used. You can force the compilation using the compileall: https://docs.python.org/3/library/compileall.html Or just import the module from the interactive interpreter. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Tue Jun 5 03:37:34 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 5 Jun 2018 07:37:34 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> Message-ID: On Mon, 04 Jun 2018 22:13:47 +0200, Peter J. Holzer wrote: > On 2018-06-04 13:23:59 +0000, Steven D'Aprano wrote: [...] >> I don't know whether or not the Linux OS is capable of accessing files >> with embedded NULs in the file name. But Mac OS is capable of doing so, >> so it should be possible. Wikipedia says: >> >> "HFS Plus mandates support for an escape sequence to allow arbitrary >> Unicode. Users of older software might see the escape sequences instead >> of the desired characters." > > I don't know about MacOS. In Linux there is no way to pass a filename > with an embedded '\0' (or a '/' which is not path separator) between the > kernel and user space. So if a filesystem contained such a filename, the > kernel would have to map it (via an escape sequence or some other > mechanism) to a different file name. Which of course means that - from > the perspective of any user space process - the filename doesn't contain > a '\0' or '/'. That's an invalid analogy. According to that analogy, Python strings don't contain ASCII NULs, because you have to use an escape mechanism to insert them: string = "Is this \0 not a NULL?" But we know that Python strings are not NUL-terminated and can contain NUL. It's just another character. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Tue Jun 5 06:15:01 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jun 2018 20:15:01 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> Message-ID: On Tue, Jun 5, 2018 at 5:37 PM, Steven D'Aprano wrote: > On Mon, 04 Jun 2018 22:13:47 +0200, Peter J. Holzer wrote: > >> On 2018-06-04 13:23:59 +0000, Steven D'Aprano wrote: > [...] > >>> I don't know whether or not the Linux OS is capable of accessing files >>> with embedded NULs in the file name. But Mac OS is capable of doing so, >>> so it should be possible. Wikipedia says: >>> >>> "HFS Plus mandates support for an escape sequence to allow arbitrary >>> Unicode. Users of older software might see the escape sequences instead >>> of the desired characters." >> >> I don't know about MacOS. In Linux there is no way to pass a filename >> with an embedded '\0' (or a '/' which is not path separator) between the >> kernel and user space. So if a filesystem contained such a filename, the >> kernel would have to map it (via an escape sequence or some other >> mechanism) to a different file name. Which of course means that - from >> the perspective of any user space process - the filename doesn't contain >> a '\0' or '/'. > > That's an invalid analogy. According to that analogy, Python strings > don't contain ASCII NULs, because you have to use an escape mechanism to > insert them: > > string = "Is this \0 not a NULL?" > > > But we know that Python strings are not NUL-terminated and can contain > NUL. It's just another character. > No; by that analogy, a Python string cannot contain a non-Unicode character. Here's a challenge: create a Python string that contains a character that isn't part of the Universal Character Set. ChrisA From steve+comp.lang.python at pearwood.info Tue Jun 5 09:11:44 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 5 Jun 2018 13:11:44 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> Message-ID: On Tue, 05 Jun 2018 20:15:01 +1000, Chris Angelico wrote: > On Tue, Jun 5, 2018 at 5:37 PM, Steven D'Aprano > wrote: >> On Mon, 04 Jun 2018 22:13:47 +0200, Peter J. Holzer wrote: >> >>> On 2018-06-04 13:23:59 +0000, Steven D'Aprano wrote: >> [...] >> >>>> I don't know whether or not the Linux OS is capable of accessing >>>> files with embedded NULs in the file name. But Mac OS is capable of >>>> doing so, so it should be possible. Wikipedia says: >>>> >>>> "HFS Plus mandates support for an escape sequence to allow arbitrary >>>> Unicode. Users of older software might see the escape sequences >>>> instead of the desired characters." >>> >>> I don't know about MacOS. In Linux there is no way to pass a filename >>> with an embedded '\0' (or a '/' which is not path separator) between >>> the kernel and user space. So if a filesystem contained such a >>> filename, the kernel would have to map it (via an escape sequence or >>> some other mechanism) to a different file name. Which of course means >>> that - from the perspective of any user space process - the filename >>> doesn't contain a '\0' or '/'. >> >> That's an invalid analogy. According to that analogy, Python strings >> don't contain ASCII NULs, because you have to use an escape mechanism >> to insert them: >> >> string = "Is this \0 not a NULL?" >> >> >> But we know that Python strings are not NUL-terminated and can contain >> NUL. It's just another character. >> >> > No; by that analogy, a Python string cannot contain a non-Unicode > character. Here's a challenge: create a Python string that contains a > character that isn't part of the Universal Character Set. Huh? In what way is that the analogy being made? Your challenge is impossible from pure Python, equivalent to "create a Python bytes object that contains a byte greater than 255". The challenge is rigged to be doomed to fail. That's not the case when it comes to \0 in file names: we know that Mac OS can do it, we know HFS and Apple FS support NUL in file names. We have an existence proof that it is possible. (Although in your case, it is conceivable that using C you might be able to solve the challenge: create a string using the UCS-4 implementation (32-bit code units), then modify some code unit to be a value outside of the 21-bit range supported by Unicode. But that would require low-level hacking, it isn't supported by the language or the interpreter except maybe via ctypes.) Apple FS, HFS and HFS Plus support \0 as a valid Unicode character. The Mac OS kernel has an escape mechanism to allow user code to include \0 characters in pathnames, just as Python has an escape mechanism to allow user code to include \0 in strings. There's no such escape mechanism for characters outside of Unicode. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Tue Jun 5 09:27:16 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jun 2018 23:27:16 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> Message-ID: On Tue, Jun 5, 2018 at 11:11 PM, Steven D'Aprano wrote: > On Tue, 05 Jun 2018 20:15:01 +1000, Chris Angelico wrote: > >> On Tue, Jun 5, 2018 at 5:37 PM, Steven D'Aprano >> wrote: >>> On Mon, 04 Jun 2018 22:13:47 +0200, Peter J. Holzer wrote: >>> >>>> On 2018-06-04 13:23:59 +0000, Steven D'Aprano wrote: >>> [...] >>> >>>>> I don't know whether or not the Linux OS is capable of accessing >>>>> files with embedded NULs in the file name. But Mac OS is capable of >>>>> doing so, so it should be possible. Wikipedia says: >>>>> >>>>> "HFS Plus mandates support for an escape sequence to allow arbitrary >>>>> Unicode. Users of older software might see the escape sequences >>>>> instead of the desired characters." >>>> >>>> I don't know about MacOS. In Linux there is no way to pass a filename >>>> with an embedded '\0' (or a '/' which is not path separator) between >>>> the kernel and user space. So if a filesystem contained such a >>>> filename, the kernel would have to map it (via an escape sequence or >>>> some other mechanism) to a different file name. Which of course means >>>> that - from the perspective of any user space process - the filename >>>> doesn't contain a '\0' or '/'. >>> >>> That's an invalid analogy. According to that analogy, Python strings >>> don't contain ASCII NULs, because you have to use an escape mechanism >>> to insert them: >>> >>> string = "Is this \0 not a NULL?" >>> >>> >>> But we know that Python strings are not NUL-terminated and can contain >>> NUL. It's just another character. >>> >>> >> No; by that analogy, a Python string cannot contain a non-Unicode >> character. Here's a challenge: create a Python string that contains a >> character that isn't part of the Universal Character Set. > > Huh? In what way is that the analogy being made? Your challenge is > impossible from pure Python, equivalent to "create a Python bytes object > that contains a byte greater than 255". The challenge is rigged to be > doomed to fail. And an ASCIIZ string cannot contain a byte value of zero. The parallel is exact. ChrisA From bellcanadardp at gmail.com Tue Jun 5 09:42:29 2018 From: bellcanadardp at gmail.com (bellcanadardp at gmail.com) Date: Tue, 5 Jun 2018 06:42:29 -0700 (PDT) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <27ef2bfb-e3ed-495c-bb98-f71e502d412a@googlegroups.com> <20180520134354.GB2192@hermes.hilbert.loc> <20180522212337.cvtbh32tydvaft4r@hjp.at> Message-ID: <48742502-aaf3-43a4-93b1-a1eb37f3e37c@googlegroups.com> On Sunday, 3 June 2018 20:11:43 UTC-4, Steven D'Aprano wrote: > On Sun, 03 Jun 2018 16:36:12 -0700, bellcanadardp wrote: > > > hello peter ...how exactly would i solve this issue .....i have a script > > that works in python 2 but not pytho3..i did 2 to 3.py ...but i still > > get the errro...character undefieed..unicode decode error cant decode > > byte 1x09 in line 7414 from cp 1252..like would you have a sraright > > solution answer??..i cant get a straight answer..it was ported from ansi > > to python...so its utf-8 as far asi can see > > You won't get a straight answer because you won't tell us *precisely* > what is happening. > > Don't retype a summary of what you think the error is. "character > undefieed" is not a thing, and there is no such thing as "byte 1x09". > > You need to COPY AND PASTE the EXACT error that you get. Not just the > last line, the error message, but the FULL TRACEBACK starting from the > line "Traceback" and going to the end. > > Until you do that, we cannot give you a straight answer. > > You also need to COPY AND PASTE the EXACT line of code that gives the > error, plus enough code so that it works. For a file read error, that > probably means code that opens the file, and then tries to read from it. > > Until you do that, we cannot give you a straight answer. > > You need to tell us what version of Python you are using, and the > operating system. > > You should read this: > > http://sscce.org/ > > Even though it is written for Java programmers, it applies to Python to. > > If you think that your file is UTF-8, why are you using CP-1252 to read > the file? > > https://en.wikipedia.org/wiki/Windows-1252 > > https://en.wikipedia.org/wiki/UTF-8 > > > > I recommend you start with reading this if you haven't already: > > https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every- > software-developer-absolutely-positively-must-know-about-unicode-and- > character-sets-no-excuses/ > > Sorry for the huge URL, try this if your mail client breaks it: > > https://tinyurl.com/h8yg9d7 > > > Until you read that, you will probably remain confused about text > encodings and Unicode and will probably not understand the straight > answer we give you. > > Also read: https://nedbatchelder.com/text/unipain.html > > > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson here is the exact error full message in the attachment...UPDATE..i am manually modifying this reply..i tried to answer by my gmail but i get errors and i couldnt find this webpage till today and it doesnt accept attachments..so many you can for future provide an email if thats ok...anyway i will write the error manually here: ********************* File "C:\Users\Robert\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table[0] UnicodeDecodeError: 'charmap'codec can't decode byte 0x9d in position 7414: character maps to ******************************* for the record i did not puprosely set the code or decode o encode to cp-1252; this is a 3rd party script i have from the internet thats all this a set of files that runs find in python 2.7 i am trying to run it in python 3 becuz i was told in 2020 python 2 will no longer be supported not sure if that really matters for my script it runs completey fine in python 2, so for me the issue is with python 3 and its changes relative to python 2 tommy From grant.b.edwards at gmail.com Tue Jun 5 09:46:15 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 5 Jun 2018 13:46:15 +0000 (UTC) Subject: Attachments References: <85zi0cikt5.fsf@benfinney.id.au> <20180603182032.i4k7x47bdteuntg2@hjp.at> <20180604203716.iq4v5hhfstgj734v@hjp.at> <20180604211435.ngdmlt2mfvda53mg@hjp.at> Message-ID: On 2018-06-05, Peter Otten <__peter__ at web.de> wrote: > Peter J. Holzer wrote: > >>> However, I did see that particular particular attachment, test.py in >>> Jach's original post, and I'm reading c.l.py via gmane. >> >> comp.lang.python or gmane.comp.python.general? (I see the latter >> but not the former on gmane, but I'm accessing it anonymously which >> might make a difference.) > > gmane.comp.python.general. I thought that was their alias for > comp.lang.python, for whatever reason. No, that's their alias for their archive of python-list at python.org messages. Gmane is unaware of comp.lang.python. -- Grant Edwards grant.b.edwards Yow! I just remembered at something about a TOAD! gmail.com From hjp-python at hjp.at Tue Jun 5 11:28:24 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 5 Jun 2018 17:28:24 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> Message-ID: <20180605152824.54ner6n2ngx5zhdu@hjp.at> On 2018-06-05 07:37:34 +0000, Steven D'Aprano wrote: > On Mon, 04 Jun 2018 22:13:47 +0200, Peter J. Holzer wrote: > > On 2018-06-04 13:23:59 +0000, Steven D'Aprano wrote: > >> I don't know whether or not the Linux OS is capable of accessing > >> files with embedded NULs in the file name. But Mac OS is capable of > >> doing so, so it should be possible. Wikipedia says: > >> > >> "HFS Plus mandates support for an escape sequence to allow > >> arbitrary Unicode. Users of older software might see the escape > >> sequences instead of the desired characters." > > > > I don't know about MacOS. In Linux there is no way to pass a > > filename with an embedded '\0' (or a '/' which is not path > > separator) between the kernel and user space. So if a filesystem > > contained such a filename, the kernel would have to map it (via an > > escape sequence or some other mechanism) to a different file name. > > Which of course means that - from the perspective of any user space > > process - the filename doesn't contain a '\0' or '/'. > > That's an invalid analogy. According to that analogy, Python strings > don't contain ASCII NULs, because you have to use an escape mechanism > to insert them: > > string = "Is this \0 not a NULL?" > > > But we know that Python strings are not NUL-terminated and can contain > NUL. It's just another character. I think that's a bad analogy. The escape mechanism for string literals is mostly for convenience of the programmer. It's there to make the program's source code more readable (and yes, also easier to write). But at run time the \0 character is just that: A character with the value 0. If a disk with a file system which allows embedded NUL characters is mounted on Linux (let's for the sake of the argument assume it is HFS+, although I have to admit that I don't know anything about the internals of that filesystem), then the low level filesystem code has to map that character to something else. Even the generic filesystem code of the kernel will never see that NUL character, let alone the user space. As far as the OS is concerned, that file doesn't contain a NUL character. The whole system (except for some low-level FS-dependent code) will always only see the mapped name. If some application (which might be an interpreter, or it might be a graphics program, for example) decides that it knows better what the "real" filename is and reverses that mapping, it can do so - but it would be very confusing because it would use a different file name than the rest of the system. The user would see one file name with ls, but would have to use a different filename in the application. The application would show one filename in its "save" dialog, but the OS's file manager would show another. Not a good idea, especially as the benefits of such a scheme would be extremely narrow (you could share an HFS+ formatted USB disk between MacOS and Linux with filenames with embedded NULs and that application would let you use the same filenames as you would use on MacOS). Now, if MacOS uses something like that, this is a different matter. Presumably (since HFS+ is a native file system) the kernel deals with NUL characters in a straightforward manner. It might even have a (non-POSIX) API to expose such filenames. Even if it hasn't, presumably the mapping back and forth is done in a very low level library used by all (or most) of the applications, so that they all show consistently the same filename. But Linux isn't MacOS. On Linux there are no filenames with embedded NULs, even if you mount an HFS+ disk and even if some application decides to internally remap filenames in a way that they can contain NUL characters. 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 hjp-python at hjp.at Tue Jun 5 11:39:56 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 5 Jun 2018 17:39:56 +0200 Subject: Attachments In-Reply-To: <85lgbui0uo.fsf@benfinney.id.au> References: <85zi0cikt5.fsf@benfinney.id.au> <20180603182032.i4k7x47bdteuntg2@hjp.at> <20180604203716.iq4v5hhfstgj734v@hjp.at> <85lgbui0uo.fsf@benfinney.id.au> Message-ID: <20180605153956.l6oz2zquq477ln5j@hjp.at> On 2018-06-05 09:33:03 +1000, Ben Finney wrote: > "Peter J. Holzer" writes: > > So we have determined that "the forum" is not the mailing list and not > > the newsgroup (Jach's message appeared on both with the attachment). > > By ?the forum? I don't mean any specific server to the exclusion of > others. I mean the aggregate forum in which we are having this > discussion: comp.lang.python and python-list are a single discussion > forum, distributed across many servers. Then the statement | (For good reasons, attachments are dropped when messages are distributed | on the forum.) was demonstrable false (at least overly general) as the attachment in Jach's message wasn't dropped. It was distributed over all the servers I can easily check (plus some servers others have checked). It might have been dropped on some specific servers, but certainly not on "the forum" as a whole. (I remember that I have seen some messages in the past where an attachment was obviously missing. Maybe specific content types are stripped, but not attachments in general) 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 jlee54 at gmail.com Tue Jun 5 12:19:35 2018 From: jlee54 at gmail.com (Jim Lee) Date: Tue, 5 Jun 2018 09:19:35 -0700 Subject: tkinter (ttk) combobox dropdown text is white on white In-Reply-To: References: <645f9cc9-4bac-010f-460c-941160f575a4@gmail.com> Message-ID: <19f5cb2f-f0e6-c2ff-7784-5949368f97f4@gmail.com> On 06/05/2018 12:21 AM, Peter Otten wrote: > Jim Lee wrote: > >> Oops, I hit "reply" instead of "reply-list" last time. Trying again... >> >> >> On 06/03/2018 02:01 PM, Christian Gollwitzer wrote: >>> Am 03.06.18 um 21:54 schrieb Jim Lee:> import tkinter as tk >>>> from tkinter import ttk >>>> >>>> root = tk.Tk() >>>> cb = ttk.Combobox(root) >>>> cb.grid(row=0, column=0, sticky='NSEW') >>>> cb['values'] = ['one', 'two', 'three', 'four'] >>>> root.mainloop() >>>> >>>> The text of the values in the combobox dropdown list is white on >>>> white. The *selected* item in the list is white on light grey, but >>>> all the unselected items are invisible (white on white). >>> Which platform are you on, i.e. which operating system? I guess it is >>> Linux. In that case the default colors are read by Tk from the X11 >>> options database, which is some cruft from the past to set options for >>> X11 applications. Try to run >>> >>> xrdb -query >>> >>> That should give you a list of default values, and maybe you can see >>> something. The dropdown list is actually a popdown menu, so look for >>> Menu colors. For instance, if you use a dark theme in your desktop >>> environment, it could be that the foreground is correctly set to >>> white, but the background is hardcoded white for some reason e.g. >>> >>> >>> Christian >> Thanks. Yes, I am on Linux (Fedora 28, MATE desktop). Yes, I am using >> a dark theme - however, xrdb does not show #ffffff for *any* background >> color, so I have no idea where ttk is picking it up from. Even if I >> change to a light desktop theme, the ttk widget still displays white on >> white. The only solution I have found so far is rather hackish, but it >> works: >> >> class MyCombobox(ttk.Combobox): >> def __init__(self, *args, **kwargs): >> super().__init__(*args, **kwargs) >> self.bind('', self._change_popdown_color) >> >> def _change_popdown_color(self, *args): >> popdown = self.tk.eval('ttk::combobox::PopdownWindow >> {}'.format(self)) >> self.tk.call('{}.f.l'.format(popdown), 'configure', >> '-foreground', 'black') >> >> However, I am still looking for a more elegant solution that preferably >> doesn't hardcode colors... > import tkinter as tk > from tkinter import ttk > > root = tk.Tk() > root.option_add('*TCombobox*Listbox.foreground', "black") > > cb = ttk.Combobox(root) > cb.grid(row=0, column=0, sticky='NSEW') > cb['values'] = ['one', 'two', 'three', 'four'] > root.mainloop() > > The foreground color is still hardcoded, but the extra code is a little less > invasive. > > Thanks for that - it's certainly cleaner.? I'm finding that ttk (at least as wrapped by tkinter) is fairly buggy - many of the options (particularly sytle-related ones) are order dependent, while others are ignored entirely.? For example, behavior is different if you set the foreground color before the background vs. the other way around.? Also, I've found that changing combobox colors in a certain order will affect the appearance of buttons ?!?? I think it's time to look for a different Python GUI... -Jim Lee From brgrt2 at gmail.com Tue Jun 5 12:51:17 2018 From: brgrt2 at gmail.com (T Berger) Date: Tue, 5 Jun 2018 09:51:17 -0700 (PDT) Subject: Learning Python Message-ID: <9adedc60-5a8b-499e-971c-d1edbf031d5f@googlegroups.com> Can someone learn Python through a book such as Head Start Python? Would an online course from MIT or google be better? From ned at nedbatchelder.com Tue Jun 5 13:33:57 2018 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 5 Jun 2018 13:33:57 -0400 Subject: Learning Python In-Reply-To: <9adedc60-5a8b-499e-971c-d1edbf031d5f@googlegroups.com> References: <9adedc60-5a8b-499e-971c-d1edbf031d5f@googlegroups.com> Message-ID: On 6/5/18 12:51 PM, T Berger wrote: > Can someone learn Python through a book such as Head Start Python? Would an online course from MIT or google be better? This is really a question about your own learning style.? It is possible to learn from a book.? Not too long ago, that was one of the only methods there was! :) --Ned. From eryksun at gmail.com Tue Jun 5 13:34:09 2018 From: eryksun at gmail.com (eryk sun) Date: Tue, 5 Jun 2018 17:34:09 +0000 Subject: Why exception from os.path.exists()? In-Reply-To: <20180605152824.54ner6n2ngx5zhdu@hjp.at> References: <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <20180605152824.54ner6n2ngx5zhdu@hjp.at> Message-ID: On Tue, Jun 5, 2018 at 3:28 PM, Peter J. Holzer wrote: > > Now, if MacOS uses something like that, this is a different matter. > Presumably (since HFS+ is a native file system) the kernel deals with > NUL characters in a straightforward manner. It might even have a > (non-POSIX) API to expose such filenames. Even if it hasn't, presumably > the mapping back and forth is done in a very low level library used by > all (or most) of the applications, so that they all show consistently > the same filename. The Linux subsystem in Windows 10 has to use character escaping. The root file system is stored in the NTFS directory "%LocalAppData%\Packages\\LocalState\rootfs". It escapes invalid NTFS characters (as implemented by the ntfs.sys driver) using the hex code prefixed by "#". Thus "#" itself has to be escaped as "#0023". For example: $ touch '\*?<>|#' $ ls '\*?<>|#' \*?<>|# With CMD in the above directory, we can see the real filename: > dir /b #* #005C#002A#003F#003C#003E#007C#0023 From stephen_tucker at sil.org Tue Jun 5 13:35:27 2018 From: stephen_tucker at sil.org (Stephen Tucker) Date: Tue, 5 Jun 2018 18:35:27 +0100 Subject: Learning Python In-Reply-To: <9adedc60-5a8b-499e-971c-d1edbf031d5f@googlegroups.com> References: <9adedc60-5a8b-499e-971c-d1edbf031d5f@googlegroups.com> Message-ID: I have found Learning Python by Mark Lutz helpful. I have the 4th edition (2009). Its ISBN is 978-0-596-15806-4. A lot will depend on your learning style. This book reads more like a set of course notes than a reference book, but it does contain tables and summaries, too. On Tue, Jun 5, 2018 at 5:51 PM, T Berger wrote: > Can someone learn Python through a book such as Head Start Python? Would > an online course from MIT or google be better? > -- > https://mail.python.org/mailman/listinfo/python-list > From eman_no1 at yahoo.com Tue Jun 5 16:33:11 2018 From: eman_no1 at yahoo.com (Erik Martinson) Date: Tue, 5 Jun 2018 20:33:11 +0000 (UTC) Subject: site package does not work References: <905884138.650082.1528230791659.ref@mail.yahoo.com> Message-ID: <905884138.650082.1528230791659@mail.yahoo.com> I am trying to dynamically add a site-package to a script that is run as a cron job. The method adduseristepackages does not seem to do anything. import sys import site print('-------------------------')print(site.getusersitepackages()) print('add', site.addusersitepackages('/home/erik/.local/lib/python3.6/site-packages')) print(site.getusersitepackages()) print(site.getsitepackages()) print(site.check_enableusersite()) output:------------------------- /root/.local/lib/python3.6/site-packages add /home/erik/.local/lib/python3.6/site-packages /root/.local/lib/python3.6/site-packages ['/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.6/dist-packages'] True Thanks, Erik From nelle.varoquaux at gmail.com Tue Jun 5 20:06:37 2018 From: nelle.varoquaux at gmail.com (Nelle Varoquaux) Date: Tue, 5 Jun 2018 17:06:37 -0700 Subject: 2018 John Hunter Excellence in Plotting Contest Message-ID: Hello everyone, Sorry about the cross-posting. There's a couple more days to submit to the John Hunter Excellence in Plotting Competition! If you have any scientific plot worth sharing, submit an entry before June 8th. For more information, see below. Thanks, Nelle In memory of John Hunter, we are pleased to be reviving the SciPy John Hunter Excellence in Plotting Competition for 2018. This open competition aims to highlight the importance of data visualization to scientific progress and showcase the capabilities of open source software. Participants are invited to submit scientific plots to be judged by a panel. The winning entries will be announced and displayed at the conference. John Hunter?s family and NumFocus are graciously sponsoring cash prizes for the winners in the following amounts: - 1st prize: $1000 - 2nd prize: $750 - 3rd prize: $500 - Entries must be submitted by June, 8th to the form at https://goo.gl/forms/7q86zgu5OYUOjODH3 . - Winners will be announced at Scipy 2018 in Austin, TX. - Participants do not need to attend the Scipy conference. - Entries may take the definition of ?visualization? rather broadly. Entries may be, for example, a traditional printed plot, an interactive visualization for the web, or an animation. - Source code for the plot must be provided, in the form of Python code and/or a Jupyter notebook, along with a rendering of the plot in a widely used format. This may be, for example, PDF for print, standalone HTML and Javascript for an interactive plot, or MPEG-4 for a video. If the original data can not be shared for reasons of size or licensing, "fake" data may be substituted, along with an image of the plot using real data. - Each entry must include a 300-500 word abstract describing the plot and its importance for a general scientific audience. - Entries will be judged on their clarity, innovation and aesthetics, but most importantly for their effectiveness in communicating a real-world problem. Entrants are encouraged to submit plots that were used during the course of research or work, rather than merely being hypothetical. - SciPy reserves the right to display any and all entries, whether prize-winning or not, at the conference, use in any materials or on its website, with attribution to the original author(s). SciPy John Hunter Excellence in Plotting Competition Co-Chairs Thomas Caswell Michael Droettboom Nelle Varoquaux From ben+python at benfinney.id.au Tue Jun 5 20:48:17 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 06 Jun 2018 10:48:17 +1000 Subject: Attachments References: <85zi0cikt5.fsf@benfinney.id.au> <20180603182032.i4k7x47bdteuntg2@hjp.at> <20180604203716.iq4v5hhfstgj734v@hjp.at> <85lgbui0uo.fsf@benfinney.id.au> <20180605153956.l6oz2zquq477ln5j@hjp.at> Message-ID: <85efhkivu6.fsf@benfinney.id.au> "Peter J. Holzer" writes: > Then the statement > > | (For good reasons, attachments are dropped when messages are > | distributed on the forum.) > > was demonstrable false (at least overly general) as the attachment in > Jach's message wasn't dropped. Try this more precise statement, then: Many attachments are dropped when distributed on this forum, to the extent that one should expect attachments will tend not survive distribution on this forum. > (I remember that I have seen some messages in the past where an > attachment was obviously missing. Maybe specific content types are > stripped, but not attachments in general) Yes. There may be exceptions, but ?don't expect that readers of this forum can see your attachments? is a good rule to operate by. -- \ ?Writing a book is like washing an elephant: there no good | `\ place to begin or end, and it's hard to keep track of what | _o__) you've already covered.? ?anonymous | Ben Finney From tjreedy at udel.edu Tue Jun 5 21:42:02 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 5 Jun 2018 21:42:02 -0400 Subject: tkinter (ttk) combobox dropdown text is white on white In-Reply-To: <645f9cc9-4bac-010f-460c-941160f575a4@gmail.com> References: <645f9cc9-4bac-010f-460c-941160f575a4@gmail.com> Message-ID: On 6/3/2018 3:54 PM, Jim Lee wrote: > Given the following snippet (Python 3.6.5, Tk 8.6.8): What OS? Likely not Windows > import tkinter as tk > from tkinter import ttk > > root = tk.Tk() > cb = ttk.Combobox(root) > cb.grid(row=0, column=0, sticky='NSEW') > cb['values'] = ['one', 'two', 'three', 'four'] > root.mainloop() > > The text of the values in the combobox dropdown list is white on > white. Win 10, 3.7.0b5: I see black on white with blue selection background. ?? The *selected* item in the list is white on light grey, but all > the unselected items are invisible (white on white).? I have played with > themes and styles, and can alter the foreground and background colors of > the combobox itself, but I cannot figure out how to alter the appearance > of entries in the dropdown list. Any pointers? -- Terry Jan Reedy From python at mrabarnett.plus.com Tue Jun 5 21:52:32 2018 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 6 Jun 2018 02:52:32 +0100 Subject: tkinter (ttk) combobox dropdown text is white on white In-Reply-To: References: <645f9cc9-4bac-010f-460c-941160f575a4@gmail.com> Message-ID: <1effc347-f051-c561-a789-d317de6f797b@mrabarnett.plus.com> On 2018-06-06 02:42, Terry Reedy wrote: > On 6/3/2018 3:54 PM, Jim Lee wrote: >> Given the following snippet (Python 3.6.5, Tk 8.6.8): > > What OS? Likely not Windows > Already answered: Linux (Fedora 28, MATE desktop). >> import tkinter as tk >> from tkinter import ttk >> >> root = tk.Tk() >> cb = ttk.Combobox(root) >> cb.grid(row=0, column=0, sticky='NSEW') >> cb['values'] = ['one', 'two', 'three', 'four'] >> root.mainloop() >> >> The text of the values in the combobox dropdown list is white on >> white. > > Win 10, 3.7.0b5: I see black on white with blue selection background. > > ?? The *selected* item in the list is white on light grey, but all >> the unselected items are invisible (white on white).? I have played with >> themes and styles, and can alter the foreground and background colors of >> the combobox itself, but I cannot figure out how to alter the appearance >> of entries in the dropdown list. Any pointers? > I haven't had a problem with it on Windows. From Cecil at decebal.nl Wed Jun 6 00:33:33 2018 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 06 Jun 2018 06:33:33 +0200 Subject: urllib3 1.23 breaks API Message-ID: <87fu20zg82.fsf@munus.decebal.nl> I had installed urllib3 1.22 for Python3. I upgraded it to 1.23. This broke the requirements for requests 2.18.4: requests 2.18.4 has requirement urllib3<1.23,>=1.21.1, but you'll have urllib3 1.23 which is incompatible I downgraded to 1.22, but this should not happen I think. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From tjol at tjol.eu Wed Jun 6 02:38:15 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 6 Jun 2018 08:38:15 +0200 Subject: Attachments In-Reply-To: <85efhkivu6.fsf@benfinney.id.au> References: <85zi0cikt5.fsf@benfinney.id.au> <20180603182032.i4k7x47bdteuntg2@hjp.at> <20180604203716.iq4v5hhfstgj734v@hjp.at> <85lgbui0uo.fsf@benfinney.id.au> <20180605153956.l6oz2zquq477ln5j@hjp.at> <85efhkivu6.fsf@benfinney.id.au> Message-ID: On 06/06/18 02:48, Ben Finney wrote: > "Peter J. Holzer" writes: >> (I remember that I have seen some messages in the past where an >> attachment was obviously missing. Maybe specific content types are >> stripped, but not attachments in general) > > Yes. There may be exceptions, but ?don't expect that readers of this > forum can see your attachments? is a good rule to operate by. > Sure, but was it actually dropped anywhere we know of? Non-text attachments are dropped, and most people who try to attach things want to send screenshots, which is why I was a bit surprised to see the attachment here. But are text attachments dropped? At all? From steve+comp.lang.python at pearwood.info Wed Jun 6 03:17:58 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 6 Jun 2018 07:17:58 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <20180605152824.54ner6n2ngx5zhdu@hjp.at> Message-ID: On Tue, 05 Jun 2018 17:28:24 +0200, Peter J. Holzer wrote: [...] > If a disk with a file system which allows embedded NUL characters is > mounted on Linux (let's for the sake of the argument assume it is HFS+, > although I have to admit that I don't know anything about the internals > of that filesystem), then the low level filesystem code has to map that > character to something else. Even the generic filesystem code of the > kernel will never see that NUL character, Even if this were true, why is it even the tiniest bit relevant to what os.path.exists() does when given a path containing a NUL byte? > let alone the user space. As > far as the OS is concerned, that file doesn't contain a NUL character. I don't care about "as far as the OS". I care about users, people like me. If I say "Here's a file called "sp\0am" then I don't care what the OS does, or the FS driver, or the disk hardware. I couldn't care less what the actual byte pattern on the disk is. If you told me that the pattern of bytes representing that filename was 0x0102030405 then I'd be momentarily impressed by the curious pattern and then do my best to immediately forget all about it. As a Python programmer, *why do you care* about NULs? How does this special treatment make your life as a Python programmer better? > The whole system (except for some low-level FS-dependent code) will > always only see the mapped name. Yes. So what? That's *already the case*. Even Python string you pass to os.path.exists is already mapped, and errors from the kernel are mapped to False. Why should NUL be treated differently? Typical Linux file systems (ext3, ext4, btrfs, ReiserFS etc) don't support Unicode, only bytes 0...255, but we can query "invalid" file names containing characters like ? ? or ?, without any problem. We don't get ValueError just because of some irrelevant technical detail that the file system doesn't support characters outside of the range of bytes 1...255 (excluding 47). We can do this because Python seamlessly maps Unicode to bytes and back again. You may have heard of a little-known operating system called "Windows", which defaults to NTFS as its file system. I'm told that there are a few people who use this file system. Even under Linux, you might have (knowingly or unknowingly) used a network file system or storage device that used NTFS under the hood. If so, then every time you query a filename, even an ordinary looking one like "foo", you could be dealing with multiple NUL bytes, as the NTFS file system (even under Linux!) uses Unicode file names encoded with UTF-16. There's a good chance that EVERY filename you've used on a NAS device or network drive has included embedded NUL bytes. You've painted a pretty picture of the supposed confusion and difficulty such NUL bytes would cause, but its all nonsense. We already can seamlessly and transparently interact with file systems where file names include NUL bytes under Linux. BUT even if what you said was true, that Linux cannot deal with NUL bytes in file names even with driver support, even if passing a NUL byte to the Linux kernel would cause the fall of human civilization, that STILL wouldn't require us to raise ValueError from os.path.exists! -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From jon+usenet at unequivocal.eu Wed Jun 6 06:50:45 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Wed, 6 Jun 2018 10:50:45 -0000 (UTC) Subject: urllib3 1.23 breaks API References: <87fu20zg82.fsf@munus.decebal.nl> Message-ID: On 2018-06-06, Cecil Westerhof wrote: > I had installed urllib3 1.22 for Python3. I upgraded it to 1.23. This > broke the requirements for requests 2.18.4: > requests 2.18.4 has requirement urllib3<1.23,>=1.21.1, but you'll have urllib3 1.23 which is incompatible > > I downgraded to 1.22, but this should not happen I think. For some reason requests is weirdly specific about which versions of urllib3 it will accept. The latest version in github allows urllib3 1.23, but for some reason requests also appears to have stopped issuing new releases mid last year. From brgrt2 at gmail.com Wed Jun 6 12:19:17 2018 From: brgrt2 at gmail.com (T Berger) Date: Wed, 6 Jun 2018 09:19:17 -0700 (PDT) Subject: Problem finding my folder via terminal Message-ID: <96bbacf2-482a-4670-80be-0ee784d255e3@googlegroups.com> I?m learning Python on my own and have been stuck for two days trying to get modules I created into site-packages. As a trial step, we were asked to change directly into the folder containing our modules. I typed ?cd mymodules? per instructions, but got this error message: ?-bash: cd: mymodules: No such file or directory.? I saved mymodules to my documents. What is going wrong here? When I tried to create a distribution file, I typed ?192:~ TamaraB$ mymodules$ python3 setup.py sdist.? I got this error message: ?-bash: mymodules$: command not found.? What should I do? From jlee54 at gmail.com Wed Jun 6 12:23:17 2018 From: jlee54 at gmail.com (Jim Lee) Date: Wed, 6 Jun 2018 09:23:17 -0700 Subject: site package does not work In-Reply-To: <905884138.650082.1528230791659@mail.yahoo.com> References: <905884138.650082.1528230791659.ref@mail.yahoo.com> <905884138.650082.1528230791659@mail.yahoo.com> Message-ID: <0ca19298-2e15-7dc6-65a5-fc140c8a60d2@gmail.com> On 06/05/2018 01:33 PM, Erik Martinson via Python-list wrote: > I am trying to dynamically add a site-package to a script that is run as a cron job. The method adduseristepackages does not seem to do anything. > > import sys > import site > > print('-------------------------')print(site.getusersitepackages()) > print('add', site.addusersitepackages('/home/erik/.local/lib/python3.6/site-packages')) > print(site.getusersitepackages()) > print(site.getsitepackages()) > print(site.check_enableusersite()) > > > output:------------------------- > /root/.local/lib/python3.6/site-packages > add /home/erik/.local/lib/python3.6/site-packages > /root/.local/lib/python3.6/site-packages > ['/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.6/dist-packages'] > True > > > Thanks, > Erik > It seems you are trying to run your script from the root cron job rather than the user's cron job, and then trying to add a user site directory to root's site path.? From the docs: |site.||ENABLE_USER_SITE| Flag showing the status of the usersite-packages directory.|True|means that it is enabled and was added to|sys.path|.|False|means that it was disabled by user request (with|-s| or|PYTHONNOUSERSITE| ).|None|means it was disabled for security reasons (mismatch between user or group id and effective id) or by an administrator. || So perhaps a mismatch between UID/GID and EID is causing the whole process to silently fail... || -Jim || From phd at phdru.name Wed Jun 6 12:28:51 2018 From: phd at phdru.name (Oleg Broytman) Date: Wed, 6 Jun 2018 18:28:51 +0200 Subject: SQLObject 3.7.0 Message-ID: <20180606162851.dnlowo4ftwyz3ze7@phdru.name> Hello! I'm pleased to announce version 3.7.0, the first stable release of branch 3.7 of SQLObject. What's new in SQLObject ======================= Contributors for this release are Scott Stahl and Christophe Popov. Features -------- * Add signals on commit and rollback; pull request by Scott Stahl. Bug fixes --------- * Fix SSL-related parameters for MySQL-connector (connector uses a different param style). Bug reported by Christophe Popov. Drivers ------- * Remove psycopg1. Driver ``psycopg`` is now just an alias for ``psycopg2``. Tests ----- * Install psycopg2 from `psycopg2-binary`_ package. .. _`psycopg2-binary`: https://pypi.org/project/psycopg2-binary/ For a more complete list, please see the news: http://sqlobject.org/News.html What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Python 2.7 or 3.4+ is required. Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Download: https://pypi.org/project/SQLObject/3.7.0/ News and changes: http://sqlobject.org/News.html StackOverflow: https://stackoverflow.com/questions/tagged/sqlobject Example ======= Create a simple class that wraps a table:: >>> from sqlobject import * >>> >>> sqlhub.processConnection = connectionForURI('sqlite:/:memory:') >>> >>> class Person(SQLObject): ... fname = StringCol() ... mi = StringCol(length=1, default=None) ... lname = StringCol() ... >>> Person.createTable() Use the object:: >>> p = Person(fname="John", lname="Doe") >>> p >>> p.fname 'John' >>> p.mi = 'Q' >>> p2 = Person.get(1) >>> p2 >>> p is p2 True Queries:: >>> p3 = Person.selectBy(lname="Doe")[0] >>> p3 >>> pc = Person.select(Person.q.lname=="Doe").count() >>> pc 1 Oleg. -- Oleg Broytman https://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From __peter__ at web.de Wed Jun 6 12:51:11 2018 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Jun 2018 18:51:11 +0200 Subject: site package does not work References: <905884138.650082.1528230791659.ref@mail.yahoo.com> <905884138.650082.1528230791659@mail.yahoo.com> Message-ID: Erik Martinson via Python-list wrote: > I am trying to dynamically add a site-package to a script that is run as a > cron job. The method adduseristepackages does not seem to do anything. The function addusersitepackages() seems to be un(der)documented; looking at the source it turns out that the expected argument is a sequence of known paths rather than a directory you want to add. If you need to add a directory that is not deteced by getusersitepackages() you can do so with addsitedir(my_directory) or by modifying sys.path directly with sys.path.append(my_directory). However, > site.addusersitepackages('/home/erik/.local/lib/python3.6/site-packages')) I recommend that you install the required packages as root rather than trick root into executing user-modifiable code, or, even better, that you run the cron job as user "erik". From shakti.shrivastava13 at gmail.com Wed Jun 6 12:51:12 2018 From: shakti.shrivastava13 at gmail.com (Shakti Kumar) Date: Wed, 6 Jun 2018 22:21:12 +0530 Subject: Problem finding my folder via terminal In-Reply-To: <96bbacf2-482a-4670-80be-0ee784d255e3@googlegroups.com> References: <96bbacf2-482a-4670-80be-0ee784d255e3@googlegroups.com> Message-ID: Hi Berger, Do you have any space in the absolute path for mymodules? Spaces avoid getting the correct path as I had seen in one of my virtual environments. Shakti. On Wed, Jun 6, 2018, 9:53 PM T Berger wrote: > I?m learning Python on my own and have been stuck for two days trying to > get modules I created into site-packages. As a trial step, we were asked to > change directly into the folder containing our modules. I typed ?cd > mymodules? per instructions, but got this error message: ?-bash: cd: > mymodules: No such file or directory.? I saved mymodules to my documents. > What is going wrong here? > > When I tried to create a distribution file, I typed ?192:~ TamaraB$ > mymodules$ python3 setup.py sdist.? I got this error message: ?-bash: > mymodules$: command not found.? What should I do? > -- > https://mail.python.org/mailman/listinfo/python-list > From marko at pacujo.net Wed Jun 6 16:43:10 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 06 Jun 2018 23:43:10 +0300 Subject: Names and identifiers References: Message-ID: <87muw7y7c1.fsf@elektro.pacujo.net> ram at zedat.fu-berlin.de (Stefan Ram): > I was asked about the difference between a name and an > identifier. I was not sure. Ah, a delicious terminology debate ahead! Traditionally, an "identifier" refers to a syntactic (lexical, to be exact) unit. It is a sequence of Unicode code points inside Python text. Ultimately, then, an identifier is a string that satisfies some lexical constraints. For example, the first code point must be a letter. "Name" is latter-day hypercorrect jargon for a variable. It is an abstract entity inside the Python runtime engine. It is a memory slot that can hold a temporal reference to an object. In Python text, you refer to these memory slots using identifiers (lists, dicts and tuples have memory slots as well, but I'll leave those out of this discussion). One identifier can refer to more than one memory slot. In fact, there is no limit to the number of memory slots that are referred to using an identical identifier (for example, you could have a parameter of a recursive function). > Shouldn't it say, > > NameError: identifier 'aiuerhguqieh' is not defined That's an odd way to put it. > or even, > > NameError: identifier 'aiuerhguqieh' is not a name That's better. Conceptually, every identifier in every context refers to a memory slot. Only a finite subset of them holds a reference to an object at any given time. Or to put it in Python-speak, all names exist, but not all of them are bound. Marko From steve+comp.lang.python at pearwood.info Wed Jun 6 19:43:20 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 6 Jun 2018 23:43:20 +0000 (UTC) Subject: Problem finding my folder via terminal References: <96bbacf2-482a-4670-80be-0ee784d255e3@googlegroups.com> Message-ID: Hi Tamara, and welcome! My response is written below. Please ensure your reply is to the group, not just to me personally, thank you. On Wed, 06 Jun 2018 09:19:17 -0700, T Berger wrote: > I?m learning Python on my own and have been stuck for two days trying to > get modules I created into site-packages. As a trial step, we were asked > to change directly into the folder containing our modules. Who asked you to do that? >From looking at the commands you give below, you are using Linux or Mac OS, is that right? > I typed ?cd mymodules? per instructions, but got this error message: > ?-bash: cd: mymodules: No such file or directory.? I saved mymodules to > my documents. What is going wrong here? My guess is that the mymodules folder is inside the "my documents" folder, so when you ask the computer to change into the mymodules folder, it can't see it. Remember that Linux is case-sensitive, so you have to get the exact upper/ lower case mix correct. Try: cd "My Documents/mymodules" and see if that works. Notice that the space inside "My Documents" means you need to use quotation marks. Adjust the uppercase "My Doc..." to lowercase "my doc..." if need be. If it doesn't work, try this: - start typing the command "cd My" *WITHOUT* the quote marks; - hit the TAB key; - hopefully the bash interpreter (the shell you are using) will auto-complete the name of the folder and save you typing the rest; - then start type "mym" (without the quotes!) and hit TAB again; - and hopefully the rest of the name will be auto-completed; - and finally hit ENTER and with luck that will work. If not, we'll need some more information about the computer you are using: what OS are you using (Mac, Linux, Windows, something else), what shell are you using, perhaps a file listing of your home directory. (Which I'm reluctant to ask for, as that potentially may show personal details you might not want to share with the world.) > When I tried to create a distribution file, I typed ?192:~ TamaraB$ > mymodules$ python3 setup.py sdist.? I got this error message: ?-bash: > mymodules$: command not found.? What should I do? The "mymodules$" part you saw in the instructions is not part of the command you need to type. That is intended to be the prompt. In your case, because you didn't successfully cd into the mymodules folder, your prompt hasn't changed from 192:~ TamaraB$ (I'm not sure what the 192 part means. Does that increase each time you type a command?) Once you successfully cd into the mymodules folder, the prompt will hopefully be: 192:mymodules$ or something similar to that. But whatever it is, you don't need to type the prompt as part of your commands. By the way, thank you for giving so much detail in your request for help! That was very helpful for me to help you. Many supposedly professional programmers don't give anywhere near as useful detail, thinking we can just read their mind and magically know what is going on. Keep up the good work! -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Wed Jun 6 21:23:31 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 7 Jun 2018 01:23:31 +0000 (UTC) Subject: Names and identifiers References: <87muw7y7c1.fsf@elektro.pacujo.net> Message-ID: Disclaimer: Ido not see Stefan's original post. I recall that he has set some sort of header on his posts which means they are not processed by Gmane, but unfortunately I no longer have any of his posts in my cache where I can check. If anyone else is getting Stefan's posts, can you inspect the full headers and see if there is a relevant header? On Wed, 06 Jun 2018 23:43:10 +0300, Marko Rauhamaa wrote: > ram at zedat.fu-berlin.de (Stefan Ram): > >> I was asked about the difference between a name and an identifier. I >> was not sure. The Python documentation makes it clear that "name" and "identifier" are considered synonyms and there is no difference: Identifiers (also referred to as names) are described by the following lexical definitions. https://docs.python.org/3/reference/lexical_analysis.html#identifiers So as far as Python is concerned, "name" and "identifier" mean precisely the same thing. > Ah, a delicious terminology debate ahead! > > Traditionally, an "identifier" refers to a syntactic (lexical, to be > exact) unit. It is a sequence of Unicode code points inside Python text. > Ultimately, then, an identifier is a string that satisfies some lexical > constraints. For example, the first code point must be a letter. I agree with this. > "Name" is latter-day hypercorrect jargon for a variable. I disagree with this. "Hypercorrectness" doesn't come into this. If you wanted to say "pedantic", I'd agree: there are shades of meaning between "variable" and "name" and "name binding", but often (especially in informal language) we can gloss over those subtleties. But the differences can lead us astray (see below). There are also legitimate and reasonable disagreement as to whether the term "variable" carries too much baggage to be useful in Python, but either way, there is no doubt that *names are not variables* in the same way that the name "Marko" is not *you*, the person. We wouldn't want to say that "names are people", or "names are pets", or "names are ships", and we shouldn't say that "names are variables". Names refer to people, pets, ships and variables. They aren't people, pets, ships or variables either. https://en.wikipedia.org/wiki/Use%E2%80%93mention_distinction Also relevant: https://en.wikipedia.org/wiki/Map%E2%80%93territory_relation > It is an > abstract entity inside the Python runtime engine. It is a memory slot > that can hold a temporal reference to an object. That is certainly wrong for Python, as Python variables typically are found in namespaces (implemented as dictionaries) not fixed memory slots. Even if an implementation should use memory slots for variables, that is not mandated by the language. It's a mere implementation detail. > In Python text, you refer to these memory slots using identifiers > (lists, dicts and tuples have memory slots as well, but I'll leave those > out of this discussion). One identifier can refer to more than one > memory slot. In fact, there is no limit to the number of memory slots > that are referred to using an identical identifier (for example, you > could have a parameter of a recursive function). Not the best example, because of course Python does enforce a limit on the number of recursive calls. But putting aside memory limits and similar, I don't think I like the terminology you use. I wouldn't say that one identifier can refer to multiple variables (absolutely not "memory slot", that's just wrong). If that were the case, and you mentioned the name "x", how would the interpreter know which variable you meant? Rather I would say that within a single context (or namespace), each identifier refers to no more than one variable. But the same name can be used in multiple contexts: - we can have a built-in "x", a global "x", and a local "x" at the same time; - the name resolution rules make it clear which one applies in context; - each function invocation results in a new context, so the local variable "x" in one call and the local variable "x" in another call are different "x"es. >> Shouldn't it say, >> >> NameError: identifier 'aiuerhguqieh' is not defined > > That's an odd way to put it. Since "name" and "identifier" are synonyms, it wouldn't be wrong to put it that way, but nor would there be any advantage. >> or even, >> >> NameError: identifier 'aiuerhguqieh' is not a name > > That's better. No, that is completely wrong. Of course "aiuerhguqieh" is a name. It matches the lexical definition of a name, and it occurred in the correct place to match the grammar rules for where names can occur (otherwise you would have had a SyntaxError). As far as the interpreter is concerned, it is a name, and that's all that matters. The programmer's intent hardly comes into it. (Maybe the person who typed that was under the misapprehension that they could use base-32 numeric literals, and intended it to be the decimal number 381626039374006737. Or maybe it was typed by a cat walking over the keyboard and there was no semantic intention at all.) > Conceptually, every identifier in every context refers to a memory slot. That's false. Of course the value of a variable must, if it is to exist inside a digital computer, be located *somewhere* in memory space at some moment in time. That's mere location, it isn't important, conceptually it is not part of the model of names and name bindings. (See what I mean about the unfortunate baggage of the C model for variables as memory locations and how it leads people astray?) The name/identifier is no more conceptually limited to a specific memory slot or location than the name/identifier "Marko" refers to the position in space you happen to be sitting in right now. When you move, the name follows you, it doesn't stick to the location. Likewise, if your Python interpreter has a garbage collector that can move objects (such as Jython and IronPython), when the object moves, the names referring to them follow the object. Names in general do not track memory slots (except as a mere accident of implementation). If they did, they would dangle when the objects move. > Only a finite subset of them holds a reference to an object at any given > time. > Or to put it in Python-speak, all names exist, but not all of them are > bound. Or to put it in terms which are less wrong, all names are names, but only some of them are defined. Names that have never been used only exist as some sort of purely Platonic abstraction. They don't *actually* exist in reality. Since there is no upper bound on the length of Python names (except that of memory), we can be pretty sure than the Vast majority of them have never, and never will, be written down in source code anywhere. Not if people are still programming in Python in a million years could we have actually used anything more than a vanishing subset of potential names. To put some hard numbers to it... the set of all possible names includes all the combinations of at least 5000 possible Unicode characters up to a maximum length of 2**64 (given existing computer limitations). So something of the order of 5000**(2**64) = 5000**18446744073709551616 or roughly 2**221360928884514619392 or 1 followed by approximately 66 million trillion zeroes possible names.[1] That is so much larger than the entire universe that the only way we can claim they all exist is to posit some sort of Platonic ideal existence. They exist only in the abstract, not in reality. [1] Admittedly the Vast majority would be utterly impractical to use. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Wed Jun 6 23:55:09 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 7 Jun 2018 03:55:09 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> Message-ID: On Tue, 05 Jun 2018 23:27:16 +1000, Chris Angelico wrote: > And an ASCIIZ string cannot contain a byte value of zero. The parallel > is exact. Why should we, as Python programmers, care one whit about ASCIIZ strings? They're not relevant. You might as well say that file names cannot contain the character "?" because ASCIIZ strings don't support it. No they don't, and yet nevertheless file names can and do contain characters outside of the ASCIIZ range. Python strings are rich objects which support the Unicode code point \0 in them. The limitation of the Linux kernel that it relies on NULL- terminated byte strings is irrelevant to the question of what os.path.exists ought to do when given a path containing NUL. Other invalid path names return False. As a Python programmer, how does treating NUL specially make our life better? I don't know what the implementation of os.path.exists is precisely, but in pseudocode I expect it is something like this: if "\0" in pathname: panic("OH NOES A NUL WHATEVER SHALL WE DO?!?!?!") else: ask the OS to do a stat on pathname if an error occurs: return False else: return True Why not just return False instead of panicking? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Thu Jun 7 00:14:56 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 7 Jun 2018 04:14:56 +0000 (UTC) Subject: Sorting NaNs References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On Sat, 02 Jun 2018 21:02:14 +1000, Chris Angelico wrote: > Point of curiosity: Why "> 0.5"? No particular reason, I just happened to hit that key and then copied and pasted the line into the next one. > Normally when I want a fractional > chance, I write the comparison the other way: "random.random() < 0.5" > has exactly a 50% chance of occurring (presuming that random.random() > follows its correct documented distribution). I've no idea what the > probability of random.random() returning exactly 0.5 is Neither do I. But I expect that "exactly 50% chance" is only approximately true :-) My understanding is that given the assumption of uniformity, the 50% chance is mathematically true, but in that case, it makes no difference whether you go from 0 to 0.5 or 0.5 to 1.0. Mathematically it makes no difference whether you include or exclude the end points. In the Real numbers, there's an uncountable infinity of points either way. *But* once you move to actual floats, that's no longer true. There are a great many more floats between 0 and 0.5 than between 0.5 and 1.0. Including the end points, if we enumerate the floats we get: 0.0 --> 0 0.5 --> 4602678819172646912 1.0 --> 4607182418800017408 so clearly the results of random.random() cannot be uniformly distributed over the individual floats. If they were, the probably of getting something less than or equal to 0.5 would be 4602678819172646912 / 4607182418800017407 or a little more than 99.9%. So given that our mathematically pure(ish) probability of 0.5 for the reals has to be mapped in some way to a finite number of floats, I wouldn't want to categorically say that that the probability remains *precisely* one half. But if it were (let's say) 1 ULP greater or less than one half, would we even know? 0.5 - 1 ULP = 0.49999999999999994 0.5 + 1 ULP = 0.5000000000000001 I would love to see the statistical experiment that could distinguish those two probabilities from exactly 1/2 to even a 90% confidence level :-) > but since it > can return 0.0 and cannot return 1.0, I've just always used less-than. > (Also because it works nicely with other values - there's a 30% chance > that random.random() is less than 0.3, etc.) Is there a reason for going > greater-than, or is it simply that it doesn't matter? No, no particular reason. If I had thought about it I would have used < too, but I didn't. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From greg.ewing at canterbury.ac.nz Thu Jun 7 03:02:42 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 07 Jun 2018 19:02:42 +1200 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: Steven D'Aprano wrote: > But if it were (let's say) 1 ULP greater or less > than one half, would we even know? In practice it's probably somewhat bigger than 1 ULP. A typical PRNG will first generate a 32-bit integer and then map it to a float, giving a resolution coarser than the 52 bits of an IEEE double. But even then, the probability of getting exactly 0.5 is only 1/2^32, which you're not likely to notice. -- Greg From mal at europython.eu Thu Jun 7 03:31:43 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 7 Jun 2018 09:31:43 +0200 Subject: EuroPython 2018: Training pass sale starts on Friday at 12:00 CEST Message-ID: <79cd8979-0810-771f-2836-2eed091ca82d@europython.eu> As we have already announced, access to trainings is not included in our regular conference tickets this year. We have done this to keep the conference ticket prices reasonable, acknowledge the value in the trainings are and to add more flexibility. Two full days of trainings included ----------------------------------- Training passes allow you to access all trainings on the two training days, Monday and Tuesday. Each training will run for 3 hours and they will be scheduled in 3 parallel tracks. Please note: Training access is on a first-come-first-served basis. We don?t provide registration for specific training sessions. A light lunch is served on the training days, which is included in the training pass price. * Business training pass: EUR 295.00 excl. VAT, EUR 354.00 incl. 20% UK VAT (for people using Python to make a living) * Personal training pass: EUR 175.00 incl. 20% UK VAT (for people enjoying Python from home) * Student training pass: EUR 125.00 incl. 20% UK VAT (only available for pupils, students and postdoctoral researchers; please bring your student card or declaration from University, stating your affiliation, starting and end dates of your contract) The trainings pass does not grant you permission to attend the main EuroPython conference days or the sprints. Please get a separate conference ticket for this. Available training sessions --------------------------- We have already selected an initial set of trainings, you can view on our session list: https://ep2018.europython.eu/en/events/sessions/#Training-sessions We will also have a few sponsored trainings, which are free (you don?t need a training pass to attend these). These will be announced in a separate blog post. Only a limited number of training passes available -------------------------------------------------- Since we don?t want to overbook the trainings sessions, we have limited the number of training passes to 200. Training pass sales will start on Friday, June 6, at around 12:00 CEST (that?s 10:00 UTC, 11:00 BST, 13:00 EEST, etc.). Given the experience with the early bird tickets, which sold out in less than 45 minutes, we recommend to get your ticket as soon as you can. Regular conference tickets are selling out much faster than last year as well, so the same recommendation applies to those as well: https://ep2018.europython.eu/en/registration/buy-tickets/ 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/174655358657/europython-2018-training-pass-sale-starts-on Tweet: https://twitter.com/europython/status/1004625811335458818 Enjoy, -- EuroPython 2018 Team https://ep2018.europython.eu/ https://www.europython-society.org/ From rosuav at gmail.com Thu Jun 7 03:45:06 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jun 2018 17:45:06 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> Message-ID: On Thu, Jun 7, 2018 at 1:55 PM, Steven D'Aprano wrote: > On Tue, 05 Jun 2018 23:27:16 +1000, Chris Angelico wrote: > >> And an ASCIIZ string cannot contain a byte value of zero. The parallel >> is exact. > > Why should we, as Python programmers, care one whit about ASCIIZ strings? > They're not relevant. You might as well say that file names cannot > contain the character "?" because ASCIIZ strings don't support it. > > No they don't, and yet nevertheless file names can and do contain > characters outside of the ASCIIZ range. Under Linux, a file name contains bytes, most commonly representing UTF-8 sequences. So... an ASCIIZ string *can* contain that character, or at least a representation of it. Yet it cannot contain "\0". ChrisA From rosuav at gmail.com Thu Jun 7 03:52:29 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jun 2018 17:52:29 +1000 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On Thu, Jun 7, 2018 at 2:14 PM, Steven D'Aprano wrote: > On Sat, 02 Jun 2018 21:02:14 +1000, Chris Angelico wrote: > >> Point of curiosity: Why "> 0.5"? > > No particular reason, I just happened to hit that key and then copied and > pasted the line into the next one. Hah! The simplicity of it. >> Normally when I want a fractional >> chance, I write the comparison the other way: "random.random() < 0.5" >> has exactly a 50% chance of occurring (presuming that random.random() >> follows its correct documented distribution). I've no idea what the >> probability of random.random() returning exactly 0.5 is > > Neither do I. But I expect that "exactly 50% chance" is only > approximately true :-) Oh, I have no doubt about that. (Though as Gregory says, the uniformity is based on the PRNG more than on any enumeration of floats. There are probably floating-point values between 0.0 and 1.0 that can never actually be returned.) > So given that our mathematically pure(ish) probability of 0.5 for the > reals has to be mapped in some way to a finite number of floats, I > wouldn't want to categorically say that that the probability remains > *precisely* one half. But if it were (let's say) 1 ULP greater or less > than one half, would we even know? > > 0.5 - 1 ULP = 0.49999999999999994 > > 0.5 + 1 ULP = 0.5000000000000001 > > > I would love to see the statistical experiment that could distinguish > those two probabilities from exactly 1/2 to even a 90% confidence > level :-) LOL, no kidding. How many RNG rolls would you need before you could even distinguish between 50-50 and 49-51% chance? How many people have done any sort of statistical analysis even that accurate? ChrisA From antoon.pardon at vub.be Thu Jun 7 04:04:53 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 7 Jun 2018 10:04:53 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> Message-ID: <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> On 07-06-18 05:55, Steven D'Aprano wrote: > Python strings are rich objects which support the Unicode code point \0 > in them. The limitation of the Linux kernel that it relies on NULL- > terminated byte strings is irrelevant to the question of what > os.path.exists ought to do when given a path containing NUL. Other > invalid path names return False. It is not irrelevant. It makes the disctinction clear between possible values and impossible values. Now you personnaly may find that distinction of minor importance but it is a relevant distinction in discussing how to treat it. > As a Python programmer, how does treating NUL specially make our life > better? By treating possible path values differently from impossible path values. -- Antoon. From marko at pacujo.net Thu Jun 7 05:29:27 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 07 Jun 2018 12:29:27 +0300 Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> Message-ID: <87o9gn3pxk.fsf@elektro.pacujo.net> Antoon Pardon : > On 07-06-18 05:55, Steven D'Aprano wrote: >> As a Python programmer, how does treating NUL specially make our life >> better? > > By treating possible path values differently from impossible path > values. There are all kinds of impossibility. The os.stat() reports those impossibilities via an OSError exception. It's just that os.path.exists() converts the OSError exception into a False return value. A ValueError is raised by the Python os.stat() wrapper to indicate that it can't even deliver the request to the kernel. The application programmer doesn't give an iota who determined the impossibility of a pathname. Unfortunately, os.path.exists() forces the distinction on the application. If I have to be prepared to catch a ValueError from os.path.exists(), what added value does os.path.exists() give on top of os.stat()? The whole point of os.path.exists() is 1. To provide an operating-system-independent abstraction. 2. To provide a boolean interface instead of an exception interface. This is a security risk. Here is a brief demonstration. Copy the example HTTP server from: Run the server. Try these URLs in your browser: 1. http://localhost:8000/ => The directory listing is provided 2. http://localhost:8000/test.html => A file is served or an HTTP error response (404) is generated 3. http://localhost:8000/te%00st.html => The server crashes with a ValueError and the TCP connection is reset Marko From marko at pacujo.net Thu Jun 7 05:40:43 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 07 Jun 2018 12:40:43 +0300 Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> Message-ID: <87k1rb3pes.fsf@elektro.pacujo.net> Marko Rauhamaa : > This is a security risk. Here is a brief demonstration. Copy the example > HTTP server from: > > ttp#http.server.SimpleHTTPRequestHandler> > > [...] > > 3. http://localhost:8000/te%00st.html > > => The server crashes with a ValueError and the TCP connection is > reset An exercise for the reader: provide a fix for the example server so the request returns a 404 response just like any other nonexistent resource. Marko From rosuav at gmail.com Thu Jun 7 05:47:03 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jun 2018 19:47:03 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: <87o9gn3pxk.fsf@elektro.pacujo.net> References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> Message-ID: On Thu, Jun 7, 2018 at 7:29 PM, Marko Rauhamaa wrote: > This is a security risk. Here is a brief demonstration. Copy the example > HTTP server from: > > ttp#http.server.SimpleHTTPRequestHandler> > > Run the server. Try these URLs in your browser: > > 1. http://localhost:8000/ > > => The directory listing is provided > > 2. http://localhost:8000/test.html > > => A file is served or an HTTP error response (404) is generated > > 3. http://localhost:8000/te%00st.html > > => The server crashes with a ValueError and the TCP connection is > reset > Actually, I couldn't even get Chrome to make that request, so it obviously was considered by the browser to be invalid. Doing the request with curl produced a traceback on the server and an empty response in the client. (And then the server returns to handling requests normally.) How is this a security risk, exactly? To be fair, it's somewhat unideal behaviour - I would prefer to see an HTTP 500 come back if the server crashes - but I can't see that that's a security problem. Just a QOS issue, wherein you might get a 500 rather than a 404 for certain requests. ChrisA From antoon.pardon at vub.be Thu Jun 7 06:21:04 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 7 Jun 2018 12:21:04 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: <87o9gn3pxk.fsf@elektro.pacujo.net> References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> Message-ID: <318eaece-8d16-f37f-9cff-74a081ffcb5c@vub.be> On 07-06-18 11:29, Marko Rauhamaa wrote: > Antoon Pardon : > >> On 07-06-18 05:55, Steven D'Aprano wrote: >>> As a Python programmer, how does treating NUL specially make our life >>> better? >> By treating possible path values differently from impossible path >> values. > There are all kinds of impossibility. The os.stat() reports those > impossibilities via an OSError exception. It's just that > os.path.exists() converts the OSError exception into a False return > value. A ValueError is raised by the Python os.stat() wrapper to > indicate that it can't even deliver the request to the kernel. > > The application programmer doesn't give an iota who determined the > impossibility of a pathname. So? The fact that the application programmer doesn't give an iota who determined the impossibility of a pathname, doesn't imply he is equally unconcerned about the specific impossibility he ran into. > Unfortunately, os.path.exists() forces the > distinction on the application. No it doesn't. It forces the distinction between two different kinds of impossibilities, but you don't have to care where they originate from. > If I have to be prepared to catch a > ValueError from os.path.exists(), what added value does os.path.exists() > give on top of os.stat()? The whole point of os.path.exists() is > > 1. To provide an operating-system-independent abstraction. > > 2. To provide a boolean interface instead of an exception interface. Mayby trying to provide such an interface is inherently flawed. Answering me a path doesn't exist because of a permission problem is IMO not a good idea. -- Antoon. From marko at pacujo.net Thu Jun 7 06:47:07 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 07 Jun 2018 13:47:07 +0300 Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> Message-ID: <87efhi50wk.fsf@elektro.pacujo.net> Chris Angelico : > On Thu, Jun 7, 2018 at 7:29 PM, Marko Rauhamaa wrote: >> 3. http://localhost:8000/te%00st.html >> >> => The server crashes with a ValueError and the TCP connection is >> reset >> > > Actually, I couldn't even get Chrome to make that request, so it > obviously was considered by the browser to be invalid. Wow! Why on earth? > it's somewhat unideal behaviour - I would prefer to see an HTTP 500 > come back if the server crashes - but I can't see that that's a > security problem. Just a QOS issue, wherein you might get a 500 rather > than a 404 for certain requests. It's a demonstration of how this innocent-looking problem can lead to surprising and even serious consequences. The given URI is well-formed and should not give any particular trouble to any HTTP server. Marko From none at gmail.com Thu Jun 7 07:09:18 2018 From: none at gmail.com (ast) Date: Thu, 7 Jun 2018 13:09:18 +0200 Subject: round Message-ID: <5b191260$0$5505$426a74cc@news.free.fr> Hi round is supposed to provide an integer when called without any precision argument. here is the doc: >>> help(round) round(number[, ndigits]) -> number Round a number to a given precision in decimal digits (default 0 digits). This returns an int when called with one argument, otherwise the same type as the number but in some circumstances it provides a float import numpy as np M = np.array([[0, 9],[2, 7]], dtype=int) np.linalg.det(M) -18.000000000000004 round(np.linalg.det(M)) -18.0 # i was expecting an integer -18, not a float # same problem with np.round np.round(np.linalg.det(M)) -18.0 From lutz.horn at posteo.de Thu Jun 7 07:58:47 2018 From: lutz.horn at posteo.de (Lutz Horn) Date: Thu, 07 Jun 2018 13:58:47 +0200 Subject: round In-Reply-To: <5b191260$0$5505$426a74cc@news.free.fr> References: <5b191260$0$5505$426a74cc@news.free.fr> Message-ID: <1be0c41d9886a90baf2a4f02a68edc4b@posteo.de> > M = np.array([[0, 9],[2, 7]], dtype=int) > np.linalg.det(M) > -18.000000000000004 > round(np.linalg.det(M)) np.linalg.det(M) has type numpy.float64, not float. Try this: >>> round(float(np.linalg.det(M))) -18 Lutz From steve+comp.lang.python at pearwood.info Thu Jun 7 08:13:20 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 7 Jun 2018 12:13:20 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> Message-ID: On Thu, 07 Jun 2018 19:47:03 +1000, Chris Angelico wrote: > To be fair, it's somewhat unideal behaviour - I would prefer to see an > HTTP 500 come back if the server crashes - but I can't see that that's a > security problem. You think that being able to remotely crash a webserver isn't a security issue? If Denial Of Service isn't a security issue in your eyes, what would it take? "Armed men burst into your house and shoot you"? *only half a wink* -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Thu Jun 7 08:15:27 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jun 2018 22:15:27 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: <87efhi50wk.fsf@elektro.pacujo.net> References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> <87efhi50wk.fsf@elektro.pacujo.net> Message-ID: On Thu, Jun 7, 2018 at 8:47 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Thu, Jun 7, 2018 at 7:29 PM, Marko Rauhamaa wrote: >>> 3. http://localhost:8000/te%00st.html >>> >>> => The server crashes with a ValueError and the TCP connection is >>> reset >>> >> it's somewhat unideal behaviour - I would prefer to see an HTTP 500 >> come back if the server crashes - but I can't see that that's a >> security problem. Just a QOS issue, wherein you might get a 500 rather >> than a 404 for certain requests. > > It's a demonstration of how this innocent-looking problem can lead to > surprising and even serious consequences. > > The given URI is well-formed and should not give any particular trouble > to any HTTP server. You haven't demonstrated a security problem. Don't claim security risks unless you can show there's at least a possibility of that; otherwise, it's just FUD. ChrisA From __peter__ at web.de Thu Jun 7 08:17:29 2018 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Jun 2018 14:17:29 +0200 Subject: round References: <5b191260$0$5505$426a74cc@news.free.fr> Message-ID: ast wrote: > Hi > > round is supposed to provide an integer when > called without any precision argument. > > here is the doc: > > >>> help(round) > > round(number[, ndigits]) -> number > > Round a number to a given precision in decimal digits (default 0 digits). > This returns an int when called with one argument, otherwise the > same type as the number That's not the complete story. Quoting https://docs.python.org/dev/library/functions.html#round """ For a general Python object number, round delegates to number.__round__. """ Bogus example to make the point: >>> class A: ... def __round__(self): return "whatever" ... >>> round(A()) 'whatever' > but in some circumstances it provides a float > > import numpy as np > > M = np.array([[0, 9],[2, 7]], dtype=int) > np.linalg.det(M) > -18.000000000000004 > round(np.linalg.det(M)) > -18.0 # i was expecting an integer -18, not a float > > # same problem with np.round > np.round(np.linalg.det(M)) > -18.0 >>> M = np.array([[0, 9],[2, 7]], dtype=int) >>> type(np.linalg.det(M)) So numpy.linalg.det() returns a custom type float64 which maps round() to float64: >>> round(np.float64(1.23)) 1.0 >>> type(_) From steve+comp.lang.python at pearwood.info Thu Jun 7 08:18:53 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 7 Jun 2018 12:18:53 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> <87efhi50wk.fsf@elektro.pacujo.net> Message-ID: On Thu, 07 Jun 2018 13:47:07 +0300, Marko Rauhamaa wrote: > Chris Angelico : > >> On Thu, Jun 7, 2018 at 7:29 PM, Marko Rauhamaa >> wrote: >>> 3. http://localhost:8000/te%00st.html >>> >>> => The server crashes with a ValueError and the TCP connection is >>> reset >>> >>> >> Actually, I couldn't even get Chrome to make that request, so it >> obviously was considered by the browser to be invalid. > > Wow! Why on earth? It works in Firefox, but Apache truncates the URL: Not Found The requested URL /te was not found on this server. instead of te%00st.html I wonder how many publicly facing web servers can be induced to either crash, or serve the wrong content, this way? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Thu Jun 7 08:28:03 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 7 Jun 2018 12:28:03 +0000 (UTC) Subject: round References: <5b191260$0$5505$426a74cc@news.free.fr> Message-ID: On Thu, 07 Jun 2018 13:09:18 +0200, ast wrote: > Hi > > round is supposed to provide an integer when called without any > precision argument. True, but that's really under the control of the object you feed it to. It would be possible for round() to enforce that, but it might break code that relies on having __round__ return a non-int. [...] > round(np.linalg.det(M)) > -18.0 # i was expecting an integer -18, not a float Yes, that's surprising, but I'm not sure if that's a bug or not, and if it is a bug, whether it counts as a bug in round() or in numpy. Most Python operators and functions that call dunder methods specify the *expected* but not *mandatory* behaviour. There are a few exceptions: py> class BadClass: ... def __len__(self): ... return "Surprise!" ... py> x = BadClass() py> len(x) Traceback (most recent call last): File "", line 1, in TypeError: 'str' object cannot be interpreted as an integer but generally it is up to the object itself to do the right thing, or else have a good reason not to. My feeling here is that this *probably* counts as a bug in numpy, but I'm open to persuasion otherwise. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Thu Jun 7 08:43:54 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jun 2018 22:43:54 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> Message-ID: On Thu, Jun 7, 2018 at 10:13 PM, Steven D'Aprano wrote: > On Thu, 07 Jun 2018 19:47:03 +1000, Chris Angelico wrote: > >> To be fair, it's somewhat unideal behaviour - I would prefer to see an >> HTTP 500 come back if the server crashes - but I can't see that that's a >> security problem. > > You think that being able to remotely crash a webserver isn't a security > issue? > > > If Denial Of Service isn't a security issue in your eyes, what would it > take? "Armed men burst into your house and shoot you"? > > *only half a wink* > By "crash" I mean that the request handler popped out an exception. The correct behaviour is to send back a 500 and go back to handling requests; with the extremely simple server given in that example, it fails to send back the 500, but it DOES go back to handling requests. So it's not a DOS. In any real server environment, this wouldn't have any significant impact; even in this trivially simple server, the only way you could hurt the server is by spamming enough of these that it runs out of file handles for sockets or something. ChrisA From rosuav at gmail.com Thu Jun 7 08:46:09 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jun 2018 22:46:09 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> <87efhi50wk.fsf@elektro.pacujo.net> Message-ID: On Thu, Jun 7, 2018 at 10:18 PM, Steven D'Aprano wrote: > On Thu, 07 Jun 2018 13:47:07 +0300, Marko Rauhamaa wrote: > >> Chris Angelico : >> >>> On Thu, Jun 7, 2018 at 7:29 PM, Marko Rauhamaa >>> wrote: >>>> 3. http://localhost:8000/te%00st.html >>>> >>>> => The server crashes with a ValueError and the TCP connection is >>>> reset >>>> >>>> >>> Actually, I couldn't even get Chrome to make that request, so it >>> obviously was considered by the browser to be invalid. >> >> Wow! Why on earth? > > It works in Firefox, but Apache truncates the URL: > > > Not Found > The requested URL /te was not found on this server. > > > instead of te%00st.html > > I wonder how many publicly facing web servers can be induced to either > crash, or serve the wrong content, this way? > Define "serve the wrong content". You could get the exact same content by asking for "te" instead of "te%00st.html"; what you've done is not significantly different from this: http://localhost:8000/te?st.html Is that a security problem too? ChrisA From steve+comp.lang.python at pearwood.info Thu Jun 7 08:47:15 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 7 Jun 2018 12:47:15 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> Message-ID: On Thu, 07 Jun 2018 10:04:53 +0200, Antoon Pardon wrote: > On 07-06-18 05:55, Steven D'Aprano wrote: >> Python strings are rich objects which support the Unicode code point \0 >> in them. The limitation of the Linux kernel that it relies on NULL- >> terminated byte strings is irrelevant to the question of what >> os.path.exists ought to do when given a path containing NUL. Other >> invalid path names return False. > > It is not irrelevant. It makes the disctinction clear between possible > values and impossible values. That is simply wrong. It is wrong in principle, and it is wrong in practice, for reasons already covered to death in this thread. It is *wrong in practice* because other impossible values don't raise ValueError, they simply return False: - illegal pathnames under Windows, those containing special characters like ? > < * etc, simply return False; - even on Linux, illegal pathnames like "" (the empty string) return False; - invalid pathnames with too many path components, or too many characters in a single component, simply return False; - the os.path.exists() function is not documented as making a three-way split between "exists, doesn't exist and invalid"; - and it isn't even true to say that NULL is illegal in pathnames: there are at least five file systems that allow either NUL bytes: FAT-8, MFS, HFS, or Unicode \0 code points: HFS Plus and Apple File System. And it is *wrong in principle* because in the most general case, there is no way to tell which pathnames are valid or invalid without querying an actual file system. In the case of Linux, any directory could be used as a mount point. Is "/mnt/some?file" valid or invalid? If an NTFS file system is mounted on /mnt, it is invalid; if an ext4 file system is mounted there, it is valid; if there's nothing mounted there, the question is impossible to answer. >> As a Python programmer, how does treating NUL specially make our life >> better? > > By treating possible path values differently from impossible path > values. But it doesn't do that. "Pathnames cannot contain NUL" is a falsehood that programmers wrongly believe about paths. HFS Plus and Apple File System support NULs in paths. So what it does is wrongly single out one *POSSIBLE* path value to raise an exception, while other so-called "impossible" path values simply return False. But in the spirit of compromise, okay, let's ignore the existence of file systems like HFS which allow NUL. Apart from Mac users, who uses them anyway? Let's pretend that every file system in existence, now and into the future, will prohibit NULs in paths. Have you ever actually used this feature? When was the last time you wrote code like this? try: flag = os.path.exists(pathname) except ValueError: handle_null_in_path() else: if flag: handle_file() else: handle_invalid_path_or_no_such_file() I want to see actual, real code used in production, not made up code snippets, that demonstrate that this is a useful distinction to make. Until such time that somebody shows me an actual real-world use-case for wanting to make this distinction for NULs and NULs alone, I call bullshit. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Thu Jun 7 09:09:47 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 7 Jun 2018 13:09:47 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> <87efhi50wk.fsf@elektro.pacujo.net> Message-ID: On Thu, 07 Jun 2018 22:46:09 +1000, Chris Angelico wrote: >> I wonder how many publicly facing web servers can be induced to either >> crash, or serve the wrong content, this way? >> >> > Define "serve the wrong content". You could get the exact same content > by asking for "te" instead of "te%00st.html"; Perhaps so, but maybe you can bypass access controls to te and get access to it even though it is supposed to be private. This is a real vulnerability, called null-byte injection. One component of the system sees a piece of input, truncates it at the NULL, and validates the truncated input; then another component acts on the untruncated (and unvalidated) input. https://resources.infosecinstitute.com/null-byte-injection-php/ https://capec.mitre.org/data/definitions/52.html Null-byte injection attacks have lead to remote attackers executing arbitrary code. That's unlikely in this scenario, but given that most web servers are written in C, not Python, it is conceivable that they could do anything under a null-byte injection attack. Does the Python web server suffer from that vulnerability? I would be surprised if it were. But it can be induced to crash (an exception, not a seg fault) which is certainly a vulnerability. Since people are unlikely to use this web server to serve mission critical public services over the internet, the severity is likely low. Nevertheless, it is still a real vulnerability. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Thu Jun 7 09:25:54 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jun 2018 23:25:54 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> <87efhi50wk.fsf@elektro.pacujo.net> Message-ID: On Thu, Jun 7, 2018 at 11:09 PM, Steven D'Aprano wrote: > On Thu, 07 Jun 2018 22:46:09 +1000, Chris Angelico wrote: > >>> I wonder how many publicly facing web servers can be induced to either >>> crash, or serve the wrong content, this way? >>> >>> >> Define "serve the wrong content". You could get the exact same content >> by asking for "te" instead of "te%00st.html"; > > Perhaps so, but maybe you can bypass access controls to te and get access > to it even though it is supposed to be private. > > This is a real vulnerability, called null-byte injection. > > One component of the system sees a piece of input, truncates it at the > NULL, and validates the truncated input; then another component acts on > the untruncated (and unvalidated) input. > > https://resources.infosecinstitute.com/null-byte-injection-php/ > > https://capec.mitre.org/data/definitions/52.html > > Null-byte injection attacks have lead to remote attackers executing > arbitrary code. That's unlikely in this scenario, but given that most web > servers are written in C, not Python, it is conceivable that they could > do anything under a null-byte injection attack. Fair point. So you should just truncate early and have done with it. Easy. > Does the Python web server suffer from that vulnerability? I would be > surprised if it were. But it can be induced to crash (an exception, not a > seg fault) which is certainly a vulnerability. "Certainly"? I'm dubious on that. This isn't C, where a segfault usually comes after executing duff memory, and therefore it's plausible to transform a segfault into a remote code execution exploit. This is Python, where we have EXCEPTION handling. Tell me, is this a vulnerability? @app.route("/foo") def foo(): return "Kaboom", 500 What about this? @app.route("/bar") def bar(): 1/0 return "Won't get here" Put those into a Flask app and see what they do. One of them will explicitly return a 500. The other will crash... and will return a 500. Is either of those a security problem? Now let's suppose a more realistic version of the latter: @app.route("/paginate/"): def paginate(size): total_pages = total_data/size ... Yes, it's a bug. If someone tries a page size of zero, it'll divide by zero and bomb. Great. But how is it a vulnerability? It is a properly-handled exception. It's slightly different with SimpleHTTPServer, as it fails to properly send back the 500. That would be a bug IMO. Even then, though, all you can do is clog the server with unfinished requests - and you can do that much more easily by just connecting and being really slow to send data. (And I doubt that people are using SimpleHTTPServer in security-sensitive contexts anyway.) ChrisA From steve+comp.lang.python at pearwood.info Thu Jun 7 09:32:10 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 7 Jun 2018 13:32:10 +0000 (UTC) Subject: Python web server weirdness Message-ID: I'm following the instructions here: https://docs.python.org/3/library/http.server.html and running this from the command line as a regular unprivileged user: python3.5 -m http.server 8000 What I expected was a directory listing of my current directory. What I got was Livejournal's front page. W.T.F.??? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From python.list at tim.thechases.com Thu Jun 7 09:32:44 2018 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 7 Jun 2018 08:32:44 -0500 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> <87efhi50wk.fsf@elektro.pacujo.net> Message-ID: <20180607083244.1e199ae3@bigbox.christie.dr> On 2018-06-07 22:46, Chris Angelico wrote: > On Thu, Jun 7, 2018 at 10:18 PM, Steven D'Aprano > >>>> 3. http://localhost:8000/te%00st.html > >>> Actually, I couldn't even get Chrome to make that request, so it > >>> obviously was considered by the browser to be invalid. It doesn't matter whether Chrome or Firefox can make the request if it can be made by opening the socket yourself with something as simple as $ telnet example.com 80 GET /te%00st.html HTTP/1.1 Host: example.com If that crashes the server, it's a problem, even if browsers try to prevent it from happening by accident. >> It works in Firefox, but Apache truncates the URL: >> >> Not Found >> The requested URL /te was not found on this server. >> >> instead of te%00st.html This is a sensible result, left up to each server to decide what to do. >> I wonder how many publicly facing web servers can be induced to >> either crash, or serve the wrong content, this way? I'm sure there are plenty. I mean, I discovered this a while back https://mail.python.org/pipermail/python-list/2016-August/713373.html and that's Microsoft running their own stack. They seem to have fixed that issue at that particular set of URLs, but a little probing has turned it up elsewhere at microsoft.com since (for the record, the first set of non-existent URLs return 404-not-found errors while the second set of reserved filename URLs return 500-Server-Internal-Error pages). Filename processing is full of sharp edge-cases. > Define "serve the wrong content". You could get the exact same > content by asking for "te" instead of "te%00st.html"; what you've > done is not significantly different from this: > > http://localhost:8000/te?st.html > > Is that a security problem too? Depending on the server, it might allow injection for something like http://example.com/page%00cat+/etc/passwd Or it might allow the request to be processed in an attack, but leave the log files without the details: GET /innocent%00malicious_payload (where only the "/innocent" gets logged) Or false data could get injected in log files http://example.com/innocent%00%0a23.200.89.180+-+-+%5b07/Jun/2018%3a13%3a55%3a36+-0700%5d+%22GET+/nasty_porn.mov+HTTP/1.0%22+200+2326 (`host whitehouse.gov` = 23.200.89.180) It all depends on the server and how the request is handled. -tkc From antoon.pardon at vub.be Thu Jun 7 09:35:17 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 7 Jun 2018 15:35:17 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> Message-ID: <1915fcb6-70aa-e973-75f0-00aa4c4054c0@vub.be> On 07-06-18 14:47, Steven D'Aprano wrote: > On Thu, 07 Jun 2018 10:04:53 +0200, Antoon Pardon wrote: > >> On 07-06-18 05:55, Steven D'Aprano wrote: >>> Python strings are rich objects which support the Unicode code point \0 >>> in them. The limitation of the Linux kernel that it relies on NULL- >>> terminated byte strings is irrelevant to the question of what >>> os.path.exists ought to do when given a path containing NUL. Other >>> invalid path names return False. >> It is not irrelevant. It makes the disctinction clear between possible >> values and impossible values. > That is simply wrong. It is wrong in principle, and it is wrong in > practice, for reasons already covered to death in this thread. > > It is *wrong in practice* because other impossible values don't raise > ValueError, they simply return False: > > - illegal pathnames under Windows, those containing special > characters like ? > < * etc, simply return False; > > - even on Linux, illegal pathnames like "" (the empty string) > return False; > > - invalid pathnames with too many path components, or too many > characters in a single component, simply return False; > > - the os.path.exists() function is not documented as making > a three-way split between "exists, doesn't exist and invalid"; So? Maybe we should reconsider the above behaviour? > > - and it isn't even true to say that NULL is illegal in pathnames: > there are at least five file systems that allow either NUL bytes: > FAT-8, MFS, HFS, or Unicode \0 code points: HFS Plus and Apple > File System. That doesn't matter much. sqrt(-1) gives a ValueError, while there are numberdomains for which it has a value. > And it is *wrong in principle* because in the most general case, there is > no way to tell which pathnames are valid or invalid without querying an > actual file system. In the case of Linux, any directory could be used as > a mount point. I don't see how your first statement follows from that explanation. I don't have a problem with needing to query the actual file system in order to find out which pathnames are valid or invalid. > Have you ever actually used this feature? When was the last time you? This is irrelevant. You are now trying to argue the uselesness. The fact that after consideration something turns out not very useful, is not a reason to conclude that the factors that were taken into consideration were irrelevant. Personaly I don't use os.path.exists because it tries to shoe horn too many possibilities into a boolean result. Do you think os.stat("\0") should raise FileNotFoundError? -- Antoon. From e at kellett.im Thu Jun 7 09:43:57 2018 From: e at kellett.im (Ed Kellett) Date: Thu, 7 Jun 2018 14:43:57 +0100 Subject: Python web server weirdness In-Reply-To: References: Message-ID: On 2018-06-07 14:32, Steven D'Aprano wrote: > I'm following the instructions here: > > https://docs.python.org/3/library/http.server.html > > > and running this from the command line as a regular unprivileged user: > > python3.5 -m http.server 8000 > > What I expected was a directory listing of my current directory. > > What I got was Livejournal's front page. > > W.T.F.??? > > Do you have LiveJournal's index.html in your current directory? -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From grant.b.edwards at gmail.com Thu Jun 7 09:44:26 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 7 Jun 2018 13:44:26 +0000 (UTC) Subject: Python web server weirdness References: Message-ID: On 2018-06-07, Steven D'Aprano wrote: > I'm following the instructions here: > > https://docs.python.org/3/library/http.server.html > > > and running this from the command line as a regular unprivileged user: > > python3.5 -m http.server 8000 > > What I expected was a directory listing of my current directory. > > What I got was Livejournal's front page. That's very odd. What I get is the message below: $ python3.5 -m http.server 8000 Serving HTTP on 0.0.0.0 port 8000 ... -- Grant Edwards grant.b.edwards Yow! I invented skydiving at in 1989! gmail.com From grant.b.edwards at gmail.com Thu Jun 7 09:46:49 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 7 Jun 2018 13:46:49 +0000 (UTC) Subject: Python web server weirdness References: Message-ID: On 2018-06-07, Steven D'Aprano wrote: > I'm following the instructions here: > > https://docs.python.org/3/library/http.server.html > > > and running this from the command line as a regular unprivileged user: > > python3.5 -m http.server 8000 > > What I expected was a directory listing of my current directory. > > What I got was Livejournal's front page. Looking into the crystal ball and guessing that "got" means you pointed a browser at "http://localhost:8000/"... Do you have a file named "index.html" in your home directory? https://docs.python.org/3/library/http.server.html If the request was mapped to a directory, the directory is checked for a file named index.html or index.htm (in that order). If found, the file?s contents are returned; -- Grant Edwards grant.b.edwards Yow! I want another at RE-WRITE on my CEASAR gmail.com SALAD!! From python.list at tim.thechases.com Thu Jun 7 09:51:39 2018 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 7 Jun 2018 08:51:39 -0500 Subject: Python web server weirdness In-Reply-To: References: Message-ID: <20180607085139.42a342a4@bigbox.christie.dr> On 2018-06-07 13:32, Steven D'Aprano wrote: > I'm following the instructions here: > > https://docs.python.org/3/library/http.server.html > > and running this from the command line as a regular unprivileged > user: > > python3.5 -m http.server 8000 > > What I expected was a directory listing of my current directory. > > What I got was Livejournal's front page. A couple things to check: 1) you don't mention which URL you pointed your browser at. I *presume* it was http://localhost:8000 but without confirmation, it's hard to tell. Also, you don't mention if you had anything in the {path} portion of the URL such as "http://localhost:8000/livejournal_homepage.html" 2) you don't mention whether your command succeeded with "Serving HTTP on 0.0.0.0 port 8000" or if it failed because perhaps something else was listening on that port ("OSError: [Errno 98] Address already in use"). 3) when your browser made the request to that localhost URL, did that command produce output logging the incoming requests? 4) do you have any funky redirection for localhost in your /etc/hosts file (or corresponding file location on Windows) -tkc From steve+comp.lang.python at pearwood.info Thu Jun 7 09:55:49 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 7 Jun 2018 13:55:49 +0000 (UTC) Subject: Python web server weirdness SOLVED References: Message-ID: On Thu, 07 Jun 2018 13:32:10 +0000, Steven D'Aprano wrote: [...] > python3.5 -m http.server 8000 > > What I expected was a directory listing of my current directory. > > What I got was Livejournal's front page. Never mind -- it turned out I had an "index.html" file in the directory which had been wget'ed from LiveJournal. When I deleted that, it worked as expected. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Thu Jun 7 10:37:29 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 7 Jun 2018 14:37:29 +0000 (UTC) Subject: Python web server weirdness References: Message-ID: On Thu, 07 Jun 2018 13:32:10 +0000, Steven D'Aprano wrote: > python3.5 -m http.server 8000 [...] Thank you to everyone who responded, pointing out that I should check for an index.html file. That was exactly the problem. And yes, I acknowledge that my original post was lacking in some necessary debugging detail. Mea culpa. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From brgrt2 at gmail.com Thu Jun 7 11:27:31 2018 From: brgrt2 at gmail.com (T Berger) Date: Thu, 7 Jun 2018 08:27:31 -0700 (PDT) Subject: Problem finding my folder via terminal In-Reply-To: <96bbacf2-482a-4670-80be-0ee784d255e3@googlegroups.com> References: <96bbacf2-482a-4670-80be-0ee784d255e3@googlegroups.com> Message-ID: On Wednesday, June 6, 2018 at 12:19:35 PM UTC-4, T Berger wrote: > I?m learning Python on my own and have been stuck for two days trying to get modules I created into site-packages. As a trial step, we were asked to change directly into the folder containing our modules. I typed ?cd mymodules? per instructions, but got this error message: ?-bash: cd: mymodules: No such file or directory.? I saved mymodules to my documents. What is going wrong here? > > When I tried to create a distribution file, I typed ?192:~ TamaraB$ mymodules$ python3 setup.py sdist.? I got this error message: ?-bash: mymodules$: command not found.? What should I do? ~~~~~ To answer your questions in order: ?Who asked you to do that?? I?m teaching myself python with the book, Head First Python. In the exercise I?m having trouble with, we?re supposed to install a module we created into site-packages. ?We'll need some more information about the computer you are using: what OS are you using (Mac, Linux, Windows, something else), what shell are you using, perhaps a file listing of your home directory. ? I?m using Terminal in Mac Sierra (10.12.6). ?(I'm not sure what the 192 part means. Does that increase each time you type a command?) ? I new to Terminal, but that 192 looked weird to me too. It doesn?t increase, just stays at 192. There is also a thin gray left bracket in front of the ?192? which didn?t copy into my email. Is there some way to restore the default prompt in Terminal? What is the default prompt? Back to my problem. Your email helped me get into the mymodules folder, but I?m still stuck at the next step of the exercise I?m working on, which is to getting the module I created into site-packages. The folder, mymodules, contains three files: the module we created, a setup file (setup.py), and a readme file. The line of text we were instructed to type into our terminal was: ?python3 setup.py sdist.? In response, I got this error message: ?/Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such file or directory?. What is going wrong here? Thanks to any replies From brgrt2 at gmail.com Thu Jun 7 11:39:48 2018 From: brgrt2 at gmail.com (T Berger) Date: Thu, 7 Jun 2018 08:39:48 -0700 (PDT) Subject: Problem finding my folder via terminal In-Reply-To: <96bbacf2-482a-4670-80be-0ee784d255e3@googlegroups.com> References: <96bbacf2-482a-4670-80be-0ee784d255e3@googlegroups.com> Message-ID: On Wednesday, June 6, 2018 at 12:19:35 PM UTC-4, T Berger wrote: > I?m learning Python on my own and have been stuck for two days trying to get modules I created into site-packages. As a trial step, we were asked to change directly into the folder containing our modules. I typed ?cd mymodules? per instructions, but got this error message: ?-bash: cd: mymodules: No such file or directory.? I saved mymodules to my documents. What is going wrong here? > > When I tried to create a distribution file, I typed ?192:~ TamaraB$ mymodules$ python3 setup.py sdist.? I got this error message: ?-bash: mymodules$: command not found.? What should I do? ~~~~ To answer your questions in order: ?Who asked you to do that?? I?m teaching myself python with the book, Head First Python. In the exercise I?m having trouble with, we?re supposed to install a module we created into site-packages. ?We'll need some more information about the computer you are using: what OS are you using (Mac, Linux, Windows, something else), what shell are you using, perhaps a file listing of your home directory. ? I?m using Terminal in Mac Sierra (10.12.6). ?(I'm not sure what the 192 part means. Does that increase each time you type a command?) ? I'm new to Terminal, but that 192 looked weird to me too. It doesn?t increase, just stays at 192. There is also a thin gray left bracket in front of the ?192? which didn?t copy into my email. Is there some way to restore the default prompt in Terminal (and what is the default prompt)? Back to my problem. Your email helped me get into the mymodules folder, but I?m still stuck at the next step of the exercise, which is to get the module I created into site-packages. mymodules contains three files: the module we created, a setup file (setup.py), and a readme file. The line of text we were instructed to type into our terminal was: ?python3 setup.py sdist.? In response, I got this error message: ?/Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such file or directory?. Why is this not working for me? Thanks to any replies From python at mrabarnett.plus.com Thu Jun 7 13:10:53 2018 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 7 Jun 2018 18:10:53 +0100 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> Message-ID: <45adc4df-b1ef-bfa0-474f-879a85c8547c@mrabarnett.plus.com> On 2018-06-07 08:45, Chris Angelico wrote: > On Thu, Jun 7, 2018 at 1:55 PM, Steven D'Aprano > wrote: >> On Tue, 05 Jun 2018 23:27:16 +1000, Chris Angelico wrote: >> >>> And an ASCIIZ string cannot contain a byte value of zero. The parallel >>> is exact. >> >> Why should we, as Python programmers, care one whit about ASCIIZ strings? >> They're not relevant. You might as well say that file names cannot >> contain the character "?" because ASCIIZ strings don't support it. >> >> No they don't, and yet nevertheless file names can and do contain >> characters outside of the ASCIIZ range. > > Under Linux, a file name contains bytes, most commonly representing > UTF-8 sequences. So... an ASCIIZ string *can* contain that character, > or at least a representation of it. Yet it cannot contain "\0". > I've seen a variation of UTF-8 that encodes U+0000 as 2 bytes so that a zero byte can be used as a terminator. It's therefore not impossible to have a version of Linux that allowed a (Unicode) "\0" in a filename. From email at paulstgeorge.com Thu Jun 7 13:12:00 2018 From: email at paulstgeorge.com (Paul St George) Date: Thu, 7 Jun 2018 19:12:00 +0200 Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: References: Message-ID: This is both a narrow question about some code and a more general question about syntax in Python Using the Pygame modules, I want to set both FULLSCREEN and DOUBLEBUF I can use screen = pygame.display.set_mode((screen_width,screen_height),pygame.FULLSCREEN) to set a FULLSCREEN display Or, I can use screen = pygame.display.set_mode((screen_width,screen_height),pygame.DOUBLEBUF) to set DOUBLEBUF But how do I set both FULLSCREEN and DOUBLEBUF? And, how can I test or check that DOUBLEBUF is set? -- Paul St George http://www.paulstgeorge.com http://www.devices-of-wonder.com From breamoreboy at gmail.com Thu Jun 7 13:41:56 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Thu, 7 Jun 2018 18:41:56 +0100 Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: References: Message-ID: On 07/06/18 18:12, Paul St George wrote: > This is both a narrow question about some code and a more general > question about syntax in Python > > Using the Pygame modules, I want to set both FULLSCREEN and DOUBLEBUF > > I can use > screen = > pygame.display.set_mode((screen_width,screen_height),pygame.FULLSCREEN) > to set a FULLSCREEN display > > Or, I can use > screen = > pygame.display.set_mode((screen_width,screen_height),pygame.DOUBLEBUF) > to set DOUBLEBUF > > But how do I set both FULLSCREEN and DOUBLEBUF? > > And, how can I test or check that DOUBLEBUF is set? > Pure guesswork but how about:- screen = pygame.display.set_mode((screen_width,screen_height), pygame.FULLSCREEN | pygame.DOUBLEBUF) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Thu Jun 7 13:52:39 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jun 2018 03:52:39 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: <45adc4df-b1ef-bfa0-474f-879a85c8547c@mrabarnett.plus.com> References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <45adc4df-b1ef-bfa0-474f-879a85c8547c@mrabarnett.plus.com> Message-ID: On Fri, Jun 8, 2018 at 3:10 AM, MRAB wrote: > On 2018-06-07 08:45, Chris Angelico wrote: >> Under Linux, a file name contains bytes, most commonly representing >> UTF-8 sequences. So... an ASCIIZ string *can* contain that character, >> or at least a representation of it. Yet it cannot contain "\0". >> > I've seen a variation of UTF-8 that encodes U+0000 as 2 bytes so that a zero > byte can be used as a terminator. > > It's therefore not impossible to have a version of Linux that allowed a > (Unicode) "\0" in a filename. Considering that Linux treats filenames as raw bytes, that's not surprising. The mangled encoding you refer to is a horrendous cheat, though, and violates several of the design principles of UTF-8, so I do not recommend it EVER. The correct way for Python to handle and represent such a file name would be to use the U+DCxx range to carry the bytes through unchanged - not using "\0". ChrisA From rosuav at gmail.com Thu Jun 7 13:56:49 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jun 2018 03:56:49 +1000 Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: References: Message-ID: On Fri, Jun 8, 2018 at 3:12 AM, Paul St George wrote: > This is both a narrow question about some code and a more general question > about syntax in Python > > Using the Pygame modules, I want to set both FULLSCREEN and DOUBLEBUF > > I can use > screen = > pygame.display.set_mode((screen_width,screen_height),pygame.FULLSCREEN) > to set a FULLSCREEN display > > Or, I can use > screen = > pygame.display.set_mode((screen_width,screen_height),pygame.DOUBLEBUF) > to set DOUBLEBUF > > But how do I set both FULLSCREEN and DOUBLEBUF? > > And, how can I test or check that DOUBLEBUF is set? This is definitely a pygame question. So let's grab the docos for that set_mode function. https://www.pygame.org/docs/ref/display.html#pygame.display.set_mode You're passing two parameters in each of your examples. The first is a tuple of (w,h) for the dimensions; the second is a constant for the mode you want. The name of the second argument is "flags", according to the documentation. That usually means that you can provide multiple. The exact mechanism for combining flags is given in the last paragraph of the docs. I'll let you take the credit for figuring out the details yourself :) ChrisA From jenil.desai25 at gmail.com Thu Jun 7 14:45:51 2018 From: jenil.desai25 at gmail.com (jenil.desai25 at gmail.com) Date: Thu, 7 Jun 2018 11:45:51 -0700 (PDT) Subject: logging with multiprocessing Message-ID: Hello, I am new to logging module. I want to use logging module with multiprocessing. can anyone help me understand how can I do it?. Any help would be appreciated. Thank you. From pkpearson at nowhere.invalid Thu Jun 7 16:36:25 2018 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 7 Jun 2018 20:36:25 GMT Subject: Stefan's headers [was:Names and identifiers] References: <87muw7y7c1.fsf@elektro.pacujo.net> Message-ID: On Thu, 7 Jun 2018 01:23:31 +0000 (UTC), Steven D'Aprano wrote: > Disclaimer: Ido not see Stefan's original post. I recall that he has set > some sort of header on his posts which means they are not processed by > Gmane, but unfortunately I no longer have any of his posts in my cache > where I can check. > > If anyone else is getting Stefan's posts, can you inspect the full > headers and see if there is a relevant header? Here's the full header, as received by slrn from news.individual.net: Path: uni-berlin.de!not-for-mail From: ram at zedat.fu-berlin.de (Stefan Ram) Newsgroups: comp.lang.python Subject: Names and identifiers Date: 6 Jun 2018 18:37:46 GMT Organization: Stefan Ram Lines: 26 Expires: 1 Aug 2018 11:59:58 GMT Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de y/fWNNOsUiR8l3NiIdt8QQKv4EmIpqY+4EFRjM4L9WcmK0 X-Copyright: (C) Copyright 2018 Stefan Ram. All rights reserved. Distribution through any means other than regular usenet channels is forbidden. It is forbidden to publish this article in the Web, to change URIs of this article into links, and to transfer the body without this notice, but quotations of parts in other Usenet posts are allowed. X-No-Archive: Yes Archive: no X-No-Archive-Readme: "X-No-Archive" is only set, because this prevents some services to mirror the article via the web (HTTP). But Stefan Ram hereby allows to keep this article within a Usenet archive server with only NNTP access without any time limitation. X-No-Html: yes Content-Language: en Xref: uni-berlin.de comp.lang.python:794657 From danielhglus at gmail.com Thu Jun 7 16:40:20 2018 From: danielhglus at gmail.com (Daniel Glus) Date: Thu, 7 Jun 2018 16:40:20 -0400 Subject: Valid encodings for a Python source file Message-ID: I'm trying to figure out the entire list of possible encodings for a Python source file - that is, encodings that can go in a PEP 263 encoding specification, like # -*- encoding: foo -*-. Is this list the same as the list given in the documentation for the codecs library, under "Standard Encodings" ? If not, where can I find the actual list? (I know that list is the same as the set of unique values in CPython's /Lib/encodings/aliases.py , or equivalently, the set of filenames in /Lib/encodings/ , but again I'm not sure.) -Daniel From pkpearson at nowhere.invalid Thu Jun 7 16:43:10 2018 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 7 Jun 2018 20:43:10 GMT Subject: Sorting NaNs References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On Thu, 07 Jun 2018 19:02:42 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: >> But if it were (let's say) 1 ULP greater or less >> than one half, would we even know? > > In practice it's probably somewhat bigger than 1 ULP. > A typical PRNG will first generate a 32-bit integer and > then map it to a float, giving a resolution coarser than > the 52 bits of an IEEE double. > > But even then, the probability of getting exactly 0.5 > is only 1/2^32, which you're not likely to notice. But gosh, if there are only 2**32 different "random" floats, then you'd have about a 50% chance of finding a collision among any set of 2**16 samples. Is that really tolerable? From rosuav at gmail.com Thu Jun 7 16:47:31 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jun 2018 06:47:31 +1000 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <87muw7y7c1.fsf@elektro.pacujo.net> Message-ID: On Fri, Jun 8, 2018 at 6:36 AM, Peter Pearson wrote: > Here's the full header, as received by slrn from news.individual.net: > > X-Copyright: (C) Copyright 2018 Stefan Ram. All rights reserved. Distribution through any means > other than regular usenet channels is forbidden. It is forbidden to publish this article in the > Web, to change URIs of this article into links, and to transfer the body without this > notice, but quotations of parts in other Usenet posts are allowed. > X-No-Archive: Yes > Archive: no > X-No-Archive-Readme: "X-No-Archive" is only set, because this prevents some services to mirror the > article via the web (HTTP). But Stefan Ram hereby allows to keep this article within a Usenet > archive server with only NNTP access without any time limitation. Yeah, if I were a sysadmin carrying this kind of traffic, I'd just block all those posts rather than risk any sort of legal liability. Not worth any sort of risk. A simple ban is easy and effective, and fully compliant with the copyright notice. (I don't understand this paranoia about HTTP, frankly.) ChrisA From diagonaldevice at gmail.com Thu Jun 7 19:49:45 2018 From: diagonaldevice at gmail.com (Michael Lamparski) Date: Thu, 7 Jun 2018 19:49:45 -0400 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On Thu, Jun 7, 2018 at 4:43 PM, Peter Pearson wrote: > But gosh, if there are only 2**32 different "random" floats, then > you'd have about a 50% chance of finding a collision among any > set of 2**16 samples. Is that really tolerable? > -- > https://mail.python.org/mailman/listinfo/python-list > In any case, it's verifiably not true for CPython. > >>> def birthday(b): > ... rand = random.random > ... xs = [rand() for _ in range(2**b)] > ... return len(xs) - len(set(xs)) > ... > >>> birthday(24) > 0 > >>> [birthday(24) for _ in range(10)] > [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] Michael From cs at cskk.id.au Thu Jun 7 20:04:11 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 8 Jun 2018 10:04:11 +1000 Subject: Problem finding my folder via terminal In-Reply-To: References: Message-ID: <20180608000411.GA62848@cskk.homeip.net> Hi, Replies inline below, which is the style we prefer on this list. (And to reply, please reply to the specific message, not your original post. This will let you pick up that branch of the conversation directly and not confuse your readers.) On 07Jun2018 08:39, T Berger wrote: >On Wednesday, June 6, 2018 at 12:19:35 PM UTC-4, T Berger wrote: >> I?m learning Python on my own and have been stuck for two days trying to get modules I created into site-packages. As a trial step, we were asked to change directly into the folder containing our modules. I typed ?cd mymodules? per instructions, but got this error message: ?-bash: cd: mymodules: No such file or directory.? I saved mymodules to my documents. What is going wrong here? >> >> When I tried to create a distribution file, I typed ?192:~ TamaraB$ mymodules$ python3 setup.py sdist.? I got this error message: ?-bash: mymodules$: command not found.? What should I do? [...snip...] > ?We'll need some more information about the computer you are using: what OS > are you using (Mac, Linux, Windows, something else), what shell are you > using, perhaps a file listing of your home directory. ? > >I?m using Terminal in Mac Sierra (10.12.6). Cool. >?(I'm not sure what the 192 part means. Does that increase each time you type a command?) ? > >I'm new to Terminal, but that 192 looked weird to me too. It doesn?t increase, just stays at 192. There is also a thin gray left bracket in front of the ?192? which didn?t copy into my email. Is there some way to restore the default prompt in Terminal (and what is the default prompt)? On a Mac, it tends to be like this: "{hostname}:~ {username}$ " where {hostname} is your Mac's name and {username} is your login name; that is called the "shell prompt", and "the shell" is the command line interpreter running the commands you type. On a Mac, this is usually bash, a UNIX Bourne shell. There is a secondary prompt like this "> ". That indicates that you're typing a compond command, or at least that the shell believes you're typing a compond command, which is just a command which extends to more than one line. The common way to confuse the shell about this is to forget to close a quote - the shell expects that string to continue until it sees a closing quote. You can leave the secondary prompt by typing Control-C (often denoted "^C"). That will cancel the incomplete command and get you back to a clean empty primary prompt. Note that if you start some interactive command, such as the interactive Python interpreter, you will then be dealing with _its_ prompts until you leave that command. >Back to my problem. Your email helped me get into the mymodules folder, but I?m still stuck at the next step of the exercise, which is to get the module I created into site-packages. mymodules contains three files: the module we created, a setup file (setup.py), and a readme file. The line of text we were instructed to type into our terminal was: ?python3 setup.py sdist.? In response, I got this error message: ?/Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such file or directory?. > >Why is this not working for me? I would expect that your shell is not actually in the "mymodules" directory when you typed "python3 setup.py sdist". Usually your shell prompt includes the current working directory (the "~" in my example above, which is your home directory), which is a useful contextual clue. You can also find out your current working directory by running the "pwd" command (the "print working directory" command). The "ls" (list) command without arguments will list what is in the current directory, so you can now check (a) whether you're where you thought you were, and (b) what is in the current directory (in case it doesn't contain what you expected). The "ls -la" command will provide a longer and more detailed listing too. Let us know what you find out. Cheers, Cameron Simpson From steve+comp.lang.python at pearwood.info Thu Jun 7 21:17:57 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 8 Jun 2018 01:17:57 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: On Thu, 07 Jun 2018 15:38:39 -0400, Dennis Lee Bieber wrote: > On Fri, 1 Jun 2018 23:16:32 +0000 (UTC), Steven D'Aprano > declaimed the following: > >>It should either return False, or raise TypeError. Of the two, since >>3.14159 cannot represent a file on any known OS, TypeError would be more >>appropriate. >> > I wouldn't be so sure of that... I would. There is no existing file system which uses floats instead of byte- or character-strings for file names. If you believe different, please name the file > Xerox CP/V allowed for embedding > non-printable characters into file names Just like most modern file systems. Even FAT-16 supports a range of non-ASCII bytes with the high-bit set (although not the control codes with the high-bit cleared). Unix file systems typically support any byte except \0 and /. Most modern file systems outside of Unix support any Unicode character (or almost any) including ASCII control characters. https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits [...] > With some work, one could probably generate a file name containing the > bytes used for storing a floating point value. Any collection of bytes can be interpreted as any thing we like. (Possibly requiring padding or splitting to fit fixed-width data structures.) Sounds. Bitmaps. Coordinates in three dimension space. Floating point numbers is no challenge. A Python float is represented by an eight-byte C double. Provided we agree on a convention for splitting byte strings into eight-byte chunks, adding padding, and agree on big- or little-endianness, it is trivial to convert file names to one or more floats: /etc is equivalent to 2.2617901550715974e-80 (big endian, padding added to the right) But just because I can do that conversion, doesn't mean that the file system uses floats for file names. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From tkadm30 at yandex.com Thu Jun 7 21:29:47 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Thu, 7 Jun 2018 21:29:47 -0400 Subject: Django-hotsauce/ZODB 5.4.0/PyPy nightly sprint!! Message-ID: Yo people I'm doing a nightly hacking sprint for django-hotsauce on pypy and got some cool bugs I would like to share: Traceback (most recent call last): ? File "/usr/local/bin/schevo", line 11, in ??? load_entry_point('libschevo', 'console_scripts', 'schevo')() ? File "/home/erob/src/libschevo/lib/schevo/script/command.py", line 32, in __call__ ??? return self.main(arg0, args) ? File "/home/erob/src/libschevo/lib/schevo/script/command.py", line 74, in main ??? return command()(*args) ? File "/home/erob/src/libschevo/lib/schevo/script/command.py", line 32, in __call__ ??? return self.main(arg0, args) ? File "/home/erob/src/libschevo/lib/schevo/script/command.py", line 74, in main ??? return command()(*args) ? File "/home/erob/src/libschevo/lib/schevo/script/command.py", line 32, in __call__ ??? return self.main(arg0, args) ? File "/home/erob/src/libschevo/lib/schevo/script/db_evolve.py", line 86, in main ??? db = schevo.database.open(url) ? File "/home/erob/src/libschevo/lib/schevo/database.py", line 371, in open ??? db = Database(backend) ? File "/home/erob/src/libschevo/lib/schevo/database2.py", line 95, in __init__ ??? self._update_extent_maps_by_name() ? File "/home/erob/src/libschevo/lib/schevo/database2.py", line 1633, in _update_extent_maps_by_name ??? for extent in self._extent_maps_by_id.itervalues(): ? File "/usr/local/lib/python2.7/dist-packages/ZODB/Connection.py", line 791, in setstate ??? p, serial = self._storage.load(oid) ? File "/usr/local/lib/python2.7/dist-packages/ZODB/mvccadapter.py", line 143, in load ??? r = self._storage.loadBefore(oid, self._start) ? File "/home/erob/work/ZEO-5.1.0/src/ZEO/ClientStorage.py", line 520, in loadBefore ??? return self._server.load_before(oid, tid) ? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", line 783, in load_before ??? return self.__call(self.client.load_before_threadsafe, oid, tid) ? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", line 748, in call ??? return self.wait_for_result(result, self.timeout) ? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", line 756, in wait_for_result ??? return future.result(timeout) ? File "/usr/local/lib/python2.7/dist-packages/futures-3.0.5-py2.7.egg/concurrent/futures/_base.py", line 405, in result ??? return self.__get_result() ? File "/usr/local/lib/python2.7/dist-packages/futures-3.0.5-py2.7.egg/concurrent/futures/_base.py", line 357, in __get_result ??? raise type(self._exception), self._exception, self._traceback ZEO.Exceptions.ClientDisconnected: connection lost erob at marina:/home/www/isotopesoftware.ca/trunk$ Not sure about this first one! :) The command I'm trying to run is: % schevo db evolve --app blogengine2 zodb://127.0.0.1:4545 31 The ZODB 5.4.0 server then produce the following traceback: 2018-06-07T21:14:55 INFO ZEO.asyncio.base Connected server protocol ------ 2018-06-07T21:14:55 INFO ZEO.asyncio.server received handshake 'Z5' ------ 2018-06-07T21:14:55 ERROR ZEO.asyncio.marshal can't decode message: '((ccopy_reg\n_reconstructor\n(czodbpickle\nbinary\nc__b...' ------ 2018-06-07T21:14:55 ERROR ZEO.asyncio.server Can't deserialize message Traceback (most recent call last): ? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/server.py", line 89, in message_received ??? message_id, async, name, args = self.decode(message) ? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/marshal.py", line 114, in pickle_server_decode ??? return unpickler.load() # msgid, flags, name, args ? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/marshal.py", line 164, in server_find_global ??? raise ImportError("import error %s: %s" % (module, msg)) ImportError: import error copy_reg: ------ 2018-06-07T21:14:55 ERROR ZEO.asyncio.base data_received 4 0 True Traceback (most recent call last): ? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/base.py", line 128, in data_received ??? self.message_received(collected) ? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/server.py", line 94, in message_received ??? if message_id == -1: UnboundLocalError: local variable 'message_id' referenced before assignment ------ 2018-06-07T21:14:55 INFO ZEO.StorageServer (127.0.0.1:4545) disconnected ------ 2018-06-07T21:14:55 INFO ZEO.asyncio.base Connected server protocol ------ 2018-06-07T21:14:55 INFO ZEO.asyncio.server received handshake 'Z5' ------ 2018-06-07T21:14:55 INFO ZEO.StorageServer (127.0.0.1:4545) disconnected Please hit me up if you know how to fix theses errors! :) I'm using PyPy 5.9 and 5.10 for dev and Python 2.7.13 for production with Cython bindings! Cheers, Etienne From steve+comp.lang.python at pearwood.info Thu Jun 7 22:15:02 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 8 Jun 2018 02:15:02 +0000 (UTC) Subject: Sorting NaNs References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On Thu, 07 Jun 2018 20:43:10 +0000, Peter Pearson wrote: > On Thu, 07 Jun 2018 19:02:42 +1200, Gregory Ewing wrote: >> Steven D'Aprano wrote: >>> But if it were (let's say) 1 ULP greater or less than one half, would >>> we even know? >> >> In practice it's probably somewhat bigger than 1 ULP. A typical PRNG >> will first generate a 32-bit integer and then map it to a float, giving >> a resolution coarser than the 52 bits of an IEEE double. >> >> But even then, the probability of getting exactly 0.5 is only 1/2^32, >> which you're not likely to notice. > > But gosh, if there are only 2**32 different "random" floats, then you'd > have about a 50% chance of finding a collision among any set of 2**16 > samples. Is that really tolerable? Why wouldn't it be? It would be shocking if a sufficiently large sequence of numbers contained no collisions at all: that would imply the values were very much NON random. If you truly were limited to 2**32 different values (we're not), then it would be exactly right and proper to expect a collision in 2**16 samples. Actually, a lot less than that: more like 78000. https://en.wikipedia.org/wiki/Birthday_problem (For 2**60 values, we'd need about 1.2 billion samples.) Greg's statement about "a typical PRNG" may or may not be true, depending on what counts as "typical". The standard C language PRNG is notoriously awful, with a tiny period and lots and lots of correlations between values. Its barely random-ish. But like many other languages, Python uses a more modern random number generator, the Mersenne Twister, which passes a battery of statistical tests for randomness (including DieHard) and has a very long period of 2**19937 - 1. I understand that Python's Mersenne Twister implementation is based on 64-bit ints. https://en.wikipedia.org/wiki/Mersenne_Twister -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Thu Jun 7 22:16:38 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 8 Jun 2018 02:16:38 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> <87efhi50wk.fsf@elektro.pacujo.net> Message-ID: On Thu, 07 Jun 2018 23:25:54 +1000, Chris Angelico wrote: [...] >> Does the Python web server suffer from that vulnerability? I would be >> surprised if it were. But it can be induced to crash (an exception, not >> a seg fault) which is certainly a vulnerability. > > "Certainly"? I'm dubious on that. This isn't C, where a segfault usually > comes after executing duff memory, and therefore it's plausible to > transform a segfault into a remote code execution exploit. I just said that I would be surprised if you could get remote code execution from the Python web server, for exactly the reason you state: its an exception, not a segfault. Stop agreeing with me when we're trying to have an argument! *wink* [...] > Yes, it's a bug. If someone tries a page size of zero, it'll divide by > zero and bomb. Great. But how is it a vulnerability? It is a > properly-handled exception. Causing a denial of service is a vulnerability. Security vulnerabilities are not just about remote code execution. Can remote attackers bring your service down? If so, you are vulnerable to having remote attackers bring your service down. Can remote attackers overwhelm your server with so many errors that they fill your disks with error logs and either stop logging, or crash? Then you are vulnerable to having remote attackers crash your server, or hide their tracks by preventing logging. Can remote attackers induce your server to serve files it shouldn't? Then you are vulnerable to attacks that leak sensitive or private information. There's far more to security vulnerabilities than just "oh well, they can't get a shell or execute code on my server, so it's all cool" *wink* In this specific case: > It's slightly different with SimpleHTTPServer, as it fails to properly > send back the 500. That would be a bug IMO. There seems to be some weird interaction occurring on my system between the SimpleHTTPServer, Firefox, and my web proxy, so I may have misinterpreted the precise nature of the crash. What I initially saw was that allow the SimpleHTTPServer remained running, it stopped responding to requests and Firefox would repeatedly respond: Firefox can't find the server at www.localhost.com even though the process was still running. But when I tried with a different browser (links), I don't get that same behaviour. links is using the web proxy, Firefox isn't, but I'm not quite sure why that makes a difference. > Even then, though, all you > can do is clog the server with unfinished requests - and you can do that > much more easily by just connecting and being really slow to send data. > (And I doubt that people are using SimpleHTTPServer in > security-sensitive contexts anyway.) Again, you're just repeating what I said in different words. I already said that *this specific* issue is probably low severity, because people are unlikely to use SimpleHTTPServer for mission critical services exposed to the internet. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Thu Jun 7 22:19:20 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 8 Jun 2018 02:19:20 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> Message-ID: On Thu, 07 Jun 2018 17:45:06 +1000, Chris Angelico wrote: > On Thu, Jun 7, 2018 at 1:55 PM, Steven D'Aprano > wrote: >> On Tue, 05 Jun 2018 23:27:16 +1000, Chris Angelico wrote: >> >>> And an ASCIIZ string cannot contain a byte value of zero. The parallel >>> is exact. >> >> Why should we, as Python programmers, care one whit about ASCIIZ >> strings? They're not relevant. You might as well say that file names >> cannot contain the character "?" because ASCIIZ strings don't support >> it. >> >> No they don't, and yet nevertheless file names can and do contain >> characters outside of the ASCIIZ range. > > Under Linux, a file name contains bytes, most commonly representing > UTF-8 sequences. The fact that user-space applications like the shell and GUI file managers sometimes treat file names at UTF-8 Unicode is not really relevant to what the file system allows. The most common Linux file systems are fundamentally bytes, not Unicode characters, and while I'm willing to agree to call the byte 0x41 "A", there simply is no such byte that means "?" or U+10902 PHOENICIAN LETTER GAML. File names under typical Linux file systems are not necessarily valid UTF-8 Unicode. That's why Python still provides a bytes-interface as well as a text interface. > So... an ASCIIZ string *can* contain that character, or > at least a representation of it. Yet it cannot contain "\0". You keep saying that as if it made one whit of difference to what os.path.exists should do. I completely agree that ASCIIZ strings cannot contain NUL bytes. What does that have to do with os.path.exists()? NTFS file systems use UTF-16 encoded strings. For typical mostly-ASCII pathnames, the bytes on disk are *full* of NUL bytes. If the implementation detail that ASCIIZ strings cannot contain NUL is important to you, it should be equally important that UTF-16 strings typically have many NULs. They're actually both equally implementation details and utterly irrelevant to the behaviour of os.path.exists. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Thu Jun 7 22:23:40 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jun 2018 12:23:40 +1000 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On Fri, Jun 8, 2018 at 12:15 PM, Steven D'Aprano wrote: > If you truly were limited to 2**32 different values (we're not), then it > would be exactly right and proper to expect a collision in 2**16 samples. > Actually, a lot less than that: more like 78000. > > https://en.wikipedia.org/wiki/Birthday_problem 2**16 is 65536, so the figure you give is pretty close to the rule-of-thumb estimate that the square root of your pool is where you're likely to have collisions. ChrisA From rosuav at gmail.com Thu Jun 7 22:42:13 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jun 2018 12:42:13 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> <87efhi50wk.fsf@elektro.pacujo.net> Message-ID: On Fri, Jun 8, 2018 at 12:16 PM, Steven D'Aprano wrote: > On Thu, 07 Jun 2018 23:25:54 +1000, Chris Angelico wrote: >> Yes, it's a bug. If someone tries a page size of zero, it'll divide by >> zero and bomb. Great. But how is it a vulnerability? It is a >> properly-handled exception. > > Causing a denial of service is a vulnerability. Yes, but remember, anyone can build a botnet and send large numbers of entirely legitimate requests to your server. Since no server has infinite capacity, a DOS is inherently unavoidable. So to call something a "DOS vulnerability", you have to show that it makes you *more vulnerable* than simply getting overloaded with requests. For example: 1) If the kernel allocates resources for half-open socket connections, a malicious client can SYN-flood the server, causing massive resource usage from relatively few packets. 2) If the language can be induced to build a hashtable using values that all have the same hash, the CPU load required for the O(n?) operations can easily exceed the cost of making the requests. 3) If the app inefficiently performs many database transactions for a simple request, a plausible number of such requests could slow the database to a crawl. 4) If a small request results in an inordinately large response, the server's outgoing bandwidth can be saturated by a small number of requests. Where in this is a simple HTTP 500 from the os.stat() call worse than a legitimate request for an actual page? The response is small (far smaller than many legit files - consider a web app with a large JavaScript bundle, easily multiple megabytes). It required zero disk operations, so it's as fast as returning a file from cache. The only way it's more expensive is the actual exception handling code itself, and if you reckon someone can DOS a server via the cost of throwing and catching exceptions, I'm going to have to ask for some serious measurements. Apart from the one odd bug with SimpleHTTPServer not properly sending back 500s, I very much doubt that the original concern - namely that os.path.exists() and os.stat() raise ValueError if therels a %00 in the URL - can be abused effectively. ChrisA From Richard at Damon-Family.org Thu Jun 7 22:56:49 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 7 Jun 2018 22:56:49 -0400 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: On 6/7/18 9:17 PM, Steven D'Aprano wrote: > On Thu, 07 Jun 2018 15:38:39 -0400, Dennis Lee Bieber wrote: > >> On Fri, 1 Jun 2018 23:16:32 +0000 (UTC), Steven D'Aprano >> declaimed the following: >> >>> It should either return False, or raise TypeError. Of the two, since >>> 3.14159 cannot represent a file on any known OS, TypeError would be more >>> appropriate. >>> >> I wouldn't be so sure of that... > I would. > > There is no existing file system which uses floats instead of byte- or > character-strings for file names. If you believe different, please name > the file > > >> Xerox CP/V allowed for embedding >> non-printable characters into file names > Just like most modern file systems. > > Even FAT-16 supports a range of non-ASCII bytes with the high-bit set > (although not the control codes with the high-bit cleared). Unix file > systems typically support any byte except \0 and /. Most modern file > systems outside of Unix support any Unicode character (or almost any) > including ASCII control characters. > > https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits > > > This does bring up an interesting point. Since the Unix file system really has file names that are collection of bytes instead of really being strings, and the Python API to it want to treat them as strings, then we have an issue that we are going to be stuck with problems with filenames. If we assume they are utf-8 encoded, then there exist filenames that will trap with invalid encodings? (if for example the name were generated on a system that was using Latin-1 as an 8 bit character set for file names). On the other hand, if we treat the file names as 8 bit characters by themselves, if the system was using utf-8 then we are mangling any characters outside the basic ASCII set. Basically we hit to old problem of confusing bytes and strings. Ultimately we have a fundamental limitation with trying to abstract out the format of filenames in the API, and we need a back door to allow us to define what encoding to use for filenames (and be able to detect that it doesn't work for a given file, and change it on the fly to try again), or we need an alternate API that lets us pass raw bytes as file names and the program needs to know how to handle the raw filename for that particular file system. -- Richard Damon From ben+python at benfinney.id.au Thu Jun 7 23:00:24 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 08 Jun 2018 13:00:24 +1000 Subject: Valid encodings for a Python source file References: Message-ID: <85vaaugeyf.fsf@benfinney.id.au> Daniel Glus writes: > I'm trying to figure out the entire list of possible encodings for a Python > source file - that is, encodings that can go in a PEP 263 > encoding specification, like # > -*- encoding: foo -*-. What if the answer is not an emunerated set of encodings? That is, I am pretty sure the set isn't specified, to allow the encoding to be negotiated. Whatever the interpreter recognises as an encoding can be the encoding of the source. So, I guess that leads to the question: Why do you need it to be an exhaustive set (rather than deliberately unspecified)? What are you hoping to do with that information? -- \ ?Good design adds value faster than it adds cost.? ?Thomas C. | `\ Gale | _o__) | Ben Finney From ben+python at benfinney.id.au Thu Jun 7 23:12:32 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 08 Jun 2018 13:12:32 +1000 Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: <85r2ligee7.fsf@benfinney.id.au> Richard Damon writes: > This does bring up an interesting point. Since the Unix file system > really has file names that are collection of bytes instead of really > being strings, and the Python API to it want to treat them as strings, > then we have an issue that we are going to be stuck with problems with > filenames. I agree with the general statement ?we are going to be stuck with problems with filenames?; the world of filesystems is messy, which will always cause problems. With that said, I don't agree that ?the Python API wants to treat [file paths] as strings?. The ?os? module explicitly promises to treat bytes as bytes, and text as text, in filesystem paths: Note: All of these functions accept either only bytes or only string objects as their parameters. The result is an object of the same type, if a path or file name is returned. There is a *preference* for text, it's true. The opening paragraph includes this: Applications are encouraged to represent file names as (Unicode) character strings. That is immediately followed by more specific advice that says when to use bytes: Unfortunately, some file names may not be representable as strings on Unix, so applications that need to support arbitrary file names on Unix should use bytes objects to represent path names. Vice versa, using bytes objects cannot represent all file names on Windows (in the standard mbcs encoding), hence Windows applications should use string objects to access all files. (That needs IMO a correction, because as already explored in this thread, it's not Unix or Windows that makes the distinction there. It's the specific *filesystem type* which records either bytes or text, and that is true no matter what operating system happens to be reading the filesystem.) > Ultimately we have a fundamental limitation with trying to abstract out > the format of filenames in the API, and we need a back door to allow us > to define what encoding to use for filenames (and be able to detect that > it doesn't work for a given file, and change it on the fly to try > again), or we need an alternate API that lets us pass raw bytes as file > names and the program needs to know how to handle the raw filename for > that particular file system. Yes, I agree that there is an unresolved problem to explicitly declare the encoding for filesystem paths on ext4 and other filesystems where byte strings are used for filesystem paths. -- \ ?Give a man a fish, and you'll feed him for a day; give him a | `\ religion, and he'll starve to death while praying for a fish.? | _o__) ?Anonymous | Ben Finney From brgrt2 at gmail.com Fri Jun 8 01:20:55 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Fri, 8 Jun 2018 01:20:55 -0400 Subject: Problem finding my folder via terminal In-Reply-To: <20180608000411.GA62848@cskk.homeip.net> References: <20180608000411.GA62848@cskk.homeip.net> Message-ID: Hi Cameron, Before I reply to the meat of your email, I guess we'd better clear up your initial issues. You write: "Replies inline below, which is the style we prefer on this list. (And to reply, please reply to the specific message, not your original post. This will let you pick up that branch of the conversation directly and not confuse your readers.)" 1. I don't know what you mean by "inline," though I do notice all the single and double carets at the left margin. I don't understand the underlying rationale for the different patterns. And how do I create them, manually? 2. I also don't understand your instruction that I reply to the specific message and not to my original post. I did not reply to my own post but to Steven's comments. And then I brought up my main issue, which had remained unaddressed by his email. Thanks, Tamara On Thu, Jun 7, 2018 at 10:27 PM Cameron Simpson wrote: > > Hi, > > Replies inline below, which is the style we prefer on this list. (And to reply, > please reply to the specific message, not your original post. This will let you > pick up that branch of the conversation directly and not confuse your readers.) > > On 07Jun2018 08:39, T Berger wrote: > >On Wednesday, June 6, 2018 at 12:19:35 PM UTC-4, T Berger wrote: > >> I?m learning Python on my own and have been stuck for two days trying to get modules I created into site-packages. As a trial step, we were asked to change directly into the folder containing our modules. I typed ?cd mymodules? per instructions, but got this error message: ?-bash: cd: mymodules: No such file or directory.? I saved mymodules to my documents. What is going wrong here? > >> > >> When I tried to create a distribution file, I typed ?192:~ TamaraB$ mymodules$ python3 setup.py sdist.? I got this error message: ?-bash: mymodules$: command not found.? What should I do? > [...snip...] > > ?We'll need some more information about the computer you are using: what OS > > are you using (Mac, Linux, Windows, something else), what shell are you > > using, perhaps a file listing of your home directory. ? > > > >I?m using Terminal in Mac Sierra (10.12.6). > > Cool. > > >?(I'm not sure what the 192 part means. Does that increase each time you type a command?) ? > > > >I'm new to Terminal, but that 192 looked weird to me too. It doesn?t increase, just stays at 192. There is also a thin gray left bracket in front of the ?192? which didn?t copy into my email. Is there some way to restore the default prompt in Terminal (and what is the default prompt)? > > On a Mac, it tends to be like this: "{hostname}:~ {username}$ " where > {hostname} is your Mac's name and {username} is your login name; that is called > the "shell prompt", and "the shell" is the command line interpreter running the > commands you type. On a Mac, this is usually bash, a UNIX Bourne shell. > > There is a secondary prompt like this "> ". That indicates that you're typing a > compond command, or at least that the shell believes you're typing a compond > command, which is just a command which extends to more than one line. The > common way to confuse the shell about this is to forget to close a quote - the > shell expects that string to continue until it sees a closing quote. > > You can leave the secondary prompt by typing Control-C (often denoted "^C"). > That will cancel the incomplete command and get you back to a clean empty > primary prompt. > > Note that if you start some interactive command, such as the interactive Python > interpreter, you will then be dealing with _its_ prompts until you leave that > command. > > >Back to my problem. Your email helped me get into the mymodules folder, but I?m still stuck at the next step of the exercise, which is to get the module I created into site-packages. mymodules contains three files: the module we created, a setup file (setup.py), and a readme file. The line of text we were instructed to type into our terminal was: ?python3 setup.py sdist.? In response, I got this error message: ?/Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such file or directory?. > > > >Why is this not working for me? > > I would expect that your shell is not actually in the "mymodules" directory > when you typed "python3 setup.py sdist". Usually your shell prompt includes the > current working directory (the "~" in my example above, which is your home > directory), which is a useful contextual clue. > > You can also find out your current working directory by running the "pwd" > command (the "print working directory" command). > > The "ls" (list) command without arguments will list what is in the current > directory, so you can now check (a) whether you're where you thought you were, > and (b) what is in the current directory (in case it doesn't contain what you > expected). > > The "ls -la" command will provide a longer and more detailed listing too. > > Let us know what you find out. > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list From brgrt2 at gmail.com Fri Jun 8 01:52:12 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Fri, 8 Jun 2018 01:52:12 -0400 Subject: Problem finding my folder via terminal In-Reply-To: <20180608000411.GA62848@cskk.homeip.net> References: <20180608000411.GA62848@cskk.homeip.net> Message-ID: Hi Cameron, I'm replying via email because the Post Reply button is missing from the forum website. In answer to your comments, I am in the correct folder. But the "ls" command did not return any files. Did I enter the command incorrectly? Or are the files not recognized? Here is what I typed into terminal: "Last login: Fri Jun 8 01:40:07 on ttys001 192:~ TamaraB$ cd Desktop/mymodules 192:mymodules TamaraB$ pwd /Users/TamaraB/Desktop/mymodules 192:mymodules TamaraB$ ls mymodules 192:mymodules TamaraB$" Thanks, Tamara On Thu, Jun 7, 2018 at 10:27 PM Cameron Simpson wrote: > > Hi, > > Replies inline below, which is the style we prefer on this list. (And to reply, > please reply to the specific message, not your original post. This will let you > pick up that branch of the conversation directly and not confuse your readers.) > > On 07Jun2018 08:39, T Berger wrote: > >On Wednesday, June 6, 2018 at 12:19:35 PM UTC-4, T Berger wrote: > >> I?m learning Python on my own and have been stuck for two days trying to get modules I created into site-packages. As a trial step, we were asked to change directly into the folder containing our modules. I typed ?cd mymodules? per instructions, but got this error message: ?-bash: cd: mymodules: No such file or directory.? I saved mymodules to my documents. What is going wrong here? > >> > >> When I tried to create a distribution file, I typed ?192:~ TamaraB$ mymodules$ python3 setup.py sdist.? I got this error message: ?-bash: mymodules$: command not found.? What should I do? > [...snip...] > > ?We'll need some more information about the computer you are using: what OS > > are you using (Mac, Linux, Windows, something else), what shell are you > > using, perhaps a file listing of your home directory. ? > > > >I?m using Terminal in Mac Sierra (10.12.6). > > Cool. > > >?(I'm not sure what the 192 part means. Does that increase each time you type a command?) ? > > > >I'm new to Terminal, but that 192 looked weird to me too. It doesn?t increase, just stays at 192. There is also a thin gray left bracket in front of the ?192? which didn?t copy into my email. Is there some way to restore the default prompt in Terminal (and what is the default prompt)? > > On a Mac, it tends to be like this: "{hostname}:~ {username}$ " where > {hostname} is your Mac's name and {username} is your login name; that is called > the "shell prompt", and "the shell" is the command line interpreter running the > commands you type. On a Mac, this is usually bash, a UNIX Bourne shell. > > There is a secondary prompt like this "> ". That indicates that you're typing a > compond command, or at least that the shell believes you're typing a compond > command, which is just a command which extends to more than one line. The > common way to confuse the shell about this is to forget to close a quote - the > shell expects that string to continue until it sees a closing quote. > > You can leave the secondary prompt by typing Control-C (often denoted "^C"). > That will cancel the incomplete command and get you back to a clean empty > primary prompt. > > Note that if you start some interactive command, such as the interactive Python > interpreter, you will then be dealing with _its_ prompts until you leave that > command. > > >Back to my problem. Your email helped me get into the mymodules folder, but I?m still stuck at the next step of the exercise, which is to get the module I created into site-packages. mymodules contains three files: the module we created, a setup file (setup.py), and a readme file. The line of text we were instructed to type into our terminal was: ?python3 setup.py sdist.? In response, I got this error message: ?/Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such file or directory?. > > > >Why is this not working for me? > > I would expect that your shell is not actually in the "mymodules" directory > when you typed "python3 setup.py sdist". Usually your shell prompt includes the > current working directory (the "~" in my example above, which is your home > directory), which is a useful contextual clue. > > You can also find out your current working directory by running the "pwd" > command (the "print working directory" command). > > The "ls" (list) command without arguments will list what is in the current > directory, so you can now check (a) whether you're where you thought you were, > and (b) what is in the current directory (in case it doesn't contain what you > expected). > > The "ls -la" command will provide a longer and more detailed listing too. > > Let us know what you find out. > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list From greg.ewing at canterbury.ac.nz Fri Jun 8 02:05:28 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 08 Jun 2018 18:05:28 +1200 Subject: Python web server weirdness SOLVED In-Reply-To: References: Message-ID: Steven D'Aprano wrote: > Never mind -- it turned out I had an "index.html" file in the directory > which had been wget'ed from LiveJournal. That's okay, then. The other possibility was that your computer had been recruited into an evil botnet set up by LiveJournal to create backup servers for their site... -- Greg From greg.ewing at canterbury.ac.nz Fri Jun 8 02:23:44 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 08 Jun 2018 18:23:44 +1200 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: Michael Lamparski wrote: > In any case, it's verifiably not true for CPython. Yes, CPython uses a particularly good PRNG. You may not be as lucky using libraries that come with other languages. A great many PRNG algorithms have been proposed, and a good proportion of them produce 32-bit ints as their basic output. Of course, this isn't necessarily a problem, since you can always stick two of them together if you need more bits. But for the majority of purposes, 32 bits is probably all you need anyway. -- Greg From mauro.amico at gmail.com Fri Jun 8 02:25:56 2018 From: mauro.amico at gmail.com (Mauro Amico) Date: Fri, 8 Jun 2018 08:25:56 +0200 Subject: [ZODB] Django-hotsauce/ZODB 5.4.0/PyPy nightly sprint!! In-Reply-To: References: Message-ID: seems to me really similar to https://github.com/zopefoundation/ZEO/pull/96 try to upgrade to ZEO 5.1.2 mauro. Il Ven 8 Giu 2018, 03:29 Etienne Robillard ha scritto: > Yo people I'm doing a nightly hacking sprint for django-hotsauce on pypy > and got some cool bugs I would like to share: > > Traceback (most recent call last): > File "/usr/local/bin/schevo", line 11, in > load_entry_point('libschevo', 'console_scripts', 'schevo')() > File "/home/erob/src/libschevo/lib/schevo/script/command.py", line > 32, in __call__ > return self.main(arg0, args) > File "/home/erob/src/libschevo/lib/schevo/script/command.py", line > 74, in main > return command()(*args) > File "/home/erob/src/libschevo/lib/schevo/script/command.py", line > 32, in __call__ > return self.main(arg0, args) > File "/home/erob/src/libschevo/lib/schevo/script/command.py", line > 74, in main > return command()(*args) > File "/home/erob/src/libschevo/lib/schevo/script/command.py", line > 32, in __call__ > return self.main(arg0, args) > File "/home/erob/src/libschevo/lib/schevo/script/db_evolve.py", line > 86, in main > db = schevo.database.open(url) > File "/home/erob/src/libschevo/lib/schevo/database.py", line 371, in > open > db = Database(backend) > File "/home/erob/src/libschevo/lib/schevo/database2.py", line 95, in > __init__ > self._update_extent_maps_by_name() > File "/home/erob/src/libschevo/lib/schevo/database2.py", line 1633, > in _update_extent_maps_by_name > for extent in self._extent_maps_by_id.itervalues(): > File "/usr/local/lib/python2.7/dist-packages/ZODB/Connection.py", > line 791, in setstate > p, serial = self._storage.load(oid) > File "/usr/local/lib/python2.7/dist-packages/ZODB/mvccadapter.py", > line 143, in load > r = self._storage.loadBefore(oid, self._start) > File "/home/erob/work/ZEO-5.1.0/src/ZEO/ClientStorage.py", line 520, > in loadBefore > return self._server.load_before(oid, tid) > File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", line 783, > in load_before > return self.__call(self.client.load_before_threadsafe, oid, tid) > File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", line 748, > in call > return self.wait_for_result(result, self.timeout) > File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", line 756, > in wait_for_result > return future.result(timeout) > File > "/usr/local/lib/python2.7/dist-packages/futures-3.0.5-py2.7.egg/concurrent/futures/_base.py", > > line 405, in result > return self.__get_result() > File > "/usr/local/lib/python2.7/dist-packages/futures-3.0.5-py2.7.egg/concurrent/futures/_base.py", > > line 357, in __get_result > raise type(self._exception), self._exception, self._traceback > ZEO.Exceptions.ClientDisconnected: connection lost > erob at marina:/home/www/isotopesoftware.ca/trunk$ > > > Not sure about this first one! :) > > The command I'm trying to run is: > > % schevo db evolve --app blogengine2 zodb://127.0.0.1:4545 31 > > The ZODB 5.4.0 server then produce the following traceback: > > 2018-06-07T21:14:55 INFO ZEO.asyncio.base Connected server protocol > ------ > 2018-06-07T21:14:55 INFO ZEO.asyncio.server received handshake 'Z5' > ------ > 2018-06-07T21:14:55 ERROR ZEO.asyncio.marshal can't decode message: > '((ccopy_reg\n_reconstructor\n(czodbpickle\nbinary\nc__b...' > ------ > 2018-06-07T21:14:55 ERROR ZEO.asyncio.server Can't deserialize message > Traceback (most recent call last): > File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/server.py", line 89, > in message_received > message_id, async, name, args = self.decode(message) > File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/marshal.py", line > 114, in pickle_server_decode > return unpickler.load() # msgid, flags, name, args > File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/marshal.py", line > 164, in server_find_global > raise ImportError("import error %s: %s" % (module, msg)) > ImportError: import error copy_reg: > ------ > 2018-06-07T21:14:55 ERROR ZEO.asyncio.base data_received 4 0 True > Traceback (most recent call last): > File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/base.py", line 128, > in data_received > self.message_received(collected) > File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/server.py", line 94, > in message_received > if message_id == -1: > UnboundLocalError: local variable 'message_id' referenced before assignment > ------ > 2018-06-07T21:14:55 INFO ZEO.StorageServer (127.0.0.1:4545) disconnected > ------ > 2018-06-07T21:14:55 INFO ZEO.asyncio.base Connected server protocol > ------ > 2018-06-07T21:14:55 INFO ZEO.asyncio.server received handshake 'Z5' > ------ > 2018-06-07T21:14:55 INFO ZEO.StorageServer (127.0.0.1:4545) disconnected > > Please hit me up if you know how to fix theses errors! :) > > I'm using PyPy 5.9 and 5.10 for dev and Python 2.7.13 for production > with Cython bindings! > > > Cheers, > > Etienne > > > > -- > You received this message because you are subscribed to the Google Groups > "zodb" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to zodb+unsubscribe at googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > From tjreedy at udel.edu Fri Jun 8 02:28:13 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 8 Jun 2018 02:28:13 -0400 Subject: Valid encodings for a Python source file In-Reply-To: References: Message-ID: On 6/7/2018 4:40 PM, Daniel Glus wrote: > I'm trying to figure out the entire list of possible encodings for a Python > source file - that is, encodings that can go in a PEP 263 > encoding specification, like # > -*- encoding: foo -*-. For new code for python 3, don't use an encoding cookie. Use an editor that can save in utf-8 and tell it to do so if it does not do so by default. -- Terry Jan Reedy From tjol at tjol.eu Fri Jun 8 02:34:33 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 8 Jun 2018 08:34:33 +0200 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <87muw7y7c1.fsf@elektro.pacujo.net> Message-ID: <9e5bd558-9889-936a-20a6-c49493471200@tjol.eu> On 07/06/18 22:36, Peter Pearson wrote: > X-Copyright: (C) Copyright 2018 Stefan Ram. All rights reserved. Distribution through any means > other than regular usenet channels is forbidden. It is forbidden to publish this article in the > Web, to change URIs of this article into links, and to transfer the body without this > notice, but quotations of parts in other Usenet posts are allowed. As discussed previously [1], this arguably means that it's best if you don't even quote his messages if your posts are mirrored on the mailing list (as most people's are). [1]. https://mail.python.org/pipermail/python-list/2017-November/728635.html From steve+comp.lang.python at pearwood.info Fri Jun 8 02:38:51 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 8 Jun 2018 06:38:51 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> Message-ID: On Thu, 07 Jun 2018 22:56:49 -0400, Richard Damon wrote: > or we need an alternate API that lets us pass raw bytes as file names Guido's Time Machine strikes again. All the path related functions, include open(), take arguments as either bytes or strings. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From antoon.pardon at vub.be Fri Jun 8 03:19:23 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 8 Jun 2018 09:19:23 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: <85r2ligee7.fsf@benfinney.id.au> References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <85r2ligee7.fsf@benfinney.id.au> Message-ID: On 08-06-18 05:12, Ben Finney wrote: > That is immediately followed by more specific advice that says when to > use bytes: > > Unfortunately, some file names may not be representable as strings > on Unix, so applications that need to support arbitrary file names > on Unix should use bytes objects to represent path names. Vice > versa, using bytes objects cannot represent all file names on > Windows (in the standard mbcs encoding), hence Windows applications > should use string objects to access all files. > > (That needs IMO a correction, because as already explored in this > thread, it's not Unix or Windows that makes the distinction there. It's > the specific *filesystem type* which records either bytes or text, and > that is true no matter what operating system happens to be reading the > filesystem.) But it is the Unix or Windows api that is used. If the unix-api wants bytes, then you don't have to care about what ends up on the file-system. Just as you don't care whether the file-system uses encryption or not to store it's data. That is all hidden in layers that are normally inaccessible to the user. Maybe some FS that is hooked up to my linux box does allow embedded NUL bytes. I won't be able to notice that because even if there are such files, they will need some remapping in order to make them accessible. To the user the actuale filenames are the remapped filenames, not what is actually on the FS. -- Antoon Pardon. From antoon.pardon at vub.be Fri Jun 8 03:27:17 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 8 Jun 2018 09:27:17 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> Message-ID: <526fe11c-d9a6-398b-8c07-a3ec60294f23@vub.be> On 08-06-18 04:19, Steven D'Aprano wrote: > On Thu, 07 Jun 2018 17:45:06 +1000, Chris Angelico wrote: > >> So... an ASCIIZ string *can* contain that character, or >> at least a representation of it. Yet it cannot contain "\0". > You keep saying that as if it made one whit of difference to what > os.path.exists should do. I completely agree that ASCIIZ strings cannot > contain NUL bytes. What does that have to do with os.path.exists()? > > NTFS file systems use UTF-16 encoded strings. For typical mostly-ASCII > pathnames, the bytes on disk are *full* of NUL bytes. This is irrelevant. If you are on a linux box, you will still need to pass an ASCIIZ string to the OS and won't be able to pass an embedded NUL byte as part of a file name. What is on the disk and what kind of remapping the OS performs to get at the actual data, is something that happens in layer the user is mostly not aware off. From marko at pacujo.net Fri Jun 8 03:45:32 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 08 Jun 2018 10:45:32 +0300 Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <526fe11c-d9a6-398b-8c07-a3ec60294f23@vub.be> Message-ID: <874lid4t7n.fsf@elektro.pacujo.net> Antoon Pardon : > On 08-06-18 04:19, Steven D'Aprano wrote: >> On Thu, 07 Jun 2018 17:45:06 +1000, Chris Angelico wrote: >> >>> So... an ASCIIZ string *can* contain that character, or >>> at least a representation of it. Yet it cannot contain "\0". >> [...] >> NTFS file systems use UTF-16 encoded strings. For typical mostly-ASCII >> pathnames, the bytes on disk are *full* of NUL bytes. > > This is irrelevant. As for what is relevant for the original question is that the ValueError exception is a practical trap that I have fallen into, and, as I demonstrated yesterday, the http.server module has fallen into (through os.path.isdir()). In fact, I couldn't spot a single instance of os.path.exists() in the Python standard library that would guard against a ValueError (to be sure, in almost all of the cases you could argue it would be redundant). Whatever your philosophical tastes, this unexpected feature of os.path.exists() (& co) leads to unexpected application behavior IRL, and, in the GhostBusters sense, that is bad. Marko From email at paulstgeorge.com Fri Jun 8 04:00:31 2018 From: email at paulstgeorge.com (Paul St George) Date: Fri, 8 Jun 2018 10:00:31 +0200 Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: References: Message-ID: <64899b39-ef16-0c74-7a1b-30f49b470c3f@paulstgeorge.com> Excellent. Now I know what to do in this instance and I understand the principle. I hesitantly tried this: ??? screen = pygame.display.set_mode((720,480), pygame.FULLSCREEN | pygame.DOUBLEBUF) Hesitantly because I expected the *bitwise or operator* (|) to work like a toggle, so FULLSCREEN or DOUBLEBUF. No errors were reported, but how would I check that DOUBLEBUF had been set? Is there a general rule, such as replace 'set_something' with 'get_something'? Paul St George On 07/06/2018 19:56, Chris Angelico wrote: > On Fri, Jun 8, 2018 at 3:12 AM, Paul St George wrote: >> This is both a narrow question about some code and a more general question >> about syntax in Python >> >> Using the Pygame modules, I want to set both FULLSCREEN and DOUBLEBUF >> >> I can use >> screen = >> pygame.display.set_mode((screen_width,screen_height),pygame.FULLSCREEN) >> to set a FULLSCREEN display >> >> Or, I can use >> screen = >> pygame.display.set_mode((screen_width,screen_height),pygame.DOUBLEBUF) >> to set DOUBLEBUF >> >> But how do I set both FULLSCREEN and DOUBLEBUF? >> >> And, how can I test or check that DOUBLEBUF is set? > This is definitely a pygame question. So let's grab the docos for that > set_mode function. > > https://www.pygame.org/docs/ref/display.html#pygame.display.set_mode > > You're passing two parameters in each of your examples. The first is a > tuple of (w,h) for the dimensions; the second is a constant for the > mode you want. The name of the second argument is "flags", according > to the documentation. That usually means that you can provide > multiple. The exact mechanism for combining flags is given in the last > paragraph of the docs. I'll let you take the credit for figuring out > the details yourself :) > > ChrisA > -- Paul St George http://www.paulstgeorge.com http://www.devices-of-wonder.com +44(0)7595 37 1302 From antoon.pardon at vub.be Fri Jun 8 04:11:32 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 8 Jun 2018 10:11:32 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: <874lid4t7n.fsf@elektro.pacujo.net> References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <526fe11c-d9a6-398b-8c07-a3ec60294f23@vub.be> <874lid4t7n.fsf@elektro.pacujo.net> Message-ID: <6d88f139-2370-d5de-b497-62b6f1247e30@vub.be> On 08-06-18 09:45, Marko Rauhamaa wrote: > Whatever your philosophical tastes, this unexpected feature of > os.path.exists() (& co) leads to unexpected application behavior IRL, > and, in the GhostBusters sense, that is bad. Sure, I agree that it is unexpected behaviour. But does that mean the behaviour should be fixed or that the behaviour should be better documented? Either could be an answer and in trying to find the answer I don't think the actual FS is relevant because the doesn't access the FS directly but through the OS api. -- Antoon Pardon. From tkadm30 at yandex.com Fri Jun 8 04:30:47 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Fri, 8 Jun 2018 04:30:47 -0400 Subject: [ZODB] Django-hotsauce/ZODB 5.4.0/PyPy nightly sprint!! In-Reply-To: References: Message-ID: <3dcdf6de-a3c4-ad9c-4826-656f682593b4@yandex.com> Le 2018-06-08 ? 02:25, Mauro Amico a ?crit?: > seems to me really similar to > https://github.com/zopefoundation/ZEO/pull/96 try to upgrade to ZEO 5.1.2 > > mauro. Hey man! Thanks for the heads up! Looks like I messed up again... :) That error was caused because my zodb database file was out of sync with the schema definition. peace, Etienne > > Il Ven 8 Giu 2018, 03:29 Etienne Robillard > ha scritto: > > Yo people I'm doing a nightly hacking sprint for django-hotsauce > on pypy > and got some cool bugs I would like to share: > > Traceback (most recent call last): > ?? File "/usr/local/bin/schevo", line 11, in > ???? load_entry_point('libschevo', 'console_scripts', 'schevo')() > ?? File "/home/erob/src/libschevo/lib/schevo/script/command.py", line > 32, in __call__ > ???? return self.main(arg0, args) > ?? File "/home/erob/src/libschevo/lib/schevo/script/command.py", line > 74, in main > ???? return command()(*args) > ?? File "/home/erob/src/libschevo/lib/schevo/script/command.py", line > 32, in __call__ > ???? return self.main(arg0, args) > ?? File "/home/erob/src/libschevo/lib/schevo/script/command.py", line > 74, in main > ???? return command()(*args) > ?? File "/home/erob/src/libschevo/lib/schevo/script/command.py", line > 32, in __call__ > ???? return self.main(arg0, args) > ?? File "/home/erob/src/libschevo/lib/schevo/script/db_evolve.py", > line > 86, in main > ???? db = schevo.database.open(url) > ?? File "/home/erob/src/libschevo/lib/schevo/database.py", line > 371, in open > ???? db = Database(backend) > ?? File "/home/erob/src/libschevo/lib/schevo/database2.py", line > 95, in > __init__ > ???? self._update_extent_maps_by_name() > ?? File "/home/erob/src/libschevo/lib/schevo/database2.py", line > 1633, > in _update_extent_maps_by_name > ???? for extent in self._extent_maps_by_id.itervalues(): > ?? File "/usr/local/lib/python2.7/dist-packages/ZODB/Connection.py", > line 791, in setstate > ???? p, serial = self._storage.load(oid) > ?? File "/usr/local/lib/python2.7/dist-packages/ZODB/mvccadapter.py", > line 143, in load > ???? r = self._storage.loadBefore(oid, self._start) > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/ClientStorage.py", line > 520, > in loadBefore > ???? return self._server.load_before(oid, tid) > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", > line 783, > in load_before > ???? return self.__call(self.client.load_before_threadsafe, oid, tid) > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", > line 748, > in call > ???? return self.wait_for_result(result, self.timeout) > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", > line 756, > in wait_for_result > ???? return future.result(timeout) > ?? File > "/usr/local/lib/python2.7/dist-packages/futures-3.0.5-py2.7.egg/concurrent/futures/_base.py", > > line 405, in result > ???? return self.__get_result() > ?? File > "/usr/local/lib/python2.7/dist-packages/futures-3.0.5-py2.7.egg/concurrent/futures/_base.py", > > line 357, in __get_result > ???? raise type(self._exception), self._exception, self._traceback > ZEO.Exceptions.ClientDisconnected: connection lost > erob at marina:/home/www/isotopesoftware.ca/trunk$ > > > > Not sure about this first one! :) > > The command I'm trying to run is: > > % schevo db evolve --app blogengine2 zodb://127.0.0.1:4545 > 31 > > The ZODB 5.4.0 server then produce the following traceback: > > 2018-06-07T21:14:55 INFO ZEO.asyncio.base Connected server protocol > ------ > 2018-06-07T21:14:55 INFO ZEO.asyncio.server received handshake 'Z5' > ------ > 2018-06-07T21:14:55 ERROR ZEO.asyncio.marshal can't decode message: > '((ccopy_reg\n_reconstructor\n(czodbpickle\nbinary\nc__b...' > ------ > 2018-06-07T21:14:55 ERROR ZEO.asyncio.server Can't deserialize message > Traceback (most recent call last): > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/server.py", > line 89, > in message_received > ???? message_id, async, name, args = self.decode(message) > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/marshal.py", line > 114, in pickle_server_decode > ???? return unpickler.load() # msgid, flags, name, args > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/marshal.py", line > 164, in server_find_global > ???? raise ImportError("import error %s: %s" % (module, msg)) > ImportError: import error copy_reg: > ------ > 2018-06-07T21:14:55 ERROR ZEO.asyncio.base data_received 4 0 True > Traceback (most recent call last): > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/base.py", line > 128, > in data_received > ???? self.message_received(collected) > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/server.py", > line 94, > in message_received > ???? if message_id == -1: > UnboundLocalError: local variable 'message_id' referenced before > assignment > ------ > 2018-06-07T21:14:55 INFO ZEO.StorageServer (127.0.0.1:4545 > ) disconnected > ------ > 2018-06-07T21:14:55 INFO ZEO.asyncio.base Connected server protocol > ------ > 2018-06-07T21:14:55 INFO ZEO.asyncio.server received handshake 'Z5' > ------ > 2018-06-07T21:14:55 INFO ZEO.StorageServer (127.0.0.1:4545 > ) disconnected > > Please hit me up if you know how to fix theses errors! :) > > I'm using PyPy 5.9 and 5.10 for dev and Python 2.7.13 for production > with Cython bindings! > > > Cheers, > > Etienne > > > > -- > You received this message because you are subscribed to the Google > Groups "zodb" group. > To unsubscribe from this group and stop receiving emails from it, > send an email to zodb+unsubscribe at googlegroups.com > . > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google > Groups "zodb" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to zodb+unsubscribe at googlegroups.com > . > For more options, visit https://groups.google.com/d/optout. -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From tkadm30 at yandex.com Fri Jun 8 04:30:58 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Fri, 8 Jun 2018 04:30:58 -0400 Subject: [ZODB] Django-hotsauce/ZODB 5.4.0/PyPy nightly sprint!! In-Reply-To: References: Message-ID: Le 2018-06-08 ? 02:25, Mauro Amico a ?crit?: > seems to me really similar to > https://github.com/zopefoundation/ZEO/pull/96 try to upgrade to ZEO 5.1.2 > > mauro. Hey man! Thanks for the heads up! Looks like I messed up again... :) That error was caused because my zodb database file was out of sync with the schema definition. peace, Etienne > > Il Ven 8 Giu 2018, 03:29 Etienne Robillard > ha scritto: > > Yo people I'm doing a nightly hacking sprint for django-hotsauce > on pypy > and got some cool bugs I would like to share: > > Traceback (most recent call last): > ?? File "/usr/local/bin/schevo", line 11, in > ???? load_entry_point('libschevo', 'console_scripts', 'schevo')() > ?? File "/home/erob/src/libschevo/lib/schevo/script/command.py", line > 32, in __call__ > ???? return self.main(arg0, args) > ?? File "/home/erob/src/libschevo/lib/schevo/script/command.py", line > 74, in main > ???? return command()(*args) > ?? File "/home/erob/src/libschevo/lib/schevo/script/command.py", line > 32, in __call__ > ???? return self.main(arg0, args) > ?? File "/home/erob/src/libschevo/lib/schevo/script/command.py", line > 74, in main > ???? return command()(*args) > ?? File "/home/erob/src/libschevo/lib/schevo/script/command.py", line > 32, in __call__ > ???? return self.main(arg0, args) > ?? File "/home/erob/src/libschevo/lib/schevo/script/db_evolve.py", > line > 86, in main > ???? db = schevo.database.open(url) > ?? File "/home/erob/src/libschevo/lib/schevo/database.py", line > 371, in open > ???? db = Database(backend) > ?? File "/home/erob/src/libschevo/lib/schevo/database2.py", line > 95, in > __init__ > ???? self._update_extent_maps_by_name() > ?? File "/home/erob/src/libschevo/lib/schevo/database2.py", line > 1633, > in _update_extent_maps_by_name > ???? for extent in self._extent_maps_by_id.itervalues(): > ?? File "/usr/local/lib/python2.7/dist-packages/ZODB/Connection.py", > line 791, in setstate > ???? p, serial = self._storage.load(oid) > ?? File "/usr/local/lib/python2.7/dist-packages/ZODB/mvccadapter.py", > line 143, in load > ???? r = self._storage.loadBefore(oid, self._start) > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/ClientStorage.py", line > 520, > in loadBefore > ???? return self._server.load_before(oid, tid) > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", > line 783, > in load_before > ???? return self.__call(self.client.load_before_threadsafe, oid, tid) > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", > line 748, > in call > ???? return self.wait_for_result(result, self.timeout) > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/client.py", > line 756, > in wait_for_result > ???? return future.result(timeout) > ?? File > "/usr/local/lib/python2.7/dist-packages/futures-3.0.5-py2.7.egg/concurrent/futures/_base.py", > > line 405, in result > ???? return self.__get_result() > ?? File > "/usr/local/lib/python2.7/dist-packages/futures-3.0.5-py2.7.egg/concurrent/futures/_base.py", > > line 357, in __get_result > ???? raise type(self._exception), self._exception, self._traceback > ZEO.Exceptions.ClientDisconnected: connection lost > erob at marina:/home/www/isotopesoftware.ca/trunk$ > > > > Not sure about this first one! :) > > The command I'm trying to run is: > > % schevo db evolve --app blogengine2 zodb://127.0.0.1:4545 > 31 > > The ZODB 5.4.0 server then produce the following traceback: > > 2018-06-07T21:14:55 INFO ZEO.asyncio.base Connected server protocol > ------ > 2018-06-07T21:14:55 INFO ZEO.asyncio.server received handshake 'Z5' > ------ > 2018-06-07T21:14:55 ERROR ZEO.asyncio.marshal can't decode message: > '((ccopy_reg\n_reconstructor\n(czodbpickle\nbinary\nc__b...' > ------ > 2018-06-07T21:14:55 ERROR ZEO.asyncio.server Can't deserialize message > Traceback (most recent call last): > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/server.py", > line 89, > in message_received > ???? message_id, async, name, args = self.decode(message) > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/marshal.py", line > 114, in pickle_server_decode > ???? return unpickler.load() # msgid, flags, name, args > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/marshal.py", line > 164, in server_find_global > ???? raise ImportError("import error %s: %s" % (module, msg)) > ImportError: import error copy_reg: > ------ > 2018-06-07T21:14:55 ERROR ZEO.asyncio.base data_received 4 0 True > Traceback (most recent call last): > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/base.py", line > 128, > in data_received > ???? self.message_received(collected) > ?? File "/home/erob/work/ZEO-5.1.0/src/ZEO/asyncio/server.py", > line 94, > in message_received > ???? if message_id == -1: > UnboundLocalError: local variable 'message_id' referenced before > assignment > ------ > 2018-06-07T21:14:55 INFO ZEO.StorageServer (127.0.0.1:4545 > ) disconnected > ------ > 2018-06-07T21:14:55 INFO ZEO.asyncio.base Connected server protocol > ------ > 2018-06-07T21:14:55 INFO ZEO.asyncio.server received handshake 'Z5' > ------ > 2018-06-07T21:14:55 INFO ZEO.StorageServer (127.0.0.1:4545 > ) disconnected > > Please hit me up if you know how to fix theses errors! :) > > I'm using PyPy 5.9 and 5.10 for dev and Python 2.7.13 for production > with Cython bindings! > > > Cheers, > > Etienne > > > > -- > You received this message because you are subscribed to the Google > Groups "zodb" group. > To unsubscribe from this group and stop receiving emails from it, > send an email to zodb+unsubscribe at googlegroups.com > . > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google > Groups "zodb" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to zodb+unsubscribe at googlegroups.com > . > For more options, visit https://groups.google.com/d/optout. -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From cs at cskk.id.au Fri Jun 8 04:53:43 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 8 Jun 2018 18:53:43 +1000 Subject: Problem finding my folder via terminal In-Reply-To: References: Message-ID: <20180608085343.GA10046@cskk.homeip.net> On 08Jun2018 01:20, Tamara Berger wrote: >Before I reply to the meat of your email, I guess we'd better clear up >your initial issues. You write: > >"Replies inline below, which is the style we prefer on this list. (And to reply, >please reply to the specific message, not your original post. This will let you >pick up that branch of the conversation directly and not confuse your readers.)" > >1. I don't know what you mean by "inline," though I do notice all the >single and double carets at the left margin. I don't understand the >underlying rationale for the different patterns. And how do I create >them, manually? The inline style lets messages read like conversations, and lets you reply to the preceeding message point by point. If you look at the text above, you'll see: On 08Jun2018 01:20, Tamara Berger wrote: >Before I reply to the meat of your email, I guess we'd better clear up and so on. You (the previous message) are identified and your text indented with a leading ">" symbol. My replies come below each point in your email, unindented and with a blank line separating them out. Generally you keep just the context needed for your reply to make sense. Sometimes that involves keeping some message quote from even earlier messages, in which case _their_ intro line and text is preserved, with an extra level of ">", like this: On Thu, Jun 7, 2018 at 10:27 PM Cameron Simpson wrote: > Replies inline below, which is the style we prefer on this list. (And to > reply, > please reply to the specific message, not your original post. This will let you > pick up that branch of the conversation directly and not confuse your readers.) > > On 07Jun2018 08:39, T Berger wrote: > >... message text from you, now 2 messages back ... Most mailers will arrange this nesting automatically for you. When you hit Reply you get a new message with the previous message already quoted in the text with leading ">" markers. All you need to do is trim it to just what you need to keep for context. If you're doing this via the Post Reply button here: https://groups.google.com/forum/#!forum/comp.lang.python you'll find the previous message quoted. Instead of just putting your reply at the top, and maybe hand quoting soe line of text with cut/paste (which you seem to be doing), start scrolling down the quoted text. Just cut out anything no longer needed (but keeping the attribution. Then where you want to reply to a specifi point, insert a nice blank line and put in your reply, and leave another blank line. Then proceed down the rest of the quote deleting what isn't relevant and replying where you want to. The advantages here are (a) you can keep as much context at you like and everyone can see that context because you've left it there and (b) the reply reads like a discussion - people can see what you said right after the text to which you're responding. For a reader, that is a huge advantage. Anyway, that is the "inline" style, and a lot of techincal lists/groups use it because it keeps things very understandable, not just for the people directly involved but also for anyone else reading, who may decide to participate. >2. I also don't understand your instruction that I reply to the >specific message and not to my original post. I did not reply to my >own post but to Steven's comments. And then I brought up my main >issue, which had remained unaddressed by his email. Ah, here the fun begins. There are several forums for this list/group :-( The main two are the mailing list "python-list at pythonorg" and the newsgroup "comp.lang.python". It looks like you're using the latter, but via the Google Groups interface here (I'm guessing here from your message header lines): https://groups.google.com/forum/#!forum/comp.lang.python Posts to one side are copied to the other. The mailing list has a lot less spam (witness the many "solution manual" posts etc in the google groups forum view). Anyway, at least one gateway between the newsgroup and the list is known to mangle to In-Reply-To header on the the group->mail copy, which is what led me to think you'd replied to the wrong message. My apologies for that. Cheers, Cameron Simpson From marko at pacujo.net Fri Jun 8 05:08:10 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 08 Jun 2018 12:08:10 +0300 Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <526fe11c-d9a6-398b-8c07-a3ec60294f23@vub.be> <874lid4t7n.fsf@elektro.pacujo.net> <6d88f139-2370-d5de-b497-62b6f1247e30@vub.be> Message-ID: <87zi053ath.fsf@elektro.pacujo.net> Antoon Pardon : > On 08-06-18 09:45, Marko Rauhamaa wrote: >> Whatever your philosophical tastes, this unexpected feature of >> os.path.exists() (& co) leads to unexpected application behavior IRL, >> and, in the GhostBusters sense, that is bad. > > Sure, I agree that it is unexpected behaviour. But does that mean the > behaviour should be fixed or that the behaviour should be better > documented? I'd say it should be fixed. I would go so far as to say that os.stat() should be fixed so that "" and "\0" result in the same exception (EINVAL ~ ValueError). If the documentation option is taken, the documentation should emphasize the issue. Furthermore, the http.server module should be fixed because it is broken at the moment. Marko From cs at cskk.id.au Fri Jun 8 05:35:04 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 8 Jun 2018 19:35:04 +1000 Subject: Problem finding my folder via terminal In-Reply-To: References: Message-ID: <20180608093504.GA23926@cskk.homeip.net> On 08Jun2018 01:52, Tamara Berger wrote: >In answer to your comments, I am in the correct folder. But the "ls" >command did not return any files. Did I enter the command incorrectly? >Or are the files not recognized? Here is what I typed into terminal: > >"Last login: Fri Jun 8 01:40:07 on ttys001 >192:~ TamaraB$ cd Desktop/mymodules >192:mymodules TamaraB$ pwd >/Users/TamaraB/Desktop/mymodules >192:mymodules TamaraB$ ls >mymodules >192:mymodules TamaraB$" It looks like you have a "mymodules" folder _inside_ your "Desktop/mymodules" folder. Form the /Users/TamaraB/Desktop/mymodules folder, type these commands. ls -la ls -la mymodules (Feel free to omit any other stuff in your Desktop folder listing for privacy reasons.) Or: cd ~/Desktop/mymodules ls -laR The "R" option will create a recursive listing. Or you could just open the folder in the Finder and look around: open ~/Desktop/mymodules I'm thinking you've just made an additional "mymodules" inside your main "mymodules" by accident. Cheers, Cameron Simpson From bellcanadardp at gmail.com Fri Jun 8 06:35:12 2018 From: bellcanadardp at gmail.com (bellcanadardp at gmail.com) Date: Fri, 8 Jun 2018 03:35:12 -0700 (PDT) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <27ef2bfb-e3ed-495c-bb98-f71e502d412a@googlegroups.com> <20180520134354.GB2192@hermes.hilbert.loc> <20180522212337.cvtbh32tydvaft4r@hjp.at> Message-ID: <01e3fac3-c389-410b-8a17-3adf83876e02@googlegroups.com> On Sunday, 3 June 2018 20:11:43 UTC-4, Steven D'Aprano wrote: > On Sun, 03 Jun 2018 16:36:12 -0700, bellcanadardp wrote: > > > hello peter ...how exactly would i solve this issue .....i have a script > > that works in python 2 but not pytho3..i did 2 to 3.py ...but i still > > get the errro...character undefieed..unicode decode error cant decode > > byte 1x09 in line 7414 from cp 1252..like would you have a sraright > > solution answer??..i cant get a straight answer..it was ported from ansi > > to python...so its utf-8 as far asi can see > > You won't get a straight answer because you won't tell us *precisely* > what is happening. > > Don't retype a summary of what you think the error is. "character > undefieed" is not a thing, and there is no such thing as "byte 1x09". > > You need to COPY AND PASTE the EXACT error that you get. Not just the > last line, the error message, but the FULL TRACEBACK starting from the > line "Traceback" and going to the end. > > Until you do that, we cannot give you a straight answer. > > You also need to COPY AND PASTE the EXACT line of code that gives the > error, plus enough code so that it works. For a file read error, that > probably means code that opens the file, and then tries to read from it. > > Until you do that, we cannot give you a straight answer. > > You need to tell us what version of Python you are using, and the > operating system. > > You should read this: > > http://sscce.org/ > > Even though it is written for Java programmers, it applies to Python to. > > If you think that your file is UTF-8, why are you using CP-1252 to read > the file? > > https://en.wikipedia.org/wiki/Windows-1252 > > https://en.wikipedia.org/wiki/UTF-8 > > > > I recommend you start with reading this if you haven't already: > > https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every- > software-developer-absolutely-positively-must-know-about-unicode-and- > character-sets-no-excuses/ > > Sorry for the huge URL, try this if your mail client breaks it: > > https://tinyurl.com/h8yg9d7 > > > Until you read that, you will probably remain confused about text > encodings and Unicode and will probably not understand the straight > answer we give you. > > Also read: https://nedbatchelder.com/text/unipain.html > > > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson hello steven are you there?? i posted the full error message...plz let me know if you need from traceback if so..can you provide an email address where i can send a computer pic?? its a long error and it seems i cant post pics here...here is my email tommy.ross at thefriendsnetwork,.ca tommy From Richard at Damon-Family.org Fri Jun 8 06:35:45 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 8 Jun 2018 06:35:45 -0400 Subject: Valid encodings for a Python source file In-Reply-To: References: Message-ID: On 6/7/18 4:40 PM, Daniel Glus wrote: > I'm trying to figure out the entire list of possible encodings for a Python > source file - that is, encodings that can go in a PEP 263 > encoding specification, like # > -*- encoding: foo -*-. > > Is this list the same as the list given in the documentation for the codecs > library, under "Standard Encodings" > ? If > not, where can I find the actual list? > > (I know that list is the same as the set of unique values in CPython's > /Lib/encodings/aliases.py > , > or equivalently, the set of filenames in /Lib/encodings/ > , but again > I'm not sure.) > -Daniel Reading the proposal, I see one thing that seems worthy of a comment, the proposal specifically calls out the UTF-8 'BOM" sequence, (which the Unicode standard actually doesn't recommend using, as UTF-8 doesn't have a 'Byte Order Problem', but doesn't allow the UTF-16 (0xFF, 0xFE or 0xFE, 0xFF) or UCS-4 BOM (0x00, 0x00, 0xFE, 0xFF or 0xFF, 0xFE, 0x00, 0x00)? marks which while the formats are unlikely are very likely to have the marks, and detecting the marks are very important to detect those encoding as they are NOT 'ACSII Compatible' formats, so the rest of the header doesn't match what would be expected. -- Richard Damon From rhodri at kynesim.co.uk Fri Jun 8 06:52:36 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 8 Jun 2018 11:52:36 +0100 Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: <64899b39-ef16-0c74-7a1b-30f49b470c3f@paulstgeorge.com> References: <64899b39-ef16-0c74-7a1b-30f49b470c3f@paulstgeorge.com> Message-ID: On 08/06/18 09:00, Paul St George wrote: > Excellent. Now I know what to do in this instance and I understand the > principle. > > I hesitantly tried this: > > ??? screen = pygame.display.set_mode((720,480), pygame.FULLSCREEN | > pygame.DOUBLEBUF) > > Hesitantly because I expected the *bitwise or operator* (|) to work like > a toggle, so FULLSCREEN or DOUBLEBUF. The bitwise OR operator peforms a bitwise OR, i.e. *both* flags get set. > No errors were reported, but how would I check that DOUBLEBUF had been > set? Is there a general rule, such as replace 'set_something' with > 'get_something'? There's documentation. The link Chris gave you for pygame.display.set_mode() tells you that you get a Surface out of it. Reaching for the docs for that, this leaps out: https://www.pygame.org/docs/ref/surface.html#pygame.Surface.get_flags PS: it's generally considered polite not to top post on this mailing list. -- Rhodri James *-* Kynesim Ltd From tjol at tjol.eu Fri Jun 8 06:53:09 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 8 Jun 2018 12:53:09 +0200 Subject: Valid encodings for a Python source file In-Reply-To: References: Message-ID: <29f4664d-65f9-c972-99b2-c1d7adfbc215@tjol.eu> On 2018-06-07 22:40, Daniel Glus wrote: > I'm trying to figure out the entire list of possible encodings for a Python > source file - that is, encodings that can go in a PEP 263 > encoding specification, like # > -*- encoding: foo -*-. > > Is this list the same as the list given in the documentation for the codecs > library, under "Standard Encodings" > ? If > not, where can I find the actual list? > > (I know that list is the same as the set of unique values in CPython's > /Lib/encodings/aliases.py > , > or equivalently, the set of filenames in /Lib/encodings/ > , but again > I'm not sure.) > -Daniel It's none of these. To quote PEP 263: > Any encoding which allows processing the first two lines in the way indicated above is allowed as source code encoding, this includes ASCII compatible encodings as well as certain multi-byte encodings such as Shift_JIS. It does not include encodings which use two or more bytes for all characters like e.g. UTF-16. The reason for this is to keep the encoding detection algorithm in the tokenizer simple. All of the lists above include encodings like UTF-16 that are not sufficiently ASCII-compatible. Of course, as Terry Reedy writes, > For new code for python 3, don't use an encoding cookie. Use an editor that can save in utf-8 and tell it to do so if it does not do so by default. -- Thomas From steve+comp.lang.python at pearwood.info Fri Jun 8 07:35:09 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 8 Jun 2018 11:35:09 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <526fe11c-d9a6-398b-8c07-a3ec60294f23@vub.be> Message-ID: On Fri, 08 Jun 2018 09:27:17 +0200, Antoon Pardon wrote: > On 08-06-18 04:19, Steven D'Aprano wrote: >> On Thu, 07 Jun 2018 17:45:06 +1000, Chris Angelico wrote: >> >>> So... an ASCIIZ string *can* contain that character, or at least a >>> representation of it. Yet it cannot contain "\0". >> You keep saying that as if it made one whit of difference to what >> os.path.exists should do. I completely agree that ASCIIZ strings cannot >> contain NUL bytes. What does that have to do with os.path.exists()? >> >> NTFS file systems use UTF-16 encoded strings. For typical mostly-ASCII >> pathnames, the bytes on disk are *full* of NUL bytes. > > This is irrelevant. Of course it is irrelevant, JUST LIKE I SAID IN THE PARAGRAPH YOU DELETED: They're actually both equally implementation details and utterly irrelevant to the behaviour of os.path.exists. (referring to both the NUL bytes in UTF-16 encoded NTFS file names, and the lack of NUL bytes in common Linux file names). I think that's dirty debating tactics, a variant of "Strawman argument". I make a statement. You delete it, and respond saying the same thing I said, but making it out as if it were a devastating response to my argument. Pretty pathetic really. The existence or use of ASCIIZ strings by the Linux kernel are not the least bit relevant to the question of why, alone of a near-infinite number of possible invalid pathnames, those containing NUL are singled out for an exception when all others simply return False. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Fri Jun 8 07:36:34 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 8 Jun 2018 11:36:34 +0000 (UTC) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <27ef2bfb-e3ed-495c-bb98-f71e502d412a@googlegroups.com> <20180520134354.GB2192@hermes.hilbert.loc> <20180522212337.cvtbh32tydvaft4r@hjp.at> <01e3fac3-c389-410b-8a17-3adf83876e02@googlegroups.com> Message-ID: On Fri, 08 Jun 2018 03:35:12 -0700, bellcanadardp wrote: > hello steven are you there?? > i posted the full error message... No you didn't. I saw your post, and ignored it, because you didn't follow instructions. I told you we need to see the *full* traceback, starting from the line beginning "Traceback". You only posted the end of the traceback. I told you we needed to see the actual line of code you are trying to run. You didn't show us the line of code you are trying to run. We're not mind-readers. We can't fix code that we can't see, giving errors from a line you won't tell us, using a file we don't have. Please read this before replying: http://sscce.org/ Thank you. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Fri Jun 8 07:37:33 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 8 Jun 2018 11:37:33 +0000 (UTC) Subject: Sorting NaNs References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On Fri, 08 Jun 2018 12:23:40 +1000, Chris Angelico wrote: > On Fri, Jun 8, 2018 at 12:15 PM, Steven D'Aprano > wrote: >> If you truly were limited to 2**32 different values (we're not), then >> it would be exactly right and proper to expect a collision in 2**16 >> samples. Actually, a lot less than that: more like 78000. >> >> https://en.wikipedia.org/wiki/Birthday_problem > > 2**16 is 65536, so the figure you give is pretty close to the > rule-of-thumb estimate that the square root of your pool is where you're > likely to have collisions. D'oh! I mean, I knew that, I was just testing to see if anyone was paying attention. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From darren at pardoe.eu Fri Jun 8 07:41:36 2018 From: darren at pardoe.eu (Darren Pardoe) Date: Fri, 8 Jun 2018 04:41:36 -0700 (PDT) Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: References: <64899b39-ef16-0c74-7a1b-30f49b470c3f@paulstgeorge.com> Message-ID: On Friday, 8 June 2018 12:24:26 UTC+1, Rhodri James wrote: > On 08/06/18 09:00, Paul St George wrote: > PS: it's generally considered polite not to top post on this mailing list. > > -- > Rhodri James *-* Kynesim Ltd Rhodri, Guys, I have always top posted even though most editors start with the cursor at the bottom. Is there any foundation to this methodology as my logic suggest we top post? From rosuav at gmail.com Fri Jun 8 08:07:18 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jun 2018 22:07:18 +1000 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On Fri, Jun 8, 2018 at 9:37 PM, Steven D'Aprano wrote: > On Fri, 08 Jun 2018 12:23:40 +1000, Chris Angelico wrote: > >> On Fri, Jun 8, 2018 at 12:15 PM, Steven D'Aprano >> wrote: >>> If you truly were limited to 2**32 different values (we're not), then >>> it would be exactly right and proper to expect a collision in 2**16 >>> samples. Actually, a lot less than that: more like 78000. >>> >>> https://en.wikipedia.org/wiki/Birthday_problem >> >> 2**16 is 65536, so the figure you give is pretty close to the >> rule-of-thumb estimate that the square root of your pool is where you're >> likely to have collisions. > > D'oh! > > > I mean, I knew that, I was just testing to see if anyone was paying > attention. > Plus, you were making another very clear point: Humans are *terrible* at estimating exponentiation. Unless you've memorized specific values (2**16 and 2**32 are fairly common and familiar), it's really hard to estimate the value of x**y. Want to hazard a guess as to what 0.99**100 is? (That's the chances that a one-in-a-hundred event won't happen after a hundred opportunities.) What about 85**8? (Theoretical password entropy if you have uppercase, lowercase, digit, symbol.) What is the smallest n such that 26**n > 85**8? (That's the length of monocase password required for equivalent theoretical entropy.) Thank you for that elegant demonstration of an important fact about humans. :-) ChrisA From antoon.pardon at vub.be Fri Jun 8 08:08:07 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 8 Jun 2018 14:08:07 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <526fe11c-d9a6-398b-8c07-a3ec60294f23@vub.be> Message-ID: On 08-06-18 13:35, Steven D'Aprano wrote: > On Fri, 08 Jun 2018 09:27:17 +0200, Antoon Pardon wrote: > >> On 08-06-18 04:19, Steven D'Aprano wrote: >>> On Thu, 07 Jun 2018 17:45:06 +1000, Chris Angelico wrote: >>> >>>> So... an ASCIIZ string *can* contain that character, or at least a >>>> representation of it. Yet it cannot contain "\0". >>> You keep saying that as if it made one whit of difference to what >>> os.path.exists should do. I completely agree that ASCIIZ strings cannot >>> contain NUL bytes. What does that have to do with os.path.exists()? >>> >>> NTFS file systems use UTF-16 encoded strings. For typical mostly-ASCII >>> pathnames, the bytes on disk are *full* of NUL bytes. >> This is irrelevant. > Of course it is irrelevant, JUST LIKE I SAID IN THE PARAGRAPH YOU DELETED: > > They're actually both equally implementation details and > utterly irrelevant to the behaviour of os.path.exists. > > (referring to both the NUL bytes in UTF-16 encoded NTFS file names, and > the lack of NUL bytes in common Linux file names). > > I think that's dirty debating tactics, a variant of "Strawman argument". > I make a statement. You delete it, and respond saying the same thing I > said, but making it out as if it were a devastating response to my > argument. > > Pretty pathetic really. Get of your high horse. Sure I was too quick in my reaction, without reading your contribution through. That is regretable but it happens. But you are in no situation to cast the first stone. These things and worse have been happening to you too. > The existence or use of ASCIIZ strings by the Linux kernel are not the > least bit relevant to the question of why, alone of a near-infinite > number of possible invalid pathnames, those containing NUL are singled > out for an exception when all others simply return False. Only if you phrase the question as being about eliminating an exception. If you phrase the question as being about how invalid pathnames should be treated and may consider that they all should raise an exception then ASCIIZ is relevant as an illustration of what is in some situation an invalid pathname. -- Antoon. From ned at nedbatchelder.com Fri Jun 8 08:13:25 2018 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 8 Jun 2018 08:13:25 -0400 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: <9e5bd558-9889-936a-20a6-c49493471200@tjol.eu> References: <87muw7y7c1.fsf@elektro.pacujo.net> <9e5bd558-9889-936a-20a6-c49493471200@tjol.eu> Message-ID: On 6/8/18 2:34 AM, Thomas Jollans wrote: > On 07/06/18 22:36, Peter Pearson wrote: > >> X-Copyright: (C) Copyright 2018 Stefan Ram. All rights reserved. Distribution through any means >> other than regular usenet channels is forbidden. It is forbidden to publish this article in the >> Web, to change URIs of this article into links, and to transfer the body without this >> notice, but quotations of parts in other Usenet posts are allowed. > As discussed previously [1], this arguably means that it's best if you > don't even quote his messages if your posts are mirrored on the mailing > list (as most people's are). > > [1]. https://mail.python.org/pipermail/python-list/2017-November/728635.html The restriction is absurd, and the idea that people will obey the restriction in the headers is absurd. If Stefan posts to a newsgroup in this day and age, he knows full well that his words will end up on http servers somewhere.? He needs to get over it, or stop posting to newsgroups. --Ned. From eryksun at gmail.com Fri Jun 8 08:16:42 2018 From: eryksun at gmail.com (eryk sun) Date: Fri, 8 Jun 2018 12:16:42 +0000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> <526fe11c-d9a6-398b-8c07-a3ec60294f23@vub.be> Message-ID: On Fri, Jun 8, 2018 at 11:35 AM, Steven D'Aprano wrote: > > (referring to both the NUL bytes in UTF-16 encoded NTFS file names, and > the lack of NUL bytes in common Linux file names). NTFS filenames are stored as wchar_t strings, for which NUL is L"\x00\x00". Individual null bytes are irrelevant to this problem, unless we're using an encoding such as an ASCII superset that stores the character NUL as "\x00". From rosuav at gmail.com Fri Jun 8 08:18:19 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jun 2018 22:18:19 +1000 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <87muw7y7c1.fsf@elektro.pacujo.net> <9e5bd558-9889-936a-20a6-c49493471200@tjol.eu> Message-ID: On Fri, Jun 8, 2018 at 10:13 PM, Ned Batchelder wrote: > On 6/8/18 2:34 AM, Thomas Jollans wrote: >> >> On 07/06/18 22:36, Peter Pearson wrote: >> >>> X-Copyright: (C) Copyright 2018 Stefan Ram. All rights reserved. >>> Distribution through any means >>> other than regular usenet channels is forbidden. It is forbidden to >>> publish this article in the >>> Web, to change URIs of this article into links, and to transfer >>> the body without this >>> notice, but quotations of parts in other Usenet posts are >>> allowed. >> >> As discussed previously [1], this arguably means that it's best if you >> don't even quote his messages if your posts are mirrored on the mailing >> list (as most people's are). >> >> [1]. >> https://mail.python.org/pipermail/python-list/2017-November/728635.html > > > The restriction is absurd, and the idea that people will obey the > restriction in the headers is absurd. If Stefan posts to a newsgroup in this > day and age, he knows full well that his words will end up on http servers > somewhere. He needs to get over it, or stop posting to newsgroups. Are news servers guaranteed to carry the X-Copyright header in all transmissions? If not, the copyright notice isn't part of the message, and is most likely unenforceable. ChrisA From python at mrabarnett.plus.com Fri Jun 8 10:18:39 2018 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 8 Jun 2018 15:18:39 +0100 Subject: Problem finding my folder via terminal In-Reply-To: <20180608085343.GA10046@cskk.homeip.net> References: <20180608085343.GA10046@cskk.homeip.net> Message-ID: On 2018-06-08 09:53, Cameron Simpson wrote: [snip] > Instead of just putting your reply at the top, and maybe hand quoting soe line > of text with cut/paste (which you seem to be doing), start scrolling down the > quoted text. Just cut out anything no longer needed (but keeping the > attribution. Then where you want to reply to a specifi point, insert a nice > blank line and put in your reply, and leave another blank line. Then proceed > down the rest of the quote deleting what isn't relevant and replying where you > want to. > If you omit some of the text, for clarity it's a good idea to show that you've done so by adding a line "[snip]", "[cut]" or something similar. [snip] From brgrt2 at gmail.com Fri Jun 8 10:23:56 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Fri, 8 Jun 2018 10:23:56 -0400 Subject: Problem finding my folder via terminal In-Reply-To: <20180608093504.GA23926@cskk.homeip.net> References: <20180608093504.GA23926@cskk.homeip.net> Message-ID: Nope. No duplicate folder. On Fri, Jun 8, 2018 at 5:35 AM Cameron Simpson wrote: > > On 08Jun2018 01:52, Tamara Berger wrote: > >In answer to your comments, I am in the correct folder. But the "ls" > >command did not return any files. Did I enter the command incorrectly? > >Or are the files not recognized? Here is what I typed into terminal: > > > >"Last login: Fri Jun 8 01:40:07 on ttys001 > >192:~ TamaraB$ cd Desktop/mymodules > >192:mymodules TamaraB$ pwd > >/Users/TamaraB/Desktop/mymodules > >192:mymodules TamaraB$ ls > >mymodules > >192:mymodules TamaraB$" > > It looks like you have a "mymodules" folder _inside_ your "Desktop/mymodules" > folder. Form the /Users/TamaraB/Desktop/mymodules folder, type these commands. > > ls -la > ls -la mymodules > > (Feel free to omit any other stuff in your Desktop folder listing for privacy > reasons.) > > Or: > > cd ~/Desktop/mymodules > ls -laR > > The "R" option will create a recursive listing. Or you could just open the > folder in the Finder and look around: > > open ~/Desktop/mymodules > > I'm thinking you've just made an additional "mymodules" inside your main > "mymodules" by accident. > > Cheers, > Cameron Simpson From python at mrabarnett.plus.com Fri Jun 8 10:29:35 2018 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 8 Jun 2018 15:29:35 +0100 Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: References: <64899b39-ef16-0c74-7a1b-30f49b470c3f@paulstgeorge.com> Message-ID: On 2018-06-08 12:41, Darren Pardoe wrote: > On Friday, 8 June 2018 12:24:26 UTC+1, Rhodri James wrote: >> On 08/06/18 09:00, Paul St George wrote: >> PS: it's generally considered polite not to top post on this mailing list. >> >> -- >> Rhodri James *-* Kynesim Ltd > > Rhodri, Guys, > I have always top posted even though most editors start with the cursor at the bottom. Is there any foundation to this methodology as my logic suggest we top post? > Those who invented and first used email decades ago found that the interleaved style with trimming of unwanted text worked best in practice. Many years later, when the internet and World Wide Web gained widespread usage, people weren't told about what had been found to work best, and the email programs they used created a reply that quoted the original message and left the cursor at the top, so people just put their reply there. From gheskett at shentel.net Fri Jun 8 10:42:39 2018 From: gheskett at shentel.net (Gene Heskett) Date: Fri, 8 Jun 2018 10:42:39 -0400 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: Message-ID: <201806081042.39619.gheskett@shentel.net> On Friday 08 June 2018 08:18:19 Chris Angelico wrote: > On Fri, Jun 8, 2018 at 10:13 PM, Ned Batchelder wrote: > > On 6/8/18 2:34 AM, Thomas Jollans wrote: > >> On 07/06/18 22:36, Peter Pearson wrote: > >>> X-Copyright: (C) Copyright 2018 Stefan Ram. All rights reserved. > >>> Distribution through any means > >>> other than regular usenet channels is forbidden. It is > >>> forbidden to publish this article in the > >>> Web, to change URIs of this article into links, and to > >>> transfer the body without this > >>> notice, but quotations of parts in other Usenet posts > >>> are allowed. > >> > >> As discussed previously [1], this arguably means that it's best if > >> you don't even quote his messages if your posts are mirrored on the > >> mailing list (as most people's are). > >> > >> [1]. > >> https://mail.python.org/pipermail/python-list/2017-November/728635. > >>html > > > > The restriction is absurd, and the idea that people will obey the > > restriction in the headers is absurd. If Stefan posts to a newsgroup > > in this day and age, he knows full well that his words will end up > > on http servers somewhere. He needs to get over it, or stop posting > > to newsgroups. > > Are news servers guaranteed to carry the X-Copyright header in all > transmissions? If not, the copyright notice isn't part of the message, > and is most likely unenforceable. > > ChrisA As the courts have so found when this has come up over the last 30 years. Basically, its just some newly minted lawyer trying to earn his place at the feeding trough. It does have a tendency to scare off the copyright violators that can't afford a legal dept, pushing them under the bus. Copyrights, Patents, often interchangeable in civil court, and having been the victim (because I was the designated Chief Operator at a tv station) of a frivolous patent that attacked every broadcast facility in the US, demanding royalties in the 5 digit range per month for implementing what the FCC edict said we had to do WRT the EAS system. The courts weren't amused. I don't know as any of us ever cut those patent troll turkey's a check, but if they did, they were also awarded triple damages. I've not heard that name in the press since. Probably changed to protect the guilty. -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From brgrt2 at gmail.com Fri Jun 8 10:52:01 2018 From: brgrt2 at gmail.com (T Berger) Date: Fri, 8 Jun 2018 07:52:01 -0700 (PDT) Subject: Distribution file error Message-ID: <03ba0d79-f94d-4f24-95d7-d99be3716840@googlegroups.com> Hi, I really need help here. I?m trying to create a distribution file for my module, but got an error message. The module, including the setup and read me files, are contained within the folder ?mymodules.? I typed this command (per instructions from my workbook) from within mymodules folder: 192:~ TamaraB$ cd Desktop/mymodules/ 192:mymodules TamaraB$ python3 setup.py sdist /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such file or directory. Why is this not working? (I?m working in the OS Sierra terminal.) From ftg at lutix.org Fri Jun 8 11:45:09 2018 From: ftg at lutix.org (ftg at lutix.org) Date: Fri, 08 Jun 2018 15:45:09 +0000 Subject: Project tree and import module Message-ID: <3f36be78299f126a70dca3d111a74298@webmail.lutix.org> Hello, here is my project hierarchy: myproject | |- django-project-name | |- django-project-name | | |-urls.py | | |-views.py | |- manage.py |- my-package Is my projet tree correct? Shouldn't I put my-package into my django-project-name folder? Because I am facing some questionning about how to reach my-package from views.py and in the current situation, I have to insert a sys.path.append line (with full path) in my views.py file, and I don't find this very elegant. What if my package is really in another folder location? Should I need to use the sys.path.append function anyway? Thanks From rhodri at kynesim.co.uk Fri Jun 8 12:09:51 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 8 Jun 2018 17:09:51 +0100 Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: References: <64899b39-ef16-0c74-7a1b-30f49b470c3f@paulstgeorge.com> Message-ID: <1b566872-c475-775c-0370-40082bb33b41@kynesim.co.uk> On 08/06/18 12:41, Darren Pardoe wrote: > On Friday, 8 June 2018 12:24:26 UTC+1, Rhodri James wrote: >> On 08/06/18 09:00, Paul St George wrote: >> PS: it's generally considered polite not to top post on this mailing list. >> >> -- >> Rhodri James *-* Kynesim Ltd > > Rhodri, Guys, > I have always top posted even though most editors start with the cursor at the bottom. Is there any foundation to this methodology as my logic suggest we top post? > Others have given you the history, but I think this sums up the practicality nicely: A: Because it reverses the order of the conversation Q: Why is top posting unhelpful? -- Rhodri James *-* Kynesim Ltd From adam.preble at gmail.com Fri Jun 8 13:04:59 2018 From: adam.preble at gmail.com (adam.preble at gmail.com) Date: Fri, 8 Jun 2018 10:04:59 -0700 (PDT) Subject: Distributing a Python module as .rpm and .deb packages across major distributions Message-ID: <2347a88b-d676-4a8e-8495-b77c4cfe0561@googlegroups.com> I have a situation where internally I need to distribute some Python code using Linux packages rather than simply relying on wheel files. This seems to be a solved problem because a lot of Python modules clearly get distributed as .rpm and .deb. It's not completely unreasonable because soon I will have some other modules that are depending on binary applications that are also coming in from packages, and having the system package manage resolve and install all this is convenient. I'm not really in a political position to change that policy, for what it's worth. I'm still stuck in Python 2.7 here for at least a few more months. Also, it probably helps to know this is a pure Python module that doesn't have to compile any native code. Creating a package itself isn't a problem. In my case, I bandied with the bdist_rpm rule in setup.py, and used stdeb to add a bdist_deb rule. I get rpm and deb files from these, but they seem to be plagued with a problem of making assumptions about paths based on my build environment. I'm building on an Ubuntu rig where Python modules are installed into dist-packages. The rpm package will try to install my module into dist-packages instead of site-packages on a Red Hat rig. I haven't yet tried the Debian package on different rigs, but the stdeb documentation did call out that this likely won't work. I'm wondering first if many of the modules we see in packages right now are actually literally being built using Jenkins or some other CD tool on every major OS distribution. If that's the case then at least I know and I can try to do that. I was surprised that I couldn't easily provide some additional flags. I believe I can specify a setup.cfg that can override the module installation path, and I think I can do a little shell script to just rotate different setup.cfg files through, but I can't help but wonder if I'm even on the right path. From marko at pacujo.net Fri Jun 8 13:34:44 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 08 Jun 2018 20:34:44 +0300 Subject: Stefan's headers [was:Names and identifiers] References: <201806081042.39619.gheskett@shentel.net> Message-ID: <87sh5x2nd7.fsf@elektro.pacujo.net> Gene Heskett : > On Friday 08 June 2018 08:18:19 Chris Angelico wrote: >> Are news servers guaranteed to carry the X-Copyright header in all >> transmissions? If not, the copyright notice isn't part of the message, >> and is most likely unenforceable. > > As the courts have so found when this has come up over the last 30 years. > Basically, its just some newly minted lawyer trying to earn his place at > the feeding trough. Copyrights exist whether they are declared or not. If I publish a poem or, say, a Python application on Usenet, you will need my permission to distribute it. Of course, its dissemination via Usenet and remailers is ultimately *me* distributing my work. In one Usenet discussion I published my translation of a Finnish Christmas carol. The author of the original lyrics had died more than 70 years before so that was ok. However, the melody was still under copyright so I didn't have a right to *explain* in any direct manner how the melody went. Luckily, someone had posted the song on Youtube so I could provide a link (although even that could be considered criminal in some jurisdictions). Marko PS IMO copyright laws should be abolished altogether. At the very least one should pay for copyright protection. One ?1 for the first year, ?2 for the second, ?4 for the third and so on exponentially. From pkpearson at nowhere.invalid Fri Jun 8 13:45:58 2018 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 8 Jun 2018 17:45:58 GMT Subject: Sorting NaNs References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On Fri, 8 Jun 2018 02:15:02 +0000 (UTC), Steven D'Aprano wrote: > On Thu, 07 Jun 2018 20:43:10 +0000, Peter Pearson wrote: [snip] >> >> But gosh, if there are only 2**32 different "random" floats, then you'd >> have about a 50% chance of finding a collision among any set of 2**16 >> samples. Is that really tolerable? > > Why wouldn't it be? It would be shocking if a sufficiently large sequence > of numbers contained no collisions at all: that would imply the values > were very much NON random. [snip] > . . . I understand that Python's Mersenne Twister implementation > is based on 64-bit ints. OK, I'll relax, particularly since Michael Lamparski's experiment strongly indicates that random floats are drawn from a population much larger than 2**16. You're completely correct, of course, in noting that an absence of collisions would condemn the random-number generator just as badly as an excess. What bothered me was my feeling that a "reasonable observer" would expect the random-float population to be much larger than 2**32, and the probably-collision-free sample size to be accordingly much larger than 2**16, which is, after all, small enough to appear in many applications. Exactly what the "reasonable observer" would expect that population to be, I don't know. To a mathematician, there's zero chance of collision in any finite sample of real numbers, or even just rational numbers; but I don't think anybody would expect that from a computer. When I picture the diligent software engineer asking himself, "Wait, how large can I make this sample before I'll start seeing collisions," I imagine his first guess is going to be the size of a float's mantissa. What applications would have to worry about colliding floats? I don't know. I'm coming from cryptology, where worrying about such things becomes a reflex. -- To email me, substitute nowhere->runbox, invalid->com. From tjol at tjol.eu Fri Jun 8 13:49:17 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 8 Jun 2018 19:49:17 +0200 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <87muw7y7c1.fsf@elektro.pacujo.net> <9e5bd558-9889-936a-20a6-c49493471200@tjol.eu> Message-ID: <57c86b1a-205b-dc89-ae85-0e37423e92da@tjol.eu> On 08/06/18 14:13, Ned Batchelder wrote: > On 6/8/18 2:34 AM, Thomas Jollans wrote: >> On 07/06/18 22:36, Peter Pearson wrote: >> >>> X-Copyright: (C) Copyright 2018 Stefan Ram. All rights reserved. >>> Distribution through any means >>> ?? other than regular usenet channels is forbidden. It is forbidden >>> to publish this article in the >>> ?? Web, to change URIs of this article into links,??????? and to >>> transfer the body without this >>> ?? notice, but quotations??????? of parts in other Usenet posts are >>> allowed. >> As discussed previously [1], this arguably means that it's best if you >> don't even quote his messages if your posts are mirrored on the mailing >> list (as most people's are). >> >> [1]. >> https://mail.python.org/pipermail/python-list/2017-November/728635.html > > The restriction is absurd, and the idea that people will obey the > restriction in the headers is absurd. If Stefan posts to a newsgroup in > this day and age, he knows full well that his words will end up on http > servers somewhere.? He needs to get over it, or stop posting to newsgroups. > > --Ned. Quite right. Of course it's probably unenforceable, but that's not really the point. I have nothing against Stefan. In fact, back when I could (illegally) see his posts, I quite enjoyed them. However, if he writes in a public forum like this, he should accept that he's writing in a public forum. As long as he doesn't, it's only right that he should be banned (from the list) and ignored (by the few remaining comp.lang.python users). -- Thomas From rosuav at gmail.com Fri Jun 8 13:54:25 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Jun 2018 03:54:25 +1000 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: <87sh5x2nd7.fsf@elektro.pacujo.net> References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> Message-ID: On Sat, Jun 9, 2018 at 3:34 AM, Marko Rauhamaa wrote: > Gene Heskett : >> On Friday 08 June 2018 08:18:19 Chris Angelico wrote: >>> Are news servers guaranteed to carry the X-Copyright header in all >>> transmissions? If not, the copyright notice isn't part of the message, >>> and is most likely unenforceable. >> >> As the courts have so found when this has come up over the last 30 years. >> Basically, its just some newly minted lawyer trying to earn his place at >> the feeding trough. > > Copyrights exist whether they are declared or not. Yes, this is true. It's not copyright that is unenforceable, but the copyright notice in his message. Nobody is denying that he owns his own words; but by posting them on a public forum, he - like everyone else here - is implicitly granting us the right to read them. > If I publish a poem or, say, a Python application on Usenet, you will > need my permission to distribute it. Of course, its dissemination via > Usenet and remailers is ultimately *me* distributing my work. Right. Imagine if I write a poem, just like you say, and then I have the words posted on a gigantic billboard. In small print in the bottom corner of the billboard, I say "Copyright 2018 Chris Angelico. Taking photographs of this billboard is forbidden.". Do I still own copyright in the poem? Definitely. Can I stop people from (or sue people for) taking photos of the billboard? Probably not, although that's one for the lawyers to argue. > In one Usenet discussion I published my translation of a Finnish > Christmas carol. The author of the original lyrics had died more than 70 > years before so that was ok. However, the melody was still under > copyright so I didn't have a right to *explain* in any direct manner how > the melody went. > > Luckily, someone had posted the song on Youtube so I could provide a > link (although even that could be considered criminal in some > jurisdictions). That's the flip side of copyright: you're taking someone else's copyrighted material and posting it in public. Since you are not the author, you do not inherently have the right to do that. There are various legal permissions (very old works, "fair use", etc), but absent those, you would be violating copyright. (Whether linking to a third-party Youtube video is itself a violation of the original author's copyright is even more complicated. IANAL and I am not going to even think about how messy that situation could get.) > PS IMO copyright laws should be abolished altogether. At the very least > one should pay for copyright protection. One ?1 for the first year, ?2 > for the second, ?4 for the third and so on exponentially. Why should I have to pay money for the right to own my own creations? At what point does a creation have to be paid for - do I pay only if I think that I can make money off it? If I fail to pay, what happens - are people allowed to completely reuse and remix my work without even acknowledging me? And who would you pay that to anyway? The one world government? Copyright laws and international treaties are there to protect content creators and encourage creation. They need to have set expiration time (IMO 50 years is long enough - not "50 years since author's death" but 50 years since publication) after which the work becomes free to use, but the protections are important and extremely useful. Open source would not exist without copyright, because it is copyright law that gives license terms their meaning. Even if your license terms amount to "do what you like with this but be sure to credit me as the author", that's only enforceable because of copyright law. If people had to pay exorbitant rates for the privilege of being properly credited for their work, theft would completely trump generosity. ChrisA From marko at pacujo.net Fri Jun 8 14:11:10 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 08 Jun 2018 21:11:10 +0300 Subject: Stefan's headers [was:Names and identifiers] References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> Message-ID: <87lgbp2loh.fsf@elektro.pacujo.net> Chris Angelico : > On Sat, Jun 9, 2018 at 3:34 AM, Marko Rauhamaa wrote: >> PS IMO copyright laws should be abolished altogether. At the very >> least one should pay for copyright protection. One ?1 for the first >> year, ?2 for the second, ?4 for the third and so on exponentially. > > Why should I have to pay money for the right to own my own creations? You shouldn't have to. IMO the government shouldn't interfere with other people distributing your creations without your permission. I offered a compromise: the government steps in to defend your monopoly to your creation and you will pay for the protection -- exponentially. > At what point does a creation have to be paid for - do I pay only if I > think that I can make money off it? If I fail to pay, what happens - No money, no protection. > are people allowed to completely reuse and remix my work without even > acknowledging me? That would be ideal, absolutely! > And who would you pay that to anyway? The one world government? A good question! If I violate your foreign copyright in my country, which country should enforce the collection of damages? There's a precedent. If I send you a letter by mail, only my country's postal service gets money but your country's postal service will deliver it to you without compensation. > the protections are important and extremely useful. Disagree there. > Open source would not exist without copyright, because it is copyright > law that gives license terms their meaning. Some people would lose, others would win. On the balance, society would win out by dropping the concept of a copyright. > If people had to pay exorbitant rates for the privilege of being > properly credited for their work, theft would completely trump > generosity. That wouldn't be theft. Marko From gheskett at shentel.net Fri Jun 8 14:33:45 2018 From: gheskett at shentel.net (Gene Heskett) Date: Fri, 8 Jun 2018 14:33:45 -0400 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: <87sh5x2nd7.fsf@elektro.pacujo.net> References: <87sh5x2nd7.fsf@elektro.pacujo.net> Message-ID: <201806081433.45936.gheskett@shentel.net> On Friday 08 June 2018 13:34:44 Marko Rauhamaa wrote: > Gene Heskett : > > On Friday 08 June 2018 08:18:19 Chris Angelico wrote: > >> Are news servers guaranteed to carry the X-Copyright header in all > >> transmissions? If not, the copyright notice isn't part of the > >> message, and is most likely unenforceable. > > > > As the courts have so found when this has come up over the last 30 > > years. Basically, its just some newly minted lawyer trying to earn > > his place at the feeding trough. > > Copyrights exist whether they are declared or not. > > If I publish a poem or, say, a Python application on Usenet, you will > need my permission to distribute it. Of course, its dissemination via > Usenet and remailers is ultimately *me* distributing my work. > > In one Usenet discussion I published my translation of a Finnish > Christmas carol. The author of the original lyrics had died more than > 70 years before so that was ok. However, the melody was still under > copyright so I didn't have a right to *explain* in any direct manner > how the melody went. > > Luckily, someone had posted the song on Youtube so I could provide a > link (although even that could be considered criminal in some > jurisdictions). > > > Marko > > PS IMO copyright laws should be abolished altogether. At the very > least one should pay for copyright protection. One ?1 for the first > year, ?2 for the second, ?4 for the third and so on exponentially. I rather like that idea. Unforch, who would be in charge of keeping the books uptodate? The USTPO? Of course that would expand another guvmnt agencies payroll x10, and its a waste of taxpayer dollars since Albert retired anyway. Here in the hew hess aye, we originally had a copyright term of 7 years, renewable just once for another 7. I will date myself by saying I can actually remember those days. But then Disney started buying senators and congressmen, and we now have this asinine lifetime +70 years just to keep Mickey Mouse and Company's (oh, and don't forget a widow named Cher) income rolling in. Thats the sort of stuff usually found, warm and squishy, on the ground behind the male of the bovine specie. -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From markos at c2o.pro.br Fri Jun 8 14:54:24 2018 From: markos at c2o.pro.br (Markos) Date: Fri, 8 Jun 2018 15:54:24 -0300 Subject: How to install matplotlib in Debian 9 Message-ID: <59e29d92-7725-1fff-db1c-7bac94c42c4d@c2o.pro.br> Hi, I'm starting my studies with Python 3 on Debian 9 that I just installed. I have to install the matplotlib module, but I am in doubt what is the difference of the commands: pip3 install matplotlib or apt-get install python3-matplotlib Is there any difference in the packages which are installed? Thanks, Markos From marko at pacujo.net Fri Jun 8 15:16:50 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 08 Jun 2018 22:16:50 +0300 Subject: Stefan's headers [was:Names and identifiers] References: <87sh5x2nd7.fsf@elektro.pacujo.net> <201806081433.45936.gheskett@shentel.net> Message-ID: <87tvqdulzx.fsf@elektro.pacujo.net> Gene Heskett : > On Friday 08 June 2018 13:34:44 Marko Rauhamaa wrote: >> PS IMO copyright laws should be abolished altogether. At the very >> least one should pay for copyright protection. One ?1 for the first >> year, ?2 for the second, ?4 for the third and so on exponentially. > > I rather like that idea. Unforch, who would be in charge of keeping the > books uptodate? The USTPO? Of course that would expand another guvmnt > agencies payroll x10, and its a waste of taxpayer dollars since Albert > retired anyway. That exponential system would pay for itself. At the moment nobody pays the government to enforce copyrights. > But then Disney started buying senators and congressmen, and we now > have this asinine lifetime +70 years just to keep Mickey Mouse and > Company's (oh, and don't forget a widow named Cher) income rolling in. In my scheme, ?15/$15 would buy you four years of exclusive rights to your creation. If it turns profitable, an extra $1,008 would give you six more years (10 years total -- not too bad). And if you hit a jackpot, $1,000,000 for twenty years of exclusive rights shouldn't be too much to ask. And speaking of Disney, for a mere $1,000,000,000 it could get a whopping 30 years of exclusive rights to Mickey Mouse! Marko From larry.martell at gmail.com Fri Jun 8 16:01:06 2018 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 8 Jun 2018 16:01:06 -0400 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: <87tvqdulzx.fsf@elektro.pacujo.net> References: <87sh5x2nd7.fsf@elektro.pacujo.net> <201806081433.45936.gheskett@shentel.net> <87tvqdulzx.fsf@elektro.pacujo.net> Message-ID: On Fri, Jun 8, 2018 at 3:16 PM, Marko Rauhamaa wrote: > At the moment nobody pays > the government to enforce copyrights. No, everyone pays for what the government does. From python at mrabarnett.plus.com Fri Jun 8 16:59:30 2018 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 8 Jun 2018 21:59:30 +0100 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: <87lgbp2loh.fsf@elektro.pacujo.net> References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <87lgbp2loh.fsf@elektro.pacujo.net> Message-ID: <20cbf1d5-1b92-99a4-15a1-9cebed838852@mrabarnett.plus.com> On 2018-06-08 19:11, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sat, Jun 9, 2018 at 3:34 AM, Marko Rauhamaa wrote: >>> PS IMO copyright laws should be abolished altogether. At the very >>> least one should pay for copyright protection. One ?1 for the first >>> year, ?2 for the second, ?4 for the third and so on exponentially. >> >> Why should I have to pay money for the right to own my own creations? > > You shouldn't have to. IMO the government shouldn't interfere with other > people distributing your creations without your permission. > > I offered a compromise: the government steps in to defend your monopoly > to your creation and you will pay for the protection -- exponentially. > >> At what point does a creation have to be paid for - do I pay only if I >> think that I can make money off it? If I fail to pay, what happens - > > No money, no protection. > So those with the most money can buy the most protection? [snip] From rosuav at gmail.com Fri Jun 8 17:04:56 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Jun 2018 07:04:56 +1000 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: <20cbf1d5-1b92-99a4-15a1-9cebed838852@mrabarnett.plus.com> References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <87lgbp2loh.fsf@elektro.pacujo.net> <20cbf1d5-1b92-99a4-15a1-9cebed838852@mrabarnett.plus.com> Message-ID: On Sat, Jun 9, 2018 at 6:59 AM, MRAB wrote: > On 2018-06-08 19:11, Marko Rauhamaa wrote: >> >> Chris Angelico : >> >>> On Sat, Jun 9, 2018 at 3:34 AM, Marko Rauhamaa wrote: >>>> >>>> PS IMO copyright laws should be abolished altogether. At the very >>>> least one should pay for copyright protection. One ?1 for the first >>>> year, ?2 for the second, ?4 for the third and so on exponentially. >>> >>> >>> Why should I have to pay money for the right to own my own creations? >> >> >> You shouldn't have to. IMO the government shouldn't interfere with other >> people distributing your creations without your permission. >> >> I offered a compromise: the government steps in to defend your monopoly >> to your creation and you will pay for the protection -- exponentially. >> >>> At what point does a creation have to be paid for - do I pay only if I >>> think that I can make money off it? If I fail to pay, what happens - >> >> >> No money, no protection. >> > So those with the most money can buy the most protection? Yes, or more specifically, those who believe they can make the most money from that protection. Ownership becomes pay-to-win, literally. ChrisA From Joseph.Schachner at Teledyne.com Fri Jun 8 17:10:43 2018 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Fri, 8 Jun 2018 21:10:43 +0000 Subject: logging with multiprocessing In-Reply-To: References: Message-ID: <9aeef96b46bc4296b112969a7b61cd98@Teledyne.com> Multiprocessing, not multithreading. Different processes. This is pretty easy to do. I have done this from a Python script to run an analysis program on many sets of data, at once. To do it: 1) if there is going to be an output file, each output file must have a distinct name. 2) To use logging, log to file, and each log file will have to have a distinct name. This is not hard to do. I assume input data is different for each run, so we don't have to do anything about that. Then there won't be any conflict. Input files are distinct output files are distinct, and log files are distinct. When I did this, we had the pleasure of running on a 20 core dual Xeon based system, I don't remember if ran 20 processes at a time or slightly less. Anyway, we really did achieve nearly linear speed up. Windows did assign these processes to separate cores. --- Joe S. -----Original Message----- From: jenil.desai25 at gmail.com Sent: Thursday, June 7, 2018 2:46 PM To: python-list at python.org Subject: logging with multiprocessing Hello, I am new to logging module. I want to use logging module with multiprocessing. can anyone help me understand how can I do it?. Any help would be appreciated. Thank you. From cs at cskk.id.au Fri Jun 8 18:03:27 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 9 Jun 2018 08:03:27 +1000 Subject: Problem finding my folder via terminal In-Reply-To: References: Message-ID: <20180608220327.GA50824@cskk.homeip.net> On 08Jun2018 10:23, Tamara Berger wrote: >On Fri, Jun 8, 2018 at 5:35 AM Cameron Simpson wrote: >> On 08Jun2018 01:52, Tamara Berger wrote: >> >192:~ TamaraB$ cd Desktop/mymodules >> >192:mymodules TamaraB$ pwd >> >/Users/TamaraB/Desktop/mymodules >> >192:mymodules TamaraB$ ls >> >mymodules >> >> It looks like you have a "mymodules" folder _inside_ your "Desktop/mymodules" >> folder. Form the /Users/TamaraB/Desktop/mymodules folder, type these commands. >> >> ls -la >> ls -la mymodules > >Nope. No duplicate folder. Your Terminal transcript above says otherwise, because (a) you're standing in "/Users/TamaraB/Desktop/mymodules" and (b) the "ls" command shows: mymodules Therefore, _inside_ the "/Users/TamaraB/Desktop/mymodules" folder there is something called "mymodules", unless the transcript above is not complete. Please pos the result of: ls -laR /Users/TamaraB/Desktop/mymodules Cheers, Cameron Simpson From cs at cskk.id.au Fri Jun 8 18:05:37 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 9 Jun 2018 08:05:37 +1000 Subject: Distribution file error In-Reply-To: <03ba0d79-f94d-4f24-95d7-d99be3716840@googlegroups.com> References: <03ba0d79-f94d-4f24-95d7-d99be3716840@googlegroups.com> Message-ID: <20180608220537.GA61272@cskk.homeip.net> On 08Jun2018 07:52, Tamara Berger wrote: >I?m trying to create a distribution file for my module, but got an error >message. The module, including the setup and read me files, are contained >within the folder ?mymodules.? I typed this command (per instructions from my >workbook) from within mymodules folder: > >192:~ TamaraB$ cd Desktop/mymodules/ >192:mymodules TamaraB$ python3 setup.py sdist >/Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python: can't open file 'setup.py': [Errno 2] No such file or directory. > >Why is this not working? > >(I?m working in the OS Sierra terminal.) The immediate reason that comes to mind is that there's isn't a "setup.py" file in that folder. What _is_ in that folder? We're already discussing this in another thread; it's better to keep all this stuff together. Cheers, Cameron Simpson From marko at pacujo.net Fri Jun 8 18:19:22 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 09 Jun 2018 01:19:22 +0300 Subject: Stefan's headers [was:Names and identifiers] References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <87lgbp2loh.fsf@elektro.pacujo.net> <20cbf1d5-1b92-99a4-15a1-9cebed838852@mrabarnett.plus.com> Message-ID: <87po10vs45.fsf@elektro.pacujo.net> Chris Angelico : > On Sat, Jun 9, 2018 at 6:59 AM, MRAB wrote: >> So those with the most money can buy the most protection? > > Yes, or more specifically, those who believe they can make the most > money from that protection. Ownership becomes pay-to-win, literally. In the words of Scrooge McDuck: But guys, surely you are familiar with the exponential function: * Everybody can afford a year for $1. * Every worthwhile creation is worth $1,000 for ten years. * And if Disney can pay the fee for Mickey Mouse for fifty years, the United States Government can quit all taxation, pay off the national debt and buy every American a luxury yacht and a private island in the Caribbean. Marko From cs at cskk.id.au Fri Jun 8 18:26:10 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 9 Jun 2018 08:26:10 +1000 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: <48742502-aaf3-43a4-93b1-a1eb37f3e37c@googlegroups.com> References: <48742502-aaf3-43a4-93b1-a1eb37f3e37c@googlegroups.com> Message-ID: <20180608222610.GA1230@cskk.homeip.net> On 05Jun2018 06:42, bellcanadardp at gmail.com wrote: >On Sunday, 3 June 2018 20:11:43 UTC-4, Steven D'Aprano wrote: >> Don't retype a summary of what you think the error is. "character >> undefieed" is not a thing, and there is no such thing as "byte 1x09". >> >> You need to COPY AND PASTE the EXACT error that you get. Not just the >> last line, the error message, but the FULL TRACEBACK starting from the >> line "Traceback" and going to the end. [...] > >here is the exact error full message >in the attachment...UPDATE..i am manually modifying this reply..i tried to answer by my gmail but i get errors and i couldnt find this webpage till today and it doesnt accept attachments..so many you can for future provide an email if thats ok...anyway i will write the error manually here: Many of us read this group/list via the mailing list python-list at python.org. I've CCed it here. Just avoid Google Groups, they're an awful interface to both usenet and mailing lists. >File >"C:\Users\Robert\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py", >line 23, in decode >return codecs.charmap_decode(input,self.errors,decoding_table[0] >UnicodeDecodeError: 'charmap'codec can't decode byte 0x9d in position 7414: character maps to As Steven has remarked, this is not the complete traceback he requested, just the end. We need to know the entire execution stack. >for the record i did not puprosely set the code or decode o encode to cp-1252; >this is a 3rd party script i have from the internet thats all Can you say where it came from and how you fetched it? That may affect how the file got into this situation and how it might be repaired. It might also let us fetch the file ourselves to look at it. >this a set of files that runs find in python 2.7 >i am trying to run it in python 3 becuz i was told in 2020 python 2 will no longer be supported >not sure if that really matters for my script It may not matter, but as a general rule you should try to use Python 3 for new stuff. Python 2 is effectively end of life. >it runs completey fine in python 2, so for me the issue is with python 3 and >its changes relative to python 2 It is possible that Python 2 is just glossing over the problem; Python 3 has a more rigorous view of character data. Cheers, Cameron Simpson From jlee54 at gmail.com Fri Jun 8 19:11:03 2018 From: jlee54 at gmail.com (Jim Lee) Date: Fri, 8 Jun 2018 16:11:03 -0700 Subject: How to install matplotlib in Debian 9 In-Reply-To: <59e29d92-7725-1fff-db1c-7bac94c42c4d@c2o.pro.br> References: <59e29d92-7725-1fff-db1c-7bac94c42c4d@c2o.pro.br> Message-ID: <363cc549-ec13-083d-0746-6bff89406de3@gmail.com> On 06/08/2018 11:54 AM, Markos wrote: > Hi, > > I'm starting my studies with Python 3 on Debian 9 that I just installed. > > I have to install the matplotlib module, but I am in doubt what is the > difference of the commands: > > pip3 install matplotlib > > or > > apt-get install python3-matplotlib > > Is there any difference in the packages which are installed? > > Thanks, > > Markos > It's generally preferable to use your distribution's package manager (apt-get) to install packages, as you will then receive updates as they become available.? However, Debian is notorious for having stale/outdated packages in its repository.? If you need the latest version of matplotlib, use pip (you'll have to update it manually).? If you want old but stable, use apt-get. -Jim From gheskett at shentel.net Fri Jun 8 19:50:43 2018 From: gheskett at shentel.net (Gene Heskett) Date: Fri, 8 Jun 2018 19:50:43 -0400 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <87tvqdulzx.fsf@elektro.pacujo.net> Message-ID: <201806081950.43246.gheskett@shentel.net> On Friday 08 June 2018 16:01:06 Larry Martell wrote: > On Fri, Jun 8, 2018 at 3:16 PM, Marko Rauhamaa wrote: > > At the moment nobody pays > > the government to enforce copyrights. > > No, everyone pays for what the government does, poorly. There, I fixed it for you Larry. :) -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From steve+comp.lang.python at pearwood.info Fri Jun 8 20:11:02 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 9 Jun 2018 00:11:02 +0000 (UTC) Subject: Sorting NaNs References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: On Fri, 08 Jun 2018 17:45:58 +0000, Peter Pearson wrote: > What bothered me was my feeling that a "reasonable observer" > would expect the random-float population to be much larger than 2**32, > and the probably-collision-free sample size to be accordingly much > larger than 2**16, which is, after all, small enough to appear in many > applications. People's intuition about probability is crap. Hence the Birthday Paradox I already linked to, and the Monty Hall Problem, which you can google for, and the Prosecutor's Fallacy: http://www.conceptstew.co.uk/pages/prosecutors_fallacy.html which sometimes (often?) leads to real miscarriages of justice: https://en.wikipedia.org/wiki/Sally_Clark -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Fri Jun 8 20:15:43 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Jun 2018 10:15:43 +1000 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: <87po10vs45.fsf@elektro.pacujo.net> References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <87lgbp2loh.fsf@elektro.pacujo.net> <20cbf1d5-1b92-99a4-15a1-9cebed838852@mrabarnett.plus.com> <87po10vs45.fsf@elektro.pacujo.net> Message-ID: On Sat, Jun 9, 2018 at 8:19 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sat, Jun 9, 2018 at 6:59 AM, MRAB wrote: >>> So those with the most money can buy the most protection? >> >> Yes, or more specifically, those who believe they can make the most >> money from that protection. Ownership becomes pay-to-win, literally. > > In the words of Scrooge McDuck: > > > > > But guys, surely you are familiar with the exponential function: > > * Everybody can afford a year for $1. $1 per what, though? According to GitHub, I have 157 repositories. Is that 157 separate things that cost $1 for a single year of protection? Or do I pay per file of source code? > * Every worthwhile creation is worth $1,000 for ten years. Not true by a long shot, and if you don't believe me, you can pay me $1000 right now for ten years' use of any of my free software. > * And if Disney can pay the fee for Mickey Mouse for fifty years, the > United States Government can quit all taxation, pay off the national > debt and buy every American a luxury yacht and a private island in > the Caribbean. And if you think that Disney would actually let it compound according to your theoretical definition, you're a dupe AND a fool. They'd figure out some way to reset the counter every five years. ChrisA From tkadm30 at yandex.com Fri Jun 8 20:16:54 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Fri, 8 Jun 2018 20:16:54 -0400 Subject: Django-hotsauce 0.9.4.1 is out Message-ID: Hi everyone, Django-hotsauce 0.9.4.1 (open source edition) is out! What's new - Maintenance bugfixes for ZODBController class (cPython, PyPy) - Minor bugfixes and updates Download - https://pypi.org/pypi/Django-hotsauce/ - https://www.isotopesoftware.ca/pub/django-hotsauce/django-hotsauce-0.9.4.1.tar.gz Have fun! Etienne -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From steve+comp.lang.python at pearwood.info Fri Jun 8 20:53:01 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 9 Jun 2018 00:53:01 +0000 (UTC) Subject: Stefan's headers [was:Names and identifiers] References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> Message-ID: On Sat, 09 Jun 2018 03:54:25 +1000, Chris Angelico wrote: > Right. Imagine if I write a poem, just like you say, and then I have the > words posted on a gigantic billboard. In small print in the bottom > corner of the billboard, I say "Copyright 2018 Chris Angelico. Taking > photographs of this billboard is forbidden.". Do I still own copyright > in the poem? Definitely. Can I stop people from (or sue people for) > taking photos of the billboard? Probably not, although that's one for > the lawyers to argue. If it were you? Probably not. If it were a building owned by a major company with deep pockets and powerful friends, or one with a "special relationship" to the government, especially if they can make a buck from it? Then yes, taking photos of publicly visible buildings and even natural features can be copyright infringement. https://www.diyphotography.net/10-famous-landmarks-youre-allowed- photograph-commercial-use/ [,...] > (Whether linking to a third-party Youtube video is itself a violation of > the original author's copyright is even more complicated. IANAL and I am > not going to even think about how messy that situation could get.) Describing a link to a Youtube video as copyright infringement is an incredibly egregious example of copyright creep. Such a link in no way copies the copyrighted work, nor does it distribute the work. (The video itself may or may not infringe, but that's another question.) It might be argued that it *facilitates copyright infringement*, in the same way telling people that they can buy a crowbar from Bunnings facilitates breaking and entering. But it does not and should not be considered copyright infringement under any circumstances. The fact that people even fear that it might is a good example of how the necessary and useful monopoly of copyright has grown to be a monster. [...] > Why should I have to pay money for the right to own my own creations? Because such a right is no right at all, but a privilege granted to you by the government for specific purposes. Copyright is not a natural right. Because such a privilege infringes on other people's natural rights to copy what they see and hear. If somebody tells you a story, it is the most natural thing in the world to repeat it if you liked it. > And who would you pay that to anyway? The one world government? No, your national government of course, which would then have treaties with other trading blocks or countries that effectively say "you respect and enforce our copyrights and we'll respect and enforce yours". But how quickly we forget the past. In my lifetime, copyright was not automatic. You had to officially register a work, or else it was in the public domain. If it wasn't worth it to you to fill out a registration form and post it, why should you be given a monopoly on the work? For decades the US government charged a fee to register copyright, and the vast bulk of copyrighted works were not renewed after the first 13 year term expired. Which is perfectly normal: the vast bulk of copyright works have no real value to the creator and no reasonable prospect of earning them income after a decade or two. And yet we impoverish our cultural commons by keeping works locked up under monopolistic laws for a lifetime past the death the author. I think that the monopolization of so-called "intellectual property" rights has grown to a harmful extent. Economists who study this have found that copyright hurts the economy more than it helps (it discourages creators more than encourages) but if we could roll it back somewhat, I think it would be a good and useful tool: - automatic, free copyright for an initial term of, let's say, 20 years; - followed by one more free term of ten years requiring registration; - followed by additional ten-year copyright terms, paid for at (say) $100 a term; - up to a maximum length of sixty years, or the author's life plus 30 years, whichever comes first; - and a real commitment to recognising the public domain and free culture it as an asset to be protected and encouraged, not just a commons to be looted, monetized and locked up. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Fri Jun 8 20:55:26 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 9 Jun 2018 00:55:26 +0000 (UTC) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to References: <48742502-aaf3-43a4-93b1-a1eb37f3e37c@googlegroups.com> <20180608222610.GA1230@cskk.homeip.net> Message-ID: On Sat, 09 Jun 2018 08:26:10 +1000, Cameron Simpson wrote: > It is possible that Python 2 is just glossing over the problem; Python 3 > has a more rigorous view of character data. I would say that is more than just possible, it is almost certain. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Fri Jun 8 21:13:46 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Jun 2018 11:13:46 +1000 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> Message-ID: On Sat, Jun 9, 2018 at 10:53 AM, Steven D'Aprano wrote: > On Sat, 09 Jun 2018 03:54:25 +1000, Chris Angelico wrote: >> (Whether linking to a third-party Youtube video is itself a violation of >> the original author's copyright is even more complicated. IANAL and I am >> not going to even think about how messy that situation could get.) > > Describing a link to a Youtube video as copyright infringement is an > incredibly egregious example of copyright creep. Such a link in no way > copies the copyrighted work, nor does it distribute the work. > > (The video itself may or may not infringe, but that's another question.) > > It might be argued that it *facilitates copyright infringement*, in the > same way telling people that they can buy a crowbar from Bunnings > facilitates breaking and entering. But it does not and should not be > considered copyright infringement under any circumstances. It was the "facilitates" part that I was referring to. If the video in question infringes, and I share a link to it, am I guilty of sharing something around? What if the original owner uploaded it as an unlisted video, and I share that link around? What if the uploader (who is not the owner) legitimately stayed within "fair use", but I piece together the entire original from a bunch of links, creating a playlist with all of the content, and share that? I'm sure there are legal answers to all of those questions, but it's definitely hairy territory. ChrisA From greg.ewing at canterbury.ac.nz Fri Jun 8 22:28:08 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 09 Jun 2018 14:28:08 +1200 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> Message-ID: Peter Pearson wrote: > What applications would have to worry about colliding floats? I > don't know. I'm coming from cryptology, where worrying about such > things becomes a reflex. If collisions are something to be feared, then you're into hash territory, where you're probably going to want *much* more than even 52 bits. -- Greg From brgrt2 at gmail.com Fri Jun 8 22:55:58 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Fri, 8 Jun 2018 22:55:58 -0400 Subject: Problem finding my folder via terminal In-Reply-To: <20180608220327.GA50824@cskk.homeip.net> References: <20180608220327.GA50824@cskk.homeip.net> Message-ID: Hi Cameron, I have to answer you via email because I haven't gotten the hang of the inline style yet. Here is the result of your suggestion: Last login: Fri Jun 8 22:43:58 on ttys001 192:~ TamaraB$ cd Desktop/mymodules/ 192:mymodules TamaraB$ ls -laR /Users/TamaraB/Desktop/mymodules total 16 drwxr-xr-x 4 TamaraB staff 136 Jun 7 01:32 . drwx------+ 37 TamaraB staff 1258 Jun 8 22:30 .. -rw-r--r--@ 1 TamaraB staff 6148 Jun 7 10:54 .DS_Store drwxr-xr-x 5 TamaraB staff 170 Jun 7 01:32 mymodules /Users/TamaraB/Desktop/mymodules/mymodules: total 16 drwxr-xr-x 5 TamaraB staff 170 Jun 7 01:32 . drwxr-xr-x 4 TamaraB staff 136 Jun 7 01:32 .. -rw-r--r--@ 1 TamaraB staff 0 Jun 5 09:47 README.py -rw-r--r--@ 1 TamaraB staff 253 Jun 7 10:55 setup.py -rw-r--r--@ 1 TamaraB staff 166 Jun 5 10:01 vsearch.py 192:mymodules TamaraB$ (When I copied the coding into the email, I got a line of space between each line of coding, and had to delete the extra lines one by one? Any way to do this job nonmanually or to transfer the coding into an email without the extra lines of space?) Thanks for all your help. Tamara On Fri, Jun 8, 2018 at 6:03 PM Cameron Simpson wrote: > > On 08Jun2018 10:23, Tamara Berger wrote: > >On Fri, Jun 8, 2018 at 5:35 AM Cameron Simpson wrote: > >> On 08Jun2018 01:52, Tamara Berger wrote: > >> >192:~ TamaraB$ cd Desktop/mymodules > >> >192:mymodules TamaraB$ pwd > >> >/Users/TamaraB/Desktop/mymodules > >> >192:mymodules TamaraB$ ls > >> >mymodules > >> > >> It looks like you have a "mymodules" folder _inside_ your "Desktop/mymodules" > >> folder. Form the /Users/TamaraB/Desktop/mymodules folder, type these commands. > >> > >> ls -la > >> ls -la mymodules > > > >Nope. No duplicate folder. > > Your Terminal transcript above says otherwise, because (a) you're standing in > "/Users/TamaraB/Desktop/mymodules" and (b) the "ls" command shows: > > mymodules > > Therefore, _inside_ the "/Users/TamaraB/Desktop/mymodules" folder there is > something called "mymodules", unless the transcript above is not complete. > > Please pos the result of: > > ls -laR /Users/TamaraB/Desktop/mymodules > > Cheers, > Cameron Simpson From greg.ewing at canterbury.ac.nz Fri Jun 8 23:11:22 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 09 Jun 2018 15:11:22 +1200 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> Message-ID: Gene Heskett wrote: > The courts weren't amused. I don't know as any of us ever cut those > patent troll turkey's a check, Patent troll turkeys: Don't cut them checks, cut their necks! (Insert suitable stock photo of a turkey about to have its head removed.) -- Greg From greg.ewing at canterbury.ac.nz Sat Jun 9 01:07:35 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 09 Jun 2018 17:07:35 +1200 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> Message-ID: Chris Angelico wrote: > Open source would not exist without copyright,because it is > copyright law that gives license terms their meaning. That statement doesn't make any sense. If there were no copyright laws, there would be no need for licences to distribute software. You seem to be saying that nobody would ever release the source of their software unless they could impose some kind of restrictions on what people could do with it. But I don't think that's true at all. Open sharing of software was the *default* before people got the idea of applying copyright laws to it. If there were no copyright laws, people who wanted to share their source would still do so, and people who wanted to keep it a trade secret would still do so. The only difference is there would be less lawyers making money out of it. > Even if your license terms amount > to "do what you like with this but be sure to credit me as the > author", that's only enforceable because of copyright law. If attribution is all that really matters, it could be addressed by quite a different kind of law. Or tackle it socially rather than legally. Get it out there first with your name all over it, so that anyone who tries to "steal" it later will receive the appropriate level of public shaming. -- Greg From greg.ewing at canterbury.ac.nz Sat Jun 9 01:07:41 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 09 Jun 2018 17:07:41 +1200 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <87lgbp2loh.fsf@elektro.pacujo.net> <20cbf1d5-1b92-99a4-15a1-9cebed838852@mrabarnett.plus.com> Message-ID: MRAB wrote: > So those with the most money can buy the most protection? That's the way it works with patents... -- Greg From cs at cskk.id.au Sat Jun 9 01:15:05 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 9 Jun 2018 15:15:05 +1000 Subject: Problem finding my folder via terminal In-Reply-To: References: Message-ID: <20180609051505.GA24078@cskk.homeip.net> On 08Jun2018 22:55, Tamara Berger wrote: >I have to answer you via email because I haven't gotten the hang of >the inline style yet. I'm using email :-) We use the inline style for that, too. Just walk down the quoted previous message and insert your responses below the relevant parts with blank lines separating the quoted material from your text. Anyway... >Here is the result of your suggestion: > >Last login: Fri Jun 8 22:43:58 on ttys001 >192:~ TamaraB$ cd Desktop/mymodules/ >192:mymodules TamaraB$ ls -laR /Users/TamaraB/Desktop/mymodules >total 16 >drwxr-xr-x 4 TamaraB staff 136 Jun 7 01:32 . >drwx------+ 37 TamaraB staff 1258 Jun 8 22:30 .. >-rw-r--r--@ 1 TamaraB staff 6148 Jun 7 10:54 .DS_Store >drwxr-xr-x 5 TamaraB staff 170 Jun 7 01:32 mymodules Ok, so here we see that there _is_ a "mymodules" folder inside your "/Users/TamaraB/Desktop/mymodules" folder. >/Users/TamaraB/Desktop/mymodules/mymodules: >total 16 >drwxr-xr-x 5 TamaraB staff 170 Jun 7 01:32 . >drwxr-xr-x 4 TamaraB staff 136 Jun 7 01:32 .. >-rw-r--r--@ 1 TamaraB staff 0 Jun 5 09:47 README.py >-rw-r--r--@ 1 TamaraB staff 253 Jun 7 10:55 setup.py >-rw-r--r--@ 1 TamaraB staff 166 Jun 5 10:01 vsearch.py >192:mymodules TamaraB$ And inside that second "mymodules" folder is your vsearch module and its accompanying files. This kind of mistake is easy to make (the doubled directory). You can do 2 things at this point. 1: Just: cd /Users/TamaraB/Desktop/mymodules/mymodules and run the setup.py from in there. Or: 2: Repair the mistake: cd /Users/TamaraB/Desktop/mymodules mv mymodules/* . rmdir mymodules which will move all the files from the lower directory up to where they should be. Then run the setup.py. BTW, the README is normally a text file named README.txt or maybe a markdown file named README.md. >(When I copied the coding into the email, I got a line of space >between each line of coding, and had to delete the extra lines one by >one? Any way to do this job nonmanually or to transfer the coding into >an email without the extra lines of space?) That is odd. My guess would be that your cut/paste is sending the end of line as a CR (carriage return) and a NL (newline), and both of those are being "typed" at the paste end, resulting in double spaced text. Annoying. Are you using mail.google.com to read your GMail? I just tried cut/paste some text from both iTerm and Terminal on my Mac into a scratch message there and didn't get doubled lines. Can you describe _exactly_ what you did to copy the text into your email? Presumably you're doing something different from what I'm doing: select text in the terminal, type Cmd-C to copy it, click in my new message window and type Cmd-V to paste the copied text. Cheers, Cameron Simpson From brgrt2 at gmail.com Sat Jun 9 01:36:17 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Sat, 9 Jun 2018 01:36:17 -0400 Subject: Problem finding my folder via terminal In-Reply-To: <20180609051505.GA24078@cskk.homeip.net> References: <20180609051505.GA24078@cskk.homeip.net> Message-ID: Hi Cameron, Re inline style: When I hit reply, this is the window I get. I don't get my previous email with the carets appended to the beginning of the line. Before I look at the rest of your email, I'd like for you to explain how there is a mymodule folder nested within another mymodule folder. I don't see this second folder in Finder, and I definitely didn't create it. Thanks, Tamara On Sat, Jun 9, 2018 at 1:15 AM Cameron Simpson wrote: > > On 08Jun2018 22:55, Tamara Berger wrote: > >I have to answer you via email because I haven't gotten the hang of > >the inline style yet. > > I'm using email :-) We use the inline style for that, too. Just walk down the > quoted previous message and insert your responses below the relevant parts with > blank lines separating the quoted material from your text. Anyway... > > >Here is the result of your suggestion: > > > >Last login: Fri Jun 8 22:43:58 on ttys001 > >192:~ TamaraB$ cd Desktop/mymodules/ > >192:mymodules TamaraB$ ls -laR /Users/TamaraB/Desktop/mymodules > >total 16 > >drwxr-xr-x 4 TamaraB staff 136 Jun 7 01:32 . > >drwx------+ 37 TamaraB staff 1258 Jun 8 22:30 .. > >-rw-r--r--@ 1 TamaraB staff 6148 Jun 7 10:54 .DS_Store > >drwxr-xr-x 5 TamaraB staff 170 Jun 7 01:32 mymodules > > Ok, so here we see that there _is_ a "mymodules" folder inside your > "/Users/TamaraB/Desktop/mymodules" folder. > > >/Users/TamaraB/Desktop/mymodules/mymodules: > >total 16 > >drwxr-xr-x 5 TamaraB staff 170 Jun 7 01:32 . > >drwxr-xr-x 4 TamaraB staff 136 Jun 7 01:32 .. > >-rw-r--r--@ 1 TamaraB staff 0 Jun 5 09:47 README.py > >-rw-r--r--@ 1 TamaraB staff 253 Jun 7 10:55 setup.py > >-rw-r--r--@ 1 TamaraB staff 166 Jun 5 10:01 vsearch.py > >192:mymodules TamaraB$ > > And inside that second "mymodules" folder is your vsearch module and its > accompanying files. This kind of mistake is easy to make (the doubled > directory). > > You can do 2 things at this point. > > 1: Just: > > cd /Users/TamaraB/Desktop/mymodules/mymodules > > and run the setup.py from in there. > > Or: > > 2: Repair the mistake: > > cd /Users/TamaraB/Desktop/mymodules > mv mymodules/* . > rmdir mymodules > > which will move all the files from the lower directory up to where they should > be. Then run the setup.py. > > BTW, the README is normally a text file named README.txt or maybe a markdown > file named README.md. > > >(When I copied the coding into the email, I got a line of space > >between each line of coding, and had to delete the extra lines one by > >one? Any way to do this job nonmanually or to transfer the coding into > >an email without the extra lines of space?) > > That is odd. My guess would be that your cut/paste is sending the end of line > as a CR (carriage return) and a NL (newline), and both of those are being > "typed" at the paste end, resulting in double spaced text. Annoying. > > Are you using mail.google.com to read your GMail? I just tried cut/paste some > text from both iTerm and Terminal on my Mac into a scratch message there and > didn't get doubled lines. Can you describe _exactly_ what you did to copy the > text into your email? Presumably you're doing something different from what I'm > doing: select text in the terminal, type Cmd-C to copy it, click in my new > message window and type Cmd-V to paste the copied text. > > Cheers, > Cameron Simpson From gheskett at shentel.net Sat Jun 9 01:42:02 2018 From: gheskett at shentel.net (Gene Heskett) Date: Sat, 9 Jun 2018 01:42:02 -0400 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: Message-ID: <201806090142.02584.gheskett@shentel.net> On Friday 08 June 2018 23:11:22 Gregory Ewing wrote: > Gene Heskett wrote: > > The courts weren't amused. I don't know as any of us ever cut those > > patent troll turkey's a check, > > Patent troll turkeys: Don't cut them checks, cut their necks! > > (Insert suitable stock photo of a turkey about to have its > head removed.) > > -- > Greg That was my first impulse. But thats pretty sick bird, highly frowned on by the "authorities". People like that really should be removed from the gene pool, which would markedly enhance the human race after a while. Stress, that feeling created by resisting the urge to strangle someone who desperately needs it. But I've had the ultimate revenge, I've had the great good fortune to have outlived all my enemies save one, me. My clumsiness is getting worse. I bitch and belly-ache, to those that will listen, and someone will tell me they they hope to get along as well as I do when they are 83. -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From gheskett at shentel.net Sat Jun 9 02:37:39 2018 From: gheskett at shentel.net (Gene Heskett) Date: Sat, 9 Jun 2018 02:37:39 -0400 Subject: Problem finding my folder via terminal In-Reply-To: References: <20180609051505.GA24078@cskk.homeip.net> Message-ID: <201806090237.39143.gheskett@shentel.net> On Saturday 09 June 2018 01:36:17 Tamara Berger wrote: > Hi Cameron, > > Re inline style: When I hit reply, this is the window I get. I don't > get my previous email with the carets appended to the beginning of the > line. > That might be a config choice, but since its gmail it may not be. I tried to use gmail as a pop server years ago, and bailed out in about a week, way too much was hard coded. > Before I look at the rest of your email, I'd like for you to explain > how there is a mymodule folder nested within another mymodule folder. > I don't see this second folder in Finder, and I definitely didn't > create it. Finder, if thats what you are using, I am not familiar with it, is probably showing you that which it has cached, before that folder was created. Back out one layer and go back in so it actually reads a fresh copy of that directory(folder). > Thanks, > > Tamara > > On Sat, Jun 9, 2018 at 1:15 AM Cameron Simpson wrote: > > On 08Jun2018 22:55, Tamara Berger wrote: > > >I have to answer you via email because I haven't gotten the hang of > > >the inline style yet. > > > > I'm using email :-) We use the inline style for that, too. Just walk > > down the quoted previous message and insert your responses below the > > relevant parts with blank lines separating the quoted material from > > your text. Anyway... > > > > >Here is the result of your suggestion: > > > > > >Last login: Fri Jun 8 22:43:58 on ttys001 > > >192:~ TamaraB$ cd Desktop/mymodules/ > > >192:mymodules TamaraB$ ls -laR /Users/TamaraB/Desktop/mymodules > > >total 16 > > >drwxr-xr-x 4 TamaraB staff 136 Jun 7 01:32 . > > >drwx------+ 37 TamaraB staff 1258 Jun 8 22:30 .. > > >-rw-r--r--@ 1 TamaraB staff 6148 Jun 7 10:54 .DS_Store > > >drwxr-xr-x 5 TamaraB staff 170 Jun 7 01:32 mymodules > > > > Ok, so here we see that there _is_ a "mymodules" folder inside your > > "/Users/TamaraB/Desktop/mymodules" folder. > > > > >/Users/TamaraB/Desktop/mymodules/mymodules: > > >total 16 > > >drwxr-xr-x 5 TamaraB staff 170 Jun 7 01:32 . > > >drwxr-xr-x 4 TamaraB staff 136 Jun 7 01:32 .. > > >-rw-r--r--@ 1 TamaraB staff 0 Jun 5 09:47 README.py > > >-rw-r--r--@ 1 TamaraB staff 253 Jun 7 10:55 setup.py > > >-rw-r--r--@ 1 TamaraB staff 166 Jun 5 10:01 vsearch.py > > >192:mymodules TamaraB$ > > > > And inside that second "mymodules" folder is your vsearch module and > > its accompanying files. This kind of mistake is easy to make (the > > doubled directory). > > > > You can do 2 things at this point. > > > > 1: Just: > > > > cd /Users/TamaraB/Desktop/mymodules/mymodules > > > > and run the setup.py from in there. > > > > Or: > > > > 2: Repair the mistake: > > > > cd /Users/TamaraB/Desktop/mymodules > > mv mymodules/* . > > rmdir mymodules > > > > which will move all the files from the lower directory up to where > > they should be. Then run the setup.py. > > > > BTW, the README is normally a text file named README.txt or maybe a > > markdown file named README.md. > > > > >(When I copied the coding into the email, I got a line of space > > >between each line of coding, and had to delete the extra lines one > > > by one? Any way to do this job nonmanually or to transfer the > > > coding into an email without the extra lines of space?) > > > > That is odd. My guess would be that your cut/paste is sending the > > end of line as a CR (carriage return) and a NL (newline), and both > > of those are being "typed" at the paste end, resulting in double > > spaced text. Annoying. > > > > Are you using mail.google.com to read your GMail? I just tried > > cut/paste some text from both iTerm and Terminal on my Mac into a > > scratch message there and didn't get doubled lines. Can you describe > > _exactly_ what you did to copy the text into your email? Presumably > > you're doing something different from what I'm doing: select text in > > the terminal, type Cmd-C to copy it, click in my new message window > > and type Cmd-V to paste the copied text. > > > > Cheers, > > Cameron Simpson -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From greg.ewing at canterbury.ac.nz Sat Jun 9 03:45:16 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 09 Jun 2018 19:45:16 +1200 Subject: Problem finding my folder via terminal In-Reply-To: References: <20180609051505.GA24078@cskk.homeip.net> <201806090237.39143.gheskett@shentel.net> Message-ID: Gene Heskett wrote: > Finder, if thats what you are using, I am not familiar with it, is > probably showing you that which it has cached, before that folder was > created. The Finder is usually pretty good at noticing things like that. I just tried creating a directory using a shell command while the Finder was displaying the containing folder, and it appeared immediately. MacOSX has a "hidden" attribute that stops things showing up in the Finder. You can check for that using: ls -ldO /Users/TamaraB/Desktop/mymodules ls -ldO /Users/TamaraB/Desktop/mymodules/mymodules (note that's a capital letter O in the options). If the hidden flag is set on either of those, it will show up as "hidden" in the ls listing. Here's an example from my system: % ls -ldO newfolder2 drwxr-xr-x@ 2 greg staff hidden 68 9 Jun 19:32 newfolder2 ^^^^^^ As for *how* you ended up with an extra folder (and how it came to be hidden, if it really is) there's no way to be sure. One way you can end up with extra folders is by unpacking zip files. MacOSX's unzipping utility will create a folder for the unzipped contents if the zip file contains more than just a single folder at the top level. So if you created a folder called "mymodules" and then unzipped a file called "mymodules.zip" into it, you would get what you have here (except that nothing would be hidden). -- Greg From vincent.vande.vyvre at telenet.be Sat Jun 9 04:07:18 2018 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Sat, 9 Jun 2018 10:07:18 +0200 Subject: Obsolete method in the html module Message-ID: Not really important, just a comment. In Python-3.7.0b5 we can find at the end of html/parser.py: ??? def unescape(self, s): ??????? warnings.warn('The unescape method is deprecated and will be removed ' ????????????????????? 'in 3.5, use html.unescape() instead.', ????????????????????? DeprecationWarning, stacklevel=2) ??????? return unescape(s) Vincent (send at 08:07 GMT) From cs at cskk.id.au Sat Jun 9 05:04:59 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 9 Jun 2018 19:04:59 +1000 Subject: Problem finding my folder via terminal In-Reply-To: <201806090237.39143.gheskett@shentel.net> References: <201806090237.39143.gheskett@shentel.net> Message-ID: <20180609090459.GA17745@cskk.homeip.net> On 09Jun2018 02:37, Gene Heskett wrote: >On Saturday 09 June 2018 01:36:17 Tamara Berger wrote: >> Re inline style: When I hit reply, this is the window I get. The python-list server strips attachments, so I didn't get the screenshot you may have attached. However... >> I don't >> get my previous email with the carets appended to the beginning of the >> line. I've just gone to my GMail and tried a reply. In my reply compose window there is a little button at the bottom left with three dots in it, thus: "[...]", kind of. Click that, it expands to the prior quoted text. Then you can trim it and insert your responses. >> Before I look at the rest of your email, I'd like for you to explain >> how there is a mymodule folder nested within another mymodule folder. >> I don't see this second folder in Finder, and I definitely didn't >> create it. > >Finder, if thats what you are using, I am not familiar with it, is >probably showing you that which it has cached, before that folder was >created. Back out one layer and go back in so it actually reads a fresh >copy of that directory(folder). The Finder uses MacOS' equivalent of Linux' inotify: its folder views are "live" and update as soon as anything changes. Tamara, there are things the Finder won't show, particularly "hidden" files, which is an attribute you can assign to folders. Maybe that is what happened. I've got no concrete explaination, and I can't inspect your machine directly. Also, how sure are you that the "mymodules" in the Finder is the upper one and not the lower one? Just guessing here. My opinion is that you did create it, but not realised how that happened. All you'd need to do is something like this: cd Desktop mkdir mymodules cd mymodules ... get distracted, do something else, come back much later ... mkdir mymodules cd mymodules ... proceed to make the setup.py and so forth ... i.e. just do it twice. Alternatively, and this is a common one, you got a template archive, such as a zip file, containing an "empty" module to get you started. And did something like this: cd Desktop mkdir mymodules cd mymodules unzip the-empty-module-template.zip If the zip file itself also contained a top level "mymodules" folder in it, it will have made the second "mymodules" inside the one you made. Most archive files are set up to have their entire contents inside a single top folder, so this scenario isn't all that unlikely. A third possibility is that you made a mymodules somewhere else (such as in your top level home directory), and later decided to put it on your Desktop to make it easy to find/access. So you might have decided to "mv" your "mymodules" folder into the Desktop like this: mv mymodules Desktop/mymodules which is fine. But mv has some interesting behaviour. If "mymodules" didn't exist in Desktop, then youre "mymodules" will get moved into the Desktop. However, if mv's final argument is an _existing_ directory, mv puts things inside it. So if you went: mkdir Desktop/mymodules mv mymodules Desktop/mymodules then mv would put your top level "mymodules" _inside_ the "Desktop/mymodules" folder that already exists, producing the structure you currently have. Cheers, Cameron Simpson From steve+comp.lang.python at pearwood.info Sat Jun 9 05:54:13 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 9 Jun 2018 09:54:13 +0000 (UTC) Subject: Inverting a conditional function Message-ID: I frequently have a function which tests some condition, returning True or False, and want a function which reverses the condition. If all I wanted was the result of calling the function, I could say not condition(x) and be done with it, but I want a new function. I've been doing this: lambda arg: not condition(arg) which is okay, but its a bit long and adds the cost of an extra function call. Is there a better way? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From Richard at Damon-Family.org Sat Jun 9 06:06:04 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 9 Jun 2018 06:06:04 -0400 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> Message-ID: On 6/9/18 1:07 AM, Gregory Ewing wrote: > Chris Angelico wrote: >> Open source would not exist without copyright,because it is >> copyright law that gives license terms their meaning. > > That statement doesn't make any sense. If there were no > copyright laws, there would be no need for licences to > distribute software. > > You seem to be saying that nobody would ever release the > source of their software unless they could impose some > kind of restrictions on what people could do with it. > > But I don't think that's true at all. Open sharing of > software was the *default* before people got the idea > of applying copyright laws to it. If there were no > copyright laws, people who wanted to share their source > would still do so, and people who wanted to keep it a > trade secret would still do so. The only difference is > there would be less lawyers making money out of it. Copyright law is not what makes something 'closed source' in the eyes of the Open Source community. For example, Microsoft doesn't use Copyright to keep the source code for Windows secret, they just don't provide it. The thing that gives the Open Source licenses the power to force people to share the source code is that their IS a copyright on the source code and the usage license on it demands revealing modifications to others. If software providers could no longer depend on Copyright law, then you would see much more use of the hobbling copy protection technologies, and automatically enforced licensing methods. That, and a lot less software produced. -- Richard Damon From marko at pacujo.net Sat Jun 9 06:48:17 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 09 Jun 2018 13:48:17 +0300 Subject: Stefan's headers [was:Names and identifiers] References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> Message-ID: <874licutfy.fsf@elektro.pacujo.net> Richard Damon : > Copyright law is not what makes something 'closed source' in the eyes > of the Open Source community. For example, Microsoft doesn't use > Copyright to keep the source code for Windows secret, they just don't > provide it. It would leak out with developers who move to new jobs. And that would be good. > The thing that gives the Open Source licenses the power to force > people to share the source code is that their IS a copyright on the > source code and the usage license on it demands revealing > modifications to others. Most open-source licenses don't have that stipulation: In particular, CPython's license doesn't seem to require it: > If software providers could no longer depend on Copyright law, then > you would see much more use of the hobbling copy protection > technologies, and automatically enforced licensing methods. That, and > a lot less software produced. The consequences would be hard to estimate precisely. You don't need so many reimplementations of ideas if good ideas could be copied freely. I believe the society would gain faster progress of software solutions with the copyright restrictions gone. Marko From duncan at invalid.invalid Sat Jun 9 11:20:42 2018 From: duncan at invalid.invalid (duncan smith) Date: Sat, 9 Jun 2018 16:20:42 +0100 Subject: plotly / dash export data Message-ID: Hello, I have been trying to work out how to export data from a dash application. I know little about html or javascript. I can upload data into a table as per the example at https://github.com/plotly/dash-core-components/pull/73. I can edit the data in the table. But I can't find a way of exporting the edited data. (Saving the data to file after each edit and providing a link to said file might do it, but doesn't seem particularly clean). The data are model parameters, and the user can edit these and run simulations. It seems unreasonable to allow the user to experiment with different parameters, but not allow them to export the parameters for future use. Hopefully someone with better knowledge of dash (or html) can point me in the right direction. TIA. Duncan From tjreedy at udel.edu Sat Jun 9 12:06:42 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 9 Jun 2018 12:06:42 -0400 Subject: Inverting a conditional function In-Reply-To: References: Message-ID: On 6/9/2018 5:54 AM, Steven D'Aprano wrote: > I frequently have a function which tests some condition, returning True > or False, and want a function which reverses the condition. > > If all I wanted was the result of calling the function, I could say > > not condition(x) > > and be done with it, but I want a new function. I've been doing this: > > lambda arg: not condition(arg) def not_condition(arg): return not condition(arg) > > which is okay, but its a bit long and adds the cost of an extra function > call. Is there a better way? If you have access to source, replace each 'return e' with 'return not e' or perhaps 'return not (e)'. Don't replace 'not not e' unless you know 'e' evaluates to False or True. Otherwise, disassemble the function, replace code for return with code for invert, return. Assemble new function. Better? -- Terry Jan Reedy From deonglweb at gmail.com Sat Jun 9 12:12:43 2018 From: deonglweb at gmail.com (deon gordon) Date: Sat, 9 Jun 2018 18:12:43 +0200 Subject: Python System Error Message-ID: Greetings, confirm 1b131414ca21eea0843469f76454389f1e9ceebe I am using Window 7 Professional (32bit). I downloaded and installed python-3.6.5.exe and have an error after several attempts to install and repair. Python-system error api-mis-win-crt-runtime-l1-1-0.dll is missing from your computer Regards Deon Laubscher From tjreedy at udel.edu Sat Jun 9 12:46:44 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 9 Jun 2018 12:46:44 -0400 Subject: Obsolete method in the html module In-Reply-To: References: Message-ID: On 6/9/2018 4:07 AM, Vincent Vande Vyvre wrote: > In Python-3.7.0b5 we can find at the end of html/parser.py: > > ??? def unescape(self, s): > ??????? warnings.warn('The unescape method is deprecated and will be > removed ' > ????????????????????? 'in 3.5, use html.unescape() instead.', > ????????????????????? DeprecationWarning, stacklevel=2) > ??????? return unescape(s) https://bugs.python.org/issue33813 -- Terry Jan Reedy From Richard at Damon-Family.org Sat Jun 9 13:02:30 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 9 Jun 2018 13:02:30 -0400 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: <874licutfy.fsf@elektro.pacujo.net> References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: On 6/9/18 6:48 AM, Marko Rauhamaa wrote: > Richard Damon : >> Copyright law is not what makes something 'closed source' in the eyes >> of the Open Source community. For example, Microsoft doesn't use >> Copyright to keep the source code for Windows secret, they just don't >> provide it. > It would leak out with developers who move to new jobs. And that would > be good. If you plan on eliminating not only copyright, but trade secret and non-disclosure laws, sure, maybe. Yes probably some limited stuff would leak. More likely the work conditions at those places would get stricter, and likely would make it hard for someone inside to 'make a copy'. More importantly, if we didn't have copyright laws, we likely didn't get windows or even Dos anywhere near as early, and maybe even not home computers. >> The thing that gives the Open Source licenses the power to force >> people to share the source code is that their IS a copyright on the >> source code and the usage license on it demands revealing >> modifications to others. > Most open-source licenses don't have that stipulation: > > ce_software_licenses> > > In particular, CPython's license doesn't seem to require it: > > > >> If software providers could no longer depend on Copyright law, then >> you would see much more use of the hobbling copy protection >> technologies, and automatically enforced licensing methods. That, and >> a lot less software produced. > The consequences would be hard to estimate precisely. You don't need so > many reimplementations of ideas if good ideas could be copied freely. I > believe the society would gain faster progress of software solutions > with the copyright restrictions gone. > > > Marko I've had this discussion before, and I think you underestimate how much innovation would be inhibited it companies were restricted from being able to make a profit off the development of intellectual property. Our current computing environment grew out of the ability for companies to make a profit out of the sales of software. Without the base of commercial software, the demand for inexpensive hardware to run it on wouldn't be there, and computers then would be expensive, and a limited base to promote the development of the Free Software movement. -- Richard Damon From breamoreboy at gmail.com Sat Jun 9 13:31:30 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Sat, 9 Jun 2018 18:31:30 +0100 Subject: Python System Error In-Reply-To: References: Message-ID: On 09/06/18 17:12, deon gordon wrote: > Greetings, > > confirm 1b131414ca21eea0843469f76454389f1e9ceebe > > I am using Window 7 Professional (32bit). > > I downloaded and installed python-3.6.5.exe and have an error after several > attempts to install and repair. > > Python-system error api-mis-win-crt-runtime-l1-1-0.dll is missing from your > computer > > > Regards > > > Deon Laubscher > You need this https://support.microsoft.com/en-us/help/2999226/update-for-universal-c-runtime-in-windows little beastie :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From brgrt2 at gmail.com Sat Jun 9 13:48:09 2018 From: brgrt2 at gmail.com (T Berger) Date: Sat, 9 Jun 2018 10:48:09 -0700 (PDT) Subject: Problem finding my folder via terminal In-Reply-To: References: <201806090237.39143.gheskett@shentel.net> <20180609090459.GA17745@cskk.homeip.net> Message-ID: <9ce4d1f9-8d5c-40be-b4dc-ea338a2d52ad@googlegroups.com> On Saturday, June 9, 2018 at 5:05:25 AM UTC-4, Cameron Simpson wrote: > On 09Jun2018 02:37, Gene Heskett wrote: > >On Saturday 09 June 2018 01:36:17 Tamara Berger wrote: > >> Re inline style: When I hit reply, this is the window I get. > > The python-list server strips attachments, so I didn't get the screenshot you > may have attached. However... > > >> I don't > >> get my previous email with the carets appended to the beginning of the > >> line. > > I've just gone to my GMail and tried a reply. In my reply compose window there > is a little button at the bottom left with three dots in it, thus: "[...]", > kind of. Click that, it expands to the prior quoted text. Then you can trim it > and insert your responses. > > >> Before I look at the rest of your email, I'd like for you to explain > >> how there is a mymodule folder nested within another mymodule folder. > >> I don't see this second folder in Finder, and I definitely didn't > >> create it. > > > >Finder, if thats what you are using, I am not familiar with it, is > >probably showing you that which it has cached, before that folder was > >created. Back out one layer and go back in so it actually reads a fresh > >copy of that directory(folder). > > The Finder uses MacOS' equivalent of Linux' inotify: its folder views are > "live" and update as soon as anything changes. > > Tamara, there are things the Finder won't show, particularly "hidden" files, > which is an attribute you can assign to folders. Maybe that is what happened. > I've got no concrete explaination, and I can't inspect your machine directly. > Also, how sure are you that the "mymodules" in the Finder is the upper one and > not the lower one? Just guessing here. > > My opinion is that you did create it, but not realised how that happened. > > All you'd need to do is something like this: > > cd Desktop > mkdir mymodules > cd mymodules > ... get distracted, do something else, come back much later ... > mkdir mymodules > cd mymodules > ... proceed to make the setup.py and so forth ... > > i.e. just do it twice. Alternatively, and this is a common one, you got a > template archive, such as a zip file, containing an "empty" module to get you > started. And did something like this: > > cd Desktop > mkdir mymodules > cd mymodules > unzip the-empty-module-template.zip > > If the zip file itself also contained a top level "mymodules" folder in it, it > will have made the second "mymodules" inside the one you made. > > Most archive files are set up to have their entire contents inside a single top > folder, so this scenario isn't all that unlikely. > > A third possibility is that you made a mymodules somewhere else (such as in > your top level home directory), and later decided to put it on your Desktop to > make it easy to find/access. So you might have decided to "mv" your "mymodules" > folder into the Desktop like this: > > mv mymodules Desktop/mymodules > > which is fine. But mv has some interesting behaviour. If "mymodules" didn't > exist in Desktop, then youre "mymodules" will get moved into the Desktop. > However, if mv's final argument is an _existing_ directory, mv puts things > inside it. So if you went: > > mkdir Desktop/mymodules > mv mymodules Desktop/mymodules > > then mv would put your top level "mymodules" _inside_ the "Desktop/mymodules" > folder that already exists, producing the structure you currently have. > > Cheers, > Cameron Simpson Hi Cameron, I want to read your last two emails in the evening when I have more time to digest the information, but I have a quick question now. I made the correction you suggested to mymodule and went on to create a source distribution file. Then I got stuck again when trying to install my module into site-packages. I think I got a permission error. How do I fix this? Here is the coding from the shell: Last login: Sat Jun 9 13:16:15 on ttys000 192:~ TamaraB$ cd Desktop/mymodules/dict -bash: cd: Desktop/mymodules/dict: No such file or directory 192:~ TamaraB$ cd Desktop/mymodules/dist 192:dist TamaraB$ sudo python3 -m pop install vsearch-1.0.tar.gz Password: There is a symbol of a key after the word "Password." Thanks, Tamara From tmrsg11 at gmail.com Sat Jun 9 14:24:57 2018 From: tmrsg11 at gmail.com (C W) Date: Sat, 9 Jun 2018 14:24:57 -0400 Subject: In Pandas, can you do groupby in on two different datasets? Message-ID: Dear all, I want find the average ratings of movies by movieId. Below is ratings.head() of the dataset. > ratings.head() userId movieId rating timestamp parsed_time 0 1 2 3.5 1112486027 2005-04-02 23:53:47 1 1 29 3.5 1112484676 2005-04-02 23:31:16 2 1 32 3.5 1112484819 2005-04-02 23:33:39 3 1 47 3.5 1112484727 2005-04-02 23:32:07 4 1 50 3.5 1112484580 2005-04-02 23:29:40 I'm trying two methods: Method 1 (makes sense) > ratings[['movieId', 'rating']].groupby('rating').mean() This returns dataframe, it's the most common. Method 2 (confusing) > ratings.rating.groupby(ratings.movieId).mean() movieId 1 3.921240 2 3.211977 3 3.151040 4 2.861393 5 3.064592 Name: rating, dtype: float64 What going on in method 2? It's calling ratings dataset twice. First in ratings.rating, it restricts the working dataset to only rating column. Then, it groups by ratings.movieId, but how does it know there is movieId. Didn't we just restrict the data to rating column only? Thanks in advance! From marko at pacujo.net Sat Jun 9 15:06:35 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 09 Jun 2018 22:06:35 +0300 Subject: Stefan's headers [was:Names and identifiers] References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: <87vaaru6dg.fsf@elektro.pacujo.net> Richard Damon : > On 6/9/18 6:48 AM, Marko Rauhamaa wrote: >> It would leak out with developers who move to new jobs. And that would >> be good. > > If you plan on eliminating not only copyright, but trade secret and > non-disclosure laws, sure, maybe. Yes probably some limited stuff > would leak. More likely the work conditions at those places would get > stricter, and likely would make it hard for someone inside to 'make a > copy'. Copying some general-purpose frameworks and libraries is not a trade secret any more than, say, clever HR practices. > More importantly, if we didn't have copyright laws, we likely didn't > get windows or even Dos anywhere near as early, and maybe even not > home computers. I'm not moved. > I've had this discussion before, and I think you underestimate how > much innovation would be inhibited it companies were restricted from > being able to make a profit off the development of intellectual > property. > > Our current computing environment grew out of the ability for > companies to make a profit out of the sales of software. Without the > base of commercial software, the demand for inexpensive hardware to > run it on wouldn't be there, and computers then would be expensive, > and a limited base to promote the development of the Free Software > movement. No doubt there would be some damage -- I could lose my job, for example. I believe, though, necessary and useful things will get done even in the absense of copyright protections. I *may* mean that some of those necessary and useful things need public funding. The situation is very analogous to science, which depends on public funding and is based on open exchange of ideas and discoveries. Your belief and mine can be put to incremental tests so an immediate revolution is not needed. For example, set a fixed date when *everything* will fall into Public Domain (say, year 2100). As the date approaches, we might start seeing the good and bad societal effects of the change and can react accordingly. Maybe there *is* a need for copyright protection, and the optimal duration turns out to be five years from publication. Marko From python at mrabarnett.plus.com Sat Jun 9 15:30:17 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 9 Jun 2018 20:30:17 +0100 Subject: Problem finding my folder via terminal In-Reply-To: <9ce4d1f9-8d5c-40be-b4dc-ea338a2d52ad@googlegroups.com> References: <201806090237.39143.gheskett@shentel.net> <20180609090459.GA17745@cskk.homeip.net> <9ce4d1f9-8d5c-40be-b4dc-ea338a2d52ad@googlegroups.com> Message-ID: On 2018-06-09 18:48, T Berger wrote: [snip] > I want to read your last two emails in the evening when I have more time to digest the information, but I have a quick question now. I made the correction you suggested to mymodule and went on to create a source distribution file. Then I got stuck again when trying to install my module into site-packages. I think I got a permission error. How do I fix this? Here is the coding from the shell: > > Last login: Sat Jun 9 13:16:15 on ttys000 > 192:~ TamaraB$ cd Desktop/mymodules/dict > -bash: cd: Desktop/mymodules/dict: No such file or directory > 192:~ TamaraB$ cd Desktop/mymodules/dist > 192:dist TamaraB$ sudo python3 -m pop install vsearch-1.0.tar.gz > Password: > > There is a symbol of a key after the word "Password." > Did you really type "pop"? It looks that you're running the wrong code. The module you want is "pip". From email at paulstgeorge.com Sat Jun 9 15:31:23 2018 From: email at paulstgeorge.com (Paul St George) Date: Sat, 9 Jun 2018 21:31:23 +0200 Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: References: <64899b39-ef16-0c74-7a1b-30f49b470c3f@paulstgeorge.com> Message-ID: <77b0d1eb-8b01-e785-4951-6d0a90702ec7@paulstgeorge.com> > On 08/06/18 09:00, Paul St George wrote: >> Excellent. Now I know what to do in this instance and I understand >> the principle. >> >> I hesitantly tried this: >> >> ???? screen = pygame.display.set_mode((720,480), pygame.FULLSCREEN | >> pygame.DOUBLEBUF) >> >> Hesitantly because I expected the *bitwise or operator* (|) to work >> like a toggle, so FULLSCREEN or DOUBLEBUF. > On 08/06/2018 12:52, Rhodri James wrote: > The bitwise OR operator peforms a bitwise OR, i.e. *both* flags get set. > >> No errors were reported, but how would I check that DOUBLEBUF had >> been set? Is there a general rule, such as replace 'set_something' >> with 'get_something'? > > There's documentation.? The link Chris gave you for > pygame.display.set_mode() tells you that you get a Surface out of it. > Reaching for the docs for that, this leaps out: > > https://www.pygame.org/docs/ref/surface.html#pygame.Surface.get_flags > > So... ??? print pygame.display.get_surface() gives and ??? print screen.get_flags() gives -2147483648 The lists of flags at and has nothing remotely like -2147483648. I would expect something more like 0x40000000 Am I using the wrong code to determine whether I have successfully set DOUBLEBUF with ??? screen = pygame.display.set_mode((720,480), pygame.FULLSCREEN | pygame.DOUBLEBUF) AND What does -2147483648 tell me? Does this number need converting? > > > From e+python-list at kellett.im Sat Jun 9 15:53:40 2018 From: e+python-list at kellett.im (Ed Kellett) Date: Sat, 9 Jun 2018 20:53:40 +0100 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> <87efhi50wk.fsf@elektro.pacujo.net> Message-ID: <727df485-e243-4f72-bf69-b9bc86b08d01@kellett.im> On 2018-06-08 03:42, Chris Angelico wrote: > Apart from the one odd bug with SimpleHTTPServer not properly sending > back 500s, I very much doubt that the original concern - namely that > os.path.exists() and os.stat() raise ValueError if therels a %00 in > the URL - can be abused effectively. Dismissing HTTP 500s as "not a vulnerability" sounds reasonable enough to me. But you're assuming that all other expressions of this bug in applications will be at least as benign. I'm not sure that that's warranted. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From Richard at Damon-Family.org Sat Jun 9 16:03:46 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 9 Jun 2018 16:03:46 -0400 Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: <77b0d1eb-8b01-e785-4951-6d0a90702ec7@paulstgeorge.com> References: <64899b39-ef16-0c74-7a1b-30f49b470c3f@paulstgeorge.com> <77b0d1eb-8b01-e785-4951-6d0a90702ec7@paulstgeorge.com> Message-ID: <5a3c7858-79c0-e1d0-af26-bd9530055d5c@Damon-Family.org> On 6/9/18 3:31 PM, Paul St George wrote: > So... > > ??? print pygame.display.get_surface() > gives > > > and > ??? print screen.get_flags() > gives > -2147483648 > > The lists of flags at > > and > > > has nothing remotely like -2147483648. I would expect something more > like 0x40000000 > > Am I using the wrong code to determine whether I have successfully set > DOUBLEBUF with > > ??? screen = pygame.display.set_mode((720,480), pygame.FULLSCREEN | > pygame.DOUBLEBUF) > > AND > > What does -2147483648 tell me? Does this number need converting? That number is printed in Decimal, the listing gives it in hex. If you convert the number to hex you get 0x80000000 -- Richard Damon From breamoreboy at gmail.com Sat Jun 9 16:04:10 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Sat, 9 Jun 2018 21:04:10 +0100 Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: <77b0d1eb-8b01-e785-4951-6d0a90702ec7@paulstgeorge.com> References: <64899b39-ef16-0c74-7a1b-30f49b470c3f@paulstgeorge.com> <77b0d1eb-8b01-e785-4951-6d0a90702ec7@paulstgeorge.com> Message-ID: On 09/06/18 20:31, Paul St George wrote: > > ??? print pygame.display.get_surface() > gives > > > and > ??? print screen.get_flags() > gives > -2147483648 > > The lists of flags at > > and > > > has nothing remotely like -2147483648. I would expect something more > like 0x40000000 > > Am I using the wrong code to determine whether I have successfully set > DOUBLEBUF with > > ??? screen = pygame.display.set_mode((720,480), pygame.FULLSCREEN | > pygame.DOUBLEBUF) > > AND > > What does -2147483648 tell me? Does this number need converting? >> From the interactive interpreter:- >>> hex(-2147483648) '-0x80000000' >>> hex(pygame.FULLSCREEN) '-0x80000000' >>> hex(pygame.DOUBLEBUF) '0x40000000' -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From brgrt2 at gmail.com Sat Jun 9 16:43:22 2018 From: brgrt2 at gmail.com (T Berger) Date: Sat, 9 Jun 2018 13:43:22 -0700 (PDT) Subject: Problem finding my folder via terminal In-Reply-To: References: <201806090237.39143.gheskett@shentel.net> <20180609090459.GA17745@cskk.homeip.net> <9ce4d1f9-8d5c-40be-b4dc-ea338a2d52ad@googlegroups.com> Message-ID: <0712bc00-a00e-4998-af29-258312e3ea49@googlegroups.com> On Saturday, June 9, 2018 at 3:30:39 PM UTC-4, MRAB wrote: > On 2018-06-09 18:48, T Berger wrote: > [snip] > > > I want to read your last two emails in the evening when I have more time to digest the information, but I have a quick question now. I made the correction you suggested to mymodule and went on to create a source distribution file. Then I got stuck again when trying to install my module into site-packages. I think I got a permission error. How do I fix this? Here is the coding from the shell: > > > > Last login: Sat Jun 9 13:16:15 on ttys000 > > 192:~ TamaraB$ cd Desktop/mymodules/dict > > -bash: cd: Desktop/mymodules/dict: No such file or directory > > 192:~ TamaraB$ cd Desktop/mymodules/dist > > 192:dist TamaraB$ sudo python3 -m pop install vsearch-1.0.tar.gz > > Password: > > > > There is a symbol of a key after the word "Password." > > > Did you really type "pop"? It looks that you're running the wrong code. > The module you want is "pip". Hi Cameron, Sorry. That's terrible. But I did run the code a number of times correctly. I just did it again and got the same key icon: Last login: Sat Jun 9 13:26:14 on ttys000 192:~ TamaraB$ cd Desktop/mymodules/dist 192:dist TamaraB$ dist TamaraB$ sudo python3 -m pip install vsearch-1.0.tar.gz -bash: dist: command not found 192:dist TamaraB$ sudo python3 -m pip install vsearch-1.0.tar.gz Password: What next? Thanks, Tamara From Richard at Damon-Family.org Sat Jun 9 16:44:30 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 9 Jun 2018 16:44:30 -0400 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: <87vaaru6dg.fsf@elektro.pacujo.net> References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> <87vaaru6dg.fsf@elektro.pacujo.net> Message-ID: On 6/9/18 3:06 PM, Marko Rauhamaa wrote: > Richard Damon : > >> On 6/9/18 6:48 AM, Marko Rauhamaa wrote: >>> It would leak out with developers who move to new jobs. And that would >>> be good. >> >> If you plan on eliminating not only copyright, but trade secret and >> non-disclosure laws, sure, maybe. Yes probably some limited stuff >> would leak. More likely the work conditions at those places would get >> stricter, and likely would make it hard for someone inside to 'make a >> copy'. > > Copying some general-purpose frameworks and libraries is not a trade > secret any more than, say, clever HR practices. > >> More importantly, if we didn't have copyright laws, we likely didn't >> get windows or even Dos anywhere near as early, and maybe even not >> home computers. > > I'm not moved. > >> I've had this discussion before, and I think you underestimate how >> much innovation would be inhibited it companies were restricted from >> being able to make a profit off the development of intellectual >> property. >> >> Our current computing environment grew out of the ability for >> companies to make a profit out of the sales of software. Without the >> base of commercial software, the demand for inexpensive hardware to >> run it on wouldn't be there, and computers then would be expensive, >> and a limited base to promote the development of the Free Software >> movement. > > No doubt there would be some damage -- I could lose my job, for example. > I believe, though, necessary and useful things will get done even in the > absense of copyright protections. I *may* mean that some of those > necessary and useful things need public funding. > > The situation is very analogous to science, which depends on public > funding and is based on open exchange of ideas and discoveries. > > Your belief and mine can be put to incremental tests so an immediate > revolution is not needed. For example, set a fixed date when > *everything* will fall into Public Domain (say, year 2100). As the date > approaches, we might start seeing the good and bad societal effects of > the change and can react accordingly. Maybe there *is* a need for > copyright protection, and the optimal duration turns out to be five > years from publication. > > > Marko > In the comparison to science, I would say that my guess is that a LOT more science is being done by private companies being encouraged by the promise of Patent protection than by the support of the general public. Admittedly, there are likely significant differences in focus of these aspects. I will agree that the current rules may have been pushed out of balance by greed. Not sure if 5 years for copyright is long enough, but the life+70 that the House of the Mouse got is too long. From lee at lcongdon.com Sat Jun 9 17:01:10 2018 From: lee at lcongdon.com (Lee Congdon) Date: Sat, 9 Jun 2018 17:01:10 -0400 Subject: Problem finding my folder via terminal In-Reply-To: <0712bc00-a00e-4998-af29-258312e3ea49@googlegroups.com> References: <201806090237.39143.gheskett@shentel.net> <20180609090459.GA17745@cskk.homeip.net> <9ce4d1f9-8d5c-40be-b4dc-ea338a2d52ad@googlegroups.com> <0712bc00-a00e-4998-af29-258312e3ea49@googlegroups.com> Message-ID: On Sat, Jun 9, 2018 at 4:45 PM T Berger wrote: > [snip] > Sorry. That's terrible. But I did run the code a number of times > correctly. I just did it again and got the same key icon: > > Last login: Sat Jun 9 13:26:14 on ttys000 > 192:~ TamaraB$ cd Desktop/mymodules/dist > 192:dist TamaraB$ dist TamaraB$ sudo python3 -m pip install > vsearch-1.0.tar.gz > -bash: dist: command not found > 192:dist TamaraB$ sudo python3 -m pip install vsearch-1.0.tar.gz > Password: > > What next? > > Thanks, > > Tamara > -- > https://mail.python.org/mailman/listinfo/python-list > Assuming your account has administrator rights on your Mac, enter the password you use to sign on. If not, or you don't use a password to sign on, see https://support.apple.com/en-us/HT202035 -- Lee From sjeik_appie at hotmail.com Sat Jun 9 17:43:52 2018 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Sat, 9 Jun 2018 21:43:52 +0000 Subject: user defined modules In-Reply-To: Message-ID: On 5 Jun 2018 09:32, Steven D'Aprano wrote: On Mon, 04 Jun 2018 20:13:32 -0700, Sharan Basappa wrote: > Is there a specific location where user defined modules need to be kept? > If not, do we need to specify search location so that Python interpreter > can find it? Python modules used as scripts can be run from anywhere, by pointing the interpreter at the script: python /path/to/my/script.py But Python modules uses as libraries, to be imported by other modules, have to be on the Python search path. You can add extra paths to the Python search path from the shell by setting the environment variable PYTHONPATH to a colon-separated list of paths. On Linux, I do this in my .bashrc config file: export PYTHONPATH="paths:to:add" In the Python interpreter, you can query and modify the search path by importing sys and looking at sys.path. (But you should not do so unless you really know what you are doing.) The default search path is set by the site module: https://docs.python.org/3/library/site.html but again, you should not mess with this unless you know what you are doing. There are some per-user directories which are automatically added to the search path. I can't find the existing documentation for them, but a good place to start is the PEP that introduced the feature: https://www.python.org/dev/peps/pep-0370/ Apart from setting the PYTHONPATH environment variable, the best way to add extra paths to is to install a .pth file. If you run both Python 2 and 3, than .pth might be a better choice. With Pythonpath, you run the risk of e.g. importing python3-incompatible code. From cs at cskk.id.au Sat Jun 9 17:49:12 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 10 Jun 2018 07:49:12 +1000 Subject: Problem finding my folder via terminal In-Reply-To: <9ce4d1f9-8d5c-40be-b4dc-ea338a2d52ad@googlegroups.com> References: <9ce4d1f9-8d5c-40be-b4dc-ea338a2d52ad@googlegroups.com> Message-ID: <20180609214912.GA93471@cskk.homeip.net> On 09Jun2018 10:48, Tamara Berger wrote: >I want to read your last two emails in the evening when I have more time to >digest the information, but I have a quick question now. I made the correction >you suggested to mymodule and went on to create a source distribution file. >Then I got stuck again when trying to install my module into site-packages. I >think I got a permission error. How do I fix this? Here is the coding from the >shell: > >Last login: Sat Jun 9 13:16:15 on ttys000 >192:~ TamaraB$ cd Desktop/mymodules/dict >-bash: cd: Desktop/mymodules/dict: No such file or directory I think this should be "dist", not "dict". >192:~ TamaraB$ cd Desktop/mymodules/dist Ah, yes. Ok then. >192:dist TamaraB$ sudo python3 -m pop install vsearch-1.0.tar.gz >Password: > >There is a symbol of a key after the word "Password." There are a few issue here. First, it should be "pip", not "pop". Second, this is using the "sudo" command to run "python3 -m pip install vsearch-1.0.tar.gz" as root, the system administrator account. "sudo" is asking you for your password before proceeding. Might I suggest that you don't do this step? The reason here is that it will install your "vsearch" module into the _system_ site-packages area. That area is under the control of the OS vendor (Apple in this case) and they may legitimately put something else of the same name there, or have already done so. In the former case they're land on your module and in the latter case you will be destroying the vendor supplied module. As a rule of thumb it is best to avoid putting stuff in the vendor controlled places - it leads to maintenance problems and can lead to unexpected behaviour. Instead, use pip's "--user" option, thus: python3 -m pip install --user vsearch-1.0.tar.gz Note: there is _no_ "sudo" command there. This command runs as you, not root, and installs in your home directory in an area for user supplied packages. Cheers, Cameron Simpson From marko at pacujo.net Sat Jun 9 18:15:16 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Jun 2018 01:15:16 +0300 Subject: Stefan's headers [was:Names and identifiers] References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> <87vaaru6dg.fsf@elektro.pacujo.net> Message-ID: <87po0ztxmz.fsf@elektro.pacujo.net> Richard Damon : > In the comparison to science, I would say that my guess is that a LOT > more science is being done by private companies being encouraged by > the promise of Patent protection than by the support of the general > public. Admittedly, there are likely significant differences in focus > of these aspects. "Proprietary science" seems like an oxymoron to me. At best, profit-seeking research can produce scientific discoveries as a side-effect. Marko From steve+comp.lang.python at pearwood.info Sat Jun 9 20:33:06 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jun 2018 00:33:06 +0000 (UTC) Subject: Stefan's headers [was:Names and identifiers] References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: On Sat, 09 Jun 2018 13:48:17 +0300, Marko Rauhamaa wrote: > Richard Damon : >> Copyright law is not what makes something 'closed source' in the eyes >> of the Open Source community. For example, Microsoft doesn't use >> Copyright to keep the source code for Windows secret, they just don't >> provide it. > > It would leak out with developers who move to new jobs. And that would > be good. Are you proposing to abolish trade secrets and NDAs as well? Good luck with that. Do your customers and clients know your opinion on releasing code you write for them to the rest of the world? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From gheskett at shentel.net Sat Jun 9 21:37:23 2018 From: gheskett at shentel.net (Gene Heskett) Date: Sat, 9 Jun 2018 21:37:23 -0400 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <874licutfy.fsf@elektro.pacujo.net> Message-ID: <201806092137.23404.gheskett@shentel.net> On Saturday 09 June 2018 20:33:06 Steven D'Aprano wrote: > On Sat, 09 Jun 2018 13:48:17 +0300, Marko Rauhamaa wrote: > > Richard Damon : > >> Copyright law is not what makes something 'closed source' in the > >> eyes of the Open Source community. For example, Microsoft doesn't > >> use Copyright to keep the source code for Windows secret, they just > >> don't provide it. > > > > It would leak out with developers who move to new jobs. And that > > would be good. > > Are you proposing to abolish trade secrets and NDAs as well? Good luck > with that. > > Do your customers and clients know your opinion on releasing code you > write for them to the rest of the world? > If they did, I expect it would cut the length of his ladder to where he eats off the hog by serious amounts. While we may voice our opinions of the current copyright laws, they are to the advantage of companies who would have little or no reticence about silenceing dissenting opinions that might fall on the lawmakers ears. Those of you working for the man ought not to forget that. -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From steve+comp.lang.python at pearwood.info Sat Jun 9 21:52:14 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jun 2018 01:52:14 +0000 (UTC) Subject: Stefan's headers [was:Names and identifiers] References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: On Sat, 09 Jun 2018 13:02:30 -0400, Richard Damon wrote: > On 6/9/18 6:48 AM, Marko Rauhamaa wrote: >> Richard Damon : >>> Copyright law is not what makes something 'closed source' in the eyes >>> of the Open Source community. For example, Microsoft doesn't use >>> Copyright to keep the source code for Windows secret, they just don't >>> provide it. >> It would leak out with developers who move to new jobs. And that would >> be good. > > If you plan on eliminating not only copyright, but trade secret and > non-disclosure laws, sure, maybe. Yes probably some limited stuff would > leak. More likely the work conditions at those places would get > stricter, and likely would make it hard for someone inside to 'make a > copy'. > > More importantly, if we didn't have copyright laws, we likely didn't get > windows or even Dos anywhere near as early, and maybe even not home > computers. I think that Marko is being awfully naive about copyright, but I think that your claim is a gross misrepresentation of the early history of computing. The money was in selling the hardware, especially in the home computer market, not the software. Things would have been ... interesting ... if (let's say) IBM had been free just take CP/M and use that, but don't underestimate the benefits of dealing with the people who actually wrote the software and understand it, even if you could just take the software and work on it yourself. (Richard Stallman makes a pretty penny consulting for GNU software.) Another factor you failed to account for is that without piracy (in other words, despite copyright, not because of copyright) Microsoft's software would be unlikely to hold its preeminent position it does today. From Word and especially Excel, Windows, MS BASIC and DOS, Microsoft captured the market *because of* copyright infringement, not in spite of it. The bottom line is, the idea that copyright is responsible for innovation is more a matter of faith than economic reality. Economists who study this sort of thing argue back and forth whether the economic cost of copyright outweighs the benefits, but one way or the other it is hardly a clear cut win for copyright as conventional wisdom says. I think the wise thing is to have *just enough* copyright but not too much. Zero is not enough, but what we have now is too much. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sat Jun 9 22:08:36 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jun 2018 12:08:36 +1000 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: On Sun, Jun 10, 2018 at 11:52 AM, Steven D'Aprano wrote: > I think the wise thing is to have *just enough* copyright but not too > much. Zero is not enough, but what we have now is too much. > Agreed. If copyright lapsed by default after ten years but could be extended through paid registration to a hard limit of fifty, I think a lot of things would be better off. Numbers could be tweaked but something along those lines. ChrisA From brgrt2 at gmail.com Sat Jun 9 22:50:06 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Sat, 9 Jun 2018 22:50:06 -0400 Subject: Problem finding my folder via terminal In-Reply-To: <20180609090459.GA17745@cskk.homeip.net> References: <201806090237.39143.gheskett@shentel.net> <20180609090459.GA17745@cskk.homeip.net> Message-ID: On Sat, Jun 9, 2018 at 5:05 AM Cameron Simpson wrote: > > A third possibility is that you made a mymodules somewhere else (such as in > your top level home directory), and later decided to put it on your Desktop to > make it easy to find/access. I did save it in My Documents first and then moved it to my desktop. But I did not write code. I just dragged and dropped. >So you might have decided to "mv" your "mymodules" > folder into the Desktop like this: > > mv mymodules Desktop/mymodules > > which is fine. But mv has some interesting behaviour. If "mymodules" didn't > exist in Desktop, then youre "mymodules" will get moved into the Desktop. > However, if mv's final argument is an _existing_ directory, mv puts things > inside it. So if you went: > > mkdir Desktop/mymodules > mv mymodules Desktop/mymodules > > then mv would put your top level "mymodules" _inside_ the "Desktop/mymodules" > folder that already exists, producing the structure you currently have. I didn't do any of this. Could dragging and dropping have created the duplicate folder? Thanks, Tamara From greg.ewing at canterbury.ac.nz Sat Jun 9 22:54:58 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 10 Jun 2018 14:54:58 +1200 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> Message-ID: Richard Damon wrote: > If software providers could no longer depend on Copyright law, then you > would see much more use of the hobbling copy protection technologies, Maybe so, but that has nothing to do with open source, since, as you say, the sort of people that don't want their binaries copied don't release their source anyway. -- Greg From brgrt2 at gmail.com Sat Jun 9 22:57:07 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Sat, 9 Jun 2018 22:57:07 -0400 Subject: Problem finding my folder via terminal In-Reply-To: <20180609214912.GA93471@cskk.homeip.net> References: <9ce4d1f9-8d5c-40be-b4dc-ea338a2d52ad@googlegroups.com> <20180609214912.GA93471@cskk.homeip.net> Message-ID: Hi Cameron, Thanks for the help. I was just following the coding in the workbook when I inserted sudo. What you said about it makes a lot of sense. Again, thanks for all your help. Tamara On Sat, Jun 9, 2018 at 5:49 PM Cameron Simpson wrote: > > On 09Jun2018 10:48, Tamara Berger wrote: > >I want to read your last two emails in the evening when I have more time to > >digest the information, but I have a quick question now. I made the correction > >you suggested to mymodule and went on to create a source distribution file. > >Then I got stuck again when trying to install my module into site-packages. I > >think I got a permission error. How do I fix this? Here is the coding from the > >shell: > > > >Last login: Sat Jun 9 13:16:15 on ttys000 > >192:~ TamaraB$ cd Desktop/mymodules/dict > >-bash: cd: Desktop/mymodules/dict: No such file or directory > > I think this should be "dist", not "dict". > > >192:~ TamaraB$ cd Desktop/mymodules/dist > > Ah, yes. Ok then. > > >192:dist TamaraB$ sudo python3 -m pop install vsearch-1.0.tar.gz > >Password: > > > >There is a symbol of a key after the word "Password." > > There are a few issue here. > > First, it should be "pip", not "pop". > > Second, this is using the "sudo" command to run "python3 -m pip install > vsearch-1.0.tar.gz" as root, the system administrator account. "sudo" is asking > you for your password before proceeding. > > Might I suggest that you don't do this step? > > The reason here is that it will install your "vsearch" module into the _system_ > site-packages area. That area is under the control of the OS vendor (Apple in > this case) and they may legitimately put something else of the same name there, > or have already done so. In the former case they're land on your module and in > the latter case you will be destroying the vendor supplied module. > > As a rule of thumb it is best to avoid putting stuff in the vendor controlled > places - it leads to maintenance problems and can lead to unexpected behaviour. > > Instead, use pip's "--user" option, thus: > > python3 -m pip install --user vsearch-1.0.tar.gz > > Note: there is _no_ "sudo" command there. This command runs as you, not root, > and installs in your home directory in an area for user supplied packages. > > Cheers, > Cameron Simpson From greg.ewing at canterbury.ac.nz Sat Jun 9 23:07:26 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 10 Jun 2018 15:07:26 +1200 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: Richard Damon wrote: > Our current computing environment grew out of the ability for companies > to make a profit out of the sales of software. Without the base of > commercial software, the demand for inexpensive hardware to run it on > wouldn't be there, and computers then would be expensive, and a limited > base to promote the development of the Free Software movement. That's all speculation. It's impossible to say how things would have turned out if copyrights didn't apply to software. Certainly different, but not necessarily worse. In the early days, computer manufacturers didn't worry about people copying their software, because it was no use without the hardware, and selling hardware was how they made their money. There's no reason that business model couldn't have continued into the PC era. -- Greg From cs at cskk.id.au Sat Jun 9 23:19:57 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 10 Jun 2018 13:19:57 +1000 Subject: Problem finding my folder via terminal In-Reply-To: References: Message-ID: <20180610031957.GA80808@cskk.homeip.net> On 09Jun2018 22:50, Tamara Berger wrote: >On Sat, Jun 9, 2018 at 5:05 AM Cameron Simpson wrote: >> A third possibility is that you made a mymodules somewhere else (such as in >> your top level home directory), and later decided to put it on your Desktop to >> make it easy to find/access. > >I did save it in My Documents first and then moved it to my desktop. >But I did not write code. I just dragged and dropped. > >>So you might have decided to "mv" your "mymodules" >> folder into the Desktop like this: >> >> mv mymodules Desktop/mymodules >> >> which is fine. But mv has some interesting behaviour. If "mymodules" didn't >> exist in Desktop, then youre "mymodules" will get moved into the Desktop. >> However, if mv's final argument is an _existing_ directory, mv puts things >> inside it. So if you went: >> >> mkdir Desktop/mymodules >> mv mymodules Desktop/mymodules >> >> then mv would put your top level "mymodules" _inside_ the "Desktop/mymodules" >> folder that already exists, producing the structure you currently have. > >I didn't do any of this. Could dragging and dropping have created the >duplicate folder? Maybe? If you'd premade an empty "Desktop/mymodules" first, and happened to drop the "My Documents/mymodules" onto it instead of "into" the wider "Desktop" folder. Again, just guessing. We should just get on; just pay close attention next time you move things around like this and see if anything suggests itself as an explaination. BTW, congrats: a fine inline response! Cheers, Cameron Simpson From cs at cskk.id.au Sat Jun 9 23:24:11 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 10 Jun 2018 13:24:11 +1000 Subject: Problem finding my folder via terminal In-Reply-To: References: Message-ID: <20180610032411.GA90468@cskk.homeip.net> On 09Jun2018 22:57, Tamara Berger wrote: >Thanks for the help. I was just following the coding in the workbook >when I inserted sudo. Fair enough too. But generally, in future, consider any command prefixed with sudo with some suspicion. Sometimes it is the sensible thing to do, but many many people use it as a reflex as soon as they get some kind of permission error instead of thinking though why something may be forbidden (by default). In this instance "pip" has support for "personal" python modules, and that is usually the better way to go. >What you said about it makes a lot of sense. > >Again, thanks for all your help. No worries, that's what the list is for. Cheers, Cameron Simpson From rosuav at gmail.com Sat Jun 9 23:36:34 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jun 2018 13:36:34 +1000 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: On Sun, Jun 10, 2018 at 1:07 PM, Gregory Ewing wrote: > Richard Damon wrote: >> >> Our current computing environment grew out of the ability for companies >> to make a profit out of the sales of software. Without the base of >> commercial software, the demand for inexpensive hardware to run it on >> wouldn't be there, and computers then would be expensive, and a limited >> base to promote the development of the Free Software movement. > > > That's all speculation. It's impossible to say how things > would have turned out if copyrights didn't apply to software. > Certainly different, but not necessarily worse. > > In the early days, computer manufacturers didn't worry about > people copying their software, because it was no use without > the hardware, and selling hardware was how they made their > money. There's no reason that business model couldn't have > continued into the PC era. > It would have meant that third-party software would not exist. The nearest comparison we have today is game consoles. You cannot, to my knowledge, publish a game for the PS4 or Xbox 360 without permission from Nintendo or Microsoft. Take that just a little bit further and imagine that the game console you just bought is populated SOLELY with games by the same publisher. And now imagine that this applies to every piece of computing hardware: an IBM computer runs only IBM programs, etc. Nobody can sell software without also selling hardware, which is an expensive industry to get into. Is that an improvement over what we now have? ChrisA From rosuav at gmail.com Sun Jun 10 00:55:56 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jun 2018 14:55:56 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: <727df485-e243-4f72-bf69-b9bc86b08d01@kellett.im> References: <87tvqoghhh.fsf@elektro.pacujo.net> <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> <87efhi50wk.fsf@elektro.pacujo.net> <727df485-e243-4f72-bf69-b9bc86b08d01@kellett.im> Message-ID: On Sun, Jun 10, 2018 at 5:53 AM, Ed Kellett wrote: > On 2018-06-08 03:42, Chris Angelico wrote: >> Apart from the one odd bug with SimpleHTTPServer not properly sending >> back 500s, I very much doubt that the original concern - namely that >> os.path.exists() and os.stat() raise ValueError if therels a %00 in >> the URL - can be abused effectively. > Dismissing HTTP 500s as "not a vulnerability" sounds reasonable enough > to me. But you're assuming that all other expressions of this bug in > applications will be at least as benign. I'm not sure that that's warranted. > It is an exception. There are a small number of possible results: 1) It happens in code where ValueError could otherwise happen, and the code gets confused. That's a bug, but bugs do happen. No way to predict the actual results; it's probably going to make something else go into a default mode or something. Highly unlikely for it to trigger a vulnerability, but if it does, the problem is that you have code that's catching an exception that it shouldn't be. 2) It happens in code where ValueError is not expected, and is handled as an unexpected exception. ALL end-user-facing code should have a means of coping with exceptions (web servers should toss back a 500, etc). If it doesn't, then *that* is the vulnerability, not the ValueError itself; there are many MANY ways for Python code to unexpectedly raise exceptions. Either way, this exception isn't itself a problem; but it might reveal a different problem. For instance, an end-user-facing app that has no protective exception handler might be induced to terminate in this way, which is a DOS; but the problem isn't os.path.exists raising ValueError, the problem is an unexpected exception causing termination. It's important to pin down the true cause of the problem, and not blame something for doing the proper Pythonic thing. Python is not Go; exceptions exist to be used. The advantage of Go is that you never get unexpected exceptions... instead, you just get unexpected incorrect behaviour if you fail to check the return value of a function and just assume that it did its job. Exceptions don't remove all responsibility from you, but they DO make it a lot easier to handle them coherently. ChrisA From marko at pacujo.net Sun Jun 10 05:06:00 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Jun 2018 12:06:00 +0300 Subject: Why exception from os.path.exists()? References: <87tvqoghhh.fsf@elektro.pacujo.net> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> <87efhi50wk.fsf@elektro.pacujo.net> <727df485-e243-4f72-bf69-b9bc86b08d01@kellett.im> Message-ID: <87in6rt3if.fsf@elektro.pacujo.net> Chris Angelico : > It's important to pin down the true cause of the problem, and not > blame something for doing the proper Pythonic thing. So could you tell me what the proper Pythonic fix for the example server in Python's documentation would be? Here's the code in question: ======================================================================== import http.server import socketserver PORT = 8000 Handler = http.server.SimpleHTTPRequestHandler with socketserver.TCPServer(("", PORT), Handler) as httpd: print("serving at port", PORT) httpd.serve_forever() ======================================================================== BTW, the proper response would be a 404. 500 means: "There's a bug in my code". Marko From rosuav at gmail.com Sun Jun 10 05:22:14 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jun 2018 19:22:14 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: <87in6rt3if.fsf@elektro.pacujo.net> References: <87tvqoghhh.fsf@elektro.pacujo.net> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <87o9gn3pxk.fsf@elektro.pacujo.net> <87efhi50wk.fsf@elektro.pacujo.net> <727df485-e243-4f72-bf69-b9bc86b08d01@kellett.im> <87in6rt3if.fsf@elektro.pacujo.net> Message-ID: On Sun, Jun 10, 2018 at 7:06 PM, Marko Rauhamaa wrote: > Chris Angelico : >> It's important to pin down the true cause of the problem, and not >> blame something for doing the proper Pythonic thing. > > So could you tell me what the proper Pythonic fix for the example server > in Python's documentation would be? > > Here's the code in question: > > ======================================================================== > import http.server > import socketserver > > PORT = 8000 > > Handler = http.server.SimpleHTTPRequestHandler > > with socketserver.TCPServer(("", PORT), Handler) as httpd: > print("serving at port", PORT) > httpd.serve_forever() > ======================================================================== > > BTW, the proper response would be a 404. 500 means: "There's a bug in my > code". > The fix is a pull request against serve_forever to catch exceptions and return 500s. ChrisA From jon+usenet at unequivocal.eu Sun Jun 10 05:23:35 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sun, 10 Jun 2018 09:23:35 -0000 (UTC) Subject: Stefan's headers [was:Names and identifiers] References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> Message-ID: On 2018-06-08, Chris Angelico wrote: > Yes, this is true. It's not copyright that is unenforceable, but the > copyright notice in his message. Nobody is denying that he owns his > own words; but by posting them on a public forum, he - like everyone > else here - is implicitly granting us the right to read them. Copyright law protects copying - you don't need permission to read things, except inasmuch as the words must be copied onto your screen in order for you to see them. The question is whether he's implicitly granting the right for his posts to be copied to all the places that Usenet posts will generally get copied to when one posts them, or whether his header message explicitly disavowing such permission overrides the implicit grant. I'd suggest that since the processes he's purporting to disallow are entirely standard and automated and he knows full well they exist and that there is no mechanism by which they could be affected by his notice, the notice has little effect. > Right. Imagine if I write a poem, just like you say, and then I have > the words posted on a gigantic billboard. In small print in the bottom > corner of the billboard, I say "Copyright 2018 Chris Angelico. Taking > photographs of this billboard is forbidden.". Do I still own copyright > in the poem? Definitely. Can I stop people from (or sue people for) > taking photos of the billboard? Probably not, although that's one for > the lawyers to argue. You probably can actually. I'm not an expert but I seem to recall the rules are along the lines that you can't complain if your billboard happens to appear incidentally in the background of a photograph, but if someone takes a photo specifically *of* the billboard, your copyright is infringed. >> PS IMO copyright laws should be abolished altogether. At the very least >> one should pay for copyright protection. One ?1 for the first year, ?2 >> for the second, ?4 for the third and so on exponentially. > > Why should I have to pay money for the right to own my own creations? Because ideas are not inherently property. Why should you get to "own" a particular sequence of notes, or words, or colours? Why should the government grant you and enforce an ability to prevent other people singing those notes, or writing those words, or painting those colours? > Copyright laws and international treaties are there to protect content > creators and encourage creation. They need to have set expiration time > (IMO 50 years is long enough - not "50 years since author's death" but > 50 years since publication) after which the work becomes free to use, > but the protections are important and extremely useful. That was the original intention of copyright certainly, but I'd hope that it is relatively non-controversial that the terms limits on copyright these days have skewed the balance far too much in favour of copyright owners and away from the public. > Open source would not exist without copyright, because it is > copyright law that gives license terms their meaning That's patent nonsense. The only reason, in general, that open source even requires any licence terms because of the existence of copyright law. Sure, you couldn't do tricks like the GPL without copyright law, but then there would be much less *need* for the GPL without copyright law. From hjp-python at hjp.at Sun Jun 10 06:49:08 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 10 Jun 2018 12:49:08 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> Message-ID: <20180610104908.g6tugqmxdodnjjtm@hjp.at> On 2018-06-07 12:47:15 +0000, Steven D'Aprano wrote: > But it doesn't do that. "Pathnames cannot contain NUL" is a falsehood > that programmers wrongly believe about paths. HFS Plus and Apple File > System support NULs in paths. [...] > But in the spirit of compromise, okay, let's ignore the existence of file > systems like HFS which allow NUL. Apart from Mac users, who uses them > anyway? Let's pretend that every file system in existence, now and into > the future, will prohibit NULs in paths. Could you (or anybody else who owns a Mac) please do the following: * Create an empty directory * In this directory, create two files: * One with an embedded \0 in the file name * One with an embedded / in the file name * Compile and run this C program in the directory and post the output: #include #include #include int main(void) { DIR *dp; struct dirent *de; char *p; dp = opendir("."); while ((de = readdir(dp)) != NULL) { printf("%ld -", (long)de->d_ino); for (p = de->d_name; *p; p++) { printf(" %02x", (unsigned char)*p); } printf("\n"); } return 0; } Bonuspoints for doing this on an USB stick and then mounting the USB stick on a Linux system and posting the output there as well. I'm really curious how MacOS maps those characters in the POSIX API. 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 steve+comp.lang.python at pearwood.info Sun Jun 10 07:08:27 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jun 2018 11:08:27 +0000 (UTC) Subject: Stefan's headers [was:Names and identifiers] References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: On Sun, 10 Jun 2018 13:36:34 +1000, Chris Angelico wrote: >> That's all speculation. It's impossible to say how things would have >> turned out if copyrights didn't apply to software. Certainly different, >> but not necessarily worse. >> >> In the early days, computer manufacturers didn't worry about people >> copying their software, because it was no use without the hardware, and >> selling hardware was how they made their money. There's no reason that >> business model couldn't have continued into the PC era. >> >> > It would have meant that third-party software would not exist. Says the fellow using a free mail server (funded by advertising) on a free OS (funded by donations) on a free mailing list about a free programming language :-) Lack of copyright for software would not affect software-as-a-service like Gmail. It would not affect FOSS licences like the MIT and BSD licence, although it might declaw the GPL. It would not affect shareware and postcardware and freeware software to any appreciable amount. It would not affect the primary driver for FOSS, namely people scratching their own itch and being willing to share that solution with others. So long as people had access to interpreters and compilers and the ability to write and distribute their own code, the lack of copyright for software would only have mattered for certain economic models for software, namely the paid, closed-source, non-free commercial software market. That's an important market, but it is not all of it. The scenario you describe would require computers to be locked down behind paywalls with trusted computing hardware (a misnomer, because its about *not trusting the user* rather than trusting the computer) etc., or a wholesale move to SAS with no access to any sort of development environment beyond Excel spreadsheets. While we are creeping ever closer to the day that the general purpose computer is extinct or only available to an elite few, while the rest of us are stuck in walled gardens using only approved software, the technology for that didn't exist in the early days of the home computer revolution. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From email at paulstgeorge.com Sun Jun 10 07:15:35 2018 From: email at paulstgeorge.com (Paul St George) Date: Sun, 10 Jun 2018 13:15:35 +0200 Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: References: <64899b39-ef16-0c74-7a1b-30f49b470c3f@paulstgeorge.com> <77b0d1eb-8b01-e785-4951-6d0a90702ec7@paulstgeorge.com> Message-ID: To recap: this thread started with a question. How do I know whether DOUBLEBUF has been set with: ??? screen = pygame.display.set_mode((720,480), pygame.DOUBLEBUF | pygame.FULLSCREEN) On 09/06/2018 22:04, Mark Lawrence wrote: > On 09/06/18 20:31, Paul St George wrote: >> >> ???? print pygame.display.get_surface() >> gives >> >> >> and >> ???? print screen.get_flags() >> gives >> -2147483648 >> >> The lists of flags at >> >> and >> >> >> has nothing remotely like -2147483648. I would expect something more >> like 0x40000000 >> >> Am I using the wrong code to determine whether I have successfully >> set DOUBLEBUF with >> >> ???? screen = pygame.display.set_mode((720,480), pygame.FULLSCREEN | >> pygame.DOUBLEBUF) >> >> AND >> >> What does -2147483648 tell me? Does this number need converting? >>> > > From the interactive interpreter:- > > >>> hex(-2147483648) > '-0x80000000' > >>> hex(pygame.FULLSCREEN) > '-0x80000000' > >>> hex(pygame.DOUBLEBUF) > '0x40000000' > Thanks go to Mark Lawrence and Richard Damon. Using print hex(screen.get_flags()) I can see that the order of the two flags does not make a difference. screen = pygame.display.set_mode((720,480), pygame.DOUBLEBUF | pygame.FULLSCREEN) screen = pygame.display.set_mode((720,480), pygame.FULLSCREEN | pygame.DOUBLEBUF) both report the same print hex(screen.get_flags()) '-0x80000000' BUT omitting DOUBLEBUF from the code screen = pygame.display.set_mode((720,480), pygame.FULLSCREEN) also makes no difference to the report print hex(screen.get_flags()) '-0x80000000' AND with with only DOUBLEBUF in the code screen = pygame.display.set_mode((720,480), pygame.DOUBLEBUF) does not give the expected and desired '-0x40000000' instead, the report is print hex(screen.get_flags()) ?0x0? 0x0 (SWSURFACE) is consistent with print pygame.display.get_surface() ?? It seems that DOUBLEBUF is *not* being set. I am guessing this is because the arguments passed by pygame.display.set_mode() are only requests. The actual display will depend on the system, and what is available/possible. More guessing leads me to wonder whether DOUBLEBUF is only available when HWSURFACE is being used so I tried three flags with: flags = pygame.FULLSCREEN | pygame.DOUBLEBUF | pygame.HWSURFACE screen = pygame.display.set_mode((0, 0), flags) But no change (screen is still SW and DOUBLEBUF is not set): print pygame.display.get_surface() print hex(screen.get_flags()) -0x80000000 QUESTIONS Can anyone find an error in any of this? I hope so. Is DOUBLEBUF dependent on HWSURFACE? If so, how does one force the change to a Hardware surface? ?set_mode? is not doing it. From rosuav at gmail.com Sun Jun 10 07:33:19 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jun 2018 21:33:19 +1000 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: On Sun, Jun 10, 2018 at 9:08 PM, Steven D'Aprano wrote: > On Sun, 10 Jun 2018 13:36:34 +1000, Chris Angelico wrote: > >>> That's all speculation. It's impossible to say how things would have >>> turned out if copyrights didn't apply to software. Certainly different, >>> but not necessarily worse. >>> >>> In the early days, computer manufacturers didn't worry about people >>> copying their software, because it was no use without the hardware, and >>> selling hardware was how they made their money. There's no reason that >>> business model couldn't have continued into the PC era. >>> >>> >> It would have meant that third-party software would not exist. > > Says the fellow using a free mail server (funded by advertising) on a > free OS (funded by donations) on a free mailing list about a free > programming language :-) > > Lack of copyright for software would not affect software-as-a-service > like Gmail. It would not affect FOSS licences like the MIT and BSD > licence, although it might declaw the GPL. I'm not sure that these kinds of concepts would even exist, though. If the business model had always been "sell hardware, it comes fully programmed", what would bring people to try to create third-party software at all? It's easy to look back NOW and say "even if software had no copyright, this could still exist". It's not so easy to see that such things would have come about. We live today in a world of massive cross-compatibility and third-party software creations, where your "computer" may have many different manufacturers and many different software authors, all happily running together. While IBM did create hardware compatibility standards (allowing other manufacturers to create fully-compatible expansion cards etc) as a viable commercial decision, I doubt very much that anyone other than hobbyists would write software that they're unable to sell. Don't forget that "software-as-a-service" is an extremely young concept; to be a saleable form of software (as opposed to a saleable service involving both hardware and software), it depends on people having the clients AND a means of connecting to the servers - which today means web browsers and internet connections. Possibly the oldest "SaaS" concept for computers would be a dial-in BBS. Would that sort of thing exist if copyright did not? I'm not sure. Maybe it would, but it's certainly not "oh well saas wouldn't be affected by this". I'm also not sure that the MIT and BSD licenses would still be viable. Without copyright, they have no teeth, which would mean that their license terms of "don't sue me if it doesn't work" wouldn't apply. IANAL, but I'm fairly sure that those terms are in the licenses for good reason. The GPL, which has much stronger requirements, would be completely powerless. "Not affect" is far FAR too broad. Open source still depends on copyright. ChrisA From greg.ewing at canterbury.ac.nz Sun Jun 10 09:03:57 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 11 Jun 2018 01:03:57 +1200 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: Chris Angelico wrote: > You cannot, to > my knowledge, publish a game for the PS4 or Xbox 360 without > permission from Nintendo or Microsoft. That's because, since we *do* have copyright laws, the manufacturers of the consoles are able to make money by selling the software as well as the hardware -- and they want a monopoly on that source of income. If there was no copyright, they wouldn't be able to make money from the software side alone, so there would be no incentive for them to lock things down that way. The opposite, in fact -- the more games are available for a machine, the more people are going to want to buy it. > Nobody can sell software without also selling > hardware, which is an expensive industry to get into. I don't follow what you're saying here. Are you suggesting that nobody would write any software for someone else's hardware if they couldn't sell it for money? Experience with the open source community that we do have suggests otherwise. -- Greg From marko at pacujo.net Sun Jun 10 09:17:34 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Jun 2018 16:17:34 +0300 Subject: Stefan's headers [was:Names and identifiers] References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: <87zi02srv5.fsf@elektro.pacujo.net> Chris Angelico : > It's easy to look back NOW and say "even if software had no copyright, > this could still exist". It's not so easy to see that such things > would have come about. [...] I doubt very much that anyone other than > hobbyists would write software that they're unable to sell. A lot of software is custom-written to the specific needs of one customer. That software is extremely expensive but would get written regardless because the work must be done and couldn't be directly exploited by competitors. Now, as far as off-the-shelf products go (say computer games), the price can be low because the identical product is sold to more than one customer, sometimes even millions of customers. What would happen to software products that didn't have copyright protections? Nothing would prevent a competitor from starting to sell your product as theirs. This question must be asked in business in general. Could someone build another Mexican Restaurant? Could someone build a similar auction web site? Could someone go after your customers? And often the answer is, yes they could so it's not worth the investment. In this situation, will someone do the work or will it not get done? In some cases, it would not get done. I still don't think the existence of copyright laws is the proper burden to put on the society. Instead, the government should fund such needs as it already does for necessary things that don't have a market. The government won't see an incentive to build a computer game so some lucrative markets would disappear with the copyright gone. However, you will see lots of creative community efforts to build not only games but business utilities to address real needs. For example, a doctor in my hometown built an appointment web app that was easier to use than the expensive, professional alternative. When there's no copyright protection, development communities can arise around such tools and the germs can become high-quality applications over time. > I'm also not sure that the MIT and BSD licenses would still be viable. > Without copyright, they have no teeth, which would mean that their > license terms of "don't sue me if it doesn't work" wouldn't apply. I think the MIT and BSD licenses are just silly variants of the Public Domain. The no-warranty clauses might not be enforceable anyway. Their main point is the requirement for attribution. Marko From greg.ewing at canterbury.ac.nz Sun Jun 10 09:23:08 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 11 Jun 2018 01:23:08 +1200 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: Chris Angelico wrote: > I doubt very much that anyone other than > hobbyists would write software that they're unable to sell. Or, maybe, people who *use* the machines as part of their livelihood, and have an incentive to produce good, reliable software that does what they need. > I'm also not sure that the MIT and BSD licenses would still be viable. > Without copyright, they have no teeth, which would mean that their > license terms of "don't sue me if it doesn't work" wouldn't apply. It's not clear that such terms are even enforcible now. There are places where wording like "not even the implied warranty of fitness for a particular purpose" etc. have no meaning, because you're not allowed to contract out of things like that. But in any case, there's nothing stopping you from attaching a notice like that to something you distribute, it just wouldn't be called a licence, but a disclaimer or something like that. It would have the same number of teeth either way. -- Greg From bellcanadardp at gmail.com Sun Jun 10 09:24:30 2018 From: bellcanadardp at gmail.com (bellcanadardp at gmail.com) Date: Sun, 10 Jun 2018 06:24:30 -0700 (PDT) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <27ef2bfb-e3ed-495c-bb98-f71e502d412a@googlegroups.com> <20180520134354.GB2192@hermes.hilbert.loc> <20180522212337.cvtbh32tydvaft4r@hjp.at> <01e3fac3-c389-410b-8a17-3adf83876e02@googlegroups.com> Message-ID: <86fb8359-56a9-48ba-851d-2e37dd2f9187@googlegroups.com> On Friday, 8 June 2018 07:42:34 UTC-4, Steven D'Aprano wrote: > On Fri, 08 Jun 2018 03:35:12 -0700, bellcanadardp wrote: > > > hello steven are you there?? > > i posted the full error message... > > No you didn't. > > I saw your post, and ignored it, because you didn't follow instructions. > I told you we need to see the *full* traceback, starting from the line > beginning "Traceback". You only posted the end of the traceback. > > I told you we needed to see the actual line of code you are trying to > run. You didn't show us the line of code you are trying to run. > > We're not mind-readers. We can't fix code that we can't see, giving > errors from a line you won't tell us, using a file we don't have. > > Please read this before replying: > > http://sscce.org/ > > Thank you. > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson *********************************************** Traceback (most recent call last): File "createIndex.py", line 132, in c.createindex() File "creatIndex.py", line 102, in createIndex pagedict=self.parseCollection() File "createIndex.py", line 47, in parseCollection for line in self.collFile: File "C:\Users\Robert\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table[0] UnicodeDecodeError: 'charmap'codec can't decode byte 0x9d in position 7414: character maps to ***************************************************** From sagardaya379 at gmail.com Sun Jun 10 09:28:17 2018 From: sagardaya379 at gmail.com (sagar daya) Date: Sun, 10 Jun 2018 18:58:17 +0530 Subject: No subject Message-ID: Couldn't install any module from pip Plz help??? From steve+comp.lang.python at pearwood.info Sun Jun 10 10:21:03 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jun 2018 14:21:03 +0000 (UTC) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <27ef2bfb-e3ed-495c-bb98-f71e502d412a@googlegroups.com> <20180520134354.GB2192@hermes.hilbert.loc> <20180522212337.cvtbh32tydvaft4r@hjp.at> <01e3fac3-c389-410b-8a17-3adf83876e02@googlegroups.com> <86fb8359-56a9-48ba-851d-2e37dd2f9187@googlegroups.com> Message-ID: Do you enjoy wasting your own time (as well as ours) by failing to follow instructions? We can't read your mind to see the code you are using, and I am getting frustrated from telling you the same thing again and again. PLEASE PLEASE PLEASE PLEASE help us to help you. Start by reading this: http://sscce.org/ What is self.collFile? How does it get opened? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From hjp-python at hjp.at Sun Jun 10 10:25:24 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 10 Jun 2018 16:25:24 +0200 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <87sh5x2nd7.fsf@elektro.pacujo.net> <87lgbp2loh.fsf@elektro.pacujo.net> <20cbf1d5-1b92-99a4-15a1-9cebed838852@mrabarnett.plus.com> <87po10vs45.fsf@elektro.pacujo.net> Message-ID: <20180610142524.rlqdl5zny2534wv4@hjp.at> On 2018-06-09 10:15:43 +1000, Chris Angelico wrote: > On Sat, Jun 9, 2018 at 8:19 AM, Marko Rauhamaa wrote: > > Chris Angelico : > >> On Sat, Jun 9, 2018 at 6:59 AM, MRAB wrote: > >>> So those with the most money can buy the most protection? > >> > >> Yes, or more specifically, those who believe they can make the most > >> money from that protection. Ownership becomes pay-to-win, literally. > > > > In the words of Scrooge McDuck: > > > > > > > > > > But guys, surely you are familiar with the exponential function: > > > > * Everybody can afford a year for $1. > > $1 per what, though? According to GitHub, I have 157 repositories. Is > that 157 separate things that cost $1 for a single year of protection? > Or do I pay per file of source code? When I first read about the scheme Marko is proposing here it was presented mainly as an alternative of the current patent scheme. There it is obvious: You pay per patent. The article also extended it to books. There it is also obvious: You pay per book. Patents and books are nice, distinctive "works". You might argue whether "The Lord of the Rings" is one book or three, and whether each edition of "Learning Python" (there are now 5 of them) is a separate book, but these are relatively easy cases. Software is harder. When software was still sold in a nice box with a three-ring binder and a few floppies, it was similar to a book: If it comes in one box, it is one work to be copyrighted. But with online distribution (not necessarily github) the boundaries become very fluid. When Debian still contained the Roxen webserver, it comprised over 100 packages: The maintainer had put every plugin into a separate package. I did something similar with my qpsmtpd plugins: Each is in a separate .deb or .rpm file. There is also the problem of how to treat revisions: If I always register the newest revision and stop paying for older revisions, is code I didn't change still protected or not? I don't remember whether the article addressed these problems. I guess I should read it again (it was in CACM, a few years ago). Personally, I would let the author decide what constitutes one work. If you think your 157 git repos are a single work, register it as one. Whenever you think you have made enough changes that this is a new work which should be protected, register it again. And if the fees for your old versions become too high, let them lapse. > > * Every worthwhile creation is worth $1,000 for ten years. > > Not true by a long shot, and if you don't believe me, you can pay me > $1000 right now for ten years' use of any of my free software. I think he meant it the other way around: If you can sell your software for 10 years, you can affort $1000 to have your monopoly protected. > > * And if Disney can pay the fee for Mickey Mouse for fifty years, the > > United States Government can quit all taxation, pay off the national > > debt and buy every American a luxury yacht and a private island in > > the Caribbean. > > And if you think that Disney would actually let it compound according > to your theoretical definition, you're a dupe AND a fool. They'd > figure out some way to reset the counter every five years. More likely they would prevent such law from being passed in the first place. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From __peter__ at web.de Sun Jun 10 10:38:47 2018 From: __peter__ at web.de (Peter Otten) Date: Sun, 10 Jun 2018 16:38:47 +0200 Subject: FULLSCREEN and DOUBLEBUF References: <64899b39-ef16-0c74-7a1b-30f49b470c3f@paulstgeorge.com> <77b0d1eb-8b01-e785-4951-6d0a90702ec7@paulstgeorge.com> Message-ID: Paul St George wrote: > So... > > print pygame.display.get_surface() > gives > > > and > print screen.get_flags() > gives > -2147483648 > To recap: this thread started with a question. How do I know whether > DOUBLEBUF has been set with: > > screen = pygame.display.set_mode((720,480), pygame.DOUBLEBUF | > pygame.FULLSCREEN) flags = screen.get_flags() if flags & pygame.DOUBLEBUF: print("DOUBLEBUF has been set") if flags & pygame.FULLSCREEN: print("FULLSCREEN has been set") See the pattern? The easiest way to argue about flags is in binary notation. Every flag corresponds to an integer with a single bit set, e. g. HOT = 0b001 BLUE = 0b010 RIGHTEOUS = 0b100 You can combine the flags with bitwise or hot_and_righteous = HOT | RIGHTEOUS # 0b101 and query them with bitwise and: >>> if hot_and_righteous & HOT: print("hot") ... hot >>> if hot_and_righteous & BLUE: print("blue") ... >>> if hot_and_righteous & RIGHTEOUS: print("righteous") ... righteous With your actual pygame flags it's very much the same. However, because integers in Python are signed numbers like -2147483648 may be puzzling, even when you display them in binary >>> bin(-2147483648) '-0b10000000000000000000000000000000' You might think that only one flag is set because there is only one 1, but the - sign corresponds to an "infinite" number of leading 1s. If you know that the flags are stored (for example) in a 32bit integer you can mask off these leading 1s and see the actual data more clearly: >>> bin(-2147483648 & 0b11111111111111111111111111111111) '0b10000000000000000000000000000000' OK, so in this case it probably* was a single flag, but that's not always the case: >>> bin(-7) '-0b111' >>> bin(-7 & 0b11111111111111111111111111111111) '0b11111111111111111111111111111001' (*) What if the flags were stored in a 64bit integer? From countryone77 at gmail.com Sun Jun 10 10:45:06 2018 From: countryone77 at gmail.com (Bev in TX) Date: Sun, 10 Jun 2018 09:45:06 -0500 Subject: Why exception from os.path.exists()? In-Reply-To: <20180610104908.g6tugqmxdodnjjtm@hjp.at> References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> Message-ID: <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> > On Jun 10, 2018, at 5:49 AM, Peter J. Holzer wrote: > > On 2018-06-07 12:47:15 +0000, Steven D'Aprano wrote: >> But it doesn't do that. "Pathnames cannot contain NUL" is a falsehood >> that programmers wrongly believe about paths. HFS Plus and Apple File >> System support NULs in paths. > [...] >> But in the spirit of compromise, okay, let's ignore the existence of file >> systems like HFS which allow NUL. Apart from Mac users, who uses them >> anyway? Let's pretend that every file system in existence, now and into >> the future, will prohibit NULs in paths. > > Could you (or anybody else who owns a Mac) please do the following: > > * Create an empty directory > * In this directory, create two files: > * One with an embedded \0 in the file name I don?t know how to do this. I can?t enter a Nul in Finder. Bash silently converts it to a zero when using it as a file name. C considers the previous character the end of the file name. Python considers it an error. > * One with an embedded / in the file name This is easily done in Finder, where I created a folder named "my/slash?. When I list it at the command line in Terminal, this shows up as "my:slash?, with the slash shown as a colon. If I create a file with a colon in its name at the command line, that file name acts the same way: $ touch ?my:colon" $ ls my:colon my:slash In Finder they both display as: my/colon my/slash However, if you use Finder?s ?Copy item as Pathname? option, then you will again see the colon. /Users/bev/Training/myPython/pygroup/files/my:colon /Users/bev/Training/myPython/pygroup/files/my:slash But if you paste that folder?s name in Finder?s ?Go to Folder? option, it converts it to the following, and goes to that folder: /Users/bev/Training/myPython/pygroup/files/my/slash/slash So we can see three (3) separate behaviors for the same folder in Finder. This is because at some higher level, Apple?s file systems reserve the colon for the path separator, in stead of the slash. I know that AppleScript does use the colon as a path separator. However at a lower level, macOS still uses the slash, rather than colon, as the path name separator. IMO, this is confusing. Similarly in Finder file names are case insensitive, but case preserving. At the command line they are still case sensitive. Note that it?s possible to format a disk with a fully case sensitive file system, but that?s not the default. Please note that I am not an Apple HFS+ or AFS file system expert, by any stretch of the imagination. So please excuse me if I did?t state things perfectly. > * Compile and run this C program in the directory and post the output: > > #include > #include > #include > > int main(void) { > DIR *dp; > struct dirent *de; > char *p; > > dp = opendir("."); > while ((de = readdir(dp)) != NULL) { > printf("%ld -", (long)de->d_ino); > for (p = de->d_name; *p; p++) { > printf(" %02x", (unsigned char)*p); > } > printf("\n"); > } > return 0; > } I added printing the file name. As suspected, the ?slash? is a colon: . - 56096374 - 2e .. - 56095464 - 2e 2e .DS_Store - 56109197 - 2e 44 53 5f 53 74 6f 72 65 my:colon - 56095933 - 6d 79 3a 63 6f 6c 6f 6e my:slash - 56095521 - 6d 79 3a 73 6c 61 73 68 > Bonuspoints for doing this on an USB stick and then mounting the USB > stick on a Linux system and posting the output there as well. > Sorry, I don?t have Linux, but I suspect it?s the same as the macOS command line. > I'm really curious how MacOS maps those characters in the POSIX API. > > hp Bev in TX From brgrt2 at gmail.com Sun Jun 10 10:46:48 2018 From: brgrt2 at gmail.com (T Berger) Date: Sun, 10 Jun 2018 07:46:48 -0700 (PDT) Subject: Posting warning message Message-ID: When I go to post a reply, I get a warning asking if I want my email address (or other email addresses listed) visible to all, and do I want to edit my post. What should I do? From steve+comp.lang.python at pearwood.info Sun Jun 10 11:24:38 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jun 2018 15:24:38 +0000 (UTC) Subject: Stefan's headers [was:Names and identifiers] References: <87sh5x2nd7.fsf@elektro.pacujo.net> <87lgbp2loh.fsf@elektro.pacujo.net> <20cbf1d5-1b92-99a4-15a1-9cebed838852@mrabarnett.plus.com> <87po10vs45.fsf@elektro.pacujo.net> <20180610142524.rlqdl5zny2534wv4@hjp.at> Message-ID: On Sun, 10 Jun 2018 16:25:24 +0200, Peter J. Holzer wrote: > Personally, I would let the author decide what constitutes one work. Ah yes... Star Wars, Empire Strikes Back, Return of the Jedi, Phantom Menace, Attack of the Clones, Revenge of the Sith, Rogue One, Force Awakens, Last Jedi, Solo... they're all chapters in one work, yes? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From marko at pacujo.net Sun Jun 10 11:45:13 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Jun 2018 18:45:13 +0300 Subject: Stefan's headers [was:Names and identifiers] References: <87sh5x2nd7.fsf@elektro.pacujo.net> <87lgbp2loh.fsf@elektro.pacujo.net> <20cbf1d5-1b92-99a4-15a1-9cebed838852@mrabarnett.plus.com> <87po10vs45.fsf@elektro.pacujo.net> <20180610142524.rlqdl5zny2534wv4@hjp.at> Message-ID: <87tvqasl12.fsf@elektro.pacujo.net> Steven D'Aprano : > On Sun, 10 Jun 2018 16:25:24 +0200, Peter J. Holzer wrote: > >> Personally, I would let the author decide what constitutes one work. > > Ah yes... > > Star Wars, Empire Strikes Back, Return of the Jedi, Phantom Menace, > Attack of the Clones, Revenge of the Sith, Rogue One, Force Awakens, > Last Jedi, Solo... they're all chapters in one work, yes? If the author so decides, but they'll have to pay the registration fee at the time of publication. Marko From Karsten.Hilbert at gmx.net Sun Jun 10 12:30:51 2018 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sun, 10 Jun 2018 18:30:51 +0200 Subject: your mail In-Reply-To: References: Message-ID: <20180610163050.GC1673@hermes.hilbert.loc> On Sun, Jun 10, 2018 at 06:58:17PM +0530, sagar daya wrote: > Couldn't install any module from pip > Plz help??? https://duckduckgo.com kh -- From bellcanadardp at gmail.com Sun Jun 10 12:49:37 2018 From: bellcanadardp at gmail.com (bellcanadardp at gmail.com) Date: Sun, 10 Jun 2018 09:49:37 -0700 (PDT) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <27ef2bfb-e3ed-495c-bb98-f71e502d412a@googlegroups.com> <20180520134354.GB2192@hermes.hilbert.loc> <20180522212337.cvtbh32tydvaft4r@hjp.at> <01e3fac3-c389-410b-8a17-3adf83876e02@googlegroups.com> <86fb8359-56a9-48ba-851d-2e37dd2f9187@googlegroups.com> Message-ID: On Sunday, 10 June 2018 10:23:47 UTC-4, Steven D'Aprano wrote: > Do you enjoy wasting your own time (as well as ours) by failing to follow > instructions? > > We can't read your mind to see the code you are using, and I am getting > frustrated from telling you the same thing again and again. > > PLEASE PLEASE PLEASE PLEASE help us to help you. > > Start by reading this: > > http://sscce.org/ > > > What is self.collFile? How does it get opened? > > > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson excuse but sorry i took the time to manually write the code error from the traceback as you said and thats because i cant seem to find a way to attach files here..which would make it so easier for me and also i could attach snippets of the actual source code..and i asked the forum how i can attach files or also i asked for an email adress but i didnt get a response....also i find this is why programmers can have a bad reputation..cuz of examples of people like yourself barking out orders and getting upset for no good reason at tall..now one including myself is giving you obligations to answer my queires.... ok??..im not your slave the way you say that i have to follow instructions..so why do you kindly just buzz off of my thread since it makes you and myself really get annoyed..ok.. From rantingrickjohnson at gmail.com Sun Jun 10 13:29:55 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Jun 2018 10:29:55 -0700 (PDT) Subject: (no subject) In-Reply-To: References: Message-ID: <6cdc5b7d-3dfc-4025-96a4-3bd94ac712aa@googlegroups.com> sagar daya wrote: > Couldn't install any module from pip > Plz help??? As with most actions, an algorithm is required. (shocking, i know!) What methodology have you implemented thus far to achieve your goal of "installing modules from PIP"? Please enumerate the steps you chose to take, and then we _might_ can offer advice. For instance, if someone is having trouble brushing their teeth, the first question we might ask is: "Have you located the toothbrush and toothpaste yet?". From email at paulstgeorge.com Sun Jun 10 13:45:05 2018 From: email at paulstgeorge.com (Paul St George) Date: Sun, 10 Jun 2018 19:45:05 +0200 Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: References: <64899b39-ef16-0c74-7a1b-30f49b470c3f@paulstgeorge.com> <77b0d1eb-8b01-e785-4951-6d0a90702ec7@paulstgeorge.com> Message-ID: <7b79bff2-bf5b-b49e-115b-5f4a01b877f0@paulstgeorge.com> > Paul St George wrote: > >> So... >> >> print pygame.display.get_surface() >> gives >> >> >> and >> print screen.get_flags() >> gives >> -2147483648 >> To recap: this thread started with a question. How do I know whether >> DOUBLEBUF has been set with: >> >> screen = pygame.display.set_mode((720,480), pygame.DOUBLEBUF | >> pygame.FULLSCREEN) On 10/06/2018 16:38, Peter Otten wrote: > flags = screen.get_flags() > if flags & pygame.DOUBLEBUF: > print("DOUBLEBUF has been set") > if flags & pygame.FULLSCREEN: > print("FULLSCREEN has been set") > > See the pattern? I do. I do. And also, I now know for certain that DOUBLEBUF is not being set. The insights about flags will take more time to digest. Thank you for both! From rantingrickjohnson at gmail.com Sun Jun 10 13:56:07 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Jun 2018 10:56:07 -0700 (PDT) Subject: Why exception from os.path.exists()? In-Reply-To: <87o9gwgepm.fsf@elektro.pacujo.net> References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> Message-ID: <479e86b0-753a-4bd7-9595-071187d09b1e@googlegroups.com> Marko Rauhamaa wrote: > Chris Angelico : > > > Marko Rauhamaa wrote: > >> > >> This surprising exception can even be a security issue: > >> > >> >>> os.path.exists("\0") > >> Traceback (most recent call last): > >> File "", line 1, in > >> File "/usr/lib64/python3.6/genericpath.py", line 19, in exists > >> os.stat(path) > >> ValueError: embedded null byte > > > > [...] > > > > A Unix path name cannot contain a null byte, so what you > > have is a fundamentally invalid name. ValueError is > > perfectly acceptable. > > At the very least, that should be emphasized in the > documentation. The pathname may come from an external > source. It is routine to check for "/", "." and ".." but > most developers (!?) would not think of checking for "\0". > That means few test suites would catch this issue and few > developers would think of catching ValueError here. The end > result is unpredictable. I'd have to agree with this assessment. Either a filepath exists, or it doesn't. Therefore, in the "worldview" of os.path.exist, there should be no consideration of conformity, as it is blatantly obvious that any malformed path would _not_ and could _not_ possibly, exist. In fact, the only case in which the method in question should raise an Exception is when a non-stringy argument is passed. Which -- at least in 2.x version -- i can confirm (with limited testing) it does this correctly! ## PYTHON 2.X SESSION ## py> os.path.exists('') False py> os.path.exists(None) Traceback (most recent call last): File "", line 1, in os.path.exists(None) File "C:\Python27\lib\genericpath.py", line 26, in exists os.stat(path) TypeError: coercing to Unicode: need string or buffer, NoneType found >>> os.path.exists(1) Traceback (most recent call last): File "", line 1, in os.path.exists(1) File "C:\Python27\lib\genericpath.py", line 26, in exists os.stat(path) TypeError: coercing to Unicode: need string or buffer, int found But if the argument is a string, either it exists as a filepath or it doesn't. Case closed. Anything less would constitute type discrimination. Which is not only inconsistent, it's unethical. From ben.usenet at bsb.me.uk Sun Jun 10 14:07:34 2018 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Sun, 10 Jun 2018 19:07:34 +0100 Subject: Stefan's headers [was:Names and identifiers] References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> Message-ID: <878t7mjz15.fsf@bsb.me.uk> Jon Ribbens writes: > I'd suggest that since the processes he's purporting to disallow are > entirely standard and automated and he knows full well they exist and > that there is no mechanism by which they could be affected by his > notice, the notice has little effect. The Copyright notice is probably intended for human eyes. IIRC his posts don't show up on Google groups, for example, so there *is* a mechanism by which *some* of the headers (it may be X-no-archive) do get acted on. -- Ben. From rantingrickjohnson at gmail.com Sun Jun 10 14:26:14 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Jun 2018 11:26:14 -0700 (PDT) Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: <87sh5x2nd7.fsf@elektro.pacujo.net> References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> Message-ID: <95133bff-cb21-4e69-8a99-454a74a3c7fb@googlegroups.com> On Friday, June 8, 2018 at 12:34:58 PM UTC-5, Marko Rauhamaa wrote: > PS IMO copyright laws should be abolished altogether. At > the very least one should pay for copyright protection. One > ?1 for the first year, ?2 for the second, ?4 for the third > and so on exponentially. I like your idea of a exponential punitive annual increase to "secure the right" of copyright protection. However, your pricing scheme seems a bit outdated. Like, a century or _two_ outdated. ;-) Heck, in the spirit of the Python tutorial, i say we utilize the Fibonacci sequence (slightly modified) and finally put that atrocious code example to some good use. Yep, and pass it an initial argument reflecting the current "year of our lord", would ya? From john_ladasky at sbcglobal.net Sun Jun 10 14:26:33 2018 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sun, 10 Jun 2018 11:26:33 -0700 (PDT) Subject: Posting warning message In-Reply-To: References: Message-ID: <098dcf1c-c7c2-4617-b53b-82298b2dc458@googlegroups.com> On Sunday, June 10, 2018 at 7:47:01 AM UTC-7, T Berger wrote: > When I go to post a reply, I get a warning asking if I want my email address (or other email addresses listed) visible to all, and do I want to edit my post. What should I do? Are you posting through Google Groups? Sometimes I see that warning as well. Some, but not all, Usenet software deliberately mangles email addresses when composing posts. It's a good thing to mangle email addresses when posting publicly, as it makes it harder for spammers to find new targets. So answer "yes", and manually edit any email addresses you see in the post so that they can't be recovered. For example, if my email address was posted undisguised, you could edit it to "j... at g...com" and that should do the trick. From rantingrickjohnson at gmail.com Sun Jun 10 14:42:02 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Jun 2018 11:42:02 -0700 (PDT) Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <87sh5x2nd7.fsf@elektro.pacujo.net> <201806081433.45936.gheskett@shentel.net> Message-ID: Gene Heskett wrote: > I rather like that idea. Unforch, who would be in charge of keeping the > books uptodate? The USTPO? Of course that would expand another guvmnt > agencies payroll x10, and its a waste of taxpayer dollars since Albert > retired anyway. What century are you trapped in pal? Heck, all you need is a Godaddy(c) website and a simple HTML form (Hell, they even gots templates for that!!!). > Here in the hew hess aye, we originally had a copyright term of 7 years, > renewable just once for another 7. I will date myself by saying I can > actually remember those days. But then Disney started buying senators > and congressmen, and we now have this asinine lifetime +70 years just to > keep Mickey Mouse and Company's (oh, and don't forget a widow named > Cher) income rolling in. Yeah, and they've sucked up every independent animation house between here and Kathmandu. > Thats the sort of stuff usually found, warm and squishy, on the ground > behind the male of the bovine specie. Huh? The female bovines don't defecate where you come from? Well then! i see! Say hello to Qin-I, would ya? From tuxtimo at gmail.com Sun Jun 10 14:51:22 2018 From: tuxtimo at gmail.com (Timo Furrer) Date: Sun, 10 Jun 2018 20:51:22 +0200 Subject: No subject In-Reply-To: References: Message-ID: Can you be more specific. What did you try? In which environment? What was the error message you got? On Sun, Jun 10, 2018 at 6:32 PM sagar daya wrote: > Couldn't install any module from pip > Plz help??? > -- > https://mail.python.org/mailman/listinfo/python-list > -- *Timo Furrer* https://github.com/timofurrer tuxtimo at gmail.com From charleshixsn at earthlink.net Sun Jun 10 15:09:13 2018 From: charleshixsn at earthlink.net (Charles Hixson) Date: Sun, 10 Jun 2018 12:09:13 -0700 Subject: Why exception from os.path.exists()? In-Reply-To: References: <87tvqoghhh.fsf@elektro.pacujo.net> <87o9gwgepm.fsf@elektro.pacujo.net> <6342113.ZVQNR0knA0@varric.chelsea.private> <20180604201347.c56ffpeezycoo6ij@hjp.at> Message-ID: On 06/07/2018 12:45 AM, Chris Angelico wrote: > On Thu, Jun 7, 2018 at 1:55 PM, Steven D'Aprano > wrote: >> On Tue, 05 Jun 2018 23:27:16 +1000, Chris Angelico wrote: >> >>> And an ASCIIZ string cannot contain a byte value of zero. The parallel >>> is exact. >> Why should we, as Python programmers, care one whit about ASCIIZ strings? >> They're not relevant. You might as well say that file names cannot >> contain the character "?" because ASCIIZ strings don't support it. >> >> No they don't, and yet nevertheless file names can and do contain >> characters outside of the ASCIIZ range. > Under Linux, a file name contains bytes, most commonly representing > UTF-8 sequences. So... an ASCIIZ string *can* contain that character, > or at least a representation of it. Yet it cannot contain "\0". > > ChrisA This seems like an argument for allowing byte strings to be used as file names, not for altering text strings.? If file names are allowed to contain values that are illegal for text strings, then they shouldn't be necessarily considered as text strings. The unicode group sets one set of rules, and their rules should apply in their area.? The Linux group sets another set of rules, and their rules should apply in their area.? Just because there is a large area of overlap doesn't mean that the two areas are congruent.? Byte strings are designed to handle any byte pattern, but text strings are designed to handle a subset of those patterns. Most byte strings are readable as text, but not all of them. From rantingrickjohnson at gmail.com Sun Jun 10 15:17:32 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Jun 2018 12:17:32 -0700 (PDT) Subject: user defined modules In-Reply-To: References: Message-ID: <6f02ac5c-9e24-4e7d-bc3c-15b6fee12bd4@googlegroups.com> Sharan Basappa wrote: > Is there a specific location where user defined modules > need to be kept? My advice is that any location is a good location so long as the location you chose is _not_ a part of the PythonXY directory tree. For example, on a windoze machine (and in Python2.x at least), the PythonXY directory is placed (by default) at the root of the default drive (usually C drive). Your scripts (on a windows machine) should be (idealy) somewhere in the os.path.expanduser('~/Documents') tree. Personally i use a .pth file to point Python in the direction of my library modules. Unlike the old time masochist, i just hate having to repeat myself. Thus, like most modern folk, i have learned that copy+paste and "set- it-and-forget-it" text file are a computer users best friend and loyal companions. ## MAP ## C:/ PythonXY/ config.pth The contents of my .pth file is simply an unquoted string representing the path to my library folders. (something like this) ## PTH FILE CONTENT ## C:/.../Documents/path/to/my/lib/folder That's it! From andersjm at stofanet.dk Sun Jun 10 15:28:02 2018 From: andersjm at stofanet.dk (Anders Munch) Date: Sun, 10 Jun 2018 21:28:02 +0200 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> <20180602152828.morhwizcuqdmi7sv@hjp.at> Message-ID: Richard Damon wrote: > The two behaviors that I have heard suggested are: > > 1) If any of the inputs are a NaN, the median should be a NaN. > (Propagating the NaN as indicator of a numeric error) > > 2) Remove the NaNs from the input set and process what is left. If > nothing, then return a NaN (treating NaN as a 'No Data' placeholder). 3) Raise an exception. I can't believe anyone even suggested 2).? "In the face of ambiguity, refuse the temptation to guess." regards, Anders From barry at barrys-emacs.org Sun Jun 10 15:41:35 2018 From: barry at barrys-emacs.org (Barry) Date: Sun, 10 Jun 2018 20:41:35 +0100 Subject: Distributing a Python module as .rpm and .deb packages across major distributions In-Reply-To: <2347a88b-d676-4a8e-8495-b77c4cfe0561@googlegroups.com> References: <2347a88b-d676-4a8e-8495-b77c4cfe0561@googlegroups.com> Message-ID: <7F886456-06C7-4FFA-8E44-3B02D6E0C748@barrys-emacs.org> > On 8 Jun 2018, at 18:04, adam.preble at gmail.com wrote: > > I have a situation where internally I need to distribute some Python code using Linux packages rather than simply relying on wheel files. This seems to be a solved problem because a lot of Python modules clearly get distributed as .rpm and .deb. It's not completely unreasonable because soon I will have some other modules that are depending on binary applications that are also coming in from packages, and having the system package manage resolve and install all this is convenient. I'm not really in a political position to change that policy, for what it's worth. > > I'm still stuck in Python 2.7 here for at least a few more months. Also, it probably helps to know this is a pure Python module that doesn't have to compile any native code. > > Creating a package itself isn't a problem. In my case, I bandied with the bdist_rpm rule in setup.py, and used stdeb to add a bdist_deb rule. I get rpm and deb files from these, but they seem to be plagued with a problem of making assumptions about paths based on my build environment. I'm building on an Ubuntu rig where Python modules are installed into dist-packages. The rpm package will try to install my module into dist-packages instead of site-packages on a Red Hat rig. I haven't yet tried the Debian package on different rigs, but the stdeb documentation did call out that this likely won't work. > > I'm wondering first if many of the modules we see in packages right now are actually literally being built using Jenkins or some other CD tool on every major OS distribution. If that's the case then at least I know and I can try to do that. I was surprised that I couldn't easily provide some additional flags. I believe I can specify a setup.cfg that can override the module installation path, and I think I can do a little shell script to just rotate different setup.cfg files through, but I can't help but wonder if I'm even on the right path. > -- > https://mail.python.org/mailman/listinfo/python-list The way I learn about the details of RPM packaging is to look at examples like what I wish to achieve. I would go get the source RPM for a python2 package from each distro you want to supoort and read its .spec file. I see on fedora that the way they install packages that are from pypi makes it possible to use pip list to see them. Barry From gheskett at shentel.net Sun Jun 10 15:44:47 2018 From: gheskett at shentel.net (Gene Heskett) Date: Sun, 10 Jun 2018 15:44:47 -0400 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: Message-ID: <201806101544.47718.gheskett@shentel.net> On Sunday 10 June 2018 14:42:02 Rick Johnson wrote: > Gene Heskett wrote: > > I rather like that idea. Unforch, who would be in charge of keeping > > the books uptodate? The USTPO? Of course that would expand another > > guvmnt agencies payroll x10, and its a waste of taxpayer dollars > > since Albert retired anyway. > > What century are you trapped in pal? Heck, all you need is a > Godaddy(c) website and a simple HTML form (Hell, they even gots > templates for that!!!). > > > Here in the hew hess aye, we originally had a copyright term of 7 > > years, renewable just once for another 7. I will date myself by > > saying I can actually remember those days. But then Disney started > > buying senators and congressmen, and we now have this asinine > > lifetime +70 years just to keep Mickey Mouse and Company's (oh, and > > don't forget a widow named Cher) income rolling in. > > Yeah, and they've sucked up every independent animation house between > here and Kathmandu. > Probably farther than that. > > Thats the sort of stuff usually found, warm and squishy, on the > > ground behind the male of the bovine specie. > > Huh? The female bovines don't defecate where you come from? Well then! > i see! Say hello to Qin-I, would ya? Oh they do, but have the great good sense to take several steps away from the evidence, if they can. :) Qin-I? You lost me there. -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From bellcanadardp at gmail.com Sun Jun 10 16:04:28 2018 From: bellcanadardp at gmail.com (bellcanadardp at gmail.com) Date: Sun, 10 Jun 2018 13:04:28 -0700 (PDT) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <48742502-aaf3-43a4-93b1-a1eb37f3e37c@googlegroups.com> <20180608222610.GA1230@cskk.homeip.net> Message-ID: <7f780736-291f-4c65-b677-171691e326f7@googlegroups.com> On Friday, 8 June 2018 18:26:28 UTC-4, Cameron Simpson wrote: > On 05Jun2018 06:42, bellcanadardp at gmail.com wrote: > >On Sunday, 3 June 2018 20:11:43 UTC-4, Steven D'Aprano wrote: > >> Don't retype a summary of what you think the error is. "character > >> undefieed" is not a thing, and there is no such thing as "byte 1x09". > >> > >> You need to COPY AND PASTE the EXACT error that you get. Not just the > >> last line, the error message, but the FULL TRACEBACK starting from the > >> line "Traceback" and going to the end. > [...] > > > >here is the exact error full message > >in the attachment...UPDATE..i am manually modifying this reply..i tried to answer by my gmail but i get errors and i couldnt find this webpage till today and it doesnt accept attachments..so many you can for future provide an email if thats ok...anyway i will write the error manually here: > > Many of us read this group/list via the mailing list python-list at python.org. > I've CCed it here. Just avoid Google Groups, they're an awful interface to both > usenet and mailing lists. > > >File > >"C:\Users\Robert\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py", > >line 23, in decode > >return codecs.charmap_decode(input,self.errors,decoding_table[0] > >UnicodeDecodeError: 'charmap'codec can't decode byte 0x9d in position 7414: character maps to > > As Steven has remarked, this is not the complete traceback he requested, just > the end. We need to know the entire execution stack. > > >for the record i did not puprosely set the code or decode o encode to cp-1252; > >this is a 3rd party script i have from the internet thats all > > Can you say where it came from and how you fetched it? That may affect how the > file got into this situation and how it might be repaired. > > It might also let us fetch the file ourselves to look at it. > > >this a set of files that runs find in python 2.7 > >i am trying to run it in python 3 becuz i was told in 2020 python 2 will no longer be supported > >not sure if that really matters for my script > > It may not matter, but as a general rule you should try to use Python 3 for new > stuff. Python 2 is effectively end of life. > > >it runs completey fine in python 2, so for me the issue is with python 3 and > >its changes relative to python 2 > > It is possible that Python 2 is just glossing over the problem; Python 3 has a > more rigorous view of character data. > > Cheers, > Cameron Simpson here is the full error once again to summarize, my script works fine in python2 i get this error trying to run it in python3 plz see below after the error, my settings for python 2 and python 3 for me it seems i need to change some settings to 'utf-8'..either just in python 3, since thats where i am having issues or change the settings to 'utf-8' both in python 2 and 3....i would appreciate feedback b4 i do some trial and error thanks for the consideration tommy *********************************************** Traceback (most recent call last): File "createIndex.py", line 132, in c.createindex() File "creatIndex.py", line 102, in createIndex pagedict=self.parseCollection() File "createIndex.py", line 47, in parseCollection for line in self.collFile: File "C:\Users\Robert\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table[0] UnicodeDecodeError: 'charmap'codec can't decode byte 0x9d in position 7414: character maps to ***************************************************** *************************************************** python 3 settings import sys import locale locale.getpreferredencoding() 'cp1252' sys.stdout.encoding 'cp1252' sys.getdefaultencoding() 'utf-8' sys.getfilesystemencoding() 'utf-8' sys.stdin.encoding 'cp1252' sys.stderr.encoding 'cp1252' PYTHON 2 settings import sys import locale locale.getpreferredencoding() 'cp1252' sys.stdout.encoding 'cp1252' sys.getdefaultencoding() 'ascii' sys.getfilesystemencoding() 'mbcs' sys.stdin.encoding 'cp1252' sys.stderr.encoding 'cp1252' *************************************** From rosuav at gmail.com Sun Jun 10 16:07:02 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jun 2018 06:07:02 +1000 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <1a7951080901290824p424caee3jb74b1343ce884916@mail.gmail.com> <27ef2bfb-e3ed-495c-bb98-f71e502d412a@googlegroups.com> <20180520134354.GB2192@hermes.hilbert.loc> <20180522212337.cvtbh32tydvaft4r@hjp.at> <01e3fac3-c389-410b-8a17-3adf83876e02@googlegroups.com> <86fb8359-56a9-48ba-851d-2e37dd2f9187@googlegroups.com> Message-ID: On Mon, Jun 11, 2018 at 2:49 AM, wrote: > > excuse but sorry > i took the time to manually write the code error from the traceback as you said > and thats because i cant seem to find a way to attach files here..which would make it so easier for me and also i could attach snippets of the actual source code..and i asked the forum how i can attach files or also i asked for an email adress but i didnt get a response....also i find this is why programmers can have a bad reputation..cuz of examples of people like yourself barking out orders and getting upset for no good reason at tall..now one including myself is giving you obligations to answer my queires.... ok??..im not your slave the way you say that i have to follow instructions..so why do you kindly just buzz off of my thread since it makes you and myself really get annoyed..ok.. > -- Nope, you're not our slave. But here's the thing: none of us is your slave either. If you don't want help, we don't have to provide any. ChrisA From rosuav at gmail.com Sun Jun 10 16:10:26 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jun 2018 06:10:26 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> Message-ID: On Mon, Jun 11, 2018 at 12:45 AM, Bev in TX wrote: >> * One with an embedded / in the file name > > This is easily done in Finder, where I created a folder named "my/slash?. > When I list it at the command line in Terminal, this shows up as "my:slash?, with the slash shown as a colon. > If I create a file with a colon in its name at the command line, that file name acts the same way: > > $ touch ?my:colon" > $ ls > my:colon > my:slash > > In Finder they both display as: > my/colon > my/slash > > However, if you use Finder?s ?Copy item as Pathname? option, then you will again see the colon. > > /Users/bev/Training/myPython/pygroup/files/my:colon > /Users/bev/Training/myPython/pygroup/files/my:slash > > But if you paste that folder?s name in Finder?s ?Go to Folder? option, it converts it to the following, and goes to that folder: > > /Users/bev/Training/myPython/pygroup/files/my/slash/slash Can you try creating "spam:ham" and "spam/ham"? If they're both legal, I'd like to see what their file names are represented as. ChrisA From rosuav at gmail.com Sun Jun 10 16:13:10 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jun 2018 06:13:10 +1000 Subject: Posting warning message In-Reply-To: <098dcf1c-c7c2-4617-b53b-82298b2dc458@googlegroups.com> References: <098dcf1c-c7c2-4617-b53b-82298b2dc458@googlegroups.com> Message-ID: On Mon, Jun 11, 2018 at 4:26 AM, John Ladasky wrote: > On Sunday, June 10, 2018 at 7:47:01 AM UTC-7, T Berger wrote: >> When I go to post a reply, I get a warning asking if I want my email address (or other email addresses listed) visible to all, and do I want to edit my post. What should I do? > > Are you posting through Google Groups? Sometimes I see that warning as well. > > Some, but not all, Usenet software deliberately mangles email addresses when composing posts. It's a good thing to mangle email addresses when posting publicly, as it makes it harder for spammers to find new targets. So answer "yes", and manually edit any email addresses you see in the post so that they can't be recovered. For example, if my email address was posted undisguised, you could edit it to "j... at g...com" and that should do the trick. > Or just use the mailing list and do things honestly. Much easier AND safer than using Google Groups. ChrisA From rosuav at gmail.com Sun Jun 10 16:21:31 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jun 2018 06:21:31 +1000 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: On Sun, Jun 10, 2018 at 11:03 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> You cannot, to >> my knowledge, publish a game for the PS4 or Xbox 360 without >> permission from Nintendo or Microsoft. > > > That's because, since we *do* have copyright laws, the > manufacturers of the consoles are able to make money by > selling the software as well as the hardware -- and they > want a monopoly on that source of income. > > If there was no copyright, they wouldn't be able to > make money from the software side alone, so there would > be no incentive for them to lock things down that way. > The opposite, in fact -- the more games are available > for a machine, the more people are going to want to > buy it. > >> Nobody can sell software without also selling >> hardware, which is an expensive industry to get into. > > > I don't follow what you're saying here. Are you suggesting > that nobody would write any software for someone else's > hardware if they couldn't sell it for money? Experience > with the open source community that we do have suggests > otherwise. > Nice work there. You trimmed key parts of my post, and then responded to me out of context. Go back and read my actual post, then respond to what I actually said. Thanks! ChrisA From marko at pacujo.net Sun Jun 10 16:22:47 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Jun 2018 23:22:47 +0300 Subject: Why exception from os.path.exists()? References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> Message-ID: <87in6qs86g.fsf@elektro.pacujo.net> Chris Angelico : > Can you try creating "spam:ham" and "spam/ham"? If they're both legal, > I'd like to see what their file names are represented as. I think Bev already explained it. At Unix level, you can't have slashes in filenames. At GUI level, you can't have colons in filenames. Unix slashes are bijectively mapped to colons in the GUI. So what you are asking can't really be tried out. Marko From Richard at Damon-Family.org Sun Jun 10 16:28:57 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 10 Jun 2018 16:28:57 -0400 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> <20180602152828.morhwizcuqdmi7sv@hjp.at> Message-ID: <020a8f10-1dff-214e-d802-67f3dabd0baa@Damon-Family.org> On 6/10/18 3:28 PM, Anders Munch wrote: > Richard Damon wrote: > >> The two behaviors that I have heard suggested are: >> >> 1) If any of the inputs are a NaN, the median should be a NaN. >> (Propagating the NaN as indicator of a numeric error) >> >> 2) Remove the NaNs from the input set and process what is left. If >> nothing, then return a NaN (treating NaN as a 'No Data' placeholder). > > 3) Raise an exception. > > I can't believe anyone even suggested 2).? "In the face of ambiguity, > refuse the temptation to guess." > > regards, Anders > Many people doing statistics (mis-)use 'NaN' as a flag for 'missing data for this record'. If you want the statistic of a sample as an estimate of the statistic of the population, then omitting 'missing data' can be a reasonable option. I will agree that I see issues with this attitude, but it isn't uncommon. -- Richard Damon From rosuav at gmail.com Sun Jun 10 16:35:27 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jun 2018 06:35:27 +1000 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: <20180610142524.rlqdl5zny2534wv4@hjp.at> References: <87sh5x2nd7.fsf@elektro.pacujo.net> <87lgbp2loh.fsf@elektro.pacujo.net> <20cbf1d5-1b92-99a4-15a1-9cebed838852@mrabarnett.plus.com> <87po10vs45.fsf@elektro.pacujo.net> <20180610142524.rlqdl5zny2534wv4@hjp.at> Message-ID: On Mon, Jun 11, 2018 at 12:25 AM, Peter J. Holzer wrote: > But with online distribution (not necessarily github) the boundaries > become very fluid. When Debian still contained the Roxen webserver, it > comprised over 100 packages: The maintainer had put every plugin into a > separate package. I did something similar with my qpsmtpd plugins: Each > is in a separate .deb or .rpm file. Python has long been distributed as a single .msi file on Windows, but as many separate .deb packages on Debian Linux. One work or many? Back in the 90s, my family sold books, many of them imported and/or exported. We had a few books by Earl Rodd, all looking like books and behaving like books. And we also had the "Rodd Papers", which are individual photocopied leaflets (A5, maybe 20-32 pages tops). They're also copyrightable, right? Well here's the thing. One of the books was simply a published compilation of a large number of the papers. So what is the "work"? Is the book a brand-new work? If you cease to register the papers and start registering the book (one work, not dozens, and also a new work so the stupid exponentiation resets), people can't copy the papers either, because they're entirely contained within the book. So... all you have to do is, every couple of years, gather everything you've ever written into a brand new book and register it. >> > * Every worthwhile creation is worth $1,000 for ten years. >> >> Not true by a long shot, and if you don't believe me, you can pay me >> $1000 right now for ten years' use of any of my free software. > > I think he meant it the other way around: If you can sell your software > for 10 years, you can affort $1000 to have your monopoly protected. Except that I'm not selling it. What if I want to give it away, but with the proviso that the document credits me properly? "Go ahead, use it, publish it, but keep my name on it" is a common thing for people to request. And it's toothless [1] without copyright; so if you have to pay money for the right to be credited, there's going to be a lot of corporate bullying. ChrisA [1] No, it's not a dragon. I can't imagine why you would think that. From rosuav at gmail.com Sun Jun 10 16:36:49 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jun 2018 06:36:49 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: <87in6qs86g.fsf@elektro.pacujo.net> References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <87in6qs86g.fsf@elektro.pacujo.net> Message-ID: On Mon, Jun 11, 2018 at 6:22 AM, Marko Rauhamaa wrote: > Chris Angelico : >> Can you try creating "spam:ham" and "spam/ham"? If they're both legal, >> I'd like to see what their file names are represented as. > > I think Bev already explained it. At Unix level, you can't have slashes > in filenames. At GUI level, you can't have colons in filenames. Unix > slashes are bijectively mapped to colons in the GUI. > > So what you are asking can't really be tried out. > I'd like to find out about that. If it doesn't work, it'll be easily provable that it can't be done. ChrisA From hjp-python at hjp.at Sun Jun 10 16:38:42 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 10 Jun 2018 22:38:42 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> Message-ID: <20180610203842.aeqcmhkmpsvrgch6@hjp.at> On 2018-06-10 09:45:06 -0500, Bev in TX wrote: > On Jun 10, 2018, at 5:49 AM, Peter J. Holzer wrote: > > On 2018-06-07 12:47:15 +0000, Steven D'Aprano wrote: > >> But it doesn't do that. "Pathnames cannot contain NUL" is a falsehood > >> that programmers wrongly believe about paths. HFS Plus and Apple File > >> System support NULs in paths. > > [...] > >> But in the spirit of compromise, okay, let's ignore the existence of file > >> systems like HFS which allow NUL. Apart from Mac users, who uses them > >> anyway? Let's pretend that every file system in existence, now and into > >> the future, will prohibit NULs in paths. [...] > > * One with an embedded / in the file name > > This is easily done in Finder, where I created a folder named "my/slash?. > When I list it at the command line in Terminal, this shows up as "my:slash?, with the slash shown as a colon. > If I create a file with a colon in its name at the command line, that file name acts the same way: > > $ touch ?my:colon" > $ ls > my:colon > my:slash > > In Finder they both display as: > my/colon > my/slash Thanks. So they just map '/' to ':'. IIRC, MacOS <= 9 used ':' as the directory separator, so that makes sense. They kept the old behaviour for applications using the Mac API (and for the GUI), but for the POSIX API they use '/' (as they have to). Since ':' wasn't previously allowed, there is no conflict, just some confusion for the users who sees different filenames depending on which tool they use. It does, however, mean that on MacOS filenames can't contain all Unicode characters, either. [...] > I added printing the file name. As suspected, the ?slash? is a colon: > > . - 56096374 - 2e > .. - 56095464 - 2e 2e > .DS_Store - 56109197 - 2e 44 53 5f 53 74 6f 72 65 > my:colon - 56095933 - 6d 79 3a 63 6f 6c 6f 6e > my:slash - 56095521 - 6d 79 3a 73 6c 61 73 68 Yup. > > Bonuspoints for doing this on an USB stick and then mounting the USB > > stick on a Linux system and posting the output there as well. > > > Sorry, I don?t have Linux, but I suspect it?s the same as the macOS command line. Very likely, yes. 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 jon+usenet at unequivocal.eu Sun Jun 10 17:08:51 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sun, 10 Jun 2018 21:08:51 -0000 (UTC) Subject: Stefan's headers [was:Names and identifiers] References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <878t7mjz15.fsf@bsb.me.uk> Message-ID: On 2018-06-10, Ben Bacarisse wrote: > Jon Ribbens writes: > >> I'd suggest that since the processes he's purporting to disallow are >> entirely standard and automated and he knows full well they exist and >> that there is no mechanism by which they could be affected by his >> notice, the notice has little effect. > > The Copyright notice is probably intended for human eyes. IIRC his > posts don't show up on Google groups, for example, so there *is* a > mechanism by which *some* of the headers (it may be X-no-archive) do get > acted on. True - many Usenet headers are intended for automated processing - but the meaning of X-No-Archive is not even slightly similar to what he says in his copyright notice, and so any overlap between the effect of the former and the intention of the latter is merely coincidental. From hjp-python at hjp.at Sun Jun 10 17:09:31 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 10 Jun 2018 23:09:31 +0200 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <87lgbp2loh.fsf@elektro.pacujo.net> <20cbf1d5-1b92-99a4-15a1-9cebed838852@mrabarnett.plus.com> <87po10vs45.fsf@elektro.pacujo.net> <20180610142524.rlqdl5zny2534wv4@hjp.at> Message-ID: <20180610210931.22icr3jukchcsjph@hjp.at> On 2018-06-10 15:24:38 +0000, Steven D'Aprano wrote: > On Sun, 10 Jun 2018 16:25:24 +0200, Peter J. Holzer wrote: > > Personally, I would let the author decide what constitutes one work. > > Ah yes... > > Star Wars, Empire Strikes Back, Return of the Jedi, Phantom Menace, > Attack of the Clones, Revenge of the Sith, Rogue One, Force Awakens, Last > Jedi, Solo... they're all chapters in one work, yes? Yes, that would be possible. But there were 40+ years between the release of Star Wars and the release of Solo, so if George Lucas had decided to wait until the series is complete before registering it for copyright, he either couldn't have published it yet (Episode IX is scheduled for next year) or he would have published the parts without protection (effectively making them public domain). So Lucas would have registered Star Wars in 1977, and when the Empire Strikes Back came out in 1980, he would have had the option to register it as a separate work or to register the series consisting of both films. Wouldn't have made a difference since he would have had to continue to pay for Star Wars to prevent it from falling into the public domain. At some point he probably would have decided that continued copyright protection wasn't worth the cost, so the first three episodes would be public domain by now (If the doubling period is only one year. The article I read suggested different doubling periods for different kind of works: 1 year for patents, 3 years for books, ... It also depends on the initial fee: Start at $1 (a token amount), $100 (may cover the cost of having a person actually looking at it), $1000, ...?) 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 barry at barrys-emacs.org Sun Jun 10 17:09:39 2018 From: barry at barrys-emacs.org (Barry Scott) Date: Sun, 10 Jun 2018 22:09:39 +0100 Subject: Why exception from os.path.exists()? In-Reply-To: References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> Message-ID: <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> > On 10 Jun 2018, at 21:10, Chris Angelico wrote: > > On Mon, Jun 11, 2018 at 12:45 AM, Bev in TX wrote: >>> * One with an embedded / in the file name >> >> This is easily done in Finder, where I created a folder named "my/slash?. >> When I list it at the command line in Terminal, this shows up as "my:slash?, with the slash shown as a colon. >> If I create a file with a colon in its name at the command line, that file name acts the same way: >> >> $ touch ?my:colon" >> $ ls >> my:colon >> my:slash >> >> In Finder they both display as: >> my/colon >> my/slash >> >> However, if you use Finder?s ?Copy item as Pathname? option, then you will again see the colon. >> >> /Users/bev/Training/myPython/pygroup/files/my:colon >> /Users/bev/Training/myPython/pygroup/files/my:slash >> >> But if you paste that folder?s name in Finder?s ?Go to Folder? option, it converts it to the following, and goes to that folder: >> >> /Users/bev/Training/myPython/pygroup/files/my/slash/slash > > Can you try creating "spam:ham" and "spam/ham"? If they're both legal, > I'd like to see what their file names are represented as. On Classic Mac OS the folder separator was : not /. /usr/bin/ls would be usr:bin:ls for example. It looks like a hang over from Classic that the macOS Finder maps between : to / for presentation. In bash you see the ":" in Finder you see a /. In the Finder attempting to use a : in a filename gets an error message "Name cannot be uses a:b". In macOS bash you cannot use a / in a filename. I think what all boils down to this: Windows, macOS and Linux etc all use a 0 as the end of string marker. (Windows uses 16bit 0 not 8bit 0). The os file functions call the underlying OS and map its results into successes or exceptions. The \0 means that the OS functions cannot be passed the data from the user. Therefore you cannot get an error code from the OS. All the other file systems rules are checked by the OS itself and any errors are reported to the user as OSError etc. For example on windows the OS will prevent use '<' in a filename and it is the OS that returned the error. Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> open('a", line 1, in OSError: [Errno 22] Invalid argument: 'a>> open('a\0b', 'w') Traceback (most recent call last): File "", line 1, in ValueError: embedded null character >>> Singling out os.path.exists as a special case I do think is reasonable. All functions that take paths need to have a consistent response to data that is impossible to pass to the OS. When it is impossible to get the OS to see all of the users data I'm not sure what else is reasonable for python to do then what it already does not NUL. With the exception that I do not think this is documented and the docs should be fixed. Barry From marko at pacujo.net Sun Jun 10 17:28:11 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 11 Jun 2018 00:28:11 +0300 Subject: Why exception from os.path.exists()? References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> Message-ID: <87efhes55g.fsf@elektro.pacujo.net> Barry Scott : > Singling out os.path.exists as a special case I do think is > reasonable. I don't think anyone has proposed that. While I brought up os.path.exists() in my bug report, os.path.isfile(), os.path.isdir() etc should obviously be addressed simultaneously. It may even be that the fix needs to go to os.stat(). That's for the Python gods to decide. > All functions that take paths need to have a consistent response to > data that is impossible to pass to the OS. Possibly. Marko From cs at cskk.id.au Sun Jun 10 17:29:36 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 11 Jun 2018 07:29:36 +1000 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: <7f780736-291f-4c65-b677-171691e326f7@googlegroups.com> References: <7f780736-291f-4c65-b677-171691e326f7@googlegroups.com> Message-ID: <20180610212936.GA42086@cskk.homeip.net> On 10Jun2018 13:04, bellcanadardp at gmail.com wrote: >here is the full error once again >to summarize, my script works fine in python2 >i get this error trying to run it in python3 >plz see below after the error, my settings for python 2 and python 3 >for me it seems i need to change some settings to 'utf-8'..either just in python 3, since thats where i am having issues or change the settings to 'utf-8' both in python 2 and 3....i would appreciate feedback b4 i do some trial and error >thanks for the consideration >tommy > >*********************************************** >Traceback (most recent call last): >File "createIndex.py", line 132, in >c.createindex() >File "creatIndex.py", line 102, in createIndex >pagedict=self.parseCollection() >File "createIndex.py", line 47, in parseCollection >for line in self.collFile: >File >"C:\Users\Robert\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py", >line 23, in decode >return codecs.charmap_decode(input,self.errors,decoding_table[0] >UnicodeDecodeError: 'charmap'codec can't decode byte 0x9d in position 7414: character maps to Ok, this is more helpful. It says that the decoding error, which occurred in ...\cp1252.py, was decoding lines from the file self.collFile. What is that file? And how was it opened? Also, your settings below may indeed be important. >*************************************************** >python 3 settings >import sys > import locale >locale.getpreferredencoding() >'cp1252' The setting above is the default encoding used when you open a file in text mode in Python 3, but you can override it. In Python 3 this matters a lot, because Python 3 strings are Unicode. In Python 2, strings are just bytes, and are not "decoded" (there is a whole separate "unicode" type for that when it matters). So in Python 3 the text file reader is decoding the text in the file according to what it expects the encoding to be. Find the place where self.collFile is opened. You can specify the decoding method there by adding the "encoding=" parameter to the open() call. It is defaulting to "cp1252" because that is what locale.getpreferredencoding() returns, but presumably the actual file data are not encoded that way. You can (a) find out what encoding _is_ used in the file and specify that or (b) tell Python to be less picky. Choice (a) is better if it is feasible. If you have to guess because you don't know the encoding, one possibility is that collFile contains utf-8 or utf-16; of these 2, utf-8 seems more likely given the 0x9d byte causing the trouble. Try adding: encoding='utf-8' to the open() call, eg: self.collFile = open('path-to-the-coll-file', encoding='utf-8') at the appropriate place. If that just produces a different decoding error, you have 2 choices: pick an encoding where every byte is "valid", such as 'iso8859-1', or to tell the decode to just cope with th errors by adding the errors="replace" or "errors="ignore" or errors="namereplace" parameter to the open() call. Both these choices have downsides. There are several ISO8859 encodings, and they might all be wrong for your file, leading to _incorrect_ text lines. The errors="..." parameter also has downsides: you will also end up with missing (errors="ignore") or incorrect (errors="replace" or errors="namereplace") text, because the decoder has to do something with the data: drop it or replace it with something wrong. The former loses data while the latter puts in bad data, but at least it is visible if you inspect the data later. The full documentation for Python 3's open() call is here: https://docs.python.org/3/library/functions.html#open where the various encoding= and errors= choices are described. Cheers, Cameron Simpson From cs at cskk.id.au Sun Jun 10 17:38:33 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 11 Jun 2018 07:38:33 +1000 Subject: Posting warning message In-Reply-To: <098dcf1c-c7c2-4617-b53b-82298b2dc458@googlegroups.com> References: <098dcf1c-c7c2-4617-b53b-82298b2dc458@googlegroups.com> Message-ID: <20180610213833.GA99313@cskk.homeip.net> On 10Jun2018 11:26, John Ladasky wrote: >On Sunday, June 10, 2018 at 7:47:01 AM UTC-7, T Berger wrote: >> When I go to post a reply, I get a warning asking if I want my email address (or other email addresses listed) visible to all, and do I want to edit my post. What should I do? > >Are you posting through Google Groups? Sometimes I see that warning as well. >Some, but not all, Usenet software deliberately mangles email addresses when >composing posts. Ah, interesting. >It's a good thing to mangle email addresses when posting publicly, as it makes >it harder for spammers to find new targets. So answer "yes", and manually >edit any email addresses you see in the post so that they can't be recovered. "Good" is subjective. I don't think it is a good thing, but many people do. My reasoning is that I'm never going to successfully hide my email address, so usually I won't bother. If I need to post somewhere I'd like private, I can always invent a random address like: c2d56bb1edc5ab8a at mailinator.com for that special purpose and move on. GMail has good spam filtering tech on the whole, so its users should be relatively comfortable about spam. So when I post to a public forum I usually use my normal email address. This is a personal decision and anyone might choose differently. Cheers, Cameron Simpson From hjp-python at hjp.at Sun Jun 10 17:57:35 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 10 Jun 2018 23:57:35 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: <87efhes55g.fsf@elektro.pacujo.net> References: <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <87efhes55g.fsf@elektro.pacujo.net> Message-ID: <20180610215735.ezrrtdwyskfv4jrj@hjp.at> On 2018-06-11 00:28:11 +0300, Marko Rauhamaa wrote: > Barry Scott : > > Singling out os.path.exists as a special case I do think is > > reasonable. > > I don't think anyone has proposed that. While I brought up > os.path.exists() in my bug report, os.path.isfile(), os.path.isdir() etc > should obviously be addressed simultaneously. Yes. > It may even be that the fix needs to go to os.stat(). That's for the > Python gods to decide. I'm not a Python god, but I don't think os.stat() should be changed. That already throws different exceptions for different errors: >>> os.stat("nix") Traceback (most recent call last): File "", line 1, in FileNotFoundError: [Errno 2] No such file or directory: 'nix' >>> os.stat("/lost+found/foo") Traceback (most recent call last): File "", line 1, in PermissionError: [Errno 13] Permission denied: '/lost+found/foo' >>> os.stat("\0") Traceback (most recent call last): File "", line 1, in ValueError: embedded null byte I think this is worth keeping, and "I couldn't pass that file name to the OS" is a different error than "the OS told me the file doesn't exist", so I think it should be a different exception. 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 hjp-python at hjp.at Sun Jun 10 18:26:41 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 11 Jun 2018 00:26:41 +0200 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <87lgbp2loh.fsf@elektro.pacujo.net> <20cbf1d5-1b92-99a4-15a1-9cebed838852@mrabarnett.plus.com> <87po10vs45.fsf@elektro.pacujo.net> <20180610142524.rlqdl5zny2534wv4@hjp.at> Message-ID: <20180610222641.hodbu2txfh7wlxm3@hjp.at> On 2018-06-11 06:35:27 +1000, Chris Angelico wrote: > Back in the 90s, my family sold books, many of them imported and/or > exported. We had a few books by Earl Rodd, all looking like books and > behaving like books. And we also had the "Rodd Papers", which are > individual photocopied leaflets (A5, maybe 20-32 pages tops). They're > also copyrightable, right? Well here's the thing. One of the books was > simply a published compilation of a large number of the papers. So > what is the "work"? Is the book a brand-new work? If you cease to > register the papers and start registering the book (one work, not > dozens, and also a new work so the stupid exponentiation resets), > people can't copy the papers either, because they're entirely > contained within the book. But they can, because each of the papers is now public domain. This situation also exists with current copyright law. If a book is out of copyright (either because the author has been dead for 70 years or because it fell through one of the gaps of the various copyright law changes in the US), you can re-publish it. Now you do have the copyright for the new book, but that stops others only from copying your book, not the original. > So... all you have to do is, every couple of years, gather everything > you've ever written into a brand new book and register it. That would be stupid. Fortunately the solution is obvious. > >> > * Every worthwhile creation is worth $1,000 for ten years. > >> > >> Not true by a long shot, and if you don't believe me, you can pay me > >> $1000 right now for ten years' use of any of my free software. > > > > I think he meant it the other way around: If you can sell your software > > for 10 years, you can affort $1000 to have your monopoly protected. > > Except that I'm not selling it. What if I want to give it away, but > with the proviso that the document credits me properly? "Go ahead, use > it, publish it, but keep my name on it" is a common thing for people > to request. And it's toothless [1] without copyright; so if you have > to pay money for the right to be credited, Depends on the details of the law. For example, in most of Europe there is a difference between the "Urheberrecht" (creator's rights) and the "Verwertungsrecht" (exploitation rights) (there are no exact equivalent in English, so I'm using the German words). The former is always bound to the person who created the work and cannot be sold. The latter can (and usually is). The right of a person to be credited could be part of the former. There is also much less incentive to pretend you wrote something you didn't if there is no financial advantage, so it may not be that important. > there's going to be a lot of corporate bullying. I don't really see why there would be more than now. 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 hjp-python at hjp.at Sun Jun 10 18:35:11 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 11 Jun 2018 00:35:11 +0200 Subject: Multiprocessing on a remote host In-Reply-To: References: Message-ID: <20180610223511.5yho7vvos35kzsh5@hjp.at> On 2018-03-21 09:27:37 -0400, Larry Martell wrote: > Yeah, I saw that and I wasn't trying to reinvent the wheel. On this > page https://docs.python.org/2/library/multiprocessing.html it says > this: > > The multiprocessing package offers both local and remote concurrency, > effectively side-stepping the Global Interpreter Lock by using > subprocesses instead of threads. Due to this, the multiprocessing > module allows the programmer to fully leverage multiple processors on > a given machine. > > I took 'remote concurrency' to mean I could use it run a process on > another host. Yes. > But I don't see how to do that, and I was asking if it was possible or > am I misinterpreting the docs. It is described on the same page, a little bit farther down: https://docs.python.org/2/library/multiprocessing.html#using-a-remote-manager 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 bgailer at gmail.com Sun Jun 10 18:39:55 2018 From: bgailer at gmail.com (Bob Gailer) Date: Sun, 10 Jun 2018 18:39:55 -0400 Subject: your mail In-Reply-To: <20180610163050.GC1673@hermes.hilbert.loc> References: <20180610163050.GC1673@hermes.hilbert.loc> Message-ID: On Jun 10, 2018 12:44 PM, "Karsten Hilbert" wrote: > > On Sun, Jun 10, 2018 at 06:58:17PM +0530, sagar daya wrote: > > > Couldn't install any module from pip > > Plz help??? The only help I can give at this point is to suggest that you tell us what you tried and how it failed. Please copy and paste any relevant terminal entries and error messages. No screenshots no attempts to rephrase just the facts. Once we have those we can take the next step. Just out of curiosity did you think there could be any other answer to your question? In the future please think about what you're asking otherwise it cost us time to have to ask you for the information we need got > > https://duckduckgo.com > > kh > -- > -- > https://mail.python.org/mailman/listinfo/python-list From steve+comp.lang.python at pearwood.info Sun Jun 10 19:35:09 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jun 2018 23:35:09 +0000 (UTC) Subject: Sorting NaNs References: <20180602073205.67ihzu52mdan2fqm@hjp.at> <20180602152828.morhwizcuqdmi7sv@hjp.at> Message-ID: On Sun, 10 Jun 2018 21:28:02 +0200, Anders Munch wrote: > Richard Damon wrote: > >> The two behaviors that I have heard suggested are: >> >> 1) If any of the inputs are a NaN, the median should be a NaN. >> (Propagating the NaN as indicator of a numeric error) >> >> 2) Remove the NaNs from the input set and process what is left. If >> nothing, then return a NaN (treating NaN as a 'No Data' placeholder). > > 3) Raise an exception. > > I can't believe anyone even suggested 2).? "In the face of ambiguity, > refuse the temptation to guess." It is not a guess if the user explicitly specifies that as the behaviour. It would be no more of a guess than if the user called data = [x for x in data if not math.isnan(x)] on their data first. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From greg.ewing at canterbury.ac.nz Sun Jun 10 19:47:56 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 11 Jun 2018 11:47:56 +1200 Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: References: <64899b39-ef16-0c74-7a1b-30f49b470c3f@paulstgeorge.com> <77b0d1eb-8b01-e785-4951-6d0a90702ec7@paulstgeorge.com> <5l9qhd90v8bnqra06fimm0p0gu1ee711r6@4ax.com> Message-ID: Dennis Lee Bieber wrote: > Both may be dependent upon the actual hardware graphics board and the > drivers for said board. My guess is that if your surface is not fullscreen or is not a hardware surface, then you're always drawing into an ofscreen buffer that gets copied to the screen when display.flip() is called. In other words, it's effectively double-buffered whether you request it or not. The only time it's an issue is when you're drawing directly to the screen memory, i.e. both FULLSCREEN and HWSURFACE where your hardware and drivers support that. My suggestion is to just always specify DOUBLEBUF and not worry about what's going on behind the scenes. That will almost always give the result you want, i.e. a flicker-free display. The only time it would be an issue is if you wanted your surface to *not* be double-buffered for some reason, but that would be a rare situation. -- Greg From steve+comp.lang.python at pearwood.info Sun Jun 10 19:52:45 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jun 2018 23:52:45 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> Message-ID: On Mon, 11 Jun 2018 06:10:26 +1000, Chris Angelico wrote: > Can you try creating "spam:ham" and "spam/ham"? If they're both legal, > I'd like to see what their file names are represented as. The Finder could very easily be substituting another character, like Konqueror (the KDE 3 file manager) does. In Konqueror, you can create a file named "spam/ham" and it quietly substitutes "spam%2fham" instead. But Konqueror's GUI treats it completely transparently: it is displayed as a slash, and if you copy the file name from the GUI you get a slash. I seem to recall Gnome doing something similar, except it quietly substitutes U+2044 FRACTION SLASH or U+2215 DIVISION SLASH instead. To really be sure what is going on, you would have to bypass the Finder and any shell and write the file name using the OS X low-level API. Or create the file using a classic Mac (system 8 or older), where slashes definitely are not treated as special. Not the Mac OS classic emulation layer. Hmmm... you know I might just be able to do that. Write a file to a floppy, then mount it under Linux. If I had a Linux computer with a floppy disk drive. (The march of technology is sometimes a nuisance.) By the way, for some reason I don't seem to have received Bev's post. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From bellcanadardp at gmail.com Sun Jun 10 19:55:56 2018 From: bellcanadardp at gmail.com (bellcanadardp at gmail.com) Date: Sun, 10 Jun 2018 16:55:56 -0700 (PDT) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <7f780736-291f-4c65-b677-171691e326f7@googlegroups.com> <20180610212936.GA42086@cskk.homeip.net> Message-ID: <3645f804-f32c-43f4-9c52-83b6c2d37629@googlegroups.com> On Sunday, 10 June 2018 17:29:59 UTC-4, Cameron Simpson wrote: > On 10Jun2018 13:04, bellcanadardp at gmail.com wrote: > >here is the full error once again > >to summarize, my script works fine in python2 > >i get this error trying to run it in python3 > >plz see below after the error, my settings for python 2 and python 3 > >for me it seems i need to change some settings to 'utf-8'..either just in python 3, since thats where i am having issues or change the settings to 'utf-8' both in python 2 and 3....i would appreciate feedback b4 i do some trial and error > >thanks for the consideration > >tommy > > > >*********************************************** > >Traceback (most recent call last): > >File "createIndex.py", line 132, in > >c.createindex() > >File "creatIndex.py", line 102, in createIndex > >pagedict=self.parseCollection() > >File "createIndex.py", line 47, in parseCollection > >for line in self.collFile: > >File > >"C:\Users\Robert\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py", > >line 23, in decode > >return codecs.charmap_decode(input,self.errors,decoding_table[0] > >UnicodeDecodeError: 'charmap'codec can't decode byte 0x9d in position 7414: character maps to > > Ok, this is more helpful. It says that the decoding error, which occurred in > ...\cp1252.py, was decoding lines from the file self.collFile. > > What is that file? And how was it opened? > > Also, your settings below may indeed be important. > > >*************************************************** > >python 3 settings > >import sys > > import locale > >locale.getpreferredencoding() > >'cp1252' > > The setting above is the default encoding used when you open a file in text > mode in Python 3, but you can override it. > > In Python 3 this matters a lot, because Python 3 strings are Unicode. In Python > 2, strings are just bytes, and are not "decoded" (there is a whole separate > "unicode" type for that when it matters). > > So in Python 3 the text file reader is decoding the text in the file according > to what it expects the encoding to be. > > Find the place where self.collFile is opened. You can specify the decoding > method there by adding the "encoding=" parameter to the open() call. It is > defaulting to "cp1252" because that is what locale.getpreferredencoding() > returns, but presumably the actual file data are not encoded that way. > > You can (a) find out what encoding _is_ used in the file and specify that or > (b) tell Python to be less picky. Choice (a) is better if it is feasible. > > If you have to guess because you don't know the encoding, one possibility is > that collFile contains utf-8 or utf-16; of these 2, utf-8 seems more likely > given the 0x9d byte causing the trouble. Try adding: > > encoding='utf-8' > > to the open() call, eg: > > self.collFile = open('path-to-the-coll-file', encoding='utf-8') > > at the appropriate place. > > If that just produces a different decoding error, you have 2 choices: pick an > encoding where every byte is "valid", such as 'iso8859-1', or to tell the > decode to just cope with th errors by adding the errors="replace" or > "errors="ignore" or errors="namereplace" parameter to the open() call. > > Both these choices have downsides. > > There are several ISO8859 encodings, and they might all be wrong for your file, > leading to _incorrect_ text lines. > > The errors="..." parameter also has downsides: you will also end up with > missing (errors="ignore") or incorrect (errors="replace" or > errors="namereplace") text, because the decoder has to do something with the > data: drop it or replace it with something wrong. The former loses data while > the latter puts in bad data, but at least it is visible if you inspect the data > later. > > The full documentation for Python 3's open() call is here: > > https://docs.python.org/3/library/functions.html#open > > where the various encoding= and errors= choices are described. > > Cheers, > Cameron Simpson thank you for the reply let me try these tips and suggestions and i will update here thanxz alot and thnxz also to all who post ..i appreciate it.. regards tommy From steve+comp.lang.python at pearwood.info Sun Jun 10 19:59:19 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jun 2018 23:59:19 +0000 (UTC) Subject: Stefan's headers [was:Names and identifiers] References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: On Mon, 11 Jun 2018 06:21:31 +1000, Chris Angelico wrote: [...] > Nice work there. You trimmed key parts of my post, and then responded to > me out of context. Go back and read my actual post, then respond to what > I actually said. Thanks! I didn't trim any part of your post when I read it, but I took away the same message as Greg. Perhaps your point was not as clear as you thought it was. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sun Jun 10 20:03:48 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jun 2018 10:03:48 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> Message-ID: On Mon, Jun 11, 2018 at 9:52 AM, Steven D'Aprano wrote: > On Mon, 11 Jun 2018 06:10:26 +1000, Chris Angelico wrote: > >> Can you try creating "spam:ham" and "spam/ham"? If they're both legal, >> I'd like to see what their file names are represented as. > > The Finder could very easily be substituting another character, like > Konqueror (the KDE 3 file manager) does. In Konqueror, you can create a > file named "spam/ham" and it quietly substitutes "spam%2fham" instead. > But Konqueror's GUI treats it completely transparently: it is displayed > as a slash, and if you copy the file name from the GUI you get a slash. Speculation is all very well, but I was wanting to see what actually happened. :) ChrisA From countryone77 at gmail.com Sun Jun 10 20:22:00 2018 From: countryone77 at gmail.com (Bev in TX) Date: Sun, 10 Jun 2018 19:22:00 -0500 Subject: Why exception from os.path.exists()? In-Reply-To: <886E942E-3D67-41E5-B9F1-D13FD7A7D537@gmail.com> References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <886E942E-3D67-41E5-B9F1-D13FD7A7D537@gmail.com> Message-ID: <734933B3-36DB-4B36-B915-8DBDCE1DF9CA@gmail.com> I accidentally did not send this to the list... > On Jun 10, 2018, at 7:10 PM, Bev in TX wrote: > > >> On Jun 10, 2018, at 3:10 PM, Chris Angelico > wrote: >>> ... >> >> Can you try creating "spam:ham" and "spam/ham"? If they're both legal, >> I'd like to see what their file names are represented as. >> > I dug around and found this very old article, in which it says: > > "Another obvious problem is the different path separators between HFS+ (colon, ':') and UFS (slash, '/'). This also means that HFS+ file names may contain the slash character and not colons, while the opposite is true for UFS file names. This was easy to address, though it involves transforming strings back and forth. The HFS+ implementation in the kernel's VFS layer converts colon to slash and vice versa when reading from and writing to the on-disk format. So on disk the separator is a colon, but at the VFS layer (and therefore anything above it and the kernel, such as libc) it's a slash. However, the traditional Mac OS toolkits expect colons, so above the BSD layer, the core Carbon toolkit does yet another translation. The result is that Carbon applications see colons, and everyone else sees slashes. This can create a user-visible schizophrenia in the rare cases of file names containing colon characters, which appear to Carbon applications as slash characters, but to BSD programs and Cocoa applications as colons.? > > That was from, "USENIX 2000 Invited Talks Presentation? at: > http://www.wsanchez.net/papers/USENIX_2000/ > > Bev in TX From steve+comp.lang.python at pearwood.info Sun Jun 10 20:28:46 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jun 2018 00:28:46 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> Message-ID: On Sun, 10 Jun 2018 22:09:39 +0100, Barry Scott wrote: > Singling out os.path.exists as a special case I do think is reasonable. > All functions that take paths need to have a consistent response to data The *mere existence* of os.path.exists means that there is not a consistent response to file names: open(foo) raises an exception if foo doesn't exist; os.path.exists(foo) returns False if foo doesn't exist. There is no requirement that different functions do the same thing with the same bad input. The *whole point* of o.p.exists is to return False, not raise an exception. > that is impossible to pass to the OS. Even if it were true that file names cannot contain certain characters, and it is not, why is that a distinction that anyone gives a shit about? I do not expect that there are more than a handful of use-cases for distinguishing "file names which cannot be passed to the OS" versus "any other illegal file name". And even that is generous. Besides, it is certainly not true that there are no OSes that can deal with NULs in file names. Classic Mac OS can, as filenames there are represented as Pascal strings (a length byte followed by an array of arbitrary bytes), not NUL-terminated C strings. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sun Jun 10 21:06:37 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jun 2018 01:06:37 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <87efhes55g.fsf@elektro.pacujo.net> <20180610215735.ezrrtdwyskfv4jrj@hjp.at> Message-ID: On Sun, 10 Jun 2018 23:57:35 +0200, Peter J. Holzer wrote: > I think this is worth keeping, and "I couldn't pass that file name to > the OS" is a different error than "the OS told me the file doesn't > exist", so I think it should be a different exception. What makes you think that NUL bytes are a fundamental limitation that no OS could every cope with? Classic Mac OS takes file names as Pascal strings, with a length byte and an array of arbitrary bytes, no NUL terminator required. Despite what far too many C programmers appear to believe, NUL-terminated strings are not a fundamental requirement. Navigating Apple's documentation is a nightmare, but I've found the deprecated Carbon file manager APIs. For example, creating a file with PBCreateFileUnicodeSync: https://developer.apple.com/documentation/coreservices/1566896- pbcreatefileunicodesync?language=objc takes a FSRefParam argument: https://developer.apple.com/documentation/coreservices/fsrefparam? language=objc which includes a name field which is a pointer to an array of Unicode characters, and a separate name length. The evidence suggests that using the Carbon APIs, NUL is just another Unicode character. Whatever API replaces Carbon, it will have to deal with file names created under Carbon, and classic Mac, and so likely will support the same. Baking a limitation of some file systems into the high-level interface is simply a *bad idea*. There is no good reason to treat file names containing NUL as special in the API (even if, for implementation reasons, it has to be treated specially in the implementation). How would you feel if there were a whole lot of ignorant Pascal programmers arguing that it was fundamentally impossible for file names to exceed 255 characters, and therefore os.path.exists() out to raise ValueError when passed a file name of 256 characters? "But it is impossible to pass a string of 256 characters to the OS" is no more foolish than "it is impossible to pass a string with an embedded NUL to the OS". Both are implementation details. Neither should be baked into the high-level language as a fundamental requirement. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sun Jun 10 21:12:24 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jun 2018 11:12:24 +1000 Subject: Why exception from os.path.exists()? In-Reply-To: References: <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <87efhes55g.fsf@elektro.pacujo.net> <20180610215735.ezrrtdwyskfv4jrj@hjp.at> Message-ID: On Mon, Jun 11, 2018 at 11:06 AM, Steven D'Aprano wrote: > On Sun, 10 Jun 2018 23:57:35 +0200, Peter J. Holzer wrote: > >> I think this is worth keeping, and "I couldn't pass that file name to >> the OS" is a different error than "the OS told me the file doesn't >> exist", so I think it should be a different exception. > > What makes you think that NUL bytes are a fundamental limitation that no > OS could every cope with? I didn't say that. If you have an OS that can't handle more than 255 bytes of file name, it's allowed to raise ValueError just the same. ChrisA From steve+comp.lang.python at pearwood.info Mon Jun 11 01:05:22 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jun 2018 05:05:22 +0000 (UTC) Subject: NUL in file names verified [was Re: Why exception from os.path.exists()?] References: <87tvqoghhh.fsf@elektro.pacujo.net> Message-ID: Straight from the horse's mouth, Apple's HFS Plus volumes do indeed support NULs in file names. Quote: Indirect node files exist in a special directory called the metadata directory. This directory exists in the volume's root directory. The name of the metadata directory is four null characters followed by the string "HFS+ Private Data". and: The case-insensitive Unicode string comparison used by HFS Plus and case-insensitive HFSX sorts null characters after all other characters, so the metadata directory will typically be the last item in the root directory. On case-sensitive HFSX volumes, null characters sort before other characters, so the metadata directory will typically be the first item in the root directory. https://developer.apple.com/library/archive/technotes/tn/tn1150.html#HFSPlusNames -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From greg.ewing at canterbury.ac.nz Mon Jun 11 02:28:02 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 11 Jun 2018 18:28:02 +1200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <87in6qs86g.fsf@elektro.pacujo.net> Message-ID: Chris Angelico wrote: > I'd like to find out about that. If it doesn't work, it'll be easily > provable that it can't be done. Using the shell: % touch colonic:name % ls colonic:name % touch slashy/name touch: slashy/name: No such file or directory (It's trying to create a file in a directory called "slashy", which doesn't exist.) Using Python: >>> open("colonic:name", "w").close() >>> os.listdir(".") ['colonic:name'] >>> open("slashy/name", "w").close() Traceback (most recent call last): File "", line 1, in FileNotFoundError: [Errno 2] No such file or directory: 'slashy/name' (Same reason as before.) Using the GUI: I tried to use TextEdit to save a file with a colon in the name. When I typed ":" into the filename box, it substituted "-". I was able to type "slashy/textfile" into the filename box and save. In the shell it shows as: % ls slashy:textfile.rtf Is that proof enough for you? -- Greg From brgrt2 at gmail.com Mon Jun 11 02:38:44 2018 From: brgrt2 at gmail.com (T Berger) Date: Sun, 10 Jun 2018 23:38:44 -0700 (PDT) Subject: Posting warning message In-Reply-To: References: <098dcf1c-c7c2-4617-b53b-82298b2dc458@googlegroups.com> <20180610213833.GA99313@cskk.homeip.net> Message-ID: <08dc4a70-3dc4-4421-893d-832764918150@googlegroups.com> Thanks, everyone, for your suggestions. I didn't respond to your posts earlier because I wasn't notified by email updates. I don't understand why they've stopped coming. I didn't change any settings. From greg.ewing at canterbury.ac.nz Mon Jun 11 02:52:05 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 11 Jun 2018 18:52:05 +1200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> Message-ID: Steven D'Aprano wrote: > Hmmm... you know I might just be able to do that. Write a file to a > floppy, then mount it under Linux. That still might not tell you much. The Linux system will need a filesystem driver that understands the Mac HFS file system, which is what your classic Mac system will be writing. And that driver will have its own way of handling file names with slashes in them, probably by substituting something else. So you still won't know what's actually stored on the disk. The only way to be really sure would be to make a dump of the raw disk contents and go looking for the file name in it. > (The march of technology is sometimes a nuisance.) BTW, another problem there would be if your Mac was old enough, it would be using a variable speed floppy drive, which I doubt any PC-based system would be able to cope with... -- Greg From greg.ewing at canterbury.ac.nz Mon Jun 11 02:58:27 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 11 Jun 2018 18:58:27 +1200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> Message-ID: Steven D'Aprano wrote: > Besides, it is certainly not true that there are no OSes that can deal > with NULs in file names. Classic Mac OS can, as filenames there are > represented as Pascal strings (a length byte followed by an array of > arbitrary bytes), not NUL-terminated C strings. There's even a way you could potentially tell the classic Mac file manager API to create a filename with a colon in it, by using the (volume reference number, directory id, filename) way of specifying a file. I don't know whether it would have succeeded, though -- I suspect it would have rejected such a file name as invalid. -- Greg From greg.ewing at canterbury.ac.nz Mon Jun 11 03:12:26 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 11 Jun 2018 19:12:26 +1200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <87efhes55g.fsf@elektro.pacujo.net> <20180610215735.ezrrtdwyskfv4jrj@hjp.at> Message-ID: Steven D'Aprano wrote: > The evidence suggests that using the Carbon APIs, NUL is just another > Unicode character. Whatever API replaces Carbon, it will have to deal > with file names created under Carbon, and classic Mac, and so likely will > support the same. Thsi raises the interesting quesion of what happens if you use Carbon to create a file name containing a null, and then try to access it throught the BSD API. Does the file become inaccessible? Does the NUL get turned into some kind of escape sequence? -- Greg From greg.ewing at canterbury.ac.nz Mon Jun 11 03:47:18 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 11 Jun 2018 19:47:18 +1200 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: Chris Angelico wrote: > You trimmed key parts of my post, I don't get this "You trimmed my post!!!!!11!" complaint that people make. Trimming a post when replying is the *right* thing to do. Just because someone doesn't quote a certain part of what you wrote, doesn't mean that they didn't read it or ignored it. As I said, I didn't understand what argument you were trying to make, so I may have been mistaken about what you thought were the key parts. If you can point them out, I'll be happy to respond to them. -- Greg From antoon.pardon at vub.be Mon Jun 11 03:55:06 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 11 Jun 2018 09:55:06 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> Message-ID: <9cb577f4-a73e-f268-5c52-cca197533167@vub.be> On 11-06-18 02:28, Steven D'Aprano wrote: > On Sun, 10 Jun 2018 22:09:39 +0100, Barry Scott wrote: > >> Singling out os.path.exists as a special case I do think is reasonable. >> All functions that take paths need to have a consistent response to data > The *mere existence* of os.path.exists means that there is not a > consistent response to file names: > > open(foo) raises an exception if foo doesn't exist; > > os.path.exists(foo) returns False if foo doesn't exist. That is not correct. The path can exist and os.path.exists still return False. > There is no requirement that different functions do the same thing with > the same bad input. The *whole point* of o.p.exists is to return False, > not raise an exception. And the price is that it will not always give the correct answer. -- Antoon Pardon. From barry at barrys-emacs.org Mon Jun 11 04:07:52 2018 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 11 Jun 2018 09:07:52 +0100 Subject: Why exception from os.path.exists()? In-Reply-To: References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> Message-ID: <8543B478-3CED-408C-A60D-29B43DAEABC0@barrys-emacs.org> > On 11 Jun 2018, at 01:28, Steven D'Aprano wrote: > > On Sun, 10 Jun 2018 22:09:39 +0100, Barry Scott wrote: > >> Singling out os.path.exists as a special case I do think is reasonable. >> All functions that take paths need to have a consistent response to data > > The *mere existence* of os.path.exists means that there is not a > consistent response to file names: > > open(foo) raises an exception if foo doesn't exist; > > os.path.exists(foo) returns False if foo doesn't exist. > > There is no requirement that different functions do the same thing with > the same bad input. The *whole point* of o.p.exists is to return False, > not raise an exception. I meant that if you cannot call the OS function then always deal with that error the same way and python does. How the result of the OS call is reported to the user is another matter. returning a bool is fine for a predicate and raising an exception is fine for open etc. > > >> that is impossible to pass to the OS. > > Even if it were true that file names cannot contain certain characters, > and it is not, why is that a distinction that anyone gives a shit about? > > I do not expect that there are more than a handful of use-cases for > distinguishing "file names which cannot be passed to the OS" versus "any > other illegal file name". And even that is generous. > > Besides, it is certainly not true that there are no OSes that can deal > with NULs in file names. Classic Mac OS can, as filenames there are > represented as Pascal strings (a length byte followed by an array of > arbitrary bytes), not NUL-terminated C strings. Any OS that can take NUL would have the string passed with the NUL by python and it would then leave it up to the OS figure out if the NUL is valid. I think the rule is, if python can pass the string faithfully to the OS, then do so, otherwise raise an exception that tells the programmer that they are doing something that the OS does not allow for. Barry From barry at barrys-emacs.org Mon Jun 11 04:10:23 2018 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 11 Jun 2018 09:10:23 +0100 Subject: Why exception from os.path.exists()? In-Reply-To: References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> Message-ID: <0BA5AC7D-D2D9-48C6-A74A-AB03FAF0A6B1@barrys-emacs.org> > On 11 Jun 2018, at 01:03, Chris Angelico wrote: > > On Mon, Jun 11, 2018 at 9:52 AM, Steven D'Aprano > wrote: >> On Mon, 11 Jun 2018 06:10:26 +1000, Chris Angelico wrote: >> >>> Can you try creating "spam:ham" and "spam/ham"? If they're both legal, >>> I'd like to see what their file names are represented as. >> >> The Finder could very easily be substituting another character, like >> Konqueror (the KDE 3 file manager) does. In Konqueror, you can create a >> file named "spam/ham" and it quietly substitutes "spam%2fham" instead. >> But Konqueror's GUI treats it completely transparently: it is displayed >> as a slash, and if you copy the file name from the GUI you get a slash. > > Speculation is all very well, but I was wanting to see what actually > happened. :) As interesting as it is to see the way applications transform user input into filenames its does not affect the API that python presents. Barry From cs at cskk.id.au Mon Jun 11 04:22:57 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 11 Jun 2018 18:22:57 +1000 Subject: Posting warning message In-Reply-To: <08dc4a70-3dc4-4421-893d-832764918150@googlegroups.com> References: <08dc4a70-3dc4-4421-893d-832764918150@googlegroups.com> Message-ID: <20180611082257.GA71991@cskk.homeip.net> On 10Jun2018 23:38, Tamara Berger wrote: >Thanks, everyone, for your suggestions. I didn't respond to your posts earlier because I wasn't notified by email updates. I don't understand why they've stopped coming. I didn't change any settings. Maybe we haven't been CCing you directly, just posting straight back to the list. Did you tick "Automatically subscribe me to email updates when I post to a topic" in the group settings? This is one reason to prefer the mailing list. You can subscribe here: https://mail.python.org/mailman/listinfo/python-list Many of us prefer that to Google Groups. You have the advantage that email messages arrive to your GMail directly, instead of to the group. You can easily file messages from the list into its own folder (in GMail, this is called "apply a label"). Wait for the first message or so and for that message choose GMail's "filter messages like this" action. I like to choose "Apply the label Python" and "Skip the inbox" for such things. Then you'll get a nice little "Python" mail folder in your collection where the list will accumulate. And less spam than the Group. Cheers, Cameron Simpson (formerly cs at zip.com.au) From marko at pacujo.net Mon Jun 11 04:35:02 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 11 Jun 2018 11:35:02 +0300 Subject: Why exception from os.path.exists()? References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <9cb577f4-a73e-f268-5c52-cca197533167@vub.be> Message-ID: <87fu1t3emh.fsf@elektro.pacujo.net> Antoon Pardon : > On 11-06-18 02:28, Steven D'Aprano wrote: >> The *whole point* of o.p.exists is to return False, not raise an >> exception. > > And the price is that it will not always give the correct answer. Yes, but that's still the point of the function's existence. Marko From marko at pacujo.net Mon Jun 11 04:40:15 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 11 Jun 2018 11:40:15 +0300 Subject: Why exception from os.path.exists()? References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <8543B478-3CED-408C-A60D-29B43DAEABC0@barrys-emacs.org> Message-ID: <87bmch3eds.fsf@elektro.pacujo.net> Barry Scott : > I think the rule is, if python can pass the string faithfully to the > OS, then do so, otherwise raise an exception that tells the programmer > that they are doing something that the OS does not allow for. Sure, but few application programmers would think of dealing with the surprising ValueError. If they did, they wouldn't think os.path.exists() had any usefulness. Why write: try: ex = os.path.exists(path) except ValueError: ex = False if not ex: ... instead of: try: os.stat(path) except (OSError, ValueError): ... Marko From mohan4h at gmail.com Mon Jun 11 04:44:19 2018 From: mohan4h at gmail.com (mohan4h at gmail.com) Date: Mon, 11 Jun 2018 01:44:19 -0700 (PDT) Subject: Question : Input after all prompts in python Message-ID: Everyone, I am very new to python. I am trying to achieve the below in it, but i am unable to find suitable documentation to guide me on the same. I want to prompt 3 questions together and then get input for the first question next to question as below. 1. Enter your name : _ 2. Enter your age : 3. Enter your gender : After showing the below prompts, the cursor waits in first question for an input. How to achieve this in python. Please help on the same. Regards Mohan C From Karsten.Hilbert at gmx.net Mon Jun 11 05:27:52 2018 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Mon, 11 Jun 2018 11:27:52 +0200 Subject: Question : Input after all prompts in python In-Reply-To: References: Message-ID: <20180611092752.GB5714@hermes.hilbert.loc> On Mon, Jun 11, 2018 at 01:44:19AM -0700, mohan4h at gmail.com wrote: > I am very new to python. I am trying to achieve the below in it, but i am unable to find suitable documentation to guide me on the same. > > I want to prompt 3 questions together and then get input for the first question next to question as below. > > 1. Enter your name : _ > 2. Enter your age : > 3. Enter your gender : > > After showing the below prompts, the cursor waits in first question for an input. > > How to achieve this in python. Please help on the same. The builtin way is with the tkinter module: https://docs.python.org/3/library/tkinter.html There's also a builtin way to get input from the user without resorting to a UI toolkit https://docs.python.org/3/library/functions.html#input but it will not allow you to (easily) prompt 3 questions *together* and *then* get input for the *first* question *next* to question (emphasis mine) Karsten -- From antoon.pardon at vub.be Mon Jun 11 06:26:37 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 11 Jun 2018 12:26:37 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: <87fu1t3emh.fsf@elektro.pacujo.net> References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <9cb577f4-a73e-f268-5c52-cca197533167@vub.be> <87fu1t3emh.fsf@elektro.pacujo.net> Message-ID: <8b0f4a69-5e03-47e3-bbad-9a5ad5679c20@vub.be> On 11-06-18 10:35, Marko Rauhamaa wrote: > Antoon Pardon : >> On 11-06-18 02:28, Steven D'Aprano wrote: >>> The *whole point* of o.p.exists is to return False, not raise an >>> exception. >> And the price is that it will not always give the correct answer. > Yes, but that's still the point of the function's existence. I find it very strange that the point of a function is to sometimes give incorrect answers. I find it an annoying misnomer. -- Antoon. From hjp-python at hjp.at Mon Jun 11 06:31:09 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 11 Jun 2018 12:31:09 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <87efhes55g.fsf@elektro.pacujo.net> <20180610215735.ezrrtdwyskfv4jrj@hjp.at> Message-ID: <20180611103109.lrn4dwjbleknfo7z@hjp.at> On 2018-06-11 01:06:37 +0000, Steven D'Aprano wrote: > On Sun, 10 Jun 2018 23:57:35 +0200, Peter J. Holzer wrote: [Note: I was talking about os.stat here, not os.path.exists. I agree that os.path.exists (and the other boolean functions) should simply return false] > > I think this is worth keeping, and "I couldn't pass that file name to > > the OS" is a different error than "the OS told me the file doesn't > > exist", so I think it should be a different exception. > > What makes you think that NUL bytes are a fundamental limitation that no > OS could every cope with? What makes you think that I think that? We are talking about platform-specific code here. On POSIX systems, there IS NO WAY to pass a filename with an embedded NUL byte to the OS. On such systems Python MUST NOT simply pass a pointer to the start of the (utf-8 encoded) string to the OS, it must take special action. It could fake an ENOENT error, but that would be confusing in many situations. Therefore it should raise an exception which cannot be confused with an error returned from the OS. > Classic Mac OS takes file names as Pascal strings, with a length byte and > an array of arbitrary bytes, no NUL terminator required. On such a system os.stat would have to check that filename is less than 256 bytes and raise an Exception otherwise. In this case it is even more obvious, because there is no Python structure which it can simply pass to the OS. > Baking a limitation of some file systems into the high-level interface is > simply a *bad idea*. We aren't talking about a high-level interface here. We are talking about low-level code which is just above the OS. THAT code MUST make sure that it calls the OS API with meaningful parameters or not at all. And it should raise an Exception in the latter case. And that exception should not be misleading. > How would you feel if there were a whole lot of ignorant Pascal > programmers arguing that it was fundamentally impossible for file names > to exceed 255 characters, and therefore os.path.exists() out to raise > ValueError when passed a file name of 256 characters? You are barking up the wrong tree here. 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 steve+comp.lang.python at pearwood.info Mon Jun 11 07:16:39 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jun 2018 11:16:39 +0000 (UTC) Subject: Question : Input after all prompts in python References: Message-ID: On Mon, 11 Jun 2018 01:44:19 -0700, mohan4h wrote: > Everyone, > > I am very new to python. I am trying to achieve the below in it, but i > am unable to find suitable documentation to guide me on the same. > > I want to prompt 3 questions together and then get input for the first > question next to question as below. > > 1. Enter your name : _ > 2. Enter your age : > 3. Enter your gender : > > After showing the below prompts, the cursor waits in first question for > an input. How else do you expect to tell the three inputs apart? But okay. print("1. Enter your name :") print("2. Enter your age :") print("3. Enter your gender :") name = input("") age = input("") gender = input("") -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From marko at pacujo.net Mon Jun 11 07:23:42 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 11 Jun 2018 14:23:42 +0300 Subject: Why exception from os.path.exists()? References: <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <87efhes55g.fsf@elektro.pacujo.net> <20180610215735.ezrrtdwyskfv4jrj@hjp.at> <20180611103109.lrn4dwjbleknfo7z@hjp.at> Message-ID: <87602p36td.fsf@elektro.pacujo.net> "Peter J. Holzer" : > On 2018-06-11 01:06:37 +0000, Steven D'Aprano wrote: >> Baking a limitation of some file systems into the high-level >> interface is simply a *bad idea*. > > We aren't talking about a high-level interface here. Call it high-level or not, we *are* talking about an interface ("os.path") whose whole raison d'?tre is abstracting OS specifics from basic pathname processing. > We are talking about low-level code which is just above the OS. THAT > code MUST make sure that it calls the OS API with meaningful > parameters or not at all. And it should raise an Exception in the > latter case. And that exception should not be misleading. I respectfully disagree. You are breaking the illusion os.path seeks to provide. What you are saying, essentially, is that os.path should not exist. Since it does exist and can't be wished away *and* since the trap we are talking about ensnares well-meaning developers, there should be a *practical* defense against accidents, which could be serious. >> How would you feel if there were a whole lot of ignorant Pascal >> programmers arguing that it was fundamentally impossible for file >> names to exceed 255 characters, and therefore os.path.exists() out to >> raise ValueError when passed a file name of 256 characters? > > You are barking up the wrong tree here. I believe the "wrong tree" would want a ValueError to be raised in this situation. Funny thing is, nothing in the os.path.exists() API suggests what kinds of illegal value result in a ValueError and what result in a False. The application developer has no way of guaranteeing a ValueError won't take place. It should normally be possible for an application to avoid a ValueError (or TypeError) if it so chose. Marko From Karsten.Hilbert at gmx.net Mon Jun 11 07:31:34 2018 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Mon, 11 Jun 2018 13:31:34 +0200 Subject: Question : Input after all prompts in python In-Reply-To: References: Message-ID: <20180611113134.GA2539@hermes.hilbert.loc> On Mon, Jun 11, 2018 at 11:16:39AM +0000, Steven D'Aprano wrote: > > I want to prompt 3 questions together and then get input for the first > > question next to question as below. > > > > 1. Enter your name : _ > > 2. Enter your age : > > 3. Enter your gender : > > > > After showing the below prompts, the cursor waits in first question for > > an input. > > How else do you expect to tell the three inputs apart? > > But okay. > > > print("1. Enter your name :") > print("2. Enter your age :") > print("3. Enter your gender :") > name = input("") > age = input("") > gender = input("") That doesn't solve the "next to" part in get input for the first question next to question :) Karsten -- From steve+comp.lang.python at pearwood.info Mon Jun 11 07:59:05 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jun 2018 11:59:05 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <9cb577f4-a73e-f268-5c52-cca197533167@vub.be> Message-ID: On Mon, 11 Jun 2018 09:55:06 +0200, Antoon Pardon wrote: > On 11-06-18 02:28, Steven D'Aprano wrote: [...] >> open(foo) raises an exception if foo doesn't exist; >> >> os.path.exists(foo) returns False if foo doesn't exist. > > That is not correct. The path can exist and os.path.exists still return > False. It is correct. I made no claim about what happens if foo exists. I said only that if it doesn't exist, the function returns False. If you're going to be pedantic, be *right*. Being pedantically wrong is just sad. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From __peter__ at web.de Mon Jun 11 08:14:26 2018 From: __peter__ at web.de (Peter Otten) Date: Mon, 11 Jun 2018 14:14:26 +0200 Subject: Question : Input after all prompts in python References: <20180611113134.GA2539@hermes.hilbert.loc> Message-ID: Karsten Hilbert wrote: > On Mon, Jun 11, 2018 at 11:16:39AM +0000, Steven D'Aprano wrote: > >> > I want to prompt 3 questions together and then get input for the first >> > question next to question as below. >> > >> > 1. Enter your name : _ >> > 2. Enter your age : >> > 3. Enter your gender : >> > >> > After showing the below prompts, the cursor waits in first question for >> > an input. >> >> How else do you expect to tell the three inputs apart? >> >> But okay. >> >> >> print("1. Enter your name :") >> print("2. Enter your age :") >> print("3. Enter your gender :") >> name = input("") >> age = input("") >> gender = input("") > > That doesn't solve the "next to" part in > > get input for the first question next to question > > :) Easy: def up(n): print("\u001b[{}A".format(n), flush=True, end="") def right(n): print("\u001b[{}C".format(n), flush=True, end="") print("1. Enter your name:") print("2. Enter your age:") print("3. Enter your gender:") up(3) right(22) name = input("") right(22) age = input("") right(22) gender = input("") If it doesn't work you are using the wrong terminal ;) From Karsten.Hilbert at gmx.net Mon Jun 11 08:22:24 2018 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Mon, 11 Jun 2018 14:22:24 +0200 Subject: Question : Input after all prompts in python In-Reply-To: References: <20180611113134.GA2539@hermes.hilbert.loc> Message-ID: <20180611122224.GB2539@hermes.hilbert.loc> On Mon, Jun 11, 2018 at 02:14:26PM +0200, Peter Otten wrote: > >> print("1. Enter your name :") > >> print("2. Enter your age :") > >> print("3. Enter your gender :") > >> name = input("") > >> age = input("") > >> gender = input("") > > > > That doesn't solve the "next to" part in > > > > get input for the first question next to question > > Easy: > > def up(n): > print("\u001b[{}A".format(n), flush=True, end="") > > def right(n): > print("\u001b[{}C".format(n), flush=True, end="") > > print("1. Enter your name:") > print("2. Enter your age:") > print("3. Enter your gender:") > up(3) > right(22) > name = input("") > right(22) > age = input("") > right(22) > gender = input("") > > If it doesn't work you are using the wrong terminal ;) Sure, but notice how I said "(easily)" in the original answer ? The above is NOT easy for an OP who has to ask the original question. Karsten -- From steve+comp.lang.python at pearwood.info Mon Jun 11 08:24:54 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jun 2018 12:24:54 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <87efhes55g.fsf@elektro.pacujo.net> <20180610215735.ezrrtdwyskfv4jrj@hjp.at> <20180611103109.lrn4dwjbleknfo7z@hjp.at> Message-ID: On Mon, 11 Jun 2018 12:31:09 +0200, Peter J. Holzer wrote: > On 2018-06-11 01:06:37 +0000, Steven D'Aprano wrote: >> On Sun, 10 Jun 2018 23:57:35 +0200, Peter J. Holzer wrote: > > [Note: I was talking about os.stat here, not os.path.exists. I agree > that os.path.exists (and the other boolean functions) should simply > return false] o_O Well... I don't know what to say. In a thread about os.path.exists, you're talking about os.stat. I see. I don't understand why, but if you want to derail the thread to discuss something else, okay, I'll play along. [...] > We are talking about platform-specific code here. Are we? I thought we were talking about Python and the os module. The very first paragraph of the documentation for os says: This module provides a portable way of using operating system dependent functionality. https://docs.python.org/3/library/os.html It also clearly states: All functions in this module raise OSError in the case of invalid or inaccessible file names and paths, or other arguments that have the correct type, but are not accepted by the operating system. You know... like strings with NUL in them. > On POSIX systems, there IS NO WAY to pass a > filename with an embedded NUL byte to the OS. Mac OS X is certified as POSIX-compliant. As I pointed out in a previous email, OS X also provides APIs that are perfectly capable of dealing with NULs in file names. POSIX specifies a *minimum* set of functionality, not a maximum. > On such systems Python > MUST NOT simply pass a pointer to the start of the (utf-8 encoded) > string to the OS, it must take special action. It could fake an ENOENT > error, but that would be confusing in many situations. Therefore it > should raise an exception which cannot be confused with an error > returned from the OS. I agree that for os.stat, which already raises on error, raising for invalid file names is the right thing to do. As stated in the documentation, the right exception is an OSError, which matches the current behaviour for other impossible and invalid file names: py> os.stat('') Traceback (most recent call last): File "", line 1, in FileNotFoundError: [Errno 2] No such file or directory: '' [...] >> Baking a limitation of some file systems into the high-level interface >> is simply a *bad idea*. > > We aren't talking about a high-level interface here. Yes we are. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From __peter__ at web.de Mon Jun 11 08:52:53 2018 From: __peter__ at web.de (Peter Otten) Date: Mon, 11 Jun 2018 14:52:53 +0200 Subject: Question : Input after all prompts in python References: <20180611113134.GA2539@hermes.hilbert.loc> <20180611122224.GB2539@hermes.hilbert.loc> Message-ID: Karsten Hilbert wrote: > On Mon, Jun 11, 2018 at 02:14:26PM +0200, Peter Otten wrote: > >> >> print("1. Enter your name :") >> >> print("2. Enter your age :") >> >> print("3. Enter your gender :") >> >> name = input("") >> >> age = input("") >> >> gender = input("") >> > >> > That doesn't solve the "next to" part in >> > >> > get input for the first question next to question >> >> Easy: >> >> def up(n): >> print("\u001b[{}A".format(n), flush=True, end="") >> >> def right(n): >> print("\u001b[{}C".format(n), flush=True, end="") >> >> print("1. Enter your name:") >> print("2. Enter your age:") >> print("3. Enter your gender:") >> up(3) >> right(22) >> name = input("") >> right(22) >> age = input("") >> right(22) >> gender = input("") >> >> If it doesn't work you are using the wrong terminal ;) > > Sure, but notice how I said "(easily)" in the original answer ? Actually, no. > The above is NOT easy for an OP who has to ask the original question. If the above hack works in the OP's environment it's certainly as easy as it can get; he just has to copy the up() and right() functions, and maybe adapt the arguments. The learning curve for tkinter or curses is steep by comparison. From antoon.pardon at vub.be Mon Jun 11 08:53:25 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 11 Jun 2018 14:53:25 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <20180604201347.c56ffpeezycoo6ij@hjp.at> <8e0f3e4c-08f5-4a27-7919-92263985d442@vub.be> <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <9cb577f4-a73e-f268-5c52-cca197533167@vub.be> Message-ID: <2348ade0-1a92-2406-2702-c8b4a7af76c9@vub.be> On 11-06-18 13:59, Steven D'Aprano wrote: > On Mon, 11 Jun 2018 09:55:06 +0200, Antoon Pardon wrote: > >> On 11-06-18 02:28, Steven D'Aprano wrote: > [...] >>> open(foo) raises an exception if foo doesn't exist; >>> >>> os.path.exists(foo) returns False if foo doesn't exist. >> That is not correct. The path can exist and os.path.exists still return >> False. > It is correct. I made no claim about what happens if foo exists. I said > only that if it doesn't exist, the function returns False. > > If you're going to be pedantic, be *right*. Being pedantically wrong is > just sad. I can live with that. -- Antoon. From Karsten.Hilbert at gmx.net Mon Jun 11 09:12:45 2018 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Mon, 11 Jun 2018 15:12:45 +0200 Subject: Question : Input after all prompts in python In-Reply-To: References: <20180611113134.GA2539@hermes.hilbert.loc> <20180611122224.GB2539@hermes.hilbert.loc> Message-ID: <20180611131245.GD2539@hermes.hilbert.loc> On Mon, Jun 11, 2018 at 02:52:53PM +0200, Peter Otten wrote: > If the above hack works in the OP's environment it's certainly as easy as it > can get; he just has to copy the up() and right() functions, and maybe adapt > the arguments. > > The learning curve for tkinter or curses is steep by comparison. Agreed. Note that I had a lurking suspicion this whole thing amounts to a homework assignment (which I didn't say, however) ... ;-) Karsten -- From mohan4h at gmail.com Mon Jun 11 10:19:15 2018 From: mohan4h at gmail.com (mohan4h at gmail.com) Date: Mon, 11 Jun 2018 07:19:15 -0700 (PDT) Subject: Question : Input after all prompts in python In-Reply-To: References: <20180611113134.GA2539@hermes.hilbert.loc> <20180611122224.GB2539@hermes.hilbert.loc> <20180611131245.GD2539@hermes.hilbert.loc> Message-ID: On Monday, June 11, 2018 at 9:13:04 PM UTC+8, Karsten Hilbert wrote: > On Mon, Jun 11, 2018 at 02:52:53PM +0200, Peter Otten wrote: > > > If the above hack works in the OP's environment it's certainly as easy as it > > can get; he just has to copy the up() and right() functions, and maybe adapt > > the arguments. > > > > The learning curve for tkinter or curses is steep by comparison. > > Agreed. > > Note that I had a lurking suspicion this whole thing amounts > to a homework assignment (which I didn't say, however) ... ;-) > > Karsten > -- Thanks all for your support, I am a data storage admin by profession, starting to learn python as a hobby. I was just curious to learn this task, since this task is usually tricky in command prompt. BTW i tried the code above, but i encountered a syntax error. print(u"\u001b[{}A".format(n), flush=True, end="") ^ SyntaxError :invalid syntax I m trying this in a centos el7 bash terminal. If i try running as print(u"\u001b[{}A".format(n)) It works but the right function does not move the cursor right. is it possible to achieve the same using sys.stdout.write. Regards Mohan C From steve+comp.lang.python at pearwood.info Mon Jun 11 10:55:44 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jun 2018 14:55:44 +0000 (UTC) Subject: Question : Input after all prompts in python References: <20180611113134.GA2539@hermes.hilbert.loc> <20180611122224.GB2539@hermes.hilbert.loc> <20180611131245.GD2539@hermes.hilbert.loc> Message-ID: On Mon, 11 Jun 2018 07:19:15 -0700, mohan4h wrote: > print(u"\u001b[{}A".format(n), flush=True, end="") > ^ > SyntaxError :invalid syntax My crystal ball tell me you are using Python 2. Is that right? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From wolfgang.maier at biologie.uni-freiburg.de Mon Jun 11 10:57:30 2018 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 11 Jun 2018 16:57:30 +0200 Subject: Question : Input after all prompts in python In-Reply-To: References: <20180611113134.GA2539@hermes.hilbert.loc> <20180611122224.GB2539@hermes.hilbert.loc> <20180611131245.GD2539@hermes.hilbert.loc> Message-ID: <17ce80a3-4d5c-c5fb-b30b-f3b5af132904@biologie.uni-freiburg.de> On 06/11/2018 04:19 PM, mohan4h at gmail.com wrote: > > BTW i tried the code above, but i encountered a syntax error. > > print(u"\u001b[{}A".format(n), flush=True, end="") > ^ > SyntaxError :invalid syntax > That's probably because you have been running it in Python2. Most people here assume you mean Python3 nowadays if you say Python, especially when you ask a beginner's question. From wolfgang.maier at biologie.uni-freiburg.de Mon Jun 11 10:57:30 2018 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 11 Jun 2018 16:57:30 +0200 Subject: Question : Input after all prompts in python In-Reply-To: References: <20180611113134.GA2539@hermes.hilbert.loc> <20180611122224.GB2539@hermes.hilbert.loc> <20180611131245.GD2539@hermes.hilbert.loc> Message-ID: <17ce80a3-4d5c-c5fb-b30b-f3b5af132904@biologie.uni-freiburg.de> On 06/11/2018 04:19 PM, mohan4h at gmail.com wrote: > > BTW i tried the code above, but i encountered a syntax error. > > print(u"\u001b[{}A".format(n), flush=True, end="") > ^ > SyntaxError :invalid syntax > That's probably because you have been running it in Python2. Most people here assume you mean Python3 nowadays if you say Python, especially when you ask a beginner's question. From brgrt2 at gmail.com Mon Jun 11 11:54:33 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Mon, 11 Jun 2018 11:54:33 -0400 Subject: Posting warning message In-Reply-To: <20180611082257.GA71991@cskk.homeip.net> References: <08dc4a70-3dc4-4421-893d-832764918150@googlegroups.com> <20180611082257.GA71991@cskk.homeip.net> Message-ID: I did subscribe to the mailing list, but it opened the floodgates to a torrent of irrelevant emails. I didn't know how to turn the flood off, so I unsubscribed. How do I set the appropriate option? I was just going to post another message to google groups. If you don't mind, I'll ask you now. I got an error message when trying to install pytest. Following the workbook, I typed these 2 lines in the terminal: Last login: Mon Jun 11 11:07:46 on ttys000 192:~ TamaraB$ sudo python3 Password: Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> python3 -m pip install pytest File "", line 1 python3 -m pip install pytest ^ SyntaxError: invalid syntax >>> I know you warned against using the sudo command, but Apple supports using it. What does the "-m" stand for in the line of code? Thanks, Tamara From brgrt2 at gmail.com Mon Jun 11 12:02:15 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Mon, 11 Jun 2018 12:02:15 -0400 Subject: Posting warning message In-Reply-To: <20180611082257.GA71991@cskk.homeip.net> References: <08dc4a70-3dc4-4421-893d-832764918150@googlegroups.com> <20180611082257.GA71991@cskk.homeip.net> Message-ID: Apropos my earlier message: Before I post a question, I search online for an answer. Though I try all combinations of search terms, I get irrelevant results. Do you have a suggestion on how to frame searches? Tamara On Mon, Jun 11, 2018 at 4:32 AM Cameron Simpson wrote: > > On 10Jun2018 23:38, Tamara Berger wrote: > >Thanks, everyone, for your suggestions. I didn't respond to your posts earlier because I wasn't notified by email updates. I don't understand why they've stopped coming. I didn't change any settings. > > Maybe we haven't been CCing you directly, just posting straight back to the > list. Did you tick "Automatically subscribe me to email updates when I post to > a topic" in the group settings? > > This is one reason to prefer the mailing list. You can subscribe here: > > https://mail.python.org/mailman/listinfo/python-list > > Many of us prefer that to Google Groups. You have the advantage that email > messages arrive to your GMail directly, instead of to the group. You can easily > file messages from the list into its own folder (in GMail, this is called > "apply a label"). > > Wait for the first message or so and for that message choose GMail's "filter > messages like this" action. I like to choose "Apply the label Python" and "Skip > the inbox" for such things. Then you'll get a nice little "Python" mail folder > in your collection where the list will accumulate. And less spam than the > Group. > > Cheers, > Cameron Simpson (formerly cs at zip.com.au) From andersjm at stofanet.dk Mon Jun 11 12:09:59 2018 From: andersjm at stofanet.dk (Anders Munch) Date: Mon, 11 Jun 2018 18:09:59 +0200 Subject: Sorting NaNs In-Reply-To: References: <20180602073205.67ihzu52mdan2fqm@hjp.at> <20180602152828.morhwizcuqdmi7sv@hjp.at> Message-ID: Steven D'Aprano: > It is not a guess if the user explicitly specifies that as the behaviour. If that was the context, sure, no problem. - Anders From python at mrabarnett.plus.com Mon Jun 11 12:23:51 2018 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 11 Jun 2018 17:23:51 +0100 Subject: Posting warning message In-Reply-To: References: <08dc4a70-3dc4-4421-893d-832764918150@googlegroups.com> <20180611082257.GA71991@cskk.homeip.net> Message-ID: <991f0121-d369-7de3-f331-c7f2394ba346@mrabarnett.plus.com> On 2018-06-11 16:54, Tamara Berger wrote: > I did subscribe to the mailing list, but it opened the floodgates to a > torrent of irrelevant emails. I didn't know how to turn the flood off, > so I unsubscribed. How do I set the appropriate option? > > I was just going to post another message to google groups. If you > don't mind, I'll ask you now. > > I got an error message when trying to install pytest. Following the > workbook, I typed these 2 lines in the terminal: > > Last login: Mon Jun 11 11:07:46 on ttys000 > 192:~ TamaraB$ sudo python3 > Password: > Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28) > [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> python3 -m pip install pytest > File "", line 1 > python3 -m pip install pytest > ^ > SyntaxError: invalid syntax That should've been typed at the system's prompt, not Python's. >>>> > > I know you warned against using the sudo command, but Apple supports using it. > What does the "-m" stand for in the line of code? > From rosuav at gmail.com Mon Jun 11 14:01:51 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jun 2018 04:01:51 +1000 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: On Mon, Jun 11, 2018 at 6:21 AM, Chris Angelico wrote: > On Sun, Jun 10, 2018 at 11:03 PM, Gregory Ewing > wrote: >> Chris Angelico wrote: >>> >>> You cannot, to >>> my knowledge, publish a game for the PS4 or Xbox 360 without >>> permission from Nintendo or Microsoft. >> >> >> That's because, since we *do* have copyright laws, the >> manufacturers of the consoles are able to make money by >> selling the software as well as the hardware -- and they >> want a monopoly on that source of income. > Nice work there. You trimmed key parts of my post, and then responded > to me out of context. Go back and read my actual post, then respond to > what I actually said. Thanks! The bit you trimmed out was: > If the business model had always been "sell hardware, it comes fully > programmed", what would bring people to try to create third-party > software at all? You're trying to argue against my hypothetical statements about game publishing, and declaring that it's possible to use software to encourage hardware sales. But my point was that, absent copyright and the ability to make money from software, software probably *would not exist*. Tell me, do you go to a car manufacturer and buy the ability to use a third-party dashboard? If the dashboard itself is fundamentally unsaleable, and MUST be given away for free, who other than the original manufacturer will produce one? ChrisA From markos at c2o.pro.br Mon Jun 11 14:43:43 2018 From: markos at c2o.pro.br (Markos) Date: Mon, 11 Jun 2018 15:43:43 -0300 Subject: How to install matplotlib in Debian 9 In-Reply-To: <363cc549-ec13-083d-0746-6bff89406de3@gmail.com> References: <59e29d92-7725-1fff-db1c-7bac94c42c4d@c2o.pro.br> <363cc549-ec13-083d-0746-6bff89406de3@gmail.com> Message-ID: <80cef43a-fad8-c69c-45c8-42034034f727@c2o.pro.br> Em 08-06-2018 20:11, Jim Lee escreveu: > > On 06/08/2018 11:54 AM, Markos wrote: >> Hi, >> >> I'm starting my studies with Python 3 on Debian 9 that I just installed. >> >> I have to install the matplotlib module, but I am in doubt what is >> the difference of the commands: >> >> pip3 install matplotlib >> >> or >> >> apt-get install python3-matplotlib >> >> Is there any difference in the packages which are installed? >> >> Thanks, >> >> Markos >> > It's generally preferable to use your distribution's package manager > (apt-get) to install packages, as you will then receive updates as > they become available.? However, Debian is notorious for having > stale/outdated packages in its repository.? If you need the latest > version of matplotlib, use pip (you'll have to update it manually).? > If you want old but stable, use apt-get. > > -Jim > > Hi Jim, As I prefer more stability than "updability" I will install the package: apt-get install python3-matplotlib Best Regards, Markos From rantingrickjohnson at gmail.com Mon Jun 11 15:17:47 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 11 Jun 2018 12:17:47 -0700 (PDT) Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: <9f203e53-e0db-471a-b6e4-fb193402c351@googlegroups.com> On Monday, June 11, 2018 at 1:02:15 PM UTC-5, Chris Angelico wrote: > You're trying to argue against my hypothetical statements > about game publishing, and declaring that it's possible to > use software to encourage hardware sales. But my point was > that, absent copyright and the ability to make money from > software, software probably *would not exist*. Tell me, do > you go to a car manufacturer and buy the ability to use a > third-party dashboard? If the dashboard itself is > fundamentally unsaleable, and MUST be given away for free, > who other than the original manufacturer will produce one? A dashboard is a horrible analogy. Software and hardware are connected at the _hip_. A more correct analogy to describe the relationship between computer hardware and computer software would be a car and an engine. A car is basically useless without an engine, and likewise for an engine without a car. And yes, there are aftermarket engines sold by third parties and people buy them all the time to replace OEM engines. From rosuav at gmail.com Mon Jun 11 15:57:44 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jun 2018 05:57:44 +1000 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: <9f203e53-e0db-471a-b6e4-fb193402c351@googlegroups.com> References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> <9f203e53-e0db-471a-b6e4-fb193402c351@googlegroups.com> Message-ID: On Tue, Jun 12, 2018 at 5:17 AM, Rick Johnson wrote: > On Monday, June 11, 2018 at 1:02:15 PM UTC-5, Chris Angelico wrote: > >> You're trying to argue against my hypothetical statements >> about game publishing, and declaring that it's possible to >> use software to encourage hardware sales. But my point was >> that, absent copyright and the ability to make money from >> software, software probably *would not exist*. Tell me, do >> you go to a car manufacturer and buy the ability to use a >> third-party dashboard? If the dashboard itself is >> fundamentally unsaleable, and MUST be given away for free, >> who other than the original manufacturer will produce one? > > A dashboard is a horrible analogy. > > Software and hardware are connected at the _hip_. > > A more correct analogy to describe the relationship between > computer hardware and computer software would be a car and > an engine. A car is basically useless without an engine, > and likewise for an engine without a car. > > And yes, there are aftermarket engines sold by third parties > and people buy them all the time to replace OEM engines. In other words: "Your analogy is terrible. Here's a better analogy - one that doesn't work." I think I'll stick to mine, thanks. ChrisA From python at mrabarnett.plus.com Mon Jun 11 16:03:59 2018 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 11 Jun 2018 21:03:59 +0100 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: <9f203e53-e0db-471a-b6e4-fb193402c351@googlegroups.com> References: <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> <9f203e53-e0db-471a-b6e4-fb193402c351@googlegroups.com> Message-ID: <9a62eac9-62ff-77c5-0657-eca6a40e3be7@mrabarnett.plus.com> On 2018-06-11 20:17, Rick Johnson wrote: > On Monday, June 11, 2018 at 1:02:15 PM UTC-5, Chris Angelico wrote: > >> You're trying to argue against my hypothetical statements >> about game publishing, and declaring that it's possible to >> use software to encourage hardware sales. But my point was >> that, absent copyright and the ability to make money from >> software, software probably *would not exist*. Tell me, do >> you go to a car manufacturer and buy the ability to use a >> third-party dashboard? If the dashboard itself is >> fundamentally unsaleable, and MUST be given away for free, >> who other than the original manufacturer will produce one? > > A dashboard is a horrible analogy. > > Software and hardware are connected at the _hip_. > > A more correct analogy to describe the relationship between > computer hardware and computer software would be a car and > an engine. A car is basically useless without an engine, > and likewise for an engine without a car. > I'm going to have to disagree with you there. The engine is also hardware. The software is more like the fuel. > And yes, there are aftermarket engines sold by third parties > and people buy them all the time to replace OEM engines. > It doesn't matter how good the engine is (or how much you've upgraded the processor), because without the fuel (or software) it's just a large paperweight (or room heater). :-) From rtomek at ceti.pl Mon Jun 11 16:42:08 2018 From: rtomek at ceti.pl (Tomasz Rola) Date: Mon, 11 Jun 2018 22:42:08 +0200 Subject: How to install matplotlib in Debian 9 In-Reply-To: <80cef43a-fad8-c69c-45c8-42034034f727@c2o.pro.br> References: <59e29d92-7725-1fff-db1c-7bac94c42c4d@c2o.pro.br> <363cc549-ec13-083d-0746-6bff89406de3@gmail.com> <80cef43a-fad8-c69c-45c8-42034034f727@c2o.pro.br> Message-ID: <20180611204208.GA23459@tau1.ceti.pl> On Mon, Jun 11, 2018 at 03:43:43PM -0300, Markos wrote: > [...] > As I prefer more stability than "updability" I will install the package: > > apt-get install python3-matplotlib > > Best Regards, > Markos Good choice IMHO. The "stable" in Debian is simply "supposed to work without problem". Packages in stable are "old" but in fact they are maintained and updated in case there is a security related bug - so "old" but someone is taking care. For one who is fresh to Python and Debian (as it seems is your case) this means you get a working environment while folks from Debian do their job behind the curtain. I think this is ideal for learning. You do not get the latest software from stable, but you will not need the latest while you learn. Just remember to do this from time to time: aptitude update && aptitude safe-upgrade && aptitude clean or (roughly) equivalent apt-get commands: apt-get update && apt-get -u upgrade && apt-get clean And you should be good. Caveat: Debian (in its stable branch) served me well for many many years until very recently, so my opinion might be a bit biased :-). Stable is very nice for base system, and I always could manually install (i.e. compile from sources) newer version of something on top of this - usually in /opt or /usr/local, so as to keep stable part isolated from my possible errors. I have never used pip, so if you decide so, you may want to make sure it does not mess with the stable part before you run it. The stable part - i.e. the part of the Debian that is maintained with aptitude/apt* commands. Like /usr, /bin, good part of /var etc. HTH -- Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From subhabangalore at gmail.com Mon Jun 11 16:48:47 2018 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Mon, 11 Jun 2018 13:48:47 -0700 (PDT) Subject: Index of entity in List with a Condition Message-ID: <20277b9a-143f-4b43-8cbe-bce908f4668d@googlegroups.com> I have the following sentence, "Donald Trump is the president of United States of America". I am trying to extract the index 'of', not only for single but also for its multi-occurance (if they occur), from the list of words of the string, made by simply splitting the sentence. index1=[index for index, value in enumerate(words) if value == "of"], where words=sentence.split() I could do this part more or less nicely. But I am trying to say if the list of words has the words "United" and "States" and it has "of " in the sentence then the previous word before of is, president. I am confused how may I write this, if any one may help it. Thanking in advance. From cs at cskk.id.au Mon Jun 11 17:42:10 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 12 Jun 2018 07:42:10 +1000 Subject: Posting warning message In-Reply-To: References: Message-ID: <20180611214210.GA68454@cskk.homeip.net> On 11Jun2018 11:54, Tamara Berger wrote: >I did subscribe to the mailing list, but it opened the floodgates to a >torrent of irrelevant emails. I didn't know how to turn the flood off, >so I unsubscribed. How do I set the appropriate option? My personal approach is to add a filter for list messages as soon as they start to arrive. I suggested using GMail's "Filter messages like this" action (under the "More" button up the top) to: - skip the inbox (removes the flood from your inbox) - add the label Python (or python-list or whatever you like) This is getting off topic for Python; we should take this off-list to personal email if you agree. >I was just going to post another message to google groups. If you >don't mind, I'll ask you now. This question wants a separate thread of its own with a distinct subject line. That way people ignoring the current thread (google/groups/email) can see it and respond. Cheers, Cameron Simpson From alister.ware at ntlworld.com Mon Jun 11 18:21:13 2018 From: alister.ware at ntlworld.com (Alister) Date: Mon, 11 Jun 2018 22:21:13 GMT Subject: Stefan's headers [was:Names and identifiers] References: <874licutfy.fsf@elektro.pacujo.net> <9f203e53-e0db-471a-b6e4-fb193402c351@googlegroups.com> <9a62eac9-62ff-77c5-0657-eca6a40e3be7@mrabarnett.plus.com> Message-ID: On Mon, 11 Jun 2018 21:03:59 +0100, MRAB wrote: > On 2018-06-11 20:17, Rick Johnson wrote: >> On Monday, June 11, 2018 at 1:02:15 PM UTC-5, Chris Angelico wrote: >> >>> You're trying to argue against my hypothetical statements about game >>> publishing, and declaring that it's possible to use software to >>> encourage hardware sales. But my point was that, absent copyright and >>> the ability to make money from software, software probably *would not >>> exist*. Tell me, do you go to a car manufacturer and buy the ability >>> to use a third-party dashboard? If the dashboard itself is >>> fundamentally unsaleable, and MUST be given away for free, >>> who other than the original manufacturer will produce one? >> >> A dashboard is a horrible analogy. >> >> Software and hardware are connected at the _hip_. >> >> A more correct analogy to describe the relationship between computer >> hardware and computer software would be a car and an engine. A car is >> basically useless without an engine, >> and likewise for an engine without a car. >> > I'm going to have to disagree with you there. The engine is also > hardware. The software is more like the fuel. > >> And yes, there are aftermarket engines sold by third parties and people >> buy them all the time to replace OEM engines. >> > It doesn't matter how good the engine is (or how much you've upgraded > the processor), because without the fuel (or software) it's just a large > paperweight (or room heater). :-) its a bloody lousy room heater without the fuel to burn & generate heat -- I want to be the white man's brother, not his brother-in-law. -- Martin Luther King, Jr. From rantingrickjohnson at gmail.com Mon Jun 11 18:24:00 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 11 Jun 2018 15:24:00 -0700 (PDT) Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> <9f203e53-e0db-471a-b6e4-fb193402c351@googlegroups.com> <9a62eac9-62ff-77c5-0657-eca6a40e3be7@mrabarnett.plus.com> Message-ID: On Monday, June 11, 2018 at 3:04:14 PM UTC-5, MRAB wrote: > On 2018-06-11 20:17, Rick Johnson wrote: [...] > > A dashboard is a horrible analogy. Software and hardware > > are connected at the _hip_. A more correct analogy to > > describe the relationship between computer hardware and > > computer software would be a car and an engine. A car is > > basically useless without an engine, and likewise for an > > engine without a car. > > > I'm going to have to disagree with you there. The engine is > also hardware. My analogy was not intented to draw direct parallels between car components and computer components. It was intented to underscore the mutual dependancy between them. For example: computers function by combining hardware and software. Likewise, automobiles function by combining a power-plant with a passenger compartment. > The software is more like the fuel. How so? (01) Can energy be extracted from software? (02) If so, at what rate is software depleted as the hardware transforms it into energy? (03) What is the energy potential of... oh... say... a pint of software? (04) Is software a solvent? (05) Does software easily vaporize? (06) What is the flash point of software? (07) What sort of mining processes are required to extract software (or its precursors) from the environment. (08) How much more software do you estimate we can extract? (09) Does the concept of "peak software" have any potential of becoming a toxic political football? (10) Who discovered software? (11) And finally -- and in the interest of safety -- may we have a look at the MSDS sheet for software? > > And yes, there are aftermarket engines sold by third > > parties and people buy them all the time to replace OEM > > engines. > > > It doesn't matter how good the engine is (or how much > you've upgraded the processor), because without the fuel > (or software) it's just a large paperweight (or room > heater). :-) Well, that was kinda my point. No. Wait a sec. Allow me to rephrase. That was _exactly_ my point. :-) From rosuav at gmail.com Mon Jun 11 19:00:57 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jun 2018 09:00:57 +1000 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> <9f203e53-e0db-471a-b6e4-fb193402c351@googlegroups.com> <9a62eac9-62ff-77c5-0657-eca6a40e3be7@mrabarnett.plus.com> Message-ID: On Tue, Jun 12, 2018 at 8:24 AM, Rick Johnson wrote: > On Monday, June 11, 2018 at 3:04:14 PM UTC-5, MRAB wrote: >> The software is more like the fuel. > > How so? > > (01) Can energy be extracted from software? Yes, absolutely. > (02) If so, at what rate is software depleted as the hardware > transforms it into energy? That depends on the efficiency of the hardware involved. Ideally, you should get at least 100 microninjas per bug-free line of code, but cheap third-rate computers may fall a long way short of that. > (03) What is the energy potential of... oh... say... a pint of > software? I'm sorry, that question doesn't make sense. You cannot measure software by the pint. It is sold by weight, not volume. > (04) Is software a solvent? Of course it is! A solvent is something which solves problems. If your software isn't solving problems, what is it for? > (05) Does software easily vaporize? https://en.wikipedia.org/wiki/Vaporware specifically https://en.wikipedia.org/wiki/Half-Life_(series)#Episode_Three > (06) What is the flash point of software? You'd have to ask Macromedia. > (07) What sort of mining processes are required to extract > software (or its precursors) from the environment. I'm not entirely sure, but as soon as you start talking about "mining", graphics card prices go up. Please stop talking about mining. I need to upgrade my video card so I can play Shadow of the Tomb Raider, and I don't want to have to pay a bitcoin for the card. > (08) How much more software do you estimate we can extract? That's a question based on a myth. It was once thought that we would achieve "peak software" and then run out, but as technology improves, we gain the ability to extract more software from the same raw materials. Also, there have been proposals to construct software generation facilities on the moon. Google had grand plans, but they've been deferred for now. > (09) Does the concept of "peak software" have any potential > of becoming a toxic political football? Definitely. See above, though; "peak software" is not actually a thing. That won't stop it becoming a toxic football. > (10) Who discovered software? Nikola Tesla, but Edison got the credit. > (11) And finally -- and in the interest of safety -- may we > have a look at the MSDS sheet for software? Of course! Please remit $100 as a processing fee, and a stamped, self-addressed envelope, to: The Internet (no other address needed; your post office will figure it out) ChrisA From greg.ewing at canterbury.ac.nz Mon Jun 11 19:24:40 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 12 Jun 2018 11:24:40 +1200 Subject: Posting warning message In-Reply-To: References: <08dc4a70-3dc4-4421-893d-832764918150@googlegroups.com> <20180611082257.GA71991@cskk.homeip.net> Message-ID: Tamara Berger wrote: > I typed these 2 lines in the terminal: > > 192:~ TamaraB$ sudo python3 > ... >>>>python3 -m pip install pytest You need to enter this *single* line in the Terminal: sudo python3 -m pip install pytest > What does the "-m" stand for in the line of code? It's a cmmand-line option to the python interpreter telling it to execute a module. (What you did was first launch the Python interpreter and then tell it to run "python3 -m pip install pytest" as a Python statement. But it's not Python code, it's a shell command.) -- Greg From rantingrickjohnson at gmail.com Mon Jun 11 21:03:34 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 11 Jun 2018 18:03:34 -0700 (PDT) Subject: Index of entity in List with a Condition In-Reply-To: <20277b9a-143f-4b43-8cbe-bce908f4668d@googlegroups.com> References: <20277b9a-143f-4b43-8cbe-bce908f4668d@googlegroups.com> Message-ID: <1bf997b7-05d3-44e2-8ce7-8213863f6661@googlegroups.com> subhaba... at gmail.com wrote: > I have the following sentence, > > "Donald Trump is the president of United States of America". > > I am trying to extract the index 'of', not only for single but also > for its multi-occurance (if they occur), from the list of words of the > string, made by simply splitting the sentence. > index1=[index for index, value in enumerate(words) if value == "of"], > where words=sentence.split() > > I could do this part more or less nicely. > > But I am trying to say if the list of words has the words "United" > and "States" and it has "of " in the sentence then the previous > word before of is, president. > > I am confused how may I write this, if any one may help it. > > Thanking in advance. Typically when you ask us to do your homework for you, it is considered bad taste to present the teacher's assignment verbatim and then expect that we will provide a turn-key solution. And although you _did_ provide some sort of "Pythony looking" code, unfortunately the code is poorly formatted. Next time, please try to present your question in a formal, well-though-out manner. Source code should either be executable, or conspicuously labeled as psuedo code. Not because we don't _know_ what pseudo code looks like, but because we can intuit your level of knowledge from the presentation. And i gotta tell ya, this presentation is not exactly screaming valedictorian -- but i digress. Now, as to your problem... Well, first, hold on a second, because, i want to correct your sentence. You presented your target string as: "Donald Trump is the president of United States of America" No-no-no. This sentence seems to be missing a few things. The first is a three letter word. And let's insert that word now... >>> s = "Donald Trump is the president of United States of America" >>> s.index('U') 33 >>> s = s[:33] + 'the ' + s[33:] >>> s 'Donald Trump is the president of the United States of America' Ah yes. You see how much more smoothly that rolls off the ol' tongue? Now, in the interest of public awareness, let's add an addendum, shall we? >>> s += ", who was duly elected to office by the great people of this fine country in a free and open election. And no amount of whining; pouting; sniveling; conspiratorial hoopla; flailing of the arms; the legs; or any combination thereof for that matter; will change the reality that Donald *BIG JOHN* Trump is now the president of this fine country. Seriously folks. It's been an interesting ride. But the circus is over now. Elvis left the building over a _year_ ago. Heck, Jimmy Hoffa has already rolled over in his grave *THREE* times! But most disturbing of all, is that the dozens of emaciated cats trapped in each of your apartments are on the verge of cannibalism (yesh, you forgot about them, didn't you?), and the toxic ammonia fumes are melting the paint off the walls! It's time to go home and lick your wounds folks. Better luck next time. Aloha." Whew! (*wipes brow*) Now that we've gotten all of that out of the way... what was your question again? o_O From brgrt2 at gmail.com Tue Jun 12 01:51:38 2018 From: brgrt2 at gmail.com (T Berger) Date: Mon, 11 Jun 2018 22:51:38 -0700 (PDT) Subject: Posting warning message In-Reply-To: References: <08dc4a70-3dc4-4421-893d-832764918150@googlegroups.com> <20180611082257.GA71991@cskk.homeip.net> Message-ID: On Monday, June 11, 2018 at 7:24:58 PM UTC-4, Gregory Ewing wrote: > Tamara Berger wrote: > > I typed these 2 lines in the terminal: > > > > 192:~ TamaraB$ sudo python3 > > ... > >>>>python3 -m pip install pytest > > You need to enter this *single* line in the Terminal: > > sudo python3 -m pip install pytest > > > What does the "-m" stand for in the line of code? > > It's a cmmand-line option to the python interpreter > telling it to execute a module. > > (What you did was first launch the Python interpreter and > then tell it to run "python3 -m pip install pytest" as a > Python statement. But it's not Python code, it's a shell > command.) > > -- > Greg Thanks, Greg. But I got a permission error. Here is my command at the prompt and the terminal's response. 192:~ TamaraB$ sudo python3 -m pip install pytest Password: The directory '/Users/TamaraB/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/Users/TamaraB/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Requirement already satisfied: pytest in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) Requirement already satisfied: pluggy<0.7,>=0.5 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) Requirement already satisfied: atomicwrites>=1.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) Requirement already satisfied: more-itertools>=4.0.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) Requirement already satisfied: six>=1.10.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) Requirement already satisfied: py>=1.5.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) Requirement already satisfied: attrs>=17.4.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) You are using pip version 9.0.1, however version 10.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. So I'm stuck again. I thought "sudo" was supposed to take care of permissions. Do you have a suggestion? Thanks, Tamara From greg.ewing at canterbury.ac.nz Tue Jun 12 02:32:24 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 12 Jun 2018 18:32:24 +1200 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: Chris Angelico wrote: > The bit you trimmed out was: > >>If the business model had always been "sell hardware, it comes fully >>programmed", what would bring people to try to create third-party >>software at all? Maybe because they want to do things with the machine that the manufacturer didn't anticipate? Maybe they just enjoy programming and do it for fun? Also, the business model doesn't have to be "sell hardware that's fully programmed". It could be just "sell hardware, it runs all this wonderful open source software you can get". > my point was that, absent copyright and > the ability to make money from software, software probably *would not > exist*. There are some historical and present-day facts that don't support that idea. * Software existed in the days before it became seen as something to be sold for money per-copy. Both computer companies and programmers seemed to to all right in that environment. * Currently there exist people who choose to write and distribute software free of charge, even though they could charge for it if they wanted due to copyright laws. * Charging money for copies of software is not the only way to make money from programming. You can charge for support services. You can charge for writing custom one-off software. There are people who make a good living from doing these things. > Tell me, do you go to a car manufacturer and buy the ability > to use a third-party dashboard? If the dashboard itself is > fundamentally unsaleable, and MUST be given away for free, who other > than the original manufacturer will produce one? That's a strained analogy, because there is a substantial per-unit cost for making a dashboard. But if it were possible to make your own dashboard at home with a 3D printer for very little cost, I can well imagine a hobbyist community springing up around designing and making custom dashboards. And if that community got big enough, I can imagine a car company marketing a model that comes without any dashboard, so you can install the dashboard of your choice. Just like there are people that will sell you a computer without any OS, so you can install the OS of your choice. -- Greg From rosuav at gmail.com Tue Jun 12 02:40:47 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jun 2018 16:40:47 +1000 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: On Tue, Jun 12, 2018 at 4:32 PM, Gregory Ewing wrote: > There are some historical and present-day facts that don't > support that idea. > > * Software existed in the days before it became seen as > something to be sold for money per-copy. Both computer > companies and programmers seemed to to all right in that > environment. Third-party software? Can you give examples? It doesn't count if the same organization (company, etc) created the hardware and the programming. It also doesn't count if it's hobbyists reprogramming their own units. I'm looking for examples of *third-party* software, of the sort that can today be saleable, but which - in this proposed alternate universe where copyright does not exist - would by force be given away for nothing. ChrisA From steve+comp.lang.python at pearwood.info Tue Jun 12 03:07:50 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 12 Jun 2018 07:07:50 +0000 (UTC) Subject: Stefan's headers [was:Names and identifiers] References: <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: On Tue, 12 Jun 2018 16:40:47 +1000, Chris Angelico wrote: > On Tue, Jun 12, 2018 at 4:32 PM, Gregory Ewing > wrote: >> There are some historical and present-day facts that don't support that >> idea. >> >> * Software existed in the days before it became seen as something to be >> sold for money per-copy. Both computer companies and programmers seemed >> to to all right in that environment. > > Third-party software? Can you give examples? > > It doesn't count if the same organization (company, etc) created the > hardware and the programming. It also doesn't count if it's hobbyists > reprogramming their own units. Why not? Historically, that's exactly where the software industry started. Commercial third-party software didn't exist until long after the software industry was well-established in the business market, and when the home computer industry began, the same process occurred again: the commercial third-party software market followed long afterwards, driven on the back of hobbyists writing their own software and sharing it around. > I'm looking for examples of *third-party* > software, of the sort that can today be saleable, but which - in this > proposed alternate universe where copyright does not exist - would by > force be given away for nothing. Ah, its one of *those* challenges... "If we ignore all the facts that refutes my position, I challenge you to find a fact that refutes my position!" *wink* I don't think there would be any doubt that, minus copyright laws, the commercial third-party software industry would probably be much smaller. The biggest threat wouldn't be piracy in the "you wouldn't download a car" sense, but competitors mass duplicating your product and selling it more cheaply. But even there, historically we've seen that consumers in Western countries will pirate software for free, they'll pay full price, but the majority won't pay for pirated software even if its cheaper. So its not clear that lack of copyright would necessarily have killed the commercial third-party software industry stone dead. But to jump from there to the conclusion that there would be user- generated software, no open source software, no public domain software, no corporate or academic in-house software, no freeware, no shareware, no hobbyist software, no freemium or advertising driven software or SAAS... that's a mighty big leap. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From cs at cskk.id.au Tue Jun 12 03:28:14 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 12 Jun 2018 17:28:14 +1000 Subject: Posting warning message In-Reply-To: References: Message-ID: <20180612072814.GA84354@cskk.homeip.net> On 11Jun2018 22:51, Tamara Berger wrote: >On Monday, June 11, 2018 at 7:24:58 PM UTC-4, Gregory Ewing wrote: >> Tamara Berger wrote: >> > I typed these 2 lines in the terminal: >> > 192:~ TamaraB$ sudo python3 >> >>>>python3 -m pip install pytest >> >> You need to enter this *single* line in the Terminal: >> sudo python3 -m pip install pytest >> >> > What does the "-m" stand for in the line of code? >> It's a cmmand-line option to the python interpreter >> telling it to execute a module. > >Thanks, Greg. But I got a permission error. Here is my command at the prompt and the terminal's response. > >192:~ TamaraB$ sudo python3 -m pip install pytest >Password: >The directory '/Users/TamaraB/Library/Caches/pip/http' or its parent directory >is not owned by the current user and the cache has been disabled. Please check >the permissions and owner of that directory. If executing pip with sudo, you >may want sudo's -H flag. sudo leaves the $HOME environment variable unchanged, at least on my Mac. So it is using your personal cache directory. And rejecting it becuse it is (correctly) owned by you. >The directory '/Users/TamaraB/Library/Caches/pip' or its parent directory is >not owned by the current user and caching wheels has been disabled. check the >permissions and owner of that directory. If executing pip with sudo, you may >want sudo's -H flag. Have a look at the sudo command's manual page, by running the command: man sudo In that we can read this: -H The -H (HOME) option option sets the HOME environment variable to the home directory of the target user (root by default) as specified by the password database. The default handling of the HOME environment variable depends on sudoers(5) settings. By default, sudo will set HOME if env_reset or always_set_home are set, or if set_home is set and the -s option is specified on the command line. So the message is a reasonable suggestion, and it is suggesting that you run this command: sudo -H python3 -m pip install pytest Regarding the other messages: >Requirement already satisfied: pytest in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages >Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) >Requirement already satisfied: pluggy<0.7,>=0.5 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) >Requirement already satisfied: atomicwrites>=1.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) >Requirement already satisfied: more-itertools>=4.0.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) >Requirement already satisfied: six>=1.10.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) >Requirement already satisfied: py>=1.5.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) >Requirement already satisfied: attrs>=17.4.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) This is all fine - it is just saying that various prerequisites are already there. >You are using pip version 9.0.1, however version 10.0.1 is available. >You should consider upgrading via the 'pip install --upgrade pip' command. This is just a suggestion to upgrade pip. Since you're running pip from Python's "pip" builtin module this effectively suggests upgrading your Python 3 install. Not important or urgent. >So I'm stuck again. I thought "sudo" was supposed to take care of permissions. >Do you have a suggestion? Sudo isn't magic, and treating it like magic is very common, which is one reason I discourage unthinking use of it. Sudo exists to let your run specific commands as root, the system superuser. (It also has modes to run as other users, but root is the default and also the most dangerous.) When you use sudo you have almost unlimited power to change things. This is handy for installation activities, and also handy for doing unbound damage to the OS install. I still recommend that you avoid sudo here and use pip's --user option, installing the packages in your personal Python tree. It will work just as well for almost every purpose and avoid risk to your machine's OS. Cheers, Cameron Simpson From marko at pacujo.net Tue Jun 12 04:33:54 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 12 Jun 2018 11:33:54 +0300 Subject: Stefan's headers [was:Names and identifiers] References: <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: <87r2lc1k0d.fsf@elektro.pacujo.net> Gregory Ewing : > * Charging money for copies of software is not the only way to make > money from programming. You can charge for support services. You can > charge for writing custom one-off software. There are people who make > a good living from doing these things. Maybe so. It can't be denied, though, that there are business models that would collapse without copyright laws. So be it. If your business model doesn't work, do something else. The society is not responsible for upholding a particular business model. The only relevant question is, is society gaining or losing by sustaining copyright protections? This is not a question of any fundamental individual rights. Marko From bc at freeuk.com Tue Jun 12 07:37:15 2018 From: bc at freeuk.com (Bart) Date: Tue, 12 Jun 2018 12:37:15 +0100 Subject: Question : Input after all prompts in python In-Reply-To: References: Message-ID: On 11/06/2018 12:16, Steven D'Aprano wrote: > On Mon, 11 Jun 2018 01:44:19 -0700, mohan4h wrote: > >> Everyone, >> >> I am very new to python. I am trying to achieve the below in it, but i >> am unable to find suitable documentation to guide me on the same. >> >> I want to prompt 3 questions together and then get input for the first >> question next to question as below. >> >> 1. Enter your name : _ >> 2. Enter your age : >> 3. Enter your gender : >> >> After showing the below prompts, the cursor waits in first question for >> an input. > > How else do you expect to tell the three inputs apart? > > But okay. > > > print("1. Enter your name :") > print("2. Enter your age :") > print("3. Enter your gender :") > name = input("") > age = input("") > gender = input("") This will do the job, eventually: print("1. Enter your name :") print("2. Enter your age :") print("3. Enter your gender :") name = input("") age = input("") gender = input("") print("1. Enter your name :",name) print("2. Enter your age :",age) print("3. Enter your gender :",gender) -- bart From brgrt2 at gmail.com Tue Jun 12 09:49:22 2018 From: brgrt2 at gmail.com (T Berger) Date: Tue, 12 Jun 2018 06:49:22 -0700 (PDT) Subject: Posting warning message In-Reply-To: References: <20180612072814.GA84354@cskk.homeip.net> Message-ID: <6303efb2-3a34-4893-a474-f18e67696234@googlegroups.com> On Tuesday, June 12, 2018 at 3:28:29 AM UTC-4, Cameron Simpson wrote: > On 11Jun2018 22:51, Tamara Berger wrote: > >On Monday, June 11, 2018 at 7:24:58 PM UTC-4, Gregory Ewing wrote: > >> Tamara Berger wrote: > >> > I typed these 2 lines in the terminal: > >> > 192:~ TamaraB$ sudo python3 > >> >>>>python3 -m pip install pytest > >> > >> You need to enter this *single* line in the Terminal: > >> sudo python3 -m pip install pytest > >> > >> > What does the "-m" stand for in the line of code? > >> It's a cmmand-line option to the python interpreter > >> telling it to execute a module. > > > >Thanks, Greg. But I got a permission error. Here is my command at the prompt and the terminal's response. > > > >192:~ TamaraB$ sudo python3 -m pip install pytest > >Password: > >The directory '/Users/TamaraB/Library/Caches/pip/http' or its parent directory > >is not owned by the current user and the cache has been disabled. Please check > >the permissions and owner of that directory. If executing pip with sudo, you > >may want sudo's -H flag. > > sudo leaves the $HOME environment variable unchanged, at least on my Mac. So it > is using your personal cache directory. And rejecting it becuse it is > (correctly) owned by you. > > >The directory '/Users/TamaraB/Library/Caches/pip' or its parent directory is > >not owned by the current user and caching wheels has been disabled. check the > >permissions and owner of that directory. If executing pip with sudo, you may > >want sudo's -H flag. > > Have a look at the sudo command's manual page, by running the command: > > man sudo > > In that we can read this: > > -H The -H (HOME) option option sets the HOME environment > variable to the home directory of the target user (root by > default) as specified by the password database. The > default handling of the HOME environment variable depends > on sudoers(5) settings. By default, sudo will set HOME if > env_reset or always_set_home are set, or if set_home is > set and the -s option is specified on the command line. > > So the message is a reasonable suggestion, and it is suggesting that you run > this command: > > sudo -H python3 -m pip install pytest > > Regarding the other messages: > > >Requirement already satisfied: pytest in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages > >Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: pluggy<0.7,>=0.5 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: atomicwrites>=1.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: more-itertools>=4.0.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: six>=1.10.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: py>=1.5.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: attrs>=17.4.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > > This is all fine - it is just saying that various prerequisites are already > there. > > >You are using pip version 9.0.1, however version 10.0.1 is available. > >You should consider upgrading via the 'pip install --upgrade pip' command. > > This is just a suggestion to upgrade pip. Since you're running pip from > Python's "pip" builtin module this effectively suggests upgrading your Python 3 > install. Not important or urgent. > > >So I'm stuck again. I thought "sudo" was supposed to take care of permissions. > >Do you have a suggestion? > > Sudo isn't magic, and treating it like magic is very common, which is one > reason I discourage unthinking use of it. > > Sudo exists to let your run specific commands as root, the system superuser. > (It also has modes to run as other users, but root is the default and also the > most dangerous.) > > When you use sudo you have almost unlimited power to change things. This is > handy for installation activities, and also handy for doing unbound damage to > the OS install. > > I still recommend that you avoid sudo here and use pip's --user option, > installing the packages in your personal Python tree. It will work just as well > for almost every purpose and avoid risk to your machine's OS. > > Cheers, > Cameron Simpson Thanks a lot, Cameron. I was going to try the --user option this morning, if no one had responded to my post. From brgrt2 at gmail.com Tue Jun 12 09:50:25 2018 From: brgrt2 at gmail.com (T Berger) Date: Tue, 12 Jun 2018 06:50:25 -0700 (PDT) Subject: Posting warning message In-Reply-To: References: <08dc4a70-3dc4-4421-893d-832764918150@googlegroups.com> <20180611082257.GA71991@cskk.homeip.net> Message-ID: <601dd483-52b1-45f1-a093-aea4ef4e9cf8@googlegroups.com> On Monday, June 11, 2018 at 7:24:58 PM UTC-4, Gregory Ewing wrote: > Tamara Berger wrote: > > I typed these 2 lines in the terminal: > > > > 192:~ TamaraB$ sudo python3 > > ... > >>>>python3 -m pip install pytest > > You need to enter this *single* line in the Terminal: > > sudo python3 -m pip install pytest > > > What does the "-m" stand for in the line of code? > > It's a cmmand-line option to the python interpreter > telling it to execute a module. > > (What you did was first launch the Python interpreter and > then tell it to run "python3 -m pip install pytest" as a > Python statement. But it's not Python code, it's a shell > command.) > > -- > Greg Thanks, Greg, for your answer. It helped me out of that hole. From mohan4h at gmail.com Tue Jun 12 10:12:42 2018 From: mohan4h at gmail.com (mohan4h at gmail.com) Date: Tue, 12 Jun 2018 07:12:42 -0700 (PDT) Subject: Question : Input after all prompts in python In-Reply-To: References: Message-ID: <307f0914-d444-47e3-a474-9e60f8069d09@googlegroups.com> On Tuesday, June 12, 2018 at 7:37:25 PM UTC+8, Bart wrote: > On 11/06/2018 12:16, Steven D'Aprano wrote: > > On Mon, 11 Jun 2018 01:44:19 -0700, mohan4h wrote: > > > >> Everyone, > >> > >> I am very new to python. I am trying to achieve the below in it, but i > >> am unable to find suitable documentation to guide me on the same. > >> > >> I want to prompt 3 questions together and then get input for the first > >> question next to question as below. > >> > >> 1. Enter your name : _ > >> 2. Enter your age : > >> 3. Enter your gender : > >> > >> After showing the below prompts, the cursor waits in first question for > >> an input. > > > > How else do you expect to tell the three inputs apart? > > > > But okay. > > > > > > print("1. Enter your name :") > > print("2. Enter your age :") > > print("3. Enter your gender :") > > name = input("") > > age = input("") > > gender = input("") > > This will do the job, eventually: > > print("1. Enter your name :") > print("2. Enter your age :") > print("3. Enter your gender :") > name = input("") > age = input("") > gender = input("") > > print("1. Enter your name :",name) > print("2. Enter your age :",age) > print("3. Enter your gender :",gender) > > -- > bart Everyone, I want to thank you all for your support, As advised Steven D'Aprano and Wolfgang Maier, I tried the same code in python3 and it worked like a wonder. I would like to thank Peter Otten for the solution. I learned something new. Thanks for all your support. Regards Mohan C From brgrt2 at gmail.com Tue Jun 12 10:14:53 2018 From: brgrt2 at gmail.com (T Berger) Date: Tue, 12 Jun 2018 07:14:53 -0700 (PDT) Subject: Posting warning message In-Reply-To: References: <20180612072814.GA84354@cskk.homeip.net> Message-ID: <2f713a93-d650-4764-8389-3e9e06cd82f3@googlegroups.com> On Tuesday, June 12, 2018 at 3:28:29 AM UTC-4, Cameron Simpson wrote: > On 11Jun2018 22:51, Tamara Berger wrote: > >On Monday, June 11, 2018 at 7:24:58 PM UTC-4, Gregory Ewing wrote: > >> Tamara Berger wrote: > >> > I typed these 2 lines in the terminal: > >> > 192:~ TamaraB$ sudo python3 > >> >>>>python3 -m pip install pytest > >> > >> You need to enter this *single* line in the Terminal: > >> sudo python3 -m pip install pytest > >> > >> > What does the "-m" stand for in the line of code? > >> It's a cmmand-line option to the python interpreter > >> telling it to execute a module. > > > >Thanks, Greg. But I got a permission error. Here is my command at the prompt and the terminal's response. > > > >192:~ TamaraB$ sudo python3 -m pip install pytest > >Password: > >The directory '/Users/TamaraB/Library/Caches/pip/http' or its parent directory > >is not owned by the current user and the cache has been disabled. Please check > >the permissions and owner of that directory. If executing pip with sudo, you > >may want sudo's -H flag. > > sudo leaves the $HOME environment variable unchanged, at least on my Mac. So it > is using your personal cache directory. And rejecting it becuse it is > (correctly) owned by you. > > >The directory '/Users/TamaraB/Library/Caches/pip' or its parent directory is > >not owned by the current user and caching wheels has been disabled. check the > >permissions and owner of that directory. If executing pip with sudo, you may > >want sudo's -H flag. > > Have a look at the sudo command's manual page, by running the command: > > man sudo > > In that we can read this: > > -H The -H (HOME) option option sets the HOME environment > variable to the home directory of the target user (root by > default) as specified by the password database. The > default handling of the HOME environment variable depends > on sudoers(5) settings. By default, sudo will set HOME if > env_reset or always_set_home are set, or if set_home is > set and the -s option is specified on the command line. > > So the message is a reasonable suggestion, and it is suggesting that you run > this command: > > sudo -H python3 -m pip install pytest > > Regarding the other messages: > > >Requirement already satisfied: pytest in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages > >Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: pluggy<0.7,>=0.5 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: atomicwrites>=1.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: more-itertools>=4.0.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: six>=1.10.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: py>=1.5.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: attrs>=17.4.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > > This is all fine - it is just saying that various prerequisites are already > there. > > >You are using pip version 9.0.1, however version 10.0.1 is available. > >You should consider upgrading via the 'pip install --upgrade pip' command. > > This is just a suggestion to upgrade pip. Since you're running pip from > Python's "pip" builtin module this effectively suggests upgrading your Python 3 > install. Not important or urgent. > > >So I'm stuck again. I thought "sudo" was supposed to take care of permissions. > >Do you have a suggestion? > > Sudo isn't magic, and treating it like magic is very common, which is one > reason I discourage unthinking use of it. > > Sudo exists to let your run specific commands as root, the system superuser. > (It also has modes to run as other users, but root is the default and also the > most dangerous.) > > When you use sudo you have almost unlimited power to change things. This is > handy for installation activities, and also handy for doing unbound damage to > the OS install. > > I still recommend that you avoid sudo here and use pip's --user option, > installing the packages in your personal Python tree. It will work just as well > for almost every purpose and avoid risk to your machine's OS. > > Cheers, > Cameron Simpson Just one more thing, Cameron. I was looking at an Apple support page, and it says "When you're logged in to your Mac using an administrator account, you can use the sudo command in the Terminal app to execute commands as a different user, such as the root user." (https://support.apple.com/en-us/HT202035). I am logged in as administrator. So why isn't sudo working for me? Tamara P.S. How would I make the link I provided live? From brgrt2 at gmail.com Tue Jun 12 10:17:10 2018 From: brgrt2 at gmail.com (T Berger) Date: Tue, 12 Jun 2018 07:17:10 -0700 (PDT) Subject: Posting warning message In-Reply-To: References: <20180612072814.GA84354@cskk.homeip.net> Message-ID: <177de5bd-f883-4188-b689-830f3398216c@googlegroups.com> On Tuesday, June 12, 2018 at 3:28:29 AM UTC-4, Cameron Simpson wrote: > On 11Jun2018 22:51, Tamara Berger wrote: > >On Monday, June 11, 2018 at 7:24:58 PM UTC-4, Gregory Ewing wrote: > >> Tamara Berger wrote: > >> > I typed these 2 lines in the terminal: > >> > 192:~ TamaraB$ sudo python3 > >> >>>>python3 -m pip install pytest > >> > >> You need to enter this *single* line in the Terminal: > >> sudo python3 -m pip install pytest > >> > >> > What does the "-m" stand for in the line of code? > >> It's a cmmand-line option to the python interpreter > >> telling it to execute a module. > > > >Thanks, Greg. But I got a permission error. Here is my command at the prompt and the terminal's response. > > > >192:~ TamaraB$ sudo python3 -m pip install pytest > >Password: > >The directory '/Users/TamaraB/Library/Caches/pip/http' or its parent directory > >is not owned by the current user and the cache has been disabled. Please check > >the permissions and owner of that directory. If executing pip with sudo, you > >may want sudo's -H flag. > > sudo leaves the $HOME environment variable unchanged, at least on my Mac. So it > is using your personal cache directory. And rejecting it becuse it is > (correctly) owned by you. > > >The directory '/Users/TamaraB/Library/Caches/pip' or its parent directory is > >not owned by the current user and caching wheels has been disabled. check the > >permissions and owner of that directory. If executing pip with sudo, you may > >want sudo's -H flag. > > Have a look at the sudo command's manual page, by running the command: > > man sudo > > In that we can read this: > > -H The -H (HOME) option option sets the HOME environment > variable to the home directory of the target user (root by > default) as specified by the password database. The > default handling of the HOME environment variable depends > on sudoers(5) settings. By default, sudo will set HOME if > env_reset or always_set_home are set, or if set_home is > set and the -s option is specified on the command line. > > So the message is a reasonable suggestion, and it is suggesting that you run > this command: > > sudo -H python3 -m pip install pytest > > Regarding the other messages: > > >Requirement already satisfied: pytest in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages > >Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: pluggy<0.7,>=0.5 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: atomicwrites>=1.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: more-itertools>=4.0.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: six>=1.10.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: py>=1.5.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: attrs>=17.4.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > > This is all fine - it is just saying that various prerequisites are already > there. > > >You are using pip version 9.0.1, however version 10.0.1 is available. > >You should consider upgrading via the 'pip install --upgrade pip' command. > > This is just a suggestion to upgrade pip. Since you're running pip from > Python's "pip" builtin module this effectively suggests upgrading your Python 3 > install. Not important or urgent. > > >So I'm stuck again. I thought "sudo" was supposed to take care of permissions. > >Do you have a suggestion? > > Sudo isn't magic, and treating it like magic is very common, which is one > reason I discourage unthinking use of it. > > Sudo exists to let your run specific commands as root, the system superuser. > (It also has modes to run as other users, but root is the default and also the > most dangerous.) > > When you use sudo you have almost unlimited power to change things. This is > handy for installation activities, and also handy for doing unbound damage to > the OS install. > > I still recommend that you avoid sudo here and use pip's --user option, > installing the packages in your personal Python tree. It will work just as well > for almost every purpose and avoid risk to your machine's OS. > > Cheers, > Cameron Simpson Sorry, to bother you again. But is there some way to edit a message once its posted? Or do I have to delete it and rewrite it? From rosuav at gmail.com Tue Jun 12 10:26:44 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jun 2018 00:26:44 +1000 Subject: Posting warning message In-Reply-To: <177de5bd-f883-4188-b689-830f3398216c@googlegroups.com> References: <20180612072814.GA84354@cskk.homeip.net> <177de5bd-f883-4188-b689-830f3398216c@googlegroups.com> Message-ID: On Wed, Jun 13, 2018 at 12:17 AM, T Berger wrote: > > Sorry, to bother you again. But is there some way to edit a message once its posted? Or do I have to delete it and rewrite it? Nope. And you can't delete it either. ChrisA From brgrt2 at gmail.com Tue Jun 12 10:45:58 2018 From: brgrt2 at gmail.com (T Berger) Date: Tue, 12 Jun 2018 07:45:58 -0700 (PDT) Subject: Filters Message-ID: <57e2e5cf-3d17-4127-ba0b-16eaea1ab4e8@googlegroups.com> Why doesn't the system allow me to set filters for my own posts? I was able to do it once, but when I returned to the forum, I was back among the unfiltered posts. When I tried to reapply the filter, the option was grayed out. Also, I've selected the option to get email updates to my posts, but the option seems to work only selectively. From brgrt2 at gmail.com Tue Jun 12 10:48:07 2018 From: brgrt2 at gmail.com (T Berger) Date: Tue, 12 Jun 2018 07:48:07 -0700 (PDT) Subject: Posting warning message In-Reply-To: References: <20180612072814.GA84354@cskk.homeip.net> <177de5bd-f883-4188-b689-830f3398216c@googlegroups.com> Message-ID: On Tuesday, June 12, 2018 at 10:27:06 AM UTC-4, Chris Angelico wrote: > On Wed, Jun 13, 2018 at 12:17 AM, T Berger wrote: > > > > Sorry, to bother you again. But is there some way to edit a message once its posted? Or do I have to delete it and rewrite it? > > Nope. And you can't delete it either. > > ChrisA I deleted them a number of time, then got a bar across the page indicating that a post had been deleted. It's nuts that you can't edit your own post. From brgrt2 at gmail.com Tue Jun 12 10:51:15 2018 From: brgrt2 at gmail.com (T Berger) Date: Tue, 12 Jun 2018 07:51:15 -0700 (PDT) Subject: Posting warning message In-Reply-To: References: <20180612072814.GA84354@cskk.homeip.net> Message-ID: On Tuesday, June 12, 2018 at 3:28:29 AM UTC-4, Cameron Simpson wrote: > On 11Jun2018 22:51, Tamara Berger wrote: > >On Monday, June 11, 2018 at 7:24:58 PM UTC-4, Gregory Ewing wrote: > >> Tamara Berger wrote: > >> > I typed these 2 lines in the terminal: > >> > 192:~ TamaraB$ sudo python3 > >> >>>>python3 -m pip install pytest > >> > >> You need to enter this *single* line in the Terminal: > >> sudo python3 -m pip install pytest > >> > >> > What does the "-m" stand for in the line of code? > >> It's a cmmand-line option to the python interpreter > >> telling it to execute a module. > > > >Thanks, Greg. But I got a permission error. Here is my command at the prompt and the terminal's response. > > > >192:~ TamaraB$ sudo python3 -m pip install pytest > >Password: > >The directory '/Users/TamaraB/Library/Caches/pip/http' or its parent directory > >is not owned by the current user and the cache has been disabled. Please check > >the permissions and owner of that directory. If executing pip with sudo, you > >may want sudo's -H flag. > > sudo leaves the $HOME environment variable unchanged, at least on my Mac. So it > is using your personal cache directory. And rejecting it becuse it is > (correctly) owned by you. > > >The directory '/Users/TamaraB/Library/Caches/pip' or its parent directory is > >not owned by the current user and caching wheels has been disabled. check the > >permissions and owner of that directory. If executing pip with sudo, you may > >want sudo's -H flag. > > Have a look at the sudo command's manual page, by running the command: > > man sudo > > In that we can read this: > > -H The -H (HOME) option option sets the HOME environment > variable to the home directory of the target user (root by > default) as specified by the password database. The > default handling of the HOME environment variable depends > on sudoers(5) settings. By default, sudo will set HOME if > env_reset or always_set_home are set, or if set_home is > set and the -s option is specified on the command line. > > So the message is a reasonable suggestion, and it is suggesting that you run > this command: > > sudo -H python3 -m pip install pytest > > Regarding the other messages: > > >Requirement already satisfied: pytest in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages > >Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: pluggy<0.7,>=0.5 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: atomicwrites>=1.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: more-itertools>=4.0.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: six>=1.10.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: py>=1.5.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > >Requirement already satisfied: attrs>=17.4.0 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from pytest) > > This is all fine - it is just saying that various prerequisites are already > there. > > >You are using pip version 9.0.1, however version 10.0.1 is available. > >You should consider upgrading via the 'pip install --upgrade pip' command. > > This is just a suggestion to upgrade pip. Since you're running pip from > Python's "pip" builtin module this effectively suggests upgrading your Python 3 > install. Not important or urgent. > > >So I'm stuck again. I thought "sudo" was supposed to take care of permissions. > >Do you have a suggestion? > > Sudo isn't magic, and treating it like magic is very common, which is one > reason I discourage unthinking use of it. > > Sudo exists to let your run specific commands as root, the system superuser. > (It also has modes to run as other users, but root is the default and also the > most dangerous.) > > When you use sudo you have almost unlimited power to change things. This is > handy for installation activities, and also handy for doing unbound damage to > the OS install. > > I still recommend that you avoid sudo here and use pip's --user option, > installing the packages in your personal Python tree. It will work just as well > for almost every purpose and avoid risk to your machine's OS. > > Cheers, > Cameron Simpson One more thing about PEP8. My workbook is a bit skimpy on details. Is there a quick way to make the edits or am I supposed to root around for my module and make the edits one by one? From phamp at mindspring.com Tue Jun 12 11:40:32 2018 From: phamp at mindspring.com (pyotr filipivich) Date: Tue, 12 Jun 2018 08:40:32 -0700 Subject: Filters References: <57e2e5cf-3d17-4127-ba0b-16eaea1ab4e8@googlegroups.com> Message-ID: T Berger on Tue, 12 Jun 2018 07:45:58 -0700 (PDT) typed in comp.lang.python the following: >Why doesn't the system allow me to set filters for my own posts? I was able to do it once, but when I returned to the forum, I was back among the unfiltered posts. When I tried to reapply the filter, the option was grayed out. Message-ID: <57e2e5cf-3d17-4127-ba0b-16eaea1ab4e8 at googlegroups.com> That says it all. "It is not a bug, it is a feature." Google has totally screwed up their archiving of Usenet, and doesn't care bugger all for those who use it. You must conform to the new Method of Web based Fora. >Also, I've selected the option to get email updates to my posts, but the option seems to work only selectively. It is Google. They will decide what is evil. and not do that. -- pyotr filipivich Next month's Panel: Graft - Boon or blessing? From email at paulstgeorge.com Tue Jun 12 12:57:53 2018 From: email at paulstgeorge.com (Paul St George) Date: Tue, 12 Jun 2018 18:57:53 +0200 Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: References: <64899b39-ef16-0c74-7a1b-30f49b470c3f@paulstgeorge.com> <77b0d1eb-8b01-e785-4951-6d0a90702ec7@paulstgeorge.com> <5l9qhd90v8bnqra06fimm0p0gu1ee711r6@4ax.com> Message-ID: <0fb98c65-4a23-6f62-2772-e1a424b882c5@paulstgeorge.com> > Dennis Lee Bieber wrote: >> ????Both may be dependent upon the actual hardware graphics board and >> the >> drivers for said board. > On 11/06/2018 01:47, Gregory Ewing wrote: > My guess is that if your surface is not fullscreen or is not > a hardware surface, then you're always drawing into an ofscreen > buffer that gets copied to the screen when display.flip() is > called. In other words, it's effectively double-buffered > whether you request it or not. > > The only time it's an issue is when you're drawing directly > to the screen memory, i.e. both FULLSCREEN and HWSURFACE > where your hardware and drivers support that. > > My suggestion is to just always specify DOUBLEBUF and not > worry about what's going on behind the scenes. That will > almost always give the result you want, i.e. a flicker-free > display. > > The only time it would be an issue is if you wanted your > surface to *not* be double-buffered for some reason, but > that would be a rare situation. > Thank you! Your intervention could not have been more timely. I was just about to throw away the screen and try again with another. I want to use display.flip() and thought that was dependent on being able to set DOUBLEBUF. The surface is fullscreen. I had considered meddling with the config.txt to try to enable* HWSURFACE but from what you say, this is unnecessary. Have I understood you right? Paul * Perhaps by uncommenting #dtparam=spi=on From grant.b.edwards at gmail.com Tue Jun 12 14:51:42 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 12 Jun 2018 18:51:42 +0000 (UTC) Subject: Posting warning message References: <20180612072814.GA84354@cskk.homeip.net> <177de5bd-f883-4188-b689-830f3398216c@googlegroups.com> Message-ID: On 2018-06-12, Chris Angelico wrote: > On Wed, Jun 13, 2018 at 12:17 AM, T Berger wrote: > >> Sorry, to bother you again. But is there some way to edit a message >> once its posted? Or do I have to delete it and rewrite it? > > Nope. And you can't delete it either. That depends. If you're posting via NNTP, and your NNTP server supports CANCEL messages, and the posting hasn't been passed on to any peers yet, then you _can_ delete it. But, I'd bet cash money those conditions are not true for T Berger. -- Grant Edwards grant.b.edwards Yow! Are we live or on at tape? gmail.com From grant.b.edwards at gmail.com Tue Jun 12 14:52:46 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 12 Jun 2018 18:52:46 +0000 (UTC) Subject: Filters References: <57e2e5cf-3d17-4127-ba0b-16eaea1ab4e8@googlegroups.com> Message-ID: On 2018-06-12, pyotr filipivich wrote: > It is Google. They will decide what is evil. and not do that. They've found it simpler to just declare than anything they do is, by definition, therefore not evil. -- Grant Edwards grant.b.edwards Yow! There's enough money at here to buy 5000 cans of gmail.com Noodle-Roni! From breamoreboy at gmail.com Tue Jun 12 15:27:35 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Tue, 12 Jun 2018 20:27:35 +0100 Subject: Filters In-Reply-To: <57e2e5cf-3d17-4127-ba0b-16eaea1ab4e8@googlegroups.com> References: <57e2e5cf-3d17-4127-ba0b-16eaea1ab4e8@googlegroups.com> Message-ID: On 12/06/18 15:45, T Berger wrote: > Why doesn't the system allow me to set filters for my own posts? I was able to do it once, but when I returned to the forum, I was back among the unfiltered posts. When I tried to reapply the filter, the option was grayed out. > > Also, I've selected the option to get email updates to my posts, but the option seems to work only selectively. > A solution is to point any (semi-)decent email client/news reader/whatever the things are called, at news.gmane.org and read hundreds of python forums and thousands of other technical forums whilst leaving your own inbox clear. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From nad at python.org Tue Jun 12 16:29:38 2018 From: nad at python.org (Ned Deily) Date: Tue, 12 Jun 2018 16:29:38 -0400 Subject: [RELEASE] Python 3.7.0rc1 and 3.6.6rc1 are now available Message-ID: <18BD5CA7-EB42-477F-9D14-7EE78CBEB5C2@python.org> Python 3.7.0rc1 and 3.6.6rc1 are now available. 3.7.0rc1 is the final planned release preview of Python 3.7, the next feature release of Python. 3.6.6rc1 is the the release preview of the next maintenance release of Python 3.6, the current release of Python. Assuming no critical problems are found prior to *2018-06-27*, the scheduled release dates for 3.7.0 and 3.6.6, no code changes are planned between these release candidates and the final releases. These release candidates are intended to give you the opportunity to test the new features and bug fixes in 3.7.0 and 3.6.6 and to prepare your projects to support them. 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 these are preview releases and, thus, their use is not recommended for production environments. Attention macOS users: there is now a new installer variant for macOS 10.9+ that includes a built-in version of Tcl/Tk 8.6. This variant will become the default version when 3.7.0 releases. Check it out! You can find these releases and more information here: https://www.python.org/downloads/release/python-370rc1/ https://www.python.org/downloads/release/python-366rc1/ -- Ned Deily nad at python.org -- [] From rantingrickjohnson at gmail.com Tue Jun 12 17:33:40 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Jun 2018 14:33:40 -0700 (PDT) Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> <874licutfy.fsf@elektro.pacujo.net> Message-ID: Gregory Ewing wrote: [...] > * Charging money for copies of software is not the only way > to make money from programming. You can charge for support > services. You can charge for writing custom one-off > software. There are people who make a good living from > doing these things. Microsoft not only demands to be paid for writing the software *and* maintaining it, but they also demand that you pay to have it upgraded every couple of years after it "mysteriously" becomes exponentially more laggy and exploit prone than usual. "Hmm, i wonder how that happened?" *SCRATCHES-HEAD* *LOOKS-AT-INSTRUMENT-PANEL* "Oh noes!" O_O "The software fuel tank is almost _empty_!" How else will they convince you to buy the latest copy of windoze 95? From bill at baddogconsulting.com Tue Jun 12 18:00:44 2018 From: bill at baddogconsulting.com (Bill Deegan) Date: Tue, 12 Jun 2018 15:00:44 -0700 Subject: Splitting up large python module impact on performance? Message-ID: Greetings, I'm doing some refactoring on a fairly large python codebase. Some of the files are > 4000 lines long and contain many classes. Should I expect any performance hit from splitting some of the classes out to other files? Thanks, Bill From torriem at gmail.com Tue Jun 12 19:20:59 2018 From: torriem at gmail.com (Michael Torrie) Date: Tue, 12 Jun 2018 17:20:59 -0600 Subject: Posting warning message In-Reply-To: References: <20180612072814.GA84354@cskk.homeip.net> <177de5bd-f883-4188-b689-830f3398216c@googlegroups.com> Message-ID: <5f230c72-4931-b337-b99e-10709ec710a7@gmail.com> On 06/12/2018 08:48 AM, T Berger wrote: > I deleted them a number of time, then got a bar across the page indicating that a post had been deleted. It's nuts that you can't edit your own post. This "forum" is actually a mailing list mirrored to Usenet, so whatever you post gets instantly emailed out to the list members, and also gets sent to all the Usenet servers throughout the world. So by the time you want to edit your post, it's already in my email box. You're accessing it via Google Groups, but it's not really an online forum. It just looks like one. Google Groups may let you delete your message within Groups, but out here on the mailing list where I am, and on Usenet where others read, you definitely can't. From greg.ewing at canterbury.ac.nz Tue Jun 12 19:26:23 2018 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 13 Jun 2018 11:26:23 +1200 Subject: FULLSCREEN and DOUBLEBUF In-Reply-To: <0fb98c65-4a23-6f62-2772-e1a424b882c5@paulstgeorge.com> References: <64899b39-ef16-0c74-7a1b-30f49b470c3f@paulstgeorge.com> <77b0d1eb-8b01-e785-4951-6d0a90702ec7@paulstgeorge.com> <5l9qhd90v8bnqra06fimm0p0gu1ee711r6@4ax.com> <0fb98c65-4a23-6f62-2772-e1a424b882c5@paulstgeorge.com> Message-ID: <5B20569F.4000309@canterbury.ac.nz> Paul St George wrote: > I had considered meddling with the config.txt to try to enable* > HWSURFACE but from what you say, this is unnecessary. I don't really have much idea what effect HWSURFACE would have, if any. It will certainly depend a lot on your hardware and drivers. My suggestion would be not to bother with it unless you're having performance issues, and then try it to see if it makes any difference. Note that it's conceivable that HWSURFACE could actually make things slower in some situations, e.g. if it results in more movement of data between main memory and video memory. Experimentation is the only way to be sure. -- Greg From cs at cskk.id.au Tue Jun 12 19:50:45 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 13 Jun 2018 09:50:45 +1000 Subject: Posting warning message In-Reply-To: References: Message-ID: <20180612235045.GA68474@cskk.homeip.net> On 12Jun2018 07:48, Tamara Berger wrote: >On Tuesday, June 12, 2018 at 10:27:06 AM UTC-4, Chris Angelico wrote: >> On Wed, Jun 13, 2018 at 12:17 AM, T Berger wrote: >> > Sorry, to bother you again. But is there some way to edit a message once >> > its posted? Or do I have to delete it and rewrite it? >> >> Nope. And you can't delete it either. > >I deleted them a number of time, then got a bar across the page indicating >that a post had been deleted. As has been mentioned, any "delete" you do on Google Groups is pretty limited, possibly only to Google's copy. The message has already gone planetwide. Google's delete _may_ propagate to the rest of usenet, and _may_ be obeyed in some of those places. But it certainly doesn't propagate to the mailing list, and even if it did, those of use who pull the list down to our personal mail folders would ignore such a thing. >It's nuts that you can't edit your own post. No, it is actually good: - there's not one copy of your post that google can modify: it gets copied planet wide, to thousands or millions of independent places - how do people discover that you've modified a post, to review your change? how do their replies before your modification make any kind of sense if the preceeding message is no longer what they replied to? The correct way to correct a post is to follow up to it (reply to it) with a correction or clarification. That way everyone sees the change/fix as a new messge. And it works even though the messages get copied everywhere, because all that has to happen is to copy your own new message. Cheers, Cameron Simpson From cs at cskk.id.au Tue Jun 12 19:57:46 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 13 Jun 2018 09:57:46 +1000 Subject: Posting warning message In-Reply-To: <2f713a93-d650-4764-8389-3e9e06cd82f3@googlegroups.com> References: <2f713a93-d650-4764-8389-3e9e06cd82f3@googlegroups.com> Message-ID: <20180612235746.GA85573@cskk.homeip.net> On 12Jun2018 07:14, Tamara Berger wrote: >On Tuesday, June 12, 2018 at 3:28:29 AM UTC-4, Cameron Simpson wrote: >> On 11Jun2018 22:51, Tamara Berger wrote: [...] >> >192:~ TamaraB$ sudo python3 -m pip install pytest >> >Password: >> >The directory '/Users/TamaraB/Library/Caches/pip/http' or its parent directory >> >is not owned by the current user and the cache has been disabled. Please check >> >the permissions and owner of that directory. If executing pip with sudo, you >> >may want sudo's -H flag. >> >> sudo leaves the $HOME environment variable unchanged, at least on my Mac. So it >> is using your personal cache directory. And rejecting it becuse it is >> (correctly) owned by you. [...] > >Just one more thing, Cameron. I was looking at an Apple support page, and it says "When you're logged in to your Mac using an administrator account, you can use the sudo command in the Terminal app to execute commands as a different user, such as the root user." (https://support.apple.com/en-us/HT202035). I am logged in as administrator. So why isn't sudo working for me? Please trim the quoted material of the irrelevant bits. Like the above. It makes things managable for others. Sudo is working just fine: it is running pip as the root user. That's _all_ it does. Pip itself makes certain sanity checks before it proceeds, and here it is complaining that its cache directory is not entirely owned by the user it is running as (root). That is because without the -H option it is trying to use _your_ cache directory. Now, as root, it _could_ tread all over that directory with updates. But that would be rude, specificly because later, when _you_ go to run pip without sudo and with the --user option, portions of that cache directory will not be owned by you, and may not be readable or modifiable etc. So it refuses. >P.S. How would I make the link I provided live? What link? This is why we trim quoted text and reply below the relevant bit directly: I don't know what link you provided or even whether it is there, just buried in the huge quoted text. Just cite it again, eg: How would I make this link (link here) live? And then, of course, tell us what "live" means :-) Cheers, Cameron Simpson From cs at cskk.id.au Tue Jun 12 20:17:12 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 13 Jun 2018 10:17:12 +1000 Subject: pep8 Re: Posting warning message In-Reply-To: References: Message-ID: <20180613001712.GA4429@cskk.homeip.net> On 12Jun2018 07:51, Tamara Berger wrote: [... snip ...] >One more thing about PEP8. My workbook is a bit skimpy on details. Is there a >quick way to make the edits PEP8 is a style recommendation for Python code: https://www.python.org/dev/peps/pep-0008/ It is followed pretty rigorously in the Python standard library, and most Python code follows a lot of it as a matter of good practice, in that (a) it is a fairly good style, producing easy to read code and (b) when everyone uses the same or similar styes, we all find other people's code easier to read. But it is not enforced. There are several "lint" tools around which will look at your code and complain about violations of PEP8 and various other constraints generally held to be good to obey, particularly some kinds of initialisation errors and other practices that while syntacticly legal may indicate bugs or lead to header to debug or maintain code. Also, some text editors have facilities for autostyling code, sometimes as you type it and sometimes as a final step when you save the modified file. For example, there are tools like autopep8 (https://pypi.org/project/autopep8/) which will modify python code directly to apply the PEP8 style. Personally, I run a few lint commands against my Python code by hand, and hand repair. Typical workflow goes: - modify code for whatever reason (add feature, fix bugs, etc) and test - when happy, _then_ run a lint tool and tidy up most of what it reports - _then_ instal the code where other things may use it (eg pip install) My personal kit has a "lint" shell script: https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/lint which runs my preferred linters against code files, and for Python it runs: - pyflakes: https://pypi.org/project/pyflakes/ - pep8: https://pypi.org/project/pep8/ - pylint: https://pypi.org/project/pylint/, https://pylint.readthedocs.io/en/latest/ These can all be installed using pip: pip install --user pyflakes pep8 pylint As you can see from my lint script I run them with various options that oveeride their default checks to better match my preffered code style. >or am I supposed to root around for my module and make the edits one by one? Finally, no you don't normally root around and change an installed module. Instead, modify your original copy and reinstall the newer version! Cheers, Cameron Simpson From cs at cskk.id.au Tue Jun 12 20:32:49 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 13 Jun 2018 10:32:49 +1000 Subject: Splitting up large python module impact on performance? In-Reply-To: References: Message-ID: <20180613003249.GA76714@cskk.homeip.net> On 12Jun2018 15:00, Bill Deegan wrote: >I'm doing some refactoring on a fairly large python codebase. >Some of the files are > 4000 lines long and contain many classes. > >Should I expect any performance hit from splitting some of the classes out >to other files? In general, nothing significant. Yes, your programs will load more files than before. But only once per invocation. If you really have concerns here you would need to measure the change, not just in a stub "import old_module and quit" vs "import new module in pieces and quit" but against a larger program doing significant work. The former will let you measure how big the impact generally is, but the latter will tell you if it matters. Also, where does the cost go? In reading the .py code, or in compiling the code to whatever internal form your Python interpreter runs against? If the (time) cost is greater for the compilation versus the opening a few files, then you might actually win with the breakup if most programmes do not need to import _all_ the library pieces. I think I'm saying: don't worry unless your applications are very time critical (eg invoked very frequently and/or doing almost nothing after the "import" phase) or you notice a significant slowdown after your changes. And it is usually easier to stick things back together than it was to pull them apart if that happens. Cheers, Cameron Simpson From rosuav at gmail.com Tue Jun 12 20:44:31 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jun 2018 10:44:31 +1000 Subject: Splitting up large python module impact on performance? In-Reply-To: <20180613003249.GA76714@cskk.homeip.net> References: <20180613003249.GA76714@cskk.homeip.net> Message-ID: On Wed, Jun 13, 2018 at 10:32 AM, Cameron Simpson wrote: > I think I'm saying: don't worry unless your applications are very time > critical (eg invoked very frequently and/or doing almost nothing after the > "import" phase) or you notice a significant slowdown after your changes. And > it is usually easier to stick things back together than it was to pull them > apart if that happens. ^^ This. You may find some speed-ups from loading only the parts you want. You may find some slowdowns from extra levels of indirection. But more than likely, neither matters. Design your code to be logical. If splitting the files up lets you more logically organize your code, do it; if it's arbitrary (piece1, piece2, piece3), don't. A general rule for refactoring: For any piece of code you could describe, you should be able to say instantly which file it belongs in. That way, when you notice a behavioural bug, you go "oh that's in class X, so I need to edit file Y". If you can't do that, refactoring your code may help. There are no arbitrary file size limits in Python. Four thousand lines of code is fine if they logically go together; you could go as far as ten thousand or even more, and it won't be a problem. Split things up exactly as far as they logically need to be split, and no further. ChrisA From cs at cskk.id.au Tue Jun 12 20:44:58 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 13 Jun 2018 10:44:58 +1000 Subject: helpfulness Re: Index of entity in List with a Condition In-Reply-To: <1bf997b7-05d3-44e2-8ce7-8213863f6661@googlegroups.com> References: <1bf997b7-05d3-44e2-8ce7-8213863f6661@googlegroups.com> Message-ID: <20180613004458.GA6400@cskk.homeip.net> On 11Jun2018 18:03, Rick Johnson wrote: >subhaba... at gmail.com wrote: >> I have the following sentence, >> >> "Donald Trump is the president of United States of America". [...] > >Typically when you ask us to do your homework for you, it is >considered bad taste to present the teacher's assignment >verbatim and then expect that we will provide a turn-key >solution. And although you _did_ provide some sort of >"Pythony looking" code, unfortunately the code is poorly >formatted. Rick, this is unhelpful. Firstly, Subhabrata isn't getting us to do his work for him; he's posted here several times in the past and clearly is working on probems in good faith with demonstrated willingness _and_ ability to think things through in detail. He comes here having tried things, with specific questions following from problems he has encountered. Secondly, his question is reasonably expressed. Lacking a lot of code, it is perfectly feasible and reasonable to respond in general prose form instead of purely code. Finally, adding in political editorial in your code response doesn't improve the discussion environment. If you want to encourage more detail from him, just ask without overtones. If you're unwilling to engage with his post for whatever criteria, just don't engage. Easy! It is better for all concerned, both the OP and we the list readers. Thanks, Cameron Simpson >Next time, please try to present your question in a formal, >well-though-out manner. Source code should either be >executable, or conspicuously labeled as psuedo code. Not >because we don't _know_ what pseudo code looks like, but >because we can intuit your level of knowledge from the >presentation. And i gotta tell ya, this presentation is not >exactly screaming valedictorian -- but i digress. > >Now, as to your problem... > >Well, first, hold on a second, because, i want to correct your >sentence. You presented your target string as: > > "Donald Trump is the president of United States of America" > >No-no-no. This sentence seems to be missing a few things. >The first is a three letter word. And let's insert that word >now... > > >>> s = "Donald Trump is the president of United States of America" > >>> s.index('U') > 33 > >>> s = s[:33] + 'the ' + s[33:] > >>> s > 'Donald Trump is the president of the United States of America' > >Ah yes. You see how much more smoothly that rolls off the >ol' tongue? Now, in the interest of public awareness, let's >add an addendum, shall we? > > >>> s += ", who was duly elected to office by the great people of this fine country in a free and open election. And no amount of whining; pouting; sniveling; conspiratorial hoopla; flailing of the arms; the legs; or any combination thereof for that matter; will change the reality that Donald *BIG JOHN* Trump is now the president of this fine country. Seriously folks. It's been an interesting ride. But the circus is over now. Elvis left the building over a _year_ ago. Heck, Jimmy Hoffa has already rolled over in his grave *THREE* times! But most disturbing of all, is that the dozens of emaciated cats trapped in each of your apartments are on the verge of cannibalism (yesh, you forgot about them, didn't you?), and the toxic ammonia fumes are melting the paint off the walls! It's time to go home and lick your wounds folks. Better luck next time. Aloha." > >Whew! (*wipes brow*) Now that we've gotten all of that out of >the way... what was your question again? o_O >-- https://mail.python.org/mailman/listinfo/python-list From greg.ewing at canterbury.ac.nz Tue Jun 12 20:46:12 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 13 Jun 2018 12:46:12 +1200 Subject: pep8 Re: Posting warning message In-Reply-To: References: <20180613001712.GA4429@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > PEP8 is a style recommendation for Python code: > > https://www.python.org/dev/peps/pep-0008/ Specifically, it's a style guide for *code in the Python standard library*, as it says in the Introduction: > This document gives coding conventions for the Python code comprising > the standard library in the main Python distribution. Some of its recommendations are also good to follow in general Python code, but whether you do so is entirely up to you. -- Greg From rosuav at gmail.com Tue Jun 12 20:52:33 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jun 2018 10:52:33 +1000 Subject: pep8 Re: Posting warning message In-Reply-To: References: <20180613001712.GA4429@cskk.homeip.net> Message-ID: On Wed, Jun 13, 2018 at 10:46 AM, Gregory Ewing wrote: > Cameron Simpson wrote: >> >> PEP8 is a style recommendation for Python code: >> >> https://www.python.org/dev/peps/pep-0008/ > > > Specifically, it's a style guide for *code in the Python > standard library*, as it says in the Introduction: > >> This document gives coding conventions for the Python code comprising > >> the standard library in the main Python distribution. > > Some of its recommendations are also good to follow in > general Python code, but whether you do so is entirely > up to you. Many of its recommendations are good to follow in code written in other languages, too :) ChrisA From greg.ewing at canterbury.ac.nz Tue Jun 12 20:57:30 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 13 Jun 2018 12:57:30 +1200 Subject: Splitting up large python module impact on performance? In-Reply-To: References: Message-ID: Bill Deegan wrote: > Should I expect any performance hit from splitting some of the classes out > to other files? I doubt it. Time taken to load modules is mostly dependent on the total amount of code, not how many files it lives in. If you had a *very* large number of tiny files, it might be a bit slower due to all the stat calls required, but I wouldn't worry about it too much. Just structure you code in a way that makes sense, and deal with performance problems if and when the occur. -- Greg From cs at cskk.id.au Tue Jun 12 21:00:28 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 13 Jun 2018 11:00:28 +1000 Subject: Index of entity in List with a Condition In-Reply-To: <20277b9a-143f-4b43-8cbe-bce908f4668d@googlegroups.com> References: <20277b9a-143f-4b43-8cbe-bce908f4668d@googlegroups.com> Message-ID: <20180613010028.GA31831@cskk.homeip.net> On 11Jun2018 13:48, Subhabrata Banerjee wrote: >I have the following sentence, > >"Donald Trump is the president of United States of America". > >I am trying to extract the index 'of', not only for single but also >for its multi-occurance (if they occur), from the list of words of the >string, made by simply splitting the sentence. > index1=[index for index, value in enumerate(words) if value == "of"], >where words=sentence.split() > >I could do this part more or less nicely. > >But I am trying to say if the list of words has the words "United" >and "States" and it has "of " in the sentence then the previous >word before of is, president. > >I am confused how may I write this, if any one may help it. You will probably have to drop the list comprehension and go with something more elaborate. Also, lists have an "index" method: >>> L = [4,5,6] >>> L.index(5) 1 though it doesn't solve your indexing problems on its own. I would be inclined to deconstuct the sentence into a cross linked list of elements. Consider making a simple class to encapsulate the knowledge about each word (totally untested): class Word: def __init__(word): self.word = word words = [] for index, word in sentence.split(): W = Word(word) W.index = index words.append(W) W.wordlist = words Now you have a list of Word objects, each of which knows its list position _and_ also knows about the list itself, _and_ you have the list of Word objects correspnding to your sentence words. You'll notice we can just hang whatever attributes we like off these "Word" objects: we added a .wordlist and .index on the fly. It isn't great formal object design, but it makes building things up very easy. You can add methods or properties to your class, such as ".next": @property def next(self): return self.wordlist[self.index - 1] and so forth. That will let you write expressions about Words: for W in wordlist: if W.word == 'of' and W.next.word == 'the' and W.next.next.word == 'United' ...: if W.previous.word != 'president': ... oooh, unexpected preceeding word! ... You can see that you could also write methods like "is_preceeded_by": def is_preceed_by(self, word2): return self.previous.word == word2 and test "W.is_preceeded_by('president')". In short, write out what you would like to express. Then write methods that implement the smaller parts of what you just wrote. Cheers, Cameron Simpson From steve+comp.lang.python at pearwood.info Tue Jun 12 22:28:06 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jun 2018 02:28:06 +0000 (UTC) Subject: Splitting up large python module impact on performance? References: Message-ID: On Tue, 12 Jun 2018 15:00:44 -0700, Bill Deegan wrote: > Greetings, > > I'm doing some refactoring on a fairly large python codebase. Some of > the files are > 4000 lines long and contain many classes. > > Should I expect any performance hit from splitting some of the classes > out to other files? Depends on whether you split it out to 4000 one-line files or 10 100 line files. But in practice, no, there will be no runtime performance hit aside from the very small cost of needing to import X files instead of a single file. The actual performance of the classes themselves should be unchanged. However, you'll need to be careful to manage circular dependencies, where module A depends on B which depends on C which depends on A. (Linear dependencies are fine: A depends on B which depends on C, which depends on nothing.) Circular dependencies can be managed in various ways, but the best way to manage them is to avoid them altogether. In other words: if your classes are very tightly coupled, you might have a hard time splitting them into multiple files. If they are loosely coupled, you shouldn't have any trouble at all. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rantingrickjohnson at gmail.com Tue Jun 12 23:23:23 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Jun 2018 20:23:23 -0700 (PDT) Subject: Splitting up large python module impact on performance? In-Reply-To: References: Message-ID: Bill Deegan wrote: > I'm doing some refactoring on a fairly large python > codebase. Some of the files are > 4000 lines long and > contain many classes. I would argue that files of such size are a total pain to navigate and thus, edit. I prefer to place only one -- or only a handful of classes -- in each file. One class per file is _most_ preferred. But if you have a small group of classes that are closely dependent on one another, and, the source definitions can fit comfortably in a single file, well then, i say do it. You just have to decide what is comfortable for _you_; your coworkers; and anyone who may be forced to maintain your code in the future. When in doubt, and when it comes to style issues, there is one universal rule you should always strive to follow, and that rule is to be _consistent_. PEP8 underscores the importance of consistency, and you may want to read it. > Should I expect any performance hit from splitting some of > the classes out to other files? I think you should worry less about the startup performance hit and more about the possibility of circular imports. I'm not a big fan of Python's import or packaging systems, as neither mesh nicely with my style of programming. But i've found some ways to work around them... So if you're using the OOP paradigm (like i am), and if you write your OOP code in a strict formal style (hail java!), then you can leverage some of the machinery of OOP to get _around_ the limitations inherent in the aforementioned components of the Python language. I may exaggerate on this a bit more if you're interested. From rosuav at gmail.com Tue Jun 12 23:35:32 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jun 2018 13:35:32 +1000 Subject: Splitting up large python module impact on performance? In-Reply-To: References: Message-ID: On Wed, Jun 13, 2018 at 1:23 PM, Rick Johnson wrote: > Bill Deegan wrote: >> I'm doing some refactoring on a fairly large python >> codebase. Some of the files are > 4000 lines long and >> contain many classes. > > I would argue that files of such size are a total pain to > navigate and thus, edit. I prefer to place only one -- or > only a handful of classes -- in each file. One class per > file is _most_ preferred. But if you have a small group of > classes that are closely dependent on one another, and, the > source definitions can fit comfortably in a single file, > well then, i say do it. You just have to decide what is > comfortable for _you_; your coworkers; and anyone who may be > forced to maintain your code in the future. A few thousand lines in a file is only a problem if you're using an editor that lacks a Find feature. Or if you use bad function/class names that you can't search for. > When in doubt, and when it comes to style issues, there is > one universal rule you should always strive to follow, and > that rule is to be _consistent_. PEP8 underscores the > importance of consistency, and you may want to read it. Yep! It does. Let me see... https://www.python.org/dev/peps/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds """However, know when to be inconsistent -- sometimes style guide recommendations just aren't applicable.""" > I may exaggerate on this a bit more if you're interested. Isn't it normal for you to exaggerate everything? ChrisA From brgrt2 at gmail.com Wed Jun 13 00:05:47 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Wed, 13 Jun 2018 00:05:47 -0400 Subject: pep8 Re: Posting warning message In-Reply-To: <20180613001712.GA4429@cskk.homeip.net> References: <20180613001712.GA4429@cskk.homeip.net> Message-ID: Hi Cameron, Thanks for the in-depth answer. I'm going to have to read it carefully, with the help of a Python glossary. Some of the terms you use are new to me. >or am I supposed to root around for my module and make the edits one by one? I was trying to be amusing and didn't get my point across. >Finally, no you don't normally root around and change an installed module. >Instead, modify your original copy and reinstall the newer version! What I meant was, do I have to open the file, search for, e.g., colons and insert space after them? These were the sorts of picayune errors picked up by PEP8 on my program. I deliberately omit such spaces when I code because I like to do as little unnecessary work as possible. There is enough repetitive coding as it is. I know some IDEs have word completion suggestion for variables, etc, that the user creates. But I'm practicing in barebones IDLE and that means a lot of extra work. Thanks, Tamara On Tue, Jun 12, 2018 at 8:17 PM Cameron Simpson wrote: > > On 12Jun2018 07:51, Tamara Berger wrote: > [... snip ...] > >One more thing about PEP8. My workbook is a bit skimpy on details. Is there a > >quick way to make the edits > > PEP8 is a style recommendation for Python code: > > https://www.python.org/dev/peps/pep-0008/ > > It is followed pretty rigorously in the Python standard library, and most > Python code follows a lot of it as a matter of good practice, in that (a) it is > a fairly good style, producing easy to read code and (b) when everyone uses the > same or similar styes, we all find other people's code easier to read. > > But it is not enforced. > > There are several "lint" tools around which will look at your code and complain > about violations of PEP8 and various other constraints generally held to be > good to obey, particularly some kinds of initialisation errors and other > practices that while syntacticly legal may indicate bugs or lead to header to > debug or maintain code. > > Also, some text editors have facilities for autostyling code, sometimes as you > type it and sometimes as a final step when you save the modified file. > > For example, there are tools like autopep8 (https://pypi.org/project/autopep8/) > which will modify python code directly to apply the PEP8 style. > > Personally, I run a few lint commands against my Python code by hand, and hand > repair. Typical workflow goes: > > - modify code for whatever reason (add feature, fix bugs, etc) and test > > - when happy, _then_ run a lint tool and tidy up most of what it reports > > - _then_ instal the code where other things may use it (eg pip install) > > My personal kit has a "lint" shell script: > > https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/lint > > which runs my preferred linters against code files, and for Python it runs: > > - pyflakes: https://pypi.org/project/pyflakes/ > > - pep8: https://pypi.org/project/pep8/ > > - pylint: https://pypi.org/project/pylint/, > https://pylint.readthedocs.io/en/latest/ > > These can all be installed using pip: > > pip install --user pyflakes pep8 pylint > > As you can see from my lint script I run them with various options that > oveeride their default checks to better match my preffered code style. > > >or am I supposed to root around for my module and make the edits one by one? > > Finally, no you don't normally root around and change an installed module. > Instead, modify your original copy and reinstall the newer version! > > Cheers, > Cameron Simpson From subhabangalore at gmail.com Wed Jun 13 00:06:18 2018 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Tue, 12 Jun 2018 21:06:18 -0700 (PDT) Subject: Index of entity in List with a Condition In-Reply-To: References: <20277b9a-143f-4b43-8cbe-bce908f4668d@googlegroups.com> <20180613010028.GA31831@cskk.homeip.net> Message-ID: On Wednesday, June 13, 2018 at 6:30:45 AM UTC+5:30, Cameron Simpson wrote: > On 11Jun2018 13:48, Subhabrata Banerjee wrote: > >I have the following sentence, > > > >"Donald Trump is the president of United States of America". > > > >I am trying to extract the index 'of', not only for single but also > >for its multi-occurance (if they occur), from the list of words of the > >string, made by simply splitting the sentence. > > index1=[index for index, value in enumerate(words) if value == "of"], > >where words=sentence.split() > > > >I could do this part more or less nicely. > > > >But I am trying to say if the list of words has the words "United" > >and "States" and it has "of " in the sentence then the previous > >word before of is, president. > > > >I am confused how may I write this, if any one may help it. > > You will probably have to drop the list comprehension and go with something > more elaborate. > > Also, lists have an "index" method: > > >>> L = [4,5,6] > >>> L.index(5) > 1 > > though it doesn't solve your indexing problems on its own. > > I would be inclined to deconstuct the sentence into a cross linked list of > elements. Consider making a simple class to encapsulate the knowledge about > each word (totally untested): > > class Word: > def __init__(word): > self.word = word > > words = [] > for index, word in sentence.split(): > W = Word(word) > W.index = index > words.append(W) > W.wordlist = words > > Now you have a list of Word objects, each of which knows its list position > _and_ also knows about the list itself, _and_ you have the list of Word objects > correspnding to your sentence words. > > You'll notice we can just hang whatever attributes we like off these "Word" > objects: we added a .wordlist and .index on the fly. It isn't great formal > object design, but it makes building things up very easy. > > You can add methods or properties to your class, such as ".next": > > @property > def next(self): > return self.wordlist[self.index - 1] > > and so forth. That will let you write expressions about Words: > > for W in wordlist: > if W.word == 'of' and W.next.word == 'the' and W.next.next.word == 'United' ...: > if W.previous.word != 'president': > ... oooh, unexpected preceeding word! ... > > You can see that you could also write methods like "is_preceeded_by": > > def is_preceed_by(self, word2): > return self.previous.word == word2 > > and test "W.is_preceeded_by('president')". > > In short, write out what you would like to express. Then write methods that > implement the smaller parts of what you just wrote. > > Cheers, > Cameron Simpson References: Message-ID: <20180613040835.GA4683@cskk.homeip.net> On 13Jun2018 13:35, Chris Angelico wrote: >On Wed, Jun 13, 2018 at 1:23 PM, Rick Johnson > wrote: >> Bill Deegan wrote: >>> I'm doing some refactoring on a fairly large python >>> codebase. Some of the files are > 4000 lines long and >>> contain many classes. >> >> I would argue that files of such size are a total pain to >> navigate and thus, edit. I prefer to place only one -- or >> only a handful of classes -- in each file. One class per >> file is _most_ preferred. But if you have a small group of >> classes that are closely dependent on one another, and, the >> source definitions can fit comfortably in a single file, >> well then, i say do it. You just have to decide what is >> comfortable for _you_; your coworkers; and anyone who may be >> forced to maintain your code in the future. > >A few thousand lines in a file is only a problem if you're using an >editor that lacks a Find feature. Or if you use bad function/class >names that you can't search for. I was going to say something along these lines, but to some extent this feels like an unfair finger pointing exercise. Huge files can be a PITA; having something that aids moving around them reduces the pain, but doesn't remove the fact that sometimes something is too big. The flip side is that editor support is amazingly important, or amazingly useful. I'm a long time vi user, and its tags feature is outstandingly useful (go to identifier, type ctlr-[, you're transported to the file and line defining it, with luck). I recently spent some time updating my support for this, getting ctags to run whenever I save a file, with good context for what to tag and not). Recently part of that movitation came from spending a year as a software engineer in a fast moving agile environment, and seeing first hand just how much an advantage good tooling can be. Editor support. Multiple panes, autoformat on save, vim extensions for finding files (big codebase, many many files in a deep tree). Tools matter, it turns out. >"""However, know when to be inconsistent -- sometimes style guide >recommendations just aren't applicable.""" > >> I may exaggerate on this a bit more if you're interested. > >Isn't it normal for you to exaggerate everything? Shhh! Don't discourage his restraint! Cheers, Cameron Simpson From rantingrickjohnson at gmail.com Wed Jun 13 00:15:54 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Jun 2018 21:15:54 -0700 (PDT) Subject: Splitting up large python module impact on performance? In-Reply-To: References: Message-ID: <8c712483-5aba-4d53-b498-0c8940746701@googlegroups.com> On Tuesday, June 12, 2018 at 10:35:47 PM UTC-5, Chris Angelico wrote: [...] > A few thousand lines in a file is only a problem if you're > using an editor that lacks a Find feature. Or if you use > bad function/class names that you can't search for. I'm unaware of any text editor that doesn't have a find feature. But, in a any event, the real problem is not a lack of features, no, it's a matter of reducing the mental load. The smaller the file, the less "off screen" data the programmer must consider at any one time during the editing process. Say for instance, you want to add a new symbol, and the symbol is going in the module namespace. Okay. Seems simple enough, right? But if your file contains thousands of lines of code, you can't determine with any degree of certainly (unless you have a photographic memory!), if the name is already assigned. Sure, it only takes a few seconds to (1) bring up the find feature, (2) type in the symbol, and (3) do the search. But as programmers we are constantly inventing and assigning names. And if your modules are so big that you have to bring up a search tool everytime a new name needs to be assigned, well, then, i cannot image that workflow being conducive to any professional environment. But knowing Chris, we can only assume that he has a custom MUD solution. Who knows! > > When in doubt, and when it comes to style issues, there is > > one universal rule you should always strive to follow, and > > that rule is to be _consistent_. PEP8 underscores the > > importance of consistency, and you may want to read it. > > Yep! It does. Let me see... > > [snip link] > > """However, know when to be inconsistent -- sometimes style > guide recommendations just aren't applicable.""" Hey. Don't blame me. Blame Monty. > > I may exaggerate on this a bit more if you're interested. > > Isn't it normal for you to exaggerate everything? Nothing about me is "normal", Chris. Haven't you noticed? From rosuav at gmail.com Wed Jun 13 00:24:00 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jun 2018 14:24:00 +1000 Subject: Splitting up large python module impact on performance? In-Reply-To: <8c712483-5aba-4d53-b498-0c8940746701@googlegroups.com> References: <8c712483-5aba-4d53-b498-0c8940746701@googlegroups.com> Message-ID: On Wed, Jun 13, 2018 at 2:15 PM, Rick Johnson wrote: > On Tuesday, June 12, 2018 at 10:35:47 PM UTC-5, Chris Angelico wrote: > [...] >> A few thousand lines in a file is only a problem if you're >> using an editor that lacks a Find feature. Or if you use >> bad function/class names that you can't search for. > > I'm unaware of any text editor that doesn't have a find > feature. But, in a any event, the real problem is not a lack > of features, no, it's a matter of reducing the mental load. > The smaller the file, the less "off screen" data the > programmer must consider at any one time during the editing > process. > > Say for instance, you want to add a new symbol, and the > symbol is going in the module namespace. Okay. Seems simple > enough, right? But if your file contains thousands of lines > of code, you can't determine with any degree of certainly > (unless you have a photographic memory!), if the name is > already assigned. > > Sure, it only takes a few seconds to (1) bring up the find > feature, (2) type in the symbol, and (3) do the search. But > as programmers we are constantly inventing and assigning > names. And if your modules are so big that you have to bring > up a search tool everytime a new name needs to be assigned, > well, then, i cannot image that workflow being conducive to > any professional environment. If your names are at all sane, the mere fact that the feature doesn't exist is proof that the name doesn't exist. Oh wait, your code isn't anything remotely sane. But for the rest of us, large files aren't a problem. ChrisA From brgrt2 at gmail.com Wed Jun 13 00:29:53 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Wed, 13 Jun 2018 00:29:53 -0400 Subject: Posting warning message In-Reply-To: <20180612235746.GA85573@cskk.homeip.net> References: <2f713a93-d650-4764-8389-3e9e06cd82f3@googlegroups.com> <20180612235746.GA85573@cskk.homeip.net> Message-ID: On Tue, Jun 12, 2018 at 7:57 PM Cameron Simpson wrote: > > On 12Jun2018 07:14, Tamara Berger wrote: > >Just one more thing, Cameron. I was looking at an Apple support page, and it says "When you're logged in to your Mac using an administrator account, you can use the sudo command in the Terminal app to execute commands as a different user, such as the root user." (https://support.apple.com/en-us/HT202035). I am logged in as administrator. So why isn't sudo working for me? > > >P.S. How would I make the link I provided live? > > What link? This is why we trim quoted text and reply below the relevant bit directly: I don't know what link you provided or even whether it is there, just buried in the huge quoted text. Just cite it again, eg: > > How would I make this link (link here) live? The link is above, in the first paragraph, beginning with the words "Just one more thing, Cameron." > And then, of course, tell us what "live" means :-) Live means live. It is not a word I created. It means that the link has been activated, so clicking on it will take you to the associated page. Here is a definition from www.yourdictionary.com/live-link. "Live Link - Computer Definition: An active text or graphic link on a Web page. Clicking the link redirects the user to another Web page or a document or image." The link to the definition I just copied into this paragraph is not live because clicking on it will not do anything. This question became moot when I posted my message, because that action activated the link. That is why I asked in my next post how one can edit one's own messages, because at that point I would have deleted this post. Thanks, Tamara From cs at cskk.id.au Wed Jun 13 00:30:23 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 13 Jun 2018 14:30:23 +1000 Subject: pep8 Re: Posting warning message In-Reply-To: References: Message-ID: <20180613043023.GA75144@cskk.homeip.net> On 13Jun2018 00:05, Tamara Berger wrote: >Thanks for the in-depth answer. I'm going to have to read it >carefully, with the help of a Python glossary. Some of the terms you >use are new to me. No worries. Just ask if you don't find definitions. BTW, a "lint" program, or "linter" is a program for reporting on style trivia, trivial logic errors like variable used before defined (or never defined, which is often a typing error misspelling a variable or function name), and things that look like they might be bugs (a common mistake of mine is constructing exceptions like logging calls, and one of my linters has found dozens of these for me.) >>or am I supposed to root around for my module and make the edits one by one? > >I was trying to be amusing and didn't get my point across. Ah, ok then. Easy for stuff like that to fall flat in email. >>Finally, no you don't normally root around and change an installed module. >>Instead, modify your original copy and reinstall the newer version! > >What I meant was, do I have to open the file, search for, e.g., colons >and insert space after them? These were the sorts of picayune errors >picked up by PEP8 on my program. I deliberately omit such spaces when >I code because I like to do as little unnecessary work as possible. >There is enough repetitive coding as it is. I know some IDEs have word >completion suggestion for variables, etc, that the user creates. But >I'm practicing in barebones IDLE and that means a lot of extra work. Regrettably, yes, unless you're using an editor that has autoformatting support. Learn typing habits which minimise stuff like that, it saves going back later. I don't use IDEs on the whole, and I don't use an autoformatter for Python. My environment tends to be an editor window and a shell to run things from (thus: 2 terminals, one running vim and one running a shell). Training your fingers to do the trivia reflexively helps. And leaving the linting until _after_ you've got your code working correctly helps, because you aren't changing tasks midstream and you are linting code you've deleted or changed :-) An editor with syntax support can help. I use vi or vim, and its syntax support is fairly crude. Two things its does have which I use a lot is autoindent (as simple as starting the next line at the same indent as the one I just completed) and syntax highlighting, which colours keywords and identifiers and strings differently. When you make trivial mistakes like not closing a quote or misspelling a keyword or leaving off a colon there is often a visual cue. Cheers, Cameron Simpson From brgrt2 at gmail.com Wed Jun 13 00:41:26 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Wed, 13 Jun 2018 00:41:26 -0400 Subject: Posting warning message In-Reply-To: <20180612235045.GA68474@cskk.homeip.net> References: <20180612235045.GA68474@cskk.homeip.net> Message-ID: On Tue, Jun 12, 2018 at 7:50 PM Cameron Simpson wrote: > > On 12Jun2018 07:48, Tamara Berger wrote: > > > >> On Wed, Jun 13, 2018 at 12:17 AM, T Berger wrote: > >> > Sorry, to bother you again. But is there some way to edit a message once > >> > its posted? Or do I have to delete it and rewrite it? > >> > >> Nope. And you can't delete it either. > > > >I deleted them a number of time, then got a bar across the page indicating > >that a post had been deleted. > > As has been mentioned, any "delete" you do on Google Groups is pretty limited, > possibly only to Google's copy. The message has already gone planetwide. > > Google's delete _may_ propagate to the rest of usenet, and _may_ be obeyed in > some of those places. But it certainly doesn't propagate to the mailing list, > and even if it did, those of use who pull the list down to our personal mail > folders would ignore such a thing. > > >It's nuts that you can't edit your own post. > > No, it is actually good: > > - there's not one copy of your post that google can modify: it gets copied > planet wide, to thousands or millions of independent places > > - how do people discover that you've modified a post, to review your change? > how do their replies before your modification make any kind of sense if the > preceeding message is no longer what they replied to? I just meant edit within the moment or two after you've posted a message. I think a good feature in this forum would allow posters to edit their messages in just that way. I have such a feature enabled in gmail. I can "undo" my action for 30 seconds after I've clicked on "send." > The correct way to correct a post is to follow up to it (reply to it) with a > correction or clarification. That way everyone sees the change/fix as a new > messge. And it works even though the messages get copied everywhere, because > all that has to happen is to copy your own new message. Got it. Thanks, Tamara From rosuav at gmail.com Wed Jun 13 00:49:40 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jun 2018 14:49:40 +1000 Subject: Posting warning message In-Reply-To: References: <20180612235045.GA68474@cskk.homeip.net> Message-ID: On Wed, Jun 13, 2018 at 2:41 PM, Tamara Berger wrote: > I just meant edit within the moment or two after you've posted a > message. I think a good feature in this forum would allow posters to > edit their messages in just that way. I have such a feature enabled in > gmail. I can "undo" my action for 30 seconds after I've clicked on > "send." The way that works is that Gmail waits 30 seconds after you click "send" before it actually sends it. You could potentially have that anywhere, but it'll be implemented the same way: that all sending is delayed until you're happy to let it go through. It isn't a feature of "the forum"; it's a feature of the way you post to the newsgroup/mailing list. I, for instance, post directly to the mailing list via email; if you do that through Gmail, you'd get the exact same "undo send" feature. ChrisA From cs at cskk.id.au Wed Jun 13 00:57:10 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 13 Jun 2018 14:57:10 +1000 Subject: Posting warning message In-Reply-To: References: Message-ID: <20180613045710.GA81489@cskk.homeip.net> On 13Jun2018 00:41, Tamara Berger wrote: >I just meant edit within the moment or two after you've posted a >message. I think a good feature in this forum would allow posters to >edit their messages in just that way. I have such a feature enabled in >gmail. I can "undo" my action for 30 seconds after I've clicked on >"send." Ah. Well that's reasonable. Now you just need to petition Google for such a feature :-) Hmm, I wonder if there are browser extensions for that kind of thing. Alternatively you could move outside the forum web page and use other tools. Many of us interact with this via email, using whatever email reader we prefer. I am minded of a post to alt.peeves from long ago: I suppose the solution would be to close the composition window and let my article sit for half an hour or so once I've finished with it, and then go back and proofread it once more. But that would be a pain in the proverbial bifurcated derriere. Part of the experience of flaming is to load a searing missive into the conceptual breech of my SPARCcannon and pull the imaginary lanyard whilst flushed with the adrenaline of mortal combat. - Geoff Miller, Cheers, Cameron Simpson From dieter at handshake.de Wed Jun 13 00:59:07 2018 From: dieter at handshake.de (dieter) Date: Wed, 13 Jun 2018 06:59:07 +0200 Subject: What is the "Unpacking Arguments List" rule? References: <961e9bc2-59c3-f4fd-c35c-b6893988963f@ms4.hinet.net> Message-ID: <87po0vp9ic.fsf@handshake.de> Jach Fong writes: > ... > 4.7.4. Unpacking Argument Lists > The reverse situation occurs when the arguments are already in a list or > tuple but need to be unpacked for a function call requiring separate > positional arguments. > ... >>>> args = [3, 6] >>>> list(range(*args)) > """ > > I can't understand why line 19 works? Not sure what "line 19" is - but if it refers to the example above: "range" accepts (among others) 2 integer arguments. The "*args" above means: unpack the sequence in "args" into individual arguments. This means (with the values of the example above), that "range(*args)" is equivalent to "range(3, 6)". > Didn't it violate the rule of > "# non-keyword argument after a keyword argument"? No keyword arguments at all in the above example. > and why a more > reasonable look syntax gets an error? > > action(*args, progress) > ^ > SyntaxError: only named arguments may follow *expression File > "test.py", line 19 This is (in my view) a somewhat arbitrary restriction -- maybe introduced for symmetry with the function definition syntax. The message is quite clear, however: after the "*arg", you must pass keyword arguments only, i.e. they must have the form "param=value". > The only reason I can guess is that it checks with the rule in 4.7.3 > which is really unrelated. The "*any" notation used in different places > with different meaning, such as defining arbitrary argument, unpacking > argument or even in an assignment(a,*b=any). Maybe it will be better to > stop this syntax checking and lets both statements below valid:-) The "*args" and "**kw" are very helpfull. I hope (and expect) they will remain. From cs at cskk.id.au Wed Jun 13 01:02:48 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 13 Jun 2018 15:02:48 +1000 Subject: Posting warning message In-Reply-To: References: Message-ID: <20180613050248.GA95063@cskk.homeip.net> On 13Jun2018 00:29, Tamara Berger wrote: >On Tue, Jun 12, 2018 at 7:57 PM Cameron Simpson wrote: >> On 12Jun2018 07:14, Tamara Berger wrote: > >> >Just one more thing, Cameron. I was looking at an Apple support page, and it says "When you're logged in to your Mac using an administrator account, you can use the sudo command in the Terminal app to execute commands as a different user, such as the root user." (https://support.apple.com/en-us/HT202035). I am logged in as administrator. So why isn't sudo working for me? >> >> >P.S. How would I make the link I provided live? >> >> What link? This is why we trim quoted text and reply below the relevant bit directly: I don't know what link you provided or even whether it is there, just buried in the huge quoted text. Just cite it again, eg: >> >> How would I make this link (link here) live? > >The link is above, in the first paragraph, beginning with the words >"Just one more thing, Cameron." > >> And then, of course, tell us what "live" means :-) > >Live means live. It is not a word I created. It means that the link >has been activated, so clicking on it will take you to the associated >page. Here is a definition from www.yourdictionary.com/live-link. >"Live Link - Computer Definition: An active text or graphic link on a >Web page. Clicking the link redirects the user to another Web page or >a document or image." The link to the definition I just copied into >this paragraph is not live because clicking on it will not do >anything. Aha. Well, clicking on it worked for me! But then I'm using email in a terminal window where the terminal window has some support for recognising links and making them clickable. I'm surprised GMail doesn't do that as well. >This question became moot when I posted my message, because that >action activated the link. [...] It may be that the "post" action didn't do it, but Google Groups' message rendering did it. You don't need to make some things "live", your user interface will do it for you. To elaborate, I see your messages as plain text. But my reading tool (in this case the terminal emulator enclosing my mail reader) saw the link and made it a clickable thing for me. Cheers, Cameron Simpson From cs at cskk.id.au Wed Jun 13 01:06:46 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 13 Jun 2018 15:06:46 +1000 Subject: Index of entity in List with a Condition In-Reply-To: References: Message-ID: <20180613050646.GA11406@cskk.homeip.net> On 12Jun2018 21:06, Subhabrata Banerjee wrote: >Dear Sir, >Thank you for your kind reply. I am trying in few days time and getting back. >I made a small fix of my own and I would discuss it, too. Thank you for your >kind words, but I ignore unnecessary remarks. So please do not worry. >Meanwhile, please see as you are posting your mail id is coming here, it may >be misused. If possible, please omit it as you post next time. I have long considered my email id to be impossible to conceal, so I usually don't try. Please don't worry if it is misused by others, that is a risk I have accepted. Of course, as consideration to others, I try to avoid reciting someone else's contact info unless it is already publicly in play where I am. Cheers, Cameron Simpson From dieter at handshake.de Wed Jun 13 01:12:10 2018 From: dieter at handshake.de (dieter) Date: Wed, 13 Jun 2018 07:12:10 +0200 Subject: Splitting up large python module impact on performance? References: Message-ID: <87lgbjp8wl.fsf@handshake.de> Bill Deegan writes: > I'm doing some refactoring on a fairly large python codebase. > Some of the files are > 4000 lines long and contain many classes. I am typically working with systems consisting of hundreds of modules (Zope/Plone). Such large systems have a significant impact on startup time (caused by extensive file system operation during startup). For one application, I had to significantly optimize to get an acceptable startup time: I have put most of the application modules into zip archives). > Should I expect any performance hit from splitting some of the classes out > to other files? Important is the number of resulting modules (and how fast your file system is): for each module, Python accesses the file system potentially many times (up to 4 times, when my memory is right) and this may significantly slow down startup (if a large number of modules must be imported). From greg.ewing at canterbury.ac.nz Wed Jun 13 01:53:03 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 13 Jun 2018 17:53:03 +1200 Subject: Splitting up large python module impact on performance? In-Reply-To: References: Message-ID: Chris Angelico wrote: > A few thousand lines in a file is only a problem if you're using an > editor that lacks a Find feature. My editor has a find feature, but I still find it a nuisance to have to use it every single time I want to find something. -- Greg From greg.ewing at canterbury.ac.nz Wed Jun 13 02:01:14 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 13 Jun 2018 18:01:14 +1200 Subject: Posting warning message In-Reply-To: References: <2f713a93-d650-4764-8389-3e9e06cd82f3@googlegroups.com> <20180612235746.GA85573@cskk.homeip.net> Message-ID: Tamara Berger wrote: > Live means live. It is not a word I created. It means that the link > has been activated, so clicking on it will take you to the associated > page. Okay, I think "clickable" is a better word to describe this. Most mail reading software these days automatically recognises things that look like URLs and makes them clickable, so you usually don't need to do anything special. (And if you're sending plain text email, there's nothing special you *can* do.) -- Greg From hjp-python at hjp.at Wed Jun 13 02:14:29 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 13 Jun 2018 08:14:29 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: References: <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <87efhes55g.fsf@elektro.pacujo.net> <20180610215735.ezrrtdwyskfv4jrj@hjp.at> <20180611103109.lrn4dwjbleknfo7z@hjp.at> Message-ID: <20180613061429.c5drpooewoqrp4ss@hjp.at> On 2018-06-11 12:24:54 +0000, Steven D'Aprano wrote: > On Mon, 11 Jun 2018 12:31:09 +0200, Peter J. Holzer wrote: > > On 2018-06-11 01:06:37 +0000, Steven D'Aprano wrote: > >> On Sun, 10 Jun 2018 23:57:35 +0200, Peter J. Holzer wrote: > > > > [Note: I was talking about os.stat here, not os.path.exists. I agree > > that os.path.exists (and the other boolean functions) should simply > > return false] > > o_O > > Well... I don't know what to say. In a thread about os.path.exists, > you're talking about os.stat. I see. I don't understand why, Easy to explain. Marko wrote: | It may even be that the fix needs to go to os.stat(). That's for the | Python gods to decide. And to this I replied: | I'm not a Python god, but I don't think os.stat() should be changed. [and then explained why] I do take some care to quote only what is necessary for context and phrase my replies in a way which make it clear what I'm replying to. Apparently I wasn't successful in this case (even though the message is relatively short). If you have suggestions on how I might have been clearer, I'm all ears. > but if you want to derail the thread to discuss something else, I wasn't derailing the thread, I was replying to a specific suggestion. > okay, I'll play along. > > > [...] > > We are talking about platform-specific code here. > > Are we? I thought we were talking about Python and the os module. The > very first paragraph of the documentation for os says: > > This module provides a portable way of using operating > system dependent functionality. Note the magic words "system dependent functionality". The way you call os.stat() is the same on all systems, but what it actually does and what it returns depends on the OS. For example, the description of class os.stat_result says: | st_ino | | Platform dependent, but if non-zero, uniquely identifies the file | for a given value of st_dev. [...] | On some Unix systems (such as Linux), the following attributes may also | be available: [...] | On other Unix systems (such as FreeBSD), the following attributes may be | available (but may be only filled out if root tries to use them): [...] | On Mac OS systems, the following attributes may also be available: [...] | On Windows systems, the following attribute is also available: So, quite some variation dependent on the system type. > It also clearly states: > > All functions in this module raise OSError in the case of > invalid or inaccessible file names and paths, or other > arguments that have the correct type, but are not accepted > by the operating system. > > You know... like strings with NUL in them. Ok. I missed that. So either the documentation or the implementation should be fixed. In any case, if the implementation is changed, I still think that OSError(ENOENT) is wrong. It would have to be OSError(None, "embedded null byte"), or, if that is not possible (I haven't checked) OSError(EINVAL, "embedded null byte"), although that is slightly misleading (it implies that the OS returned EINVAL, which it didn't). The same check for NUL is also in other functions (e.g. open()), so those would have to be changed as well. > > On POSIX systems, there IS NO WAY to pass a filename with an > > embedded NUL byte to the OS. > > Mac OS X is certified as POSIX-compliant. As I pointed out in a previous > email, OS X also provides APIs that are perfectly capable of dealing with > NULs in file names. I wasn't entirely clear here. What I meant is that POSIX systems, as a group, provide no such way. Some specific systems may have such an API, but it isn't in POSIX and it not even likely to be the same on different systems, so it cannot be used portably across POSIX systems or even the subset of systems which allow NUL in filenames (unless that subset happens to contain only one OS). > POSIX specifies a *minimum* set of functionality, not a maximum. But when writing an application for POSIX systems you are interested in that minimum set of functionality. Plus maybe some common extensions. Oh, and from the test results Gregory Ewing posted, it looks like Python does use the POSIX API (and not the Carbon API) on MacOS. So you won't ever see a filename containing NUL in a Python program on MacOS and you won't be able to create one. 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 sales at caprilion.com.tw Wed Jun 13 02:21:53 2018 From: sales at caprilion.com.tw (sales at caprilion.com.tw) Date: Wed, 13 Jun 2018 14:21:53 +0800 Subject: What is the "Unpacking Arguments List" rule? In-Reply-To: <87po0vp9ic.fsf@handshake.de> References: <961e9bc2-59c3-f4fd-c35c-b6893988963f@ms4.hinet.net> <87po0vp9ic.fsf@handshake.de> Message-ID: <2619aef8-09f1-a706-76e1-45c5679e0d20@caprilion.com.tw> [Of the first part] line 19 is action(progress=progress, *args) where the args is a tuple args = (i, 3) and the function is defined as def action(id, reps, progress): In documents 4.7.2. Keyword Arguments, it says ''' def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'): ... ... but all the following calls would be invalid: ... parrot(voltage=5.0, 'dead') # non-keyword argument after a keyword argument ... ''' After unpack the args in line 19, it will be looks like action(progress=progress, i, 3) and it seems violate the above rule. [Of the second part] > The "*args" and "**kw" are very helpfull. I hope (and expect) > they will remain. There is no "**kw" involved in this topic:-) and the positional limit of "*args" in a function definitions has its own good reason:-) IMHO, there is no reason to check the *args has to appear at last in positional argument list in a function call because of there is no "unknown number of parameters" at the time of unpacking. It should be alright to write line 19 action(*args, progress) just like assignment below where both are valid. a, *b = any *a, b = any Best Regards, Jach Fong dieter at 2018/6/13 PM 12:59 wrote: > Jach Fong writes: >> ... >> 4.7.4. Unpacking Argument Lists >> The reverse situation occurs when the arguments are already in a list or >> tuple but need to be unpacked for a function call requiring separate >> positional arguments. >> ... >>>>> args = [3, 6] >>>>> list(range(*args)) >> """ >> >> I can't understand why line 19 works? > > Not sure what "line 19" is - but if it refers to the example above: > > "range" accepts (among others) 2 integer arguments. > The "*args" above means: unpack the sequence in "args" into > individual arguments. > This means (with the values of the example above), > that "range(*args)" is equivalent to "range(3, 6)". > >> Didn't it violate the rule of >> "# non-keyword argument after a keyword argument"? > > No keyword arguments at all in the above example. > >> and why a more >> reasonable look syntax gets an error? >> >> action(*args, progress) >> ^ >> SyntaxError: only named arguments may follow *expression File >> "test.py", line 19 > > This is (in my view) a somewhat arbitrary restriction -- maybe > introduced for symmetry with the function definition syntax. > > The message is quite clear, however: after the "*arg", > you must pass keyword arguments only, i.e. they must have > the form "param=value". > >> The only reason I can guess is that it checks with the rule in 4.7.3 >> which is really unrelated. The "*any" notation used in different places >> with different meaning, such as defining arbitrary argument, unpacking >> argument or even in an assignment(a,*b=any). Maybe it will be better to >> stop this syntax checking and lets both statements below valid:-) > > The "*args" and "**kw" are very helpfull. I hope (and expect) > they will remain. > --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From cs at cskk.id.au Wed Jun 13 02:43:26 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 13 Jun 2018 16:43:26 +1000 Subject: Splitting up large python module impact on performance? In-Reply-To: References: Message-ID: <20180613064326.GA63624@cskk.homeip.net> On 13Jun2018 17:53, Greg Ewing wrote: >Chris Angelico wrote: >>A few thousand lines in a file is only a problem if you're using an >>editor that lacks a Find feature. > >My editor has a find feature, but I still find it a nuisance >to have to use it every single time I want to find something. Tags files. A mapping from names to their definition lines. Tres handy. Cheers, Cameron Simpson From sapna.intell at gmail.com Wed Jun 13 03:02:40 2018 From: sapna.intell at gmail.com (Priya Singh) Date: Wed, 13 Jun 2018 00:02:40 -0700 (PDT) Subject: python lmfit.minimizer not working Message-ID: Dear All, I am trying to fit a spectrum using a power law model. I am using lmfit.minimizer. But the problem is that the value of parameter I am getting is same as the initial value. Means minimizer is not working. Here is the part of my code: p = Parameters() p.add('b', value=10) p.add('x_0', value=0.007, vary=False) p.add('a', value=0.2) p.add('tv', value=3.0, min=0.0) def residual(p): v = p.valuesdict() return (f_c_unmask - (v['b'] * (w_c_unmask/ v['x_0'] )**(-v['a']))*(np.exp(-v['tv']*kpa_smc))) mi = minimize(residual, p, method='leastsq') print(fit_report(mi)) The output I am getting: [[Fit Statistics]] # fitting method = leastsq # function evals = 48 # data points = 1304 # variables = 3 chi-square = 232448.935 reduced chi-square = 178.669435 Akaike info crit = 6764.93727 Bayesian info crit = 6780.45685 [[Variables]] b: 10.0000000 +/- 0.00000000 (0.00%) (init = 10) x_0: 0.007 (fixed) a: 0.20000000 +/- 0.00000000 (0.00%) (init = 0.2) tv: 4.8215e-12 +/- 0.00000000 (0.00%) (init = 3) From marko at pacujo.net Wed Jun 13 03:10:03 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 13 Jun 2018 10:10:03 +0300 Subject: Why exception from os.path.exists()? References: <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <87efhes55g.fsf@elektro.pacujo.net> <20180610215735.ezrrtdwyskfv4jrj@hjp.at> <20180611103109.lrn4dwjbleknfo7z@hjp.at> <20180613061429.c5drpooewoqrp4ss@hjp.at> Message-ID: <87lgbj17sk.fsf@elektro.pacujo.net> "Peter J. Holzer" : > On 2018-06-11 12:24:54 +0000, Steven D'Aprano wrote: >> It also clearly states: >> >> All functions in this module raise OSError in the case of >> invalid or inaccessible file names and paths, or other >> arguments that have the correct type, but are not accepted >> by the operating system. >> >> You know... like strings with NUL in them. Nice catch! > Ok. I missed that. So either the documentation or the implementation > should be fixed. > > In any case, if the implementation is changed, I still think that > OSError(ENOENT) is wrong. It would have to be OSError(None, "embedded > null byte"), or, if that is not possible (I haven't checked) > OSError(EINVAL, "embedded null byte"), although that is slightly > misleading (it implies that the OS returned EINVAL, which it didn't). You say "misleading", I say "abstracting". > The same check for NUL is also in other functions (e.g. open()), so > those would have to be changed as well. Maybe. > I wasn't entirely clear here. What I meant is that POSIX systems, as a > group, provide no such way. I still don't see how POSIX is directly relevant here. Marko From e+python-list at kellett.im Wed Jun 13 03:56:14 2018 From: e+python-list at kellett.im (Ed Kellett) Date: Wed, 13 Jun 2018 08:56:14 +0100 Subject: Splitting up large python module impact on performance? In-Reply-To: References: <8c712483-5aba-4d53-b498-0c8940746701@googlegroups.com> Message-ID: <8e3ed270-5951-9020-62c0-beeb343d5e07@kellett.im> On 2018-06-13 05:24, Chris Angelico wrote: > Oh wait, your code isn't anything remotely sane. But for the rest of > us, large files aren't a problem. I don't like large files--I think mostly because files are an organisational tool, they're quite good at that job, and one might as well use them. But slightly more concretely, Python encourages us to use module scope for things like imports, which can easily get messy and confusing when files are large. A find feature isn't a replacement for a global scope that's small enough to remember. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From ganesh1pal at gmail.com Wed Jun 13 04:08:00 2018 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Wed, 13 Jun 2018 13:38:00 +0530 Subject: Regex to extract multiple fields in the same line Message-ID: Hi Team, I wanted to parse a file and extract few feilds that are present after "=" in a text file . Example , form the below line I need to extract the values present after --struct =, --loc=, --size= and --log_file= Sample input line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 --path=/tmp/data_block.txt size=8' Expected output data_block /var/1000111/test18.log 0 8 Here is my sample code , its still not complete , I wanted to use regex and find and extract all the fields after " =", any suggestion or alternative way to optimize this further import re line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 --path=/tmp/data_block.txt size=8' r_loc = r"--loc=(\d+)" r_struct = r'--struct=(\w+)' if re.findall(r_loc, line): print re.findall(r_loc, line) if re.findall(r_struct, line): print re.findall(r_struct, line) root at X1:/# python regex_02.py ['0'] ['data_block'] I am a Linux user with python 2.7 Regards, Ganesh From huey.y.jiang at gmail.com Wed Jun 13 05:23:05 2018 From: huey.y.jiang at gmail.com (huey.y.jiang at gmail.com) Date: Wed, 13 Jun 2018 02:23:05 -0700 (PDT) Subject: How to make a button flashing? Message-ID: <8bacbe4a-ceb6-439c-b845-f2ba51d64f35@googlegroups.com> Hi All, I forgot the syntax of making a button flash, and failed to find an example in the web. I use Tkinter, to create a button. Then made it packed, and showed up. Now I am trying to make button b flashing, to make it get better noticed. I checked the docs, and found a method flash() is available, then I tried: b.flash() there was no error message popped out, but there was nothing happened also. I wonder who can give me this help? Thanks! Huey From rosuav at gmail.com Wed Jun 13 05:27:18 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jun 2018 19:27:18 +1000 Subject: Splitting up large python module impact on performance? In-Reply-To: <8e3ed270-5951-9020-62c0-beeb343d5e07@kellett.im> References: <8c712483-5aba-4d53-b498-0c8940746701@googlegroups.com> <8e3ed270-5951-9020-62c0-beeb343d5e07@kellett.im> Message-ID: On Wed, Jun 13, 2018 at 5:56 PM, Ed Kellett wrote: > On 2018-06-13 05:24, Chris Angelico wrote: >> Oh wait, your code isn't anything remotely sane. But for the rest of >> us, large files aren't a problem. > > I don't like large files--I think mostly because files are an > organisational tool, they're quite good at that job, and one might as > well use them. But slightly more concretely, Python encourages us to use > module scope for things like imports, which can easily get messy and > confusing when files are large. A find feature isn't a replacement for a > global scope that's small enough to remember. > It's more his definition of "large" and "small" that I was disagreeing with. You're absolutely right that a dense global scope is a problem; but a "one class per file" rule is a terrible idea. A hundred tiny files is far harder to work with than ten medium-sized files, and IMO a single file with all the code in it is only slightly worse. That is to say, I would prefer to work with a single gigantic file than a directory with lots and lots of tiny interdependent files, each one importing six or seven others. ChrisA From bellcanadardp at gmail.com Wed Jun 13 06:55:58 2018 From: bellcanadardp at gmail.com (bellcanadardp at gmail.com) Date: Wed, 13 Jun 2018 03:55:58 -0700 (PDT) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <7f780736-291f-4c65-b677-171691e326f7@googlegroups.com> <20180610212936.GA42086@cskk.homeip.net> Message-ID: <029a41c6-620f-4d25-8324-01b74176d6c0@googlegroups.com> On Sunday, 10 June 2018 17:29:59 UTC-4, Cameron Simpson wrote: > On 10Jun2018 13:04, bellcanadardp at gmail.com wrote: > >here is the full error once again > >to summarize, my script works fine in python2 > >i get this error trying to run it in python3 > >plz see below after the error, my settings for python 2 and python 3 > >for me it seems i need to change some settings to 'utf-8'..either just in python 3, since thats where i am having issues or change the settings to 'utf-8' both in python 2 and 3....i would appreciate feedback b4 i do some trial and error > >thanks for the consideration > >tommy > > > >*********************************************** > >Traceback (most recent call last): > >File "createIndex.py", line 132, in > >c.createindex() > >File "creatIndex.py", line 102, in createIndex > >pagedict=self.parseCollection() > >File "createIndex.py", line 47, in parseCollection > >for line in self.collFile: > >File > >"C:\Users\Robert\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py", > >line 23, in decode > >return codecs.charmap_decode(input,self.errors,decoding_table[0] > >UnicodeDecodeError: 'charmap'codec can't decode byte 0x9d in position 7414: character maps to > > Ok, this is more helpful. It says that the decoding error, which occurred in > ...\cp1252.py, was decoding lines from the file self.collFile. > > What is that file? And how was it opened? > > Also, your settings below may indeed be important. > > >*************************************************** > >python 3 settings > >import sys > > import locale > >locale.getpreferredencoding() > >'cp1252' > > The setting above is the default encoding used when you open a file in text > mode in Python 3, but you can override it. > > In Python 3 this matters a lot, because Python 3 strings are Unicode. In Python > 2, strings are just bytes, and are not "decoded" (there is a whole separate > "unicode" type for that when it matters). > > So in Python 3 the text file reader is decoding the text in the file according > to what it expects the encoding to be. > > Find the place where self.collFile is opened. You can specify the decoding > method there by adding the "encoding=" parameter to the open() call. It is > defaulting to "cp1252" because that is what locale.getpreferredencoding() > returns, but presumably the actual file data are not encoded that way. > > You can (a) find out what encoding _is_ used in the file and specify that or > (b) tell Python to be less picky. Choice (a) is better if it is feasible. > > If you have to guess because you don't know the encoding, one possibility is > that collFile contains utf-8 or utf-16; of these 2, utf-8 seems more likely > given the 0x9d byte causing the trouble. Try adding: > > encoding='utf-8' > > to the open() call, eg: > > self.collFile = open('path-to-the-coll-file', encoding='utf-8') > > at the appropriate place. > > If that just produces a different decoding error, you have 2 choices: pick an > encoding where every byte is "valid", such as 'iso8859-1', or to tell the > decode to just cope with th errors by adding the errors="replace" or > "errors="ignore" or errors="namereplace" parameter to the open() call. > > Both these choices have downsides. > > There are several ISO8859 encodings, and they might all be wrong for your file, > leading to _incorrect_ text lines. > > The errors="..." parameter also has downsides: you will also end up with > missing (errors="ignore") or incorrect (errors="replace" or > errors="namereplace") text, because the decoder has to do something with the > data: drop it or replace it with something wrong. The former loses data while > the latter puts in bad data, but at least it is visible if you inspect the data > later. > > The full documentation for Python 3's open() call is here: > > https://docs.python.org/3/library/functions.html#open > > where the various encoding= and errors= choices are described. > > Cheers, > Cameron Simpson hello community forums still failed but i tried many things and i beleive we are getting close to getting 1st is this script is from a library module online open source so many things in source code i may not trully be sure since i cant reach the original authors or sub authors..so the collFile has to be like a variable that would refer to the file Collection.dat..thats my best guess also in the error line , it doesnt actually open the file ...so i didnt try your code but i did try somethin similar b4 and it didnt work..here is a snippet of the code line error ******* def parseCollection(self): ''' returns the id, title and text of the next page in the collection ''' doc=[] for line in self.collFile: if line=='\n': break doc.append(line) ********* so as you can see there is not open file line to try to encode to utf-8 now here is what i tried anyways ******************* # -*- encoding: utf-8 -*- #for line in self.collFile.decode("utf-8"): #pagedict=self.parseCollection.encode("utf-8")() ********************** i tried the 1st line at the top of the script.....no effect i tried the 2nd line at the error line for the collFile....no effect i tried the 3rd line and the parseCollection line...no effect no here is what i found on stackoverflow and i had some progress but still get errors , so maybe i am not inserting the code in the right place i tried this in various spots in the createindex.py file ****************** import locale def getpreferredencoding(do_setlocale = True): return "utf-8" locale.getpreferredencoding = getpreferredencoding **************************** i tried this in the actual file, in many different spots...but no effect so i tried it at the python 3.6.4 interpeter prompt and when i enter the code and after last line..i press enter and then enter the finction locale.getpreferredencoding()......i do finally get "utf-8".....instaed of default "cp1252" but when i go to run my script,,,i still get the same cant decode byte in cp1252 file.................... so to me it seems my code that changed the preferedencoding is not posting to my file how can i make it permanent or actually have an effect cuz i do see the change at the interperter..but not yet at the script tommy From bellcanadardp at gmail.com Wed Jun 13 07:01:24 2018 From: bellcanadardp at gmail.com (bellcanadardp at gmail.com) Date: Wed, 13 Jun 2018 04:01:24 -0700 (PDT) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <7f780736-291f-4c65-b677-171691e326f7@googlegroups.com> <20180610212936.GA42086@cskk.homeip.net> Message-ID: <4a19dec0-e1b1-45a0-9044-8da2919f1906@googlegroups.com> On Sunday, 10 June 2018 17:29:59 UTC-4, Cameron Simpson wrote: > On 10Jun2018 13:04, bellcanadardp at gmail.com wrote: > >here is the full error once again > >to summarize, my script works fine in python2 > >i get this error trying to run it in python3 > >plz see below after the error, my settings for python 2 and python 3 > >for me it seems i need to change some settings to 'utf-8'..either just in python 3, since thats where i am having issues or change the settings to 'utf-8' both in python 2 and 3....i would appreciate feedback b4 i do some trial and error > >thanks for the consideration > >tommy > > > >*********************************************** > >Traceback (most recent call last): > >File "createIndex.py", line 132, in > >c.createindex() > >File "creatIndex.py", line 102, in createIndex > >pagedict=self.parseCollection() > >File "createIndex.py", line 47, in parseCollection > >for line in self.collFile: > >File > >"C:\Users\Robert\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py", > >line 23, in decode > >return codecs.charmap_decode(input,self.errors,decoding_table[0] > >UnicodeDecodeError: 'charmap'codec can't decode byte 0x9d in position 7414: character maps to > > Ok, this is more helpful. It says that the decoding error, which occurred in > ...\cp1252.py, was decoding lines from the file self.collFile. > > What is that file? And how was it opened? > > Also, your settings below may indeed be important. > > >*************************************************** > >python 3 settings > >import sys > > import locale > >locale.getpreferredencoding() > >'cp1252' > > The setting above is the default encoding used when you open a file in text > mode in Python 3, but you can override it. > > In Python 3 this matters a lot, because Python 3 strings are Unicode. In Python > 2, strings are just bytes, and are not "decoded" (there is a whole separate > "unicode" type for that when it matters). > > So in Python 3 the text file reader is decoding the text in the file according > to what it expects the encoding to be. > > Find the place where self.collFile is opened. You can specify the decoding > method there by adding the "encoding=" parameter to the open() call. It is > defaulting to "cp1252" because that is what locale.getpreferredencoding() > returns, but presumably the actual file data are not encoded that way. > > You can (a) find out what encoding _is_ used in the file and specify that or > (b) tell Python to be less picky. Choice (a) is better if it is feasible. > > If you have to guess because you don't know the encoding, one possibility is > that collFile contains utf-8 or utf-16; of these 2, utf-8 seems more likely > given the 0x9d byte causing the trouble. Try adding: > > encoding='utf-8' > > to the open() call, eg: > > self.collFile = open('path-to-the-coll-file', encoding='utf-8') > > at the appropriate place. > > If that just produces a different decoding error, you have 2 choices: pick an > encoding where every byte is "valid", such as 'iso8859-1', or to tell the > decode to just cope with th errors by adding the errors="replace" or > "errors="ignore" or errors="namereplace" parameter to the open() call. > > Both these choices have downsides. > > There are several ISO8859 encodings, and they might all be wrong for your file, > leading to _incorrect_ text lines. > > The errors="..." parameter also has downsides: you will also end up with > missing (errors="ignore") or incorrect (errors="replace" or > errors="namereplace") text, because the decoder has to do something with the > data: drop it or replace it with something wrong. The former loses data while > the latter puts in bad data, but at least it is visible if you inspect the data > later. > > The full documentation for Python 3's open() call is here: > > https://docs.python.org/3/library/functions.html#open > > where the various encoding= and errors= choices are described. > > Cheers, > Cameron Simpson hello just to clarify a typo from my last post(i make many , not verify good with key buttons)... #for line in self.collFile.decode("utf-8"): i actually write.encode...then i tried the decode but both dont have any effect thank you for any comments tommy From songofacandy at gmail.com Wed Jun 13 07:13:17 2018 From: songofacandy at gmail.com (INADA Naoki) Date: Wed, 13 Jun 2018 20:13:17 +0900 Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: <029a41c6-620f-4d25-8324-01b74176d6c0@googlegroups.com> References: <7f780736-291f-4c65-b677-171691e326f7@googlegroups.com> <20180610212936.GA42086@cskk.homeip.net> <029a41c6-620f-4d25-8324-01b74176d6c0@googlegroups.com> Message-ID: ?> 1st is this script is from a library module online open source If it's open source, why didn't you show the link to the soruce? I assume your code is this: https://github.com/siddharth2010/String-Search/blob/6770c7a1e811a5d812e7f9f7c5c83a12e5b28877/createIndex.py And self.collFile is opened here: https://github.com/siddharth2010/String-Search/blob/6770c7a1e811a5d812e7f9f7c5c83a12e5b28877/createIndex.py#L91 You need to add `encoding='utf-8'` argument. From steve+comp.lang.python at pearwood.info Wed Jun 13 07:17:31 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jun 2018 11:17:31 +0000 (UTC) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to References: <7f780736-291f-4c65-b677-171691e326f7@googlegroups.com> <20180610212936.GA42086@cskk.homeip.net> <4a19dec0-e1b1-45a0-9044-8da2919f1906@googlegroups.com> Message-ID: On Wed, 13 Jun 2018 04:01:24 -0700, bellcanadardp wrote: > for line in self.collFile.decode("utf-8"): > i actually write.encode...then i tried the decode but both dont have any > effect Raising AttributeError isn't an effect? py> f = open("/tmp/x") py> f.write.decode Traceback (most recent call last): File "", line 1, in AttributeError: 'builtin_function_or_method' object has no attribute 'decode' -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From __peter__ at web.de Wed Jun 13 07:21:31 2018 From: __peter__ at web.de (Peter Otten) Date: Wed, 13 Jun 2018 13:21:31 +0200 Subject: How to make a button flashing? References: <8bacbe4a-ceb6-439c-b845-f2ba51d64f35@googlegroups.com> Message-ID: huey.y.jiang at gmail.com wrote: > Hi All, > > I forgot the syntax of making a button flash, and failed to find an > example in the web. I use Tkinter, to create a button. Then made it > packed, and showed up. Now I am trying to make button b flashing, to make > it get better noticed. I checked the docs, and found a method flash() is > available, then I tried: > > b.flash() > > there was no error message popped out, but there was nothing happened > also. I wonder who can give me this help? Thanks! > > Huey Quoting http://tcl.tk/man/tcl8.6/TkCmd/button.htm#M16 """ pathName flash Flash the button. This is accomplished by redisplaying the button several times, alternating between the configured activebackground and background colors. At the end of the flash the button is left in the same normal/active state as when the command was invoked. This command is ignored if the button's state is disabled. """ So to see something you have to ensure that the two background colors actually differ. Complete example: import tkinter as tk root = tk.Tk() button = tk.Button(root, text="Hello") button.pack() button["activebackground"] = "red" button["background"] = "silver" root.after(1000, button.flash) root.mainloop() From steve+comp.lang.python at pearwood.info Wed Jun 13 07:35:34 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jun 2018 11:35:34 +0000 (UTC) Subject: Splitting up large python module impact on performance? References: <20180613040835.GA4683@cskk.homeip.net> Message-ID: On Wed, 13 Jun 2018 14:08:35 +1000, Cameron Simpson wrote: > I was going to say something along these lines, but to some extent this > feels like an unfair finger pointing exercise. Huge files can be a PITA; > having something that aids moving around them reduces the pain, but > doesn't remove the fact that sometimes something is too big. Indeed. As a simple practical matter, it is often simpler to navigate a large code base when you can open separate files in separate windows or tabs, rather than one giant file. An editor which supports multiple independent views of the same file can mitigate that somewhat, good tooling helps (but also only goes so far), but as the Zen says Namespaces are one honking great idea Even if we could put the entire Python std lib in a single giant file with half a million lines plus, we probably shouldn't. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rantingrickjohnson at gmail.com Wed Jun 13 08:28:14 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 13 Jun 2018 05:28:14 -0700 (PDT) Subject: Splitting up large python module impact on performance? In-Reply-To: References: <8c712483-5aba-4d53-b498-0c8940746701@googlegroups.com> <8e3ed270-5951-9020-62c0-beeb343d5e07@kellett.im> Message-ID: <9b347cbf-112a-4d5b-bac5-0895bf75eb2c@googlegroups.com> On Wednesday, June 13, 2018 at 4:27:35 AM UTC-5, Chris Angelico wrote: > It's more his definition of "large" and "small" that I was > disagreeing with. You're absolutely right that a dense > global scope is a problem; but a "one class per file" rule > is a terrible idea. What if the "one class" spans thousands of lines? Surely you don't believe that class definitions (outside of toy classes and academic examples, that is) are limited to a couple dozen lines, do you? > A hundred tiny files is far harder to work with than ten > medium-sized files, I doubt anyone here is suggesting that modules should be limited to 10 lines each, or something ridiculous like that. Heck, the minimum class definition _alone_ (at least, if you're going to properly utilize vertical whitespace) requires around 2 dozen lines. ## BEGIN MODULE ## 01# 02# import something here 03# 04# define constants here 05# 06# 07# (WHITE SPACE BUFFER) 08# 09# 10class MyClass(object): 11 def __init__(self): 12 pass 13 14 def method(self): 15 pass 16# 17# 18# (WHITE SPACE BUFFER) 19# 20# 21# (INITIALIZATION/TESTING/LOGIC/ETC) 22# 23# ## END MODULE ## That's 23 lines of code to define whitespace and boilerplate _alone_. > and IMO a single file with all the code in it is only > slightly worse. That is to say, I would prefer to work with > a single gigantic file than a directory with lots and lots > of tiny interdependent files, each one importing six or > seven others. Blame the import mess on a missing feature, not on those of us who prefer reasonably sized source files. To alleviate a large portion of the circular import mess (and depending on the coding style employed, possibly all of it), python's packaging system could have leveraged the power of "componentized modules" -- much the way that classes share variables between them using class attributes (no import required!) -- but unfortunately, this powerful feature was overlooked. And packages are nothing more than some kind of quasi directory tree which masquerades itself as a namespace so that a programmer can replace a long import path with a _dot_. WELL, WHOOP-DEE-DO! That's like a superhero without a superpower. Hmm... After considering the blinkered state of Python packages and the resulting pitfalls of the python import mechanism, we can only assume the Python gods found inspiration for this "hot mess" in the title of GnR's fifth studio album. From rhodri at kynesim.co.uk Wed Jun 13 08:29:53 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 13 Jun 2018 13:29:53 +0100 Subject: Regex to extract multiple fields in the same line In-Reply-To: References: Message-ID: On 13/06/18 09:08, Ganesh Pal wrote: > Hi Team, > > I wanted to parse a file and extract few feilds that are present after "=" > in a text file . > > > Example , form the below line I need to extract the values present after > --struct =, --loc=, --size= and --log_file= > > Sample input > > line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block > --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 > --path=/tmp/data_block.txt size=8' Did you mean "--size=8" at the end? That's what your explanation implied. > > Expected output > > data_block > /var/1000111/test18.log > 0 > 8 Regexs are more complicated than you need for this. Plain split will do. line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 --path=/tmp/data_block.txt --size=8' for item in line.split(): if item.startswith("--struct="): # You may want to tidy this up print(item[9:]) # ...and so on for the other fields Alternatively you could observe this is a previously solved problem and abuse argparse: import argparse parser = argparse.ArgumentParser() parser.add_argument("prefix", nargs=5) parser.add_argument("--struct") parser.add_argument("--log_file") parser.add_argument("--addr") parser.add_argument("--loc") parser.add_argument("--mirror") parser.add_argument("--path") parser.add_argument("--size") line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 --path=/tmp/data_block.txt --size=8' args = parser.parse_args(line.split()) print(args) -- Rhodri James *-* Kynesim Ltd From alister.ware at ntlworld.com Wed Jun 13 08:43:12 2018 From: alister.ware at ntlworld.com (Alister) Date: Wed, 13 Jun 2018 12:43:12 GMT Subject: What is the "Unpacking Arguments List" rule? References: <961e9bc2-59c3-f4fd-c35c-b6893988963f@ms4.hinet.net> <87po0vp9ic.fsf@handshake.de> <2619aef8-09f1-a706-76e1-45c5679e0d20@caprilion.com.tw> Message-ID: On Wed, 13 Jun 2018 14:21:53 +0800, sales at caprilion.com.tw wrote: > [Of the first part] > line 19 is > action(progress=progress, *args) > where the args is a tuple > args = (i, 3) > and the function is defined as > def action(id, reps, progress): > > In documents 4.7.2. Keyword Arguments, it says ''' > def parrot(voltage, state='a stiff', action='voom', type='Norwegian > Blue'): > ... > ... > but all the following calls would be invalid: > ... > parrot(voltage=5.0, 'dead') # non-keyword argument after a keyword > argument > ... > ''' > > After unpack the args in line 19, it will be looks like > action(progress=progress, i, 3) > and it seems violate the above rule. > > [Of the second part] > > The "*args" and "**kw" are very helpfull. I hope (and expect) > > they will remain. > There is no "**kw" involved in this topic:-) and the positional limit of > "*args" in a function definitions has its own good reason:-) > > IMHO, there is no reason to check the *args has to appear at last in > positional argument list in a function call because of there is no > "unknown number of parameters" at the time of unpacking. It should be > alright to write line 19 > action(*args, progress) Anyone wanting to write such code should be banned form ever accessing a computer. if you know how many arguments are going to be passed to match the *args part of this function then they should be assigned known variables otherwise the code will soon become an unmanageable mess. this is why the language specifications states it should only appear after all known positional arguments have been declared > just like assignment below where both are valid. > a, *b = any *a, b = any > > Best Regards, > Jach Fong > > > dieter at 2018/6/13 PM 12:59 wrote: >> Jach Fong writes: >>> ... >>> 4.7.4. Unpacking Argument Lists The reverse situation occurs when the >>> arguments are already in a list or tuple but need to be unpacked for a >>> function call requiring separate positional arguments. >>> ... >>>>>> args = [3, 6] list(range(*args)) >>> """ >>> >>> I can't understand why line 19 works? >> >> Not sure what "line 19" is - but if it refers to the example above: >> >> "range" accepts (among others) 2 integer arguments. >> The "*args" above means: unpack the sequence in "args" into >> individual arguments. >> This means (with the values of the example above), >> that "range(*args)" is equivalent to "range(3, 6)". >> >>> Didn't it violate the rule of "# non-keyword argument after a keyword >>> argument"? >> >> No keyword arguments at all in the above example. >> >>> and why a more reasonable look syntax gets an error? >>> >>> action(*args, progress) >>> ^ >>> SyntaxError: only named arguments may follow *expression File >>> "test.py", line 19 >> >> This is (in my view) a somewhat arbitrary restriction -- maybe >> introduced for symmetry with the function definition syntax. >> >> The message is quite clear, however: after the "*arg", >> you must pass keyword arguments only, i.e. they must have the form >> "param=value". >> >>> The only reason I can guess is that it checks with the rule in 4.7.3 >>> which is really unrelated. The "*any" notation used in different >>> places with different meaning, such as defining arbitrary argument, >>> unpacking argument or even in an assignment(a,*b=any). Maybe it will >>> be better to stop this syntax checking and lets both statements below >>> valid:-) >> >> The "*args" and "**kw" are very helpfull. I hope (and expect) >> they will remain. >> >> > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus -- I have a theory that it's impossible to prove anything, but I can't prove it. From steve+comp.lang.python at pearwood.info Wed Jun 13 09:04:53 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jun 2018 13:04:53 +0000 (UTC) Subject: Why exception from os.path.exists()? References: <20180610104908.g6tugqmxdodnjjtm@hjp.at> <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <87efhes55g.fsf@elektro.pacujo.net> <20180610215735.ezrrtdwyskfv4jrj@hjp.at> <20180611103109.lrn4dwjbleknfo7z@hjp.at> <20180613061429.c5drpooewoqrp4ss@hjp.at> <87lgbj17sk.fsf@elektro.pacujo.net> Message-ID: On Wed, 13 Jun 2018 10:10:03 +0300, Marko Rauhamaa wrote: > "Peter J. Holzer" : [...] >> I wasn't entirely clear here. What I meant is that POSIX systems, as a >> group, provide no such way. > > I still don't see how POSIX is directly relevant here. Linux users like to sneer at Windows users for believing that Windows is a synonym for "computer", that what Windows does is what all computers do, but Linux users (especially if they're also C programmers) sometimes have a hard time remembering that "what POSIX does" is no more a universal limitation on computing than "what Windows does". (And ironically, Linux doesn't even have POSIX certification.) That is, when they're not blindly writing shell scripts using bashisms and expecting them to work under any shell :-) I still would like to see one real-world use-case where the distinction between "file name is invalid because it has NUL" and "file name is invalid for any of a dozen other reasons" is necessary and important. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Wed Jun 13 09:06:30 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jun 2018 13:06:30 +0000 (UTC) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to References: <7f780736-291f-4c65-b677-171691e326f7@googlegroups.com> <20180610212936.GA42086@cskk.homeip.net> <029a41c6-620f-4d25-8324-01b74176d6c0@googlegroups.com> Message-ID: On Wed, 13 Jun 2018 03:55:58 -0700, bellcanadardp wrote: > the collFile has to be like a variable that would refer to the file > Collection.dat..thats my best guess also in the error line , it doesnt > actually open the file ... The file has to be opened if you are reading from it. If it isn't opened in the line of code you are looking at, look at the rest of the code. *Somewhere* is must be opened. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From ftg at lutix.org Wed Jun 13 09:09:10 2018 From: ftg at lutix.org (ftg at lutix.org) Date: Wed, 13 Jun 2018 13:09:10 +0000 Subject: Design of my program Message-ID: Hello everyone, Here is a small picture of my project. I'd like to fetch several datas from a website representing races results. Each line of the result contains rank, runner's name and other attributes of the runner (like club etc...). For now I have created 2 classes (Race and Runner). Methods of Race allow me to fetch datas on the www thanks to beautifulsoup module.I instanciate a race at the beginning of the scan and for each line I instanciate a Runner. I want to store all those information in a database (for both Race and Runner), but here is the point, I have the feeling, on a programming elegance point of view, that I have to separate methods that fetch from method that store and also have a kind of superior object that controls those 2 features. Moreover fetching will interact with storage: if race is already in database, no need to fetch again. How should I "design" this? Should I have only (despite my first impression) one class and all the methods in it? Should I create a parent class along with 2 childrens that manage the two kind of methods? Is there a design pattern for this? I precise I am relatively new in "intelligent" python programming ;) Thanks From fabienluce at gmail.com Wed Jun 13 09:23:57 2018 From: fabienluce at gmail.com (Fabien LUCE) Date: Wed, 13 Jun 2018 15:23:57 +0200 Subject: Design of my project Message-ID: Hello everyone, Here is a small picture of my project. I'd like to fetch several datas from a website representing races results. Each line of the result contains rank, runner's name and other attributes of the runner (like club etc...). For now I have created 2 classes (Race and Runner). Methods of Race allow me to fetch datas on the www thanks to beautifulsoup module.I instanciate a race at the beginning of the scan and for each line I instanciate a Runner. I want to store all those information in a database (for both Race and Runner), but here is the point, I have the feeling, on a programming elegance point of view, that I have to separate methods that fetch from method that store and also have a kind of superior object that controls those 2 features. Moreover fetching will interact with storage: if race is already in database, no need to fetch again. How should I "design" this? Should I have only (despite my first impression) one class and all the methods in it? Should I create a parent class along with 2 childrens that manage the two kind of methods? Is there a design pattern for this? I precise I am relatively new in "intelligent" python programming ;) Thanks From bellcanadardp at gmail.com Wed Jun 13 09:28:29 2018 From: bellcanadardp at gmail.com (bellcanadardp at gmail.com) Date: Wed, 13 Jun 2018 06:28:29 -0700 (PDT) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <7f780736-291f-4c65-b677-171691e326f7@googlegroups.com> <20180610212936.GA42086@cskk.homeip.net> <029a41c6-620f-4d25-8324-01b74176d6c0@googlegroups.com> Message-ID: <4a593dfd-1554-4031-80ac-0846217519ae@googlegroups.com> On Wednesday, 13 June 2018 07:14:06 UTC-4, INADA Naoki wrote: > ?> 1st is this script is from a library module online open source > > If it's open source, why didn't you show the link to the soruce? > I assume your code is this: > > https://github.com/siddharth2010/String-Search/blob/6770c7a1e811a5d812e7f9f7c5c83a12e5b28877/createIndex.py > > And self.collFile is opened here: > > https://github.com/siddharth2010/String-Search/blob/6770c7a1e811a5d812e7f9f7c5c83a12e5b28877/createIndex.py#L91 > > You need to add `encoding='utf-8'` argument. thank you INADA here is the line of code solution ************** self.collFile=open(self.collectionFile,'r',encoding='utf-8') ****************** it was tricky only because the modification had to be done not at the actual error line but further down in the file where INADA correctly pointed out where the collFile is opened thank you to all who posted, i truly appreciate all posts tommy From bellcanadardp at gmail.com Wed Jun 13 10:19:40 2018 From: bellcanadardp at gmail.com (bellcanadardp at gmail.com) Date: Wed, 13 Jun 2018 07:19:40 -0700 (PDT) Subject: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to In-Reply-To: References: <7f780736-291f-4c65-b677-171691e326f7@googlegroups.com> <20180610212936.GA42086@cskk.homeip.net> <029a41c6-620f-4d25-8324-01b74176d6c0@googlegroups.com> Message-ID: <28d230cb-afa4-435b-82d3-ca348e1a71f9@googlegroups.com> On Wednesday, 13 June 2018 09:12:32 UTC-4, Steven D'Aprano wrote: > On Wed, 13 Jun 2018 03:55:58 -0700, bellcanadardp wrote: > > > the collFile has to be like a variable that would refer to the file > > Collection.dat..thats my best guess also in the error line , it doesnt > > actually open the file ... > > The file has to be opened if you are reading from it. If it isn't opened > in the line of code you are looking at, look at the rest of the code. > *Somewhere* is must be opened. > > > > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson yes thank you further down in the script..the collectionFile is indeed opened and all it took was this line, to get the full program to work in python 3 ************** self.collFile=open(self.collectionFile,'r',encoding='utf-8') ****************** where ,encoding='utf-8' is the only change that had to be made, pointed out from INADA (plus i used the 2to3.py, which corrected many print statements) thanks alot for your efforts...im sure i will need this forum for future errors thanks again to all who posted for this python 2 to python3 utf-8 unicodedecode error its very kind and built on the online programmers community spirit tommy From grant.b.edwards at gmail.com Wed Jun 13 10:30:05 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 13 Jun 2018 14:30:05 +0000 (UTC) Subject: Posting warning message References: <20180612235045.GA68474@cskk.homeip.net> Message-ID: On 2018-06-13, Tamara Berger wrote: > I just meant edit within the moment or two after you've posted a > message. I think a good feature in this forum would allow posters to > edit their messages in just that way. I have such a feature enabled in > gmail. I can "undo" my action for 30 seconds after I've clicked on > "send." You refer to "this forum" as if you think it's some centrally controlled web application. It's not. It's a Usenet group gatewayed to a mailing list gatewayed to an archive/nntp server at gmane.org. Google then duct-taped the atrocity that is Google Groops onto the side of the Usenet group. https://en.wikipedia.org/wiki/Usenet https://en.wikipedia.org/wiki/Electronic_mailing_list https://en.wikipedia.org/wiki/Google_Groups IOW, there is no such think as "this forum". If you want whatever user interface you're using to send postings to hold onto them for 15 minutes to allow you a second chance to edit them, then you need to talk to whoever maintains the user interface that you use to send messages to the Usetnet group or mailing list. -- Grant Edwards grant.b.edwards Yow! LOOK!! Sullen at American teens wearing gmail.com MADRAS shorts and "Flock of Seagulls" HAIRCUTS! From brgrt2 at gmail.com Wed Jun 13 11:04:27 2018 From: brgrt2 at gmail.com (T Berger) Date: Wed, 13 Jun 2018 08:04:27 -0700 (PDT) Subject: PEP8 compliance Message-ID: <04df185b-04b6-47c7-8fd7-dfca48c8d947@googlegroups.com> Sorry for this basic question, but to change my code if it's failed the PEP8 test, what code do I use to open my program and make changes? Obviously, I should still be in bash, but then what? Thanks, Tamara From python at mrabarnett.plus.com Wed Jun 13 11:28:50 2018 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 13 Jun 2018 16:28:50 +0100 Subject: PEP8 compliance In-Reply-To: <04df185b-04b6-47c7-8fd7-dfca48c8d947@googlegroups.com> References: <04df185b-04b6-47c7-8fd7-dfca48c8d947@googlegroups.com> Message-ID: <09abb5e4-63ae-286c-50b8-a113f3d7d7ea@mrabarnett.plus.com> On 2018-06-13 16:04, T Berger wrote: > Sorry for this basic question, but to change my code if it's failed the PEP8 test, what code do I use to open my program and make changes? Obviously, I should still be in bash, but then what? > You edit it in a plain text editor (i.e. an editor for plain text). From steve+comp.lang.python at pearwood.info Wed Jun 13 11:45:07 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jun 2018 15:45:07 +0000 (UTC) Subject: PEP8 compliance References: <04df185b-04b6-47c7-8fd7-dfca48c8d947@googlegroups.com> Message-ID: On Wed, 13 Jun 2018 08:04:27 -0700, T Berger wrote: > Sorry for this basic question, but to change my code if it's failed the > PEP8 test, what code do I use to open my program and make changes? Use your text editor to modify the source code of the program. I'm of two minds here... on the one hand, I think that generally speaking, PEP 8 is a good style guide to follow, and I think that in the long run using a consistent style is a good habit to get into. On the other hand, some people follow PEP 8 religiously, except for the most important rule of all: the one about knowing when to break all the other rules. They can get obsessed with following PEP 8 rules even when it makes the code *worse*. I don't want to encourage that way of thinking. (Making purely stylistic changes to working code is also a good way to avoid doing actual productive work while still looking busy.) On the third hand, you're a beginner and you may be finding this whole experience confusing enough without also being told off by the computer because you wrote "x+1" instead of "x + 1". I don't find that helpful for beginners. So use your own judgement: if following PEP 8 becomes a chore, or if you would rather follow your own style, don't feel guilty about ignoring the style guide. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Wed Jun 13 11:55:16 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jun 2018 15:55:16 +0000 (UTC) Subject: Posting warning message References: <20180612235045.GA68474@cskk.homeip.net> Message-ID: On Wed, 13 Jun 2018 14:30:05 +0000, Grant Edwards wrote: [...] > You refer to "this forum" as if you think it's some centrally controlled > web application. It's not. It's a Usenet group gatewayed to a mailing > list gatewayed to an archive/nntp server at gmane.org. Google then > duct-taped the atrocity that is Google Groops onto the side of the > Usenet group. > > https://en.wikipedia.org/wiki/Usenet > > https://en.wikipedia.org/wiki/Electronic_mailing_list > > https://en.wikipedia.org/wiki/Google_Groups > > IOW, there is no such think as "this forum". Your description of the various technologies involved may be correct (although you've missed at least one: gmane) but there certainly is such a thing as "this forum". "This forum" is an abstraction of the community and technologies (note plural) we are using (comp.lang.python/pythonlist at python.org/whatever Google Groups calls it) from *other* forums like python-dev mailing list, Stackoverflow, #python on Freenode, the various Python-related sub- reddits, etc. A forum is not necessarily a single piece of technology controlled at a single point. Like the internet itself, forums can be decentralised and running on multiple diverse technologies. > If you want whatever user interface you're using to send postings to > hold onto them for 15 minutes to allow you a second chance to edit them, > then you need to talk to whoever maintains the user interface that you > use to send messages to the Usetnet group or mailing list. Indeed. The "I've changed my mind, don't send that message" function depends on the technology you use to communicate with the forum, not the forum. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Wed Jun 13 11:59:54 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jun 2018 15:59:54 +0000 (UTC) Subject: OFF-TOPIC Good sig [was Re: What is the "Unpacking Arguments List" rule?] References: <961e9bc2-59c3-f4fd-c35c-b6893988963f@ms4.hinet.net> <87po0vp9ic.fsf@handshake.de> <2619aef8-09f1-a706-76e1-45c5679e0d20@caprilion.com.tw> Message-ID: On Wed, 13 Jun 2018 12:43:12 +0000, Alister via Python-list wrote: > I have a theory that it's impossible to prove anything, but I can't > prove it. Heh, that reminds me of Stephen Pinker's comment from "Enlightenment Now": "one cannot reason that there's no such thing as reason" but on the other hand, Kurt G?del successfully proved using mathematics that (sufficiently powerful) maths is either inconsistent or incomplete, and we can never tell which. In a sense, G?del proved that it is impossible to prove *certain* things which are true, or disprove some which are false, but we have no way of proving which are which. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From marko at pacujo.net Wed Jun 13 12:34:26 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 13 Jun 2018 19:34:26 +0300 Subject: PEP8 compliance References: <04df185b-04b6-47c7-8fd7-dfca48c8d947@googlegroups.com> Message-ID: <87a7ry1w8d.fsf@elektro.pacujo.net> ram at zedat.fu-berlin.de (Stefan Ram): > T Berger writes: >>to change my code if it's failed the PEP8 test, >>what code do I use to open my program and make changes? > > A text editor (emacs, vim, pico, IDLE, notepad, ex, sed, ...). > What did you use to write your code in the first place? This is a hugely important introductory hurdle for beginning programmers. The Wikipedia page on the topic, makes the gross mistake of equating a text editor with Microsoft's Notepad. In fact, I couldn't find a simple introduction to the topic on the Web. One shouldn't think the term is obvious to beginning programmers because they probably don't understand that "text editor" refers to a very specific, hard-to-explain kind of a tool. Maybe, before you try to explain what a text editor is, you should try to explain what "text" is. For that you have to start explaining the organization of information, "characters" and integers as sequences of bits, and bits as disturbances in the force... Marko From brgrt2 at gmail.com Wed Jun 13 12:35:00 2018 From: brgrt2 at gmail.com (T Berger) Date: Wed, 13 Jun 2018 09:35:00 -0700 (PDT) Subject: PEP8 compliance In-Reply-To: <04df185b-04b6-47c7-8fd7-dfca48c8d947@googlegroups.com> References: <04df185b-04b6-47c7-8fd7-dfca48c8d947@googlegroups.com> Message-ID: <3308dc46-d0d2-494f-a724-c84732f57ec0@googlegroups.com> On Wednesday, June 13, 2018 at 11:04:39 AM UTC-4, T Berger wrote: > Sorry for this basic question, but to change my code if it's failed the PEP8 test, what code do I use to open my program and make changes? Obviously, I should still be in bash, but then what? > > Thanks, > > Tamara I did make the changes in IDLE, but I thought I must be in the wrong place. The line of code I got in terminal was: /Users/TamaraB/Desktop/mymodules/vsearch.py:1:25: E231 missing whitespace after ':' def search4vowels(phrase:str)->set: I thought the 1:25: E231 couldn't be referring to anything in my text editor. But now I see that 1:25 refers to the first line, 25th spot (I suppose the 25 refers to the spot BEFORE which I'm supposed to add white space. I don't know what the E231 refers to, but it doesn't seem helpful. And, no, I'm not going to make these picayune changes that actually make the code harder to read. Adding a white space between "phrase:" and "str" just splits apart a conceptual unit in a complicated line of code. I was just doing this exercise in my workbook. Thanks, Tamara From tmrsg11 at gmail.com Wed Jun 13 12:53:57 2018 From: tmrsg11 at gmail.com (C W) Date: Wed, 13 Jun 2018 12:53:57 -0400 Subject: What data types does matplotlib pyplot take? Message-ID: Hi everyone, I'm curious what data types pyplot takes. It seems that it can take numpy series, pandas series, and possibly pandas dataframe? How many people data types are out there? Is that true for all functions in like hist(), bar(), line(), etc? Is there an official documentation that lists this? I have seen this official documentation: https://pandas.pydata.org/pandas-docs/stable/visualization.html But it does not specify data types. I would appreciate it if someone can point it out. Thank you! From tjreedy at udel.edu Wed Jun 13 13:16:26 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jun 2018 13:16:26 -0400 Subject: How to make a button flashing? In-Reply-To: References: <8bacbe4a-ceb6-439c-b845-f2ba51d64f35@googlegroups.com> Message-ID: On 6/13/2018 7:21 AM, Peter Otten wrote: > huey.y.jiang at gmail.com wrote: >> I forgot the syntax of making a button flash, and failed to find an >> example in the web. I use Tkinter, to create a button. Then made it >> packed, and showed up. Now I am trying to make button b flashing, to make >> it get better noticed. I checked the docs, and found a method flash() is >> available, then I tried: >> >> b.flash() >> >> there was no error message popped out, but there was nothing happened >> also. I wonder who can give me this help? Thanks! > Quoting http://tcl.tk/man/tcl8.6/TkCmd/button.htm#M16 > > """ > pathName flash > Flash the button. This is accomplished by redisplaying the button > several times, alternating between the configured activebackground and > background colors. At the end of the flash the button is left in the same > normal/active state as when the command was invoked. This command is ignored > if the button's state is disabled. > """ > > So to see something you have to ensure that the two background colors > actually differ. Complete example: > > import tkinter as tk > root = tk.Tk() > > button = tk.Button(root, text="Hello") > button.pack() > > button["activebackground"] = "red" > button["background"] = "silver" > > root.after(1000, button.flash) > root.mainloop() On Windows, this flashes red about 3 time in about .2 seconds and stops. The following repeat the flashing every second, and shows how to stop an animation. import tkinter as tk root = tk.Tk() def stop_flash(): print('stop_flash') root.after_cancel(flasher) button = tk.Button(root, text="Hello", command=stop_flash, background='silver', activebackground='red') button.pack() def flash(): global flasher button.flash() flasher = root.after(1000, flash) flasher = root.after(1000, flash) root.mainloop() -- Terry Jan Reedy From rantingrickjohnson at gmail.com Wed Jun 13 13:19:21 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 13 Jun 2018 10:19:21 -0700 (PDT) Subject: PEP8 compliance In-Reply-To: References: <04df185b-04b6-47c7-8fd7-dfca48c8d947@googlegroups.com> Message-ID: On Wednesday, June 13, 2018 at 10:47:40 AM UTC-5, Steven D'Aprano wrote: > I'm of two minds here... Obviously. > [...] So use your own judgement: if following PEP 8 becomes > a chore, or if you would rather follow your own style, > don't feel guilty about ignoring the style guide. IOWs: "Be consistent!" "Except, when you don't want to be." "Although, it might be a good idea to be." "Hmm. Well. Maybe not. "Who knows!" Great advice Steven. Great advice. > "Ever since I learned about confirmation bias, I've been > seeing it everywhere." -- Jon Ronson I'm glad to see you've chosen a new foot quote, because as opposed to the previous one, this is _actually_ funny. From tjreedy at udel.edu Wed Jun 13 13:31:37 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jun 2018 13:31:37 -0400 Subject: PEP8 compliance In-Reply-To: <3308dc46-d0d2-494f-a724-c84732f57ec0@googlegroups.com> References: <04df185b-04b6-47c7-8fd7-dfca48c8d947@googlegroups.com> <3308dc46-d0d2-494f-a724-c84732f57ec0@googlegroups.com> Message-ID: On 6/13/2018 12:35 PM, T Berger wrote: > I did make the changes in IDLE, but I thought I must be in the wrong place. This is a good place for beginners. > The line of code I got in terminal was: > /Users/TamaraB/Desktop/mymodules/vsearch.py:1:25: E231 missing whitespace after ':' > def search4vowels(phrase:str)->set: The recommended style is def search4vowels(phrase: str) -> set: > I thought the 1:25: E231 couldn't be referring to anything in my text editor. But now I see that 1:25 refers to the first line, 25th spot (I suppose the 25 refers to the spot BEFORE which I'm supposed to add white space. 25 is the slice position between ':' and 's', where a new space would go. > I don't know what the E231 refers to, but it doesn't seem helpful. It is an arbitrary label. You can probably use it to look up the 'error'. > And, no, I'm not going to make these picayune changes that actually make the code harder to read. Adding a white space between "phrase:" and "str" just splits apart a conceptual unit in a complicated line of code. I was just doing this exercise in my workbook. *I* happen to prefer the spaced-out version, but I also prefer that people do what they want, especially in private code. You should also able to use E231 to tell pep8 to not report E231s (because you disagree with the recommendation). -- Terry Jan Reedy From ganesh1pal at gmail.com Wed Jun 13 13:32:35 2018 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Wed, 13 Jun 2018 23:02:35 +0530 Subject: Regex to extract multiple fields in the same line In-Reply-To: References: Message-ID: On Wed, Jun 13, 2018 at 5:59 PM, Rhodri James wrote: > On 13/06/18 09:08, Ganesh Pal wrote: > >> Hi Team, >> >> I wanted to parse a file and extract few feilds that are present after "=" >> in a text file . >> >> >> Example , form the below line I need to extract the values present after >> --struct =, --loc=, --size= and --log_file= >> >> Sample input >> >> line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block >> --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 >> --path=/tmp/data_block.txt size=8' >> > > Did you mean "--size=8" at the end? That's what your explanation implied. Yes James you got it right , I meant "--size=8 " ., Hi Team, I played further with python's re.findall() and I am able to extract all the required fields , I have 2 further questions too , please suggest Question 1: Please let me know the mistakes in the below code and suggest if it can be optimized further with better regex # This code has to extract various the fields from a single line ( assuming the line is matched here ) of a log file that contains various values (and then store the extracted values in a dictionary ) import re line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 --path=/tmp/data_block.txt --size=8' #loc is an number r_loc = r"--loc=([0-9]+)" r_size = r'--size=([0-9]+)' r_struct = r'--struct=([A-Za-z_]+)' r_log_file = r'--log_file=([A-Za-z0-9_/.]+)' if re.findall(r_loc, line): print re.findall(r_loc, line) if re.findall(r_size, line): print re.findall(r_size, line) if re.findall(r_struct, line): print re.findall(r_struct, line) if re.findall(r_log_file, line): print re.findall(r_log_file, line) o/p: root at X1:/Play_ground/SPECIAL_TYPES/REGEX# python regex_002.py ['0'] ['8'] ['data_block'] ['/var/1000111/test18.log'] Question 2: I tried to see if I can use re.search with look behind assertion , it seems to work , any comments or suggestions Example: import re line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 --path=/tmp/data_block.txt --size=8' match = re.search(r'(?P(?<=--loc=)([0-9]+))', line) if match: print match.group('loc') o/p: root at X1:/Play_ground/SPECIAL_TYPES/REGEX# python regex_002.py 0 I want to build the sub patterns and use match.group() to get the values , some thing as show below but it doesn't seem to work match = re.search(r'(?P(?<=--loc=)([0-9]+))' r'(?P(?<=--size=)([0-9]+))', line) if match: print match.group('loc') print match.group('size') Regards, Ganesh From blindanagram at nowhere.com Wed Jun 13 13:35:10 2018 From: blindanagram at nowhere.com (BlindAnagram) Date: Wed, 13 Jun 2018 18:35:10 +0100 Subject: Matplotlib and Python 3.7 Message-ID: Now that Python 3.7 has reached release candidate status, I thought that I should try it. But I use Matplotlib a lot and this fails to install with Python 3.7 because "freetype and png cannot be installed" (I am using Windows 10). I am wondering if anyone knows how to work around this issue? I looked for a way to report the issue to the Matplotlib team but the only forum I could find for reporting issues required me to create an account, which I don't want to do. From p.f.moore at gmail.com Wed Jun 13 13:44:28 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 13 Jun 2018 18:44:28 +0100 Subject: PEP8 compliance In-Reply-To: <3308dc46-d0d2-494f-a724-c84732f57ec0@googlegroups.com> References: <04df185b-04b6-47c7-8fd7-dfca48c8d947@googlegroups.com> <3308dc46-d0d2-494f-a724-c84732f57ec0@googlegroups.com> Message-ID: On 13 June 2018 at 17:35, T Berger wrote: > I did make the changes in IDLE, but I thought I must be in the wrong place. The line of code I got in terminal was: > /Users/TamaraB/Desktop/mymodules/vsearch.py:1:25: E231 missing whitespace after ':' > def search4vowels(phrase:str)->set: > > I thought the 1:25: E231 couldn't be referring to anything in my text editor. But now I see that 1:25 refers to the first line, 25th spot (I suppose the 25 refers to the spot BEFORE which I'm supposed to add white space. I don't know what the E231 refers to, but it doesn't seem helpful. That's the correct interpretation of that message. Well done (and I don't mean that patronisingly) - messages from tools like whatever it was that reported these errors to you are often rooted in assumptions which are *far* from obvious to someone new to programming. To expand a little: The 1 is as you say the line on which the tool spotted the problem. Program text is viewed (by tools just as by people) as a block of lines of text, numbered starting from line 1. Tools will number blank lines (lines with nothing on them) equally with lines with text on them - sometimes people number only the non-blank lines, but programming tools don't typically do that. The 25 does refer to the position on the line that the tool is referring to. Position is measured in characters. You say "spot", and that's as good a term as any. Characters as counted by a computer include letters, numbers, punctuation, and even spaces. You can think of it as "column on the screen" in this case and not be far wrong. The E231 is a code for the specific error that the tool found - so it means "missing whitespace". The text of the message is all you need to deal with, but having a unique, concise code can help, for example when looking up information in the documentation or the source code of the tool. It's very helpful to quote error numbers like this when reporting problems or asking for help, as they are more precise (to people who know how to interpret them) than the textual message. But reporting the text as well is crucial, as it saves people having to look up the code to know what you're talking about! > And, no, I'm not going to make these picayune changes that actually make the code harder to read. Adding a white space between "phrase:" and "str" just splits apart a conceptual unit in a complicated line of code. I was just doing this exercise in my workbook. That's a very good attitude. There *are* good reasons for many of the style recommendations, and as you learn more you may be persuaded to change your view, but style guides are all ultimately about making your code "readable", and it sounds like you are already developing a good sense of how you want to group and present your code. That's something many programmers can take a long time (years, in some cases) to develop, and a good sense of style is often (IMO) what separates good programmers from mediocre/bad ones. Reading other people's code is often a very good way to develop a sense of style, if you get the chance to do so. Paul From vinay_sajip at yahoo.co.uk Wed Jun 13 14:06:51 2018 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 13 Jun 2018 18:06:51 +0000 (UTC) Subject: ANN: A new version (0.4.3) of python-gnupg has been released. It contains a security-related change - please update to this version References: <2072830771.8419896.1528913211931.ref@mail.yahoo.com> Message-ID: <2072830771.8419896.1528913211931@mail.yahoo.com> A new version of the Python module which wraps GnuPG has been released. What Changed?=============This is a security-fix release, and all users are strongly encouraged to upgrade.This fix mitigates against CVE-2018-12020. See the discoverer's blog post [6] formore information. Brief summary: * Added --no-verbose to the gpg command line, in case verbose is specified in? gpg.conf - we don't need verbose output. This release [2] has been signed with my code signing key: Vinay Sajip (CODE SIGNING KEY) Fingerprint: CA74 9061 914E AC13 8E66 EADB 9147 B477 339A 9B86 Recent changes to PyPI don't show the GPG signature with the download links.An alternative download source where the signatures are available is the project'sown downloads page [5]. What Does It Do?================The gnupg module allows Python programs to make use of thefunctionality provided by the Gnu Privacy Guard (abbreviated GPG orGnuPG). Using this module, Python programs can encrypt and decryptdata, digitally sign documents and verify digital signatures, manage(generate, list and delete) encryption keys, using proven Public KeyInfrastructure (PKI) encryption technology based on OpenPGP. This module is expected to be used with Python versions >= 2.4, as itmakes use of the subprocess module which appeared in that version ofPython. This module is a newer version derived from earlier work byAndrew Kuchling, Richard Jones and Steve Traugott. A test suite using unittest is included with the source distribution. Simple usage: >>> import gnupg>>> gpg = gnupg.GPG(gnupghome='/path/to/keyring/directory')>>> gpg.list_keys() [{...'fingerprint': 'F819EE7705497D73E3CCEE65197D5DAC68F1AAB2','keyid': '197D5DAC68F1AAB2','length': '1024','type': 'pub','uids': ['', 'Gary Gross (A test user) ']},{...'fingerprint': '37F24DD4B918CC264D4F31D60C5FEFA7A921FC4A','keyid': '0C5FEFA7A921FC4A','length': '1024',...'uids': ['', 'Danny Davis (A test user) ']}]>>> encrypted = gpg.encrypt("Hello, world!", ['0C5FEFA7A921FC4A'])>>> str(encrypted) '-----BEGIN PGP MESSAGE-----\nVersion: GnuPG v1.4.9 (GNU/Linux)\n\nhQIOA/6NHMDTXUwcEAf.-----END PGP MESSAGE-----\n'>>> decrypted = gpg.decrypt(str(encrypted), passphrase='secret')>>> str(decrypted) 'Hello, world!'>>> signed = gpg.sign("Goodbye, world!", passphrase='secret')>>> verified = gpg.verify(str(signed))>>> print "Verified" if verified else "Not verified" 'Verified' As always, your feedback is most welcome (especially bug reports [3],patches and suggestions for improvement, or any other points via themailing list/discussion group [4]). Enjoy! Cheers Vinay SajipRed Dove Consultants Ltd. [1] https://bitbucket.org/vinay.sajip/python-gnupg[2] https://pypi.python.org/pypi/python-gnupg/0.4.3[3] https://bitbucket.org/vinay.sajip/python-gnupg/issues[4] https://groups.google.com/forum/#!forum/python-gnupg[5] https://bitbucket.org/vinay.sajip/python-gnupg/downloads/[6] https://neopg.io/blog/gpg-signature-spoof/ From ian.g.kelly at gmail.com Wed Jun 13 14:36:03 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Jun 2018 12:36:03 -0600 Subject: OFF-TOPIC Good sig [was Re: What is the "Unpacking Arguments List" rule?] In-Reply-To: References: <961e9bc2-59c3-f4fd-c35c-b6893988963f@ms4.hinet.net> <87po0vp9ic.fsf@handshake.de> <2619aef8-09f1-a706-76e1-45c5679e0d20@caprilion.com.tw> Message-ID: On Wed, Jun 13, 2018 at 10:10 AM Steven D'Aprano wrote: > > On Wed, 13 Jun 2018 12:43:12 +0000, Alister via Python-list wrote: > > > I have a theory that it's impossible to prove anything, but I can't > > prove it. > > Heh, that reminds me of Stephen Pinker's comment from "Enlightenment Now": > > "one cannot reason that there's no such thing as reason" > > but on the other hand, Kurt G?del successfully proved using mathematics > that (sufficiently powerful) maths is either inconsistent or incomplete, > and we can never tell which. In a sense, G?del proved that it is > impossible to prove *certain* things which are true, or disprove some > which are false, but we have no way of proving which are which. I'm not an expert, but my understanding of the Second Incompleteness Theorem is that a consistent, sufficiently powerful formal system cannot prove its own consistency. It doesn't mean that we can't prove it in some other way. From python at mrabarnett.plus.com Wed Jun 13 15:00:27 2018 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 13 Jun 2018 20:00:27 +0100 Subject: Regex to extract multiple fields in the same line In-Reply-To: References: Message-ID: On 2018-06-13 18:32, Ganesh Pal wrote: > On Wed, Jun 13, 2018 at 5:59 PM, Rhodri James wrote: > >> On 13/06/18 09:08, Ganesh Pal wrote: >> >>> Hi Team, >>> >>> I wanted to parse a file and extract few feilds that are present after "=" >>> in a text file . >>> >>> >>> Example , form the below line I need to extract the values present after >>> --struct =, --loc=, --size= and --log_file= >>> >>> Sample input >>> >>> line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block >>> --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 >>> --path=/tmp/data_block.txt size=8' >>> >> >> Did you mean "--size=8" at the end? That's what your explanation implied. > > Yes James you got it right , I meant "--size=8 " ., > > Hi Team, > > I played further with python's re.findall() and I am able to extract all > the required fields , I have 2 further questions too , please suggest > > Question 1: > > Please let me know the mistakes in the below code and suggest if it can > be optimized further with better regex > > > # This code has to extract various the fields from a single line ( > assuming the line is matched here ) of a log file that contains various > values (and then store the extracted values in a dictionary ) > > import re > > line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block > --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 > --path=/tmp/data_block.txt --size=8' > > #loc is an number > r_loc = r"--loc=([0-9]+)" > r_size = r'--size=([0-9]+)' > r_struct = r'--struct=([A-Za-z_]+)' > r_log_file = r'--log_file=([A-Za-z0-9_/.]+)' > > Here you're searching for each match _twice_: > if re.findall(r_loc, line): > print re.findall(r_loc, line) > > if re.findall(r_size, line): > print re.findall(r_size, line) > > if re.findall(r_struct, line): > print re.findall(r_struct, line) > > if re.findall(r_log_file, line): > print re.findall(r_log_file, line) > > > o/p: > root at X1:/Play_ground/SPECIAL_TYPES/REGEX# python regex_002.py > ['0'] > ['8'] > ['data_block'] > ['/var/1000111/test18.log'] > > > Question 2: > > I tried to see if I can use re.search with look behind assertion , it > seems to work , any comments or suggestions > > Example: > > import re > > line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block > --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 > --path=/tmp/data_block.txt --size=8' > > match = re.search(r'(?P(?<=--loc=)([0-9]+))', line) > if match: > print match.group('loc') > > > o/p: root at X1:/Play_ground/SPECIAL_TYPES/REGEX# python regex_002.py > > 0 > > > I want to build the sub patterns and use match.group() to get the values > , some thing as show below but it doesn't seem to work > > > match = re.search(r'(?P(?<=--loc=)([0-9]+))' > r'(?P(?<=--size=)([0-9]+))', line) > if match: > print match.group('loc') > print match.group('size') > You can combine them into a single findall: >>> captures = re.findall(r'--(loc=[0-9]+)|--(size=[0-9]+)|--(struct=[A-Za-z_]+)|--(log_file=[A-Za-z0-9_/.]+)', line) >>> captures [('', '', 'struct=data_block', ''), ('', '', '', 'log_file=/var/1000111/test18.log'), ('loc=0', '', '', ''), ('', 'size=8', '', '')] In each tuple of the list, there's only one match, the others are empty, so get rid of the empty ones: >>> [c for cap in captures for c in cap if c] Split each of the matches on the first '=': >>> [c.split('=', 1) for cap in captures for c in cap if c] For ease of use, pass the key/value pairs into dict: >>> info = dict(c.split('=', 1) for cap in captures for c in cap if c) >>> info {'struct': 'data_block', 'log_file': '/var/1000111/test18.log', 'loc': '0', 'size': '8'} From adam.preble at gmail.com Wed Jun 13 16:02:19 2018 From: adam.preble at gmail.com (adam.preble at gmail.com) Date: Wed, 13 Jun 2018 13:02:19 -0700 (PDT) Subject: Distributing a Python module as .rpm and .deb packages across major distributions In-Reply-To: References: <2347a88b-d676-4a8e-8495-b77c4cfe0561@googlegroups.com> <7F886456-06C7-4FFA-8E44-3B02D6E0C748@barrys-emacs.org> Message-ID: <407e689c-0be6-45d9-a02e-9fd2d60585ad@googlegroups.com> On Sunday, June 10, 2018 at 3:05:45 PM UTC-5, Barry wrote: > The way I learn about the details of RPM packaging is to look at examples like what I wish to achieve. > > I would go get the source RPM for a python2 package from each distro you want to supoort and read its .spec file. > > I see on fedora that the way they install packages that are from pypi makes it possible to use pip list to see them. The impression I'm getting is that they're using tools to help in this process, rather than manually specifying crafting the package descriptors and shell scripts. I'd like to do similar, of course, since it sounds like it's a lot easier. I have looked at a few already, which is where I got where I was already. In Debian packages I see a lot of references to dh_python, and the regularity of it implies the lines in question are being generated--but by what? The source packages will have these generated outputs, which means it's already too late in the process when it comes to reverse engineering what generated those outputs. From rosuav at gmail.com Wed Jun 13 16:09:04 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jun 2018 06:09:04 +1000 Subject: PEP8 compliance In-Reply-To: References: <04df185b-04b6-47c7-8fd7-dfca48c8d947@googlegroups.com> Message-ID: On Thu, Jun 14, 2018 at 1:45 AM, Steven D'Aprano wrote: > On Wed, 13 Jun 2018 08:04:27 -0700, T Berger wrote: > >> Sorry for this basic question, but to change my code if it's failed the >> PEP8 test, what code do I use to open my program and make changes? > > Use your text editor to modify the source code of the program. > > > I'm of two minds here... on the one hand, I think that generally > speaking, PEP 8 is a good style guide to follow, and I think that in the > long run using a consistent style is a good habit to get into. > > On the other hand, some people follow PEP 8 religiously, except for the > most important rule of all: the one about knowing when to break all the > other rules. They can get obsessed with following PEP 8 rules even when > it makes the code *worse*. I don't want to encourage that way of thinking. ... and THIS RIGHT HERE is why the tool should not be called "pep8". Didn't this exact discussion come up and the tool got renamed? There's big confusion here between "following PEP 8" (the document) and "failing the PEP8 test" (the tool). ChrisA From hjp-python at hjp.at Wed Jun 13 16:37:25 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 13 Jun 2018 22:37:25 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: <87lgbj17sk.fsf@elektro.pacujo.net> References: <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <87efhes55g.fsf@elektro.pacujo.net> <20180610215735.ezrrtdwyskfv4jrj@hjp.at> <20180611103109.lrn4dwjbleknfo7z@hjp.at> <20180613061429.c5drpooewoqrp4ss@hjp.at> <87lgbj17sk.fsf@elektro.pacujo.net> Message-ID: <20180613203725.u3c4htfvjd4ejy2y@hjp.at> On 2018-06-13 10:10:03 +0300, Marko Rauhamaa wrote: > "Peter J. Holzer" : > > On 2018-06-11 12:24:54 +0000, Steven D'Aprano wrote: > >> It also clearly states: > >> > >> All functions in this module raise OSError in the case of > >> invalid or inaccessible file names and paths, or other > >> arguments that have the correct type, but are not accepted > >> by the operating system. > >> > >> You know... like strings with NUL in them. > > Nice catch! > > > Ok. I missed that. So either the documentation or the implementation > > should be fixed. > > > > In any case, if the implementation is changed, I still think that > > OSError(ENOENT) is wrong. It would have to be OSError(None, "embedded > > null byte"), or, if that is not possible (I haven't checked) > > OSError(EINVAL, "embedded null byte"), although that is slightly > > misleading (it implies that the OS returned EINVAL, which it didn't). > > You say "misleading", I say "abstracting". If I get an error message which leads me on a wild goose chase, I call that misleading when I'm in a good mood. If I'm feeling cranky, I call it "lying". > > The same check for NUL is also in other functions (e.g. open()), so > > those would have to be changed as well. > > Maybe. Consistency is a virtue. > > I wasn't entirely clear here. What I meant is that POSIX systems, as a > > group, provide no such way. > > I still don't see how POSIX is directly relevant here. POSIX systems (or more specifically, systems where the Python implementation uses a POSIX-conforming API to access the file system) are relevant here because on such systems the Python implementation needs to treat filenames with an embedded NUL specially. The reasons have been mentioned several times in this threadm, but to recap: 1) The API uses nul-terminated byte strings for file names. 2) Python may also use byte strings for for file names, but they are not nul-terminated (they may contain nuls) 3) Simply passing a pointer to the start of a python byte string to the OS seems to work, and is therefore tempting. 4) But this would mean the OS gets a different file name than the application passed to it if the name contains NUL, which can lead to security holes (this isn't theoretical, it has happened) 5) Therefore an implemntation must not succumb to the tempation in point 3 and must explicitely check for NULs. A theoretical Python implementation on MacOS using the Carbon API wouldn't have to do this (and in fact it shouldn't). This is system-dependent code ensuring that the OS API is called correctly. For os.stat() POSIX is further relevant because stat() is a POSIX function. On POSIX systems, os.stat() is just a very thin wrapper around the syscall. On other systems, POSIX stat is basically emulated by invoking other system calls. A user on a POSIX system should therefore expect the result of os.stat() be the same as that of the stat() system call (i.e. if successful the fields should have the same values and if not, the exception should reflect the errno returned by the OS). On other systems a user can only expect a rough correspondence between what the actual system call returned and what os.stat() returns, because there may not be a simple 1:1 mapping. POSIX specifies a number of error codes which can be returned by stat(): [EACCES] Search permission is denied for a component of the path prefix. [EIO] An error occurred while reading from the file system. [ELOOP] A loop exists in symbolic links encountered during resolution of the path argument. [ENAMETOOLONG] The length of a component of a pathname is longer than {NAME_MAX}. [ENOENT] A component of path does not name an existing file or path is an empty string. [ENOTDIR] A component of the path prefix names an existing file that is neither a directory nor a symbolic link to a directory, or the path argument contains at least one non- character and ends with one or more trailing characters and the last pathname component names an existing file that is neither a directory nor a symbolic link to a directory. [EOVERFLOW] The file size in bytes or the number of blocks allocated to the file or the file serial number cannot be represented correctly in the structure pointed to by buf. A Python application may want to treat these errors differently. Even if the application doesn't, the user reading the stack trace will want to see the correct errno and not some generic "something went wrong" message. Note that none of these covers "file name contains an illegal character" for the simple reason that on POSIX systems there are no illegal characters. So none of these is a good choice for the errno parameter of an OSError to be thrown. One might try to find out what Linux returns on a filesystem which doesn't allow some characters, but that would be Linux specific and probably even file system specific, so not a good choice for a situation which can occur on many systems. I think that the best way to do it would be set errno to None, because it reflects rather clearly that the OS didn't return an error (because it wasn't even called). As a user and programmer I find it very important to get precise error messages. I really, really hate it when the computer lies to me. However, errno is normally an int, and None isn't. So I'm not sure how much code an OSError with errno=None would break. Maybe the reason why os.stat raises a ValueError instead of an OSError is that whoever wrote that code thought an OSError with an unexpected errno would break too much existing code. I don't know. Raising an OSError with errno=EINVAL is too close to lying for my taste, but I could live with that. For non-POSIX systems, most of the above doesn't apply. Which brings me to the third reason why I talk about POSIX: Because I know it. I don't know much about the Windows API and I know almost nothing about Carbon, so I cannot offer much of an opinion on how Python should be implemented on them. But I do know a number of POSIX systems[1] and I know how I would like Python to behave on them and how this behaviour can be implemented. hp [1] I probably should use the past tense here. 20 years ago I regularly used several different Unixes. Now it's only Linux. And I don't see that changing anytime soon. -- _ | 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 hjp-python at hjp.at Wed Jun 13 16:43:16 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 13 Jun 2018 22:43:16 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: <87602p36td.fsf@elektro.pacujo.net> References: <242A1681-E081-4D66-9EBC-A9335AE57CB3@gmail.com> <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <87efhes55g.fsf@elektro.pacujo.net> <20180610215735.ezrrtdwyskfv4jrj@hjp.at> <20180611103109.lrn4dwjbleknfo7z@hjp.at> <87602p36td.fsf@elektro.pacujo.net> Message-ID: <20180613204316.oaht3ld3i5v6k6bg@hjp.at> On 2018-06-11 14:23:42 +0300, Marko Rauhamaa wrote: > "Peter J. Holzer" : > > On 2018-06-11 01:06:37 +0000, Steven D'Aprano wrote: > >> Baking a limitation of some file systems into the high-level > >> interface is simply a *bad idea*. > > > > We aren't talking about a high-level interface here. > > Call it high-level or not, we *are* talking about an interface > ("os.path") whose whole raison d'?tre is abstracting OS specifics from > basic pathname processing. I can understand that Stephen missed the fact that we were talking about os.stat, not os.path. But how could you miss that? It was you who brought up os.stat and I was just replying to your message. Please try to keep track of what you are talking about, otherwise discussions will not be very productive. > > You are barking up the wrong tree here. > > I believe the "wrong tree" would want a ValueError to be raised in this > situation. Nope. The wrong tree is os.path, when we are talking about os.stat. 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 anthra.norell at bluewin.ch Wed Jun 13 16:53:22 2018 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Wed, 13 Jun 2018 22:53:22 +0200 Subject: Regex to extract multiple fields in the same line In-Reply-To: References: Message-ID: <10022be1-8a7f-8eea-cd0d-85c895e8a3bd@bluewin.ch> On 06/13/2018 07:32 PM, Ganesh Pal wrote: > On Wed, Jun 13, 2018 at 5:59 PM, Rhodri James wrote: > >> On 13/06/18 09:08, Ganesh Pal wrote: >> >>> Hi Team, >>> >>> I wanted to parse a file and extract few feilds that are present after "=" >>> in a text file . >>> >>> >>> Example , form the below line I need to extract the values present after >>> --struct =, --loc=, --size= and --log_file= >>> >>> Sample input >>> >>> line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block >>> --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 >>> --path=/tmp/data_block.txt size=8' >>> >> Did you mean "--size=8" at the end? That's what your explanation implied. How's this? (Supposing that the values contain no spaces): >>> regex = re.compile (r"--(struct|loc|size|mirror|log_file)\s*=\s*([^\s]+)") >>> regex.findall (line) [('struct', 'data_block'), ('log_file', '/var/1000111/test18.log'), ('loc', '0'), ('mirror', '10')] Frederic > > > > Yes James you got it right , I meant "--size=8 " ., > > > Hi Team, > > > I played further with python's re.findall() and I am able to extract all > the required fields , I have 2 further questions too , please suggest > > > Question 1: > > Please let me know the mistakes in the below code and suggest if it can > be optimized further with better regex > > > # This code has to extract various the fields from a single line ( > assuming the line is matched here ) of a log file that contains various > values (and then store the extracted values in a dictionary ) > > import re > > line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block > --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 > --path=/tmp/data_block.txt --size=8' > > #loc is an number > r_loc = r"--loc=([0-9]+)" > r_size = r'--size=([0-9]+)' > r_struct = r'--struct=([A-Za-z_]+)' > r_log_file = r'--log_file=([A-Za-z0-9_/.]+)' > > > if re.findall(r_loc, line): > print re.findall(r_loc, line) > > if re.findall(r_size, line): > print re.findall(r_size, line) > > if re.findall(r_struct, line): > print re.findall(r_struct, line) > > if re.findall(r_log_file, line): > print re.findall(r_log_file, line) > > > o/p: > root at X1:/Play_ground/SPECIAL_TYPES/REGEX# python regex_002.py > ['0'] > ['8'] > ['data_block'] > ['/var/1000111/test18.log'] > > > Question 2: > > I tried to see if I can use re.search with look behind assertion , it > seems to work , any comments or suggestions > > Example: > > import re > > line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block > --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 > --path=/tmp/data_block.txt --size=8' > > match = re.search(r'(?P(?<=--loc=)([0-9]+))', line) > if match: > print match.group('loc') > > > o/p: root at X1:/Play_ground/SPECIAL_TYPES/REGEX# python regex_002.py > > 0 > > > I want to build the sub patterns and use match.group() to get the values > , some thing as show below but it doesn't seem to work > > > match = re.search(r'(?P(?<=--loc=)([0-9]+))' > r'(?P(?<=--size=)([0-9]+))', line) > if match: > print match.group('loc') > print match.group('size') > > Regards, > Ganesh From marko at pacujo.net Wed Jun 13 16:56:09 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 13 Jun 2018 23:56:09 +0300 Subject: Why exception from os.path.exists()? References: <90D155D8-B042-4621-A1E8-7ACE2260BD0E@barrys-emacs.org> <87efhes55g.fsf@elektro.pacujo.net> <20180610215735.ezrrtdwyskfv4jrj@hjp.at> <20180611103109.lrn4dwjbleknfo7z@hjp.at> <20180613061429.c5drpooewoqrp4ss@hjp.at> <87lgbj17sk.fsf@elektro.pacujo.net> <20180613203725.u3c4htfvjd4ejy2y@hjp.at> Message-ID: <87sh5qpfrq.fsf@elektro.pacujo.net> "Peter J. Holzer" : > POSIX specifies a number of error codes which can be returned by stat(): > > [EACCES] > Search permission is denied for a component of the path prefix. > [EIO] > An error occurred while reading from the file system. > [ELOOP] > A loop exists in symbolic links encountered during resolution of the > path argument. > [ENAMETOOLONG] > The length of a component of a pathname is longer than {NAME_MAX}. > [ENOENT] > A component of path does not name an existing file or path is an > empty string. > [ENOTDIR] > A component of the path prefix names an existing file that is > neither a directory nor a symbolic link to a directory, or the path > argument contains at least one non- character and ends with > one or more trailing characters and the last pathname > component names an existing file that is neither a directory nor a > symbolic link to a directory. > [EOVERFLOW] > The file size in bytes or the number of blocks allocated to the file > or the file serial number cannot be represented correctly in the > structure pointed to by buf. > > [...] > > Note that none of these covers "file name contains an illegal character" > for the simple reason that on POSIX systems there are no illegal > characters. > > So none of these is a good choice for the errno parameter of an OSError > to be thrown. The natural errno value would be EINVAL, which is returned whenever a system call is invoked with an illegal argument. Marko From tkadm30 at yandex.com Wed Jun 13 17:37:54 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Wed, 13 Jun 2018 17:37:54 -0400 Subject: Django-hotsauce 1.0 LTS (Commercial Edition) now available for preorder!! Message-ID: Dear all, It is my pleasure to announce the availability of Django-hotsauce 1.0 LTS (Commercial Edition) for preorder: https://www.livestore.ca/product/django-hotsauce/ Purchase this gem using Paypal before October 1st 2018 with the discount code "djangohotsauce" and get 50% off the regular price! Everyone who will make this purchase will receive their registered copy of Django-hotsauce 1.0 on October 1st 2018. One more thing, this discount code also works for all commercial softwares listed on livestore.ca! :) Have fun!! Etienne -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From hjp-python at hjp.at Wed Jun 13 18:10:05 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Thu, 14 Jun 2018 00:10:05 +0200 Subject: Why exception from os.path.exists()? In-Reply-To: <87sh5qpfrq.fsf@elektro.pacujo.net> References: <20180610215735.ezrrtdwyskfv4jrj@hjp.at> <20180611103109.lrn4dwjbleknfo7z@hjp.at> <20180613061429.c5drpooewoqrp4ss@hjp.at> <87lgbj17sk.fsf@elektro.pacujo.net> <20180613203725.u3c4htfvjd4ejy2y@hjp.at> <87sh5qpfrq.fsf@elektro.pacujo.net> Message-ID: <20180613221005.deqqapwdzokctzgq@hjp.at> On 2018-06-13 23:56:09 +0300, Marko Rauhamaa wrote: > "Peter J. Holzer" : > > POSIX specifies a number of error codes which can be returned by stat(): [...] > > So none of these is a good choice for the errno parameter of an OSError > > to be thrown. > > The natural errno value would be EINVAL, which is returned whenever a > system call is invoked with an illegal argument. And you present it like it's a new idea, after I have already discussed the pros and cons of that twice (the second time in the very message you just replied to, except that decided to not quote that part but some other part ...) hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From cs at cskk.id.au Wed Jun 13 18:35:13 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 14 Jun 2018 08:35:13 +1000 Subject: Design of my project In-Reply-To: References: Message-ID: <20180613223513.GA48778@cskk.homeip.net> On 13Jun2018 15:23, Fabien LUCE wrote: >Here is a small picture of my project. >I'd like to fetch several datas from a website representing races results. >Each line of the result contains rank, runner's name and other attributes >of the runner (like club etc...). >For now I have created 2 classes (Race and Runner). >Methods of Race allow me to fetch datas on the www thanks to beautifulsoup >module.I instanciate a race at the beginning of the scan and for each line >I instanciate a Runner. >I want to store all those information in a database (for both Race and >Runner), but here is the point, I have the feeling, on a programming >elegance point of view, that I have to separate methods that fetch from >method that store and also have a kind of superior object that controls >those 2 features. >Moreover fetching will interact with storage: if race is already in >database, no need to fetch again. >How should I "design" this? Should I have only (despite my first >impression) one class and all the methods in it? Should I create a parent >class along with 2 childrens that manage the two kind of methods? >Is there a design pattern for this? My inclination would be to start by providing a class which "wraps" your Race database table, and presents it as a mapping. Something along the lines of: class RaceTable: def __init__(self, database_connection, table_name): self.conn = database_connection self.table_name = table_name def __contains__(self, race_id): ... do SQL to see if the race_id is already present, return True or False def __getitem__(self, race_id): ... do SQL to fetch a Race row from the table and return it ... def __setitem__(self, race_id, race_info): ... do SQL to store race_info in the table ... The special __foo__ methods (called "dunder" methods in the Puython world because of the "double underscore") are what make the class look like a Python "dict" from outside: when you perform a mapping method like "value in x" or "x[key] = value", Python calls x.__contains__ or x.__setitem__ for you. Look up "Emulating Container Types" here: https://docs.python.org/3/reference/datamodel.html#emulating-container-types That will show you how to write a class like the above example to implement a "maping" interface. You don't need to implement everything, just what you need. The example above only implements 3 methods. Then your outer code can look a bit like: race_store = RaceTable(database_connection, 'race_table_name_here') ... if race_id in race_store: ... mention that this race_id is already stored ... else: race_store[race_id] = race_info So the objective here is a simple class that makes it easy to talk about where your information is stored in nice Pythonic terms, and which hides the details of database access - that lets you talk about the data in a sensbile and clear way outside the storage class, and also leaves scrope for changing the storage mechanism later without changing the main code (eg from a conventional SQL database to some other service). Cheers, Cameron Simpson From jfong at ms4.hinet.net Wed Jun 13 20:03:04 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Thu, 14 Jun 2018 08:03:04 +0800 Subject: What is the "Unpacking Arguments List" rule? In-Reply-To: References: <961e9bc2-59c3-f4fd-c35c-b6893988963f@ms4.hinet.net> <87po0vp9ic.fsf@handshake.de> <2619aef8-09f1-a706-76e1-45c5679e0d20@caprilion.com.tw> Message-ID: <93c5d6e9-1967-5f1c-afd8-6fe7a4d428d2@ms4.hinet.net> Alister via Python-list at 2018/6/13 PM 08:43 wrote: >> IMHO, there is no reason to check the *args has to appear at last in >> positional argument list in a function call because of there is no >> "unknown number of parameters" at the time of unpacking. It should be >> alright to write line 19 >> action(*args, progress) > > Anyone wanting to write such code should be banned form ever accessing a > computer. Won't it be too hard to this guy:-) > if you know how many arguments are going to be passed to match the *args > part of this function then they should be assigned known variables > otherwise the code will soon become an unmanageable mess. I think it's depend on the situation. > this is why the language specifications states it should only appear > after all known positional arguments have been declared To a function call, where the spec is? --Jach --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From huey.y.jiang at gmail.com Wed Jun 13 20:57:20 2018 From: huey.y.jiang at gmail.com (huey.y.jiang at gmail.com) Date: Wed, 13 Jun 2018 17:57:20 -0700 (PDT) Subject: How to make a button flashing? In-Reply-To: <8bacbe4a-ceb6-439c-b845-f2ba51d64f35@googlegroups.com> References: <8bacbe4a-ceb6-439c-b845-f2ba51d64f35@googlegroups.com> Message-ID: On Wednesday, June 13, 2018 at 5:23:17 PM UTC+8, huey.y... at gmail.com wrote: > Hi All, > > I forgot the syntax of making a button flash, and failed to find an example in the web. I use Tkinter, to create a button. Then made it packed, and showed up. Now I am trying to make button b flashing, to make it get better noticed. I checked the docs, and found a method flash() is available, then I tried: > > b.flash() > > there was no error message popped out, but there was nothing happened also. I wonder who can give me this help? Thanks! > > Huey Thanks, Terry, it works! From jlee54 at gmail.com Wed Jun 13 21:07:41 2018 From: jlee54 at gmail.com (Jim Lee) Date: Wed, 13 Jun 2018 18:07:41 -0700 Subject: Django-hotsauce 1.0 LTS (Commercial Edition) now available for preorder!! In-Reply-To: References: Message-ID: <6192e413-4d4f-6fee-c6a5-76f063485abe@gmail.com> I haven't purchased commercial software in decades, so I'm not up on the prevailing business model, but I have to ask: Why would anyone purchase software and then agree to wait 14 weeks for it to be delivered?? I can see that model for hardware, where material resources are limited and a finite number of product is produced, but software?? What's the point? On 06/13/2018 02:37 PM, Etienne Robillard wrote: > Dear all, > > It is my pleasure to announce the availability of Django-hotsauce 1.0 > LTS (Commercial Edition) for preorder: > > https://www.livestore.ca/product/django-hotsauce/ > > Purchase this gem using Paypal before October 1st 2018 with the > discount code "djangohotsauce" and get 50% off the regular price! > > Everyone who will make this purchase will receive their registered > copy of Django-hotsauce 1.0 on October 1st 2018. > > One more thing, this discount code also works for all commercial > softwares listed on livestore.ca! :) > > > Have fun!! > > Etienne > > From sharan.basappa at gmail.com Wed Jun 13 22:51:21 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Wed, 13 Jun 2018 19:51:21 -0700 (PDT) Subject: pattern Message-ID: <63fd3a0e-bc40-4b68-b598-b0a2183900cc@googlegroups.com> Can anyone explain to me the purpose of "pattern" in the line below: documents.append((w, pattern['class'])) documents is declared as a list as follows: documents.append((w, pattern['class'])) From sharan.basappa at gmail.com Wed Jun 13 22:56:49 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Wed, 13 Jun 2018 19:56:49 -0700 (PDT) Subject: mutable sequences Message-ID: The term mutable appears quite often in Python. Can anyone explain what is meant by mutable and immutable sequences. For example, Python lists are mutable. BTW, is the below explanation correct (it is taken from a book I am reading) Python lists are mutable sequences. They are very similar to tuples, but they don't have the restrictions due to immutability. It says lists are mutable and then says they are immutable??? From huey.y.jiang at gmail.com Wed Jun 13 23:14:31 2018 From: huey.y.jiang at gmail.com (huey.y.jiang at gmail.com) Date: Wed, 13 Jun 2018 20:14:31 -0700 (PDT) Subject: How to find an object existing? Message-ID: Hi All, root = Tkinter.Tk() button = Tkinter.Button(root, text="Find me") button.pack() I created a button, Python object. I recall I can check this object existing by using winfo, such as winfo.exists(button). However, I forgot which super class contains this winfo method. I printed out dir(os), dir(sys), dir(Tkinter), but did not find this winfo method. I wonder who will be kindly drop down a few lines? Thanks a lot! Huey From jlee54 at gmail.com Wed Jun 13 23:52:27 2018 From: jlee54 at gmail.com (Jim Lee) Date: Wed, 13 Jun 2018 20:52:27 -0700 Subject: mutable sequences In-Reply-To: References: Message-ID: On 06/13/2018 07:56 PM, Sharan Basappa wrote: > The term mutable appears quite often in Python. > Can anyone explain what is meant by mutable and immutable sequences. Mutable means changeable, and immutible means not mutable, or unchangeable. > For example, Python lists are mutable. > > BTW, is the below explanation correct (it is taken from a book I am reading) > > Python lists are mutable sequences. They are very similar to tuples, but they > don't have the restrictions due to immutability. > > It says lists are mutable and then says they are immutable??? > ? You have come across a pet-peeve of mine.? The current crop of technical books are categorically inferior to those published in the past.?? There seems to be little to no proofreading involved before publication, and the authors' grammar is no better than what we see in casual, off-the-cuff email.? You have shown us a prime example of email-speak being published as a finished work.? The author states (if one assumes that his grammar is correct) that immutability is what gives lists an advantage over tuples.? This is simply wrong due to poor grammar. ? What the author *intended* to say is that lists don't suffer from the restrictions placed on tuples - i.e. immutability.? In other words, lists are mutable, tuples are immutable.? Try to find a better book - which is difficult to do these days. -Jim From rosuav at gmail.com Thu Jun 14 00:04:08 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jun 2018 14:04:08 +1000 Subject: mutable sequences In-Reply-To: References: Message-ID: On Thu, Jun 14, 2018 at 12:56 PM, Sharan Basappa wrote: > The term mutable appears quite often in Python. > Can anyone explain what is meant by mutable and immutable sequences. > > For example, Python lists are mutable. > > BTW, is the below explanation correct (it is taken from a book I am reading) > > Python lists are mutable sequences. They are very similar to tuples, but they > don't have the restrictions due to immutability. > > It says lists are mutable and then says they are immutable??? Lists are indeed mutable. Since they are mutable, they do not have the restrictions of immutability, which is the state of NOT being mutable. So what does "mutable" mean? It means the thing can be changed, while still being itself. It has an identity, and a value, and you can change the value. If you have a shopping list, it has certain items on it - you need eggs, milk, bacon, and broccoli - and if you remove broccoli from the list (seriously, you don't need it), the list is still that same list. In contrast, the number 5 is immutable. It is the number 5. It cannot be any other number and still somehow be "itself". If you add 1 to it, you now have a different number - you have 6 instead. Numbers are immutable. A tuple is like a group of values. For instance, the location (3,4) can be represented as a tuple. It's immutable in the same way that numbers are; the position (3,4) is different from the position (6,8) and it's a completely different "thing". I'm massively simplifying, but that should give you some idea of what (im)mutability is. ChrisA From ben+python at benfinney.id.au Thu Jun 14 00:24:46 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 14 Jun 2018 14:24:46 +1000 Subject: mutable sequences References: Message-ID: <858t7igfld.fsf@benfinney.id.au> Sharan Basappa writes: > For example, Python lists are mutable. Yes, that's correct. > BTW, is the below explanation correct (it is taken from a book I am > reading) > > Python lists are mutable sequences. They are very similar to tuples, > but they don't have the restrictions due to immutability. > > It says lists are mutable and then says they are immutable??? The passage is correct, but is ambiguously phrased. You appear to be parsing it as: Python lists are mutable sequences. They are very similar to tuples, but {{they don't have the restrictions} due to immutability}. which would imply that Python lists are both mutable and are immutable. Instead, I think the intended parsing is: Python lists are mutable sequences. They are very similar to tuples, but {they don't have {the restrictions due to immutability}}. implying that Python lists are mutable; and then contrasting lists against Python tuples which have ?the restrictions due to immutability?. Does that help? You might send the publisher a request to clarify the text in a future edition. -- \ ?To have the choice between proprietary software packages, is | `\ being able to choose your master. Freedom means not having a | _o__) master.? ?Richard M. Stallman, 2007-05-16 | Ben Finney From dieter at handshake.de Thu Jun 14 00:39:15 2018 From: dieter at handshake.de (dieter) Date: Thu, 14 Jun 2018 06:39:15 +0200 Subject: python lmfit.minimizer not working References: Message-ID: <87muvy7zik.fsf@handshake.de> Priya Singh writes: > Dear All, > > I am trying to fit a spectrum using a power law model. I am using lmfit.minimizer. You are asking a question about a specific module ("lmfit") not part of the Python standard library. You might get better help from a different audience (one closer to "lmfit", maybe its authors). I, for example, do not know "lmfit" at all. From dieter at handshake.de Thu Jun 14 00:48:46 2018 From: dieter at handshake.de (dieter) Date: Thu, 14 Jun 2018 06:48:46 +0200 Subject: How to find an object existing? References: Message-ID: <87in6m7z2p.fsf@handshake.de> huey.y.jiang at gmail.com writes: > root = Tkinter.Tk() > button = Tkinter.Button(root, text="Find me") > button.pack() > > I created a button, Python object. I recall I can check this object existing by using winfo, such as winfo.exists(button). However, I forgot which super class contains this winfo method. I printed out dir(os), dir(sys), dir(Tkinter), but did not find this winfo method. I wonder who will be kindly drop down a few lines? Thanks a lot! Python is suggesting some naming conventions. Those state, that classes are using camel-case names. If they are applied, "winfo" is not a class - but instead either an object (= class/type instance) or a module. "winfo" is obviously related to graphical objects (windows, in particular). This means, you wont find it in "pure" Python. If it exists, it belongs to "Tkinter". I would look for "winfo" (or "WInfo" (potentially slightly differently camel-cased)) in the "Tk[inter]" documentation. Note, that "Tkinter" is a Python binding for the "tk" library. If you find something in the "tk" documentation, it is likely "translated" in a uniform way (to other "tk" objects) for "Tkinter". From brgrt2 at gmail.com Thu Jun 14 01:16:20 2018 From: brgrt2 at gmail.com (T Berger) Date: Wed, 13 Jun 2018 22:16:20 -0700 (PDT) Subject: PEP8 compliance In-Reply-To: References: <04df185b-04b6-47c7-8fd7-dfca48c8d947@googlegroups.com> <3308dc46-d0d2-494f-a724-c84732f57ec0@googlegroups.com> Message-ID: <7f48c6ef-b9a1-4628-a5ce-617eb3e7c52f@googlegroups.com> On Wednesday, June 13, 2018 at 1:44:49 PM UTC-4, Paul Moore wrote: > On 13 June 2018 at 17:35, T Berger wrote: > > > I did make the changes in IDLE, but I thought I must be in the wrong place. The line of code I got in terminal was: > > /Users/TamaraB/Desktop/mymodules/vsearch.py:1:25: E231 missing whitespace after ':' > > def search4vowels(phrase:str)->set: > > > > I thought the 1:25: E231 couldn't be referring to anything in my text editor. But now I see that 1:25 refers to the first line, 25th spot (I suppose the 25 refers to the spot BEFORE which I'm supposed to add white space. I don't know what the E231 refers to, but it doesn't seem helpful. > > That's the correct interpretation of that message. Well done (and I > don't mean that patronisingly) - messages from tools like whatever it > was that reported these errors to you are often rooted in assumptions > which are *far* from obvious to someone new to programming. > > To expand a little: > > The 1 is as you say the line on which the tool spotted the problem. > Program text is viewed (by tools just as by people) as a block of > lines of text, numbered starting from line 1. Tools will number blank > lines (lines with nothing on them) equally with lines with text on > them - sometimes people number only the non-blank lines, but > programming tools don't typically do that. > > The 25 does refer to the position on the line that the tool is > referring to. Position is measured in characters. You say "spot", and > that's as good a term as any. Characters as counted by a computer > include letters, numbers, punctuation, and even spaces. You can think > of it as "column on the screen" in this case and not be far wrong. > > The E231 is a code for the specific error that the tool found - so it > means "missing whitespace". The text of the message is all you need to > deal with, but having a unique, concise code can help, for example > when looking up information in the documentation or the source code of > the tool. It's very helpful to quote error numbers like this when > reporting problems or asking for help, as they are more precise (to > people who know how to interpret them) than the textual message. But > reporting the text as well is crucial, as it saves people having to > look up the code to know what you're talking about! > > > And, no, I'm not going to make these picayune changes that actually make the code harder to read. Adding a white space between "phrase:" and "str" just splits apart a conceptual unit in a complicated line of code. I was just doing this exercise in my workbook. > > That's a very good attitude. There *are* good reasons for many of the > style recommendations, and as you learn more you may be persuaded to > change your view, but style guides are all ultimately about making > your code "readable", and it sounds like you are already developing a > good sense of how you want to group and present your code. That's > something many programmers can take a long time (years, in some cases) > to develop, and a good sense of style is often (IMO) what separates > good programmers from mediocre/bad ones. Reading other people's code > is often a very good way to develop a sense of style, if you get the > chance to do so. > > Paul Thanks, Paul, for your encouraging, informative reply Tamara From auriocus at gmx.de Thu Jun 14 01:20:22 2018 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 14 Jun 2018 07:20:22 +0200 Subject: How to find an object existing? In-Reply-To: References: Message-ID: Am 14.06.18 um 05:14 schrieb huey.y.jiang at gmail.com: > root = Tkinter.Tk() > button = Tkinter.Button(root, text="Find me") > button.pack() > > I created a button, Python object. I recall I can check this object existing by using winfo, such as winfo.exists(button). However, I forgot which super class contains this winfo method. I printed out dir(os), dir(sys), dir(Tkinter), but did not find this winfo method. I wonder who will be kindly drop down a few lines? This is due to a bad wrapping of the original Tcl interface of Tk. In the original Tcl, "winfo" is not a method of anything, it is a free function. In TkInter, all free functions that accept a widget as the first parameter were made methods of that widget. Therefore, "winfo_exists" is a method of "button", which is logically contorted: you are asking an object "do you exist?". However, since it can be explicitly destroyed, this can still be useful: >>> import Tkinter >>> root = Tkinter.Tk() >>> button = Tkinter.Button(root, text="Find me") >>> button.pack() >>> button.winfo_exists() 1 >>> button.destroy() >>> button.winfo_exists() 0 I am not sure that this is very helpful, though. Usually you don't destroy a button yourself, it is done by the destructor when the button is deleted, and therefore, winfo_exists() under normal circumstances returns true. What are you really trying to achieve? Christian From brgrt2 at gmail.com Thu Jun 14 01:34:09 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Thu, 14 Jun 2018 01:34:09 -0400 Subject: pep8 Re: Posting warning message In-Reply-To: <20180613043023.GA75144@cskk.homeip.net> References: <20180613043023.GA75144@cskk.homeip.net> Message-ID: Is it possible to do the "linting" after you've written your code but before you install it for the first time? Tamara On Wed, Jun 13, 2018 at 12:30 AM Cameron Simpson wrote: > > On 13Jun2018 00:05, Tamara Berger wrote: > >Thanks for the in-depth answer. I'm going to have to read it > >carefully, with the help of a Python glossary. Some of the terms you > >use are new to me. > > No worries. Just ask if you don't find definitions. > > BTW, a "lint" program, or "linter" is a program for reporting on style trivia, > trivial logic errors like variable used before defined (or never defined, which > is often a typing error misspelling a variable or function name), and things > that look like they might be bugs (a common mistake of mine is constructing > exceptions like logging calls, and one of my linters has found dozens of these > for me.) > > >>or am I supposed to root around for my module and make the edits one by one? > > > >I was trying to be amusing and didn't get my point across. > > Ah, ok then. Easy for stuff like that to fall flat in email. > > >>Finally, no you don't normally root around and change an installed module. > >>Instead, modify your original copy and reinstall the newer version! > > > >What I meant was, do I have to open the file, search for, e.g., colons > >and insert space after them? These were the sorts of picayune errors > >picked up by PEP8 on my program. I deliberately omit such spaces when > >I code because I like to do as little unnecessary work as possible. > >There is enough repetitive coding as it is. I know some IDEs have word > >completion suggestion for variables, etc, that the user creates. But > >I'm practicing in barebones IDLE and that means a lot of extra work. > > Regrettably, yes, unless you're using an editor that has autoformatting > support. Learn typing habits which minimise stuff like that, it saves going > back later. > > I don't use IDEs on the whole, and I don't use an autoformatter for Python. My > environment tends to be an editor window and a shell to run things from (thus: > 2 terminals, one running vim and one running a shell). > > Training your fingers to do the trivia reflexively helps. And leaving the > linting until _after_ you've got your code working correctly helps, because you > aren't changing tasks midstream and you are linting code you've deleted or > changed :-) > > An editor with syntax support can help. I use vi or vim, and its syntax support > is fairly crude. Two things its does have which I use a lot is autoindent (as > simple as starting the next line at the same indent as the one I just > completed) and syntax highlighting, which colours keywords and identifiers and > strings differently. When you make trivial mistakes like not closing a quote or > misspelling a keyword or leaving off a colon there is often a visual cue. > > Cheers, > Cameron Simpson From brgrt2 at gmail.com Thu Jun 14 01:47:36 2018 From: brgrt2 at gmail.com (T Berger) Date: Wed, 13 Jun 2018 22:47:36 -0700 (PDT) Subject: How to apply filters to posts In-Reply-To: References: Message-ID: <9972560b-6af0-45ca-8a75-5d1ca5f4715f@googlegroups.com> On Tuesday, April 10, 2018 at 1:21:53 AM UTC-4, Chris Angelico wrote: > I recommend, instead, joining the mailing list: > > https://mail.python.org/mailman/listinfo/python-list There seem to be two options on the Python-list Information Page. * Subscribe to the list (see sections below) * Send email to python-list at python.org Which are you recommending? Tamara > > ChrisA From cs at cskk.id.au Thu Jun 14 01:49:33 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 14 Jun 2018 15:49:33 +1000 Subject: pep8 Re: Posting warning message In-Reply-To: References: Message-ID: <20180614054933.GA98425@cskk.homeip.net> On 14Jun2018 01:34, Tamara Berger wrote: >Is it possible to do the "linting" after you've written your code but >before you install it for the first time? Sure. I always do it that way. Just as you can run your code before you install it, you can lint your code beforehand also. In fact, you should be doing both: run and test the code _before_ installing it, and also lint it (when you care) and test again (because if you made lint changes you want to check they haven't done something unwanted). Cheers, Cameron Simpson From tjreedy at udel.edu Thu Jun 14 01:57:11 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Jun 2018 01:57:11 -0400 Subject: How to make a button flashing? In-Reply-To: References: <8bacbe4a-ceb6-439c-b845-f2ba51d64f35@googlegroups.com> Message-ID: On 6/13/2018 8:57 PM, huey.y.jiang at gmail.com wrote: > On Wednesday, June 13, 2018 at 5:23:17 PM UTC+8, huey.y... at gmail.com wrote: >> Hi All, >> >> I forgot the syntax of making a button flash, and failed to find an example in the web. I use Tkinter, to create a button. Then made it packed, and showed up. Now I am trying to make button b flashing, to make it get better noticed. I checked the docs, and found a method flash() is available, then I tried: >> >> b.flash() >> >> there was no error message popped out, but there was nothing happened also. I wonder who can give me this help? Thanks! >> >> Huey > > Thanks, Terry, it works! I try to always test code before posting ;-). With different code, you could switch state every 1/2 second or so, like a flashing red traffic light. You might try to do that. -- Terry Jan Reedy From rosuav at gmail.com Thu Jun 14 02:34:26 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jun 2018 16:34:26 +1000 Subject: How to apply filters to posts In-Reply-To: <9972560b-6af0-45ca-8a75-5d1ca5f4715f@googlegroups.com> References: <9972560b-6af0-45ca-8a75-5d1ca5f4715f@googlegroups.com> Message-ID: On Thu, Jun 14, 2018 at 3:47 PM, T Berger wrote: > On Tuesday, April 10, 2018 at 1:21:53 AM UTC-4, Chris Angelico wrote: > >> I recommend, instead, joining the mailing list: >> >> https://mail.python.org/mailman/listinfo/python-list > > There seem to be two options on the Python-list Information Page. > > * Subscribe to the list (see sections below) > * Send email to python-list at python.org > > Which are you recommending? > They're connected. "Subscribe to the list" makes you a member of the mailing list (and thus you will start receiving posts), which also entitles you to send to the list. Sending email to that address will send it to the list. So what you're seeing is not options, but steps - first you subscribe, then you send email. ChrisA From brgrt2 at gmail.com Thu Jun 14 02:35:43 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Thu, 14 Jun 2018 02:35:43 -0400 Subject: pep8 Re: Posting warning message In-Reply-To: <20180614054933.GA98425@cskk.homeip.net> References: <20180614054933.GA98425@cskk.homeip.net> Message-ID: On Thu, Jun 14, 2018 at 1:49 AM Cameron Simpson wrote: > Just as you can run your code before you install it, you can lint your code > beforehand also. In fact, you should be doing both: run and test the code > _before_ installing it, and also lint it (when you care) and test again > (because if you made lint changes you want to check they haven't done something > unwanted). Great. So I'm using three interfaces: in my case, the text editor, the Python shell, and the UNIX terminal. Is that right? Tamara From rosuav at gmail.com Thu Jun 14 02:38:46 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jun 2018 16:38:46 +1000 Subject: Django-hotsauce 1.0 LTS (Commercial Edition) now available for preorder!! In-Reply-To: <6192e413-4d4f-6fee-c6a5-76f063485abe@gmail.com> References: <6192e413-4d4f-6fee-c6a5-76f063485abe@gmail.com> Message-ID: On Thu, Jun 14, 2018 at 11:07 AM, Jim Lee wrote: > I haven't purchased commercial software in decades, so I'm not up on the > prevailing business model, but I have to ask: > > Why would anyone purchase software and then agree to wait 14 weeks for it to > be delivered? I can see that model for hardware, where material resources > are limited and a finite number of product is produced, but software? > What's the point? > For the 50% discount, I presume. If you wait 14 weeks, then buy, then own, you pay full price. >From the company's point of view: if the release date is in the future and ALL the revenue is also in the future, cash flow becomes tricky. By getting at least _some_ money in advance, they give themselves a way to pay the bills. ChrisA From tjreedy at udel.edu Thu Jun 14 02:42:28 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Jun 2018 02:42:28 -0400 Subject: How to find an object existing? In-Reply-To: References: Message-ID: On 6/14/2018 1:20 AM, Christian Gollwitzer wrote: > Am 14.06.18 um 05:14 schrieb huey.y.jiang at gmail.com: >> root = Tkinter.Tk() >> button = Tkinter.Button(root, text="Find me") >> button.pack() >> >> I created a button, Python object. I recall I can check this object >> existing by using?? winfo, such as? winfo.exists(button). However, I >> forgot which super class contains this?? winfo?? method.? I printed >> out dir(os), dir(sys), dir(Tkinter), but did not find this winfo >> method. I wonder who will be kindly drop down a few lines? > This is due to a bad wrapping of the original Tcl interface of Tk. In > the original Tcl, "winfo" is not a method of anything, it is a free > function. In TkInter, all free functions that accept a widget as the > first parameter were made methods of that widget. They were made methods of all widgets. Thanks for pointing this out, as it same some anomalies more understandable. Someone was overcome with Java-esque OO-itis, the notion that all function have to be methods. http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/universal.html calls them universal methods. The result is that help(Text), for instance, returns over 1000 lines because it includes all the universal methods in addition to the real Text methods. dir(Text(root)) is also overburdened with non-Text information. > Therefore, > "winfo_exists" is a method of "button", which is logically contorted: > you are asking an object "do you exist?". You are actually asking the python instance whether the tk window it initially represented still exists. In tk, the argument is a window name that represents a window structure. Does the structure initially represented by a name still exist? This is similar to a python file instance myfile existing after the corresponding OS file has been closed (destroyed) with myfile.close. This sets the attribute myfile.closed to True. Calling other file methods fails because there is no OS structure to relay it to. > However, since it can be explicitly destroyed, this can still be useful: > > >>> import Tkinter > >>> root = Tkinter.Tk() > >>> button = Tkinter.Button(root, text="Find me") > >>> button.pack() > >>> button.winfo_exists() > 1 > >>> button.destroy() > >>> button.winfo_exists() > 0 > > I am not sure that this is very helpful, though. Usually you don't > destroy a button yourself, it is done by the destructor when the button > is deleted, and therefore, winfo_exists() under normal circumstances > returns true. The reference above omits winfo-exists, perhaps because it is so useless. -- Terry Jan Reedy From tkadm30 at yandex.com Thu Jun 14 02:50:37 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Thu, 14 Jun 2018 02:50:37 -0400 Subject: Django-hotsauce 1.0 LTS (Commercial Edition) now available for preorder!! In-Reply-To: References: <6192e413-4d4f-6fee-c6a5-76f063485abe@gmail.com> Message-ID: <805374c8-e587-9bd4-0d0f-79b8b22ff6c3@yandex.com> Le 2018-06-14 ? 02:38, Chris Angelico a ?crit?: > On Thu, Jun 14, 2018 at 11:07 AM, Jim Lee wrote: >> I haven't purchased commercial software in decades, so I'm not up on the >> prevailing business model, but I have to ask: >> >> Why would anyone purchase software and then agree to wait 14 weeks for it to >> be delivered? I can see that model for hardware, where material resources >> are limited and a finite number of product is produced, but software? >> What's the point? >> > For the 50% discount, I presume. If you wait 14 weeks, then buy, then > own, you pay full price. > > >From the company's point of view: if the release date is in the future > and ALL the revenue is also in the future, cash flow becomes tricky. > By getting at least _some_ money in advance, they give themselves a > way to pay the bills. Chris got it right I think! :) Thank you, Etienne -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From greg.ewing at canterbury.ac.nz Thu Jun 14 03:30:34 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 14 Jun 2018 19:30:34 +1200 Subject: PEP8 compliance In-Reply-To: References: <04df185b-04b6-47c7-8fd7-dfca48c8d947@googlegroups.com> Message-ID: Chris Angelico wrote: > ... and THIS RIGHT HERE is why the tool should not be called "pep8". > Didn't this exact discussion come up and the tool got renamed? Seems it's been renamed to pycodestyle, but there's still an old project called pep8 on pypi.org. I guess there's always going to be some confusion as long as it's there to be found. -- Greg From cs at cskk.id.au Thu Jun 14 04:36:31 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 14 Jun 2018 18:36:31 +1000 Subject: pep8 Re: Posting warning message In-Reply-To: References: Message-ID: <20180614083631.GA20884@cskk.homeip.net> On 14Jun2018 02:35, Tamara Berger wrote: >On Thu, Jun 14, 2018 at 1:49 AM Cameron Simpson wrote: >> Just as you can run your code before you install it, you can lint your code >> beforehand also. In fact, you should be doing both: run and test the code >> _before_ installing it, and also lint it (when you care) and test again >> (because if you made lint changes you want to check they haven't done something >> unwanted). > >Great. So I'm using three interfaces: in my case, the text editor, the >Python shell, and the UNIX terminal. Is that right? Possibly; I thought you were using IDLE, which is a GUI with a simple editor and a Python interpreter built in? My setup tends to be a terminal with an editor in it, and another terminal with a UNIX shell in it. And sometimes the Python shell in the UNIX shell in the terminal when I'm testing something simple. For example: [~/hg/css(hg:default)]fleet*> python3 + exec /Users/cameron/var/venv/3/bin/python3 Python 3.6.5 (default, Mar 29 2018, 15:38:28) [GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> That's a python 3 shell run from the UNIX shell in a terminal. The "[~/hg/css(hg:default)]fleet*>" is my UNIX shell prompt, with my working directory, VCS branch and hostname. So "~/hg/css" is where I'm working, separate from where the code gets installed. For testing I run the local code, which might be arbitrarily bad. I don't do the "install" step until it seems fairly good. Of course, the UNIX shell is there to run whatever I like. So to lint one of my Python files I might do this: [~/hg/css(hg:default)]fleet*> lint cs/sh.py + exec lint cs/sh.py + exec python3 -m py_compile cs/sh.py + exec /Users/cameron/var/venv/3/bin/python3 -m py_compile cs/sh.py + exec pyflakes cs/sh.py + exec pep8 --ignore=E111,E114,E124,E126,E201,E202,E221,E226,E227,E265,E266,E301,E302,E501,E731,W503 cs/sh.py + exec pylint --rcfile=/Users/cameron/.pylintrc --disable=bad-whitespace,invalid-name cs/sh.py Using config file /Users/cameron/.pylintrc ************* Module python.cs.sh W:105, 2: Using possibly undefined loop variable 'offset' (undefined-loop-variable) ------------------------------------------------------------------ Your code has been rated at 9.85/10 (previous run: 9.85/10, +0.00) You can see my lint script doing: - test compile the script (no need to bother with the rest if that fails) - run pyflakes on it - run pep8 on it - run pylint on it Cheers, Cameron Simpson From ftg at lutix.org Thu Jun 14 05:27:44 2018 From: ftg at lutix.org (ftg at lutix.org) Date: Thu, 14 Jun 2018 09:27:44 +0000 Subject: Design of my program In-Reply-To: References: Message-ID: <0a9a122447cad837eee543979c985f4b@webmail.lutix.org> Thanks for your answer. The term "picture" was more a metaphor ;) I am not sure I want to dive into ORM, since I am newbie, maybe I want to code something more from scratch to understand well program designing. What would be the best way: - create 2 classes, one that deals with web scraping, the other one with database, and then create child from those 2 parents? - create one unique class dealing with all those things - create one first class that deals with DB things and then a child class that deals additionnaly with web scraping. What would be the ideal way? Thanks June 13 2018 6:50 PM, "Dennis Lee Bieber" wrote: > On Wed, 13 Jun 2018 13:09:10 +0000, ftg at lutix.org declaimed the following: > >> Hello everyone, >> >> Here is a small picture of my project. > > This is a text-only group. Any binary attachments are removed before > messages propagate. > > As for the rest of your post... Possibly look at SQLAlchemy > https://www.sqlalchemy.org or (if it is still in development -- doesn't > seem to have moved since 2013) DABO https://dabodev.com ( > https://github.com/dabodev/dabo shows some action two years ago) > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list From cs at cskk.id.au Thu Jun 14 05:34:52 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 14 Jun 2018 19:34:52 +1000 Subject: pattern In-Reply-To: <63fd3a0e-bc40-4b68-b598-b0a2183900cc@googlegroups.com> References: <63fd3a0e-bc40-4b68-b598-b0a2183900cc@googlegroups.com> Message-ID: <20180614093452.GA96620@cskk.homeip.net> On 13Jun2018 19:51, Sharan Basappa wrote: >Can anyone explain to me the purpose of "pattern" in the line below: > >documents.append((w, pattern['class'])) > >documents is declared as a list as follows: >documents.append((w, pattern['class'])) Not without a lot more context. Where did you find this code? Cheers, Cameron Simpson From ftg at lutix.org Thu Jun 14 05:37:53 2018 From: ftg at lutix.org (ftg at lutix.org) Date: Thu, 14 Jun 2018 09:37:53 +0000 Subject: Design of my project In-Reply-To: <20180613223513.GA48778@cskk.homeip.net> References: <20180613223513.GA48778@cskk.homeip.net> Message-ID: <977d80b6b9a8dc85154a29d823e01a01@webmail.lutix.org> Hello, thanks for this nice answer I didn't see at first (I have parallely asked again in the list, sorry about the inconvenience). I will read deeply your proposal I will come bakc with my quesitons if any ;) Thanks! June 14 2018 12:37 AM, "Cameron Simpson" wrote: > On 13Jun2018 15:23, Fabien LUCE wrote: > >> Here is a small picture of my project. >> I'd like to fetch several datas from a website representing races results. >> Each line of the result contains rank, runner's name and other attributes >> of the runner (like club etc...). >> For now I have created 2 classes (Race and Runner). >> Methods of Race allow me to fetch datas on the www thanks to beautifulsoup >> module.I instanciate a race at the beginning of the scan and for each line >> I instanciate a Runner. >> I want to store all those information in a database (for both Race and >> Runner), but here is the point, I have the feeling, on a programming >> elegance point of view, that I have to separate methods that fetch from >> method that store and also have a kind of superior object that controls >> those 2 features. >> Moreover fetching will interact with storage: if race is already in >> database, no need to fetch again. >> How should I "design" this? Should I have only (despite my first >> impression) one class and all the methods in it? Should I create a parent >> class along with 2 childrens that manage the two kind of methods? >> Is there a design pattern for this? > > My inclination would be to start by providing a class which "wraps" your Race database table, and > presents it as a mapping. > > Something along the lines of: > > class RaceTable: > def __init__(self, database_connection, table_name): > self.conn = database_connection > self.table_name = table_name > def __contains__(self, race_id): > ... do SQL to see if the race_id is already present, return True or False > def __getitem__(self, race_id): > ... do SQL to fetch a Race row from the table and return it ... > def __setitem__(self, race_id, race_info): > ... do SQL to store race_info in the table ... > > The special __foo__ methods (called "dunder" methods in the Puython world because of the "double > underscore") are what make the class look like a Python "dict" from outside: when you perform a > mapping method like "value in x" or "x[key] = value", Python calls x.__contains__ or x.__setitem__ > for you. > > Look up "Emulating Container Types" here: > > https://docs.python.org/3/reference/datamodel.html#emulating-container-types > > That will show you how to write a class like the above example to implement a "maping" interface. > You don't need to implement everything, just what you need. The example above only implements 3 > methods. > > Then your outer code can look a bit like: > > race_store = RaceTable(database_connection, 'race_table_name_here') > ... > if race_id in race_store: > ... mention that this race_id is already stored ... > else: > race_store[race_id] = race_info > > So the objective here is a simple class that makes it easy to talk about where your information is > stored in nice Pythonic terms, and which hides the details of database access - that lets you talk > about the data in a sensbile and clear way outside the storage class, and also leaves scrope for > changing the storage mechanism later without changing the main code (eg from a conventional SQL > database to some other service). > > Cheers, > Cameron Simpson > -- https://mail.python.org/mailman/listinfo/python-list From tkadm30 at yandex.com Thu Jun 14 08:55:40 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Thu, 14 Jun 2018 08:55:40 -0400 Subject: How to delete a branch permanently in mercurial/bitbucket? Message-ID: <21433628-280e-c862-505b-b4481b409e58@yandex.com> Hi, I need to delete a branch in mercurial in order to move it into a private repository. I have heard of the "hg strip" method but Bitbucket is warning me that this operation will affect branches I would prefer keeping... So I just have no idea right now how to prune this specific branch out of my public repo! :( Any suggestions for doing this would be much appreciated! Kind regards, Etienne -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From breamoreboy at gmail.com Thu Jun 14 09:10:49 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Thu, 14 Jun 2018 14:10:49 +0100 Subject: Stefan's headers [was:Names and identifiers] In-Reply-To: <87sh5x2nd7.fsf@elektro.pacujo.net> References: <201806081042.39619.gheskett@shentel.net> <87sh5x2nd7.fsf@elektro.pacujo.net> Message-ID: On 08/06/18 18:34, Marko Rauhamaa wrote: > > PS IMO copyright laws should be abolished altogether. At the very least > one should pay for copyright protection. One ?1 for the first year, ?2 > for the second, ?4 for the third and so on exponentially. > Thoughts on the proposed new EU copyright laws are welcome. Here's the first link https://juliareda.eu/eu-copyright-reform/ of the hits from the results of a google search for "eu new copyright proposal". I'll leave you all to read the remaining 26,199,999 hits at your leisure. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From Joseph.Schachner at Teledyne.com Thu Jun 14 09:52:15 2018 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Thu, 14 Jun 2018 13:52:15 +0000 Subject: mutable sequences In-Reply-To: References: Message-ID: <7a706507aea64c8793f2629f84ea1f00@Teledyne.com> No, it says lists are mutable and tuples are immutable. Mutable has the same root as "mutation". Mutable means "can be changed in place". Immutable means "cannot be changed in place". Examples: 1) pass your list to a function, the function modifies the list. When the function returns your script gets control back. Your list is modified. 2) pass a tuple to a function. The function wants to modify the tuple. It can't Append( ) to it, if it tries Python will throw an exception because tuples don't have an append method. It can't assign a new value to an element of the tuple. But it can assign different content to the tuple entirely. When the function returns your script gets control back. YOUR tuple is NOT modified. When the function assigned to it, a new tuple with a different ID was created. Basically, from that point on, the function had its own tuple. The original was not modified because it can't be modified. It's immutable. 3) You use a list constructor, i.e., function( list(mylist) ). That passes a copy of your list, which has a different ID, to the function. The function can append to it, or otherwise modify it. When the function returns, YOUR list is not modified because you didn't pass your list to the function; you passed a newly constructed copy of your list to the function. (Advanced comment: If a tuple has an element which is a list, that list is mutable. Thinking about whether the list inside the tuple should be modifiable gives me a headache. Try it and see what happens.) If you don't like the terms mutable and immutable, think of them as related to "pass by reference" and "pass by value" in some other languages. If you pass by reference, you give the function a reference to your object; it modifies your object. If you pass by value, you load a copy of your object probably onto the stack, to pass to the function; the function can modify the copy but your object is not modified (this seems most similar to example 3 above). To avoid having to copy huge things onto the stack, C++ grew a const keyword so that you can pass a const reference to a function, which means the function won't be allowed to modify it. I think this is very much like immutable. I think it's fair to say Python always passes by reference. Immutable types allow Python to have behavior that acts sort of like pass by value, or very much like passing a const reference in C++. (One difference is Python allows a line that looks like it's assigning to the tuple, but really it makes a new tuple.) In example 3 above Python didn't actually pass a copy of your list (which could be huge), it passed a reference to a copy of your list. --- Joseph Schachner -----Original Message----- From: Sharan Basappa Sent: Wednesday, June 13, 2018 10:57 PM To: python-list at python.org Subject: mutable sequences The term mutable appears quite often in Python. Can anyone explain what is meant by mutable and immutable sequences. For example, Python lists are mutable. BTW, is the below explanation correct (it is taken from a book I am reading) Python lists are mutable sequences. They are very similar to tuples, but they don't have the restrictions due to immutability. It says lists are mutable and then says they are immutable??? From larry.martell at gmail.com Thu Jun 14 09:59:26 2018 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 14 Jun 2018 09:59:26 -0400 Subject: mutable sequences In-Reply-To: References: Message-ID: On Wed, Jun 13, 2018 at 10:56 PM, Sharan Basappa wrote: > The term mutable appears quite often in Python. > Can anyone explain what is meant by mutable and immutable sequences. A string and a list go into a bar. The string asks for a cup of coffee. The bartender says "We don't have coffee." The string asks for a cup of coffee. The bartender says "I told you we don't have coffee." The string asks for a cup of coffee. The bartender says to the list "What is wrong with him? Is he deaf?" The list replies, "No, he's immutable." From brgrt2 at gmail.com Thu Jun 14 11:00:01 2018 From: brgrt2 at gmail.com (T Berger) Date: Thu, 14 Jun 2018 08:00:01 -0700 (PDT) Subject: How to apply filters to posts In-Reply-To: References: <9972560b-6af0-45ca-8a75-5d1ca5f4715f@googlegroups.com> Message-ID: <6ab67980-7668-40c2-ab8f-d2e8792d5022@googlegroups.com> On Thursday, June 14, 2018 at 8:02:44 AM UTC-4, Chris Angelico wrote: > They're connected. "Subscribe to the list" makes you a member of the > mailing list (and thus you will start receiving posts), which also > entitles you to send to the list. Sending email to that address will > send it to the list. So what you're seeing is not options, but steps - > first you subscribe, then you send email. OK. And can you tell me how to apply filters so that only replies to my emails are included. I subscribed to the list a couple of weeks ago and then had to unsubscribe because I was getting emails on every posted topic. Thanks, Tamara From rhodri at kynesim.co.uk Thu Jun 14 11:25:26 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 14 Jun 2018 16:25:26 +0100 Subject: How to apply filters to posts In-Reply-To: <6ab67980-7668-40c2-ab8f-d2e8792d5022@googlegroups.com> References: <9972560b-6af0-45ca-8a75-5d1ca5f4715f@googlegroups.com> <6ab67980-7668-40c2-ab8f-d2e8792d5022@googlegroups.com> Message-ID: On 14/06/18 16:00, T Berger wrote: > On Thursday, June 14, 2018 at 8:02:44 AM UTC-4, Chris Angelico wrote: > >> They're connected. "Subscribe to the list" makes you a member of the >> mailing list (and thus you will start receiving posts), which also >> entitles you to send to the list. Sending email to that address will >> send it to the list. So what you're seeing is not options, but steps - >> first you subscribe, then you send email. > > OK. And can you tell me how to apply filters so that only replies to my emails are included. I subscribed to the list a couple of weeks ago and then had to unsubscribe because I was getting emails on every posted topic. That's exactly how mailing lists work: you get everything. Any filtering has to be done at your end in your mail program. Personally I use Thunderbird, get it to sort messages into threads (sequences of conversation, in effect) and only read the threads that seem interesting. -- Rhodri James *-* Kynesim Ltd From brgrt2 at gmail.com Thu Jun 14 12:23:13 2018 From: brgrt2 at gmail.com (T Berger) Date: Thu, 14 Jun 2018 09:23:13 -0700 (PDT) Subject: How to apply filters to posts In-Reply-To: References: <9972560b-6af0-45ca-8a75-5d1ca5f4715f@googlegroups.com> <6ab67980-7668-40c2-ab8f-d2e8792d5022@googlegroups.com> Message-ID: <37eccdff-e7cf-44ed-b1f6-0034dd73b653@googlegroups.com> On Thursday, June 14, 2018 at 11:26:00 AM UTC-4, Rhodri James wrote: > On 14/06/18 16:00, T Berger wrote: > > On Thursday, June 14, 2018 at 8:02:44 AM UTC-4, Chris Angelico wrote: > > > >> They're connected. "Subscribe to the list" makes you a member of the > >> mailing list (and thus you will start receiving posts), which also > >> entitles you to send to the list. Sending email to that address will > >> send it to the list. So what you're seeing is not options, but steps - > >> first you subscribe, then you send email. > > > > OK. And can you tell me how to apply filters so that only replies to my emails are included. I subscribed to the list a couple of weeks ago and then had to unsubscribe because I was getting emails on every posted topic. > > That's exactly how mailing lists work: you get everything. Any > filtering has to be done at your end in your mail program. Personally I > use Thunderbird, get it to sort messages into threads (sequences of > conversation, in effect) and only read the threads that seem interesting. > > -- > Rhodri James *-* Kynesim Ltd Thanks, Rhodri. One more question. What is a daily digest? I'm wondering whether to choose that option. Tamara From francois.rabanel at outscale.com Thu Jun 14 12:26:44 2018 From: francois.rabanel at outscale.com (francois.rabanel at outscale.com) Date: Thu, 14 Jun 2018 09:26:44 -0700 (PDT) Subject: How can I verify if the regex exist in a file without reading ? Message-ID: <8898e58f-228b-4b91-bc2b-1c8a40433637@googlegroups.com> Hi, Here is my script : It propose to replace some words in a file with a regular expression. It create a copy to write on it, and if there isn't an error, it delete the original by the copy with "os.rename" at the end. My problem is, if I work on a huge file, I'll try to avoid to read the file because it will be crash my computer :) and I would to verify if the regex enter by the user, exist. I don't know if it's possible, I'm looking for a solution since few hours... so sorry if the question is easy or wtf :) ------------------------------------ import re import os try: path = raw_input('Please enter the path of your file that you want to correct : \n') print("------------------------") print('Which regex ? \n') regex = raw_input('----- : ') print('By what ? \n') new_word = raw_input('----- : ') # Creating copy file filenames_regex = re.findall(r'[a-zA-Z0-9]+\.', path) filename = filenames_regex[len(filenames_regex)-1] new_filename = filename + 'copy.txt' # Replace regex by new word line by line on copy file with open(path) as rf, open(new_filename, 'w') as wf: for line in rf: wf.write(re.sub(regex, new_word, line)) except OSError: print("Permission denied") except IOError: print("This file doesn't exist") else: os.rename(new_filename, filename + 'txt') python 2.7.10 Thanks ! Best regards, Fran?ois. From steve+comp.lang.python at pearwood.info Thu Jun 14 12:54:42 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 14 Jun 2018 16:54:42 +0000 (UTC) Subject: How can I verify if the regex exist in a file without reading ? References: <8898e58f-228b-4b91-bc2b-1c8a40433637@googlegroups.com> Message-ID: On Thu, 14 Jun 2018 09:26:44 -0700, francois.rabanel wrote: > Hi, > > Here is my script : > > It propose to replace some words in a file with a regular expression. It > create a copy to write on it, and if there isn't an error, it delete the > original by the copy with "os.rename" at the end. > > My problem is, if I work on a huge file, I'll try to avoid to read the > file because it will be crash my computer :) How does reading a file crash your computer? > and I would to verify if the regex enter by the user, exist. The only way to know if a regex matches the file is to try to match the regex and see if it matches. [...] > import re > import os > > try: > > path = raw_input('Please enter the path of your file that you want to > correct : \n') > print("------------------------") > print('Which regex ? \n') > regex = raw_input('----- : ') > print('By what ? \n') > new_word = raw_input('----- : ') > Don't do this: > # Creating copy file > filenames_regex = re.findall(r'[a-zA-Z0-9]+\.', path) > filename = filenames_regex[len(filenames_regex)-1] > new_filename = filename + 'copy.txt' Do this instead: filename, extension = os.path.splitext(path) new_filename = filename + '.copy' + extension > # Replace regex by new word line by line on copy file > with open(path) as rf, open(new_filename, 'w') as wf: > for line in rf: > wf.write(re.sub(regex, new_word, line)) > > except OSError: > print("Permission denied") That's not what OSError means. OSError can mean many different things. That's why it isn't called "PermissionDeniedError". You need to look at the exception to see what caused it, not just assume it was a permissions error. > except IOError: > print("This file doesn't exist") That's not what IOError means either. That is why it isn't called FileDoesntExistError. Again, you need to look at the exception to see what the error actually is. > else: > os.rename(new_filename, filename + 'txt') os.rename(new_filename, path) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From jlee54 at gmail.com Thu Jun 14 12:58:29 2018 From: jlee54 at gmail.com (Jim Lee) Date: Thu, 14 Jun 2018 09:58:29 -0700 Subject: Django-hotsauce 1.0 LTS (Commercial Edition) now available for preorder!! In-Reply-To: References: <6192e413-4d4f-6fee-c6a5-76f063485abe@gmail.com> Message-ID: On 06/13/2018 11:38 PM, Chris Angelico wrote: > On Thu, Jun 14, 2018 at 11:07 AM, Jim Lee wrote: >> I haven't purchased commercial software in decades, so I'm not up on the >> prevailing business model, but I have to ask: >> >> Why would anyone purchase software and then agree to wait 14 weeks for it to >> be delivered? I can see that model for hardware, where material resources >> are limited and a finite number of product is produced, but software? >> What's the point? >> > For the 50% discount, I presume. If you wait 14 weeks, then buy, then > own, you pay full price. > > From the company's point of view: if the release date is in the future > and ALL the revenue is also in the future, cash flow becomes tricky. > By getting at least _some_ money in advance, they give themselves a > way to pay the bills. > > ChrisA But the "50% discount" is supposedly good up until the release date.? I could purchase the software the day before release and still enjoy the same benefit without the 14 week wait. I understand the advantages *to the company*, but to enjoy those advantages, they need to provide some kind of incentive to the buyer.? I don't see one here.? Anyway, I was just curious to see if there was any kind of thought process behind the "promotion". -Jim From brgrt2 at gmail.com Thu Jun 14 13:51:00 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Thu, 14 Jun 2018 13:51:00 -0400 Subject: Flask not responding after installation Message-ID: It seems I can?t progress a single step without encountering a wall. I?m trying to build a webapp with flask. I installed flask. I followed the workbook-provided prompts, which should have resulted in a flask confirmation. Nothing happened. Any ideas what?s gone wrong: Last login: Thu Jun 14 13:31:25 on ttys000 Tamaras-iMac:~ TamaraB$ cd Desktop/Web -bash: cd: Desktop/Web: No such file or directory Tamaras-iMac:~ TamaraB$ cd Desktop/Webapp Tamaras-iMac:Webapp TamaraB$ python3 hello_flask.py Tamaras-iMac:Webapp TamaraB$ Thanks, Tamara From breamoreboy at gmail.com Thu Jun 14 14:26:26 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Thu, 14 Jun 2018 19:26:26 +0100 Subject: How to apply filters to posts In-Reply-To: <37eccdff-e7cf-44ed-b1f6-0034dd73b653@googlegroups.com> References: <9972560b-6af0-45ca-8a75-5d1ca5f4715f@googlegroups.com> <6ab67980-7668-40c2-ab8f-d2e8792d5022@googlegroups.com> <37eccdff-e7cf-44ed-b1f6-0034dd73b653@googlegroups.com> Message-ID: On 14/06/18 17:23, T Berger wrote: > On Thursday, June 14, 2018 at 11:26:00 AM UTC-4, Rhodri James wrote: >> On 14/06/18 16:00, T Berger wrote: >>> On Thursday, June 14, 2018 at 8:02:44 AM UTC-4, Chris Angelico wrote: >>> >>>> They're connected. "Subscribe to the list" makes you a member of the >>>> mailing list (and thus you will start receiving posts), which also >>>> entitles you to send to the list. Sending email to that address will >>>> send it to the list. So what you're seeing is not options, but steps - >>>> first you subscribe, then you send email. >>> >>> OK. And can you tell me how to apply filters so that only replies to my emails are included. I subscribed to the list a couple of weeks ago and then had to unsubscribe because I was getting emails on every posted topic. >> >> That's exactly how mailing lists work: you get everything. Any >> filtering has to be done at your end in your mail program. Personally I >> use Thunderbird, get it to sort messages into threads (sequences of >> conversation, in effect) and only read the threads that seem interesting. >> >> -- >> Rhodri James *-* Kynesim Ltd > > Thanks, Rhodri. One more question. What is a daily digest? I'm wondering whether to choose that option. > > Tamara > Please no, not the misery of people replying to daily digests. As I've said previously and as reinforced by Rhodri James above, point Thunderbird or similar at news.gmane.org and read and reply to everything to your hearts content without bothering your own inbox. Simples :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ben+python at benfinney.id.au Thu Jun 14 15:39:08 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 15 Jun 2018 05:39:08 +1000 Subject: How to apply filters to posts References: <9972560b-6af0-45ca-8a75-5d1ca5f4715f@googlegroups.com> <6ab67980-7668-40c2-ab8f-d2e8792d5022@googlegroups.com> <37eccdff-e7cf-44ed-b1f6-0034dd73b653@googlegroups.com> Message-ID: <854li5gntv.fsf@benfinney.id.au> T Berger writes: > Thanks, Rhodri. One more question. What is a daily digest? I'm > wondering whether to choose that option. Don't choose the daily digest, because it makes a special ?digest? message for you each day. That message is disconnected from any other message, and so you will not be able to reply correctly to any discussion. It's not appropriate for anyone who wants to also participate in discussions. -- \ ?I have said to you to speak the truth is a painful thing. To | `\ be forced to tell lies is much worse.? ?Oscar Wilde, _De | _o__) Profundis_, 1897 | Ben Finney From ben+python at benfinney.id.au Thu Jun 14 15:42:56 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 15 Jun 2018 05:42:56 +1000 Subject: mutable sequences References: Message-ID: <85zhzxf933.fsf@benfinney.id.au> Larry Martell writes: > A string and a list go into a bar. The string asks for a cup of > coffee. The bartender says "We don't have coffee." The string asks for > a cup of coffee. The bartender says "I told you we don't have coffee." > The string asks for a cup of coffee. The bartender says to the list > "What is wrong with him? Is he deaf?" The list replies, "No, he's > immutable." There need to be more bartender scenarios in programming tutorials. -- \ ?The internet's completely over.? Anyway, all these computers | `\ and digital gadgets are no good. They just fill your head with | _o__) numbers and that can't be good for you.? ?Prince, 2010-07-05 | Ben Finney From brgrt2 at gmail.com Thu Jun 14 16:43:29 2018 From: brgrt2 at gmail.com (T Berger) Date: Thu, 14 Jun 2018 13:43:29 -0700 (PDT) Subject: How to apply filters to posts In-Reply-To: References: <9972560b-6af0-45ca-8a75-5d1ca5f4715f@googlegroups.com> <6ab67980-7668-40c2-ab8f-d2e8792d5022@googlegroups.com> <37eccdff-e7cf-44ed-b1f6-0034dd73b653@googlegroups.com> <854li5gntv.fsf@benfinney.id.au> Message-ID: On Thursday, June 14, 2018 at 3:39:44 PM UTC-4, Ben Finney wrote: > T Berger writes: > > > Thanks, Rhodri. One more question. What is a daily digest? I'm > > wondering whether to choose that option. > > Don't choose the daily digest, because it makes a special ?digest? > message for you each day. That message is disconnected from any other > message, and so you will not be able to reply correctly to any > discussion. It's not appropriate for anyone who wants to also > participate in discussions. > > -- > \ ?I have said to you to speak the truth is a painful thing. To | > `\ be forced to tell lies is much worse.? ?Oscar Wilde, _De | > _o__) Profundis_, 1897 | > Ben Finney Thanks, Ben From sivan at vitakka.co Thu Jun 14 19:51:14 2018 From: sivan at vitakka.co (Sivan Greenberg) Date: Fri, 15 Jun 2018 02:51:14 +0300 Subject: Flask not responding after installation In-Reply-To: References: Message-ID: How did you install flask? Can you paste the content of your flask app .py file? -Sivan On Fri, 15 Jun 2018 12:15 am Tamara Berger, wrote: > It seems I can?t progress a single step without encountering a wall. > I?m trying to build a webapp with flask. I installed flask. I followed > the workbook-provided prompts, which should have resulted in a flask > confirmation. Nothing happened. Any ideas what?s gone wrong: > > Last login: Thu Jun 14 13:31:25 on ttys000 > Tamaras-iMac:~ TamaraB$ cd Desktop/Web > -bash: cd: Desktop/Web: No such file or directory > Tamaras-iMac:~ TamaraB$ cd Desktop/Webapp > Tamaras-iMac:Webapp TamaraB$ python3 hello_flask.py > Tamaras-iMac:Webapp TamaraB$ > > Thanks, > > Tamara > -- > https://mail.python.org/mailman/listinfo/python-list > From cs at cskk.id.au Thu Jun 14 19:51:35 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 15 Jun 2018 09:51:35 +1000 Subject: How to apply filters to posts In-Reply-To: <37eccdff-e7cf-44ed-b1f6-0034dd73b653@googlegroups.com> References: <37eccdff-e7cf-44ed-b1f6-0034dd73b653@googlegroups.com> Message-ID: <20180614235135.GA13263@cskk.homeip.net> On 14Jun2018 09:23, Tamara Berger wrote: >Thanks, Rhodri. One more question. What is a daily digest? I'm wondering >whether to choose that option. Please don't use the digest mode. They're a terrible way to read lists, and an even worse way to participate - your replies will never be correctly associate with any particular discussion thread and unless you're paying attention, won't even have a decent subject line (which, BTW, is _not_ how discussion threads are connected together). Instead, filter the list messages to their own GMail label and skip your inbox. That way the whole list is off to the side under its own section which you can visit whenever you want to instead of cluttering your inbox. Also, the discussion threads will be nicely collected together, with the most recent at the top where they're easy to see. If the threads you're interested in have a new reply, that thread should be up near the top. Cheers, Cameron Simpson From cs at cskk.id.au Thu Jun 14 19:53:16 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 15 Jun 2018 09:53:16 +1000 Subject: How to apply filters to posts In-Reply-To: <56v5idt01jjcf7ralbb1abh2ejfeglrcva@4ax.com> References: <56v5idt01jjcf7ralbb1abh2ejfeglrcva@4ax.com> Message-ID: <20180614235316.GA24078@cskk.homeip.net> On 14Jun2018 19:42, Dennis Lee Bieber wrote: >On Fri, 15 Jun 2018 05:39:08 +1000, Ben Finney >declaimed the following: > >>Don't choose the daily digest, because it makes a special ?digest? >>message for you each day. That message is disconnected from any other >>message, and so you will not be able to reply correctly to any > > Unless one has a client that can do digest bursting -- if the digest >provides all the proper headers for each message in it, the burst messages >should link properly. > > Though I don't use Forte Agent for email, so don't have actual >experience with its bursting feature. Digests drop a lot of headers. Historically, they omit the Message-ID and In-Reply-To headers, and thus completely break threading for new replies. It is better all around to just get individual list messages and arrange to file them off into a folder distinct from your main inbox. Cheers, Cameron Simpson From ben+python at benfinney.id.au Thu Jun 14 19:59:27 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 15 Jun 2018 09:59:27 +1000 Subject: How to apply filters to posts References: <9972560b-6af0-45ca-8a75-5d1ca5f4715f@googlegroups.com> <6ab67980-7668-40c2-ab8f-d2e8792d5022@googlegroups.com> <37eccdff-e7cf-44ed-b1f6-0034dd73b653@googlegroups.com> <854li5gntv.fsf@benfinney.id.au> <56v5idt01jjcf7ralbb1abh2ejfeglrcva@4ax.com> Message-ID: <85vaakgbs0.fsf@benfinney.id.au> Dennis Lee Bieber writes: > On Fri, 15 Jun 2018 05:39:08 +1000, Ben Finney > declaimed the following: > > >Don't choose the daily digest, because it makes a special ?digest? > >message for you each day. That message is disconnected from any other > >message, and so you will not be able to reply correctly to any > > Unless one has a client that can do digest bursting -- if the digest > provides all the proper headers for each message in it, the burst messages > should link properly. At which point, there seems little point in subscribing to the digest: just get all the actual messages delivered, and use the more powerful filtering built into the mail client. -- \ ?[Entrenched media corporations will] maintain the status quo, | `\ or die trying. Either is better than actually WORKING for a | _o__) living.? ?ringsnake.livejournal.com, 2007-11-12 | Ben Finney From cs at cskk.id.au Thu Jun 14 20:00:59 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 15 Jun 2018 10:00:59 +1000 Subject: How can I verify if the regex exist in a file without reading ? In-Reply-To: References: Message-ID: <20180615000059.GA34357@cskk.homeip.net> On 14Jun2018 16:54, Steven D'Aprano wrote: >On Thu, 14 Jun 2018 09:26:44 -0700, francois.rabanel wrote: >> My problem is, if I work on a huge file, I'll try to avoid to read the >> file because it will be crash my computer :) > >How does reading a file crash your computer? Likely because he tried to read the whole file into memory and match against it. Guessing: text = open(the_filename).read() ... search the text for the regexp ... Francois, unless your regex can cross multiple lines it is better to search files like this: with open(the_filename) as f: for line in f: ... search the line for the regexp ... That way you only need to keep one line at a time in memory. >> except OSError: >> print("Permission denied") > >That's not what OSError means. OSError can mean many different things. >That's why it isn't called "PermissionDeniedError". > >You need to look at the exception to see what caused it, not just assume >it was a permissions error. > >> except IOError: >> print("This file doesn't exist") > >That's not what IOError means either. That is why it isn't called >FileDoesntExistError. Again, you need to look at the exception to see >what the error actually is. In particular, you should always _either_ inspect the exception to see what went wrong and handle it, _or_ include the exception text in your error message, for example: except IOError as e: print("IO Error on file:", e) That way an unhandled exception gets reported. >> else: >> os.rename(new_filename, filename + 'txt') > >os.rename(new_filename, path) Importantly: os.rename(path, new_filename) The old name comes first, then the new name. Also, you might want to ensure that new_filename doesn't already exist... Cheers, Cameron Simpson From steve+comp.lang.python at pearwood.info Thu Jun 14 20:24:31 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 15 Jun 2018 00:24:31 +0000 (UTC) Subject: How can I verify if the regex exist in a file without reading ? References: <20180615000059.GA34357@cskk.homeip.net> Message-ID: On Fri, 15 Jun 2018 10:00:59 +1000, Cameron Simpson wrote: > Francois, unless your regex can cross multiple lines it is better to > search files like this: > > with open(the_filename) as f: > for line in f: > ... search the line for the regexp ... > > That way you only need to keep one line at a time in memory. That's what Fran?ois is doing. > Importantly: > > os.rename(path, new_filename) > > The old name comes first, then the new name. Oops! I forgot about that. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From cs at cskk.id.au Thu Jun 14 20:41:53 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 15 Jun 2018 10:41:53 +1000 Subject: How can I verify if the regex exist in a file without reading ? In-Reply-To: References: Message-ID: <20180615004153.GA49488@cskk.homeip.net> On 15Jun2018 00:24, Steven D'Aprano wrote: >On Fri, 15 Jun 2018 10:00:59 +1000, Cameron Simpson wrote: >> Francois, unless your regex can cross multiple lines it is better to >> search files like this: >> >> with open(the_filename) as f: >> for line in f: >> ... search the line for the regexp ... >> >> That way you only need to keep one line at a time in memory. > >That's what Fran?ois is doing. Urr, so he is. Then like you, I don't know why he's concerned about running out of memory. Unless it hasn't been made clear the Python will free up unused memory on its own. Cheers, Cameron Simpson From sharan.basappa at gmail.com Thu Jun 14 22:53:58 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Thu, 14 Jun 2018 19:53:58 -0700 (PDT) Subject: mutable sequences In-Reply-To: References: <85zhzxf933.fsf@benfinney.id.au> Message-ID: <6c0662bf-c62f-4185-8388-1b9bdf8da775@googlegroups.com> Thanks, All, for the responses. From sharan.basappa at gmail.com Thu Jun 14 23:01:52 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Thu, 14 Jun 2018 20:01:52 -0700 (PDT) Subject: pattern In-Reply-To: References: <63fd3a0e-bc40-4b68-b598-b0a2183900cc@googlegroups.com> <20180614093452.GA96620@cskk.homeip.net> Message-ID: > >Can anyone explain to me the purpose of "pattern" in the line below: > > > >documents.append((w, pattern['class'])) > > > >documents is declared as a list as follows: > >documents.append((w, pattern['class'])) > > Not without a lot more context. Where did you find this code? > > Cheers, I am sorry that partial info was not sufficient. I am actually trying to implement my first text classification code and I am referring to the below URL for that: https://machinelearnings.co/text-classification-using-neural-networks-f5cd7b8765c6 I hope this helps. From cs at cskk.id.au Thu Jun 14 23:42:03 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 15 Jun 2018 13:42:03 +1000 Subject: pattern In-Reply-To: References: Message-ID: <20180615034203.GA2722@cskk.homeip.net> On 14Jun2018 20:01, Sharan Basappa wrote: >> >Can anyone explain to me the purpose of "pattern" in the line below: >> > >> >documents.append((w, pattern['class'])) >> > >> >documents is declared as a list as follows: >> >documents.append((w, pattern['class'])) >> >> Not without a lot more context. Where did you find this code? > >I am sorry that partial info was not sufficient. >I am actually trying to implement my first text classification code and I am referring to the below URL for that: > >https://machinelearnings.co/text-classification-using-neural-networks-f5cd7b8765c6 Ah, ok. It helps to include some cut/paste of the relevant code, though the URL is a big help. The wider context of the code you recite looks like this: words = [] classes = [] documents = [] ignore_words = ['?'] # loop through each sentence in our training data for pattern in training_data: # tokenize each word in the sentence w = nltk.word_tokenize(pattern['sentence']) # add to our words list words.extend(w) # add to documents in our corpus documents.append((w, pattern['class'])) and the training_data is defined like this: training_data = [] training_data.append({"class":"greeting", "sentence":"how are you?"}) training_data.append({"class":"greeting", "sentence":"how is your day?"}) ... lots more ... So training data is a list of dicts, each dict holding a "class" and "sentence" key. The "for pattern in training_data" loop iterates over each item of the training_data. It calls nltk.word_tokenize on the 'sentence" part of the training item, presumably getting a list of "word" strings. The documents list gets this tuple: (w, pattern['class']) added to it. In this way the documents list ends up with tuples of (words, classification), with the words coming from the sentence via nltk and the classification coming straight from the train item's "class" value. So at the end of the loop the documents array will look like: documents = [ ( ['how', 'are', 'you'], 'greeting' ), ( ['how', 'is', 'your', 'day', 'greeting' ), ] and so forth. Cheers, Cameron Simpson From brgrt2 at gmail.com Fri Jun 15 00:09:07 2018 From: brgrt2 at gmail.com (T Berger) Date: Thu, 14 Jun 2018 21:09:07 -0700 (PDT) Subject: Posting warning message In-Reply-To: References: <08dc4a70-3dc4-4421-893d-832764918150@googlegroups.com> <20180611082257.GA71991@cskk.homeip.net> Message-ID: On Monday, June 11, 2018 at 4:32:56 AM UTC-4, Cameron Simpson wrote: > This is one reason to prefer the mailing list. You can subscribe here: > > https://mail.python.org/mailman/listinfo/python-list > > Many of us prefer that to Google Groups. You have the advantage that email > messages arrive to your GMail directly, instead of to the group. You can easily > file messages from the list into its own folder (in GMail, this is called > "apply a label"). > > Wait for the first message or so and for that message choose GMail's "filter > messages like this" action. I like to choose "Apply the label Python" and "Skip > the inbox" for such things. Then you'll get a nice little "Python" mail folder > in your collection where the list will accumulate. And less spam than the > Group. Sounds great, Cameron. But Gmail doesn't give me the options "Apply the label Python" and "Skip the inbox" under "Filter messages like this." I just get the generic To, From, Has the words, Doesn't have. Tamara From francois.rabanel at outscale.com Fri Jun 15 04:01:03 2018 From: francois.rabanel at outscale.com (francois.rabanel at outscale.com) Date: Fri, 15 Jun 2018 01:01:03 -0700 (PDT) Subject: How can I verify if the regex exist in a file without reading ? In-Reply-To: References: <20180615004153.GA49488@cskk.homeip.net> Message-ID: <9c9093ab-40d1-4660-8ddf-782126ff04a6@googlegroups.com> Le vendredi 15 juin 2018 02:42:12 UTC+2, Cameron Simpson a ?crit?: > On 15Jun2018 00:24, Steven D'Aprano wrote: > >On Fri, 15 Jun 2018 10:00:59 +1000, Cameron Simpson wrote: > >> Francois, unless your regex can cross multiple lines it is better to > >> search files like this: > >> > >> with open(the_filename) as f: > >> for line in f: > >> ... search the line for the regexp ... > >> > >> That way you only need to keep one line at a time in memory. > > > >That's what Fran?ois is doing. > > Urr, so he is. Then like you, I don't know why he's concerned about running out > of memory. Unless it hasn't been made clear the Python will free up unused > memory on its own. > > Cheers, > Cameron Simpson Thanks you a lot for all your tips ! They helps me a lot :) I'm beginner in python, this is an excercise I'm trying to realise. I gonna read more about exceptions and .splitex() ! I work with a file which contains millions lines, a simply file.read() and I'm running out of memory Fran?ois From cs at cskk.id.au Fri Jun 15 04:17:07 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 15 Jun 2018 18:17:07 +1000 Subject: Posting warning message In-Reply-To: References: Message-ID: <20180615081707.GA10580@cskk.homeip.net> On 14Jun2018 21:09, Tamara Berger wrote: >On Monday, June 11, 2018 at 4:32:56 AM UTC-4, Cameron Simpson wrote: >> This is one reason to prefer the mailing list. You can subscribe here: >> https://mail.python.org/mailman/listinfo/python-list [...] >> Wait for the first message or so and for that message choose GMail's "filter >> messages like this" action. I like to choose "Apply the label Python" and "Skip >> the inbox" for such things. Then you'll get a nice little "Python" mail folder >> in your collection where the list will accumulate. And less spam than the >> Group. > >Sounds great, Cameron. But Gmail doesn't give me the options "Apply the label >Python" and "Skip the inbox" under "Filter messages like this." I just get the >generic To, From, Has the words, Doesn't have. The first panel with to/from etc is just the message selection panel. It probably has the "includes the words" field already filled in with something that will match a python-list message. When you click "Create filter with this search" you get another panel with what to do with matching messages. I usually: - skip the Inbox - apply the label: click the "Choose label" dropdown and create a new label "python" or whatever suits you - also apply filter to matching conversations, which will gather up all the list messages that have already arrived and filter them, too Also note that you don't need a label per list. I file a few mailing lists in the same "python" folder. Alternatively, you might make a label per list; note that you can put a slash in a label eg "python/python-list" and GMail will treat that as a hierarchy, making a "python" category on the left with "python-list" underneath it. Might be handy of you join several lists and want to group them. Cheers, Cameron Simpson From ganesh1pal at gmail.com Fri Jun 15 05:04:45 2018 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Fri, 15 Jun 2018 14:34:45 +0530 Subject: Regex to extract multiple fields in the same line In-Reply-To: References: Message-ID: > >>>> {'struct': 'data_block', 'log_file': '/var/1000111/test18.log', 'loc': > '0', 'size': '8'} > > MARB, as usual the solution you you look nice, Thanks for the excellent solutions >>> regex = re.compile (r"--(struct|loc|size|mirror|l og_file)\s*=\s*([^\s]+)") >>> regex.findall (line) [('struct', 'data_block'), ('log_file', '/var/1000111/test18.log'), ('loc', '0'), ('mirror', '10')] Frederic , this look great, thanks for your response From steve+comp.lang.python at pearwood.info Fri Jun 15 06:34:06 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 15 Jun 2018 10:34:06 +0000 (UTC) Subject: How can I verify if the regex exist in a file without reading ? References: <20180615004153.GA49488@cskk.homeip.net> <9c9093ab-40d1-4660-8ddf-782126ff04a6@googlegroups.com> Message-ID: On Fri, 15 Jun 2018 01:01:03 -0700, francois.rabanel wrote: > I work with a file which contains millions lines, a simply file.read() > and I'm running out of memory Assuming each line is on average a hundred characters long, a million lines is (approximately) 100 MB. Even on a computer with only 2GB of memory, you should be able to read 100 MB. But you shouldn't: it is much better to process the file line by line. # Don't do this: with open(pathname) as f: text = f.read() # Slurp the entire file into memory at once. ... # Do this instead with open(pathname) as f: for line in f: # process one line at a time You said you are running out of memory, earlier you said the computer was crashing... please describe exactly what happens. If you get a Traceback, copy and paste the entire message. (Not just the last line.) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From mohanshankercbe at gmail.com Fri Jun 15 08:23:17 2018 From: mohanshankercbe at gmail.com (mohan shanker) Date: Fri, 15 Jun 2018 05:23:17 -0700 (PDT) Subject: text mining Message-ID: <61d4bc38-5fc6-4412-aca2-46bba96eae90@googlegroups.com> anotology using text mining in python pls any one one described fo me From francois.rabanel at outscale.com Fri Jun 15 08:33:31 2018 From: francois.rabanel at outscale.com (francois.rabanel at outscale.com) Date: Fri, 15 Jun 2018 05:33:31 -0700 (PDT) Subject: How can I verify if the regex exist in a file without reading ? In-Reply-To: References: <20180615004153.GA49488@cskk.homeip.net> <9c9093ab-40d1-4660-8ddf-782126ff04a6@googlegroups.com> Message-ID: <1cafe204-f089-45ee-bf3e-be15ed5f1ace@googlegroups.com> Le vendredi 15 juin 2018 12:36:40 UTC+2, Steven D'Aprano a ?crit?: > On Fri, 15 Jun 2018 01:01:03 -0700, francois.rabanel wrote: > > > I work with a file which contains millions lines, a simply file.read() > > and I'm running out of memory > > Assuming each line is on average a hundred characters long, a million > lines is (approximately) 100 MB. Even on a computer with only 2GB of > memory, you should be able to read 100 MB. > > But you shouldn't: it is much better to process the file line by line. > > > # Don't do this: > with open(pathname) as f: > text = f.read() # Slurp the entire file into memory at once. > ... > > # Do this instead > with open(pathname) as f: > for line in f: > # process one line at a time > > > You said you are running out of memory, earlier you said the computer was > crashing... please describe exactly what happens. If you get a Traceback, > copy and paste the entire message. > > (Not just the last line.) > > > > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson I resolve my problem and when I look to my solution I don't understand why I didn't do it earlier :) with open(path) as file: result = [] for line in file: find_regex = re.search(regex,line) if find_regex: result.append(find_regex.group()) if len(result) == 0: sys.exit('Regex not found') elif result[0] == '': sys.exit('Whitespace as regex don\'t work') I was looking for a way to check if the regex's user was correct or not From steve+comp.lang.python at pearwood.info Fri Jun 15 08:57:46 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 15 Jun 2018 12:57:46 +0000 (UTC) Subject: text mining References: <61d4bc38-5fc6-4412-aca2-46bba96eae90@googlegroups.com> Message-ID: On Fri, 15 Jun 2018 05:23:17 -0700, mohan shanker wrote: > anotology using text mining in python pls any one one described fo me fi u cant b bothed to rite prper sentences y shld we be bothered to anwsr ur qestion Seriously, you are asking strangers to help you out of the goodness of their heart. If your intention was to send the message that you're lazy, drunk, or just don't give a damn about the question, you were successful. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From tkadm30 at yandex.com Fri Jun 15 09:31:06 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Fri, 15 Jun 2018 09:31:06 -0400 Subject: Django-hotsauce 1.0 LTS (Commercial Edition) now available for preorder!! In-Reply-To: References: <6192e413-4d4f-6fee-c6a5-76f063485abe@gmail.com> Message-ID: Le 2018-06-14 ? 12:58, Jim Lee a ?crit?: > > > On 06/13/2018 11:38 PM, Chris Angelico wrote: >> On Thu, Jun 14, 2018 at 11:07 AM, Jim Lee wrote: >>> I haven't purchased commercial software in decades, so I'm not up on >>> the >>> prevailing business model, but I have to ask: >>> >>> Why would anyone purchase software and then agree to wait 14 weeks >>> for it to >>> be delivered?? I can see that model for hardware, where material >>> resources >>> are limited and a finite number of product is produced, but software? >>> What's the point? >>> >> For the 50% discount, I presume. If you wait 14 weeks, then buy, then >> own, you pay full price. >> >> ?From the company's point of view: if the release date is in the future >> and ALL the revenue is also in the future, cash flow becomes tricky. >> By getting at least _some_ money in advance, they give themselves a >> way to pay the bills. >> >> ChrisA > But the "50% discount" is supposedly good up until the release date.? > I could purchase the software the day before release and still enjoy > the same benefit without the 14 week wait. > > I understand the advantages *to the company*, but to enjoy those > advantages, they need to provide some kind of incentive to the buyer.? > I don't see one here.? Anyway, I was just curious to see if there was > any kind of thought process behind the "promotion". > > -Jim > > Thought process? I believe the current strategy I have in mind is to let any potential new customers to take the time needed to consider seriously Django-hotsauce for their commercial web applications. This includes allowing some time for peoples (developers) to at least try the free version and then possibly consider switching to the LTS version for extended support and troubleshooting. Anyways, thank you for your input! :) Etienne -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From nhilterbrand at gmail.com Fri Jun 15 09:45:43 2018 From: nhilterbrand at gmail.com (Nathan Hilterbrand) Date: Fri, 15 Jun 2018 09:45:43 -0400 Subject: Regex to extract multiple fields in the same line In-Reply-To: References: Message-ID: On Wed, Jun 13, 2018 at 4:08 AM, Ganesh Pal wrote: > Hi Team, > > I wanted to parse a file and extract few feilds that are present after "=" > in a text file . > > > Example , form the below line I need to extract the values present after > --struct =, --loc=, --size= and --log_file= > > Sample input > > line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block > --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 > --path=/tmp/data_block.txt size=8' > > > Expected output > > data_block > /var/1000111/test18.log > 0 > 8 > > > Here is my sample code , its still not complete , I wanted to use regex > and find and extract all the fields after " =", any suggestion or > alternative way to optimize this further > > > import re > line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block > --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 > --path=/tmp/data_block.txt size=8' > > r_loc = r"--loc=(\d+)" > r_struct = r'--struct=(\w+)' > > if re.findall(r_loc, line): > print re.findall(r_loc, line) > > if re.findall(r_struct, line): > print re.findall(r_struct, line) > > > root at X1:/# python regex_02.py > ['0'] > ['data_block'] > > > I am a Linux user with python 2.7 > > > Regards, > Ganesh > --- Ooops... I didn't notice the 'python 2.7' part until after I had coded up something. This solution could probably be squeezed to work with Python 2 somehow, though I am actually a perl guy, and I love regex... in perl. I do tend to avoid it if all possible in Python, though. I pieced together an ugly function to do what you want. It avoids naming the arguments, so if a new argument is added to your records, it should handle it with no changes. In python, I love comprehensions almost as much as I love regex in perl. Anyway, here is my n00bish stab at it: #!/usr/bin/python3 line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 --path=/tmp/data_block.txt size=8' def get_args(lne): first_hyphens = lne.find('--') # find where the args start if first_hyphens == -1: # Blow up if ill-formed arg raise ValueError("Invalid input line") prelude = lne[0:first_hyphens] # Get the stuff before the args prelude = prelude.strip() args = lne[first_hyphens:] # Get the arguments # The following line uses comprehensions to build a dictionary of # argument/value pairs. The arguments portion is split on whitespace, # then each --XX=YY pair is split by '=' into a two element list, Each # two element list then provides the key and value for each argument. # Note the 'd[0][2:]' strips the '--' from the front of the argument # name argdict = {d[0][2:]:d[1] for d in [e.split('=')[0:2] for e in args.split()]} return (prelude, argdict) if __name__ == "__main__": pre, argdict = get_args(line) print('Prelude is "{}"'.format(pre)) for arg in argdict: print(' Argument {} = {}'.format(arg, argdict[arg])) > -- > https://mail.python.org/mailman/listinfo/python-list > From anthra.norell at bluewin.ch Fri Jun 15 10:31:39 2018 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Fri, 15 Jun 2018 16:31:39 +0200 Subject: Regex to extract multiple fields in the same line In-Reply-To: References: <65b28fa1-a9fb-0c89-0525-c053d16f9727@bluewin.ch> Message-ID: <5cfe4b8d-429f-eac8-1d7e-1be4ad94709f@bluewin.ch> On 06/15/2018 12:37 PM, Ganesh Pal wrote: > Hey Friedrich, > > The proposed solution worked nice , Thank you for the reply really > appreciate that > > > Only thing I think would need a review is if the assignment of the value > of one dictionary to the another dictionary if is done correctly ( lines > 17 to 25 in the below code) > > > Here is my code : > > root at X1:/Play_ground/SPECIAL_TYPES/REGEX# vim Friedrich.py > 1 import re > 2 from collections import OrderedDict > 3 > 4 keys = ["struct", "loc", "size", "mirror", > 5 "filename","final_results"] > 6 > 7 stats = OrderedDict.fromkeys(keys) > 8 > 9 > 10 line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block > --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 > --path=/tmp/data_block.txt --s ize=8' > 11 > 12 regex = re.compile (r"--(struct|loc|size|mirror| > log_file)\s*=\s*([^\s]+)") > 13 result = dict(re.findall(regex, line)) > 14 print result > 15 > 16 if result['log_file']: > 17 stats['filename'] = result['log_file'] > 18 if result['struct']: > 19 stats['struct'] = result['struct'] > 20 if result['size']: > 21 stats['size'] = result['size'] > 22 if result['loc']: > 23 stats['loc'] = result['loc'] > 24 if result['mirror']: > 25 stats['mirror'] = result['mirror'] > 26 > 27 print stats > 28 Looks okay to me. If you'd read 'result' using 'get' you wouldn't need to test for the key. 'stats' would then have all keys and value None for keys missing in 'result': stats['filename'] = result.get ('log_file') stats['struct']?? = result.get ('struct') This may or may not suit your purpose. > > Also, I think the regex can just be > (r"--(struct|loc|size|mirror|log_file)=([^\s]+)") > no need to match white space character (\s* ) before and after the = > symbol because this would never happen ( this line is actually a key=value > pair of a dictionary getting logged) > You are right. I thought your sample line had a space in one of the groups and didn't reread to verify, letting the false impression take hold. Sorry about that. Frederic > Regards, > Ganesh > > > > > > > On Fri, Jun 15, 2018 at 12:53 PM, Friedrich Rentsch < > anthra.norell at bluewin.ch> wrote: > >> Hi Ganesch. Having proposed a solution to your problem, it would be kind >> of you to let me know whether it has helped. In case you missed my >> response, I repeat it: >> >>>>> regex = re.compile (r"--(struct|loc|size|mirror|l >> og_file)\s*=\s*([^\s]+)") >>>>> regex.findall (line) >> [('struct', 'data_block'), ('log_file', '/var/1000111/test18.log'), >> ('loc', '0'), ('mirror', '10')] >> >> Frederic >> >> >> On 06/13/2018 07:32 PM, Ganesh Pal wrote: >> >>> On Wed, Jun 13, 2018 at 5:59 PM, Rhodri James >>> wrote: >>> >>> On 13/06/18 09:08, Ganesh Pal wrote: >>>> Hi Team, >>>>> I wanted to parse a file and extract few feilds that are present after >>>>> "=" >>>>> in a text file . >>>>> >>>>> >>>>> Example , form the below line I need to extract the values present >>>>> after >>>>> --struct =, --loc=, --size= and --log_file= >>>>> >>>>> Sample input >>>>> >>>>> line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block >>>>> --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 >>>>> --path=/tmp/data_block.txt size=8' >>>>> >>>>> Did you mean "--size=8" at the end? That's what your explanation >>>> implied. >>>> >>> >>> >>> Yes James you got it right , I meant "--size=8 " ., >>> >>> >>> Hi Team, >>> >>> >>> I played further with python's re.findall() and I am able to extract all >>> the required fields , I have 2 further questions too , please suggest >>> >>> >>> Question 1: >>> >>> Please let me know the mistakes in the below code and suggest if it >>> can >>> be optimized further with better regex >>> >>> >>> # This code has to extract various the fields from a single line ( >>> assuming the line is matched here ) of a log file that contains various >>> values (and then store the extracted values in a dictionary ) >>> >>> import re >>> >>> line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block >>> --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 >>> --path=/tmp/data_block.txt --size=8' >>> >>> #loc is an number >>> r_loc = r"--loc=([0-9]+)" >>> r_size = r'--size=([0-9]+)' >>> r_struct = r'--struct=([A-Za-z_]+)' >>> r_log_file = r'--log_file=([A-Za-z0-9_/.]+)' >>> >>> >>> if re.findall(r_loc, line): >>> print re.findall(r_loc, line) >>> >>> if re.findall(r_size, line): >>> print re.findall(r_size, line) >>> >>> if re.findall(r_struct, line): >>> print re.findall(r_struct, line) >>> >>> if re.findall(r_log_file, line): >>> print re.findall(r_log_file, line) >>> >>> >>> o/p: >>> root at X1:/Play_ground/SPECIAL_TYPES/REGEX# python regex_002.py >>> ['0'] >>> ['8'] >>> ['data_block'] >>> ['/var/1000111/test18.log'] >>> >>> >>> Question 2: >>> >>> I tried to see if I can use re.search with look behind assertion , it >>> seems to work , any comments or suggestions >>> >>> Example: >>> >>> import re >>> >>> line = '06/12/2018 11:13:23 AM python toolname.py --struct=data_block >>> --log_file=/var/1000111/test18.log --addr=None --loc=0 --mirror=10 >>> --path=/tmp/data_block.txt --size=8' >>> >>> match = re.search(r'(?P(?<=--loc=)([0-9]+))', line) >>> if match: >>> print match.group('loc') >>> >>> >>> o/p: root at X1:/Play_ground/SPECIAL_TYPES/REGEX# python regex_002.py >>> >>> 0 >>> >>> >>> I want to build the sub patterns and use match.group() to get the values >>> , some thing as show below but it doesn't seem to work >>> >>> >>> match = re.search(r'(?P(?<=--loc=)([0-9]+))' >>> r'(?P(?<=--size=)([0-9]+))', line) >>> if match: >>> print match.group('loc') >>> print match.group('size') >>> >>> Regards, >>> Ganesh >>> >> From brgrt2 at gmail.com Fri Jun 15 10:48:36 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Fri, 15 Jun 2018 10:48:36 -0400 Subject: Posting warning message In-Reply-To: <20180615081707.GA10580@cskk.homeip.net> References: <20180615081707.GA10580@cskk.homeip.net> Message-ID: Cameron, I DON'T HAVE the options "skip the inbox" and "apply the label." Not within the option "filter messages like this," which is where I understood you to say they were, or outside that option. Does Gmail have these options? Tamara On Fri, Jun 15, 2018 at 4:17 AM Cameron Simpson wrote: > > On 14Jun2018 21:09, Tamara Berger wrote: > >On Monday, June 11, 2018 at 4:32:56 AM UTC-4, Cameron Simpson wrote: > >> This is one reason to prefer the mailing list. You can subscribe here: > >> https://mail.python.org/mailman/listinfo/python-list > [...] > >> Wait for the first message or so and for that message choose GMail's "filter > >> messages like this" action. I like to choose "Apply the label Python" and "Skip > >> the inbox" for such things. Then you'll get a nice little "Python" mail folder > >> in your collection where the list will accumulate. And less spam than the > >> Group. > > > >Sounds great, Cameron. But Gmail doesn't give me the options "Apply the label > >Python" and "Skip the inbox" under "Filter messages like this." I just get the > >generic To, From, Has the words, Doesn't have. > > The first panel with to/from etc is just the message selection panel. It > probably has the "includes the words" field already filled in with something > that will match a python-list message. When you click "Create filter with this > search" you get another panel with what to do with matching messages. > > I usually: > > - skip the Inbox > - apply the label: click the "Choose label" dropdown and create a new label > "python" or whatever suits you > - also apply filter to matching conversations, which will gather up all the > list messages that have already arrived and filter them, too > > Also note that you don't need a label per list. I file a few mailing lists in > the same "python" folder. > > Alternatively, you might make a label per list; note that you can put a slash > in a label eg "python/python-list" and GMail will treat that as a hierarchy, > making a "python" category on the left with "python-list" underneath it. Might > be handy of you join several lists and want to group them. > > Cheers, > Cameron Simpson From brgrt2 at gmail.com Fri Jun 15 11:04:43 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Fri, 15 Jun 2018 11:04:43 -0400 Subject: Posting warning message In-Reply-To: <20180615081707.GA10580@cskk.homeip.net> References: <20180615081707.GA10580@cskk.homeip.net> Message-ID: Hi Cameron, Please ignore my last email. I found those two options AFTER I created the filter. I expected them to be on the "filter messages like this" panel. Tamara > On 14Jun2018 21:09, Tamara Berger wrote: > >On Monday, June 11, 2018 at 4:32:56 AM UTC-4, Cameron Simpson wrote: > >> This is one reason to prefer the mailing list. You can subscribe here: > >> https://mail.python.org/mailman/listinfo/python-list > [...] > >> Wait for the first message or so and for that message choose GMail's "filter > >> messages like this" action. I like to choose "Apply the label Python" and "Skip > >> the inbox" for such things. Then you'll get a nice little "Python" mail folder > >> in your collection where the list will accumulate. And less spam than the > >> Group. > > > >Sounds great, Cameron. But Gmail doesn't give me the options "Apply the label > >Python" and "Skip the inbox" under "Filter messages like this." I just get the > >generic To, From, Has the words, Doesn't have. > > The first panel with to/from etc is just the message selection panel. It > probably has the "includes the words" field already filled in with something > that will match a python-list message. When you click "Create filter with this > search" you get another panel with what to do with matching messages. > > I usually: > > - skip the Inbox > - apply the label: click the "Choose label" dropdown and create a new label > "python" or whatever suits you > - also apply filter to matching conversations, which will gather up all the > list messages that have already arrived and filter them, too > > Also note that you don't need a label per list. I file a few mailing lists in > the same "python" folder. > > Alternatively, you might make a label per list; note that you can put a slash > in a label eg "python/python-list" and GMail will treat that as a hierarchy, > making a "python" category on the left with "python-list" underneath it. Might > be handy of you join several lists and want to group them. > > Cheers, > Cameron Simpson From brgrt2 at gmail.com Fri Jun 15 11:19:22 2018 From: brgrt2 at gmail.com (T Berger) Date: Fri, 15 Jun 2018 08:19:22 -0700 (PDT) Subject: Flask failure Message-ID: <3fe6b3e1-f582-415b-ace1-b104f42efef9@googlegroups.com> I?m trying to build a webapp with flask. I installed flask, created a webapp in IDLE, but when I tried testing it at my terminal, I got a huge error message. This is the app: from flask import Flask app = Flask(__name__) @app.route('/') def hello() -> str: ? ? return 'Hello world from Flask!' app.run() This is my command and the resulting error message, containing a warning in red: Last login: Thu Jun 14 23:54:55 on ttys000 192:~ TamaraB$ cd Desktop/Webapp/ 192:Webapp TamaraB$ python3 hello_flask.py ?* Serving Flask app "hello_flask" (lazy loading) ?* Environment: production ? ?WARNING: Do not use the development server in a production environment. ? ?Use a production WSGI server instead. ?* Debug mode: off Traceback (most recent call last): ? File "hello_flask.py", line 6, in ? ? app.run() ? File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 943, in run ? ? run_simple(host, port, self, **options) ? File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/werkzeug/serving.py", line 814, in run_simple ? ? inner() ? File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/werkzeug/serving.py", line 774, in inner ? ? fd=fd) ? File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/werkzeug/serving.py", line 660, in make_server ? ? passthrough_errors, ssl_context, fd=fd) ? File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/werkzeug/serving.py", line 577, in __init__ ? ? self.address_family), handler) ? File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socketserver.py", line 453, in __init__ ? ? self.server_bind() ? File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/server.py", line 136, in server_bind ? ? socketserver.TCPServer.server_bind(self) ? File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socketserver.py", line 467, in server_bind ? ? self.socket.bind(self.server_address) OSError: [Errno 48] Address already in use 192:Webapp TamaraB$ What went wrong? From brgrt2 at gmail.com Fri Jun 15 11:28:38 2018 From: brgrt2 at gmail.com (T Berger) Date: Fri, 15 Jun 2018 08:28:38 -0700 (PDT) Subject: Python list vs google group Message-ID: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> I'm suspecting that posting to python google groups (this site) gets more responses than mailing to the python list. Am I correct? Also, contrary to what I read on the python list information sheet, what shows up in this forum does not match what comes into my inbox. I started a post here and then replied to a post from my inbox. That reply does not show up in this forum. Tamara From alister.ware at ntlworld.com Fri Jun 15 11:31:35 2018 From: alister.ware at ntlworld.com (Alister) Date: Fri, 15 Jun 2018 15:31:35 GMT Subject: Python list vs google group References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On Fri, 15 Jun 2018 08:28:38 -0700, T Berger wrote: > I'm suspecting that posting to python google groups (this site) gets > more responses than mailing to the python list. Am I correct? Also, > contrary to what I read on the python list information sheet, what shows > up in this forum does not match what comes into my inbox. I started a > post here and then replied to a post from my inbox. That reply does not > show up in this forum. > > Tamara it certainly seems to be the source of most SPAM as such some users of this list/newsgroup call it what you like block all posts from google groups -- One day I'll be dead and THEN you'll all be sorry. (alt.fan.pratchett) From brgrt2 at gmail.com Fri Jun 15 11:47:45 2018 From: brgrt2 at gmail.com (T Berger) Date: Fri, 15 Jun 2018 08:47:45 -0700 (PDT) Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On Friday, June 15, 2018 at 11:31:47 AM UTC-4, Alister wrote: > it certainly seems to be the source of most SPAM > as such some users of this list/newsgroup call it what you like block all > posts from google groups But you don't think you get more replies to a question posted here than emailed to the list? The forum and the email list are supposed to be different access routes to the same content, but I don't find that to be the case. I replied to a post via email, but my reply did not show up on this forum. Tamara From rshepard at appl-ecosys.com Fri Jun 15 11:47:51 2018 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Jun 2018 08:47:51 -0700 (PDT) Subject: Python list vs google group In-Reply-To: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On Fri, 15 Jun 2018, T Berger wrote: > I'm suspecting that posting to python google groups (this site) gets more > responses than mailing to the python list. Am I correct? Also, contrary to > what I read on the python list information sheet, what shows up in this > forum does not match what comes into my inbox. I started a post here and > then replied to a post from my inbox. That reply does not show up in this > forum. Tamara, That's not been my experiences. I subscribe to a few mail lists that are mirrored on googlegroups.com. My preference is to have messages pushed to me by the mail list manager rather than my using the browser to go to googlegroups and pull threads. YMMV. Anyway, I've not had any threads, including ones I start, not appear in my mail reader. I've not had a response posted to google groups that did not also appear in my mailbox. Perhaps your experience has something to do with your MUA. Regards, Rich From rosuav at gmail.com Fri Jun 15 11:55:36 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jun 2018 01:55:36 +1000 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On Sat, Jun 16, 2018 at 1:47 AM, T Berger wrote: > On Friday, June 15, 2018 at 11:31:47 AM UTC-4, Alister wrote: > >> it certainly seems to be the source of most SPAM >> as such some users of this list/newsgroup call it what you like block all >> posts from google groups > > But you don't think you get more replies to a question posted here than emailed to the list? The forum and the email list are supposed to be different access routes to the same content, but I don't find that to be the case. I replied to a post via email, but my reply did not show up on this forum. > Is "more replies" your best criterion? I posted something to a much smaller mailing list and got several HUNDRED replies. In fact, that's happened to me multiple times, with multiple different lists. Perhaps quantity is not the important thing here. ChrisA From breamoreboy at gmail.com Fri Jun 15 12:03:17 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Fri, 15 Jun 2018 17:03:17 +0100 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On 15/06/18 16:47, T Berger wrote: > On Friday, June 15, 2018 at 11:31:47 AM UTC-4, Alister wrote: > >> it certainly seems to be the source of most SPAM >> as such some users of this list/newsgroup call it what you like block all >> posts from google groups > > But you don't think you get more replies to a question posted here than emailed to the list? The forum and the email list are supposed to be different access routes to the same content, but I don't find that to be the case. I replied to a post via email, but my reply did not show up on this forum. > > Tamara > For the third and final time, just get a (semi-)decent email client/news reader/whatever it's called, point it at news.gmane.org and read this forum, hundreds of other python forums and thousands of other technical forums with no problems at all. No cluttered inbox so no need to filter anything. I happen to use thunderbird, there are umpteen other choices. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From elismar at elismarluz.com Fri Jun 15 12:16:11 2018 From: elismar at elismarluz.com (Elismar Luz) Date: Fri, 15 Jun 2018 13:16:11 -0300 Subject: Flask failure In-Reply-To: <3fe6b3e1-f582-415b-ace1-b104f42efef9@googlegroups.com> References: <3fe6b3e1-f582-415b-ace1-b104f42efef9@googlegroups.com> Message-ID: Address already in use! On Fri, Jun 15, 2018 at 12:19 PM, T Berger wrote: > I?m trying to build a webapp with flask. I installed flask, created a > webapp in IDLE, but when I tried testing it at my terminal, I got a huge > error message. This is the app: > > from flask import Flask > app = Flask(__name__) > @app.route('/') > def hello() -> str: > return 'Hello world from Flask!' > app.run() > > This is my command and the resulting error message, containing a warning > in red: > > Last login: Thu Jun 14 23:54:55 on ttys000 > 192:~ TamaraB$ cd Desktop/Webapp/ > 192:Webapp TamaraB$ python3 hello_flask.py > * Serving Flask app "hello_flask" (lazy loading) > * Environment: production > WARNING: Do not use the development server in a production environment. > Use a production WSGI server instead. > * Debug mode: off > Traceback (most recent call last): > File "hello_flask.py", line 6, in > app.run() > File "/Library/Frameworks/Python.framework/Versions/3.6/lib/ > python3.6/site-packages/flask/app.py", > line 943, in run > run_simple(host, port, self, **options) > File "/Library/Frameworks/Python.framework/Versions/3.6/lib/ > python3.6/site-packages/werkzeug/serving.py", > line 814, in run_simple > inner() > File "/Library/Frameworks/Python.framework/Versions/3.6/lib/ > python3.6/site-packages/werkzeug/serving.py", > line 774, in inner > fd=fd) > File "/Library/Frameworks/Python.framework/Versions/3.6/lib/ > python3.6/site-packages/werkzeug/serving.py", > line 660, in make_server > passthrough_errors, ssl_context, fd=fd) > File "/Library/Frameworks/Python.framework/Versions/3.6/lib/ > python3.6/site-packages/werkzeug/serving.py", > line 577, in __init__ > self.address_family), handler) > File "/Library/Frameworks/Python.framework/Versions/3.6/lib/ > python3.6/socketserver.py", > line 453, in __init__ > self.server_bind() > File "/Library/Frameworks/Python.framework/Versions/3.6/lib/ > python3.6/http/server.py", > line 136, in server_bind > socketserver.TCPServer.server_bind(self) > File "/Library/Frameworks/Python.framework/Versions/3.6/lib/ > python3.6/socketserver.py", > line 467, in server_bind > self.socket.bind(self.server_address) > OSError: [Errno 48] Address already in use > 192:Webapp TamaraB$ > > What went wrong? > -- > https://mail.python.org/mailman/listinfo/python-list > -- Elismar Luz GNU/Linux Admin (61) 99400-3376 From brgrt2 at gmail.com Fri Jun 15 12:32:05 2018 From: brgrt2 at gmail.com (T Berger) Date: Fri, 15 Jun 2018 09:32:05 -0700 (PDT) Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: <475b4138-1e01-4c0a-b7cf-5262a8872d8b@googlegroups.com> On Friday, June 15, 2018 at 11:55:59 AM UTC-4, Chris Angelico wrote: > Perhaps quantity is not the important thing here. It is the important thing. I'm stuck with a problem and still waiting for replies to my email. I've decided to repost my problem here, so we'll see whether my hypothesis holds water. Tamara From brgrt2 at gmail.com Fri Jun 15 12:33:16 2018 From: brgrt2 at gmail.com (T Berger) Date: Fri, 15 Jun 2018 09:33:16 -0700 (PDT) Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On Friday, June 15, 2018 at 12:14:30 PM UTC-4, Mark Lawrence wrote: > On 15/06/18 16:47, T Berger wrote: > > On Friday, June 15, 2018 at 11:31:47 AM UTC-4, Alister wrote: > > > >> it certainly seems to be the source of most SPAM > >> as such some users of this list/newsgroup call it what you like block all > >> posts from google groups > > > > But you don't think you get more replies to a question posted here than emailed to the list? The forum and the email list are supposed to be different access routes to the same content, but I don't find that to be the case. I replied to a post via email, but my reply did not show up on this forum. > > > > Tamara > > > > For the third and final time, just get a (semi-)decent email client/news > reader/whatever it's called, point it at news.gmane.org and read this > forum, hundreds of other python forums and thousands of other technical > forums with no problems at all. No cluttered inbox so no need to filter > anything. I happen to use thunderbird, there are umpteen other choices. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence From brgrt2 at gmail.com Fri Jun 15 12:39:07 2018 From: brgrt2 at gmail.com (T Berger) Date: Fri, 15 Jun 2018 09:39:07 -0700 (PDT) Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: <84286dbc-b30e-4e65-b6e7-51eb16a7ef35@googlegroups.com> On Friday, June 15, 2018 at 12:14:30 PM UTC-4, Mark Lawrence wrote: > For the third and final time, just get a (semi-)decent email client/news > reader/whatever it's called, point it at news.gmane.org and read this > forum, hundreds of other python forums and thousands of other technical > forums with no problems at all. No cluttered inbox so no need to filter > anything. I happen to use thunderbird, there are umpteen other choices. To do this, I will have to research what you mean by "a (semi-)decent email client/news reader," and "point it at news.gmane.org." I'm a little unused to web-related lingo. Then I'll have to root around in gmane.org to see how it works. This is not to say that I might not try this route, only that it will take a bit of time and effort. I just set some filters on the incoming python email, and will see how it works first. But thanks for your thrice-proffered suggestion. Tamara From tmrsg11 at gmail.com Fri Jun 15 12:39:28 2018 From: tmrsg11 at gmail.com (C W) Date: Fri, 15 Jun 2018 12:39:28 -0400 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: I recently posted two questions, but never got any replies. I am still wondering if it was ever posted, or maybe the question was too trivial? I think someone would have at least shouted if it was too trivial or off-topic, right? On Fri, Jun 15, 2018 at 12:03 PM, Mark Lawrence wrote: > On 15/06/18 16:47, T Berger wrote: > >> On Friday, June 15, 2018 at 11:31:47 AM UTC-4, Alister wrote: >> >> it certainly seems to be the source of most SPAM >>> as such some users of this list/newsgroup call it what you like block all >>> posts from google groups >>> >> >> But you don't think you get more replies to a question posted here than >> emailed to the list? The forum and the email list are supposed to be >> different access routes to the same content, but I don't find that to be >> the case. I replied to a post via email, but my reply did not show up on >> this forum. >> >> Tamara >> >> > For the third and final time, just get a (semi-)decent email client/news > reader/whatever it's called, point it at news.gmane.org and read this > forum, hundreds of other python forums and thousands of other technical > forums with no problems at all. No cluttered inbox so no need to filter > anything. I happen to use thunderbird, there are umpteen other choices. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence > > -- > https://mail.python.org/mailman/listinfo/python-list > From brgrt2 at gmail.com Fri Jun 15 12:40:18 2018 From: brgrt2 at gmail.com (T Berger) Date: Fri, 15 Jun 2018 09:40:18 -0700 (PDT) Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: Hi Rich, Please define YMMV, MUA. Thanks, Tamara From brgrt2 at gmail.com Fri Jun 15 12:43:31 2018 From: brgrt2 at gmail.com (T Berger) Date: Fri, 15 Jun 2018 09:43:31 -0700 (PDT) Subject: Python list vs google group In-Reply-To: <475b4138-1e01-4c0a-b7cf-5262a8872d8b@googlegroups.com> References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <475b4138-1e01-4c0a-b7cf-5262a8872d8b@googlegroups.com> Message-ID: <48392218-6c67-40af-9a6f-3d4ab8686fdf@googlegroups.com> On Friday, June 15, 2018 at 12:32:17 PM UTC-4, T Berger wrote: > On Friday, June 15, 2018 at 11:55:59 AM UTC-4, Chris Angelico wrote: > > Perhaps quantity is not the important thing here. > > It is the important thing. I'm stuck with a problem and still waiting for replies to my email. I've decided to repost my problem here, so we'll see whether my hypothesis holds water. > > Tamara If anyone wants to take a stab at my problem, its subject line is "Flask Failure." Thanks, Tamara From rshepard at appl-ecosys.com Fri Jun 15 12:55:56 2018 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Jun 2018 09:55:56 -0700 (PDT) Subject: Python list vs google group In-Reply-To: <48392218-6c67-40af-9a6f-3d4ab8686fdf@googlegroups.com> References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <475b4138-1e01-4c0a-b7cf-5262a8872d8b@googlegroups.com> <48392218-6c67-40af-9a6f-3d4ab8686fdf@googlegroups.com> Message-ID: On Fri, 15 Jun 2018, T Berger wrote: > If anyone wants to take a stab at my problem, its subject line is "Flask > Failure." Tamara, I saw that earlier this morning -- on the mail list. As I know nothing about flask I deleted it without reading. Rich From larry.martell at gmail.com Fri Jun 15 12:56:01 2018 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 15 Jun 2018 12:56:01 -0400 Subject: Python list vs google group In-Reply-To: <48392218-6c67-40af-9a6f-3d4ab8686fdf@googlegroups.com> References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <475b4138-1e01-4c0a-b7cf-5262a8872d8b@googlegroups.com> <48392218-6c67-40af-9a6f-3d4ab8686fdf@googlegroups.com> Message-ID: On Fri, Jun 15, 2018 at 12:49 PM T Berger wrote: > On Friday, June 15, 2018 at 12:32:17 PM UTC-4, T Berger wrote: > > On Friday, June 15, 2018 at 11:55:59 AM UTC-4, Chris Angelico wrote: > > > Perhaps quantity is not the important thing here. > > > > It is the important thing. I'm stuck with a problem and still waiting > for replies to my email. I've decided to repost my problem here, so we'll > see whether my hypothesis holds water. > > > > Tamara > > If anyone wants to take a stab at my problem, its subject line is "Flask > Failure." There is a flask ML http://flask.pocoo.org/mailinglist/ > From rshepard at appl-ecosys.com Fri Jun 15 12:58:21 2018 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Jun 2018 09:58:21 -0700 (PDT) Subject: Python list vs google group In-Reply-To: <84286dbc-b30e-4e65-b6e7-51eb16a7ef35@googlegroups.com> References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <84286dbc-b30e-4e65-b6e7-51eb16a7ef35@googlegroups.com> Message-ID: On Fri, 15 Jun 2018, T Berger wrote: > To do this, I will have to research what you mean by "a (semi-)decent > email client/news reader," and "point it at news.gmane.org." I'm a little > unused to web-related lingo. Then I'll have to root around in gmane.org to > see how it works. This is not to say that I might not try this route, only > that it will take a bit of time and effort. I just set some filters on the > incoming python email, and will see how it works first. But thanks for > your thrice-proffered suggestion. What OS do you run? I know folks with gmail accounts who follow newsgroups using firefox, chromium, and thunderbird. I use alpine (which is text-based since e-mail messages are text it's a perfect fit) on Slackware linux. Rich From rshepard at appl-ecosys.com Fri Jun 15 13:00:27 2018 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Jun 2018 10:00:27 -0700 (PDT) Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On Fri, 15 Jun 2018, C W wrote: > I think someone would have at least shouted if it was too trivial or > off-topic, right? Nope. Most of us do not reply if we have insufficient knowledge to offer a usable response. Saves bandwidth and electrons. When you get no replies it usually indicates no one knows how to help. Happens quite a bit. Rich From rshepard at appl-ecosys.com Fri Jun 15 13:03:09 2018 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Jun 2018 10:03:09 -0700 (PDT) Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On Fri, 15 Jun 2018, T Berger wrote: > Please define YMMV, MUA. Tamara, Your Milage May Vary. Here's a list when you have the time and inclination: . Best regards, Rich From python at mrabarnett.plus.com Fri Jun 15 13:03:35 2018 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 15 Jun 2018 18:03:35 +0100 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: <73a56c64-4ea2-bcac-3d85-709402e13834@mrabarnett.plus.com> On 2018-06-15 17:40, T Berger wrote: > Hi Rich, > > Please define YMMV, MUA. > YMMV Your Mileage May Vary MUA Mail User Agent (email program) From colin.mcphail at mac.com Fri Jun 15 13:05:06 2018 From: colin.mcphail at mac.com (Colin McPhail) Date: Fri, 15 Jun 2018 18:05:06 +0100 Subject: Flask failure In-Reply-To: <3fe6b3e1-f582-415b-ace1-b104f42efef9@googlegroups.com> References: <3fe6b3e1-f582-415b-ace1-b104f42efef9@googlegroups.com> Message-ID: > On 15 Jun 2018, at 16:19, T Berger wrote: > > I?m trying to build a webapp with flask. I installed flask, created a webapp in IDLE, but when I tried testing it at my terminal, I got a huge error message. This is the app: > > from flask import Flask > app = Flask(__name__) > @app.route('/') > def hello() -> str: > return 'Hello world from Flask!' > app.run() > > This is my command and the resulting error message, containing a warning in red: > > Last login: Thu Jun 14 23:54:55 on ttys000 > 192:~ TamaraB$ cd Desktop/Webapp/ > 192:Webapp TamaraB$ python3 hello_flask.py > * Serving Flask app "hello_flask" (lazy loading) > * Environment: production > WARNING: Do not use the development server in a production environment. > Use a production WSGI server instead. > * Debug mode: off > Traceback (most recent call last): > File "hello_flask.py", line 6, in > app.run() > [snip] > File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socketserver.py", > line 467, in server_bind > self.socket.bind(self.server_address) > OSError: [Errno 48] Address already in use > 192:Webapp TamaraB$ > > What went wrong? Did the instructions for running this Flask example mention anything about not using the standard HTTP port number (80)? I don?t know much about Flask but I expect it runs an HTTP server in order to serve your HTML content to clients. If it tries to use the standard port then it will likely find it is already in use or that you do not have permission to use it. ? Colin From rshepard at appl-ecosys.com Fri Jun 15 13:05:40 2018 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Jun 2018 10:05:40 -0700 (PDT) Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On Fri, 15 Jun 2018, T Berger wrote: > Please define YMMV, MUA. Oh, ... MUA == Mail User Agent. This is the client we use to read and write e-mail messages. Other mail-related abbreviations are MTA (Mail Transfer Agent, used to sort incoming messages to subject-related files), MTA (Mail Transport Agent, such as postfix, exim, and qmail which sends and receives messages). Rich From larry.martell at gmail.com Fri Jun 15 13:36:50 2018 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 15 Jun 2018 13:36:50 -0400 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On Fri, Jun 15, 2018 at 1:14 PM Rich Shepard wrote: > On Fri, 15 Jun 2018, T Berger wrote: > > > Please define YMMV, MUA. > > Oh, ... MUA == Mail User Agent. I thought it was Made Up Acronym > > From rshepard at appl-ecosys.com Fri Jun 15 14:08:35 2018 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Jun 2018 11:08:35 -0700 (PDT) Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On Fri, 15 Jun 2018, Larry Martell wrote: >> Oh, ... MUA == Mail User Agent. > I thought it was Made Up Acronym Larry, Could be; depends on the context. Rich From larry.martell at gmail.com Fri Jun 15 14:44:25 2018 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 15 Jun 2018 14:44:25 -0400 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On Fri, Jun 15, 2018 at 2:08 PM, Rich Shepard wrote: > On Fri, 15 Jun 2018, Larry Martell wrote: > >>> Oh, ... MUA == Mail User Agent. >> >> I thought it was Made Up Acronym > > > Larry, > > Could be; depends on the context. My favorite acronym of all time is TWAIN From rgaddi at highlandtechnology.invalid Fri Jun 15 14:52:15 2018 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 15 Jun 2018 11:52:15 -0700 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On 06/15/2018 11:44 AM, Larry Martell wrote: > On Fri, Jun 15, 2018 at 2:08 PM, Rich Shepard wrote: >> On Fri, 15 Jun 2018, Larry Martell wrote: >> >>>> Oh, ... MUA == Mail User Agent. >>> >>> I thought it was Made Up Acronym >> >> >> Larry, >> >> Could be; depends on the context. > > My favorite acronym of all time is TWAIN > Really? I always thought it didn't scan. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From pkpearson at nowhere.invalid Fri Jun 15 15:09:18 2018 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 15 Jun 2018 19:09:18 GMT Subject: What data types does matplotlib pyplot take? References: Message-ID: On Wed, 13 Jun 2018 12:53:57 -0400, C W wrote: > Hi everyone, > > I'm curious what data types pyplot takes. It seems that it can take numpy > series, pandas series, and possibly pandas dataframe? How many people data > types are out there? Is that true for all functions in like hist(), bar(), > line(), etc? I regret that this might seem less than helpful, but someone should point out that an enumeration beginning "This package works with the following data types" would be antithetical to Python's "duck-typing" philosophy. The important thing is not an object's type, but whether the object has the attributes and methods required. -- To email me, substitute nowhere->runbox, invalid->com. From larry.martell at gmail.com Fri Jun 15 15:15:20 2018 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 15 Jun 2018 15:15:20 -0400 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On Fri, Jun 15, 2018 at 2:52 PM, Rob Gaddi wrote: > On 06/15/2018 11:44 AM, Larry Martell wrote: >> >> On Fri, Jun 15, 2018 at 2:08 PM, Rich Shepard >> wrote: >>> >>> On Fri, 15 Jun 2018, Larry Martell wrote: >>> >>>>> Oh, ... MUA == Mail User Agent. >>>> >>>> >>>> I thought it was Made Up Acronym >>> >>> >>> >>> Larry, >>> >>> Could be; depends on the context. >> >> >> My favorite acronym of all time is TWAIN >> > > Really? I always thought it didn't scan. YAML is good too. As is YACC. But TWAIN is the best. From rosuav at gmail.com Fri Jun 15 20:00:54 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jun 2018 10:00:54 +1000 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On Sat, Jun 16, 2018 at 4:52 AM, Rob Gaddi wrote: > On 06/15/2018 11:44 AM, Larry Martell wrote: >> >> My favorite acronym of all time is TWAIN >> > > Really? I always thought it didn't scan. > Having spent way WAY too many hours trying to turn documents into images (and text), I very much appreciate that laugh. ChrisA From jlee54 at gmail.com Fri Jun 15 21:00:29 2018 From: jlee54 at gmail.com (Jim Lee) Date: Fri, 15 Jun 2018 18:00:29 -0700 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> On 06/15/2018 05:00 PM, Chris Angelico wrote: > On Sat, Jun 16, 2018 at 4:52 AM, Rob Gaddi > wrote: >> On 06/15/2018 11:44 AM, Larry Martell wrote: >>> My favorite acronym of all time is TWAIN >>> >> Really? I always thought it didn't scan. >> > Having spent way WAY too many hours trying to turn documents into > images (and text), I very much appreciate that laugh. > > ChrisA I once had a Mustek color scanner that came with a TWAIN driver.? If the room temperature was above 80 degrees F, it would scan in color - otherwise, only black & white.? I was *sure* it was a hardware problem, but then someone released a native Linux driver for the scanner.? When I moved the scanner to my Linux box, it worked fine regardless of temperature. -Jim From rantingrickjohnson at gmail.com Fri Jun 15 21:08:03 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 15 Jun 2018 18:08:03 -0700 (PDT) Subject: text mining In-Reply-To: References: <61d4bc38-5fc6-4412-aca2-46bba96eae90@googlegroups.com> Message-ID: <9b8f2470-8fa7-49e6-a687-82339b10d650@googlegroups.com> On Friday, June 15, 2018 at 8:00:36 AM UTC-5, Steven D'Aprano wrote: > Seriously, you are asking strangers to help you out of the goodness of > their heart. Stop lying Steven. Nobody here has a heart. This is Usenet, dammit. From rosuav at gmail.com Fri Jun 15 21:51:40 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jun 2018 11:51:40 +1000 Subject: text mining In-Reply-To: <9b8f2470-8fa7-49e6-a687-82339b10d650@googlegroups.com> References: <61d4bc38-5fc6-4412-aca2-46bba96eae90@googlegroups.com> <9b8f2470-8fa7-49e6-a687-82339b10d650@googlegroups.com> Message-ID: On Sat, Jun 16, 2018 at 11:08 AM, Rick Johnson wrote: > On Friday, June 15, 2018 at 8:00:36 AM UTC-5, Steven D'Aprano wrote: >> Seriously, you are asking strangers to help you out of the goodness of >> their heart. > > Stop lying Steven. > > Nobody here has a heart. > > This is Usenet, dammit. I know what it is to have a complete apparatus for conducting the circulation of blood through the veins and arteries of the human body. But I have not a heart that up and gives me quarter-deck orders that it is life-and-death to disobey. I have not a heart of that description, nor a picture gallery that presumes to take that liberty. ChrisA From rosuav at gmail.com Fri Jun 15 21:54:15 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jun 2018 11:54:15 +1000 Subject: Python list vs google group In-Reply-To: <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> Message-ID: On Sat, Jun 16, 2018 at 11:00 AM, Jim Lee wrote: > > > On 06/15/2018 05:00 PM, Chris Angelico wrote: >> >> On Sat, Jun 16, 2018 at 4:52 AM, Rob Gaddi >> wrote: >>> >>> On 06/15/2018 11:44 AM, Larry Martell wrote: >>>> >>>> My favorite acronym of all time is TWAIN >>>> >>> Really? I always thought it didn't scan. >>> >> Having spent way WAY too many hours trying to turn documents into >> images (and text), I very much appreciate that laugh. >> >> ChrisA > > I once had a Mustek color scanner that came with a TWAIN driver. If the > room temperature was above 80 degrees F, it would scan in color - otherwise, > only black & white. I was *sure* it was a hardware problem, but then > someone released a native Linux driver for the scanner. When I moved the > scanner to my Linux box, it worked fine regardless of temperature. > I would be mind-blown if I did not have the aforementioned too many hours. Sadly, I am merely facepalming. Wow. ChrisA From greg.ewing at canterbury.ac.nz Fri Jun 15 21:54:46 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 16 Jun 2018 13:54:46 +1200 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: Rich Shepard wrote: > Most of us do not reply if we have insufficient knowledge to > offer a usable response. Saves bandwidth and electrons. Also avoids a lot of noise. Imagine if everyone who doesn't know the answer to a question posted "I don't know" as a response. It would drown out all the useful replies! -- Greg From Richard at Damon-Family.org Fri Jun 15 22:08:47 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 15 Jun 2018 22:08:47 -0400 Subject: Python list vs google group In-Reply-To: <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> Message-ID: <24af6f14-09f4-2276-b53b-95dc890c3973@Damon-Family.org> On 6/15/18 9:00 PM, Jim Lee wrote: > > > On 06/15/2018 05:00 PM, Chris Angelico wrote: >> On Sat, Jun 16, 2018 at 4:52 AM, Rob Gaddi >> wrote: >>> On 06/15/2018 11:44 AM, Larry Martell wrote: >>>> My favorite acronym of all time is TWAIN >>>> >>> Really?? I always thought it didn't scan. >>> >> Having spent way WAY too many hours trying to turn documents into >> images (and text), I very much appreciate that laugh. >> >> ChrisA > I once had a Mustek color scanner that came with a TWAIN driver.? If > the room temperature was above 80 degrees F, it would scan in color - > otherwise, only black & white.? I was *sure* it was a hardware > problem, but then someone released a native Linux driver for the > scanner.? When I moved the scanner to my Linux box, it worked fine > regardless of temperature. > > -Jim There actually may still have been a hardware issue, likely something marginal in the timing on the cable. (Timing changing with temperature). It would take a detailed look, and a fine reading of specs, to see if the Windows Driver was to spec, and the hardware is marginal (but the Linux driver didn't push the unit to full speed and got around the issue), of if the Windows driver broke some specification but still sort of worked, especially if things were warm, while the Linux driver did it right. -- Richard Damon From torriem at gmail.com Fri Jun 15 22:36:33 2018 From: torriem at gmail.com (Michael Torrie) Date: Fri, 15 Jun 2018 20:36:33 -0600 Subject: Python list vs google group In-Reply-To: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: On 06/15/2018 09:28 AM, T Berger wrote: > I'm suspecting that posting to python google groups (this site) gets > more responses than mailing to the python list. Am I correct? Also, > contrary to what I read on the python list information sheet, what > shows up in this forum does not match what comes into my inbox. I > started a post here and then replied to a post from my inbox. That > reply does not show up in this forum. Actually it does show up. The problem is that Gmail silently throws away your own post when it gets emailed back to you by the listserv. But your messages still get through to the list. The only way I've figure out to get around this bug in Gmail is to post from a different SMTP server than the normal GMail one. But most people don't have a different SMTP server to use, and also there are issues with DKIM and other supposed anti-spam features. From jlee54 at gmail.com Fri Jun 15 23:07:11 2018 From: jlee54 at gmail.com (Jim Lee) Date: Fri, 15 Jun 2018 20:07:11 -0700 Subject: Python list vs google group In-Reply-To: <24af6f14-09f4-2276-b53b-95dc890c3973@Damon-Family.org> References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> <24af6f14-09f4-2276-b53b-95dc890c3973@Damon-Family.org> Message-ID: <0860cac9-b254-8d0a-94c4-c8c8d47a1012@gmail.com> On 06/15/2018 07:08 PM, Richard Damon wrote: > On 6/15/18 9:00 PM, Jim Lee wrote: >> >> On 06/15/2018 05:00 PM, Chris Angelico wrote: >>> On Sat, Jun 16, 2018 at 4:52 AM, Rob Gaddi >>> wrote: >>>> On 06/15/2018 11:44 AM, Larry Martell wrote: >>>>> My favorite acronym of all time is TWAIN >>>>> >>>> Really?? I always thought it didn't scan. >>>> >>> Having spent way WAY too many hours trying to turn documents into >>> images (and text), I very much appreciate that laugh. >>> >>> ChrisA >> I once had a Mustek color scanner that came with a TWAIN driver.? If >> the room temperature was above 80 degrees F, it would scan in color - >> otherwise, only black & white.? I was *sure* it was a hardware >> problem, but then someone released a native Linux driver for the >> scanner.? When I moved the scanner to my Linux box, it worked fine >> regardless of temperature. >> >> -Jim > There actually may still have been a hardware issue, likely something > marginal in the timing on the cable. (Timing changing with temperature). > It would take a detailed look, and a fine reading of specs, to see if > the Windows Driver was to spec, and the hardware is marginal (but the > Linux driver didn't push the unit to full speed and got around the > issue), of if the Windows driver broke some specification but still sort > of worked, especially if things were warm, while the Linux driver did it > right. > You are exactly right.? It was so long ago that I forgot some of the details, but it boiled down to the TWAIN driver pushing the SCSI bus out of spec.?? I remember looking at the bus on a scope, measuring pulse widths, and playing with terminator values to try to optimize rise times.? I don't believe it used the Windows SCSI driver at all, but instead drove the scanner directly (I could be remembering wrong). -Jim From greg.ewing at canterbury.ac.nz Fri Jun 15 23:52:12 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 16 Jun 2018 15:52:12 +1200 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> <24af6f14-09f4-2276-b53b-95dc890c3973@Damon-Family.org> <0860cac9-b254-8d0a-94c4-c8c8d47a1012@gmail.com> Message-ID: Jim Lee wrote: > It was so long ago that I forgot some of the > details, but it boiled down to the TWAIN driver pushing the SCSI bus out > of spec. Clearly you didn't sacrifice enough goats! https://odetocode.com/blogs/scott/archive/2004/09/22/scsi-is-not-magic.aspx -- Greg From brgrt2 at gmail.com Sat Jun 16 01:31:35 2018 From: brgrt2 at gmail.com (Tamara Berger) Date: Sat, 16 Jun 2018 01:31:35 -0400 Subject: Server warning Message-ID: I created a webapp with flask, but got a warning in terminal when I tested it. Last login: Sat Jun 16 01:13:28 on ttys000 192:~ TamaraB$ cd Desktop/Webapp 192:Webapp TamaraB$ python3 hello_flask.py * Serving Flask app "hello_flask" (lazy loading) * Environment: production WARNING: Do not use the development server in a production environment. Use a production WSGI server instead. * Debug mode: off * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) Is this a serious issue, or can I ignore it? I was just following instructions in a manual I consider trustworthy. Thanks, Tamara From ben+python at benfinney.id.au Sat Jun 16 01:50:24 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 16 Jun 2018 15:50:24 +1000 Subject: Server warning References: Message-ID: <85muvvfffj.fsf@benfinney.id.au> Tamara Berger writes: > Is this a serious issue, or can I ignore it? I was just following > instructions in a manual I consider trustworthy. (A word of advice: You have recently been asking here for many different topics ? Flask, Google Mail, etc. ? that are not the focus of this forum. That's not a problem for us, but you would be better to seek specific help for those topics at their specific support forums. This is not any kind of support forum, it is a discussion forum for the Python community. You're part of that now, so welcome! But this is not a forum for getting support when you're needing help.) The message from Flask is, I believe, both serious *and* you may be able to ignore it. If you are not intending to make the server available on the internet, you are free to ignore it for that case. You should never expose the development server onto the live internet. Use a proper WSGI server (its own topic, with more involved steps) instead. The development server is much easier to start (which is why it's there, and why it is recommended when learning), but much less secure (which is why, before deploying your application, you need to configure a properly secure WSGI server). -- \ ?[F]reedom of speech does not entail freedom to have your ideas | `\ accepted by governments and incorporated into law and policy.? | _o__) ?Russell Blackford, 2010-03-06 | Ben Finney From brgrt2 at gmail.com Sat Jun 16 02:52:37 2018 From: brgrt2 at gmail.com (T Berger) Date: Fri, 15 Jun 2018 23:52:37 -0700 (PDT) Subject: Flask failure In-Reply-To: References: <3fe6b3e1-f582-415b-ace1-b104f42efef9@googlegroups.com> Message-ID: <8afa38b3-1b8a-4e9b-aedb-f4c442513aba@googlegroups.com> On Friday, June 15, 2018 at 1:48:16 PM UTC-4, Elismar Luz wrote: > Address already in use! Hi Elismar, I'm new to Python and didn't understand your post when I first read it. Thanks, Tamara From gheskett at shentel.net Sat Jun 16 04:35:46 2018 From: gheskett at shentel.net (Gene Heskett) Date: Sat, 16 Jun 2018 04:35:46 -0400 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: <201806160435.46723.gheskett@shentel.net> On Friday 15 June 2018 23:52:12 Gregory Ewing wrote: > Jim Lee wrote: > > It was so long ago that I forgot some of the > > details, but it boiled down to the TWAIN driver pushing the SCSI bus > > out of spec. > > Clearly you didn't sacrifice enough goats! > > https://odetocode.com/blogs/scott/archive/2004/09/22/scsi-is-not-magic >.aspx > > -- > Greg This biggest single thing wrong with any of those old scsi interfaces is the bus's 5 volt isolation diode, the designer speced a shotkey(sp) diode, and some damned bean counter saw the price diff and changed it to a std si power diode in the BOM on the way to the production line, thereby destroying the headroom of the logic 1 signal level by lowering the supply voltage to the resistive terms used by nominally .6 volts, the diff in the forward drop. Back when you could run over to the shack and get a shotkey diode, you could make any of them work like a charm. The other choice was to find a higher voltage to run the terms on, 5.75 volts would have been lovely but made of pure unobtainium. But combine the si diode, and a psu fading with age and down to 4.85 volts on the 5 volt line and you were doomed. -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From gandalf at shopzeus.com Sat Jun 16 06:20:34 2018 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Sat, 16 Jun 2018 12:20:34 +0200 Subject: XSD data mapper lib Message-ID: <9a7c8291-1d46-a8e3-85b9-fddd40c57ffc@shopzeus.com> ? Hello! I wonder what kind of XSD <-> Python class mapper should I use for my project. I need something that can generate classes from XSD files, and then parse XML to an objecttree and also dump object trees to XML. I'll be using Python version 3.6 and I would prefer to use something that is based on lxml. I would not like to use anything that has many dependencies (e.g. I don't need to generate django models). I have already tried generateDS but I didn't like it. I have searched for more libraries on pypi and there are too many. It is not possible to order results by number of downloads/popularity, and I do not want to spend my time finding out which ones are well supported and reliable. I know, it is opinion based. But it is better to choose from the best three candidates. Can you please point me to the most popular, well tested libraries that are not likely to be abandoned in the next few years? Thanks, ?? Laszlo From brian.j.oney at googlemail.com Sat Jun 16 09:09:05 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Sat, 16 Jun 2018 15:09:05 +0200 Subject: text mining In-Reply-To: References: <61d4bc38-5fc6-4412-aca2-46bba96eae90@googlegroups.com> Message-ID: <688FC312-D7EB-471D-AA92-CBE6994CBBE3@gmail.com> ?? 15 ??? 2018 ?. 14:57:46 GMT+02:00, Steven D'Aprano ??????: >Seriously, you are asking strangers to help you out of the goodness of >their heart. If your intention was to send the message that you're >lazy, >drunk, or just don't give a damn about the question, you were >successful. Answers like these make me also want ask "questions" like those. Thank you. I hope he's drunk. From steve+comp.lang.python at pearwood.info Sat Jun 16 09:10:21 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 16 Jun 2018 13:10:21 +0000 (UTC) Subject: Scanner freakishness [was Re: Python list vs google group] References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> Message-ID: On Sat, 16 Jun 2018 11:54:15 +1000, Chris Angelico wrote: > On Sat, Jun 16, 2018 at 11:00 AM, Jim Lee wrote: >> I once had a Mustek color scanner that came with a TWAIN driver. If >> the room temperature was above 80 degrees F, it would scan in color - >> otherwise, only black & white. I was *sure* it was a hardware problem, >> but then someone released a native Linux driver for the scanner. When >> I moved the scanner to my Linux box, it worked fine regardless of >> temperature. >> >> > I would be mind-blown if I did not have the aforementioned too many > hours. Sadly, I am merely facepalming. Wow. I'm reminded of the story of the car that would break down whenever the owner bought vanilla ice cream, but not any other flavour. Snopes points out that the story keeps changing (but that's just invariable "Chinese Whispers") and describes it as a legend: https://www.snopes.com/fact-check/cone-of-silence/ Whether or not that specific story is true, the premise is plausible. There's also the story of Magic/More Magic: http://catb.org/jargon/html/magic-story.html I don't have a link, but I recall one story about an old Russian computer that would crash whenever a woman touched it. Apparently the women were wearing nylon stockings that would build up a static charge, and that was crashing the computer. Another example I read about but don't have a link for is a researcher who used a genetic algorithm to design some sort of electrical circuit. Part of the circuit was open (it was only connected at one end), but when the researcher removed the open circuit, the rest of it stopped working. It turned out that there were some subtle static electrical effects caused by the components on the open circuit, and the genetic algorithm found them and incorporated them in the design. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From Richard at Damon-Family.org Sat Jun 16 11:36:28 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 16 Jun 2018 11:36:28 -0400 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> <24af6f14-09f4-2276-b53b-95dc890c3973@Damon-Family.org> <0860cac9-b254-8d0a-94c4-c8c8d47a1012@gmail.com> Message-ID: <08aVC.144476$nT1.118352@fx20.iad> On 6/15/18 11:07 PM, Jim Lee wrote: > > > On 06/15/2018 07:08 PM, Richard Damon wrote: >> On 6/15/18 9:00 PM, Jim Lee wrote: >>> >>> On 06/15/2018 05:00 PM, Chris Angelico wrote: >>>> On Sat, Jun 16, 2018 at 4:52 AM, Rob Gaddi >>>> wrote: >>>>> On 06/15/2018 11:44 AM, Larry Martell wrote: >>>>>> My favorite acronym of all time is TWAIN >>>>>> >>>>> Really?? I always thought it didn't scan. >>>>> >>>> Having spent way WAY too many hours trying to turn documents into >>>> images (and text), I very much appreciate that laugh. >>>> >>>> ChrisA >>> I once had a Mustek color scanner that came with a TWAIN driver.? If >>> the room temperature was above 80 degrees F, it would scan in color - >>> otherwise, only black & white.? I was *sure* it was a hardware >>> problem, but then someone released a native Linux driver for the >>> scanner.? When I moved the scanner to my Linux box, it worked fine >>> regardless of temperature. >>> >>> -Jim >> There actually may still have been a hardware issue, likely something >> marginal in the timing on the cable. (Timing changing with temperature). >> It would take a detailed look, and a fine reading of specs, to see if >> the Windows Driver was to spec, and the hardware is marginal (but the >> Linux driver didn't push the unit to full speed and got around the >> issue), of if the Windows driver broke some specification but still sort >> of worked, especially if things were warm, while the Linux driver did it >> right. >> > You are exactly right.? It was so long ago that I forgot some of the > details, but it boiled down to the TWAIN driver pushing the SCSI bus out > of spec.?? I remember looking at the bus on a scope, measuring pulse > widths, and playing with terminator values to try to optimize rise > times.? I don't believe it used the Windows SCSI driver at all, but > instead drove the scanner directly (I could be remembering wrong). > > -Jim > That sounds like it would probably be classified as a software issue then (or possibly documentation). It could be hardware if the Windows SCSI card didn't support something it was expected to or perhaps indicated that it did, or didn't negotiate correctly. Ultimately, often the difference between a hardware error and a software error is what the documentation says, I have seen more than once a hardware document saying something like Feature A was intended to work this way but the hardware doesn't work right to implement it, so the software needs to do XYZ as a work around. So now, if the software doesn't do XYZ it is a software error, all due to a hardware design issue that was just redefined. From jlee54 at gmail.com Sat Jun 16 12:31:28 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sat, 16 Jun 2018 09:31:28 -0700 Subject: Python list vs google group In-Reply-To: <08aVC.144476$nT1.118352@fx20.iad> References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> <24af6f14-09f4-2276-b53b-95dc890c3973@Damon-Family.org> <0860cac9-b254-8d0a-94c4-c8c8d47a1012@gmail.com> <08aVC.144476$nT1.118352@fx20.iad> Message-ID: <66746563-c767-a899-2862-1d47ee62ddf3@gmail.com> On 06/16/2018 08:36 AM, Richard Damon wrote: > On 6/15/18 11:07 PM, Jim Lee wrote: >>> [snip] >>>> I once had a Mustek color scanner that came with a TWAIN driver.? If >>>> the room temperature was above 80 degrees F, it would scan in color - >>>> otherwise, only black & white.? I was *sure* it was a hardware >>>> problem, but then someone released a native Linux driver for the >>>> scanner.? When I moved the scanner to my Linux box, it worked fine >>>> regardless of temperature. >>>> >>>> -Jim > That sounds like it would probably be classified as a software issue > then (or possibly documentation). It could be hardware if the Windows > SCSI card didn't support something it was expected to or perhaps > indicated that it did, or didn't negotiate correctly. > > Ultimately, often the difference between a hardware error and a software > error is what the documentation says, I have seen more than once a > hardware document saying something like Feature A was intended to work > this way but the hardware doesn't work right to implement it, so the > software needs to do XYZ as a work around. So now, if the software > doesn't do XYZ it is a software error, all due to a hardware design > issue that was just redefined. It was a software issue that manifested itself as a hardware failure.? However, SCSI was such a temperamental beast to begin with that finger pointing usually took as much time as diagnosing the problems. -Jim From ip.bcrs at gmail.com Sat Jun 16 12:38:07 2018 From: ip.bcrs at gmail.com (ip.bcrs at gmail.com) Date: Sat, 16 Jun 2018 09:38:07 -0700 (PDT) Subject: Understanding memory location of Python variables Message-ID: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> Hi everyone, I'm intrigued by the output of the following code, which was totally contrary to my expectations. Can someone tell me what is happening? >>> myName = "Kevin" >>> id(myName) 47406848 >>> id(myName[0]) 36308576 >>> id(myName[1]) 2476000 I expected myName[0] to be located at the same memory location as the myName variable itself. I also expected myName[1] to be located immediately after myName[0]. From ganesh1pal at gmail.com Sat Jun 16 13:10:36 2018 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sat, 16 Jun 2018 22:40:36 +0530 Subject: For specific keys , extract non empty values in a dictionary Message-ID: *How do I check few specific/selected keys in a dictionary and extract their values if they are not empty* *Example : Extract the values for key "one","three","seven" and "nine? if they are not empty* *Input :* *o_num = {'one': 1,* * 'three': 3,* * 'bar': None,* * 'five' : 5,* * 'rum' : None,* * 'seven' : None,* * 'brandy': None,* * 'nine' : 9,* * 'gin': None}* *Output:* *1 3 9* Here is my solution , Please review the below code and let me know your suggestion . #/usr/bin/python o_num = {'one': 1, 'three': 3, 'bar': None, 'five' : 5, 'rum' : None, 'seven' : None, 'brandy': None, 'nine' : 9, 'gin': None} args_list = ["one","three","seven","nine"] args_dict = dict( (k,v) for k, v in o_num.items() if v and k in args_list ) print args_dict o/p: root at X1:/Play_ground/DICT# python hello.py {'nine': 9, 'three': 3, 'one': 1} Also, Is unpacking the elements in the o_num dictionary as shown below fine or are there any other alternatives arg1, arg2, arg3, arg4, = map(args_dict.get, ('one', 'three', 'seven', 'nine')) print arg1, arg2, arg3, arg4 I am a Python 2.7 user and on Linux box Regards, Ganesh From joel.goldstick at gmail.com Sat Jun 16 13:19:04 2018 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 16 Jun 2018 13:19:04 -0400 Subject: Understanding memory location of Python variables In-Reply-To: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> References: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> Message-ID: On Sat, Jun 16, 2018 at 12:38 PM, wrote: > Hi everyone, > > I'm intrigued by the output of the following code, which was totally contrary to my expectations. Can someone tell me what is happening? > >>>> myName = "Kevin" >>>> id(myName) > 47406848 >>>> id(myName[0]) > 36308576 >>>> id(myName[1]) > 2476000 > > I expected myName[0] to be located at the same memory location as the myName variable itself. I also expected myName[1] to be located immediately after myName[0]. > -- > https://mail.python.org/mailman/listinfo/python-list Others can probably give a more complete explanation, but small numbers, and apparently letters are cached since they are so common. -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From python at mrabarnett.plus.com Sat Jun 16 13:35:18 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 16 Jun 2018 18:35:18 +0100 Subject: Understanding memory location of Python variables In-Reply-To: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> References: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> Message-ID: On 2018-06-16 17:38, ip.bcrs at gmail.com wrote: > Hi everyone, > > I'm intrigued by the output of the following code, which was totally contrary to my expectations. Can someone tell me what is happening? > >>>> myName = "Kevin" >>>> id(myName) > 47406848 >>>> id(myName[0]) > 36308576 >>>> id(myName[1]) > 2476000 > > I expected myName[0] to be located at the same memory location as the myName variable itself. I also expected myName[1] to be located immediately after myName[0]. > The 'id' function returns an integer ID for a value/object. The only guarantee is that no 2 values have the same ID at the same time. It is _not_ an address. myName is bound to the string "Kevin", and id(myName) tells you the ID of that string. myName[0] returns the string "K", and id(myName[0]) tells you the ID of that string. (As a side note, The CPython implementation, which is written in C, happens to use the address, but the Jython implementation, which is written in Java, doesn't.) From __peter__ at web.de Sat Jun 16 13:42:34 2018 From: __peter__ at web.de (Peter Otten) Date: Sat, 16 Jun 2018 19:42:34 +0200 Subject: For specific keys , extract non empty values in a dictionary References: Message-ID: Ganesh Pal wrote: > *How do I check few specific/selected keys in a dictionary and extract > their values if they are not empty* You mean not None. > o_num = {'one': 1, > 'three': 3, > 'bar': None, > 'five' : 5, > 'rum' : None, > 'seven' : None, > 'brandy': None, > 'nine' : 9, > 'gin': None} > args_list = ["one","three","seven","nine"] > *Output:* > > *1 3 9* >>> wanted = {"one", "three", "seven", "nine"} >>> {k: o_num[k] for k in wanted & o_num.keys() if o_num[k] is not None} {'one': 1, 'nine': 9, 'three': 3} > I am a Python 2.7 user and on Linux box You have to replace keys() with viewkeys() in Python 2. From gheskett at shentel.net Sat Jun 16 13:57:59 2018 From: gheskett at shentel.net (Gene Heskett) Date: Sat, 16 Jun 2018 13:57:59 -0400 Subject: Python list vs google group In-Reply-To: <66746563-c767-a899-2862-1d47ee62ddf3@gmail.com> References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <08aVC.144476$nT1.118352@fx20.iad> <66746563-c767-a899-2862-1d47ee62ddf3@gmail.com> Message-ID: <201806161357.59574.gheskett@shentel.net> On Saturday 16 June 2018 12:31:28 Jim Lee wrote: > On 06/16/2018 08:36 AM, Richard Damon wrote: > > On 6/15/18 11:07 PM, Jim Lee wrote: > >>> [snip] > >>> > >>>> I once had a Mustek color scanner that came with a TWAIN driver.? > >>>> If the room temperature was above 80 degrees F, it would scan in > >>>> color - otherwise, only black & white.? I was *sure* it was a > >>>> hardware problem, but then someone released a native Linux driver > >>>> for the scanner.? When I moved the scanner to my Linux box, it > >>>> worked fine regardless of temperature. > >>>> > >>>> -Jim > > > > That sounds like it would probably be classified as a software issue > > then (or possibly documentation). It could be hardware if the > > Windows SCSI card didn't support something it was expected to or > > perhaps indicated that it did, or didn't negotiate correctly. > > > > Ultimately, often the difference between a hardware error and a > > software error is what the documentation says, I have seen more than > > once a hardware document saying something like Feature A was > > intended to work this way but the hardware doesn't work right to > > implement it, so the software needs to do XYZ as a work around. So > > now, if the software doesn't do XYZ it is a software error, all due > > to a hardware design issue that was just redefined. > > It was a software issue that manifested itself as a hardware failure.? > However, SCSI was such a temperamental beast to begin with that finger > pointing usually took as much time as diagnosing the problems. > My finger never gets tired of pointing at the bean counter between engineering design and the production floor. And there has been a time or 3 over the last 70 years when the finger was loaded. > -Jim -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From Cecil at decebal.nl Sat Jun 16 14:02:28 2018 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sat, 16 Jun 2018 20:02:28 +0200 Subject: How to get the versions of dependecies Message-ID: <87y3fesj7v.fsf@munus.decebal.nl> If I update prompt-toolkit, I get: ipython 6.4.0 has requirement prompt-toolkit<2.0.0,>=1.0.15, but you'll have prompt-toolkit 2.0.3 which is incompatible. So I should not. At least not at the moment. But how do I get to know which versions of a package are needed? When Using: pip3 -vvv show ipython I just get: Name: ipython Version: 6.4.0 Summary: IPython: Productive Interactive Computing Home-page: https://ipython.org Author: The IPython Development Team Author-email: ipython-dev at python.org License: BSD Location: /usr/local/lib/python3.5/dist-packages Requires: traitlets, decorator, pickleshare, backcall, prompt-toolkit, pexpect, jedi, simplegeneric, setuptools, pygments Required-by: Metadata-Version: 2.0 Installer: pip Classifiers: Framework :: IPython Intended Audience :: Developers Intended Audience :: Science/Research License :: OSI Approved :: BSD License Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only Topic :: System :: Shells Entry-points: [console_scripts] iptest = IPython.testing.iptestcontroller:main iptest3 = IPython.testing.iptestcontroller:main ipython = IPython:start_ipython ipython3 = IPython:start_ipython [pygments.lexers] ipython = IPython.lib.lexers:IPythonLexer ipython3 = IPython.lib.lexers:IPython3Lexer ipythonconsole = IPython.lib.lexers:IPythonConsoleLexer -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From wrw at mac.com Sat Jun 16 14:25:52 2018 From: wrw at mac.com (William Ray Wing) Date: Sat, 16 Jun 2018 14:25:52 -0400 Subject: Scanner freakishness [was Re: Python list vs google group] In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> Message-ID: <775E256F-490D-4F56-854A-20AB258DBDCD@mac.com> > On Jun 16, 2018, at 9:10 AM, Steven D'Aprano wrote: > > On Sat, 16 Jun 2018 11:54:15 +1000, Chris Angelico wrote: > >> On Sat, Jun 16, 2018 at 11:00 AM, Jim Lee wrote: > >>> I once had a Mustek color scanner that came with a TWAIN driver. If >>> the room temperature was above 80 degrees F, it would scan in color - >>> otherwise, only black & white. I was *sure* it was a hardware problem, >>> but then someone released a native Linux driver for the scanner. When >>> I moved the scanner to my Linux box, it worked fine regardless of >>> temperature. >>> >>> >> I would be mind-blown if I did not have the aforementioned too many >> hours. Sadly, I am merely facepalming. Wow. > > Let me add one more story (true) to the list. Concerns an old IBM mainframe installed in a bank in New York City, that crashed rarely, and only night, never during the day. They called IBM; repair man spent the night with it - no crash; same story the next night and the next. Finally on the forth night he left around 10:00 PM to get something to eat and some coffee. Came back to find the computer had crashed. Spent the next night - no crash. Left the next again for coffee, came back to find the computer down. Obviously it was only crashing when he wasn't watching. Next night he left, but only took the elevator down to the ground floor, didn?t go outside. Computer crashed. He rebooted, restarted the job stream, left the computer room for the same length of time, but didn?t leave the floor. No crash. To make a long story short, it was the motor-generator set that ran the elevators. During the day, there was enough constant elevator traffic so that the MG set never shut down and even it it did, there was enough load elsewhere in the building to make the start-up transient a relatively small perturbation. At night it would time out, shut down, and when he called for the elevator late at night, the start-up transient was too much for the computer?s power regulators. Earlier crashes turned out to be coincident with janitorial staff working extra late after special events. Bill > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson > > -- > https://mail.python.org/mailman/listinfo/python-list From email at paulstgeorge.com Sat Jun 16 14:54:50 2018 From: email at paulstgeorge.com (Paul St George) Date: Sat, 16 Jun 2018 19:54:50 +0100 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> Message-ID: <48edf04e-9df6-a4fb-d483-ad7d021acd63@paulstgeorge.com> On 15/06/2018 17:33, T Berger wrote: > On Friday, June 15, 2018 at 12:14:30 PM UTC-4, Mark Lawrence wrote: >> On 15/06/18 16:47, T Berger wrote: >>> On Friday, June 15, 2018 at 11:31:47 AM UTC-4, Alister wrote: >>> >>>> it certainly seems to be the source of most SPAM >>>> as such some users of this list/newsgroup call it what you like block all >>>> posts from google groups >>> >>> But you don't think you get more replies to a question posted here than emailed to the list? The forum and the email list are supposed to be different access routes to the same content, but I don't find that to be the case. I replied to a post via email, but my reply did not show up on this forum. >>> >>> Tamara >>> >> >> For the third and final time, just get a (semi-)decent email client/news >> reader/whatever it's called, point it at news.gmane.org and read this >> forum, hundreds of other python forums and thousands of other technical >> forums with no problems at all. No cluttered inbox so no need to filter >> anything. I happen to use thunderbird, there are umpteen other choices. >> >> -- >> My fellow Pythonistas, ask not what our language can do for you, ask >> what you can do for our language. >> >> Mark Lawrence > Would you also need to know that the Newsgroup is called comp.python.general? I wasted many minutes looking for comp.lang.python. So, in Thunderbird, File > New > Other Accounts... News Server name (NNTP): news.gmane.org Subscribe to: gmane.comp.python.general From sharan.basappa at gmail.com Sat Jun 16 14:59:53 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 16 Jun 2018 11:59:53 -0700 (PDT) Subject: pattern In-Reply-To: References: <20180615034203.GA2722@cskk.homeip.net> Message-ID: Dear Cameron, This is so kind of you. Thanks for spending time to explain the code. It did help a lot. I did go back and brush up lists & dictionaries. At this point, I think, I need to go back and brush up Python from the start. So, I will do that first. On Friday, 15 June 2018 09:12:22 UTC+5:30, Cameron Simpson wrote: > On 14Jun2018 20:01, Sharan Basappa wrote: > >> >Can anyone explain to me the purpose of "pattern" in the line below: > >> > > >> >documents.append((w, pattern['class'])) > >> > > >> >documents is declared as a list as follows: > >> >documents.append((w, pattern['class'])) > >> > >> Not without a lot more context. Where did you find this code? > > > >I am sorry that partial info was not sufficient. > >I am actually trying to implement my first text classification code and I am referring to the below URL for that: > > > >https://machinelearnings.co/text-classification-using-neural-networks-f5cd7b8765c6 > > Ah, ok. It helps to include some cut/paste of the relevant code, though the URL > is a big help. > > The wider context of the code you recite looks like this: > > words = [] > classes = [] > documents = [] > ignore_words = ['?'] > # loop through each sentence in our training data > for pattern in training_data: > # tokenize each word in the sentence > w = nltk.word_tokenize(pattern['sentence']) > # add to our words list > words.extend(w) > # add to documents in our corpus > documents.append((w, pattern['class'])) > > and the training_data is defined like this: > > training_data = [] > training_data.append({"class":"greeting", "sentence":"how are you?"}) > training_data.append({"class":"greeting", "sentence":"how is your day?"}) > ... lots more ... > > So training data is a list of dicts, each dict holding a "class" and "sentence" > key. The "for pattern in training_data" loop iterates over each item of the > training_data. It calls nltk.word_tokenize on the 'sentence" part of the > training item, presumably getting a list of "word" strings. The documents list > gets this tuple: > > (w, pattern['class']) > > added to it. > > In this way the documents list ends up with tuples of (words, classification), > with the words coming from the sentence via nltk and the classification coming > straight from the train item's "class" value. > > So at the end of the loop the documents array will look like: > > documents = [ > ( ['how', 'are', 'you'], 'greeting' ), > ( ['how', 'is', 'your', 'day', 'greeting' ), > ] > > and so forth. > > Cheers, > Cameron Simpson From sharan.basappa at gmail.com Sat Jun 16 15:01:16 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 16 Jun 2018 12:01:16 -0700 (PDT) Subject: syntax difference Message-ID: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> Is there a difference between these prints. The first one looks a bit complex. So, why should it be used? my_age = 35 # not a lie print "my age %s." % my_age print "my age ", my_age Output: %run "D:/Projects/Initiatives/machine learning/programs/five.py" my age 35. my age 35 From alister.ware at ntlworld.com Sat Jun 16 15:11:20 2018 From: alister.ware at ntlworld.com (Alister) Date: Sat, 16 Jun 2018 19:11:20 GMT Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> Message-ID: On Sat, 16 Jun 2018 12:01:16 -0700, Sharan Basappa wrote: > Is there a difference between these prints. The first one looks a bit > complex. So, why should it be used? > > my_age = 35 # not a lie > > print "my age %s." % my_age print "my age ", my_age > > Output: > %run "D:/Projects/Initiatives/machine learning/programs/five.py" > my age 35. > my age 35 in that example probably no difference - readability counts. but if you want to display a slightly different message then you could the following print "may age is %s years",% my_age which is arguably nicer than print "my age is", print my_age, print "Years" & less error prone you can of course expand this format with multiple insertions & even explicit formatting for specific data types. -- It got to the point where I had to get a haircut or both feet firmly planted in the air. From alister.ware at ntlworld.com Sat Jun 16 15:16:37 2018 From: alister.ware at ntlworld.com (Alister) Date: Sat, 16 Jun 2018 19:16:37 GMT Subject: Understanding memory location of Python variables References: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> Message-ID: On Sat, 16 Jun 2018 13:19:04 -0400, Joel Goldstick wrote: > On Sat, Jun 16, 2018 at 12:38 PM, wrote: >> Hi everyone, >> >> I'm intrigued by the output of the following code, which was totally >> contrary to my expectations. Can someone tell me what is happening? >> >>>>> myName = "Kevin" >>>>> id(myName) >> 47406848 >>>>> id(myName[0]) >> 36308576 >>>>> id(myName[1]) >> 2476000 >> >> I expected myName[0] to be located at the same memory location as the >> myName variable itself. I also expected myName[1] to be located >> immediately after myName[0]. >> -- >> https://mail.python.org/mailman/listinfo/python-list > > Others can probably give a more complete explanation, but small numbers, > and apparently letters are cached since they are so common. also ID is not necessarily a memory location (at least not according to the language specification) the standard cpython implementation does user the memory location for an object's ID but this is an implementation detail if you are tying to make use of ID in any way to manipulate computer memory your program is fundamentaly broken -- Can you MAIL a BEAN CAKE? From alister.ware at ntlworld.com Sat Jun 16 15:21:17 2018 From: alister.ware at ntlworld.com (Alister) Date: Sat, 16 Jun 2018 19:21:17 GMT Subject: Python list vs google group References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <475b4138-1e01-4c0a-b7cf-5262a8872d8b@googlegroups.com> Message-ID: On Fri, 15 Jun 2018 09:32:05 -0700, T Berger wrote: > On Friday, June 15, 2018 at 11:55:59 AM UTC-4, Chris Angelico wrote: >> Perhaps quantity is not the important thing here. > > It is the important thing. I'm stuck with a problem and still waiting > for replies to my email. I've decided to repost my problem here, so > we'll see whether my hypothesis holds water. > > Tamara i still beg to differ & agree with Chris. quality is what counts which would you prefer 100 wrong/contradictory answers or one correct one* * i accept that even here for any moderately complex question you are still likely to get contradictory answers -- Iron Law of Distribution: Them that has, gets. From rantingrickjohnson at gmail.com Sat Jun 16 15:38:23 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 16 Jun 2018 12:38:23 -0700 (PDT) Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> <24af6f14-09f4-2276-b53b-95dc890c3973@Damon-Family.org> Message-ID: <1082af26-0486-4bee-acbf-587f5af9ebcd@googlegroups.com> On Friday, June 15, 2018 at 9:14:13 PM UTC-5, Richard Damon wrote: > if the Windows driver broke some specification but still sort > of worked [...] ...that's when the engineers in the Redmond, WA area know it's time to package and ship the product! From alister.ware at ntlworld.com Sat Jun 16 15:55:16 2018 From: alister.ware at ntlworld.com (Alister) Date: Sat, 16 Jun 2018 19:55:16 GMT Subject: Scanner freakishness [was Re: Python list vs google group] References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> <775E256F-490D-4F56-854A-20AB258DBDCD@mac.com> Message-ID: On Sat, 16 Jun 2018 14:25:52 -0400, William Ray Wing wrote: >> On Jun 16, 2018, at 9:10 AM, Steven D'Aprano >> wrote: >> >> On Sat, 16 Jun 2018 11:54:15 +1000, Chris Angelico wrote: >> >>> On Sat, Jun 16, 2018 at 11:00 AM, Jim Lee wrote: >> >>>> I once had a Mustek color scanner that came with a TWAIN driver. If >>>> the room temperature was above 80 degrees F, it would scan in color - >>>> otherwise, only black & white. I was *sure* it was a hardware >>>> problem, >>>> but then someone released a native Linux driver for the scanner. >>>> When I moved the scanner to my Linux box, it worked fine regardless >>>> of temperature. >>>> >>>> >>> I would be mind-blown if I did not have the aforementioned too many >>> hours. Sadly, I am merely facepalming. Wow. >> >> >> > Let me add one more story (true) to the list. Concerns an old IBM > mainframe installed in a bank in New York City, that crashed rarely, and > only night, never during the day. They called IBM; repair man spent the > night with it - no crash; same story the next night and the next. > Finally on the forth night he left around 10:00 PM to get something to > eat and some coffee. Came back to find the computer had crashed. Spent > the next night - no crash. Left the next again for coffee, came back to > find the computer down. Obviously it was only crashing when he wasn't > watching. Next night he left, but only took the elevator down to the > ground floor, didn?t go outside. Computer crashed. He rebooted, > restarted the job stream, left the computer room for the same length of > time, but didn?t leave the floor. No crash. > > To make a long story short, it was the motor-generator set that ran the > elevators. During the day, there was enough constant elevator traffic > so that the MG set never shut down and even it it did, there was enough > load elsewhere in the building to make the start-up transient a > relatively small perturbation. At night it would time out, shut down, > and when he called for the elevator late at night, the start-up > transient was too much for the computer?s power regulators. > > Earlier crashes turned out to be coincident with janitorial staff > working extra late after special events. > > Bill > My supervisor had a similar issue with a PBX (Telephone system) that would cut of callers when the lift was used. I personally one attended a site to try to identify why an ISDN circuit kept randomly resetting. I had been on the phone with the BT engineer for about 1/2 hr monitoring the circuit when it suddenly cut off. "Was it anything I did" asked the person using the photo copier A few quick tests later confirmed that whenever the photocopier made multiple copies (approx 10+) the circuit would reset Cust advised to relocate photocopier, case closed :-) or if you want a really strange one we used to maintain PBX's for a particular Bank. A common fault report was the earpiece buzzing. This turned out to be caused by blown halogen light bulbs in a nearby display board (i don't know who originally identified that one). working on the help desk it was always "fun" trying to convince the user that this was the problem, understandably they though we were pulling their leg" > > >> -- >> Steven D'Aprano "Ever since I learned about confirmation bias, I've >> been seeing it everywhere." -- Jon Ronson >> >> -- >> https://mail.python.org/mailman/listinfo/python-list -- It's later than you think. From jlee54 at gmail.com Sat Jun 16 16:13:23 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sat, 16 Jun 2018 13:13:23 -0700 Subject: Python list vs google group In-Reply-To: <1082af26-0486-4bee-acbf-587f5af9ebcd@googlegroups.com> References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> <24af6f14-09f4-2276-b53b-95dc890c3973@Damon-Family.org> <1082af26-0486-4bee-acbf-587f5af9ebcd@googlegroups.com> Message-ID: <1c2fd6a4-81e3-0739-f6d9-fb3332d8d533@gmail.com> On 06/16/2018 12:38 PM, Rick Johnson wrote: > On Friday, June 15, 2018 at 9:14:13 PM UTC-5, Richard Damon wrote: >> if the Windows driver broke some specification but still sort >> of worked [...] > ...that's when the engineers in the Redmond, WA area know it's time to package and ship the product! And in so doing, produce an exponential growth in wasted money and time worldwide as countless people struggle to do things that "sort of work". -Jim From jerblack at gmail.com Sat Jun 16 17:50:50 2018 From: jerblack at gmail.com (Jeremy Black) Date: Sat, 16 Jun 2018 14:50:50 -0700 Subject: Understanding memory location of Python variables In-Reply-To: References: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> Message-ID: Also, I don't think you can rely on memory being allocated sequentially any more now that everyone has implemented some level of ASLR. https://en.wikipedia.org/wiki/Address_space_layout_randomization On Sat, Jun 16, 2018 at 12:22 PM Alister via Python-list < python-list at python.org> wrote: > On Sat, 16 Jun 2018 13:19:04 -0400, Joel Goldstick wrote: > > > On Sat, Jun 16, 2018 at 12:38 PM, wrote: > >> Hi everyone, > >> > >> I'm intrigued by the output of the following code, which was totally > >> contrary to my expectations. Can someone tell me what is happening? > >> > >>>>> myName = "Kevin" > >>>>> id(myName) > >> 47406848 > >>>>> id(myName[0]) > >> 36308576 > >>>>> id(myName[1]) > >> 2476000 > >> > >> I expected myName[0] to be located at the same memory location as the > >> myName variable itself. I also expected myName[1] to be located > >> immediately after myName[0]. > >> -- > >> https://mail.python.org/mailman/listinfo/python-list > > > > Others can probably give a more complete explanation, but small numbers, > > and apparently letters are cached since they are so common. > > also ID is not necessarily a memory location (at least not according to > the language specification) > the standard cpython implementation does user the memory location for an > object's ID but this is an implementation detail > > if you are tying to make use of ID in any way to manipulate computer > memory your program is fundamentaly broken > > > > -- > Can you MAIL a BEAN CAKE? > -- > https://mail.python.org/mailman/listinfo/python-list > From cs at cskk.id.au Sat Jun 16 18:33:33 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 17 Jun 2018 08:33:33 +1000 Subject: pattern In-Reply-To: References: Message-ID: <20180616223333.GA81696@cskk.homeip.net> On 16Jun2018 11:59, Sharan Basappa wrote: >This is so kind of you. Thanks for spending time to explain the code. >It did help a lot. I did go back and brush up lists & dictionaries. > >At this point, I think, I need to go back and brush up Python from the start. >So, I will do that first. Sure, sounds good. But write code! It is not enough to read code and read about code. You need to write code and modify code. Otherwise the skills don't internalise well. If you're running the code you asked about, one way to learn a lot about something that looks obscrure is simply to put in print() calls at various places, eg: print("iterate over traing_data =", repr(training_data)) for pattern in training_data: # tokenize each word in the sentence print("pattern =", repr(pattern)) w = nltk.word_tokenize(pattern['sentence']) print("w =", repr(w)) # add to our words list words.extend(w) print("words =", repr(words)) # add to documents in our corpus documents.append((w, pattern['class'])) print("documents =", repr(documents)) Note the use of repr(): it will print out the structure of lists and so forth, very useful. Just reviewing that loop, the logic does look a little weird to me. I think the "documents.append" should be inside the loop because otherwise it only accrues the _last_ "w" and "pattern". Cheers, Cameron Simpson From cs at cskk.id.au Sat Jun 16 18:55:35 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 17 Jun 2018 08:55:35 +1000 Subject: syntax difference In-Reply-To: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> Message-ID: <20180616225535.GA37027@cskk.homeip.net> On 16Jun2018 12:01, Sharan Basappa wrote: >Is there a difference between these prints. The first one looks a bit complex. So, why should it be used? > >my_age = 35 # not a lie > >print "my age %s." % my_age >print "my age ", my_age > >Output: >%run "D:/Projects/Initiatives/machine learning/programs/five.py" >my age 35. >my age 35 In case nobody else notices, the reason the second one has 2 spaces before "35" is that print puts a space between items. So you have a space from the "my age " and also a space from the item separation. The first print statement is only printing one item. Regarding which style to use: the latter is better because it is more readable. The former can be better when constructing a string with several values where you want more control and better readablility _for the message as a whole_. Consider: # variables, just to make the examples work # in a real programme perhaps these came from # some more complex earlier stuff name = "Sharon" age = 35 print "The person named %r is %d years old." % (name, age) versus: name = "Sharon" age = 35 print "The person named", repr(name), "is", age, "years old." I'd be inclined to prefer the former one because I can see the shape of the message. Also, I notice you're using Python 2 (from the print syntax). In Python 3 we have "format strings", which let you write: name = "Sharon" age = 35 print(f"The person named {name|r} is {age} years old.") Win win! Cheers, Cameron Simpson From steve+comp.lang.python at pearwood.info Sat Jun 16 19:34:22 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 16 Jun 2018 23:34:22 +0000 (UTC) Subject: Understanding memory location of Python variables References: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> Message-ID: On Sat, 16 Jun 2018 09:38:07 -0700, ip.bcrs wrote: > Hi everyone, > > I'm intrigued by the output of the following code, which was totally > contrary to my expectations. Can someone tell me what is happening? > >>>> myName = "Kevin" >>>> id(myName) > 47406848 >>>> id(myName[0]) > 36308576 >>>> id(myName[1]) > 2476000 > > I expected myName[0] to be located at the same memory location as the > myName variable itself. Nothing in the above example tells you anything about memory locations (except by accident). The id() function does not return a memory address (except by accident). It returns an opaque integer ID code, that is all. If you try that on another Python interpreter, such as Jython or IronPython, you will see something like this: >>> sys.executable '/usr/bin/jython' >>> myName = "Kevin" >>> id(myName) 3 >>> id(myName[1]) 4 >>> id(myName[0]) 5 Notice that IDs are allocated sequentially, in the order you ask for them. > I also expected myName[1] to be located immediately after myName[0]. Why? Even if id() happens to return a memory address, the details of where Python allocates a new object is unpredictable. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sat Jun 16 19:45:22 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jun 2018 09:45:22 +1000 Subject: Understanding memory location of Python variables In-Reply-To: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> References: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> Message-ID: On Sun, Jun 17, 2018 at 2:38 AM, wrote: > Hi everyone, > > I'm intrigued by the output of the following code, which was totally contrary to my expectations. Can someone tell me what is happening? > >>>> myName = "Kevin" >>>> id(myName) > 47406848 >>>> id(myName[0]) > 36308576 >>>> id(myName[1]) > 2476000 > > I expected myName[0] to be located at the same memory location as the myName variable itself. I also expected myName[1] to be located immediately after myName[0]. > A string or array in C is allocated in contiguous memory. Python, however, is not C. What you're looking at is the identities of objects, not the memory locations of bytes. Everything you're assuming about C should be discarded. ChrisA From greg.ewing at canterbury.ac.nz Sat Jun 16 20:58:00 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 17 Jun 2018 12:58:00 +1200 Subject: Scanner freakishness [was Re: Python list vs google group] In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> <775E256F-490D-4F56-854A-20AB258DBDCD@mac.com> Message-ID: Alister wrote: > A few quick tests later confirmed that whenever the photocopier made > multiple copies (approx 10+) the circuit would reset > > Cust advised to relocate photocopier, case closed :-) I was expecting the solution to be a note attached to the photocopier saying "Please do not make more than 9 copies at a time". -- Greg From rosuav at gmail.com Sat Jun 16 21:09:26 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jun 2018 11:09:26 +1000 Subject: Scanner freakishness [was Re: Python list vs google group] In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <67aadf39-b3f6-cd00-dd90-60bce9a4dabb@gmail.com> <775E256F-490D-4F56-854A-20AB258DBDCD@mac.com> Message-ID: On Sun, Jun 17, 2018 at 10:58 AM, Gregory Ewing wrote: > Alister wrote: >> >> A few quick tests later confirmed that whenever the photocopier made >> multiple copies (approx 10+) the circuit would reset >> Cust advised to relocate photocopier, case closed :-) > > > I was expecting the solution to be a note attached to the > photocopier saying "Please do not make more than 9 copies > at a time". https://xkcd.com/1457/ XKCD is not a work of fiction. It is, at best, a slight exaggeration of reality. My Dad used to reboot his computer before burning a DVD, because it seemed to create less failed burns. No explanation was ever found. (He doesn't make DVD backups any more, so the issue has been dodged.) ChrisA From ben.usenet at bsb.me.uk Sat Jun 16 21:55:44 2018 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Sun, 17 Jun 2018 02:55:44 +0100 Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> Message-ID: <87602ib2hr.fsf@bsb.me.uk> Cameron Simpson writes: > ... In Python 3 we have "format strings", which let you write: > > name = "Sharon" > age = 35 > print(f"The person named {name|r} is {age} years old.") You meant {name!r} I think there. -- Ben. From daniel.montecillo at montecillo.ca Sat Jun 16 22:20:05 2018 From: daniel.montecillo at montecillo.ca (Daniel Montecillo) Date: Sun, 17 Jun 2018 02:20:05 +0000 Subject: Understanding memory location of Python variables In-Reply-To: References: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> Message-ID: I am also wondering about this behavior. Thank you Chris A for providing the explanation. On Jun 16, 2018, at 5:45 PM, Chris Angelico > wrote: On Sun, Jun 17, 2018 at 2:38 AM, > wrote: Hi everyone, I'm intrigued by the output of the following code, which was totally contrary to my expectations. Can someone tell me what is happening? myName = "Kevin" id(myName) 47406848 id(myName[0]) 36308576 id(myName[1]) 2476000 I expected myName[0] to be located at the same memory location as the myName variable itself. I also expected myName[1] to be located immediately after myName[0]. A string or array in C is allocated in contiguous memory. Python, however, is not C. What you're looking at is the identities of objects, not the memory locations of bytes. Everything you're assuming about C should be discarded. ChrisA -- https://mail.python.org/mailman/listinfo/python-list From grant.b.edwards at gmail.com Sat Jun 16 22:28:05 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 17 Jun 2018 02:28:05 +0000 (UTC) Subject: Understanding memory location of Python variables References: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> Message-ID: On 2018-06-16, ip.bcrs at gmail.com wrote: > I'm intrigued by the output of the following code, which was totally > contrary to my expectations. Can someone tell me what is happening? > >>>> myName = "Kevin" >>>> id(myName) > 47406848 >>>> id(myName[0]) > 36308576 >>>> id(myName[1]) > 2476000 What's happening is that you're paying attention to the values returned by id(), when you should not. The fact that CPython returns a VM address when you call id() is just an "accident" of that particular implimentation. You shouldn't assume that id() returns anything other than a number that is unique to each object. Any time you spend worrying about how that number is calculated is proably wasted. > I expected myName[0] to be located at the same memory location as the myName variable itself. Python is not C. > I also expected myName[1] to be located immediately after myName[0]. Python is not C. Just in case you missed that... Python is not C. -- Grant From sharan.basappa at gmail.com Sun Jun 17 01:13:59 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 16 Jun 2018 22:13:59 -0700 (PDT) Subject: syntax difference In-Reply-To: <87602ib2hr.fsf@bsb.me.uk> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> Message-ID: <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> On Sunday, 17 June 2018 07:25:57 UTC+5:30, Ben Bacarisse wrote: > Cameron Simpson writes: > > > ... In Python 3 we have "format strings", which let you write: > > > > name = "Sharon" > > age = 35 > > print(f"The person named {name|r} is {age} years old.") > > You meant {name!r} I think there. > > -- > Ben. thanks, everyone. I think I am now confused with format options in Python. I tried an example as below and both print proper value: age = 35 print "age is %s" % age print "age is %d" % age %run "D:/Projects/Initiatives/machine learning/programs/six.py" age is 35 age is 35 I other languages I know the format specifier should be same as the variable type. For example, in the above case, it has to be %d and not %s From ben+python at benfinney.id.au Sun Jun 17 01:30:24 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 17 Jun 2018 15:30:24 +1000 Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> Message-ID: <85fu1mf09b.fsf@benfinney.id.au> Sharan Basappa writes: > I think I am now confused with format options in Python. You should refer to the documentation for string formatting (or, if you want to continue with the older less-flexible style, ) > I tried an example as below and both print proper value: > > age = 35 > > print "age is %s" % age The ?s? format specifier says ?Ask the object for its text representation, and put that text here?. Every object has a text representation, so ?s? works with any object. > print "age is %d" % age The ?d? format specifier says ?Format the integer as a decimal text representation, and put that text here?. Only objects that are integers (or that implement the format-as-decimal API) will work with ?d?. > I other languages I know the format specifier should be same as the > variable type. For example, in the above case, it has to be %d and not > %s Because you are explicitly specifying which formatting to use, there's no ambiguity. With an object that is an integer, either of the above makes sense in different use cases. -- \ ?A right is not what someone gives you; it's what no one can | `\ take from you.? ?Ramsey Clark | _o__) | Ben Finney From rosuav at gmail.com Sun Jun 17 01:35:34 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jun 2018 15:35:34 +1000 Subject: syntax difference In-Reply-To: <85fu1mf09b.fsf@benfinney.id.au> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <85fu1mf09b.fsf@benfinney.id.au> Message-ID: On Sun, Jun 17, 2018 at 3:30 PM, Ben Finney wrote: > Sharan Basappa writes: > >> I think I am now confused with format options in Python. > > You should refer to the documentation for string formatting > > > > (or, if you want to continue with the older less-flexible style, > ) For the record, there's nothing at all wrong with printf-style formatting; its flexibility and brevity make it extremely useful in many situations. ChrisA From ben+python at benfinney.id.au Sun Jun 17 01:56:23 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 17 Jun 2018 15:56:23 +1000 Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <85fu1mf09b.fsf@benfinney.id.au> Message-ID: <85bmcaez20.fsf@benfinney.id.au> Chris Angelico writes: > On Sun, Jun 17, 2018 at 3:30 PM, Ben Finney wrote: > > (or, if you want to continue with the older less-flexible style, (I gave an unhelpful URL for that documentation. Try this instead .) > For the record, there's nothing at all wrong with printf-style > formatting; its flexibility and brevity make it extremely useful in > many situations. That isn't the impression I get from the above documentation. It starts with a clearly worded warning: Note The formatting operations described here exhibit a variety of quirks that lead to a number of common errors (such as failing to display tuples and dictionaries correctly). Using the newer formatted string literals or the str.format() interface helps avoid these errors. These alternatives also provide more powerful, flexible and extensible approaches to formatting text. That states a clear opinion that ?str.format? is preferred. -- \ ?True greatness is measured by how much freedom you give to | `\ others, not by how much you can coerce others to do what you | _o__) want.? ?Larry Wall | Ben Finney From jlee54 at gmail.com Sun Jun 17 02:11:41 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sat, 16 Jun 2018 23:11:41 -0700 Subject: syntax difference In-Reply-To: <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> Message-ID: <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> On 06/16/2018 10:13 PM, Sharan Basappa wrote: > I think I am now confused with format options in Python. > I tried an example as below and both print proper value: > > age = 35 > > print "age is %s" % age > print "age is %d" % age > > %run "D:/Projects/Initiatives/machine learning/programs/six.py" > age is 35 > age is 35 > > I other languages I know the format specifier should be same as the variable type. For example, in the above case, it has to be %d and not %s ? Python is not like other languages.? For one thing, there are no "variables" in Python (in the way you think of them).?? There are only objects and names.? Names can be thought of like void pointers in C, for example.? They don't have a "type" themselves - they only refer to objects, and the type of object they refer to can change at will.? Also, there are no integers in Python.? Scalar values are actually objects.? The number 35 is not an integer, it is an object that has an integer type.? If you do a "dir(35)" in Python, you'll see that the object "35" has more than 70 methods associated with it.?? I'll stop there to avoid information overload, but these are some of the key things a Python newcomer needs to wrap their head around.... -Jim From rosuav at gmail.com Sun Jun 17 02:32:25 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jun 2018 16:32:25 +1000 Subject: syntax difference In-Reply-To: <85bmcaez20.fsf@benfinney.id.au> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <85fu1mf09b.fsf@benfinney.id.au> <85bmcaez20.fsf@benfinney.id.au> Message-ID: On Sun, Jun 17, 2018 at 3:56 PM, Ben Finney wrote: > Chris Angelico writes: > >> On Sun, Jun 17, 2018 at 3:30 PM, Ben Finney wrote: >> > (or, if you want to continue with the older less-flexible style, > > (I gave an unhelpful URL for that documentation. Try this instead > .) > >> For the record, there's nothing at all wrong with printf-style >> formatting; its flexibility and brevity make it extremely useful in >> many situations. > > That isn't the impression I get from the above documentation. It starts > with a clearly worded warning: > > Note > > The formatting operations described here exhibit a variety of quirks > that lead to a number of common errors (such as failing to display > tuples and dictionaries correctly). Using the newer formatted string > literals or the str.format() interface helps avoid these errors. > These alternatives also provide more powerful, flexible and > extensible approaches to formatting text. > > That states a clear opinion that ?str.format? is preferred. And yet we have had a firm statement that percent-formatting is not going to be deprecated. Which is a clear statement that there's nothing wrong with it. The only problem I'm aware of with tuples and dicts is that a single parameter is misinterpreted, which is a minor nit caused by the operator syntax; the format mini-language itself is not affected by this. For instance, you can dodge the single-argument problem thus: >>> def sprintf(fmt, *args): ... return fmt % args ... >>> sprintf("%s", (1, 2, 3)) '(1, 2, 3)' Also: I would call that a "note", not a "warning". Please stop spreading the FUD that there's somehow something "wrong" with using what is a well-known convention for a format mini-language. ChrisA From jfong at ms4.hinet.net Sun Jun 17 03:08:27 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Sun, 17 Jun 2018 15:08:27 +0800 Subject: Why an object changes its "address" between adjacent calls? Message-ID: <445dbeb0-7851-f572-250d-e3654297b663@ms4.hinet.net> C:\Python34\Doc>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. >>> import tkinter as tk >>> root = tk.Tk() >>> tk.Label(root, text='label one', font='TkDefaultFont').pack() >>> from tkinter import font >>> font.nametofont('TkDefaultFont') >>> font.nametofont('TkDefaultFont') >>> The "address" of the Font object 'TkDefaultFont' changes, why? Best Regards, Jach Fong --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From ben+python at benfinney.id.au Sun Jun 17 03:30:30 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 17 Jun 2018 17:30:30 +1000 Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <85fu1mf09b.fsf@benfinney.id.au> <85bmcaez20.fsf@benfinney.id.au> Message-ID: <857emxg99l.fsf@benfinney.id.au> Chris Angelico writes: > Also: I would call that a "note", not a "warning". Please stop > spreading the FUD that there's somehow something "wrong" with using > what is a well-known convention for a format mini-language. If I say there's something ?wrong? with it (is that different from saying there's something wrong with it? I am not sure the function of the quotes you use there), I'm not aware. I haven't stated the printf-style formatting is especially prone to official deprecation. As for a clear *preference*, as presented in the Python documentation, for ?str.format? rather than printf-style, I'll continue to spread that implication which seems a pretty uncontroversial reading of the Python documentation. -- \ ?Beware of bugs in the above code; I have only proved it | `\ correct, not tried it.? ?Donald Knuth, 1977-03-29 | _o__) | Ben Finney From jlee54 at gmail.com Sun Jun 17 04:10:26 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 17 Jun 2018 01:10:26 -0700 Subject: Why an object changes its "address" between adjacent calls? In-Reply-To: <445dbeb0-7851-f572-250d-e3654297b663@ms4.hinet.net> References: <445dbeb0-7851-f572-250d-e3654297b663@ms4.hinet.net> Message-ID: <51892e91-785f-e244-f69f-ebdd394b7403@gmail.com> On 06/17/2018 12:08 AM, Jach Fong wrote: > C:\Python34\Doc>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. > >>> import tkinter as tk > >>> root = tk.Tk() > >>> tk.Label(root, text='label one', font='TkDefaultFont').pack() > >>> from tkinter import font > >>> font.nametofont('TkDefaultFont') > > >>> font.nametofont('TkDefaultFont') > > >>> > > The "address" of the Font object 'TkDefaultFont' changes, why? > > Best Regards, > Jach Fong > > def nametofont(name): ??? """Given the name of a tk named font, returns a Font representation. ??? """ ??? return Font(name=name, exists=True) Every time you call nametofont(), you're creating a new instance of the Font class. -Jim From steve+comp.lang.python at pearwood.info Sun Jun 17 04:19:45 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 17 Jun 2018 08:19:45 +0000 (UTC) Subject: Why an object changes its "address" between adjacent calls? References: <445dbeb0-7851-f572-250d-e3654297b663@ms4.hinet.net> Message-ID: On Sun, 17 Jun 2018 15:08:27 +0800, Jach Fong wrote: > The "address" of the Font object 'TkDefaultFont' changes, why? Its not an address, it is an ID number. The ID number changes because you get a different object each time you call the function. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sun Jun 17 04:43:42 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 17 Jun 2018 08:43:42 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> Message-ID: On Sat, 16 Jun 2018 23:11:41 -0700, Jim Lee wrote: > ? Python is not like other languages. Python is not like languages like C, Pascal, Algol, Fortran, D, Java (unboxed native values only) and those like that. However, Python *is* like other languages like Javascript, Ruby, Java (objects only), PHP, and others. > For one thing, there are no > "variables" in Python (in the way you think of them). Indeed -- there are no variables in Python, if you think of a variable as meaning a virtual box at a fixed memory address, containing a value, and associated with a type, like in C or Pascal. > There are only > objects and names.? Names can be thought of like void pointers in C, for > example.? They don't have a "type" themselves - they only refer to > objects, and the type of object they refer to can change at will. Very true. > Also, there are no integers in Python.? Scalar values are actually > objects. The number 35 is not an integer, it is an object that has an > integer type. I would put it another way. Python certainly has integers, but there are no integers in C, there are only fixed-width collections of one or more bytes. They don't have any integer methods, or methods at all. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sun Jun 17 05:09:25 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 17 Jun 2018 09:09:25 +0000 (UTC) Subject: Metasyntactic thingies Message-ID: We know the placeholder names used for generic variables: foo bar baz foobar ... and the Pythonic equivalents: spam eggs cheese aardvark ... But what placeholder names do you use for functions, methods or other actions? As in, placeholder verbs rather than nouns? Aside from such boring ones as "do_work" and similar, the only placeholder verb I can think of is frobnicate. Does anyone else have any? "Why do you keep saying wossname?" said Rincewind. "Limited wossname. Doodah. Thingy. You know, it's got words in it," said the parrot. "Dictionary?" said Rincewind. -- Terry Pratchett, "Eric" -- Steven D'Aprano From steve+comp.lang.python at pearwood.info Sun Jun 17 05:19:49 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 17 Jun 2018 09:19:49 +0000 (UTC) Subject: Does inspect.getstack work on other Python implementations? Message-ID: Anyone here use IronPython, Jython or PyPy? Does inspect.getstack always work? Is it considered an implementation detail for CPython or something promised to work on any compliant Python interpreter? I see that it doesn't even exist on Jython 2.5, does anyone know whether it exists in later versions? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From e+python-list at kellett.im Sun Jun 17 05:26:05 2018 From: e+python-list at kellett.im (Ed Kellett) Date: Sun, 17 Jun 2018 10:26:05 +0100 Subject: Does inspect.getstack work on other Python implementations? In-Reply-To: References: Message-ID: On 2018-06-17 10:19, Steven D'Aprano wrote: > Anyone here use IronPython, Jython or PyPy? > > Does inspect.getstack always work? Is it considered an implementation > detail for CPython or something promised to work on any compliant > Python interpreter? > > I see that it doesn't even exist on Jython 2.5, does anyone know > whether it exists in later versions? Well, inspect.currentframe says: > CPython implementation detail: This function relies on Python stack > frame support in the interpreter, which isn?t guaranteed to exist in > all implementations of Python. If running in an implementation > without Python stack frame support this function returns None. and presumably if stack frame support isn't guaranteed to exist for one inspect function it's similarly un-guaranteed in others. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From sales at caprilion.com.tw Sun Jun 17 05:39:42 2018 From: sales at caprilion.com.tw (sales at caprilion.com.tw) Date: Sun, 17 Jun 2018 17:39:42 +0800 Subject: Why an object changes its "address" between adjacent calls? In-Reply-To: <51892e91-785f-e244-f69f-ebdd394b7403@gmail.com> References: <445dbeb0-7851-f572-250d-e3654297b663@ms4.hinet.net> <51892e91-785f-e244-f69f-ebdd394b7403@gmail.com> Message-ID: <4a4d768b-eedc-d6b6-7584-d185833f95d1@caprilion.com.tw> Jim Lee at 2018/6/17 PM 04:10 wrote: > > > On 06/17/2018 12:08 AM, Jach Fong wrote: >> C:\Python34\Doc>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. >> >>> import tkinter as tk >> >>> root = tk.Tk() >> >>> tk.Label(root, text='label one', font='TkDefaultFont').pack() >> >>> from tkinter import font >> >>> font.nametofont('TkDefaultFont') >> >> >>> font.nametofont('TkDefaultFont') >> >> >>> >> >> The "address" of the Font object 'TkDefaultFont' changes, why? >> >> Best Regards, >> Jach Fong >> >> > > def nametofont(name): > ??? """Given the name of a tk named font, returns a Font representation. > ??? """ > ??? return Font(name=name, exists=True) > > Every time you call nametofont(), you're creating a new instance of the > Font class. hmm... It means every time I set a widget's font to "TkDefaultFont", a new object was created. Why python do things this way? Can't it use this same object again and again? --Jach --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From jfong at ms4.hinet.net Sun Jun 17 05:40:03 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Sun, 17 Jun 2018 17:40:03 +0800 Subject: Why an object changes its "address" between adjacent calls? In-Reply-To: References: <445dbeb0-7851-f572-250d-e3654297b663@ms4.hinet.net> Message-ID: <913028a9-0705-9404-d040-525517dfcf2c@ms4.hinet.net> Steven D'Aprano at 2018/6/17 PM 04:19 wrote: > On Sun, 17 Jun 2018 15:08:27 +0800, Jach Fong wrote: > >> The "address" of the Font object 'TkDefaultFont' changes, why? > > Its not an address, it is an ID number. > > The ID number changes because you get a different object each time you > call the function. Thanks for remind me again. I had read the subject "Understanding memory location of Python variables" recently in the forum and noticed that ID is implementation dependent, not necessary an "address". Just didn't get rid of my old habit:-) --Jach --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From bc at freeuk.com Sun Jun 17 06:01:41 2018 From: bc at freeuk.com (Bart) Date: Sun, 17 Jun 2018 11:01:41 +0100 Subject: Understanding memory location of Python variables In-Reply-To: References: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> Message-ID: <7kqVC.421436$sl2.60662@fx46.am4> On 17/06/2018 03:28, Grant Edwards wrote: > On 2018-06-16, ip.bcrs at gmail.com wrote: > >> I'm intrigued by the output of the following code, which was totally >> contrary to my expectations. Can someone tell me what is happening? >> >>>>> myName = "Kevin" >>>>> id(myName) >> 47406848 >>>>> id(myName[0]) >> 36308576 >>>>> id(myName[1]) >> 2476000 > > What's happening is that you're paying attention to the values > returned by id(), when you should not. The fact that CPython returns > a VM address when you call id() is just an "accident" of that > particular implimentation. You shouldn't assume that id() returns > anything other than a number that is unique to each object. Any time > you spend worrying about how that number is calculated is proably > wasted. > >> I expected myName[0] to be located at the same memory location as the myName variable itself. > > Python is not C. > >> I also expected myName[1] to be located immediately after myName[0]. > > Python is not C. > > Just in case you missed that... > > Python is not C. > So, how /do/ you obtain the memory address of those values are located? For example, in order to pass it to some foreign C function that takes a void* parameter. I assume there is a memory address at least for the "Kevin" value, as the other two might yield temporary objects for "K" and "e" rather the in-place strings which are the first and second characters of the name. -- bart From ben+python at benfinney.id.au Sun Jun 17 06:09:42 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 17 Jun 2018 20:09:42 +1000 Subject: Metasyntactic thingies References: Message-ID: <85y3fdenbt.fsf@benfinney.id.au> Steven D'Aprano writes: > But what placeholder names do you use for functions, methods or other > actions? As in, placeholder verbs rather than nouns? I find Lewis Carroll's canon to be a rich source of pronounceable nonsense words. The poem Jabberwocky is particularly valuable . The trouble with doesn't-mean-anything words is that they quickly *acquire* meaning. Many of the words that were unknown before Jabberwocky have since entered the English language as accepted standard words. This is going on all the time. The term ?widget? was once a deliberately abstract unit of manufacture, a metasyntactic word for discussion of economics deliberately chosen because it had no concrete meaning. It has since gained concrete meaning, and would be too confusing to use it today without disambiguating . Another good example is the word ?goon?. In the early 20th century, the word was not widespread enough to have a fixed, determined meaning , and the Popeye cartoon used it as a name for a strange grotesque giant in 1933. That word, perhaps more than the character, inspired the title of The Goon Show in the 1950s . Simultaneously, the word was *also* used to mean a hired thug. Words were so freely appropriated and gleefully mangled to surreal effect in The Goon Show that it, too, is a rich source of such semi-comprehensible words, good for use as metasyntactic tokens. So all told, English is particularly prone to have seeming nonsense words enter common use and people *apply* one or more meanings; the metasyntactic usage is thus undermined. So it goes. > Aside from such boring ones as "do_work" and similar, the only > placeholder verb I can think of is frobnicate. > > Does anyone else have any? I tend to riff on Latinate word constructions in the same vein as ?frobnicate?. I also try to channel The Goon Show when I need a metasyntactic word. Some recent ones include ?spunge?, ?nardle?, ?crun?, etc. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but where are we going to find a duck and a hose at this | _o__) hour?? ?_Pinky and The Brain_ | Ben Finney From rosuav at gmail.com Sun Jun 17 06:26:48 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jun 2018 20:26:48 +1000 Subject: Understanding memory location of Python variables In-Reply-To: <7kqVC.421436$sl2.60662@fx46.am4> References: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> <7kqVC.421436$sl2.60662@fx46.am4> Message-ID: On Sun, Jun 17, 2018 at 8:01 PM, Bart wrote: > On 17/06/2018 03:28, Grant Edwards wrote: >> >> On 2018-06-16, ip.bcrs at gmail.com wrote: >> >>> I'm intrigued by the output of the following code, which was totally >>> contrary to my expectations. Can someone tell me what is happening? >>> >>>>>> myName = "Kevin" >>>>>> id(myName) >>> >>> 47406848 >>>>>> >>>>>> id(myName[0]) >>> >>> 36308576 >>>>>> >>>>>> id(myName[1]) >>> >>> 2476000 >> >> >> What's happening is that you're paying attention to the values >> returned by id(), when you should not. The fact that CPython returns >> a VM address when you call id() is just an "accident" of that >> particular implimentation. You shouldn't assume that id() returns >> anything other than a number that is unique to each object. Any time >> you spend worrying about how that number is calculated is proably >> wasted. >> >>> I expected myName[0] to be located at the same memory location as the >>> myName variable itself. >> >> >> Python is not C. >> >>> I also expected myName[1] to be located immediately after myName[0]. >> >> >> Python is not C. >> >> Just in case you missed that... >> >> Python is not C. >> > > So, how /do/ you obtain the memory address of those values are located? For > example, in order to pass it to some foreign C function that takes a void* > parameter. For strings? You don't. > I assume there is a memory address at least for the "Kevin" value, as the > other two might yield temporary objects for "K" and "e" rather the in-place > strings which are the first and second characters of the name. > You assume wrong. Now, if you're talking about a data type that DOES have a concrete in-memory representation (such as memoryview), then the answer may be different. But in Python, no, you cannot find out where the data is located, because it quite probably isn't stored in any way that would be useful to you. If you're implementing a function *in C* that needs to accept a Python string as a parameter, you can take that string object and say "hey Python, can you give me a UTF-8 buffer with the contents of this string pls thx?", and you'll get one. But that's a conversion - albeit one that may be cached. ChrisA From rosuav at gmail.com Sun Jun 17 06:28:43 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jun 2018 20:28:43 +1000 Subject: Why an object changes its "address" between adjacent calls? In-Reply-To: <4a4d768b-eedc-d6b6-7584-d185833f95d1@caprilion.com.tw> References: <445dbeb0-7851-f572-250d-e3654297b663@ms4.hinet.net> <51892e91-785f-e244-f69f-ebdd394b7403@gmail.com> <4a4d768b-eedc-d6b6-7584-d185833f95d1@caprilion.com.tw> Message-ID: On Sun, Jun 17, 2018 at 7:39 PM, sales at caprilion.com.tw wrote: > Jim Lee at 2018/6/17 PM 04:10 wrote: >> >> >> >> On 06/17/2018 12:08 AM, Jach Fong wrote: >>> >>> C:\Python34\Doc>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. >>> >>> import tkinter as tk >>> >>> root = tk.Tk() >>> >>> tk.Label(root, text='label one', font='TkDefaultFont').pack() >>> >>> from tkinter import font >>> >>> font.nametofont('TkDefaultFont') >>> >>> >>> font.nametofont('TkDefaultFont') >>> >>> >>> >>> >>> The "address" of the Font object 'TkDefaultFont' changes, why? >>> >>> Best Regards, >>> Jach Fong >>> >>> >> >> def nametofont(name): >> """Given the name of a tk named font, returns a Font representation. >> """ >> return Font(name=name, exists=True) >> >> Every time you call nametofont(), you're creating a new instance of the >> Font class. > > > hmm... It means every time I set a widget's font to "TkDefaultFont", a > new object was created. Why python do things this way? Can't it use > this same object again and again? > That would imply keeping the object around until it's needed again. Sometimes that's worth doing; other times it isn't, or isn't worth the hassle. As soon as you stop using the previous one, Python is free to dispose of it. ChrisA From steve+comp.lang.python at pearwood.info Sun Jun 17 06:45:42 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 17 Jun 2018 10:45:42 +0000 (UTC) Subject: Understanding memory location of Python variables References: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> <7kqVC.421436$sl2.60662@fx46.am4> Message-ID: On Sun, 17 Jun 2018 11:01:41 +0100, Bart wrote: > So, how /do/ you obtain the memory address of those values are located? You don't. There is no implementation-independent Python function to get the memory address of an object. The concept of a fixed memory address for objects is not even a sensible one. In Python, all objects conceptually live in the heap, but there is no concept that they must have a fixed address, or any address at all. Depending on the memory management used by the Python virtual machine, the objects can move about as needed to free up blocks of unused memory. That's what IronPython and Jython do. Or, they could be like PyPy, where objects can conceptually disappear from existence and reappear when you look for them, a bit like quantum mechanics. PyPy can replace objects with low-level native data structures like ints, perform a bunch of calculations, and then recreate any needed objects. So long as none of this has any visible semantic differences from CPython (it is allowed to be faster :-) the PyPy interpreter is allowed to do almost anything it likes: move objects, destroy them and reallocate them, convert them to native data and back, push them onto the call stack, whatever it takes. > For example, in order to pass it to some foreign C function that > takes a void* parameter. That's up to the implementation. Jython and IronPython have little or no facility for calling C functions, hardly surprising since they are built on the JVM and .Net framework respectively. In CPython, there is probably a ctypes interface to do this, but ctypes is implementation-dependent and not portable (PyPy supports it, but other implementations probably won't). https://docs.python.org/3/library/ctypes.html Or you can use the CPython C API to write an extension class. https://docs.python.org/3/c-api/index.html -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sun Jun 17 07:06:19 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 17 Jun 2018 11:06:19 +0000 (UTC) Subject: Why an object changes its "address" between adjacent calls? References: <445dbeb0-7851-f572-250d-e3654297b663@ms4.hinet.net> <51892e91-785f-e244-f69f-ebdd394b7403@gmail.com> <4a4d768b-eedc-d6b6-7584-d185833f95d1@caprilion.com.tw> Message-ID: On Sun, 17 Jun 2018 17:39:42 +0800, sales at caprilion.com.tw wrote: [...] >> Every time you call nametofont(), you're creating a new instance of the >> Font class. > > hmm... It means every time I set a widget's font to > "TkDefaultFont", a new object was created. Correct. > Why python do things this way? Can't it use > this same object again and again? So if you create a font object, and then delete it, do you expect the interpreter to secretly hold onto that object forever just in case you need it again? If Python did that for everything, you would quickly run out of memory. The Python interpreter may cache certain objects. CPython caches some integers and small strings that look like they could be identifiers. PyPy caches floats. Other implementations may or may not cache anything. The interpreter may re-use immutable objects if doing so is a pure optimization with no effect on semantics, but it is unpredictable when it does this unless you study the interpreter source code. But caching *everything* would be a terrible idea. You cannot cache or re- use mutable objects like lists and dicts, and in general the interpreter cannot know which objects are immutable or not. So don't expect Python to magically optimize the number of objects you create. If you want to use the same object over and over again, use the same object, don't create a new one: # creates multiple font objects from tkinter import font a = font.nametofont('TkDefaultFont') b = font.nametofont('TkDefaultFont') # creates only one font object from tkinter import font a = font.nametofont('TkDefaultFont') b = a You can write your own cache function like this: _fontcache = {} def cached_font(name): try: return _fontcache[name] except KeyError: obj = font.nametofont(name) _fontcache[name] = obj return obj Or this might be better: https://docs.python.org/3/library/functools.html#functools.lru_cache But 95% of the time, the right answer is, don't worry about it. Memory is cheap, and chances are that you won't even notice that you saved a few bytes by using a cache. Sometimes, the extra time and memory used by the cache code will be greater than the memory you save. Python is designed to be used when memory is cheap, programmer's time is expensive, and it is better to throw extra memory at a problem than to try to solve it in the smallest amount of memory possible. If you think about programming in terms of saving bytes, you will probably hate Python. If you remember than even a cheap, bottom of the range computer these days has approximately two BILLION bytes of memory, and most machines have much more than that, you won't stress so much about reusing objects. The Rules of Optimization are simple. Rule 1: Don?t do it. Rule 2 (for experts only): Don?t do it yet. -- Michael A. Jackson, "Principles of Program Design" -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From marko at pacujo.net Sun Jun 17 08:05:21 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 17 Jun 2018 15:05:21 +0300 Subject: Understanding memory location of Python variables References: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> <7kqVC.421436$sl2.60662@fx46.am4> Message-ID: <87fu1lmxdq.fsf@elektro.pacujo.net> Bart : > So, how /do/ you obtain the memory address of those values are > located? For example, in order to pass it to some foreign C function > that takes a void* parameter. That is dependent on the Python implementation. CPython supports native C and C++ extensions: Here's the C API for extracting data out of strings: Marko From sharan.basappa at gmail.com Sun Jun 17 09:24:49 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sun, 17 Jun 2018 06:24:49 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <85fu1mf09b.fsf@benfinney.id.au> Message-ID: On Sunday, 17 June 2018 11:00:50 UTC+5:30, Ben Finney wrote: > Sharan Basappa writes: > > > I think I am now confused with format options in Python. > > You should refer to the documentation for string formatting > > > > (or, if you want to continue with the older less-flexible style, > ) > > > I tried an example as below and both print proper value: > > > > age = 35 > > > > print "age is %s" % age > > The ?s? format specifier says ?Ask the object for its text > representation, and put that text here?. > > Every object has a text representation, so ?s? works with any object. > > > print "age is %d" % age > > The ?d? format specifier says ?Format the integer as a decimal text > representation, and put that text here?. > > Only objects that are integers (or that implement the format-as-decimal > API) will work with ?d?. > > > I other languages I know the format specifier should be same as the > > variable type. For example, in the above case, it has to be %d and not > > %s > > Because you are explicitly specifying which formatting to use, there's > no ambiguity. With an object that is an integer, either of the above > makes sense in different use cases. > > -- > \ ?A right is not what someone gives you; it's what no one can | > `\ take from you.? ?Ramsey Clark | > _o__) | > Ben Finney Thanks a lot. From sharan.basappa at gmail.com Sun Jun 17 09:35:51 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sun, 17 Jun 2018 06:35:51 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> Message-ID: On Sunday, 17 June 2018 11:42:03 UTC+5:30, Jim Lee wrote: > On 06/16/2018 10:13 PM, Sharan Basappa wrote: > > I think I am now confused with format options in Python. > > I tried an example as below and both print proper value: > > > > age = 35 > > > > print "age is %s" % age > > print "age is %d" % age > > > > %run "D:/Projects/Initiatives/machine learning/programs/six.py" > > age is 35 > > age is 35 > > > > I other languages I know the format specifier should be same as the variable type. For example, in the above case, it has to be %d and not %s > > ? Python is not like other languages.? For one thing, there are no > "variables" in Python (in the way you think of them).?? There are only > objects and names.? Names can be thought of like void pointers in C, for > example.? They don't have a "type" themselves - they only refer to > objects, and the type of object they refer to can change at will.? Also, > there are no integers in Python.? Scalar values are actually objects.? > The number 35 is not an integer, it is an object that has an integer > type.? If you do a "dir(35)" in Python, you'll see that the object "35" > has more than 70 methods associated with it.?? I'll stop there to avoid > information overload, but these are some of the key things a Python > newcomer needs to wrap their head around.... > > -Jim Jim, thanks a lot. Somehow, not one book I referred to brought out very clearly that everything in Python is an object including basic data types. Probably, they did and not so explicitly. From ganesh1pal at gmail.com Sun Jun 17 10:47:30 2018 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sun, 17 Jun 2018 20:17:30 +0530 Subject: For specific keys , extract non empty values in a dictionary In-Reply-To: References: Message-ID: > >>> {k: o_num[k] for k in wanted & o_num.keys() if o_num[k] is not None} Thanks peter this looks better , except that I will need to use the logial 'and' operator or else I will get a TypeError >>> {k: o_num[k] for k in wanted & o_num.keys() if o_num[k] is not None} TypeError: unsupported operand type(s) for &: 'set' and 'list' Example : >>>print {k: o_num[k] for k in wanted and o_num.keys() if o_num[k] is not None} {'nine': 9, 'five': 5, 'three': 3, 'one': 1} On Sat, Jun 16, 2018 at 11:12 PM, Peter Otten <__peter__ at web.de> wrote: > Ganesh Pal wrote: > > > *How do I check few specific/selected keys in a dictionary and extract > > their values if they are not empty* > > You mean not None. > > > o_num = {'one': 1, > > 'three': 3, > > 'bar': None, > > 'five' : 5, > > 'rum' : None, > > 'seven' : None, > > 'brandy': None, > > 'nine' : 9, > > 'gin': None} > > > args_list = ["one","three","seven","nine"] > > > *Output:* > > > > *1 3 9* > > >>> wanted = {"one", "three", "seven", "nine"} > >>> {k: o_num[k] for k in wanted & o_num.keys() if o_num[k] is not None} > {'one': 1, 'nine': 9, 'three': 3} > > > I am a Python 2.7 user and on Linux box > > You have to replace keys() with viewkeys() in Python 2. > > -- > https://mail.python.org/mailman/listinfo/python-list > From bc at freeuk.com Sun Jun 17 12:19:38 2018 From: bc at freeuk.com (Bart) Date: Sun, 17 Jun 2018 17:19:38 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> Message-ID: On 17/06/2018 09:43, Steven D'Aprano wrote: > On Sat, 16 Jun 2018 23:11:41 -0700, Jim Lee wrote: > >> ? Python is not like other languages. > > Python is not like languages like C, Pascal, Algol, Fortran, D, Java > (unboxed native values only) and those like that. > > However, Python *is* like other languages like Javascript, Ruby, Java > (objects only), PHP, and others. > >> For one thing, there are no >> "variables" in Python (in the way you think of them). > > Indeed -- there are no variables in Python, if you think of a variable as > meaning a virtual box at a fixed memory address, containing a value, and > associated with a type, like in C or Pascal. So what's a Type Hint associated with in Python? -- bart From python at mrabarnett.plus.com Sun Jun 17 12:37:25 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 17 Jun 2018 17:37:25 +0100 Subject: For specific keys , extract non empty values in a dictionary In-Reply-To: References: Message-ID: <7840e3e1-b074-dd8d-5b76-e05c46da7b06@mrabarnett.plus.com> On 2018-06-17 15:47, Ganesh Pal wrote: >> >>> {k: o_num[k] for k in wanted & o_num.keys() if o_num[k] is not None} > > Thanks peter this looks better , except that I will need to use the > logial 'and' operator or else I will get a TypeError > >>>> {k: o_num[k] for k in wanted & o_num.keys() if o_num[k] is not None} > > TypeError: unsupported operand type(s) for &: 'set' and 'list' > Peter said that you need to use viewkeys() instead of keys() in Python 2: >>> {k: o_num[k] for k in wanted & o_num.viewkeys() if o_num[k] is not None} Using 'and' instead won't give the correct result. > > Example : > >>>>print {k: o_num[k] for k in wanted and o_num.keys() if o_num[k] is not > None} > {'nine': 9, 'five': 5, 'three': 3, 'one': 1} > > > > On Sat, Jun 16, 2018 at 11:12 PM, Peter Otten <__peter__ at web.de> wrote: > >> Ganesh Pal wrote: >> >> > *How do I check few specific/selected keys in a dictionary and extract >> > their values if they are not empty* >> >> You mean not None. >> >> > o_num = {'one': 1, >> > 'three': 3, >> > 'bar': None, >> > 'five' : 5, >> > 'rum' : None, >> > 'seven' : None, >> > 'brandy': None, >> > 'nine' : 9, >> > 'gin': None} >> >> > args_list = ["one","three","seven","nine"] >> >> > *Output:* >> > >> > *1 3 9* >> >> >>> wanted = {"one", "three", "seven", "nine"} >> >>> {k: o_num[k] for k in wanted & o_num.keys() if o_num[k] is not None} >> {'one': 1, 'nine': 9, 'three': 3} >> >> > I am a Python 2.7 user and on Linux box >> >> You have to replace keys() with viewkeys() in Python 2. >> From steve+comp.lang.python at pearwood.info Sun Jun 17 12:59:24 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 17 Jun 2018 16:59:24 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> Message-ID: On Sun, 17 Jun 2018 17:19:38 +0100, Bart wrote: >> Indeed -- there are no variables in Python, if you think of a variable >> as meaning a virtual box at a fixed memory address, containing a value, >> and associated with a type, like in C or Pascal. > > So what's a Type Hint associated with in Python? By the interpreter itself? Pretty much nothing at all. Aside from recording the annotation in the function object, the interpreter completely ignores it. py> def func(x: float) -> list: ... pass ... py> func.__annotations__ {'x': , 'return': } (Aside: in more recent versions of Python, the annotations are treated as strings, not objects, and you will get {'x': 'float', 'return': 'list'} instead.) Since it is a type *hint*, not a type *declaration*, the interpreter can and does ignore it. It makes no change at all to the execution model of the language. But the human reader, linters, IDEs and editors can associate it with the name it annotates, and use it as a hint as to what is intended to happen, and flag any discrepancies. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rantingrickjohnson at gmail.com Sun Jun 17 13:52:14 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 17 Jun 2018 10:52:14 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <85fu1mf09b.fsf@benfinney.id.au> Message-ID: <04a0fecd-618a-4156-ac70-107f1a8cb870@googlegroups.com> Chris Angelico wrote: [...] > For the record, there's nothing at all wrong with printf-style > formatting; its flexibility and brevity make it extremely useful in > many situations. Except that it's old, not elegant, error prone, feature poor, and not Pythonic! But besides all _that_ (and possibly more) it's slightly amusing, i suppose. Cling to the past much? What's wrong Chris, is the syntax of the new format method too difficult for you? Or do you have a personal disliking for anything OOP? Personally, i would suggest the OP should learn the new Python formatting methods and disregard the legacy printf style crap that has been copy/pasted from countless other languages. From rantingrickjohnson at gmail.com Sun Jun 17 14:10:55 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 17 Jun 2018 11:10:55 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> Message-ID: Steven D'Aprano wrote: > Bart Wrote: > > So what's a Type Hint associated with in Python? > Since it is a type *hint*, not a type *declaration*, the > interpreter can and does ignore it. But yet, the _programmer_ cannot ignore it. Does that make any sense to you, or anyone else with half a brain? > It makes no change at all to the execution model of the > language. Then why the *HELL* are type-hints an official part of the Python language syntax? Had type hints been implemented as comments (for instance: a special class of comment in the same way that doc-strings are a special class of strings), then a programmer could ignore them! Heck, i have even have a feature in my editor that will hide all comments and doc- strings! And the code to perform this task is fairly simple. But it's gonna one hell of a _nightmare_ to remove type- hints from source code when they are _interleaved_ with the damn source code, and considered by the interpreter to be syntax. > But the human reader, linters, IDEs and editors can > associate it with the name it annotates, and use it as a > hint as to what is intended to happen, and flag any > discrepancies. And each of these could have done the same with a "type-hint comment". But oh no, that would be too easy! And the whole point here is to cause a big fat ruckus? Isn't it, Mr. D'Aprano? From jlee54 at gmail.com Sun Jun 17 15:07:14 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 17 Jun 2018 12:07:14 -0700 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> Message-ID: <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> On 06/17/2018 11:10 AM, Rick Johnson wrote: > Steven D'Aprano wrote: >> Bart Wrote: >>> So what's a Type Hint associated with in Python? >> Since it is a type *hint*, not a type *declaration*, the >> interpreter can and does ignore it. > But yet, the _programmer_ cannot ignore it. Does that make > any sense to you, or anyone else with half a brain? > >> It makes no change at all to the execution model of the >> language. > Then why the *HELL* are type-hints an official part of the > Python language syntax? Had type hints been implemented as > comments (for instance: a special class of comment in the > same way that doc-strings are a special class of strings), > then a programmer could ignore them! Heck, i have even have > a feature in my editor that will hide all comments and doc- > strings! And the code to perform this task is fairly simple. > > But it's gonna one hell of a _nightmare_ to remove type- > hints from source code when they are _interleaved_ with the > damn source code, and considered by the interpreter to be > syntax. > >> But the human reader, linters, IDEs and editors can >> associate it with the name it annotates, and use it as a >> hint as to what is intended to happen, and flag any >> discrepancies. > And each of these could have done the same with a "type-hint > comment". But oh no, that would be too easy! And the whole > point here is to cause a big fat ruckus? Isn't it, Mr. > D'Aprano? > > > IMHO, trying to shoehorn static type checking on top of a dynamically typed language shows that the wrong language was chosen for the job. -Jim From rosuav at gmail.com Sun Jun 17 16:22:41 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 06:22:41 +1000 Subject: syntax difference In-Reply-To: <04a0fecd-618a-4156-ac70-107f1a8cb870@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <85fu1mf09b.fsf@benfinney.id.au> <04a0fecd-618a-4156-ac70-107f1a8cb870@googlegroups.com> Message-ID: On Mon, Jun 18, 2018 at 3:52 AM, Rick Johnson wrote: > Chris Angelico wrote: > [...] >> For the record, there's nothing at all wrong with printf-style >> formatting; its flexibility and brevity make it extremely useful in >> many situations. > > Except that it's old, not elegant, error prone, feature poor, and not Pythonic! [citation needed] > But besides all _that_ (and possibly more) it's slightly amusing, i suppose. > > Cling to the past much? > > What's wrong Chris, is the syntax of the new format method too difficult for you? Or do you have a personal disliking for anything OOP? What does "OOP" mean, exactly? Operators aren't, methods are? > Personally, i would suggest the OP should learn the new Python formatting methods and disregard the legacy printf style crap that has been copy/pasted from countless other languages. > And that's the exact same FUD. Thank you for proving that a known troll supports the FUD, which is a strong indication that it should be ignored. ChrisA From marko at pacujo.net Sun Jun 17 16:23:15 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 17 Jun 2018 23:23:15 +0300 Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: <87zhztkvrg.fsf@elektro.pacujo.net> Jim Lee : > IMHO, trying to shoehorn static type checking on top of a dynamically > typed language shows that the wrong language was chosen for the job. I'm also saddened by the type hinting initiative. When you try to be best for everybody, you end up being best for nobody. The niche Python has successfully occupied is huge. Why risk it all by trying to take the whole cake? Marko From rosuav at gmail.com Sun Jun 17 16:27:10 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 06:27:10 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> Message-ID: On Mon, Jun 18, 2018 at 4:10 AM, Rick Johnson wrote: > Steven D'Aprano wrote: >> Bart Wrote: >> > So what's a Type Hint associated with in Python? >> Since it is a type *hint*, not a type *declaration*, the >> interpreter can and does ignore it. > > But yet, the _programmer_ cannot ignore it. Does that make > any sense to you, or anyone else with half a brain? You're absolutely right. We should eliminate the 'assert' keyword (since the interpreter can and does ignore assertions in optimized mode), comments, and blank lines. Anyone with half a brain will see at once that they should obviously be removed. Anyone with an entire brain, of course, will appreciate them. >> It makes no change at all to the execution model of the >> language. > > Then why the *HELL* are type-hints an official part of the > Python language syntax? Had type hints been implemented as > comments (for instance: a special class of comment in the > same way that doc-strings are a special class of strings), > then a programmer could ignore them! Huh. Funny you should say that. https://www.python.org/dev/peps/pep-0484/#type-comments ChrisA From rosuav at gmail.com Sun Jun 17 16:35:40 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 06:35:40 +1000 Subject: syntax difference In-Reply-To: <87zhztkvrg.fsf@elektro.pacujo.net> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> Message-ID: On Mon, Jun 18, 2018 at 6:23 AM, Marko Rauhamaa wrote: > Jim Lee : >> IMHO, trying to shoehorn static type checking on top of a dynamically >> typed language shows that the wrong language was chosen for the job. > > I'm also saddened by the type hinting initiative. When you try to be > best for everybody, you end up being best for nobody. The niche Python > has successfully occupied is huge. Why risk it all by trying to take the > whole cake? Did you complain when function annotations were introduced back in 2006? https://www.python.org/dev/peps/pep-3107/ That's TWELVE YEARS ago. Over in the Node.js world, that's ... uhh, actually that's longer ago than Node.js has even been around. Another trendy language is Go... oh wait, that wasn't around in 2006 either. Type annotations have been in Python for nearly twelve years; ten if you count the actual release of Python 3.0. The thing that changed more recently was that *non-type* annotations were deprecated, since very few use-cases were found. When did the shoehorning happen, exactly? ChrisA From jlee54 at gmail.com Sun Jun 17 16:50:09 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 17 Jun 2018 13:50:09 -0700 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> Message-ID: <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> On 06/17/2018 01:35 PM, Chris Angelico wrote: > On Mon, Jun 18, 2018 at 6:23 AM, Marko Rauhamaa wrote: >> Jim Lee : >>> IMHO, trying to shoehorn static type checking on top of a dynamically >>> typed language shows that the wrong language was chosen for the job. >> I'm also saddened by the type hinting initiative. When you try to be >> best for everybody, you end up being best for nobody. The niche Python >> has successfully occupied is huge. Why risk it all by trying to take the >> whole cake? > Did you complain when function annotations were introduced back in 2006? > > https://www.python.org/dev/peps/pep-3107/ > > That's TWELVE YEARS ago. Over in the Node.js world, that's ... uhh, > actually that's longer ago than Node.js has even been around. Another > trendy language is Go... oh wait, that wasn't around in 2006 either. > > Type annotations have been in Python for nearly twelve years; ten if > you count the actual release of Python 3.0. The thing that changed > more recently was that *non-type* annotations were deprecated, since > very few use-cases were found. When did the shoehorning happen, > exactly? > > ChrisA What does time have to do with anything?? I wasn't using Python in 2006.? A bad idea is a bad idea, regardless of *when* it was conceived. -Jim -Jim From marko at pacujo.net Sun Jun 17 16:52:35 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 17 Jun 2018 23:52:35 +0300 Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> Message-ID: <87tvq1kuek.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Jun 18, 2018 at 6:23 AM, Marko Rauhamaa wrote: >> I'm also saddened by the type hinting initiative. When you try to be >> best for everybody, you end up being best for nobody. The niche Python >> has successfully occupied is huge. Why risk it all by trying to take the >> whole cake? > > Did you complain when function annotations were introduced back in 2006? No. I have yet to see them in the wild. I hope never to see them. Do you mean you must like them by now? > That's TWELVE YEARS ago. Over in the Node.js world, that's ... uhh, > actually that's longer ago than Node.js has even been around. Another > trendy language is Go... oh wait, that wasn't around in 2006 either. What are you talking about? Marko From rosuav at gmail.com Sun Jun 17 16:56:56 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 06:56:56 +1000 Subject: syntax difference In-Reply-To: <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> Message-ID: On Mon, Jun 18, 2018 at 6:50 AM, Jim Lee wrote: > > > On 06/17/2018 01:35 PM, Chris Angelico wrote: >> >> On Mon, Jun 18, 2018 at 6:23 AM, Marko Rauhamaa wrote: >>> >>> Jim Lee : >>>> >>>> IMHO, trying to shoehorn static type checking on top of a dynamically >>>> typed language shows that the wrong language was chosen for the job. >>> >>> I'm also saddened by the type hinting initiative. When you try to be >>> best for everybody, you end up being best for nobody. The niche Python >>> has successfully occupied is huge. Why risk it all by trying to take the >>> whole cake? >> >> Did you complain when function annotations were introduced back in 2006? >> >> https://www.python.org/dev/peps/pep-3107/ >> >> That's TWELVE YEARS ago. Over in the Node.js world, that's ... uhh, >> actually that's longer ago than Node.js has even been around. Another >> trendy language is Go... oh wait, that wasn't around in 2006 either. >> >> Type annotations have been in Python for nearly twelve years; ten if >> you count the actual release of Python 3.0. The thing that changed >> more recently was that *non-type* annotations were deprecated, since >> very few use-cases were found. When did the shoehorning happen, >> exactly? >> >> ChrisA > > What does time have to do with anything? I wasn't using Python in 2006. A > bad idea is a bad idea, regardless of *when* it was conceived. > You talk about "risk it all by trying to take the whole cake" as if annotations are a change. But if they were already around before you first met the language, then they're just part of the language. You might as well argue against the += operator or list comprehensions. ChrisA From drsalists at gmail.com Sun Jun 17 16:58:07 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 17 Jun 2018 13:58:07 -0700 Subject: syntax difference In-Reply-To: <87zhztkvrg.fsf@elektro.pacujo.net> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> Message-ID: On Sun, Jun 17, 2018 at 1:23 PM, Marko Rauhamaa wrote: > Jim Lee : > > IMHO, trying to shoehorn static type checking on top of a dynamically > > typed language shows that the wrong language was chosen for the job. > > I'm also saddened by the type hinting initiative. When you try to be > best for everybody, you end up being best for nobody. The niche Python > has successfully occupied is huge. Why risk it all by trying to take the > whole cake? I actually really like Python's type hinting, which I've recently started using. I've now used it on 10 projects, and I imagine I'll be using it in many more. Don't like them? I guess you don't have to use them. From jlee54 at gmail.com Sun Jun 17 17:10:18 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 17 Jun 2018 14:10:18 -0700 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> Message-ID: On 06/17/2018 01:56 PM, Chris Angelico wrote: > On Mon, Jun 18, 2018 at 6:50 AM, Jim Lee wrote: >> >> On 06/17/2018 01:35 PM, Chris Angelico wrote: >>> On Mon, Jun 18, 2018 at 6:23 AM, Marko Rauhamaa wrote: >>>> Jim Lee : >>>>> IMHO, trying to shoehorn static type checking on top of a dynamically >>>>> typed language shows that the wrong language was chosen for the job. >>>> I'm also saddened by the type hinting initiative. When you try to be >>>> best for everybody, you end up being best for nobody. The niche Python >>>> has successfully occupied is huge. Why risk it all by trying to take the >>>> whole cake? >>> Did you complain when function annotations were introduced back in 2006? >>> >>> https://www.python.org/dev/peps/pep-3107/ >>> >>> That's TWELVE YEARS ago. Over in the Node.js world, that's ... uhh, >>> actually that's longer ago than Node.js has even been around. Another >>> trendy language is Go... oh wait, that wasn't around in 2006 either. >>> >>> Type annotations have been in Python for nearly twelve years; ten if >>> you count the actual release of Python 3.0. The thing that changed >>> more recently was that *non-type* annotations were deprecated, since >>> very few use-cases were found. When did the shoehorning happen, >>> exactly? >>> >>> ChrisA >> What does time have to do with anything? I wasn't using Python in 2006. A >> bad idea is a bad idea, regardless of *when* it was conceived. >> > You talk about "risk it all by trying to take the whole cake" as if > annotations are a change. But if they were already around before you > first met the language, then they're just part of the language. You > might as well argue against the += operator or list comprehensions. > > ChrisA You seem to have lost the attribution to those comments in your reply.? I wasn't the one who talked about "risk it all by trying to take the whole cake". -Jim From drsalists at gmail.com Sun Jun 17 17:13:29 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 17 Jun 2018 14:13:29 -0700 Subject: Understanding memory location of Python variables In-Reply-To: <87fu1lmxdq.fsf@elektro.pacujo.net> References: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> <7kqVC.421436$sl2.60662@fx46.am4> <87fu1lmxdq.fsf@elektro.pacujo.net> Message-ID: On Sun, Jun 17, 2018 at 5:05 AM, Marko Rauhamaa wrote: > Bart : > > So, how /do/ you obtain the memory address of those values are > > located? For example, in order to pass it to some foreign C function > > that takes a void* parameter. > > That is dependent on the Python implementation. CPython supports native > C and C++ extensions: > > > > Here's the C API for extracting data out of strings: > > > I'd actually recommend, in order from greatest preference to least: 1) Cython (but probably only for CPython) 2) CFFI (for CPython and Pypy, but perhaps not for others) 3) ctypes (but only for quick little projects with CPython or PyPy) 4) The new stable C extension type ABI (for CPython... and PyPy?) 5) The old, common C extension type ABI (for CPython, and if you don't get too fancy, for PyPy) Cython is almost like Python, except it allows you to intermix C and Python datatypes. And it gets a lot of the silly fiddly bits right, so you don't have to. But you can still do byte-level stuff with it, if you actually need to. From rosuav at gmail.com Sun Jun 17 17:17:11 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 07:17:11 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> Message-ID: On Mon, Jun 18, 2018 at 7:10 AM, Jim Lee wrote: > > > On 06/17/2018 01:56 PM, Chris Angelico wrote: >> >> On Mon, Jun 18, 2018 at 6:50 AM, Jim Lee wrote: >>> >>> >>> On 06/17/2018 01:35 PM, Chris Angelico wrote: >>>> >>>> On Mon, Jun 18, 2018 at 6:23 AM, Marko Rauhamaa >>>> wrote: >>>>> >>>>> Jim Lee : >>>>>> >>>>>> IMHO, trying to shoehorn static type checking on top of a dynamically >>>>>> typed language shows that the wrong language was chosen for the job. >>>>> >>>>> I'm also saddened by the type hinting initiative. When you try to be >>>>> best for everybody, you end up being best for nobody. The niche Python >>>>> has successfully occupied is huge. Why risk it all by trying to take >>>>> the >>>>> whole cake? >>>> >>>> Did you complain when function annotations were introduced back in 2006? >>>> >>>> https://www.python.org/dev/peps/pep-3107/ >>>> >>>> That's TWELVE YEARS ago. Over in the Node.js world, that's ... uhh, >>>> actually that's longer ago than Node.js has even been around. Another >>>> trendy language is Go... oh wait, that wasn't around in 2006 either. >>>> >>>> Type annotations have been in Python for nearly twelve years; ten if >>>> you count the actual release of Python 3.0. The thing that changed >>>> more recently was that *non-type* annotations were deprecated, since >>>> very few use-cases were found. When did the shoehorning happen, >>>> exactly? >>>> >>>> ChrisA >>> >>> What does time have to do with anything? I wasn't using Python in 2006. >>> A >>> bad idea is a bad idea, regardless of *when* it was conceived. >>> >> You talk about "risk it all by trying to take the whole cake" as if >> annotations are a change. But if they were already around before you >> first met the language, then they're just part of the language. You >> might as well argue against the += operator or list comprehensions. >> >> ChrisA > > You seem to have lost the attribution to those comments in your reply. I > wasn't the one who talked about > > "risk it all by trying to take the whole cake". > My apologies, stuff wrapped and I misread as I skimmed back. You were the one who used the word "shoehorned". In the same way, that sounds like you already knew the language, and then someone added extra features that don't fit. It's not shoehorning if the feature was already there before you met the language. The point is the same, the citation incorrect. Mea culpa. ChrisA From marko at pacujo.net Sun Jun 17 17:21:53 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Jun 2018 00:21:53 +0300 Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> Message-ID: <87muvtkt1q.fsf@elektro.pacujo.net> Dan Stromberg : > On Sun, Jun 17, 2018 at 1:23 PM, Marko Rauhamaa wrote: >> I'm also saddened by the type hinting initiative. When you try to be >> best for everybody, you end up being best for nobody. The niche >> Python has successfully occupied is huge. Why risk it all by trying >> to take the whole cake? > > I actually really like Python's type hinting, which I've recently started > using. I've now used it on 10 projects, and I imagine I'll be using it in > many more. > > Don't like them? I guess you don't have to use them. I that were true, fine. I'm most afraid of it becoming an all-encompassing fad that can't be avoided. So far so good. Marko From __peter__ at web.de Sun Jun 17 17:42:31 2018 From: __peter__ at web.de (Peter Otten) Date: Sun, 17 Jun 2018 23:42:31 +0200 Subject: For specific keys , extract non empty values in a dictionary References: <7840e3e1-b074-dd8d-5b76-e05c46da7b06@mrabarnett.plus.com> Message-ID: Dennis Lee Bieber wrote: > On Sun, 17 Jun 2018 17:37:25 +0100, MRAB > declaimed the following: > >>On 2018-06-17 15:47, Ganesh Pal wrote: >>>> >>> {k: o_num[k] for k in wanted & o_num.keys() if o_num[k] is not >>>> >>> {None} >>> >>> Thanks peter this looks better , except that I will need to use the >>> logial 'and' operator or else I will get a TypeError >>> >>>>>> {k: o_num[k] for k in wanted & o_num.keys() if o_num[k] is not None} >>> >>> TypeError: unsupported operand type(s) for &: 'set' and 'list' >>> >>Peter said that you need to use viewkeys() instead of keys() in Python 2: >> >> >>> {k: o_num[k] for k in wanted & o_num.viewkeys() if o_num[k] is not >>None} >> > > What's wrong with the simple > >>>> o_num = { "one" : 1, > ... "three" : 3, > ... "bar" : None, > ... "five" : 5, > ... "rum" : None, > ... "seven" : None, > ... "brandy" : None, > ... "nine" : 9, > ... "gin" : None } >>>> args_list = [ "one", "three", "seven", "nine" ] >>>> >>>> { k : o_num[k] for k in args_list if o_num.get(k, None) is not None } > {'nine': 9, 'three': 3, 'one': 1} >>>> It's hidden here because of the removal of None values, but in the generic case when you say "give me all x in a that are also in b" instead of "give me the intersection of a and b" you are overspecifying the problem. From pkpearson at nowhere.invalid Sun Jun 17 18:18:37 2018 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 17 Jun 2018 22:18:37 GMT Subject: Understanding memory location of Python variables References: <6baf3f62-9bde-48bb-a4c9-d5c5fe0ba613@googlegroups.com> Message-ID: On Sat, 16 Jun 2018 09:38:07 -0700 (PDT), ip.bcrs at gmail.com wrote: > Hi everyone, > > I'm intrigued by the output of the following code, which was totally > contrary to my expectations. Can someone tell me what is happening? > >>>> myName = "Kevin" >>>> id(myName) > 47406848 >>>> id(myName[0]) > 36308576 >>>> id(myName[1]) > 2476000 You left out one of the more interesting (and possibly informative) angles: >>> myName = "Kevin" >>> x0 = myName[0] >>> x1 = myName[1] >>> x01 = myName[0:2] >>> y0 = "K" >>> y1 = "e" >>> y01 = "Ke" >>> id(x0) == id(y0) True >>> id(x1) == id(y1) True >>> id(x01) == id(y01) False >>> x01 == y01 True myName[0] is the string "K", and this Python implementation happens to economize by having only a single object "K". This economy measure probably only applies to single-character strings. -- To email me, substitute nowhere->runbox, invalid->com. From cs at cskk.id.au Sun Jun 17 18:45:40 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 18 Jun 2018 08:45:40 +1000 Subject: syntax difference In-Reply-To: References: Message-ID: <20180617224540.GA96222@cskk.homeip.net> On 17Jun2018 11:10, Rick Johnson wrote: >Steven D'Aprano wrote: >> But the human reader, linters, IDEs and editors can >> associate it with the name it annotates, and use it as a >> hint as to what is intended to happen, and flag any >> discrepancies. > >And each of these could have done the same with a "type-hint >comment". But oh no, that would be too easy! And the whole >point here is to cause a big fat ruckus? Isn't it, Mr. >D'Aprano? No, it is so that there can be an agreed syntax for this stuff rather than a billion funky special comments, and also so that _compiled_ python can be inspected for type hints because they survive that step. This makes for machine inspectable hints very easily, and that is a boon for linters. Another advantage of type hints being part of the syntax is that invalid/mistyped type hints can be caught by the parser. If they're just special comments then linters _might_ see them and complain, or equally they might say "this comment isn't a valid type hint, so it is an ordinary comment", silently ignoring it. Thus weakening the lint. As for the runtime ignoring them: they can't accomodate all situations in a dynamic language, and type checking would impose a performance penalty for no semantic effect. Cheers, Cameron Simpson From rantingrickjohnson at gmail.com Sun Jun 17 19:30:53 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 17 Jun 2018 16:30:53 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: On Sunday, June 17, 2018 at 2:07:40 PM UTC-5, Jim Lee wrote: > IMHO, trying to shoehorn static type checking on top of a dynamically > typed language shows that the wrong language was chosen for the job. Exactly. I'm not against the idea of Python growing a new feature. Features are great. My objection is concerned merely with the "how" it is implemented, not the "why" it was implemented. "Type-hint comments" would allow: (1) those who need them, to use them. (2) those who don't care about them, to totally ignore them. (3) and those who utterly *HATE* them, to write a simply little function which will strip them from any and all source code they might be forced to maintain. Personally, i would never put type-hints in my Python code. I write a large portion of my overall code in Python specifically because i do not wish to be distracted by type declarations. Of course, regardless of how much i try to avoid type-hints, the problem will come, when one day in the future, i am forced to maintain another Python programmer's code that is littered with these declarations. And removing them won't be easy. But that's the real danger of this feature. The Python community will not see the real effect of type-hints (at least, as they are currently implemented) for a long time. But as more and more type-hints are spread in the wild, more and more people, and more and more organizations, are going to look for "cleaner language" to solve their R&D and general purpose high-level problems. What's the point of eye-ball-parsing through miles of type- hints which demand all the burdens of static typing whilst giving none of the real benefits. The Python interpreter ignores these hints. But as programmers -- as, human beings, and not machines! -- ignoring the syntactical noise of type- hints will be impossible. So either the Python devs need to release a "3ToTypeHintFree.py", or they need to re-implement this so- called feature as a special class of comment. And here is an example of how that might be done, using Steven's example from above: ## Steven's Example ## #(Current implementation of type-hints) py> def func(x: float) -> list: """Ello, ime-uh lit-al doc-string, yes i am.""" ... pass ## Prposed solution v1 ## py> def func(x): """Ello, ime-uh lit-al doc-string, yes i am.""" # x:float -> list ... pass From rantingrickjohnson at gmail.com Sun Jun 17 19:46:05 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 17 Jun 2018 16:46:05 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> Message-ID: <1c3c7110-840c-46fa-8f3c-3b1bd73172dc@googlegroups.com> On Sunday, June 17, 2018 at 3:58:26 PM UTC-5, Dan Stromberg wrote: [...] > I actually really like Python's type hinting, which I've recently started > using. I've now used it on 10 projects, and I imagine I'll be using it in > many more. > > Don't like them? I guess you don't have to use them. Go ahead an be cocky if you want to. But just remember this: People like myself will outright refuse to maintain your code. And do you know what that means Dan? It means your code will _die_! And then we will get paid to rewrite your code. Code that will be far more maintainable than the syntactical mess you wrote. And if we want static typing -- no problem! -- we'll convince out clients to switch to a language that has *REAL* static typing. Okay? Howdya like that? (shills gonna do what shills gonna do, i guess @_@) From rantingrickjohnson at gmail.com Sun Jun 17 19:48:21 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 17 Jun 2018 16:48:21 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> Message-ID: <4461ded6-cc86-4804-bf43-62158c8e5bf1@googlegroups.com> On Sunday, June 17, 2018 at 4:17:33 PM UTC-5, Chris Angelico wrote: > On Mon, Jun 18, 2018 at 7:10 AM, Jim Lee wrote: > > > > > > On 06/17/2018 01:56 PM, Chris Angelico wrote: > >> > >> On Mon, Jun 18, 2018 at 6:50 AM, Jim Lee wrote: > >>> > >>> > >>> On 06/17/2018 01:35 PM, Chris Angelico wrote: > >>>> > >>>> On Mon, Jun 18, 2018 at 6:23 AM, Marko Rauhamaa > >>>> wrote: > >>>>> > >>>>> Jim Lee : > >>>>>> > >>>>>> IMHO, trying to shoehorn static type checking on top of a dynamically > >>>>>> typed language shows that the wrong language was chosen for the job. > >>>>> > >>>>> I'm also saddened by the type hinting initiative. When you try to be > >>>>> best for everybody, you end up being best for nobody. The niche Python > >>>>> has successfully occupied is huge. Why risk it all by trying to take > >>>>> the > >>>>> whole cake? > >>>> > >>>> Did you complain when function annotations were introduced back in 2006? > >>>> > >>>> https://www.python.org/dev/peps/pep-3107/ > >>>> > >>>> That's TWELVE YEARS ago. Over in the Node.js world, that's ... uhh, > >>>> actually that's longer ago than Node.js has even been around. Another > >>>> trendy language is Go... oh wait, that wasn't around in 2006 either. > >>>> > >>>> Type annotations have been in Python for nearly twelve years; ten if > >>>> you count the actual release of Python 3.0. The thing that changed > >>>> more recently was that *non-type* annotations were deprecated, since > >>>> very few use-cases were found. When did the shoehorning happen, > >>>> exactly? > >>>> > >>>> ChrisA > >>> > >>> What does time have to do with anything? I wasn't using Python in 2006. > >>> A > >>> bad idea is a bad idea, regardless of *when* it was conceived. > >>> > >> You talk about "risk it all by trying to take the whole cake" as if > >> annotations are a change. But if they were already around before you > >> first met the language, then they're just part of the language. You > >> might as well argue against the += operator or list comprehensions. > >> > >> ChrisA > > > > You seem to have lost the attribution to those comments in your reply. I > > wasn't the one who talked about > > > > "risk it all by trying to take the whole cake". > > > > My apologies, stuff wrapped and I misread as I skimmed back. You were > the one who used the word "shoehorned". In the same way, that sounds > like you already knew the language, and then someone added extra > features that don't fit. It's not shoehorning if the feature was > already there before you met the language. Red herring! From rosuav at gmail.com Sun Jun 17 20:10:32 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 10:10:32 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: On Mon, Jun 18, 2018 at 9:30 AM, Rick Johnson wrote: > On Sunday, June 17, 2018 at 2:07:40 PM UTC-5, Jim Lee wrote: > >> IMHO, trying to shoehorn static type checking on top of a dynamically >> typed language shows that the wrong language was chosen for the job. > > Exactly. > > I'm not against the idea of Python growing a new feature. > Features are great. My objection is concerned merely with > the "how" it is implemented, not the "why" it was > implemented. > > "Type-hint comments" would allow: > > (1) those who need them, to use them. > > (2) those who don't care about them, to totally ignore > them. > > (3) and those who utterly *HATE* them, to write a simply > little function which will strip them from any and all > source code they might be forced to maintain. Awwww. Isn't it cute, how he thinks that comments are easier to remove than other elements equally well defined in the grammar? ChrisA From jlee54 at gmail.com Sun Jun 17 20:22:08 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 17 Jun 2018 17:22:08 -0700 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> Message-ID: On 06/17/2018 02:17 PM, Chris Angelico wrote: > [snip] > My apologies, stuff wrapped and I misread as I skimmed back. You were > the one who used the word "shoehorned". In the same way, that sounds > like you already knew the language, and then someone added extra > features that don't fit. It's not shoehorning if the feature was > already there before you met the language. > > The point is the same, the citation incorrect. Mea culpa. > > ChrisA Of course it is "shoehorning".? Why do you care when I started using the language?? Shoehorning implies an attempt to add a feature that didn't exist in the original design - a feature that is a difficult, awkward, or ill-fitting complement to the original design.? Whether it happened yesterday or 12 years ago is immaterial.? When I personally met the language is also immaterial. Microsoft "shoehorned" a Linux subsystem into Windows.? I don't even use Windows, yet by your logic, I can't call it "shoehorning". -Jim From rosuav at gmail.com Sun Jun 17 20:39:51 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 10:39:51 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> Message-ID: On Mon, Jun 18, 2018 at 10:22 AM, Jim Lee wrote: > > > On 06/17/2018 02:17 PM, Chris Angelico wrote: >> >> [snip] >> My apologies, stuff wrapped and I misread as I skimmed back. You were >> the one who used the word "shoehorned". In the same way, that sounds >> like you already knew the language, and then someone added extra >> features that don't fit. It's not shoehorning if the feature was >> already there before you met the language. >> >> The point is the same, the citation incorrect. Mea culpa. >> >> ChrisA > > > Of course it is "shoehorning". Why do you care when I started using the > language? Shoehorning implies an attempt to add a feature that didn't exist > in the original design - a feature that is a difficult, awkward, or > ill-fitting complement to the original design. Whether it happened > yesterday or 12 years ago is immaterial. When I personally met the language > is also immaterial. > > Microsoft "shoehorned" a Linux subsystem into Windows. I don't even use > Windows, yet by your logic, I can't call it "shoehorning". Or maybe that's an indication of a change in design goals. Python's original goal was to be very similar to C, and thus had a lot of behaviours copied from C; up until Python 2.2, the default 'int' type would overflow if it exceeded a machine word. Were long integers shoehorned into the design, or does it indicate that the design was modified to welcome them? Personally, I think the Linux subsystem is (a) no different from (but converse to) Wine, and (b) a good stepping-stone towards a Windows release using a Unix kernel. ChrisA From rantingrickjohnson at gmail.com Sun Jun 17 22:12:22 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 17 Jun 2018 19:12:22 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: <3c7bbf63-95f1-4c8c-8aa3-fb15e14e55a0@googlegroups.com> Chris Angelico wrote: [...] > Awwww. Isn't it cute, how he thinks that comments are easier to remove > than other elements equally well defined in the grammar? And may we see your code that will remove all instances of type-hints error free? Hmm? I look forward to scraping the internet for source code i can try it on, and then posting the tracebacks here for all to see. From rosuav at gmail.com Sun Jun 17 22:22:43 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 12:22:43 +1000 Subject: syntax difference In-Reply-To: <3c7bbf63-95f1-4c8c-8aa3-fb15e14e55a0@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <3c7bbf63-95f1-4c8c-8aa3-fb15e14e55a0@googlegroups.com> Message-ID: On Mon, Jun 18, 2018 at 12:12 PM, Rick Johnson wrote: > Chris Angelico wrote: > [...] >> Awwww. Isn't it cute, how he thinks that comments are easier to remove >> than other elements equally well defined in the grammar? > > And may we see your code that will remove all instances of type-hints error free? > > Hmm? > > I look forward to scraping the internet for source code i can try it on, and then posting the tracebacks here for all to see. First, show me your perfect comment removal code. Don't forget to correctly handle different source code encodings, backslashes escaping newlines, and triple-quoted strings. Then if that is proven easy, I'll show you how a small tweak will remove any other syntactic element you like. And yes, I know exactly what tool I would use for the job. If I ever had to do something so stupid. ChrisA From rantingrickjohnson at gmail.com Sun Jun 17 23:20:57 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 17 Jun 2018 20:20:57 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <3c7bbf63-95f1-4c8c-8aa3-fb15e14e55a0@googlegroups.com> Message-ID: On Sunday, June 17, 2018 at 9:22:57 PM UTC-5, Chris Angelico wrote: > First, No. You're not squirming your way out this one Chris. _You_ leveled the assertion that removing interleaved type- hints from the executable code would be easier than removing my proposed "type-hint comments". What was the quote??? Oh, i remember: "Awwww. Isn't it cute, how he thinks that comments are easier to remove than other elements equally well defined in the grammar?" Now. Put up, or shut up. > [...] From rosuav at gmail.com Mon Jun 18 00:24:50 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 14:24:50 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <3c7bbf63-95f1-4c8c-8aa3-fb15e14e55a0@googlegroups.com> Message-ID: On Mon, Jun 18, 2018 at 1:20 PM, Rick Johnson wrote: > On Sunday, June 17, 2018 at 9:22:57 PM UTC-5, Chris Angelico wrote: >> First, > > No. > > You're not squirming your way out this one Chris. > > _You_ leveled the assertion that removing interleaved type- > hints from the executable code would be easier than removing > my proposed "type-hint comments". > > What was the quote??? > > Oh, i remember: > > "Awwww. Isn't it cute, how he thinks that comments are > easier to remove than other elements equally well defined > in the grammar?" > > Now. Put up, or shut up. What was the quote before that? > "Type-hint comments" would allow: > (3) and those who utterly *HATE* them, to write a simply > little function which will strip them from any and all > source code they might be forced to maintain. Put up or shut up. Write something that strips all type hint comments. ChrisA From dieter at handshake.de Mon Jun 18 00:35:24 2018 From: dieter at handshake.de (dieter) Date: Mon, 18 Jun 2018 06:35:24 +0200 Subject: XSD data mapper lib References: <9a7c8291-1d46-a8e3-85b9-fddd40c57ffc@shopzeus.com> Message-ID: <874li0btkj.fsf@handshake.de> Nagy L?szl? Zsolt writes: > I wonder what kind of XSD <-> Python class mapper should I use for my > project. I am using "PyXB" for this kind of tasks. From jfong at ms4.hinet.net Mon Jun 18 00:48:23 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Mon, 18 Jun 2018 12:48:23 +0800 Subject: Is it possible to call a class but without a new instance created? Message-ID: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> After looking into the \tkiniter\font.py source file, triggered by Jim's hint on my previous subject "Why an object changes its "address" between adjacent calls?", I get more confused. Below was quoted from the font.py: ------------------------ def nametofont(name): """Given the name of a tk named font, returns a Font representation. """ return Font(name=name, exists=True) class Font: """Represents a named font. Constructor options are: ... exists -- does a named font by this name already exist? Creates a new named font if False, points to the existing font if True. ... """ def __init__(self, root=None, font=None, name=None, exists=False, **options): ... ---------------------- From my understanding, the __init__ method was called after the instance was created, that's why the __init__ has a self parameter, right? Then, how is it possible "...points to the existing font if True"? I didn't see any clue in __init__ doing this. I also make a test of my own and it fails too. >>> class A: ... objs = [] ... def __init__(self, exists=False): ... if exists: self = self.objs[0] ... else: self.objs.append(self) ... >>> a0 = A() >>> id(a0) 35569968 >>> a1 = A(exists=True) >>> id(a1) 35572336 What I expect is that id(a0) and id(a1) has the same value. They should points to the same object. Best Regards, Jach Fong --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From jlee54 at gmail.com Mon Jun 18 00:59:03 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 17 Jun 2018 21:59:03 -0700 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> Message-ID: <907b56cc-1961-c28a-6de7-42febe5556c5@gmail.com> On 06/17/2018 05:39 PM, Chris Angelico wrote: > On Mon, Jun 18, 2018 at 10:22 AM, Jim Lee wrote: >> >> On 06/17/2018 02:17 PM, Chris Angelico wrote: >>> [snip] >>> My apologies, stuff wrapped and I misread as I skimmed back. You were >>> the one who used the word "shoehorned". In the same way, that sounds >>> like you already knew the language, and then someone added extra >>> features that don't fit. It's not shoehorning if the feature was >>> already there before you met the language. >>> >>> The point is the same, the citation incorrect. Mea culpa. >>> >>> ChrisA >> >> Of course it is "shoehorning". Why do you care when I started using the >> language? Shoehorning implies an attempt to add a feature that didn't exist >> in the original design - a feature that is a difficult, awkward, or >> ill-fitting complement to the original design. Whether it happened >> yesterday or 12 years ago is immaterial. When I personally met the language >> is also immaterial. >> >> Microsoft "shoehorned" a Linux subsystem into Windows. I don't even use >> Windows, yet by your logic, I can't call it "shoehorning". > Or maybe that's an indication of a change in design goals. Python's > original goal was to be very similar to C, and thus had a lot of > behaviours copied from C; up until Python 2.2, the default 'int' type > would overflow if it exceeded a machine word. Were long integers > shoehorned into the design, or does it indicate that the design was > modified to welcome them? > > Personally, I think the Linux subsystem is (a) no different from (but > converse to) Wine, and (b) a good stepping-stone towards a Windows > release using a Unix kernel. > > ChrisA I say: "frobnitz was broken". You say: "you can't call frobnitz broken because it was broken before you found out it was broken". I say: "foo is bad". You say: "foo is no different than bar (except it's the opposite), and might eventually be like baz (which doesn't exist)." Hard to argue with that kind of...umm...logic.? :) -Jim From rosuav at gmail.com Mon Jun 18 01:04:02 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 15:04:02 +1000 Subject: syntax difference In-Reply-To: <907b56cc-1961-c28a-6de7-42febe5556c5@gmail.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> <907b56cc-1961-c28a-6de7-42febe5556c5@gmail.com> Message-ID: On Mon, Jun 18, 2018 at 2:59 PM, Jim Lee wrote: > > > On 06/17/2018 05:39 PM, Chris Angelico wrote: >> >> On Mon, Jun 18, 2018 at 10:22 AM, Jim Lee wrote: >>> >>> >>> On 06/17/2018 02:17 PM, Chris Angelico wrote: >>>> >>>> [snip] >>>> My apologies, stuff wrapped and I misread as I skimmed back. You were >>>> the one who used the word "shoehorned". In the same way, that sounds >>>> like you already knew the language, and then someone added extra >>>> features that don't fit. It's not shoehorning if the feature was >>>> already there before you met the language. >>>> >>>> The point is the same, the citation incorrect. Mea culpa. >>>> >>>> ChrisA >>> >>> >>> Of course it is "shoehorning". Why do you care when I started using the >>> language? Shoehorning implies an attempt to add a feature that didn't >>> exist >>> in the original design - a feature that is a difficult, awkward, or >>> ill-fitting complement to the original design. Whether it happened >>> yesterday or 12 years ago is immaterial. When I personally met the >>> language >>> is also immaterial. >>> >>> Microsoft "shoehorned" a Linux subsystem into Windows. I don't even use >>> Windows, yet by your logic, I can't call it "shoehorning". >> >> Or maybe that's an indication of a change in design goals. Python's >> original goal was to be very similar to C, and thus had a lot of >> behaviours copied from C; up until Python 2.2, the default 'int' type >> would overflow if it exceeded a machine word. Were long integers >> shoehorned into the design, or does it indicate that the design was >> modified to welcome them? >> >> Personally, I think the Linux subsystem is (a) no different from (but >> converse to) Wine, and (b) a good stepping-stone towards a Windows >> release using a Unix kernel. >> >> ChrisA > > I say: "frobnitz was broken". > > You say: "you can't call frobnitz broken because it was broken before you > found out it was broken". > > > I say: "foo is bad". > > You say: "foo is no different than bar (except it's the opposite), and might > eventually be like baz (which doesn't exist)." > > > Hard to argue with that kind of...umm...logic. :) That isn't what I said, and you know it. I said that you can't decry changes that were before your time (they're simply the way things are). My comments about the Linux subsystem are parenthetical. ChrisA From jlee54 at gmail.com Mon Jun 18 01:10:56 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 17 Jun 2018 22:10:56 -0700 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> <907b56cc-1961-c28a-6de7-42febe5556c5@gmail.com> Message-ID: <7bfdc89d-e354-28f0-f840-0f346cbdd47f@gmail.com> On 06/17/2018 10:04 PM, Chris Angelico wrote: > On Mon, Jun 18, 2018 at 2:59 PM, Jim Lee wrote: >> >> On 06/17/2018 05:39 PM, Chris Angelico wrote: >>> On Mon, Jun 18, 2018 at 10:22 AM, Jim Lee wrote: >>>> >>>> On 06/17/2018 02:17 PM, Chris Angelico wrote: >>>>> [snip] >>>>> My apologies, stuff wrapped and I misread as I skimmed back. You were >>>>> the one who used the word "shoehorned". In the same way, that sounds >>>>> like you already knew the language, and then someone added extra >>>>> features that don't fit. It's not shoehorning if the feature was >>>>> already there before you met the language. >>>>> >>>>> The point is the same, the citation incorrect. Mea culpa. >>>>> >>>>> ChrisA >>>> >>>> Of course it is "shoehorning". Why do you care when I started using the >>>> language? Shoehorning implies an attempt to add a feature that didn't >>>> exist >>>> in the original design - a feature that is a difficult, awkward, or >>>> ill-fitting complement to the original design. Whether it happened >>>> yesterday or 12 years ago is immaterial. When I personally met the >>>> language >>>> is also immaterial. >>>> >>>> Microsoft "shoehorned" a Linux subsystem into Windows. I don't even use >>>> Windows, yet by your logic, I can't call it "shoehorning". >>> Or maybe that's an indication of a change in design goals. Python's >>> original goal was to be very similar to C, and thus had a lot of >>> behaviours copied from C; up until Python 2.2, the default 'int' type >>> would overflow if it exceeded a machine word. Were long integers >>> shoehorned into the design, or does it indicate that the design was >>> modified to welcome them? >>> >>> Personally, I think the Linux subsystem is (a) no different from (but >>> converse to) Wine, and (b) a good stepping-stone towards a Windows >>> release using a Unix kernel. >>> >>> ChrisA >> I say: "frobnitz was broken". >> >> You say: "you can't call frobnitz broken because it was broken before you >> found out it was broken". >> >> >> I say: "foo is bad". >> >> You say: "foo is no different than bar (except it's the opposite), and might >> eventually be like baz (which doesn't exist)." >> >> >> Hard to argue with that kind of...umm...logic. :) > That isn't what I said, and you know it. I said that you can't decry > changes that were before your time (they're simply the way things > are). My comments about the Linux subsystem are parenthetical. > > ChrisA Really?? Wow.? I'd hate to live in your world!? Just because something exists, it can't be challenged or questioned.? Got it! -Jim From marko at pacujo.net Mon Jun 18 01:24:58 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Jun 2018 08:24:58 +0300 Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> <907b56cc-1961-c28a-6de7-42febe5556c5@gmail.com> <7bfdc89d-e354-28f0-f840-0f346cbdd47f@gmail.com> Message-ID: <87in6gll91.fsf@elektro.pacujo.net> Jim Lee : > Really?? Wow.? I'd hate to live in your world!? Just because something > exists, it can't be challenged or questioned.? Got it! No need to get overly agitated just because someone says something preposterous. Marko From vincent.vande.vyvre at telenet.be Mon Jun 18 03:17:41 2018 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Mon, 18 Jun 2018 09:17:41 +0200 Subject: Is it possible to call a class but without a new instance created? In-Reply-To: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> References: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> Message-ID: <0a8a26ba-37dc-3c30-219a-2f050e68eabd@telenet.be> Le 18/06/18 ? 06:48, Jach Fong a ?crit?: > After looking into the \tkiniter\font.py source file, triggered by Jim's > hint on my previous subject "Why an object changes its "address" between > adjacent calls?", I get more confused. > > Below was quoted from the font.py: > ------------------------ > def nametofont(name): > ??? """Given the name of a tk named font, returns a Font representation. > ??? """ > ??? return Font(name=name, exists=True) > > class Font: > ??? """Represents a named font. > ??? Constructor options are: > ??? ... > ??? exists -- does a named font by this name already exist? > ?????? Creates a new named font if False, points to the existing font > if True. > ??? ... > ??? """ > > ??? def __init__(self, root=None, font=None, name=None, exists=False, > ???????????????? **options): > ??????? ... > ---------------------- > From my understanding, the __init__ method was called after the instance > was created, that's why the __init__ has a self parameter, right? Then, > how is it possible "...points to the existing font if True"? I didn't > see any clue in __init__ doing this. > > I also make a test of my own and it fails too. > > >>> class A: > ...???? objs = [] > ...???? def __init__(self, exists=False): > ...???????????? if exists:? self = self.objs[0] > ...???????????? else:? self.objs.append(self) > ... > >>> a0 = A() > >>> id(a0) > 35569968 > >>> a1 = A(exists=True) > >>> id(a1) > 35572336 > > What I expect is that id(a0) and id(a1) has the same value. They > should points to the same object. > > > Best Regards, > Jach Fong > > > > > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus > Hi, What you try to do is called a /singleton./ A classic example : class Foo: ??? _instance = None ??? def __new__(cls, *args, **kwargs): ??????? if cls._instance is None: ??????????? cls._instance = super(Foo, cls).__new__(cls, *args, **kwargs) ??????? return cls._instance ??? def __init__(self, ...): ??? ??? ... Vincent Send at Mon, 18 Jun 2018 09:17:21 +0200 From rosuav at gmail.com Mon Jun 18 03:25:49 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 17:25:49 +1000 Subject: Is it possible to call a class but without a new instance created? In-Reply-To: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> References: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> Message-ID: On Mon, Jun 18, 2018 at 2:48 PM, Jach Fong wrote: > After looking into the \tkiniter\font.py source file, triggered by Jim's > hint on my previous subject "Why an object changes its "address" between > adjacent calls?", I get more confused. > > Below was quoted from the font.py: > ------------------------ > def nametofont(name): > """Given the name of a tk named font, returns a Font representation. > """ > return Font(name=name, exists=True) > > class Font: > """Represents a named font. > Constructor options are: > ... > exists -- does a named font by this name already exist? > Creates a new named font if False, points to the existing font if > True. > ... > """ > > def __init__(self, root=None, font=None, name=None, exists=False, > **options): > ... > ---------------------- > From my understanding, the __init__ method was called after the instance > was created, that's why the __init__ has a self parameter, right? Then, > how is it possible "...points to the existing font if True"? I didn't > see any clue in __init__ doing this. > > I also make a test of my own and it fails too. > >>>> class A: > ... objs = [] > ... def __init__(self, exists=False): > ... if exists: self = self.objs[0] > ... else: self.objs.append(self) > ... >>>> a0 = A() >>>> id(a0) > 35569968 >>>> a1 = A(exists=True) >>>> id(a1) > 35572336 > > What I expect is that id(a0) and id(a1) has the same value. They should > points to the same object. Yes, what you want is possible; but you need a slightly different method. Assigning to 'self' doesn't do anything - it's not magical, it's just a parameter. Instead, look into overriding __new__; that's how, for instance, the int() constructor can return cached objects. ChrisA From ben+python at benfinney.id.au Mon Jun 18 03:29:50 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 18 Jun 2018 17:29:50 +1000 Subject: Is it possible to call a class but without a new instance created? References: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> Message-ID: <85tvq0eemp.fsf@benfinney.id.au> Jach Fong writes: > I also make a test of my own and it fails too. > > >>> class A: > ... objs = [] > ... def __init__(self, exists=False): > ... if exists: self = self.objs[0] The function parameters (bound here to the names ?self?, ?exists?) are in the local function scope. After the function ends, the scope of those names ends; those name bindings no longer affect anything. So, changing what ?self? refers to has no effect on the A instance that exists. In other words: Creating the instance is the responsibility of the constructor method (a class method named ?__new__?), and that instance is what gets passed to the instance initialiser (an instance method named ?__init__?). The initialiser has no control over what instance gets passed in, and no control over that same instance being returned from the constructor. > What I expect is that id(a0) and id(a1) has the same value. They > should points to the same object. You can't get that effect from within the instance initialiser. What you need to do is change the class constructor (named ?__new__?), and that's a more advanced topic I leave you to research on your own. -- \ ?Now Maggie, I?ll be watching you too, in case God is busy | `\ creating tornadoes or not existing.? ?Homer, _The Simpsons_ | _o__) | Ben Finney From __peter__ at web.de Mon Jun 18 04:27:30 2018 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 Jun 2018 10:27:30 +0200 Subject: Is it possible to call a class but without a new instance created? References: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> Message-ID: Jach Fong wrote: > Is it possible to call a class but without a new instance created? Yes, this is possible in Python, by writing a custom __new__ method. An extreme example: >>> class Three: ... def __new__(*args): return 3 ... >>> a = Three() >>> b = Three() >>> a 3 >>> b 3 >>> a is b True But this is not what is done with the tkinter Font class. Most tkinter classes refer to a tcl/tk object and so does Font. import tkinter as tk from tkinter.font import Font root = tk.Tk() a = Font(root, name="foo", size=10, exists=False) label = tk.Label(root, text="hello", font=a) label.pack() def update_foo(): b = Font(root, name="foo", size=20, exists=True) # two distinct Font objects referring to the same underlying tcl font. assert a is not b button = tk.Button(root, text="update foo font to 20pt", command=update_foo) button.pack() root.mainloop() Here the b = Font(...) creates another wrapper for the "foo" font and updates its size in the process so that the label's appearance is updated, too. From tjreedy at udel.edu Mon Jun 18 05:09:21 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Jun 2018 05:09:21 -0400 Subject: Is it possible to call a class but without a new instance created? In-Reply-To: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> References: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> Message-ID: On 6/18/2018 12:48 AM, Jach Fong wrote: > After looking into the \tkiniter\font.py source file, triggered by Jim's > hint on my previous subject "Why an object changes its "address" between > adjacent calls?", I get more confused. > > Below was quoted from the font.py: > ------------------------ > def nametofont(name): > ??? """Given the name of a tk named font, returns a Font representation. > ??? """ > ??? return Font(name=name, exists=True) > > class Font: > ??? """Represents a named font. tkinter abbreviates tk interface. A Python tkinter Font instance represents a tk named font structure. It has a hidden pointer to the tk structure. The same is true of all instances of tkinter widgets classes. Each has a hidden pointer to a tk widget > ??? Constructor options are: > ??? ... > ??? exists -- does a named font by this name already exist? Does a *tk* named font exist? > ?????? Creates a new named font if False, points to the existing font > if True. Again, 'font' here means a tk structure, not a python instance. Each call to Font returns a new python instance. But for Fonts, it may or may not point to a new tk structure. > ??? ... > ??? """ > > ??? def __init__(self, root=None, font=None, name=None, exists=False, > ???????????????? **options): > ??????? ... One can mostly ignore the parallel existence of python instances and tk structures. But they can get out of sync during shutdown. If t is an instance of Text, t.destroy() causes tkinter to tell tk to destroy the tk widget, leaving t useless. Similarly, if 'del t' deletes the last reference to the Python instance, it may disappear, leaving the tk widget possibly unaccessible. -- Terry Jan Reedy From tjreedy at udel.edu Mon Jun 18 05:19:05 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Jun 2018 05:19:05 -0400 Subject: Is it possible to call a class but without a new instance created? In-Reply-To: References: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> Message-ID: To answer the question of the title, which is a bit different from the question in the text, yes. type(None)() always returns the singleton None object. (And one can write a singleton class in Python also.) bool() always returns one of False or True. int() and str() may return either a new or old object. For such immutables, it does not matter as long at the object has the correct value. As others said, this is all handled in a __new__ method. But none of this has much to do with tkinter instances. On 6/18/2018 5:09 AM, Terry Reedy wrote: > On 6/18/2018 12:48 AM, Jach Fong wrote: >> After looking into the \tkiniter\font.py source file, triggered by Jim's >> hint on my previous subject "Why an object changes its "address" between >> adjacent calls?", I get more confused. >> >> Below was quoted from the font.py: >> ------------------------ >> def nametofont(name): >> ???? """Given the name of a tk named font, returns a Font representation. >> ???? """ >> ???? return Font(name=name, exists=True) >> >> class Font: >> ???? """Represents a named font. > > tkinter abbreviates tk interface.? A Python tkinter Font instance > represents a tk named font structure. It has a hidden pointer to the tk > structure.? The same is true of all instances of tkinter widgets > classes.? Each has a hidden pointer to a tk widget > >> ???? Constructor options are: >> ???? ... >> ???? exists -- does a named font by this name already exist? > > Does a *tk* named font exist? > >> ??????? Creates a new named font if False, points to the existing font >> if True. > > Again, 'font' here means a tk structure, not a python instance.? Each > call to Font returns a new python instance.? But for Fonts, it may or > may not point to a new tk structure. > >> ???? ... >> ???? """ >> >> ???? def __init__(self, root=None, font=None, name=None, exists=False, >> ????????????????? **options): >> ???????? ... > > One can mostly ignore the parallel existence of python instances and tk > structures.? But they can get out of sync during shutdown.? If t is an > instance of Text, t.destroy() causes tkinter to tell tk to destroy the > tk widget, leaving t useless.? Similarly, if 'del t' deletes the last > reference to the Python instance, it may disappear, leaving the tk > widget possibly unaccessible. > -- Terry Jan Reedy From bc at freeuk.com Mon Jun 18 06:33:19 2018 From: bc at freeuk.com (Bart) Date: Mon, 18 Jun 2018 11:33:19 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: On 18/06/2018 01:10, Chris Angelico wrote: > On Mon, Jun 18, 2018 at 9:30 AM, Rick Johnson > wrote: >> On Sunday, June 17, 2018 at 2:07:40 PM UTC-5, Jim Lee wrote: >> >>> IMHO, trying to shoehorn static type checking on top of a dynamically >>> typed language shows that the wrong language was chosen for the job. >> >> Exactly. >> >> I'm not against the idea of Python growing a new feature. >> Features are great. My objection is concerned merely with >> the "how" it is implemented, not the "why" it was >> implemented. >> >> "Type-hint comments" would allow: >> >> (1) those who need them, to use them. >> >> (2) those who don't care about them, to totally ignore >> them. >> >> (3) and those who utterly *HATE* them, to write a simply >> little function which will strip them from any and all >> source code they might be forced to maintain. > > Awwww. Isn't it cute, how he thinks that comments are easier to remove > than other elements equally well defined in the grammar? You're right in that neither task is that trivial. I can remove comments by writing a tokeniser which scans Python source and re-outputs tokens one at a time. Such a tokeniser normally ignores comments. But to remove type hints, a deeper understanding of the input is needed. I would need a parser rather than a tokeniser. So it is harder. Both methods would fail with source code that exists as a string constant (for exec() for example), or source code that is synthesised at runtime. -- bart From rosuav at gmail.com Mon Jun 18 06:45:06 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 20:45:06 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: On Mon, Jun 18, 2018 at 8:33 PM, Bart wrote: > On 18/06/2018 01:10, Chris Angelico wrote: >> >> On Mon, Jun 18, 2018 at 9:30 AM, Rick Johnson >> wrote: >>> >>> On Sunday, June 17, 2018 at 2:07:40 PM UTC-5, Jim Lee wrote: >>> >>>> IMHO, trying to shoehorn static type checking on top of a dynamically >>>> typed language shows that the wrong language was chosen for the job. >>> >>> >>> Exactly. >>> >>> I'm not against the idea of Python growing a new feature. >>> Features are great. My objection is concerned merely with >>> the "how" it is implemented, not the "why" it was >>> implemented. >>> >>> "Type-hint comments" would allow: >>> >>> (1) those who need them, to use them. >>> >>> (2) those who don't care about them, to totally ignore >>> them. >>> >>> (3) and those who utterly *HATE* them, to write a simply >>> little function which will strip them from any and all >>> source code they might be forced to maintain. >> >> >> Awwww. Isn't it cute, how he thinks that comments are easier to remove >> than other elements equally well defined in the grammar? > > > You're right in that neither task is that trivial. > > I can remove comments by writing a tokeniser which scans Python source and > re-outputs tokens one at a time. Such a tokeniser normally ignores comments. > > But to remove type hints, a deeper understanding of the input is needed. I > would need a parser rather than a tokeniser. So it is harder. They would actually both end up the same. To properly recognize comments, you need to understand enough syntax to recognize them. To properly recognize type hints, you need to understand enough syntax to recognize them. And in both cases, you need to NOT discard important information like consecutive whitespace. So in both cases, you would probably end up with something like 2to3. The effective work is going to be virtually identical. And.... there's another complication, if you want any form of generic tool. You have to ONLY remove certain comments, not others. For instance, you probably should NOT remove copyright/license comments. > Both methods would fail with source code that exists as a string constant > (for exec() for example), or source code that is synthesised at runtime. > Sure, but I would just consider that to be outside the scope. ChrisA From rhodri at kynesim.co.uk Mon Jun 18 07:09:32 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 18 Jun 2018 12:09:32 +0100 Subject: Metasyntactic thingies In-Reply-To: References: Message-ID: <0b0b28de-14f3-712f-91a0-25a9581142f2@kynesim.co.uk> On 17/06/18 10:09, Steven D'Aprano wrote: > But what placeholder names do you use for functions, methods or other > actions? As in, placeholder verbs rather than nouns? > > Aside from such boring ones as "do_work" and similar, the only > placeholder verb I can think of is frobnicate. > > Does anyone else have any? Sometimes I "mangle()" things, but I'm usually boring. "do_something()", "do_something_else()" or (if I'm feeling particularly nostalgic and helpless) "do_something_muttley()". -- Rhodri James *-* Kynesim Ltd From bc at freeuk.com Mon Jun 18 07:16:26 2018 From: bc at freeuk.com (Bart) Date: Mon, 18 Jun 2018 12:16:26 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: On 18/06/2018 11:45, Chris Angelico wrote: > On Mon, Jun 18, 2018 at 8:33 PM, Bart wrote: >> You're right in that neither task is that trivial. >> >> I can remove comments by writing a tokeniser which scans Python source and >> re-outputs tokens one at a time. Such a tokeniser normally ignores comments. >> >> But to remove type hints, a deeper understanding of the input is needed. I >> would need a parser rather than a tokeniser. So it is harder. > > They would actually both end up the same. To properly recognize > comments, you need to understand enough syntax to recognize them. To > properly recognize type hints, you need to understand enough syntax to > recognize them. And in both cases, you need to NOT discard important > information like consecutive whitespace. No. If syntax is defined on top of tokens, then at the token level, you don't need to know any syntax. The process that scans characters looking for the next token, will usually discard comments. Job done. It is very different for type-hints as you will need to properly parse the source code. As a simpler example, if the task was the eliminate the "+" symbol, that would be one kind of token; it would just be skipped when encountered. But if the requirement to eliminate only unary "+", and leave binary "+", then that can't be done at tokeniser level; it will not know the context. (The matter of leading white space sometimes being important, is a minor detail. It just becomes a token of its own.) > So in both cases, you would probably end up with something like 2to3. > The effective work is going to be virtually identical. And.... there's > another complication, if you want any form of generic tool. You have > to ONLY remove certain comments, not others. For instance, you > probably should NOT remove copyright/license comments. What will those look like? If copyright/licence comments have their own specific syntax, then they just become another token which has to be recognised. The main complication I can see is that, if this is really a one-time source-to-source translator so that you will be working with the result, then usually you will want to keep the comments. Then it is a question of more precisely defining the task that such a translator is to perform. -- bart From vinay_sajip at yahoo.co.uk Mon Jun 18 07:17:15 2018 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 18 Jun 2018 11:17:15 +0000 (UTC) Subject: ANN: Version 0.1.5 of sarge (a subprocess wrapper library) has been released. References: <623045556.2285083.1529320635284.ref@mail.yahoo.com> Message-ID: <623045556.2285083.1529320635284@mail.yahoo.com> Version 0.1.5 of Sarge, a cross-platform library which wraps the subprocessmodule in the standard library, has been released. What changed?------------- - Fixed #37: Instead of an OSError with a "no such file or directory" message,? a ValueError is raised with a more informative "Command not found" message. - Fixed #38: Replaced ``async`` keyword argument with ``async_``, as ``async``? has become a keyword in Python 3.7. - Fixed #39: Updated tutorial example on progress monitoring. What does Sarge do?------------------- Sarge tries to make interfacing with external programs from yourPython applications easier than just using subprocess alone. Sarge offers the following features: * A simple way to run command lines which allows a rich subset of Bash-style shell command syntax, but parsed and run by sarge so that youcan run on Windows without cygwin (subject to having those commandsavailable): >>> from sarge import capture_stdout>>> p = capture_stdout('echo foo | cat; echo bar')>>> for line in p.stdout: print(repr(line))...'foo\n''bar\n' * The ability to format shell commands with placeholders, such thatvariables are quoted to prevent shell injection attacks. * The ability to capture output streams without requiring you toprogram your own threads. You just use a Capture object and then youcan read from it as and when you want. * The ability to look for patterns in captured output and to interactaccordingly with the child process. Advantages over subprocess--------------------------- Sarge offers the following benefits compared to using subprocess: * The API is very simple. * It's easier to use command pipelines - using subprocess out of thebox often leads to deadlocks because pipe buffers get filled up. * It would be nice to use Bash-style pipe syntax on Windows, butWindows shells don't support some of the syntax which is useful, like&&, ||, |& and so on. Sarge gives you that functionality on Windows,without cygwin. * Sometimes, subprocess.Popen.communicate() is not flexible enough forone's needs - for example, when one needs to process output a line ata time without buffering the entire output in memory. * It's desirable to avoid shell injection problems by having theability to quote command arguments safely. * subprocess allows you to let stderr be the same as stdout, but notthe other way around - and sometimes, you need to do that. Python version and platform compatibility----------------------------------------- Sarge is intended to be used on any Python version >= 2.6 and istested on Python versions 2.6, 2.7, 3.3, 3.4, 3.5, 3.6 and 3.7 on Linux,Windows, and Mac OS X (not all versions are tested on all platforms,but sarge is expected to work correctly on all these versions on allthese platforms). Finding out more---------------- You can read the documentation at http://sarge.readthedocs.org/ There's a lot more information, with examples, than I can put intothis post. You can install Sarge using "pip install sarge" to try it out. Theproject is hosted on BitBucket at https://bitbucket.org/vinay.sajip/sarge/ And you can leave feedback on the issue tracker there. I hope you find Sarge useful! Regards, Vinay Sajip From rosuav at gmail.com Mon Jun 18 07:33:08 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 21:33:08 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: On Mon, Jun 18, 2018 at 9:16 PM, Bart wrote: > On 18/06/2018 11:45, Chris Angelico wrote: >> >> On Mon, Jun 18, 2018 at 8:33 PM, Bart wrote: > > > >>> You're right in that neither task is that trivial. >>> >>> I can remove comments by writing a tokeniser which scans Python source >>> and >>> re-outputs tokens one at a time. Such a tokeniser normally ignores >>> comments. >>> >>> But to remove type hints, a deeper understanding of the input is needed. >>> I >>> would need a parser rather than a tokeniser. So it is harder. >> >> >> They would actually both end up the same. To properly recognize >> comments, you need to understand enough syntax to recognize them. To >> properly recognize type hints, you need to understand enough syntax to >> recognize them. And in both cases, you need to NOT discard important >> information like consecutive whitespace. > > > No. If syntax is defined on top of tokens, then at the token level, you > don't need to know any syntax. The process that scans characters looking for > the next token, will usually discard comments. Job done. And it also will usually discard formatting (consecutive whitespace, etc). So unless you're okay with reconstructing functionally-equivalent code, rather than actually preserving the original code, you cannot merely tokenize. You have to use a special form of tokenization that actually keeps all that. > It is very different for type-hints as you will need to properly parse the > source code. > > As a simpler example, if the task was the eliminate the "+" symbol, that > would be one kind of token; it would just be skipped when encountered. But > if the requirement to eliminate only unary "+", and leave binary "+", then > that can't be done at tokeniser level; it will not know the context. Right. You can fairly easily reconstruct code that uses a single newline for any NEWLINE token, and a single space in any location where whitespace makes sense. It's not so easy to correctly reconstruct "x*y + a*b" with the original spacing. > What will those look like? If copyright/licence comments have their own > specific syntax, then they just become another token which has to be > recognised. If they have specific syntax, they're not comments, are they? > The main complication I can see is that, if this is really a one-time > source-to-source translator so that you will be working with the result, > then usually you will want to keep the comments. > > Then it is a question of more precisely defining the task that such a > translator is to perform. Right, exactly. So you need to do an actual smart parse, which - as mentioned - is functionally equivalent whether you're stripping comments or some lexical token. ChrisA From steve+comp.lang.python at pearwood.info Mon Jun 18 07:40:59 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 18 Jun 2018 11:40:59 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> Message-ID: On Sun, 17 Jun 2018 11:10:55 -0700, Rick Johnson wrote: > Steven D'Aprano wrote: >> Bart Wrote: >> > So what's a Type Hint associated with in Python? >> Since it is a type *hint*, not a type *declaration*, the interpreter >> can and does ignore it. > > But yet, the _programmer_ cannot ignore it. The programmer can ignore it, just as they can ignore any other form of documentation. Nobody is stopping you from writing: result = function(the_string=42.5) if you wish. Adding a type hint doesn't change that. >> It makes no change at all to the execution model of the language. > > Then why the *HELL* are type-hints an official part of the Python > language syntax? Just to annoy you. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jun 18 07:50:52 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 18 Jun 2018 11:50:52 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> Message-ID: On Mon, 18 Jun 2018 06:35:40 +1000, Chris Angelico wrote: > On Mon, Jun 18, 2018 at 6:23 AM, Marko Rauhamaa > wrote: >> Jim Lee : >>> IMHO, trying to shoehorn static type checking on top of a dynamically >>> typed language shows that the wrong language was chosen for the job. >> >> I'm also saddened by the type hinting initiative. When you try to be >> best for everybody, you end up being best for nobody. The niche Python >> has successfully occupied is huge. Why risk it all by trying to take >> the whole cake? > > Did you complain when function annotations were introduced back in 2006? > > https://www.python.org/dev/peps/pep-3107/ > > That's TWELVE YEARS ago. Over in the Node.js world, that's ... uhh, > actually that's longer ago than Node.js has even been around. Another > trendy language is Go... oh wait, that wasn't around in 2006 either. Yes, but in fairness, people have abandoned Python by the handful for Go and Javascript. At the rate people are abandoning Python, in another 10 or 20 years Python will have dropped to the second most popular language: http://pypl.github.io/PYPL.html -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jun 18 07:52:34 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 18 Jun 2018 11:52:34 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> Message-ID: On Mon, 18 Jun 2018 06:56:56 +1000, Chris Angelico wrote: > You talk about "risk it all by trying to take the whole cake" as if > annotations are a change. But if they were already around before you > first met the language, then they're just part of the language. You > might as well argue against the += operator or list comprehensions. I still think that Python has been going nowhere but downhill ever since extended slicing was added in version 1.4. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jun 18 07:56:19 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 18 Jun 2018 11:56:19 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <1c3c7110-840c-46fa-8f3c-3b1bd73172dc@googlegroups.com> Message-ID: On Sun, 17 Jun 2018 16:46:05 -0700, Rick Johnson wrote: > People like myself will outright refuse to maintain your code. Whew Dan, you dodged a bullet there. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Mon Jun 18 08:00:20 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 22:00:20 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> Message-ID: On Mon, Jun 18, 2018 at 9:50 PM, Steven D'Aprano wrote: > On Mon, 18 Jun 2018 06:35:40 +1000, Chris Angelico wrote: > >> On Mon, Jun 18, 2018 at 6:23 AM, Marko Rauhamaa >> wrote: >>> Jim Lee : >>>> IMHO, trying to shoehorn static type checking on top of a dynamically >>>> typed language shows that the wrong language was chosen for the job. >>> >>> I'm also saddened by the type hinting initiative. When you try to be >>> best for everybody, you end up being best for nobody. The niche Python >>> has successfully occupied is huge. Why risk it all by trying to take >>> the whole cake? >> >> Did you complain when function annotations were introduced back in 2006? >> >> https://www.python.org/dev/peps/pep-3107/ >> >> That's TWELVE YEARS ago. Over in the Node.js world, that's ... uhh, >> actually that's longer ago than Node.js has even been around. Another >> trendy language is Go... oh wait, that wasn't around in 2006 either. > > Yes, but in fairness, people have abandoned Python by the handful for Go > and Javascript. At the rate people are abandoning Python, in another 10 > or 20 years Python will have dropped to the second most popular language: > > http://pypl.github.io/PYPL.html > Oh, I forgot about that. That's why Guido is busily stuffing it with every feature he possibly can, in the hope that - once Python runs out of popularity - it'll at least... actually, you know what, I got nothing. ChrisA From bc at freeuk.com Mon Jun 18 08:07:50 2018 From: bc at freeuk.com (Bart) Date: Mon, 18 Jun 2018 13:07:50 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: On 18/06/2018 12:33, Chris Angelico wrote: > On Mon, Jun 18, 2018 at 9:16 PM, Bart wrote: >> What will those look like? If copyright/licence comments have their own >> specific syntax, then they just become another token which has to be >> recognised. > > If they have specific syntax, they're not comments, are they? So how is it possible for ANY program to determine what kind of comments they are? I've used 'smart' comments myself, which contain special information, but are also designed to be very easily detected by the simplest of programs which scan the source code. For that purpose, they might start with a special prefix so that it is not necessary to parse the special information, but just to detect the prefix. For example, comments that start with #T# (and in my case, that begin at the start of a line). Funnily enough, this also provided type information (although for different purposes than what is discussed here). >> The main complication I can see is that, if this is really a one-time >> source-to-source translator so that you will be working with the result, >> then usually you will want to keep the comments. >> >> Then it is a question of more precisely defining the task that such a >> translator is to perform. > > Right, exactly. So you need to do an actual smart parse, which - as > mentioned - is functionally equivalent whether you're stripping > comments or some lexical token. The subject is type annotation. Presumably there is some way to distinguish such a type annotation within a comment from a regular comment? Such as the marker I suggested above. Then the tokeniser just needs to detect that kind of comment rather than need to understand the contents. Although the tokeniser will need to work a little differently by maintaining the positions of all tokens within the line, information that is usually discarded. -- bart From marko at pacujo.net Mon Jun 18 08:11:05 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Jun 2018 15:11:05 +0300 Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> Message-ID: <87wouwz44m.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Jun 18, 2018 at 9:50 PM, Steven D'Aprano > wrote: >> On Mon, 18 Jun 2018 06:35:40 +1000, Chris Angelico wrote: >> >>> On Mon, Jun 18, 2018 at 6:23 AM, Marko Rauhamaa >>> wrote: >>>> I'm also saddened by the type hinting initiative. When you try to >>>> be best for everybody, you end up being best for nobody. The niche >>>> Python has successfully occupied is huge. Why risk it all by trying >>>> to take the whole cake? >>> >>> Did you complain when function annotations were introduced back in >>> 2006? >>> [...] >> >> Yes, but in fairness, people have abandoned Python by the handful for >> Go and Javascript. At the rate people are abandoning Python, in >> another 10 or 20 years Python will have dropped to the second most >> popular language: >> >> http://pypl.github.io/PYPL.html >> > > Oh, I forgot about that. That's why Guido is busily stuffing it with > every feature he possibly can, in the hope that - once Python runs out > of popularity - it'll at least... actually, you know what, I got > nothing. So the point *was* popularity!? I suspected as much. Marko From rosuav at gmail.com Mon Jun 18 08:18:00 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 22:18:00 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: On Mon, Jun 18, 2018 at 10:07 PM, Bart wrote: > On 18/06/2018 12:33, Chris Angelico wrote: >> >> On Mon, Jun 18, 2018 at 9:16 PM, Bart wrote: > > >>> What will those look like? If copyright/licence comments have their own >>> specific syntax, then they just become another token which has to be >>> recognised. >> >> >> If they have specific syntax, they're not comments, are they? > > > So how is it possible for ANY program to determine what kind of comments > they are? > > I've used 'smart' comments myself, which contain special information, but > are also designed to be very easily detected by the simplest of programs > which scan the source code. For that purpose, they might start with a > special prefix so that it is not necessary to parse the special information, > but just to detect the prefix. > > For example, comments that start with #T# (and in my case, that begin at the > start of a line). Funnily enough, this also provided type information > (although for different purposes than what is discussed here). Oh, a specific format of comments? Sorry, I misunderstood. Yes, it is certainly possible to start with a program that removes all comments, and then refine it to one which only removes those which (don't) match some pattern. That's definitely a possibility. > The subject is type annotation. Presumably there is some way to distinguish > such a type annotation within a comment from a regular comment? Such as the > marker I suggested above. > > Then the tokeniser just needs to detect that kind of comment rather than > need to understand the contents. > > Although the tokeniser will need to work a little differently by maintaining > the positions of all tokens within the line, information that is usually > discarded. Pretty much, yes. It's going to end up basically in the same place, though: 1) Parse the code, keeping all the non-essential parts as well as the essential parts. 2) Find the comments, or find the annotations 3) If comments, figure out if they're the ones you want to remove. 4) Reconstruct the file without the bits you want to remember. Step 3 is removed if you're using syntactic annotations. Otherwise, they're identical. ChrisA From tkadm30 at yandex.com Mon Jun 18 08:18:13 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Mon, 18 Jun 2018 08:18:13 -0400 Subject: A quick question for you! Message-ID: <6060aa7a-7b2a-94cb-228e-d40c974a597e@yandex.com> Hi, Quick question: Does anyone of you know what is the effect of enabling gc.enable() in sitecustomize.py when using PyPy? Can it reduce latency for long-lived WSGI applications? Thanks, Etienne -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From e+python-list at kellett.im Mon Jun 18 08:46:42 2018 From: e+python-list at kellett.im (Ed Kellett) Date: Mon, 18 Jun 2018 13:46:42 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: On 2018-06-18 13:18, Chris Angelico wrote: > 1) Parse the code, keeping all the non-essential parts as well as the > essential parts. > 2) Find the comments, or find the annotations > 3) If comments, figure out if they're the ones you want to remove. > 4) Reconstruct the file without the bits you want to remember. > > Step 3 is removed if you're using syntactic annotations. Otherwise, > they're identical. It's likely that Python comments are much easier to remove than arbitrary bits of Python syntax--you need to know the answer to "am I in a string literal?", which is a lexical analysis problem you could hack together a solution for over the course of about one coffee, as opposed to "where exactly am I in the Python parse tree?", which is... harder. The information you need to keep track of and later reconstruct is substantially simpler, too. I don't think "they're hard to mechanically remove" is a particularly good argument against type hints, but considered on its own it probably is true. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From rosuav at gmail.com Mon Jun 18 09:02:12 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2018 23:02:12 +1000 Subject: Is it possible to call a class but without a new instance created? In-Reply-To: <0a8a26ba-37dc-3c30-219a-2f050e68eabd@telenet.be> References: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> <0a8a26ba-37dc-3c30-219a-2f050e68eabd@telenet.be> Message-ID: On Mon, Jun 18, 2018 at 5:17 PM, Vincent Vande Vyvre wrote: > What you try to do is called a /singleton./ In this case, not necessarily a singleton, but returning a cached object that's the same for any given argument. Basically, interned objects. But yes, the same idea. ChrisA From __peter__ at web.de Mon Jun 18 09:16:10 2018 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 Jun 2018 15:16:10 +0200 Subject: Python list vs google group References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <201806160435.46723.gheskett@shentel.net> Message-ID: Gene Heskett wrote: > This biggest single thing wrong with any of those old scsi interfaces is > the bus's 5 volt isolation diode, the designer speced a shotkey(sp) > diode, and some damned bean counter saw the price diff and changed it to Is this a case of ? https://en.wikipedia.org/wiki/Walter_H._Schottky From gheskett at shentel.net Mon Jun 18 09:36:12 2018 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 18 Jun 2018 09:36:12 -0400 Subject: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <201806160435.46723.gheskett@shentel.net> Message-ID: <201806180936.12286.gheskett@shentel.net> On Monday 18 June 2018 09:16:10 Peter Otten wrote: > Gene Heskett wrote: > > This biggest single thing wrong with any of those old scsi > > interfaces is the bus's 5 volt isolation diode, the designer speced > > a shotkey(sp) diode, and some damned bean counter saw the price diff > > and changed it to > > Is this a case of ? > > https://en.wikipedia.org/wiki/Walter_H._Schottky So its spelled with two t's. Concentrating on my spelling mistake, you probably missed my point entirely. But then you are not a CET either so the rest of my explanation may not have been in reach as it passed by at a pretty good technical altitude. Sigh... -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From __peter__ at web.de Mon Jun 18 09:59:58 2018 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 Jun 2018 15:59:58 +0200 Subject: Technical altitude, was Re: Python list vs google group References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <201806160435.46723.gheskett@shentel.net> <201806180936.12286.gheskett@shentel.net> Message-ID: Gene Heskett wrote: > On Monday 18 June 2018 09:16:10 Peter Otten wrote: > >> Gene Heskett wrote: >> > This biggest single thing wrong with any of those old scsi >> > interfaces is the bus's 5 volt isolation diode, the designer speced >> > a shotkey(sp) diode, and some damned bean counter saw the price diff >> > and changed it to >> >> Is this a case of ? >> >> https://en.wikipedia.org/wiki/Walter_H._Schottky > > So its spelled with two t's. > > Concentrating on my spelling mistake, you probably missed my point > entirely. But then you are not a CET either so the rest of my > explanation may not have been in reach as it passed by at a pretty good > technical altitude. Sigh... > I'm doomed. Right? :) Other than that I find it hard to believe that a "bean counter" can change a technical spec. He may put pressure on the designer, but when the designer gives in he's still responsible for the resulting technical problems. From steve+comp.lang.python at pearwood.info Mon Jun 18 10:03:53 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 18 Jun 2018 14:03:53 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: On Sun, 17 Jun 2018 12:07:14 -0700, Jim Lee wrote: > IMHO, trying to shoehorn static type checking on top of a dynamically > typed language shows that the wrong language was chosen for the job. The experience of computer languages like Lisp, Smalltalk/StrongTalk, Erlang, Racket, Javascript variant Typescript, and PHP variant Hack (to mention only a few) shows that type hinting on top of dynamic languages can and does work very well. As a human programmer, you surely perform your own ad hoc type checking when you write and debug code. When reading a function like this: # from the calender.py module in the standard library def isleap(year): """Return True for leap years, False for non-leap years.""" return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) naturally you reason that year is probably an integer, not a list of strings, and if you see code call: isleap("hello") you almost certainly realise it will fail without needing to run the code. Having an automated checker or linter do something similar is neither rocket science, nor against the spirit of dynamic typing. Linters have done some type-checking for many years. One popular convention was Sphinx-based type annotations in docstrings: http://www.pydev.org/manual_adv_type_hints.html Across the programming language landscape, dynamic languages are adding static features, and static languages are adding dynamic features: http://steve-yegge.blogspot.com/2008/05/dynamic-languages-strike-back.html Since Steve Yegge gave that talk, the process has only accelerated, driven by both practical experience with gradual typing and a lot of academic research. PySonar has been successfully used by Google for close on a decade: https://yinwang0.wordpress.com/2010/09/12/pysonar/ and MyPy has also been very successful: http://mypy-lang.org/ particular at DropBox, which is (I believe) funding a lot of Guido's time on this, because they need it. It is 2018. People who say that static typing cannot be integrated with dynamic languages are nearly half a century behind the state of the art in computer programming. (As an industry, the programming community is *painfully* conservative. Things which Lisp was doing in the 1950s are *still* not mainstream, and most programmers do not even imagine they are possible.) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jun 18 10:08:17 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 18 Jun 2018 14:08:17 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <87wouwz44m.fsf@elektro.pacujo.net> Message-ID: On Mon, 18 Jun 2018 15:11:05 +0300, Marko Rauhamaa wrote: [...] > So the point *was* popularity!? I suspected as much. Presumably you missed the invisible sarcasm tags. As well as the point that despite all the "type annotation is killing Python" FUD from certain corners of the Python community, Python is not only alive and well, but actually growing in popularity according to (as far as I can see) all the well-known measures of language popularity. Personally I don't think that type annotations are specifically driving that increase in popularity, but there is no evidence that they are harming it. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From greg.ewing at canterbury.ac.nz Mon Jun 18 10:08:44 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 19 Jun 2018 02:08:44 +1200 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: Bart wrote: > I can remove comments by writing a tokeniser which scans Python source > and re-outputs tokens one at a time. Such a tokeniser normally ignores > comments. What was being talked about wasn't removing *all* comments, but removing just the ones that contain type hints. > But to remove type hints, a deeper understanding of the input is needed. > I would need a parser rather than a tokeniser. Fortunately, Python comes with a parser for Python built in (the ast module). So you get quite a good head start. -- Greg From steve+comp.lang.python at pearwood.info Mon Jun 18 10:21:37 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 18 Jun 2018 14:21:37 +0000 (UTC) Subject: Technical altitude, was Re: Python list vs google group References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <201806160435.46723.gheskett@shentel.net> <201806180936.12286.gheskett@shentel.net> Message-ID: On Mon, 18 Jun 2018 15:59:58 +0200, Peter Otten wrote: > Other than that I find it hard to believe that a "bean counter" can > change a technical spec. He may put pressure on the designer, but when > the designer gives in he's still responsible for the resulting technical > problems. Surely it depends on how dysfunctional the organisation is, and whether or not they are answerable to independent standards. Ultimately, the engineers answer to management, and if management treat them as drones that have to do what they're told instead of experts that can make decisions for themselves, anything is possible. When you hear of technical disasters like tens of thousands of cars having to be recalled, or laptop batteries catching fire, or similar problems, we almost never find out whether this was an unavoidable failure, a technical mistake by the designers, or a case of managerial interference. Fortunately I've avoided having to work in that sort of environment, but my wife used to work in the entertainment industry where that sort of managerial interference is the rule, not the exception. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jun 18 10:32:50 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 18 Jun 2018 14:32:50 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: Further to my earlier comments... On Sun, 17 Jun 2018 12:07:14 -0700, Jim Lee wrote: > IMHO, trying to shoehorn static type checking on top of a dynamically > typed language shows that the wrong language was chosen for the job. Relevant: http://lambda-the-ultimate.org/node/1519 and this quote is extremely pertinent: Giving people a dynamically-typed language does not mean that they write dynamically-typed programs. -- John Aycock Lots of people have observed that *nearly all* real Python code is much less dynamic than the language allows. When you call "len(x)", the compiler has to resolve the name "len" at runtime in case it has been monkey-patched or shadowed, but in practice that hardly ever happens. Moving the type-checking out of the core language into the IDE or linter which can be used or not used according to the desire of the programmer is an elegant (partial) solution to the problem that testing can never demonstrate the absence of bugs, only their presence, without compromising on the full range of dynamic programming available to those who want it. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From grant.b.edwards at gmail.com Mon Jun 18 10:36:15 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 18 Jun 2018 14:36:15 +0000 (UTC) Subject: Why an object changes its "address" between adjacent calls? References: <445dbeb0-7851-f572-250d-e3654297b663@ms4.hinet.net> Message-ID: On 2018-06-17, Jach Fong wrote: > C:\Python34\Doc>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. > >>> import tkinter as tk > >>> root = tk.Tk() > >>> tk.Label(root, text='label one', font='TkDefaultFont').pack() > >>> from tkinter import font > >>> font.nametofont('TkDefaultFont') > > >>> font.nametofont('TkDefaultFont') > > >>> > > The "address" of the Font object 'TkDefaultFont' changes, why? What makes you think it's the same object the second time and not a new object? -- Grant Edwards grant.b.edwards Yow! Make me look like at LINDA RONSTADT again!! gmail.com From Joseph.Schachner at Teledyne.com Mon Jun 18 10:57:30 2018 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Mon, 18 Jun 2018 14:57:30 +0000 Subject: syntax difference (type hints) Message-ID: <2507028f7e4a4c2ca497f7dd48a529db@Teledyne.com> Assuming that we want Python to remain a dynamically typed (but strongly typed) language, I believe the proposed type hints are only necessary for function definitions, where the caller really needs to know the types of arguments to pass in. At the moment that purpose is (I think adequately) served by def strings, triple quoted strings immediately following the function declaration. When I do code reviews for Python developed here, if the argument names of a function do not hint at the type they should be and there is no def string then I insist that something be added. Often what gets added is a def string that says something about what the function does and explains what argument types are expected. -- Joseph S. -----Original Message----- From: Ed Kellett Sent: Monday, June 18, 2018 8:47 AM To: python-list at python.org Subject: Re: syntax difference On 2018-06-18 13:18, Chris Angelico wrote: > 1) Parse the code, keeping all the non-essential parts as well as the > essential parts. > 2) Find the comments, or find the annotations > 3) If comments, figure out if they're the ones you want to remove. > 4) Reconstruct the file without the bits you want to remember. > > Step 3 is removed if you're using syntactic annotations. Otherwise, > they're identical. It's likely that Python comments are much easier to remove than arbitrary bits of Python syntax--you need to know the answer to "am I in a string literal?", which is a lexical analysis problem you could hack together a solution for over the course of about one coffee, as opposed to "where exactly am I in the Python parse tree?", which is... harder. The information you need to keep track of and later reconstruct is substantially simpler, too. I don't think "they're hard to mechanically remove" is a particularly good argument against type hints, but considered on its own it probably is true. From Joseph.Schachner at Teledyne.com Mon Jun 18 10:58:29 2018 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Mon, 18 Jun 2018 14:58:29 +0000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: <6ab498a04aa9455785c4df954354671e@Teledyne.com> As soon as I sent the previous message I realized it's "doc string" not def string. Pardon me. --- Joe S. -----Original Message----- From: Ed Kellett Sent: Monday, June 18, 2018 8:47 AM To: python-list at python.org Subject: Re: syntax difference On 2018-06-18 13:18, Chris Angelico wrote: > 1) Parse the code, keeping all the non-essential parts as well as the > essential parts. > 2) Find the comments, or find the annotations > 3) If comments, figure out if they're the ones you want to remove. > 4) Reconstruct the file without the bits you want to remember. > > Step 3 is removed if you're using syntactic annotations. Otherwise, > they're identical. It's likely that Python comments are much easier to remove than arbitrary bits of Python syntax--you need to know the answer to "am I in a string literal?", which is a lexical analysis problem you could hack together a solution for over the course of about one coffee, as opposed to "where exactly am I in the Python parse tree?", which is... harder. The information you need to keep track of and later reconstruct is substantially simpler, too. I don't think "they're hard to mechanically remove" is a particularly good argument against type hints, but considered on its own it probably is true. From rantingrickjohnson at gmail.com Mon Jun 18 11:10:12 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 08:10:12 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <3c7bbf63-95f1-4c8c-8aa3-fb15e14e55a0@googlegroups.com> Message-ID: Chris Angelico wrote: [...] > What was the quote before that? > > > "Type-hint comments" would allow: > > (3) and those who utterly *HATE* them, to write a simpl[e] > > little function which will strip them from any and all > > source code they might be forced to maintain. > > Put up or shut up. Write something that strips all type > hint comments. "Type-hint comments" don't exist yet. They are only theoretical at this point. Now stop distracting, and let's see your code! From rantingrickjohnson at gmail.com Mon Jun 18 11:21:18 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 08:21:18 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> <907b56cc-1961-c28a-6de7-42febe5556c5@gmail.com> <7bfdc89d-e354-28f0-f840-0f346cbdd47f@gmail.com> Message-ID: Jim Lee wrote: > Chris wrote: > > > > I said that you can't decry changes that were before > > your time (they're simply the way things are). > > Really? Wow. I'd hate to live in your world! Just > because something exists, it can't be challenged or > questioned. Got it! Chris is a good choir boy. He consistently ranks a perfect 10 out 10 on parochial surveys. From D.Strohl at F5.com Mon Jun 18 11:26:43 2018 From: D.Strohl at F5.com (Dan Strohl) Date: Mon, 18 Jun 2018 15:26:43 +0000 Subject: syntax difference (type hints) In-Reply-To: <2507028f7e4a4c2ca497f7dd48a529db@Teledyne.com> References: <2507028f7e4a4c2ca497f7dd48a529db@Teledyne.com> Message-ID: > -----Original Message----- > From: Python-list On > Behalf Of Schachner, Joseph > Sent: Monday, June 18, 2018 7:58 AM > To: Ed Kellett ; python-list at python.org > Subject: RE: syntax difference (type hints) > > EXTERNAL MAIL: python-list-bounces+d.strohl=f5.com at python.org > > Assuming that we want Python to remain a dynamically typed (but strongly > typed) language, I believe the proposed type hints are only necessary for > function definitions, where the caller really needs to know the types of > arguments to pass in. At the moment that purpose is (I think adequately) > served by def strings, triple quoted strings immediately following the function > declaration. When I do code reviews for Python developed here, if the > argument names of a function do not hint at the type they should be and there > is no def string then I insist that something be added. Often what gets added > is a def string that says something about what the function does and explains > what argument types are expected. > > -- Joseph S. > I like having the option to add type hints to various things, including functions, but also classes, and the methods, and attributes of a class. While I don't add them to every one of these every time, if I write a function that I expect to be used by someone else, I will annotate it. Similarly, if I write a class that I expect to be instantiated or sub-classed as part of a library, I will annotate that as well, including any attributes that I expect to be used or changed. I haven't totally utilized the new type hinting yet, I am still often still documenting in the triple quoted strings using epytext type hinting, but that doesn't really handle things like "a list of strings", or even worse, " a dictionary that looks like dict("key1":1, "key2":"foobar") in a "standard" way (that I have found at least), or cases where an argument can be a string OR an int, or a list. (I use the string/list option pretty regularly when I have functions that can handle one object, or multiple ones, and I've already used the * to break out something else). I'm looking forward to finding the time to figure out how to best annotate those types of things. And I have found that having these things well annotated does help my IDE (PyCharm) to keep me from making simple mistakes. In the end, I figure that I don't see any real downside to the new type hinting, if I use it, great, if not, that's fine as well. I would certainly not be supportive of making it required in order to compile though. From ian.g.kelly at gmail.com Mon Jun 18 11:38:42 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 18 Jun 2018 09:38:42 -0600 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <3c7bbf63-95f1-4c8c-8aa3-fb15e14e55a0@googlegroups.com> Message-ID: On Mon, Jun 18, 2018 at 9:17 AM Rick Johnson wrote: > > Chris Angelico wrote: > [...] > > What was the quote before that? > > > > > "Type-hint comments" would allow: > > > (3) and those who utterly *HATE* them, to write a simpl[e] > > > little function which will strip them from any and all > > > source code they might be forced to maintain. > > > > Put up or shut up. Write something that strips all type > > hint comments. > > "Type-hint comments" don't exist yet. They are only > theoretical at this point. Now stop distracting, and let's > see your code! Uh, yes, they do. They're defined in PEP 484, and Mypy uses them for type-checking Python 2 code, where the annotations don't exist. https://mypy.readthedocs.io/en/stable/python2.html?highlight=comment#type-checking-python-2-code From pfeiffer at cs.nmsu.edu Mon Jun 18 11:45:45 2018 From: pfeiffer at cs.nmsu.edu (Joe Pfeiffer) Date: Mon, 18 Jun 2018 09:45:45 -0600 Subject: Python list vs google group References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <201806160435.46723.gheskett@shentel.net> Message-ID: <1befh4dro6.fsf@pfeifferfamily.net> Peter Otten <__peter__ at web.de> writes: > Gene Heskett wrote: > >> This biggest single thing wrong with any of those old scsi interfaces is >> the bus's 5 volt isolation diode, the designer speced a shotkey(sp) >> diode, and some damned bean counter saw the price diff and changed it to > > Is this a case of ? > > https://en.wikipedia.org/wiki/Walter_H._Schottky I'm missing why the claim that management changed the spec on a diode from Schottky to conventional would be folk etymology? Or why Gene being unsure of his spelling would? What does any of this have to do with etymology, folk or genuine? From rantingrickjohnson at gmail.com Mon Jun 18 11:48:12 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 08:48:12 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: <51aeb257-f587-402b-bd2d-faba481ae5eb@googlegroups.com> On Monday, June 18, 2018 at 5:45:28 AM UTC-5, Chris Angelico wrote: > So in both cases, you would probably end up with something > like 2to3. And there you have it! Just Like Python3000, the python devs have caused a major disruption by saddling us with the syntactic noise of type- hints. Therefore, _they_ are responsible for producing a tool which will remove these type-hints from scripts and do it error _free_. So petition your friends over at py-dev and get the ball rolling, would ya pal? And the great news is, after they release this tool, myself, and all the other folks who have been blindsided by a special purpose feature can no longer complain. Nope. And you will _finally_ have the moral high ground when you brow beat others for daring to protest. That's right Chris! We will quietly run the tool on all the type-hint scripts we encounter and then we will be as content as you. Why can't we _all_ be happy little clams just like you? Hmm? Is that really too much to ask? From ian.g.kelly at gmail.com Mon Jun 18 11:48:22 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 18 Jun 2018 09:48:22 -0600 Subject: syntax difference (type hints) In-Reply-To: <2507028f7e4a4c2ca497f7dd48a529db@Teledyne.com> References: <2507028f7e4a4c2ca497f7dd48a529db@Teledyne.com> Message-ID: FYI, Python type hints aren't "proposed"; they're already here. The function annotation syntax was added in 3.0, without any imposition of semantic meaning or requirements on it, and allowed to simmer for several years for third-party frameworks to find uses for. Python 3.5 added the typing module to support type hinting in the style of Mypy without any further language changes. Most recently, Python 3.6 added syntax for annotating variables in addition to functions. All of these things are already fully available in modern Python. On Mon, Jun 18, 2018 at 9:05 AM Schachner, Joseph wrote: > > Assuming that we want Python to remain a dynamically typed (but strongly typed) language, I believe the proposed type hints are only necessary for function definitions, where the caller really needs to know the types of arguments to pass in. At the moment that purpose is (I think adequately) served by def strings, triple quoted strings immediately following the function declaration. When I do code reviews for Python developed here, if the argument names of a function do not hint at the type they should be and there is no def string then I insist that something be added. Often what gets added is a def string that says something about what the function does and explains what argument types are expected. > > -- Joseph S. > > -----Original Message----- > From: Ed Kellett > Sent: Monday, June 18, 2018 8:47 AM > To: python-list at python.org > Subject: Re: syntax difference > > On 2018-06-18 13:18, Chris Angelico wrote: > > 1) Parse the code, keeping all the non-essential parts as well as the > > essential parts. > > 2) Find the comments, or find the annotations > > 3) If comments, figure out if they're the ones you want to remove. > > 4) Reconstruct the file without the bits you want to remember. > > > > Step 3 is removed if you're using syntactic annotations. Otherwise, > > they're identical. > > It's likely that Python comments are much easier to remove than arbitrary bits of Python syntax--you need to know the answer to "am I in a string literal?", which is a lexical analysis problem you could hack together a solution for over the course of about one coffee, as opposed to "where exactly am I in the Python parse tree?", which is... harder. > The information you need to keep track of and later reconstruct is substantially simpler, too. > > I don't think "they're hard to mechanically remove" is a particularly good argument against type hints, but considered on its own it probably is true. > > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Mon Jun 18 11:51:45 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2018 01:51:45 +1000 Subject: syntax difference (type hints) In-Reply-To: <2507028f7e4a4c2ca497f7dd48a529db@Teledyne.com> References: <2507028f7e4a4c2ca497f7dd48a529db@Teledyne.com> Message-ID: On Tue, Jun 19, 2018 at 12:57 AM, Schachner, Joseph wrote: > Assuming that we want Python to remain a dynamically typed (but strongly typed) language, I believe the proposed type hints are only necessary for function definitions, where the caller really needs to know the types of arguments to pass in. At the moment that purpose is (I think adequately) served by def strings, triple quoted strings immediately following the function declaration. When I do code reviews for Python developed here, if the argument names of a function do not hint at the type they should be and there is no def string then I insist that something be added. Often what gets added is a def string that says something about what the function does and explains what argument types are expected. > (The official term is "docstring", and you can find some specifics on them in PEP 257.) What you're doing is all very well, but it isn't very machine-readable. Type hints as defined in PEP 3107 and 484 are designed to be understood by linters and autocompletion tools and the like. And once you have the machine-readable, you should be able to leave off any type information in the purely-human-readable parts of documentation. ChrisA From grant.b.edwards at gmail.com Mon Jun 18 12:10:32 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 18 Jun 2018 16:10:32 +0000 (UTC) Subject: Python list vs google group References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <201806160435.46723.gheskett@shentel.net> <1befh4dro6.fsf@pfeifferfamily.net> Message-ID: On 2018-06-18, Joe Pfeiffer wrote: > Peter Otten <__peter__ at web.de> writes: > >> Gene Heskett wrote: >> >>> This biggest single thing wrong with any of those old scsi interfaces is >>> the bus's 5 volt isolation diode, the designer speced a shotkey(sp) >>> diode, and some damned bean counter saw the price diff and changed it to >> >> Is this a case of ? >> >> https://en.wikipedia.org/wiki/Walter_H._Schottky > > I'm missing why the claim that management changed the spec on a diode > from Schottky to conventional would be folk etymology? Or why Gene > being unsure of his spelling would? What does any of this have to do > with etymology, folk or genuine? I was wondering the same thing... -- Grant Edwards grant.b.edwards Yow! Half a mind is a at terrible thing to waste! gmail.com From rantingrickjohnson at gmail.com Mon Jun 18 12:11:16 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 09:11:16 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: <20cb0f2f-ca06-411c-84b4-c83b0b276688@googlegroups.com> Chris Angelico wrote: > Bart wrote: [...] > > What will those look like? If copyright/license comments > > have their own specific syntax, then they just become > > another token which has to be recognized. > > If they have specific syntax, they're not comments, are they? Yes, they are. >From the POV of the interpreter, comments are nothing but a human crutch that is to be ignored. And even from the POV of a programmer, comments can be more useful if they are ignored than if they are not. Some programmers lack the skill required to properly explain the workings of an algorithm in natural language, and thus, the reader of such a comment will only become confused. Likewise, comments are notorious for becoming out-of-sync with the code. And at such point, comments are not only _confusing_ or _misleading_, no, they have become _lies_. The point is, from the POV of the interpreter and the programmer. comments are always going to be comments regardless of whether special purpose tools parse them or not. And given a choice between placing a new burden on a programmer or placing that burden on the machine, we should always choose to place that burden on the _machine_. After all, it's the Python way. The beauty of type-hint comments is that even without striping the type-hint comment from the source code, a programmer can more easily ignore a type-hint comment than the interleaved type-hint. This is especially true if the programmer uses an editor which has syntax hilighting. My syntax hilighter colors all comments a light gray. So therefore, i can skip block and blocks of comments in a fraction of second simply by quickly scanning down to the first line that is not grayed out. From ben.usenet at bsb.me.uk Mon Jun 18 12:25:10 2018 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Mon, 18 Jun 2018 17:25:10 +0100 Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: <87efh4xdsp.fsf@bsb.me.uk> Bart writes: > On 18/06/2018 11:45, Chris Angelico wrote: >> On Mon, Jun 18, 2018 at 8:33 PM, Bart wrote: > > >>> You're right in that neither task is that trivial. >>> >>> I can remove comments by writing a tokeniser which scans Python source and >>> re-outputs tokens one at a time. Such a tokeniser normally ignores comments. >>> >>> But to remove type hints, a deeper understanding of the input is needed. I >>> would need a parser rather than a tokeniser. So it is harder. >> >> They would actually both end up the same. To properly recognize >> comments, you need to understand enough syntax to recognize them. To >> properly recognize type hints, you need to understand enough syntax to >> recognize them. And in both cases, you need to NOT discard important >> information like consecutive whitespace. > > No. If syntax is defined on top of tokens, then at the token level, > you don't need to know any syntax. The process that scans characters > looking for the next token, will usually discard comments. Job done. You don't even need to scan for tokens other than strings. From what I read in the documentation a simple scanner like this would do the trick: %option noyywrap %x sqstr dqstr sqtstr dqtstr %% \' ECHO; BEGIN(sqstr); \" ECHO; BEGIN(dqstr); \'\'\' ECHO; BEGIN(dqtstr); \"\"\" ECHO; BEGIN(dqtstr); \" | \' | \'\'\' | \"\"\" ECHO; BEGIN(INITIAL); \\\' | \\\" | . ECHO; #.* %% int main(void) { yylex(); } and it's only this long because there are four kinds of string. Not being a Python expert, there may be some corner case errors. And really there are comments that should not be removed such as #! on line 1 and encoding declarations, but they would just need another line or two. -- Ben. From rantingrickjohnson at gmail.com Mon Jun 18 12:37:18 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 09:37:18 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> Message-ID: <4c0b26c3-54b0-420a-b004-b63e740ce043@googlegroups.com> On Monday, June 18, 2018 at 6:43:36 AM UTC-5, Steven D'Aprano wrote: > The programmer can ignore [type-hints], just as they can > ignore any other form of documentation. Type-hints, as implemented, break all the rules of conventional documentation. In any programming language i have ever seen, formal documentation elements such as documentation strings and comments do not _interleave_ themselves with executable code, no, they are forced to isolate themselves on entire lines, or, the tail ends of lines. For instance, i have never seem a dynamic programming language that did anything like the following: def foo(): for k,v in d: print(k, v) Have you??? Maybe i'm crazy, but i would prefer to have my _documentation_ and executable-code separated from one another. def foo(): # Iterate over the keys of d # k: string # v: integer # d: dict (duh!) for k,v in d: print(k, v) # That was builtin! > Nobody is stopping you from writing: > > result = function(the_string=42.5) Steven, that's an example of "self-documenting names" not "documentation". I'm sorry, but you are terribly confused if you cannot understand the non-subtle difference between these two concepts. > [we do it] Just to annoy you. You're also terribly confused if you believe i'm the only person in this community who is opposed to the current implementation of type-hints. Remember, i'm not advocating that type-hints be removed completely (the train has left the station). I'm only requesting that one of the following be done to _alleviate_ the burden of their poorly executed implementation: (1) Re-implement type-hints as a comment. (2) Provide a tool that will remove type-hints from scripts error free. Is that _really_ too much to ask? From rantingrickjohnson at gmail.com Mon Jun 18 12:39:21 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 09:39:21 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> Message-ID: <396bc2be-ff08-4d4b-8e52-c3557d8a3fbc@googlegroups.com> On Monday, June 18, 2018 at 6:57:27 AM UTC-5, Steven D'Aprano wrote: > I still think that Python has been going nowhere but downhill ever since > extended slicing was added in version 1.4. Apples to oranges! From __peter__ at web.de Mon Jun 18 12:41:36 2018 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 Jun 2018 18:41:36 +0200 Subject: Folk etymology, was Re: Python list vs google group References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <201806160435.46723.gheskett@shentel.net> <1befh4dro6.fsf@pfeifferfamily.net> Message-ID: Grant Edwards wrote: > On 2018-06-18, Joe Pfeiffer wrote: >> Peter Otten <__peter__ at web.de> writes: >> >>> Gene Heskett wrote: >>> >>>> This biggest single thing wrong with any of those old scsi interfaces >>>> is the bus's 5 volt isolation diode, the designer speced a shotkey(sp) >>>> diode, and some damned bean counter saw the price diff and changed it >>>> to >>> >>> Is this a case of ? >>> >>> https://en.wikipedia.org/wiki/Walter_H._Schottky >> >> I'm missing why the claim that management changed the spec on a diode >> from Schottky to conventional would be folk etymology? Or why Gene >> being unsure of his spelling would? What does any of this have to do >> with etymology, folk or genuine? > > I was wondering the same thing... "folk etymology" would be the retrofitting of the exotic "Schottky" into two familiar words "shot" and "key". Sometimes the writer assumes that these words are somehow related to the labeled object. The best known example in German is Maulwurf ("mouth throw" for mole) leading to the (false) idea that moles use their mouth to build mole hills. From rantingrickjohnson at gmail.com Mon Jun 18 12:50:28 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 09:50:28 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: Bart wrote: [...] > For example, comments that start with #T# (and in my case, > that begin at the start of a line). Such would be a _breeze_ to parse out. And i would argue (given a sufficiently unique tag) that arbitrary white space would not be any more error prone, either. Thus, your "tagged comments" would be much more readable as they will match the current block indentation and not be smashed against the left most column. "Readability counts!". From rantingrickjohnson at gmail.com Mon Jun 18 13:01:58 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 10:01:58 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: Steven D'Aprano wrote: [...] > particular at DropBox, which is (I believe) funding a lot of Guido's time > on this, because they need it. And now we get to the truth! Guido's new puppet master is the sole reason why this fine community -- of once free-roaming *STALLIONS*-- is now corralled and saddled with type-hints! And we thoughts _google_ was evil. o_O From e+python-list at kellett.im Mon Jun 18 13:07:00 2018 From: e+python-list at kellett.im (Ed Kellett) Date: Mon, 18 Jun 2018 18:07:00 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: <99e44e00-78e5-a119-ca7d-7c7a861f6053@kellett.im> are you someone's ironic 3rd-year art project -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From rantingrickjohnson at gmail.com Mon Jun 18 13:09:11 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 10:09:11 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <87wouwz44m.fsf@elektro.pacujo.net> Message-ID: <30688a13-b497-4dfe-aae2-89ca81a31c6a@googlegroups.com> Steven D'Aprano said: > Python is not only alive and well, but actually growing in > popularity according to (as far as I can see) all the well- > known measures of language popularity. Steven *ALSO* said: > "Ever since I learned about confirmation bias, I've been > seeing it everywhere." Hmm? From rantingrickjohnson at gmail.com Mon Jun 18 13:15:37 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 10:15:37 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: <7a50b232-0c22-4232-b1f7-c97deb6ab82e@googlegroups.com> Steven D'Aprano wrote: > Moving the type-checking out of the core language into the > IDE or linter which can be used or not used according to > the desire of the programmer Except, what your poppycock commentary seems to glaze over is the fact that whilst a programmer can certainly decided to "use or not use" the type-hints feature in his or her own code, he or she certainly cannot "see or _unsee_" type-hints that are written by other programmers. From rantingrickjohnson at gmail.com Mon Jun 18 13:21:11 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 10:21:11 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <3c7bbf63-95f1-4c8c-8aa3-fb15e14e55a0@googlegroups.com> Message-ID: <079d24f4-949a-4117-a428-f06ef3adc420@googlegroups.com> Ian wrote: > Uh, yes, they do. They're defined in PEP 484, and Mypy uses them for > type-checking Python 2 code, where the annotations don't exist. So when will the interleaved type-hints be removed from the language specification? From jlee54 at gmail.com Mon Jun 18 13:34:54 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 18 Jun 2018 10:34:54 -0700 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> On 06/18/2018 07:03 AM, Steven D'Aprano wrote: > As a human programmer, you surely perform your own ad hoc type checking > when you write and debug code. Of course.? And, I use linting tools and other forms of static type checking.? What I don't like is adding the *syntax* for static type checking to the (dynamically typed) language proper, particularly when the implementations of said language do nothing but ignore it. The syntax should be defined inside comments, by the tools that actually need to use them.? Let the tools do what they were designed to do.? Let the language do what it was designed to do. If static type checking were a high priority, I would not choose a language like Python for the task - but some people seem to want to beat the language into submission as a do-everything-but-wash-my-car solution; and in so doing, the language becomes so fragile and bloated that people will walk away from it. In reading through many of the PEPs, I'm reminded of the saying, "If all you have is a hammer, everything looks like a nail". -Jim From rosuav at gmail.com Mon Jun 18 13:46:09 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2018 03:46:09 +1000 Subject: syntax difference In-Reply-To: <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> Message-ID: On Tue, Jun 19, 2018 at 3:34 AM, Jim Lee wrote: > > > On 06/18/2018 07:03 AM, Steven D'Aprano wrote: >> >> As a human programmer, you surely perform your own ad hoc type checking >> when you write and debug code. > > Of course. And, I use linting tools and other forms of static type > checking. What I don't like is adding the *syntax* for static type checking > to the (dynamically typed) language proper, particularly when the > implementations of said language do nothing but ignore it. So you have annotations for type information. Tell me: why should these annotations be introduced with a hash and ended with a newline? What is it about type annotations that requires that they be delimited in this way? What about assertions? Are they comments too? Should we have, for instance: if x > 0: ... elif x < 0: ... else: #assert: x == 0 ... or is it better to use an 'assert' statement? After all, they can legitimately be ignored by the interpreter. ChrisA From ian.g.kelly at gmail.com Mon Jun 18 14:01:20 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 18 Jun 2018 12:01:20 -0600 Subject: syntax difference In-Reply-To: <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> Message-ID: On Mon, Jun 18, 2018 at 11:39 AM Jim Lee wrote: > On 06/18/2018 07:03 AM, Steven D'Aprano wrote: > > As a human programmer, you surely perform your own ad hoc type checking > > when you write and debug code. > Of course. And, I use linting tools and other forms of static type > checking. What I don't like is adding the *syntax* for static type > checking to the (dynamically typed) language proper, particularly when > the implementations of said language do nothing but ignore it. > > The syntax should be defined inside comments, by the tools that actually > need to use them. Let the tools do what they were designed to do. Let > the language do what it was designed to do. If you want to use a type checking tool that uses type comments, then by all means do so. The existence of annotation syntax in no way prevents that. When PEP 3107 was written, it was anticipated that annotations would find more uses than just type hinting. Some of those proposed ideas (e.g. database query mapping) depend on the annotation being readable at run-time, for which a comment would be wholly inadequate. In practice, I don't think that has really been borne out. Still, the intention was to make the language more flexible, not just to cram in type hinting, and I don't think that was necessarily a bad idea. PEP 484 was created out of the observation that the community of static type analysis tools that has grown out of PEP 3107 would benefit from a common dialect of types. All it does is provide that. Neither of these are forcing you to use a type checker that requires annotations for type hints rather than comments, if that's what you prefer. The annotation-based checker is probably a fair bit easier to build from the maintainer's standpoint, though, since it can rely on existing parsing tools and the typing module. From jlee54 at gmail.com Mon Jun 18 14:09:58 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 18 Jun 2018 11:09:58 -0700 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> Message-ID: On 06/18/2018 10:46 AM, Chris Angelico wrote: > On Tue, Jun 19, 2018 at 3:34 AM, Jim Lee wrote: >> >> On 06/18/2018 07:03 AM, Steven D'Aprano wrote: >>> As a human programmer, you surely perform your own ad hoc type checking >>> when you write and debug code. >> Of course. And, I use linting tools and other forms of static type >> checking. What I don't like is adding the *syntax* for static type checking >> to the (dynamically typed) language proper, particularly when the >> implementations of said language do nothing but ignore it. > So you have annotations for type information. Tell me: why should > these annotations be introduced with a hash and ended with a newline? > What is it about type annotations that requires that they be delimited > in this way? Uhhh....because that's mostly the definition of a comment?? Duh! > What about assertions? Are they comments too? Should we have, for instance: > > if x > 0: > ... > elif x < 0: > ... > else: > #assert: x == 0 > ... > > or is it better to use an 'assert' statement? After all, they can > legitimately be ignored by the interpreter. > > ChrisA I'm noticing a pattern here.? Can we stick to the subject at hand? -Jim From rosuav at gmail.com Mon Jun 18 14:18:06 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2018 04:18:06 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> Message-ID: On Tue, Jun 19, 2018 at 4:09 AM, Jim Lee wrote: > > > On 06/18/2018 10:46 AM, Chris Angelico wrote: >> >> On Tue, Jun 19, 2018 at 3:34 AM, Jim Lee wrote: >>> >>> >>> On 06/18/2018 07:03 AM, Steven D'Aprano wrote: >>>> >>>> As a human programmer, you surely perform your own ad hoc type checking >>>> when you write and debug code. >>> >>> Of course. And, I use linting tools and other forms of static type >>> checking. What I don't like is adding the *syntax* for static type >>> checking >>> to the (dynamically typed) language proper, particularly when the >>> implementations of said language do nothing but ignore it. >> >> So you have annotations for type information. Tell me: why should >> these annotations be introduced with a hash and ended with a newline? >> What is it about type annotations that requires that they be delimited >> in this way? > > Uhhh....because that's mostly the definition of a comment? Duh! Yes, that's the definition of a comment. What is it about type annotations that requires them to be comments? Please explain. >> What about assertions? Are they comments too? Should we have, for >> instance: >> >> if x > 0: >> ... >> elif x < 0: >> ... >> else: >> #assert: x == 0 >> ... >> >> or is it better to use an 'assert' statement? After all, they can >> legitimately be ignored by the interpreter. >> >> ChrisA > > > I'm noticing a pattern here. Can we stick to the subject at hand? Yes, but probably not the same pattern you are. What, fundamentally, is the difference between type hints and assertions, such that - in your view - one gets syntax and the other is just comments? ChrisA From jlee54 at gmail.com Mon Jun 18 14:21:59 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 18 Jun 2018 11:21:59 -0700 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> Message-ID: On 06/18/2018 11:01 AM, Ian Kelly wrote: > On Mon, Jun 18, 2018 at 11:39 AM Jim Lee wrote: >> On 06/18/2018 07:03 AM, Steven D'Aprano wrote: >>> As a human programmer, you surely perform your own ad hoc type checking >>> when you write and debug code. >> Of course. And, I use linting tools and other forms of static type >> checking. What I don't like is adding the *syntax* for static type >> checking to the (dynamically typed) language proper, particularly when >> the implementations of said language do nothing but ignore it. >> >> The syntax should be defined inside comments, by the tools that actually >> need to use them. Let the tools do what they were designed to do. Let >> the language do what it was designed to do. > If you want to use a type checking tool that uses type comments, then > by all means do so. The existence of annotation syntax in no way > prevents that. No, but it adds an awful lot of functionally inert noise to live code. > When PEP 3107 was written, it was anticipated that annotations would > find more uses than just type hinting. Some of those proposed ideas > (e.g. database query mapping) depend on the annotation being readable > at run-time, for which a comment would be wholly inadequate. In > practice, I don't think that has really been borne out. Still, the > intention was to make the language more flexible, not just to cram in > type hinting, and I don't think that was necessarily a bad idea. > > PEP 484 was created out of the observation that the community of > static type analysis tools that has grown out of PEP 3107 would > benefit from a common dialect of types. All it does is provide that. > > Neither of these are forcing you to use a type checker that requires > annotations for type hints rather than comments, if that's what you > prefer. The annotation-based checker is probably a fair bit easier to > build from the maintainer's standpoint, though, since it can rely on > existing parsing tools and the typing module. Thanks for the explanation, but it only reinforces my view.? The more entrenched this feature becomes, the more we will see annotation-based tools and, at some point, we will all be forced to used annotations in order to take advantage of the tools. -Jim From jlee54 at gmail.com Mon Jun 18 14:34:40 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 18 Jun 2018 11:34:40 -0700 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> Message-ID: <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> On 06/18/2018 11:18 AM, Chris Angelico wrote: > What, fundamentally, is the difference between type hints and > assertions, such that - in > your view - one gets syntax and the other is just comments? Type hints are just that - hints.? They have no syntactic meaning to the parser, and do not affect the execution path in any way. Therefore, they are effectively and actually comments.? The way they have been implemented, though, causes noise to be interspersed with live code and, as others have said, are difficult to remove or ignore. -Jim From rosuav at gmail.com Mon Jun 18 14:49:51 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2018 04:49:51 +1000 Subject: syntax difference In-Reply-To: <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> Message-ID: On Tue, Jun 19, 2018 at 4:34 AM, Jim Lee wrote: > > > On 06/18/2018 11:18 AM, Chris Angelico wrote: >> >> What, fundamentally, is the difference between type hints and assertions, >> such that - in >> your view - one gets syntax and the other is just comments? > > Type hints are just that - hints. They have no syntactic meaning to the > parser, and do not affect the execution path in any way. Therefore, they are > effectively and actually comments. The way they have been implemented, > though, causes noise to be interspersed with live code and, as others have > said, are difficult to remove or ignore. > I don't know what you mean by "syntactic meaning". Do you mean that they create no executable bytecode, that they have no run-time influence? Because that's not entirely true; they are stored, and can be viewed at run-time. In fact, in optimized mode, assertions produce no bytecode whatsoever; so by that definition, they are more comment-y than annotations are. Do you have some other definition? ChrisA From jlee54 at gmail.com Mon Jun 18 14:55:24 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 18 Jun 2018 11:55:24 -0700 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> Message-ID: <72fd4a64-1f61-29e2-2b51-4a2fd7eace07@gmail.com> On 06/18/2018 11:49 AM, Chris Angelico wrote: > On Tue, Jun 19, 2018 at 4:34 AM, Jim Lee wrote: >> >> On 06/18/2018 11:18 AM, Chris Angelico wrote: >>> What, fundamentally, is the difference between type hints and assertions, >>> such that - in >>> your view - one gets syntax and the other is just comments? >> Type hints are just that - hints. They have no syntactic meaning to the >> parser, and do not affect the execution path in any way. Therefore, they are >> effectively and actually comments. The way they have been implemented, >> though, causes noise to be interspersed with live code and, as others have >> said, are difficult to remove or ignore. >> > I don't know what you mean by "syntactic meaning". Do you mean that > they create no executable bytecode, that they have no run-time > influence? Because that's not entirely true; they are stored, and can > be viewed at run-time. In fact, in optimized mode, assertions produce > no bytecode whatsoever; so by that definition, they are more comment-y > than annotations are. Do you have some other definition? > > ChrisA I'm tired of running around in circles with you, so I will respectfully decline to comment further. -Jim From ian.g.kelly at gmail.com Mon Jun 18 15:25:42 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 18 Jun 2018 13:25:42 -0600 Subject: syntax difference In-Reply-To: <079d24f4-949a-4117-a428-f06ef3adc420@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <3c7bbf63-95f1-4c8c-8aa3-fb15e14e55a0@googlegroups.com> <079d24f4-949a-4117-a428-f06ef3adc420@googlegroups.com> Message-ID: On Mon, Jun 18, 2018 at 11:27 AM Rick Johnson wrote: > > Ian wrote: > > > Uh, yes, they do. They're defined in PEP 484, and Mypy uses them for > > type-checking Python 2 code, where the annotations don't exist. > > So when will the interleaved type-hints be removed from the language specification? These things are unrelated. The comment specification was added to supplement type hints, not replace them. From rantingrickjohnson at gmail.com Mon Jun 18 15:26:22 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 12:26:22 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> Message-ID: <6b9d3ddc-08a0-4ec6-9008-8dc0b0f55404@googlegroups.com> On Monday, June 18, 2018 at 12:46:36 PM UTC-5, Chris Angelico wrote: > What about assertions? Are they comments too? Should we > have, for instance: > > if x > 0: > ... > elif x < 0: > ... > else: > #assert: x == 0 > ... > > or is it better to use an 'assert' statement? After all, > they can legitimately be ignored by the interpreter. (oh my!) Of course they can "easily be ignored", for cryin' out loud, assert statements all begin with the same "syntactical tag"! okay, wait for it... --> assert <-- ^^^^^^ Yep! Which BTW is a _keyword_. (if you didn't know that already) *wink* But please Chris, feel free to bring us your next logical dead end. From rantingrickjohnson at gmail.com Mon Jun 18 15:31:39 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 12:31:39 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> Message-ID: <226f30f1-46b3-45d9-8ab2-b17b84f7ad46@googlegroups.com> On Monday, June 18, 2018 at 1:02:18 PM UTC-5, Ian wrote: [...] > When PEP 3107 was written, it was anticipated that > annotations would find more uses than just type hinting. > Some of those proposed ideas (e.g. database query mapping) > depend on the annotation being readable at run-time, for > which a comment would be wholly inadequate. That's a BS excuse! Any tool can pre-process a python script simply by reading the source from disc before passing it off to the Python interpreter. It's a simple matter of _delegation_. From rantingrickjohnson at gmail.com Mon Jun 18 15:34:43 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 12:34:43 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> Message-ID: On Monday, June 18, 2018 at 1:50:09 PM UTC-5, Chris Angelico wrote: [...] > I don't know what you mean by "syntactic meaning". Do you mean that > they create no executable bytecode, that they have no run-time > influence? Because that's not entirely true; they are stored, and can > be viewed at run-time. So can doc-strings! Ever used the help(...) function? From rosuav at gmail.com Mon Jun 18 15:42:14 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2018 05:42:14 +1000 Subject: syntax difference In-Reply-To: <6b9d3ddc-08a0-4ec6-9008-8dc0b0f55404@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <6b9d3ddc-08a0-4ec6-9008-8dc0b0f55404@googlegroups.com> Message-ID: On Tue, Jun 19, 2018 at 5:26 AM, Rick Johnson wrote: > On Monday, June 18, 2018 at 12:46:36 PM UTC-5, Chris Angelico wrote: > >> What about assertions? Are they comments too? Should we >> have, for instance: >> >> if x > 0: >> ... >> elif x < 0: >> ... >> else: >> #assert: x == 0 >> ... >> >> or is it better to use an 'assert' statement? After all, >> they can legitimately be ignored by the interpreter. > > (oh my!) > > Of course they can "easily be ignored", > > for cryin' out loud, > > assert statements all begin with the same "syntactical > tag"! > > okay, wait for it... > > --> assert <-- > ^^^^^^ > > Yep! > > Which BTW is a _keyword_. > > (if you didn't know that already) *wink* > > But please Chris, feel free to bring us your next logical > dead end. Ahh, yes, it's easy to find the end of an assert statement, too, isn't it? Or are you talking about properly parsing, which - as you miiiiight recall - was my original point? assert """ """", ", ";print('Will I print?');\ "';print("Or will I?");\ ';print("What about me?");'''\ print("And me? Where endeth");"""\ print('the assertion?');\'''' So easy to take shortcuts. So easy to get bitten. Isn't it nice how Python provides proper parsing as a module, though? Except that, oh how terrible, that makes it just as easy to find ALL syntactic elements. ChrisA From ian.g.kelly at gmail.com Mon Jun 18 15:47:59 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 18 Jun 2018 13:47:59 -0600 Subject: syntax difference In-Reply-To: <20cb0f2f-ca06-411c-84b4-c83b0b276688@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <20cb0f2f-ca06-411c-84b4-c83b0b276688@googlegroups.com> Message-ID: On Mon, Jun 18, 2018 at 10:19 AM Rick Johnson wrote: > And even from the POV of a programmer, comments can be more > useful if they are ignored than if they are not. Some > programmers lack the skill required to properly explain the > workings of an algorithm in natural language, and thus, the > reader of such a comment will only become confused. > Likewise, comments are notorious for becoming out-of-sync > with the code. And at such point, comments are not only > _confusing_ or _misleading_, no, they have become _lies_. If this is really your attitude, then I pity anybody who has the misfortune to work with you. If a comment is wrong, the best course of action is to fix it. Not to come to the conclusion that all comments are useless or worse than useless and to therefore swear off reading all comments forever more. As most seasoned programmers would say, the most useful comments are those that explain why, not what or how. What the code does or how it does it can generally be understood just by reading the code. *Why* the code does what it does often cannot. Here's an example of a bad comment: def num_threads(): # Use 10 threads. return 20 We easily see the value is 20, but *should* it be 10 or 20? We don't know. Now here's an example of a useful comment: def num_threads(): # Use 10 threads because the system randomly # locks up at 15 or more. (bug: 12345) return 20 This one makes it clear that whoever increased the value from 10 to 20 wasn't paying attention. The change should likely be reverted. I would also note that none of this applies to type hinting in any case. Type hints don't require the programmer to be able to explain anything in natural language, nor are they prone to becoming out-of-sync. Because if they do, then then the type analyzer will complain the very next time you run it. So if you're trying to make the case for type hints being treated like comments, this isn't it. From rhodri at kynesim.co.uk Mon Jun 18 15:50:43 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 18 Jun 2018 20:50:43 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> Message-ID: <93688f09-d5bb-a866-e781-8ce6189e9e82@kynesim.co.uk> On 18/06/18 19:21, Jim Lee wrote: > Thanks for the explanation, but it only reinforces my view.? The more > entrenched this feature becomes, the more we will see annotation-based > tools and, at some point, we will all be forced to used annotations in > order to take advantage of the tools. So don't take advantage of the tools. They're just tools, and they may be a help for programmers who can't be bothered to figure things out for themselves, but they aren't required by any means. -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Mon Jun 18 15:52:05 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 18 Jun 2018 20:52:05 +0100 Subject: syntax difference In-Reply-To: <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> Message-ID: On 18/06/18 19:34, Jim Lee wrote: > Type hints are just that - hints.? They have no syntactic meaning to the > parser, This is plainly not true, otherwise the parser would be throwing syntax errors at you all the time. Whether they have semantic meaning to the parser is more debatable. -- Rhodri James *-* Kynesim Ltd From bc at freeuk.com Mon Jun 18 16:03:14 2018 From: bc at freeuk.com (Bart) Date: Mon, 18 Jun 2018 21:03:14 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: <6eUVC.491716$Qg7.378011@fx08.am4> On 18/06/2018 15:03, Steven D'Aprano wrote: > It is 2018. People who say that static typing cannot be integrated with > dynamic languages are nearly half a century behind the state of the art > in computer programming. It can be, but it spoils the language. In the case of Python, it is already so big and has so many features crammed in that adding type hints probably makes little difference. I spent a bit of time a decade ago with adding type hints to my own dynamic language. It was done to improve performance, and yes some benchmarks could be double the speed. In the end I got rid of them to keep the language purer, smaller and simpler. Other approaches which don't involve annotating source code (eg. type inference) are better IMO. One problem with them was that, if you said X was an int, you were obliged to check it was int, otherwise bad things could happen if it assumed X was int because you said so, and in reality it wasn't. That checking doesn't help improve performance, which was one aim. -- bart From rosuav at gmail.com Mon Jun 18 16:12:25 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2018 06:12:25 +1000 Subject: syntax difference In-Reply-To: <6eUVC.491716$Qg7.378011@fx08.am4> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: On Tue, Jun 19, 2018 at 6:03 AM, Bart wrote: > In the end I got rid of them to keep the language purer, smaller and > simpler. Other approaches which don't involve annotating source code (eg. > type inference) are better IMO. Inference is great when it works. How do you assist a type inference engine, when it's unable to get all the information it needs? A type system has to either be imperfect, or be an entire executable programming language, or have additional information given to it. ChrisA From rantingrickjohnson at gmail.com Mon Jun 18 16:25:38 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 13:25:38 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <6b9d3ddc-08a0-4ec6-9008-8dc0b0f55404@googlegroups.com> Message-ID: <6baf39f5-0e27-40e1-b0f2-49539387524d@googlegroups.com> Chris Angelico wrote: [...] > assert """ > """", ", ";print('Will I print?');\ > "';print("Or will I?");\ > ';print("What about me?");'''\ > print("And me? Where endeth");"""\ > print('the assertion?');\'''' Chris, that's not code... That's a syntactical representation of some random flea circus. From rosuav at gmail.com Mon Jun 18 16:39:45 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2018 06:39:45 +1000 Subject: syntax difference In-Reply-To: <6baf39f5-0e27-40e1-b0f2-49539387524d@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <6b9d3ddc-08a0-4ec6-9008-8dc0b0f55404@googlegroups.com> <6baf39f5-0e27-40e1-b0f2-49539387524d@googlegroups.com> Message-ID: On Tue, Jun 19, 2018 at 6:25 AM, Rick Johnson wrote: > Chris Angelico wrote: > [...] >> assert """ >> """", ", ";print('Will I print?');\ >> "';print("Or will I?");\ >> ';print("What about me?");'''\ >> print("And me? Where endeth");"""\ >> print('the assertion?');\'''' > > Chris, that's not code... > > That's a syntactical representation of some random flea circus. Fortunately, my Python interpreter is able to execute flea circuses. ChrisA From jlee54 at gmail.com Mon Jun 18 16:42:50 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 18 Jun 2018 13:42:50 -0700 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> Message-ID: <2df608fd-4d5c-aa05-87a9-7c9fb7f8a6ad@gmail.com> On 06/18/2018 12:52 PM, Rhodri James wrote: > On 18/06/18 19:34, Jim Lee wrote: >> Type hints are just that - hints.? They have no syntactic meaning to >> the parser, > > This is plainly not true, otherwise the parser would be throwing > syntax errors at you all the time.? Whether they have semantic meaning > to the parser is more debatable. > That's funny - arguing semantics over the difference between syntactic and semantic.? If we're not careful, this conversation could become recursive and blow up the Internet! :) -Jim From rantingrickjohnson at gmail.com Mon Jun 18 16:52:24 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Jun 2018 13:52:24 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <20cb0f2f-ca06-411c-84b4-c83b0b276688@googlegroups.com> Message-ID: <12d85ed5-bf89-4537-a4e9-02308d7a2f52@googlegroups.com> On Monday, June 18, 2018 at 2:48:58 PM UTC-5, Ian wrote: > I would also note that none of this applies to type hinting > in any case. Type hints don't require the programmer to be > able to explain anything in natural language, nor are they > prone to becoming out-of-sync. > > Because if they do, then then the type analyzer will > complain the very next time you run it. So if you're trying > to make the case for type hints being treated like > comments, this isn't it. My point is perfectly clear to anyone who bothers to read it in its entirety. I have asked time and time again for someone to directly justify why py-dev won't offer a tool to remove the interleaved type-hint syntax from scripts. And yet, this whole thread has been a giant cascade of distractions from that one, simple, question. It is obvious to the impartial reader what is going on here. There is a systematic campaign of brow beating underway to punish those who do not blindly accept the validity of type- hints. And any wavering from the the official party line will be subject to retributions. That is not behavior of a community. A community would care for the opinions of all members. I have made my sacrifice, by agreeing that i will accept the inclusion of type-hints even though i find the whole concept the be a violation of Python's core principles. All i ask in return is that the py-devs make a sacrifice of their own, by releasing a tool to remove these type-hints error free. And then those of us who are offended by type-hints will have no reason to complain. And wouldn't that be nice? Wouldn't it be nice to actually have a sense of community again. Wouldn't it be nice to compromise instead of squabble? From rosuav at gmail.com Mon Jun 18 17:00:54 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2018 07:00:54 +1000 Subject: syntax difference In-Reply-To: <12d85ed5-bf89-4537-a4e9-02308d7a2f52@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <20cb0f2f-ca06-411c-84b4-c83b0b276688@googlegroups.com> <12d85ed5-bf89-4537-a4e9-02308d7a2f52@googlegroups.com> Message-ID: On Tue, Jun 19, 2018 at 6:52 AM, Rick Johnson wrote: > On Monday, June 18, 2018 at 2:48:58 PM UTC-5, Ian wrote: >> I would also note that none of this applies to type hinting >> in any case. Type hints don't require the programmer to be >> able to explain anything in natural language, nor are they >> prone to becoming out-of-sync. >> >> Because if they do, then then the type analyzer will >> complain the very next time you run it. So if you're trying >> to make the case for type hints being treated like >> comments, this isn't it. > > My point is perfectly clear to anyone who bothers to read it > in its entirety. > > I have asked time and time again for someone to directly > justify why py-dev won't offer a tool to remove the > interleaved type-hint syntax from scripts. For the same reason that the core devs won't offer a tool to remove assertions, or docstrings. If you want it, write it yourself. Why should busy volunteer core devs write the tool for you? > It is obvious to the impartial reader what is going on here. > > There is a systematic campaign of brow beating underway to > punish those who do not blindly accept the validity of type- > hints. And any wavering from the the official party line > will be subject to retributions. > > That is not behavior of a community. A community would care > for the opinions of all members. I believe you're confusing "community" with "democracy". This is not a democracy. This is a place in which the overwhelming majority of the work is done by volunteers. You cannot demand that they do work for you unless you are paying for it. ChrisA From Joseph.Schachner at Teledyne.com Mon Jun 18 17:36:20 2018 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Mon, 18 Jun 2018 21:36:20 +0000 Subject: syntax difference In-Reply-To: <7a50b232-0c22-4232-b1f7-c97deb6ab82e@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <7a50b232-0c22-4232-b1f7-c97deb6ab82e@googlegroups.com> Message-ID: On YouTube you can watch videos of Guido van Rossum presenting at PyCon from a few years ago, in which he makes clear that he has been thinking about this since 2000, that he wants someone else to guide this PEP along its path because he is too close to it, and that NOTHING about having a typing module requires you to use it. In fact, you can use it without affecting your source code and interleaving the (helpful) information into the source code. They support "stub" files, with a ".pyi" extension, in which you can place the declarations with the typing information. The type checker will read that an use it along with your unmodified source code to do its checking. He also thanked multiple people for their contributions bringing this from an idea to a preliminary implementation in 3.5 and now possibly final form in 3.6.6rc1. Now that you know that 1) You are not required to modify your source code at all, even if you want to get full utility from typing, and 2) you really don't have use typing at all, nothing forces you to, and 3) it's been developed by the Python community for years and was proposed by Guido years before he went to DropBox, does that help? -- Joe S. -----Original Message----- From: Rick Johnson Sent: Monday, June 18, 2018 1:16 PM To: python-list at python.org Subject: Re: syntax difference Steven D'Aprano wrote: > Moving the type-checking out of the core language into the IDE or > linter which can be used or not used according to the desire of the > programmer Except, what your poppycock commentary seems to glaze over is the fact that whilst a programmer can certainly decided to "use or not use" the type-hints feature in his or her own code, he or she certainly cannot "see or _unsee_" type-hints that are written by other programmers. From jlee54 at gmail.com Mon Jun 18 18:10:27 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 18 Jun 2018 15:10:27 -0700 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <7a50b232-0c22-4232-b1f7-c97deb6ab82e@googlegroups.com> Message-ID: <6f13c27b-8066-abe7-2345-1d29a78252fe@gmail.com> On 06/18/2018 02:36 PM, Schachner, Joseph wrote: > Now that you know that 1) You are not required to modify your source code at all, even if you want to get full utility from typing, and 2) you really don't have use typing at all, nothing forces you to, and 3) it's been developed by the Python community for years and was proposed by Guido years before he went to DropBox, does that help? > > -- Joe S. > Not at all.? As Rick said, you cannot *unsee* what other programmers have written.? Just because I don't personally use a feature, it doesn't follow that I can ignore it.? I still have to deal with other people's code. -Jim From pfeiffer at cs.nmsu.edu Mon Jun 18 18:24:17 2018 From: pfeiffer at cs.nmsu.edu (Joe Pfeiffer) Date: Mon, 18 Jun 2018 16:24:17 -0600 Subject: Folk etymology, was Re: Python list vs google group References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <201806160435.46723.gheskett@shentel.net> <1befh4dro6.fsf@pfeifferfamily.net> Message-ID: <1b602fense.fsf@pfeifferfamily.net> Peter Otten <__peter__ at web.de> writes: > Grant Edwards wrote: > >> On 2018-06-18, Joe Pfeiffer wrote: >>> Peter Otten <__peter__ at web.de> writes: >>> >>>> Gene Heskett wrote: >>>> >>>>> This biggest single thing wrong with any of those old scsi interfaces >>>>> is the bus's 5 volt isolation diode, the designer speced a shotkey(sp) >>>>> diode, and some damned bean counter saw the price diff and changed it >>>>> to >>>> >>>> Is this a case of ? >>>> >>>> https://en.wikipedia.org/wiki/Walter_H._Schottky >>> >>> I'm missing why the claim that management changed the spec on a diode >>> from Schottky to conventional would be folk etymology? Or why Gene >>> being unsure of his spelling would? What does any of this have to do >>> with etymology, folk or genuine? >> >> I was wondering the same thing... > > "folk etymology" would be the retrofitting of the exotic "Schottky" into two > familiar words "shot" and "key". Sometimes the writer assumes that these > words are somehow related to the labeled object. This would only be a folk etymology if (1) the spelling were really "shotkey", and (2) someone thought it was because of some tortured derivation from "shot" and "key". Most of the best-known examples in English are backronyms like Port Outboard Starboard Home and For Unlawful Carnal Knowledge. From gheskett at shentel.net Mon Jun 18 18:51:55 2018 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 18 Jun 2018 18:51:55 -0400 Subject: Python list vs google group In-Reply-To: <1befh4dro6.fsf@pfeifferfamily.net> References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <1befh4dro6.fsf@pfeifferfamily.net> Message-ID: <201806181851.55876.gheskett@shentel.net> On Monday 18 June 2018 11:45:45 Joe Pfeiffer wrote: > Peter Otten <__peter__ at web.de> writes: > > Gene Heskett wrote: > >> This biggest single thing wrong with any of those old scsi > >> interfaces is the bus's 5 volt isolation diode, the designer speced > >> a shotkey(sp) diode, and some damned bean counter saw the price > >> diff and changed it to > > > > Is this a case of ? > > > > https://en.wikipedia.org/wiki/Walter_H._Schottky > > I'm missing why the claim that management changed the spec on a diode > from Schottky to conventional would be folk etymology? Or why Gene > being unsure of his spelling would? What does any of this have to do > with etymology, folk or genuine? Its this list, Joe. Anything as long as there is a provable effect, is fair game here, and has been for a goodly number of years. -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From greg.ewing at canterbury.ac.nz Mon Jun 18 19:09:10 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 19 Jun 2018 11:09:10 +1200 Subject: Folk etymology, was Re: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <201806160435.46723.gheskett@shentel.net> <1befh4dro6.fsf@pfeifferfamily.net> Message-ID: Peter Otten wrote: > "folk etymology" would be the retrofitting of the exotic "Schottky" into two > familiar words "shot" and "key". Sometimes the writer assumes that these > words are somehow related to the labeled object. Well, there is a thing called "shot noise", and you can probaby get it from a Shottky diode under some circumstances, but Shottky is definitely someone's name. (Walter H. Shottky, to be specific.) -- Greg From jlee54 at gmail.com Mon Jun 18 19:24:14 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 18 Jun 2018 16:24:14 -0700 Subject: Folk etymology, was Re: Python list vs google group In-Reply-To: References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <201806160435.46723.gheskett@shentel.net> <1befh4dro6.fsf@pfeifferfamily.net> Message-ID: <20a12691-32e3-bdec-48b1-e59a8c0d0aaa@gmail.com> On 06/18/2018 04:09 PM, Gregory Ewing wrote: > Peter Otten wrote: >> "folk etymology" would be the retrofitting of the exotic "Schottky" >> into two familiar words "shot" and "key". Sometimes the writer >> assumes that these words are somehow related to the labeled object. > > Well, there is a thing called "shot noise", and you can probaby > get it from a Shottky diode under some circumstances, but > Shottky is definitely someone's name. (Walter H. Shottky, to > be specific.) > FWIW, we used to call them barrier diodes, or sometimes hot carrier diodes, until the name "Schottky" became commonplace in, what, the mid 80s or so? -Jim From jfong at ms4.hinet.net Mon Jun 18 19:48:04 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Tue, 19 Jun 2018 07:48:04 +0800 Subject: Is it possible to call a class but without a new instance created? In-Reply-To: <85tvq0eemp.fsf@benfinney.id.au> References: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> <85tvq0eemp.fsf@benfinney.id.au> Message-ID: <8fd0188d-15ac-5b1a-8b4a-9f78f46e57bb@ms4.hinet.net> Ben Finney at 2018/6/18 PM 03:29 wrote: > Jach Fong writes: > >> I also make a test of my own and it fails too. >> >>>>> class A: >> ... objs = [] >> ... def __init__(self, exists=False): >> ... if exists: self = self.objs[0] > > The function parameters (bound here to the names ?self?, ?exists?) are > in the local function scope. After the function ends, the scope of those > names ends; those name bindings no longer affect anything. So, changing > what ?self? refers to has no effect on the A instance that exists. > > In other words: Creating the instance is the responsibility of the > constructor method (a class method named ?__new__?), and that instance > is what gets passed to the instance initialiser (an instance method > named ?__init__?). > > The initialiser has no control over what instance gets passed in, and no > control over that same instance being returned from the constructor. > >> What I expect is that id(a0) and id(a1) has the same value. They >> should points to the same object. > > You can't get that effect from within the instance initialiser. What you > need to do is change the class constructor (named ?__new__?), and that's > a more advanced topic I leave you to research on your own. > class B: _obj = None def __new__(*args, **kwargs): if not B._obj: B._obj = object.__new__(*args, **kwargs) return B._obj b0 = B() b1 = B() assert b0 is b1 Although it passed the first examination, I have no idea if it can work correctly in the real application:-) --Jach --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From jfong at ms4.hinet.net Mon Jun 18 20:01:25 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Tue, 19 Jun 2018 08:01:25 +0800 Subject: Is it possible to call a class but without a new instance created? In-Reply-To: References: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> Message-ID: <9ac17d88-79f1-ec49-a6d2-69a810a9bc7b@ms4.hinet.net> It seems most of confusion comes from mixing up python object and tk widgets, and ignored that the tkinter is really a python-tk-interface. Thank you for pointing it out. Terry Reedy at 2018/6/18 PM 05:19 wrote: > To answer the question of the title, which is a bit different from the > question in the text, yes.? type(None)() always returns the singleton > None object.? (And one can write a singleton class in Python also.) > bool() always returns one of False or True.? int() and str() may return > either a new or old object.? For such immutables, it does not matter as > long at the object has the correct value.? As others said, this is all > handled in a __new__ method.? But none of this has much to do with > tkinter instances. > > On 6/18/2018 5:09 AM, Terry Reedy wrote: >> On 6/18/2018 12:48 AM, Jach Fong wrote: >>> After looking into the \tkiniter\font.py source file, triggered by Jim's >>> hint on my previous subject "Why an object changes its "address" between >>> adjacent calls?", I get more confused. >>> >>> Below was quoted from the font.py: >>> ------------------------ >>> def nametofont(name): >>> ???? """Given the name of a tk named font, returns a Font >>> representation. >>> ???? """ >>> ???? return Font(name=name, exists=True) >>> >>> class Font: >>> ???? """Represents a named font. >> >> tkinter abbreviates tk interface.? A Python tkinter Font instance >> represents a tk named font structure. It has a hidden pointer to the >> tk structure.? The same is true of all instances of tkinter widgets >> classes.? Each has a hidden pointer to a tk widget >> >>> ???? Constructor options are: >>> ???? ... >>> ???? exists -- does a named font by this name already exist? >> >> Does a *tk* named font exist? >> >>> ??????? Creates a new named font if False, points to the existing >>> font if True. >> >> Again, 'font' here means a tk structure, not a python instance.? Each >> call to Font returns a new python instance.? But for Fonts, it may or >> may not point to a new tk structure. >> >>> ???? ... >>> ???? """ >>> >>> ???? def __init__(self, root=None, font=None, name=None, exists=False, >>> ????????????????? **options): >>> ???????? ... >> >> One can mostly ignore the parallel existence of python instances and >> tk structures.? But they can get out of sync during shutdown.? If t is >> an instance of Text, t.destroy() causes tkinter to tell tk to destroy >> the tk widget, leaving t useless.? Similarly, if 'del t' deletes the >> last reference to the Python instance, it may disappear, leaving the >> tk widget possibly unaccessible. >> > > --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From sales at caprilion.com.tw Mon Jun 18 20:38:18 2018 From: sales at caprilion.com.tw (sales at caprilion.com.tw) Date: Tue, 19 Jun 2018 08:38:18 +0800 Subject: Why an object changes its "address" between adjacent calls? In-Reply-To: References: <445dbeb0-7851-f572-250d-e3654297b663@ms4.hinet.net> Message-ID: <8c7dace8-28ef-96fd-fd20-3418e3e84268@caprilion.com.tw> Grant Edwards at 2018/6/18 PM 10:36 wrote: > On 2018-06-17, Jach Fong wrote: >> C:\Python34\Doc>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. >>>>> import tkinter as tk >>>>> root = tk.Tk() >>>>> tk.Label(root, text='label one', font='TkDefaultFont').pack() >>>>> from tkinter import font >>>>> font.nametofont('TkDefaultFont') >> >>>>> font.nametofont('TkDefaultFont') >> >>>>> >> >> The "address" of the Font object 'TkDefaultFont' changes, why? > > What makes you think it's the same object the second time and not a > new object? Simply from what the method's name "name-to-font" implied. The font is already there, so naturally it should be the same one:-) --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From steve+comp.lang.python at pearwood.info Mon Jun 18 20:45:17 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jun 2018 00:45:17 +0000 (UTC) Subject: syntax difference (type hints) References: <2507028f7e4a4c2ca497f7dd48a529db@Teledyne.com> Message-ID: On Mon, 18 Jun 2018 14:57:30 +0000, Schachner, Joseph wrote: > Assuming that we want Python to remain a dynamically typed (but strongly > typed) language, There is no question about that. > I believe the proposed type hints are only necessary > for function definitions, What is the basis of this belief? How much experience do you have using type annotations and gradual typing? On a scale of 0 to 10, where 0 is "never even used it", and 10 is "used it extensively on projects with tens or hundreds of thousands of lines of code", where do you fit? Because type annotations and gradual typing *is* being used extensively on huge code bases at Dropbox, and they have been using it for years, and I can tell you that the type hinting features being added to Python, such as the ability to annotate names outside of function definitions, *are* necessary. Which won't come as a surprise to anyone who has used languages with type inference. Sometimes the type system cannot infer the type of a variable or name, and needs a hint from the author. ML proved that nearly fifty years ago. Honestly folks, you're talking as if what Python is doing is cutting edge experimental stuff. It isn't. It is *old and boring* and well-understood with nearly half a century of practical experience behind it. You all sound like old BASIC programmers bitterly complaining about this new-fangled idea of "functions" when all anybody could possibly need is GOTO and a good memory for remembering line numbers. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jun 18 20:48:53 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jun 2018 00:48:53 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <3c7bbf63-95f1-4c8c-8aa3-fb15e14e55a0@googlegroups.com> Message-ID: On Mon, 18 Jun 2018 08:10:12 -0700, Rick Johnson wrote: > "Type-hint comments" don't exist yet. Yes they do, and they have existed for years. https://www.python.org/dev/peps/pep-0526/ But don't let a little thing like the fact you have no clue whatsoever about this stop you from pontificating about it. Because the opinions of the ignorant are of course the most important thing of all, far more important than facts or experience. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jun 18 20:52:09 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jun 2018 00:52:09 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: On Mon, 18 Jun 2018 21:03:14 +0100, Bart wrote: > In the case of Python, it is > already so big and has so many features crammed in that adding type > hints probably makes little difference. You've never used C++ have you? Describing Python as a "big" language is ludicrous. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From gheskett at shentel.net Mon Jun 18 21:53:52 2018 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 18 Jun 2018 21:53:52 -0400 Subject: Folk etymology, was Re: Python list vs google group In-Reply-To: <20a12691-32e3-bdec-48b1-e59a8c0d0aaa@gmail.com> References: <00cf26aa-0747-4065-94f8-84482fb41eae@googlegroups.com> <20a12691-32e3-bdec-48b1-e59a8c0d0aaa@gmail.com> Message-ID: <201806182153.52877.gheskett@shentel.net> On Monday 18 June 2018 19:24:14 Jim Lee wrote: > On 06/18/2018 04:09 PM, Gregory Ewing wrote: > > Peter Otten wrote: > >> "folk etymology" would be the retrofitting of the exotic "Schottky" > >> into two familiar words "shot" and "key". Sometimes the writer > >> assumes that these words are somehow related to the labeled object. > > > > Well, there is a thing called "shot noise", and you can probaby > > get it from a Shottky diode under some circumstances, but > > Shottky is definitely someone's name. (Walter H. Shottky, to > > be specific.) > > FWIW, we used to call them barrier diodes, or sometimes hot carrier > diodes, until the name "Schottky" became commonplace in, what, the mid > 80s or so? > > -Jim More like the early 70's. I spent from 70, to late 77 keeping one of Nebraska ETV's 3rd of a megawatt transmitters on the air. One of the support engineers brought up a 10 pack of the first HP schottkey diodes up and made the claim that it was a 98% efficient rectifier at 500 mhz. So I removed the twin vacuum tube diode (a 6AL5) that wasn't capable of delivering a volt of video from a monitoring test point into astd 75 ohm load, and soldered one of this new HP diodes in its place. I had to lift it back out of its mount nearly 3/4" just to get it down to one volt. It didn't take me long to modify the other 5. -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From ben+python at benfinney.id.au Mon Jun 18 22:20:07 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 19 Jun 2018 12:20:07 +1000 Subject: Is it possible to call a class but without a new instance created? References: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> <85tvq0eemp.fsf@benfinney.id.au> <8fd0188d-15ac-5b1a-8b4a-9f78f46e57bb@ms4.hinet.net> Message-ID: <85o9g7ecvc.fsf@benfinney.id.au> Jach Fong writes: > Although it passed the first examination, I have no idea if it can > work correctly in the real application:-) Neither do I. What is the real-world problem you are trying to solve? Why do you think this (and not some more idiomatic Python feature) is needed for solving that problem? -- \ ?The Vatican is not a state.? a state must have territory. This | `\ is a palace with gardens, about as big as an average golf | _o__) course.? ?Geoffrey Robertson, 2010-09-18 | Ben Finney From william.leslie.ttg at gmail.com Mon Jun 18 22:47:19 2018 From: william.leslie.ttg at gmail.com (William ML Leslie) Date: Tue, 19 Jun 2018 12:47:19 +1000 Subject: [pypy-dev] A quick question for you! In-Reply-To: <6060aa7a-7b2a-94cb-228e-d40c974a597e@yandex.com> References: <6060aa7a-7b2a-94cb-228e-d40c974a597e@yandex.com> Message-ID: On 18 June 2018 at 22:18, Etienne Robillard wrote: > Hi, > > Quick question: Does anyone of you know what is the effect of enabling > gc.enable() in sitecustomize.py when using PyPy? Can it reduce latency for > long-lived WSGI applications? > gc is enabled by default. you only need to use gc.enable() if you have earlier run gc.disable(). -- William Leslie Notice: Likely much of this email is, by the nature of copyright, covered under copyright law. You absolutely MAY reproduce any part of it in accordance with the copyright law of the nation you are reading this in. Any attempt to DENY YOU THOSE RIGHTS would be illegal without prior contractual agreement. From drsalists at gmail.com Mon Jun 18 23:33:35 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 18 Jun 2018 20:33:35 -0700 Subject: syntax difference (type hints) In-Reply-To: References: <2507028f7e4a4c2ca497f7dd48a529db@Teledyne.com> Message-ID: On Mon, Jun 18, 2018 at 5:45 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Mon, 18 Jun 2018 14:57:30 +0000, Schachner, Joseph wrote: > > I believe the proposed type hints are only necessary > > for function definitions, > > What is the basis of this belief? How much experience do you have using > type annotations and gradual typing? > > On a scale of 0 to 10, where 0 is "never even used it", and 10 is "used > it extensively on projects with tens or hundreds of thousands of lines of > code", where do you fit? > I've done 10 projects of varying sizes with Python 3 type hints now. Some I wrote from scratch with type hints from the beginning, others I retrofitted type hints into existing code. I've found that I mostly add type hints to function definitions, but infrequently I have to add them to the creation of collection types, like an empty list or empty dictionary. I tend to call mypy like: mypy --disallow-untyped-call foo.py bar.py ...or: mypy --disallow-untyped-calls --ignore-missing-imports foo.py bar.py ...if there are dependency modules that don't (yet?) have type hints in them. I'm eager to try MonkeyType and/or pep484transform.py to automatically add type hints, but so far I've only added them manually. It remains to be seen (by me, at least) how many nonessential names will be type hinted by these tools. Instagram says mypy is by far the most common python type checker, but they like "pyre" for its speed, which is another type checker. From drsalists at gmail.com Mon Jun 18 23:46:28 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 18 Jun 2018 20:46:28 -0700 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: On Mon, Jun 18, 2018 at 5:52 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Mon, 18 Jun 2018 21:03:14 +0100, Bart wrote: > > > In the case of Python, it is > > already so big and has so many features crammed in that adding type > > hints probably makes little difference. > > You've never used C++ have you? > > Describing Python as a "big" language is ludicrous. > Actually, I think Python is getting a bit big. I feel like there may be a push to add "important" features to 3.x to make people want to move off of 2.x. But that's making it hard for the many other implementations of Python to catch up (and stay caught up). What would I remove, if Python weren't used in production all over the world? map and filter. metaclasses. List comprehensions. "feature strings" (AKA "f strings"). And that new := assignment expression makes me shudder - that's something I haven't missed at all since I switched from C to Python. I'm pleased that machine int's and long's were unified. Great languages are small but extensible, easy to read, and don't require learning a lot before you can get started writing code or reading someone else's code. Great languages: C and Scheme. And Python. But isn't Lua smaller than Python? That thought worries me a little. From jfong at ms4.hinet.net Tue Jun 19 00:22:33 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Tue, 19 Jun 2018 12:22:33 +0800 Subject: Is it possible to call a class but without a new instance created? In-Reply-To: <85o9g7ecvc.fsf@benfinney.id.au> References: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> <85tvq0eemp.fsf@benfinney.id.au> <8fd0188d-15ac-5b1a-8b4a-9f78f46e57bb@ms4.hinet.net> <85o9g7ecvc.fsf@benfinney.id.au> Message-ID: Ben Finney at 2018/6/19 PM 10:20 wrote: > Jach Fong writes: > >> Although it passed the first examination, I have no idea if it can >> work correctly in the real application:-) > > Neither do I. What is the real-world problem you are trying to solve? > Why do you think this (and not some more idiomatic Python feature) is > needed for solving that problem? > No, I don't have any specific application in mind. This idea was just triggered by a sentence in a Docstring in file font.py. class Font: """Represents a named font. Constructor options are: ... exists -- does a named font by this name already exist? Creates a new named font if False, points to the existing font if True. ... """ But honestly I still don't know how it "points to the existing font":-( --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From rosuav at gmail.com Tue Jun 19 01:08:28 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2018 15:08:28 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: On Tue, Jun 19, 2018 at 1:46 PM, Dan Stromberg wrote: > Great languages are small but extensible, easy to read, and don't require > learning a lot before you can get started writing code or reading someone > else's code. > > Great languages: C and Scheme. And Python. > > But isn't Lua smaller than Python? That thought worries me a little. It's a lot smaller. And that worries me ONLY to the extent that I might, at some point, have to write something in Lua. I would much rather use a richer language than a poorer one, any day. A well-designed language has linear complexity, quadratic power. You learn new language constructs and they are completely orthogonal; you use those constructs and they interact infinitely. Python isn't quite 100% there (there are some odd edge cases), but it's close. ChrisA From drsalists at gmail.com Tue Jun 19 01:33:59 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 18 Jun 2018 22:33:59 -0700 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: On Mon, Jun 18, 2018 at 10:08 PM, Chris Angelico wrote: > On Tue, Jun 19, 2018 at 1:46 PM, Dan Stromberg > wrote: > > Great languages are small but extensible, easy to read, and don't require > > learning a lot before you can get started writing code or reading someone > > else's code. > > > > Great languages: C and Scheme. And Python. > > > > But isn't Lua smaller than Python? That thought worries me a little. > > It's a lot smaller. And that worries me ONLY to the extent that I > might, at some point, have to write something in Lua. I would much > rather use a richer language than a poorer one, any day. > Some size is useful. A lot of "richness" leads you to Perl. You > learn new language constructs and they are completely orthogonal; you > use those constructs and they interact infinitely. > Agreed. From greg.ewing at canterbury.ac.nz Tue Jun 19 01:52:31 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 19 Jun 2018 17:52:31 +1200 Subject: syntax difference (type hints) In-Reply-To: References: <2507028f7e4a4c2ca497f7dd48a529db@Teledyne.com> Message-ID: Steven D'Aprano wrote: > Sometimes the type system cannot infer the type of a variable > or name, and needs a hint from the author. Or it can infer it, but is unable to produce intelligible error messages without some intermediate signposts to follow. -- Greg From jlee54 at gmail.com Tue Jun 19 03:44:52 2018 From: jlee54 at gmail.com (Jim Lee) Date: Tue, 19 Jun 2018 00:44:52 -0700 Subject: Is it possible to call a class but without a new instance created? In-Reply-To: References: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> <85tvq0eemp.fsf@benfinney.id.au> <8fd0188d-15ac-5b1a-8b4a-9f78f46e57bb@ms4.hinet.net> <85o9g7ecvc.fsf@benfinney.id.au> Message-ID: <4e73a6d8-4408-664e-d04b-85c176fdecdf@gmail.com> On 06/18/2018 09:22 PM, Jach Fong wrote: > Ben Finney at 2018/6/19 PM 10:20 wrote: >> Jach Fong writes: >> >>> Although it passed the first examination, I have no idea if it can >>> work correctly in the real application:-) >> >> Neither do I. What is the real-world problem you are trying to solve? >> Why do you think this (and not some more idiomatic Python feature) is >> needed for solving that problem? >> > No, I don't have any specific application in mind. This idea was just > triggered by a sentence in a Docstring in file font.py. > > class Font: > ??? """Represents a named font. > ??? Constructor options are: > ??? ... > ??? exists -- does a named font by this name already exist? > ?????? Creates a new named font if False, points to the existing font > if True. > ??? ... > ??? """ > > But honestly I still don't know how it "points to the existing font":-( > > If the font exists, the Font object calls this: ??? tk.call("font", "configure", self.name, *font) Otherwise, it calls this: ??? tk.call("font", "create", self.name, *font) The font caching is all handled by Tk, not Python.? The Font object is just a wrapper around calls to Tk. -Jim From tkadm30 at yandex.com Tue Jun 19 04:06:33 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Tue, 19 Jun 2018 04:06:33 -0400 Subject: [pypy-dev] A quick question for you! In-Reply-To: References: <6060aa7a-7b2a-94cb-228e-d40c974a597e@yandex.com> Message-ID: <6dffebe7-cd18-8b81-dac3-32a51466deef@yandex.com> Le 2018-06-18 ? 22:47, William ML Leslie a ?crit?: > On 18 June 2018 at 22:18, Etienne Robillard wrote: >> Hi, >> >> Quick question: Does anyone of you know what is the effect of enabling >> gc.enable() in sitecustomize.py when using PyPy? Can it reduce latency for >> long-lived WSGI applications? >> > gc is enabled by default. you only need to use gc.enable() if you > have earlier run gc.disable(). Good to know man! I didn't knew that. Thanks for sharing. Etienne -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From none at gmail.com Tue Jun 19 04:34:55 2018 From: none at gmail.com (ast) Date: Tue, 19 Jun 2018 10:34:55 +0200 Subject: Speed of animation with matplotlib.animation Message-ID: <5b28c031$0$20331$426a34cc@news.free.fr> Hello I noticed that the speed of animations made with module matplotlib.animation always seems wrong. Here is a small example for demonstration purpose: import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation fig = plt.figure() ax = fig.add_subplot(111) txt = ax.text(0.5, 0.5, "", transform=ax.transAxes) dt = 0.1 # 100 ms def animate(i): txt.set_text("time= %.1f" % (i*dt)) return txt, ani = animation.FuncAnimation(fig=fig, func=animate, frames = 200, interval = dt, blit = True, repeat=False) plt.show() ---------------------- so function animate is ran every interval=dt=100ms with i=0, 1, 2, ..., 200 and it simply prints time (i*dt) on the figure. The animation should last 20s, but on my computer it is twice faster A link to FuncAnimation doc: https://bit.ly/2t5UKjA interval : number, optional Delay between frames in milliseconds. Defaults to 200. What's wrong ? From steve+comp.lang.python at pearwood.info Tue Jun 19 04:42:51 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jun 2018 08:42:51 +0000 (UTC) Subject: Speed of animation with matplotlib.animation References: <5b28c031$0$20331$426a34cc@news.free.fr> Message-ID: On Tue, 19 Jun 2018 10:34:55 +0200, ast wrote: > The animation should last 20s, but on my computer it is twice faster [...] > What's wrong ? Try replacing your CPU with one half as fast. *wink* (Sorry for the bad advice, I couldn't resist.) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Tue Jun 19 04:45:17 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jun 2018 08:45:17 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <87zhztkvrg.fsf@elektro.pacujo.net> <8eb7b92d-f113-1c1d-b465-4ee6009e2a80@gmail.com> <396bc2be-ff08-4d4b-8e52-c3557d8a3fbc@googlegroups.com> Message-ID: On Mon, 18 Jun 2018 09:39:21 -0700, Rick Johnson wrote: > On Monday, June 18, 2018 at 6:57:27 AM UTC-5, Steven D'Aprano wrote: >> I still think that Python has been going nowhere but downhill ever >> since extended slicing was added in version 1.4. > > Apples to oranges! That whooshing noise you heard was the point going over your head. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From __peter__ at web.de Tue Jun 19 04:57:12 2018 From: __peter__ at web.de (Peter Otten) Date: Tue, 19 Jun 2018 10:57:12 +0200 Subject: Speed of animation with matplotlib.animation References: <5b28c031$0$20331$426a34cc@news.free.fr> Message-ID: ast wrote: > I noticed that the speed of animations made > with module matplotlib.animation always seems > wrong. > dt = 0.1 # 100 ms > interval : number, optional > > Delay between frames in milliseconds. Defaults to 200. > > > What's wrong ? >From the above I would conclude that you get a 100 ms delay with dt = 100 From steve+comp.lang.python at pearwood.info Tue Jun 19 05:09:33 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jun 2018 09:09:33 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: On Mon, 18 Jun 2018 10:01:58 -0700, Rick Johnson wrote: > Steven D'Aprano wrote: > [...] >> particular at DropBox, which is (I believe) funding a lot of Guido's >> time on this, because they need it. > > And now we get to the truth! > > Guido's new puppet master is the sole reason why this fine community -- > of once free-roaming *STALLIONS*-- is now corralled and saddled with > type-hints! I know that Rick's attitude towards reality is that facts are only for other people, and that once he has made up his mind nothing will budge it, *especially* not facts, but for anyone reading this who might be fooled into imagining that Rick has a point, really, no. People have been requesting static typing in Python virtually since Day 1, and certainly since Python 1.5. Guido has been talking about it publicly since at least 2004: https://www.artima.com/weblogs/viewpost.jsp?thread=85551 a few years before DropBox was even a startup. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From none at gmail.com Tue Jun 19 05:18:46 2018 From: none at gmail.com (ast) Date: Tue, 19 Jun 2018 11:18:46 +0200 Subject: Speed of animation with matplotlib.animation In-Reply-To: References: <5b28c031$0$20331$426a34cc@news.free.fr> Message-ID: <5b28ca79$0$14320$426a74cc@news.free.fr> Le 19/06/2018 ? 10:57, Peter Otten a ?crit?: > ast wrote: > >> I noticed that the speed of animations made >> with module matplotlib.animation always seems >> wrong. > >> dt = 0.1 # 100 ms > >> interval : number, optional >> >> Delay between frames in milliseconds. Defaults to 200. >> >> >> What's wrong ? > >>From the above I would conclude that you get a 100 ms delay with > > dt = 100 > > So the animation should last 200*0.1 = 20s but it is twice faster From bc at freeuk.com Tue Jun 19 05:19:15 2018 From: bc at freeuk.com (Bart) Date: Tue, 19 Jun 2018 10:19:15 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: On 19/06/2018 06:08, Chris Angelico wrote: > On Tue, Jun 19, 2018 at 1:46 PM, Dan Stromberg wrote: >> Great languages are small but extensible, easy to read, and don't require >> learning a lot before you can get started writing code or reading someone >> else's code. >> >> Great languages: C and Scheme. And Python. >> >> But isn't Lua smaller than Python? That thought worries me a little. > > It's a lot smaller. And that worries me ONLY to the extent that I > might, at some point, have to write something in Lua. I would much > rather use a richer language than a poorer one, any day. > > A well-designed language has linear complexity, quadratic power. You > learn new language constructs and they are completely orthogonal; you > use those constructs and they interact infinitely. Python isn't quite > 100% there (there are some odd edge cases), but it's close. My own dynamic language is much smaller than Python, much less dynamic, much less extendable, and lower level. Yet it might have a dozen highly useful features, ones I consider basic, that are already built-in and Just Work without having to grapple with innumerable, incompatible add-ons. (What, I have to list them? Let's see: * Goto (yes this /can/ be very useful) * Pointers (this allows some of the features below) * Swap(x,y) (evaluate each once unlike a,y=y,x) * Reference parameters * Mutable records * Mutable and in-place modifiable strings * Named constants * Simple enums * 'Tabledata' (too hard to explain; mix of enums and linked tables) * Integer sets (Pascal-like sets) * Bit indexing (eg. a.[i] to get the i'th bit, or a.[0..7]) * Switch statement (like C) * Case statement (switch but for any types and for runtime expressions) * N-way select (n|a,b,c,...|z); only one expr evaluated, z is default) * Increment/decrement ops * C-style packed struct types * Direct access to native-code functions in external DLL/.so files * Type punning * Byte-code compiler will always compile all modules of app to single- byte-code file (very fast too) * The interpreter is a single executable file. (Distribute any app as one exe plus one byte-code program file; or they can be trivially combined into one file) * Built-in read statement: readln a,b,c * Bit arrays (including 1, 2 and 4-bit elements) * Packed arrays of C-style types * View-slices * Stop or 'stop x' (not a big feature, but it's there). * 'main' function replaces all the '__main__ business; it will be called first if present. * Dedicated loop statements for endless loop and repeat N times Is that a dozen yet? Sorry it's about two dozen, of things which I don't think are in Python, or which may require add-ons.) -- bart From greg.ewing at canterbury.ac.nz Tue Jun 19 05:19:50 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 19 Jun 2018 21:19:50 +1200 Subject: Speed of animation with matplotlib.animation In-Reply-To: References: <5b28c031$0$20331$426a34cc@news.free.fr> Message-ID: Steven D'Aprano wrote: >>The animation should last 20s, but on my computer it is twice faster > > Try replacing your CPU with one half as fast. Or push the Turbo button to slow it down to 4.77MHz. -- Greg From jfong at ms4.hinet.net Tue Jun 19 05:32:22 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Tue, 19 Jun 2018 17:32:22 +0800 Subject: Is it possible to call a class but without a new instance created? In-Reply-To: <4e73a6d8-4408-664e-d04b-85c176fdecdf@gmail.com> References: <1d7eddd0-f58c-1bec-2973-c6c931d8f55e@ms4.hinet.net> <85tvq0eemp.fsf@benfinney.id.au> <8fd0188d-15ac-5b1a-8b4a-9f78f46e57bb@ms4.hinet.net> <85o9g7ecvc.fsf@benfinney.id.au> <4e73a6d8-4408-664e-d04b-85c176fdecdf@gmail.com> Message-ID: <59f1a673-72e8-883e-7fc3-a65788402a25@ms4.hinet.net> Jim Lee at 2018/6/19 PM 03:44 wrote: > > > On 06/18/2018 09:22 PM, Jach Fong wrote: >> Ben Finney at 2018/6/19 PM 10:20 wrote: >>> Jach Fong writes: >>> >>>> Although it passed the first examination, I have no idea if it can >>>> work correctly in the real application:-) >>> >>> Neither do I. What is the real-world problem you are trying to solve? >>> Why do you think this (and not some more idiomatic Python feature) is >>> needed for solving that problem? >>> >> No, I don't have any specific application in mind. This idea was just >> triggered by a sentence in a Docstring in file font.py. >> >> class Font: >> ??? """Represents a named font. >> ??? Constructor options are: >> ??? ... >> ??? exists -- does a named font by this name already exist? >> ?????? Creates a new named font if False, points to the existing font >> if True. >> ??? ... >> ??? """ >> >> But honestly I still don't know how it "points to the existing font":-( >> >> > If the font exists, the Font object calls this: > ??? tk.call("font", "configure", self.name, *font) > Otherwise, it calls this: > ??? tk.call("font", "create", self.name, *font) If the Font was called through nametofont, then the font is None and neither will be called:-) --Jach > The font caching is all handled by Tk, not Python.? The Font object is > just a wrapper around calls to Tk. > > -Jim > --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From steve+comp.lang.python at pearwood.info Tue Jun 19 05:40:40 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jun 2018 09:40:40 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <20cb0f2f-ca06-411c-84b4-c83b0b276688@googlegroups.com> <12d85ed5-bf89-4537-a4e9-02308d7a2f52@googlegroups.com> Message-ID: On Mon, 18 Jun 2018 13:52:24 -0700, Rick Johnson wrote: > I have asked time and time again for someone to directly justify why > py-dev won't offer a tool to remove the interleaved type-hint syntax > from scripts. You say that as if the core developers were obligated to cater to your every idle whim or passing fancy. Let me answer your question directly: they haven't written this tool for you because they don't have to pander to your idiosyncrasies. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From __peter__ at web.de Tue Jun 19 05:47:26 2018 From: __peter__ at web.de (Peter Otten) Date: Tue, 19 Jun 2018 11:47:26 +0200 Subject: Speed of animation with matplotlib.animation References: <5b28c031$0$20331$426a34cc@news.free.fr> <5b28ca79$0$14320$426a74cc@news.free.fr> Message-ID: ast wrote: > Le 19/06/2018 ? 10:57, Peter Otten a ?crit : >> ast wrote: >> >>> I noticed that the speed of animations made >>> with module matplotlib.animation always seems >>> wrong. >> >>> dt = 0.1 # 100 ms >> >>> interval : number, optional >>> >>> Delay between frames in milliseconds. Defaults to 200. >>> >>> >>> What's wrong ? >> >>>From the above I would conclude that you get a 100 ms delay with >> >> dt = 100 >> >> > > So the animation should last 200*0.1 = 20s > but it is twice faster No, with dt = 100 it should last 200 * 100ms = 20.000ms = 20s with dt = 0.1 it should last 200 * 0.1ms = 20ms = 0.02s but your computer is probably not fast enough for that. From steve+comp.lang.python at pearwood.info Tue Jun 19 06:12:47 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jun 2018 10:12:47 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> Message-ID: On Mon, 18 Jun 2018 11:34:40 -0700, Jim Lee wrote: > On 06/18/2018 11:18 AM, Chris Angelico wrote: >> What, fundamentally, is the difference between type hints and >> assertions, such that - in >> your view - one gets syntax and the other is just comments? > Type hints are just that - hints.? They have no syntactic meaning to the > parser, and do not affect the execution path in any way. Therefore, they > are effectively and actually comments.? The way they have been > implemented, though, causes noise to be interspersed with live code and, > as others have said, are difficult to remove or ignore. So let me get this straight... Using annotations is evil, because it intersperses noise with live code: def function(argument: int, flag: bool, sequence: list) -> str: ... But using comments is great, because it doesn't: def function(argument, # type=int, flag, # type=bool, sequence, # type=list): # type=str ... Okay, I'm glad we cleared that up. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Tue Jun 19 06:13:10 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2018 20:13:10 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: On Tue, Jun 19, 2018 at 7:19 PM, Bart wrote: > My own dynamic language is much smaller than Python, much less dynamic, much > less extendable, and lower level. > > Yet it might have a dozen highly useful features, ones I consider basic, > that are already built-in and Just Work without having to grapple with > innumerable, incompatible add-ons. > > (What, I have to list them? Let's see: > > * Goto (yes this /can/ be very useful) > > * Pointers (this allows some of the features below) > > * Swap(x,y) (evaluate each once unlike a,y=y,x) > > * Reference parameters > > * Mutable records > > * Mutable and in-place modifiable strings > > * Named constants > > * Simple enums > > * 'Tabledata' (too hard to explain; mix of enums and linked tables) > > * Integer sets (Pascal-like sets) > > * Bit indexing (eg. a.[i] to get the i'th bit, or a.[0..7]) > > * Switch statement (like C) > > * Case statement (switch but for any types and for runtime expressions) > > * N-way select (n|a,b,c,...|z); only one expr evaluated, z is default) > > * Increment/decrement ops > > * C-style packed struct types > > * Direct access to native-code functions in external DLL/.so files > > * Type punning > > * Byte-code compiler will always compile all modules of app to single- > byte-code file (very fast too) > > * The interpreter is a single executable file. (Distribute any app as one > exe plus one byte-code program file; or they can be trivially combined into > one file) > > * Built-in read statement: readln a,b,c > > * Bit arrays (including 1, 2 and 4-bit elements) > > * Packed arrays of C-style types > > * View-slices > > * Stop or 'stop x' (not a big feature, but it's there). > > * 'main' function replaces all the '__main__ business; it will be called > first if present. > > * Dedicated loop statements for endless loop and repeat N times > > Is that a dozen yet? Sorry it's about two dozen, of things which I don't > think are in Python, or which may require add-ons.) Great! Now, for this next test, you are also allowed to count any standard library that is included as part of your single-file distribution (and thus isn't an "add-on"). Do you have: * Arbitrary-precision integers? * Unicode strings? * The ability to create TCP sockets, and bind, listen, and connect them? * Ditto for UDP and Unix sockets? * Easy ways to create servers and clients for common internet protocols eg HTTP, SMTP, IMAP? * Out-of-the-box handling for SSL certificates? * An efficient way to multiplex many concurrent connections eg select()? * Reading and writing files relative to a previously-opened directory (openat etc)? * Parsers for common transport formats and encodings eg JSON, MIME, etc? * A unit test framework? * A GUI framework? * An interactive interpreter, with GNU readline (on supported platforms)? * An argument parser? * A secure and reliable way to generate random numbers? * Any form of compression library (eg zlib, lzma)? * Parsers for any form of compressed file (eg zip, gz)? * Inbuilt access to at least one database (SQLite3, PostgreSQL, etc)? * Trigonometric functions (sin/cos/tan)? * High-resolution timers? * Cryptographic hashing functions (eg sha256)? * A regex engine? (Bonus points for having two or more. Maybe negative points.) * Date/time calculations using the Gregorian calendar? (Bonus points for supporting other calendars.) * Dare I ask: Multiple inheritance? ALL of these are fully supported, out-of-the-box, by both Python and Pike, the two languages I happen to have full source and docs for at my fingertips. I would expect that most or all of these are also supported by most other modern languages; some won't include a GUI framework, others don't have arbitrary-precision integers, etc, but I'd predict scores of 75% or better across the board. What's your language's score? And no, these are not cherry-picked from the most obscure features I could find. Every single one of these is of immense value to real-world code. Even multiple inheritance, which I listed last because it's a bit of a hairy one, and is part of the reason that very few languages will score 100%. But can you at least score *some*? ChrisA From rosuav at gmail.com Tue Jun 19 06:21:10 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2018 20:21:10 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> Message-ID: On Tue, Jun 19, 2018 at 8:12 PM, Steven D'Aprano wrote: > On Mon, 18 Jun 2018 11:34:40 -0700, Jim Lee wrote: > >> On 06/18/2018 11:18 AM, Chris Angelico wrote: >>> What, fundamentally, is the difference between type hints and >>> assertions, such that - in >>> your view - one gets syntax and the other is just comments? >> Type hints are just that - hints. They have no syntactic meaning to the >> parser, and do not affect the execution path in any way. Therefore, they >> are effectively and actually comments. The way they have been >> implemented, though, causes noise to be interspersed with live code and, >> as others have said, are difficult to remove or ignore. > > So let me get this straight... > > Using annotations is evil, because it intersperses noise with live code: > > def function(argument: int, > flag: bool, > sequence: list) -> str: > ... > > > But using comments is great, because it doesn't: > > def function(argument, # type=int, > flag, # type=bool, > sequence, # type=list): # type=str > ... > > > Okay, I'm glad we cleared that up. > Isn't it nice how comments, being terminated exclusively by end-of-line, allow the introduction of subtle bugs? Let's see how many people spot the (presumably deliberate) bug in Steve's code here. ChrisA From none at gmail.com Tue Jun 19 06:27:22 2018 From: none at gmail.com (ast) Date: Tue, 19 Jun 2018 12:27:22 +0200 Subject: Speed of animation with matplotlib.animation In-Reply-To: References: <5b28c031$0$20331$426a34cc@news.free.fr> <5b28ca79$0$14320$426a74cc@news.free.fr> Message-ID: <5b28da8c$0$3337$426a74cc@news.free.fr> Le 19/06/2018 ? 11:47, Peter Otten a ?crit?: > ast wrote: > >> Le 19/06/2018 ? 10:57, Peter Otten a ?crit : >>> ast wrote: >>> > > No, with dt = 100 it should last > > 200 * 100ms = 20.000ms = 20s > > with dt = 0.1 it should last > > 200 * 0.1ms = 20ms = 0.02s > > but your computer is probably not fast enough for that. > > You are right. I didn't noticed that interval was in ms Ty From steve+comp.lang.python at pearwood.info Tue Jun 19 06:33:34 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jun 2018 10:33:34 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: On Tue, 19 Jun 2018 10:19:15 +0100, Bart wrote: > * Swap(x,y) (evaluate each once unlike a,y=y,x) Sigh. Really? You think x,y = y,x evaluates x and y twice? The rest of your list seemed like a very nice list of low-level operations, if you want a low-level language with lots of redundancy and functional duplication. Like: * Integer sets (Pascal-like sets) Why do you need them if you have real sets? * Increment/decrement ops Why do you need them if you have + and - operators? * Stop or 'stop x' Why do you need a syntactic feature if a simple exit() function could do the job? * Dedicated loop statements for endless loop and repeat N times Why do you need them when regular while and for loops will work? (Mind you, I do like the N-way select.) But Python isn't a low-level language. You make a big deal of having named constants. Okay, great. Do you support Unicode strings and Decimals? Does your language come with a functioning web server? Can it send email straight out of the box? Yeah, I get it, you like your language to have lots and lots and lots of syntax to do *slightly* different things. But it doesn't seem to be so good at doing application level functionality. Its basically just a less efficient, slightly prettier C. Assuming that people who aren't you can even get it to compile. When I tried, it wouldn't compile on my computer. Oh, with your pointer syntax -- how do you guarantee that your language is safe? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Tue Jun 19 06:45:02 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2018 20:45:02 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: On Tue, Jun 19, 2018 at 8:33 PM, Steven D'Aprano wrote: > Yeah, I get it, you like your language to have lots and lots and lots of > syntax to do *slightly* different things. But it doesn't seem to be so > good at doing application level functionality. Its basically just a less > efficient, slightly prettier C. With the word "dynamic" in its description, of course. That's VERY important. C is not a dynamic language. Bart's language is dynamic. That makes it unimaginably better. ChrisA From sandy0511.star at gmail.com Tue Jun 19 06:49:13 2018 From: sandy0511.star at gmail.com (sandy star) Date: Tue, 19 Jun 2018 03:49:13 -0700 (PDT) Subject: Python Training in Bangalore Message-ID: <7655d6be-b928-49b9-9a43-196a5a967eb2@googlegroups.com> Python Training in Bangalore Best Python Training Courses in Bangalore ? Marathahalli, BTM Layout, Rajajinagar & Jaya Nagar. We train the students from basic level to advanced concepts with a real-time environment. We are the Best Python Training Institute in bangalore. URL : https://www.besanttechnologies.com/training-courses/python-training-institute-in-bangalore From bc at freeuk.com Tue Jun 19 06:52:22 2018 From: bc at freeuk.com (Bart) Date: Tue, 19 Jun 2018 11:52:22 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: On 19/06/2018 11:33, Steven D'Aprano wrote: > On Tue, 19 Jun 2018 10:19:15 +0100, Bart wrote: > >> * Swap(x,y) (evaluate each once unlike a,y=y,x) > > Sigh. Really? You think x,y = y,x evaluates x and y twice? Yes. Try: count=0 def fn(): global count count=count+1 return 1 a=[10,20,30,40] b=[1,2,3,4] a[1],b[fn()] = b[fn()],a[1] print (a) print (b) print ("Count",count) b[fn()] is evaluated twice. (May reply to other points of yours and Chris' in a few days.) -- bart From rosuav at gmail.com Tue Jun 19 07:03:55 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2018 21:03:55 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: On Tue, Jun 19, 2018 at 8:52 PM, Bart wrote: > On 19/06/2018 11:33, Steven D'Aprano wrote: >> >> On Tue, 19 Jun 2018 10:19:15 +0100, Bart wrote: >> >>> * Swap(x,y) (evaluate each once unlike a,y=y,x) >> >> >> Sigh. Really? You think x,y = y,x evaluates x and y twice? > > > Yes. Try: > > count=0 > > def fn(): > global count > count=count+1 > return 1 > > a=[10,20,30,40] > b=[1,2,3,4] > > a[1],b[fn()] = b[fn()],a[1] > > print (a) > print (b) > print ("Count",count) > > b[fn()] is evaluated twice. Ahh right. You never mentioned that your swap targets had complex expressions in them. What a horrible pity that Python requires you to be explicit that fn should be called only once: idx = fn() a[1], b[idx] = b[idx], a[1] It's the price you pay for orthogonality, I guess. ChrisA From bc at freeuk.com Tue Jun 19 07:07:45 2018 From: bc at freeuk.com (Bart) Date: Tue, 19 Jun 2018 12:07:45 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: <3u5WC.872890$yN1.374078@fx28.am4> On 19/06/2018 11:45, Chris Angelico wrote: > On Tue, Jun 19, 2018 at 8:33 PM, Steven D'Aprano > wrote: >> Yeah, I get it, you like your language to have lots and lots and lots of >> syntax to do *slightly* different things. But it doesn't seem to be so >> good at doing application level functionality. Its basically just a less >> efficient, slightly prettier C. > > With the word "dynamic" in its description, of course. That's VERY > important. C is not a dynamic language. Bart's language is dynamic. > That makes it unimaginably better. > > ChrisA > What does 'dynamic' mean? For many it just means that variables have dynamic type. Which is exactly what mine has (and with automatic memory management which goes along with that). Some people may not even be aware of just how dynamic Python is. -- bart From e+python-list at kellett.im Tue Jun 19 07:13:30 2018 From: e+python-list at kellett.im (Ed Kellett) Date: Tue, 19 Jun 2018 12:13:30 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> Message-ID: <67c8dcef-d21d-217a-0371-1a7ba500e138@kellett.im> On 2018-06-19 11:21, Chris Angelico wrote: > Isn't it nice how comments, being terminated exclusively by > end-of-line, allow the introduction of subtle bugs? Let's see how many > people spot the (presumably deliberate) bug in Steve's code here. Hardly subtle. It does also make them considerably easier to remove from code. I think we're all--still--missing the larger point that "easy to remove" is a completely stupid metric for judging language features. Seriously. Not a little bit stupid. What would Python look like if every new feature had to be possible to grep out? -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From rosuav at gmail.com Tue Jun 19 07:16:55 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2018 21:16:55 +1000 Subject: syntax difference In-Reply-To: <3u5WC.872890$yN1.374078@fx28.am4> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <3u5WC.872890$yN1.374078@fx28.am4> Message-ID: On Tue, Jun 19, 2018 at 9:07 PM, Bart wrote: > On 19/06/2018 11:45, Chris Angelico wrote: >> >> On Tue, Jun 19, 2018 at 8:33 PM, Steven D'Aprano >> wrote: >>> >>> Yeah, I get it, you like your language to have lots and lots and lots of >>> syntax to do *slightly* different things. But it doesn't seem to be so >>> good at doing application level functionality. Its basically just a less >>> efficient, slightly prettier C. >> >> >> With the word "dynamic" in its description, of course. That's VERY >> important. C is not a dynamic language. Bart's language is dynamic. >> That makes it unimaginably better. >> >> ChrisA >> > > > What does 'dynamic' mean? Good question. You're the one who called your language "dynamic". > For many it just means that variables have dynamic type. Which is exactly > what mine has (and with automatic memory management which goes along with > that). So what does it mean for a variable to have dynamic type, then? Automatic memory management is different again. You can have typed variables (often called static typing), typed data (often called dynamic typing), and automatic garbage collection. They're all completely orthogonal. And they're not absolutes, although I don't often see partially-typed-data in a language. (Partially-typed variables are common.) If you're not using "dynamic typing" to mean "values have types", you're going to have to define it. ChrisA From rhodri at kynesim.co.uk Tue Jun 19 07:33:17 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 19 Jun 2018 12:33:17 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <6b9d3ddc-08a0-4ec6-9008-8dc0b0f55404@googlegroups.com> <6baf39f5-0e27-40e1-b0f2-49539387524d@googlegroups.com> Message-ID: On 18/06/18 21:39, Chris Angelico wrote: > On Tue, Jun 19, 2018 at 6:25 AM, Rick Johnson > wrote: >> Chris Angelico wrote: >> [...] >>> assert """ >>> """", ", ";print('Will I print?');\ >>> "';print("Or will I?");\ >>> ';print("What about me?");'''\ >>> print("And me? Where endeth");"""\ >>> print('the assertion?');\'''' >> >> Chris, that's not code... >> >> That's a syntactical representation of some random flea circus. > > Fortunately, my Python interpreter is able to execute flea circuses. It has little flea executioners running around with little flea axes chopping off little flea heads? -- Rhodri James *-* Kynesim Ltd From rosuav at gmail.com Tue Jun 19 07:43:11 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2018 21:43:11 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <6b9d3ddc-08a0-4ec6-9008-8dc0b0f55404@googlegroups.com> <6baf39f5-0e27-40e1-b0f2-49539387524d@googlegroups.com> Message-ID: On Tue, Jun 19, 2018 at 9:33 PM, Rhodri James wrote: > On 18/06/18 21:39, Chris Angelico wrote: >> >> On Tue, Jun 19, 2018 at 6:25 AM, Rick Johnson >> wrote: >>> >>> Chris Angelico wrote: >>> [...] >>>> >>>> assert """ >>>> """", ", ";print('Will I print?');\ >>>> "';print("Or will I?");\ >>>> ';print("What about me?");'''\ >>>> print("And me? Where endeth");"""\ >>>> print('the assertion?');\'''' >>> >>> >>> Chris, that's not code... >>> >>> That's a syntactical representation of some random flea circus. >> >> >> Fortunately, my Python interpreter is able to execute flea circuses. > > > It has little flea executioners running around with little flea axes > chopping off little flea heads? > Nah, it doesn't decapitate. It hangs them. It's a Python, after all. But yeah, you have the right idea. ChrisA From tjreedy at udel.edu Tue Jun 19 08:35:08 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 19 Jun 2018 08:35:08 -0400 Subject: Why an object changes its "address" between adjacent calls? In-Reply-To: <8c7dace8-28ef-96fd-fd20-3418e3e84268@caprilion.com.tw> References: <445dbeb0-7851-f572-250d-e3654297b663@ms4.hinet.net> <8c7dace8-28ef-96fd-fd20-3418e3e84268@caprilion.com.tw> Message-ID: On 6/18/2018 8:38 PM, sales at caprilion.com.tw wrote: > Grant Edwards at 2018/6/18 PM 10:36 wrote: >> On 2018-06-17, Jach Fong wrote: >>> C:\Python34\Doc>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. >>>>>> import tkinter as tk >>>>>> root = tk.Tk() >>>>>> tk.Label(root, text='label one', font='TkDefaultFont').pack() >>>>>> from tkinter import font >>>>>> font.nametofont('TkDefaultFont') >>> >>>>>> font.nametofont('TkDefaultFont') >>> >>>>>> >>> >>> The "address" of the Font object 'TkDefaultFont' changes, why? >> >> What makes you think it's the same object the second time and not a >> new object? > > Simply from what the method's name "name-to-font" implied. The font is > already there, so naturally it should be the same one:-) 'nametofont' is a trivial function returning 'Font(name=name, exists=True)'. As explained before, the address is the address of the Python Font interface object, not the tk font structure. tk has a mapping of font names to font structures. tkinter does not keep a dict mapping names or font structures to Font instances, so each call to Font returns a new Font instance. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Tue Jun 19 10:59:27 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jun 2018 14:59:27 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> <67c8dcef-d21d-217a-0371-1a7ba500e138@kellett.im> Message-ID: On Tue, 19 Jun 2018 12:13:30 +0100, Ed Kellett wrote: > I think > we're all--still--missing the larger point that "easy to remove" is a > completely stupid metric for judging language features. Seriously. Not a > little bit stupid. +1 -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From sharan.basappa at gmail.com Tue Jun 19 11:26:13 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Tue, 19 Jun 2018 08:26:13 -0700 (PDT) Subject: curve_fit in scipy Message-ID: Hi All, I am working out an exercise on curve_fit function available scipy package. While I understand in general about curve_fit, I am unable to understand the following: params, params_covariance = optimize.curve_fit(test_func, x_data, y_data, p0=[2, 2]) Firstly, I don't understand why test_func is passed as an argument to cur_fit Secondly, I don't understand how curve_fit knows the number of arguments that test_func takes. Full code is available below for reference: import numpy as np # Seed the random number generator for reproducibility np.random.seed(0) x_data = np.linspace(-5, 5, num=50) y_data = 2.9 * np.sin(1.5 * x_data) + np.random.normal(size=50) # And plot it import matplotlib.pyplot as plt plt.figure(figsize=(6, 4)) plt.scatter(x_data, y_data) from scipy import optimize def test_func(x, a, b): return a * np.sin(b * x) params, params_covariance = optimize.curve_fit(test_func, x_data, y_data, p0=[2, 2]) print(params) plt.figure(figsize=(6, 4)) plt.scatter(x_data, y_data, label='Data') plt.plot(x_data, test_func(x_data, params[0], params[1]), label='Fitted function') plt.legend(loc='best') plt.show() From steve+comp.lang.python at pearwood.info Tue Jun 19 11:31:44 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jun 2018 15:31:44 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: On Tue, 19 Jun 2018 11:52:22 +0100, Bart wrote: > On 19/06/2018 11:33, Steven D'Aprano wrote: >> On Tue, 19 Jun 2018 10:19:15 +0100, Bart wrote: >> >>> * Swap(x,y) (evaluate each once unlike a,y=y,x) >> >> Sigh. Really? You think x,y = y,x evaluates x and y twice? > > Yes. Well, you would be wrong. [steve at ando ~]$ python3.5 -c "import dis; dis.dis('x, y = y, x')" 1 0 LOAD_NAME 0 (y) 3 LOAD_NAME 1 (x) 6 ROT_TWO 7 STORE_NAME 1 (x) 10 STORE_NAME 0 (y) 13 LOAD_CONST 0 (None) 16 RETURN_VALUE > Try: [snip complex example] Why would I try that? You made a claim that x, y = y, x evaluates x and y twice. You didn't say anything about calling a function twice. Of course if you call a function twice, the function gets called twice. What does your language do? Shifting the goals posts is not a nice thing to do Bart. You made a claim about swapping two named variables, not one about multiple function calls. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From gherron at digipen.edu Tue Jun 19 12:14:24 2018 From: gherron at digipen.edu (Gary Herron) Date: Tue, 19 Jun 2018 09:14:24 -0700 Subject: curve_fit in scipy In-Reply-To: References: Message-ID: <8aee7e45-ad96-ed18-b937-380c4af8a7a2@digipen.edu> This is a Python forum, but what you are asking is not a Python question.? You might find a better source of answers on a scipy specific forum. But here's my attempt at answers: On 06/19/2018 08:26 AM, sharan.basappa at gmail.com wrote: > Hi All, > > I am working out an exercise on curve_fit function available scipy package. > > While I understand in general about curve_fit, I am unable to understand the following: > > params, params_covariance = optimize.curve_fit(test_func, x_data, y_data, > p0=[2, 2]) > > Firstly, I don't understand why test_func is passed as an argument to cur_fit You are trying to fit a curve to some data, right.? The curve_fit procedure needs to know what curve you are trying to fit.? Is it a linear curve, exponential, polynomial or ...?? In this example it's a sine function with parameters for regulating amplitude and frequency.? But it could be any function with any parameters.? To be more precise, test_function is not a single function y=f(x), but a whole family of functions y=f(x; a,b) where a and b define a particular function. > Secondly, I don't understand how curve_fit knows the number of arguments that test_func takes. Part of the dynamic nature of Python is that a function carries with it the number of parameters (as just one among many such properties).? We call it "introspection" when we examine such properties of objects.? The curve_fit function usees such an introspection to find that test_function has two parameters (a and b) defining the family of curves. > > Full code is available below for reference: > > import numpy as np > > # Seed the random number generator for reproducibility > np.random.seed(0) > > x_data = np.linspace(-5, 5, num=50) > y_data = 2.9 * np.sin(1.5 * x_data) + np.random.normal(size=50) > > # And plot it > import matplotlib.pyplot as plt > plt.figure(figsize=(6, 4)) > plt.scatter(x_data, y_data) > > from scipy import optimize > > def test_func(x, a, b): > return a * np.sin(b * x) > > params, params_covariance = optimize.curve_fit(test_func, x_data, y_data, > p0=[2, 2]) > > print(params) > > plt.figure(figsize=(6, 4)) > plt.scatter(x_data, y_data, label='Data') > plt.plot(x_data, test_func(x_data, params[0], params[1]), > label='Fitted function') > > plt.legend(loc='best') > > plt.show() -- Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology (425) 895-4418 From rantingrickjohnson at gmail.com Tue Jun 19 12:43:50 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 19 Jun 2018 09:43:50 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> Message-ID: On Tuesday, June 19, 2018 at 5:21:25 AM UTC-5, Chris Angelico wrote: > On Tue, Jun 19, 2018 at 8:12 PM, Steven D'Aprano > wrote: > > On Mon, 18 Jun 2018 11:34:40 -0700, Jim Lee wrote: > > > >> On 06/18/2018 11:18 AM, Chris Angelico wrote: > >>> What, fundamentally, is the difference between type hints and > >>> assertions, such that - in > >>> your view - one gets syntax and the other is just comments? > >> Type hints are just that - hints. They have no syntactic meaning to the > >> parser, and do not affect the execution path in any way. Therefore, they > >> are effectively and actually comments. The way they have been > >> implemented, though, causes noise to be interspersed with live code and, > >> as others have said, are difficult to remove or ignore. > > > > So let me get this straight... > > > > Using annotations is evil, because it intersperses noise with live code: > > > > def function(argument: int, > > flag: bool, > > sequence: list) -> str: > > ... > > > > > > But using comments is great, because it doesn't: > > > > def function(argument, # type=int, > > flag, # type=bool, > > sequence, # type=list): # type=str > > ... > > > > > > Okay, I'm glad we cleared that up. > > > > Isn't it nice how comments, being terminated exclusively by > end-of-line, allow the introduction of subtle bugs? Let's see how many > people spot the (presumably deliberate) bug in Steve's code here. It wasn't deliberate, Chris. But if Steven "presumably" wanted to show us why hanging comments are a code smell that most professional programmers will avoid, well, he certainly excelled at that, didn't he? From rantingrickjohnson at gmail.com Tue Jun 19 12:50:33 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 19 Jun 2018 09:50:33 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <6b9d3ddc-08a0-4ec6-9008-8dc0b0f55404@googlegroups.com> <6baf39f5-0e27-40e1-b0f2-49539387524d@googlegroups.com> Message-ID: <7f03e15f-32fe-4e9c-b249-da1fde121afd@googlegroups.com> Rhodri James wrote: [...] > It has little flea executioners running around with little flea axes > chopping off little flea heads? Hmm. And who knew that Python-list was really just a homicidal flea circus. Go figure! From steve+comp.lang.python at pearwood.info Tue Jun 19 13:07:25 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jun 2018 17:07:25 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> Message-ID: On Mon, 18 Jun 2018 10:34:54 -0700, Jim Lee wrote: > The syntax should be defined inside comments Then you ought to be pleased that from Python 4.0 (or from Python 3.7 with a ``__future__`` import) annotations will be treated as strings by the interpreter. That makes them effectively special comments like docstrings: they aren't executed, only recorded in the object for introspection. def func(x: int) -> str: becomes precisely the same as: def func(x): # type x:int, return:str except that the comment is attached to the function as a string for runtime introspection. > by the tools that actually > need to use them.? Let the tools do what they were designed to do.? Let > the language do what it was designed to do. Then you should be glad, because the language is designed to do this. Annotations in Python are the end result of a long, carefully thought out design process. > If static type checking were a high priority, I would not choose a > language like Python for the task You are talking as if "static type checking" were an end in itself. That's like saying "If unit tests were a high priority, I would not choose a language like C". Static type-checking is a means to an end. The end is more reliable code and making it easier to find bugs. I trust you don't mean to imply that you don't need to find bugs in Python code. If your linter or IDE can tell you that the function you intended to return a string can sometimes return None, why is this so horrible? > - but some people seem to want to beat > the language into submission as a do-everything-but-wash-my-car > solution; and in so doing, the language becomes so fragile and bloated > that people will walk away from it. Ah, I wondered how long it would be before the "feature X is killing Python" FUD reared its ugly head. > In reading through many of the PEPs, I'm reminded of the saying, "If all > you have is a hammer, everything looks like a nail". And when the most advanced tool you've used is a hammer, an electric drill looks like a very expensive, awkward to use hammer. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From ian.g.kelly at gmail.com Tue Jun 19 13:10:52 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 19 Jun 2018 11:10:52 -0600 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: On Tue, Jun 19, 2018 at 3:14 AM Steven D'Aprano wrote: > > On Mon, 18 Jun 2018 10:01:58 -0700, Rick Johnson wrote: > > > Steven D'Aprano wrote: > > [...] > >> particular at DropBox, which is (I believe) funding a lot of Guido's > >> time on this, because they need it. > > > > And now we get to the truth! > > > > Guido's new puppet master is the sole reason why this fine community -- > > of once free-roaming *STALLIONS*-- is now corralled and saddled with > > type-hints! > > I know that Rick's attitude towards reality is that facts are only for > other people, and that once he has made up his mind nothing will budge > it, *especially* not facts, but for anyone reading this who might be > fooled into imagining that Rick has a point, really, no. Don't worry, I think that most people are capable of recognizing it as an ad-hominem by a troll. Speaking of which, why hasn't Rick been banned years ago for this kind of crap? From rantingrickjohnson at gmail.com Tue Jun 19 13:58:08 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 19 Jun 2018 10:58:08 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: <3cab99e7-1f98-43c7-a0c3-045a72caa435@googlegroups.com> On Tuesday, June 19, 2018 at 4:12:10 AM UTC-5, Steven D'Aprano wrote: [...] > People have been requesting static typing in Python virtually since Day > 1, "Day one"??? Really? "People"??? How many people? Contrary to to your fuzzy memories, Steven, we all know that Guido _purposely_ designed this language to be _dynamic_. Python was never intended to be a statically typed language. Not then, and not ever! Hmm? Now you're confusing your own "straw man nostalgia" with actual history. But hey, don't allow the facts get in the way of a good lie! From ian.g.kelly at gmail.com Tue Jun 19 14:01:58 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 19 Jun 2018 12:01:58 -0600 Subject: syntax difference In-Reply-To: <12d85ed5-bf89-4537-a4e9-02308d7a2f52@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <20cb0f2f-ca06-411c-84b4-c83b0b276688@googlegroups.com> <12d85ed5-bf89-4537-a4e9-02308d7a2f52@googlegroups.com> Message-ID: On Mon, Jun 18, 2018 at 2:57 PM Rick Johnson wrote: > > On Monday, June 18, 2018 at 2:48:58 PM UTC-5, Ian wrote: > > I would also note that none of this applies to type hinting > > in any case. Type hints don't require the programmer to be > > able to explain anything in natural language, nor are they > > prone to becoming out-of-sync. > > > > Because if they do, then then the type analyzer will > > complain the very next time you run it. So if you're trying > > to make the case for type hints being treated like > > comments, this isn't it. > > My point is perfectly clear to anyone who bothers to read it > in its entirety. Actually, I responded to this paragraph because it was the only one that made any sense at all. I didn't consider the rest to be worth of the post to be worth the time. But if you want, I'll respond to the rest. > From the POV of the interpreter, comments are nothing but a > human crutch that is to be ignored. This is like saying that from the POV of the interpreter, the keyboard and monitor are nothing but a human crutch to be ignored. Okay, fine, but so what? > And even from the POV of a programmer, comments can be more > useful if they are ignored than if they are not. Some > programmers lack the skill required to properly explain the > workings of an algorithm in natural language, and thus, the > reader of such a comment will only become confused. > Likewise, comments are notorious for becoming out-of-sync > with the code. And at such point, comments are not only > _confusing_ or _misleading_, no, they have become _lies_. Already responded to above. > The point is, from the POV of the interpreter and the > programmer. comments are always going to be comments > regardless of whether special purpose tools parse them or > not. And given a choice between placing a new burden on a > programmer or placing that burden on the machine, we should > always choose to place that burden on the _machine_. As far as I can tell, you seem to be arguing that putting type hints in an annotation somehow puts a burden on the programmer, while putting type hints in a comment somehow puts a burden on the machine. This makes no sense to me. It's a "burden" (actually, a helpful tool) to the programmer either way: whether it's in a comment or an annotation, it's the programmer's job to keep it correct. Whether it's in a comment or an annotation, it's up to the programmer to read it or not in order to better understand the code. How it would be a burden on the machine either way is beyond me. > After all, it's the Python way. Whatever this platitude is supposed to mean. I don't see "shift the work of programming onto the machine" anywhere in the Zen of Python. > The beauty of type-hint comments is that even without > striping the type-hint comment from the source code, a > programmer can more easily ignore a type-hint comment than > the interleaved type-hint. This is especially true if the > programmer uses an editor which has syntax hilighting. My > syntax hilighter colors all comments a light gray. So > therefore, i can skip block and blocks of comments in a > fraction of second simply by quickly scanning down to the > first line that is not grayed out. This paragraph was the reason for my statement about "if you're trying to make the case for type hints being treated like comments, this isn't it". If this is not trying to justify why type hints should be in comments (so you can brush them under the rug and pretend they don't exist), then what is it? > I have asked time and time again for someone to directly > justify why py-dev won't offer a tool to remove the > interleaved type-hint syntax from scripts. You've been answered time and time again -- the devs are volunteers and are not beholden to do whatever you want just because you don't like it -- yet for some reason you keep asking. > And yet, this whole thread has been a giant cascade of > distractions from that one, simple, question. > > It is obvious to the impartial reader what is going on here. > > There is a systematic campaign of brow beating underway to > punish those who do not blindly accept the validity of type- > hints. And any wavering from the the official party line > will be subject to retributions. Yeah, just as soon as we finish covering up the moon landing hoax and chemtrails, we're all going to a secret Hillary Clinton deep state Illuminati meeting where we'll plan out how to control Python users forever. > That is not behavior of a community. A community would care > for the opinions of all members. Somebody who actually values the community would not make rude posts on the mailing list about other members of the community, accusing them all of being part of some conspiracy and accusing GvR of being a puppet. All I'm saying, you reap what you sow. And for all your desire to have your opinion heard, you seem awfully eager to dismiss the opinions of those who actually like and want type hints the way they are. > I have made my sacrifice, by agreeing that i will accept > the inclusion of type-hints even though i find the whole > concept the be a violation of Python's core principles. All > i ask in return is that the py-devs make a sacrifice of their > own, by releasing a tool to remove these type-hints error > free. I don't know why you seem to think that this is a negotiation between yourself and the devs. It's not. As far as the devs are concerned, the discussion on the function annotation feature is done. It was done over a decade ago, when the feature was added in Python 3.0. Nobody back then brought up "oh, there needs to also be a tool to cripple the new feature by removing all the annotations from the source". And FWIW, I rather doubt that the devs care about whether you personally "will accept the inclusion of type-hints". Python development is not about what Rick Johnson will accept. If you really, actually want this tool, then write it yourself. In the time you've spent complaining about it, you could have written it several times over already. But I don't think you will, because honestly, I don't think that you actually care about this issue at all. This is all just a control game for you, yet another soapbox for you to stand on and pretend like you have some sort of power over the Python community. > And then those of us who are offended by type-hints will > have no reason to complain. > > And wouldn't that be nice? > > Wouldn't it be nice to actually have a sense of community > again. > > Wouldn't it be nice to compromise instead of squabble? You can stop squabbling over this ridiculous issue any time you want. Just go away and write your type-hint-removal tool. From breamoreboy at gmail.com Tue Jun 19 14:10:50 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Tue, 19 Jun 2018 19:10:50 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: On 19/06/18 18:10, Ian Kelly wrote: > On Tue, Jun 19, 2018 at 3:14 AM Steven D'Aprano > wrote: >> >> On Mon, 18 Jun 2018 10:01:58 -0700, Rick Johnson wrote: >> >>> Steven D'Aprano wrote: >>> [...] >>>> particular at DropBox, which is (I believe) funding a lot of Guido's >>>> time on this, because they need it. >>> >>> And now we get to the truth! >>> >>> Guido's new puppet master is the sole reason why this fine community -- >>> of once free-roaming *STALLIONS*-- is now corralled and saddled with >>> type-hints! >> >> I know that Rick's attitude towards reality is that facts are only for >> other people, and that once he has made up his mind nothing will budge >> it, *especially* not facts, but for anyone reading this who might be >> fooled into imagining that Rick has a point, really, no. > > Don't worry, I think that most people are capable of recognizing it as > an ad-hominem by a troll. Speaking of which, why hasn't Rick been > banned years ago for this kind of crap? > The moderators are mostly thick Yanks who think that rr, Trump and Putin are decent people? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From grant.b.edwards at gmail.com Tue Jun 19 14:39:33 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 19 Jun 2018 18:39:33 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: On 2018-06-19, Steven D'Aprano wrote: > I know that Rick's attitude towards reality is that facts are only for > other people, and that once he has made up his mind nothing will budge > it, *especially* not facts, but for anyone reading this who might be > fooled into imagining that Rick has a point, really, no. Many of us plonked Rick ages ago. Now we only see his posts when people followup and quote him. -- Grant Edwards grant.b.edwards Yow! ... If I had heart at failure right now, gmail.com I couldn't be a more fortunate man!! From jlee54 at gmail.com Tue Jun 19 15:13:40 2018 From: jlee54 at gmail.com (Jim Lee) Date: Tue, 19 Jun 2018 12:13:40 -0700 Subject: syntax difference In-Reply-To: <67c8dcef-d21d-217a-0371-1a7ba500e138@kellett.im> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> <67c8dcef-d21d-217a-0371-1a7ba500e138@kellett.im> Message-ID: <3b51233d-94ee-5fc9-7c3e-5270df383cd0@gmail.com> On 06/19/2018 04:13 AM, Ed Kellett wrote: > I think > we're all--still--missing the larger point that "easy to remove" is a > completely stupid metric for judging language features. Seriously. Not a > little bit stupid. Not if you think of the feature as analogous to cancer. -Jim From rantingrickjohnson at gmail.com Tue Jun 19 15:38:24 2018 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 19 Jun 2018 12:38:24 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <20cb0f2f-ca06-411c-84b4-c83b0b276688@googlegroups.com> <12d85ed5-bf89-4537-a4e9-02308d7a2f52@googlegroups.com> Message-ID: <2f18ec2f-a8f4-4119-8230-f02632b21aec@googlegroups.com> On Tuesday, June 19, 2018 at 1:02:52 PM UTC-5, Ian wrote: > On Mon, Jun 18, 2018 at 2:57 PM Rick Johnson [...] > > The point is, from the POV of the interpreter and the > > programmer. comments are always going to be comments > > regardless of whether special purpose tools parse them or > > not. And given a choice between placing a new burden on a > > programmer or placing that burden on the machine, we > > should always choose to place that burden on the > > _machine_. > > As far as I can tell, you seem to be arguing that putting > type hints in an annotation somehow puts a burden on the > programmer, while putting type hints in a comment somehow > puts a burden on the machine. This makes no sense to me. And if it's any consolation for you, you'll be happy to know that i'm not at all surprised to learn this, either. > It's a "burden" (actually, a helpful tool) to the > programmer either way: whether it's in a comment or an > annotation, it's the programmer's job to keep it correct. > Whether it's in a comment or an annotation, it's up to the > programmer to read it or not in order to better understand > the code. How it would be a burden on the machine either > way is beyond me. If you had read my argument from the beginning of the thread, you would have known that: whilst i never liked the idea of Python having any kind of type annotations, i made it very clear at multiple places in this debate, that i am willing to grit my teeth and accept them *IF* the python dev team would be kind enough to (1) force all type annotation to be declared as comments, or (2) release a tool that will remove type-hints (error free) from scripts. And while i don't particularly enjoy repeating myself, i am hoping that perhaps this time it might sink in... > > After all, it's the Python way. > > Whatever this platitude is supposed to mean. I don't see > "shift the work of programming onto the machine" anywhere > in the Zen of Python. Ian, you an i both know that at our current level of technological evolution, we do not yet have machines that program themselves. That would require artificial intelligence. However, while our machines cannot yet program themselves, we certainly can offload many of the _burdens_ we programmers face onto these machines. And parsing, just like computation, is one of those repetitive burdens that machines perform far much better than any human ever could. Furthermore, and contrary to popular belief, the full philosophy of Python is not as neatly contained in the Zen as some may think. No. The Python Zen is merely a list of style prejudices which attempt to convey the "overall" philosophy of the stereotypical python programmer. Not a detailed style guide or an exhaustive rule book. Moreover, Guido has written and has been documented in interviews detailing the core principles of Python's design, and i dare any of you to find me one quote from those early days that gushed about type annotations. Go ahead now.... Give 'er a go! > > The beauty of type-hint comments is that even without > > striping the type-hint comment from the source code, a > > programmer can more easily ignore a type-hint comment than > > the interleaved type-hint. This is especially true if the > > programmer uses an editor which has syntax hilighting. My > > syntax hilighter colors all comments a light gray. So > > therefore, i can skip block and blocks of comments in a > > fraction of second simply by quickly scanning down to the > > first line that is not grayed out. > > This paragraph was the reason for my statement about "if > you're trying to make the case for type hints being treated > like comments, this isn't it". If this is not trying to > justify why type hints should be in comments (so you can > brush them under the rug and pretend they don't exist), > then what is it? Why shouldn't i have the right to "brush type-hints under the rug" Ian? After all, if the code *I* write doesn't belong to *ME*, well then, who *HELL* does it belong to? Is it not the right of the programmer to decide whether a named function is more appropriate than a list comprehension or an anonymous function? Huh??? Is is not the right of the programmer to decide that string formatting is more appropriate than string concatenation, or vice versa? Hmm??? Correct me if i'm wrong here, but i seem to remember an oft- sited statement around these parts which says roughly: "Python is programming for adults" . Meaning, that unlike more "formalized" languages (such as Java, for instance), Python does not try to dictate how we must write our code. Sure, there are certain exceptions to this rule, like forced indentation, for instance, but, compared to other languages, Python is perhaps one of the most tolerant when it comes to freedom. For instance, Python does not force us to declare private attribute and public attributes. Nor does it require us to write setters or getters. Each programmer can decide for themselves if they want to employ strategies which will present proper interfaces, or not. This is "programming for adults" -- okay. So with that in mind, i cannot understand why Python wants to saddle me with type-hints? But what is even more disturbing, is the hostility that is being displayed here when i request a simple tool that will remove these offensive type-hints. > You've been answered time and time again -- the devs are > volunteers and are not beholden to do whatever you want > just because you don't like it -- yet for some reason you > keep asking. Are you a dev? Is Chris a Dev? Is Steven a Dev? > [...] > And for all your desire to have your opinion heard, you > seem awfully eager to dismiss the opinions of those who > actually like and want type hints the way they are. Did you miss the part where i came to the table and made a compromise? Yea -- that part -- the part where i compromised to accept these type-hints in exchange for a tool that will remove them. Hmm. Is that too much to ask? Surely you don't believe that diplomacy is a one-sided compromise, do you? > I don't know why you seem to think that this is a > negotiation between yourself and the devs. It's not. As far > as the devs are concerned, the discussion on the function > annotation feature is done. And still you don't get it! I am willing to accept the inclusion of type-hints, just give me a damn tool to remove them! > It was done over a decade ago, when the feature was added > in Python 3.0. Nobody back then brought up "oh, there needs > to also be a tool to cripple the new feature by removing > all the annotations from the source". How will my non-use of type-hints "cripple" the feature? Does choosing a named function over a list comprehension somehow "cripple" list comprehensions? Does choosing a lambda over a named function cripple the "named-function feature"? No. That's ridiculous! Besides, isn't it you and chris and steven who claim that i am the only person in the whole community who doesn't want type-hints? Well, if that's true (and it's not!) then how is one person going to effect this supposedly "beloved" feature of yours it that one person refuses to use it? And BTW, what's the definition of FUD? PS: Tell your friend Steven that I'm still waiting on the nyms of all these supposed "people" of his who have been requesting static typing since "day one". From rosuav at gmail.com Tue Jun 19 15:45:56 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Jun 2018 05:45:56 +1000 Subject: syntax difference In-Reply-To: <2f18ec2f-a8f4-4119-8230-f02632b21aec@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <20cb0f2f-ca06-411c-84b4-c83b0b276688@googlegroups.com> <12d85ed5-bf89-4537-a4e9-02308d7a2f52@googlegroups.com> <2f18ec2f-a8f4-4119-8230-f02632b21aec@googlegroups.com> Message-ID: On Wed, Jun 20, 2018 at 5:38 AM, Rick Johnson wrote: >> You've been answered time and time again -- the devs are >> volunteers and are not beholden to do whatever you want >> just because you don't like it -- yet for some reason you >> keep asking. > > Are you a dev? > > Is Chris a Dev? > > Is Steven a Dev? > >> [...] > >> And for all your desire to have your opinion heard, you >> seem awfully eager to dismiss the opinions of those who >> actually like and want type hints the way they are. > > Did you miss the part where i came to the table and made a > compromise? Yea -- that part -- the part where i compromised > to accept these type-hints in exchange for a tool that will > remove them. Hmm. Is that too much to ask? Surely you don't > believe that diplomacy is a one-sided compromise, do you? Well, it looks like that compromise isn't going to happen. Which means, according to this statement, you are not going to accept type hints. Congratulations. You have rejected type hints. Now what? ChrisA From ian.g.kelly at gmail.com Tue Jun 19 16:44:34 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 19 Jun 2018 14:44:34 -0600 Subject: syntax difference In-Reply-To: <2f18ec2f-a8f4-4119-8230-f02632b21aec@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <20cb0f2f-ca06-411c-84b4-c83b0b276688@googlegroups.com> <12d85ed5-bf89-4537-a4e9-02308d7a2f52@googlegroups.com> <2f18ec2f-a8f4-4119-8230-f02632b21aec@googlegroups.com> Message-ID: On Tue, Jun 19, 2018 at 1:42 PM Rick Johnson wrote: > > On Tuesday, June 19, 2018 at 1:02:52 PM UTC-5, Ian wrote: > > On Mon, Jun 18, 2018 at 2:57 PM Rick Johnson > > It's a "burden" (actually, a helpful tool) to the > > programmer either way: whether it's in a comment or an > > annotation, it's the programmer's job to keep it correct. > > Whether it's in a comment or an annotation, it's up to the > > programmer to read it or not in order to better understand > > the code. How it would be a burden on the machine either > > way is beyond me. > > If you had read my argument from the beginning of the > thread, you would have known that: whilst i never liked the > idea of Python having any kind of type annotations, i made > it very clear at multiple places in this debate, that i am > willing to grit my teeth and accept them *IF* the python dev > team would be kind enough to (1) force all type annotation > to be declared as comments, or (2) release a tool that will > remove type-hints (error free) from scripts. No, that's been perfectly clear. What befuddles me is your continued insistence that the devs must do this, rather than writing the tool yourself. And yes, it would have to be (2), because (1) is obviously out of the question. The only way to "force" type annotations to be comments would be to remove the function annotation feature altogether, which would be hugely backward-incompatible. > > > After all, it's the Python way. > > > > Whatever this platitude is supposed to mean. I don't see > > "shift the work of programming onto the machine" anywhere > > in the Zen of Python. > > Ian, you an i both know that at our current level of > technological evolution, we do not yet have machines that > program themselves. That would require artificial > intelligence. However, while our machines cannot yet program > themselves, we certainly can offload many of the _burdens_ > we programmers face onto these machines. And parsing, just > like computation, is one of those repetitive burdens that > machines perform far much better than any human ever could. Type hints are no different in this regard than any other part of the program. You seem to be under the impression that the less you have to read, the easier it is. And while that's true to an extent, I'll remind you that comments, type hints, readable code, all of it are written primarily for consumption by *humans*, not the machine. "Programs must be written for people to read, and only incidentally for machines to execute." - Hal Abelson > Moreover, Guido has written and has been documented in > interviews detailing the core principles of Python's design, > and i dare any of you to find me one quote from those early > days that gushed about type annotations. Sorry, I won't be baited by your rhetorical nonsense. Function annotations are a feature, not a "core principle". You could equally well ask to find quotes about decorators, or coroutines, or list comprehensions, or metaclasses, etc. etc. > > > The beauty of type-hint comments is that even without > > > striping the type-hint comment from the source code, a > > > programmer can more easily ignore a type-hint comment than > > > the interleaved type-hint. This is especially true if the > > > programmer uses an editor which has syntax hilighting. My > > > syntax hilighter colors all comments a light gray. So > > > therefore, i can skip block and blocks of comments in a > > > fraction of second simply by quickly scanning down to the > > > first line that is not grayed out. > > > > This paragraph was the reason for my statement about "if > > you're trying to make the case for type hints being treated > > like comments, this isn't it". If this is not trying to > > justify why type hints should be in comments (so you can > > brush them under the rug and pretend they don't exist), > > then what is it? > > Why shouldn't i have the right to "brush type-hints under > the rug" Ian? After all, if the code *I* write doesn't > belong to *ME*, well then, who *HELL* does it belong to? You're deflecting. This goes on for several more angry paragraphs, so I'm just going to ignore it and skip ahead. > So with that in mind, i cannot understand why Python wants > to saddle me with type-hints? You seem to keep forgetting that they're optional. Even if you inherit a program that uses them, nobody is forcing you to read them, to run any sort of type analysis over them, or even to retain them. But just because you can delete them doesn't make anybody obligated to provide you with a tool that you can't be bothered to write for yourself. > But what is even more disturbing, is the hostility that is > being displayed here when i request a simple tool that will > remove these offensive type-hints. WRITE IT YOURSELF. That's not me being hostile, just direct. > > And for all your desire to have your opinion heard, you > > seem awfully eager to dismiss the opinions of those who > > actually like and want type hints the way they are. > > Did you miss the part where i came to the table and made a > compromise? Yea -- that part -- the part where i compromised > to accept these type-hints in exchange for a tool that will > remove them. Hmm. Is that too much to ask? Surely you don't > believe that diplomacy is a one-sided compromise, do you? I was actually referring to statements like this: > But yet, the _programmer_ cannot ignore it. Does that make > any sense to you, or anyone else with half a brain? That's the first thing you wrote in your second post in this thread. I have no doubt I can find more examples but I don't really want to wade through it. Sorry, but you can't go around labeling people as stupid for disagreeing with you, then turn around the next moment and hail yourself as a pillar of the community just because you "offered a [completely one-sided] compromise". You want to know what would actually be productive for the community and worthy of respect? Write the tool yourself. You claim that this is what people really want, right? So just sit down and knock it out, and you'll be a hero of the people. > > I don't know why you seem to think that this is a > > negotiation between yourself and the devs. It's not. As far > > as the devs are concerned, the discussion on the function > > annotation feature is done. > > And still you don't get it! I am willing to accept the > inclusion of type-hints, just give me a damn tool to remove > them! No, you still don't get it: nobody is losing any sleep over whether you personally accept the inclusion of type-hints or not. > Besides, isn't it you and chris and steven who claim that i > am the only person in the whole community who doesn't want > type-hints? I've not claimed any such thing. > PS: Tell your friend Steven that I'm still waiting on the > nyms of all these supposed "people" of his who have been > requesting static typing since "day one". Sorry, I don't know Steven beyond the occasional intersections of our posts here. From bart4858 at gmail.com Tue Jun 19 17:07:32 2018 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Tue, 19 Jun 2018 14:07:32 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: <1aff825f-8eac-4a59-9312-4ae17dc3b346@googlegroups.com> Do you think that a feature like swap(x,y) literally only works on two simple variables? X and y represent any two lvalue expressions. For example, a[I] and a[I+1]. Python will evaluate each twice. My version sets up two references then exchanges what they point to with one bytecode. -- Bart From rosuav at gmail.com Tue Jun 19 17:16:33 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Jun 2018 07:16:33 +1000 Subject: syntax difference In-Reply-To: <1aff825f-8eac-4a59-9312-4ae17dc3b346@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <1aff825f-8eac-4a59-9312-4ae17dc3b346@googlegroups.com> Message-ID: On Wed, Jun 20, 2018 at 7:07 AM, wrote: > Do you think that a feature like swap(x,y) literally only works on two simple variables? X and y represent any two lvalue expressions. For example, a[I] and a[I+1]. Python will evaluate each twice. > > My version sets up two references then exchanges what they point to with one bytecode. > Congratulations. You have something that you, personally, consider important, and which has zero externally-visible impact. But what about the couple dozen important features that I listed? ChrisA From bart4858 at gmail.com Tue Jun 19 17:41:24 2018 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Tue, 19 Jun 2018 14:41:24 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> I think you're getting a programming language mixed up with a bunch of random libraries. If you want to do any actual coding rather than scripting, such as implementing some of that stuff, then this is where those basic language features that are missing from core Python become useful. What do you do in python when a local function variable needs to retain its value? I'm sure it can do it, but I bet it's not as simple as how I do it. Multi-level loop break? Separators in numbers? I think that one is finally in. You can have all your libraries /and/ have fundamental language features at the same time. They are not mutually exclusive. From rosuav at gmail.com Tue Jun 19 17:52:31 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Jun 2018 07:52:31 +1000 Subject: syntax difference In-Reply-To: <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20180616225535.GA37027@cskk.homeip.net> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: On Wed, Jun 20, 2018 at 7:41 AM, wrote: > I think you're getting a programming language mixed up with a bunch of random libraries. > > If you want to do any actual coding rather than scripting, such as implementing some of that stuff, then this is where those basic language features that are missing from core Python become useful. > ALL of those features are part of the Python standard library. Every one of them is something you can do with a plain vanilla Python installation. They are useful for real-world coding, scripting, or whatever you want to call it. > What do you do in python when a local function variable needs to retain its value? I'm sure it can do it, but I bet it's not as simple as how I do it. > What do you mean, "retain its value"? Do you mean the way closures work? > Multi-level loop break? Separators in numbers? I think that one is finally in. Multi-level loop break is most commonly spelled "return". In over two decades of programming, the number of times I've needed to break out of multiple loops without breaking out of an entire function can be counted on the fingers of one hand. Specifically, three times. In nearly three decades. > You can have all your libraries /and/ have fundamental language features at the same time. They are not mutually exclusive. Of course! Funnily enough, that's what I have with Python. Do you have both, or do you only have checkbox language features? ChrisA From bart4858 at gmail.com Tue Jun 19 18:14:49 2018 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Tue, 19 Jun 2018 15:14:49 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <1aff825f-8eac-4a59-9312-4ae17dc3b346@googlegroups.com> Message-ID: Features? Important ones? Go back 40 years and see how important they were then. Most of them,nobody had heard of, and would not be meaningful. Now do the same with my list - most are programming features that could be understood and appreciated even then. Finally, imagine going forward 40 years; how many of those acronyms will still be relevant? But anyone still involved in coding algorithms will likely still find some of my features useful. Although the language will long be gone. From rosuav at gmail.com Tue Jun 19 18:40:07 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Jun 2018 08:40:07 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <1aff825f-8eac-4a59-9312-4ae17dc3b346@googlegroups.com> Message-ID: On Wed, Jun 20, 2018 at 8:14 AM, wrote: > Features? Important ones? Go back 40 years and see how important they were then. Most of them,nobody had heard of, and would not be meaningful. > Let's see. Forty years ago was 1978. Databasing was a little bit important. I mean, not much... just that it was the main reason a lot of companies would buy computers. It was a simpler time; a time when people didn't have to worry about silly things like "standards", because you would just always buy from the same manufacturer. You didn't have to worry about "security" because people didn't send information out on the internet. Oh, and people like you weren't writing programming languages, so nobody cared about checklists. Fortunately, it's 2018, and we have this little thing called the "internet" in every single person's home, more or less. Internet protocols, consequently, are fairly important. > Now do the same with my list - most are programming features that could be understood and appreciated even then. > > Finally, imagine going forward 40 years; how many of those acronyms will still be relevant? Here are all of the acronyms I used: * TCP, UDP: Definitely going to be relevant for the foreseeable future. * HTTP, SMTP, IMAP: Probably going to be relevant. * SSL: Definitely relevant, although you might prefer to use the acronym "TLS" today, and maybe others in the future. But the concept will still stand, and libraries will migrate. * JSON, MIME: Likely to be relevant. Maybe others will be as well, but without tipping these out. * GUI: Definitely relevant. So long as we have humans, GUIs will be wanted. * GNU: https://xkcd.com/1508/ * lzma: Maybe, maybe not. * sha: Definitely. I'd go with "most of them". > But anyone still involved in coding algorithms will likely still find some of my features useful. Although the language will long be gone. Ahh, coding algorithms. Okay. Do you have: 1) A way to guarantee that a function is pure? 2) A simple means of constructing a list/array from another list/array by performing a transformation on it? ("map" or a comprehension) 3) A simple means of filtering a list/array to only those which fit some criterion? ("filter" or a comprehension) 4) First-class functions, and closures? 5) A way to easily see whether a function will mutate its arguments? That's a basic start. If you can do all of those, you might possibly have a language that is beautifully aimed at whiteboards and blackboards across the world. Mathematicians will love you. ChrisA From bart4858 at gmail.com Tue Jun 19 19:25:50 2018 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Tue, 19 Jun 2018 16:25:50 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <1aff825f-8eac-4a59-9312-4ae17dc3b346@googlegroups.com> Message-ID: Some of that can be done. It may not need specific support. But my intention is to have an ordinary language for everyday coding not one that can only be understood by CS professors. Mine is unusual in that I can drop features I rarely use, which means that everything in it gets good use. Including multi-level breaks. And the core language can stay small (or smallish - it's not Forth). Which I think is where we came in. From iansuderman at gmail.com Tue Jun 19 20:41:11 2018 From: iansuderman at gmail.com (iansuderman at gmail.com) Date: Tue, 19 Jun 2018 17:41:11 -0700 (PDT) Subject: Writing an assembler in Python In-Reply-To: References: Message-ID: <23e8c7fc-9297-4a4c-9501-63a00dded1b1@googlegroups.com> What does the code look like to insert assembler into python and how does that code send information back to python. It seems you wrote that python is a good compiler for assembly. If possible I want to add assembly to my python. From steve+comp.lang.python at pearwood.info Tue Jun 19 21:11:19 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 20 Jun 2018 01:11:19 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <1aff825f-8eac-4a59-9312-4ae17dc3b346@googlegroups.com> Message-ID: On Tue, 19 Jun 2018 14:07:32 -0700, bart4858 wrote: > Do you think that a feature like swap(x,y) literally only works on two > simple variables? I think that if you write "x" and "y", you mean placeholder names that stand in for arbitrary variable names, not expressions. That's the common and usual meaning. I *know* that when I write "x" and "y", I mean names. Not integer literals, not class definition statements, not while loops, not try...except blocks, not GOTO labels. If I intended something other than simple names, I would have said so. So how about accepting that your communication was less than clear, instead of trying to deflect the blame for miscommunication on the reader? As the writer, you are responsible for your own words, and if they are open to misinterpretation, the correct response is "Mea culpa", not "why didn't you read what I meant, instead of what I wrote, you idiot?" -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From jfong at ms4.hinet.net Tue Jun 19 21:19:10 2018 From: jfong at ms4.hinet.net (Jach Fong) Date: Wed, 20 Jun 2018 09:19:10 +0800 Subject: Why an object changes its "address" between adjacent calls? In-Reply-To: References: <445dbeb0-7851-f572-250d-e3654297b663@ms4.hinet.net> <8c7dace8-28ef-96fd-fd20-3418e3e84268@caprilion.com.tw> Message-ID: <6cc5e7f0-8d14-b709-ac9c-12be3b6dfc77@ms4.hinet.net> Terry Reedy at 2018/6/19 PM 08:35 wrote: > On 6/18/2018 8:38 PM, sales at caprilion.com.tw wrote: >> Grant Edwards at 2018/6/18 PM 10:36 wrote: >>> On 2018-06-17, Jach Fong wrote: >>>> The "address" of the Font object 'TkDefaultFont' changes, why? >>> >>> What makes you think it's the same object the second time and not a >>> new object? >> >> Simply from what the method's name "name-to-font" implied. The font is >> already there, so naturally it should be the same one:-) > > 'nametofont' is a trivial function returning 'Font(name=name, > exists=True)'.? As explained before, the address is the address of the > Python Font interface object, not the tk font structure.? tk has a > mapping of font names to font structures.? tkinter does not keep a dict > mapping names or font structures to Font instances, so each call to Font > returns a new Font instance. > Thank you, Terry. I understand the relationship between Python- tkinter-tk after you had explained before. Even though, I had to push myself back to the status when I started this thread, to reply Grant's question:-) After switching from comp.lang.python to python-list a while, I noticed that a thread can become fragile caused by the delay of email. Sometimes it makes discussion a little confusion:-) --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From steve+comp.lang.python at pearwood.info Tue Jun 19 21:19:37 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 20 Jun 2018 01:19:37 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: On Wed, 20 Jun 2018 07:52:31 +1000, Chris Angelico wrote: >> What do you do in python when a local function variable needs to retain >> its value? I'm sure it can do it, but I bet it's not as simple as how I >> do it. >> > What do you mean, "retain its value"? Do you mean the way closures work? I think that Bart means something like static variables in C. That's something I'd like to see Python get. The simplest work-around we have is to put the static variable in the function parameter list as if it were an argument of the function. >> Multi-level loop break? Separators in numbers? I think that one is >> finally in. > > Multi-level loop break is most commonly spelled "return". Not in languages that have a multi-level break. > In over two > decades of programming, the number of times I've needed to break out of > multiple loops without breaking out of an entire function can be counted > on the fingers of one hand. Specifically, three times. In nearly three > decades. Okay. The number of times I've wanted an asynchronous function so far has been zero, therefore the feature must be useless, right? *wink* -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Tue Jun 19 22:33:29 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 20 Jun 2018 02:33:29 +0000 (UTC) Subject: Writing an assembler in Python References: <23e8c7fc-9297-4a4c-9501-63a00dded1b1@googlegroups.com> Message-ID: On Tue, 19 Jun 2018 17:41:11 -0700, iansuderman wrote: > What does the code look like to insert assembler into python and how > does that code send information back to python. > > It seems you wrote that python is a good compiler for assembly. If > possible I want to add assembly to my python. Who are you talking too? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From drsalists at gmail.com Tue Jun 19 22:54:37 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 19 Jun 2018 19:54:37 -0700 Subject: Writing an assembler in Python In-Reply-To: References: <23e8c7fc-9297-4a4c-9501-63a00dded1b1@googlegroups.com> Message-ID: On Tue, Jun 19, 2018 at 7:33 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Tue, 19 Jun 2018 17:41:11 -0700, iansuderman wrote: > > > What does the code look like to insert assembler into python and how > > does that code send information back to python. > > > > It seems you wrote that python is a good compiler for assembly. If > > possible I want to add assembly to my python. > > Who are you talking too? > If Python does inline assembler, this is the first I've heard of it. You can do something kind of like this (but nicer) using https://pypi.org/project/numba/ Just make sure to use it in "no-python" mode, not "object" mode. HTH > From sharan.basappa at gmail.com Tue Jun 19 23:01:54 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Tue, 19 Jun 2018 20:01:54 -0700 (PDT) Subject: curve_fit in scipy In-Reply-To: References: <8aee7e45-ad96-ed18-b937-380c4af8a7a2@digipen.edu> Message-ID: > > Secondly, I don't understand how curve_fit knows the number of arguments that test_func takes. > > Part of the dynamic nature of Python is that a function carries with it > the number of parameters (as just one among many such properties).? We > call it "introspection" when we examine such properties of objects.? The > curve_fit function usees such an introspection to find that > test_function has two parameters (a and b) defining the family of curves. Thanks a lot. The above feature where a given function is able to inspect another function is really cool. This gives me an idea to go a read it further. From steve+comp.lang.python at pearwood.info Tue Jun 19 23:11:56 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 20 Jun 2018 03:11:56 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <20cb0f2f-ca06-411c-84b4-c83b0b276688@googlegroups.com> <12d85ed5-bf89-4537-a4e9-02308d7a2f52@googlegroups.com> <2f18ec2f-a8f4-4119-8230-f02632b21aec@googlegroups.com> Message-ID: On Tue, 19 Jun 2018 12:38:24 -0700, Rick Johnson wrote: > Why shouldn't i have the right to "brush type-hints under the rug" Ian? > After all, if the code *I* write doesn't belong to *ME*, well then, who > *HELL* does it belong to? If you don't want to use type-hints in your own code, why did you put them in in the first place? Don't expect somebody else to reverse your own foolishness. You put the annotations in, you can take them out. > Is it not the right of the programmer to decide whether a named function > is more appropriate than a list comprehension or an anonymous function? It isn't the right of the programmer to have somebody else write a function to convert the one to another for them. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Tue Jun 19 23:13:09 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 20 Jun 2018 03:13:09 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> <67c8dcef-d21d-217a-0371-1a7ba500e138@kellett.im> <3b51233d-94ee-5fc9-7c3e-5270df383cd0@gmail.com> Message-ID: On Tue, 19 Jun 2018 12:13:40 -0700, Jim Lee wrote: > On 06/19/2018 04:13 AM, Ed Kellett wrote: >> I think >> we're all--still--missing the larger point that "easy to remove" is a >> completely stupid metric for judging language features. Seriously. Not >> a little bit stupid. > > Not if you think of the feature as analogous to cancer. That would take it so far beyond the stupidity event horizon that no human language has an adjective for how stupid it is. Besides, annotations aren't cancer. They're obviously terrorism. Any fool can see that. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Wed Jun 20 00:18:19 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Jun 2018 14:18:19 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: On Wed, Jun 20, 2018 at 11:19 AM, Steven D'Aprano wrote: > On Wed, 20 Jun 2018 07:52:31 +1000, Chris Angelico wrote: > >>> What do you do in python when a local function variable needs to retain >>> its value? I'm sure it can do it, but I bet it's not as simple as how I >>> do it. >>> >> What do you mean, "retain its value"? Do you mean the way closures work? > > I think that Bart means something like static variables in C. That's > something I'd like to see Python get. The simplest work-around we have is > to put the static variable in the function parameter list as if it were > an argument of the function. Ah. Yeah, that would be a plausible feature to add to Python. But in C, a static variable is basically the same thing as a global variable, except that its name is scoped to the function. There is only one of it. What happens in Python? For instance: def f(): def g(): static x = 0 x += 1 return x return g Does the static variable exist once for each instance of g()? If so, it'll behave like a closure variable; if not, it'll behave like a global. Either way, I'm pretty much certain that people will expect the other. >>> Multi-level loop break? Separators in numbers? I think that one is >>> finally in. >> >> Multi-level loop break is most commonly spelled "return". > > Not in languages that have a multi-level break. Sure, but across all languages, it's most commonly spelled "return", and I don't see very many people screaming for multi-level break. >> In over two >> decades of programming, the number of times I've needed to break out of >> multiple loops without breaking out of an entire function can be counted >> on the fingers of one hand. Specifically, three times. In nearly three >> decades. > > Okay. The number of times I've wanted an asynchronous function so far has > been zero, therefore the feature must be useless, right? > > *wink* Fair criticism. However, his original statement was that these were inherently useful features. Some of them are definitely useful (static variables, maybe reference arguments); others are useful in some languages but a terrible fit for something like Python (pointers); and some are just not all that commonly needed. Compare the number of times you use a for...else, the number of times you use multi-level break, and the number of times you use slices with negative steps. Now add all of them up, and compare to the number of times you use subprocesses, or network calls (either the direct socket layer, or one of the higher level features that's built on it, like HTTP download). Both of those are highly practical features. Neither can be implemented purely in the stdlib (unless you just punt on it by making a totally unchecked way to make system calls). Both are, therefore, extremely useful language features, even though they don't actually require dedicated syntax. ChrisA From dieter at handshake.de Wed Jun 20 01:16:33 2018 From: dieter at handshake.de (dieter) Date: Wed, 20 Jun 2018 07:16:33 +0200 Subject: Writing an assembler in Python References: <23e8c7fc-9297-4a4c-9501-63a00dded1b1@googlegroups.com> Message-ID: <87bmc6ujf2.fsf@handshake.de> iansuderman at gmail.com writes: > What does the code look like to insert assembler into python and how does that code send information back to python. Python is a "high level" language: it tries hard to hide many "low level" details such as addresses and memory management. Thus, it is quite far away from low level assembler code. You can use something like "cython" to compile something similar to Python source code into C/C++ code - either for direct optimizations or to interface with C/C++ libraries. In the second case, the C/C++ functions can include assembly code (provided this is supported by the compiler). "cython" handles most of the difficulties of Python's C API, thus typically providing for (rather) safe Python-C/C++ interaction. I suggest to read its documentation. From greg.ewing at canterbury.ac.nz Wed Jun 20 02:00:12 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 20 Jun 2018 18:00:12 +1200 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: Bart wrote: > a[1],b[fn()] = b[fn()],a[1] I suppose if you find yourself doing heaps of swaps with complicated indexes it could be useful to have a swap primitive. In my experience it's a pretty rare thing to want to do, though. Also it only covers one special case of all possible permutations. It won't help you with a, b, c = b, c, a for example. -- Greg From brian.j.oney at googlemail.com Wed Jun 20 05:28:38 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Wed, 20 Jun 2018 11:28:38 +0200 Subject: command line utility for cups Message-ID: <1529486918.18542.1.camel@gmail.com> Dear all, I am having trouble with argparse. I am trying to translate the following line to a sleek python script: lpr -o media=legal -o sides=two-sided-long-edge filename Now where I am. import argparse parser = argparse.ArgumentParser(description='Print stuff with cups') parser.add_argument('--printer', '-p', ????????????????????help='Use this printer, try running: lpstat -a') parser.add_argument('--options', '-o',? ????????????????????help='Options for this printer, try running: \ ????????????????????lpoptions -p PRINTER -l') parser.parse_known_args(['-o', 'sides=one-sided', '-o', 'test=crap']) Namespace(options='test=crap', printer=None)) How should I deal with multiple options being fed into my script? Thanks! Cheers, Brian From bart4858 at gmail.com Wed Jun 20 05:35:28 2018 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Wed, 20 Jun 2018 02:35:28 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: (Sorry no idea how to do quoting on this mobile app I have to use.) Those examples of using network features are merely examples of function calls. This is what I'm talking about with basic language features. Pointers are merely an extra level of indirection; they can be made to fit. A few things might need language help, or help from its runtime. So that if I wanted a pointer to the first byte of this programs image on windows, I'd have to do: P := makeref(0x40'0000, byte) Which I then access as P^. The stuff you're talking about, imo, is at a completely different level. Someone could take core Python and repackage it with a completely different set of libraries. What happened to the network stuff? From rosuav at gmail.com Wed Jun 20 05:46:44 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Jun 2018 19:46:44 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: On Wed, Jun 20, 2018 at 7:35 PM, wrote: > (Sorry no idea how to do quoting on this mobile app I have to use.) > > Those examples of using network features are merely examples of function calls. This is what I'm talking about with basic language features. > > Pointers are merely an extra level of indirection; they can be made to fit. > > A few things might need language help, or help from its runtime. So that if I wanted a pointer to the first byte of this programs image on windows, I'd have to do: > > P := makeref(0x40'0000, byte) > > Which I then access as P^. The stuff you're talking about, imo, is at a completely different level. Someone could take core Python and repackage it with a completely different set of libraries. What happened to the network stuff? > http://wiki.c2.com/?BlubParadox ChrisA From __peter__ at web.de Wed Jun 20 06:21:02 2018 From: __peter__ at web.de (Peter Otten) Date: Wed, 20 Jun 2018 12:21:02 +0200 Subject: command line utility for cups References: <1529486918.18542.1.camel@gmail.com> Message-ID: Brian Oney via Python-list wrote: > Dear all, > > I am having trouble with argparse. I am trying to translate the following > line to a sleek python script: > > lpr -o media=legal -o sides=two-sided-long-edge filename > > Now where I am. > > import argparse > parser = argparse.ArgumentParser(description='Print stuff with cups') > parser.add_argument('--printer', '-p', > help='Use this printer, try running: lpstat -a') > parser.add_argument('--options', '-o', > help='Options for this printer, try running: \ > lpoptions -p PRINTER -l') > > parser.parse_known_args(['-o', 'sides=one-sided', '-o', 'test=crap']) > Namespace(options='test=crap', printer=None)) > > How should I deal with multiple options being fed into my script? > > Thanks! Try action="append". You may also provide a type=split_func argument to split the key=value pairs: >>> import argparse >>> parser = argparse.ArgumentParser() >>> parser.add_argument("-o", action="append", type=lambda p: p.split("=", 1)) _AppendAction(option_strings=['-o'], dest='o', nargs=None, const=None, default=None, type= at 0x7feef70a8510>, choices=None, help=None, metavar=None) >>> parser.parse_args(["-o", "a=b", "-o", "c=d"]) Namespace(o=[['a', 'b'], ['c', 'd']]) From george at fischhof.hu Wed Jun 20 06:36:29 2018 From: george at fischhof.hu (George Fischhof) Date: Wed, 20 Jun 2018 12:36:29 +0200 Subject: command line utility for cups In-Reply-To: References: <1529486918.18542.1.camel@gmail.com> Message-ID: Peter Otten <__peter__ at web.de> ezt ?rta (id?pont: 2018. j?n. 20., Sze 12:22): > Brian Oney via Python-list wrote: > > > Dear all, > > > > I am having trouble with argparse. I am trying to translate the following > > line to a sleek python script: > > > > lpr -o media=legal -o sides=two-sided-long-edge filename > > > > Now where I am. > > > > import argparse > > parser = argparse.ArgumentParser(description='Print stuff with cups') > > parser.add_argument('--printer', '-p', > > help='Use this printer, try running: lpstat -a') > > parser.add_argument('--options', '-o', > > help='Options for this printer, try running: \ > > lpoptions -p PRINTER -l') > > > > parser.parse_known_args(['-o', 'sides=one-sided', '-o', 'test=crap']) > > Namespace(options='test=crap', printer=None)) > > > > How should I deal with multiple options being fed into my script? > > > > Thanks! > > Try action="append". You may also provide a type=split_func argument to > split the key=value pairs: > > >>> import argparse > >>> parser = argparse.ArgumentParser() > >>> parser.add_argument("-o", action="append", type=lambda p: p.split("=", > 1)) > _AppendAction(option_strings=['-o'], dest='o', nargs=None, const=None, > default=None, type= at 0x7feef70a8510>, choices=None, > help=None, metavar=None) > >>> parser.parse_args(["-o", "a=b", "-o", "c=d"]) > Namespace(o=[['a', 'b'], ['c', 'd']]) > > > -- > https://mail.python.org/mailman/listinfo/python-list Hi, You can also try click library from pypi, that is a very good command line stuff. George > > From bart4858 at gmail.com Wed Jun 20 06:43:17 2018 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Wed, 20 Jun 2018 03:43:17 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Yeah, people keep bringing that up when they run out of arguments. So, every programmer must always use the most advanced, most esoteric features possible at every opportunity? Coding should only be for the elite? There is a place for various levels of programming language. I'm saying that Python which is always touted as a 'simple' language suitable for beginners, is missing a surprising number of basics. That these are useful is demonstrated by the cumbersome add-ons that need to be used to provide that functionality. Often in over the top ways and often in a bewildering variety of ways in the case of records. From brian.j.oney at googlemail.com Wed Jun 20 06:46:14 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Wed, 20 Jun 2018 12:46:14 +0200 Subject: command line utility for cups In-Reply-To: References: <1529486918.18542.1.camel@gmail.com> Message-ID: <772E9776-2ACC-42F5-84F2-3BAF4413EB2E@gmail.com> Thanks Peter! That's pretty slick. I will get it working for sure now. Regards, Brian From rosuav at gmail.com Wed Jun 20 06:49:46 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Jun 2018 20:49:46 +1000 Subject: syntax difference In-Reply-To: <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: On Wed, Jun 20, 2018 at 8:43 PM, wrote: > Yeah, people keep bringing that up when they run out of arguments. > > So, every programmer must always use the most advanced, most esoteric features possible at every opportunity? Coding should only be for the elite? > > There is a place for various levels of programming language. I'm saying that Python which is always touted as a 'simple' language suitable for beginners, is missing a surprising number of basics. The whole point of the Blub Paradox is that you, from your perspective, perceive pointers and such as "basics", whereas someone who is ACTUALLY new to programming does not want or need them. And I can say this for certain because I frequently work with people who have never written a line of code in their lives. Python has tools that help them to solve real-world problems. It does not have toys that let you write high-level C code. Since you apparently have never used the bulk of Python's features, you don't value them. They are above you on the Blub scale. ChrisA From brian.j.oney at googlemail.com Wed Jun 20 07:40:49 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Wed, 20 Jun 2018 13:40:49 +0200 Subject: command line utility for cups In-Reply-To: References: <1529486918.18542.1.camel@gmail.com> Message-ID: <1529494849.21969.1.camel@gmail.com> On Wed, 2018-06-20 at 12:36 +0200, George Fischhof wrote: > Hi, > You can also try click library from pypi, that is a very good command line > stuff. > > George Thank you for the tip. I am away of click and it's awesomeness, but am hesitant because it's not apart of stdlib. I have gotten bitten too often. From bart4858 at gmail.com Wed Jun 20 07:53:49 2018 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Wed, 20 Jun 2018 04:53:49 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> Pointers are perhaps a more technical feature. Switch and case, the latter a more general version of switch, are universal. Repeat n times is universal. While it is trivial to implement with other constructs, it as an annoyance and distraction that is easily fixed. Now you will probably say it is possible to do without loops at all, or without selecting from one of multiple execution paths (by using functional approaches). I suggest that such features just make life a little simpler. (And make writing an efficient interpreter a little bit easier.) From steve+comp.lang.python at pearwood.info Wed Jun 20 08:03:17 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 20 Jun 2018 12:03:17 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: On Wed, 20 Jun 2018 03:43:17 -0700, bart4858 wrote: > I'm saying > that Python which is always touted as a 'simple' language suitable for > beginners, is missing a surprising number of basics. You call them "basics". Must of us call most of them "unnecessary bloat". What we call "the basics", like the object execution module which you hate so much, *you* call "unnecessary bloat". THAT is the blub paradox, which you have completely failed to grok. I consider a seamless and easy way to open, incrementally read line by line, and close, a Unicode text file like this: with open(somefile, "r", encoding='spam', errors='eggs') as f: # for some value of spam and eggs :-) for line in f: process(line) to be "the basics". If your language doesn't do that, to me it is too primitive to use. You, on the other hand, probably consider the idea of context managers and iterators and Unicode to be unnecessary bloat, and think that any language which doesn't have a 1970-style Pascal read()/ readln() function is missing "the basics". -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Wed Jun 20 08:05:02 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Jun 2018 22:05:02 +1000 Subject: syntax difference In-Reply-To: <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> Message-ID: On Wed, Jun 20, 2018 at 9:53 PM, wrote: > Pointers are perhaps a more technical feature. Switch and case, the latter a more general version of switch, are universal. > > > Repeat n times is universal. While it is trivial to implement with other constructs, it as an annoyance and distraction that is easily fixed. > > Now you will probably say it is possible to do without loops at all, or without selecting from one of multiple execution paths (by using functional approaches). I suggest that such features just make life a little simpler. (And make writing an efficient interpreter a little bit easier.) > Interesting that you want a "repeat N times" construct rather than "for _ in range(n):", for efficiency; but you're happy to have pointers, which prevent many forms of optimization. The instant you have a pointer, you are forced to store that data at that location in memory, in case something dereferences that pointer. Python, on the other hand, is free to optimize things down to a stack, so long as there's no semantic difference. Also: how do you do memory management when you have pointers? Or do you give that job to the programmer? ChrisA From mail at timgolden.me.uk Wed Jun 20 08:10:56 2018 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 20 Jun 2018 13:10:56 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> Message-ID: <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> [... snip discussions about Bart's language ...] Wearing my moderator hat Can we take the "Bart's language vs Python Show" to some other forum, please? We've already gone over this ground again and again and it isn't helping the signal-to-noise ratio here on the Python list / comp.lang.python Thanks TJG From alister.ware at ntlworld.com Wed Jun 20 09:03:26 2018 From: alister.ware at ntlworld.com (Alister) Date: Wed, 20 Jun 2018 13:03:26 GMT Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <6eUVC.491716$Qg7.378011@fx08.am4> <1aff825f-8eac-4a59-9312-4ae17dc3b346@googlegroups.com> Message-ID: On Tue, 19 Jun 2018 16:25:50 -0700, bart4858 wrote: > Some of that can be done. It may not need specific support. > > But my intention is to have an ordinary language for everyday coding not > one that can only be understood by CS professors. > > Mine is unusual in that I can drop features I rarely use, which means > that everything in it gets good use. Including multi-level breaks. > only because no one else is using your language & you do not have to worry about breaking the code of your userbase. I think you are suffering from NIH* syndrome & are reinventing the wheel for no particular reason other than "Because you can" > And the core language can stay small (or smallish - it's not Forth). > Which I think is where we came in. * Not Invented Here -- To be a kind of moral Unix, he touched the hem of Nature's shift. -- Shelley From bart4858 at gmail.com Wed Jun 20 09:08:07 2018 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Wed, 20 Jun 2018 06:08:07 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> Message-ID: <42caa157-9897-4ce0-b9b5-e325a5391707@googlegroups.com> It isn't about my language versus Python. It is about the surprising number of simple features that are missing and that people are claiming don't matter, despite the considerable efforts made to provide them via add-ons. But I'm glad you stepped because making these posts via a smartphone AND google groups is a rather painful experience. -- Bart From darcy at VybeNetworks.com Wed Jun 20 09:08:48 2018 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Wed, 20 Jun 2018 09:08:48 -0400 Subject: Feeding the trolls In-Reply-To: <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> Message-ID: <7435bbd5-656b-7976-0f1d-605bd1a9ae35@VybeNetworks.com> On 2018-06-20 08:10 AM, Tim Golden wrote: > [... snip discussions about Bart's language ...] > > Wearing my moderator hat > > Can we take the "Bart's language vs Python Show" to some other forum, > please? We've already gone over this ground again and again and it isn't > helping the signal-to-noise ratio here on the Python list / > comp.lang.python Thank you. Many of us have blocked rick and bart years ago. If you are just going to feed the trolls we have to see their nonsense anyway. Just email them privately if you really feel the need to vent. One of these days I will have to figure out how to block replies to the trolls as well. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From alister.ware at ntlworld.com Wed Jun 20 09:41:16 2018 From: alister.ware at ntlworld.com (Alister) Date: Wed, 20 Jun 2018 13:41:16 GMT Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> <67c8dcef-d21d-217a-0371-1a7ba500e138@kellett.im> <3b51233d-94ee-5fc9-7c3e-5270df383cd0@gmail.com> Message-ID: <0QsWC.308334$AX1.195345@fx25.am4> On Wed, 20 Jun 2018 03:13:09 +0000, Steven D'Aprano wrote: > On Tue, 19 Jun 2018 12:13:40 -0700, Jim Lee wrote: > >> On 06/19/2018 04:13 AM, Ed Kellett wrote: >>> I think we're all--still--missing the larger point that "easy to >>> remove" is a completely stupid metric for judging language features. >>> Seriously. Not a little bit stupid. >> >> Not if you think of the feature as analogous to cancer. > > That would take it so far beyond the stupidity event horizon that no > human language has an adjective for how stupid it is. > > Besides, annotations aren't cancer. They're obviously terrorism. Any > fool can see that. Annotations were invented by the Nazi's on the explicit instruction of Hitler. there, can someone now invoke Godwins law & call this discussion closed :-) -- Do what comes naturally. Seethe and fume and throw a tantrum. From grant.b.edwards at gmail.com Wed Jun 20 09:59:40 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 20 Jun 2018 13:59:40 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> <67c8dcef-d21d-217a-0371-1a7ba500e138@kellett.im> <3b51233d-94ee-5fc9-7c3e-5270df383cd0@gmail.com> <0QsWC.308334$AX1.195345@fx25.am4> Message-ID: On 2018-06-20, Alister via Python-list wrote: > Annotations were invented by the Nazi's on the explicit instruction > of Hitler. there, can someone now invoke Godwins law & call this > discussion closed :-) I'm pretty sure I read somewhere that Godwin's law doesn't apply when one invokes Hitler/Nazis for the purpose of stopping the thread... -- Grant Edwards grant.b.edwards Yow! I joined scientology at at a garage sale!! gmail.com From bart4858 at gmail.com Wed Jun 20 10:43:35 2018 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Wed, 20 Jun 2018 07:43:35 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> Message-ID: <1a8424c8-539b-40b8-acbb-dfaa5aac66f2@googlegroups.com> If you're genuinely interested in how pointers might work I'll try and write that up when I get back to a real machine, and will do it in the form of a link. Since people are clearly unhappy with discussing features that ought to be in Python in a Python forum. From alister.ware at ntlworld.com Wed Jun 20 11:31:34 2018 From: alister.ware at ntlworld.com (Alister) Date: Wed, 20 Jun 2018 15:31:34 GMT Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <4cddb6aa-3399-a9fa-0f23-082195dfa962@gmail.com> <78fd7d21-669c-345e-8b87-e0ece5a8faca@gmail.com> <67c8dcef-d21d-217a-0371-1a7ba500e138@kellett.im> <3b51233d-94ee-5fc9-7c3e-5270df383cd0@gmail.com> <0QsWC.308334$AX1.195345@fx25.am4> Message-ID: On Wed, 20 Jun 2018 13:59:40 +0000, Grant Edwards wrote: > On 2018-06-20, Alister via Python-list wrote: > >> Annotations were invented by the Nazi's on the explicit instruction of >> Hitler. there, can someone now invoke Godwins law & call this >> discussion closed :-) > > I'm pretty sure I read somewhere that Godwin's law doesn't apply when > one invokes Hitler/Nazis for the purpose of stopping the thread... damn protocol nazi -- Pure drivel tends to drive ordinary drivel off the TV screen. From torriem at gmail.com Wed Jun 20 14:03:31 2018 From: torriem at gmail.com (Michael Torrie) Date: Wed, 20 Jun 2018 12:03:31 -0600 Subject: syntax difference In-Reply-To: <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> Message-ID: On 06/20/2018 05:53 AM, bart4858 at gmail.com wrote: > I suggest that such features just make life a little simpler. (And > make writing an efficient interpreter a little bit easier.) And I posit that most efficient interpreters don't use switch/case at all, but rather jump tables. From torriem at gmail.com Wed Jun 20 14:11:16 2018 From: torriem at gmail.com (Michael Torrie) Date: Wed, 20 Jun 2018 12:11:16 -0600 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: On 06/20/2018 03:35 AM, bart4858 at gmail.com wrote: > Pointers are merely an extra level of indirection; they can be made to fit. I'm hard pressed to think of any way in which pointers could fit into Python given the way python variables work and given the virtual machien architecture and abstraction that python presents to programemrs. Pointers are for a different conceptual model, a different (virtual) machine architecture. I programmed for many years when I was a young without pointers and never needed them in the language I was using which broadly abstracted memory. When I learned C and C++, I learned how to work with pointers because they were intrinsically a part of the programming paradigm these languages espouse. Both languages are extremely low-level, with very little abstraction between you and the Von Neumann machine. Given your experience with programming and making your own programming languages, I'm often surprised by your assertions. From bart4858 at gmail.com Wed Jun 20 14:41:23 2018 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Wed, 20 Jun 2018 11:41:23 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> Message-ID: The actual interpreter code is irrelevant. Switch would be a feature of the language being interpreted, not of the interpreter. If the task is to match an expression X against a variety of values, then expressing that as a switch means the interpreter /could/ use a jump table (of labels within the byte code), rather than execute a chain of X==Y tests within byte code. So, evaluate X once then it could be a single byte code op. At least, it will know that exactly the same X value is being tested. So you evaluate it once then keep it on the stack. Think of Switch as another kind if hint. -- Bart From bart4858 at gmail.com Wed Jun 20 16:47:46 2018 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Wed, 20 Jun 2018 13:47:46 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: You're right. While pointers can be made to fit, it would be an awkward fit into Python and could introduce overheads even when not used. My use of them is frequently when straddling boundaries between languages (a pointer in one environment points to the data of another), or when working just outside the language's object system, or using pointers to raw machine types that are not reference counted. This would not be disciplined enough for Python. So forget I mentioned them even though they could open up interesting possibilities such as reference parameters. -- Bart From greg.ewing at canterbury.ac.nz Wed Jun 20 18:31:38 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 21 Jun 2018 10:31:38 +1200 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> Message-ID: Michael Torrie wrote: > And I posit that most efficient interpreters don't use switch/case at > all, but rather jump tables. Not always true. If the number of cases is small enough, a tree of branches could be faster due to cacheing and pipelining issues. -- Greg From greg.ewing at canterbury.ac.nz Wed Jun 20 18:42:59 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 21 Jun 2018 10:42:59 +1200 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: Michael Torrie wrote: > Pointers are for a different conceptual model, a different (virtual) > machine architecture. And even in many lower-level languages that do have pointers, they're not much like the wild, undisciplined version that you get in C and C++. In Pascal, for example (and derivatives like Modula) the only legitimate use for a pointer is to reference a heap-allocated memory block -- they can't point into the middle of arbitrary data structures. I think Pascal does a pretty good job of abstracting the essential features of the underlying hardware, and it does it without needing anything like a C-style pointer. -- Greg From sharan.basappa at gmail.com Wed Jun 20 23:40:55 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Wed, 20 Jun 2018 20:40:55 -0700 (PDT) Subject: nltk related issue Message-ID: <69d3aa89-a66b-4631-9b78-e0b56d4dc824@googlegroups.com> Folks, I am trying to run a simple example associated with nltk. I get some error and I don't know what the issue is. I need some guidance please. I am using python canopy distribution The following is the code: inputstring = ' This is an example sent. The sentence splitter will split on sent markers. Ohh really !!' from nltk.tokenize import sent_tokenize sentences = sent_tokenize(inputstring) print sentences The following is the error report: LookupErrorTraceback (most recent call last) D:\Projects\Initiatives\machine learning\programs\nltk_1.py in () 2 from nltk.tokenize import sent_tokenize 3 ----> 4 sentences = sent_tokenize(inputstring) 5 6 print sentences D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\nltk\tokenize\__init__.pyc in sent_tokenize(text, language) 94 :param language: the model name in the Punkt corpus 95 """ ---> 96 tokenizer = load('tokenizers/punkt/{0}.pickle'.format(language)) 97 return tokenizer.tokenize(text) 98 D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\nltk\data.pyc in load(resource_url, format, cache, verbose, logic_parser, fstruct_reader, encoding) 812 813 # Load the resource. --> 814 opened_resource = _open(resource_url) 815 816 if format == 'raw': D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\nltk\data.pyc in _open(resource_url) 930 931 if protocol is None or protocol.lower() == 'nltk': --> 932 return find(path_, path + ['']).open() 933 elif protocol.lower() == 'file': 934 # urllib might not use mode='rb', so handle this one ourselves: D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\nltk\data.pyc in find(resource_name, paths) 651 sep = '*' * 70 652 resource_not_found = '\n%s\n%s\n%s' % (sep, msg, sep) --> 653 raise LookupError(resource_not_found) 654 655 LookupError: ********************************************************************** Resource u'tokenizers/punkt/english.pickle' not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download() Searched in: - 'D:\\Users\\sharanb/nltk_data' - 'C:\\nltk_data' - 'D:\\nltk_data' - 'E:\\nltk_data' - 'D:\\Users\\sharanb\\AppData\\Local\\Enthought\\Canopy\\edm\\envs\\User\\nltk_data' - 'D:\\Users\\sharanb\\AppData\\Local\\Enthought\\Canopy\\edm\\envs\\User\\lib\\nltk_data' - 'D:\\Users\\sharanb\\AppData\\Roaming\\nltk_data' - u'' ********************************************************************** From arj.python at gmail.com Thu Jun 21 00:02:23 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 21 Jun 2018 08:02:23 +0400 Subject: Feeding the trolls In-Reply-To: <7435bbd5-656b-7976-0f1d-605bd1a9ae35@VybeNetworks.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> <7435bbd5-656b-7976-0f1d-605bd1a9ae35@VybeNetworks.com> Message-ID: by building a custom py-based mail client maybe ^^_ Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ On Wed, 20 Jun 2018, 17:18 D'Arcy Cain, wrote: > On 2018-06-20 08:10 AM, Tim Golden wrote: > > [... snip discussions about Bart's language ...] > > > > Wearing my moderator hat > > > > Can we take the "Bart's language vs Python Show" to some other forum, > > please? We've already gone over this ground again and again and it isn't > > helping the signal-to-noise ratio here on the Python list / > > comp.lang.python > > Thank you. Many of us have blocked rick and bart years ago. If you are > just going to feed the trolls we have to see their nonsense anyway. > Just email them privately if you really feel the need to vent. > > One of these days I will have to figure out how to block replies to the > trolls as well. > > -- > D'Arcy J.M. Cain > Vybe Networks Inc. > http://www.VybeNetworks.com/ > IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com > -- > https://mail.python.org/mailman/listinfo/python-list > From as at sci.fi Thu Jun 21 04:05:54 2018 From: as at sci.fi (Anssi Saari) Date: Thu, 21 Jun 2018 11:05:54 +0300 Subject: Feeding the trolls References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> <7435bbd5-656b-7976-0f1d-605bd1a9ae35@VybeNetworks.com> Message-ID: D'Arcy Cain writes: > One of these days I will have to figure out how to block replies to the > trolls as well. Benefit of reading the mailing list via nntp (i.e. gmane): can easily score down follow-ups to annoying people in addition to their posts. Well, assuming a decent newsreader. From ganesh1pal at gmail.com Thu Jun 21 13:11:48 2018 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Thu, 21 Jun 2018 22:41:48 +0530 Subject: write the values of an ordered dictionary into a file Message-ID: Hi Team I need to write the values of an ordered dictionary into a file . All values should be in a single row with a header list *Example:* *student = [("NAME", "John"),* * ("AGE", 28),* * ("SCORE", 13),* * ("YEAR", 2018),* * ("FEE", 250)]* *student = OrderedDict(student)* *The OrderedDict Should be append at the end of the file as as shown below.* *# tail -2 /tmp/student_record.txt * *.................................................................* *||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||* *||John || 28 || 13 || 2018 || 250 ||* Questions: (1) Below is my partial solution , any comments and suggestions ( I am not to get the ?||? delimiter correctly, trying it ) #!/usr/bin/python # A Python program to write the values of an OderedDict into a file # The values should be formatted correctly under its headers from collections import OrderedDict tmp = '/tmp/student_record.txt' student = [("NAME", "John"), ("AGE", 28), ("SCORE", 13), ("YEAR", 2018), ("FEE", 250)] student = OrderedDict(student) header_list = ["STUDENT NAME", "STUDENT AGE", "MARKS SCORED", "PASSED YEAR", "FEES PAID"] header_string = '||' + '||'.join(header_list) + '||' with open(tmp, 'a') as fd: for item in header_string: fd.write("%s" % (item)) for value in student.values(): fd.write("\n") fd.write("||") fd.write("%s" % (value)) *output:* *root at X1:/Play_ground/SPECIAL_TYPES# cat /tmp/student_record.txt* *||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||* *||John* *||28* *||13* *||2018* (2)Any alternative way to solve this easily and store the data in the requested format (can I still use cvs writer to format this) I am a Linux user with Python 2.7 Regards, Ganesh From ethan at stoneleaf.us Thu Jun 21 13:12:27 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 21 Jun 2018 10:12:27 -0700 Subject: translating foreign data Message-ID: <5B2BDC7B.3040508@stoneleaf.us> I need to translate numeric data in a string format into a binary format. I know there are at least two different methods of representing parts less that 1, such as "10.5" and "10,5". The data is encoded using code pages, and can vary depending on the file being read (so I can't rely on current locale settings). I'm sure this is a solved problem, but I'm not finding those solutions. Any pointers? -- ~Ethan~ From pkpearson at nowhere.invalid Thu Jun 21 13:33:09 2018 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 21 Jun 2018 17:33:09 GMT Subject: write the values of an ordered dictionary into a file References: Message-ID: On Thu, 21 Jun 2018 22:41:48 +0530, Ganesh Pal wrote: [snip] [what I think OP wants:] > > *.................................................................* > > *||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||* > > *||John || 28 || 13 || 2018 || 250 ||* > > > Questions: > > (1) Below is my partial solution , any comments and suggestions ( I am not > to get the ?||? delimiter correctly, trying it ) > > #!/usr/bin/python > # A Python program to write the values of an OderedDict into a file > # The values should be formatted correctly under its headers > > from collections import OrderedDict > > tmp = '/tmp/student_record.txt' > student = [("NAME", "John"), > ("AGE", 28), > ("SCORE", 13), > ("YEAR", 2018), > ("FEE", 250)] > > student = OrderedDict(student) > header_list = ["STUDENT NAME", "STUDENT AGE", "MARKS SCORED", "PASSED YEAR", > "FEES PAID"] > > header_string = '||' + '||'.join(header_list) + '||' > with open(tmp, 'a') as fd: > for item in header_string: > fd.write("%s" % (item)) > > for value in student.values(): > fd.write("\n") > fd.write("||") > fd.write("%s" % (value)) > > *output:* > *root at X1:/Play_ground/SPECIAL_TYPES# cat /tmp/student_record.txt* > *||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||* > *||John* > *||28* > *||13* > *||2018* [snip] You don't say which aspects of this output you find unsatisfactory and want help with, but . . . - You're writing "\n" in front of every *field*, when you only want to write it in front of every line; and - To make the columns line up right, you'll want to specify the widths of the character strings being written, e.g., using "%10s" in place of "%s". -- To email me, substitute nowhere->runbox, invalid->com. From pkpearson at nowhere.invalid Thu Jun 21 13:36:23 2018 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 21 Jun 2018 17:36:23 GMT Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> Message-ID: On Thu, 21 Jun 2018 10:12:27 -0700, Ethan Furman wrote: > I need to translate numeric data in a string format into a binary > format. I know there are at least two different methods of > representing parts less that 1, such as "10.5" and "10,5". The data > is encoded using code pages, and can vary depending on the file being > read (so I can't rely on current locale settings). > > I'm sure this is a solved problem, but I'm not finding those > solutions. Any pointers? Do you also have to accommodate the possibility that one thousand might be written "1,000" or "1.000"? -- To email me, substitute nowhere->runbox, invalid->com. From python at mrabarnett.plus.com Thu Jun 21 13:48:19 2018 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 21 Jun 2018 18:48:19 +0100 Subject: write the values of an ordered dictionary into a file In-Reply-To: References: Message-ID: <6262e7bd-e67d-95f0-6991-901246fbd91f@mrabarnett.plus.com> On 2018-06-21 18:11, Ganesh Pal wrote: > Hi Team > > I need to write the values of an ordered dictionary into a file . All > values should be in a single row with a header list > > *Example:* > > *student = [("NAME", "John"),* > * ("AGE", 28),* > * ("SCORE", 13),* > * ("YEAR", 2018),* > * ("FEE", 250)]* > *student = OrderedDict(student)* > > *The OrderedDict Should be append at the end of the file as as shown below.* > > *# tail -2 /tmp/student_record.txt * > *.................................................................* > *||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||* > *||John || 28 || 13 || 2018 || 250 ||* > > > Questions: > > (1) Below is my partial solution , any comments and suggestions ( I am not > to get the ?||? delimiter correctly, trying it ) > > #!/usr/bin/python > > # A Python program to write the values of an OderedDict into a file > # The values should be formatted correctly under its headers > > from collections import OrderedDict > tmp = '/tmp/student_record.txt' > > student = [("NAME", "John"), > ("AGE", 28), > ("SCORE", 13), > ("YEAR", 2018), > ("FEE", 250)] > > student = OrderedDict(student) > > header_list = ["STUDENT NAME", "STUDENT AGE", "MARKS SCORED", "PASSED YEAR", > "FEES PAID"] > > header_string = '||' + '||'.join(header_list) + '||' > > with open(tmp, 'a') as fd: header_string is already a string, so here you're just iterating over the characters of that string: > for item in header_string: > fd.write("%s" % (item)) > You can write it more simple like this: fd.write("%s\n" % header_string) Here you're writing a newline before each of the fields/columns: > for value in student.values(): > fd.write("\n") > fd.write("||") > fd.write("%s" % (value)) > > > *output:* > > *root at X1:/Play_ground/SPECIAL_TYPES# cat /tmp/student_record.txt* > *||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||* > *||John* > *||28* > *||13* > *||2018* > > > (2)Any alternative way to solve this easily and store the data in the > requested format (can I still use cvs writer to format this) > > > I am a Linux user with Python 2.7 > What I would do is measure the widths of the each heading and of each value and then pad them out to the longest: header_list = ["STUDENT NAME", "STUDENT AGE", "MARKS SCORED", "PASSED YEAR", "FEES PAID"] header_widths = [len(header) for header in header_list] value_list = [str(value) for value in student.values()] value_widths = [len(value) for value in value_list] column_widths = [max(header_width, value_width) for header_width, value_width in zip(header_widths, value_widths)] with open(tmp, 'a') as fd: fd.write('||' + '||'.join(header.ljust(width) for header, width in zip(header_list, column_widths)) + '||\n') fd.write('||' + '||'.join(value.ljust(width) for value, width in zip(value_list, column_widths)) + '||\n') From __peter__ at web.de Thu Jun 21 13:49:30 2018 From: __peter__ at web.de (Peter Otten) Date: Thu, 21 Jun 2018 19:49:30 +0200 Subject: write the values of an ordered dictionary into a file References: Message-ID: Ganesh Pal wrote: > Hi Team There is no team, just some random guys on the net. Sorry to disappoint you... > I need to write the values of an ordered dictionary into a file . All > values should be in a single row with a header list > > > > *Example:* > > > > *student = [("NAME", "John"),* > > * ("AGE", 28),* > > * ("SCORE", 13),* > > * ("YEAR", 2018),* > > * ("FEE", 250)]* > > *student = OrderedDict(student)* > > > > *The OrderedDict Should be append at the end of the file as as shown > below.* > > > *# tail -2 /tmp/student_record.txt * > > *.................................................................* > > *||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||* > > *||John || 28 || 13 || 2018 || 250 ||* Here's one way, written in Python 3. widths = [len(ch) for ch in header_list] def print_row(values, widths=widths, file=None): print( "||", "||".join("{:^{}}".format(v, w) for v, w in zip(values, widths)), "||", sep="", file=file ) print_row(header_list) print_row(student.values()) In Python 2 it should work after from __future__ import print_function or by replacing print() with a few file.write() calls. From alister.ware at ntlworld.com Thu Jun 21 14:01:58 2018 From: alister.ware at ntlworld.com (Alister) Date: Thu, 21 Jun 2018 18:01:58 GMT Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> Message-ID: On Wed, 20 Jun 2018 11:41:23 -0700, bart4858 wrote: > The actual interpreter code is irrelevant. Switch would be a feature of > the language being interpreted, not of the interpreter. > > If the task is to match an expression X against a variety of values, > then expressing that as a switch means the interpreter /could/ use a > jump table (of labels within the byte code), rather than execute a chain > of X==Y tests within byte code. So, evaluate X once then it could be a > single byte code op. > > At least, it will know that exactly the same X value is being tested. So > you evaluate it once then keep it on the stack. > > Think of Switch as another kind if hint. which can be implemented in python by putting function calls as members of a list or dictionary switch=[case1,case2,case3] switch[a]() (although i personally would still like to see a switch if anyone can come up with a suitable syntax that does not break the rest of the python philosophy wtr indentation.) -- There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy. -- Wm. Shakespeare, "Hamlet" From codewizard at gmail.com Thu Jun 21 15:07:59 2018 From: codewizard at gmail.com (codewizard at gmail.com) Date: Thu, 21 Jun 2018 12:07:59 -0700 (PDT) Subject: translating foreign data In-Reply-To: References: <5B2BDC7B.3040508@stoneleaf.us> Message-ID: On Thursday, June 21, 2018 at 1:08:35 PM UTC-4, Ethan Furman wrote: > I need to translate numeric data in a string format into a binary format. I know there are at least two different > methods of representing parts less that 1, such as "10.5" and "10,5". The data is encoded using code pages, and can > vary depending on the file being read (so I can't rely on current locale settings). > > I'm sure this is a solved problem, but I'm not finding those solutions. Any pointers? > > -- > ~Ethan~ Try this StackOverflow answer: https://stackoverflow.com/a/17815252 Regards, Igor. From ethan at stoneleaf.us Thu Jun 21 15:37:50 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 21 Jun 2018 12:37:50 -0700 Subject: translating foreign data In-Reply-To: References: <5B2BDC7B.3040508@stoneleaf.us> Message-ID: <5B2BFE8E.2020909@stoneleaf.us> On 06/21/2018 10:36 AM, Peter Pearson wrote: > On Thu, 21 Jun 2018 10:12:27 -0700, Ethan Furman wrote: >> I need to translate numeric data in a string format into a binary >> format. I know there are at least two different methods of >> representing parts less that 1, such as "10.5" and "10,5". The data >> is encoded using code pages, and can vary depending on the file being >> read (so I can't rely on current locale settings). >> >> I'm sure this is a solved problem, but I'm not finding those >> solutions. Any pointers? > > Do you also have to accommodate the possibility that one thousand > might be written "1,000" or "1.000"? Nope, just the decimal character. -- ~Ethan~ From ethan at stoneleaf.us Thu Jun 21 15:42:58 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 21 Jun 2018 12:42:58 -0700 Subject: translating foreign data In-Reply-To: References: <5B2BDC7B.3040508@stoneleaf.us> Message-ID: <5B2BFFC2.4000905@stoneleaf.us> On 06/21/2018 12:07 PM, codewizard at gmail.com wrote: > On Thursday, June 21, 2018 at 1:08:35 PM UTC-4, Ethan Furman wrote: >> I need to translate numeric data in a string format into a binary format. I know there are at least two different >> methods of representing parts less that 1, such as "10.5" and "10,5". The data is encoded using code pages, and can >> vary depending on the file being read (so I can't rely on current locale settings). >> >> I'm sure this is a solved problem, but I'm not finding those solutions. Any pointers? > > Try this StackOverflow answer: https://stackoverflow.com/a/17815252 --> import locale --> a = u'545,545.2222' --> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') 'en_US.UTF-8' The problem there is it sets the locale for the entire process -- I just need the conversion step for individual pieces of data without modifying the user's settings. -- ~Ethan~ From bart4858 at gmail.com Thu Jun 21 16:14:14 2018 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Thu, 21 Jun 2018 13:14:14 -0700 (PDT) Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> Message-ID: <47445824-57af-4972-b1c8-bee1fd225448@googlegroups.com> Alister: ====== which can be implemented in python by putting function calls as members of a list or dictionary switch=[case1,case2,case3] switch[a]() ====== This is the approach you might use when you don't have a proper switch. It could be done in C that way. Problems: the code for the different cases is not localised. You have to think up function names. The cases must be listed in that order. If the first case is not zero, you have to deal with that. Gaps in the sequence are problematical. You need a way of detecting the default case. There is no association between case number and its entry. The case numbers may be named values, so won't know what order they need to be in. Using a dict will solve some of that, but its not clear what overheads there are in setting up the dict. A proper switch also allows lists, ranges and scalars, or any mix, for each case block. It's not clear how a dict can be used for that, without adding another layer of processing which defeats part of the purpose in having switch. Above all, you lose the clarity of a proper switch construct. Alister: ====== (although i personally would still like to see a switch if anyone can come up with a suitable syntax that does not break the rest of the python philosophy wtr indentation.) ====== The syntax is a minor detail. The biggest problem with adding an int-based switch to Python that uses a jump-table is that that requires the case values to be known at compile-time. Usually they won't be. I came up with a way around this which used tentative byte code which is fixed up the first time it is executed. But that is rather hairy, and it means case values are fixed: if A is a case value of 10, then if later on it is 20, it will be treated as 10 still. For such reasons it is unlikely to make it into Python in that form. However a switch statement can still be useful for its expressiveness, and implemented as sequential tests. -- Bart From ben.usenet at bsb.me.uk Thu Jun 21 16:20:01 2018 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Thu, 21 Jun 2018 21:20:01 +0100 Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> Message-ID: <87k1qrsxhq.fsf@bsb.me.uk> Ethan Furman writes: > I need to translate numeric data in a string format into a binary > format. I know there are at least two different methods of > representing parts less that 1, such as "10.5" and "10,5". The data > is encoded using code pages, and can vary depending on the file being > read (so I can't rely on current locale settings). > > I'm sure this is a solved problem, but I'm not finding those > solutions. Any pointers? You say "at least two" and give two but not knowing the others will hamper anyone trying to help. (I appreciate that you may not yet know if there are to be any others.) You say in a followup that you don't need to worry about digit grouping marks (like thousands separators) so I'm not sure what the problem is. Can't you just replace ',' with '.' a proceed as if you had only one representation? The code page remark is curious. Will some "code pages" have digits that are not ASCII digits? -- Ben. From __peter__ at web.de Thu Jun 21 16:43:42 2018 From: __peter__ at web.de (Peter Otten) Date: Thu, 21 Jun 2018 22:43:42 +0200 Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> Message-ID: Ethan Furman wrote: > I need to translate numeric data in a string format into a binary format. > I know there are at least two different > methods of representing parts less that 1, such as "10.5" and "10,5". The > data is encoded using code pages, and can vary depending on the file being > read (so I can't rely on current locale settings). > > I'm sure this is a solved problem, but I'm not finding those solutions. > Any pointers? There's babel http://babel.pocoo.org/en/latest/numbers.html#parsing-numbers though I'm not sure what to think of the note below the linked paragraph. From none at invalid.com Thu Jun 21 16:49:15 2018 From: none at invalid.com (mm0fmf) Date: Thu, 21 Jun 2018 21:49:15 +0100 Subject: Feeding the trolls In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> <7435bbd5-656b-7976-0f1d-605bd1a9ae35@VybeNetworks.com> Message-ID: On 21/06/2018 05:02, Abdur-Rahmaan Janhangeer wrote: > by building a custom py-based mail client maybe ^^_ > > Abdur-Rahmaan Janhangeer > https://github.com/Abdur-rahmaanJ > > On Wed, 20 Jun 2018, 17:18 D'Arcy Cain, wrote: > >> On 2018-06-20 08:10 AM, Tim Golden wrote: >>> [... snip discussions about Bart's language ...] >>> >>> Wearing my moderator hat >>> >>> Can we take the "Bart's language vs Python Show" to some other forum, >>> please? We've already gone over this ground again and again and it isn't >>> helping the signal-to-noise ratio here on the Python list / >>> comp.lang.python >> >> Thank you. Many of us have blocked rick and bart years ago. If you are >> just going to feed the trolls we have to see their nonsense anyway. >> Just email them privately if you really feel the need to vent. >> >> One of these days I will have to figure out how to block replies to the >> trolls as well. >> >> -- >> D'Arcy J.M. Cain >> Vybe Networks Inc. >> http://www.VybeNetworks.com/ >> IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com >> -- >> https://mail.python.org/mailman/listinfo/python-list >> Design requirements for python newsreader client: 1. Block all top posters From george at fischhof.hu Thu Jun 21 17:03:59 2018 From: george at fischhof.hu (George Fischhof) Date: Thu, 21 Jun 2018 23:03:59 +0200 Subject: translating foreign data In-Reply-To: References: <5B2BDC7B.3040508@stoneleaf.us> Message-ID: Peter Otten <__peter__ at web.de> ezt ?rta (id?pont: 2018. j?n. 21., Cs, 22:45): > Ethan Furman wrote: > > > I need to translate numeric data in a string format into a binary > format. > > I know there are at least two different > > methods of representing parts less that 1, such as "10.5" and "10,5". > The > > data is encoded using code pages, and can vary depending on the file > being > > read (so I can't rely on current locale settings). > > > > I'm sure this is a solved problem, but I'm not finding those solutions. > > Any pointers? > > There's babel > > http://babel.pocoo.org/en/latest/numbers.html#parsing-numbers > > though I'm not sure what to think of the note below the linked paragraph. > > > -- > https://mail.python.org/mailman/listinfo/python-list Hi, if you have several values in a file, then you probably you can check the delimiters: there is only one decimal separator, - so if you find a number with 2 separators, then a rightmost is a the decimal - if you found only one type, then that is the decimal - try to check the separator from right to left - if you found 4 digits right to a separator, then that is the decimal separator etc (maybe wikipedia should be checked for other separators. Other thousand separators used: space, apostrophe, and in India after the first thousand separator the separation is done with two numbers, not three And if you are able to identify the encoding codepage, then you should follow what the codepage says Another help can be if know the possible value range of the numbers (maybe it should be asked ...) George From greg.ewing at canterbury.ac.nz Thu Jun 21 19:07:15 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 22 Jun 2018 11:07:15 +1200 Subject: translating foreign data In-Reply-To: References: <5B2BDC7B.3040508@stoneleaf.us> Message-ID: George Fischhof wrote: > - if you found only one type, then that is the decimal Only if you're sure that all numbers contain a decimal separator. Otherwise there's no way to be sure in general. -- Greg From steve+comp.lang.python at pearwood.info Thu Jun 21 19:51:25 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 21 Jun 2018 23:51:25 +0000 (UTC) Subject: Feeding the trolls References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> <7435bbd5-656b-7976-0f1d-605bd1a9ae35@VybeNetworks.com> Message-ID: On Thu, 21 Jun 2018 21:49:15 +0100, mm0fmf wrote: [snip unnecessary quoting] > Design requirements for python newsreader client: > > 1. Block all top posters I think it would be far more useful to block bottom-posters who don't snip irrelevant quoted text. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From cs at cskk.id.au Thu Jun 21 20:36:15 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 22 Jun 2018 10:36:15 +1000 Subject: translating foreign data In-Reply-To: <5B2BDC7B.3040508@stoneleaf.us> References: <5B2BDC7B.3040508@stoneleaf.us> Message-ID: <20180622003615.GA23979@cskk.homeip.net> On 21Jun2018 10:12, Ethan Furman wrote: >I need to translate numeric data in a string format into a binary >format. I know there are at least two different methods of >representing parts less that 1, such as "10.5" and "10,5". The data >is encoded using code pages, and can vary depending on the file being >read (so I can't rely on current locale settings). > >I'm sure this is a solved problem, but I'm not finding those solutions. Any >pointers? It sounds like you're conflating two problems: - the file character data encoding - the numeric representation Can't you just read the file as a text file using the correct codepage->decoding setting to get strings, _then_ parse numbers either with some clunky regexp based approach or some flexible external library for common numeric forms? (Someone suggested babel, I've never used it.) Cheers, Cameron Simpson From arj.python at gmail.com Thu Jun 21 22:56:55 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 22 Jun 2018 06:56:55 +0400 Subject: Feeding the trolls In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> <7435bbd5-656b-7976-0f1d-605bd1a9ae35@VybeNetworks.com> Message-ID: aie maybe we can learn then warn ! mail sender is top poster Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Design requirements for python newsreader client: > > 1. Block all top posters > From greg.ewing at canterbury.ac.nz Fri Jun 22 01:20:41 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 22 Jun 2018 17:20:41 +1200 Subject: Feeding the trolls In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> <7435bbd5-656b-7976-0f1d-605bd1a9ae35@VybeNetworks.com> Message-ID: Steven D'Aprano wrote: > On Thu, 21 Jun 2018 21:49:15 +0100, mm0fmf wrote: > >>Design requirements for python newsreader client: >> >>1. Block all top posters > > I think it would be far more useful to block bottom-posters who don't > snip irrelevant quoted text. In the early days of Usenet, it was common for news servers to refuse posts that didn't have a high enough ratio of new to quoted text. . . . . . . . . . . . . . It was easily defeated, of course. :-) But at least it forced you to think about the issue. -- Greg From fantasywangxg at gmail.com Fri Jun 22 02:44:40 2018 From: fantasywangxg at gmail.com (fantasywangxg at gmail.com) Date: Thu, 21 Jun 2018 23:44:40 -0700 (PDT) Subject: ironpython not support py3.6 Message-ID: <58dacf58-a637-4957-9922-c32a32ca3a51@googlegroups.com> We have a project implemented with c# and python, iron python is a good choice for us to integrate these two tech together but iron python not support python 3.6 yet, any suggest for this? From email at paulstgeorge.com Fri Jun 22 03:28:25 2018 From: email at paulstgeorge.com (Paul St George) Date: Fri, 22 Jun 2018 09:28:25 +0200 Subject: Feeding the trolls In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> <7435bbd5-656b-7976-0f1d-605bd1a9ae35@VybeNetworks.com> Message-ID: <83a1976b-65ab-8a43-08a6-4ea2b89c2604@paulstgeorge.com> On 21/06/2018 10:05, Anssi Saari wrote: > D'Arcy Cain writes: > >> One of these days I will have to figure out how to block replies to the >> trolls as well. > > Benefit of reading the mailing list via nntp (i.e. gmane): can easily > score down follow-ups to annoying people in addition to their > posts. Well, assuming a decent newsreader. > I have a decent newsreader (Thunderbird). How do I score down follow-ups to Bart and still see the respondents' other posts? From bart4858 at gmail.com Fri Jun 22 04:33:41 2018 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Fri, 22 Jun 2018 01:33:41 -0700 (PDT) Subject: Feeding the trolls In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> <7435bbd5-656b-7976-0f1d-605bd1a9ae35@VybeNetworks.com> <83a1976b-65ab-8a43-08a6-4ea2b89c2604@paulstgeorge.com> Message-ID: <7bc8c43c-a2bc-41df-acd4-79567fca97a0@googlegroups.com> What a friendly, welcoming and open-minded group this is! It costs me some genuine effort to make what I believe are relevant and interesting technical posts, and people are discussing not just how to avoid seeing them, but how to screen anyone who wants to reply. Yes my posts are more 'meta' than some would like but that is fitting for such a language. I in the meantime have to wade through reams of Case Solution and Test Bank posts. Guys, get a proper moderated Usenet group then I won't bother with it at all. From ethan at stoneleaf.us Fri Jun 22 04:43:56 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 22 Jun 2018 01:43:56 -0700 Subject: translating foreign data In-Reply-To: <87k1qrsxhq.fsf@bsb.me.uk> References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> Message-ID: <5B2CB6CC.10500@stoneleaf.us> On 06/21/2018 01:20 PM, Ben Bacarisse wrote: > Ethan Furman writes: > >> I need to translate numeric data in a string format into a binary >> format. I know there are at least two different methods of >> representing parts less that 1, such as "10.5" and "10,5". The data >> is encoded using code pages, and can vary depending on the file being >> read (so I can't rely on current locale settings). >> >> I'm sure this is a solved problem, but I'm not finding those >> solutions. Any pointers? > > You say "at least two" and give two but not knowing the others will hamper > anyone trying to help. (I appreciate that you may not yet know if there > are to be any others.) Yes, I don't know if there are others -- I have not studied the various ways different peoples represent decimal numbers. ;) > You say in a followup that you don't need to worry about digit grouping > marks (like thousands separators) so I'm not sure what the problem is. > Can't you just replace ',' with '.' a proceed as if you had only one > representation? I could, and that would work right up until a third decimal separator was found. I'd like to solve the problem just once if possible. > The code page remark is curious. Will some "code pages" have digits > that are not ASCII digits? Good question. I have no idea. I get the appropriate decoder/encoder based on the code page contained in the file, then decode to unicode and go from there. Unfortunately, that doesn't convert the decimal comma to the decimal point. :( So I was hoping to map the code page to a locale that would properly translate the numbers for me, but so far what I have found in my readings suggests that in order to use the locale option I would have to actually change the active locale and potentially mess up every other part of the program when the file in question is opened in a locale that's different from its code page. Worst case scenario is I manually create a map for each code page to decimal separator, but there's more than a few and I'd rather not if there is already a prebuilt solution out there. -- ~Ethan~ From steve+comp.lang.python at pearwood.info Fri Jun 22 05:04:38 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 22 Jun 2018 09:04:38 +0000 (UTC) Subject: ironpython not support py3.6 References: <58dacf58-a637-4957-9922-c32a32ca3a51@googlegroups.com> Message-ID: On Thu, 21 Jun 2018 23:44:40 -0700, fantasywangxg wrote: > We have a project implemented with c# and python, iron python is a good > choice for us to integrate these two tech together but iron python not > support python 3.6 yet, any suggest for this? How big is your budget? Could you pay the IronPython developers to build support for 3.6? Probably not... Do you need fully managed .Net code from Python? If not "Python for .Net" may suit: https://pythonnet.github.io/ Either stick to the latest version of IronPython (2.7), or the latest of CPython (3.6). Or maybe you can do both, use IronPython only for the parts that really need C# integration, and use CPython for the rest: C# <--> IronPython 2.7 <--> CPython 3.6 although I suspect that will be even more annoying, complicated and fragile. Have you tried asking this question on an IronPython support forum? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Fri Jun 22 05:09:04 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 22 Jun 2018 09:09:04 +0000 (UTC) Subject: Feeding the trolls References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> <7435bbd5-656b-7976-0f1d-605bd1a9ae35@VybeNetworks.com> <83a1976b-65ab-8a43-08a6-4ea2b89c2604@paulstgeorge.com> <7bc8c43c-a2bc-41df-acd4-79567fca97a0@googlegroups.com> Message-ID: On Fri, 22 Jun 2018 01:33:41 -0700, bart4858 wrote: > What a friendly, welcoming and open-minded group this is! You reap what you sow. If you were more interested in appreciating Python for what it is, instead of turning everything into a pissing contest where your personal, private language does it better, your experience might be different. And who knows, you might even learn a thing or two. There's a reason why the Python/Ruby/Lua/Javascript style of languages exists. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From mail at timgolden.me.uk Fri Jun 22 05:26:55 2018 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 22 Jun 2018 10:26:55 +0100 Subject: Feeding the trolls In-Reply-To: <7bc8c43c-a2bc-41df-acd4-79567fca97a0@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> <7435bbd5-656b-7976-0f1d-605bd1a9ae35@VybeNetworks.com> <83a1976b-65ab-8a43-08a6-4ea2b89c2604@paulstgeorge.com> <7bc8c43c-a2bc-41df-acd4-79567fca97a0@googlegroups.com> Message-ID: On 22/06/2018 09:33, bart4858 at gmail.com wrote: > It costs me some genuine effort to make what I believe are relevant > and interesting technical posts I thank you for at least taking that trouble. But I think that this is probably where the difference lies. This newsgroup/mailing list is primarily for the purpose of asking about or discussing aspects of the Python programming language, not a forum for discussing languages in general. Obviously a genuine enquiry into how or why Python has taken a particular design path can lead to an enlightening discussion on language design. Sometimes as an unexpected spin-off discussion from an original query. But, for the most part Bart, you've failed to understand anyone's design decisions but your own. You've consistently replied in a way that effectively dismisses the various challenges facing this particular language at this particular point in time, and instead have referred to your own design choices and implementations as an exemplar. If you have a genuine interest in how Python is implemented (and not simply in expressing how it is different in some way to your own languages) then please bring it up. If you have a plausible way in which Python could improve then please take it to the Python Ideas list (and be prepared for some robust discussion): https://mail.python.org/mailman/listinfo/python-ideas But if your only goal is to highlight the advantages of your own language and design choices, then please write a blog post, or tweet about it, or take it to some kind of cross-language forum. Thanks TJG From steve+comp.lang.python at pearwood.info Fri Jun 22 06:01:26 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 22 Jun 2018 10:01:26 +0000 (UTC) Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> Message-ID: On Fri, 22 Jun 2018 01:43:56 -0700, Ethan Furman wrote: >> You say in a followup that you don't need to worry about digit grouping >> marks (like thousands separators) so I'm not sure what the problem is. >> Can't you just replace ',' with '.' a proceed as if you had only one >> representation? > > I could, and that would work right up until a third decimal separator > was found. I'd like to solve the problem just once if possible. I don't know of any already existing solution, but there's only a limited number of decimal separators in common use around the world. There's probably nothing you can do ahead of time if somebody decides to start using (say) 5 as a decimal separator within Hindi numerals, except cry, but you can probably start by transforming all of the following into decimal points: - interpuct (middle dot) ? U+00B7 - comma , - Arabic decimal separator ? U+066B https://en.wikipedia.org/wiki/Decimal_separator Those three cover pretty much the whole world, using Hindu-Arabic numerals (1234...) and Eastern Arabic numerals (what the Arabs and Persians use). Other numeral systems seem to have either adopted Arabic numerals, or introduced the decimal point/comma into their own numeral system, or just don't use a decimal place value system. Either way, I expect that the period . plus the three above will cover anything you are likely to find in real data. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From ben.usenet at bsb.me.uk Fri Jun 22 06:14:59 2018 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Fri, 22 Jun 2018 11:14:59 +0100 Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> Message-ID: <878t77ruu4.fsf@bsb.me.uk> Ethan Furman writes: > On 06/21/2018 01:20 PM, Ben Bacarisse wrote: >> You say in a followup that you don't need to worry about digit grouping >> marks (like thousands separators) so I'm not sure what the problem is. >> Can't you just replace ',' with '.' a proceed as if you had only one >> representation? > > I could, and that would work right up until a third decimal separator > was found. I'd like to solve the problem just once if possible. Ah, I see. I took you to mean you knew this won't be an issue. >> The code page remark is curious. Will some "code pages" have digits >> that are not ASCII digits? > > Good question. I have no idea. It's much more of an open question than I thought. My only advice, then, it to ignore problems that *might* arise. Solve the problem you face now and hope that you can extend it as needed. It's good to check if there is an well-known solution ready to use out of the box, but since there really isn't, you might as well get something working now. > I get the appropriate decoder/encoder > based on the code page contained in the file, then decode to unicode > and go from there. It's rather off-topic but what does it mean for the code page to be contained in the file? Are you guessing the character encoding from the rest of the file contents or is there some actual description of the encoding present? > ... I was hoping to map the code page to > a locale that would properly translate the numbers for me, > Worst case scenario is I manually create a map for each code page to > decimal separator, but there's more than a few and I'd rather not if > there is already a prebuilt solution out there. That can't work in general, but you may be lucky with your particular data set. For example, files using one of the "Latin" encodings could have numbers written using the UK convention (0.5) or the French convention (0,5). I do both depending on the audience. -- Ben. From Richard at Damon-Family.org Fri Jun 22 06:39:59 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 22 Jun 2018 06:39:59 -0400 Subject: Feeding the trolls In-Reply-To: <83a1976b-65ab-8a43-08a6-4ea2b89c2604@paulstgeorge.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> <7435bbd5-656b-7976-0f1d-605bd1a9ae35@VybeNetworks.com> <83a1976b-65ab-8a43-08a6-4ea2b89c2604@paulstgeorge.com> Message-ID: <056ea88e-b959-2b85-a30b-48b2011a7e50@Damon-Family.org> On 6/22/18 3:28 AM, Paul St George wrote: > On 21/06/2018 10:05, Anssi Saari wrote: >> D'Arcy Cain writes: >> >>> One of these days I will have to figure out how to block replies to the >>> trolls as well. >> >> Benefit of reading the mailing list via nntp (i.e. gmane): can easily >> score down follow-ups to annoying people in addition to their >> posts. Well, assuming a decent newsreader. >> > > I have a decent newsreader (Thunderbird). How do I score down > follow-ups to Bart and still see the respondents' other posts? First, Thunderbird is really an email program that does Usenet, so actually doesn't quite fall into that catagory, but it can do something like that. Create a filter, the detect side of the filter would be from is Bart, and the filter action would be ignore subthread (that will mark as read any message from Bart and any message that is in reply to one of his). This would actually work from the mailing list too. Many more classically Usenet readers had a 'score' system where you could include various attributes of the usenet message (similar to the Thunderbird filter criteria) and give them a value, and if the filter just used information in the 'overview' of the message (a subset of the headers) and based on the value decide if it wants to download the message. Because Email doesn't provide a similar overview function, email based programs tend not to support this type of filter. It was important for Usenet as it is (or at least was) a much higher volume of information (and noise) system, so it was quite common to pull down only a subset of a group. -- Richard Damon From steve+comp.lang.python at pearwood.info Fri Jun 22 06:45:27 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 22 Jun 2018 10:45:27 +0000 (UTC) Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> Message-ID: On Fri, 22 Jun 2018 11:14:59 +0100, Ben Bacarisse wrote: >>> The code page remark is curious. Will some "code pages" have digits >>> that are not ASCII digits? >> >> Good question. I have no idea. > > It's much more of an open question than I thought. Nah, Python already solves that for you: py> s = "?????.?????" py> for c in s: ... print(unicodedata.name(c)) ... BENGALI DIGIT ONE BENGALI DIGIT TWO BENGALI DIGIT THREE BENGALI DIGIT FOUR BENGALI DIGIT FIVE FULL STOP BENGALI DIGIT SIX BENGALI DIGIT SEVEN BENGALI DIGIT EIGHT BENGALI DIGIT NINE BENGALI DIGIT ZERO py> float(s) 12345.6789 Further to my earlier post, if you call: for sep in ",u\00B7u\066B": mystring = mystring.replace(sep, '.') before passing it to float, that ought to cover just about anything you will find in real-world data regardless of language. If Ethan finds something that isn't covered by those three cases (comma, middle dot and Arabic decimal separator) he'll likely need to consult an expert on that language. Provided Ethan doesn't have to deal with thousands separators as well. Then it gets complicated. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From Richard at Damon-Family.org Fri Jun 22 06:48:42 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 22 Jun 2018 06:48:42 -0400 Subject: translating foreign data In-Reply-To: <5B2CB6CC.10500@stoneleaf.us> References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> Message-ID: On 6/22/18 4:43 AM, Ethan Furman wrote: > On 06/21/2018 01:20 PM, Ben Bacarisse wrote: > >> The code page remark is curious.? Will some "code pages" have digits >> that are not ASCII digits? > > Good question.? I have no idea.? I get the appropriate decoder/encoder > based on the code page contained in the file, then decode to unicode > and go from there.? Unfortunately, that doesn't convert the decimal > comma to the decimal point. :(? So I was hoping to map the code page > to a locale that would properly translate the numbers for me, but so > far what I have found in my readings suggests that in order to use the > locale option I would have to actually change the active locale and > potentially mess up every other part of the program when the file in > question is opened in a locale that's different from its code page. > > Worst case scenario is I manually create a map for each code page to > decimal separator, but there's more than a few and I'd rather not if > there is already a prebuilt solution out there. > > -- > ~Ethan~ > One problem is that code page does NOT uniquely define what decimal separator to use (or what locale to use). You can get the decimal separator issue even on files that are pure ASCII, and Latin-1 is full of the issue too. -- Richard Damon From bart4858 at gmail.com Fri Jun 22 07:41:51 2018 From: bart4858 at gmail.com (bart4858 at gmail.com) Date: Fri, 22 Jun 2018 04:41:51 -0700 (PDT) Subject: Feeding the trolls In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> <7435bbd5-656b-7976-0f1d-605bd1a9ae35@VybeNetworks.com> <83a1976b-65ab-8a43-08a6-4ea2b89c2604@paulstgeorge.com> <7bc8c43c-a2bc-41df-acd4-79567fca97a0@googlegroups.com> Message-ID: <8efca409-0d2b-4667-aa5c-893c87f5b46a@googlegroups.com> Steven D'Aprano wrote: ====== If you were more interested in appreciating Python for what it is, instead of turning everything into a pissing contest where your personal, private language does it better, your experience might be different. And who knows, you might even learn a thing or two. There's a reason why the Python/Ruby/Lua/Javascript style of languages exists. ====== You're reading too much in my highlighting a number of features from a much smaller language that I believe could be of benefit. Naturally I wouldn't bring up less useful or inferior features. Nor would I bring up the one or two features of Python I've copied. Nor the ones I haven't got round to copying. Nor the ones I can't yet use because they belong in the next category of language. -- Bart From diagonaldevice at gmail.com Fri Jun 22 11:49:15 2018 From: diagonaldevice at gmail.com (Michael Lamparski) Date: Fri, 22 Jun 2018 11:49:15 -0400 Subject: Did zip ever used to fail with 0 arguments? Message-ID: >>> list(zip()) [] I'm not sure why, but I really could've sworn this used to produce something like: TypeError: zip requires at least one argument which is often what I would rather have happen since 0 arguments is a degenerate case. (consider the result of zip(*zip(*args)) for 1+ arguments versus 0 arguments). I looked all through the changelog (including the HISTORY file, which I searched all the way down to the point where zip first became an iterator), but I don't see anything to this effect. Am I crazy? (maybe I am confusing it with another language? But I can hardly even begin to guess how, because Python is more or less the only dynamically-typed language I use!) --- Michael From steve+comp.lang.python at pearwood.info Fri Jun 22 12:26:57 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 22 Jun 2018 16:26:57 +0000 (UTC) Subject: Did zip ever used to fail with 0 arguments? References: Message-ID: On Fri, 22 Jun 2018 11:49:15 -0400, Michael Lamparski wrote: >>>> list(zip()) > [] > > I'm not sure why, but I really could've sworn this used to produce > something like: > > TypeError: zip requires at least one argument No, you are correct, but you have to go all the way back to Python 2.3 to see that behaviour: https://docs.python.org/2/library/functions.html#zip New in version 2.0. Changed in version 2.4: Formerly, zip() required at least one argument and zip() raised a TypeError instead of returning an empty list. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From Joseph.Schachner at Teledyne.com Fri Jun 22 13:04:01 2018 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Fri, 22 Jun 2018 17:04:01 +0000 Subject: ironpython not support py3.6 In-Reply-To: <58dacf58-a637-4957-9922-c32a32ca3a51@googlegroups.com> References: <58dacf58-a637-4957-9922-c32a32ca3a51@googlegroups.com> Message-ID: <666e747f3e2d4a6b8ce9514c6f3142f5@Teledyne.com> Wait. -----Original Message----- From: fantasywangxg at gmail.com Sent: Friday, June 22, 2018 2:45 AM To: python-list at python.org Subject: ironpython not support py3.6 We have a project implemented with c# and python, iron python is a good choice for us to integrate these two tech together but iron python not support python 3.6 yet, any suggest for this? From none at invalid.com Fri Jun 22 14:50:35 2018 From: none at invalid.com (mm0fmf) Date: Fri, 22 Jun 2018 19:50:35 +0100 Subject: Feeding the trolls In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <83429799-6952-44a9-9489-56811297cecf@googlegroups.com> <45764fe0-d839-834a-cb42-f3d01a21e182@timgolden.me.uk> <7435bbd5-656b-7976-0f1d-605bd1a9ae35@VybeNetworks.com> Message-ID: On 22/06/2018 00:51, Steven D'Aprano wrote: > On Thu, 21 Jun 2018 21:49:15 +0100, mm0fmf wrote: > > [snip unnecessary quoting] >> Design requirements for python newsreader client: >> >> 1. Block all top posters > > I think it would be far more useful to block bottom-posters who don't > snip irrelevant quoted text. > > > But the irony of being just as bad a post by quoting all the redundant text would be lost if that was cut and it just bitched about top posting. From ben.usenet at bsb.me.uk Fri Jun 22 15:06:35 2018 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Fri, 22 Jun 2018 20:06:35 +0100 Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> Message-ID: <8736xesksk.fsf@bsb.me.uk> Steven D'Aprano writes: > On Fri, 22 Jun 2018 11:14:59 +0100, Ben Bacarisse wrote: > >>>> The code page remark is curious. Will some "code pages" have digits >>>> that are not ASCII digits? >>> >>> Good question. I have no idea. >> >> It's much more of an open question than I thought. > > Nah, Python already solves that for you: My understanding was that the OP does not (reliably) know the encoding, though that was a guess based on a turn of phrase. Another guess is that the OP does not have Unicode data. The term "code page" hints at an 8-bit encoding or at least a pre-Unicode one. -- Ben. From denis.akhiyarov at 1 Fri Jun 22 18:20:28 2018 From: denis.akhiyarov at 1 (denis akhiyarov) Date: Fri, 22 Jun 2018 17:20:28 -0500 Subject: ironpython not support py3.6 Message-ID: <5B2FCDF9.20882.uclanpyth@castlerockbbs.com> To: Schachner, Joseph From: denis.akhiyarov at gmail.com Either wait for IronPython 3.6, use COM interop, pythonnet, subprocess, or things like gRPC. Based on PyPy experience, it is probably 1-2 years of sponsored development to get a working IronPython 3.6. --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From denis.akhiyarov at 1 Fri Jun 22 18:20:28 2018 From: denis.akhiyarov at 1 (denis akhiyarov) Date: Fri, 22 Jun 2018 17:20:28 -0500 Subject: ironpython not support py3.6 Message-ID: <5B324678.21102.uclanpyth@castlerockbbs.com> To: Schachner, Joseph From: "denis akhiyarov" To: Schachner, Joseph From: denis.akhiyarov at gmail.com Either wait for IronPython 3.6, use COM interop, pythonnet, subprocess, or things like gRPC. Based on PyPy experience, it is probably 1-2 years of sponsored development to get a working IronPython 3.6. -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From denis.akhiyarov at gmail.com Fri Jun 22 20:20:29 2018 From: denis.akhiyarov at gmail.com (denis.akhiyarov at gmail.com) Date: Fri, 22 Jun 2018 17:20:29 -0700 (PDT) Subject: ironpython not support py3.6 In-Reply-To: References: <58dacf58-a637-4957-9922-c32a32ca3a51@googlegroups.com> <666e747f3e2d4a6b8ce9514c6f3142f5@Teledyne.com> Message-ID: <09f7839f-a5d8-433d-80b6-16330959a2a5@googlegroups.com> Either wait for IronPython 3.6, use COM interop, pythonnet, subprocess, or things like gRPC. Based on PyPy experience, it is probably 1-2 years of sponsored development to get a working IronPython 3.6. From mm0fmf at 1 Fri Jun 22 20:50:34 2018 From: mm0fmf at 1 (mm0fmf) Date: Fri, 22 Jun 2018 19:50:34 -0500 Subject: Feeding the trolls Message-ID: <5B2FCDF9.20880.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: mm0fmf On 22/06/2018 00:51, Steven D'Aprano wrote: > On Thu, 21 Jun 2018 21:49:15 +0100, mm0fmf wrote: > > [snip unnecessary quoting] >> Design requirements for python newsreader client: >> >> 1. Block all top posters > > I think it would be far more useful to block bottom-posters who don't > snip irrelevant quoted text. > > > But the irony of being just as bad a post by quoting all the redundant text would be lost if that was cut and it just bitched about top posting. --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From mm0fmf at 1 Fri Jun 22 20:50:34 2018 From: mm0fmf at 1 (mm0fmf) Date: Fri, 22 Jun 2018 19:50:34 -0500 Subject: Feeding the trolls Message-ID: <5B324677.21100.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: "mm0fmf" To: Steven D'Aprano From: mm0fmf On 22/06/2018 00:51, Steven D'Aprano wrote: > On Thu, 21 Jun 2018 21:49:15 +0100, mm0fmf wrote: > > [snip unnecessary quoting] >> Design requirements for python newsreader client: >> >> 1. Block all top posters > > I think it would be far more useful to block bottom-posters who don't > snip irrelevant quoted text. > > > But the irony of being just as bad a post by quoting all the redundant text would be lost if that was cut and it just bitched about top posting. -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From ben.bacarisse at 1 Fri Jun 22 21:06:34 2018 From: ben.bacarisse at 1 (Ben Bacarisse) Date: Fri, 22 Jun 2018 20:06:34 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20881.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: Ben Bacarisse Steven D'Aprano writes: > On Fri, 22 Jun 2018 11:14:59 +0100, Ben Bacarisse wrote: > >>>> The code page remark is curious. Will some "code pages" have digits >>>> that are not ASCII digits? >>> >>> Good question. I have no idea. >> >> It's much more of an open question than I thought. > > Nah, Python already solves that for you: My understanding was that the OP does not (reliably) know the encoding, though that was a guess based on a turn of phrase. Another guess is that the OP does not have Unicode data. The term "code page" hints at an 8-bit encoding or at least a pre-Unicode one. -- Ben. --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From ben.bacarisse at 1 Fri Jun 22 21:06:34 2018 From: ben.bacarisse at 1 (Ben Bacarisse) Date: Fri, 22 Jun 2018 20:06:34 -0500 Subject: translating foreign data Message-ID: <5B324678.21101.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: "Ben Bacarisse" To: Steven D'Aprano From: Ben Bacarisse Steven D'Aprano writes: > On Fri, 22 Jun 2018 11:14:59 +0100, Ben Bacarisse wrote: > >>>> The code page remark is curious. Will some "code pages" have digits >>>> that are not ASCII digits? >>> >>> Good question. I have no idea. >> >> It's much more of an open question than I thought. > > Nah, Python already solves that for you: My understanding was that the OP does not (reliably) know the encoding, though that was a guess based on a turn of phrase. Another guess is that the OP does not have Unicode data. The term "code page" hints at an 8-bit encoding or at least a pre-Unicode one. -- Ben. -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steve+comp.lang.python at pearwood.info Fri Jun 22 23:21:08 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 23 Jun 2018 03:21:08 +0000 (UTC) Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> Message-ID: On Fri, 22 Jun 2018 20:06:35 +0100, Ben Bacarisse wrote: > Steven D'Aprano writes: > >> On Fri, 22 Jun 2018 11:14:59 +0100, Ben Bacarisse wrote: >> >>>>> The code page remark is curious. Will some "code pages" have digits >>>>> that are not ASCII digits? >>>> >>>> Good question. I have no idea. >>> >>> It's much more of an open question than I thought. >> >> Nah, Python already solves that for you: > > My understanding was that the OP does not (reliably) know the encoding, > though that was a guess based on a turn of phrase. I took it the other way: that Ethan *does* know the encoding, and his problem is that knowing the encoding and/or locale is not enough to recognise whether to use a period or comma as the decimal separator. Which it isn't. If he doesn't know the encoding, he has bigger problems than just converting strings into floats. Without knowing the encoding, he cannot even reliably detect non-ASCII digits at all. > Another guess is that the OP does not have Unicode data. The term "code > page" hints at an 8-bit encoding or at least a pre-Unicode one. Assuming he is using Python 3, or using Python 2 sensibly, once he has specified the encoding and read the data from the file, he has Unicode. Unicode is a superset of (ideally) all code pages. Once you have decoded the data using the appropriate code page, you have a Unicode string, and Python doesn't care where it came from. The point is, once Ethan can get the intended characters out of the file into Python, it doesn't matter what code page they came from. They're now full-fledged Unicode characters, and Python's float() and int() functions can easily deal with non-ASCII digits. So long as he has digits in the first place, float() and int() will deal with them correctly. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Fri Jun 22 23:51:22 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 23 Jun 2018 03:51:22 +0000 (UTC) Subject: Static variables [was Re: syntax difference] References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: On Wed, 20 Jun 2018 14:18:19 +1000, Chris Angelico wrote: > Ah. Yeah, that would be a plausible feature to add to Python. But in C, > a static variable is basically the same thing as a global variable, > except that its name is scoped to the function. There is only one of it. > What happens in Python? For instance: > > def f(): > def g(): > static x = 0 > x += 1 > return x > return g > > Does the static variable exist once for each instance of g()? If so, > it'll behave like a closure variable; if not, it'll behave like a > global. Either way, I'm pretty much certain that people will expect the > other. Yes, but given the normal execution model of Python, only one solution is valid. Since the function g is created fresh each time f is called, each one gets a fresh static x. If you want all the g's to share the same x, you would write: def f(): static x = 0 def g(): x += 1 return x return g In this case, every invocation of f shares the same static x, and all the g's refer to that same x, using the ordinary closure mechanism. In the earlier case, each invocation of f creates a brand new g with its own x. Simple and elegant. This could at last get rid of that useful but ugly idiom: def function(real, arguments, len=len, int=int, str=str): ... if we allowed the "static" declaration to access the values from the surrounding scope: def function(real, arguments): static len=len, int=int, str=str But I think nicer than that would be a decorator: @static(len=len, int=int, str=str) def function(real, arguments): ... which adds local variables len, int, str to the function, with the given values, and transforms all the bytecode LOAD_NAME len to LOAD_FAST len (or whatever). (We might need a new bytecode to SET_STATIC.) That would be a nice bytecode hack to prove the usefulness of the concept! -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sat Jun 23 00:16:58 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 23 Jun 2018 14:16:58 +1000 Subject: Static variables [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: On Sat, Jun 23, 2018 at 1:51 PM, Steven D'Aprano wrote: > On Wed, 20 Jun 2018 14:18:19 +1000, Chris Angelico wrote: > >> Ah. Yeah, that would be a plausible feature to add to Python. But in C, >> a static variable is basically the same thing as a global variable, >> except that its name is scoped to the function. There is only one of it. >> What happens in Python? For instance: >> >> def f(): >> def g(): >> static x = 0 >> x += 1 >> return x >> return g >> >> Does the static variable exist once for each instance of g()? If so, >> it'll behave like a closure variable; if not, it'll behave like a >> global. Either way, I'm pretty much certain that people will expect the >> other. > > Yes, but given the normal execution model of Python, only one solution is > valid. Since the function g is created fresh each time f is called, each > one gets a fresh static x. > > If you want all the g's to share the same x, you would write: > > def f(): > static x = 0 > def g(): > x += 1 > return x > return g > > > In this case, every invocation of f shares the same static x, and all the > g's refer to that same x, using the ordinary closure mechanism. In the > earlier case, each invocation of f creates a brand new g with its own x. > > Simple and elegant. > > This could at last get rid of that useful but ugly idiom: > > def function(real, arguments, len=len, int=int, str=str): > ... > > if we allowed the "static" declaration to access the values from the > surrounding scope: > > def function(real, arguments): > static len=len, int=int, str=str > > But I think nicer than that would be a decorator: > > @static(len=len, int=int, str=str) > def function(real, arguments): > ... > > which adds local variables len, int, str to the function, with the given > values, and transforms all the bytecode LOAD_NAME len to LOAD_FAST len > (or whatever). > > (We might need a new bytecode to SET_STATIC.) > > That would be a nice bytecode hack to prove the usefulness of the concept! > Okay, that makes sense. So in a way, static variables would be like closure variables with an invisible outer function. These would be roughly equivalent: def f(): static x = 0 x += 1 return x def make_f(): x = 0 def f(): nonlocal x x += 1 return x return f f = make_f() I don't think LOAD_FAST is appropriate (those cells get disposed of when the function returns), but transforming those lookups into closure lookups would be a reasonable way to do it I think. For getting rid of the "len=len" trick, though, I would REALLY like to transform those into LOAD_CONST. That'd be a fun bytecode hack all on its own. In fact, I'm gonna have a shot at that. An "early bind these names" decorator. ChrisA From rosuav at gmail.com Sat Jun 23 01:21:33 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 23 Jun 2018 15:21:33 +1000 Subject: Static variables [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: On Sat, Jun 23, 2018 at 2:16 PM, Chris Angelico wrote: > For getting rid of the "len=len" trick, though, I would REALLY like to > transform those into LOAD_CONST. That'd be a fun bytecode hack all on > its own. In fact, I'm gonna have a shot at that. An "early bind these > names" decorator. Well, that was easier than I expected. Which almost certainly means I haven't properly solved the problem. https://github.com/Rosuav/shed/blob/master/consts.py Let's start finding all the edge cases that don't work, so I can work on fixing them :) ChrisA From wxjmfauth at 1 Sat Jun 23 02:03:48 2018 From: wxjmfauth at 1 (wxjmfauth) Date: Sat, 23 Jun 2018 01:03:48 -0500 Subject: ironpython not support py3.6 Message-ID: <5B2FCDF9.20887.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: wxjmfauth at gmail.com Le vendredi 22 juin 2018 11:07:15 UTC+2, Steven D'Aprano a ?Ccrit? : > > C# <--> IronPython 2.7 <--> CPython 3.6 > C# <--> IronPython 2.7. It will not work. Coding of characters ! Try with IronPython 2.7.8. PS Yes, I know, it is based on .NET !!! --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From wxjmfauth at 1 Sat Jun 23 02:03:48 2018 From: wxjmfauth at 1 (wxjmfauth) Date: Sat, 23 Jun 2018 01:03:48 -0500 Subject: ironpython not support py3.6 Message-ID: <5B324678.21107.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: "wxjmfauth" To: Steven D'Aprano From: wxjmfauth at gmail.com Le vendredi 22 juin 2018 11:07:15 UTC+2, Steven D'Aprano a ?Ccrit? : > > C# <--> IronPython 2.7 <--> CPython 3.6 > C# <--> IronPython 2.7. It will not work. Coding of characters ! Try with IronPython 2.7.8. PS Yes, I know, it is based on .NET !!! -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From hjp-python at hjp.at Sat Jun 23 04:20:24 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 23 Jun 2018 10:20:24 +0200 Subject: ironpython not support py3.6 In-Reply-To: <09f7839f-a5d8-433d-80b6-16330959a2a5@googlegroups.com> References: <58dacf58-a637-4957-9922-c32a32ca3a51@googlegroups.com> <666e747f3e2d4a6b8ce9514c6f3142f5@Teledyne.com> <09f7839f-a5d8-433d-80b6-16330959a2a5@googlegroups.com> Message-ID: <20180623082023.jhqyalf4s4xirdgn@hjp.at> On 2018-06-22 17:20:29 -0700, denis.akhiyarov at gmail.com wrote: > Either wait for IronPython 3.6, use COM interop, pythonnet, > subprocess, or things like gRPC. Based on PyPy experience, it is > probably 1-2 years of sponsored development to get a working > IronPython 3.6. What is the current state of IronPython 3? The website is very uninformative (there's a 4 year old blog post saying "we started a repository", but that's it). The repository gets commits every now and then (so it's obviously not dead yet), but neither the readme nor the wiki give a hint beyond "not ready yet". 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 steven.d'aprano at 1 Sat Jun 23 04:21:08 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sat, 23 Jun 2018 03:21:08 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20883.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Fri, 22 Jun 2018 20:06:35 +0100, Ben Bacarisse wrote: > Steven D'Aprano writes: > >> On Fri, 22 Jun 2018 11:14:59 +0100, Ben Bacarisse wrote: >> >>>>> The code page remark is curious. Will some "code pages" have digits >>>>> that are not ASCII digits? >>>> >>>> Good question. I have no idea. >>> >>> It's much more of an open question than I thought. >> >> Nah, Python already solves that for you: > > My understanding was that the OP does not (reliably) know the encoding, > though that was a guess based on a turn of phrase. I took it the other way: that Ethan *does* know the encoding, and his problem is that knowing the encoding and/or locale is not enough to recognise whether to use a period or comma as the decimal separator. Which it isn't. If he doesn't know the encoding, he has bigger problems than just converting strings into floats. Without knowing the encoding, he cannot even reliably detect non-ASCII digits at all. > Another guess is that the OP does not have Unicode data. The term "code > page" hints at an 8-bit encoding or at least a pre-Unicode one. Assuming he is using Python 3, or using Python 2 sensibly, once he has specified the encoding and read the data from the file, he has Unicode. Unicode is a superset of (ideally) all code pages. Once you have decoded the data using the appropriate code page, you have a Unicode string, and Python doesn't care where it came from. The point is, once Ethan can get the intended characters out of the file into Python, it doesn't matter what code page they came from. They're now full-fledged Unicode characters, and Python's float() and int() functions can easily deal with non-ASCII digits. So long as he has digits in the first place, float() and int() will deal with them correctly. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sat Jun 23 04:21:08 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sat, 23 Jun 2018 03:21:08 -0500 Subject: translating foreign data Message-ID: <5B324678.21103.uclanpyth@castlerockbbs.com> From: "Steven D'Aprano" From: Steven D'Aprano On Fri, 22 Jun 2018 20:06:35 +0100, Ben Bacarisse wrote: > Steven D'Aprano writes: > >> On Fri, 22 Jun 2018 11:14:59 +0100, Ben Bacarisse wrote: >> >>>>> The code page remark is curious. Will some "code pages" have digits >>>>> that are not ASCII digits? >>>> >>>> Good question. I have no idea. >>> >>> It's much more of an open question than I thought. >> >> Nah, Python already solves that for you: > > My understanding was that the OP does not (reliably) know the encoding, > though that was a guess based on a turn of phrase. I took it the other way: that Ethan *does* know the encoding, and his problem is that knowing the encoding and/or locale is not enough to recognise whether to use a period or comma as the decimal separator. Which it isn't. If he doesn't know the encoding, he has bigger problems than just converting strings into floats. Without knowing the encoding, he cannot even reliably detect non-ASCII digits at all. > Another guess is that the OP does not have Unicode data. The term "code > page" hints at an 8-bit encoding or at least a pre-Unicode one. Assuming he is using Python 3, or using Python 2 sensibly, once he has specified the encoding and read the data from the file, he has Unicode. Unicode is a superset of (ideally) all code pages. Once you have decoded the data using the appropriate code page, you have a Unicode string, and Python doesn't care where it came from. The point is, once Ethan can get the intended characters out of the file into Python, it doesn't matter what code page they came from. They're now full-fledged Unicode characters, and Python's float() and int() functions can easily deal with non-ASCII digits. So long as he has digits in the first place, float() and int() will deal with them correctly. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sat Jun 23 04:51:22 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sat, 23 Jun 2018 03:51:22 -0500 Subject: Static variables [was Re: syntax difference] Message-ID: <5B2FCDF9.20884.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Wed, 20 Jun 2018 14:18:19 +1000, Chris Angelico wrote: > Ah. Yeah, that would be a plausible feature to add to Python. But in C, > a static variable is basically the same thing as a global variable, > except that its name is scoped to the function. There is only one of it. > What happens in Python? For instance: > > def f(): > def g(): > static x = 0 > x += 1 > return x > return g > > Does the static variable exist once for each instance of g()? If so, > it'll behave like a closure variable; if not, it'll behave like a > global. Either way, I'm pretty much certain that people will expect the > other. Yes, but given the normal execution model of Python, only one solution is valid. Since the function g is created fresh each time f is called, each one gets a fresh static x. If you want all the g's to share the same x, you would write: def f(): static x = 0 def g(): x += 1 return x return g In this case, every invocation of f shares the same static x, and all the g's refer to that same x, using the ordinary closure mechanism. In the earlier case, each invocation of f creates a brand new g with its own x. Simple and elegant. This could at last get rid of that useful but ugly idiom: def function(real, arguments, len=len, int=int, str=str): ... if we allowed the "static" declaration to access the values from the surrounding scope: def function(real, arguments): static len=len, int=int, str=str But I think nicer than that would be a decorator: @static(len=len, int=int, str=str) def function(real, arguments): ... which adds local variables len, int, str to the function, with the given values, and transforms all the bytecode LOAD_NAME len to LOAD_FAST len (or whatever). (We might need a new bytecode to SET_STATIC.) That would be a nice bytecode hack to prove the usefulness of the concept! -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sat Jun 23 04:51:22 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sat, 23 Jun 2018 03:51:22 -0500 Subject: Static variables [was Re: syntax difference] Message-ID: <5B324678.21104.uclanpyth@castlerockbbs.com> From: "Steven D'Aprano" From: Steven D'Aprano On Wed, 20 Jun 2018 14:18:19 +1000, Chris Angelico wrote: > Ah. Yeah, that would be a plausible feature to add to Python. But in C, > a static variable is basically the same thing as a global variable, > except that its name is scoped to the function. There is only one of it. > What happens in Python? For instance: > > def f(): > def g(): > static x = 0 > x += 1 > return x > return g > > Does the static variable exist once for each instance of g()? If so, > it'll behave like a closure variable; if not, it'll behave like a > global. Either way, I'm pretty much certain that people will expect the > other. Yes, but given the normal execution model of Python, only one solution is valid. Since the function g is created fresh each time f is called, each one gets a fresh static x. If you want all the g's to share the same x, you would write: def f(): static x = 0 def g(): x += 1 return x return g In this case, every invocation of f shares the same static x, and all the g's refer to that same x, using the ordinary closure mechanism. In the earlier case, each invocation of f creates a brand new g with its own x. Simple and elegant. This could at last get rid of that useful but ugly idiom: def function(real, arguments, len=len, int=int, str=str): ... if we allowed the "static" declaration to access the values from the surrounding scope: def function(real, arguments): static len=len, int=int, str=str But I think nicer than that would be a decorator: @static(len=len, int=int, str=str) def function(real, arguments): ... which adds local variables len, int, str to the function, with the given values, and transforms all the bytecode LOAD_NAME len to LOAD_FAST len (or whatever). (We might need a new bytecode to SET_STATIC.) That would be a nice bytecode hack to prove the usefulness of the concept! -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From Richard at Damon-Family.org Sat Jun 23 06:26:22 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 23 Jun 2018 06:26:22 -0400 Subject: translating foreign data In-Reply-To: References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> Message-ID: On 6/22/18 11:21 PM, Steven D'Aprano wrote: > On Fri, 22 Jun 2018 20:06:35 +0100, Ben Bacarisse wrote: > >> Steven D'Aprano writes: >> >>> On Fri, 22 Jun 2018 11:14:59 +0100, Ben Bacarisse wrote: >>> >>>>>> The code page remark is curious. Will some "code pages" have digits >>>>>> that are not ASCII digits? >>>>> Good question. I have no idea. >>>> It's much more of an open question than I thought. >>> Nah, Python already solves that for you: >> My understanding was that the OP does not (reliably) know the encoding, >> though that was a guess based on a turn of phrase. > I took it the other way: that Ethan *does* know the encoding, and his > problem is that knowing the encoding and/or locale is not enough to > recognise whether to use a period or comma as the decimal separator. > > Which it isn't. If you know the Locale, then you do know what the decimal separator is, as that is part of what a locale defines. The issue is that if you just know the encoding, you don't necessarily know the locale. He also commented that he didn't want to set the locale in the routine, as that sets it globally for the full application (but perhaps that latter could be fixed by first doing a locale.getlocale(), then setlocale for the files locale, and then at the end of reading and processing restore back the old locale. > > If he doesn't know the encoding, he has bigger problems than just > converting strings into floats. Without knowing the encoding, he cannot > even reliably detect non-ASCII digits at all. > > >> Another guess is that the OP does not have Unicode data. The term "code >> page" hints at an 8-bit encoding or at least a pre-Unicode one. > Assuming he is using Python 3, or using Python 2 sensibly, once he has > specified the encoding and read the data from the file, he has Unicode. > > Unicode is a superset of (ideally) all code pages. Once you have decoded > the data using the appropriate code page, you have a Unicode string, and > Python doesn't care where it came from. > > The point is, once Ethan can get the intended characters out of the file > into Python, it doesn't matter what code page they came from. They're now > full-fledged Unicode characters, and Python's float() and int() functions > can easily deal with non-ASCII digits. So long as he has digits in the > first place, float() and int() will deal with them correctly. > > -- Richard Damon From richard.damon at 1 Sat Jun 23 07:26:22 2018 From: richard.damon at 1 (Richard Damon) Date: Sat, 23 Jun 2018 06:26:22 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20889.uclanpyth@castlerockbbs.com> From: Richard Damon On 6/22/18 11:21 PM, Steven D'Aprano wrote: > On Fri, 22 Jun 2018 20:06:35 +0100, Ben Bacarisse wrote: > >> Steven D'Aprano writes: >> >>> On Fri, 22 Jun 2018 11:14:59 +0100, Ben Bacarisse wrote: >>> >>>>>> The code page remark is curious. Will some "code pages" have digits >>>>>> that are not ASCII digits? >>>>> Good question. I have no idea. >>>> It's much more of an open question than I thought. >>> Nah, Python already solves that for you: >> My understanding was that the OP does not (reliably) know the encoding, >> though that was a guess based on a turn of phrase. > I took it the other way: that Ethan *does* know the encoding, and his > problem is that knowing the encoding and/or locale is not enough to > recognise whether to use a period or comma as the decimal separator. > > Which it isn't. If you know the Locale, then you do know what the decimal separator is, as that is part of what a locale defines. The issue is that if you just know the encoding, you don't necessarily know the locale. He also commented that he didn't want to set the locale in the routine, as that sets it globally for the full application (but perhaps that latter could be fixed by first doing a locale.getlocale(), then setlocale for the files locale, and then at the end of reading and processing restore back the old locale. > > If he doesn't know the encoding, he has bigger problems than just > converting strings into floats. Without knowing the encoding, he cannot > even reliably detect non-ASCII digits at all. > > >> Another guess is that the OP does not have Unicode data. The term "code >> page" hints at an 8-bit encoding or at least a pre-Unicode one. > Assuming he is using Python 3, or using Python 2 sensibly, once he has > specified the encoding and read the data from the file, he has Unicode. > > Unicode is a superset of (ideally) all code pages. Once you have decoded > the data using the appropriate code page, you have a Unicode string, and > Python doesn't care where it came from. > > The point is, once Ethan can get the intended characters out of the file > into Python, it doesn't matter what code page they came from. They're now > full-fledged Unicode characters, and Python's float() and int() functions > can easily deal with non-ASCII digits. So long as he has digits in the > first place, float() and int() will deal with them correctly. > > -- Richard Damon --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From richard.damon at 1 Sat Jun 23 07:26:22 2018 From: richard.damon at 1 (Richard Damon) Date: Sat, 23 Jun 2018 06:26:22 -0500 Subject: translating foreign data Message-ID: <5B324678.21109.uclanpyth@castlerockbbs.com> From: "Richard Damon" From: Richard Damon On 6/22/18 11:21 PM, Steven D'Aprano wrote: > On Fri, 22 Jun 2018 20:06:35 +0100, Ben Bacarisse wrote: > >> Steven D'Aprano writes: >> >>> On Fri, 22 Jun 2018 11:14:59 +0100, Ben Bacarisse wrote: >>> >>>>>> The code page remark is curious. Will some "code pages" have digits >>>>>> that are not ASCII digits? >>>>> Good question. I have no idea. >>>> It's much more of an open question than I thought. >>> Nah, Python already solves that for you: >> My understanding was that the OP does not (reliably) know the encoding, >> though that was a guess based on a turn of phrase. > I took it the other way: that Ethan *does* know the encoding, and his > problem is that knowing the encoding and/or locale is not enough to > recognise whether to use a period or comma as the decimal separator. > > Which it isn't. If you know the Locale, then you do know what the decimal separator is, as that is part of what a locale defines. The issue is that if you just know the encoding, you don't necessarily know the locale. He also commented that he didn't want to set the locale in the routine, as that sets it globally for the full application (but perhaps that latter could be fixed by first doing a locale.getlocale(), then setlocale for the files locale, and then at the end of reading and processing restore back the old locale. > > If he doesn't know the encoding, he has bigger problems than just > converting strings into floats. Without knowing the encoding, he cannot > even reliably detect non-ASCII digits at all. > > >> Another guess is that the OP does not have Unicode data. The term "code >> page" hints at an 8-bit encoding or at least a pre-Unicode one. > Assuming he is using Python 3, or using Python 2 sensibly, once he has > specified the encoding and read the data from the file, he has Unicode. > > Unicode is a superset of (ideally) all code pages. Once you have decoded > the data using the appropriate code page, you have a Unicode string, and > Python doesn't care where it came from. > > The point is, once Ethan can get the intended characters out of the file > into Python, it doesn't matter what code page they came from. They're now > full-fledged Unicode characters, and Python's float() and int() functions > can easily deal with non-ASCII digits. So long as he has digits in the > first place, float() and int() will deal with them correctly. > > -- Richard Damon -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steve+comp.lang.python at pearwood.info Sat Jun 23 07:46:23 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 23 Jun 2018 11:46:23 +0000 (UTC) Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> Message-ID: On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote: > If you know the Locale, then you do know what the decimal separator is, > as that is part of what a locale defines. A locale defines a set of common cultural conventions. It doesn't mandate the actual conventions in use in any specific document. If I'm in Australia, using the en-AU locale, nevertheless I can generate a file using , as a decimal separator. Try and stop me :-) But your point is taken -- I misread Ethan saying that he knew the locale and it wasn't helping, when in fact he was reluctant to change the locale as that's a process-wide global change. > The issue is that if you just > know the encoding, you don't necessarily know the locale. He also > commented that he didn't want to set the locale in the routine, as that > sets it globally for the full application (but perhaps that latter could > be fixed by first doing a locale.getlocale(), then setlocale for the > files locale, and then at the end of reading and processing restore back > the old locale. Indeed. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From marko at pacujo.net Sat Jun 23 08:03:10 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 23 Jun 2018 15:03:10 +0300 Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> Message-ID: <87h8ltiubl.fsf@elektro.pacujo.net> Richard Damon : > If you know the Locale, then you do know what the decimal separator > is, as that is part of what a locale defines. I don't know what that sentence means. > The issue is that if you just know the encoding, you don't necessarily > know the locale. I always know my locale. The locale is tied to the human user. > He also commented that he didn't want to set the locale in the > routine, as that sets it globally for the full application (but > perhaps that latter could be fixed by first doing a > locale.getlocale(), then setlocale for the files locale, and then at > the end of reading and processing restore back the old locale. Setting a locale application-wise is * not in accordance with the idea of a locale (the locale should be constant within a user session) * not easily possible (the locale is seen by all threads simultaneously) BTW, I think the locale is a terrible invention. Marko From Richard at Damon-Family.org Sat Jun 23 08:12:52 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 23 Jun 2018 08:12:52 -0400 Subject: translating foreign data In-Reply-To: References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> Message-ID: On 6/23/18 7:46 AM, Steven D'Aprano wrote: > On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote: > >> If you know the Locale, then you do know what the decimal separator is, >> as that is part of what a locale defines. > A locale defines a set of common cultural conventions. It doesn't mandate > the actual conventions in use in any specific document. > > If I'm in Australia, using the en-AU locale, nevertheless I can generate > a file using , as a decimal separator. Try and stop me :-) yes, you can MIS-use the en-AU locale and write 1,000 to mean the number One, just as you can misuse the language and write cat when you mean a member of the Canine group, but then the misinterpretation is on the creator of the document, not on the program that was told how the document is to be read. > > But your point is taken -- I misread Ethan saying that he knew the locale > and it wasn't helping, when in fact he was reluctant to change the locale > as that's a process-wide global change. > >> The issue is that if you just >> know the encoding, you don't necessarily know the locale. He also >> commented that he didn't want to set the locale in the routine, as that >> sets it globally for the full application (but perhaps that latter could >> be fixed by first doing a locale.getlocale(), then setlocale for the >> files locale, and then at the end of reading and processing restore back >> the old locale. > Indeed. > > -- Richard Damon From hjp-python at hjp.at Sat Jun 23 08:28:30 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 23 Jun 2018 14:28:30 +0200 Subject: translating foreign data In-Reply-To: References: <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> Message-ID: <20180623122830.s3y7k7642h2hixc2@hjp.at> On 2018-06-23 08:12:52 -0400, Richard Damon wrote: > On 6/23/18 7:46 AM, Steven D'Aprano wrote: > > On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote: > >> If you know the Locale, then you do know what the decimal separator is, > >> as that is part of what a locale defines. > > A locale defines a set of common cultural conventions. It doesn't mandate > > the actual conventions in use in any specific document. > > > > If I'm in Australia, using the en-AU locale, nevertheless I can generate > > a file using , as a decimal separator. Try and stop me :-) > yes, you can MIS-use the en-AU locale and write 1,000 to mean the number > One, just as you can misuse the language and write cat when you mean a > member of the Canine group, but then the misinterpretation is on the > creator of the document, not on the program that was told how the > document is to be read. How would he mis-use the en-AU locale to write 1 as "1,000"? I think to do that he would simply NOT use the locale. I think there are very good reasons to ignore the locale for specific purposes. For example, a Python interpreter should not use the locale when parsing Python, and a program producing Python should also ignore the locale. You two also seem to be writing about different things when you write "THE locale". Steven seems to mean the global settings a user has chosen, you seem to mean the specidic settings appropriate for parsing a specific file. 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 Richard at Damon-Family.org Sat Jun 23 08:34:00 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 23 Jun 2018 08:34:00 -0400 Subject: translating foreign data In-Reply-To: <87h8ltiubl.fsf@elektro.pacujo.net> References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <87h8ltiubl.fsf@elektro.pacujo.net> Message-ID: <8318150e-1f3c-eb97-d25c-475bddc6e223@Damon-Family.org> On 6/23/18 8:03 AM, Marko Rauhamaa wrote: > Richard Damon : >> If you know the Locale, then you do know what the decimal separator >> is, as that is part of what a locale defines. > I don't know what that sentence means. When you set the locale > >> The issue is that if you just know the encoding, you don't necessarily >> know the locale. > I always know my locale. The locale is tied to the human user. No, it should be tied to the data you are processing. If an English user is feeding a program Chinese documents, while processing those documents the program should be using the appropriate Chinese Locale. When generating output to the user, it should switch (back) to the appropriate English Locale (likely the system locale that the user set). > >> He also commented that he didn't want to set the locale in the >> routine, as that sets it globally for the full application (but >> perhaps that latter could be fixed by first doing a >> locale.getlocale(), then setlocale for the files locale, and then at >> the end of reading and processing restore back the old locale. > Setting a locale application-wise is > > * not in accordance with the idea of a locale (the locale should be > constant within a user session) Again, no, a locale is tied to the data, not the user (unless you want to require the user to translate all data to his locale conventions (without using a program that can use locale information) before providing it to a program. Yes, the default for the interpretation should be the users default/current locale, but you really want them to be able to say I got this file from someone whose locale was different than mine. Data presented to the user should normally use his locale (unless he has specified something different). > > * not easily possible (the locale is seen by all threads > simultaneously) That is an implementation error. It should be possible to create a thread specific locale, and it is really useful to create a local locale that can be used by the various conversion operators to say for this conversion use this specific locale as that is what this data indicated how it is to be interpreted. > > > BTW, I think the locale is a terrible invention. > > > Marko The locale is a lot better than the alternative, where every application that needs to deal with internationalization need to recreate (and debub) all of the mechanism. I agree it isn't perfect, and for small simple programs it would be nice to be able to say "I don't want all this stuff, make it go away". Python took its locale (at least initially) from C, which was a single global which does have more issues because of this. C++ objectified the locale and allows the programmer to imbue a specific locale into different parts of his program (in particular, each I/O Stream knows what locale its data is to be processed with). Perhaps (maybe it has) it could be good to adopt the object based locale concept of C++ (but that does come at a significant cost for things like CPython) where streams know their locale, and other operations can be optionally passed a locale to use. -- Richard Damon From Richard at Damon-Family.org Sat Jun 23 08:41:38 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 23 Jun 2018 08:41:38 -0400 Subject: translating foreign data In-Reply-To: <20180623122830.s3y7k7642h2hixc2@hjp.at> References: <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <20180623122830.s3y7k7642h2hixc2@hjp.at> Message-ID: <4ab18727-b47d-8fb3-3ed5-2ae4c8e6d123@Damon-Family.org> On 6/23/18 8:28 AM, Peter J. Holzer wrote: > On 2018-06-23 08:12:52 -0400, Richard Damon wrote: >> On 6/23/18 7:46 AM, Steven D'Aprano wrote: >>> On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote: >>>> If you know the Locale, then you do know what the decimal separator is, >>>> as that is part of what a locale defines. >>> A locale defines a set of common cultural conventions. It doesn't mandate >>> the actual conventions in use in any specific document. >>> >>> If I'm in Australia, using the en-AU locale, nevertheless I can generate >>> a file using , as a decimal separator. Try and stop me :-) >> yes, you can MIS-use the en-AU locale and write 1,000 to mean the number >> One, just as you can misuse the language and write cat when you mean a >> member of the Canine group, but then the misinterpretation is on the >> creator of the document, not on the program that was told how the >> document is to be read. > How would he mis-use the en-AU locale to write 1 as "1,000"? I think > to do that he would simply NOT use the locale. Once you open the Locale can of worms, EVERYTHING has a locale, to say you aren't using a locale is to say you are writing something unintelligible, as you can thing of the locale as the set of rules to interpret > > I think there are very good reasons to ignore the locale for specific > purposes. For example, a Python interpreter should not use the locale > when parsing Python, and a program producing Python should also ignore > the locale. Python, like many languages, define the formatting of things, so Python programs should be interpreted according to the "Python" locale (which may actually be named "C"). > > You two also seem to be writing about different things when you write > "THE locale". Steven seems to mean the global settings a user has > chosen, you seem to mean the specidic settings appropriate for parsing a > specific file. > > hp > You have THE locale for a given piece of data. My point is that Python has adopted the C method of a single global locale for a program, so in the program there is a 'THE Locale' which may actually need to be different when processing different information, leading to some of the issues. -- Richard Damon From bc at freeuk.com Sat Jun 23 08:41:59 2018 From: bc at freeuk.com (Bart) Date: Sat, 23 Jun 2018 13:41:59 +0100 Subject: Static variables [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: On 23/06/2018 04:51, Steven D'Aprano wrote: > On Wed, 20 Jun 2018 14:18:19 +1000, Chris Angelico wrote: > >> Ah. Yeah, that would be a plausible feature to add to Python. But in C, >> a static variable is basically the same thing as a global variable, >> except that its name is scoped to the function. There is only one of it. >> What happens in Python? For instance: >> >> def f(): >> def g(): >> static x = 0 >> x += 1 >> return x >> return g >> >> Does the static variable exist once for each instance of g()? If so, >> it'll behave like a closure variable; if not, it'll behave like a >> global. Either way, I'm pretty much certain that people will expect the >> other. > > Yes, but given the normal execution model of Python, only one solution is > valid. Since the function g is created fresh each time f is called, each > one gets a fresh static x. > > If you want all the g's to share the same x, you would write: > > def f(): > static x = 0 > def g(): > x += 1 > return x > return g > > > In this case, every invocation of f shares the same static x, and all the > g's refer to that same x, using the ordinary closure mechanism. In the > earlier case, each invocation of f creates a brand new g with its own x. > > Simple and elegant. > > This could at last get rid of that useful but ugly idiom: > > def function(real, arguments, len=len, int=int, str=str): > ... > > if we allowed the "static" declaration to access the values from the > surrounding scope: > > def function(real, arguments): > static len=len, int=int, str=str > > But I think nicer than that would be a decorator: > > @static(len=len, int=int, str=str) > def function(real, arguments): > ... > > which adds local variables len, int, str to the function, with the given > values, and transforms all the bytecode LOAD_NAME len to LOAD_FAST len > (or whatever). > > (We might need a new bytecode to SET_STATIC.) > > That would be a nice bytecode hack to prove the usefulness of the concept! This is an example of a simple concept getting so out of hand that it will either never be implemented, or the resulting implementation becomes impractical to use. This is what we're trying to do: def nextx(): static x = 0 x += 1 return x And this is the simplest equivalent code in current Python that will cater for 99% of uses: _nextx_x = 0 def nextx(): global _nextx_x _nextx_x += 1 return _nextx_x No nested functions. No generating new instances of functions complete with a new set of statics each time you happen to refer to the name. (Which sounds to me as useful as creating a new instance of an import when you copy its name, complete with a separate set of its globals. Isn't this stuff what classes are for?) (At what point would that happen anyway; if you do this: g = nextx # hypothetical version would static it will create a new instance of 'nextx'. But it won't create one here, just before () is applied: nextx() # ? Or how about here: listoffunctions = (nextx1, nextx2, nextx3) listoffunctions[i]() # ? ) -- bartc From marko at pacujo.net Sat Jun 23 09:05:07 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 23 Jun 2018 16:05:07 +0300 Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <87h8ltiubl.fsf@elektro.pacujo.net> <8318150e-1f3c-eb97-d25c-475bddc6e223@Damon-Family.org> Message-ID: <87d0whirgc.fsf@elektro.pacujo.net> Richard Damon : > On 6/23/18 8:03 AM, Marko Rauhamaa wrote: >> I always know my locale. The locale is tied to the human user. > No, it should be tied to the data you are processing. In computing, a locale is a set of parameters that defines the user's language, region and any special variant preferences that the user wants to see in their user interface. The data should not depend on the locale. > If an English user is feeding a program Chinese documents, while > processing those documents the program should be using the appropriate > Chinese Locale. Not true. > Again, no, a locale is tied to the data, not the user (unless you want > to require the user to translate all data to his locale conventions > (without using a program that can use locale information) before > providing it to a program. Yes, the default for the interpretation > should be the users default/current locale, but you really want them > to be able to say I got this file from someone whose locale was > different than mine. The locale is not directly related to data or data formats. Of course, locales leak into data and create the sorry mess we are talking about. > Data presented to the user should normally use his locale (unless he > has specified something different). Ok. Here's a value for you: 100? I see '1', '0', '0', '?'. What do you see in your locale (LC_MONETARY)? >> BTW, I think the locale is a terrible invention. > > The locale is a lot better than the alternative, where every > application that needs to deal with internationalization need to > recreate (and debub) all of the mechanism. I agree it isn't perfect, > and for small simple programs it would be nice to be able to say "I > don't want all this stuff, make it go away". The locale doesn't solve a single problem in practice and often trips up programs. For example, a customer-visible bug was once caused by: sort Python took its locale (at least initially) from C, which was a single > global which does have more issues because of this. The single global is due to what the locale was introduced for. It came about around the time when Unix applications were being made "8-bit clean." Along with UCS-2 and XML, it's one of those things you wish you'd never have to deal with. Marko From e+python-list at kellett.im Sat Jun 23 09:08:22 2018 From: e+python-list at kellett.im (Ed Kellett) Date: Sat, 23 Jun 2018 14:08:22 +0100 Subject: Static variables [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: <98ecd8c1-13b7-8317-8177-6a35921712ff@kellett.im> On 2018-06-23 06:21, Chris Angelico wrote: > Let's start finding all the edge cases that don't work, so I can work > on fixing them :) Very long functions (or, more specifically, functions with a very large number of consts) will likely prove annoying. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From richard.damon at 1 Sat Jun 23 09:12:52 2018 From: richard.damon at 1 (Richard Damon) Date: Sat, 23 Jun 2018 08:12:52 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20900.uclanpyth@castlerockbbs.com> From: Richard Damon On 6/23/18 7:46 AM, Steven D'Aprano wrote: > On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote: > >> If you know the Locale, then you do know what the decimal separator is, >> as that is part of what a locale defines. > A locale defines a set of common cultural conventions. It doesn't mandate > the actual conventions in use in any specific document. > > If I'm in Australia, using the en-AU locale, nevertheless I can generate > a file using , as a decimal separator. Try and stop me :-) yes, you can MIS-use the en-AU locale and write 1,000 to mean the number One, just as you can misuse the language and write cat when you mean a member of the Canine group, but then the misinterpretation is on the creator of the document, not on the program that was told how the document is to be read. > > But your point is taken -- I misread Ethan saying that he knew the locale > and it wasn't helping, when in fact he was reluctant to change the locale > as that's a process-wide global change. > >> The issue is that if you just >> know the encoding, you don't necessarily know the locale. He also >> commented that he didn't want to set the locale in the routine, as that >> sets it globally for the full application (but perhaps that latter could >> be fixed by first doing a locale.getlocale(), then setlocale for the >> files locale, and then at the end of reading and processing restore back >> the old locale. > Indeed. > > -- Richard Damon --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From rick.johnson at 1 Sat Jun 23 09:32:32 2018 From: rick.johnson at 1 (Rick Johnson) Date: Sat, 23 Jun 2018 08:32:32 -0500 Subject: "Data blocks" syntax specification draft Message-ID: <5B2FCDF9.20915.uclanpyth@castlerockbbs.com> From: Rick Johnson On Sunday, May 20, 2018 at 5:29:11 PM UTC-5, Mikhail V wrote: > What against PDF? I'm not a big fan of PDF either. Adobe Reader is one the most bloated POS software i have ever had the misfortune of hosting on my computers, and i absolutely refuse to host that crapware any longer. And while there are smaller more sane PDF viewers and editors, i find the whole experience of PDF to be annoying. I would suggest sticking with HTML or raw text. Every computer worth its salt has a web browser, but not every computer needs (yet another) special purpose document format (PUKE!). And I refuse to participate in the propagation of the PDF file format. > Anyway, I have reloaded files with most recent corrections in various formats: > > PDF > https://github.com/Mikhail22/Documents/blob/master/data-blocks-v01.pdf > > TXT > https://github.com/Mikhail22/Documents/blob/master/data-blocks-v01.txt > > HTML(direct preview link) > http://htmlpreview.github.io/?https://raw.githubusercontent.com/Mikhail22/Doc uments/master/data-blocks-v01.html Thanks for providing the last two "sane" formats. --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From richard.damon at 1 Sat Jun 23 09:34:00 2018 From: richard.damon at 1 (Richard Damon) Date: Sat, 23 Jun 2018 08:34:00 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20902.uclanpyth@castlerockbbs.com> From: Richard Damon On 6/23/18 8:03 AM, Marko Rauhamaa wrote: > Richard Damon : >> If you know the Locale, then you do know what the decimal separator >> is, as that is part of what a locale defines. > I don't know what that sentence means. When you set the locale > >> The issue is that if you just know the encoding, you don't necessarily >> know the locale. > I always know my locale. The locale is tied to the human user. No, it should be tied to the data you are processing. If an English user is feeding a program Chinese documents, while processing those documents the program should be using the appropriate Chinese Locale. When generating output to the user, it should switch (back) to the appropriate English Locale (likely the system locale that the user set). > >> He also commented that he didn't want to set the locale in the >> routine, as that sets it globally for the full application (but >> perhaps that latter could be fixed by first doing a >> locale.getlocale(), then setlocale for the files locale, and then at >> the end of reading and processing restore back the old locale. > Setting a locale application-wise is > > * not in accordance with the idea of a locale (the locale should be > constant within a user session) Again, no, a locale is tied to the data, not the user (unless you want to require the user to translate all data to his locale conventions (without using a program that can use locale information) before providing it to a program. Yes, the default for the interpretation should be the users default/current locale, but you really want them to be able to say I got this file from someone whose locale was different than mine. Data presented to the user should normally use his locale (unless he has specified something different). > > * not easily possible (the locale is seen by all threads > simultaneously) That is an implementation error. It should be possible to create a thread specific locale, and it is really useful to create a local locale that can be used by the various conversion operators to say for this conversion use this specific locale as that is what this data indicated how it is to be interpreted. > > > BTW, I think the locale is a terrible invention. > > > Marko The locale is a lot better than the alternative, where every application that needs to deal with internationalization need to recreate (and debub) all of the mechanism. I agree it isn't perfect, and for small simple programs it would be nice to be able to say "I don't want all this stuff, make it go away". Python took its locale (at least initially) from C, which was a single global which does have more issues because of this. C++ objectified the locale and allows the programmer to imbue a specific locale into different parts of his program (in particular, each I/O Stream knows what locale its data is to be processed with). Perhaps (maybe it has) it could be good to adopt the object based locale concept of C++ (but that does come at a significant cost for things like CPython) where streams know their locale, and other operations can be optionally passed a locale to use. -- Richard Damon --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From richard.damon at 1 Sat Jun 23 09:41:38 2018 From: richard.damon at 1 (Richard Damon) Date: Sat, 23 Jun 2018 08:41:38 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20904.uclanpyth@castlerockbbs.com> From: Richard Damon On 6/23/18 8:28 AM, Peter J. Holzer wrote: > On 2018-06-23 08:12:52 -0400, Richard Damon wrote: >> On 6/23/18 7:46 AM, Steven D'Aprano wrote: >>> On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote: >>>> If you know the Locale, then you do know what the decimal separator is, >>>> as that is part of what a locale defines. >>> A locale defines a set of common cultural conventions. It doesn't mandate >>> the actual conventions in use in any specific document. >>> >>> If I'm in Australia, using the en-AU locale, nevertheless I can generate >>> a file using , as a decimal separator. Try and stop me :-) >> yes, you can MIS-use the en-AU locale and write 1,000 to mean the number >> One, just as you can misuse the language and write cat when you mean a >> member of the Canine group, but then the misinterpretation is on the >> creator of the document, not on the program that was told how the >> document is to be read. > How would he mis-use the en-AU locale to write 1 as "1,000"? I think > to do that he would simply NOT use the locale. Once you open the Locale can of worms, EVERYTHING has a locale, to say you aren't using a locale is to say you are writing something unintelligible, as you can thing of the locale as the set of rules to interpret > > I think there are very good reasons to ignore the locale for specific > purposes. For example, a Python interpreter should not use the locale > when parsing Python, and a program producing Python should also ignore > the locale. Python, like many languages, define the formatting of things, so Python programs should be interpreted according to the "Python" locale (which may actually be named "C"). > > You two also seem to be writing about different things when you write > "THE locale". Steven seems to mean the global settings a user has > chosen, you seem to mean the specidic settings appropriate for parsing a > specific file. > > hp > You have THE locale for a given piece of data. My point is that Python has adopted the C method of a single global locale for a program, so in the program there is a 'THE Locale' which may actually need to be different when processing different information, leading to some of the issues. -- Richard Damon --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From Richard at Damon-Family.org Sat Jun 23 09:42:29 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 23 Jun 2018 09:42:29 -0400 Subject: translating foreign data In-Reply-To: <87d0whirgc.fsf@elektro.pacujo.net> References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <87h8ltiubl.fsf@elektro.pacujo.net> <8318150e-1f3c-eb97-d25c-475bddc6e223@Damon-Family.org> <87d0whirgc.fsf@elektro.pacujo.net> Message-ID: On 6/23/18 9:05 AM, Marko Rauhamaa wrote: > Richard Damon : > >> On 6/23/18 8:03 AM, Marko Rauhamaa wrote: >>> I always know my locale. The locale is tied to the human user. >> No, it should be tied to the data you are processing. > In computing, a locale is a set of parameters that defines the user's > language, region and any special variant preferences that the user > wants to see in their user interface. > > > > The data should not depend on the locale. So no one foreign ever gives you data? Note, that wikipedia article is focused on the SYSTEM locale, which yes, that should reflect the what the user wants in his interface. > >> If an English user is feeding a program Chinese documents, while >> processing those documents the program should be using the appropriate >> Chinese Locale. > Not true. How else is the program going to understand the Chinese data? > >> Again, no, a locale is tied to the data, not the user (unless you want >> to require the user to translate all data to his locale conventions >> (without using a program that can use locale information) before >> providing it to a program. Yes, the default for the interpretation >> should be the users default/current locale, but you really want them >> to be able to say I got this file from someone whose locale was >> different than mine. > The locale is not directly related to data or data formats. Of course, > locales leak into data and create the sorry mess we are talking about. The fact that locale issues leak into data is the reason that the single immutable global locale doesn't work. You really want to imbue into data streams what locale their data represents (and use that in some of the later processing of data from that stream). > >> Data presented to the user should normally use his locale (unless he >> has specified something different). > Ok. Here's a value for you: > > 100? > > I see '1', '0', '0', '?'. What do you see in your locale (LC_MONETARY)? If I processed that on my system I would either get $100, or an error of wrong currency symbol depending on the error checking. > >>> BTW, I think the locale is a terrible invention. >> The locale is a lot better than the alternative, where every >> application that needs to deal with internationalization need to >> recreate (and debub) all of the mechanism. I agree it isn't perfect, >> and for small simple programs it would be nice to be able to say "I >> don't want all this stuff, make it go away". > The locale doesn't solve a single problem in practice and often trips up > programs. For example, a customer-visible bug was once caused by: > > sort > producing different results on different customers' machines. > > Mental note: *always* prefix GNU textutils commands with LANG=C. Yes, one issue is that systems currently don't naturally tag data with the locale to use (you can't even know for sure character set a file is in, so your example above might be 100 some funny character(s). It is starting be true that you can often assume UTF-8 (at least on Linux, on Windows it is much less so), and validating that it is valid UTF-8 is a pretty good sign that it is. > >> Python took its locale (at least initially) from C, which was a single >> global which does have more issues because of this. > The single global is due to what the locale was introduced for. It came > about around the time when Unix applications were being made "8-bit > clean." Along with UCS-2 and XML, it's one of those things you wish > you'd never have to deal with. > > > Marko Locale predates UCS-2, it was the early attempt to provide internationalization to C code so even programmers who didn't think about it could add the line setlocale(LC_ALL, "") and make their code work at least mostly right in more places. A single global was quick and simple, and since threads didn't exist, not an issue. In many ways it was the first attempt that should have been thrown away, but got too intertwined. C++ made a significant improvement to it by having streams remember their own locale. -- Richard Damon From hjp-python at hjp.at Sat Jun 23 10:05:49 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 23 Jun 2018 16:05:49 +0200 Subject: translating foreign data In-Reply-To: <4ab18727-b47d-8fb3-3ed5-2ae4c8e6d123@Damon-Family.org> References: <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <20180623122830.s3y7k7642h2hixc2@hjp.at> <4ab18727-b47d-8fb3-3ed5-2ae4c8e6d123@Damon-Family.org> Message-ID: <20180623140549.3vun765hyvax2fe5@hjp.at> On 2018-06-23 08:41:38 -0400, Richard Damon wrote: > On 6/23/18 8:28 AM, Peter J. Holzer wrote: > > On 2018-06-23 08:12:52 -0400, Richard Damon wrote: > >> On 6/23/18 7:46 AM, Steven D'Aprano wrote: > >>> If I'm in Australia, using the en-AU locale, nevertheless I can generate > >>> a file using , as a decimal separator. Try and stop me :-) > >> yes, you can MIS-use the en-AU locale and write 1,000 to mean the number > >> One, just as you can misuse the language and write cat when you mean a > >> member of the Canine group, but then the misinterpretation is on the > >> creator of the document, not on the program that was told how the > >> document is to be read. > > How would he mis-use the en-AU locale to write 1 as "1,000"? I think > > to do that he would simply NOT use the locale. > Once you open the Locale can of worms, EVERYTHING has a locale, to say > you aren't using a locale is to say you are writing > something unintelligible, as you can thing of the locale as the set of > rules to interpret I don't think that's a useful way to look at it. "Locale" in (non-technical) English means "place" or "site". The idea behind the locale concept is that some conventions (e.g. how to write numbers or how to write strings) depend on the place where the program runs (or maybe where the user is sitting or grew up or maybe where a file was produced). For stuff which doesn't depend on the place (e.g. how a Python program should be parsed), the locale concept doesn't apply. > > You two also seem to be writing about different things when you write > > "THE locale". Steven seems to mean the global settings a user has > > chosen, you seem to mean the specidic settings appropriate for parsing a > > specific file. While I was writing this paragraph I realized that I had also used "the locale" in a specific meaning in the previous paragraph. I decided to let it stand and see whether anyone would call me out it. > You have THE locale for a given piece of data. Well, you didn't. Even though I quite obviously used "the locale" in Steven's meaning, you didn't react to that at all and just continue as if your definition is the only possible one. 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 marko at pacujo.net Sat Jun 23 10:10:08 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 23 Jun 2018 17:10:08 +0300 Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <87h8ltiubl.fsf@elektro.pacujo.net> <8318150e-1f3c-eb97-d25c-475bddc6e223@Damon-Family.org> <87d0whirgc.fsf@elektro.pacujo.net> Message-ID: <871scxegqn.fsf@elektro.pacujo.net> Richard Damon : > On 6/23/18 9:05 AM, Marko Rauhamaa wrote: >> Richard Damon : >> >>> On 6/23/18 8:03 AM, Marko Rauhamaa wrote: >>>> I always know my locale. The locale is tied to the human user. >>> No, it should be tied to the data you are processing. >> In computing, a locale is a set of parameters that defines the user's >> language, region and any special variant preferences that the user >> wants to see in their user interface. >> >> >> >> The data should not depend on the locale. > So no one foreign ever gives you data? Never in my decades in computer programming have I found any use for locales. In particular, they have never helped me decode "foreign" data, whether in ASCII, Latin-1, Latin-3, Latin-9, JIS or UTF-8. > Note, that wikipedia article is focused on the SYSTEM locale, which > yes, that should reflect the what the user wants in his interface. I don't think locales have anything to do with anything else. >>> If an English user is feeding a program Chinese documents, while >>> processing those documents the program should be using the >>> appropriate Chinese Locale. >> Not true. > How else is the program going to understand the Chinese data? If someone gives me a file, they had better indicate the file format. > The fact that locale issues leak into data is the reason that the > single immutable global locale doesn't work. Locales don't work. Period. > You really want to imbue into data streams what locale their data > represents (and use that in some of the later processing of data from > that stream). Can you refer to a standard for that kind of imbuement? Of course, you have document types, schema definitions and other implicit and explicit format indicators. You shouldn't call them locales, though. >>> Data presented to the user should normally use his locale (unless he >>> has specified something different). >> Ok. Here's a value for you: >> >> 100? >> >> I see '1', '0', '0', '?'. What do you see in your locale (LC_MONETARY)? > If I processed that on my system I would either get $100, or an error of > wrong currency symbol depending on the error checking. Don't forget to convert the amount as well... >> The single global is due to what the locale was introduced for. It >> came about around the time when Unix applications were being made >> "8-bit clean." Along with UCS-2 and XML, it's one of those things you >> wish you'd never have to deal with. > > Locale predates UCS-2, it was the early attempt to provide > internationalization to C code so even programmers who didn't think > about it could add the line setlocale(LC_ALL, "") and make their code > work at least mostly right in more places. A single global was quick > and simple, and since threads didn't exist, not an issue. > > In many ways it was the first attempt that should have been thrown > away, but got too intertwined. C++ made a significant improvement to > it by having streams remember their own locale. Noone should breathe any new life into locales. And yes, add C++ to the list of things you wish you'd never have to deal with... Marko From hjp-python at hjp.at Sat Jun 23 10:23:53 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 23 Jun 2018 16:23:53 +0200 Subject: translating foreign data In-Reply-To: <20180623140549.3vun765hyvax2fe5@hjp.at> References: <8736xesksk.fsf@bsb.me.uk> <20180623122830.s3y7k7642h2hixc2@hjp.at> <4ab18727-b47d-8fb3-3ed5-2ae4c8e6d123@Damon-Family.org> <20180623140549.3vun765hyvax2fe5@hjp.at> Message-ID: <20180623142353.y7bld53ltmtdeunc@hjp.at> On 2018-06-23 16:05:49 +0200, Peter J. Holzer wrote: > I don't think that's a useful way to look at it. "Locale" in > (non-technical) English means "place" or "site". The idea behind the > locale concept is that some conventions (e.g. how to write numbers or > how to write strings) depend on the place where the program runs Sorry, I meant "how to *sort* strings. 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 richard.damon at 1 Sat Jun 23 10:42:28 2018 From: richard.damon at 1 (Richard Damon) Date: Sat, 23 Jun 2018 09:42:28 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20909.uclanpyth@castlerockbbs.com> From: Richard Damon On 6/23/18 9:05 AM, Marko Rauhamaa wrote: > Richard Damon : > >> On 6/23/18 8:03 AM, Marko Rauhamaa wrote: >>> I always know my locale. The locale is tied to the human user. >> No, it should be tied to the data you are processing. > In computing, a locale is a set of parameters that defines the user's > language, region and any special variant preferences that the user > wants to see in their user interface. > > > > The data should not depend on the locale. So no one foreign ever gives you data? Note, that wikipedia article is focused on the SYSTEM locale, which yes, that should reflect the what the user wants in his interface. > >> If an English user is feeding a program Chinese documents, while >> processing those documents the program should be using the appropriate >> Chinese Locale. > Not true. How else is the program going to understand the Chinese data? > >> Again, no, a locale is tied to the data, not the user (unless you want >> to require the user to translate all data to his locale conventions >> (without using a program that can use locale information) before >> providing it to a program. Yes, the default for the interpretation >> should be the users default/current locale, but you really want them >> to be able to say I got this file from someone whose locale was >> different than mine. > The locale is not directly related to data or data formats. Of course, > locales leak into data and create the sorry mess we are talking about. The fact that locale issues leak into data is the reason that the single immutable global locale doesn't work. You really want to imbue into data streams what locale their data represents (and use that in some of the later processing of data from that stream). > >> Data presented to the user should normally use his locale (unless he >> has specified something different). > Ok. Here's a value for you: > > 100??? > > I see '1', '0', '0', '???'. What do you see in your locale (LC_MONETARY)? If I processed that on my system I would either get $100, or an error of wrong currency symbol depending on the error checking. > >>> BTW, I think the locale is a terrible invention. >> The locale is a lot better than the alternative, where every >> application that needs to deal with internationalization need to >> recreate (and debub) all of the mechanism. I agree it isn't perfect, >> and for small simple programs it would be nice to be able to say "I >> don't want all this stuff, make it go away". > The locale doesn't solve a single problem in practice and often trips up > programs. For example, a customer-visible bug was once caused by: > > sort > producing different results on different customers' machines. > > Mental note: *always* prefix GNU textutils commands with LANG=C. Yes, one issue is that systems currently don't naturally tag data with the locale to use (you can't even know for sure character set a file is in, so your example above might be 100 some funny character(s). It is starting be true that you can often assume UTF-8 (at least on Linux, on Windows it is much less so), and validating that it is valid UTF-8 is a pretty good sign that it is. > >> Python took its locale (at least initially) from C, which was a single >> global which does have more issues because of this. > The single global is due to what the locale was introduced for. It came > about around the time when Unix applications were being made "8-bit > clean." Along with UCS-2 and XML, it's one of those things you wish > you'd never have to deal with. > > > Marko Locale predates UCS-2, it was the early attempt to provide internationalization to C code so even programmers who didn't think about it could add the line setlocale(LC_ALL, "") and make their code work at least mostly right in more places. A single global was quick and simple, and since threads didn't exist, not an issue. In many ways it was the first attempt that should have been thrown away, but got too intertwined. C++ made a significant improvement to it by having streams remember their own locale. -- Richard Damon --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From arj.python at gmail.com Sat Jun 23 10:44:08 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sat, 23 Jun 2018 18:44:08 +0400 Subject: "Data blocks" syntax specification draft In-Reply-To: References: Message-ID: the tab separated idea is used in : e.g. see last section of files Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > > From peter.j..holzer at 1 Sat Jun 23 11:20:24 2018 From: peter.j..holzer at 1 (Peter J. Holzer) Date: Sat, 23 Jun 2018 10:20:24 -0500 Subject: ironpython not support py3.6 Message-ID: <5B2FCDF9.20888.uclanpyth@castlerockbbs.com> From: "Peter J. Holzer" --prnws536gtytpj5v Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2018-06-22 17:20:29 -0700, denis.akhiyarov at gmail.com wrote: > Either wait for IronPython 3.6, use COM interop, pythonnet, > subprocess, or things like gRPC. Based on PyPy experience, it is > probably 1-2 years of sponsored development to get a working > IronPython 3.6. What is the current state of IronPython 3? The website is very uninformative (there's a 4 year old blog post saying "we started a repository", but that's it). The repository gets commits every now and then (so it's obviously not dead yet), but neither the readme nor the wiki give a hint beyond "not ready yet". hp --=20 _ | 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 --prnws536gtytpj5v Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAlsuAsMACgkQ8g5IURL+ KF3tZRAArjij8tON0JDZA9HW2eC3hjLEQVR5xk8qvsKOsuLfSZ4vpzF9DyAq+mSy R+poIBfJwQglBeHs3yMOhxzsynZHD8sdoO6BtdAAZHNlgl8aCAzRQqxxJxOSi9RY A0VfL1IGt8M7FiT//nttpxGKknSaDVNy37H/fPSertJOD7QIvh7OjOD1wpnfFpg7 JO4B5Q1R4J2HBVwqszcsJgoBJtQLTKg4peZVqyLrKZeF6nr8YyPmtx4pHLGLYTtX gH1K25dERjWpv0soISd0GI6aCJvr7Pmm6OmxNK8Qw+wB1maDxAkI/tVCs3HZRIsf q6BW+mWC/WCmNJg+A8QenC8ISp/pBhOaM3WIln0g/FcWEfOOwut9vnQJcyLrFYYW GXTHhVpJQm5KwcfTTEXh5Czorr6bfIa9IvTOnhZukgRdc0lSDT2JMykmeo97bS9M rC6GJqk0qVEVw66+M0vbVmaKbzugqH0rsYSGoHiTaAYFyFuq5T+G8etl8phGmpXN sRw9jRzBj5eoA3toYK4XDRB7hm8JzQjCxJdSjoP3hgmqa7jmozor70pm22nUy8ql e7ZE9E3cuUyKLe1zAfZ07W8dUo1WcNB9h0zedR53jx29m5W/ouixGZ1VhQN6DcRY XUYAR66l1Xk4AZxXrKWmYAfxlC2PION/oHykev2nR5sCgFrF1Xw= =dC9K -----END PGP SIGNATURE----- --prnws536gtytpj5v-- --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From peter.j..holzer at 1 Sat Jun 23 11:20:24 2018 From: peter.j..holzer at 1 (Peter J. Holzer) Date: Sat, 23 Jun 2018 10:20:24 -0500 Subject: ironpython not support py3.6 Message-ID: <5B324678.21108.uclanpyth@castlerockbbs.com> From: "Peter J. Holzer" From: "Peter J. Holzer" --prnws536gtytpj5v Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2018-06-22 17:20:29 -0700, denis.akhiyarov at gmail.com wrote: > Either wait for IronPython 3.6, use COM interop, pythonnet, > subprocess, or things like gRPC. Based on PyPy experience, it is > probably 1-2 years of sponsored development to get a working > IronPython 3.6. What is the current state of IronPython 3? The website is very uninformative (there's a 4 year old blog post saying "we started a repository", but that's it). The repository gets commits every now and then (so it's obviously not dead yet), but neither the readme nor the wiki give a hint beyond "not ready yet". hp --=20 _ | 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 --prnws536gtytpj5v Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAlsuAsMACgkQ8g5IURL+ KF3tZRAArjij8tON0JDZA9HW2eC3hjLEQVR5xk8qvsKOsuLfSZ4vpzF9DyAq+mSy R+poIBfJwQglBeHs3yMOhxzsynZHD8sdoO6BtdAAZHNlgl8aCAzRQqxxJxOSi9RY A0VfL1IGt8M7FiT//nttpxGKknSaDVNy37H/fPSertJOD7QIvh7OjOD1wpnfFpg7 JO4B5Q1R4J2HBVwqszcsJgoBJtQLTKg4peZVqyLrKZeF6nr8YyPmtx4pHLGLYTtX gH1K25dERjWpv0soISd0GI6aCJvr7Pmm6OmxNK8Qw+wB1maDxAkI/tVCs3HZRIsf q6BW+mWC/WCmNJg+A8QenC8ISp/pBhOaM3WIln0g/FcWEfOOwut9vnQJcyLrFYYW GXTHhVpJQm5KwcfTTEXh5Czorr6bfIa9IvTOnhZukgRdc0lSDT2JMykmeo97bS9M rC6GJqk0qVEVw66+M0vbVmaKbzugqH0rsYSGoHiTaAYFyFuq5T+G8etl8phGmpXN sRw9jRzBj5eoA3toYK4XDRB7hm8JzQjCxJdSjoP3hgmqa7jmozor70pm22nUy8ql e7ZE9E3cuUyKLe1zAfZ07W8dUo1WcNB9h0zedR53jx29m5W/ouixGZ1VhQN6DcRY XUYAR66l1Xk4AZxXrKWmYAfxlC2PION/oHykev2nR5sCgFrF1Xw= =dC9K -----END PGP SIGNATURE----- --prnws536gtytpj5v-- -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steve+comp.lang.python at pearwood.info Sat Jun 23 11:27:57 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 23 Jun 2018 15:27:57 +0000 (UTC) Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <87h8ltiubl.fsf@elektro.pacujo.net> <8318150e-1f3c-eb97-d25c-475bddc6e223@Damon-Family.org> <87d0whirgc.fsf@elektro.pacujo.net> Message-ID: On Sat, 23 Jun 2018 09:42:29 -0400, Richard Damon wrote: > On 6/23/18 9:05 AM, Marko Rauhamaa wrote: >> Ok. Here's a value for you: >> >> 100? >> >> I see '1', '0', '0', '?'. What do you see in your locale (LC_MONETARY)? > > If I processed that on my system I would either get $100, or an error of > wrong currency symbol depending on the error checking. Then your system is so unbelievably broken that it should be nuked from orbit, just to be sure. The data you were given was 100 Euros. If your system is incapable of reading that as 100 Euros, and errors out, then at least to know that it is brain-damaged and useless. But if instead it silently changes the data to $100 (US dollars? Australian dollars? Zimbabwe dollars? the gods only know what a system that broken might do...) then it is not only broken but *dangerously* broken. [...] > Locale predates UCS-2, it was the early attempt to provide > internationalization to C code so even programmers who didn't think > about it could add the line setlocale(LC_ALL, "") and make their code > work at least mostly right in more places. A single global was quick and > simple, and since threads didn't exist, not an issue. Threads were first used in 1967, five years before C even existed. https://en.wikipedia.org/wiki/Thread_%28computing%29#History -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sat Jun 23 11:44:14 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 23 Jun 2018 15:44:14 +0000 (UTC) Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> Message-ID: On Sat, 23 Jun 2018 08:12:52 -0400, Richard Damon wrote: > On 6/23/18 7:46 AM, Steven D'Aprano wrote: >> On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote: >> >>> If you know the Locale, then you do know what the decimal separator >>> is, as that is part of what a locale defines. >> A locale defines a set of common cultural conventions. It doesn't >> mandate the actual conventions in use in any specific document. >> >> If I'm in Australia, using the en-AU locale, nevertheless I can >> generate a file using , as a decimal separator. Try and stop me :-) > > yes, you can MIS-use the en-AU locale and write 1,000 to mean the number > One, just as you can misuse the language and write cat when you mean a > member of the Canine group, How about if I write "le chien" or "der Hund" or "??????"? Is that also a misuse of the locale because I choose to write in a foreign language, using foreign conventions for spelling, grammar and syntax? > but then the misinterpretation is on the > creator of the document, not on the program that was told how the > document is to be read. You're assuming that there will be a misinterpretation. That's an absurd assumption to make. There might be, of course, but the documentation for my document might be clear that comma is to be used for decimal separators. Or it might include numbers like 1.234.567,012345678 which is understandable to anyone who is aware of the possibility that comma may mean decimal separator and period the thousands separator. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From Richard at Damon-Family.org Sat Jun 23 12:11:34 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 23 Jun 2018 12:11:34 -0400 Subject: translating foreign data In-Reply-To: <20180623140549.3vun765hyvax2fe5@hjp.at> References: <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <20180623122830.s3y7k7642h2hixc2@hjp.at> <4ab18727-b47d-8fb3-3ed5-2ae4c8e6d123@Damon-Family.org> <20180623140549.3vun765hyvax2fe5@hjp.at> Message-ID: On 6/23/18 10:05 AM, Peter J. Holzer wrote: > On 2018-06-23 08:41:38 -0400, Richard Damon wrote: >> On 6/23/18 8:28 AM, Peter J. Holzer wrote: >>> On 2018-06-23 08:12:52 -0400, Richard Damon wrote: >>>> On 6/23/18 7:46 AM, Steven D'Aprano wrote: >>>>> If I'm in Australia, using the en-AU locale, nevertheless I can generate >>>>> a file using , as a decimal separator. Try and stop me :-) >>>> yes, you can MIS-use the en-AU locale and write 1,000 to mean the number >>>> One, just as you can misuse the language and write cat when you mean a >>>> member of the Canine group, but then the misinterpretation is on the >>>> creator of the document, not on the program that was told how the >>>> document is to be read. >>> How would he mis-use the en-AU locale to write 1 as "1,000"? I think >>> to do that he would simply NOT use the locale. >> Once you open the Locale can of worms, EVERYTHING has a locale, to say >> you aren't using a locale is to say you are writing >> something unintelligible, as you can thing of the locale as the set of >> rules to interpret > I don't think that's a useful way to look at it. "Locale" in > (non-technical) English means "place" or "site". The idea behind the > locale concept is that some conventions (e.g. how to write numbers or > how to write strings) depend on the place where the program runs (or > maybe where the user is sitting or grew up or maybe where a file was > produced). > > For stuff which doesn't depend on the place (e.g. how a Python program > should be parsed), the locale concept doesn't apply. > The Locale should NOT be the place the computer is running in (at least not anymore), but where the data and the user are from (which can be different). Do your really mean that when I travel to a place that uses . as the thousands separator and , as the decimal separator (instead of my normal environment when they are the other way around) all my programs should immediately change how they read all my data files and how I need to enter data? I hope not. I want my computer to use the Locale of where "I" came from (not current am) to talk to me, and to be able to set the Locale to interpret data to match the rules the person who generated them used to generate them, so if they swap . and , compared to me, I can tell the program that. Your last parenthetical comment in the first paragraph is my key point, the locale used to read data should match the locale used to generate it, and that can easily be different than the locale being used to interact with the user. If a program doesn't care about the locale it is running in, like a Python compiler, the either it needs to use routines that totally ignore the locale or it needs to set the locale to one that matches the rules it wants. -- Richard Damon From Richard at Damon-Family.org Sat Jun 23 12:41:33 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 23 Jun 2018 12:41:33 -0400 Subject: translating foreign data In-Reply-To: References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> Message-ID: <0c89025f-54ae-03d1-3013-2febbbf3e149@Damon-Family.org> On 6/23/18 11:44 AM, Steven D'Aprano wrote: > On Sat, 23 Jun 2018 08:12:52 -0400, Richard Damon wrote: > >> On 6/23/18 7:46 AM, Steven D'Aprano wrote: >>> On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote: >>> >>>> If you know the Locale, then you do know what the decimal separator >>>> is, as that is part of what a locale defines. >>> A locale defines a set of common cultural conventions. It doesn't >>> mandate the actual conventions in use in any specific document. >>> >>> If I'm in Australia, using the en-AU locale, nevertheless I can >>> generate a file using , as a decimal separator. Try and stop me :-) >> yes, you can MIS-use the en-AU locale and write 1,000 to mean the number >> One, just as you can misuse the language and write cat when you mean a >> member of the Canine group, > How about if I write "le chien" or "der Hund" or "??????"? Is that also a > misuse of the locale because I choose to write in a foreign language, > using foreign conventions for spelling, grammar and syntax? > > >> but then the misinterpretation is on the >> creator of the document, not on the program that was told how the >> document is to be read. > You're assuming that there will be a misinterpretation. That's an absurd > assumption to make. There might be, of course, but the documentation for > my document might be clear that comma is to be used for decimal > separators. Or it might include numbers like > > 1.234.567,012345678 > > which is understandable to anyone who is aware of the possibility that > comma may mean decimal separator and period the thousands separator. > Then I shouldn't be using en-AU to decode the file. If I use a locale based parser, I need to give it the right locale. Now, if I have a parser that doesn't use the locale, but some other rule base than I just need to provide it with the right rules, which is basically just defining the right locale. -- Richard Damon From bc at freeuk.com Sat Jun 23 12:43:57 2018 From: bc at freeuk.com (Bart) Date: Sat, 23 Jun 2018 17:43:57 +0100 Subject: Static variables [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> Message-ID: <0NuXC.658628$oo.172787@fx35.am4> On 23/06/2018 14:32, Stefan Ram wrote: > ram at zedat.fu-berlin.de (Stefan Ram) writes: >> def f(): >> def g(): >> g.x += 1 >> return g.x >> g.x = 0 >> return g > > Or, "for all g to share the same x": > > main.py > > def f(): > def g(): > f.x += 1 > return f.x > return g > f.x = 0 OK, problem solved: we just use attributes of function objects rather than locally static variables (I didn't even know that was possible). These apparently can be created, accessed and modified from anywhere in the program. The only provisos are that functions with 'static' must be written as nested functions and the name of the function must be returned via the enclosing function in some setup code. The initialising of the static is showed as happening in global space in your example, but may be possible to move that to the enclosing function. (For example, when the static data is a local table.) However, here's a reminder of what the feature looks like implemented properly: def g() static x = 0 x += 1 return x print (g()) No set up of g needed. 'static' can be added to any existing function without changing how its used. And it can be removed without having to dismantled all the extra machinery. /And/ the access to x inside g() can be a fast local lookup not an attribute lookup (unless implemented on top of global variables). -- bart From steven.d'aprano at 1 Sat Jun 23 12:46:22 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sat, 23 Jun 2018 11:46:22 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20893.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote: > If you know the Locale, then you do know what the decimal separator is, > as that is part of what a locale defines. A locale defines a set of common cultural conventions. It doesn't mandate the actual conventions in use in any specific document. If I'm in Australia, using the en-AU locale, nevertheless I can generate a file using , as a decimal separator. Try and stop me :-) But your point is taken -- I misread Ethan saying that he knew the locale and it wasn't helping, when in fact he was reluctant to change the locale as that's a process-wide global change. > The issue is that if you just > know the encoding, you don't necessarily know the locale. He also > commented that he didn't want to set the locale in the routine, as that > sets it globally for the full application (but perhaps that latter could > be fixed by first doing a locale.getlocale(), then setlocale for the > files locale, and then at the end of reading and processing restore back > the old locale. Indeed. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sat Jun 23 12:46:22 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sat, 23 Jun 2018 11:46:22 -0500 Subject: translating foreign data Message-ID: <5B324678.21113.uclanpyth@castlerockbbs.com> From: "Steven D'Aprano" From: Steven D'Aprano On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote: > If you know the Locale, then you do know what the decimal separator is, > as that is part of what a locale defines. A locale defines a set of common cultural conventions. It doesn't mandate the actual conventions in use in any specific document. If I'm in Australia, using the en-AU locale, nevertheless I can generate a file using , as a decimal separator. Try and stop me :-) But your point is taken -- I misread Ethan saying that he knew the locale and it wasn't helping, when in fact he was reluctant to change the locale as that's a process-wide global change. > The issue is that if you just > know the encoding, you don't necessarily know the locale. He also > commented that he didn't want to set the locale in the routine, as that > sets it globally for the full application (but perhaps that latter could > be fixed by first doing a locale.getlocale(), then setlocale for the > files locale, and then at the end of reading and processing restore back > the old locale. Indeed. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From dennis.lee.bieber at 1 Sat Jun 23 12:57:00 2018 From: dennis.lee.bieber at 1 (Dennis Lee Bieber) Date: Sat, 23 Jun 2018 11:57:00 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20917.uclanpyth@castlerockbbs.com> From: Dennis Lee Bieber On Sat, 23 Jun 2018 15:44:14 +0000 (UTC), Steven D'Aprano declaimed the following: > 1.234.567,012345678 > >which is understandable to anyone who is aware of the possibility that >comma may mean decimal separator and period the thousands separator. > Or it is an oddly marked local (7-digit) telephone number (though typically for US, a leading "1" implies long-distance and should be followed by a 10-digit phone number) followed by a 9-digit (US) postal zip-code. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From richard.damon at 1 Sat Jun 23 13:11:34 2018 From: richard.damon at 1 (Richard Damon) Date: Sat, 23 Jun 2018 12:11:34 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20918.uclanpyth@castlerockbbs.com> From: Richard Damon On 6/23/18 10:05 AM, Peter J. Holzer wrote: > On 2018-06-23 08:41:38 -0400, Richard Damon wrote: >> On 6/23/18 8:28 AM, Peter J. Holzer wrote: >>> On 2018-06-23 08:12:52 -0400, Richard Damon wrote: >>>> On 6/23/18 7:46 AM, Steven D'Aprano wrote: >>>>> If I'm in Australia, using the en-AU locale, nevertheless I can generate >>>>> a file using , as a decimal separator. Try and stop me :-) >>>> yes, you can MIS-use the en-AU locale and write 1,000 to mean the number >>>> One, just as you can misuse the language and write cat when you mean a >>>> member of the Canine group, but then the misinterpretation is on the >>>> creator of the document, not on the program that was told how the >>>> document is to be read. >>> How would he mis-use the en-AU locale to write 1 as "1,000"? I think >>> to do that he would simply NOT use the locale. >> Once you open the Locale can of worms, EVERYTHING has a locale, to say >> you aren't using a locale is to say you are writing >> something unintelligible, as you can thing of the locale as the set of >> rules to interpret > I don't think that's a useful way to look at it. "Locale" in > (non-technical) English means "place" or "site". The idea behind the > locale concept is that some conventions (e.g. how to write numbers or > how to write strings) depend on the place where the program runs (or > maybe where the user is sitting or grew up or maybe where a file was > produced). > > For stuff which doesn't depend on the place (e.g. how a Python program > should be parsed), the locale concept doesn't apply. > The Locale should NOT be the place the computer is running in (at least not anymore), but where the data and the user are from (which can be different). Do your really mean that when I travel to a place that uses . as the thousands separator and , as the decimal separator (instead of my normal environment when they are the other way around) all my programs should immediately change how they read all my data files and how I need to enter data? I hope not. I want my computer to use the Locale of where "I" came from (not current am) to talk to me, and to be able to set the Locale to interpret data to match the rules the person who generated them used to generate them, so if they swap . and , compared to me, I can tell the program that. Your last parenthetical comment in the first paragraph is my key point, the locale used to read data should match the locale used to generate it, and that can easily be different than the locale being used to interact with the user. If a program doesn't care about the locale it is running in, like a Python compiler, the either it needs to use routines that totally ignore the locale or it needs to set the locale to one that matches the rules it wants. -- Richard Damon --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From python at mrabarnett.plus.com Sat Jun 23 13:29:51 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 23 Jun 2018 18:29:51 +0100 Subject: Static variables [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: <2113d8c5-ee00-d073-1bfd-5bde34d64235@mrabarnett.plus.com> On 2018-06-23 05:16, Chris Angelico wrote: > On Sat, Jun 23, 2018 at 1:51 PM, Steven D'Aprano > wrote: >> On Wed, 20 Jun 2018 14:18:19 +1000, Chris Angelico wrote: >> >>> Ah. Yeah, that would be a plausible feature to add to Python. But in C, >>> a static variable is basically the same thing as a global variable, >>> except that its name is scoped to the function. There is only one of it. >>> What happens in Python? For instance: >>> >>> def f(): >>> def g(): >>> static x = 0 >>> x += 1 >>> return x >>> return g >>> >>> Does the static variable exist once for each instance of g()? If so, >>> it'll behave like a closure variable; if not, it'll behave like a >>> global. Either way, I'm pretty much certain that people will expect the >>> other. >> >> Yes, but given the normal execution model of Python, only one solution is >> valid. Since the function g is created fresh each time f is called, each >> one gets a fresh static x. >> >> If you want all the g's to share the same x, you would write: >> >> def f(): >> static x = 0 >> def g(): >> x += 1 >> return x >> return g >> >> >> In this case, every invocation of f shares the same static x, and all the >> g's refer to that same x, using the ordinary closure mechanism. In the >> earlier case, each invocation of f creates a brand new g with its own x. >> >> Simple and elegant. >> >> This could at last get rid of that useful but ugly idiom: >> >> def function(real, arguments, len=len, int=int, str=str): >> ... >> >> if we allowed the "static" declaration to access the values from the >> surrounding scope: >> >> def function(real, arguments): >> static len=len, int=int, str=str >> >> But I think nicer than that would be a decorator: >> >> @static(len=len, int=int, str=str) >> def function(real, arguments): >> ... >> >> which adds local variables len, int, str to the function, with the given >> values, and transforms all the bytecode LOAD_NAME len to LOAD_FAST len >> (or whatever). >> >> (We might need a new bytecode to SET_STATIC.) >> >> That would be a nice bytecode hack to prove the usefulness of the concept! >> > > Okay, that makes sense. So in a way, static variables would be like > closure variables with an invisible outer function. These would be > roughly equivalent: > > def f(): > static x = 0 > x += 1 > return x > You can already do something similar like this: def f(): f.x += 1 return f.x f.x = 0 [snip] From richard.damon at 1 Sat Jun 23 13:41:32 2018 From: richard.damon at 1 (Richard Damon) Date: Sat, 23 Jun 2018 12:41:32 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20926.uclanpyth@castlerockbbs.com> From: Richard Damon On 6/23/18 11:44 AM, Steven D'Aprano wrote: > On Sat, 23 Jun 2018 08:12:52 -0400, Richard Damon wrote: > >> On 6/23/18 7:46 AM, Steven D'Aprano wrote: >>> On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote: >>> >>>> If you know the Locale, then you do know what the decimal separator >>>> is, as that is part of what a locale defines. >>> A locale defines a set of common cultural conventions. It doesn't >>> mandate the actual conventions in use in any specific document. >>> >>> If I'm in Australia, using the en-AU locale, nevertheless I can >>> generate a file using , as a decimal separator. Try and stop me :-) >> yes, you can MIS-use the en-AU locale and write 1,000 to mean the number >> One, just as you can misuse the language and write cat when you mean a >> member of the Canine group, > How about if I write "le chien" or "der Hund" or "??D1D?D?D?D?"? Is that also a > misuse of the locale because I choose to write in a foreign language, > using foreign conventions for spelling, grammar and syntax? > > >> but then the misinterpretation is on the >> creator of the document, not on the program that was told how the >> document is to be read. > You're assuming that there will be a misinterpretation. That's an absurd > assumption to make. There might be, of course, but the documentation for > my document might be clear that comma is to be used for decimal > separators. Or it might include numbers like > > 1.234.567,012345678 > > which is understandable to anyone who is aware of the possibility that > comma may mean decimal separator and period the thousands separator. > Then I shouldn't be using en-AU to decode the file. If I use a locale based parser, I need to give it the right locale. Now, if I have a parser that doesn't use the locale, but some other rule base than I just need to provide it with the right rules, which is basically just defining the right locale. -- Richard Damon --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From hjp-python at hjp.at Sat Jun 23 14:09:08 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 23 Jun 2018 20:09:08 +0200 Subject: translating foreign data In-Reply-To: References: <8736xesksk.fsf@bsb.me.uk> <20180623122830.s3y7k7642h2hixc2@hjp.at> <4ab18727-b47d-8fb3-3ed5-2ae4c8e6d123@Damon-Family.org> <20180623140549.3vun765hyvax2fe5@hjp.at> Message-ID: <20180623180908.wdqbgevqvvcf2bk3@hjp.at> On 2018-06-23 12:11:34 -0400, Richard Damon wrote: > On 6/23/18 10:05 AM, Peter J. Holzer wrote: > > On 2018-06-23 08:41:38 -0400, Richard Damon wrote: > >> Once you open the Locale can of worms, EVERYTHING has a locale, to say > >> you aren't using a locale is to say you are writing > >> something unintelligible, as you can thing of the locale as the set of > >> rules to interpret > > I don't think that's a useful way to look at it. "Locale" in > > (non-technical) English means "place" or "site". The idea behind the > > locale concept is that some conventions (e.g. how to write numbers or > > how to write strings) depend on the place where the program runs (or > > maybe where the user is sitting or grew up or maybe where a file was > > produced). > > > > For stuff which doesn't depend on the place (e.g. how a Python program > > should be parsed), the locale concept doesn't apply. > > > The Locale should NOT be the place the computer is running in (at least > not anymore), but where the data and the user are from (which can be > different). Yes, it can be different, but for some *very* common cases (PCs, smartphones most of the time) it isn't. More imporantly for the concept, when the concept was developed (in the late 1980's) is was very common (probably more common than 10 years earlier). > Do your really mean that when I travel to a place that uses > . as the thousands separator and , as the decimal separator (instead of > my normal environment when they are the other way around) all my > programs should immediately change how they read all my data files and > how I need to enter data? I hope not. Sometimes, yes. If you want to work with your colleagues at that place they might thank you to use the local conventions. > I want my computer to use the Locale of where "I" came from (not > current am) to talk to me, That's why I wrote "or grew up". > and to be able to set the Locale to interpret data to match the rules > the person who generated them used to generate them, And that's why I wrote "where a file was produced". So many words to repeat what I already wrote ... > so if they swap . and , compared to me, I can tell the program that. > Your last parenthetical comment in the first paragraph is my key > point, I think it is the weakest point. The locale is useful for interactive use (input and output) and also for output intended for human users. For parsing files it is woefully inadequate (also for generating files intended to be parsed). > the locale used to read data should match the locale used to generate > it, and that can easily be different than the locale being used to > interact with the user. Which is basically why "locale" is a rather useless concept with files. When I get a CSV file, I don't want to say "use locale en_US.cp437", because the location "US" is almost completely irrelevant, the language "English" is somewhat relevant but much too specific", and the list separator isn't there at all. I want to tell it: Decode using CP437, a decimal point, tabs as a list separator, CRLF as the record separator, no quoting. > If a program doesn't care about the locale it is running in, like a > Python compiler, the either it needs to use routines that totally ignore > the locale or it needs to set the locale to one that matches the rules > it wants. The former. Because locales are in general opaque, so you can never be sure that a given locale will use the rules you want ("C" is the exception, but not very useful). 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 hjp-python at hjp.at Sat Jun 23 14:12:31 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 23 Jun 2018 20:12:31 +0200 Subject: translating foreign data In-Reply-To: <0c89025f-54ae-03d1-3013-2febbbf3e149@Damon-Family.org> References: <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <0c89025f-54ae-03d1-3013-2febbbf3e149@Damon-Family.org> Message-ID: <20180623181231.3seof6gjrgqoszlu@hjp.at> On 2018-06-23 12:41:33 -0400, Richard Damon wrote: > On 6/23/18 11:44 AM, Steven D'Aprano wrote: > > You're assuming that there will be a misinterpretation. That's an absurd > > assumption to make. There might be, of course, but the documentation for > > my document might be clear that comma is to be used for decimal > > separators. Or it might include numbers like > > > > 1.234.567,012345678 > > > > which is understandable to anyone who is aware of the possibility that > > comma may mean decimal separator and period the thousands separator. > > > Then I shouldn't be using en-AU to decode the file. Quite right, You shouldn't. > Now, if I have a parser that doesn't use the locale, but some other rule > base than I just need to provide it with the right rules, which is > basically just defining the right locale. Nope. The right rules for almost any file format are much more than the locale. 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 stefan.ram at 1 Sat Jun 23 14:29:24 2018 From: stefan.ram at 1 (Stefan Ram) Date: Sat, 23 Jun 2018 13:29:24 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B2FCDF9.20884.uclanpyth@castlerockbbs.com> References: <5B2FCDF9.20884.uclanpyth@castlerockbbs.com> Message-ID: <5B2FCDF9.20907.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: ram at zedat.fu-berlin.de (Stefan Ram) Steven D'Aprano writes: >def f(): > static x = 0 > def g(): > x += 1 > return x > return g What one can do today: main.py def g(): g.x += 1 return g.x g.x = 0 print( g() ) print( g() ) print( g() ) transcript 1 2 3 main.py def f(): def g(): g.x += 1 return g.x g.x = 0 return g g = f() print( g() ) print( g() ) print( g() ) transcript 1 2 3 --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From stefan.ram at 1 Sat Jun 23 14:29:24 2018 From: stefan.ram at 1 (Stefan Ram) Date: Sat, 23 Jun 2018 13:29:24 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B324678.21104.uclanpyth@castlerockbbs.com> References: <5B324678.21104.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21122.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: "Stefan Ram" To: Steven D'Aprano From: ram at zedat.fu-berlin.de (Stefan Ram) Steven D'Aprano writes: >def f(): > static x = 0 > def g(): > x += 1 > return x > return g What one can do today: main.py def g(): g.x += 1 return g.x g.x = 0 print( g() ) print( g() ) print( g() ) transcript 1 2 3 main.py def f(): def g(): g.x += 1 return g.x g.x = 0 return g g = f() print( g() ) print( g() ) print( g() ) transcript 1 2 3 -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From stefan.ram at 1 Sat Jun 23 14:32:26 2018 From: stefan.ram at 1 (Stefan Ram) Date: Sat, 23 Jun 2018 13:32:26 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B2FCDF9.20907.uclanpyth@castlerockbbs.com> References: <5B2FCDF9.20907.uclanpyth@castlerockbbs.com> Message-ID: <5B2FCDF9.20908.uclanpyth@castlerockbbs.com> To: Stefan Ram From: ram at zedat.fu-berlin.de (Stefan Ram) ram at zedat.fu-berlin.de (Stefan Ram) writes: >def f(): > def g(): > g.x += 1 > return g.x > g.x = 0 > return g Or, "for all g to share the same x": main.py def f(): def g(): f.x += 1 return f.x return g f.x = 0 g = f() print( g() ) print( g() ) print( g() ) g1 = f() print( g1() ) print( g1() ) print( g1() ) transcript 1 2 3 4 5 6 --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From stefan.ram at 1 Sat Jun 23 14:32:26 2018 From: stefan.ram at 1 (Stefan Ram) Date: Sat, 23 Jun 2018 13:32:26 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B324678.21122.uclanpyth@castlerockbbs.com> References: <5B324678.21122.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21123.uclanpyth@castlerockbbs.com> To: Stefan Ram From: "Stefan Ram" To: Stefan Ram From: ram at zedat.fu-berlin.de (Stefan Ram) ram at zedat.fu-berlin.de (Stefan Ram) writes: >def f(): > def g(): > g.x += 1 > return g.x > g.x = 0 > return g Or, "for all g to share the same x": main.py def f(): def g(): f.x += 1 return f.x return g f.x = 0 g = f() print( g() ) print( g() ) print( g() ) g1 = f() print( g1() ) print( g1() ) print( g1() ) transcript 1 2 3 4 5 6 -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bart at 1 Sat Jun 23 14:41:58 2018 From: bart at 1 (Bart) Date: Sat, 23 Jun 2018 13:41:58 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B2FCDF9.20884.uclanpyth@castlerockbbs.com> References: <5B2FCDF9.20884.uclanpyth@castlerockbbs.com> Message-ID: <5B2FCDF9.20903.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: Bart On 23/06/2018 04:51, Steven D'Aprano wrote: > On Wed, 20 Jun 2018 14:18:19 +1000, Chris Angelico wrote: > >> Ah. Yeah, that would be a plausible feature to add to Python. But in C, >> a static variable is basically the same thing as a global variable, >> except that its name is scoped to the function. There is only one of it. >> What happens in Python? For instance: >> >> def f(): >> def g(): >> static x = 0 >> x += 1 >> return x >> return g >> >> Does the static variable exist once for each instance of g()? If so, >> it'll behave like a closure variable; if not, it'll behave like a >> global. Either way, I'm pretty much certain that people will expect the >> other. > > Yes, but given the normal execution model of Python, only one solution is > valid. Since the function g is created fresh each time f is called, each > one gets a fresh static x. > > If you want all the g's to share the same x, you would write: > > def f(): > static x = 0 > def g(): > x += 1 > return x > return g > > > In this case, every invocation of f shares the same static x, and all the > g's refer to that same x, using the ordinary closure mechanism. In the > earlier case, each invocation of f creates a brand new g with its own x. > > Simple and elegant. > > This could at last get rid of that useful but ugly idiom: > > def function(real, arguments, len=len, int=int, str=str): > ... > > if we allowed the "static" declaration to access the values from the > surrounding scope: > > def function(real, arguments): > static len=len, int=int, str=str > > But I think nicer than that would be a decorator: > > @static(len=len, int=int, str=str) > def function(real, arguments): > ... > > which adds local variables len, int, str to the function, with the given > values, and transforms all the bytecode LOAD_NAME len to LOAD_FAST len > (or whatever). > > (We might need a new bytecode to SET_STATIC.) > > That would be a nice bytecode hack to prove the usefulness of the concept! This is an example of a simple concept getting so out of hand that it will either never be implemented, or the resulting implementation becomes impractical to use. This is what we're trying to do: def nextx(): static x = 0 x += 1 return x And this is the simplest equivalent code in current Python that will cater for 99% of uses: _nextx_x = 0 def nextx(): global _nextx_x _nextx_x += 1 return _nextx_x No nested functions. No generating new instances of functions complete with a new set of statics each time you happen to refer to the name. (Which sounds to me as useful as creating a new instance of an import when you copy its name, complete with a separate set of its globals. Isn't this stuff what classes are for?) (At what point would that happen anyway; if you do this: g = nextx # hypothetical version would static it will create a new instance of 'nextx'. But it won't create one here, just before () is applied: nextx() # ? Or how about here: listoffunctions = (nextx1, nextx2, nextx3) listoffunctions[i]() # ? ) -- bartc --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bart at 1 Sat Jun 23 14:41:58 2018 From: bart at 1 (Bart) Date: Sat, 23 Jun 2018 13:41:58 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B324678.21104.uclanpyth@castlerockbbs.com> References: <5B324678.21104.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21120.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: "Bart" To: Steven D'Aprano From: Bart On 23/06/2018 04:51, Steven D'Aprano wrote: > On Wed, 20 Jun 2018 14:18:19 +1000, Chris Angelico wrote: > >> Ah. Yeah, that would be a plausible feature to add to Python. But in C, >> a static variable is basically the same thing as a global variable, >> except that its name is scoped to the function. There is only one of it. >> What happens in Python? For instance: >> >> def f(): >> def g(): >> static x = 0 >> x += 1 >> return x >> return g >> >> Does the static variable exist once for each instance of g()? If so, >> it'll behave like a closure variable; if not, it'll behave like a >> global. Either way, I'm pretty much certain that people will expect the >> other. > > Yes, but given the normal execution model of Python, only one solution is > valid. Since the function g is created fresh each time f is called, each > one gets a fresh static x. > > If you want all the g's to share the same x, you would write: > > def f(): > static x = 0 > def g(): > x += 1 > return x > return g > > > In this case, every invocation of f shares the same static x, and all the > g's refer to that same x, using the ordinary closure mechanism. In the > earlier case, each invocation of f creates a brand new g with its own x. > > Simple and elegant. > > This could at last get rid of that useful but ugly idiom: > > def function(real, arguments, len=len, int=int, str=str): > ... > > if we allowed the "static" declaration to access the values from the > surrounding scope: > > def function(real, arguments): > static len=len, int=int, str=str > > But I think nicer than that would be a decorator: > > @static(len=len, int=int, str=str) > def function(real, arguments): > ... > > which adds local variables len, int, str to the function, with the given > values, and transforms all the bytecode LOAD_NAME len to LOAD_FAST len > (or whatever). > > (We might need a new bytecode to SET_STATIC.) > > That would be a nice bytecode hack to prove the usefulness of the concept! This is an example of a simple concept getting so out of hand that it will either never be implemented, or the resulting implementation becomes impractical to use. This is what we're trying to do: def nextx(): static x = 0 x += 1 return x And this is the simplest equivalent code in current Python that will cater for 99% of uses: _nextx_x = 0 def nextx(): global _nextx_x _nextx_x += 1 return _nextx_x No nested functions. No generating new instances of functions complete with a new set of statics each time you happen to refer to the name. (Which sounds to me as useful as creating a new instance of an import when you copy its name, complete with a separate set of its globals. Isn't this stuff what classes are for?) (At what point would that happen anyway; if you do this: g = nextx # hypothetical version would static it will create a new instance of 'nextx'. But it won't create one here, just before () is applied: nextx() # ? Or how about here: listoffunctions = (nextx1, nextx2, nextx3) listoffunctions[i]() # ? ) -- bartc -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From ed.kellett at 1 Sat Jun 23 15:08:22 2018 From: ed.kellett at 1 (Ed Kellett) Date: Sat, 23 Jun 2018 14:08:22 -0500 Subject: Static variables [was Re: syntax difference] Message-ID: <5B2FCDF9.20906.uclanpyth@castlerockbbs.com> From: Ed Kellett This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --Xw5fa1GFtucLPGBT1sLtLtUpmbraGkiYl Content-Type: multipart/mixed; boundary="lDyl22ZCUIEM3fl5YMnfJ3B8O9bwBCY9r"; protected-headers="v1" From: Ed Kellett To: python-list at python.org Message-ID: <98ecd8c1-13b7-8317-8177-6a35921712ff at kellett.im> Subject: Re: Static variables [was Re: syntax difference] References: <72edc16a-69e0-41a2-bec3-290083f6e6ec at googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707 at gmail.com> <6eUVC.491716$Qg7.378011 at fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c at googlegroups.com> In-Reply-To: --lDyl22ZCUIEM3fl5YMnfJ3B8O9bwBCY9r Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 2018-06-23 06:21, Chris Angelico wrote: > Let's start finding all the edge cases that don't work, so I can work > on fixing them :) Very long functions (or, more specifically, functions with a very large number of consts) will likely prove annoying. --lDyl22ZCUIEM3fl5YMnfJ3B8O9bwBCY9r-- --Xw5fa1GFtucLPGBT1sLtLtUpmbraGkiYl Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEECzNSP7n340AYaHPmcC7hJ3E8yBAFAlsuRkYACgkQcC7hJ3E8 yBBYbQf/fqEhdZWJoA/1Zq2x9dV0LgDTTAU0T8ze6jjMoq/Wxj/kzovLSgWODD8u 63tJgR9c2twEVdfILiWmgKD1BSzyLGXN/LOEjieFu62tqYVfDJOf6g0/pBzG5Ih3 rsGt9e1tx8S60xUR7pnEtbSrMtKruclUaUQQXnpJG4mHKwaLKgpQDSknTKyHzOec ulf+iQxWb5v9pG8fwsygdrKYsObKdQJrCUI3ggeDFYkSJK/sDBYitIlpSaHNNaV+ QZQFaf0j9ACLttVIhOJxWxnlxmbbNQ7P5Z4QdznI1y5xUnEIAgNKPTMjjgsb1h5Y Q8gx7MxYB6+reNHQNl7V2b5UxAWYwQ== =rmC2 -----END PGP SIGNATURE----- --Xw5fa1GFtucLPGBT1sLtLtUpmbraGkiYl-- --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From chris.angelico at 1 Sat Jun 23 15:16:58 2018 From: chris.angelico at 1 (Chris Angelico) Date: Sat, 23 Jun 2018 14:16:58 -0500 Subject: Static variables [was Re: syntax difference] Message-ID: <5B2FCDF9.20885.uclanpyth@castlerockbbs.com> From: Chris Angelico On Sat, Jun 23, 2018 at 1:51 PM, Steven D'Aprano wrote: > On Wed, 20 Jun 2018 14:18:19 +1000, Chris Angelico wrote: > >> Ah. Yeah, that would be a plausible feature to add to Python. But in C, >> a static variable is basically the same thing as a global variable, >> except that its name is scoped to the function. There is only one of it. >> What happens in Python? For instance: >> >> def f(): >> def g(): >> static x = 0 >> x += 1 >> return x >> return g >> >> Does the static variable exist once for each instance of g()? If so, >> it'll behave like a closure variable; if not, it'll behave like a >> global. Either way, I'm pretty much certain that people will expect the >> other. > > Yes, but given the normal execution model of Python, only one solution is > valid. Since the function g is created fresh each time f is called, each > one gets a fresh static x. > > If you want all the g's to share the same x, you would write: > > def f(): > static x = 0 > def g(): > x += 1 > return x > return g > > > In this case, every invocation of f shares the same static x, and all the > g's refer to that same x, using the ordinary closure mechanism. In the > earlier case, each invocation of f creates a brand new g with its own x. > > Simple and elegant. > > This could at last get rid of that useful but ugly idiom: > > def function(real, arguments, len=len, int=int, str=str): > ... > > if we allowed the "static" declaration to access the values from the > surrounding scope: > > def function(real, arguments): > static len=len, int=int, str=str > > But I think nicer than that would be a decorator: > > @static(len=len, int=int, str=str) > def function(real, arguments): > ... > > which adds local variables len, int, str to the function, with the given > values, and transforms all the bytecode LOAD_NAME len to LOAD_FAST len > (or whatever). > > (We might need a new bytecode to SET_STATIC.) > > That would be a nice bytecode hack to prove the usefulness of the concept! > Okay, that makes sense. So in a way, static variables would be like closure variables with an invisible outer function. These would be roughly equivalent: def f(): static x = 0 x += 1 return x def make_f(): x = 0 def f(): nonlocal x x += 1 return x return f f = make_f() I don't think LOAD_FAST is appropriate (those cells get disposed of when the function returns), but transforming those lookups into closure lookups would be a reasonable way to do it I think. For getting rid of the "len=len" trick, though, I would REALLY like to transform those into LOAD_CONST. That'd be a fun bytecode hack all on its own. In fact, I'm gonna have a shot at that. An "early bind these names" decorator. ChrisA --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From chris.angelico at 1 Sat Jun 23 15:16:58 2018 From: chris.angelico at 1 (Chris Angelico) Date: Sat, 23 Jun 2018 14:16:58 -0500 Subject: Static variables [was Re: syntax difference] Message-ID: <5B324678.21105.uclanpyth@castlerockbbs.com> From: "Chris Angelico" From: Chris Angelico On Sat, Jun 23, 2018 at 1:51 PM, Steven D'Aprano wrote: > On Wed, 20 Jun 2018 14:18:19 +1000, Chris Angelico wrote: > >> Ah. Yeah, that would be a plausible feature to add to Python. But in C, >> a static variable is basically the same thing as a global variable, >> except that its name is scoped to the function. There is only one of it. >> What happens in Python? For instance: >> >> def f(): >> def g(): >> static x = 0 >> x += 1 >> return x >> return g >> >> Does the static variable exist once for each instance of g()? If so, >> it'll behave like a closure variable; if not, it'll behave like a >> global. Either way, I'm pretty much certain that people will expect the >> other. > > Yes, but given the normal execution model of Python, only one solution is > valid. Since the function g is created fresh each time f is called, each > one gets a fresh static x. > > If you want all the g's to share the same x, you would write: > > def f(): > static x = 0 > def g(): > x += 1 > return x > return g > > > In this case, every invocation of f shares the same static x, and all the > g's refer to that same x, using the ordinary closure mechanism. In the > earlier case, each invocation of f creates a brand new g with its own x. > > Simple and elegant. > > This could at last get rid of that useful but ugly idiom: > > def function(real, arguments, len=len, int=int, str=str): > ... > > if we allowed the "static" declaration to access the values from the > surrounding scope: > > def function(real, arguments): > static len=len, int=int, str=str > > But I think nicer than that would be a decorator: > > @static(len=len, int=int, str=str) > def function(real, arguments): > ... > > which adds local variables len, int, str to the function, with the given > values, and transforms all the bytecode LOAD_NAME len to LOAD_FAST len > (or whatever). > > (We might need a new bytecode to SET_STATIC.) > > That would be a nice bytecode hack to prove the usefulness of the concept! > Okay, that makes sense. So in a way, static variables would be like closure variables with an invisible outer function. These would be roughly equivalent: def f(): static x = 0 x += 1 return x def make_f(): x = 0 def f(): nonlocal x x += 1 return x return f f = make_f() I don't think LOAD_FAST is appropriate (those cells get disposed of when the function returns), but transforming those lookups into closure lookups would be a reasonable way to do it I think. For getting rid of the "len=len" trick, though, I would REALLY like to transform those into LOAD_CONST. That'd be a fun bytecode hack all on its own. In fact, I'm gonna have a shot at that. An "early bind these names" decorator. ChrisA -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From peter.j..holzer at 1 Sat Jun 23 15:28:30 2018 From: peter.j..holzer at 1 (Peter J. Holzer) Date: Sat, 23 Jun 2018 14:28:30 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20901.uclanpyth@castlerockbbs.com> From: "Peter J. Holzer" --drblskvcly73v23o Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2018-06-23 08:12:52 -0400, Richard Damon wrote: > On 6/23/18 7:46 AM, Steven D'Aprano wrote: > > On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote: > >> If you know the Locale, then you do know what the decimal separator is, > >> as that is part of what a locale defines. > > A locale defines a set of common cultural conventions. It doesn't manda= te=20 > > the actual conventions in use in any specific document. > > > > If I'm in Australia, using the en-AU locale, nevertheless I can generat= e=20 > > a file using , as a decimal separator. Try and stop me :-) > yes, you can MIS-use the en-AU locale and write 1,000 to mean the number > One, just as you can misuse the language and write cat when you mean a > member of the Canine group, but then the misinterpretation is on the > creator of the document, not on the program that was told how the > document is to be read. How would he mis-use the en-AU locale to write 1 as "1,000"? I think to do that he would simply NOT use the locale. I think there are very good reasons to ignore the locale for specific purposes. For example, a Python interpreter should not use the locale when parsing Python, and a program producing Python should also ignore the locale. You two also seem to be writing about different things when you write "THE locale". Steven seems to mean the global settings a user has chosen, you seem to mean the specidic settings appropriate for parsing a specific file. hp --=20 _ | 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 --drblskvcly73v23o Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAlsuPOoACgkQ8g5IURL+ KF3nWw//T34BviAcOezJAU59Fkp7i6gcaTJ4meYOkvvXaipB3QQGIVKZck1T/6VE UcNJQipftT1/g3Uf4C9VRlrGwe2vq7QbeP220jBEECztmoqCBzpOgaVxOlpiP0gD YiPDdk69KZYzjtt6kTO6kwAVLRereyYh4kPeq2zrpSe0tmx53jg9RrmztQz9SFtk kU8klPFb1jzmgG8RLqrcB9FuUrBzfDxEXSsbHEqVqckAT9rYMLUtuqQPPZbi2zkC ncXXVvBVA061CcYwvnIxfp8jWvAlXwKwC1mv7DFkOtSgnoo85STmWcGryybJsTID cgCY90hnWfWM6rqLCS9eoeMMYOUItsxu0/uOAhsRMipt4lMI2Ebzhk5Udv87RFme CmJEcSEHwYD4iB2Zw2BE8DksSyfciNbuWYS7GHiMz/fiO25upVikCoNZEPk1Xu/C 6wJ+H6fsSv4GGdQls25ykyyt73b+OXGvbIr8hp3Mcup/Fn5P0BCc2vZehDxNaC4p alzqhRLfql2Hhr1TyPdapuxixBuD55PeRYOpKrpZmeQ0/O2m3Zube2Z3CrhPmQvH JNdI5suWRyV52QVvDQXV/3bUVywehe8C/kmPtWl0FeDaZPjcO/yHOgQK2abGYfAs t9vAMldEpQmBixh/hOqeGs5y9xLwQgf7liyvAV1ak2gIr9ntgdI= =XB3R -----END PGP SIGNATURE----- --drblskvcly73v23o-- --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From robertvstepp at gmail.com Sat Jun 23 15:52:24 2018 From: robertvstepp at gmail.com (boB Stepp) Date: Sat, 23 Jun 2018 14:52:24 -0500 Subject: syntax difference In-Reply-To: <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: I've finally found time to examine this rather long, rambling thread. On Wed, Jun 20, 2018 at 5:46 AM wrote: > > Yeah, people keep bringing that up when they run out of arguments. > > So, every programmer must always use the most advanced, most esoteric features possible at every opportunity? Coding should only be for the elite? > > There is a place for various levels of programming language. I'm saying that Python which is always touted as a 'simple' language suitable for beginners, is missing a surprising number of basics. I still feel like a rank beginner, but on the Tutor list some disagree. Perhaps I feel this way because the more I try to study and research programming/computer science topics, the more I realize how little I know and how much remains to be learned, so I continue to feel like a beginner. But I am beginner enough that I can respond to the above points. A handful of years ago at the job I do, I started to get tired of doing the same basic things over and over, so I investigated what possibilities the software I used on the OS it used had in order to automate these tasks. Perl proved to be available, but Python wasn't uniformly then, so I wrote some programs in Perl. I got it figured out and wrote some useful program in Perl, but the language never did feel natural and easy to understand to me. Later the OS and hardware got updated and I found Python was now fully available in the 2.4 version. I started writing new programs in Python and found it quite easy to use and understand. As I needed to, I started rewriting earlier programs I had done in Perl in Python instead, and was happier for it. As an aside we just had another round of software, OS and hardware upgrades. Now I can use Python 2.7! Because I read and study about new things as I take them up, I soon learned that I had only so far scratched the surface of Python's depths. But despite knowing that Python had many more features to explore, both in the core language and the standard library, this never hindered me in writing my beginner-level programs. I got things done, and I got them done fairly easily, and never felt burdened by all the "other stuff" that Python had to offer. But I am continually grateful that this "other stuff" exists! For instance, recently I was working on a problem for home use that I was doing in Python 3 (Not that 3 vs. 2 matters here.). I was concerned about loading potentially really large files into RAM and not having enough memory for it. Alan Gauld suggested I try a generator approach. I had not used these yet, though I was aware of this feature's existence. So I did some reading up on them, wrote some code with my attempted implementation of them, submitted my efforts to the Tutor list for critique, and while I am sure I did not do a professional job of things, I was quite happy with the result as it solved the problem I was concerned about. So even dipping my big toe into the "other stuff" proved an enjoyable and understandable experience. This has always been my experience with Python. When the time comes that I need something, I find it is there either in the core language or the standard library, and it proves not burdensome to learn the new feature(s). This has been my beginner's journey with Python: Easy to do useful stuff, easy to read and easy to understand. When I need something _more_, I find it already exists and proves relatively easy to understand *as long as* I am willing to put in a bit of study. And I don't think needing to put in a bit of study to learn how to use a new feature is unreasonable for me or anyone else. Anyway, so far Python has not lacked for anything I have needed so far. Of course, I realize that if I need to do something closer to the machine level, Python is probably not going to be the preferred go to tool, and even being a beginner I have enough sense to realize this. But then again, I would not be too surprised if Python or a third party library did not already meet this future, hypothetical need. > That these are useful is demonstrated by the cumbersome add-ons that need to be used to provide that functionality. Often in over the top ways and often in a bewildering variety of ways in the case of records. All I can say is I have yet to find much at all in Python cumbersome or bewildering. As to the original point of this thread concerning type-hints, I am aware of them, once asked a bit on Tutor about them, but decided I am not ready to go there yet. But to (I hope.) help my learning of Python syntax, I am forcing myself to *not* use linters, etc. Once I feel that I have Python in my head and in my fingers, then I will start using such sensible tools and will probably reexamine type-hints. As an aside to Bart, if you strongly feel that Python is missing a really useful feature, then why don't you do the usual thing, start a very specific thread about just that feature (Not just a collection of things you like in one of your languages.), and if you manage to persuade the community of its usefulness, then write up a PEP about it? Just saying ... ~(:>)) -- boB From bob.stepp at 1 Sat Jun 23 15:52:24 2018 From: bob.stepp at 1 (boB Stepp) Date: Sat, 23 Jun 2018 14:52:24 -0500 Subject: syntax difference Message-ID: <5B30F4ED.20969.uclanpyth@castlerockbbs.com> From: boB Stepp I've finally found time to examine this rather long, rambling thread. On Wed, Jun 20, 2018 at 5:46 AM wrote: > > Yeah, people keep bringing that up when they run out of arguments. > > So, every programmer must always use the most advanced, most esoteric features possible at every opportunity? Coding should only be for the elite? > > There is a place for various levels of programming language. I'm saying that Python which is always touted as a 'simple' language suitable for beginners, is missing a surprising number of basics. I still feel like a rank beginner, but on the Tutor list some disagree. Perhaps I feel this way because the more I try to study and research programming/computer science topics, the more I realize how little I know and how much remains to be learned, so I continue to feel like a beginner. But I am beginner enough that I can respond to the above points. A handful of years ago at the job I do, I started to get tired of doing the same basic things over and over, so I investigated what possibilities the software I used on the OS it used had in order to automate these tasks. Perl proved to be available, but Python wasn't uniformly then, so I wrote some programs in Perl. I got it figured out and wrote some useful program in Perl, but the language never did feel natural and easy to understand to me. Later the OS and hardware got updated and I found Python was now fully available in the 2.4 version. I started writing new programs in Python and found it quite easy to use and understand. As I needed to, I started rewriting earlier programs I had done in Perl in Python instead, and was happier for it. As an aside we just had another round of software, OS and hardware upgrades. Now I can use Python 2.7! Because I read and study about new things as I take them up, I soon learned that I had only so far scratched the surface of Python's depths. But despite knowing that Python had many more features to explore, both in the core language and the standard library, this never hindered me in writing my beginner-level programs. I got things done, and I got them done fairly easily, and never felt burdened by all the "other stuff" that Python had to offer. But I am continually grateful that this "other stuff" exists! For instance, recently I was working on a problem for home use that I was doing in Python 3 (Not that 3 vs. 2 matters here.). I was concerned about loading potentially really large files into RAM and not having enough memory for it. Alan Gauld suggested I try a generator approach. I had not used these yet, though I was aware of this feature's existence. So I did some reading up on them, wrote some code with my attempted implementation of them, submitted my efforts to the Tutor list for critique, and while I am sure I did not do a professional job of things, I was quite happy with the result as it solved the problem I was concerned about. So even dipping my big toe into the "other stuff" proved an enjoyable and understandable experience. This has always been my experience with Python. When the time comes that I need something, I find it is there either in the core language or the standard library, and it proves not burdensome to learn the new feature(s). This has been my beginner's journey with Python: Easy to do useful stuff, easy to read and easy to understand. When I need something _more_, I find it already exists and proves relatively easy to understand *as long as* I am willing to put in a bit of study. And I don't think needing to put in a bit of study to learn how to use a new feature is unreasonable for me or anyone else. Anyway, so far Python has not lacked for anything I have needed so far. Of course, I realize that if I need to do something closer to the machine level, Python is probably not going to be the preferred go to tool, and even being a beginner I have enough sense to realize this. But then again, I would not be too surprised if Python or a third party library did not already meet this future, hypothetical need. > That these are useful is demonstrated by the cumbersome add-ons that need to be used to provide that functionality. Often in over the top ways and often in a bewildering variety of ways in the case of records. All I can say is I have yet to find much at all in Python cumbersome or bewildering. As to the original point of this thread concerning type-hints, I am aware of them, once asked a bit on Tutor about them, but decided I am not ready to go there yet. But to (I hope.) help my learning of Python syntax, I am forcing myself to *not* use linters, etc. Once I feel that I have Python in my head and in my fingers, then I will start using such sensible tools and will probably reexamine type-hints. As an aside to Bart, if you strongly feel that Python is missing a really useful feature, then why don't you do the usual thing, start a very specific thread about just that feature (Not just a collection of things you like in one of your languages.), and if you manage to persuade the community of its usefulness, then write up a PEP about it? Just saying ... ~(:>)) -- boB --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From marko.rauhamaa at 1 Sat Jun 23 16:03:10 2018 From: marko.rauhamaa at 1 (Marko Rauhamaa) Date: Sat, 23 Jun 2018 15:03:10 -0500 Subject: translating foreign data In-Reply-To: <5B2FCDF9.20889.uclanpyth@castlerockbbs.com> References: <5B2FCDF9.20889.uclanpyth@castlerockbbs.com> Message-ID: <5B2FCDF9.20899.uclanpyth@castlerockbbs.com> To: Richard Damon From: Marko Rauhamaa Richard Damon : > If you know the Locale, then you do know what the decimal separator > is, as that is part of what a locale defines. I don't know what that sentence means. > The issue is that if you just know the encoding, you don't necessarily > know the locale. I always know my locale. The locale is tied to the human user. > He also commented that he didn't want to set the locale in the > routine, as that sets it globally for the full application (but > perhaps that latter could be fixed by first doing a > locale.getlocale(), then setlocale for the files locale, and then at > the end of reading and processing restore back the old locale. Setting a locale application-wise is * not in accordance with the idea of a locale (the locale should be constant within a user session) * not easily possible (the locale is seen by all threads simultaneously) BTW, I think the locale is a terrible invention. Marko --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From marko.rauhamaa at 1 Sat Jun 23 16:03:10 2018 From: marko.rauhamaa at 1 (Marko Rauhamaa) Date: Sat, 23 Jun 2018 15:03:10 -0500 Subject: translating foreign data In-Reply-To: <5B324678.21109.uclanpyth@castlerockbbs.com> References: <5B324678.21109.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21119.uclanpyth@castlerockbbs.com> To: Richard Damon From: "Marko Rauhamaa" To: Richard Damon From: Marko Rauhamaa Richard Damon : > If you know the Locale, then you do know what the decimal separator > is, as that is part of what a locale defines. I don't know what that sentence means. > The issue is that if you just know the encoding, you don't necessarily > know the locale. I always know my locale. The locale is tied to the human user. > He also commented that he didn't want to set the locale in the > routine, as that sets it globally for the full application (but > perhaps that latter could be fixed by first doing a > locale.getlocale(), then setlocale for the files locale, and then at > the end of reading and processing restore back the old locale. Setting a locale application-wise is * not in accordance with the idea of a locale (the locale should be constant within a user session) * not easily possible (the locale is seen by all threads simultaneously) BTW, I think the locale is a terrible invention. Marko -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From rosuav at gmail.com Sat Jun 23 16:13:16 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jun 2018 06:13:16 +1000 Subject: Static variables [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: > This is an example of a simple concept getting so out of hand that it will > either never be implemented, or the resulting implementation becomes > impractical to use. > > This is what we're trying to do: > > def nextx(): > static x = 0 > x += 1 > return x > > And this is the simplest equivalent code in current Python that will cater > for 99% of uses: > > _nextx_x = 0 > > def nextx(): > global _nextx_x > _nextx_x += 1 > return _nextx_x > > No nested functions. No generating new instances of functions complete with > a new set of statics each time you happen to refer to the name. (Which > sounds to me as useful as creating a new instance of an import when you copy > its name, complete with a separate set of its globals. Isn't this stuff what > classes are for?) > > (At what point would that happen anyway; if you do this: > > g = nextx # hypothetical version would static > > it will create a new instance of 'nextx'. But it won't create one here, just > before () is applied: > > nextx() # ? > > Or how about here: > > listoffunctions = (nextx1, nextx2, nextx3) > > listoffunctions[i]() # ? > > ) Clearly you have completely misunderstood the entire concept of Python's memory model, so I am not going to engage in debate with you on this. This is my ONLY post explaining this to you. NONE of your examples are taking copies of the function. They all are making REFERENCES to the same function. That is all. Creating new functions is the job of 'def' and 'lambda'. Not assignment. So the concept of "multiple functions with the same name" comes from executing the def statement more than once. ChrisA From chris.angelico at 1 Sat Jun 23 16:21:32 2018 From: chris.angelico at 1 (Chris Angelico) Date: Sat, 23 Jun 2018 15:21:32 -0500 Subject: Static variables [was Re: syntax difference] Message-ID: <5B2FCDF9.20886.uclanpyth@castlerockbbs.com> From: Chris Angelico On Sat, Jun 23, 2018 at 2:16 PM, Chris Angelico wrote: > For getting rid of the "len=len" trick, though, I would REALLY like to > transform those into LOAD_CONST. That'd be a fun bytecode hack all on > its own. In fact, I'm gonna have a shot at that. An "early bind these > names" decorator. Well, that was easier than I expected. Which almost certainly means I haven't properly solved the problem. https://github.com/Rosuav/shed/blob/master/consts.py Let's start finding all the edge cases that don't work, so I can work on fixing them :) ChrisA --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From chris.angelico at 1 Sat Jun 23 16:21:32 2018 From: chris.angelico at 1 (Chris Angelico) Date: Sat, 23 Jun 2018 15:21:32 -0500 Subject: Static variables [was Re: syntax difference] Message-ID: <5B324678.21106.uclanpyth@castlerockbbs.com> From: "Chris Angelico" From: Chris Angelico On Sat, Jun 23, 2018 at 2:16 PM, Chris Angelico wrote: > For getting rid of the "len=len" trick, though, I would REALLY like to > transform those into LOAD_CONST. That'd be a fun bytecode hack all on > its own. In fact, I'm gonna have a shot at that. An "early bind these > names" decorator. Well, that was easier than I expected. Which almost certainly means I haven't properly solved the problem. https://github.com/Rosuav/shed/blob/master/consts.py Let's start finding all the edge cases that don't work, so I can work on fixing them :) ChrisA -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sat Jun 23 16:27:56 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sat, 23 Jun 2018 15:27:56 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20914.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sat, 23 Jun 2018 09:42:29 -0400, Richard Damon wrote: > On 6/23/18 9:05 AM, Marko Rauhamaa wrote: >> Ok. Here's a value for you: >> >> 100??? >> >> I see '1', '0', '0', '???'. What do you see in your locale (LC_MONETARY)? > > If I processed that on my system I would either get $100, or an error of > wrong currency symbol depending on the error checking. Then your system is so unbelievably broken that it should be nuked from orbit, just to be sure. The data you were given was 100 Euros. If your system is incapable of reading that as 100 Euros, and errors out, then at least to know that it is brain-damaged and useless. But if instead it silently changes the data to $100 (US dollars? Australian dollars? Zimbabwe dollars? the gods only know what a system that broken might do...) then it is not only broken but *dangerously* broken. [...] > Locale predates UCS-2, it was the early attempt to provide > internationalization to C code so even programmers who didn't think > about it could add the line setlocale(LC_ALL, "") and make their code > work at least mostly right in more places. A single global was quick and > simple, and since threads didn't exist, not an issue. Threads were first used in 1967, five years before C even existed. https://en.wikipedia.org/wiki/Thread_%28computing%29#History -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bc at freeuk.com Sat Jun 23 16:44:00 2018 From: bc at freeuk.com (Bart) Date: Sat, 23 Jun 2018 21:44:00 +0100 Subject: Static variables [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> Message-ID: <2iyXC.494652$Vs7.246701@fx41.am4> On 23/06/2018 21:13, Chris Angelico wrote: > On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: >> (At what point would that happen anyway; if you do this: > NONE of your examples are taking copies of the function. They all are > making REFERENCES to the same function. That is all. This is about your notion that invocations of the same function via different references, should maintain their own versions of the function's 'static' data. Since these references are created via the return g statement here: def f(): def g(): .... return g (say to create function references i and j like this: i = f() j = f() ) I'm assuming that something special must be happening. Otherwise, how does f() know which reference it's being called via? What is different, what extra bit of information is provided when f() is invoked via i() or j()? -- bart From steven.d'aprano at 1 Sat Jun 23 16:44:14 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sat, 23 Jun 2018 15:44:14 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20916.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sat, 23 Jun 2018 08:12:52 -0400, Richard Damon wrote: > On 6/23/18 7:46 AM, Steven D'Aprano wrote: >> On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote: >> >>> If you know the Locale, then you do know what the decimal separator >>> is, as that is part of what a locale defines. >> A locale defines a set of common cultural conventions. It doesn't >> mandate the actual conventions in use in any specific document. >> >> If I'm in Australia, using the en-AU locale, nevertheless I can >> generate a file using , as a decimal separator. Try and stop me :-) > > yes, you can MIS-use the en-AU locale and write 1,000 to mean the number > One, just as you can misuse the language and write cat when you mean a > member of the Canine group, How about if I write "le chien" or "der Hund" or "??D1D?D?D?D?"? Is that also a misuse of the locale because I choose to write in a foreign language, using foreign conventions for spelling, grammar and syntax? > but then the misinterpretation is on the > creator of the document, not on the program that was told how the > document is to be read. You're assuming that there will be a misinterpretation. That's an absurd assumption to make. There might be, of course, but the documentation for my document might be clear that comma is to be used for decimal separators. Or it might include numbers like 1.234.567,012345678 which is understandable to anyone who is aware of the possibility that comma may mean decimal separator and period the thousands separator. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From marko.rauhamaa at 1 Sat Jun 23 17:05:06 2018 From: marko.rauhamaa at 1 (Marko Rauhamaa) Date: Sat, 23 Jun 2018 16:05:06 -0500 Subject: translating foreign data In-Reply-To: <5B2FCDF9.20902.uclanpyth@castlerockbbs.com> References: <5B2FCDF9.20902.uclanpyth@castlerockbbs.com> Message-ID: <5B2FCDF9.20905.uclanpyth@castlerockbbs.com> To: Richard Damon From: Marko Rauhamaa Richard Damon : > On 6/23/18 8:03 AM, Marko Rauhamaa wrote: >> I always know my locale. The locale is tied to the human user. > No, it should be tied to the data you are processing. In computing, a locale is a set of parameters that defines the user's language, region and any special variant preferences that the user wants to see in their user interface. The data should not depend on the locale. > If an English user is feeding a program Chinese documents, while > processing those documents the program should be using the appropriate > Chinese Locale. Not true. > Again, no, a locale is tied to the data, not the user (unless you want > to require the user to translate all data to his locale conventions > (without using a program that can use locale information) before > providing it to a program. Yes, the default for the interpretation > should be the users default/current locale, but you really want them > to be able to say I got this file from someone whose locale was > different than mine. The locale is not directly related to data or data formats. Of course, locales leak into data and create the sorry mess we are talking about. > Data presented to the user should normally use his locale (unless he > has specified something different). Ok. Here's a value for you: 100??? I see '1', '0', '0', '???'. What do you see in your locale (LC_MONETARY)? >> BTW, I think the locale is a terrible invention. > > The locale is a lot better than the alternative, where every > application that needs to deal with internationalization need to > recreate (and debub) all of the mechanism. I agree it isn't perfect, > and for small simple programs it would be nice to be able to say "I > don't want all this stuff, make it go away". The locale doesn't solve a single problem in practice and often trips up programs. For example, a customer-visible bug was once caused by: sort Python took its locale (at least initially) from C, which was a single > global which does have more issues because of this. The single global is due to what the locale was introduced for. It came about around the time when Unix applications were being made "8-bit clean." Along with UCS-2 and XML, it's one of those things you wish you'd never have to deal with. Marko --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From marko.rauhamaa at 1 Sat Jun 23 17:05:06 2018 From: marko.rauhamaa at 1 (Marko Rauhamaa) Date: Sat, 23 Jun 2018 16:05:06 -0500 Subject: translating foreign data Message-ID: <5B324678.21121.uclanpyth@castlerockbbs.com> To: Richard Damon From: "Marko Rauhamaa" To: Richard Damon From: Marko Rauhamaa Richard Damon : > On 6/23/18 8:03 AM, Marko Rauhamaa wrote: >> I always know my locale. The locale is tied to the human user. > No, it should be tied to the data you are processing. In computing, a locale is a set of parameters that defines the user's language, region and any special variant preferences that the user wants to see in their user interface. The data should not depend on the locale. > If an English user is feeding a program Chinese documents, while > processing those documents the program should be using the appropriate > Chinese Locale. Not true. > Again, no, a locale is tied to the data, not the user (unless you want > to require the user to translate all data to his locale conventions > (without using a program that can use locale information) before > providing it to a program. Yes, the default for the interpretation > should be the users default/current locale, but you really want them > to be able to say I got this file from someone whose locale was > different than mine. The locale is not directly related to data or data formats. Of course, locales leak into data and create the sorry mess we are talking about. > Data presented to the user should normally use his locale (unless he > has specified something different). Ok. Here's a value for you: 100??? I see '1', '0', '0', '???'. What do you see in your locale (LC_MONETARY)? >> BTW, I think the locale is a terrible invention. > > The locale is a lot better than the alternative, where every > application that needs to deal with internationalization need to > recreate (and debub) all of the mechanism. I agree it isn't perfect, > and for small simple programs it would be nice to be able to say "I > don't want all this stuff, make it go away". The locale doesn't solve a single problem in practice and often trips up programs. For example, a customer-visible bug was once caused by: sort Python took its locale (at least initially) from C, which was a single > global which does have more issues because of this. The single global is due to what the locale was introduced for. It came about around the time when Unix applications were being made "8-bit clean." Along with UCS-2 and XML, it's one of those things you wish you'd never have to deal with. Marko -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From Richard at Damon-Family.org Sat Jun 23 17:05:17 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 23 Jun 2018 17:05:17 -0400 Subject: translating foreign data In-Reply-To: References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <87h8ltiubl.fsf@elektro.pacujo.net> <8318150e-1f3c-eb97-d25c-475bddc6e223@Damon-Family.org> <87d0whirgc.fsf@elektro.pacujo.net> Message-ID: <1d713ce6-d8d8-110c-aa78-d7d672a024b9@Damon-Family.org> On 6/23/18 11:27 AM, Steven D'Aprano wrote: > On Sat, 23 Jun 2018 09:42:29 -0400, Richard Damon wrote: > >> On 6/23/18 9:05 AM, Marko Rauhamaa wrote: >>> Ok. Here's a value for you: >>> >>> 100? >>> >>> I see '1', '0', '0', '?'. What do you see in your locale (LC_MONETARY)? >> If I processed that on my system I would either get $100, or an error of >> wrong currency symbol depending on the error checking. > Then your system is so unbelievably broken that it should be nuked from > orbit, just to be sure. > > The data you were given was 100 Euros. If your system is incapable of > reading that as 100 Euros, and errors out, then at least to know that it > is brain-damaged and useless. > > But if instead it silently changes the data to $100 (US dollars? > Australian dollars? Zimbabwe dollars? the gods only know what a system > that broken might do...) then it is not only broken but *dangerously* > broken. > Locale based currency transformations are defined as a number to/from a text string. The number CAN'T say 100 Euros (can you give me what bit pattern you would use for such a number). The currency is encoded in the locale used for the conversion, so if it is using en-US, the currency value would ALWAYS be US$ (which the general locale format is just $). As such 100? is an invalid input to a system getting a Locale based input for a currency if the locale is not one from a country that uses the euro. What the input sees is '1', '0', '0',? some funny character (or maybe 2 of them). A poorly designed input, or one being intentionally generous on input acceptance would return 100, which would be implied US Dollars. A better error checking routine would give an error. It is IMPOSSIBLE for it to return a number that would be 100 euros. I suppose a very smart system might see that it was in a different currency and try to convert it, but unless time reference point to use for the currency, you are likely to get a wrong answer, but in any case, the answer will NOT be 100 euros, but some equivalent value in Dollars. Now, if you want to define a perhaps more general currency input routine that tries to detect a pan-locale currency input, and returned both a value and a currency type, that could be more useful in some contexts. But you then run into the interesting (and difficult) problem that if you see the input of 123.456? what is that value, is it a value around a hundred euros specified to 3 decimal places, or is it a number just over 100 thousand euros. > > [...] >> Locale predates UCS-2, it was the early attempt to provide >> internationalization to C code so even programmers who didn't think >> about it could add the line setlocale(LC_ALL, "") and make their code >> work at least mostly right in more places. A single global was quick and >> simple, and since threads didn't exist, not an issue. > Threads were first used in 1967, five years before C even existed. > > https://en.wikipedia.org/wiki/Thread_%28computing%29#History > Threads did NOT exist (at least to the Standard) in C when locales were added, and the C language did nothing to support threading at that time. Looking back, it was perhaps a regrettable decision to implement locales globally the way there were, but it is what it is. -- Richard Damon From peter.j..holzer at 1 Sat Jun 23 17:05:48 2018 From: peter.j..holzer at 1 (Peter J. Holzer) Date: Sat, 23 Jun 2018 16:05:48 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20910.uclanpyth@castlerockbbs.com> From: "Peter J. Holzer" --p4u6dkqn7e5fhtwt Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2018-06-23 08:41:38 -0400, Richard Damon wrote: > On 6/23/18 8:28 AM, Peter J. Holzer wrote: > > On 2018-06-23 08:12:52 -0400, Richard Damon wrote: > >> On 6/23/18 7:46 AM, Steven D'Aprano wrote: > >>> If I'm in Australia, using the en-AU locale, nevertheless I can gener= ate=20 > >>> a file using , as a decimal separator. Try and stop me :-) > >> yes, you can MIS-use the en-AU locale and write 1,000 to mean the numb= er > >> One, just as you can misuse the language and write cat when you mean a > >> member of the Canine group, but then the misinterpretation is on the > >> creator of the document, not on the program that was told how the > >> document is to be read. > > How would he mis-use the en-AU locale to write 1 as "1,000"? I think > > to do that he would simply NOT use the locale. > Once you open the Locale can of worms, EVERYTHING has a locale, to say > you aren't using a locale is to say you are writing > something unintelligible, as you can thing of the locale as the set of > rules to interpret I don't think that's a useful way to look at it. "Locale" in (non-technical) English means "place" or "site". The idea behind the locale concept is that some conventions (e.g. how to write numbers or how to write strings) depend on the place where the program runs (or maybe where the user is sitting or grew up or maybe where a file was produced). For stuff which doesn't depend on the place (e.g. how a Python program should be parsed), the locale concept doesn't apply. > > You two also seem to be writing about different things when you write > > "THE locale". Steven seems to mean the global settings a user has > > chosen, you seem to mean the specidic settings appropriate for parsing a > > specific file. While I was writing this paragraph I realized that I had also used "the locale" in a specific meaning in the previous paragraph. I decided to let it stand and see whether anyone would call me out it. > You have THE locale for a given piece of data. Well, you didn't. Even though I quite obviously used "the locale" in Steven's meaning, you didn't react to that at all and just continue as if your definition is the only possible one. hp --=20 _ | 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 --p4u6dkqn7e5fhtwt Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAlsuU7kACgkQ8g5IURL+ KF308BAAkxEOzzNfnaRez6RwpTWGI7CbWb5HK8B8mmn+AoAo788Cj+yQYE0CEUbG HBM0UPtc44ZqSrvIcyXlmL6xjUzkuPOYUZbtxVunWQm3NLgaViHf3b+1uSqsapYT jqQo+LbQiENqPrroSjqWmOKpo3B5T9m7howPuvGMCBRV7B/CriOnVwYjrolo02JL gcdcLPPyN4tGHhWFvMN6xycLS5m/bC4do8yRz/GPzRT/IoEI4gmKbk/10pzEK7iH s3V+P74uznvR8B4PxCPNCWiI9LJD61K+u1qhdrmg+7XPHHqr/04GiPFZ2JHSthhG joRP0UdlbTs+esELjUhrN7Xcd+Z1qlA9N86ULXv5QA0YaDCUXNhjOEkLAzOpx9Af XWcmnVfaHePxhqIKHvo5tsx/eEdLRttiScw11UoAvyNmFHW9oiVZhP0za6GgiiHr jXNOcC5uDTpisi3TsR8jV/MhBwGc01up6JMkVnCIXArGneZAeTDVocQrp99IDg4z bGLoSeSafqH0Xxzv+f0UomOrvTlCV011Tst/rn94EkI3SonNq6/0TxLVO5da/Jj+ 626iYqQcqk7vzF5cL8umtYDe78oRdycvJcxMmfheORuCiLTWLbYYi+0nHmo3q35F /bfsla74h5ysvuJAyNLNCBoamziZvK/b35j9CQzLLN86QQNntdI= =HQTI -----END PGP SIGNATURE----- --p4u6dkqn7e5fhtwt-- --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From peter.j..holzer at 1 Sat Jun 23 17:23:52 2018 From: peter.j..holzer at 1 (Peter J. Holzer) Date: Sat, 23 Jun 2018 16:23:52 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20912.uclanpyth@castlerockbbs.com> From: "Peter J. Holzer" --jbhqoow7s7225t6e Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2018-06-23 16:05:49 +0200, Peter J. Holzer wrote: > I don't think that's a useful way to look at it. "Locale" in > (non-technical) English means "place" or "site". The idea behind the > locale concept is that some conventions (e.g. how to write numbers or > how to write strings) depend on the place where the program runs Sorry, I meant "how to *sort* strings. hp --=20 _ | 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 --jbhqoow7s7225t6e Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAlsuV/UACgkQ8g5IURL+ KF33DQ//aHNtdu5IitrWXN2+HIiyjN6I2Pepd6Uw59rIItHOTqSbO0quv0SEIYqp pA/MBmVFVkCnzImOEY4/vP7CbZREnqDoSrjpK0UOTzm8rowi7Ovgr94b1eNYdfCv B8fJxh4EJ7d852afVb3UM6SMrqJnGk2LZd4Ck0ViCTQg0AFI3BlGSGvvqwLt1tJ5 sN4J1pMR+Y6wlCZ3D7ElF/qEwnJTdSllteNWZA2egAtrvoFP+sk2spb+8PC9KaeU cvhYILaQLI0Tqqfud6J4qNDGztWN9NtGYnoPcbwG6siXTwMIKniihKcogeGtNA8m ynn3MES2BuSZ0tnxyCtdQcmN4bRkrtWM+2DALs6dnRizRgmH2WAn+PWb1t609oXV 9uegyyloaOtUDNwLkhMI0+W7VmE7yraUYpvXqOZIeNK+Aorbh0rsDtEcQyxc4TwJ oPfW4ExQyV75d9n+IiFerDj/lKNQN5nIWrBzCf4ue29sxfAuABdDBudrgQ6HMM3K w4kmUgzfvKqk+srnmFeMG+aCmglsUvZKQvzb+7W+yRx6zQkie/uzjFS5j4r8pOP/ Kk43L2oH3OMjZMBkky6WoRZkKMKexD7MfEpS1UaISkat2NQYeVIyal7Er9k3s4ZV VXO/G77ac+qysAr2PPJXxrtVRcX/7/s2/p/P3bNxElUqk/oqE6s= =lwIj -----END PGP SIGNATURE----- --jbhqoow7s7225t6e-- --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From ben+python at benfinney.id.au Sat Jun 23 17:31:28 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 24 Jun 2018 07:31:28 +1000 Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <87h8ltiubl.fsf@elektro.pacujo.net> <8318150e-1f3c-eb97-d25c-475bddc6e223@Damon-Family.org> <87d0whirgc.fsf@elektro.pacujo.net> <1d713ce6-d8d8-110c-aa78-d7d672a024b9@Damon-Family.org> Message-ID: <857empdwb3.fsf@benfinney.id.au> Richard Damon writes: > On 6/23/18 11:27 AM, Steven D'Aprano wrote: > >> On 6/23/18 9:05 AM, Marko Rauhamaa wrote: > >>> Richard Damon wrote: > >>> > Data presented to the user should normally use his locale > >>> > (unless he has specified something different). > >>> > >>> Ok. Here's a value for you: > >>> > >>> 100? > >>> > > [?] > > The data you were given was 100 Euros. If your system is incapable > > of reading that as 100 Euros, and errors out, then at least to know > > that it is brain-damaged and useless. > > > > But if instead it silently changes the data to $100 (US dollars? > > Australian dollars? Zimbabwe dollars? the gods only know what a > > system that broken might do...) then it is not only broken but > > *dangerously* broken. > > > [?] > > The number CAN'T say 100 Euros (can you give me what bit pattern you > would use for such a number). That is (I believe) the point being made: The data is *not* a number. It is a value that must encapsulate more than only the number 100, but also and simultaneously the curency ?Euro?. > The currency is encoded in the locale used for the conversion, so if it > is using en-US, the currency value would ALWAYS be US$ (which the > general locale format is just $). As such 100? is an invalid input to a > system getting a Locale based input for a currency if the locale is not > one from a country that uses the euro. The value is 100 Euro, a quantity of a particular currency and not something trivially converted to US$ (for many reasons, including the obvious one that we don't know the exact exchange rate to use, and it will be different at a different time). You appear to be arguing that this value must either be arbitrarily converted to the user's local currency, something we agree is impossible to do given the data, or the value is simply invalid. So the rule you assert ? ?Data presented to the user should normally use his locale? ? fails to usefuly handle the very normal case of data that represents a quantity of some foreign currency. Any system following your asserted rule will give either the wrong answer, or an error. We had better hope the rule you assert is not in effect. -- \ ?DRM doesn't inconvenience [lawbreakers] ? indeed, over time it | `\ trains law-abiding users to become [lawbreakers] out of sheer | _o__) frustration.? ?Charles Stross, 2010-05-09 | Ben Finney From Richard at Damon-Family.org Sat Jun 23 17:52:55 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 23 Jun 2018 17:52:55 -0400 Subject: translating foreign data In-Reply-To: <857empdwb3.fsf@benfinney.id.au> References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <87h8ltiubl.fsf@elektro.pacujo.net> <8318150e-1f3c-eb97-d25c-475bddc6e223@Damon-Family.org> <87d0whirgc.fsf@elektro.pacujo.net> <1d713ce6-d8d8-110c-aa78-d7d672a024b9@Damon-Family.org> <857empdwb3.fsf@benfinney.id.au> Message-ID: <03814d57-08fd-dfef-8bb5-469140f5de0a@Damon-Family.org> On 6/23/18 5:31 PM, Ben Finney wrote: > Richard Damon writes: > >> On 6/23/18 11:27 AM, Steven D'Aprano wrote: >>>> On 6/23/18 9:05 AM, Marko Rauhamaa wrote: >>>>> Richard Damon wrote: >>>>>> Data presented to the user should normally use his locale >>>>>> (unless he has specified something different). >>>>> Ok. Here's a value for you: >>>>> >>>>> 100? >>>>> >>> [?] >>> The data you were given was 100 Euros. If your system is incapable >>> of reading that as 100 Euros, and errors out, then at least to know >>> that it is brain-damaged and useless. >>> >>> But if instead it silently changes the data to $100 (US dollars? >>> Australian dollars? Zimbabwe dollars? the gods only know what a >>> system that broken might do...) then it is not only broken but >>> *dangerously* broken. >>> >> [?] >> >> The number CAN'T say 100 Euros (can you give me what bit pattern you >> would use for such a number). > That is (I believe) the point being made: The data is *not* a number. It > is a value that must encapsulate more than only the number 100, but also > and simultaneously the curency ?Euro?. If you have more than just a number representing a value in the locale currency, you can't ask the locale how to present/accept it. > >> The currency is encoded in the locale used for the conversion, so if it >> is using en-US, the currency value would ALWAYS be US$ (which the >> general locale format is just $). As such 100? is an invalid input to a >> system getting a Locale based input for a currency if the locale is not >> one from a country that uses the euro. > The value is 100 Euro, a quantity of a particular currency and not > something trivially converted to US$ (for many reasons, including the > obvious one that we don't know the exact exchange rate to use, and it > will be different at a different time). > > You appear to be arguing that this value must either be arbitrarily > converted to the user's local currency, something we agree is impossible > to do given the data, or the value is simply invalid. > > So the rule you assert ? ?Data presented to the user should normally use > his locale? ? fails to usefuly handle the very normal case of data that > represents a quantity of some foreign currency. Any system following > your asserted rule will give either the wrong answer, or an error. We > had better hope the rule you assert is not in effect. > If the user wants to talk in Euro using software that uses locales, then he should specify a locale that uses Euros. If you have a field to enter a foreign currency, then you can NOT make that a LC_CURRENCY field, or you need to make that field use a different locale than the local locale. This isn't the fault of locales, but in a misuse of the system. This original question came when it was asked what do I see with 100? in MY locale LC_CURRENCY, well MY locale doesn't have a LC_CURRENCY that is euros, so it can't express that. It is a bit like asking how to draw a circle with 4 straight lines or get to the moon in a boat. It is a question with an improper premise. -- Richard Damon From richard.damon at 1 Sat Jun 23 18:05:16 2018 From: richard.damon at 1 (Richard Damon) Date: Sat, 23 Jun 2018 17:05:16 -0500 Subject: translating foreign data Message-ID: <5B30F4ED.20972.uclanpyth@castlerockbbs.com> From: Richard Damon On 6/23/18 11:27 AM, Steven D'Aprano wrote: > On Sat, 23 Jun 2018 09:42:29 -0400, Richard Damon wrote: > >> On 6/23/18 9:05 AM, Marko Rauhamaa wrote: >>> Ok. Here's a value for you: >>> >>> 100??? >>> >>> I see '1', '0', '0', '???'. What do you see in your locale (LC_MONETARY)? >> If I processed that on my system I would either get $100, or an error of >> wrong currency symbol depending on the error checking. > Then your system is so unbelievably broken that it should be nuked from > orbit, just to be sure. > > The data you were given was 100 Euros. If your system is incapable of > reading that as 100 Euros, and errors out, then at least to know that it > is brain-damaged and useless. > > But if instead it silently changes the data to $100 (US dollars? > Australian dollars? Zimbabwe dollars? the gods only know what a system > that broken might do...) then it is not only broken but *dangerously* > broken. > Locale based currency transformations are defined as a number to/from a text string. The number CAN'T say 100 Euros (can you give me what bit pattern you would use for such a number). The currency is encoded in the locale used for the conversion, so if it is using en-US, the currency value would ALWAYS be US$ (which the general locale format is just $). As such 100??? is an invalid input to a system getting a Locale based input for a currency if the locale is not one from a country that uses the euro. What the input sees is '1', '0', '0',? some funny character (or maybe 2 of them). A poorly designed input, or one being intentionally generous on input acceptance would return 100, which would be implied US Dollars. A better error checking routine would give an error. It is IMPOSSIBLE for it to return a number that would be 100 euros. I suppose a very smart system might see that it was in a different currency and try to convert it, but unless time reference point to use for the currency, you are likely to get a wrong answer, but in any case, the answer will NOT be 100 euros, but some equivalent value in Dollars. Now, if you want to define a perhaps more general currency input routine that tries to detect a pan-locale currency input, and returned both a value and a currency type, that could be more useful in some contexts. But you then run into the interesting (and difficult) problem that if you see the input of 123.456??? what is that value, is it a value around a hundred euros specified to 3 decimal places, or is it a number just over 100 thousand euros. > > [...] >> Locale predates UCS-2, it was the early attempt to provide >> internationalization to C code so even programmers who didn't think >> about it could add the line setlocale(LC_ALL, "") and make their code >> work at least mostly right in more places. A single global was quick and >> simple, and since threads didn't exist, not an issue. > Threads were first used in 1967, five years before C even existed. > > https://en.wikipedia.org/wiki/Thread_%28computing%29#History > Threads did NOT exist (at least to the Standard) in C when locales were added, and the C language did nothing to support threading at that time. Looking back, it was perhaps a regrettable decision to implement locales globally the way there were, but it is what it is. -- Richard Damon --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From marko.rauhamaa at 1 Sat Jun 23 18:10:08 2018 From: marko.rauhamaa at 1 (Marko Rauhamaa) Date: Sat, 23 Jun 2018 17:10:08 -0500 Subject: translating foreign data In-Reply-To: <5B2FCDF9.20909.uclanpyth@castlerockbbs.com> References: <5B2FCDF9.20909.uclanpyth@castlerockbbs.com> Message-ID: <5B2FCDF9.20911.uclanpyth@castlerockbbs.com> To: Richard Damon From: Marko Rauhamaa Richard Damon : > On 6/23/18 9:05 AM, Marko Rauhamaa wrote: >> Richard Damon : >> >>> On 6/23/18 8:03 AM, Marko Rauhamaa wrote: >>>> I always know my locale. The locale is tied to the human user. >>> No, it should be tied to the data you are processing. >> In computing, a locale is a set of parameters that defines the user's >> language, region and any special variant preferences that the user >> wants to see in their user interface. >> >> >> >> The data should not depend on the locale. > So no one foreign ever gives you data? Never in my decades in computer programming have I found any use for locales. In particular, they have never helped me decode "foreign" data, whether in ASCII, Latin-1, Latin-3, Latin-9, JIS or UTF-8. > Note, that wikipedia article is focused on the SYSTEM locale, which > yes, that should reflect the what the user wants in his interface. I don't think locales have anything to do with anything else. >>> If an English user is feeding a program Chinese documents, while >>> processing those documents the program should be using the >>> appropriate Chinese Locale. >> Not true. > How else is the program going to understand the Chinese data? If someone gives me a file, they had better indicate the file format. > The fact that locale issues leak into data is the reason that the > single immutable global locale doesn't work. Locales don't work. Period. > You really want to imbue into data streams what locale their data > represents (and use that in some of the later processing of data from > that stream). Can you refer to a standard for that kind of imbuement? Of course, you have document types, schema definitions and other implicit and explicit format indicators. You shouldn't call them locales, though. >>> Data presented to the user should normally use his locale (unless he >>> has specified something different). >> Ok. Here's a value for you: >> >> 100??? >> >> I see '1', '0', '0', '???'. What do you see in your locale (LC_MONETARY)? > If I processed that on my system I would either get $100, or an error of > wrong currency symbol depending on the error checking. Don't forget to convert the amount as well... >> The single global is due to what the locale was introduced for. It >> came about around the time when Unix applications were being made >> "8-bit clean." Along with UCS-2 and XML, it's one of those things you >> wish you'd never have to deal with. > > Locale predates UCS-2, it was the early attempt to provide > internationalization to C code so even programmers who didn't think > about it could add the line setlocale(LC_ALL, "") and make their code > work at least mostly right in more places. A single global was quick > and simple, and since threads didn't exist, not an issue. > > In many ways it was the first attempt that should have been thrown > away, but got too intertwined. C++ made a significant improvement to > it by having streams remember their own locale. Noone should breathe any new life into locales. And yes, add C++ to the list of things you wish you'd never have to deal with... Marko --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From marko.rauhamaa at 1 Sat Jun 23 18:10:08 2018 From: marko.rauhamaa at 1 (Marko Rauhamaa) Date: Sat, 23 Jun 2018 17:10:08 -0500 Subject: translating foreign data Message-ID: <5B324678.21124.uclanpyth@castlerockbbs.com> To: Richard Damon From: "Marko Rauhamaa" To: Richard Damon From: Marko Rauhamaa Richard Damon : > On 6/23/18 9:05 AM, Marko Rauhamaa wrote: >> Richard Damon : >> >>> On 6/23/18 8:03 AM, Marko Rauhamaa wrote: >>>> I always know my locale. The locale is tied to the human user. >>> No, it should be tied to the data you are processing. >> In computing, a locale is a set of parameters that defines the user's >> language, region and any special variant preferences that the user >> wants to see in their user interface. >> >> >> >> The data should not depend on the locale. > So no one foreign ever gives you data? Never in my decades in computer programming have I found any use for locales. In particular, they have never helped me decode "foreign" data, whether in ASCII, Latin-1, Latin-3, Latin-9, JIS or UTF-8. > Note, that wikipedia article is focused on the SYSTEM locale, which > yes, that should reflect the what the user wants in his interface. I don't think locales have anything to do with anything else. >>> If an English user is feeding a program Chinese documents, while >>> processing those documents the program should be using the >>> appropriate Chinese Locale. >> Not true. > How else is the program going to understand the Chinese data? If someone gives me a file, they had better indicate the file format. > The fact that locale issues leak into data is the reason that the > single immutable global locale doesn't work. Locales don't work. Period. > You really want to imbue into data streams what locale their data > represents (and use that in some of the later processing of data from > that stream). Can you refer to a standard for that kind of imbuement? Of course, you have document types, schema definitions and other implicit and explicit format indicators. You shouldn't call them locales, though. >>> Data presented to the user should normally use his locale (unless he >>> has specified something different). >> Ok. Here's a value for you: >> >> 100??? >> >> I see '1', '0', '0', '???'. What do you see in your locale (LC_MONETARY)? > If I processed that on my system I would either get $100, or an error of > wrong currency symbol depending on the error checking. Don't forget to convert the amount as well... >> The single global is due to what the locale was introduced for. It >> came about around the time when Unix applications were being made >> "8-bit clean." Along with UCS-2 and XML, it's one of those things you >> wish you'd never have to deal with. > > Locale predates UCS-2, it was the early attempt to provide > internationalization to C code so even programmers who didn't think > about it could add the line setlocale(LC_ALL, "") and make their code > work at least mostly right in more places. A single global was quick > and simple, and since threads didn't exist, not an issue. > > In many ways it was the first attempt that should have been thrown > away, but got too intertwined. C++ made a significant improvement to > it by having streams remember their own locale. Noone should breathe any new life into locales. And yes, add C++ to the list of things you wish you'd never have to deal with... Marko -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From ben.usenet at bsb.me.uk Sat Jun 23 18:25:55 2018 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Sat, 23 Jun 2018 23:25:55 +0100 Subject: Static variables [was Re: syntax difference] References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <2iyXC.494652$Vs7.246701@fx41.am4> Message-ID: <876029qgwc.fsf@bsb.me.uk> Bart writes: > On 23/06/2018 21:13, Chris Angelico wrote: >> On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: > >>> (At what point would that happen anyway; if you do this: > >> NONE of your examples are taking copies of the function. They all are >> making REFERENCES to the same function. That is all. > > This is about your notion that invocations of the same function via > different references, should maintain their own versions of the > function's 'static' data. > > Since these references are created via the return g statement here: > > def f(): > def g(): > .... > return g > > (say to create function references i and j like this: > > i = f() > j = f() > ) > > I'm assuming that something special must be happening. Otherwise, how > does f() know which reference it's being called via? > > What is different, what extra bit of information is provided when f() > is invoked via i() or j()? f is not being invoked by either i() or j(). i = f() binds i to the function returned by f. That's a newly minted function. In languages like Python, executing def creates a function. In your example, i and j refer to different functions. If the function temporarily named g has "own" variables ("static" in C), then each such function should have its own. That was the point of the example much further up. The effect can simulated like this: def make_counter(): def c(): c.x += 1 return c.x c.x = 0 return c i = make_counter() j = make_counter() print(i(), i(), j(), i()) -- Ben. From bc at freeuk.com Sat Jun 23 18:26:43 2018 From: bc at freeuk.com (Bart) Date: Sat, 23 Jun 2018 23:26:43 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: On 23/06/2018 20:52, boB Stepp wrote: > I've finally found time to examine this rather long, rambling thread. >> There is a place for various levels of programming language. I'm saying that Python which is always touted as a 'simple' language suitable for beginners, is missing a surprising number of basics. > I still feel like a rank beginner, but on the Tutor list some > disagree. The first programming exercise I ever did involved asking for three numbers, then determining whether those numbers could form the sides of a triangle. Then [40 years ago], the easy part was reading the three numbers. Now that would be the more challenging part. This is one of the basics that is missing. Getting around it is not hard, but it's some messing about and it's a distraction. But 40 years ago it was just 'readln a,b,c'; it was just taken for granted. (It make seem quaint in these days of GUIs, gestures, and voice recognition to be reading a line at a time, but you will need it still for text file i/o.) > Anyway, so far Python has not lacked for anything I have needed so > far. I'd be surprised if Python lacked anything; there can't be anything that someone has thought of that is either built-in or bolted on, if not always that elegantly or that efficiently. However, imagine having to use a language which didn't have assignments as you are used to, and that you would expect to exist. Then you might well remark that it's missing something that you regard as a basic, while the proponents of that language point out that it doesn't stop you writing programs; it just needs a different approach. (I believe that you can write any program using just IF-GOTO statements and ASSIGNMENT statements, and no other flow control (given suitable data-types and means of I/O). But if you wanted to try out an interesting experiment along those lines (eg. transcribe any flowchart to code), a large number of languages, including Python, make it hard because 'goto' is missing.) > All I can say is I have yet to find much at all in Python cumbersome > or bewildering. No? How many ways are there in Python, including third party add-ons, of working with record-like objects? > As an aside to Bart, if you strongly feel that Python is missing a > really useful feature, then why don't you do the usual thing, start a > very specific thread about just that feature (Not just a collection of > things you like in one of your languages.), and if you manage to > persuade the community of its usefulness, then write up a PEP about > it? Just saying ... ~(:>)) I'm not a user. My interest is in design and implementation, especially of interpreters, and especially of efficient ones. A lot of things that Python could do with are made very difficult by the existing design of that language. Being so dynamic has a lot to answer for. So I don't envy the job of the people who really have to move the language forward. That doesn't mean I can't argue with people who say that Python doesn't really need (say) Switch. (I guess the Blub paradox works both ways...) -- bart From bart at 1 Sat Jun 23 18:43:56 2018 From: bart at 1 (Bart) Date: Sat, 23 Jun 2018 17:43:56 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B2FCDF9.20908.uclanpyth@castlerockbbs.com> References: <5B2FCDF9.20908.uclanpyth@castlerockbbs.com> Message-ID: <5B2FCDF9.20927.uclanpyth@castlerockbbs.com> To: Stefan Ram From: Bart On 23/06/2018 14:32, Stefan Ram wrote: > ram at zedat.fu-berlin.de (Stefan Ram) writes: >> def f(): >> def g(): >> g.x += 1 >> return g.x >> g.x = 0 >> return g > > Or, "for all g to share the same x": > > main.py > > def f(): > def g(): > f.x += 1 > return f.x > return g > f.x = 0 OK, problem solved: we just use attributes of function objects rather than locally static variables (I didn't even know that was possible). These apparently can be created, accessed and modified from anywhere in the program. The only provisos are that functions with 'static' must be written as nested functions and the name of the function must be returned via the enclosing function in some setup code. The initialising of the static is showed as happening in global space in your example, but may be possible to move that to the enclosing function. (For example, when the static data is a local table.) However, here's a reminder of what the feature looks like implemented properly: def g() static x = 0 x += 1 return x print (g()) No set up of g needed. 'static' can be added to any existing function without changing how its used. And it can be removed without having to dismantled all the extra machinery. /And/ the access to x inside g() can be a fast local lookup not an attribute lookup (unless implemented on top of global variables). -- bart --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bart at 1 Sat Jun 23 18:43:56 2018 From: bart at 1 (Bart) Date: Sat, 23 Jun 2018 17:43:56 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B324678.21123.uclanpyth@castlerockbbs.com> References: <5B324678.21123.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21125.uclanpyth@castlerockbbs.com> To: Stefan Ram From: "Bart" To: Stefan Ram From: Bart On 23/06/2018 14:32, Stefan Ram wrote: > ram at zedat.fu-berlin.de (Stefan Ram) writes: >> def f(): >> def g(): >> g.x += 1 >> return g.x >> g.x = 0 >> return g > > Or, "for all g to share the same x": > > main.py > > def f(): > def g(): > f.x += 1 > return f.x > return g > f.x = 0 OK, problem solved: we just use attributes of function objects rather than locally static variables (I didn't even know that was possible). These apparently can be created, accessed and modified from anywhere in the program. The only provisos are that functions with 'static' must be written as nested functions and the name of the function must be returned via the enclosing function in some setup code. The initialising of the static is showed as happening in global space in your example, but may be possible to move that to the enclosing function. (For example, when the static data is a local table.) However, here's a reminder of what the feature looks like implemented properly: def g() static x = 0 x += 1 return x print (g()) No set up of g needed. 'static' can be added to any existing function without changing how its used. And it can be removed without having to dismantled all the extra machinery. /And/ the access to x inside g() can be a fast local lookup not an attribute lookup (unless implemented on top of global variables). -- bart -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From richard.damon at 1 Sat Jun 23 18:52:54 2018 From: richard.damon at 1 (Richard Damon) Date: Sat, 23 Jun 2018 17:52:54 -0500 Subject: translating foreign data Message-ID: <5B30F4ED.20974.uclanpyth@castlerockbbs.com> From: Richard Damon On 6/23/18 5:31 PM, Ben Finney wrote: > Richard Damon writes: > >> On 6/23/18 11:27 AM, Steven D'Aprano wrote: >>>> On 6/23/18 9:05 AM, Marko Rauhamaa wrote: >>>>> Richard Damon wrote: >>>>>> Data presented to the user should normally use his locale >>>>>> (unless he has specified something different). >>>>> Ok. Here's a value for you: >>>>> >>>>> 100??? >>>>> >>> [? |] >>> The data you were given was 100 Euros. If your system is incapable >>> of reading that as 100 Euros, and errors out, then at least to know >>> that it is brain-damaged and useless. >>> >>> But if instead it silently changes the data to $100 (US dollars? >>> Australian dollars? Zimbabwe dollars? the gods only know what a >>> system that broken might do...) then it is not only broken but >>> *dangerously* broken. >>> >> [? |] >> >> The number CAN'T say 100 Euros (can you give me what bit pattern you >> would use for such a number). > That is (I believe) the point being made: The data is *not* a number. It > is a value that must encapsulate more than only the number 100, but also > and simultaneously the curency ? ?Euro? ?. If you have more than just a number representing a value in the locale currency, you can't ask the locale how to present/accept it. > >> The currency is encoded in the locale used for the conversion, so if it >> is using en-US, the currency value would ALWAYS be US$ (which the >> general locale format is just $). As such 100??? is an invalid input to a >> system getting a Locale based input for a currency if the locale is not >> one from a country that uses the euro. > The value is 100 Euro, a quantity of a particular currency and not > something trivially converted to US$ (for many reasons, including the > obvious one that we don't know the exact exchange rate to use, and it > will be different at a different time). > > You appear to be arguing that this value must either be arbitrarily > converted to the user's local currency, something we agree is impossible > to do given the data, or the value is simply invalid. > > So the rule you assert ? ? ? ?Data presented to the user should normally use > his locale? ? ? ? fails to usefuly handle the very normal case of data that > represents a quantity of some foreign currency. Any system following > your asserted rule will give either the wrong answer, or an error. We > had better hope the rule you assert is not in effect. > If the user wants to talk in Euro using software that uses locales, then he should specify a locale that uses Euros. If you have a field to enter a foreign currency, then you can NOT make that a LC_CURRENCY field, or you need to make that field use a different locale than the local locale. This isn't the fault of locales, but in a misuse of the system. This original question came when it was asked what do I see with 100??? in MY locale LC_CURRENCY, well MY locale doesn't have a LC_CURRENCY that is euros, so it can't express that. It is a bit like asking how to draw a circle with 4 straight lines or get to the moon in a boat. It is a question with an improper premise. -- Richard Damon --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From mrab at 1 Sat Jun 23 19:29:50 2018 From: mrab at 1 (MRAB) Date: Sat, 23 Jun 2018 18:29:50 -0500 Subject: Static variables [was Re: syntax difference] Message-ID: <5B2FCDF9.20928.uclanpyth@castlerockbbs.com> From: MRAB On 2018-06-23 05:16, Chris Angelico wrote: > On Sat, Jun 23, 2018 at 1:51 PM, Steven D'Aprano > wrote: >> On Wed, 20 Jun 2018 14:18:19 +1000, Chris Angelico wrote: >> >>> Ah. Yeah, that would be a plausible feature to add to Python. But in C, >>> a static variable is basically the same thing as a global variable, >>> except that its name is scoped to the function. There is only one of it. >>> What happens in Python? For instance: >>> >>> def f(): >>> def g(): >>> static x = 0 >>> x += 1 >>> return x >>> return g >>> >>> Does the static variable exist once for each instance of g()? If so, >>> it'll behave like a closure variable; if not, it'll behave like a >>> global. Either way, I'm pretty much certain that people will expect the >>> other. >> >> Yes, but given the normal execution model of Python, only one solution is >> valid. Since the function g is created fresh each time f is called, each >> one gets a fresh static x. >> >> If you want all the g's to share the same x, you would write: >> >> def f(): >> static x = 0 >> def g(): >> x += 1 >> return x >> return g >> >> >> In this case, every invocation of f shares the same static x, and all the >> g's refer to that same x, using the ordinary closure mechanism. In the >> earlier case, each invocation of f creates a brand new g with its own x. >> >> Simple and elegant. >> >> This could at last get rid of that useful but ugly idiom: >> >> def function(real, arguments, len=len, int=int, str=str): >> ... >> >> if we allowed the "static" declaration to access the values from the >> surrounding scope: >> >> def function(real, arguments): >> static len=len, int=int, str=str >> >> But I think nicer than that would be a decorator: >> >> @static(len=len, int=int, str=str) >> def function(real, arguments): >> ... >> >> which adds local variables len, int, str to the function, with the given >> values, and transforms all the bytecode LOAD_NAME len to LOAD_FAST len >> (or whatever). >> >> (We might need a new bytecode to SET_STATIC.) >> >> That would be a nice bytecode hack to prove the usefulness of the concept! >> > > Okay, that makes sense. So in a way, static variables would be like > closure variables with an invisible outer function. These would be > roughly equivalent: > > def f(): > static x = 0 > x += 1 > return x > You can already do something similar like this: def f(): f.x += 1 return f.x f.x = 0 [snip] --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From stefan.ram at 1 Sat Jun 23 19:33:24 2018 From: stefan.ram at 1 (Stefan Ram) Date: Sat, 23 Jun 2018 18:33:24 -0500 Subject: translating foreign data In-Reply-To: <5B2FCDF9.20926.uclanpyth@castlerockbbs.com> References: <5B2FCDF9.20926.uclanpyth@castlerockbbs.com> Message-ID: <5B2FCDF9.20931.uclanpyth@castlerockbbs.com> To: Richard Damon From: ram at zedat.fu-berlin.de (Stefan Ram) Richard Damon writes: >Now, if I have a parser that doesn't use the locale, but some other rule >base than I just need to provide it with the right rules, which is >basically just defining the right locale. Here's an example C++ program I wrote. It uses the class s to provide rules for an ad hoc locale which then is used to imbue a temporary string stream which then can parse numbers using the thousands separator given by s. main.cpp #include #include #include #include #include using namespace ::std::literals; struct s : ::std::numpunct< char > { char do_thousands_sep() const override { return ','; } ::std::string do_grouping() const override { return "\3"; }}; static double double_value_of( ::std::string const & string ) { ::std::stringstream source { string }; source.imbue( ::std::locale( source.getloc(), new s )); double number; source >> number; return number; } int main() { ::std::cout << double_value_of( "4,800.1"s )<< '\n'; ::std::cout << double_value_of( "3,334.5e9"s )<< '\n'; } transcript 4800.1 3.3345e+012 --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From stefan.ram at 1 Sat Jun 23 19:33:24 2018 From: stefan.ram at 1 (Stefan Ram) Date: Sat, 23 Jun 2018 18:33:24 -0500 Subject: translating foreign data Message-ID: <5B324678.21126.uclanpyth@castlerockbbs.com> To: Richard Damon From: "Stefan Ram" To: Richard Damon From: ram at zedat.fu-berlin.de (Stefan Ram) Richard Damon writes: >Now, if I have a parser that doesn't use the locale, but some other rule >base than I just need to provide it with the right rules, which is >basically just defining the right locale. Here's an example C++ program I wrote. It uses the class s to provide rules for an ad hoc locale which then is used to imbue a temporary string stream which then can parse numbers using the thousands separator given by s. main.cpp #include #include #include #include #include using namespace ::std::literals; struct s : ::std::numpunct< char > { char do_thousands_sep() const override { return ','; } ::std::string do_grouping() const override { return "\3"; }}; static double double_value_of( ::std::string const & string ) { ::std::stringstream source { string }; source.imbue( ::std::locale( source.getloc(), new s )); double number; source >> number; return number; } int main() { ::std::cout << double_value_of( "4,800.1"s )<< '\n'; ::std::cout << double_value_of( "3,334.5e9"s )<< '\n'; } transcript 4800.1 3.3345e+012 -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bc at freeuk.com Sat Jun 23 19:37:36 2018 From: bc at freeuk.com (Bart) Date: Sun, 24 Jun 2018 00:37:36 +0100 Subject: Static variables [was Re: syntax difference] In-Reply-To: <876029qgwc.fsf@bsb.me.uk> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <2iyXC.494652$Vs7.246701@fx41.am4> <876029qgwc.fsf@bsb.me.uk> Message-ID: <4RAXC.526241$sl2.501394@fx46.am4> On 23/06/2018 23:25, Ben Bacarisse wrote: > Bart writes: > >> On 23/06/2018 21:13, Chris Angelico wrote: >>> On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: >> >>>> (At what point would that happen anyway; if you do this: >> >>> NONE of your examples are taking copies of the function. They all are >>> making REFERENCES to the same function. That is all. >> >> This is about your notion that invocations of the same function via >> different references, should maintain their own versions of the >> function's 'static' data. >> >> Since these references are created via the return g statement here: >> >> def f(): >> def g(): >> .... >> return g >> >> (say to create function references i and j like this: >> >> i = f() >> j = f() >> ) >> >> I'm assuming that something special must be happening. Otherwise, how >> does f() know which reference it's being called via? >> >> What is different, what extra bit of information is provided when f() >> is invoked via i() or j()? > > f is not being invoked by either i() or j(). i = f() binds i to the > function returned by f. That's a newly minted function. In languages > like Python, executing def creates a function. Do you mean that if the same 'def' block is re-executed, it will create a different instance of the function? (Same byte-code, but a different set of everything else the function uses.) Wow. (Just think of all the times you write a function containing a neat bunch of local functions, every time it's called it has to create a new function instances for each of those functions, even if they are not used.) Anyway just for regular statics, the following appears to work. Not ideal, but simpler than some alternatives: def f(): if not hasattr(f,'x'): f.x=0 f.x += 1 return f.x -- bart. From rosuav at gmail.com Sat Jun 23 19:42:12 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jun 2018 09:42:12 +1000 Subject: Static variables [was Re: syntax difference] In-Reply-To: <4RAXC.526241$sl2.501394@fx46.am4> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <2iyXC.494652$Vs7.246701@fx41.am4> <876029qgwc.fsf@bsb.me.uk> <4RAXC.526241$sl2.501394@fx46.am4> Message-ID: On Sun, Jun 24, 2018 at 9:37 AM, Bart wrote: > On 23/06/2018 23:25, Ben Bacarisse wrote: >> >> Bart writes: >> >>> On 23/06/2018 21:13, Chris Angelico wrote: >>>> >>>> On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: >>> >>> >>>>> (At what point would that happen anyway; if you do this: >>> >>> >>>> NONE of your examples are taking copies of the function. They all are >>>> making REFERENCES to the same function. That is all. >>> >>> >>> This is about your notion that invocations of the same function via >>> different references, should maintain their own versions of the >>> function's 'static' data. >>> >>> Since these references are created via the return g statement here: >>> >>> def f(): >>> def g(): >>> .... >>> return g >>> >>> (say to create function references i and j like this: >>> >>> i = f() >>> j = f() >>> ) >>> >>> I'm assuming that something special must be happening. Otherwise, how >>> does f() know which reference it's being called via? >>> >>> What is different, what extra bit of information is provided when f() >>> is invoked via i() or j()? >> >> >> f is not being invoked by either i() or j(). i = f() binds i to the >> function returned by f. That's a newly minted function. In languages >> like Python, executing def creates a function. > > > Do you mean that if the same 'def' block is re-executed, it will create a > different instance of the function? (Same byte-code, but a different set of > everything else the function uses.) > > Wow. (Just think of all the times you write a function containing a neat > bunch of local functions, every time it's called it has to create a new > function instances for each of those functions, even if they are not used.) ... do you even understand what closures are? ChrisA From abdur-rahmaan.janhangeer at 1 Sat Jun 23 19:44:08 2018 From: abdur-rahmaan.janhangeer at 1 (Abdur-Rahmaan Janhangeer) Date: Sat, 23 Jun 2018 18:44:08 -0500 Subject: "Data blocks" syntax specification draft Message-ID: <5B2FCDF9.20913.uclanpyth@castlerockbbs.com> From: Abdur-Rahmaan Janhangeer the tab separated idea is used in : e.g. see last section of files Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > > --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bob.stepp at 1 Sat Jun 23 19:44:50 2018 From: bob.stepp at 1 (boB Stepp) Date: Sat, 23 Jun 2018 18:44:50 -0500 Subject: syntax difference Message-ID: <5B30F4ED.20979.uclanpyth@castlerockbbs.com> From: boB Stepp On Sat, Jun 23, 2018 at 5:35 PM Bart wrote: > > On 23/06/2018 20:52, boB Stepp wrote: > The first programming exercise I ever did involved asking for three > numbers, then determining whether those numbers could form the sides of > a triangle. > > Then [40 years ago], the easy part was reading the three numbers. Now > that would be the more challenging part. > > This is one of the basics that is missing. Getting around it is not > hard, but it's some messing about and it's a distraction. But 40 years > ago it was just 'readln a,b,c'; it was just taken for granted. I don't think there are any *basics* missing. One of the differences between then and now is that trying to live in a simpler ASCII/extended ASCII world is no longer possible. The Internet and open source movements among other things have brought in more (most?) of the world as participants in the programming endeavor. The many peoples of this world and their many, varied cultures is quite rich and complex, and they have real needs to express their thoughts as naturally as they can. I would contend that the basics are there, but the complexity of the data and ideas that need to be dealt with these days is what makes the programming journey more challenging but also more interesting than in the days of yore. When I first went to college in the seventies, it was all punch cards, main frames, a few minicomputers, time sharing IBM selectrics, etc. I would *not* want to go back to that! I find today's challenges and opportunities much more fascinating!! > > Anyway, so far Python has not lacked for anything I have needed so > > far. > > I'd be surprised if Python lacked anything; there can't be anything that > someone has thought of that is either built-in or bolted on, if not > always that elegantly or that efficiently. I am not qualified to speak to issues of Python's language design, but as a user of Python I have yet to be disappointed. But I imagine all languages, including yours, have accumulated cruft that in retrospect the creators would like to remove. But the difference, as far as I can tell, between your languages and Python is that Python has a huge number of active users with who knows how many LOC in production environments, but your languages do not. So you have the benefit, as their creator and essentially sole user, to keep polishing and refining your ideas. The Python devs don't have that luxury. But they are obviously, even to me, constantly not only adding new functionality, but trying to minimize the cruft as best they can without compromising people's production code. I imagine that the transition from version 2 to 3 was not undertaken halfheartedly, but only after much thought and discussion since it did break backwards compatibility. But now having used both Python 2 (Which I still have to code in at work.) and 3, even I with my limited knowledge and capabilities appreciate the positive benefits of the changes. > However, imagine having to use a language which didn't have assignments > as you are used to, and that you would expect to exist. Then you might > well remark that it's missing something that you regard as a basic, > while the proponents of that language point out that it doesn't stop you > writing programs; it just needs a different approach. But the beauty of things as they are today, is that if someone has thought of it, it is probably accessible and available to use. Not only that, but one can cruise through the many different programming languages and see what others have imagined and thought to be useful and grow one's knowledge and insight much more easily than ever before. And if I have a need that Python or any other language I use does not address, I can surely find one online. > (I believe that you can write any program using just IF-GOTO statements > and ASSIGNMENT statements, and no other flow control (given suitable > data-types and means of I/O). But if you wanted to try out an > interesting experiment along those lines (eg. transcribe any flowchart > to code), a large number of languages, including Python, make it hard > because 'goto' is missing.) I have done the "GOTO" thing ages ago. I would not want to go back to that bad place. There are too many better alternatives now for flow control. With today's hardware I don't think any benefit from any theoretical optimizations would be of any benefit in practice. As a person who does not have much time for studying and writing programs, I have a hard enough time understanding what I wrote after a break from programming. I would not want to put any more stumbling blocks in my code for later maintainability, not to imagine having to do so for other people's code. > > All I can say is I have yet to find much at all in Python cumbersome > > or bewildering. > > No? How many ways are there in Python, including third party add-ons, of > working with record-like objects? If I am understanding you correctly by your reference to "record-like objects", again it isn't a problem of lacking basics in Python, but it is in the complexity of real data structures that modern programming must deal with. And again, with the types of record-like objects I have had to deal with, Python's standard library has proved more than sufficient. > > As an aside to Bart, if you strongly feel that Python is missing a > > really useful feature, then why don't you do the usual thing, start a > > very specific thread about just that feature (Not just a collection of > > things you like in one of your languages.), and if you manage to > > persuade the community of its usefulness, then write up a PEP about > > it? Just saying ... ~(:>)) > > I'm not a user... Then I am truly puzzled, Bart. Why do you even bother to hang out on this list? If you do not want to use Python and you do not want to improve Python's design and implementation, what is your point of being here? You *do* seem to generate a lot of ill will, I hope unintentionally. But why not take a different, more helpful tack? You seem to have a lot of ideas. If you really think they are applicable to improving the Python language, why not take your ideas, one at a time, and have serious discussion, perhaps better on Python-Ideas, on how Python can be meaningfully made better? That would be a helpful approach which I think, if done with the intention of helping Python to be the best language it can be (Within the constraints it has to operate within in practice.), then I would hope your potential contributions would be positively received by the community. But as it stands, you seem to adopt the role of a naysayer and critic without offering anything positive to the community. And of course, you would have to know how to use Python properly in idiomatic style. Why not choose this positive approach? I think it would be a win-win for both you and Python. -- boB --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From robertvstepp at gmail.com Sat Jun 23 19:44:51 2018 From: robertvstepp at gmail.com (boB Stepp) Date: Sat, 23 Jun 2018 18:44:51 -0500 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: On Sat, Jun 23, 2018 at 5:35 PM Bart wrote: > > On 23/06/2018 20:52, boB Stepp wrote: > The first programming exercise I ever did involved asking for three > numbers, then determining whether those numbers could form the sides of > a triangle. > > Then [40 years ago], the easy part was reading the three numbers. Now > that would be the more challenging part. > > This is one of the basics that is missing. Getting around it is not > hard, but it's some messing about and it's a distraction. But 40 years > ago it was just 'readln a,b,c'; it was just taken for granted. I don't think there are any *basics* missing. One of the differences between then and now is that trying to live in a simpler ASCII/extended ASCII world is no longer possible. The Internet and open source movements among other things have brought in more (most?) of the world as participants in the programming endeavor. The many peoples of this world and their many, varied cultures is quite rich and complex, and they have real needs to express their thoughts as naturally as they can. I would contend that the basics are there, but the complexity of the data and ideas that need to be dealt with these days is what makes the programming journey more challenging but also more interesting than in the days of yore. When I first went to college in the seventies, it was all punch cards, main frames, a few minicomputers, time sharing IBM selectrics, etc. I would *not* want to go back to that! I find today's challenges and opportunities much more fascinating!! > > Anyway, so far Python has not lacked for anything I have needed so > > far. > > I'd be surprised if Python lacked anything; there can't be anything that > someone has thought of that is either built-in or bolted on, if not > always that elegantly or that efficiently. I am not qualified to speak to issues of Python's language design, but as a user of Python I have yet to be disappointed. But I imagine all languages, including yours, have accumulated cruft that in retrospect the creators would like to remove. But the difference, as far as I can tell, between your languages and Python is that Python has a huge number of active users with who knows how many LOC in production environments, but your languages do not. So you have the benefit, as their creator and essentially sole user, to keep polishing and refining your ideas. The Python devs don't have that luxury. But they are obviously, even to me, constantly not only adding new functionality, but trying to minimize the cruft as best they can without compromising people's production code. I imagine that the transition from version 2 to 3 was not undertaken halfheartedly, but only after much thought and discussion since it did break backwards compatibility. But now having used both Python 2 (Which I still have to code in at work.) and 3, even I with my limited knowledge and capabilities appreciate the positive benefits of the changes. > However, imagine having to use a language which didn't have assignments > as you are used to, and that you would expect to exist. Then you might > well remark that it's missing something that you regard as a basic, > while the proponents of that language point out that it doesn't stop you > writing programs; it just needs a different approach. But the beauty of things as they are today, is that if someone has thought of it, it is probably accessible and available to use. Not only that, but one can cruise through the many different programming languages and see what others have imagined and thought to be useful and grow one's knowledge and insight much more easily than ever before. And if I have a need that Python or any other language I use does not address, I can surely find one online. > (I believe that you can write any program using just IF-GOTO statements > and ASSIGNMENT statements, and no other flow control (given suitable > data-types and means of I/O). But if you wanted to try out an > interesting experiment along those lines (eg. transcribe any flowchart > to code), a large number of languages, including Python, make it hard > because 'goto' is missing.) I have done the "GOTO" thing ages ago. I would not want to go back to that bad place. There are too many better alternatives now for flow control. With today's hardware I don't think any benefit from any theoretical optimizations would be of any benefit in practice. As a person who does not have much time for studying and writing programs, I have a hard enough time understanding what I wrote after a break from programming. I would not want to put any more stumbling blocks in my code for later maintainability, not to imagine having to do so for other people's code. > > All I can say is I have yet to find much at all in Python cumbersome > > or bewildering. > > No? How many ways are there in Python, including third party add-ons, of > working with record-like objects? If I am understanding you correctly by your reference to "record-like objects", again it isn't a problem of lacking basics in Python, but it is in the complexity of real data structures that modern programming must deal with. And again, with the types of record-like objects I have had to deal with, Python's standard library has proved more than sufficient. > > As an aside to Bart, if you strongly feel that Python is missing a > > really useful feature, then why don't you do the usual thing, start a > > very specific thread about just that feature (Not just a collection of > > things you like in one of your languages.), and if you manage to > > persuade the community of its usefulness, then write up a PEP about > > it? Just saying ... ~(:>)) > > I'm not a user... Then I am truly puzzled, Bart. Why do you even bother to hang out on this list? If you do not want to use Python and you do not want to improve Python's design and implementation, what is your point of being here? You *do* seem to generate a lot of ill will, I hope unintentionally. But why not take a different, more helpful tack? You seem to have a lot of ideas. If you really think they are applicable to improving the Python language, why not take your ideas, one at a time, and have serious discussion, perhaps better on Python-Ideas, on how Python can be meaningfully made better? That would be a helpful approach which I think, if done with the intention of helping Python to be the best language it can be (Within the constraints it has to operate within in practice.), then I would hope your potential contributions would be positively received by the community. But as it stands, you seem to adopt the role of a naysayer and critic without offering anything positive to the community. And of course, you would have to know how to use Python properly in idiomatic style. Why not choose this positive approach? I think it would be a win-win for both you and Python. -- boB From ben.usenet at bsb.me.uk Sat Jun 23 20:53:59 2018 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Sun, 24 Jun 2018 01:53:59 +0100 Subject: Static variables [was Re: syntax difference] References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <2iyXC.494652$Vs7.246701@fx41.am4> <876029qgwc.fsf@bsb.me.uk> <4RAXC.526241$sl2.501394@fx46.am4> Message-ID: <87tvptovh4.fsf@bsb.me.uk> Bart writes: > On 23/06/2018 23:25, Ben Bacarisse wrote: >> Bart writes: >> >>> On 23/06/2018 21:13, Chris Angelico wrote: >>>> On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: >>> >>>>> (At what point would that happen anyway; if you do this: >>> >>>> NONE of your examples are taking copies of the function. They all are >>>> making REFERENCES to the same function. That is all. >>> >>> This is about your notion that invocations of the same function via >>> different references, should maintain their own versions of the >>> function's 'static' data. >>> >>> Since these references are created via the return g statement here: >>> >>> def f(): >>> def g(): >>> .... >>> return g >>> >>> (say to create function references i and j like this: >>> >>> i = f() >>> j = f() >>> ) >>> >>> I'm assuming that something special must be happening. Otherwise, how >>> does f() know which reference it's being called via? >>> >>> What is different, what extra bit of information is provided when f() >>> is invoked via i() or j()? >> >> f is not being invoked by either i() or j(). i = f() binds i to the >> function returned by f. That's a newly minted function. In languages >> like Python, executing def creates a function. > > Do you mean that if the same 'def' block is re-executed, it will > create a different instance of the function? (Same byte-code, but a > different set of everything else the function uses.) Logically, yes. > Wow. (Just think of all the times you write a function containing a > neat bunch of local functions, every time it's called it has to create > a new function instances for each of those functions, even if they are > not used.) I am surprised that this surprises you, and equally surprised that you seem to think it's going to be in some way grossly inefficient. -- Ben. From peter.j..holzer at 1 Sat Jun 23 21:09:08 2018 From: peter.j..holzer at 1 (Peter J. Holzer) Date: Sat, 23 Jun 2018 20:09:08 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20929.uclanpyth@castlerockbbs.com> From: "Peter J. Holzer" --b2wbudmypdkmv7il Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2018-06-23 12:11:34 -0400, Richard Damon wrote: > On 6/23/18 10:05 AM, Peter J. Holzer wrote: > > On 2018-06-23 08:41:38 -0400, Richard Damon wrote: > >> Once you open the Locale can of worms, EVERYTHING has a locale, to say > >> you aren't using a locale is to say you are writing > >> something unintelligible, as you can thing of the locale as the set of > >> rules to interpret > > I don't think that's a useful way to look at it. "Locale" in > > (non-technical) English means "place" or "site". The idea behind the > > locale concept is that some conventions (e.g. how to write numbers or > > how to write strings) depend on the place where the program runs (or > > maybe where the user is sitting or grew up or maybe where a file was > > produced). > > > > For stuff which doesn't depend on the place (e.g. how a Python program > > should be parsed), the locale concept doesn't apply. > > > The Locale should NOT be the place the computer is running in (at least > not anymore), but where the data and the user are from (which can be > different). Yes, it can be different, but for some *very* common cases (PCs, smartphones most of the time) it isn't. More imporantly for the concept, when the concept was developed (in the late 1980's) is was very common (probably more common than 10 years earlier). > Do your really mean that when I travel to a place that uses > . as the thousands separator and , as the decimal separator (instead of > my normal environment when they are the other way around) all my > programs should immediately change how they read all my data files and > how I need to enter data? I hope not. Sometimes, yes. If you want to work with your colleagues at that place they might thank you to use the local conventions. > I want my computer to use the Locale of where "I" came from (not > current am) to talk to me, That's why I wrote "or grew up". > and to be able to set the Locale to interpret data to match the rules > the person who generated them used to generate them, And that's why I wrote "where a file was produced". So many words to repeat what I already wrote ... > so if they swap . and , compared to me, I can tell the program that. > Your last parenthetical comment in the first paragraph is my key > point, I think it is the weakest point. The locale is useful for interactive use (input and output) and also for output intended for human users. For parsing files it is woefully inadequate (also for generating files intended to be parsed). > the locale used to read data should match the locale used to generate > it, and that can easily be different than the locale being used to > interact with the user. Which is basically why "locale" is a rather useless concept with files. When I get a CSV file, I don't want to say "use locale en_US.cp437", because the location "US" is almost completely irrelevant, the language "English" is somewhat relevant but much too specific", and the list separator isn't there at all. I want to tell it: Decode using CP437, a decimal point, tabs as a list separator, CRLF as the record separator, no quoting. > If a program doesn't care about the locale it is running in, like a > Python compiler, the either it needs to use routines that totally ignore > the locale or it needs to set the locale to one that matches the rules > it wants. The former. Because locales are in general opaque, so you can never be sure that a given locale will use the rules you want ("C" is the exception, but not very useful). hp --=20 _ | 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 --b2wbudmypdkmv7il Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAlsujL8ACgkQ8g5IURL+ KF0dVxAAryd5Ew15J/aco4xdLAa+EGzIwFKoPQjIb90C4vbIXCbmrVwVYmbJN/yK J9AhrnUoyipGbK2IMamCUpCp7XVfkCgnMvGmf8ZFeflwaw5NCJLvv42JqAgl+lUP I1H/hEz/RoR8NFRWGseXGmTSt6KMwAUJjdDzK5eQru25U0vxTPkGmXLXE8wqmynA lft/CbsPy374Dda99033UJpG9QDZubmhfnt8j4xuHX0u8ZJmY7LJWGQ+zt06RtP1 RA7m+IxyKRRLlRiVSoS5XslRMKSEGfUhqt+jYjVASE5nOgtPPmQswjpKb3fzTJ13 wVCQJGKTu9mOO7xPwhxms8bKBegxjDbrGF0G8FJYW/ty/brItUkhhtb+Z7Pkj1iq d4xKRBQmux0tz5/kdFFUkz0u9CpFfB0+pzHGfK1edsAGh+lwzN2KgNcBff6H+5FL er+FZ1HbicXecq2XgTgpq8UYdHeANQI5yMEPjrCiHG4ybZ9T+bVanayji1vC2xqC DNZ7cWGTFz5AtSDC1fgRupG6ZX5BK/kZjdQz8Hx0AdgW1i4fKu28/giz6mbB+NnC XgcyXRjj1Jr3aCThjaZ7bq5dYwLzZKNLRQ3shnJE+Tfm3HfvDjvw5Wqf3lOIkcaQ Wf40K7bivvEZfdZzy/QkmtHjevVutrMZclj/e3NXPevBTWle6eI= =W2Ut -----END PGP SIGNATURE----- --b2wbudmypdkmv7il-- --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From peter.j..holzer at 1 Sat Jun 23 21:12:30 2018 From: peter.j..holzer at 1 (Peter J. Holzer) Date: Sat, 23 Jun 2018 20:12:30 -0500 Subject: translating foreign data Message-ID: <5B2FCDF9.20930.uclanpyth@castlerockbbs.com> From: "Peter J. Holzer" --ngg56dmsr6vcxzs5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2018-06-23 12:41:33 -0400, Richard Damon wrote: > On 6/23/18 11:44 AM, Steven D'Aprano wrote: > > You're assuming that there will be a misinterpretation. That's an absur= d=20 > > assumption to make. There might be, of course, but the documentation fo= r=20 > > my document might be clear that comma is to be used for decimal=20 > > separators. Or it might include numbers like > > > > 1.234.567,012345678 > > > > which is understandable to anyone who is aware of the possibility that= =20 > > comma may mean decimal separator and period the thousands separator. > > > Then I shouldn't be using en-AU to decode the file. Quite right, You shouldn't. > Now, if I have a parser that doesn't use the locale, but some other rule > base than I just need to provide it with the right rules, which is > basically just defining the right locale. Nope. The right rules for almost any file format are much more than the locale. hp --=20 _ | 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 --ngg56dmsr6vcxzs5 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAlsujY4ACgkQ8g5IURL+ KF1J7Q/+K7QhbxqE/4Q1jiCCFrU2OezQMwBAD7WXX60rk5gUzB2ubmz/X5VkUxVl E9dwfQTIYzfT2e3rCif75jxjWEi1i8J6diNSJdl4SZWrLOngCLtxKC/Ns9JB54wG NBUPwKwVMO+dYkXmiGz0RTQGfnQEqaPeHsWRj5uKLc7iFFQFHvSznasIUnhwRhLF /DDzEQW7tFM0eLJ8XKCydL0BInbXNMdhnQ9WSo/N287Fio2dbVpgjVd4bVBaMhJR 5UrrP3Nim9ZWsvN0uRk75lgRzQhID/unxCC3d6J54+83ma4nNpOoBOMyHcaeU9d0 pSSE5LOeQB3QwUKOBo7kzvcxm/abK+qwaZ9D54ex170DY5O54FWrmeo/3kEU+xMX BGXvn4DSfK4f6OcDExSWd6N0W1B5fxXxHqDiaDGPsDvlXT3Jc3OSD79FYc1LEh7z 6TAOy3VgOVmbF7M5DnSNPzEn2OTCGkIANf5C7zVS7GX/izki8H1Rk654yuhoZlBj F0ixIQb2mSxsiJnOyYUT8dTFuQYhXcbgRWUM24oTUb51QEdD3DragY+J5Fai+WJH QAZS4ryWjiQfvKtzhGYuAExHFA9IPpUS+qT2tLSpqY8sboow/jLt6oAzf8MNUl7j CB+A2jxMgrvGjfgCOPkP4Ruwix1jJ62O6AvSePOmQxta+svmydQ= =nEaJ -----END PGP SIGNATURE----- --ngg56dmsr6vcxzs5-- --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From greg.ewing at canterbury.ac.nz Sat Jun 23 21:58:59 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 24 Jun 2018 13:58:59 +1200 Subject: Static variables [was Re: syntax difference] In-Reply-To: <4RAXC.526241$sl2.501394@fx46.am4> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <2iyXC.494652$Vs7.246701@fx41.am4> <876029qgwc.fsf@bsb.me.uk> <4RAXC.526241$sl2.501394@fx46.am4> Message-ID: Bart wrote: > Wow. (Just think of all the times you write a function containing a neat > bunch of local functions, every time it's called it has to create a new > function instances for each of those functions, even if they are not used.) Fortunately, function objects are small and cheap, essentially just a couple of object references. The overhead of creating one is probably about the same as creating an empty list. If your function is complicated enough to benefit from local functions, the cost is going to be swamped by the rest of the work being done. -- Greg From steve+comp.lang.python at pearwood.info Sat Jun 23 22:23:36 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 02:23:36 +0000 (UTC) Subject: Static variables [was Re: syntax difference] References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <2iyXC.494652$Vs7.246701@fx41.am4> Message-ID: On Sat, 23 Jun 2018 21:44:00 +0100, Bart wrote: > Since these references are created via the return g statement here: > > def f(): > def g(): > .... > return g > > (say to create function references i and j like this: > > i = f() > j = f() > ) > > I'm assuming that something special must be happening. Otherwise, how > does f() know which reference it's being called via? You assume wrong. > What is different, what extra bit of information is provided when f() is > invoked via i() or j()? For somebody who has been using Python for a few years now, and is constantly telling us how we're doing it wrong, you sure are ignorant about the language and how it works. For somebody who has been programming for so long, you seem awfully unaware of how dynamic languages with first-class functions and closures work. No extra bit of information is provided. i refers to one function, j, refers to another function, and there is no overlap. Each invocation of f() results in a brand new function being created, dynamically, and assigned to the appropriate name. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sat Jun 23 22:35:27 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 02:35:27 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: On Sat, 23 Jun 2018 23:26:43 +0100, Bart wrote: > Then [40 years ago], the easy part was reading the three numbers. Now > that would be the more challenging part. # Get three numbers, separated by spaces, with no error-recovery. # If you try to read bad data, the process will fail. n1, n2, n3 = [float(s) for s in input("Enter three numbers: ").split()] No more verbose or difficult (certainly not "challenging") than: var: # need to declare these otherwise how will readln # know if it is reading floats or ints or strings? n1, n2, n3: float print("Enter three numbers: ") n1, n2, n3 = readln() If the use of a list comprehension is too advanced for a beginner in day one, how about this: n1 = float(input("Enter a number: ")) n2 = float(input("Enter a number: ")) n3 = float(input("Enter a number: ")) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From greg.ewing at canterbury.ac.nz Sat Jun 23 22:35:59 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 24 Jun 2018 14:35:59 +1200 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: Bart wrote: > But 40 years > ago it was just 'readln a,b,c'; it was just taken for granted. The problem with something like that is that it's really only useful for throwaway code. For any serious application, you need to deal with the possibility of malformed input, producing helpful diagnostics, etc. And often the input isn't going to be in such a uniform format that you know exactly what to expect next. So it's debable whether it's a good idea to put something with such limited applicability into the core language or standard library. Handling input well is fundamentally much more complicated than producing output. I don't think this is as "basic" as you make out. -- Greg From steve+comp.lang.python at pearwood.info Sat Jun 23 22:41:36 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 02:41:36 +0000 (UTC) Subject: Static variables [was Re: syntax difference] References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <2iyXC.494652$Vs7.246701@fx41.am4> <876029qgwc.fsf@bsb.me.uk> <4RAXC.526241$sl2.501394@fx46.am4> Message-ID: On Sun, 24 Jun 2018 00:37:36 +0100, Bart wrote: > Do you mean that if the same 'def' block is re-executed, it will create > a different instance of the function? (Same byte-code, but a different > set of everything else the function uses.) That's not as slow as you think it is. Everything that can be is pre- prepared and assembling them is pretty fast: py> import dis py> dis.dis(lambda x: lambda n: x*n) 1 0 LOAD_CLOSURE 0 (x) 3 BUILD_TUPLE 1 6 LOAD_CONST 1 ( at 0xb78b6430, file "", line 1>) 9 LOAD_CONST 2 ('..') 12 MAKE_CLOSURE 0 15 RETURN_VALUE How else can you get functions where the definition is not known until runtime, unless you assemble them at runtime? > Wow. (Just think of all the times you write a function containing a neat > bunch of local functions, every time it's called it has to create a new > function instances for each of those functions, even if they are not > used.) That's why Pascal-style static nested functions are hardly ever used in Python. 99% of nested functions are closures. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From bart at 1 Sat Jun 23 22:44:00 2018 From: bart at 1 (Bart) Date: Sat, 23 Jun 2018 21:44:00 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B30F4ED.20970.uclanpyth@castlerockbbs.com> References: <5B30F4ED.20970.uclanpyth@castlerockbbs.com> Message-ID: <5B30F4ED.20971.uclanpyth@castlerockbbs.com> To: Chris Angelico From: Bart On 23/06/2018 21:13, Chris Angelico wrote: > On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: >> (At what point would that happen anyway; if you do this: > NONE of your examples are taking copies of the function. They all are > making REFERENCES to the same function. That is all. This is about your notion that invocations of the same function via different references, should maintain their own versions of the function's 'static' data. Since these references are created via the return g statement here: def f(): def g(): .... return g (say to create function references i and j like this: i = f() j = f() ) I'm assuming that something special must be happening. Otherwise, how does f() know which reference it's being called via? What is different, what extra bit of information is provided when f() is invoked via i() or j()? -- bart --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bart at 1 Sat Jun 23 22:44:00 2018 From: bart at 1 (Bart) Date: Sat, 23 Jun 2018 21:44:00 -0500 Subject: Static variables [was Re: syntax difference] Message-ID: <5B324678.21164.uclanpyth@castlerockbbs.com> To: Chris Angelico From: "Bart" To: Chris Angelico From: Bart On 23/06/2018 21:13, Chris Angelico wrote: > On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: >> (At what point would that happen anyway; if you do this: > NONE of your examples are taking copies of the function. They all are > making REFERENCES to the same function. That is all. This is about your notion that invocations of the same function via different references, should maintain their own versions of the function's 'static' data. Since these references are created via the return g statement here: def f(): def g(): .... return g (say to create function references i and j like this: i = f() j = f() ) I'm assuming that something special must be happening. Otherwise, how does f() know which reference it's being called via? What is different, what extra bit of information is provided when f() is invoked via i() or j()? -- bart -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steve+comp.lang.python at pearwood.info Sat Jun 23 22:44:03 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 02:44:03 +0000 (UTC) Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <87h8ltiubl.fsf@elektro.pacujo.net> <8318150e-1f3c-eb97-d25c-475bddc6e223@Damon-Family.org> <87d0whirgc.fsf@elektro.pacujo.net> <1d713ce6-d8d8-110c-aa78-d7d672a024b9@Damon-Family.org> Message-ID: On Sat, 23 Jun 2018 17:05:17 -0400, Richard Damon wrote: > On 6/23/18 11:27 AM, Steven D'Aprano wrote: >> On Sat, 23 Jun 2018 09:42:29 -0400, Richard Damon wrote: >> >>> On 6/23/18 9:05 AM, Marko Rauhamaa wrote: >>>> Ok. Here's a value for you: >>>> >>>> 100? [...] > Locale based currency transformations are defined as a number to/from a > text string. > > The number CAN'T say 100 Euros (can you give me what bit pattern you > would use for such a number). You're joking, right? You can't possibly be so ignorant as to actually believe that. You have, right in front of you, a news post or email containing the text string "100?", and yet you are writing apparently in full seriousness that it is impossible to get that text string in a file. Okay, you want a bit-pattern. In hex: '0x313030e282ac' I'll leave the question of how I generated that as an exercise. (Hint: it was a one-liner, involving two method calls and a function call, all builtins in Python.) > The currency is encoded in the locale used for the conversion, so if it > is using en-US, the currency value would ALWAYS be US$ (which the > general locale format is just $). I cannot imagine for a second why you think any of this is even a tiny bit relevant to the question of how one should read a data file containing currency in Euro. You seem to have heard about the locale and decide it is the One True Hammer than all nails must be hammered with. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sat Jun 23 22:44:12 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 02:44:12 +0000 (UTC) Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <87h8ltiubl.fsf@elektro.pacujo.net> <8318150e-1f3c-eb97-d25c-475bddc6e223@Damon-Family.org> <87d0whirgc.fsf@elektro.pacujo.net> <1d713ce6-d8d8-110c-aa78-d7d672a024b9@Damon-Family.org> <857empdwb3.fsf@benfinney.id.au> <03814d57-08fd-dfef-8bb5-469140f5de0a@Damon-Family.org> Message-ID: On Sat, 23 Jun 2018 17:52:55 -0400, Richard Damon wrote: > If you have more than just a number representing a value in the locale > currency, you can't ask the locale how to present/accept it. You're the only one saying that it has to be handled by the locale. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sat Jun 23 22:53:49 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jun 2018 12:53:49 +1000 Subject: translating foreign data In-Reply-To: References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <87h8ltiubl.fsf@elektro.pacujo.net> <8318150e-1f3c-eb97-d25c-475bddc6e223@Damon-Family.org> <87d0whirgc.fsf@elektro.pacujo.net> <1d713ce6-d8d8-110c-aa78-d7d672a024b9@Damon-Family.org> Message-ID: On Sun, Jun 24, 2018 at 12:44 PM, Steven D'Aprano wrote: > You're joking, right? You can't possibly be so ignorant as to actually > believe that. You have, right in front of you, a news post or email > containing the text string "100?", and yet you are writing apparently in > full seriousness that it is impossible to get that text string in a file. > > Okay, you want a bit-pattern. In hex: > > '0x313030e282ac' > > I'll leave the question of how I generated that as an exercise. (Hint: it > was a one-liner, involving two method calls and a function call, all > builtins in Python.) Hmm. Actually, I'm a bit confused. >>> hex("100?".encode()) Traceback (most recent call last): File "", line 1, in TypeError: 'bytes' object cannot be interpreted as an integer Nope, that's not it. Needs something to turn the bytes into an integer first. But I can't find a way to do that. Best I can find is: >>> "100?".encode().hex() '313030e282ac' No "0x" prefix, no function call. So, I'm stuck. How did you create your one? ChrisA From steve+comp.lang.python at pearwood.info Sat Jun 23 23:19:45 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 03:19:45 +0000 (UTC) Subject: Static variables [was Re: syntax difference] References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <6eUVC.491716$Qg7.378011@fx08.am4> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <2113d8c5-ee00-d073-1bfd-5bde34d64235@mrabarnett.plus.com> Message-ID: On Sat, 23 Jun 2018 18:29:51 +0100, MRAB wrote: > You can already do something similar like this: > > def f(): > f.x += 1 > return f.x > f.x = 0 > > [snip] You can, but only as an illustration, not as a serious implementation. The whole point of static local variables is that they are: (1) Local variables, and hence FAST; (2) fully encapsulated inside the function. Using f.x fails on both accounts: - it requires a global name lookup for "f" (hence slow); - followed by an attribute lookup for "x" (hence even slower); - f.x is not encapsulated inside the function. It requires initialisation outside the function. The attribute f.x is easily visible to the caller. (Technically, so probably would static variables, but only by inspecting the function's internals. People know they're on thin-ice if they mess with them. And if we really needed to, we could protect the static storage inside the function from writing, if not reading, as we do with closures. f.x looks like an ordinary attribute.) I have used the f.x trick before, for things where speed was not critical, but I've never really loved the idea, and it certainly cannot be used as a replacement of the def func(arg, len=len, int=int) optimization trick. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sat Jun 23 23:23:22 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 03:23:22 +0000 (UTC) Subject: translating foreign data References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <87h8ltiubl.fsf@elektro.pacujo.net> <8318150e-1f3c-eb97-d25c-475bddc6e223@Damon-Family.org> <87d0whirgc.fsf@elektro.pacujo.net> <1d713ce6-d8d8-110c-aa78-d7d672a024b9@Damon-Family.org> Message-ID: On Sun, 24 Jun 2018 12:53:49 +1000, Chris Angelico wrote: [...] >> Okay, you want a bit-pattern. In hex: >> >> '0x313030e282ac' [...] > Hmm. Actually, I'm a bit confused. > >>>> hex("100?".encode()) > Traceback (most recent call last): > File "", line 1, in > TypeError: 'bytes' object cannot be interpreted as an integer > > Nope, that's not it. Needs something to turn the bytes into an integer > first. But I can't find a way to do that. Best I can find is: > >>>> "100?".encode().hex() > '313030e282ac' Dammit, that was what I was looking for, but I only looked on *strings*, not bytes. > No "0x" prefix, no function call. So, I'm stuck. How did you create your > one? py> hex(int.from_bytes("100?".encode("utf-8"), 'big')) '0x313030e282ac' -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sat Jun 23 23:32:21 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jun 2018 13:32:21 +1000 Subject: translating foreign data In-Reply-To: References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <87h8ltiubl.fsf@elektro.pacujo.net> <8318150e-1f3c-eb97-d25c-475bddc6e223@Damon-Family.org> <87d0whirgc.fsf@elektro.pacujo.net> <1d713ce6-d8d8-110c-aa78-d7d672a024b9@Damon-Family.org> Message-ID: On Sun, Jun 24, 2018 at 1:23 PM, Steven D'Aprano wrote: > On Sun, 24 Jun 2018 12:53:49 +1000, Chris Angelico wrote: > > [...] >>> Okay, you want a bit-pattern. In hex: >>> >>> '0x313030e282ac' > [...] > >> Hmm. Actually, I'm a bit confused. >> >>>>> hex("100?".encode()) >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: 'bytes' object cannot be interpreted as an integer >> >> Nope, that's not it. Needs something to turn the bytes into an integer >> first. But I can't find a way to do that. Best I can find is: >> >>>>> "100?".encode().hex() >> '313030e282ac' > > Dammit, that was what I was looking for, but I only looked on *strings*, > not bytes. > > >> No "0x" prefix, no function call. So, I'm stuck. How did you create your >> one? > > py> hex(int.from_bytes("100?".encode("utf-8"), 'big')) > '0x313030e282ac' Ahhh thanks, that's the part I couldn't find (and didn't remember). Anyhow, encoding to UTF-8 and then to bytes is pretty easy. ChrisA From jim.lee at 1 Sat Jun 23 23:44:56 2018 From: jim.lee at 1 (Jim Lee) Date: Sat, 23 Jun 2018 22:44:56 -0500 Subject: Quick survey: locals in comprehensions (Python 3 only) Message-ID: <5B30F4ED.20995.uclanpyth@castlerockbbs.com> From: Jim Lee On 06/23/2018 10:03 PM, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, since > this is about your EXPECTATIONS, not what Python actually does. > > Given this function: > > > def test(): > a = 1 > b = 2 > result = [value for key, value in locals().items()] > return result > > > > > what would you expect the result of calling test() to be? Is that the > result you think is most useful? In your opinion, is this a useful > feature, a misfeature, a bug, or "whatever"? > > I'm only looking for answers for Python 3. (The results in Python 2 are > genuinely weird :-) > > I would *expect* [1, 2, None], though I haven't actually tried running it. -Jim --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From jim.lee at 1 Sun Jun 24 00:08:56 2018 From: jim.lee at 1 (Jim Lee) Date: Sat, 23 Jun 2018 23:08:56 -0500 Subject: Quick survey: locals in comprehensions (Python 3 only) Message-ID: <5B30F4ED.20997.uclanpyth@castlerockbbs.com> From: Jim Lee On 06/23/2018 11:02 PM, Chris Angelico wrote: > On Sun, Jun 24, 2018 at 3:44 PM, Jim Lee wrote: >> >> On 06/23/2018 10:03 PM, Steven D'Aprano wrote: >>> I'd like to run a quick survey. There is no right or wrong answer, since >>> this is about your EXPECTATIONS, not what Python actually does. >>> >>> Given this function: >>> >>> >>> def test(): >>> a = 1 >>> b = 2 >>> result = [value for key, value in locals().items()] >>> return result >>> >>> >>> >>> >>> what would you expect the result of calling test() to be? Is that the >>> result you think is most useful? In your opinion, is this a useful >>> feature, a misfeature, a bug, or "whatever"? >>> >>> I'm only looking for answers for Python 3. (The results in Python 2 are >>> genuinely weird :-) >>> >>> >> I would *expect* [1, 2, None], though I haven't actually tried running it. >> > Interesting. Where do you get the None from? Suppose it had been "key > for..." instead of "value", what would the third key have been? ["a", > "b", ...] > > ChrisA There are three locals:? a, b, and result.? Since result cannot be assigned a value until the list comp has been evaluated, I would expect the comp to return a value of "None" for result.? An argument could also be made for [1, 2, []], but one thing I would *not* expect is [1, 2] or [2, 1]... -Jim --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From jim.lee at 1 Sun Jun 24 00:24:16 2018 From: jim.lee at 1 (Jim Lee) Date: Sat, 23 Jun 2018 23:24:16 -0500 Subject: Quick survey: locals in comprehensions (Python 3 only) Message-ID: <5B30F4ED.20999.uclanpyth@castlerockbbs.com> From: Jim Lee On 06/23/2018 11:16 PM, Chris Angelico wrote: > On Sun, Jun 24, 2018 at 4:08 PM, Jim Lee wrote: >> There are three locals: a, b, and result. Since result cannot be assigned >> a value until the list comp has been evaluated, I would expect the comp to >> return a value of "None" for result. An argument could also be made for [1, >> 2, []], but one thing I would *not* expect is [1, 2] or [2, 1]... > Ahh, I see what you mean. Thing is, there's a definite difference > between "this is None" and "this doesn't have a value". The latter > situation is indicated by simply not having the local. > > def f(): > print("; ".join("%s=%r" % x for x in locals().items())) > a = 1 > print("; ".join("%s=%r" % x for x in locals().items())) > b = 2 > print("; ".join("%s=%r" % x for x in locals().items())) > > The results may surprise you, or may not. > > This part has nothing to do with the behaviour of locals inside a > comprehension, though. The important part is that, like me, you would > like comprehensions to represent a block of code inside the current > function, not an implicit nested function. > > ChrisA That's why I said an argument could be made for [1, 2, []].? I realize that NoneType is not the same as no type, but, having not studied the internals of any particular Python implementation,? I don't know how it builds or initializes its local symbol table. But, I expected "result" to exist before the list comprehension was evaluated simply due to left->right parsing. -Jim --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From ben.bacarisse at 1 Sun Jun 24 00:25:54 2018 From: ben.bacarisse at 1 (Ben Bacarisse) Date: Sat, 23 Jun 2018 23:25:54 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B30F4ED.20971.uclanpyth@castlerockbbs.com> References: <5B30F4ED.20971.uclanpyth@castlerockbbs.com> Message-ID: <5B30F4ED.20975.uclanpyth@castlerockbbs.com> To: Bart From: Ben Bacarisse Bart writes: > On 23/06/2018 21:13, Chris Angelico wrote: >> On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: > >>> (At what point would that happen anyway; if you do this: > >> NONE of your examples are taking copies of the function. They all are >> making REFERENCES to the same function. That is all. > > This is about your notion that invocations of the same function via > different references, should maintain their own versions of the > function's 'static' data. > > Since these references are created via the return g statement here: > > def f(): > def g(): > .... > return g > > (say to create function references i and j like this: > > i = f() > j = f() > ) > > I'm assuming that something special must be happening. Otherwise, how > does f() know which reference it's being called via? > > What is different, what extra bit of information is provided when f() > is invoked via i() or j()? f is not being invoked by either i() or j(). i = f() binds i to the function returned by f. That's a newly minted function. In languages like Python, executing def creates a function. In your example, i and j refer to different functions. If the function temporarily named g has "own" variables ("static" in C), then each such function should have its own. That was the point of the example much further up. The effect can simulated like this: def make_counter(): def c(): c.x += 1 return c.x c.x = 0 return c i = make_counter() j = make_counter() print(i(), i(), j(), i()) -- Ben. --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From ben.bacarisse at 1 Sun Jun 24 00:25:54 2018 From: ben.bacarisse at 1 (Ben Bacarisse) Date: Sat, 23 Jun 2018 23:25:54 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B324678.21164.uclanpyth@castlerockbbs.com> References: <5B324678.21164.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21165.uclanpyth@castlerockbbs.com> To: Bart From: "Ben Bacarisse" To: Bart From: Ben Bacarisse Bart writes: > On 23/06/2018 21:13, Chris Angelico wrote: >> On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: > >>> (At what point would that happen anyway; if you do this: > >> NONE of your examples are taking copies of the function. They all are >> making REFERENCES to the same function. That is all. > > This is about your notion that invocations of the same function via > different references, should maintain their own versions of the > function's 'static' data. > > Since these references are created via the return g statement here: > > def f(): > def g(): > .... > return g > > (say to create function references i and j like this: > > i = f() > j = f() > ) > > I'm assuming that something special must be happening. Otherwise, how > does f() know which reference it's being called via? > > What is different, what extra bit of information is provided when f() > is invoked via i() or j()? f is not being invoked by either i() or j(). i = f() binds i to the function returned by f. That's a newly minted function. In languages like Python, executing def creates a function. In your example, i and j refer to different functions. If the function temporarily named g has "own" variables ("static" in C), then each such function should have its own. That was the point of the example much further up. The effect can simulated like this: def make_counter(): def c(): c.x += 1 return c.x c.x = 0 return c i = make_counter() j = make_counter() print(i(), i(), j(), i()) -- Ben. -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bart at 1 Sun Jun 24 00:26:42 2018 From: bart at 1 (Bart) Date: Sat, 23 Jun 2018 23:26:42 -0500 Subject: syntax difference In-Reply-To: <5B30F4ED.20969.uclanpyth@castlerockbbs.com> References: <5B30F4ED.20969.uclanpyth@castlerockbbs.com> Message-ID: <5B30F4ED.20976.uclanpyth@castlerockbbs.com> To: boB Stepp From: Bart On 23/06/2018 20:52, boB Stepp wrote: > I've finally found time to examine this rather long, rambling thread. >> There is a place for various levels of programming language. I'm saying that Python which is always touted as a 'simple' language suitable for beginners, is missing a surprising number of basics. > I still feel like a rank beginner, but on the Tutor list some > disagree. The first programming exercise I ever did involved asking for three numbers, then determining whether those numbers could form the sides of a triangle. Then [40 years ago], the easy part was reading the three numbers. Now that would be the more challenging part. This is one of the basics that is missing. Getting around it is not hard, but it's some messing about and it's a distraction. But 40 years ago it was just 'readln a,b,c'; it was just taken for granted. (It make seem quaint in these days of GUIs, gestures, and voice recognition to be reading a line at a time, but you will need it still for text file i/o.) > Anyway, so far Python has not lacked for anything I have needed so > far. I'd be surprised if Python lacked anything; there can't be anything that someone has thought of that is either built-in or bolted on, if not always that elegantly or that efficiently. However, imagine having to use a language which didn't have assignments as you are used to, and that you would expect to exist. Then you might well remark that it's missing something that you regard as a basic, while the proponents of that language point out that it doesn't stop you writing programs; it just needs a different approach. (I believe that you can write any program using just IF-GOTO statements and ASSIGNMENT statements, and no other flow control (given suitable data-types and means of I/O). But if you wanted to try out an interesting experiment along those lines (eg. transcribe any flowchart to code), a large number of languages, including Python, make it hard because 'goto' is missing.) > All I can say is I have yet to find much at all in Python cumbersome > or bewildering. No? How many ways are there in Python, including third party add-ons, of working with record-like objects? > As an aside to Bart, if you strongly feel that Python is missing a > really useful feature, then why don't you do the usual thing, start a > very specific thread about just that feature (Not just a collection of > things you like in one of your languages.), and if you manage to > persuade the community of its usefulness, then write up a PEP about > it? Just saying ... ~(:>)) I'm not a user. My interest is in design and implementation, especially of interpreters, and especially of efficient ones. A lot of things that Python could do with are made very difficult by the existing design of that language. Being so dynamic has a lot to answer for. So I don't envy the job of the people who really have to move the language forward. That doesn't mean I can't argue with people who say that Python doesn't really need (say) Switch. (I guess the Blub paradox works both ways...) -- bart --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bart at 1 Sun Jun 24 00:26:42 2018 From: bart at 1 (Bart) Date: Sat, 23 Jun 2018 23:26:42 -0500 Subject: syntax difference Message-ID: <5B324678.21166.uclanpyth@castlerockbbs.com> To: boB Stepp From: "Bart" To: boB Stepp From: Bart On 23/06/2018 20:52, boB Stepp wrote: > I've finally found time to examine this rather long, rambling thread. >> There is a place for various levels of programming language. I'm saying that Python which is always touted as a 'simple' language suitable for beginners, is missing a surprising number of basics. > I still feel like a rank beginner, but on the Tutor list some > disagree. The first programming exercise I ever did involved asking for three numbers, then determining whether those numbers could form the sides of a triangle. Then [40 years ago], the easy part was reading the three numbers. Now that would be the more challenging part. This is one of the basics that is missing. Getting around it is not hard, but it's some messing about and it's a distraction. But 40 years ago it was just 'readln a,b,c'; it was just taken for granted. (It make seem quaint in these days of GUIs, gestures, and voice recognition to be reading a line at a time, but you will need it still for text file i/o.) > Anyway, so far Python has not lacked for anything I have needed so > far. I'd be surprised if Python lacked anything; there can't be anything that someone has thought of that is either built-in or bolted on, if not always that elegantly or that efficiently. However, imagine having to use a language which didn't have assignments as you are used to, and that you would expect to exist. Then you might well remark that it's missing something that you regard as a basic, while the proponents of that language point out that it doesn't stop you writing programs; it just needs a different approach. (I believe that you can write any program using just IF-GOTO statements and ASSIGNMENT statements, and no other flow control (given suitable data-types and means of I/O). But if you wanted to try out an interesting experiment along those lines (eg. transcribe any flowchart to code), a large number of languages, including Python, make it hard because 'goto' is missing.) > All I can say is I have yet to find much at all in Python cumbersome > or bewildering. No? How many ways are there in Python, including third party add-ons, of working with record-like objects? > As an aside to Bart, if you strongly feel that Python is missing a > really useful feature, then why don't you do the usual thing, start a > very specific thread about just that feature (Not just a collection of > things you like in one of your languages.), and if you manage to > persuade the community of its usefulness, then write up a PEP about > it? Just saying ... ~(:>)) I'm not a user. My interest is in design and implementation, especially of interpreters, and especially of efficient ones. A lot of things that Python could do with are made very difficult by the existing design of that language. Being so dynamic has a lot to answer for. So I don't envy the job of the people who really have to move the language forward. That doesn't mean I can't argue with people who say that Python doesn't really need (say) Switch. (I guess the Blub paradox works both ways...) -- bart -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steve+comp.lang.python at pearwood.info Sun Jun 24 01:03:20 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 05:03:20 +0000 (UTC) Subject: Quick survey: locals in comprehensions (Python 3 only) Message-ID: I'd like to run a quick survey. There is no right or wrong answer, since this is about your EXPECTATIONS, not what Python actually does. Given this function: def test(): a = 1 b = 2 result = [value for key, value in locals().items()] return result what would you expect the result of calling test() to be? Is that the result you think is most useful? In your opinion, is this a useful feature, a misfeature, a bug, or "whatever"? I'm only looking for answers for Python 3. (The results in Python 2 are genuinely weird :-) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sun Jun 24 01:18:49 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jun 2018 15:18:49 +1000 Subject: Quick survey: locals in comprehensions (Python 3 only) In-Reply-To: References: Message-ID: On Sun, Jun 24, 2018 at 3:03 PM, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, since > this is about your EXPECTATIONS, not what Python actually does. > > Given this function: > > > def test(): > a = 1 > b = 2 > result = [value for key, value in locals().items()] > return result > > > > > what would you expect the result of calling test() to be? Is that the > result you think is most useful? In your opinion, is this a useful > feature, a misfeature, a bug, or "whatever"? > > I'm only looking for answers for Python 3. (The results in Python 2 are > genuinely weird :-) Personally, I think it should give you [1, 2], the two values from the function's locals. But genexps introduce some problems. Compare: def test(): a = 1 b = 2 result = list(value for key, value in locals().items()) return result def test_helper(): a = 1 b = 2 gen = (value for key, value in locals().items()) return gen def test(): return list(test_helper()) Guido has stated that he wants the list comp to be equivalent to calling list() immediately on the genexp. And since a genexp has to be the same thing whether you call list() on it straight away or not, that means that all these need to behave the same way. Which, in turn, means that the genexp needs some form of closure semantics. Thus it is executed in an implicit nested function, and thus the list comp also needs to be, for consistency. So! With that in mind, I would consider bizarre behaviour of locals() inside comprehensions to be a wart. It's not a normal thing to do, and if it behaves weirdly, so be it. There are other things that I would prefer to see tidied up before that. ChrisA From steve+comp.lang.python at pearwood.info Sun Jun 24 01:22:06 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 05:22:06 +0000 (UTC) Subject: Quick survey: locals in comprehensions (Python 3 only) References: Message-ID: On Sun, 24 Jun 2018 15:18:49 +1000, Chris Angelico wrote: > Personally, I think it should give you [1, 2], the two values from the > function's locals. Thank you, that's the sort of answer I'm looking for. (I'm not saying I didn't read your long and involved analysis, only that I'm not looking for long involved analyses at the moment :-) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From bart at 1 Sun Jun 24 01:37:36 2018 From: bart at 1 (Bart) Date: Sun, 24 Jun 2018 00:37:36 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B30F4ED.20975.uclanpyth@castlerockbbs.com> References: <5B30F4ED.20975.uclanpyth@castlerockbbs.com> Message-ID: <5B30F4ED.20977.uclanpyth@castlerockbbs.com> To: Ben Bacarisse From: Bart On 23/06/2018 23:25, Ben Bacarisse wrote: > Bart writes: > >> On 23/06/2018 21:13, Chris Angelico wrote: >>> On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: >> >>>> (At what point would that happen anyway; if you do this: >> >>> NONE of your examples are taking copies of the function. They all are >>> making REFERENCES to the same function. That is all. >> >> This is about your notion that invocations of the same function via >> different references, should maintain their own versions of the >> function's 'static' data. >> >> Since these references are created via the return g statement here: >> >> def f(): >> def g(): >> .... >> return g >> >> (say to create function references i and j like this: >> >> i = f() >> j = f() >> ) >> >> I'm assuming that something special must be happening. Otherwise, how >> does f() know which reference it's being called via? >> >> What is different, what extra bit of information is provided when f() >> is invoked via i() or j()? > > f is not being invoked by either i() or j(). i = f() binds i to the > function returned by f. That's a newly minted function. In languages > like Python, executing def creates a function. Do you mean that if the same 'def' block is re-executed, it will create a different instance of the function? (Same byte-code, but a different set of everything else the function uses.) Wow. (Just think of all the times you write a function containing a neat bunch of local functions, every time it's called it has to create a new function instances for each of those functions, even if they are not used.) Anyway just for regular statics, the following appears to work. Not ideal, but simpler than some alternatives: def f(): if not hasattr(f,'x'): f.x=0 f.x += 1 return f.x -- bart. --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bart at 1 Sun Jun 24 01:37:36 2018 From: bart at 1 (Bart) Date: Sun, 24 Jun 2018 00:37:36 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B324678.21165.uclanpyth@castlerockbbs.com> References: <5B324678.21165.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21167.uclanpyth@castlerockbbs.com> To: Ben Bacarisse From: "Bart" To: Ben Bacarisse From: Bart On 23/06/2018 23:25, Ben Bacarisse wrote: > Bart writes: > >> On 23/06/2018 21:13, Chris Angelico wrote: >>> On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: >> >>>> (At what point would that happen anyway; if you do this: >> >>> NONE of your examples are taking copies of the function. They all are >>> making REFERENCES to the same function. That is all. >> >> This is about your notion that invocations of the same function via >> different references, should maintain their own versions of the >> function's 'static' data. >> >> Since these references are created via the return g statement here: >> >> def f(): >> def g(): >> .... >> return g >> >> (say to create function references i and j like this: >> >> i = f() >> j = f() >> ) >> >> I'm assuming that something special must be happening. Otherwise, how >> does f() know which reference it's being called via? >> >> What is different, what extra bit of information is provided when f() >> is invoked via i() or j()? > > f is not being invoked by either i() or j(). i = f() binds i to the > function returned by f. That's a newly minted function. In languages > like Python, executing def creates a function. Do you mean that if the same 'def' block is re-executed, it will create a different instance of the function? (Same byte-code, but a different set of everything else the function uses.) Wow. (Just think of all the times you write a function containing a neat bunch of local functions, every time it's called it has to create a new function instances for each of those functions, even if they are not used.) Anyway just for regular statics, the following appears to work. Not ideal, but simpler than some alternatives: def f(): if not hasattr(f,'x'): f.x=0 f.x += 1 return f.x -- bart. -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From jlee54 at gmail.com Sun Jun 24 01:44:57 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sat, 23 Jun 2018 22:44:57 -0700 Subject: Quick survey: locals in comprehensions (Python 3 only) In-Reply-To: References: Message-ID: <7c53fc62-7d24-508d-74a9-94ff6570cc4b@gmail.com> On 06/23/2018 10:03 PM, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, since > this is about your EXPECTATIONS, not what Python actually does. > > Given this function: > > > def test(): > a = 1 > b = 2 > result = [value for key, value in locals().items()] > return result > > > > > what would you expect the result of calling test() to be? Is that the > result you think is most useful? In your opinion, is this a useful > feature, a misfeature, a bug, or "whatever"? > > I'm only looking for answers for Python 3. (The results in Python 2 are > genuinely weird :-) > > I would *expect* [1, 2, None], though I haven't actually tried running it. -Jim From rosuav at gmail.com Sun Jun 24 02:02:54 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jun 2018 16:02:54 +1000 Subject: Quick survey: locals in comprehensions (Python 3 only) In-Reply-To: <7c53fc62-7d24-508d-74a9-94ff6570cc4b@gmail.com> References: <7c53fc62-7d24-508d-74a9-94ff6570cc4b@gmail.com> Message-ID: On Sun, Jun 24, 2018 at 3:44 PM, Jim Lee wrote: > > > On 06/23/2018 10:03 PM, Steven D'Aprano wrote: >> >> I'd like to run a quick survey. There is no right or wrong answer, since >> this is about your EXPECTATIONS, not what Python actually does. >> >> Given this function: >> >> >> def test(): >> a = 1 >> b = 2 >> result = [value for key, value in locals().items()] >> return result >> >> >> >> >> what would you expect the result of calling test() to be? Is that the >> result you think is most useful? In your opinion, is this a useful >> feature, a misfeature, a bug, or "whatever"? >> >> I'm only looking for answers for Python 3. (The results in Python 2 are >> genuinely weird :-) >> >> > I would *expect* [1, 2, None], though I haven't actually tried running it. > Interesting. Where do you get the None from? Suppose it had been "key for..." instead of "value", what would the third key have been? ["a", "b", ...] ChrisA From jlee54 at gmail.com Sun Jun 24 02:08:57 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sat, 23 Jun 2018 23:08:57 -0700 Subject: Quick survey: locals in comprehensions (Python 3 only) In-Reply-To: References: <7c53fc62-7d24-508d-74a9-94ff6570cc4b@gmail.com> Message-ID: <7b2eb614-75b0-2bb8-8cf6-05f8913bac84@gmail.com> On 06/23/2018 11:02 PM, Chris Angelico wrote: > On Sun, Jun 24, 2018 at 3:44 PM, Jim Lee wrote: >> >> On 06/23/2018 10:03 PM, Steven D'Aprano wrote: >>> I'd like to run a quick survey. There is no right or wrong answer, since >>> this is about your EXPECTATIONS, not what Python actually does. >>> >>> Given this function: >>> >>> >>> def test(): >>> a = 1 >>> b = 2 >>> result = [value for key, value in locals().items()] >>> return result >>> >>> >>> >>> >>> what would you expect the result of calling test() to be? Is that the >>> result you think is most useful? In your opinion, is this a useful >>> feature, a misfeature, a bug, or "whatever"? >>> >>> I'm only looking for answers for Python 3. (The results in Python 2 are >>> genuinely weird :-) >>> >>> >> I would *expect* [1, 2, None], though I haven't actually tried running it. >> > Interesting. Where do you get the None from? Suppose it had been "key > for..." instead of "value", what would the third key have been? ["a", > "b", ...] > > ChrisA There are three locals:? a, b, and result.? Since result cannot be assigned a value until the list comp has been evaluated, I would expect the comp to return a value of "None" for result.? An argument could also be made for [1, 2, []], but one thing I would *not* expect is [1, 2] or [2, 1]... -Jim From rosuav at gmail.com Sun Jun 24 02:16:01 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jun 2018 16:16:01 +1000 Subject: Quick survey: locals in comprehensions (Python 3 only) In-Reply-To: <7b2eb614-75b0-2bb8-8cf6-05f8913bac84@gmail.com> References: <7c53fc62-7d24-508d-74a9-94ff6570cc4b@gmail.com> <7b2eb614-75b0-2bb8-8cf6-05f8913bac84@gmail.com> Message-ID: On Sun, Jun 24, 2018 at 4:08 PM, Jim Lee wrote: > There are three locals: a, b, and result. Since result cannot be assigned > a value until the list comp has been evaluated, I would expect the comp to > return a value of "None" for result. An argument could also be made for [1, > 2, []], but one thing I would *not* expect is [1, 2] or [2, 1]... Ahh, I see what you mean. Thing is, there's a definite difference between "this is None" and "this doesn't have a value". The latter situation is indicated by simply not having the local. def f(): print("; ".join("%s=%r" % x for x in locals().items())) a = 1 print("; ".join("%s=%r" % x for x in locals().items())) b = 2 print("; ".join("%s=%r" % x for x in locals().items())) The results may surprise you, or may not. This part has nothing to do with the behaviour of locals inside a comprehension, though. The important part is that, like me, you would like comprehensions to represent a block of code inside the current function, not an implicit nested function. ChrisA From jlee54 at gmail.com Sun Jun 24 02:24:16 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sat, 23 Jun 2018 23:24:16 -0700 Subject: Quick survey: locals in comprehensions (Python 3 only) In-Reply-To: References: <7c53fc62-7d24-508d-74a9-94ff6570cc4b@gmail.com> <7b2eb614-75b0-2bb8-8cf6-05f8913bac84@gmail.com> Message-ID: <09951f76-bb90-1e1d-1b84-103d569688c8@gmail.com> On 06/23/2018 11:16 PM, Chris Angelico wrote: > On Sun, Jun 24, 2018 at 4:08 PM, Jim Lee wrote: >> There are three locals: a, b, and result. Since result cannot be assigned >> a value until the list comp has been evaluated, I would expect the comp to >> return a value of "None" for result. An argument could also be made for [1, >> 2, []], but one thing I would *not* expect is [1, 2] or [2, 1]... > Ahh, I see what you mean. Thing is, there's a definite difference > between "this is None" and "this doesn't have a value". The latter > situation is indicated by simply not having the local. > > def f(): > print("; ".join("%s=%r" % x for x in locals().items())) > a = 1 > print("; ".join("%s=%r" % x for x in locals().items())) > b = 2 > print("; ".join("%s=%r" % x for x in locals().items())) > > The results may surprise you, or may not. > > This part has nothing to do with the behaviour of locals inside a > comprehension, though. The important part is that, like me, you would > like comprehensions to represent a block of code inside the current > function, not an implicit nested function. > > ChrisA That's why I said an argument could be made for [1, 2, []].? I realize that NoneType is not the same as no type, but, having not studied the internals of any particular Python implementation,? I don't know how it builds or initializes its local symbol table. But, I expected "result" to exist before the list comprehension was evaluated simply due to left->right parsing. -Jim From ben.bacarisse at 1 Sun Jun 24 02:53:58 2018 From: ben.bacarisse at 1 (Ben Bacarisse) Date: Sun, 24 Jun 2018 01:53:58 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B30F4ED.20977.uclanpyth@castlerockbbs.com> References: <5B30F4ED.20977.uclanpyth@castlerockbbs.com> Message-ID: <5B30F4ED.20980.uclanpyth@castlerockbbs.com> To: Bart From: Ben Bacarisse Bart writes: > On 23/06/2018 23:25, Ben Bacarisse wrote: >> Bart writes: >> >>> On 23/06/2018 21:13, Chris Angelico wrote: >>>> On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: >>> >>>>> (At what point would that happen anyway; if you do this: >>> >>>> NONE of your examples are taking copies of the function. They all are >>>> making REFERENCES to the same function. That is all. >>> >>> This is about your notion that invocations of the same function via >>> different references, should maintain their own versions of the >>> function's 'static' data. >>> >>> Since these references are created via the return g statement here: >>> >>> def f(): >>> def g(): >>> .... >>> return g >>> >>> (say to create function references i and j like this: >>> >>> i = f() >>> j = f() >>> ) >>> >>> I'm assuming that something special must be happening. Otherwise, how >>> does f() know which reference it's being called via? >>> >>> What is different, what extra bit of information is provided when f() >>> is invoked via i() or j()? >> >> f is not being invoked by either i() or j(). i = f() binds i to the >> function returned by f. That's a newly minted function. In languages >> like Python, executing def creates a function. > > Do you mean that if the same 'def' block is re-executed, it will > create a different instance of the function? (Same byte-code, but a > different set of everything else the function uses.) Logically, yes. > Wow. (Just think of all the times you write a function containing a > neat bunch of local functions, every time it's called it has to create > a new function instances for each of those functions, even if they are > not used.) I am surprised that this surprises you, and equally surprised that you seem to think it's going to be in some way grossly inefficient. -- Ben. --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From ben.bacarisse at 1 Sun Jun 24 02:53:58 2018 From: ben.bacarisse at 1 (Ben Bacarisse) Date: Sun, 24 Jun 2018 01:53:58 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B324678.21167.uclanpyth@castlerockbbs.com> References: <5B324678.21167.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21168.uclanpyth@castlerockbbs.com> To: Bart From: "Ben Bacarisse" To: Bart From: Ben Bacarisse Bart writes: > On 23/06/2018 23:25, Ben Bacarisse wrote: >> Bart writes: >> >>> On 23/06/2018 21:13, Chris Angelico wrote: >>>> On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: >>> >>>>> (At what point would that happen anyway; if you do this: >>> >>>> NONE of your examples are taking copies of the function. They all are >>>> making REFERENCES to the same function. That is all. >>> >>> This is about your notion that invocations of the same function via >>> different references, should maintain their own versions of the >>> function's 'static' data. >>> >>> Since these references are created via the return g statement here: >>> >>> def f(): >>> def g(): >>> .... >>> return g >>> >>> (say to create function references i and j like this: >>> >>> i = f() >>> j = f() >>> ) >>> >>> I'm assuming that something special must be happening. Otherwise, how >>> does f() know which reference it's being called via? >>> >>> What is different, what extra bit of information is provided when f() >>> is invoked via i() or j()? >> >> f is not being invoked by either i() or j(). i = f() binds i to the >> function returned by f. That's a newly minted function. In languages >> like Python, executing def creates a function. > > Do you mean that if the same 'def' block is re-executed, it will > create a different instance of the function? (Same byte-code, but a > different set of everything else the function uses.) Logically, yes. > Wow. (Just think of all the times you write a function containing a > neat bunch of local functions, every time it's called it has to create > a new function instances for each of those functions, even if they are > not used.) I am surprised that this surprises you, and equally surprised that you seem to think it's going to be in some way grossly inefficient. -- Ben. -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sun Jun 24 03:23:36 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 02:23:36 -0500 Subject: Static variables [was Re: syntax difference] Message-ID: <5B30F4ED.20982.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sat, 23 Jun 2018 21:44:00 +0100, Bart wrote: > Since these references are created via the return g statement here: > > def f(): > def g(): > .... > return g > > (say to create function references i and j like this: > > i = f() > j = f() > ) > > I'm assuming that something special must be happening. Otherwise, how > does f() know which reference it's being called via? You assume wrong. > What is different, what extra bit of information is provided when f() is > invoked via i() or j()? For somebody who has been using Python for a few years now, and is constantly telling us how we're doing it wrong, you sure are ignorant about the language and how it works. For somebody who has been programming for so long, you seem awfully unaware of how dynamic languages with first-class functions and closures work. No extra bit of information is provided. i refers to one function, j, refers to another function, and there is no overlap. Each invocation of f() results in a brand new function being created, dynamically, and assigned to the appropriate name. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sun Jun 24 03:35:26 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 02:35:26 -0500 Subject: syntax difference Message-ID: <5B30F4ED.20984.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sat, 23 Jun 2018 23:26:43 +0100, Bart wrote: > Then [40 years ago], the easy part was reading the three numbers. Now > that would be the more challenging part. # Get three numbers, separated by spaces, with no error-recovery. # If you try to read bad data, the process will fail. n1, n2, n3 = [float(s) for s in input("Enter three numbers: ").split()] No more verbose or difficult (certainly not "challenging") than: var: # need to declare these otherwise how will readln # know if it is reading floats or ints or strings? n1, n2, n3: float print("Enter three numbers: ") n1, n2, n3 = readln() If the use of a list comprehension is too advanced for a beginner in day one, how about this: n1 = float(input("Enter a number: ")) n2 = float(input("Enter a number: ")) n3 = float(input("Enter a number: ")) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sun Jun 24 03:41:36 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 02:41:36 -0500 Subject: Static variables [was Re: syntax difference] Message-ID: <5B30F4ED.20985.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sun, 24 Jun 2018 00:37:36 +0100, Bart wrote: > Do you mean that if the same 'def' block is re-executed, it will create > a different instance of the function? (Same byte-code, but a different > set of everything else the function uses.) That's not as slow as you think it is. Everything that can be is pre- prepared and assembling them is pretty fast: py> import dis py> dis.dis(lambda x: lambda n: x*n) 1 0 LOAD_CLOSURE 0 (x) 3 BUILD_TUPLE 1 6 LOAD_CONST 1 ( at 0xb78b6430, file "", line 1>) 9 LOAD_CONST 2 ('..') 12 MAKE_CLOSURE 0 15 RETURN_VALUE How else can you get functions where the definition is not known until runtime, unless you assemble them at runtime? > Wow. (Just think of all the times you write a function containing a neat > bunch of local functions, every time it's called it has to create a new > function instances for each of those functions, even if they are not > used.) That's why Pascal-style static nested functions are hardly ever used in Python. 99% of nested functions are closures. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sun Jun 24 03:44:02 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 02:44:02 -0500 Subject: translating foreign data Message-ID: <5B30F4ED.20986.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sat, 23 Jun 2018 17:05:17 -0400, Richard Damon wrote: > On 6/23/18 11:27 AM, Steven D'Aprano wrote: >> On Sat, 23 Jun 2018 09:42:29 -0400, Richard Damon wrote: >> >>> On 6/23/18 9:05 AM, Marko Rauhamaa wrote: >>>> Ok. Here's a value for you: >>>> >>>> 100??? [...] > Locale based currency transformations are defined as a number to/from a > text string. > > The number CAN'T say 100 Euros (can you give me what bit pattern you > would use for such a number). You're joking, right? You can't possibly be so ignorant as to actually believe that. You have, right in front of you, a news post or email containing the text string "100???", and yet you are writing apparently in full seriousness that it is impossible to get that text string in a file. Okay, you want a bit-pattern. In hex: '0x313030e282ac' I'll leave the question of how I generated that as an exercise. (Hint: it was a one-liner, involving two method calls and a function call, all builtins in Python.) > The currency is encoded in the locale used for the conversion, so if it > is using en-US, the currency value would ALWAYS be US$ (which the > general locale format is just $). I cannot imagine for a second why you think any of this is even a tiny bit relevant to the question of how one should read a data file containing currency in Euro. You seem to have heard about the locale and decide it is the One True Hammer than all nails must be hammered with. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sun Jun 24 03:44:12 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 02:44:12 -0500 Subject: translating foreign data Message-ID: <5B30F4ED.20987.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sat, 23 Jun 2018 17:52:55 -0400, Richard Damon wrote: > If you have more than just a number representing a value in the locale > currency, you can't ask the locale how to present/accept it. You're the only one saying that it has to be handled by the locale. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sun Jun 24 04:19:44 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 03:19:44 -0500 Subject: Static variables [was Re: syntax difference] Message-ID: <5B30F4ED.20989.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sat, 23 Jun 2018 18:29:51 +0100, MRAB wrote: > You can already do something similar like this: > > def f(): > f.x += 1 > return f.x > f.x = 0 > > [snip] You can, but only as an illustration, not as a serious implementation. The whole point of static local variables is that they are: (1) Local variables, and hence FAST; (2) fully encapsulated inside the function. Using f.x fails on both accounts: - it requires a global name lookup for "f" (hence slow); - followed by an attribute lookup for "x" (hence even slower); - f.x is not encapsulated inside the function. It requires initialisation outside the function. The attribute f.x is easily visible to the caller. (Technically, so probably would static variables, but only by inspecting the function's internals. People know they're on thin-ice if they mess with them. And if we really needed to, we could protect the static storage inside the function from writing, if not reading, as we do with closures. f.x looks like an ordinary attribute.) I have used the f.x trick before, for things where speed was not critical, but I've never really loved the idea, and it certainly cannot be used as a replacement of the def func(arg, len=len, int=int) optimization trick. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sun Jun 24 04:23:22 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 03:23:22 -0500 Subject: translating foreign data Message-ID: <5B30F4ED.20990.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sun, 24 Jun 2018 12:53:49 +1000, Chris Angelico wrote: [...] >> Okay, you want a bit-pattern. In hex: >> >> '0x313030e282ac' [...] > Hmm. Actually, I'm a bit confused. > >>>> hex("100???".encode()) > Traceback (most recent call last): > File "", line 1, in > TypeError: 'bytes' object cannot be interpreted as an integer > > Nope, that's not it. Needs something to turn the bytes into an integer > first. But I can't find a way to do that. Best I can find is: > >>>> "100???".encode().hex() > '313030e282ac' Dammit, that was what I was looking for, but I only looked on *strings*, not bytes. > No "0x" prefix, no function call. So, I'm stuck. How did you create your > one? py> hex(int.from_bytes("100???".encode("utf-8"), 'big')) '0x313030e282ac' -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From breamoreboy at gmail.com Sun Jun 24 06:00:33 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Sun, 24 Jun 2018 11:00:33 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: On 24/06/18 00:44, boB Stepp wrote: > I imagine that the > transition from version 2 to 3 was not undertaken halfheartedly, but > only after much thought and discussion since it did break backwards > compatibility. > So much so that a specific mailing list was set up just to discus the transition, archives here https://mail.python.org/pipermail/python-3000/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steven.d'aprano at 1 Sun Jun 24 06:03:20 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 05:03:20 -0500 Subject: Quick survey: locals in comprehensions (Python 3 only) Message-ID: <5B30F4ED.20992.uclanpyth@castlerockbbs.com> From: Steven D'Aprano I'd like to run a quick survey. There is no right or wrong answer, since this is about your EXPECTATIONS, not what Python actually does. Given this function: def test(): a = 1 b = 2 result = [value for key, value in locals().items()] return result what would you expect the result of calling test() to be? Is that the result you think is most useful? In your opinion, is this a useful feature, a misfeature, a bug, or "whatever"? I'm only looking for answers for Python 3. (The results in Python 2 are genuinely weird :-) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bc at freeuk.com Sun Jun 24 06:18:37 2018 From: bc at freeuk.com (Bart) Date: Sun, 24 Jun 2018 11:18:37 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: <0eKXC.515410$eg.279610@fx43.am4> On 24/06/2018 00:44, boB Stepp wrote: > On Sat, Jun 23, 2018 at 5:35 PM Bart wrote: >> I'm not a user... > > Then I am truly puzzled, Bart. Why do you even bother to hang out on > this list? If you do not want to use Python and you do not want to > improve Python's design and implementation, what is your point of > being here? I wonder why it is just me that constantly needs to justify his existence in this group? Does someone need to be that much of a user of a language in order to discuss its design or its features or its efficiency, or how it compares with any other? You can do that from without as well as from within. Anyway I'm not here that often, I pop in from time to time when something interesting comes that I feel I can comment about. And yes I sometimes do that as a diversion because I enjoy this discussing this stuff. Why, is that allowed? As for why Python, it's the dynamic language I'm most familiar with, and I've been following it since the 1990s. Here's a small selection of threads I've posted in: Why not allow empty code blocks Python and the need for speed Building CPython What is a function parameter =[] for Considering migrating to Python from Visual Basic... How to read from a file to an arbitrary delimiter efficiently Python 2.x or 3.x, which is faster? The cost of Dynamism Case Statements [15-Mar-2016] The last is interesting. The OP there follows up with: "You have apparently mistaken me for someone who's worried. I don't use Python, I was just curious as to why a construct that is found, not only to be useful in 95% of other languages, but is generally considered more flexible and readable than the if-elif, was missing in Python. (your link 'Switch Statement Code Smell' not withstanding)" Many of the posters are explaining why Python doesn't have it, why they think the feature is so poor, and ways to get around the lack of it. Mine defend the feature. You're saying I shouldn't be allowed to put an alternative point of view because I don't use Python enough? I would say that because I /implement/ such features all the time in other languages, that my opinion is worthwhile. But people do seem to like to wind me up, and I like to defend my corner, so posts tend to proliferate. -- bart. From steven.d'aprano at 1 Sun Jun 24 06:22:06 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 05:22:06 -0500 Subject: Quick survey: locals in comprehensions (Python 3 only) Message-ID: <5B30F4ED.20994.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sun, 24 Jun 2018 15:18:49 +1000, Chris Angelico wrote: > Personally, I think it should give you [1, 2], the two values from the > function's locals. Thank you, that's the sort of answer I'm looking for. (I'm not saying I didn't read your long and involved analysis, only that I'm not looking for long involved analyses at the moment :-) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bc at freeuk.com Sun Jun 24 06:23:12 2018 From: bc at freeuk.com (Bart) Date: Sun, 24 Jun 2018 11:23:12 +0100 Subject: Static variables [was Re: syntax difference] In-Reply-To: <87tvptovh4.fsf@bsb.me.uk> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <2iyXC.494652$Vs7.246701@fx41.am4> <876029qgwc.fsf@bsb.me.uk> <4RAXC.526241$sl2.501394@fx46.am4> <87tvptovh4.fsf@bsb.me.uk> Message-ID: On 24/06/2018 01:53, Ben Bacarisse wrote: > Bart writes: >> Wow. (Just think of all the times you write a function containing a >> neat bunch of local functions, every time it's called it has to create >> a new function instances for each of those functions, even if they are >> not used.) > > I am surprised that this surprises you, and equally surprised that you > seem to think it's going to be in some way grossly inefficient. Steven D'Aprano's reply suggests there /is/ some inefficiency which is why [according to him] nested functions are rarely used that way. -- bartc From zondo42 at gmail.com Sun Jun 24 06:34:55 2018 From: zondo42 at gmail.com (Glenn Hutchings) Date: Sun, 24 Jun 2018 11:34:55 +0100 Subject: nltk related issue References: <69d3aa89-a66b-4631-9b78-e0b56d4dc824@googlegroups.com> Message-ID: On 21/06/18 04:40, Sharan Basappa wrote: > Folks, > > I am trying to run a simple example associated with nltk. > I get some error and I don't know what the issue is. > I need some guidance please. > [...] > LookupError: > ********************************************************************** > Resource u'tokenizers/punkt/english.pickle' not found. Please > use the NLTK Downloader to obtain the resource: >>> > nltk.download() > Searched in: > - 'D:\\Users\\sharanb/nltk_data' > - 'C:\\nltk_data' > - 'D:\\nltk_data' > - 'E:\\nltk_data' > - 'D:\\Users\\sharanb\\AppData\\Local\\Enthought\\Canopy\\edm\\envs\\User\\nltk_data' > - 'D:\\Users\\sharanb\\AppData\\Local\\Enthought\\Canopy\\edm\\envs\\User\\lib\\nltk_data' > - 'D:\\Users\\sharanb\\AppData\\Roaming\\nltk_data' > - u'' > ********************************************************************** > As the error message says, you need to do a one-time installation of the NLTK data. See http://www.nltk.org/data.html for more info. Glenn From steve+comp.lang.python at pearwood.info Sun Jun 24 06:40:49 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 10:40:49 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <0eKXC.515410$eg.279610@fx43.am4> Message-ID: On Sun, 24 Jun 2018 11:18:37 +0100, Bart wrote: > I wonder why it is just me that constantly needs to justify his > existence in this group? Because its just you who spends 90% of his time here complaining about how Python does it wrong. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sun Jun 24 06:51:54 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 10:51:54 +0000 (UTC) Subject: Static variables [was Re: syntax difference] References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <2iyXC.494652$Vs7.246701@fx41.am4> <876029qgwc.fsf@bsb.me.uk> <4RAXC.526241$sl2.501394@fx46.am4> <87tvptovh4.fsf@bsb.me.uk> Message-ID: On Sun, 24 Jun 2018 11:23:12 +0100, Bart wrote: > On 24/06/2018 01:53, Ben Bacarisse wrote: >> Bart writes: > >>> Wow. (Just think of all the times you write a function containing a >>> neat bunch of local functions, every time it's called it has to create >>> a new function instances for each of those functions, even if they are >>> not used.) >> >> I am surprised that this surprises you, and equally surprised that you >> seem to think it's going to be in some way grossly inefficient. > > Steven D'Aprano's reply suggests there /is/ some inefficiency which is > why [according to him] nested functions are rarely used that way. Building functions is cheap. Cheap is not free. Inner functions that aren't exposed to the outside cannot be tested in isolation, you can't access them through help() interactively. Given the choice between: # can't test eggs, can't re-use it def func(): def eggs(): ... ... and: # can test it, can re-use it def _eggs(): ... def func(): ... most people go for the later simply because it is better development practice. The very small performance penalty hardly comes into it. For what its worth, the cost of assembling a basic function is comparable to creating an empty dict: [steve at ando ~]$ python3.5 -m timeit "lambda: None" 10000000 loops, best of 3: 0.195 usec per loop [steve at ando ~]$ python3.5 -m timeit "{}" 1000000 loops, best of 3: 0.212 usec per loop so not expensive, but not free either. If using an inner function has no advantages to you, why pay that tiny cost for no benefit? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From chris.angelico at 1 Sun Jun 24 07:13:16 2018 From: chris.angelico at 1 (Chris Angelico) Date: Sun, 24 Jun 2018 06:13:16 -0500 Subject: Static variables [was Re: syntax difference] Message-ID: <5B30F4ED.20970.uclanpyth@castlerockbbs.com> From: Chris Angelico On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: > This is an example of a simple concept getting so out of hand that it will > either never be implemented, or the resulting implementation becomes > impractical to use. > > This is what we're trying to do: > > def nextx(): > static x = 0 > x += 1 > return x > > And this is the simplest equivalent code in current Python that will cater > for 99% of uses: > > _nextx_x = 0 > > def nextx(): > global _nextx_x > _nextx_x += 1 > return _nextx_x > > No nested functions. No generating new instances of functions complete with > a new set of statics each time you happen to refer to the name. (Which > sounds to me as useful as creating a new instance of an import when you copy > its name, complete with a separate set of its globals. Isn't this stuff what > classes are for?) > > (At what point would that happen anyway; if you do this: > > g = nextx # hypothetical version would static > > it will create a new instance of 'nextx'. But it won't create one here, just > before () is applied: > > nextx() # ? > > Or how about here: > > listoffunctions = (nextx1, nextx2, nextx3) > > listoffunctions[i]() # ? > > ) Clearly you have completely misunderstood the entire concept of Python's memory model, so I am not going to engage in debate with you on this. This is my ONLY post explaining this to you. NONE of your examples are taking copies of the function. They all are making REFERENCES to the same function. That is all. Creating new functions is the job of 'def' and 'lambda'. Not assignment. So the concept of "multiple functions with the same name" comes from executing the def statement more than once. ChrisA --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steve+comp.lang.python at pearwood.info Sun Jun 24 07:35:57 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 11:35:57 +0000 (UTC) Subject: Python for beginners or not? [was Re: syntax difference] References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: On Sat, 23 Jun 2018 14:52:24 -0500, boB Stepp wrote: [...] >> There is a place for various levels of programming language. I'm saying >> that Python which is always touted as a 'simple' language suitable for >> beginners, is missing a surprising number of basics. > > I still feel like a rank beginner, but on the Tutor list some disagree. It has been a long, long time since Python has been a "simple" language suitable for rank beginners, if it ever was. Python is not Scratch. https://scratch.mit.edu/ Right from version 1.0, Python has included some advanced features, even mind-blowing features (metaclasses, a.k.a. "the killer joke"). We're now up to version 3.6 (in production) and 3.7 (in beta) and Python includes some very advanced modern[1] features, like syntactic support for asynchronous programming, decorators, generators, coroutines and more. Better to say that Python is *accessible* to beginners: you can do a lot of good work in Python using simple constructs and imperative scripts, and most importantly, the syntax generally doesn't get in your way. There's relatively little boilterplate needed and a gentle learning curve. Compare "Hello World" in Java and Python: public class HelloWorld { public static void main(String[] args) { // Prints "Hello, World" to the terminal window. System.out.println("Hello, World"); } } versus: print("Hello, World") The Python example requires the programmer to learn effectively three things (print, parentheses, strings), compared to over a dozen for Java: - classes; braces; parentheses; strings; methods; attribute access using dot; "public" declarations; "static" declarations; "void" declarations; type declarations; the existence of System; System.out; System.out.println; semicolons; the implicit calling of main. Aside: there's an extensive, and yet still incomplete, list of Hello World programs here http://helloworldcollection.de/ with some impressive examples. Enjoy! [...] > As an aside we just had another round of software, OS and hardware > upgrades. Now I can use Python 2.7! Yay! Welcome to the 2000s! Hope you will catch up to Python 3 by the 2020s :-) > Because I read and study about new things as I take them up, I soon > learned that I had only so far scratched the surface of Python's depths. > But despite knowing that Python had many more features to explore, both > in the core language and the standard library, this never hindered me in > writing my beginner-level programs. I got things done, and I got them > done fairly easily, and never felt burdened by all the "other stuff" > that Python had to offer. Indeed. That's one of the beauties of Python -- even when there's an advanced way to do it, there's generally a simple way too. [1] I say "modern", but in fact very little in computer science wasn't invented by Lisp in the 1950s, or if not Lisp, by CLU in the 1970s. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From ben.finney at 1 Sun Jun 24 08:31:28 2018 From: ben.finney at 1 (Ben Finney) Date: Sun, 24 Jun 2018 07:31:28 -0500 Subject: translating foreign data Message-ID: <5B30F4ED.20973.uclanpyth@castlerockbbs.com> From: Ben Finney Richard Damon writes: > On 6/23/18 11:27 AM, Steven D'Aprano wrote: > >> On 6/23/18 9:05 AM, Marko Rauhamaa wrote: > >>> Richard Damon wrote: > >>> > Data presented to the user should normally use his locale > >>> > (unless he has specified something different). > >>> > >>> Ok. Here's a value for you: > >>> > >>> 100??? > >>> > > [? |] > > The data you were given was 100 Euros. If your system is incapable > > of reading that as 100 Euros, and errors out, then at least to know > > that it is brain-damaged and useless. > > > > But if instead it silently changes the data to $100 (US dollars? > > Australian dollars? Zimbabwe dollars? the gods only know what a > > system that broken might do...) then it is not only broken but > > *dangerously* broken. > > > [? |] > > The number CAN'T say 100 Euros (can you give me what bit pattern you > would use for such a number). That is (I believe) the point being made: The data is *not* a number. It is a value that must encapsulate more than only the number 100, but also and simultaneously the curency ? ?Euro? ?. > The currency is encoded in the locale used for the conversion, so if it > is using en-US, the currency value would ALWAYS be US$ (which the > general locale format is just $). As such 100??? is an invalid input to a > system getting a Locale based input for a currency if the locale is not > one from a country that uses the euro. The value is 100 Euro, a quantity of a particular currency and not something trivially converted to US$ (for many reasons, including the obvious one that we don't know the exact exchange rate to use, and it will be different at a different time). You appear to be arguing that this value must either be arbitrarily converted to the user's local currency, something we agree is impossible to do given the data, or the value is simply invalid. So the rule you assert ? ? ? ?Data presented to the user should normally use his locale? ? ? ? fails to usefuly handle the very normal case of data that represents a quantity of some foreign currency. Any system following your asserted rule will give either the wrong answer, or an error. We had better hope the rule you assert is not in effect. -- \ ? ?DRM doesn't inconvenience [lawbreakers] ? ? indeed, over time it | `\ trains law-abiding users to become [lawbreakers] out of sheer | _o__) frustration.? ? ? ?Charles Stross, 2010-05-09 | Ben Finney --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steve+comp.lang.python at pearwood.info Sun Jun 24 08:51:40 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 12:51:40 +0000 (UTC) Subject: Introducing Coconut Message-ID: Coconut, the functional programming language which compiles to Python: http://coconut.readthedocs.io/en/master/FAQ.html http://coconut-lang.org/ (Its not my language. I just think its cool.) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From justin.walters at 1 Sun Jun 24 08:53:48 2018 From: justin.walters at 1 (justin walters) Date: Sun, 24 Jun 2018 07:53:48 -0500 Subject: Introducing Coconut Message-ID: <5B30F4EE.21025.uclanpyth@castlerockbbs.com> From: justin walters On Sun, Jun 24, 2018 at 5:51 AM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > Coconut, the functional programming language which compiles to Python: > > http://coconut.readthedocs.io/en/master/FAQ.html > > http://coconut-lang.org/ > > (Its not my language. I just think its cool.) > > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson > > -- > https://mail.python.org/mailman/listinfo/python-list > As someone who has been studying Elixir and Phoenix lately, This is pretty neat. There have definitely been some pieces of my Python projects that could have benefited from a Functional structure. I don't think writing an entire project in Cocounut would be worth while. At that point, why not use an actual FP language? However, I do think it sounds useful for when certain parts of a project could be cleaned up or optimized with functional code. Almost like a better `functools`. All that said though, I am interested to see performance metrics for the transpiled python. --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From rick.johnson at 1 Sun Jun 24 09:23:02 2018 From: rick.johnson at 1 (Rick Johnson) Date: Sun, 24 Jun 2018 08:23:02 -0500 Subject: syntax difference In-Reply-To: <5B30F4EE.21026.uclanpyth@castlerockbbs.com> References: <5B30F4EE.21026.uclanpyth@castlerockbbs.com> Message-ID: <5B30F4EE.21027.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: Rick Johnson On Sunday, June 24, 2018 at 10:05:14 AM UTC-5, Steven D'Aprano wrote: [...] > Be fair. It's more like 50% of the time. Let's not dogpile > onto Bart. He asked a question, I answered it, we don't all > need to sink the boot in as well. And why am i _not_ surprised to learn that Steven defines "community" as kicking and dogpiling others 50% of the time. Well, at least it wasn't 100%... Eh? o_O --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From rick.johnson at 1 Sun Jun 24 09:23:02 2018 From: rick.johnson at 1 (Rick Johnson) Date: Sun, 24 Jun 2018 08:23:02 -0500 Subject: syntax difference Message-ID: <5B324678.21174.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: "Rick Johnson" To: Steven D'Aprano From: Rick Johnson On Sunday, June 24, 2018 at 10:05:14 AM UTC-5, Steven D'Aprano wrote: [...] > Be fair. It's more like 50% of the time. Let's not dogpile > onto Bart. He asked a question, I answered it, we don't all > need to sink the boot in as well. And why am i _not_ surprised to learn that Steven defines "community" as kicking and dogpiling others 50% of the time. Well, at least it wasn't 100%... Eh? o_O -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From boblatest at yahoo.com Sun Jun 24 09:58:31 2018 From: boblatest at yahoo.com (Robert Latest) Date: 24 Jun 2018 13:58:31 GMT Subject: Package directory question Message-ID: Hello, I'm building an application which consists of two largely distinct parts, a frontend and a backend. The directory layout is like this: |-- jobwatch | |-- backend | | |-- backend.py | | |-- __init__.py | | `-- tables.py | |-- frontend | | |-- __init__.py | | |-- main.py | `-- __init__.py `-- setup.py Because the main.py script needs to import the tables.py module from backend, I put this at the top if main.py: sys.path.append('../..') import jobwatch.backend.tables as tables My question is: Is this the way it should be done? It looks fishy. The only alternative I could come up with is to put a symlink to tables.py into the frontend directory, which also seems fishy. Eventually I want to package all this up neatly to be able to use only little wrapper scripts for the backend (running as a service) and the frontend (a wsgi app). Any thoughts? Thanks robert From chris.angelico at 1 Sun Jun 24 10:42:12 2018 From: chris.angelico at 1 (Chris Angelico) Date: Sun, 24 Jun 2018 09:42:12 -0500 Subject: Static variables [was Re: syntax difference] Message-ID: <5B30F4ED.20978.uclanpyth@castlerockbbs.com> From: Chris Angelico On Sun, Jun 24, 2018 at 9:37 AM, Bart wrote: > On 23/06/2018 23:25, Ben Bacarisse wrote: >> >> Bart writes: >> >>> On 23/06/2018 21:13, Chris Angelico wrote: >>>> >>>> On Sat, Jun 23, 2018 at 10:41 PM, Bart wrote: >>> >>> >>>>> (At what point would that happen anyway; if you do this: >>> >>> >>>> NONE of your examples are taking copies of the function. They all are >>>> making REFERENCES to the same function. That is all. >>> >>> >>> This is about your notion that invocations of the same function via >>> different references, should maintain their own versions of the >>> function's 'static' data. >>> >>> Since these references are created via the return g statement here: >>> >>> def f(): >>> def g(): >>> .... >>> return g >>> >>> (say to create function references i and j like this: >>> >>> i = f() >>> j = f() >>> ) >>> >>> I'm assuming that something special must be happening. Otherwise, how >>> does f() know which reference it's being called via? >>> >>> What is different, what extra bit of information is provided when f() >>> is invoked via i() or j()? >> >> >> f is not being invoked by either i() or j(). i = f() binds i to the >> function returned by f. That's a newly minted function. In languages >> like Python, executing def creates a function. > > > Do you mean that if the same 'def' block is re-executed, it will create a > different instance of the function? (Same byte-code, but a different set of > everything else the function uses.) > > Wow. (Just think of all the times you write a function containing a neat > bunch of local functions, every time it's called it has to create a new > function instances for each of those functions, even if they are not used.) ... do you even understand what closures are? ChrisA --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From rosuav at gmail.com Sun Jun 24 10:46:00 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Jun 2018 00:46:00 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <0eKXC.515410$eg.279610@fx43.am4> Message-ID: On Sun, Jun 24, 2018 at 8:40 PM, Steven D'Aprano wrote: > On Sun, 24 Jun 2018 11:18:37 +0100, Bart wrote: > >> I wonder why it is just me that constantly needs to justify his >> existence in this group? > > Because its just you who spends 90% of his time here complaining about > how Python does it wrong. ... and spends 95% of that time demonstrating his utter lack of understanding of how Python does it at all. It's wrong even though you don't understand how it actually works. ChrisA From walters.justin01 at gmail.com Sun Jun 24 10:53:48 2018 From: walters.justin01 at gmail.com (justin walters) Date: Sun, 24 Jun 2018 07:53:48 -0700 Subject: Introducing Coconut In-Reply-To: References: Message-ID: On Sun, Jun 24, 2018 at 5:51 AM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > Coconut, the functional programming language which compiles to Python: > > http://coconut.readthedocs.io/en/master/FAQ.html > > http://coconut-lang.org/ > > (Its not my language. I just think its cool.) > > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson > > -- > https://mail.python.org/mailman/listinfo/python-list > As someone who has been studying Elixir and Phoenix lately, This is pretty neat. There have definitely been some pieces of my Python projects that could have benefited from a Functional structure. I don't think writing an entire project in Cocounut would be worth while. At that point, why not use an actual FP language? However, I do think it sounds useful for when certain parts of a project could be cleaned up or optimized with functional code. Almost like a better `functools`. All that said though, I am interested to see performance metrics for the transpiled python. From steve+comp.lang.python at pearwood.info Sun Jun 24 11:02:40 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 15:02:40 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <0eKXC.515410$eg.279610@fx43.am4> Message-ID: On Mon, 25 Jun 2018 00:46:00 +1000, Chris Angelico wrote: > On Sun, Jun 24, 2018 at 8:40 PM, Steven D'Aprano > wrote: >> On Sun, 24 Jun 2018 11:18:37 +0100, Bart wrote: >> >>> I wonder why it is just me that constantly needs to justify his >>> existence in this group? >> >> Because its just you who spends 90% of his time here complaining about >> how Python does it wrong. > > ... and spends 95% of that time demonstrating his utter lack of > understanding of how Python does it at all. It's wrong even though you > don't understand how it actually works. Be fair. It's more like 50% of the time. Let's not dogpile onto Bart. He asked a question, I answered it, we don't all need to sink the boot in as well. Nobody expects Bart to love Python, but if he wants to fit in here, in a Python group, he ought to either at least make an effort to understand the reasons Python is what it is (and not just idiocy and bloat) and appreciate it for what it is, not for what it isn't. Or at least avoid trying to lecture us on why we're doing it wrong. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From robertvstepp at gmail.com Sun Jun 24 11:37:34 2018 From: robertvstepp at gmail.com (boB Stepp) Date: Sun, 24 Jun 2018 10:37:34 -0500 Subject: syntax difference In-Reply-To: <0eKXC.515410$eg.279610@fx43.am4> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <0eKXC.515410$eg.279610@fx43.am4> Message-ID: On Sun, Jun 24, 2018 at 5:21 AM Bart wrote: > > On 24/06/2018 00:44, boB Stepp wrote: > > On Sat, Jun 23, 2018 at 5:35 PM Bart wrote: > > >> I'm not a user... > > > > Then I am truly puzzled, Bart. Why do you even bother to hang out on > > this list? If you do not want to use Python and you do not want to > > improve Python's design and implementation, what is your point of > > being here? > > I wonder why it is just me that constantly needs to justify his > existence in this group? You snipped the unpleasant part of my paragraph: "... You *do* seem to generate a lot of ill will, I hope unintentionally..." > Does someone need to be that much of a user of a language in order > to discuss its design or its features or its efficiency, or how it > compares with any other? You can do that from without as well as > from within. I don't dispute this. But there are good ways to do this and there are bad ways to do this. You seem to fall into the latter category enough that at a minimum you irritate people who care very deeply about Python, and, at worst, outright enrage some. > As for why Python, it's the dynamic language I'm most familiar > with, and I've been following it since the 1990s. And this gets to the crux of the matter. If this is so, why is it that you repeatedly demonstrate a lack of understanding of the very things you are critiquing? I cannot recall how many times you have been called out on this point, but it is certainly not an uncommon event. It is one thing to have demonstrable technical understanding of one or more concepts, and critique those concepts with valid, or at least, interesting points, but it is entirely another thing to be criticizing (How you are often perceived.) something in Python while at the same time demonstrating you don't really understand the particular Pythonic implementation or usage you are criticizing. Don't you see the difference? Don't you see what it is that so riles people? But things do not have to be this way! As I said later in my paragraph I have been referencing: "... But why not take a different, more helpful tack? You seem to have a lot of ideas. If you really think they are applicable to improving the Python language, why not take your ideas, one at a time, and have serious discussion, perhaps better on Python-Ideas, on how Python can be meaningfully made better? That would be a helpful approach which I think, if done with the intention of helping Python to be the best language it can be (Within the constraints it has to operate within in practice.), then I would hope your potential contributions would be positively received by the community..." And: "... And of course, you would have to know how to use Python properly in idiomatic style. Why not choose this positive approach? I think it would be a win-win for both you and Python." Just show you genuinely care about the language and the community. Use and understand the language as well as you can before jumping into criticisms. Adopt the path of the humble learner, who does not know everything about Python. Is this too much to ask? -- boB From bob.stepp at 1 Sun Jun 24 11:37:34 2018 From: bob.stepp at 1 (boB Stepp) Date: Sun, 24 Jun 2018 10:37:34 -0500 Subject: syntax difference Message-ID: <5B30F4EE.21028.uclanpyth@castlerockbbs.com> From: boB Stepp On Sun, Jun 24, 2018 at 5:21 AM Bart wrote: > > On 24/06/2018 00:44, boB Stepp wrote: > > On Sat, Jun 23, 2018 at 5:35 PM Bart wrote: > > >> I'm not a user... > > > > Then I am truly puzzled, Bart. Why do you even bother to hang out on > > this list? If you do not want to use Python and you do not want to > > improve Python's design and implementation, what is your point of > > being here? > > I wonder why it is just me that constantly needs to justify his > existence in this group? You snipped the unpleasant part of my paragraph: "... You *do* seem to generate a lot of ill will, I hope unintentionally..." > Does someone need to be that much of a user of a language in order > to discuss its design or its features or its efficiency, or how it > compares with any other? You can do that from without as well as > from within. I don't dispute this. But there are good ways to do this and there are bad ways to do this. You seem to fall into the latter category enough that at a minimum you irritate people who care very deeply about Python, and, at worst, outright enrage some. > As for why Python, it's the dynamic language I'm most familiar > with, and I've been following it since the 1990s. And this gets to the crux of the matter. If this is so, why is it that you repeatedly demonstrate a lack of understanding of the very things you are critiquing? I cannot recall how many times you have been called out on this point, but it is certainly not an uncommon event. It is one thing to have demonstrable technical understanding of one or more concepts, and critique those concepts with valid, or at least, interesting points, but it is entirely another thing to be criticizing (How you are often perceived.) something in Python while at the same time demonstrating you don't really understand the particular Pythonic implementation or usage you are criticizing. Don't you see the difference? Don't you see what it is that so riles people? But things do not have to be this way! As I said later in my paragraph I have been referencing: "... But why not take a different, more helpful tack? You seem to have a lot of ideas. If you really think they are applicable to improving the Python language, why not take your ideas, one at a time, and have serious discussion, perhaps better on Python-Ideas, on how Python can be meaningfully made better? That would be a helpful approach which I think, if done with the intention of helping Python to be the best language it can be (Within the constraints it has to operate within in practice.), then I would hope your potential contributions would be positively received by the community..." And: "... And of course, you would have to know how to use Python properly in idiomatic style. Why not choose this positive approach? I think it would be a win-win for both you and Python." Just show you genuinely care about the language and the community. Use and understand the language as well as you can before jumping into criticisms. Adopt the path of the humble learner, who does not know everything about Python. Is this too much to ask? -- boB --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From rosuav at gmail.com Sun Jun 24 11:38:22 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Jun 2018 01:38:22 +1000 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <0eKXC.515410$eg.279610@fx43.am4> Message-ID: On Mon, Jun 25, 2018 at 1:02 AM, Steven D'Aprano wrote: > On Mon, 25 Jun 2018 00:46:00 +1000, Chris Angelico wrote: > >> On Sun, Jun 24, 2018 at 8:40 PM, Steven D'Aprano >> wrote: >>> On Sun, 24 Jun 2018 11:18:37 +0100, Bart wrote: >>> >>>> I wonder why it is just me that constantly needs to justify his >>>> existence in this group? >>> >>> Because its just you who spends 90% of his time here complaining about >>> how Python does it wrong. >> >> ... and spends 95% of that time demonstrating his utter lack of >> understanding of how Python does it at all. It's wrong even though you >> don't understand how it actually works. > > Be fair. It's more like 50% of the time. > > Let's not dogpile onto Bart. He asked a question, I answered it, we don't > all need to sink the boot in as well. Fair. Still, it does seem that most of the criticisms are based on ignorance, not reasoned disagreement. For instance, I could argue that Python's model of "variables are local if written to, otherwise they're looked up globally" is a poor choice, because I have extensively used Python AND other (C-like) models. Or I could argue that Python really ought to support "foo bar baz"/" " as a syntax for string splitting, because I've used Python's way of doing things, and have also used something that works differently. But I cannot argue that Python should have mutable strings, because I've never used a modern language that has them, so I don't know what the tradeoffs are. Thus you don't hear me pushing for it. ChrisA From bc at freeuk.com Sun Jun 24 11:39:19 2018 From: bc at freeuk.com (Bart) Date: Sun, 24 Jun 2018 16:39:19 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <0eKXC.515410$eg.279610@fx43.am4> Message-ID: On 24/06/2018 15:46, Chris Angelico wrote: > On Sun, Jun 24, 2018 at 8:40 PM, Steven D'Aprano > wrote: >> On Sun, 24 Jun 2018 11:18:37 +0100, Bart wrote: >> >>> I wonder why it is just me that constantly needs to justify his >>> existence in this group? >> >> Because its just you who spends 90% of his time here complaining about >> how Python does it wrong. > > ... and spends 95% of that time demonstrating his utter lack of > understanding of how Python does it at all. It's wrong even though you > don't understand how it actually works. More like utter disbelief at how it works. Surely it cannot work like that because it would be too inefficient? Apparently, yes it can... And all to support extreme dynamism which is only really needed a tiny proportion of the time (feel free to correct me). I know I'm going to get flak for bringing this up this old issue, but remember when you used to write a for-loop and it involved creating an actual list of N integers from 0 to N-1 in order to iterate through them? Crazy. But that has long been fixed - or so I thought. When I wrote, today: for i in range(100000000): pass # 100 million on Python 2, it used up 1.8GB, up to the limit of my RAM, and it took several minutes to regain control of my machine (and it never did finish). You don't expect that in 2018 when executing a simple empty loop. On Py 2 you have to use xrange for large ranges - that was the fix. Somebody however must have had to gently and tactfully point out the issue. I'm afraid I'm not very tactful. -- bart From steven.d'aprano at 1 Sun Jun 24 11:40:48 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 10:40:48 -0500 Subject: syntax difference Message-ID: <5B30F4ED.21003.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sun, 24 Jun 2018 11:18:37 +0100, Bart wrote: > I wonder why it is just me that constantly needs to justify his > existence in this group? Because its just you who spends 90% of his time here complaining about how Python does it wrong. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From jim.lee at 1 Sun Jun 24 11:46:08 2018 From: jim.lee at 1 (Jim Lee) Date: Sun, 24 Jun 2018 10:46:08 -0500 Subject: Python for beginners or not? [was Re: syntax difference] Message-ID: <5B324678.21139.uclanpyth@castlerockbbs.com> From: Jim Lee On 06/24/2018 04:35 AM, Steven D'Aprano wrote: > > Indeed. That's one of the beauties of Python -- even when there's an > advanced way to do it, there's generally a simple way too. > > What happened to the Python maxim "There should be one? ?and preferably only one? ?obvious way to do it"? -Jim --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sun Jun 24 11:51:54 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 10:51:54 -0500 Subject: Static variables [was Re: syntax difference] Message-ID: <5B30F4ED.21004.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sun, 24 Jun 2018 11:23:12 +0100, Bart wrote: > On 24/06/2018 01:53, Ben Bacarisse wrote: >> Bart writes: > >>> Wow. (Just think of all the times you write a function containing a >>> neat bunch of local functions, every time it's called it has to create >>> a new function instances for each of those functions, even if they are >>> not used.) >> >> I am surprised that this surprises you, and equally surprised that you >> seem to think it's going to be in some way grossly inefficient. > > Steven D'Aprano's reply suggests there /is/ some inefficiency which is > why [according to him] nested functions are rarely used that way. Building functions is cheap. Cheap is not free. Inner functions that aren't exposed to the outside cannot be tested in isolation, you can't access them through help() interactively. Given the choice between: # can't test eggs, can't re-use it def func(): def eggs(): ... ... and: # can test it, can re-use it def _eggs(): ... def func(): ... most people go for the later simply because it is better development practice. The very small performance penalty hardly comes into it. For what its worth, the cost of assembling a basic function is comparable to creating an empty dict: [steve at ando ~]$ python3.5 -m timeit "lambda: None" 10000000 loops, best of 3: 0.195 usec per loop [steve at ando ~]$ python3.5 -m timeit "{}" 1000000 loops, best of 3: 0.212 usec per loop so not expensive, but not free either. If using an inner function has no advantages to you, why pay that tiny cost for no benefit? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From arj.python at gmail.com Sun Jun 24 11:53:16 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 24 Jun 2018 19:53:16 +0400 Subject: Introducing Coconut In-Reply-To: References: Message-ID: hum syntactic coating exists even in py. nice! Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > > From mark.lawrence at 1 Sun Jun 24 12:00:32 2018 From: mark.lawrence at 1 (Mark Lawrence) Date: Sun, 24 Jun 2018 11:00:32 -0500 Subject: syntax difference Message-ID: <5B324678.21140.uclanpyth@castlerockbbs.com> From: Mark Lawrence On 24/06/18 00:44, boB Stepp wrote: > I imagine that the > transition from version 2 to 3 was not undertaken halfheartedly, but > only after much thought and discussion since it did break backwards > compatibility. > So much so that a specific mailing list was set up just to discus the transition, archives here https://mail.python.org/pipermail/python-3000/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steve+comp.lang.python at pearwood.info Sun Jun 24 12:07:51 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 16:07:51 +0000 (UTC) Subject: Anyone here on Python-Dev mailing list? Message-ID: Anyone on the Python-Dev mailing list, are you getting private emails containing nothing but stream of consciousness word-salad from somebody (some bot?) calling himself "Chanel Marvin" with a gmail address? Typical example: "I refuse to create my environment on a computer. Stalls and static and it always looks fake unless I can afford all the cool fast stuff like Prometheus speed but for dummies in plain white english" in reply to an email I posted to the list. I don't want to ask there, yet, in case it isn't a bot but some nutter with an attitude emailing me privately. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sun Jun 24 12:15:42 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Jun 2018 02:15:42 +1000 Subject: Anyone here on Python-Dev mailing list? In-Reply-To: References: Message-ID: On Mon, Jun 25, 2018 at 2:07 AM, Steven D'Aprano wrote: > Anyone on the Python-Dev mailing list, are you getting private emails > containing nothing but stream of consciousness word-salad from somebody > (some bot?) calling himself "Chanel Marvin" with a gmail address? > > Typical example: > > "I refuse to create my environment on a computer. Stalls and static > and it always looks fake unless I can afford all the cool fast stuff > like Prometheus speed but for dummies in plain white english" > > in reply to an email I posted to the list. > > I don't want to ask there, yet, in case it isn't a bot but some nutter > with an attitude emailing me privately. > Yeah, I got one of those. I'm pretty sure it's a Markov chainer. ChrisA From bart at 1 Sun Jun 24 12:18:36 2018 From: bart at 1 (Bart) Date: Sun, 24 Jun 2018 11:18:36 -0500 Subject: syntax difference In-Reply-To: <5B30F4ED.20979.uclanpyth@castlerockbbs.com> References: <5B30F4ED.20979.uclanpyth@castlerockbbs.com> Message-ID: <5B30F4ED.21000.uclanpyth@castlerockbbs.com> To: boB Stepp From: Bart On 24/06/2018 00:44, boB Stepp wrote: > On Sat, Jun 23, 2018 at 5:35 PM Bart wrote: >> I'm not a user... > > Then I am truly puzzled, Bart. Why do you even bother to hang out on > this list? If you do not want to use Python and you do not want to > improve Python's design and implementation, what is your point of > being here? I wonder why it is just me that constantly needs to justify his existence in this group? Does someone need to be that much of a user of a language in order to discuss its design or its features or its efficiency, or how it compares with any other? You can do that from without as well as from within. Anyway I'm not here that often, I pop in from time to time when something interesting comes that I feel I can comment about. And yes I sometimes do that as a diversion because I enjoy this discussing this stuff. Why, is that allowed? As for why Python, it's the dynamic language I'm most familiar with, and I've been following it since the 1990s. Here's a small selection of threads I've posted in: Why not allow empty code blocks Python and the need for speed Building CPython What is a function parameter =[] for Considering migrating to Python from Visual Basic... How to read from a file to an arbitrary delimiter efficiently Python 2.x or 3.x, which is faster? The cost of Dynamism Case Statements [15-Mar-2016] The last is interesting. The OP there follows up with: "You have apparently mistaken me for someone who's worried. I don't use Python, I was just curious as to why a construct that is found, not only to be useful in 95% of other languages, but is generally considered more flexible and readable than the if-elif, was missing in Python. (your link 'Switch Statement Code Smell' not withstanding)" Many of the posters are explaining why Python doesn't have it, why they think the feature is so poor, and ways to get around the lack of it. Mine defend the feature. You're saying I shouldn't be allowed to put an alternative point of view because I don't use Python enough? I would say that because I /implement/ such features all the time in other languages, that my opinion is worthwhile. But people do seem to like to wind me up, and I like to defend my corner, so posts tend to proliferate. -- bart. --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bart at 1 Sun Jun 24 12:18:36 2018 From: bart at 1 (Bart) Date: Sun, 24 Jun 2018 11:18:36 -0500 Subject: syntax difference Message-ID: <5B324678.21171.uclanpyth@castlerockbbs.com> To: boB Stepp From: "Bart" To: boB Stepp From: Bart On 24/06/2018 00:44, boB Stepp wrote: > On Sat, Jun 23, 2018 at 5:35 PM Bart wrote: >> I'm not a user... > > Then I am truly puzzled, Bart. Why do you even bother to hang out on > this list? If you do not want to use Python and you do not want to > improve Python's design and implementation, what is your point of > being here? I wonder why it is just me that constantly needs to justify his existence in this group? Does someone need to be that much of a user of a language in order to discuss its design or its features or its efficiency, or how it compares with any other? You can do that from without as well as from within. Anyway I'm not here that often, I pop in from time to time when something interesting comes that I feel I can comment about. And yes I sometimes do that as a diversion because I enjoy this discussing this stuff. Why, is that allowed? As for why Python, it's the dynamic language I'm most familiar with, and I've been following it since the 1990s. Here's a small selection of threads I've posted in: Why not allow empty code blocks Python and the need for speed Building CPython What is a function parameter =[] for Considering migrating to Python from Visual Basic... How to read from a file to an arbitrary delimiter efficiently Python 2.x or 3.x, which is faster? The cost of Dynamism Case Statements [15-Mar-2016] The last is interesting. The OP there follows up with: "You have apparently mistaken me for someone who's worried. I don't use Python, I was just curious as to why a construct that is found, not only to be useful in 95% of other languages, but is generally considered more flexible and readable than the if-elif, was missing in Python. (your link 'Switch Statement Code Smell' not withstanding)" Many of the posters are explaining why Python doesn't have it, why they think the feature is so poor, and ways to get around the lack of it. Mine defend the feature. You're saying I shouldn't be allowed to put an alternative point of view because I don't use Python enough? I would say that because I /implement/ such features all the time in other languages, that my opinion is worthwhile. But people do seem to like to wind me up, and I like to defend my corner, so posts tend to proliferate. -- bart. -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From breamoreboy at gmail.com Sun Jun 24 12:22:16 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Sun, 24 Jun 2018 17:22:16 +0100 Subject: Anyone here on Python-Dev mailing list? In-Reply-To: References: Message-ID: On 24/06/18 17:07, Steven D'Aprano wrote: > Anyone on the Python-Dev mailing list, are you getting private emails > containing nothing but stream of consciousness word-salad from somebody > (some bot?) calling himself "Chanel Marvin" with a gmail address? > > Typical example: > > "I refuse to create my environment on a computer. Stalls and static > and it always looks fake unless I can afford all the cool fast stuff > like Prometheus speed but for dummies in plain white english" > > in reply to an email I posted to the list. > > I don't want to ask there, yet, in case it isn't a bot but some nutter > with an attitude emailing me privately. > I see nothing like this reading python-dev via gmane. I rarely get anything in my private email inboxes about Python. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From bart at 1 Sun Jun 24 12:23:12 2018 From: bart at 1 (Bart) Date: Sun, 24 Jun 2018 11:23:12 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B30F4ED.20980.uclanpyth@castlerockbbs.com> References: <5B30F4ED.20980.uclanpyth@castlerockbbs.com> Message-ID: <5B30F4ED.21001.uclanpyth@castlerockbbs.com> To: Ben Bacarisse From: Bart On 24/06/2018 01:53, Ben Bacarisse wrote: > Bart writes: >> Wow. (Just think of all the times you write a function containing a >> neat bunch of local functions, every time it's called it has to create >> a new function instances for each of those functions, even if they are >> not used.) > > I am surprised that this surprises you, and equally surprised that you > seem to think it's going to be in some way grossly inefficient. Steven D'Aprano's reply suggests there /is/ some inefficiency which is why [according to him] nested functions are rarely used that way. -- bartc --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bart at 1 Sun Jun 24 12:23:12 2018 From: bart at 1 (Bart) Date: Sun, 24 Jun 2018 11:23:12 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B324678.21168.uclanpyth@castlerockbbs.com> References: <5B324678.21168.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21172.uclanpyth@castlerockbbs.com> To: Ben Bacarisse From: "Bart" To: Ben Bacarisse From: Bart On 24/06/2018 01:53, Ben Bacarisse wrote: > Bart writes: >> Wow. (Just think of all the times you write a function containing a >> neat bunch of local functions, every time it's called it has to create >> a new function instances for each of those functions, even if they are >> not used.) > > I am surprised that this surprises you, and equally surprised that you > seem to think it's going to be in some way grossly inefficient. Steven D'Aprano's reply suggests there /is/ some inefficiency which is why [according to him] nested functions are rarely used that way. -- bartc -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From arj.python at gmail.com Sun Jun 24 12:23:39 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 24 Jun 2018 20:23:39 +0400 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: Python is rightly called executable pseudocode. i appreciated the fact that you can go on wikipaedia, find the pseudocode of algorithms remove curly braces and replace by py's more powerful syntax and poof, suddenly it becomes too easy. Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > > From steve+comp.lang.python at pearwood.info Sun Jun 24 12:28:02 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 16:28:02 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <0eKXC.515410$eg.279610@fx43.am4> Message-ID: On Sun, 24 Jun 2018 16:39:19 +0100, Bart wrote: > More like utter disbelief at how it works. Surely it cannot work like > that because it would be too inefficient? Apparently, yes it can... Apparently, no it doesn't, because the fact that Python is used by tens of thousands of programmers for some mighty big, performance-critical, projects proves that it isn't "too inefficient". Its efficient enough. You want C, and all the headaches and buffer overflows and seg faults it gives, you know where to find it. > I know I'm going to get flak for bringing this up this old issue, And yet you're going to do it anyway. > but > remember when you used to write a for-loop and it involved creating an > actual list of N integers from 0 to N-1 in order to iterate through > them? Crazy. That's nothing, there are languages where the standard way to write a for loop is to call an external program that generates a stream of numeric strings separated by spaces in a subprocess, and read the strings from standard input as text. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sun Jun 24 12:30:32 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 16:30:32 +0000 (UTC) Subject: Anyone here on Python-Dev mailing list? References: Message-ID: On Mon, 25 Jun 2018 02:15:42 +1000, Chris Angelico wrote: > On Mon, Jun 25, 2018 at 2:07 AM, Steven D'Aprano > wrote: >> Anyone on the Python-Dev mailing list, are you getting private emails >> containing nothing but stream of consciousness word-salad from somebody >> (some bot?) calling himself "Chanel Marvin" with a gmail address? >> >> Typical example: >> >> "I refuse to create my environment on a computer. Stalls and static >> and it always looks fake unless I can afford all the cool fast >> stuff like Prometheus speed but for dummies in plain white english" >> >> in reply to an email I posted to the list. >> >> I don't want to ask there, yet, in case it isn't a bot but some nutter >> with an attitude emailing me privately. >> >> > Yeah, I got one of those. I'm pretty sure it's a Markov chainer. Only one? So far I've had seven. I get spam bots trying to flush out suckers. I don't get bots that send out random messages to random people. Why? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From glenn.hutchings at 1 Sun Jun 24 12:34:54 2018 From: glenn.hutchings at 1 (Glenn Hutchings) Date: Sun, 24 Jun 2018 11:34:54 -0500 Subject: nltk related issue Message-ID: <5B30F4ED.21002.uclanpyth@castlerockbbs.com> To: Sharan Basappa From: Glenn Hutchings On 21/06/18 04:40, Sharan Basappa wrote: > Folks, > > I am trying to run a simple example associated with nltk. > I get some error and I don't know what the issue is. > I need some guidance please. > [...] > LookupError: > ********************************************************************** > Resource u'tokenizers/punkt/english.pickle' not found. Please > use the NLTK Downloader to obtain the resource: >>> > nltk.download() > Searched in: > - 'D:\\Users\\sharanb/nltk_data' > - 'C:\\nltk_data' > - 'D:\\nltk_data' > - 'E:\\nltk_data' > - 'D:\\Users\\sharanb\\AppData\\Local\\Enthought\\Canopy\\edm\\envs\\User\\nltk_d ata' > - 'D:\\Users\\sharanb\\AppData\\Local\\Enthought\\Canopy\\edm\\envs\\User\\lib\\n ltk_data' > - 'D:\\Users\\sharanb\\AppData\\Roaming\\nltk_data' > - u'' > ********************************************************************** > As the error message says, you need to do a one-time installation of the NLTK data. See http://www.nltk.org/data.html for more info. Glenn --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sun Jun 24 12:35:56 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 11:35:56 -0500 Subject: Python for beginners or not? [was Re: syntax difference] Message-ID: <5B30F4ED.21013.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sat, 23 Jun 2018 14:52:24 -0500, boB Stepp wrote: [...] >> There is a place for various levels of programming language. I'm saying >> that Python which is always touted as a 'simple' language suitable for >> beginners, is missing a surprising number of basics. > > I still feel like a rank beginner, but on the Tutor list some disagree. It has been a long, long time since Python has been a "simple" language suitable for rank beginners, if it ever was. Python is not Scratch. https://scratch.mit.edu/ Right from version 1.0, Python has included some advanced features, even mind-blowing features (metaclasses, a.k.a. "the killer joke"). We're now up to version 3.6 (in production) and 3.7 (in beta) and Python includes some very advanced modern[1] features, like syntactic support for asynchronous programming, decorators, generators, coroutines and more. Better to say that Python is *accessible* to beginners: you can do a lot of good work in Python using simple constructs and imperative scripts, and most importantly, the syntax generally doesn't get in your way. There's relatively little boilterplate needed and a gentle learning curve. Compare "Hello World" in Java and Python: public class HelloWorld { public static void main(String[] args) { // Prints "Hello, World" to the terminal window. System.out.println("Hello, World"); } } versus: print("Hello, World") The Python example requires the programmer to learn effectively three things (print, parentheses, strings), compared to over a dozen for Java: - classes; braces; parentheses; strings; methods; attribute access using dot; "public" declarations; "static" declarations; "void" declarations; type declarations; the existence of System; System.out; System.out.println; semicolons; the implicit calling of main. Aside: there's an extensive, and yet still incomplete, list of Hello World programs here http://helloworldcollection.de/ with some impressive examples. Enjoy! [...] > As an aside we just had another round of software, OS and hardware > upgrades. Now I can use Python 2.7! Yay! Welcome to the 2000s! Hope you will catch up to Python 3 by the 2020s :-) > Because I read and study about new things as I take them up, I soon > learned that I had only so far scratched the surface of Python's depths. > But despite knowing that Python had many more features to explore, both > in the core language and the standard library, this never hindered me in > writing my beginner-level programs. I got things done, and I got them > done fairly easily, and never felt burdened by all the "other stuff" > that Python had to offer. Indeed. That's one of the beauties of Python -- even when there's an advanced way to do it, there's generally a simple way too. [1] I say "modern", but in fact very little in computer science wasn't invented by Lisp in the 1950s, or if not Lisp, by CLU in the 1970s. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From arj.python at gmail.com Sun Jun 24 12:42:00 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 24 Jun 2018 20:42:00 +0400 Subject: Anyone here on Python-Dev mailing list? In-Reply-To: References: Message-ID: i follow the dev list so far no but that particular mail might be related to pythan rather than random messages over the times i've talked to users of other langs (academics) one of the fault they find with python is the virtual env setup, too boring a task. environment in that case may refer to python environment Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > From stefan.ram at 1 Sun Jun 24 13:08:56 2018 From: stefan.ram at 1 (Stefan Ram) Date: Sun, 24 Jun 2018 12:08:56 -0500 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: <5B30F4ED.21013.uclanpyth@castlerockbbs.com> References: <5B30F4ED.21013.uclanpyth@castlerockbbs.com> Message-ID: <5B30F4ED.21021.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: ram at zedat.fu-berlin.de (Stefan Ram) Steven D'Aprano writes: >It has been a long, long time since Python has been a "simple" language >suitable for rank beginners, if it ever was. Python is not Scratch. Python is simpler insofar as you can write on a higher level than with C. Python has a GC and an intuitive syntax for lists, tuples and dictionaries. main.c #include int main( void ){ printf( "%d\n", 60000 * 60000 ); } transcript -694967296 Above, a beginner has to take care to use ??%d?? and remember to change this to ??%g?? when necessary. He also needs to understand why the result is negative, and that the result is /implementation-dependent/. Surely, |>>> print( 60000 * 60000 ) |3600000000 is easier to read, write, and understand. Still, one must not forget that learning Python encompasses all the hard work it takes to learn how to program in every language. --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From stefan.ram at 1 Sun Jun 24 13:08:56 2018 From: stefan.ram at 1 (Stefan Ram) Date: Sun, 24 Jun 2018 12:08:56 -0500 Subject: Python for beginners or not? [was Re: syntax difference] Message-ID: <5B324678.21173.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: "Stefan Ram" To: Steven D'Aprano From: ram at zedat.fu-berlin.de (Stefan Ram) Steven D'Aprano writes: >It has been a long, long time since Python has been a "simple" language >suitable for rank beginners, if it ever was. Python is not Scratch. Python is simpler insofar as you can write on a higher level than with C. Python has a GC and an intuitive syntax for lists, tuples and dictionaries. main.c #include int main( void ){ printf( "%d\n", 60000 * 60000 ); } transcript -694967296 Above, a beginner has to take care to use ??%d?? and remember to change this to ??%g?? when necessary. He also needs to understand why the result is negative, and that the result is /implementation-dependent/. Surely, |>>> print( 60000 * 60000 ) |3600000000 is easier to read, write, and understand. Still, one must not forget that learning Python encompasses all the hard work it takes to learn how to program in every language. -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From rosuav at gmail.com Sun Jun 24 13:15:07 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Jun 2018 03:15:07 +1000 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: On Mon, Jun 25, 2018 at 2:23 AM, Abdur-Rahmaan Janhangeer wrote: > Python is rightly called executable pseudocode. i appreciated the fact that > you can go on wikipaedia, find the pseudocode of algorithms remove curly > braces and replace by py's more powerful syntax and poof, suddenly it > becomes too easy. My pseudocode and Python code look extremely similar, but that's partly *because* I know Python. But I do periodically have JavaScript students ask me "Is that Python?" when what I've written is pseudocode. ChrisA From jlee54 at gmail.com Sun Jun 24 13:46:09 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 24 Jun 2018 10:46:09 -0700 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: <07c5a9a1-e9b1-4253-942f-9083423ad8ce@gmail.com> On 06/24/2018 04:35 AM, Steven D'Aprano wrote: > > Indeed. That's one of the beauties of Python -- even when there's an > advanced way to do it, there's generally a simple way too. > > What happened to the Python maxim "There should be one?and preferably only one?obvious way to do it"? -Jim From steven.d'aprano at 1 Sun Jun 24 13:51:40 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 12:51:40 -0500 Subject: Introducing Coconut Message-ID: <5B30F4ED.21022.uclanpyth@castlerockbbs.com> From: Steven D'Aprano Coconut, the functional programming language which compiles to Python: http://coconut.readthedocs.io/en/master/FAQ.html http://coconut-lang.org/ (Its not my language. I just think its cool.) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From chris.angelico at 1 Sun Jun 24 13:53:48 2018 From: chris.angelico at 1 (Chris Angelico) Date: Sun, 24 Jun 2018 12:53:48 -0500 Subject: translating foreign data Message-ID: <5B30F4ED.20988.uclanpyth@castlerockbbs.com> From: Chris Angelico On Sun, Jun 24, 2018 at 12:44 PM, Steven D'Aprano wrote: > You're joking, right? You can't possibly be so ignorant as to actually > believe that. You have, right in front of you, a news post or email > containing the text string "100???", and yet you are writing apparently in > full seriousness that it is impossible to get that text string in a file. > > Okay, you want a bit-pattern. In hex: > > '0x313030e282ac' > > I'll leave the question of how I generated that as an exercise. (Hint: it > was a one-liner, involving two method calls and a function call, all > builtins in Python.) Hmm. Actually, I'm a bit confused. >>> hex("100???".encode()) Traceback (most recent call last): File "", line 1, in TypeError: 'bytes' object cannot be interpreted as an integer Nope, that's not it. Needs something to turn the bytes into an integer first. But I can't find a way to do that. Best I can find is: >>> "100???".encode().hex() '313030e282ac' No "0x" prefix, no function call. So, I'm stuck. How did you create your one? ChrisA --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From chris.angelico at 1 Sun Jun 24 14:32:20 2018 From: chris.angelico at 1 (Chris Angelico) Date: Sun, 24 Jun 2018 13:32:20 -0500 Subject: translating foreign data Message-ID: <5B30F4ED.20991.uclanpyth@castlerockbbs.com> From: Chris Angelico On Sun, Jun 24, 2018 at 1:23 PM, Steven D'Aprano wrote: > On Sun, 24 Jun 2018 12:53:49 +1000, Chris Angelico wrote: > > [...] >>> Okay, you want a bit-pattern. In hex: >>> >>> '0x313030e282ac' > [...] > >> Hmm. Actually, I'm a bit confused. >> >>>>> hex("100???".encode()) >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: 'bytes' object cannot be interpreted as an integer >> >> Nope, that's not it. Needs something to turn the bytes into an integer >> first. But I can't find a way to do that. Best I can find is: >> >>>>> "100???".encode().hex() >> '313030e282ac' > > Dammit, that was what I was looking for, but I only looked on *strings*, > not bytes. > > >> No "0x" prefix, no function call. So, I'm stuck. How did you create your >> one? > > py> hex(int.from_bytes("100???".encode("utf-8"), 'big')) > '0x313030e282ac' Ahhh thanks, that's the part I couldn't find (and didn't remember). Anyhow, encoding to UTF-8 and then to bytes is pretty easy. ChrisA --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From arj.python at gmail.com Sun Jun 24 14:36:27 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 24 Jun 2018 22:36:27 +0400 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: see for example https://en.m.wikipedia.org/wiki/Bresenham%27s_line_algorithm see the pseudocode, i was implementing some raster algos when i found myself aux anges so close to py. i guess it was written in prehistoric times with the author trying to simplify stuffs Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > From bc at freeuk.com Sun Jun 24 14:37:33 2018 From: bc at freeuk.com (Bart) Date: Sun, 24 Jun 2018 19:37:33 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <0eKXC.515410$eg.279610@fx43.am4> Message-ID: On 24/06/2018 16:37, boB Stepp wrote: > On Sun, Jun 24, 2018 at 5:21 AM Bart wrote: > "... And of course, you would have to know how to use Python properly in > idiomatic style. No. I want to program in /my/ style, one more like the pseudo-code that was mentioned elsewhere, and that is universally understood. Even if people here don't think much of it. (eg. https://pastebin.com/0EygJzFR, raw text:https://pastebin.com/raw/0EygJzFR) Why not choose this positive approach? I think it > would be a win-win for both you and Python." > > Just show you genuinely care about the language and the community. > Use and understand the language as well as you can before jumping into > criticisms. Adopt the path of the humble learner, who does not know > everything about Python. Is this too much to ask? Sorry, I tried a few replies but they all got too long and too much about me. So I'll have to leave it. I think people know enough about my ideas by now anyway. -- bart From tjreedy at udel.edu Sun Jun 24 14:58:12 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 24 Jun 2018 14:58:12 -0400 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <0eKXC.515410$eg.279610@fx43.am4> Message-ID: On 6/24/2018 11:39 AM, Bart wrote: Bart, I agree that people should not dogpile onto you. As with Rick, I read your posts or not, depending on whether I feel like being entertained at the moment, and usually move on without comment. > I know I'm going to get flak for bringing this up this old issue, "Getting flak" is apparently your goal. This is called trolling. > remember when you used to write a for-loop and it involved creating an > actual list of N integers from 0 to N-1 in order to iterate through > them? Crazy. Yep. We first fixed it in a backward compatible way, then in a code breaking way. The second fix got some rough and rude flak: "This is the end of Python!!!" > But that has long been fixed - or so I thought. You thought right. > When I wrote, today: using an ancient version of Python, > ?? for i in range(100000000): pass????? # 100 million > > on Python 2, it used up 1.8GB, up to the limit of my RAM, and it took > several minutes to regain control of my machine (and it never did > finish). > You don't expect that in 2018 when executing a simple empty loop. And you don't get that when you use a 2018 version of Python, or even the newer 2008 version (3.0.0). Are you really unaware of that? > On Py 2 you have to use xrange for large ranges - that was the fix. Yep. This was the backward compatible fix. So what is your point? > Somebody however must have had to gently and tactfully point out the > issue. For all I know, the craziness of the original design may have prompted some rough and rude comments *BEFORE IT WAS FIXED*. Possibly ditto for the clutziness of the fix -- *BEFORE THE FIX WAS FIXED*. > I'm afraid I'm not very tactful. The above seems politely worded to me. It is just 20 and 10 years too late, and completely pointless, unless 'flak' is your goal. -- Terry Jan Reedy From robert.latest at 1 Sun Jun 24 14:58:30 2018 From: robert.latest at 1 (Robert Latest) Date: Sun, 24 Jun 2018 13:58:30 -0500 Subject: Package directory question Message-ID: <5B30F4EE.21023.uclanpyth@castlerockbbs.com> From: Robert Latest Hello, I'm building an application which consists of two largely distinct parts, a frontend and a backend. The directory layout is like this: |-- jobwatch | |-- backend | | |-- backend.py | | |-- __init__.py | | `-- tables.py | |-- frontend | | |-- __init__.py | | |-- main.py | `-- __init__.py `-- setup.py Because the main.py script needs to import the tables.py module from backend, I put this at the top if main.py: sys.path.append('../..') import jobwatch.backend.tables as tables My question is: Is this the way it should be done? It looks fishy. The only alternative I could come up with is to put a symlink to tables.py into the frontend directory, which also seems fishy. Eventually I want to package all this up neatly to be able to use only little wrapper scripts for the backend (running as a service) and the frontend (a wsgi app). Any thoughts? Thanks robert --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From gregory.ewing at 1 Sun Jun 24 14:58:58 2018 From: gregory.ewing at 1 (Gregory Ewing) Date: Sun, 24 Jun 2018 13:58:58 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B30F4ED.20977.uclanpyth@castlerockbbs.com> References: <5B30F4ED.20977.uclanpyth@castlerockbbs.com> Message-ID: <5B30F4ED.20981.uclanpyth@castlerockbbs.com> To: Bart From: Gregory Ewing Bart wrote: > Wow. (Just think of all the times you write a function containing a neat > bunch of local functions, every time it's called it has to create a new > function instances for each of those functions, even if they are not used.) Fortunately, function objects are small and cheap, essentially just a couple of object references. The overhead of creating one is probably about the same as creating an empty list. If your function is complicated enough to benefit from local functions, the cost is going to be swamped by the rest of the work being done. -- Greg --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From gregory.ewing at 1 Sun Jun 24 14:58:58 2018 From: gregory.ewing at 1 (Gregory Ewing) Date: Sun, 24 Jun 2018 13:58:58 -0500 Subject: Static variables [was Re: syntax difference] In-Reply-To: <5B324678.21167.uclanpyth@castlerockbbs.com> References: <5B324678.21167.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21169.uclanpyth@castlerockbbs.com> To: Bart From: "Gregory Ewing" To: Bart From: Gregory Ewing Bart wrote: > Wow. (Just think of all the times you write a function containing a neat > bunch of local functions, every time it's called it has to create a new > function instances for each of those functions, even if they are not used.) Fortunately, function objects are small and cheap, essentially just a couple of object references. The overhead of creating one is probably about the same as creating an empty list. If your function is complicated enough to benefit from local functions, the cost is going to be swamped by the rest of the work being done. -- Greg -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From tjreedy at udel.edu Sun Jun 24 15:01:33 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 24 Jun 2018 15:01:33 -0400 Subject: Anyone here on Python-Dev mailing list? In-Reply-To: References: Message-ID: On 6/24/2018 12:07 PM, Steven D'Aprano wrote: > Anyone on the Python-Dev mailing list, are you getting private emails > containing nothing but stream of consciousness word-salad from somebody > (some bot?) calling himself "Chanel Marvin" with a gmail address? > > Typical example: > > "I refuse to create my environment on a computer. Stalls and static > and it always looks fake unless I can afford all the cool fast stuff > like Prometheus speed but for dummies in plain white english" > > in reply to an email I posted to the list. > > I don't want to ask there, yet, in case it isn't a bot but some nutter > with an attitude emailing me privately. I recently got a request for help from a stranger, but it was more coherent than the above. -- Terry Jan Reedy From rick.johnson at 1 Sun Jun 24 15:01:58 2018 From: rick.johnson at 1 (Rick Johnson) Date: Sun, 24 Jun 2018 14:01:58 -0500 Subject: Anyone here on Python-Dev mailing list? In-Reply-To: <5B30F4EE.21036.uclanpyth@castlerockbbs.com> References: <5B30F4EE.21036.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21131.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: Rick Johnson Steven D'Aprano wrote: [...] > I get spam bots trying to flush out suckers. I don't get > bots that send out random messages to random people. Why? Steven, my son, i suppose some questions just answer themselves... --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steve+comp.lang.python at pearwood.info Sun Jun 24 15:02:44 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jun 2018 19:02:44 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <0eKXC.515410$eg.279610@fx43.am4> Message-ID: On Sun, 24 Jun 2018 19:37:33 +0100, Bart wrote: > I want to program in /my/ style Python is not Java, and Java is not Python either. Nor is it "Bart's Language", or C, or Forth, or Lisp, or bash. https://dirtsimple.org/2004/12/python-is-not-java.html https://dirtsimple.org/2004/12/java-is-not-python-either.html To get the best out of any language, you should try to program to its strengths, in the idioms that work, not insist on writing FooLanguage code in BarLanguage. Hammers are great tools. So are screwdrivers. But you wouldn't use a screwdriver to hammer nails, or hammer screws, would you? You'd probably be pretty frustrated if one of your users (ahem) insisted on duplicating the form and structure of their bash scripts in your language, and complaining bitterly about how your language sucks because it isn't bash. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From bc at freeuk.com Sun Jun 24 15:03:13 2018 From: bc at freeuk.com (Bart) Date: Sun, 24 Jun 2018 20:03:13 +0100 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: On 24/06/2018 19:36, Abdur-Rahmaan Janhangeer wrote: > see for example > > https://en.m.wikipedia.org/wiki/Bresenham%27s_line_algorithm > > see the pseudocode, i was implementing some raster algos when i found > myself aux anges > > so close to py. i guess it was written in prehistoric times with the author > trying to simplify stuffs I'm sorry, but that kind of code is a mish-mash of old Algol/Pascal-style languages. I doubt it was meant to be Python. Python doesn't have a monopoly on clear syntax. This is the first example from that link (I've taken out comments): function line(x0, y0, x1, y1) real deltax := x1 - x0 real deltay := y1 - y0 real deltaerr := abs(deltay / deltax) real error := 0.0 int y := y0 for x from x0 to x1 plot(x,y) error := error + deltaerr while error ? 0.5 then y := y + sign(deltay) * 1 error := error - 1.0 This has some problems: it's using 'function' when it doesn't return a value (those languages used 'proc' or 'procedure' in that case). It doesn't give a type for the parameters, and it uses while/then rather than the usual while/do. So it's rather sloppy even for pseudo code. The only similarity with Python is the lack of block delimiters, but then with later examples they /are/ used, for if-else-endif. Below, the first block is that code tweaked to a static language of mine. The second is the same code tweaked to Python. It was less work to adapt it my syntax rather than Python. All versions however use a decidedly un-Pythonic style, which means the difference between the two below isn't that great, even though they are different languages. But imagine trying to adapt Pythonic code to work in the other language; it would be much harder (apart from one being dynamic and the other not). --------------------------------- proc line(int x0, y0, x1, y1)= real deltax := x1 - x0 real deltay := y1 - y0 real deltaerr := abs(deltay / deltax) real error := 0.0 int y := y0 int x for x := x0 to x1 do plot(x,y) error := error + deltaerr while error = 0.5 do y := y + sign(deltay) * 1 error := error - 1.0 end end end ---------------------------------- def line(x0, y0, x1, y1): deltax = x1 - x0 deltay = y1 - y0 deltaerr = abs(deltay / deltax) error = 0.0 y = y0 for x in range(x0,x1+1): plot(x,y) error = error + deltaerr while error == 0.5: y = y + sign(deltay) * 1 error = error - 1.0 -- bart From Richard at Damon-Family.org Sun Jun 24 15:20:30 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 24 Jun 2018 15:20:30 -0400 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <0eKXC.515410$eg.279610@fx43.am4> Message-ID: <11b6d63f-8caf-b4f6-d20c-bdffcb807546@Damon-Family.org> On 6/24/18 3:02 PM, Steven D'Aprano wrote: > On Sun, 24 Jun 2018 19:37:33 +0100, Bart wrote: > >> I want to program in /my/ style > Python is not Java, and Java is not Python either. Nor is it "Bart's > Language", or C, or Forth, or Lisp, or bash. > > https://dirtsimple.org/2004/12/python-is-not-java.html > > https://dirtsimple.org/2004/12/java-is-not-python-either.html > > > To get the best out of any language, you should try to program to its > strengths, in the idioms that work, not insist on writing FooLanguage > code in BarLanguage. > > Hammers are great tools. So are screwdrivers. But you wouldn't use a > screwdriver to hammer nails, or hammer screws, would you? > > You'd probably be pretty frustrated if one of your users (ahem) insisted > on duplicating the form and structure of their bash scripts in your > language, and complaining bitterly about how your language sucks because > it isn't bash. > >From what I have seen from Bart in other groups, Bart want to write in 'Bart' using existing languages and is frustrated that no one (but him) has written a language exactly to his specs. -- Richard Damon From gregory.ewing at 1 Sun Jun 24 15:35:58 2018 From: gregory.ewing at 1 (Gregory Ewing) Date: Sun, 24 Jun 2018 14:35:58 -0500 Subject: syntax difference In-Reply-To: <5B30F4ED.20976.uclanpyth@castlerockbbs.com> References: <5B30F4ED.20976.uclanpyth@castlerockbbs.com> Message-ID: <5B30F4ED.20983.uclanpyth@castlerockbbs.com> To: Bart From: Gregory Ewing Bart wrote: > But 40 years > ago it was just 'readln a,b,c'; it was just taken for granted. The problem with something like that is that it's really only useful for throwaway code. For any serious application, you need to deal with the possibility of malformed input, producing helpful diagnostics, etc. And often the input isn't going to be in such a uniform format that you know exactly what to expect next. So it's debable whether it's a good idea to put something with such limited applicability into the core language or standard library. Handling input well is fundamentally much more complicated than producing output. I don't think this is as "basic" as you make out. -- Greg --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From gregory.ewing at 1 Sun Jun 24 15:35:58 2018 From: gregory.ewing at 1 (Gregory Ewing) Date: Sun, 24 Jun 2018 14:35:58 -0500 Subject: syntax difference In-Reply-To: <5B324678.21166.uclanpyth@castlerockbbs.com> References: <5B324678.21166.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21170.uclanpyth@castlerockbbs.com> To: Bart From: "Gregory Ewing" To: Bart From: Gregory Ewing Bart wrote: > But 40 years > ago it was just 'readln a,b,c'; it was just taken for granted. The problem with something like that is that it's really only useful for throwaway code. For any serious application, you need to deal with the possibility of malformed input, producing helpful diagnostics, etc. And often the input isn't going to be in such a uniform format that you know exactly what to expect next. So it's debable whether it's a good idea to put something with such limited applicability into the core language or standard library. Handling input well is fundamentally much more complicated than producing output. I don't think this is as "basic" as you make out. -- Greg -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From Richard at Damon-Family.org Sun Jun 24 15:47:54 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 24 Jun 2018 15:47:54 -0400 Subject: translating foreign data In-Reply-To: References: <5B2BDC7B.3040508@stoneleaf.us> <87k1qrsxhq.fsf@bsb.me.uk> <5B2CB6CC.10500@stoneleaf.us> <878t77ruu4.fsf@bsb.me.uk> <8736xesksk.fsf@bsb.me.uk> <87h8ltiubl.fsf@elektro.pacujo.net> <8318150e-1f3c-eb97-d25c-475bddc6e223@Damon-Family.org> <87d0whirgc.fsf@elektro.pacujo.net> <1d713ce6-d8d8-110c-aa78-d7d672a024b9@Damon-Family.org> <857empdwb3.fsf@benfinney.id.au> <03814d57-08fd-dfef-8bb5-469140f5de0a@Damon-Family.org> Message-ID: On 6/23/18 10:44 PM, Steven D'Aprano wrote: > On Sat, 23 Jun 2018 17:52:55 -0400, Richard Damon wrote: > >> If you have more than just a number representing a value in the locale >> currency, you can't ask the locale how to present/accept it. > You're the only one saying that it has to be handled by the locale. > > Actually, it was part of the problem statement by Marko, since he said to use LC_MONETARY, which is the part of the Locale machinery dealing with monetary quantities (and can ONLY handle the currency defined by the Locale). What would you think of providing a program in say, Java, to a problem statement that said to write a Python program. I suppose he could have just meant use the number, which would be like asking to interpret the value of 100 euros using math.pi Or it could have been just a bad question like how heavy is blue. (Since by definition a locale only knows how to handle a single type of currency, assuming any value is of that type). My answer was in part to point out the problem with the problem statement (and people seem to want to jump on me for pointing out the strengths and weaknesses of the locale system. This also goes back to the very original question at the beginning of the thread, the OP had a bunch of data with numbers using varying locale conventions (he didn't use the words), but had various decimal separators and some people asked about non-'arabic' numbers? (0-9). This also goes back to some of the comments about file formats. Most file formats are designed to be 'Machine Read' (even if they use text formatting) and as such do NOT use localization facilities, so when processing them you want the I/O processing system to be in a non-localized mode (typically numbers always use . as the decimal separator, and usually nothing as the thousands separator). While the text format files might be opened in a text editor, the file format doesn't cater to making things pretty for the user. Some programs will create input/output/storage files where it is expected that the user WILL open them, look at them and maybe even edit them. Numbers will use the locale convention of currency and decimal/thousands separators. If you have such a system, changing the locale rules for these files may cause misinterpreting the values. If you are bringing such files from a 'foreign' system, you need to be able to indicate what locale to use when reading that file. This sounds very much like the category of problem that the OP was dealing with. They have apparently a large number files, presumably organized in some consistent manner that the values in them make sense, but the numbers are written in different local conventions, and this was causing the simplistic processing to fail. -- Richard Damon From terry.reedy at 1 Sun Jun 24 15:58:12 2018 From: terry.reedy at 1 (Terry Reedy) Date: Sun, 24 Jun 2018 14:58:12 -0500 Subject: syntax difference Message-ID: <5B324677.21094.uclanpyth@castlerockbbs.com> From: Terry Reedy On 6/24/2018 11:39 AM, Bart wrote: Bart, I agree that people should not dogpile onto you. As with Rick, I read your posts or not, depending on whether I feel like being entertained at the moment, and usually move on without comment. > I know I'm going to get flak for bringing this up this old issue, "Getting flak" is apparently your goal. This is called trolling. > remember when you used to write a for-loop and it involved creating an > actual list of N integers from 0 to N-1 in order to iterate through > them? Crazy. Yep. We first fixed it in a backward compatible way, then in a code breaking way. The second fix got some rough and rude flak: "This is the end of Python!!!" > But that has long been fixed - or so I thought. You thought right. > When I wrote, today: using an ancient version of Python, > ? ? for i in range(100000000): pass? ? ? ? ? # 100 million > > on Python 2, it used up 1.8GB, up to the limit of my RAM, and it took > several minutes to regain control of my machine (and it never did > finish). > You don't expect that in 2018 when executing a simple empty loop. And you don't get that when you use a 2018 version of Python, or even the newer 2008 version (3.0.0). Are you really unaware of that? > On Py 2 you have to use xrange for large ranges - that was the fix. Yep. This was the backward compatible fix. So what is your point? > Somebody however must have had to gently and tactfully point out the > issue. For all I know, the craziness of the original design may have prompted some rough and rude comments *BEFORE IT WAS FIXED*. Possibly ditto for the clutziness of the fix -- *BEFORE THE FIX WAS FIXED*. > I'm afraid I'm not very tactful. The above seems politely worded to me. It is just 20 and 10 years too late, and completely pointless, unless 'flak' is your goal. -- Terry Jan Reedy --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From terry.reedy at 1 Sun Jun 24 16:01:32 2018 From: terry.reedy at 1 (Terry Reedy) Date: Sun, 24 Jun 2018 15:01:32 -0500 Subject: Anyone here on Python-Dev mailing list? Message-ID: <5B324677.21095.uclanpyth@castlerockbbs.com> From: Terry Reedy On 6/24/2018 12:07 PM, Steven D'Aprano wrote: > Anyone on the Python-Dev mailing list, are you getting private emails > containing nothing but stream of consciousness word-salad from somebody > (some bot?) calling himself "Chanel Marvin" with a gmail address? > > Typical example: > > "I refuse to create my environment on a computer. Stalls and static > and it always looks fake unless I can afford all the cool fast stuff > like Prometheus speed but for dummies in plain white english" > > in reply to an email I posted to the list. > > I don't want to ask there, yet, in case it isn't a bot but some nutter > with an attitude emailing me privately. I recently got a request for help from a stranger, but it was more coherent than the above. -- Terry Jan Reedy --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sun Jun 24 16:02:40 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 15:02:40 -0500 Subject: syntax difference Message-ID: <5B30F4EE.21026.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Mon, 25 Jun 2018 00:46:00 +1000, Chris Angelico wrote: > On Sun, Jun 24, 2018 at 8:40 PM, Steven D'Aprano > wrote: >> On Sun, 24 Jun 2018 11:18:37 +0100, Bart wrote: >> >>> I wonder why it is just me that constantly needs to justify his >>> existence in this group? >> >> Because its just you who spends 90% of his time here complaining about >> how Python does it wrong. > > ... and spends 95% of that time demonstrating his utter lack of > understanding of how Python does it at all. It's wrong even though you > don't understand how it actually works. Be fair. It's more like 50% of the time. Let's not dogpile onto Bart. He asked a question, I answered it, we don't all need to sink the boot in as well. Nobody expects Bart to love Python, but if he wants to fit in here, in a Python group, he ought to either at least make an effort to understand the reasons Python is what it is (and not just idiocy and bloat) and appreciate it for what it is, not for what it isn't. Or at least avoid trying to lecture us on why we're doing it wrong. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From arj.python at gmail.com Sun Jun 24 16:18:45 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Mon, 25 Jun 2018 00:18:45 +0400 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: naaa it was not meant to be python ^^ Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > > From chris.angelico at 1 Sun Jun 24 16:18:48 2018 From: chris.angelico at 1 (Chris Angelico) Date: Sun, 24 Jun 2018 15:18:48 -0500 Subject: Quick survey: locals in comprehensions (Python 3 only) Message-ID: <5B30F4ED.20993.uclanpyth@castlerockbbs.com> From: Chris Angelico On Sun, Jun 24, 2018 at 3:03 PM, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, since > this is about your EXPECTATIONS, not what Python actually does. > > Given this function: > > > def test(): > a = 1 > b = 2 > result = [value for key, value in locals().items()] > return result > > > > > what would you expect the result of calling test() to be? Is that the > result you think is most useful? In your opinion, is this a useful > feature, a misfeature, a bug, or "whatever"? > > I'm only looking for answers for Python 3. (The results in Python 2 are > genuinely weird :-) Personally, I think it should give you [1, 2], the two values from the function's locals. But genexps introduce some problems. Compare: def test(): a = 1 b = 2 result = list(value for key, value in locals().items()) return result def test_helper(): a = 1 b = 2 gen = (value for key, value in locals().items()) return gen def test(): return list(test_helper()) Guido has stated that he wants the list comp to be equivalent to calling list() immediately on the genexp. And since a genexp has to be the same thing whether you call list() on it straight away or not, that means that all these need to behave the same way. Which, in turn, means that the genexp needs some form of closure semantics. Thus it is executed in an implicit nested function, and thus the list comp also needs to be, for consistency. So! With that in mind, I would consider bizarre behaviour of locals() inside comprehensions to be a wart. It's not a normal thing to do, and if it behaves weirdly, so be it. There are other things that I would prefer to see tidied up before that. ChrisA --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From richard.damon at 1 Sun Jun 24 16:20:30 2018 From: richard.damon at 1 (Richard Damon) Date: Sun, 24 Jun 2018 15:20:30 -0500 Subject: syntax difference Message-ID: <5B324677.21098.uclanpyth@castlerockbbs.com> From: Richard Damon On 6/24/18 3:02 PM, Steven D'Aprano wrote: > On Sun, 24 Jun 2018 19:37:33 +0100, Bart wrote: > >> I want to program in /my/ style > Python is not Java, and Java is not Python either. Nor is it "Bart's > Language", or C, or Forth, or Lisp, or bash. > > https://dirtsimple.org/2004/12/python-is-not-java.html > > https://dirtsimple.org/2004/12/java-is-not-python-either.html > > > To get the best out of any language, you should try to program to its > strengths, in the idioms that work, not insist on writing FooLanguage > code in BarLanguage. > > Hammers are great tools. So are screwdrivers. But you wouldn't use a > screwdriver to hammer nails, or hammer screws, would you? > > You'd probably be pretty frustrated if one of your users (ahem) insisted > on duplicating the form and structure of their bash scripts in your > language, and complaining bitterly about how your language sucks because > it isn't bash. > >From what I have seen from Bart in other groups, Bart want to write in 'Bart' using existing languages and is frustrated that no one (but him) has written a language exactly to his specs. -- Richard Damon --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bc at freeuk.com Sun Jun 24 16:21:57 2018 From: bc at freeuk.com (Bart) Date: Sun, 24 Jun 2018 21:21:57 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <0eKXC.515410$eg.279610@fx43.am4> Message-ID: On 24/06/2018 20:02, Steven D'Aprano wrote: > On Sun, 24 Jun 2018 19:37:33 +0100, Bart wrote: > >> I want to program in /my/ style > > Python is not Java, and Java is not Python either. Nor is it "Bart's > Language", or C, or Forth, or Lisp, or bash. > > https://dirtsimple.org/2004/12/python-is-not-java.html > > https://dirtsimple.org/2004/12/java-is-not-python-either.html > > > To get the best out of any language, you should try to program to its > strengths, in the idioms that work, not insist on writing FooLanguage > code in BarLanguage. I like to write in clear code in a manner that anyone can follow (although I'm mainly thinking about myself). That means not using idioms specific to a language and hard to translate to anything else. Why might someone want to use something like Python rather than, for example, C? Here are some reasons: * Clearer syntax less full of punctuation * Simpler for-loops * Module import system * Much faster edit-run cycle * Dynamic types to eliminate most variable declarations * No need for forward declarations for functions * First class string handling * First class list handling * Flexible arrays/lists (not strings as they are immutable) * Namespaces * Default and keyword parameters * Can forget about using pointers That would be plenty to get started with, and enough to make it worthwhile to use the dynamic language provided its libraries and its performance are suitable for the task. But so far it has not been necessary to explicitly use a Pythonic style of coding or any of its esoteric features. > You'd probably be pretty frustrated if one of your users (ahem) insisted > on duplicating the form and structure of their bash scripts in your > language, and complaining bitterly about how your language sucks because > it isn't bash. I've had half a dozen users and I don't recall any particular problems nor any complaints. The language, although cruder then, must still have been sweeter to use than what was typically available at the time. -- bart From breamoreboy at gmail.com Sun Jun 24 16:39:33 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Sun, 24 Jun 2018 21:39:33 +0100 Subject: Where's the junk coming from? Message-ID: Hi folks, In the last hour or so I've seen via thunderbird and gmane around 15 emails from various people where the from field is name at 1261/38.remove-r7u-this. The part after the @ symbol never changes. I've seen the contents previously, apart from one from the RUE. Users' complete email addresses are given right at the top. What gives? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From richard.damon at 1 Sun Jun 24 16:47:54 2018 From: richard.damon at 1 (Richard Damon) Date: Sun, 24 Jun 2018 15:47:54 -0500 Subject: translating foreign data Message-ID: <5B324677.21099.uclanpyth@castlerockbbs.com> From: Richard Damon On 6/23/18 10:44 PM, Steven D'Aprano wrote: > On Sat, 23 Jun 2018 17:52:55 -0400, Richard Damon wrote: > >> If you have more than just a number representing a value in the locale >> currency, you can't ask the locale how to present/accept it. > You're the only one saying that it has to be handled by the locale. > > Actually, it was part of the problem statement by Marko, since he said to use LC_MONETARY, which is the part of the Locale machinery dealing with monetary quantities (and can ONLY handle the currency defined by the Locale). What would you think of providing a program in say, Java, to a problem statement that said to write a Python program. I suppose he could have just meant use the number, which would be like asking to interpret the value of 100 euros using math.pi Or it could have been just a bad question like how heavy is blue. (Since by definition a locale only knows how to handle a single type of currency, assuming any value is of that type). My answer was in part to point out the problem with the problem statement (and people seem to want to jump on me for pointing out the strengths and weaknesses of the locale system. This also goes back to the very original question at the beginning of the thread, the OP had a bunch of data with numbers using varying locale conventions (he didn't use the words), but had various decimal separators and some people asked about non-'arabic' numbers? (0-9). This also goes back to some of the comments about file formats. Most file formats are designed to be 'Machine Read' (even if they use text formatting) and as such do NOT use localization facilities, so when processing them you want the I/O processing system to be in a non-localized mode (typically numbers always use . as the decimal separator, and usually nothing as the thousands separator). While the text format files might be opened in a text editor, the file format doesn't cater to making things pretty for the user. Some programs will create input/output/storage files where it is expected that the user WILL open them, look at them and maybe even edit them. Numbers will use the locale convention of currency and decimal/thousands separators. If you have such a system, changing the locale rules for these files may cause misinterpreting the values. If you are bringing such files from a 'foreign' system, you need to be able to indicate what locale to use when reading that file. This sounds very much like the category of problem that the OP was dealing with. They have apparently a large number files, presumably organized in some consistent manner that the values in them make sense, but the numbers are written in different local conventions, and this was causing the simplistic processing to fail. -- Richard Damon --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From h.goebel at crazy-compilers.com Sun Jun 24 17:01:40 2018 From: h.goebel at crazy-compilers.com (Hartmut Goebel) Date: Sun, 24 Jun 2018 23:01:40 +0200 Subject: [ANN] pdfposter 0.7 Message-ID: I'm pleased to announce pdftools.pdfposter 0.7, a tool to scale and tile PDF images/pages to print on multiple pages. :Homepage: https://pdfposter.readthedocs.io/ :Author:?? Hartmut Goebel :Licence:? GNU Public Licence v3 (GPLv3) :Quick Installation: ??? pip install -U pdftools.pdfposter :Tarballs:? https://pypi.org/project/pdftools.pdfposter/#files What is pdfposter? -------------------- Scale and tile PDF images/pages to print on multiple pages. ``Pdfposter`` can be used to create a large poster by building it from multiple pages and/or printing it on large media. It expects as input a PDF file, normally printing on a single page. The output is again a PDF file, maybe containing multiple pages together building the poster. The input page will be scaled to obtain the desired size. This is much like ``poster`` does for Postscript files, but working with PDF. Since sometimes poster does not like your files converted from PDF. :-) Indeed ``pdfposter`` was inspired by ``poster``. For more information please refer to the manpage or visit the `project homepage `_. What's new in version 0.7 --------------------------------------- * Incompatible change: `DIN lang` and `Envelope No. 10` are now defined as ? landscape formats. * New options ``-f``/``--first`` and ``-l``/``--last`` for specifying the ? first resp. last page to convert * Reduce the size of the output file a lot. Now the output file is ? nearly the same size as the input file. While this behaviour was ? intended from the beginning, it was not yet implemented for two ? reasons: The content was a) copied for each print-page and b) not ? compressed. * Make the content of each page appear only once in the output file. ? This vastly reduces the size of the output file. * Compress page content. Now the output file is nearly the same size ? as the input file in much more cases. I thought, the underlying ? library will do this automatically, but it does not. * Fix bug in PDF code used for clipping the page content. Many thanks ? to Johannes Br?del for reporting this bug. * Add support for Python 3. * Use `PyPFDF2` instead of the unmaintained `pyPDF`. -- Regards Hartmut Goebel | Hartmut Goebel | h.goebel at crazy-compilers.com | | www.crazy-compilers.com | compilers which you thought are impossible | From chris.angelico at 1 Sun Jun 24 17:02:54 2018 From: chris.angelico at 1 (Chris Angelico) Date: Sun, 24 Jun 2018 16:02:54 -0500 Subject: Quick survey: locals in comprehensions (Python 3 only) Message-ID: <5B30F4ED.20996.uclanpyth@castlerockbbs.com> From: Chris Angelico On Sun, Jun 24, 2018 at 3:44 PM, Jim Lee wrote: > > > On 06/23/2018 10:03 PM, Steven D'Aprano wrote: >> >> I'd like to run a quick survey. There is no right or wrong answer, since >> this is about your EXPECTATIONS, not what Python actually does. >> >> Given this function: >> >> >> def test(): >> a = 1 >> b = 2 >> result = [value for key, value in locals().items()] >> return result >> >> >> >> >> what would you expect the result of calling test() to be? Is that the >> result you think is most useful? In your opinion, is this a useful >> feature, a misfeature, a bug, or "whatever"? >> >> I'm only looking for answers for Python 3. (The results in Python 2 are >> genuinely weird :-) >> >> > I would *expect* [1, 2, None], though I haven't actually tried running it. > Interesting. Where do you get the None from? Suppose it had been "key for..." instead of "value", what would the third key have been? ["a", "b", ...] ChrisA --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From gheskett at shentel.net Sun Jun 24 17:03:10 2018 From: gheskett at shentel.net (Gene Heskett) Date: Sun, 24 Jun 2018 17:03:10 -0400 Subject: I'm getting a spamassassin party here Message-ID: <201806241703.10658.gheskett@shentel.net> Greetings list; Generally spamassassin only gets picky about this occasionally, but for the past several hours its working overtime on python list messages, with the major problem being the servers time stamp, a day or more in the past. Anyboy ever hear of ntpd? -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From steven.d'aprano at 1 Sun Jun 24 17:07:50 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 16:07:50 -0500 Subject: Anyone here on Python-Dev mailing list? Message-ID: <5B30F4EE.21032.uclanpyth@castlerockbbs.com> From: Steven D'Aprano Anyone on the Python-Dev mailing list, are you getting private emails containing nothing but stream of consciousness word-salad from somebody (some bot?) calling himself "Chanel Marvin" with a gmail address? Typical example: "I refuse to create my environment on a computer. Stalls and static and it always looks fake unless I can afford all the cool fast stuff like Prometheus speed but for dummies in plain white english" in reply to an email I posted to the list. I don't want to ask there, yet, in case it isn't a bot but some nutter with an attitude emailing me privately. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From chris.angelico at 1 Sun Jun 24 17:16:00 2018 From: chris.angelico at 1 (Chris Angelico) Date: Sun, 24 Jun 2018 16:16:00 -0500 Subject: Quick survey: locals in comprehensions (Python 3 only) Message-ID: <5B30F4ED.20998.uclanpyth@castlerockbbs.com> From: Chris Angelico On Sun, Jun 24, 2018 at 4:08 PM, Jim Lee wrote: > There are three locals: a, b, and result. Since result cannot be assigned > a value until the list comp has been evaluated, I would expect the comp to > return a value of "None" for result. An argument could also be made for [1, > 2, []], but one thing I would *not* expect is [1, 2] or [2, 1]... Ahh, I see what you mean. Thing is, there's a definite difference between "this is None" and "this doesn't have a value". The latter situation is indicated by simply not having the local. def f(): print("; ".join("%s=%r" % x for x in locals().items())) a = 1 print("; ".join("%s=%r" % x for x in locals().items())) b = 2 print("; ".join("%s=%r" % x for x in locals().items())) The results may surprise you, or may not. This part has nothing to do with the behaviour of locals inside a comprehension, though. The important part is that, like me, you would like comprehensions to represent a block of code inside the current function, not an implicit nested function. ChrisA --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sun Jun 24 17:28:02 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 16:28:02 -0500 Subject: syntax difference Message-ID: <5B30F4EE.21035.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sun, 24 Jun 2018 16:39:19 +0100, Bart wrote: > More like utter disbelief at how it works. Surely it cannot work like > that because it would be too inefficient? Apparently, yes it can... Apparently, no it doesn't, because the fact that Python is used by tens of thousands of programmers for some mighty big, performance-critical, projects proves that it isn't "too inefficient". Its efficient enough. You want C, and all the headaches and buffer overflows and seg faults it gives, you know where to find it. > I know I'm going to get flak for bringing this up this old issue, And yet you're going to do it anyway. > but > remember when you used to write a for-loop and it involved creating an > actual list of N integers from 0 to N-1 in order to iterate through > them? Crazy. That's nothing, there are languages where the standard way to write a for loop is to call an external program that generates a stream of numeric strings separated by spaces in a subprocess, and read the strings from standard input as text. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Sun Jun 24 17:30:32 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 16:30:32 -0500 Subject: Anyone here on Python-Dev mailing list? Message-ID: <5B30F4EE.21036.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Mon, 25 Jun 2018 02:15:42 +1000, Chris Angelico wrote: > On Mon, Jun 25, 2018 at 2:07 AM, Steven D'Aprano > wrote: >> Anyone on the Python-Dev mailing list, are you getting private emails >> containing nothing but stream of consciousness word-salad from somebody >> (some bot?) calling himself "Chanel Marvin" with a gmail address? >> >> Typical example: >> >> "I refuse to create my environment on a computer. Stalls and static >> and it always looks fake unless I can afford all the cool fast >> stuff like Prometheus speed but for dummies in plain white english" >> >> in reply to an email I posted to the list. >> >> I don't want to ask there, yet, in case it isn't a bot but some nutter >> with an attitude emailing me privately. >> >> > Yeah, I got one of those. I'm pretty sure it's a Markov chainer. Only one? So far I've had seven. I get spam bots trying to flush out suckers. I don't get bots that send out random messages to random people. Why? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From p.f.moore at gmail.com Sun Jun 24 17:37:51 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Sun, 24 Jun 2018 22:37:51 +0100 Subject: Quick survey: locals in comprehensions (Python 3 only) In-Reply-To: References: Message-ID: On 24 June 2018 at 06:03, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, since > this is about your EXPECTATIONS, not what Python actually does. > > Given this function: > > > def test(): > a = 1 > b = 2 > result = [value for key, value in locals().items()] > return result > > what would you expect the result of calling test() to be? Is that the > result you think is most useful? In your opinion, is this a useful > feature, a misfeature, a bug, or "whatever"? > > I'm only looking for answers for Python 3. (The results in Python 2 are > genuinely weird :-) My immediate reaction was "that's not something I'd want to do, so I don't care (but I've a feeling it would be weird). On thinking some more, I decided that [1, 2] made sense (but I still didn't actually care). After reading Chris Angelico's analysis, I went back to my first opinion (that I don't care, but I suspect it might be weird). I'm aware of the background for this question. Is there any equivalent question that doesn't use locals()? The reason I ask is that I see locals() as "digging into implementation stuff" and sort of expect it to act oddly in situations like this... Paul From bart at 1 Sun Jun 24 17:39:18 2018 From: bart at 1 (Bart) Date: Sun, 24 Jun 2018 16:39:18 -0500 Subject: syntax difference In-Reply-To: <5B30F4EE.21024.uclanpyth@castlerockbbs.com> References: <5B30F4EE.21024.uclanpyth@castlerockbbs.com> Message-ID: <5B30F4EE.21030.uclanpyth@castlerockbbs.com> To: Chris Angelico From: Bart On 24/06/2018 15:46, Chris Angelico wrote: > On Sun, Jun 24, 2018 at 8:40 PM, Steven D'Aprano > wrote: >> On Sun, 24 Jun 2018 11:18:37 +0100, Bart wrote: >> >>> I wonder why it is just me that constantly needs to justify his >>> existence in this group? >> >> Because its just you who spends 90% of his time here complaining about >> how Python does it wrong. > > ... and spends 95% of that time demonstrating his utter lack of > understanding of how Python does it at all. It's wrong even though you > don't understand how it actually works. More like utter disbelief at how it works. Surely it cannot work like that because it would be too inefficient? Apparently, yes it can... And all to support extreme dynamism which is only really needed a tiny proportion of the time (feel free to correct me). I know I'm going to get flak for bringing this up this old issue, but remember when you used to write a for-loop and it involved creating an actual list of N integers from 0 to N-1 in order to iterate through them? Crazy. But that has long been fixed - or so I thought. When I wrote, today: for i in range(100000000): pass # 100 million on Python 2, it used up 1.8GB, up to the limit of my RAM, and it took several minutes to regain control of my machine (and it never did finish). You don't expect that in 2018 when executing a simple empty loop. On Py 2 you have to use xrange for large ranges - that was the fix. Somebody however must have had to gently and tactfully point out the issue. I'm afraid I'm not very tactful. -- bart --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bart at 1 Sun Jun 24 17:39:18 2018 From: bart at 1 (Bart) Date: Sun, 24 Jun 2018 16:39:18 -0500 Subject: syntax difference Message-ID: <5B324678.21175.uclanpyth@castlerockbbs.com> To: Chris Angelico From: "Bart" To: Chris Angelico From: Bart On 24/06/2018 15:46, Chris Angelico wrote: > On Sun, Jun 24, 2018 at 8:40 PM, Steven D'Aprano > wrote: >> On Sun, 24 Jun 2018 11:18:37 +0100, Bart wrote: >> >>> I wonder why it is just me that constantly needs to justify his >>> existence in this group? >> >> Because its just you who spends 90% of his time here complaining about >> how Python does it wrong. > > ... and spends 95% of that time demonstrating his utter lack of > understanding of how Python does it at all. It's wrong even though you > don't understand how it actually works. More like utter disbelief at how it works. Surely it cannot work like that because it would be too inefficient? Apparently, yes it can... And all to support extreme dynamism which is only really needed a tiny proportion of the time (feel free to correct me). I know I'm going to get flak for bringing this up this old issue, but remember when you used to write a for-loop and it involved creating an actual list of N integers from 0 to N-1 in order to iterate through them? Crazy. But that has long been fixed - or so I thought. When I wrote, today: for i in range(100000000): pass # 100 million on Python 2, it used up 1.8GB, up to the limit of my RAM, and it took several minutes to regain control of my machine (and it never did finish). You don't expect that in 2018 when executing a simple empty loop. On Py 2 you have to use xrange for large ranges - that was the fix. Somebody however must have had to gently and tactfully point out the issue. I'm afraid I'm not very tactful. -- bart -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From gene.heskett at 1 Sun Jun 24 18:03:10 2018 From: gene.heskett at 1 (Gene Heskett) Date: Sun, 24 Jun 2018 17:03:10 -0500 Subject: I'm getting a spamassassin party here Message-ID: <5B324678.21138.uclanpyth@castlerockbbs.com> From: Gene Heskett Greetings list; Generally spamassassin only gets picky about this occasionally, but for the past several hours its working overtime on python list messages, with the major problem being the servers time stamp, a day or more in the past. Anyboy ever hear of ntpd? -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From mark.lawrence at 1 Sun Jun 24 18:22:16 2018 From: mark.lawrence at 1 (Mark Lawrence) Date: Sun, 24 Jun 2018 17:22:16 -0500 Subject: Anyone here on Python-Dev mailing list? Message-ID: <5B324678.21141.uclanpyth@castlerockbbs.com> From: Mark Lawrence On 24/06/18 17:07, Steven D'Aprano wrote: > Anyone on the Python-Dev mailing list, are you getting private emails > containing nothing but stream of consciousness word-salad from somebody > (some bot?) calling himself "Chanel Marvin" with a gmail address? > > Typical example: > > "I refuse to create my environment on a computer. Stalls and static > and it always looks fake unless I can afford all the cool fast stuff > like Prometheus speed but for dummies in plain white english" > > in reply to an email I posted to the list. > > I don't want to ask there, yet, in case it isn't a bot but some nutter > with an attitude emailing me privately. > I see nothing like this reading python-dev via gmane. I rarely get anything in my private email inboxes about Python. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From ben+python at benfinney.id.au Sun Jun 24 19:19:20 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 25 Jun 2018 09:19:20 +1000 Subject: Package directory question References: Message-ID: <851scveps7.fsf@benfinney.id.au> Robert Latest via Python-list writes: > Because the main.py script needs to import the tables.py module from > backend, I put this at the top if main.py: > > sys.path.append('../..') > import jobwatch.backend.tables as tables > > My question is: Is this the way it should be done? It looks fishy. The > only alternative I could come up with is to put a symlink to tables.py > into the frontend directory, which also seems fishy. Your fish-sense is working correctly. Both of those are hard-coding the path, when the Python import mechanism is designed so you don't do that. Instead, to run the package, first install the package. To install the package, use the Pip tool. This comes standard when you install Python 3. By installing your code, you make it available to be discovered by Python's normal import mechanism. So, choose how you want to install the package: * To install for normal use, ?python3 -m pip install ??. * To install for use only by the current user, add the ?--user? option. * To install for use while also developing, add the ?--editable? option. See the ?python3 -m pip --help? document for details about what all that does. -- \ ?Telling pious lies to trusting children is a form of abuse, | `\ plain and simple.? ?Daniel Dennett, 2010-01-12 | _o__) | Ben Finney From ben+python at benfinney.id.au Sun Jun 24 19:20:49 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 25 Jun 2018 09:20:49 +1000 Subject: Anyone here on Python-Dev mailing list? References: Message-ID: <85tvprdb5a.fsf@benfinney.id.au> Steven D'Aprano writes: > Anyone on the Python-Dev mailing list, are you getting private emails > containing nothing but stream of consciousness word-salad from > somebody (some bot?) calling himself "Chanel Marvin" with a gmail > address? I am on that forum (via Gmane), and am not receiving anything like that. -- \ ?Today, I was ? no, that wasn't me.? ?Steven Wright | `\ | _o__) | Ben Finney From ben+python at benfinney.id.au Sun Jun 24 19:33:35 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 25 Jun 2018 09:33:35 +1000 Subject: Quick survey: locals in comprehensions (Python 3 only) References: Message-ID: <85po0fdak0.fsf@benfinney.id.au> Paul Moore writes: > On 24 June 2018 at 06:03, Steven D'Aprano > wrote: > > Given this function: > > > > def test(): > > a = 1 > > b = 2 > > result = [value for key, value in locals().items()] > > return result > > > > what would you expect the result of calling test() to be? [?] > I'm aware of the background for this question. Is there any equivalent > question that doesn't use locals()? The reason I ask is that I see > locals() as "digging into implementation stuff" and sort of expect it > to act oddly in situations like this... My understanding of Steven's question is to give an unambiguous way to: * Express the question ?which name bindings do you expect to exist in this local function scope, by the time of the ?return? statement??. * Avoid prejudicing the reader to expect any particular binding to be active. One way to do the first, at the cost of losing the second, might be this:: def test(): a = 1 b = 2 [value for key, value in dict().items()] print(a) print(b) print(key) print(value) and then ask ?Which of those statements do you expect to fail with NameError??. But I may have misunderstood some nuance of what is being asked, which is to be expected because Steven was deliberately trying to avoid having the reader second-guess what the purpose of the code is. -- \ ?I wish there was a knob on the TV to turn up the intelligence. | `\ There's a knob called ?brightness? but it doesn't work.? | _o__) ?Eugene P. Gallagher | Ben Finney From steven.d'aprano at 1 Sun Jun 24 20:02:44 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Sun, 24 Jun 2018 19:02:44 -0500 Subject: syntax difference Message-ID: <5B324677.21097.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sun, 24 Jun 2018 19:37:33 +0100, Bart wrote: > I want to program in /my/ style Python is not Java, and Java is not Python either. Nor is it "Bart's Language", or C, or Forth, or Lisp, or bash. https://dirtsimple.org/2004/12/python-is-not-java.html https://dirtsimple.org/2004/12/java-is-not-python-either.html To get the best out of any language, you should try to program to its strengths, in the idioms that work, not insist on writing FooLanguage code in BarLanguage. Hammers are great tools. So are screwdrivers. But you wouldn't use a screwdriver to hammer nails, or hammer screws, would you? You'd probably be pretty frustrated if one of your users (ahem) insisted on duplicating the form and structure of their bash scripts in your language, and complaining bitterly about how your language sucks because it isn't bash. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bart at 1 Sun Jun 24 20:37:32 2018 From: bart at 1 (Bart) Date: Sun, 24 Jun 2018 19:37:32 -0500 Subject: syntax difference In-Reply-To: <5B30F4EE.21028.uclanpyth@castlerockbbs.com> References: <5B30F4EE.21028.uclanpyth@castlerockbbs.com> Message-ID: <5B30F4EE.21048.uclanpyth@castlerockbbs.com> To: boB Stepp From: Bart On 24/06/2018 16:37, boB Stepp wrote: > On Sun, Jun 24, 2018 at 5:21 AM Bart wrote: > "... And of course, you would have to know how to use Python properly in > idiomatic style. No. I want to program in /my/ style, one more like the pseudo-code that was mentioned elsewhere, and that is universally understood. Even if people here don't think much of it. (eg. https://pastebin.com/0EygJzFR, raw text:https://pastebin.com/raw/0EygJzFR) Why not choose this positive approach? I think it > would be a win-win for both you and Python." > > Just show you genuinely care about the language and the community. > Use and understand the language as well as you can before jumping into > criticisms. Adopt the path of the humble learner, who does not know > everything about Python. Is this too much to ask? Sorry, I tried a few replies but they all got too long and too much about me. So I'll have to leave it. I think people know enough about my ideas by now anyway. -- bart --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bart at 1 Sun Jun 24 20:37:32 2018 From: bart at 1 (Bart) Date: Sun, 24 Jun 2018 19:37:32 -0500 Subject: syntax difference Message-ID: <5B324678.21176.uclanpyth@castlerockbbs.com> To: boB Stepp From: "Bart" To: boB Stepp From: Bart On 24/06/2018 16:37, boB Stepp wrote: > On Sun, Jun 24, 2018 at 5:21 AM Bart wrote: > "... And of course, you would have to know how to use Python properly in > idiomatic style. No. I want to program in /my/ style, one more like the pseudo-code that was mentioned elsewhere, and that is universally understood. Even if people here don't think much of it. (eg. https://pastebin.com/0EygJzFR, raw text:https://pastebin.com/raw/0EygJzFR) Why not choose this positive approach? I think it > would be a win-win for both you and Python." > > Just show you genuinely care about the language and the community. > Use and understand the language as well as you can before jumping into > criticisms. Adopt the path of the humble learner, who does not know > everything about Python. Is this too much to ask? Sorry, I tried a few replies but they all got too long and too much about me. So I'll have to leave it. I think people know enough about my ideas by now anyway. -- bart -+- BBBS/Li6 v4.10 Toy-3 + Origin: Prism bbs (1:261/38) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steve+comp.lang.python at pearwood.info Sun Jun 24 20:52:36 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 25 Jun 2018 00:52:36 +0000 (UTC) Subject: syntax difference References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <0eKXC.515410$eg.279610@fx43.am4> Message-ID: On Sun, 24 Jun 2018 21:21:57 +0100, Bart wrote: > I've had half a dozen users Come back when you've had *half a million users* then we'll take your experiences seriously. https://blog.pythonanywhere.com/67/ https://stackoverflow.blog/2017/09/06/incredible-growth-python/ For a language which does everything wrong, it must be doing something right. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From abdur-rahmaan.janhangeer at 1 Sun Jun 24 20:53:16 2018 From: abdur-rahmaan.janhangeer at 1 (Abdur-Rahmaan Janhangeer) Date: Sun, 24 Jun 2018 19:53:16 -0500 Subject: Introducing Coconut Message-ID: <5B30F4EE.21031.uclanpyth@castlerockbbs.com> From: Abdur-Rahmaan Janhangeer hum syntactic coating exists even in py. nice! Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > > --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bart at 1 Sun Jun 24 21:03:12 2018 From: bart at 1 (Bart) Date: Sun, 24 Jun 2018 20:03:12 -0500 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: <5B30F4EE.21047.uclanpyth@castlerockbbs.com> References: <5B30F4EE.21047.uclanpyth@castlerockbbs.com> Message-ID: <5B324677.21096.uclanpyth@castlerockbbs.com> To: Abdur-Rahmaan Janhangeer From: Bart On 24/06/2018 19:36, Abdur-Rahmaan Janhangeer wrote: > see for example > > https://en.m.wikipedia.org/wiki/Bresenham%27s_line_algorithm > > see the pseudocode, i was implementing some raster algos when i found > myself aux anges > > so close to py. i guess it was written in prehistoric times with the author > trying to simplify stuffs I'm sorry, but that kind of code is a mish-mash of old Algol/Pascal-style languages. I doubt it was meant to be Python. Python doesn't have a monopoly on clear syntax. This is the first example from that link (I've taken out comments): function line(x0, y0, x1, y1) real deltax := x1 - x0 real deltay := y1 - y0 real deltaerr := abs(deltay / deltax) real error := 0.0 int y := y0 for x from x0 to x1 plot(x,y) error := error + deltaerr while error ??? 0.5 then y := y + sign(deltay) * 1 error := error - 1.0 This has some problems: it's using 'function' when it doesn't return a value (those languages used 'proc' or 'procedure' in that case). It doesn't give a type for the parameters, and it uses while/then rather than the usual while/do. So it's rather sloppy even for pseudo code. The only similarity with Python is the lack of block delimiters, but then with later examples they /are/ used, for if-else-endif. Below, the first block is that code tweaked to a static language of mine. The second is the same code tweaked to Python. It was less work to adapt it my syntax rather than Python. All versions however use a decidedly un-Pythonic style, which means the difference between the two below isn't that great, even though they are different languages. But imagine trying to adapt Pythonic code to work in the other language; it would be much harder (apart from one being dynamic and the other not). --------------------------------- proc line(int x0, y0, x1, y1)= real deltax := x1 - x0 real deltay := y1 - y0 real deltaerr := abs(deltay / deltax) real error := 0.0 int y := y0 int x for x := x0 to x1 do plot(x,y) error := error + deltaerr while error = 0.5 do y := y + sign(deltay) * 1 error := error - 1.0 end end end ---------------------------------- def line(x0, y0, x1, y1): deltax = x1 - x0 deltay = y1 - y0 deltaerr = abs(deltay / deltax) error = 0.0 y = y0 for x in range(x0,x1+1): plot(x,y) error = error + deltaerr while error == 0.5: y = y + sign(deltay) * 1 error = error - 1.0 -- bart --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From stefan.ram at 1 Sun Jun 24 21:06:52 2018 From: stefan.ram at 1 (Stefan Ram) Date: Sun, 24 Jun 2018 20:06:52 -0500 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: <5B30F4ED.21021.uclanpyth@castlerockbbs.com> References: <5B30F4ED.21021.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21127.uclanpyth@castlerockbbs.com> To: Stefan Ram From: ram at zedat.fu-berlin.de (Stefan Ram) ram at zedat.fu-berlin.de (Stefan Ram) writes: >Still, one must not forget that learning Python encompasses >all the hard work it takes to learn how to program in every >language. "Beginner", however, is a very vague term. A good scientist or engineer who (for some reason) never programmed before (or, at least, not in Python) is a totally different kind of a "beginner" than a secretary, a garbage collector or a schoolchild. Quoting: ??I've found that some of the best [Software ]developers of all are English majors. They'll often graduate with no programming experience at all, and certainly without a clue about the difference between DRAM and EPROM. But they can write. That's the art of conveying information concisely and clearly. Software development and writing are both the art of knowing what you're going to do, and then lucidly expressing your ideas.?? http://praisecurseandrecurse.blogspot.com/2007/03/english-majors-as-programmers .html --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From abdur-rahmaan.janhangeer at 1 Sun Jun 24 21:23:38 2018 From: abdur-rahmaan.janhangeer at 1 (Abdur-Rahmaan Janhangeer) Date: Sun, 24 Jun 2018 20:23:38 -0500 Subject: Python for beginners or not? [was Re: syntax difference] Message-ID: <5B30F4EE.21034.uclanpyth@castlerockbbs.com> From: Abdur-Rahmaan Janhangeer Python is rightly called executable pseudocode. i appreciated the fact that you can go on wikipaedia, find the pseudocode of algorithms remove curly braces and replace by py's more powerful syntax and poof, suddenly it becomes too easy. Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > > --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From abdur-rahmaan.janhangeer at 1 Sun Jun 24 21:42:00 2018 From: abdur-rahmaan.janhangeer at 1 (Abdur-Rahmaan Janhangeer) Date: Sun, 24 Jun 2018 20:42:00 -0500 Subject: Anyone here on Python-Dev mailing list? Message-ID: <5B30F4EE.21041.uclanpyth@castlerockbbs.com> From: Abdur-Rahmaan Janhangeer i follow the dev list so far no but that particular mail might be related to pythan rather than random messages over the times i've talked to users of other langs (academics) one of the fault they find with python is the virtual env setup, too boring a task. environment in that case may refer to python environment Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bart at 1 Sun Jun 24 22:21:56 2018 From: bart at 1 (Bart) Date: Sun, 24 Jun 2018 21:21:56 -0500 Subject: syntax difference In-Reply-To: <5B324677.21097.uclanpyth@castlerockbbs.com> References: <5B324677.21097.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21129.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: Bart On 24/06/2018 20:02, Steven D'Aprano wrote: > On Sun, 24 Jun 2018 19:37:33 +0100, Bart wrote: > >> I want to program in /my/ style > > Python is not Java, and Java is not Python either. Nor is it "Bart's > Language", or C, or Forth, or Lisp, or bash. > > https://dirtsimple.org/2004/12/python-is-not-java.html > > https://dirtsimple.org/2004/12/java-is-not-python-either.html > > > To get the best out of any language, you should try to program to its > strengths, in the idioms that work, not insist on writing FooLanguage > code in BarLanguage. I like to write in clear code in a manner that anyone can follow (although I'm mainly thinking about myself). That means not using idioms specific to a language and hard to translate to anything else. Why might someone want to use something like Python rather than, for example, C? Here are some reasons: * Clearer syntax less full of punctuation * Simpler for-loops * Module import system * Much faster edit-run cycle * Dynamic types to eliminate most variable declarations * No need for forward declarations for functions * First class string handling * First class list handling * Flexible arrays/lists (not strings as they are immutable) * Namespaces * Default and keyword parameters * Can forget about using pointers That would be plenty to get started with, and enough to make it worthwhile to use the dynamic language provided its libraries and its performance are suitable for the task. But so far it has not been necessary to explicitly use a Pythonic style of coding or any of its esoteric features. > You'd probably be pretty frustrated if one of your users (ahem) insisted > on duplicating the form and structure of their bash scripts in your > language, and complaining bitterly about how your language sucks because > it isn't bash. I've had half a dozen users and I don't recall any particular problems nor any complaints. The language, although cruder then, must still have been sweeter to use than what was typically available at the time. -- bart --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From mark.lawrence at 1 Sun Jun 24 22:39:32 2018 From: mark.lawrence at 1 (Mark Lawrence) Date: Sun, 24 Jun 2018 21:39:32 -0500 Subject: Where's the junk coming from? Message-ID: <5B324678.21142.uclanpyth@castlerockbbs.com> From: Mark Lawrence Hi folks, In the last hour or so I've seen via thunderbird and gmane around 15 emails from various people where the from field is name at 1261/38.remove-r7u-this. The part after the @ symbol never changes. I've seen the contents previously, apart from one from the RUE. Users' complete email addresses are given right at the top. What gives? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From abdur-rahmaan.janhangeer at 1 Sun Jun 24 23:36:26 2018 From: abdur-rahmaan.janhangeer at 1 (Abdur-Rahmaan Janhangeer) Date: Sun, 24 Jun 2018 22:36:26 -0500 Subject: Python for beginners or not? [was Re: syntax difference] Message-ID: <5B30F4EE.21047.uclanpyth@castlerockbbs.com> From: Abdur-Rahmaan Janhangeer see for example https://en.m.wikipedia.org/wiki/Bresenham%27s_line_algorithm see the pseudocode, i was implementing some raster algos when i found myself aux anges so close to py. i guess it was written in prehistoric times with the author trying to simplify stuffs Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From etisbew.technology.group at 1 Sun Jun 24 23:37:22 2018 From: etisbew.technology.group at 1 (Etisbew Technology Group) Date: Sun, 24 Jun 2018 22:37:22 -0500 Subject: Web Solutions with PYTHON - Etisbew Technology Group Message-ID: <5B324678.21137.uclanpyth@castlerockbbs.com> From: Etisbew Technology Group Etisbew is a leading Python development company, serving businesses across the globe by delivering successful web-based apps using Python frameworks like TurboGears, Django, web2py & more. With hands-on experience over the Python web development, we offer bespoke, & robust PYTHON web solutions for all your web needs --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From paul.moore at 1 Sun Jun 24 23:37:50 2018 From: paul.moore at 1 (Paul Moore) Date: Sun, 24 Jun 2018 22:37:50 -0500 Subject: Quick survey: locals in comprehensions (Python 3 only) Message-ID: <5B324678.21132.uclanpyth@castlerockbbs.com> From: Paul Moore On 24 June 2018 at 06:03, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, since > this is about your EXPECTATIONS, not what Python actually does. > > Given this function: > > > def test(): > a = 1 > b = 2 > result = [value for key, value in locals().items()] > return result > > what would you expect the result of calling test() to be? Is that the > result you think is most useful? In your opinion, is this a useful > feature, a misfeature, a bug, or "whatever"? > > I'm only looking for answers for Python 3. (The results in Python 2 are > genuinely weird :-) My immediate reaction was "that's not something I'd want to do, so I don't care (but I've a feeling it would be weird). On thinking some more, I decided that [1, 2] made sense (but I still didn't actually care). After reading Chris Angelico's analysis, I went back to my first opinion (that I don't care, but I suspect it might be weird). I'm aware of the background for this question. Is there any equivalent question that doesn't use locals()? The reason I ask is that I see locals() as "digging into implementation stuff" and sort of expect it to act oddly in situations like this... Paul --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From hartmut.goebel at 1 Mon Jun 25 00:01:40 2018 From: hartmut.goebel at 1 (Hartmut Goebel) Date: Sun, 24 Jun 2018 23:01:40 -0500 Subject: [ANN] pdfposter 0.7 Message-ID: <5B324678.21130.uclanpyth@castlerockbbs.com> From: Hartmut Goebel I'm pleased to announce pdftools.pdfposter 0.7, a tool to scale and tile PDF images/pages to print on multiple pages. :Homepage: https://pdfposter.readthedocs.io/ :Author:? ? Hartmut Goebel :Licence:? GNU Public Licence v3 (GPLv3) :Quick Installation: ? ? ? pip install -U pdftools.pdfposter :Tarballs:? https://pypi.org/project/pdftools.pdfposter/#files What is pdfposter? -------------------- Scale and tile PDF images/pages to print on multiple pages. ``Pdfposter`` can be used to create a large poster by building it from multiple pages and/or printing it on large media. It expects as input a PDF file, normally printing on a single page. The output is again a PDF file, maybe containing multiple pages together building the poster. The input page will be scaled to obtain the desired size. This is much like ``poster`` does for Postscript files, but working with PDF. Since sometimes poster does not like your files converted from PDF. :-) Indeed ``pdfposter`` was inspired by ``poster``. For more information please refer to the manpage or visit the `project homepage `_. What's new in version 0.7 --------------------------------------- * Incompatible change: `DIN lang` and `Envelope No. 10` are now defined as ? landscape formats. * New options ``-f``/``--first`` and ``-l``/``--last`` for specifying the ? first resp. last page to convert * Reduce the size of the output file a lot. Now the output file is ? nearly the same size as the input file. While this behaviour was ? intended from the beginning, it was not yet implemented for two ? reasons: The content was a) copied for each print-page and b) not ? compressed. * Make the content of each page appear only once in the output file. ? This vastly reduces the size of the output file. * Compress page content. Now the output file is nearly the same size ? as the input file in much more cases. I thought, the underlying ? library will do this automatically, but it does not. * Fix bug in PDF code used for clipping the page content. Many thanks ? to Johannes Br??del for reporting this bug. * Add support for Python 3. * Use `PyPFDF2` instead of the unmaintained `pyPDF`. -- Regards Hartmut Goebel | Hartmut Goebel | h.goebel at crazy-compilers.com | | www.crazy-compilers.com | compilers which you thought are impossible | --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From abdur-rahmaan.janhangeer at 1 Mon Jun 25 01:18:44 2018 From: abdur-rahmaan.janhangeer at 1 (Abdur-Rahmaan Janhangeer) Date: Mon, 25 Jun 2018 00:18:44 -0500 Subject: Python for beginners or not? [was Re: syntax difference] Message-ID: <5B324678.21128.uclanpyth@castlerockbbs.com> From: Abdur-Rahmaan Janhangeer naaa it was not meant to be python ^^ Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > > --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From chris.angelico at 1 Mon Jun 25 01:46:00 2018 From: chris.angelico at 1 (Chris Angelico) Date: Mon, 25 Jun 2018 00:46:00 -0500 Subject: syntax difference Message-ID: <5B30F4EE.21024.uclanpyth@castlerockbbs.com> From: Chris Angelico On Sun, Jun 24, 2018 at 8:40 PM, Steven D'Aprano wrote: > On Sun, 24 Jun 2018 11:18:37 +0100, Bart wrote: > >> I wonder why it is just me that constantly needs to justify his >> existence in this group? > > Because its just you who spends 90% of his time here complaining about > how Python does it wrong. ... and spends 95% of that time demonstrating his utter lack of understanding of how Python does it at all. It's wrong even though you don't understand how it actually works. ChrisA --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steven.d'aprano at 1 Mon Jun 25 01:52:36 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Mon, 25 Jun 2018 00:52:36 -0500 Subject: syntax difference Message-ID: <5B324678.21136.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sun, 24 Jun 2018 21:21:57 +0100, Bart wrote: > I've had half a dozen users Come back when you've had *half a million users* then we'll take your experiences seriously. https://blog.pythonanywhere.com/67/ https://stackoverflow.blog/2017/09/06/incredible-growth-python/ For a language which does everything wrong, it must be doing something right. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From chris.angelico at 1 Mon Jun 25 02:38:22 2018 From: chris.angelico at 1 (Chris Angelico) Date: Mon, 25 Jun 2018 01:38:22 -0500 Subject: syntax difference Message-ID: <5B30F4EE.21029.uclanpyth@castlerockbbs.com> From: Chris Angelico On Mon, Jun 25, 2018 at 1:02 AM, Steven D'Aprano wrote: > On Mon, 25 Jun 2018 00:46:00 +1000, Chris Angelico wrote: > >> On Sun, Jun 24, 2018 at 8:40 PM, Steven D'Aprano >> wrote: >>> On Sun, 24 Jun 2018 11:18:37 +0100, Bart wrote: >>> >>>> I wonder why it is just me that constantly needs to justify his >>>> existence in this group? >>> >>> Because its just you who spends 90% of his time here complaining about >>> how Python does it wrong. >> >> ... and spends 95% of that time demonstrating his utter lack of >> understanding of how Python does it at all. It's wrong even though you >> don't understand how it actually works. > > Be fair. It's more like 50% of the time. > > Let's not dogpile onto Bart. He asked a question, I answered it, we don't > all need to sink the boot in as well. Fair. Still, it does seem that most of the criticisms are based on ignorance, not reasoned disagreement. For instance, I could argue that Python's model of "variables are local if written to, otherwise they're looked up globally" is a poor choice, because I have extensively used Python AND other (C-like) models. Or I could argue that Python really ought to support "foo bar baz"/" " as a syntax for string splitting, because I've used Python's way of doing things, and have also used something that works differently. But I cannot argue that Python should have mutable strings, because I've never used a modern language that has them, so I don't know what the tradeoffs are. Thus you don't hear me pushing for it. ChrisA --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From chris.angelico at 1 Mon Jun 25 03:15:42 2018 From: chris.angelico at 1 (Chris Angelico) Date: Mon, 25 Jun 2018 02:15:42 -0500 Subject: Anyone here on Python-Dev mailing list? Message-ID: <5B30F4EE.21033.uclanpyth@castlerockbbs.com> From: Chris Angelico On Mon, Jun 25, 2018 at 2:07 AM, Steven D'Aprano wrote: > Anyone on the Python-Dev mailing list, are you getting private emails > containing nothing but stream of consciousness word-salad from somebody > (some bot?) calling himself "Chanel Marvin" with a gmail address? > > Typical example: > > "I refuse to create my environment on a computer. Stalls and static > and it always looks fake unless I can afford all the cool fast stuff > like Prometheus speed but for dummies in plain white english" > > in reply to an email I posted to the list. > > I don't want to ask there, yet, in case it isn't a bot but some nutter > with an attitude emailing me privately. > Yeah, I got one of those. I'm pretty sure it's a Markov chainer. ChrisA --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From arj.python at gmail.com Mon Jun 25 03:36:25 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Mon, 25 Jun 2018 11:36:25 +0400 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: <07c5a9a1-e9b1-4253-942f-9083423ad8ce@gmail.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <07c5a9a1-e9b1-4253-942f-9083423ad8ce@gmail.com> Message-ID: i think he means like for a loop to iterate over a list you might do list = [1,2,3] for i in range(len(list)): print(list[i]) but the you might as well go for the simpler : for elem in list: print(elem) Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > From jkn at 1 Mon Jun 25 03:45:16 2018 From: jkn at 1 (jkn) Date: Mon, 25 Jun 2018 02:45:16 -0500 Subject: [ANN] pdfposter 0.7 In-Reply-To: <5B324678.21130.uclanpyth@castlerockbbs.com> References: <5B324678.21130.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21146.uclanpyth@castlerockbbs.com> To: Hartmut Goebel From: jkn On Sunday, June 24, 2018 at 10:02:05 PM UTC+1, Hartmut Goebel wrote: > I'm pleased to announce pdftools.pdfposter 0.7, a tool to scale and > tile PDF images/pages to print on multiple pages. > > :Homepage: https://pdfposter.readthedocs.io/ > :Author:? ? Hartmut Goebel > :Licence:? GNU Public Licence v3 (GPLv3) > > :Quick Installation: > ? ? ? pip install -U pdftools.pdfposter > > :Tarballs:? https://pypi.org/project/pdftools.pdfposter/#files > > > What is pdfposter? > -------------------- > > Scale and tile PDF images/pages to print on multiple pages. > > ``Pdfposter`` can be used to create a large poster by building it from > multiple pages and/or printing it on large media. It expects as input a > PDF file, normally printing on a single page. The output is again a > PDF file, maybe containing multiple pages together building the > poster. > The input page will be scaled to obtain the desired size. > > This is much like ``poster`` does for Postscript files, but working > with PDF. Since sometimes poster does not like your files converted > from PDF. :-) Indeed ``pdfposter`` was inspired by ``poster``. > > For more information please refer to the manpage or visit > the `project homepage `_. > > > What's new in version 0.7 > --------------------------------------- > > * Incompatible change: `DIN lang` and `Envelope No. 10` are now defined as > ? landscape formats. > > * New options ``-f``/``--first`` and ``-l``/``--last`` for specifying the > ? first resp. last page to convert > > * Reduce the size of the output file a lot. Now the output file is > ? nearly the same size as the input file. While this behaviour was > ? intended from the beginning, it was not yet implemented for two > ? reasons: The content was a) copied for each print-page and b) not > ? compressed. > > * Make the content of each page appear only once in the output file. > ? This vastly reduces the size of the output file. > > * Compress page content. Now the output file is nearly the same size > ? as the input file in much more cases. I thought, the underlying > ? library will do this automatically, but it does not. > > * Fix bug in PDF code used for clipping the page content. Many thanks > ? to Johannes Br??del for reporting this bug. > > * Add support for Python 3. > > * Use `PyPFDF2` instead of the unmaintained `pyPDF`. > > -- > Regards > Hartmut Goebel > > | Hartmut Goebel | h.goebel at crazy-compilers.com | > | www.crazy-compilers.com | compilers which you thought are impossible | Thank you, that looks useful to me. Jon N --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From chris.angelico at 1 Mon Jun 25 04:15:06 2018 From: chris.angelico at 1 (Chris Angelico) Date: Mon, 25 Jun 2018 03:15:06 -0500 Subject: Python for beginners or not? [was Re: syntax difference] Message-ID: <5B30F4EE.21046.uclanpyth@castlerockbbs.com> From: Chris Angelico On Mon, Jun 25, 2018 at 2:23 AM, Abdur-Rahmaan Janhangeer wrote: > Python is rightly called executable pseudocode. i appreciated the fact that > you can go on wikipaedia, find the pseudocode of algorithms remove curly > braces and replace by py's more powerful syntax and poof, suddenly it > becomes too easy. My pseudocode and Python code look extremely similar, but that's partly *because* I know Python. But I do periodically have JavaScript students ask me "Is that Python?" when what I've written is pseudocode. ChrisA --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From itaiyz97 at 1 Mon Jun 25 04:40:38 2018 From: itaiyz97 at 1 (itaiyz97) Date: Mon, 25 Jun 2018 03:40:38 -0500 Subject: moving to Python from Java/C++/C Message-ID: <5B324678.21148.uclanpyth@castlerockbbs.com> From: itaiyz97 at gmail.com Hey, I already have quite an experience in programming, and I wish to study Python as well. I need to study it before I continue with my comp. science academic studies. How do you recommend studying it? As mentioned in the headline, I already know Java, C++ and C. Thanks! --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From alister.ware at ntlworld.com Mon Jun 25 05:10:19 2018 From: alister.ware at ntlworld.com (Alister) Date: Mon, 25 Jun 2018 09:10:19 GMT Subject: Python for beginners or not? [was Re: syntax difference] References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <07c5a9a1-e9b1-4253-942f-9083423ad8ce@gmail.com> Message-ID: <%j2YC.926076$gE6.295723@fx06.am4> On Mon, 25 Jun 2018 11:36:25 +0400, Abdur-Rahmaan Janhangeer wrote: > i think he means like for a loop to iterate over a list you might do > > list = [1,2,3] > for i in range(len(list)): > print(list[i]) > > > but the you might as well go for the simpler : > > > for elem in list: > > print(elem) > > Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > > > for i in range(len(list)): is a python anti-pattern it is almost a 100% guarantee that you are doing something wrong* *as with all rules of thumb there is probably at least 1 exception that the python experts will now point out. -- Lend money to a bad debtor and he will hate you. From edmondo.giovannozzi at 1 Mon Jun 25 05:25:18 2018 From: edmondo.giovannozzi at 1 (edmondo giovannozzi) Date: Mon, 25 Jun 2018 04:25:18 -0500 Subject: moving to Python from Java/C++/C In-Reply-To: <5B324678.21148.uclanpyth@castlerockbbs.com> References: <5B324678.21148.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21151.uclanpyth@castlerockbbs.com> To: itaiyz97 From: edmondo.giovannozzi at gmail.com Il giorno luned?? 25 giugno 2018 12:40:53 UTC+2, itai... at gmail.com ha scritto: > Hey, > I already have quite an experience in programming, and I wish to study Python as well. I need to study it before I continue with my comp. science academic studies. > How do you recommend studying it? As mentioned in the headline, I already know Java, C++ and C. > Thanks! Well, I have used the tutorial at www.python.org. Python 3 of course. --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From arj.python at gmail.com Mon Jun 25 05:32:09 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Mon, 25 Jun 2018 13:32:09 +0400 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: <%j2YC.926076$gE6.295723@fx06.am4> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <07c5a9a1-e9b1-4253-942f-9083423ad8ce@gmail.com> <%j2YC.926076$gE6.295723@fx06.am4> Message-ID: we must maybe fibd an example where both are pythonic but one is simpler unless my type of example was intented by @steve Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > From jkn_gg at nicorp.f9.co.uk Mon Jun 25 05:45:16 2018 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Mon, 25 Jun 2018 02:45:16 -0700 (PDT) Subject: [ANN] pdfposter 0.7 In-Reply-To: References: Message-ID: <83c86687-4247-4fb7-881b-ca80fd7babaa@googlegroups.com> On Sunday, June 24, 2018 at 10:02:05 PM UTC+1, Hartmut Goebel wrote: > I'm pleased to announce pdftools.pdfposter 0.7, a tool to scale and > tile PDF images/pages to print on multiple pages. > > :Homepage: https://pdfposter.readthedocs.io/ > :Author:?? Hartmut Goebel > :Licence:? GNU Public Licence v3 (GPLv3) > > :Quick Installation: > ??? pip install -U pdftools.pdfposter > > :Tarballs:? https://pypi.org/project/pdftools.pdfposter/#files > > > What is pdfposter? > -------------------- > > Scale and tile PDF images/pages to print on multiple pages. > > ``Pdfposter`` can be used to create a large poster by building it from > multiple pages and/or printing it on large media. It expects as input a > PDF file, normally printing on a single page. The output is again a > PDF file, maybe containing multiple pages together building the > poster. > The input page will be scaled to obtain the desired size. > > This is much like ``poster`` does for Postscript files, but working > with PDF. Since sometimes poster does not like your files converted > from PDF. :-) Indeed ``pdfposter`` was inspired by ``poster``. > > For more information please refer to the manpage or visit > the `project homepage `_. > > > What's new in version 0.7 > --------------------------------------- > > * Incompatible change: `DIN lang` and `Envelope No. 10` are now defined as > ? landscape formats. > > * New options ``-f``/``--first`` and ``-l``/``--last`` for specifying the > ? first resp. last page to convert > > * Reduce the size of the output file a lot. Now the output file is > ? nearly the same size as the input file. While this behaviour was > ? intended from the beginning, it was not yet implemented for two > ? reasons: The content was a) copied for each print-page and b) not > ? compressed. > > * Make the content of each page appear only once in the output file. > ? This vastly reduces the size of the output file. > > * Compress page content. Now the output file is nearly the same size > ? as the input file in much more cases. I thought, the underlying > ? library will do this automatically, but it does not. > > * Fix bug in PDF code used for clipping the page content. Many thanks > ? to Johannes Br?del for reporting this bug. > > * Add support for Python 3. > > * Use `PyPFDF2` instead of the unmaintained `pyPDF`. > > -- > Regards > Hartmut Goebel > > | Hartmut Goebel | h.goebel at crazy-compilers.com | > | www.crazy-compilers.com | compilers which you thought are impossible | Thank you, that looks useful to me. Jon N From bc at freeuk.com Mon Jun 25 05:58:35 2018 From: bc at freeuk.com (Bart) Date: Mon, 25 Jun 2018 10:58:35 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <0eKXC.515410$eg.279610@fx43.am4> Message-ID: On 25/06/2018 01:52, Steven D'Aprano wrote: > On Sun, 24 Jun 2018 21:21:57 +0100, Bart wrote: > >> I've had half a dozen users > > Come back when you've had *half a million users* then we'll take your > experiences seriously. That being the case with Python (maybe even ten times as many), why would anybody here care what I say about it? So it doesn't a matter at all that you can do: math.pi = "Hmm, Pie!" because there are so many users who don't care. (Actually I can't remember how many users I had. The language was freely available as part of an application of which we sold thousands, and was actually used to help its implementation. There might have been a dozen people who used it to write add-on products as well as others who tinkered with it. But it was not then a stand-alone language; it was part of a 3D graphics app.) > https://blog.pythonanywhere.com/67/ > > https://stackoverflow.blog/2017/09/06/incredible-growth-python/ > > For a language which does everything wrong, it must be doing something > right. Well, you certainly you get your money's worth in terms of features and add-ons. -- bart From itaiyz97 at gmail.com Mon Jun 25 06:40:38 2018 From: itaiyz97 at gmail.com (itaiyz97 at gmail.com) Date: Mon, 25 Jun 2018 03:40:38 -0700 (PDT) Subject: moving to Python from Java/C++/C Message-ID: <96ed4112-1437-468f-ad8b-0e6f5c956314@googlegroups.com> Hey, I already have quite an experience in programming, and I wish to study Python as well. I need to study it before I continue with my comp. science academic studies. How do you recommend studying it? As mentioned in the headline, I already know Java, C++ and C. Thanks! From breamoreboy at gmail.com Mon Jun 25 06:42:27 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Mon, 25 Jun 2018 11:42:27 +0100 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: <%j2YC.926076$gE6.295723@fx06.am4> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <07c5a9a1-e9b1-4253-942f-9083423ad8ce@gmail.com> <%j2YC.926076$gE6.295723@fx06.am4> Message-ID: On 25/06/18 10:10, Alister via Python-list wrote: > On Mon, 25 Jun 2018 11:36:25 +0400, Abdur-Rahmaan Janhangeer wrote: > >> i think he means like for a loop to iterate over a list you might do >> >> list = [1,2,3] >> for i in range(len(list)): >> print(list[i]) >> >> >> but the you might as well go for the simpler : >> >> >> for elem in list: >> >> print(elem) >> >> Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ >> >> >> > > for i in range(len(list)): is a python anti-pattern it is almost a 100% > guarantee that you are doing something wrong* > > *as with all rules of thumb there is probably at least 1 exception that > the python experts will now point out. > > The exception is that if you really do need the index, you write:- for i, elem in enumerate(list): -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Mon Jun 25 06:53:26 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 25 Jun 2018 10:53:26 +0000 (UTC) Subject: Python for beginners or not? [was Re: syntax difference] References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <07c5a9a1-e9b1-4253-942f-9083423ad8ce@gmail.com> Message-ID: On Sun, 24 Jun 2018 10:46:09 -0700, Jim Lee wrote: > On 06/24/2018 04:35 AM, Steven D'Aprano wrote: >> >> Indeed. That's one of the beauties of Python -- even when there's an >> advanced way to do it, there's generally a simple way too. >> >> > What happened to the Python maxim "There should be one?and preferably > only one?obvious way to do it"? What about it? "There should be (at least) one (OBVIOUS WAY) to do it" does not preclude there being a million other non-obvious ways to do it. Even if we prefer only one (OBVIOUS WAY). Besides, its the Zen of Python. We should all know about Zen: In the second scroll of Wen the Eternally Surprised a story is written concerning one day when the apprentice Clodpool, in a rebellious mood, approached Wen and spake thusly: "Master, what is the difference between a humanistic, monastic system of belief in which wisdom is sought by means of an apparently nonsensical system of questions and answers, and a lot of mystic gibberish made up on the spur of the moment?" Wen considered this for some time, and at last said: "A fish!" And Clodpool went away, satisfied. -- (Terry Pratchett, "Thief of Time") Nearly everybody misses the fact that the Zen is a joke, not to be taken *too* seriously. A particularly subtle joke, but still a joke. https://www.wefearchange.org/2010/06/import-this-and-zen-of-python.html And the specific line you reference is *especially* a joke, one which flies past nearly everyone's head: There should be one-- and preferably only one --obvious way to do it. Notice the dashes? There are *two* traditional ways to use an pair of em- dashes for parenthetical asides: 1. With no space--like this--between the parenthetical aside and the text; 2. With a single space on either side -- like this -- between the aside and the rest of the text. Not satisfied with those two ways, Tim invented his own. https://bugs.python.org/issue3364 (Good grief, its been nearly ten years since that bug report. I remember it like it was yesterday.) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From jkn at 1 Mon Jun 25 07:15:36 2018 From: jkn at 1 (jkn) Date: Mon, 25 Jun 2018 06:15:36 -0500 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: <5B324678.21150.uclanpyth@castlerockbbs.com> References: <5B324678.21150.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21153.uclanpyth@castlerockbbs.com> To: Paul Moore From: jkn On Monday, June 25, 2018 at 12:17:29 PM UTC+1, Paul Moore wrote: > On 25 June 2018 at 11:53, Steven D'Aprano > wrote: > > > And the specific line you reference is *especially* a joke, one which > > flies past nearly everyone's head: > > > > There should be one-- and preferably only one --obvious way to do it. > > > > > > Notice the dashes? There are *two* traditional ways to use an pair of em- > > dashes for parenthetical asides: > > > > 1. With no space--like this--between the parenthetical aside and the text; > > > > 2. With a single space on either side -- like this -- between the aside > > and the rest of the text. > > > > Not satisfied with those two ways, Tim invented his own. > > > > > > https://bugs.python.org/issue3364 > > > > > > (Good grief, its been nearly ten years since that bug report. I remember > > it like it was yesterday.) > > Thank you for that bit of history! I never knew that (and indeed had > missed that part of the joke). Tim's contributions to Python are > always to be treasured :-) > > Paul Goodness, I too had missed that particular (admittedly subtle) joke, and I have an interest in orthography and typesetting etc. (as well as pedanticism ;-o). Yes, Tim Peters' contribution to python, and this newsgroup in days of yore, were to be treasured. Luckily the wisdom and measured tone he and other early pioneers modelled are (mostly) still with us here on comp.lang.python. Jon N (here since 1999 or so...) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From p.f.moore at gmail.com Mon Jun 25 07:17:02 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 25 Jun 2018 12:17:02 +0100 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <07c5a9a1-e9b1-4253-942f-9083423ad8ce@gmail.com> Message-ID: On 25 June 2018 at 11:53, Steven D'Aprano wrote: > And the specific line you reference is *especially* a joke, one which > flies past nearly everyone's head: > > There should be one-- and preferably only one --obvious way to do it. > > > Notice the dashes? There are *two* traditional ways to use an pair of em- > dashes for parenthetical asides: > > 1. With no space--like this--between the parenthetical aside and the text; > > 2. With a single space on either side -- like this -- between the aside > and the rest of the text. > > Not satisfied with those two ways, Tim invented his own. > > > https://bugs.python.org/issue3364 > > > (Good grief, its been nearly ten years since that bug report. I remember > it like it was yesterday.) Thank you for that bit of history! I never knew that (and indeed had missed that part of the joke). Tim's contributions to Python are always to be treasured :-) Paul From edmondo.giovannozzi at gmail.com Mon Jun 25 07:25:18 2018 From: edmondo.giovannozzi at gmail.com (edmondo.giovannozzi at gmail.com) Date: Mon, 25 Jun 2018 04:25:18 -0700 (PDT) Subject: moving to Python from Java/C++/C In-Reply-To: <96ed4112-1437-468f-ad8b-0e6f5c956314@googlegroups.com> References: <96ed4112-1437-468f-ad8b-0e6f5c956314@googlegroups.com> Message-ID: Il giorno luned? 25 giugno 2018 12:40:53 UTC+2, itai... at gmail.com ha scritto: > Hey, > I already have quite an experience in programming, and I wish to study Python as well. I need to study it before I continue with my comp. science academic studies. > How do you recommend studying it? As mentioned in the headline, I already know Java, C++ and C. > Thanks! Well, I have used the tutorial at www.python.org. Python 3 of course. From jkn_gg at nicorp.f9.co.uk Mon Jun 25 09:15:37 2018 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Mon, 25 Jun 2018 06:15:37 -0700 (PDT) Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <07c5a9a1-e9b1-4253-942f-9083423ad8ce@gmail.com> Message-ID: <2e37d772-5278-4096-9635-46e32403dcff@googlegroups.com> On Monday, June 25, 2018 at 12:17:29 PM UTC+1, Paul Moore wrote: > On 25 June 2018 at 11:53, Steven D'Aprano > wrote: > > > And the specific line you reference is *especially* a joke, one which > > flies past nearly everyone's head: > > > > There should be one-- and preferably only one --obvious way to do it. > > > > > > Notice the dashes? There are *two* traditional ways to use an pair of em- > > dashes for parenthetical asides: > > > > 1. With no space--like this--between the parenthetical aside and the text; > > > > 2. With a single space on either side -- like this -- between the aside > > and the rest of the text. > > > > Not satisfied with those two ways, Tim invented his own. > > > > > > https://bugs.python.org/issue3364 > > > > > > (Good grief, its been nearly ten years since that bug report. I remember > > it like it was yesterday.) > > Thank you for that bit of history! I never knew that (and indeed had > missed that part of the joke). Tim's contributions to Python are > always to be treasured :-) > > Paul Goodness, I too had missed that particular (admittedly subtle) joke, and I have an interest in orthography and typesetting etc. (as well as pedanticism ;-o). Yes, Tim Peters' contribution to python, and this newsgroup in days of yore, were to be treasured. Luckily the wisdom and measured tone he and other early pioneers modelled are (mostly) still with us here on comp.lang.python. Jon N (here since 1999 or so...) From email at paulstgeorge.com Mon Jun 25 09:23:37 2018 From: email at paulstgeorge.com (Paul St George) Date: Mon, 25 Jun 2018 15:23:37 +0200 Subject: Accessing the Python list Message-ID: <61143d0e-3ae4-6e95-bc80-58521b1723c6@paulstgeorge.com> Understanding and having an interest in Python does not imply knowledge of Usenet, mailing lists, NNTP, gateways, gmane, bottom-posting, vanilla-flopping, /et al/. But, knowledge of these seems to be needed (or is at least useful) in order to fully benefit from the Python list. Would it be a good idea to open and maintain a thread in which we would share information on accessing this excellent list? This would also move talk of Usenet, etc. away from Python topics. Paul PS It is likely that this information is already readily available and I have missed it. If so, sorry! From tim.chase at 1 Mon Jun 25 09:51:18 2018 From: tim.chase at 1 (Tim Chase) Date: Mon, 25 Jun 2018 08:51:18 -0500 Subject: Quick survey: locals in comprehensions (Python 3 only) Message-ID: <5B324678.21155.uclanpyth@castlerockbbs.com> From: Tim Chase On 2018-06-24 05:03, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, > since this is about your EXPECTATIONS, not what Python actually > does. > > Given this function: > > def test(): > a = 1 > b = 2 > result = [value for key, value in locals().items()] > return result > > what would you expect the result of calling test() to be? I'd expect either [1,2] or [2,1] depending on whether it's py2 (where dict iteration order isn't guaranteed, so could be either) or py3 (where dict order is more stable/guaranteed) > Is that the result you think is most useful? While I have difficulty imagining a case in which I'd find this useful, if I were writing this code, it's the "useful" result I'd expect. > In your opinion, is this a useful feature, a misfeature, a bug, or > "whatever"? I'd file it in the "whatever" category, possibly useful to someone other than me. -tkc --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From python.list at tim.thechases.com Mon Jun 25 09:51:19 2018 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 25 Jun 2018 08:51:19 -0500 Subject: Quick survey: locals in comprehensions (Python 3 only) In-Reply-To: References: Message-ID: <20180625085119.4558e586@bigbox.christie.dr> On 2018-06-24 05:03, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, > since this is about your EXPECTATIONS, not what Python actually > does. > > Given this function: > > def test(): > a = 1 > b = 2 > result = [value for key, value in locals().items()] > return result > > what would you expect the result of calling test() to be? I'd expect either [1,2] or [2,1] depending on whether it's py2 (where dict iteration order isn't guaranteed, so could be either) or py3 (where dict order is more stable/guaranteed) > Is that the result you think is most useful? While I have difficulty imagining a case in which I'd find this useful, if I were writing this code, it's the "useful" result I'd expect. > In your opinion, is this a useful feature, a misfeature, a bug, or > "whatever"? I'd file it in the "whatever" category, possibly useful to someone other than me. -tkc From python.list at tim.thechases.com Mon Jun 25 09:59:04 2018 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 25 Jun 2018 08:59:04 -0500 Subject: Quick survey: locals in comprehensions (Python 3 only) In-Reply-To: <7b2eb614-75b0-2bb8-8cf6-05f8913bac84@gmail.com> References: <7c53fc62-7d24-508d-74a9-94ff6570cc4b@gmail.com> <7b2eb614-75b0-2bb8-8cf6-05f8913bac84@gmail.com> Message-ID: <20180625085904.2f23cc3d@bigbox.christie.dr> On 2018-06-23 23:08, Jim Lee wrote: >>> On 06/23/2018 10:03 PM, Steven D'Aprano wrote: >>>> def test(): >>>> a = 1 >>>> b = 2 >>>> result = [value for key, value in locals().items()] >>>> return result >>>> >>>> what would you expect the result of calling test() to be? >>> >>> I would *expect* [1, 2, None], though I haven't actually tried >>> running it. >> Interesting. Where do you get the None from? > > There are three locals:? a, b, and result.? However at the time locals() is called/evaluated, "result" hasn't yet been created/defined, so I wouldn't expect to see any representation of "result" in the return value. If it existed before the locals() call, I would expect to see the value it had before the call: def test() a = 1 b = 2 result = "Steven" result = [value for key, value in locals().items()] return result test() # return [1, 2, "Steven"] -tkc From tim.chase at 1 Mon Jun 25 09:59:04 2018 From: tim.chase at 1 (Tim Chase) Date: Mon, 25 Jun 2018 08:59:04 -0500 Subject: Quick survey: locals in comprehensions (Python 3 only) Message-ID: <5B324678.21156.uclanpyth@castlerockbbs.com> From: Tim Chase On 2018-06-23 23:08, Jim Lee wrote: >>> On 06/23/2018 10:03 PM, Steven D'Aprano wrote: >>>> def test(): >>>> a = 1 >>>> b = 2 >>>> result = [value for key, value in locals().items()] >>>> return result >>>> >>>> what would you expect the result of calling test() to be? >>> >>> I would *expect* [1, 2, None], though I haven't actually tried >>> running it. >> Interesting. Where do you get the None from? > > There are three locals:? a, b, and result.? However at the time locals() is called/evaluated, "result" hasn't yet been created/defined, so I wouldn't expect to see any representation of "result" in the return value. If it existed before the locals() call, I would expect to see the value it had before the call: def test() a = 1 b = 2 result = "Steven" result = [value for key, value in locals().items()] return result test() # return [1, 2, "Steven"] -tkc --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From alister at 1 Mon Jun 25 10:10:18 2018 From: alister at 1 (Alister) Date: Mon, 25 Jun 2018 09:10:18 -0500 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: <5B324678.21143.uclanpyth@castlerockbbs.com> References: <5B324678.21143.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21144.uclanpyth@castlerockbbs.com> To: Abdur-Rahmaan Janhangeer From: Alister On Mon, 25 Jun 2018 11:36:25 +0400, Abdur-Rahmaan Janhangeer wrote: > i think he means like for a loop to iterate over a list you might do > > list = [1,2,3] > for i in range(len(list)): > print(list[i]) > > > but the you might as well go for the simpler : > > > for elem in list: > > print(elem) > > Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > > > for i in range(len(list)): is a python anti-pattern it is almost a 100% guarantee that you are doing something wrong* *as with all rules of thumb there is probably at least 1 exception that the python experts will now point out. -- Lend money to a bad debtor and he will hate you. --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From t.berger at 1 Mon Jun 25 10:12:10 2018 From: t.berger at 1 (T Berger) Date: Mon, 25 Jun 2018 09:12:10 -0500 Subject: Proper way to download stylesheets and templates Message-ID: <5B324678.21160.uclanpyth@castlerockbbs.com> From: T Berger I? ?m creating a webapp and trying to download a stylesheet and templates from my manual? ?s support site. I must be doing something wrong, because when I try to run my app, I get a 404 error message. I downloaded the files by dragging them off the screen into my webapp folder. But I? ?m getting a weird extension: ? ?hf.css.webloc.? ? Is this the problem? Is there a proper way to download such files? Thanks, Tamara --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From jkn at 1 Mon Jun 25 10:15:36 2018 From: jkn at 1 (jkn) Date: Mon, 25 Jun 2018 09:15:36 -0500 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: <5B324678.21158.uclanpyth@castlerockbbs.com> References: <5B324678.21158.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21161.uclanpyth@castlerockbbs.com> To: Chris Angelico From: jkn On Monday, June 25, 2018 at 4:23:57 PM UTC+1, Chris Angelico wrote: > On Mon, Jun 25, 2018 at 11:15 PM, jkn wrote: > > (as well as pedanticism ;-o). > > Pedantry. > > ChrisA > (You know I can't let that one pass.) I was chanel[l]ing the TimBot, as any fule kno... --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From ben.finney at 1 Mon Jun 25 10:19:20 2018 From: ben.finney at 1 (Ben Finney) Date: Mon, 25 Jun 2018 09:19:20 -0500 Subject: Package directory question Message-ID: <5B324678.21133.uclanpyth@castlerockbbs.com> From: Ben Finney Robert Latest via Python-list writes: > Because the main.py script needs to import the tables.py module from > backend, I put this at the top if main.py: > > sys.path.append('../..') > import jobwatch.backend.tables as tables > > My question is: Is this the way it should be done? It looks fishy. The > only alternative I could come up with is to put a symlink to tables.py > into the frontend directory, which also seems fishy. Your fish-sense is working correctly. Both of those are hard-coding the path, when the Python import mechanism is designed so you don't do that. Instead, to run the package, first install the package. To install the package, use the Pip tool. This comes standard when you install Python 3. By installing your code, you make it available to be discovered by Python's normal import mechanism. So, choose how you want to install the package: * To install for normal use, ? ?python3 -m pip install ? |? ?. * To install for use only by the current user, add the ? ?--user? ? option. * To install for use while also developing, add the ? ?--editable? ? option. See the ? ?python3 -m pip --help? ? document for details about what all that does. -- \ ? ?Telling pious lies to trusting children is a form of abuse, | `\ plain and simple.? ? ? ?Daniel Dennett, 2010-01-12 | _o__) | Ben Finney --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From ben.finney at 1 Mon Jun 25 10:20:48 2018 From: ben.finney at 1 (Ben Finney) Date: Mon, 25 Jun 2018 09:20:48 -0500 Subject: Anyone here on Python-Dev mailing list? Message-ID: <5B324678.21134.uclanpyth@castlerockbbs.com> From: Ben Finney Steven D'Aprano writes: > Anyone on the Python-Dev mailing list, are you getting private emails > containing nothing but stream of consciousness word-salad from > somebody (some bot?) calling himself "Chanel Marvin" with a gmail > address? I am on that forum (via Gmane), and am not receiving anything like that. -- \ ? ?Today, I was ? ? no, that wasn't me.? ? ? ?Steven Wright | `\ | _o__) | Ben Finney --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From ben.finney at 1 Mon Jun 25 10:33:34 2018 From: ben.finney at 1 (Ben Finney) Date: Mon, 25 Jun 2018 09:33:34 -0500 Subject: Quick survey: locals in comprehensions (Python 3 only) Message-ID: <5B324678.21135.uclanpyth@castlerockbbs.com> From: Ben Finney Paul Moore writes: > On 24 June 2018 at 06:03, Steven D'Aprano > wrote: > > Given this function: > > > > def test(): > > a = 1 > > b = 2 > > result = [value for key, value in locals().items()] > > return result > > > > what would you expect the result of calling test() to be? [? |] > I'm aware of the background for this question. Is there any equivalent > question that doesn't use locals()? The reason I ask is that I see > locals() as "digging into implementation stuff" and sort of expect it > to act oddly in situations like this... My understanding of Steven's question is to give an unambiguous way to: * Express the question ? ?which name bindings do you expect to exist in this local function scope, by the time of the ? ?return? ? statement?? ?. * Avoid prejudicing the reader to expect any particular binding to be active. One way to do the first, at the cost of losing the second, might be this:: def test(): a = 1 b = 2 [value for key, value in dict().items()] print(a) print(b) print(key) print(value) and then ask ? ?Which of those statements do you expect to fail with NameError?? ?. But I may have misunderstood some nuance of what is being asked, which is to be expected because Steven was deliberately trying to avoid having the reader second-guess what the purpose of the code is. -- \ ? ?I wish there was a knob on the TV to turn up the intelligence. | `\ There's a knob called ? ?brightness? ? but it doesn't work.? ? | _o__) ? ?Eugene P. Gallagher | Ben Finney --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From dan.stromberg at 1 Mon Jun 25 10:35:58 2018 From: dan.stromberg at 1 (Dan Stromberg) Date: Mon, 25 Jun 2018 09:35:58 -0500 Subject: moving to Python from Java/C++/C Message-ID: <5B324678.21163.uclanpyth@castlerockbbs.com> From: Dan Stromberg On Mon, Jun 25, 2018 at 3:40 AM, wrote: > Hey, > I already have quite an experience in programming, and I wish to study > Python as well. I need to study it before I continue with my comp. science > academic studies. > How do you recommend studying it? As mentioned in the headline, I already > know Java, C++ and C. > I recommend https://wiki.python.org/moin/BeginnersGuide/Programmers Full disclosure: I wrote the "Intro to Python" slide deck. And yes, in 2018, you probably should study Python 3, not Python 2. --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From grant.b.edwards at gmail.com Mon Jun 25 10:43:44 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 25 Jun 2018 14:43:44 +0000 (UTC) Subject: Python for beginners or not? [was Re: syntax difference] References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <07c5a9a1-e9b1-4253-942f-9083423ad8ce@gmail.com> Message-ID: On 2018-06-25, Steven D'Aprano wrote: > And the specific line you reference is *especially* a joke, one which > flies past nearly everyone's head: > > There should be one-- and preferably only one --obvious way to do it. > > Notice the dashes? There are *two* traditional ways to use an pair > of em- dashes for parenthetical asides: > > 1. With no space--like this--between the parenthetical aside and the text; > > 2. With a single space on either side -- like this -- between the aside > and the rest of the text. > > Not satisfied with those two ways, Tim invented his own. > > https://bugs.python.org/issue3364 Brilliant! I don't know how I missed that. I'm not sure which would be more impressive: that Tim thought up the joke as described, or that it was made up ex post facto. Either one is brilliant. -- Grant Edwards grant.b.edwards Yow! I once decorated my at apartment entirely in ten gmail.com foot salad forks!! From rick.johnson at 1 Mon Jun 25 11:02:32 2018 From: rick.johnson at 1 (Rick Johnson) Date: Mon, 25 Jun 2018 10:02:32 -0500 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: <5B324678.21149.uclanpyth@castlerockbbs.com> References: <5B324678.21149.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21177.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: Rick Johnson On Monday, June 25, 2018 at 5:56:04 AM UTC-5, Steven D'Aprano wrote: > Nearly everybody misses the fact that the Zen is a joke, > not to be taken *too* seriously. A particularly subtle > joke, but still a joke. The Python Zen is not merely a joke. But it does outline the philosophy of a Python programmer in a humorous and self- contradicting manner. So while you shouldn't read the Zen as some sort of religious law, you shouldn't dismiss it as a joke either. Like a Monty Python skit, the Zen exposes the hypocrisy of reality and does so in a humorous way. > Not satisfied with those two ways, Tim invented his own. > > https://bugs.python.org/issue3364 BS! If there is one skill that we pythonista's all share, it is an uncanny ability to glaze over our obvious mistakes with beautiful, sweet lies. "A bug???" "Whaddya mean a bug?" "That's not a bug!" "It's a feature!" "Here, allow me to explain..." [...snip two hours of monologue...] Alas! If only we had followed our _true_ calling and became lawyers. (at least we would have been forced to dress respectively) ;-) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From rosuav at gmail.com Mon Jun 25 11:23:31 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Jun 2018 01:23:31 +1000 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: <2e37d772-5278-4096-9635-46e32403dcff@googlegroups.com> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <07c5a9a1-e9b1-4253-942f-9083423ad8ce@gmail.com> <2e37d772-5278-4096-9635-46e32403dcff@googlegroups.com> Message-ID: On Mon, Jun 25, 2018 at 11:15 PM, jkn wrote: > (as well as pedanticism ;-o). Pedantry. ChrisA (You know I can't let that one pass.) From alister.ware at ntlworld.com Mon Jun 25 11:25:16 2018 From: alister.ware at ntlworld.com (Alister) Date: Mon, 25 Jun 2018 15:25:16 GMT Subject: Python for beginners or not? [was Re: syntax difference] References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <07c5a9a1-e9b1-4253-942f-9083423ad8ce@gmail.com> <%j2YC.926076$gE6.295723@fx06.am4> Message-ID: On Mon, 25 Jun 2018 11:42:27 +0100, Mark Lawrence wrote: > On 25/06/18 10:10, Alister via Python-list wrote: >> On Mon, 25 Jun 2018 11:36:25 +0400, Abdur-Rahmaan Janhangeer wrote: >> >>> i think he means like for a loop to iterate over a list you might do >>> >>> list = [1,2,3] >>> for i in range(len(list)): >>> print(list[i]) >>> >>> >>> but the you might as well go for the simpler : >>> >>> >>> for elem in list: >>> >>> print(elem) >>> >>> Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ >>> >>> >>> >>> >> for i in range(len(list)): is a python anti-pattern it is almost a 100% >> guarantee that you are doing something wrong* >> >> *as with all rules of thumb there is probably at least 1 exception that >> the python experts will now point out. >> >> >> > The exception is that if you really do need the index, you write:- > > for i, elem in enumerate(list): I would not call that an exception, that is still the correct way to obtain the index during the loop -- I saw a subliminal advertising executive, but only for a second. -- Steven Wright From steven.d'aprano at 1 Mon Jun 25 11:53:26 2018 From: steven.d'aprano at 1 (Steven D'Aprano) Date: Mon, 25 Jun 2018 10:53:26 -0500 Subject: Python for beginners or not? [was Re: syntax difference] Message-ID: <5B324678.21149.uclanpyth@castlerockbbs.com> From: Steven D'Aprano On Sun, 24 Jun 2018 10:46:09 -0700, Jim Lee wrote: > On 06/24/2018 04:35 AM, Steven D'Aprano wrote: >> >> Indeed. That's one of the beauties of Python -- even when there's an >> advanced way to do it, there's generally a simple way too. >> >> > What happened to the Python maxim "There should be one? ?and preferably > only one? ?obvious way to do it"? What about it? "There should be (at least) one (OBVIOUS WAY) to do it" does not preclude there being a million other non-obvious ways to do it. Even if we prefer only one (OBVIOUS WAY). Besides, its the Zen of Python. We should all know about Zen: In the second scroll of Wen the Eternally Surprised a story is written concerning one day when the apprentice Clodpool, in a rebellious mood, approached Wen and spake thusly: "Master, what is the difference between a humanistic, monastic system of belief in which wisdom is sought by means of an apparently nonsensical system of questions and answers, and a lot of mystic gibberish made up on the spur of the moment?" Wen considered this for some time, and at last said: "A fish!" And Clodpool went away, satisfied. -- (Terry Pratchett, "Thief of Time") Nearly everybody misses the fact that the Zen is a joke, not to be taken *too* seriously. A particularly subtle joke, but still a joke. https://www.wefearchange.org/2010/06/import-this-and-zen-of-python.html And the specific line you reference is *especially* a joke, one which flies past nearly everyone's head: There should be one-- and preferably only one --obvious way to do it. Notice the dashes? There are *two* traditional ways to use an pair of em- dashes for parenthetical asides: 1. With no space--like this--between the parenthetical aside and the text; 2. With a single space on either side -- like this -- between the aside and the rest of the text. Not satisfied with those two ways, Tim invented his own. https://bugs.python.org/issue3364 (Good grief, its been nearly ten years since that bug report. I remember it like it was yesterday.) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From bart at 1 Mon Jun 25 11:58:34 2018 From: bart at 1 (Bart) Date: Mon, 25 Jun 2018 10:58:34 -0500 Subject: syntax difference In-Reply-To: <5B324678.21136.uclanpyth@castlerockbbs.com> References: <5B324678.21136.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21147.uclanpyth@castlerockbbs.com> To: Steven D'Aprano From: Bart On 25/06/2018 01:52, Steven D'Aprano wrote: > On Sun, 24 Jun 2018 21:21:57 +0100, Bart wrote: > >> I've had half a dozen users > > Come back when you've had *half a million users* then we'll take your > experiences seriously. That being the case with Python (maybe even ten times as many), why would anybody here care what I say about it? So it doesn't a matter at all that you can do: math.pi = "Hmm, Pie!" because there are so many users who don't care. (Actually I can't remember how many users I had. The language was freely available as part of an application of which we sold thousands, and was actually used to help its implementation. There might have been a dozen people who used it to write add-on products as well as others who tinkered with it. But it was not then a stand-alone language; it was part of a 3D graphics app.) > https://blog.pythonanywhere.com/67/ > > https://stackoverflow.blog/2017/09/06/incredible-growth-python/ > > For a language which does everything wrong, it must be doing something > right. Well, you certainly you get your money's worth in terms of features and add-ons. -- bart --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From brgrt2 at gmail.com Mon Jun 25 12:12:11 2018 From: brgrt2 at gmail.com (T Berger) Date: Mon, 25 Jun 2018 09:12:11 -0700 (PDT) Subject: Proper way to download stylesheets and templates Message-ID: <651232b3-b444-4879-888a-73811cae842f@googlegroups.com> I?m creating a webapp and trying to download a stylesheet and templates from my manual?s support site. I must be doing something wrong, because when I try to run my app, I get a 404 error message. I downloaded the files by dragging them off the screen into my webapp folder. But I?m getting a weird extension: ?hf.css.webloc.? Is this the problem? Is there a proper way to download such files? Thanks, Tamara From jkn_gg at nicorp.f9.co.uk Mon Jun 25 12:15:36 2018 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Mon, 25 Jun 2018 09:15:36 -0700 (PDT) Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <07c5a9a1-e9b1-4253-942f-9083423ad8ce@gmail.com> <2e37d772-5278-4096-9635-46e32403dcff@googlegroups.com> Message-ID: On Monday, June 25, 2018 at 4:23:57 PM UTC+1, Chris Angelico wrote: > On Mon, Jun 25, 2018 at 11:15 PM, jkn wrote: > > (as well as pedanticism ;-o). > > Pedantry. > > ChrisA > (You know I can't let that one pass.) I was chanel[l]ing the TimBot, as any fule kno... From breamoreboy at gmail.com Mon Jun 25 12:32:31 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Mon, 25 Jun 2018 17:32:31 +0100 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> <07c5a9a1-e9b1-4253-942f-9083423ad8ce@gmail.com> <2e37d772-5278-4096-9635-46e32403dcff@googlegroups.com> Message-ID: On 25/06/18 17:15, jkn wrote: > On Monday, June 25, 2018 at 4:23:57 PM UTC+1, Chris Angelico wrote: >> On Mon, Jun 25, 2018 at 11:15 PM, jkn wrote: >>> (as well as pedanticism ;-o). >> >> Pedantry. >> >> ChrisA >> (You know I can't let that one pass.) > > I was chanel[l]ing the TimBot, as any fule kno... > Ritten by a troo Molesworth fann. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From drsalists at gmail.com Mon Jun 25 12:35:59 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 25 Jun 2018 09:35:59 -0700 Subject: moving to Python from Java/C++/C In-Reply-To: <96ed4112-1437-468f-ad8b-0e6f5c956314@googlegroups.com> References: <96ed4112-1437-468f-ad8b-0e6f5c956314@googlegroups.com> Message-ID: On Mon, Jun 25, 2018 at 3:40 AM, wrote: > Hey, > I already have quite an experience in programming, and I wish to study > Python as well. I need to study it before I continue with my comp. science > academic studies. > How do you recommend studying it? As mentioned in the headline, I already > know Java, C++ and C. > I recommend https://wiki.python.org/moin/BeginnersGuide/Programmers Full disclosure: I wrote the "Intro to Python" slide deck. And yes, in 2018, you probably should study Python 3, not Python 2. From abdur-rahmaan.janhangeer at 1 Mon Jun 25 12:36:24 2018 From: abdur-rahmaan.janhangeer at 1 (Abdur-Rahmaan Janhangeer) Date: Mon, 25 Jun 2018 11:36:24 -0500 Subject: Python for beginners or not? [was Re: syntax difference] Message-ID: <5B324678.21143.uclanpyth@castlerockbbs.com> From: Abdur-Rahmaan Janhangeer i think he means like for a loop to iterate over a list you might do list = [1,2,3] for i in range(len(list)): print(list[i]) but the you might as well go for the simpler : for elem in list: print(elem) Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From mark.lawrence at 1 Mon Jun 25 12:42:26 2018 From: mark.lawrence at 1 (Mark Lawrence) Date: Mon, 25 Jun 2018 11:42:26 -0500 Subject: Python for beginners or not? [was Re: syntax difference] Message-ID: <5B324678.21152.uclanpyth@castlerockbbs.com> From: Mark Lawrence On 25/06/18 10:10, Alister via Python-list wrote: > On Mon, 25 Jun 2018 11:36:25 +0400, Abdur-Rahmaan Janhangeer wrote: > >> i think he means like for a loop to iterate over a list you might do >> >> list = [1,2,3] >> for i in range(len(list)): >> print(list[i]) >> >> >> but the you might as well go for the simpler : >> >> >> for elem in list: >> >> print(elem) >> >> Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ >> >> >> > > for i in range(len(list)): is a python anti-pattern it is almost a 100% > guarantee that you are doing something wrong* > > *as with all rules of thumb there is probably at least 1 exception that > the python experts will now point out. > > The exception is that if you really do need the index, you write:- for i, elem in enumerate(list): -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From rosuav at gmail.com Mon Jun 25 13:15:58 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Jun 2018 03:15:58 +1000 Subject: moving to Python from Java/C++/C In-Reply-To: References: <96ed4112-1437-468f-ad8b-0e6f5c956314@googlegroups.com> Message-ID: On Tue, Jun 26, 2018 at 2:35 AM, Dan Stromberg wrote: > On Mon, Jun 25, 2018 at 3:40 AM, wrote: > >> Hey, >> I already have quite an experience in programming, and I wish to study >> Python as well. I need to study it before I continue with my comp. science >> academic studies. >> How do you recommend studying it? As mentioned in the headline, I already >> know Java, C++ and C. >> > I recommend https://wiki.python.org/moin/BeginnersGuide/Programmers > > Full disclosure: I wrote the "Intro to Python" slide deck. > > And yes, in 2018, you probably should study Python 3, not Python 2. Yes. I'd upgrade the "probably" to "definitely". ChrisA From chema at rinzewind.org Mon Jun 25 13:16:25 2018 From: chema at rinzewind.org (=?iso-8859-1?Q?Jos=E9_Mar=EDa?= Mateos) Date: Mon, 25 Jun 2018 13:16:25 -0400 Subject: Where's the junk coming from? In-Reply-To: References: Message-ID: <20180625171625.GA13645@equipaje> On Sun, Jun 24, 2018 at 09:39:33PM +0100, Mark Lawrence wrote: > Hi folks, > > In the last hour or so I've seen via thunderbird and gmane around 15 > emails from various people where the from field is > name at 1261/38.remove-r7u-this. The part after the @ symbol never > changes. I've seen the contents previously, apart from one from the > RUE. Users' complete email addresses are given right at the top. > What gives? Same for me. Could it be a news to mailing list gateway? I've found this header in some of the offending messages: X-Gateway: castlerockbbs.com [Synchronet 3.17a-Linux NewsLink 1.108] Cheers, -- Jos? Mar?a (Chema) Mateos https://rinzewind.org/blog-es || https://rinzewind.org/blog-en From paul.moore at 1 Mon Jun 25 13:17:02 2018 From: paul.moore at 1 (Paul Moore) Date: Mon, 25 Jun 2018 12:17:02 -0500 Subject: Python for beginners or not? [was Re: syntax difference] Message-ID: <5B324678.21150.uclanpyth@castlerockbbs.com> From: Paul Moore On 25 June 2018 at 11:53, Steven D'Aprano wrote: > And the specific line you reference is *especially* a joke, one which > flies past nearly everyone's head: > > There should be one-- and preferably only one --obvious way to do it. > > > Notice the dashes? There are *two* traditional ways to use an pair of em- > dashes for parenthetical asides: > > 1. With no space--like this--between the parenthetical aside and the text; > > 2. With a single space on either side -- like this -- between the aside > and the rest of the text. > > Not satisfied with those two ways, Tim invented his own. > > > https://bugs.python.org/issue3364 > > > (Good grief, its been nearly ten years since that bug report. I remember > it like it was yesterday.) Thank you for that bit of history! I never knew that (and indeed had missed that part of the joke). Tim's contributions to Python are always to be treasured :-) Paul --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From breamoreboy at gmail.com Mon Jun 25 13:37:05 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Mon, 25 Jun 2018 18:37:05 +0100 Subject: Where's the junk coming from? In-Reply-To: References: Message-ID: On 24/06/18 21:39, Mark Lawrence wrote: > Hi folks, > > In the last hour or so I've seen via thunderbird and gmane around 15 > emails from various people where the from field is > name at 1261/38.remove-r7u-this.? The part after the @ symbol never > changes.? I've seen the contents previously, apart from one from the > RUE.? Users' complete email addresses are given right at the top.? What > gives? > More of the flaming things, this time name at 1261/38.remove-ij1-this. Any ideas as I don't understand this stuff? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From qhsgrant at outlook.com Mon Jun 25 14:17:45 2018 From: qhsgrant at outlook.com (qhsgrant at outlook.com) Date: Mon, 25 Jun 2018 18:17:45 -0000 (UTC) Subject: wily+python=NNTPclient ? Message-ID: Gary Capell who designed wily [in the 90s] mentioned that it could interface with python to make a NNTP client. As a daily user of wily, I seek info on connecting with python to get NNTP service. == TIA. From grant.b.edwards at gmail.com Mon Jun 25 14:22:56 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 25 Jun 2018 18:22:56 +0000 (UTC) Subject: Static variables [was Re: syntax difference] References: <5B30F4ED.21004.uclanpyth@castlerockbbs.com> Message-ID: On 2018-06-24, Steven D'Aprano wrote: > Building functions is cheap. Cheap is not free. > > Inner functions that aren't exposed to the outside cannot be tested > in isolation, you can't access them through help() > interactively. Given the choice between: [...] > so not expensive, but not free either. If using an inner function > has no advantages to you, why pay that tiny cost for no benefit? The benefit of an inner function is that it makes it perfectly clear to the reader that that function is not used outside the function where it is defined. It also makes it more difficult for other fuctions to muck things up by changing the binding of a global name. IOW, you use a local function instead of a global one for the exact same reasons you use local "variables" instead of global ones. In Python, functions are first class objects. Binding a name to a function is no different than binding it to an integer, list, string, or dict. Don't the global vs. local cost vs. benefit calculations apply equally well to function objects as they do to those other sorts of objects? -- Grant Edwards grant.b.edwards Yow! I'm a nuclear at submarine under the gmail.com polar ice cap and I need a Kleenex! From abdur-rahmaan.janhangeer at 1 Mon Jun 25 14:32:08 2018 From: abdur-rahmaan.janhangeer at 1 (Abdur-Rahmaan Janhangeer) Date: Mon, 25 Jun 2018 13:32:08 -0500 Subject: Python for beginners or not? [was Re: syntax difference] Message-ID: <5B324678.21145.uclanpyth@castlerockbbs.com> From: Abdur-Rahmaan Janhangeer we must maybe fibd an example where both are pythonic but one is simpler unless my type of example was intented by @steve Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From boblatest at yahoo.com Mon Jun 25 14:49:19 2018 From: boblatest at yahoo.com (Robert Latest) Date: 25 Jun 2018 18:49:19 GMT Subject: Package directory question References: <851scveps7.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Robert Latest via Python-list writes: > >> Because the main.py script needs to import the tables.py module from >> backend, I put this at the top if main.py: >> >> sys.path.append('../..') >> import jobwatch.backend.tables as tables >> >> My question is: Is this the way it should be done? It looks fishy. The >> only alternative I could come up with is to put a symlink to tables.py >> into the frontend directory, which also seems fishy. > > Your fish-sense is working correctly. Both of those are hard-coding the > path, when the Python import mechanism is designed so you don't do that. [...] > * To install for use while also developing, add the ?--editable? option. Ah, that's what I needed. Of course the problem I had was only present during development. I haven't really looked into pip yet, so far I've been using only "python setup.py install". Thanks, robert From marko at pacujo.net Mon Jun 25 14:58:25 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 25 Jun 2018 21:58:25 +0300 Subject: Static variables [was Re: syntax difference] References: <5B30F4ED.21004.uclanpyth@castlerockbbs.com> Message-ID: <87tvpqhewe.fsf@elektro.pacujo.net> Grant Edwards : > IOW, you use a local function instead of a global one for the exact > same reasons you use local "variables" instead of global ones. > > In Python, functions are first class objects. Binding a name to a > function is no different than binding it to an integer, list, string, > or dict. Don't the global vs. local cost vs. benefit calculations > apply equally well to function objects as they do to those other sorts > of objects? Precisely! The most important reason to use inner functions or inner classes is that it's cromulent for the task at hand, stylistically opportune or optimal, not to use the word Pythonic. Marko From grant.edwards at 1 Mon Jun 25 15:43:44 2018 From: grant.edwards at 1 (Grant Edwards) Date: Mon, 25 Jun 2018 14:43:44 -0500 Subject: Python for beginners or not? [was Re: syntax difference] Message-ID: <5B324678.21157.uclanpyth@castlerockbbs.com> From: Grant Edwards On 2018-06-25, Steven D'Aprano wrote: > And the specific line you reference is *especially* a joke, one which > flies past nearly everyone's head: > > There should be one-- and preferably only one --obvious way to do it. > > Notice the dashes? There are *two* traditional ways to use an pair > of em- dashes for parenthetical asides: > > 1. With no space--like this--between the parenthetical aside and the text; > > 2. With a single space on either side -- like this -- between the aside > and the rest of the text. > > Not satisfied with those two ways, Tim invented his own. > > https://bugs.python.org/issue3364 Brilliant! I don't know how I missed that. I'm not sure which would be more impressive: that Tim thought up the joke as described, or that it was made up ex post facto. Either one is brilliant. -- Grant Edwards grant.b.edwards Yow! I once decorated my at apartment entirely in ten gmail.com foot salad forks!! --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From grant.b.edwards at gmail.com Mon Jun 25 16:04:54 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 25 Jun 2018 20:04:54 +0000 (UTC) Subject: syntax difference References: <5B30F4EE.21035.uclanpyth@castlerockbbs.com> Message-ID: On 2018-06-24, Steven D'Aprano wrote: > That's nothing, there are languages where the standard way to write > a for loop is to call an external program that generates a stream of > numeric strings separated by spaces in a subprocess, and read the > strings from standard input as text. What language are you bashing now? ;) -- Grant Edwards grant.b.edwards Yow! ANN JILLIAN'S HAIR at makes LONI ANDERSON'S gmail.com HAIR look like RICARDO MONTALBAN'S HAIR! From arj.python at gmail.com Mon Jun 25 16:05:32 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 26 Jun 2018 00:05:32 +0400 Subject: Accessing the Python list In-Reply-To: <61143d0e-3ae4-6e95-bc80-58521b1723c6@paulstgeorge.com> References: <61143d0e-3ae4-6e95-bc80-58521b1723c6@paulstgeorge.com> Message-ID: i would prefer everyone using the mailing list (misses many spams) but of course that is a crazy idea (no need to reply with brain-damaged by facebook, aol, gmail etc expressions) Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > From Joseph.Schachner at Teledyne.com Mon Jun 25 16:09:19 2018 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Mon, 25 Jun 2018 20:09:19 +0000 Subject: range Message-ID: <94c123f7a8e04ad49e5784050e7bef98@Teledyne.com> Re: "I know I'm going to get flak for bringing this up this old issue, but remember when you used to write a for-loop and it involved creating an actual list of N integers from 0 to N-1 in order to iterate through them? Crazy. But that has long been fixed - or so I thought. When I wrote, today: for i in range(100000000): pass # 100 million on Python 2, it used up 1.8GB, up to the limit of my RAM, and it took several minutes to regain control of my machine (and it never did finish). You don't expect that in 2018 when executing a simple empty loop. On Py 2 you have to use xrange for large ranges - that was the fix. Somebody however must have had to gently and tactfully point out the issue. I'm afraid I'm not very tactful." It HAS been fixed in Python 3, since the beginning of that branch. In Python 3 range is what xrange was in Python 2. I used past tense there on purpose. Python 2 actual demise is scheduled. See: https://python3statement.org/ It's a list of project that have pledged to drop support for Python2.7 no later than January 1, 2020. You will recognize many of them: Pandas, IPython, NumPy, Matplotlib, Jupyter... etc Anyone talking about the future of Python and features that might be added to Python really has to be talking about Python 3, because Python 2 support is already ramping down and will completely end on January 1, 2020. The original plan was to end it in 2015, but the extra five years were added to give everyone plenty of time to switch. -- Joseph S. From rosuav at gmail.com Mon Jun 25 16:15:04 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Jun 2018 06:15:04 +1000 Subject: syntax difference In-Reply-To: References: <5B30F4EE.21035.uclanpyth@castlerockbbs.com> Message-ID: On Tue, Jun 26, 2018 at 6:04 AM, Grant Edwards wrote: > On 2018-06-24, Steven D'Aprano wrote: > >> That's nothing, there are languages where the standard way to write >> a for loop is to call an external program that generates a stream of >> numeric strings separated by spaces in a subprocess, and read the >> strings from standard input as text. > > What language are you bashing now? > I swear, some people were just bourne funny... ChrisA From paul.st.george at 1 Mon Jun 25 16:23:36 2018 From: paul.st.george at 1 (Paul St George) Date: Mon, 25 Jun 2018 15:23:36 -0500 Subject: Accessing the Python list Message-ID: <5B324678.21154.uclanpyth@castlerockbbs.com> From: Paul St George Understanding and having an interest in Python does not imply knowledge of Usenet, mailing lists, NNTP, gateways, gmane, bottom-posting, vanilla-flopping, /et al/. But, knowledge of these seems to be needed (or is at least useful) in order to fully benefit from the Python list. Would it be a good idea to open and maintain a thread in which we would share information on accessing this excellent list? This would also move talk of Usenet, etc. away from Python topics. Paul PS It is likely that this information is already readily available and I have missed it. If so, sorry! --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From alister at 1 Mon Jun 25 16:25:16 2018 From: alister at 1 (Alister) Date: Mon, 25 Jun 2018 15:25:16 -0500 Subject: Python for beginners or not? [was Re: syntax difference] In-Reply-To: <5B324678.21152.uclanpyth@castlerockbbs.com> References: <5B324678.21152.uclanpyth@castlerockbbs.com> Message-ID: <5B324678.21159.uclanpyth@castlerockbbs.com> To: Mark Lawrence From: Alister On Mon, 25 Jun 2018 11:42:27 +0100, Mark Lawrence wrote: > On 25/06/18 10:10, Alister via Python-list wrote: >> On Mon, 25 Jun 2018 11:36:25 +0400, Abdur-Rahmaan Janhangeer wrote: >> >>> i think he means like for a loop to iterate over a list you might do >>> >>> list = [1,2,3] >>> for i in range(len(list)): >>> print(list[i]) >>> >>> >>> but the you might as well go for the simpler : >>> >>> >>> for elem in list: >>> >>> print(elem) >>> >>> Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ >>> >>> >>> >>> >> for i in range(len(list)): is a python anti-pattern it is almost a 100% >> guarantee that you are doing something wrong* >> >> *as with all rules of thumb there is probably at least 1 exception that >> the python experts will now point out. >> >> >> > The exception is that if you really do need the index, you write:- > > for i, elem in enumerate(list): I would not call that an exception, that is still the correct way to obtain the index during the loop -- I saw a subliminal advertising executive, but only for a second. -- Steven Wright --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From robertvstepp at gmail.com Mon Jun 25 16:58:35 2018 From: robertvstepp at gmail.com (boB Stepp) Date: Mon, 25 Jun 2018 15:58:35 -0500 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <2937f981-e2dc-41d6-9d89-373496cb5e6c@googlegroups.com> <5c98d2c5-0875-429c-8b72-3ccc91310b18@googlegroups.com> Message-ID: On Mon, Jun 25, 2018 at 2:37 AM Mark Lawrence wrote: > > On 24/06/18 00:44, boB Stepp wrote: > > I imagine that the > > transition from version 2 to 3 was not undertaken halfheartedly, but > > only after much thought and discussion since it did break backwards > > compatibility. > > > > So much so that a specific mailing list was set up just to discus the > transition, archives here https://mail.python.org/pipermail/python-3000/ Thanks for the link, Mark. I was not aware of this archive. It will probably answer some things I have always wondered about. -- boB From mark.lawrence at 1 Mon Jun 25 18:32:30 2018 From: mark.lawrence at 1 (Mark Lawrence) Date: Mon, 25 Jun 2018 17:32:30 -0500 Subject: Python for beginners or not? [was Re: syntax difference] Message-ID: <5B324678.21162.uclanpyth@castlerockbbs.com> From: Mark Lawrence On 25/06/18 17:15, jkn wrote: > On Monday, June 25, 2018 at 4:23:57 PM UTC+1, Chris Angelico wrote: >> On Mon, Jun 25, 2018 at 11:15 PM, jkn wrote: >>> (as well as pedanticism ;-o). >> >> Pedantry. >> >> ChrisA >> (You know I can't let that one pass.) > > I was chanel[l]ing the TimBot, as any fule kno... > Ritten by a troo Molesworth fann. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From steve+comp.lang.python at pearwood.info Mon Jun 25 20:10:07 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 26 Jun 2018 00:10:07 +0000 (UTC) Subject: Static variables [was Re: syntax difference] References: <5B30F4ED.21004.uclanpyth@castlerockbbs.com> Message-ID: On Mon, 25 Jun 2018 18:22:56 +0000, Grant Edwards wrote: > On 2018-06-24, Steven D'Aprano wrote: > >> Building functions is cheap. Cheap is not free. >> >> Inner functions that aren't exposed to the outside cannot be tested in >> isolation, you can't access them through help() interactively. Given >> the choice between: > > [...] > >> so not expensive, but not free either. If using an inner function has >> no advantages to you, why pay that tiny cost for no benefit? > > The benefit of an inner function is that it makes it perfectly clear to > the reader that that function is not used outside the function where it > is defined. It also makes it more difficult for other fuctions to muck > things up by changing the binding of a global name. You say "muck things up", I say "use mocks for testing". You're right, I shouldn't have said *no* advantages, I should have said "few". (Although I did use the proviso, no advantages to *you* -- this is a personal trade-off each programmer must make.) Inner functions are especially useful in languages like Pascal with compile-time correctness tests (a.k.a. static type checking). Python doesn't have those, so we rely far more on unit tests. My personal trade- off is that with no way to test inner functions, I have to assume that they're buggy. (Aside from those which are simple enough to be obviously correct, as opposed to those that have no obvious bugs.) Inner functions are particularly insidious because they *look* like you can doctest them, but you can't. I once got badly bitten by a program I wrote which used doctests extensively. Every doctest passed, or at least so I thought, and yet the program was *badly* incorrect when I ran it. Eventually I worked out that because the doctests were in inner functions, they weren't being run. My TDD was in vain -- I thought my tests were passing, but they weren't being run at all, and the inner functions were riddled with bugs. So I've always been rather wary of using inner functions since then. > IOW, you use a local function instead of a global one for the exact same > reasons you use local "variables" instead of global ones. Well, I dunno... functions aren't quite like variables. Variables are pretty boring things, they just take a value, whereas functions can be quite complex entities that *do stuff*. Functions ought to be tested. You're also likely to have far fewer functions than variables, and far fewer likely name clashes. You might have a dozen variables called "total" but only one function called "calculate_total". It would be terribly hard to write a program with only global variables, but it is rather easy to write one with only global functions, and some languages don't offer the ability to next functions at all. > In Python, functions are first class objects. Binding a name to a > function is no different than binding it to an integer, list, string, or > dict. Don't the global vs. local cost vs. benefit calculations apply > equally well to function objects as they do to those other sorts of > objects? I've never measured it, but I would expect that, cheap as it is, constructing a new function each time you need to call it would be more expensive than looking up a pre-existing global function. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From brgrt2 at gmail.com Tue Jun 26 01:43:20 2018 From: brgrt2 at gmail.com (T Berger) Date: Mon, 25 Jun 2018 22:43:20 -0700 (PDT) Subject: Proper way to download stylesheets and templates In-Reply-To: <651232b3-b444-4879-888a-73811cae842f@googlegroups.com> References: <651232b3-b444-4879-888a-73811cae842f@googlegroups.com> Message-ID: <04b8f679-ee1a-4663-a465-95c6b0dbfb1a@googlegroups.com> On Monday, June 25, 2018 at 12:12:26 PM UTC-4, T Berger wrote: > I?m creating a webapp and trying to download a stylesheet and templates from my manual?s support site. I must be doing something wrong, because when I try to run my app, I get a 404 error message. I downloaded the files by dragging them off the screen into my webapp folder. But I?m getting a weird extension: ?hf.css.webloc.? Is this the problem? Is there a proper way to download such files? > Thanks, > Tamara I solved my problem. Please ignore the question. Tamar From chris.angelico at 1 Tue Jun 26 02:23:30 2018 From: chris.angelico at 1 (Chris Angelico) Date: Tue, 26 Jun 2018 01:23:30 -0500 Subject: Python for beginners or not? [was Re: syntax difference] Message-ID: <5B324678.21158.uclanpyth@castlerockbbs.com> From: Chris Angelico On Mon, Jun 25, 2018 at 11:15 PM, jkn wrote: > (as well as pedanticism ;-o). Pedantry. ChrisA (You know I can't let that one pass.) --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From cs at cskk.id.au Tue Jun 26 02:50:01 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 26 Jun 2018 16:50:01 +1000 Subject: I'm getting a spamassassin party here In-Reply-To: <201806241703.10658.gheskett@shentel.net> References: <201806241703.10658.gheskett@shentel.net> Message-ID: <20180626065001.GA50767@cskk.homeip.net> On 24Jun2018 17:03, Gene Heskett wrote: >Greetings list; > >Generally spamassassin only gets picky about this occasionally, but for >the past several hours its working overtime on python list messages, >with the major problem being the servers time stamp, a day or more in >the past. Anyboy ever hear of ntpd? >-- Cheers, Gene Heskett Could you eyeball some of these problematic messages please? I've been noticing a swathe of messages in the past few days with From: headers like this: From: "Steven D'Aprano" where the From: has been badly mangled, I think by a usenet->list gateway. The Path: on these messages looks like this (give or take): Path: uni-berlin.de!fu-berlin.de!news.linkpendium.com!news.linkpendium.com!news.snarked.org!news.bbs.nz!.POSTED.184-155-113-241.cpe.cableone.net!not-for-mail I'd be interested to know if there is significant overlap between my problematic messages and yours. Cheers, Cameron Simpson From chris.angelico at 1 Tue Jun 26 04:15:58 2018 From: chris.angelico at 1 (Chris Angelico) Date: Tue, 26 Jun 2018 03:15:58 -0500 Subject: moving to Python from Java/C++/C Message-ID: <5B324678.21178.uclanpyth@castlerockbbs.com> From: Chris Angelico On Tue, Jun 26, 2018 at 2:35 AM, Dan Stromberg wrote: > On Mon, Jun 25, 2018 at 3:40 AM, wrote: > >> Hey, >> I already have quite an experience in programming, and I wish to study >> Python as well. I need to study it before I continue with my comp. science >> academic studies. >> How do you recommend studying it? As mentioned in the headline, I already >> know Java, C++ and C. >> > I recommend https://wiki.python.org/moin/BeginnersGuide/Programmers > > Full disclosure: I wrote the "Intro to Python" slide deck. > > And yes, in 2018, you probably should study Python 3, not Python 2. Yes. I'd upgrade the "probably" to "definitely". ChrisA --- BBBS/Li6 v4.10 Toy-3 * Origin: Prism bbs (1:261/38) From antoon.pardon at vub.be Tue Jun 26 04:20:38 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 26 Jun 2018 10:20:38 +0200 Subject: Quick survey: locals in comprehensions (Python 3 only) In-Reply-To: References: Message-ID: <6858265f-755a-6eb2-0cc6-86157463089e@vub.be> On 24-06-18 07:03, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, since > this is about your EXPECTATIONS, not what Python actually does. > > Given this function: > > > def test(): > a = 1 > b = 2 > result = [value for key, value in locals().items()] > return result > > > > > what would you expect the result of calling test() to be? Is that the > result you think is most useful? In your opinion, is this a useful > feature, a misfeature, a bug, or "whatever"? > > I'm only looking for answers for Python 3. (The results in Python 2 are > genuinely weird :-) I would expect an UnboundLocalError: local variable 'result' referenced before assignment. -- Antoon Pardon. From steve+comp.lang.python at pearwood.info Tue Jun 26 05:22:44 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 26 Jun 2018 09:22:44 +0000 (UTC) Subject: Quick survey: locals in comprehensions (Python 3 only) References: <6858265f-755a-6eb2-0cc6-86157463089e@vub.be> Message-ID: On Tue, 26 Jun 2018 10:20:38 +0200, Antoon Pardon wrote: >> def test(): >> a = 1 >> b = 2 >> result = [value for key, value in locals().items()] >> return result [...] > I would expect an UnboundLocalError: local variable 'result' referenced > before assignment. Well, I did say that there's no right or wrong answers, but that surprises me. Which line do you expect to fail, and why do you think "result" is unbound? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From antoon.pardon at vub.be Tue Jun 26 06:04:16 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 26 Jun 2018 12:04:16 +0200 Subject: Quick survey: locals in comprehensions (Python 3 only) In-Reply-To: References: <6858265f-755a-6eb2-0cc6-86157463089e@vub.be> Message-ID: <38881907-c8e9-ebb0-3885-1295df2f89c8@vub.be> On 26-06-18 11:22, Steven D'Aprano wrote: > On Tue, 26 Jun 2018 10:20:38 +0200, Antoon Pardon wrote: > >>> def test(): >>> a = 1 >>> b = 2 >>> result = [value for key, value in locals().items()] >>> return result > [...] > >> I would expect an UnboundLocalError: local variable 'result' referenced >> before assignment. > Well, I did say that there's no right or wrong answers, but that > surprises me. Which line do you expect to fail, and why do you think > "result" is unbound? I would expect the third statement to fail because IMO we call the locals function before result is bound. But result is a local variable so the locals function will try to reference it, hence the UnboundLocalError. -- Antoon Pardon. From rosuav at gmail.com Tue Jun 26 06:09:59 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Jun 2018 20:09:59 +1000 Subject: Quick survey: locals in comprehensions (Python 3 only) In-Reply-To: <38881907-c8e9-ebb0-3885-1295df2f89c8@vub.be> References: <6858265f-755a-6eb2-0cc6-86157463089e@vub.be> <38881907-c8e9-ebb0-3885-1295df2f89c8@vub.be> Message-ID: On Tue, Jun 26, 2018 at 8:04 PM, Antoon Pardon wrote: > On 26-06-18 11:22, Steven D'Aprano wrote: >> On Tue, 26 Jun 2018 10:20:38 +0200, Antoon Pardon wrote: >> >>>> def test(): >>>> a = 1 >>>> b = 2 >>>> result = [value for key, value in locals().items()] >>>> return result >> [...] >> >>> I would expect an UnboundLocalError: local variable 'result' referenced >>> before assignment. >> Well, I did say that there's no right or wrong answers, but that >> surprises me. Which line do you expect to fail, and why do you think >> "result" is unbound? > > I would expect the third statement to fail because IMO we call the locals > function before result is bound. But result is a local variable so the > locals function will try to reference it, hence the UnboundLocalError. Would you expect the same behaviour from this function? def test(): a = 1 b = 2 result = locals() return result ChrisA From antoon.pardon at vub.be Tue Jun 26 06:22:01 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 26 Jun 2018 12:22:01 +0200 Subject: Quick survey: locals in comprehensions (Python 3 only) In-Reply-To: References: <6858265f-755a-6eb2-0cc6-86157463089e@vub.be> <38881907-c8e9-ebb0-3885-1295df2f89c8@vub.be> Message-ID: <9339f7fc-f439-d75d-fbf8-467e5d625b01@vub.be> On 26-06-18 12:09, Chris Angelico wrote: > On Tue, Jun 26, 2018 at 8:04 PM, Antoon Pardon wrote: >> On 26-06-18 11:22, Steven D'Aprano wrote: >>> On Tue, 26 Jun 2018 10:20:38 +0200, Antoon Pardon wrote: >>> >>>>> def test(): >>>>> a = 1 >>>>> b = 2 >>>>> result = [value for key, value in locals().items()] >>>>> return result >>> [...] >>> >>>> I would expect an UnboundLocalError: local variable 'result' referenced >>>> before assignment. >>> Well, I did say that there's no right or wrong answers, but that >>> surprises me. Which line do you expect to fail, and why do you think >>> "result" is unbound? >> I would expect the third statement to fail because IMO we call the locals >> function before result is bound. But result is a local variable so the >> locals function will try to reference it, hence the UnboundLocalError. > Would you expect the same behaviour from this function? > > def test(): > a = 1 > b = 2 > result = locals() > return result > > ChrisA Yes, but not to the same degree. Somehow I expect this function to produce a dictionary that has "result" as key, yet will raise an error when you try to access the value associated with that key. But in the original "items" is called, so that tries to reference the value immediatly and so I expect an error immediatly. -- Antoon Pardon. From p.f.moore at gmail.com Tue Jun 26 06:27:16 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 26 Jun 2018 11:27:16 +0100 Subject: Quick survey: locals in comprehensions (Python 3 only) In-Reply-To: References: <6858265f-755a-6eb2-0cc6-86157463089e@vub.be> <38881907-c8e9-ebb0-3885-1295df2f89c8@vub.be> Message-ID: On 26 June 2018 at 11:09, Chris Angelico wrote: > On Tue, Jun 26, 2018 at 8:04 PM, Antoon Pardon wrote: >> On 26-06-18 11:22, Steven D'Aprano wrote: >>> On Tue, 26 Jun 2018 10:20:38 +0200, Antoon Pardon wrote: >>> >>>>> def test(): >>>>> a = 1 >>>>> b = 2 >>>>> result = [value for key, value in locals().items()] >>>>> return result >>> [...] >>> >>>> I would expect an UnboundLocalError: local variable 'result' referenced >>>> before assignment. >>> Well, I did say that there's no right or wrong answers, but that >>> surprises me. Which line do you expect to fail, and why do you think >>> "result" is unbound? >> >> I would expect the third statement to fail because IMO we call the locals >> function before result is bound. But result is a local variable so the >> locals function will try to reference it, hence the UnboundLocalError. > > Would you expect the same behaviour from this function? > > def test(): > a = 1 > b = 2 > result = locals() > return result Regardless of the answer to that question, the message here is basically "people don't have good intuition of how locals() works". Or to put it another way, "code that uses locals() is already something you should probably be checking the docs for if you care about the details of what it does". Which agrees with my immediate reaction when I saw the original question :-) Paul From steve+comp.lang.python at pearwood.info Tue Jun 26 06:39:15 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 26 Jun 2018 10:39:15 +0000 (UTC) Subject: Quick survey: locals in comprehensions (Python 3 only) References: <6858265f-755a-6eb2-0cc6-86157463089e@vub.be> <38881907-c8e9-ebb0-3885-1295df2f89c8@vub.be> Message-ID: On Tue, 26 Jun 2018 12:04:16 +0200, Antoon Pardon wrote: > On 26-06-18 11:22, Steven D'Aprano wrote: >> On Tue, 26 Jun 2018 10:20:38 +0200, Antoon Pardon wrote: >> >>>> def test(): >>>> a = 1 >>>> b = 2 >>>> result = [value for key, value in locals().items()] return result >> [...] >> >>> I would expect an UnboundLocalError: local variable 'result' >>> referenced before assignment. >> Well, I did say that there's no right or wrong answers, but that >> surprises me. Which line do you expect to fail, and why do you think >> "result" is unbound? > > I would expect the third statement to fail because IMO we call the > locals function before result is bound. But result is a local variable > so the locals function will try to reference it, hence the > UnboundLocalError. Ah, I see. Thanks for the explanation. Given that locals() is capable of dealing with uninitialised local variables without raising, would you like to revise your expectation? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From antoon.pardon at vub.be Tue Jun 26 06:55:02 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 26 Jun 2018 12:55:02 +0200 Subject: Quick survey: locals in comprehensions (Python 3 only) In-Reply-To: References: <6858265f-755a-6eb2-0cc6-86157463089e@vub.be> <38881907-c8e9-ebb0-3885-1295df2f89c8@vub.be> Message-ID: <5e9ef94d-2930-aa38-4766-d8e2cd0f2aa7@vub.be> On 26-06-18 12:39, Steven D'Aprano wrote: > On Tue, 26 Jun 2018 12:04:16 +0200, Antoon Pardon wrote: > >> On 26-06-18 11:22, Steven D'Aprano wrote: >>> On Tue, 26 Jun 2018 10:20:38 +0200, Antoon Pardon wrote: >>> >>>>> def test(): >>>>> a = 1 >>>>> b = 2 >>>>> result = [value for key, value in locals().items()] return result >>> [...] >>> >>>> I would expect an UnboundLocalError: local variable 'result' >>>> referenced before assignment. >>> Well, I did say that there's no right or wrong answers, but that >>> surprises me. Which line do you expect to fail, and why do you think >>> "result" is unbound? >> I would expect the third statement to fail because IMO we call the >> locals function before result is bound. But result is a local variable >> so the locals function will try to reference it, hence the >> UnboundLocalError. > Ah, I see. Thanks for the explanation. > > Given that locals() is capable of dealing with uninitialised local > variables without raising, would you like to revise your expectation? Sure, I would now expect any |permutation of either a) [1, 2] or b) [1, 2, ||UnboundLocalError|] -- Antoon Pardon. |||| From bc at freeuk.com Tue Jun 26 07:30:05 2018 From: bc at freeuk.com (Bart) Date: Tue, 26 Jun 2018 12:30:05 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> Message-ID: <0tpYC.475685$CH6.73705@fx01.am4> On 19/06/2018 11:33, Steven D'Aprano wrote: > On Tue, 19 Jun 2018 10:19:15 +0100, Bart wrote: > * Integer sets (Pascal-like sets) > > Why do you need them if you have real sets? I tried Python sets for the first time. They seemed workable but rather clunky to set up. But here is one problem on my CPython: x = set(range(10_000_000)) This used up 460MB of RAM (the original 100M I tried exhausted the memory). The advantage of Pascal-style sets is that that same set will occupy only 1.25MB, as it is a bit-map. While sets will not usually be that big, there might be lots of small sets and they all add up. > Assuming that people who aren't you can even get it to compile. When I > tried, it wouldn't compile on my computer. (It won't any more, as there is no C version. I've had it with that language.) -- bart From rosuav at gmail.com Tue Jun 26 07:39:24 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Jun 2018 21:39:24 +1000 Subject: syntax difference In-Reply-To: <0tpYC.475685$CH6.73705@fx01.am4> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <87602ib2hr.fsf@bsb.me.uk> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <0tpYC.475685$CH6.73705@fx01.am4> Message-ID: On Tue, Jun 26, 2018 at 9:30 PM, Bart wrote: > On 19/06/2018 11:33, Steven D'Aprano wrote: >> >> On Tue, 19 Jun 2018 10:19:15 +0100, Bart wrote: > > >> * Integer sets (Pascal-like sets) >> >> Why do you need them if you have real sets? > > > I tried Python sets for the first time. They seemed workable but rather > clunky to set up. But here is one problem on my CPython: > > x = set(range(10_000_000)) > > This used up 460MB of RAM (the original 100M I tried exhausted the memory). > > The advantage of Pascal-style sets is that that same set will occupy only > 1.25MB, as it is a bit-map. > > While sets will not usually be that big, there might be lots of small sets > and they all add up. Cool. Make me a bitset that can represent this Python set: {-5, -4, 6, 10, 1.5, "spam", print} ChrisA From Richard at Damon-Family.org Tue Jun 26 07:44:17 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Tue, 26 Jun 2018 07:44:17 -0400 Subject: I'm getting a spamassassin party here In-Reply-To: <20180626065001.GA50767@cskk.homeip.net> References: <201806241703.10658.gheskett@shentel.net> <20180626065001.GA50767@cskk.homeip.net> Message-ID: On 6/26/18 2:50 AM, Cameron Simpson wrote: > On 24Jun2018 17:03, Gene Heskett wrote: >> Greetings list; >> >> Generally spamassassin only gets picky about this occasionally, but for >> the past several hours its working overtime on python list messages, >> with the major problem being the servers time stamp, a day or more in >> the past. Anyboy ever hear of ntpd? >> -- Cheers, Gene Heskett > > Could you eyeball some of these problematic messages please? > > I've been noticing a swathe of messages in the past few days with > From: headers like this: > > ?From: "Steven D'Aprano" > > where the From: has been badly mangled, I think by a usenet->list > gateway. The Path: on these messages looks like this (give or take): > > ?Path: > uni-berlin.de!fu-berlin.de!news.linkpendium.com!news.linkpendium.com!news.snarked.org!news.bbs.nz!.POSTED.184-155-113-241.cpe.cableone.net!not-for-mail > > I'd be interested to know if there is significant overlap between my > problematic messages and yours. > > Cheers, > Cameron Simpson I am seeing similarly mangled messages, From is mangled, but the original added to the body, References are removed (so they don't thread), a day or two old. It looks like it was relayed to the list by news.bbs.nz -- Richard Damon From bc at freeuk.com Tue Jun 26 08:47:48 2018 From: bc at freeuk.com (Bart) Date: Tue, 26 Jun 2018 13:47:48 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <0tpYC.475685$CH6.73705@fx01.am4> Message-ID: On 26/06/2018 12:39, Chris Angelico wrote: > On Tue, Jun 26, 2018 at 9:30 PM, Bart wrote: >> On 19/06/2018 11:33, Steven D'Aprano wrote: >>> >>> On Tue, 19 Jun 2018 10:19:15 +0100, Bart wrote: >> >> >>> * Integer sets (Pascal-like sets) >>> >>> Why do you need them if you have real sets? >> >> >> I tried Python sets for the first time. They seemed workable but rather >> clunky to set up. But here is one problem on my CPython: >> >> x = set(range(10_000_000)) >> >> This used up 460MB of RAM (the original 100M I tried exhausted the memory). >> >> The advantage of Pascal-style sets is that that same set will occupy only >> 1.25MB, as it is a bit-map. >> >> While sets will not usually be that big, there might be lots of small sets >> and they all add up. > > Cool. Make me a bitset that can represent this Python set: > > {-5, -4, 6, 10, 1.5, "spam", print} Why? It's a set of integer values with a huge range of applications. Here's the set of characters allowed in a C identifier (not using Python syntax): cident = {'A'..'Z', 'a'..'z', '0'..'9', '_', '9'} The characters allowed in a hex constant: {'0'..'9', 'A'..'F', 'a'..'f'} A set representing every Unicode character, except those which can be C identifiers: {0..1_114_111} - cident The latter taking only 136KB rather than 64MB as it seemed to. I don't know whether there is a direct equivalent in Python (I thought somebody would point it out), apart from ways to construct similar functionality with bit-arrays (but then, every language can have such sets if you take the DIY approach). Steven asked why I need them when there are 'real' sets, and I answered that. -- bart From antoon.pardon at vub.be Tue Jun 26 09:48:00 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 26 Jun 2018 15:48:00 +0200 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <0tpYC.475685$CH6.73705@fx01.am4> Message-ID: On 26-06-18 14:47, Bart wrote: > > [About bitsets] > > Here's the set of characters allowed in a C identifier (not using > Python syntax): > > ? cident = {'A'..'Z', 'a'..'z', '0'..'9', '_', '9'} > > The characters allowed in a hex constant: > > ? {'0'..'9', 'A'..'F', 'a'..'f'} > > A set representing every Unicode character, except those which can be > C identifiers: > > ? {0..1_114_111} - cident > > The latter taking only 136KB rather than 64MB as it seemed to. > > I don't know whether there is a direct equivalent in Python (I thought > somebody would point it out), apart from ways to construct similar > functionality with bit-arrays (but then, every language can have such > sets if you take the DIY approach). Well that is technically correct but not the whole story. Few languages allow you to blend in your DIY approach, so that from a users perspective it makes little difference whether the datatype was provided by the language or the result of a DIY approach. So if you want your bitsets, it isn't hard to provide them and you can use them like ordinary python sets. I think that is a big positive point for a language. -- Antoon Pardon From gheskett at shentel.net Tue Jun 26 09:50:24 2018 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 26 Jun 2018 09:50:24 -0400 Subject: I'm getting a spamassassin party here In-Reply-To: <20180626065001.GA50767@cskk.homeip.net> References: <201806241703.10658.gheskett@shentel.net> <20180626065001.GA50767@cskk.homeip.net> Message-ID: <201806260950.24468.gheskett@shentel.net> On Tuesday 26 June 2018 02:50:01 Cameron Simpson wrote: > On 24Jun2018 17:03, Gene Heskett wrote: > >Greetings list; > > > >Generally spamassassin only gets picky about this occasionally, but > > for the past several hours its working overtime on python list > > messages, with the major problem being the servers time stamp, a day > > or more in the past. Anyboy ever hear of ntpd? > >-- Cheers, Gene Heskett > > Could you eyeball some of these problematic messages please? > > I've been noticing a swathe of messages in the past few days with > From: headers like this: > > From: "Steven D'Aprano" > > where the From: has been badly mangled, I think by a usenet->list > gateway. The Path: on these messages looks like this (give or take): > > Path: > uni-berlin.de!fu-berlin.de!news.linkpendium.com!news.linkpendium.com!n >ews.snarked.org!news.bbs.nz!.POSTED.184-155-113-241.cpe.cableone.net!no >t-for-mail > > I'd be interested to know if there is significant overlap between my > problematic messages and yours. > > Cheers, > Cameron Simpson Stevens messages are among the most frequent spamassassin triggers. The scoring diff that tips the scales is the time error: 1.0 DATE_IN_PAST_12_24 Date: is 12 to 24 hours before Received: date There is also this: 0.5 APOSTROPHE_FROM From address contains an apostrophe This list commits a whole menu of errors that spamassassin doesn't like. The whole list from a different message: Content analysis details: (5.6 points, 5.1 required) pts rule name description ---- ---------------------- -------------------------------------------------- 3.5 BAYES_99 BODY: Bayes spam probability is 99 to 100% [score: 1.0000] 0.0 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 1.0 DATE_IN_PAST_12_24 Date: is 12 to 24 hours before Received: date 0.2 BAYES_999 BODY: Bayes spam probability is 99.9 to 100% [score: 1.0000] 0.8 RDNS_NONE Delivered to internal network by a host with no rDNS 0.0 T_DKIM_INVALID DKIM-Signature header exists but is not valid Some of these should be fixable by proper configuration of the listserver, but don't confuse me with an expert. I am subscribed to the list. -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From chema at rinzewind.org Tue Jun 26 13:17:59 2018 From: chema at rinzewind.org (=?utf-8?Q?Jos=C3=A9=20Mar=C3=ADa=20Mateos?=) Date: Tue, 26 Jun 2018 13:17:59 -0400 Subject: Where's the junk coming from? In-Reply-To: References: Message-ID: <1530033479.3806447.1421162896.52E504CD@webmail.messagingengine.com> On Mon, Jun 25, 2018, at 13:37, Mark Lawrence wrote: > More of the flaming things, this time name at 1261/38.remove-ij1-this. Any > ideas as I don't understand this stuff? I've contacted the list admin about this. It doesn't seem like it's going to go away on its own. I just received another batch, for what it's worth. Cheers, -- Jos? Mar?a (Chema) Mateos https://rinzewind.org/blog-es || https://rinzewind.org/blog-en From vincent.vande.vyvre at telenet.be Tue Jun 26 13:55:45 2018 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Tue, 26 Jun 2018 19:55:45 +0200 Subject: I'm getting a spamassassin party here In-Reply-To: <201806260950.24468.gheskett@shentel.net> References: <201806241703.10658.gheskett@shentel.net> <20180626065001.GA50767@cskk.homeip.net> <201806260950.24468.gheskett@shentel.net> Message-ID: <445fdbb3-ed71-90f6-d8af-34ac3407ca1e@telenet.be> Le 26/06/18 ? 15:50, Gene Heskett a ?crit?: > On Tuesday 26 June 2018 02:50:01 Cameron Simpson wrote: > >> On 24Jun2018 17:03, Gene Heskett wrote: >>> Greetings list; >>> >>> Generally spamassassin only gets picky about this occasionally, but >>> for the past several hours its working overtime on python list >>> messages, with the major problem being the servers time stamp, a day >>> or more in the past. Anyboy ever hear of ntpd? >>> -- Cheers, Gene Heskett >> Could you eyeball some of these problematic messages please? >> >> I've been noticing a swathe of messages in the past few days with >> From: headers like this: >> >> From: "Steven D'Aprano" >> >> where the From: has been badly mangled, I think by a usenet->list >> gateway. The Path: on these messages looks like this (give or take): >> >> Path: >> uni-berlin.de!fu-berlin.de!news.linkpendium.com!news.linkpendium.com!n >> ews.snarked.org!news.bbs.nz!.POSTED.184-155-113-241.cpe.cableone.net!no >> t-for-mail >> >> I'd be interested to know if there is significant overlap between my >> problematic messages and yours. >> >> Cheers, >> Cameron Simpson > Stevens messages are among the most frequent spamassassin triggers. The > scoring diff that tips the scales is the time error: > 1.0 DATE_IN_PAST_12_24 Date: is 12 to 24 hours before Received: date > > There is also this: > 0.5 APOSTROPHE_FROM From address contains an apostrophe > > This list commits a whole menu of errors that spamassassin doesn't like. > > The whole list from a different message: > > Content analysis details: (5.6 points, 5.1 required) > > pts rule name description > ---- ---------------------- -------------------------------------------------- > 3.5 BAYES_99 BODY: Bayes spam probability is 99 to 100% > [score: 1.0000] > 0.0 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail > domains are different > 1.0 DATE_IN_PAST_12_24 Date: is 12 to 24 hours before Received: date > 0.2 BAYES_999 BODY: Bayes spam probability is 99.9 to 100% > [score: 1.0000] > 0.8 RDNS_NONE Delivered to internal network by a host with > no rDNS > 0.0 T_DKIM_INVALID DKIM-Signature header exists but is not valid > > Some of these should be fixable by proper configuration of the > listserver, but don't confuse me with an expert. I am subscribed to the > list. > Same for me since yesterday. Two examples: The 2018-05-18 17:20 ------------------------------- From: "Peter J. Holzer" --prnws536gtytpj5v [ following the message ] -------------------------------- Same day, same hour but arrived today -------------------------------- From: "Peter J. Holzer" From: "Peter J. Holzer" --prnws536gtytpj5v [ following the same message ] -------------------------------- Or again: The 2018-06-23 18:46 -------------------------------- From: Steven D'Aprano On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote: [ following the message ] -------------------------------- Same day, same hour but arrived today -------------------------------- From: "Steven D'Aprano" From: Steven D'Aprano On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote: [ following the same message ] -------------------------------- I've re-received 22 old duplicated messages like this today. Vincent Send Tue, 26 Jun 2018 19:53:46 +0200 From breamoreboy at gmail.com Tue Jun 26 15:02:40 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Tue, 26 Jun 2018 20:02:40 +0100 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <0tpYC.475685$CH6.73705@fx01.am4> Message-ID: On 26/06/18 12:39, Chris Angelico wrote: > On Tue, Jun 26, 2018 at 9:30 PM, Bart wrote: >> On 19/06/2018 11:33, Steven D'Aprano wrote: >>> >>> On Tue, 19 Jun 2018 10:19:15 +0100, Bart wrote: >> >> >>> * Integer sets (Pascal-like sets) >>> >>> Why do you need them if you have real sets? >> >> >> I tried Python sets for the first time. They seemed workable but rather >> clunky to set up. But here is one problem on my CPython: >> >> x = set(range(10_000_000)) >> >> This used up 460MB of RAM (the original 100M I tried exhausted the memory). >> >> The advantage of Pascal-style sets is that that same set will occupy only >> 1.25MB, as it is a bit-map. >> >> While sets will not usually be that big, there might be lots of small sets >> and they all add up. > > Cool. Make me a bitset that can represent this Python set: > > {-5, -4, 6, 10, 1.5, "spam", print} > > ChrisA > Please stop feeding this troll, it's getting very tedious. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ingy at ingy.net Tue Jun 26 18:24:03 2018 From: ingy at ingy.net (Ingy dot Net) Date: Tue, 26 Jun 2018 16:24:03 -0600 Subject: [ANN] PyYAML-4.1: YAML parser and emitter for Python Message-ID: ======================= Announcing PyYAML-4.1 ======================= A new MAJOR RELEASE of PyYAML is now available: https://pypi.org/project/PyYAML/ This is the first release of PyYAML under a new maintenance team. In August 2016, maintenance of PyYAML and LibYAML was turned over from the original author, Kirill Simonov, to Ian Cordasco and Ingy d?t Net. The canonical source repo moved: from: https://bitbucket.org/xi/pyyaml/ to: https://github.com/yaml/pyyaml The PyYAML project is now maintained by the YAML and Python communities. Planning happens on the #yaml-dev, #pyyaml and #libyaml IRC channels on irc.freenode.net. Changes ======= * https://github.com/yaml/pyyaml/pull/35 -- Some modernization of the test running * https://github.com/yaml/pyyaml/pull/42 -- Install tox in a virtualenv * https://github.com/yaml/pyyaml/pull/45 -- Allow colon in a plain scalar in a flow context * https://github.com/yaml/pyyaml/pull/48 -- Fix typos * https://github.com/yaml/pyyaml/pull/55 -- Improve RepresenterError creation * https://github.com/yaml/pyyaml/pull/59 -- Resolves #57, update readme issues link * https://github.com/yaml/pyyaml/pull/60 -- Document and test Python 3.6 support * https://github.com/yaml/pyyaml/pull/61 -- Use Travis CI built in pip cache support * https://github.com/yaml/pyyaml/pull/62 -- Remove tox workaround for Travis CI * https://github.com/yaml/pyyaml/pull/63 -- Adding support to Unicode characters over codepoint 0xffff * https://github.com/yaml/pyyaml/pull/65 -- Support unicode literals over codepoint 0xffff * https://github.com/yaml/pyyaml/pull/74 -- Make pyyaml safe by default. * https://github.com/yaml/pyyaml/pull/75 -- add 3.12 changelog * https://github.com/yaml/pyyaml/pull/76 -- Fallback to Pure Python if Compilation fails * https://github.com/yaml/pyyaml/pull/84 -- Drop unsupported Python 3.3 * https://github.com/yaml/pyyaml/pull/111 -- Remove commented out Psyco code * https://github.com/yaml/pyyaml/pull/149 -- Test on Python 3.7-dev * https://github.com/yaml/pyyaml/pull/158 -- Support escaped slash in double quotes "\/" Resources ========= PyYAML IRC Channel: #pyyaml on irc.freenode.net PyYAML homepage: https://github.com/yaml/pyyaml PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation Source and binary installers: https://pypi.org/project/PyYAML/ GitHub repository: https://github.com/yaml/pyyaml/ Bug tracking: https://github.com/yaml/pyyaml/issues YAML homepage: http://yaml.org/ YAML-core mailing list: http://lists.sourceforge.net/lists/listinfo/yaml-core About PyYAML ============ YAML is a data serialization format designed for human readability and interaction with scripting languages. PyYAML is a YAML parser and emitter for Python. PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object. PyYAML is applicable for a broad range of tasks from complex configuration files to object serialization and persistence. Example ======= >>> import yaml >>> yaml.load(""" ... name: PyYAML ... description: YAML parser and emitter for Python ... homepage: https://github.com/yaml/pyyaml ... keywords: [YAML, serialization, configuration, persistence, pickle] ... """) {'keywords': ['YAML', 'serialization', 'configuration', 'persistence', 'pickle'], 'homepage': 'https://github.com/yaml/pyyaml', 'description': 'YAML parser and emitter for Python', 'name': 'PyYAML'} >>> print yaml.dump(_) name: PyYAML homepage: https://github.com/yaml/pyyaml description: YAML parser and emitter for Python keywords: [YAML, serialization, configuration, persistence, pickle] Maintainers =========== The following people are responsible for maintaining PyYAML: * Ingy d?t Net * Ian Cordasco * Tina Mueller * Alex Gaynor * Donald Stufft * Matt Davis and many thanks to all who have contribributed! See: https://github.com/yaml/pyyaml/pulls Copyright ========= Copyright (c) 2017-2018 Ingy d?t Net Copyright (c) 2006-2016 Kirill Simonov The PyYAML module was written by Kirill Simonov . It is currently maintained by the YAML and Python communities. PyYAML is released under the MIT license. See the file LICENSE for more details. From cs at cskk.id.au Tue Jun 26 18:55:36 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 27 Jun 2018 08:55:36 +1000 Subject: I'm getting a spamassassin party here In-Reply-To: References: Message-ID: <20180626225536.GA40277@cskk.homeip.net> On 26Jun2018 07:44, Richard Damon wrote: >On 6/26/18 2:50 AM, Cameron Simpson wrote: >> On 24Jun2018 17:03, Gene Heskett wrote: >>> Generally spamassassin only gets picky about this occasionally, but for >>> the past several hours its working overtime on python list messages, >>> with the major problem being the servers time stamp, a day or more in >>> the past. Anyboy ever hear of ntpd? >>> -- Cheers, Gene Heskett >> >> Could you eyeball some of these problematic messages please? >> >> I've been noticing a swathe of messages in the past few days with >> From: headers like this: >> >> ?From: "Steven D'Aprano" >> >> where the From: has been badly mangled, I think by a usenet->list >> gateway. The Path: on these messages looks like this (give or take): >> >> ?Path: >> uni-berlin.de!fu-berlin.de!news.linkpendium.com!news.linkpendium.com!news.snarked.org!news.bbs.nz!.POSTED.184-155-113-241.cpe.cableone.net!not-for-mail >> >> I'd be interested to know if there is significant overlap between my >> problematic messages and yours. >> >> Cheers, >> Cameron Simpson > >I am seeing similarly mangled messages, From is mangled, but the >original added to the body, References are removed (so they don't >thread), a day or two old. > >It looks like it was relayed to the list by news.bbs.nz On closer inspection it looks like a FIDONET gateway may be the cause. I've made enquiries of abuse at news.bbs.nz and newsmaster at news.bbs.nz, and am awaiting a response. Cheers, Cameron Simpson From cs at cskk.id.au Tue Jun 26 19:00:13 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 27 Jun 2018 09:00:13 +1000 Subject: Where's the junk coming from? In-Reply-To: References: Message-ID: <20180626230013.GA54692@cskk.homeip.net> On 25Jun2018 18:37, Mark Lawrence wrote: >More of the flaming things, this time name at 1261/38.remove-ij1-this. Any ideas >as I don't understand this stuff? Looks like a FIDONET gateway leaking somehow. I've made an enquiry to a possible source for the message, we'll see what transpires. Cheers, Cameron Simpson From greg.ewing at canterbury.ac.nz Tue Jun 26 19:00:48 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 27 Jun 2018 11:00:48 +1200 Subject: I'm getting a spamassassin party here In-Reply-To: References: <201806241703.10658.gheskett@shentel.net> <20180626065001.GA50767@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > I've been noticing a swathe of messages in the past few days with From: > headers like this: > > From: "Steven D'Aprano" In comp.lang.python I'm seeing repeats of messages that were posted 2 or 3 days ago, with these mangled addresses. -- Greg From cs at cskk.id.au Tue Jun 26 19:10:13 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 27 Jun 2018 09:10:13 +1000 Subject: I'm getting a spamassassin party here In-Reply-To: <20180626225536.GA40277@cskk.homeip.net> References: <20180626225536.GA40277@cskk.homeip.net> Message-ID: <20180626231013.GA84230@cskk.homeip.net> On 27Jun2018 08:55, Cameron Simpson wrote: >On closer inspection it looks like a FIDONET gateway may be the cause. > >I've made enquiries of abuse at news.bbs.nz and newsmaster at news.bbs.nz, and am >awaiting a response. I've also asked at Castle Rock BBS, based on a different header. Cheers, Cameron Simpson From greg.ewing at canterbury.ac.nz Tue Jun 26 19:11:37 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 27 Jun 2018 11:11:37 +1200 Subject: syntax difference In-Reply-To: <0tpYC.475685$CH6.73705@fx01.am4> References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <28481924-5892-4b9a-be1f-3826b6dad73a@googlegroups.com> <955b6b47-7b8c-1da6-aa7e-25569b36ffa8@gmail.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <0tpYC.475685$CH6.73705@fx01.am4> Message-ID: Bart wrote: > x = set(range(10_000_000)) > > This used up 460MB of RAM (the original 100M I tried exhausted the memory). > > The advantage of Pascal-style sets is that that same set will occupy > only 1.25MB, as it is a bit-map. That's true, but they're also extremely limited compared to the things you can do with Python sets. They're really two quite different things, designed for different use cases. Compact sets of integers are possible in Python, but not as a built-in type. This suggests that they're not needed much -- if they were used a lot, they would have become part of the stdlib by now. -- Greg From greg.ewing at canterbury.ac.nz Tue Jun 26 19:18:37 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 27 Jun 2018 11:18:37 +1200 Subject: syntax difference In-Reply-To: References: <72edc16a-69e0-41a2-bec3-290083f6e6ec@googlegroups.com> <01092eb6-172f-5ee0-91fb-4e3e1df99707@gmail.com> <6eUVC.491716$Qg7.378011@fx08.am4> <0tpYC.475685$CH6.73705@fx01.am4> Message-ID: Bart wrote: > I don't know whether there is a direct equivalent in Python (I thought > somebody would point it out) Not built-in, but a tiny bit of googling turns this up: https://pypi.org/project/bitarray/ "This module provides an object type which efficiently represents an array of booleans. Bitarrays are sequence types and behave very much like usual lists. Eight bits are represented by one byte in a contiguous block of memory." -- Greg From sharan.basappa at gmail.com Tue Jun 26 23:26:34 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Tue, 26 Jun 2018 20:26:34 -0700 (PDT) Subject: sigmoid function and derivative Message-ID: <259363ad-4433-449c-9c0b-943a38ecefab@googlegroups.com> Folks, I know this is not a machine learning forum but I wanted to see if anyone can explain this to me. In artificial neural network, I can understand why sigmoid is used but I see that derivative of sigmoid output function is used. I am not able to understand why. For example: # convert output of sigmoid function to its derivative def sigmoid_output_to_derivative(output): return output*(1-output) From tjreedy at udel.edu Wed Jun 27 01:40:00 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Jun 2018 01:40:00 -0400 Subject: sigmoid function and derivative In-Reply-To: <259363ad-4433-449c-9c0b-943a38ecefab@googlegroups.com> References: <259363ad-4433-449c-9c0b-943a38ecefab@googlegroups.com> Message-ID: On 6/26/2018 11:26 PM, Sharan Basappa wrote: > Folks, > > I know this is not a machine learning forum but I wanted to see if anyone can explain this to me. > > In artificial neural network, I can understand why sigmoid is used but I see that derivative of sigmoid output function is used. I am not able to understand why. > > For example: > # convert output of sigmoid function to its derivative > def sigmoid_output_to_derivative(output): > return output*(1-output) Derivatives are used for backpropagation* of errors for adjusting weights. The convenient form of sigmoid derivative is a reason to use sigmoids as transfer functions. * You can look backpropagation as a method of training. -- Terry Jan Reedy From kikerocamora16 at gmail.com Wed Jun 27 04:45:49 2018 From: kikerocamora16 at gmail.com (Kike Rocamora) Date: Wed, 27 Jun 2018 10:45:49 +0200 Subject: thank you for inventing python Message-ID: <5b334ebf.1c69fb81.230ee.3eb0@mx.google.com> Enviado desde Correo para Windows 10 From h.goebel at crazy-compilers.com Wed Jun 27 04:46:22 2018 From: h.goebel at crazy-compilers.com (Hartmut Goebel) Date: Wed, 27 Jun 2018 10:46:22 +0200 Subject: [ANN] managesieve 0.6 Message-ID: I'm pleased to announce managesieve 0.6, a ManageSieve client library for remotely managing Sieve scripts, including an user application (the interactive 'sieveshell'). :Homepage: https://managesieve.readthedocs.io/ Development: https://gitlab.com/htgoebel/managesieve :Author:?? Hartmut Goebel :License for `managesieve`: Python Software Foundation License :License for 'sieveshell' and test suite: GNU Public Licence v3 (GPLv3) :Quick Installation: ??? pip install -U managesieve :Tarballs:? https://pypi.org/project/managesieve/#files What is managesieve? --------------------- A ManageSieve client library for remotely managing Sieve scripts, including an user application (the interactive 'sieveshell'). Sieve scripts allow users to filter incoming email on the mail server. The ManageSieve protocol allows managing Sieve scripts on a remote mail server. These servers are commonly sealed so users cannot log into them, yet users must be able to update their scripts on them. This is what for the "ManageSieve" protocol is. For more information about the ManageSieve protocol see `RFC 5804 `_. This module allows accessing a Sieve-Server for managing Sieve scripts there. It is accompanied by a simple yet functional user application 'sieveshell'. What's new in version 0.6 --------------------------------------- * Add support for Python 3. Minimum required Python version is now ? Python 2.7. * Homepage is now hosted at https://managesieve.readthedocs.io/ * Development hosted at https://gitlab.com/htgoebel/managesieve * Documentation is extended and includes API documentation. :sieveshell: ?? - Security fix: No longer leak environment variable SIEVE_PASSWORD ???? when displaying usage help. ?? - Per default enforce secure transport. Suggested by Jan Zerebecki. ?? - Add possibility to use username/password from the .netrc file. ???? The order is: command line options -> environment variables -> ???? .netrc file -> ask user. Thanks to Gr?goire D?trez. :managesieve: ?? - Fail if TLS is requested, but server doesn't support TLS. ???? Suggested by Jan Zerebecki. :project: ?? - Rework and enhance test-suite. Thanks to Mat?j Cepl for nudging ???? to proper pytest integration. ?? - Lots if internal cleanup. -- Regards Hartmut Goebel | Hartmut Goebel | h.goebel at crazy-compilers.com | | www.crazy-compilers.com | compilers which you thought are impossible | From Avon at f101.n1.z21.fsxnet Wed Jun 27 05:43:12 2018 From: Avon at f101.n1.z21.fsxnet (Avon) Date: Wed, 27 Jun 2018 21:43:12 +1200 Subject: Where's the junk coming from? References: Message-ID: <74676406@f101.n1.z21.fsxnet> On 06/27/18, Cameron Simpson pondered and said... CS> On 25Jun2018 18:37, Mark Lawrence wrote: CS> >More of the flaming things, this time name at 1261/38.remove-ij1-this. Any CS> >as I don't understand this stuff? CS> CS> Looks like a FIDONET gateway leaking somehow. I've made an enquiry to a CS> possible source for the message, we'll see what transpires. CS> CS> Cheers, CS> Cameron Simpson Hey Cameron, Apologies for this. I have contacted the Fido system connected to the gateway I run into news.bbs.nz and have asked them to urgently sort / check what's up. If I don't get any joy from them within the next 24 hours I will delink them so as to negate further probs. My hunch is a BBS (yes they still exist :)) is taking a gated feed of this newsgroup and is linked to more than one gateway so stuff is looping... not good. Stand by caller... we're working on this now. Best, Paul newsmaster [at] news dot bbs dot nz From hjp-python at hjp.at Wed Jun 27 07:42:15 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 27 Jun 2018 13:42:15 +0200 Subject: syntax difference In-Reply-To: References: <6eUVC.491716$Qg7.378011@fx08.am4> <0tpYC.475685$CH6.73705@fx01.am4> Message-ID: <20180627114215.bwhbkbksr4hnygaw@hjp.at> On 2018-06-27 11:11:37 +1200, Gregory Ewing wrote: > Bart wrote: > > x = set(range(10_000_000)) > > > > This used up 460MB of RAM (the original 100M I tried exhausted the memory). > > > > The advantage of Pascal-style sets is that that same set will occupy > > only 1.25MB, as it is a bit-map. > > That's true, but they're also extremely limited compared to > the things you can do with Python sets. They're really two > quite different things, designed for different use cases. > > Compact sets of integers are possible in Python, but not > as a built-in type. This suggests that they're not needed > much Also, when such sets are needed, a simple array of bits may not be sufficient. For example, sets may be sparse, or they may have almost all except a few bits set. In these cases a tree or RLE representation is much smaller and faster. There are a number of such implementations (Judy Arrays and Roaring Bitmaps come to mind[1]). Each has its advantages and limitations, so its probably better to leave the choice to the author. hp [1] Judy is a C library. Roaring bitmaps are a data structure which has been implemented in several languages. I haven't checked whether there are packages on pypi. Shouldn't be too hard to implement if one needs it. -- _ | 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 bc at freeuk.com Wed Jun 27 08:42:13 2018 From: bc at freeuk.com (Bart) Date: Wed, 27 Jun 2018 13:42:13 +0100 Subject: syntax difference In-Reply-To: References: <6eUVC.491716$Qg7.378011@fx08.am4> <0tpYC.475685$CH6.73705@fx01.am4> <20180627114215.bwhbkbksr4hnygaw@hjp.at> Message-ID: On 27/06/2018 12:42, Peter J. Holzer wrote: > On 2018-06-27 11:11:37 +1200, Gregory Ewing wrote: >> Bart wrote: >>> x = set(range(10_000_000)) >>> >>> This used up 460MB of RAM (the original 100M I tried exhausted the memory). >>> >>> The advantage of Pascal-style sets is that that same set will occupy >>> only 1.25MB, as it is a bit-map. >> >> That's true, but they're also extremely limited compared to >> the things you can do with Python sets. They're really two >> quite different things, designed for different use cases. >> >> Compact sets of integers are possible in Python, but not >> as a built-in type. This suggests that they're not needed >> much > > Also, when such sets are needed, a simple array of bits may not be > sufficient. For example, sets may be sparse, or they may have almost all > except a few bits set. In these cases a tree or RLE representation is > much smaller and faster. There are a number of such implementations > (Judy Arrays and Roaring Bitmaps come to mind[1]). Each has its > advantages and limitations, so its probably better to leave the choice > to the author. From roaringbitmap.org: "Bitsets, also called bitmaps, are commonly used as fast data structures. Unfortunately, they can use too much memory. To compensate, we often use compressed bitmaps." So from one extreme to another: from the 300-400 bits per element used by Python's set type, to some presumably tiny fraction of a bit [on average] used in this scheme, as 1 bit per element is too much. Is there no place at all for an ordinary, straightforward, uncompressed bit-set where each element takes exactly one bit? It does seem as though Python users have an aversion to simplicity and efficiency. FWIW when I was working with actual image bitmaps, they were nearly always uncompressed when in memory. 1-bit-per-pixel images, for mono images or masks, would pack 8 pixels per byte. Compression would only be used for storage or transmission. And the same with all the set types I've used. However there is a slight difference with the concept of a 'set' as I used it, and as it was used in Pascal, compared with Python's set: there was the notion of the overall size of the set: the total number of elements, whether each was '1' or '0'. So a set type that represented all ASCII codes would have a size of 128 elements, indexed 0 to 127. So such a set initialised to ['A'..'Z'] and then inverted would give the set [0..64,91..127]. -- bart From thatebart at gmail.com Wed Jun 27 09:20:23 2018 From: thatebart at gmail.com (Bart Thate) Date: Wed, 27 Jun 2018 06:20:23 -0700 (PDT) Subject: ANN: OB - framework to program bots Message-ID: <3e618a82-bbaa-41c5-9d0f-23219b1cea49@googlegroups.com> Hello comp.lang.python, I am Bart Thate, a 50 year old programming schizofrenic. I like to annouce version 4 of OB, a pure python3 package you can use to program bots. OB has a ?no-clause MIT license? that should be the most liberal license you can get at the year 2018. I am looking for feedback on my new bot. https://pypi.org/project/ob/ http://ob.readthedocs.io/en/latest/ thnx ! Bart - bthate at dds.nl From neilc at norwich.edu Wed Jun 27 10:30:46 2018 From: neilc at norwich.edu (Neil Cerutti) Date: Wed, 27 Jun 2018 14:30:46 +0000 (UTC) Subject: Python for beginners or not? [was Re: syntax difference] References: <5B324678.21143.uclanpyth@castlerockbbs.com> <5B324678.21144.uclanpyth@castlerockbbs.com> Message-ID: On 2018-06-25, Alister wrote: > for i in range(len(list)): is a python anti-pattern it is almost a 100% > guarantee that you are doing something wrong* > > *as with all rules of thumb there is probably at least 1 > exception that the python experts will now point out. When you need look-ahead or similar inspection of more than the current item. An alternative is a custom generator or iterator that provides the window you need. -- Neil Cerutti From ethan at stoneleaf.us Wed Jun 27 10:48:53 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 27 Jun 2018 07:48:53 -0700 Subject: Should nested classes in an Enum be Enum members? Message-ID: <5B33A3D5.7060208@stoneleaf.us> [Note: there is a similar thread on Python-Ideas, if you would like to respond there.] Consider the following Enum definition: class Color(Enum): RED = 1 GREEN = 2 BLUE = 3 @property def lower(self): return self.name.lower() def spam(self): return "I like %s eggs and spam!" % self.lower class SomeClass: pass Which of the above Color attributes are enums, and which aren't? . . . Answer: - RED, GREEN, and BLUE are members - lower and spam() are not - SomeClass /is/ a member (but not its instances) Question: Should `SomeClass` be an enum member? When would it be useful to have an embedded class in an Enum be an enum member? The only example I have seen so far of nested classes in an Enum is when folks want to make an Enum of Enums, and the nested Enum should not itself be an enum member. Since the counter-example already works I haven't seen any requests for it. ;) So I'm asking the community: What real-world examples can you offer for either behavior? Cases where nested classes should be enum members, and cases where nested classes should not be members. Thanks! -- ~Ethan~ From arj.python at gmail.com Wed Jun 27 11:08:10 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Wed, 27 Jun 2018 19:08:10 +0400 Subject: configparser v/s file variables Message-ID: what is more recommended and why? using configparser for settings or import variables from file? thanks, Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ From grant.b.edwards at gmail.com Wed Jun 27 11:14:38 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 27 Jun 2018 15:14:38 +0000 (UTC) Subject: configparser v/s file variables References: Message-ID: On 2018-06-27, Abdur-Rahmaan Janhangeer wrote: > what is more recommended and why? using configparser for settings or import > variables from file? Importing variables from a file is dangerous because it can execute arbitrary code. It should never be done with files provided by the user. Using configparser is far, far safer. -- Grant Edwards grant.b.edwards Yow! Psychoanalysis?? at I thought this was a nude gmail.com rap session!!! From brgrt2 at gmail.com Wed Jun 27 11:49:01 2018 From: brgrt2 at gmail.com (T Berger) Date: Wed, 27 Jun 2018 08:49:01 -0700 (PDT) Subject: OSError: [Errno 48] Address already in use Message-ID: Why am I getting this error? I'm not sure what additional information I need to supply, so please let me know. From brgrt2 at gmail.com Wed Jun 27 11:52:53 2018 From: brgrt2 at gmail.com (T Berger) Date: Wed, 27 Jun 2018 08:52:53 -0700 (PDT) Subject: OSError: [Errno 48] Address already in use In-Reply-To: References: Message-ID: <3cbff734-f61a-4208-8df0-39e4041dc3aa@googlegroups.com> On Wednesday, June 27, 2018 at 11:49:18 AM UTC-4, T Berger wrote: > Why am I getting this error? I'm not sure what additional information I need to supply, so please let me know. I'm working on a Flask webapp. I know there is another google group specifically for Flask. Can you please provide the url. Thanks From joaquin.henriquez at countercept.com Wed Jun 27 12:15:42 2018 From: joaquin.henriquez at countercept.com (Joaquin Henriquez) Date: Wed, 27 Jun 2018 16:15:42 +0000 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: Message-ID: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> >Subject: EXTERNAL: OSError: [Errno 48] Address already in use The best way to help if got you to put the relevant code here. The error you are experiencing means that the Port you are trying to bind is already taken by another running process. From brgrt2 at gmail.com Wed Jun 27 12:54:40 2018 From: brgrt2 at gmail.com (T Berger) Date: Wed, 27 Jun 2018 09:54:40 -0700 (PDT) Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> Message-ID: <984a776d-f22e-4812-9cf4-ef6403b710ca@googlegroups.com> On Wednesday, June 27, 2018 at 12:17:28 PM UTC-4, Joaquin Henriquez wrote: > >Subject: EXTERNAL: OSError: [Errno 48] Address already in use > > The best way to help if got you to put the relevant code here. Last login: Wed Jun 27 12:45:08 on ttys000 192:~ TamaraB$ cd Desktop/Webapp/ 192:Webapp TamaraB$ python3 vsearch4web.py * Serving Flask app "vsearch4web" (lazy loading) * Environment: production WARNING: Do not use the development server in a production environment. Use a production WSGI server instead. * Debug mode: on Traceback (most recent call last): File "vsearch4web.py", line 18, in app.run(debug=True) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 943, in run run_simple(host, port, self, **options) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/werkzeug/serving.py", line 795, in run_simple s.bind(get_sockaddr(hostname, port, address_family)) OSError: [Errno 48] Address already in use 192:Webapp TamaraB$ > The error you are experiencing means that the Port you are trying to bind is already taken by another running process. Why would another process be running? Thanks, Tamara From jlee54 at gmail.com Wed Jun 27 13:12:36 2018 From: jlee54 at gmail.com (Jim Lee) Date: Wed, 27 Jun 2018 10:12:36 -0700 Subject: OSError: [Errno 48] Address already in use In-Reply-To: References: Message-ID: On 06/27/18 08:49, T Berger wrote: > Why am I getting this error? I'm not sure what additional information I need to supply, so please let me know. You asked this question two weeks ago and got several answers.? Here is one of them: On 06/15/18 10:17, Percival John Hackworth wrote: On 15-Jun-2018, T Berger wrote (in article<3fe6b3e1-f582-415b-ace1-b104f42efef9 at googlegroups.com>): > I?m trying to build a webapp with flask. I installed flask, created a > webapp in IDLE, but when I tried testing it at my terminal, I got a huge > error message. This is the app: > > [snip] > line 467, in server_bind > self.socket.bind(self.server_address) > OSError: [Errno 48] Address already in use > 192:Webapp TamaraB$ > > What went wrong? The last message in the error message "Address already in use" means that there's a web server using the port already running on your machine. If you're on a Mac, you already have a local web server running on your machine. You may or may not have specifically set that up. I intentionally setup the development version of my web site on my system for testing. To find out what network ports are in use on your system, you can use command-line tools to display what processes are listening to what ports. If none of this makes sense to you, read more on Linux networking, web programming, and system administration before you attempt to dive into building a web application with python. It's like you opened the hood of your car and pointed to a cap marked "710" and are asking us "what's that?" It's actually where you pour the "OIL" when you need to top it off. Good luck. From marko at pacujo.net Wed Jun 27 13:40:05 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 27 Jun 2018 20:40:05 +0300 Subject: EXTERNAL: OSError: [Errno 48] Address already in use References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> Message-ID: <87a7rggmbu.fsf@elektro.pacujo.net> Joaquin Henriquez : >>Subject: EXTERNAL: OSError: [Errno 48] Address already in use > > The best way to help if got you to put the relevant code here. > > The error you are experiencing means that the Port you are trying to > bind is already taken by another running process. That error usually takes place when restarting a server. The server exited with one or more TCP connections open, which left the connections in a TIME-WAIT state for some minutes. When the server is restarted and tries to bind its address again, the ghosts of the previous connections prevent the socket from being bound. The problem can be solved by turning on the SO_REUSEADDR flag of the socket. Marko From brgrt2 at gmail.com Wed Jun 27 13:40:54 2018 From: brgrt2 at gmail.com (T Berger) Date: Wed, 27 Jun 2018 10:40:54 -0700 (PDT) Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: <984a776d-f22e-4812-9cf4-ef6403b710ca@googlegroups.com> References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <984a776d-f22e-4812-9cf4-ef6403b710ca@googlegroups.com> Message-ID: Let me add this information to clarify the context in which I got this error 48. It doesn't make sense to me, and it might not to you. This morning, I opened my webapp (vsearch4web.py in the terminal code above) and noticed a whole bunch of code I had not typed. I also noticed something weird about the file path in the title bar (it seemed to be in my downloads folder). So I created a completely fresh file, retyped everything, and replaced the older one in the folder with this one. THEN, I ran the program at my terminal, and got this error 48 in response. Does any of this make sense? Thanks, Tamara From brgrt2 at gmail.com Wed Jun 27 13:44:14 2018 From: brgrt2 at gmail.com (T Berger) Date: Wed, 27 Jun 2018 10:44:14 -0700 (PDT) Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: <87a7rggmbu.fsf@elektro.pacujo.net> References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> Message-ID: On Wednesday, June 27, 2018 at 1:40:20 PM UTC-4, Marko Rauhamaa wrote: > Joaquin Henriquez : > > >>Subject: EXTERNAL: OSError: [Errno 48] Address already in use > > > > The best way to help if got you to put the relevant code here. > > > > The error you are experiencing means that the Port you are trying to > > bind is already taken by another running process. > > That error usually takes place when restarting a server. The server > exited with one or more TCP connections open, which left the connections > in a TIME-WAIT state for some minutes. When the server is restarted and > tries to bind its address again, the ghosts of the previous connections > prevent the socket from being bound. > > The problem can be solved by turning on the SO_REUSEADDR flag of the > socket. > > > Marko Hi Marko, Can you please tell me how to "turn on the SO_REUSEADDR flag of the socket"? Thanks, Tamara From arj.python at gmail.com Wed Jun 27 14:45:23 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Wed, 27 Jun 2018 22:45:23 +0400 Subject: configparser v/s file variables In-Reply-To: References: Message-ID: and that closes it, thanks !!! Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Importing variables from a file is dangerous because it can execute > arbitrary code. It should never be done with files provided by the > user. > > Using configparser is far, far safer. > From jlee54 at gmail.com Wed Jun 27 15:15:23 2018 From: jlee54 at gmail.com (Jim Lee) Date: Wed, 27 Jun 2018 12:15:23 -0700 Subject: configparser v/s file variables In-Reply-To: References: Message-ID: On 06/27/18 11:45, Abdur-Rahmaan Janhangeer wrote: > and that closes it, > > thanks !!! > > Abdur-Rahmaan Janhangeer > https://github.com/Abdur-rahmaanJ > > Importing variables from a file is dangerous because it can execute >> arbitrary code. It should never be done with files provided by the >> user. >> >> Using configparser is far, far safer. >> ? It seems a bit silly to me to worry about arbitrary code execution in an interpreted language like Python whose default runtime execution method is to parse the source code directly.? An attacker would be far more likely to simply modify the source to achieve his ends rather than try to inject a payload externally. These days, "execute arbitrary code" implies a deliberate attack. Now, if you used input validation as an argument, I would agree that configparser is, if not safer, easier. -Jim From drsalists at gmail.com Wed Jun 27 15:34:24 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 27 Jun 2018 12:34:24 -0700 Subject: sigmoid function and derivative In-Reply-To: <259363ad-4433-449c-9c0b-943a38ecefab@googlegroups.com> References: <259363ad-4433-449c-9c0b-943a38ecefab@googlegroups.com> Message-ID: On Tue, Jun 26, 2018 at 8:26 PM, Sharan Basappa wrote: > Folks, > > I know this is not a machine learning forum but I wanted to see if anyone > can explain this to me. > > In artificial neural network, I can understand why sigmoid is used but I > see that derivative of sigmoid output function is used. I am not able to > understand why. > > For example: > # convert output of sigmoid function to its derivative > def sigmoid_output_to_derivative(output): > return output*(1-output) > The derivative tells you what direction to go in, as you update your coefficients. It's a slope of a curve. Otherwise, you'd be steering blind. From rgaddi at highlandtechnology.invalid Wed Jun 27 15:36:53 2018 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Wed, 27 Jun 2018 12:36:53 -0700 Subject: configparser v/s file variables In-Reply-To: References: Message-ID: On 06/27/2018 12:15 PM, Jim Lee wrote: > > > On 06/27/18 11:45, Abdur-Rahmaan Janhangeer wrote: >> and that closes it, >> >> thanks !!! >> >> Abdur-Rahmaan Janhangeer >> https://github.com/Abdur-rahmaanJ >> >> Importing variables from a file is dangerous because it can execute >>> arbitrary code.? It should never be done with files provided by the >>> user. >>> >>> Using configparser is far, far safer. >>> > > ? It seems a bit silly to me to worry about arbitrary code execution in > an interpreted language like Python whose default runtime execution > method is to parse the source code directly.? An attacker would be far > more likely to simply modify the source to achieve his ends rather than > try to inject a payload externally. > > These days, "execute arbitrary code" implies a deliberate attack. Now, > if you used input validation as an argument, I would agree that > configparser is, if not safer, easier. > > -Jim > Not at all. Because if you're assuming a malicious user (who wasn't the one to install it), then you're assuming a multi-user environment. In which case the malicious user wouldn't have modify access to the code, unless your program says "Hey, Mal E. Factor, why don't you run your arbitrary code in my environment?" -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From grant.b.edwards at gmail.com Wed Jun 27 15:40:31 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 27 Jun 2018 19:40:31 +0000 (UTC) Subject: configparser v/s file variables References: Message-ID: On 2018-06-27, Jim Lee wrote: > ?It seems a bit silly to me to worry about arbitrary code > execution in an interpreted language like Python whose default > runtime execution method is to parse the source code directly.? Maybe it's not a deliberate attack. Good application design is also about preventing accidents. > An attacker would be far more likely to simply modify the source to > achieve his ends rather than try to inject a payload externally. That's true if the user has write permission for the program itself. That's not how applications are usually installed (at least not on the OSes I use). > These days, "execute arbitrary code" implies a deliberate attack. Perhaps I should have phrased it differently: I didn't mean to restrict my comments to a deliberate attack. > Now, if you used input validation as an argument, I would agree that > configparser is, if not safer, easier. And it doesn't require that the end user have any knowlege of Python syntax or sematics. -- Grant Edwards grant.b.edwards Yow! ... I want FORTY-TWO at TRYNEL FLOATATION SYSTEMS gmail.com installed within SIX AND A HALF HOURS!!! From arj.python at gmail.com Wed Jun 27 16:10:11 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 28 Jun 2018 00:10:11 +0400 Subject: configparser v/s file variables In-Reply-To: References: Message-ID: i think variables also in the case of PORT = 12345 Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ And it doesn't require that the end user have any knowlege of Python > syntax or sematics. > From rgaddi at highlandtechnology.invalid Wed Jun 27 17:30:15 2018 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Wed, 27 Jun 2018 14:30:15 -0700 Subject: Something new which all programmers world wide will appreciate In-Reply-To: <7f410ee5-b3e3-4d60-b09e-f3dc2991ef29@googlegroups.com> References: <7f410ee5-b3e3-4d60-b09e-f3dc2991ef29@googlegroups.com> Message-ID: On 06/27/2018 02:14 PM, skybuck2000 at hotmail.com wrote: > Now I don't like the French much ! LOL. > > But this time they have invented something which will fill programmers with tears of joy ! =D > > http://www.euronews.com/2018/06/27/pizza-making-robot > > Hopefully this will lead to cheaper and delicious pizzas in the future ! ;) =D > > Bye, > Skybuck. > Or, you know, someone didn't bother putting limit checks in and a time out of 20 the thing gets lost and starts putting the sauce directly on the customer. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From steve+comp.lang.python at pearwood.info Wed Jun 27 18:19:04 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 27 Jun 2018 22:19:04 +0000 (UTC) Subject: configparser v/s file variables References: Message-ID: On Wed, 27 Jun 2018 12:15:23 -0700, Jim Lee wrote: > ? It seems a bit silly to me to worry about arbitrary code execution > ? in > an interpreted language like Python whose default runtime execution > method is to parse the source code directly.? An attacker would be far > more likely to simply modify the source to achieve his ends rather than > try to inject a payload externally. Spoken like a single user on a single-user machine who has administrator privileges and can write to anything anywhere. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From cs at cskk.id.au Wed Jun 27 18:19:28 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 28 Jun 2018 08:19:28 +1000 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: Message-ID: <20180627221928.GA25848@cskk.homeip.net> On 27Jun2018 10:44, Tamara Berger wrote: >On Wednesday, June 27, 2018 at 1:40:20 PM UTC-4, Marko Rauhamaa wrote: >> Joaquin Henriquez : >> >> >>Subject: EXTERNAL: OSError: [Errno 48] Address already in use >> > The best way to help if got you to put the relevant code here. >> > >> > The error you are experiencing means that the Port you are trying to >> > bind is already taken by another running process. >> >> That error usually takes place when restarting a server. The server >> exited with one or more TCP connections open, which left the connections >> in a TIME-WAIT state for some minutes. When the server is restarted and >> tries to bind its address again, the ghosts of the previous connections >> prevent the socket from being bound. >> >> The problem can be solved by turning on the SO_REUSEADDR flag of the >> socket. > >Can you please tell me how to "turn on the SO_REUSEADDR flag of the socket"? There's an example at the very bottom of the documentation for the "socket" module: https://docs.python.org/3/library/socket.html However, Flash likely creates the server socket for you; I don't know how to tell it to set the SO_REUSEADDR option, though the flask documentation might. You can check the status of the system with the netstat(8) command: netstat -an lists all the system sockets and connections running on your machine. There will be many, so if you know the port you're using you can narrow it does with a grep: netstat -an | grep 8000 if you were using port 8000. This also points the way to a workaround: since you're running the script yourself on an ad hoc basis, change ports! Maybe provide the listening port on the command line, and just bump it by one when this happens. Cheers, Cameron Simpson From drsalists at gmail.com Wed Jun 27 18:33:00 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 27 Jun 2018 15:33:00 -0700 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> Message-ID: On Wed, Jun 27, 2018 at 10:44 AM, T Berger wrote: > On Wednesday, June 27, 2018 at 1:40:20 PM UTC-4, Marko Rauhamaa wrote: > > Joaquin Henriquez : > > > > >>Subject: EXTERNAL: OSError: [Errno 48] Address already in use > > > > > > The best way to help if got you to put the relevant code here. > > > > > > The error you are experiencing means that the Port you are trying to > > > bind is already taken by another running process. > > > > That error usually takes place when restarting a server. The server > > exited with one or more TCP connections open, which left the connections > > in a TIME-WAIT state for some minutes. When the server is restarted and > > tries to bind its address again, the ghosts of the previous connections > > prevent the socket from being bound. > > > > The problem can be solved by turning on the SO_REUSEADDR flag of the > > socket. > > > > > > Marko > > Hi Marko, > > Can you please tell me how to "turn on the SO_REUSEADDR flag of the > socket"? > Here's a small script that might serve as an example: http://stromberg.dnsalias.org/svn/max-tcp-window/trunk/max-tcp-window BTW, it's a security feature you're turning off. If you're on a multiuser box, it prevents a second user from stealing lingering connections from a first user on the same port. From jlee54 at gmail.com Wed Jun 27 19:09:09 2018 From: jlee54 at gmail.com (Jim Lee) Date: Wed, 27 Jun 2018 16:09:09 -0700 Subject: configparser v/s file variables In-Reply-To: References: Message-ID: <7fdd7092-14c2-26df-99d9-eda9cc35fa64@gmail.com> On 06/27/18 15:19, Steven D'Aprano wrote: > On Wed, 27 Jun 2018 12:15:23 -0700, Jim Lee wrote: > >> ? It seems a bit silly to me to worry about arbitrary code execution >> ? in >> an interpreted language like Python whose default runtime execution >> method is to parse the source code directly.? An attacker would be far >> more likely to simply modify the source to achieve his ends rather than >> try to inject a payload externally. > Spoken like a single user on a single-user machine who has administrator > privileges and can write to anything anywhere. > > > ...which is exactly the case I was trying to illustrate.? Another is the elevation of privileges (in a multi-user environment)? due to any of a number of methods.? The point is that the source code exists in the execution environment, and once one gains access to that code, one doesn't *need* anything else. -Jim -Jim From nad at python.org Wed Jun 27 20:58:03 2018 From: nad at python.org (Ned Deily) Date: Wed, 27 Jun 2018 20:58:03 -0400 Subject: Python 3.7.0 is now available! (and so is 3.6.6) Message-ID: <6FF553CD-6580-4939-A5E4-78143633BF1F@python.org> On behalf of the Python development community and the Python 3.7 release team, we are pleased to announce the availability of Python 3.7.0. Python 3.7.0 is the newest feature release of the Python language, and it contains many new features and optimizations. You can find Python 3.7.0 here: https://www.python.org/downloads/release/python-370/ Most third-party distributors of Python should be making 3.7.0 packages available soon. See the "What?s New In Python 3.7" document (https://docs.python.org/3.7/whatsnew/3.7.html) for more information about features included in the 3.7 series. Detailed information about the changes made in 3.7.0 can be found in its change log. Maintenance releases for the 3.7 series will follow at regular intervals starting in July of 2018. We hope you enjoy Python 3.7! P.S. We are also happy to announce the availability of Python 3.6.6, the next maintenance release of Python 3.6: https://www.python.org/downloads/release/python-366/ 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/ -- Ned Deily nad at python.org -- [] From aevb42 at gmail.com Wed Jun 27 21:23:48 2018 From: aevb42 at gmail.com (Andrew von Bevern) Date: Wed, 27 Jun 2018 20:23:48 -0500 Subject: help install on Win 7 Message-ID: I have tried to install python on my home laptop several times, using 3.6 or 3.7. Each time I get the following error - anyone know what I am doing wrong? [image: image.png] thanks in advance Andrew From brgrt2 at gmail.com Thu Jun 28 01:21:19 2018 From: brgrt2 at gmail.com (T Berger) Date: Wed, 27 Jun 2018 22:21:19 -0700 (PDT) Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> Message-ID: <90c0eb64-201e-4b69-9d11-014cd4068dc2@googlegroups.com> Hi Guys, Thanks for all the suggestions. I found the problem. I had saved my program in IDLE and quit out of the shell, and then tried to run the program in Terminal. Previously, restarting the shell was enough to break the connection with the port. This time, I guess, it wasn't. So after thinking about your suggestions, I bypassed IDLE and went directly to Terminal, and the program worked. Tamara From marko at pacujo.net Thu Jun 28 01:31:48 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 28 Jun 2018 08:31:48 +0300 Subject: EXTERNAL: OSError: [Errno 48] Address already in use References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> Message-ID: <871scrh3y3.fsf@elektro.pacujo.net> Dan Stromberg : >> > The problem can be solved by turning on the SO_REUSEADDR flag of >> > the socket. > BTW, it's a security feature you're turning off. If you're on a > multiuser box, it prevents a second user from stealing lingering > connections from a first user on the same port. Can you provide a brief proof of concept? Marko From arj.python at gmail.com Thu Jun 28 03:04:23 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 28 Jun 2018 11:04:23 +0400 Subject: help install on Win 7 In-Reply-To: References: Message-ID: text-only list, can you please copy paste the error? thank you, Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > From steve+comp.lang.python at pearwood.info Thu Jun 28 03:46:24 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 28 Jun 2018 07:46:24 +0000 (UTC) Subject: configparser v/s file variables References: <7fdd7092-14c2-26df-99d9-eda9cc35fa64@gmail.com> Message-ID: On Wed, 27 Jun 2018 16:09:09 -0700, Jim Lee wrote: > On 06/27/18 15:19, Steven D'Aprano wrote: >> On Wed, 27 Jun 2018 12:15:23 -0700, Jim Lee wrote: >> >>> ? It seems a bit silly to me to worry about arbitrary code >>> ? execution in >>> an interpreted language like Python whose default runtime execution >>> method is to parse the source code directly.? An attacker would be far >>> more likely to simply modify the source to achieve his ends rather >>> than try to inject a payload externally. >> Spoken like a single user on a single-user machine who has >> administrator privileges and can write to anything anywhere. >> >> >> > ...which is exactly the case I was trying to illustrate.? Another is the > elevation of privileges (in a multi-user environment)? due to any of a > number of methods.? The point is that the source code exists in the > execution environment, and once one gains access to that code, one > doesn't *need* anything else. o_O Yes, attacks by trusted insiders are the hardest to defend against. Betrayal of trust sucks. Trusted users with sufficient privileges could just modify the source code of your application or of Python itself. They could also attack your system in a thousand different ways. But what about untrusted users with fewer privileges? They *can't* modify the source code of your application, or change the password on other accounts, or read arbitrary files, or masquerade as other users. Because they have unprivileged accounts. So why give them the ability to escalate their privilege to that of your application (which probably can do lots of things they can't do) by directly executing Python code they supply? Your argument is akin to: "I gave my partner a key to my house, and they could rob me blind if they want. Since I trust them not to, there's no point in locking the door to the house when I go out, since they have a key." -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From avon at bbs.nz.invalid Thu Jun 28 04:05:55 2018 From: avon at bbs.nz.invalid (Kerr Avon) Date: Thu, 28 Jun 2018 20:05:55 +1200 (NZST) Subject: Where's the junk coming from? References: <74676406@f101.n1.z21.fsxnet> Message-ID: On Wed, 27 Jun 2018 21:43:12 +1200, Avon wrote: > Hey Cameron, > > Apologies for this. I have contacted the Fido system connected to the > gateway I run into news.bbs.nz and have asked them to urgently sort / > check what's up. If I don't get any joy from them within the next 24 > hours I will delink them so as to negate further probs. > > My hunch is a BBS (yes they still exist :)) is taking a gated feed of > this newsgroup and is linked to more than one gateway so stuff is > looping... not good. > > Stand by caller... we're working on this now. > > Best, Paul newsmaster [at] news dot bbs dot nz Yep confirming I found the issue lay with the sysop of a BBS that connects to the gateway linked to news.bbs.nz I have delinked him while he addresses the issue (which he has found) and we will leave him delinked for a few more days to be sure. If anyone spots anything amiss that looks like it's coming in from news.bbs.nz please feel free to contact me again and I'll get right on to it. Apologies for the hassles. Best, Paul -- Agency News | news.bbs.nz From steve+comp.lang.python at pearwood.info Thu Jun 28 04:11:18 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 28 Jun 2018 08:11:18 +0000 (UTC) Subject: Should nested classes in an Enum be Enum members? References: <5B33A3D5.7060208@stoneleaf.us> Message-ID: On Wed, 27 Jun 2018 07:48:53 -0700, Ethan Furman wrote: > [Note: there is a similar thread on Python-Ideas, if you would like to > respond there.] > > Consider the following Enum definition: > > class Color(Enum): > RED = 1 > GREEN = 2 > BLUE = 3 > @property > def lower(self): > return self.name.lower() > def spam(self): > return "I like %s eggs and spam!" % self.lower > class SomeClass: > pass > > Which of the above Color attributes are enums, and which aren't? The question is ambiguous in the case of SomeClass. It could mean that: - SomeClass is the same kind of thing as Color (an Enum subclass); - SomeClass is the same kind of thing as Color.RED (an enum member); - or neither of the above. (In hindsight perhaps you should have called the class EnumType so that ambiguity would not exist. Then an enum would *always* refer to the members Color.RED etc, and never to Color itself.) Without trying it, or reading ahead, I would not want to guess which was the case. [ s p o i l e r s p a c e ] > Answer: > > - RED, GREEN, and BLUE are members > - lower and spam() are not > - SomeClass /is/ a member (but not its instances) Is that by accident or by design? > Question: > > Should `SomeClass` be an enum member? When would it be useful to > have an embedded class in an Enum be an enum member? I honestly cannot think of any reason to nest a class inside of an Enum class. But if I did, I would probably want it to be just a regular class, and not an enum member. If I wanted to nest an Enum class inside an Enum class (but why???) I'd just inherit from Enum: class Colour(Enum): class PrimaryColour(Enum): RED = 1 GREEN = 2 BLUE = 3 OCTARINE = 8 class SecondaryColour(Enum): PUCE = 101 MAUVE = 102 BEIGE = 103 TEAL = 104 > The only example I have seen so far of nested classes in an Enum is when > folks want to make an Enum of Enums, and the nested Enum should not > itself be an enum member. Since the counter-example already works I > haven't seen any requests for it. ;) > > So I'm asking the community: What real-world examples can you offer for > either behavior? Cases where nested classes should be enum members, and > cases where nested classes should not be members. Is this a trick question? :-) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From mail at timgolden.me.uk Thu Jun 28 04:30:52 2018 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 28 Jun 2018 09:30:52 +0100 Subject: Where's the junk coming from? In-Reply-To: References: <74676406@f101.n1.z21.fsxnet> Message-ID: <7d9abf6b-6dff-8894-5446-54a2a78c5925@timgolden.me.uk> On 28/06/2018 09:05, Kerr Avon wrote: > On Wed, 27 Jun 2018 21:43:12 +1200, Avon wrote: > >> Hey Cameron, >> >> Apologies for this. I have contacted the Fido system connected to the >> gateway I run into news.bbs.nz and have asked them to urgently sort / >> check what's up. If I don't get any joy from them within the next 24 >> hours I will delink them so as to negate further probs. >> >> My hunch is a BBS (yes they still exist :)) is taking a gated feed of >> this newsgroup and is linked to more than one gateway so stuff is >> looping... not good. >> >> Stand by caller... we're working on this now. >> >> Best, Paul newsmaster [at] news dot bbs dot nz > > Yep confirming I found the issue lay with the sysop of a BBS that connects > to the gateway linked to news.bbs.nz > > I have delinked him while he addresses the issue (which he has found) and > we will leave him delinked for a few more days to be sure. > > If anyone spots anything amiss that looks like it's coming in from > news.bbs.nz please feel free to contact me again and I'll get right on to > it. > > Apologies for the hassles. > > Best, Paul (Wearing my List Moderator hat) Thanks very much for addressing this for us, and to Cameron and others who did the detective work. I admit I assumed at first it was some kind of odd attack perhaps related to a dissatisfied poster so I'm glad it was a misconfiguration issue. TJG From ojaskushagra98 at gmail.com Thu Jun 28 05:14:34 2018 From: ojaskushagra98 at gmail.com (ojas gupta) Date: Thu, 28 Jun 2018 14:44:34 +0530 Subject: Error Launching python 3.7.0 Message-ID: I just downloaded and installed python 3.7.0 on my PC and whenever I tried to launch the application it showed "error" saying python runtime dll missing... and that too is happening despite i downloaded the official licenced product from python.org .... I am attaching a photo clicked by me when that error message displayed so that you can have a better idea of my issue... Thank you in advance... From rhodri at kynesim.co.uk Thu Jun 28 06:31:12 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 28 Jun 2018 11:31:12 +0100 Subject: help install on Win 7 In-Reply-To: References: Message-ID: <01977a11-69da-e97c-592c-7089aa5c845c@kynesim.co.uk> On 28/06/18 02:23, Andrew von Bevern wrote: > I have tried to install python on my home laptop several times, using 3.6 > or 3.7. Each time I get the following error - anyone know what I am doing > wrong? > [image: image.png] I'm sorry, but this mailing list removes attachments (for perfectly sensible security reasons; also they tend to be annoyingly big). Could you copy and paste (not just retype!) the full error, backtrace and everything as text? I know it's a pain on Windows, but it's the only way any of us here are going to see it. The more information you can include the better. Cheers, Rhodri -- Rhodri James *-* Kynesim Ltd From ben+python at benfinney.id.au Thu Jun 28 06:34:58 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 28 Jun 2018 20:34:58 +1000 Subject: Should nested classes in an Enum be Enum members? References: <5B33A3D5.7060208@stoneleaf.us> Message-ID: <85h8lnci7h.fsf@benfinney.id.au> Ethan Furman writes: > Consider the following Enum definition: > > class Color(Enum): > RED = 1 > GREEN = 2 > BLUE = 3 > @property > def lower(self): > return self.name.lower() > def spam(self): > return "I like %s eggs and spam!" % self.lower > class SomeClass: > pass That dumbfounds my intuitions. Specifically, I can't make sense of why someone would want to have a class that is simultaneously behaving as an enumerated type, *and* has an API of custom callable attributes. > Question: > > Should `SomeClass` be an enum member? When would it be useful to > have an embedded class in an Enum be an enum member? I can't think of a satisfactory answer to the question ?Why is SomeClass defined inside that enumerated type at all?? > So I'm asking the community: What real-world examples can you offer > for either behavior? That set is empty. I'd be going straight to the author of that code; or, if that weren't an option, re-factoring that code at the next opportunity. -- \ ?Our urge to trust our senses overpowers what our measuring | `\ devices tell us about the actual nature of reality.? ?Ann | _o__) Druyan, _Cosmos_, 2014 | Ben Finney From alister.ware at ntlworld.com Thu Jun 28 06:35:13 2018 From: alister.ware at ntlworld.com (Alister) Date: Thu, 28 Jun 2018 10:35:13 GMT Subject: Something new which all programmers world wide will appreciate References: <7f410ee5-b3e3-4d60-b09e-f3dc2991ef29@googlegroups.com> Message-ID: On Wed, 27 Jun 2018 14:30:15 -0700, Rob Gaddi wrote: > On 06/27/2018 02:14 PM, skybuck2000 at hotmail.com wrote: >> Now I don't like the French much ! LOL. >> >> But this time they have invented something which will fill programmers >> with tears of joy ! =D >> >> http://www.euronews.com/2018/06/27/pizza-making-robot >> >> Hopefully this will lead to cheaper and delicious pizzas in the future >> ! ;) =D >> >> Bye, >> Skybuck. >> >> > Or, you know, someone didn't bother putting limit checks in and a time > out of 20 the thing gets lost and starts putting the sauce directly on > the customer. as a diabetic the bread base puts them firmly on the bad list anyway :-( -- "If it ain't broke, don't fix it." - Bert Lantz From breamoreboy at gmail.com Thu Jun 28 08:19:11 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Thu, 28 Jun 2018 13:19:11 +0100 Subject: Error Launching python 3.7.0 In-Reply-To: References: Message-ID: On 28/06/18 10:14, ojas gupta wrote: > I just downloaded and installed python 3.7.0 on my PC and whenever I tried > to launch the application it showed "error" saying python runtime dll > missing... and that too is happening despite i downloaded the official > licenced product from python.org .... > > I am attaching a photo clicked by me when that error message displayed so > that you can have a better idea of my issue... > > Thank you in advance... > The photo has been stripped as this is a text only list. However I'll guess that this has been asked and answered repeatedly before, so see e.g. https://answers.microsoft.com/en-us/windows/forum/windows_7-windows_programs/python-360-cant-start-because-api-ms-win-crt/a58999ec-a94e-44ad-8f92-8136ce98871b -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From gheskett at shentel.net Thu Jun 28 08:59:36 2018 From: gheskett at shentel.net (Gene Heskett) Date: Thu, 28 Jun 2018 08:59:36 -0400 Subject: Something new which all programmers world wide will appreciate In-Reply-To: References: <7f410ee5-b3e3-4d60-b09e-f3dc2991ef29@googlegroups.com> Message-ID: <201806280859.36957.gheskett@shentel.net> On Thursday 28 June 2018 06:35:13 Alister via Python-list wrote: > On Wed, 27 Jun 2018 14:30:15 -0700, Rob Gaddi wrote: > > On 06/27/2018 02:14 PM, skybuck2000 at hotmail.com wrote: > >> Now I don't like the French much ! LOL. > >> > >> But this time they have invented something which will fill > >> programmers with tears of joy ! =D > >> > >> http://www.euronews.com/2018/06/27/pizza-making-robot > >> > >> Hopefully this will lead to cheaper and delicious pizzas in the > >> future ! ;) =D > >> > >> Bye, > >> Skybuck. > > > > Or, you know, someone didn't bother putting limit checks in and a > > time out of 20 the thing gets lost and starts putting the sauce > > directly on the customer. > > as a diabetic the bread base puts them firmly on the bad list anyway > :-( > +1 at least, from another DM-II. > > -- > "If it ain't broke, don't fix it." > - Bert Lantz -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From grant.b.edwards at gmail.com Thu Jun 28 10:30:15 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 28 Jun 2018 14:30:15 +0000 (UTC) Subject: configparser v/s file variables References: <7fdd7092-14c2-26df-99d9-eda9cc35fa64@gmail.com> Message-ID: On 2018-06-28, Steven D'Aprano wrote: > So why give them the ability to escalate their privilege to that of > your application (which probably can do lots of things they can't > do) by directly executing Python code they supply? To be fair, that situation isn't common. The vast majority of applications run with the exact same set of privledges as the user who invoked them. At least that's the case on Linux/Unix. Perhaps Windows apps are different and the usual case is for many applications to have dangerous capabilities that an average user who's invoking them shouldn't have. That sounds stupid enough to be something that would be normal for Windows. I still maintain it's a bad idea to run arbitrary code found in user-edited config files. There may be cases where somebody has figured out how to muck with a config file that's shared among multiple users, or has tricked somebody into including something from an untrusted source in an include file. Or there could be users who don't know what they're doing and unwittingly type something harmful into a config file: bad_command = os.system("rm -rf ~/*") Yes, I know, users would never be that dumb... -- Grant Edwards grant.b.edwards Yow! Everybody gets free at BORSCHT! gmail.com From grant.b.edwards at gmail.com Thu Jun 28 10:34:36 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 28 Jun 2018 14:34:36 +0000 (UTC) Subject: [OT] Why are BBSes? [was Where's the junk coming from?] References: <74676406@f101.n1.z21.fsxnet> Message-ID: On 2018-06-28, Kerr Avon wrote: > Yep confirming I found the issue lay with the sysop of a BBS that connects > to the gateway linked to news.bbs.nz OK, I've got to ask... Why are there still BBSes? Who even has a modem these days? [OK, I'll admit my 11 year old Thinkpad T500 has a built-in POTS modem, but it's never been used.] -- Grant Edwards grant.b.edwards Yow! Vote for ME -- I'm at well-tapered, half-cocked, gmail.com ill-conceived and TAX-DEFERRED! From ethan at stoneleaf.us Thu Jun 28 11:36:47 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 28 Jun 2018 08:36:47 -0700 Subject: Should nested classes in an Enum be Enum members? In-Reply-To: References: <5B33A3D5.7060208@stoneleaf.us> Message-ID: <5B35008F.3000102@stoneleaf.us> On 06/28/2018 01:11 AM, Steven D'Aprano wrote: > On Wed, 27 Jun 2018 07:48:53 -0700, Ethan Furman wrote: > >> [Note: there is a similar thread on Python-Ideas, if you would like to >> respond there.] >> >> Consider the following Enum definition: >> >> class Color(Enum): >> RED = 1 >> GREEN = 2 >> BLUE = 3 >> @property >> def lower(self): >> return self.name.lower() >> def spam(self): >> return "I like %s eggs and spam!" % self.lower >> class SomeClass: >> pass >> >> Which of the above Color attributes are enums, and which aren't? > (In hindsight perhaps you should have called the class EnumType so that > ambiguity would not exist. Then an enum would *always* refer to the > members Color.RED etc, and never to Color itself.) The problem then is the ambiguity between EnumMeta and EnumType. :/ >> Answer: >> >> - RED, GREEN, and BLUE are members >> - lower and spam() are not >> - SomeClass /is/ a member (but not its instances) > > Is that by accident or by design? By design. It is entirely possible to want an enum of types (int, float, str, etc.). >> Question: >> >> Should `SomeClass` be an enum member? When would it be useful to >> have an embedded class in an Enum be an enum member? > > I honestly cannot think of any reason to nest a class inside of an Enum > class. But if I did, I would probably want it to be just a regular class, > and not an enum member. > > If I wanted to nest an Enum class inside an Enum class (but why???) I'd > just inherit from Enum: > > class Colour(Enum): > class PrimaryColour(Enum): > RED = 1 > GREEN = 2 > BLUE = 3 > OCTARINE = 8 > class SecondaryColour(Enum): > PUCE = 101 > MAUVE = 102 > BEIGE = 103 > TEAL = 104 This really seems to be the sticking point -- what should an Enum of Enums look like? For example, should the above do --> list(Colour) [Colour.PrimaryColour <...>, Colour.SecondaryColour <...>] or something else? >> The only example I have seen so far of nested classes in an Enum is when >> folks want to make an Enum of Enums, and the nested Enum should not >> itself be an enum member. Since the counter-example already works I >> haven't seen any requests for it. ;) >> >> So I'm asking the community: What real-world examples can you offer for >> either behavior? Cases where nested classes should be enum members, and >> cases where nested classes should not be members. > > Is this a trick question? Heh. Not at all. It is entirely possible to have a real use-case which we cannot model the way we want in code. -- ~Ethan~ From marcoprosperi347 at gmail.com Thu Jun 28 12:02:46 2018 From: marcoprosperi347 at gmail.com (Marco Prosperi) Date: Thu, 28 Jun 2018 18:02:46 +0200 Subject: overlooked patch? Message-ID: hello, just to give evidence that there is a bug in python 3.6/3.7 for which there is a patch prepared a long time ago but probably it has never been applied because the status/stage of the bug is 'needs patch'. https://bugs.python.org/issue29097 Marco From ian.g.kelly at gmail.com Thu Jun 28 12:40:58 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 28 Jun 2018 10:40:58 -0600 Subject: Should nested classes in an Enum be Enum members? In-Reply-To: <85h8lnci7h.fsf@benfinney.id.au> References: <5B33A3D5.7060208@stoneleaf.us> <85h8lnci7h.fsf@benfinney.id.au> Message-ID: On Thu, Jun 28, 2018 at 4:38 AM Ben Finney wrote: > > Ethan Furman writes: > > > Consider the following Enum definition: > > > > class Color(Enum): > > RED = 1 > > GREEN = 2 > > BLUE = 3 > > @property > > def lower(self): > > return self.name.lower() > > def spam(self): > > return "I like %s eggs and spam!" % self.lower > > class SomeClass: > > pass > > That dumbfounds my intuitions. > > Specifically, I can't make sense of why someone would want to have a > class that is simultaneously behaving as an enumerated type, *and* has > an API of custom callable attributes. You don't see value in enum members having properties? From nospam at yrl.co.uk Thu Jun 28 13:08:46 2018 From: nospam at yrl.co.uk (Elliott Roper) Date: Thu, 28 Jun 2018 18:08:46 +0100 Subject: I lost nearly all my modules installing 3.7 Message-ID: <0001HW.20E54D9E037B46DA700000D972CF@news.giganews.com> I have done something stupid. Don't know what. My $PATH looks like this XXXMac:~ elliott$ echo $PATH /Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Pyth on.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3. 5/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Users/elliott/bin :/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/MacGPG2/bin:/Applications/Wireshark.app/Contents/MacOS:/usr/local/git/bin pip3 list or pip3.7 list gives me Package Version ---------- ------- pip 10.0.1 setuptools 39.0.1 > > > import numpy as np Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'numpy' So it is not lying to me!!! pip list or pip3.6 list gives the whole caboodle I was expecting with a far smaller version number for setuptools. My understanding is that the whole $PATH is searched in order to resolve an import, but it isn't. It might be relevant that I have had a bit of hassle installing module updates in the past. I would get an error saying the module version being replaced could not be deleted with permissions errors which I resolved with a bit of sudo -H. Python 3.6 is still working properly when invoked explicitly -- To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96 3CF7 637F 896B C810 E199 7E5C A9E4 8E59 E248 From tjreedy at udel.edu Thu Jun 28 13:32:05 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 Jun 2018 13:32:05 -0400 Subject: overlooked patch? In-Reply-To: References: Message-ID: Yep. We do not have enough people reviewing patches. Perhaps you could do so with this one. On 6/28/2018 12:02 PM, Marco Prosperi wrote: > hello, just to give evidence that there is a bug in python 3.6/3.7 for > which there is a patch prepared a long time ago but probably it has never > been applied because the status/stage of the bug is 'needs patch'. This is really a secondary issue but I changed it, and requested a review. > https://bugs.python.org/issue29097 -- Terry Jan Reedy From tjreedy at udel.edu Thu Jun 28 13:46:33 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 Jun 2018 13:46:33 -0400 Subject: I lost nearly all my modules installing 3.7 In-Reply-To: <0001HW.20E54D9E037B46DA700000D972CF@news.giganews.com> References: <0001HW.20E54D9E037B46DA700000D972CF@news.giganews.com> Message-ID: On 6/28/2018 1:08 PM, Elliott Roper wrote: > I have done something stupid. Don't know what. It appears that you ran 3.7 expecting that modules installed for 3.6 would magically be available for 3.7. There is a pip command for making an editable file of installed packages. Run that in 3.6, perhaps after updating everything. There is another pip command for using that file to install everything listed. Run that in 3.7. > My $PATH looks like this > XXXMac:~ elliott$ echo $PATH > /Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Pyth > on.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3. > 5/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Users/elliott/bin > :/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/MacGPG2/bin:/Applications/Wireshark.app/Contents/MacOS:/usr/local/git/bin > > pip3 list or pip3.7 list gives me > Package Version > ---------- ------- > pip 10.0.1 > setuptools 39.0.1 This is the content of the 3.7 site-packages. >>>> import numpy as np > Traceback (most recent call last): > File "", line 1, in > ModuleNotFoundError: No module named 'numpy' > So it is not lying to me!!! > > pip list or pip3.6 list > gives the whole caboodle I was expecting with a far smaller version number > for setuptools. The content of the 3.6 site-packages directory. > My understanding is that the whole $PATH is searched in order to resolve an > import, but it isn't. The OS searches the OS path, which you listed above. Python searches its sys.path, which it creates when started. Run >>> import sys; sys.path to see the contents. Unless macOS is more different than I think, you should see a 3.7 site-packages when running 3.7. > It might be relevant that I have had a bit of hassle installing module > updates in the past. I would get an error saying the module version being > replaced could not be deleted with permissions errors which I resolved with a > bit of sudo -H. > > Python 3.6 is still working properly when invoked explicitly > -- Terry Jan Reedy From jlee54 at gmail.com Thu Jun 28 13:48:38 2018 From: jlee54 at gmail.com (Jim Lee) Date: Thu, 28 Jun 2018 10:48:38 -0700 Subject: configparser v/s file variables In-Reply-To: References: <7fdd7092-14c2-26df-99d9-eda9cc35fa64@gmail.com> Message-ID: <49a09c18-3b85-9ff7-31cb-bb87e427f436@gmail.com> On 06/28/18 00:46, Steven D'Aprano wrote: > > Yes, attacks by trusted insiders are the hardest to defend against. > Betrayal of trust sucks. Trusted users with sufficient privileges could > just modify the source code of your application or of Python itself. They > could also attack your system in a thousand different ways. > > But what about untrusted users with fewer privileges? They *can't* modify > the source code of your application, or change the password on other > accounts, or read arbitrary files, or masquerade as other users. Because > they have unprivileged accounts. > > So why give them the ability to escalate their privilege to that of your > application (which probably can do lots of things they can't do) by > directly executing Python code they supply? ???? I don't follow.? I never suggested allowing someone the ability to directly execute user-supplied Python code.? However, if they have the privileges necessary to run the application, I don't see the security risk.? Many applications have embedded scripting engines that do just that. > Your argument is akin to: > > "I gave my partner a key to my house, and they could rob me blind if they > want. Since I trust them not to, there's no point in locking the door to > the house when I go out, since they have a key." > > > Not exactly.? The original question was about reading config variables from a file in Python.? That sort of thing didn't suggest (to me) a world-facing web app or other security-conscious situation. It's more like leaving the door unlocked while I'm home... -Jim From jlee54 at gmail.com Thu Jun 28 13:58:36 2018 From: jlee54 at gmail.com (Jim Lee) Date: Thu, 28 Jun 2018 10:58:36 -0700 Subject: configparser v/s file variables In-Reply-To: References: <7fdd7092-14c2-26df-99d9-eda9cc35fa64@gmail.com> Message-ID: On 06/28/18 07:30, Grant Edwards wrote: > I still maintain it's a bad idea to run arbitrary code found in > user-edited config files. > > There may be cases where somebody has figured out how to muck with a > config file that's shared among multiple users, or has tricked > somebody into including something from an untrusted source in an > include file. > > Or there could be users who don't know what they're doing and > unwittingly type something harmful into a config file: > > bad_command = os.system("rm -rf ~/*") > > Yes, I know, users would never be that dumb... > I agree with you that it's a bad idea.? I was pointing out that I look at it from an input validation viewpoint rather than a security viewpoint - that's all. Absolute security isn't a solvable problem.? It isn't even a technical problem.? But that's a discussion for another time... -Jim From jlee54 at gmail.com Thu Jun 28 14:00:17 2018 From: jlee54 at gmail.com (Jim Lee) Date: Thu, 28 Jun 2018 11:00:17 -0700 Subject: [OT] Why are BBSes? [was Where's the junk coming from?] In-Reply-To: References: <74676406@f101.n1.z21.fsxnet> Message-ID: <46df5c8c-f9b1-4bef-d5d4-5719199ce100@gmail.com> On 06/28/18 07:34, Grant Edwards wrote: > OK, I've got to ask... > > Why are there still BBSes? > > Who even has a modem these days? [OK, I'll admit my 11 year old > Thinkpad T500 has a built-in POTS modem, but it's never been used.] > BBS's are most often connected to via telnet these days.? There are still hundreds (if not thousands) of them. -Jim From grant.b.edwards at gmail.com Thu Jun 28 14:45:20 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 28 Jun 2018 18:45:20 +0000 (UTC) Subject: [OT] Why are BBSes? [was Where's the junk coming from?] References: <74676406@f101.n1.z21.fsxnet> <46df5c8c-f9b1-4bef-d5d4-5719199ce100@gmail.com> Message-ID: On 2018-06-28, Jim Lee wrote: > > > On 06/28/18 07:34, Grant Edwards wrote: >> OK, I've got to ask... >> >> Why are there still BBSes? >> >> Who even has a modem these days? [OK, I'll admit my 11 year old >> Thinkpad T500 has a built-in POTS modem, but it's never been used.] >> > BBS's are most often connected to via telnet these days.? There are > still hundreds (if not thousands) of them. Interesting. In my exerience a BBS was just a poor substitute for an FTP site, a mailing list and Usenet. I'm a little baffled as to what "added value" they provide these days, but people are probably equally baffled why I choose to participate in mailing lists via a text-mode NNTP client rather that some pointy-clicky app or website. -- Grant Edwards grant.b.edwards Yow! Used staples are good at with SOY SAUCE! gmail.com From drsalists at gmail.com Thu Jun 28 15:00:39 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 28 Jun 2018 12:00:39 -0700 Subject: OSError: [Errno 48] Address already in use In-Reply-To: References: Message-ID: On Wed, Jun 27, 2018 at 8:49 AM, T Berger wrote: > Why am I getting this error? I'm not sure what additional information I > need to supply, so please let me know. AIUI, there are 2 possible causes. You either have some other process listening on the requested port, or a process that Was using it no longer is but not enough time has passed yet for the kernel to decide that the port can safely be reused. The former keeps two processes from trying to get data from the same port at the same time, which could be confusing. The latter is a security feature. It keeps person A from starting an imap server on port tcp/5555, and having person B come along and start a fake, password-stealing imap server on the same port shortly after person A terminates theirs (for example). There would otherwise be a window of time during which B's imap daemon could steal passwords intended for A's imap daemon, because remote imap clients wouldn't know about the switcheroo. Note that even if A come back and starts their imap daemon immediately after a crash, the kernel doesn't know if that is a legitimate or illegitemate imap daemon, so that is blocked for a while too. You can check if something else is listening on that port with http://stromberg.dnsalias.org/~strombrg/What-program-is-active-on-that-port.html (Linux and Solaris - there will likely be similar tools for other OS's). You can eliminate the waiting period with SO_REUSEADDR (but if you have something else listening on that port, then don't!). Example: http://stromberg.dnsalias.org/~strombrg/max-tcp-window.html HTH. From drsalists at gmail.com Thu Jun 28 15:24:29 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 28 Jun 2018 12:24:29 -0700 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: <871scrh3y3.fsf@elektro.pacujo.net> References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> Message-ID: On Wed, Jun 27, 2018 at 10:31 PM, Marko Rauhamaa wrote: > Dan Stromberg : > >> > The problem can be solved by turning on the SO_REUSEADDR flag of > >> > the socket. > > BTW, it's a security feature you're turning off. If you're on a > > multiuser box, it prevents a second user from stealing lingering > > connections from a first user on the same port. > > Can you provide a brief proof of concept? > https://stackoverflow.com/questions/19960475/problems-related-to-so-reuseaddr From marko at pacujo.net Thu Jun 28 16:27:38 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 28 Jun 2018 23:27:38 +0300 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: (Dan Stromberg's message of "Thu, 28 Jun 2018 12:24:29 -0700") References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> Message-ID: <87muvefyh1.fsf@elektro.pacujo.net> Dan Stromberg : > On Wed, Jun 27, 2018 at 10:31 PM, Marko Rauhamaa wrote: >> Dan Stromberg : >> >> > The problem can be solved by turning on the SO_REUSEADDR flag of >> >> > the socket. >> > BTW, it's a security feature you're turning off. If you're on a >> > multiuser box, it prevents a second user from stealing lingering >> > connections from a first user on the same port. >> >> Can you provide a brief proof of concept? >> > https://stackoverflow.com/questions/19960475/problems-related-to-so-reuseaddr I'm sorry but I couldn't find a working example behind the link. Could you demonstrate the problem with a few lines of Python. Marko From ingy at ingy.net Thu Jun 28 17:17:43 2018 From: ingy at ingy.net (Ingy dot Net) Date: Thu, 28 Jun 2018 14:17:43 -0700 Subject: [ANN] PyYAML-4.1: ***RETRACTED*** Message-ID: I am sorry to report that the PyYAML-4.1 release from 48 hours ago has been removed from PyPI There were too many problems to make this a viable release. The biggest known issue with this retraction is that PyYAML will not work with the new Python 3.7 until PyYAML-4.2 is released. https://github.com/yaml/pyyaml/issues/126#issuecomment-401175258 We are starting work immediately on 4.2b1 prerelease series. I hope to see 4.2 released in the next few days. Work is being coordinated on #pyyaml on irc.freenode.net and issues can be reported and followed at https://github.com/yaml/pyyaml Thank you for your patience. From jlee54 at gmail.com Thu Jun 28 18:05:27 2018 From: jlee54 at gmail.com (Jim Lee) Date: Thu, 28 Jun 2018 15:05:27 -0700 Subject: [OT] Why are BBSes? [was Where's the junk coming from?] In-Reply-To: References: <74676406@f101.n1.z21.fsxnet> <46df5c8c-f9b1-4bef-d5d4-5719199ce100@gmail.com> Message-ID: <9dc6cd0a-bd88-9368-d8f2-824ef808e2a4@gmail.com> On 06/28/18 11:45, Grant Edwards wrote: > On 2018-06-28, Jim Lee wrote: >> >> On 06/28/18 07:34, Grant Edwards wrote: >>> OK, I've got to ask... >>> >>> Why are there still BBSes? >>> >>> Who even has a modem these days? [OK, I'll admit my 11 year old >>> Thinkpad T500 has a built-in POTS modem, but it's never been used.] >>> >> BBS's are most often connected to via telnet these days.? There are >> still hundreds (if not thousands) of them. > Interesting. In my exerience a BBS was just a poor substitute for an > FTP site, a mailing list and Usenet. > > I'm a little baffled as to what "added value" they provide these days, > but people are probably equally baffled why I choose to participate in > mailing lists via a text-mode NNTP client rather that some > pointy-clicky app or website. > Added value?? BBS, Usenet, IRC, Twitter, whatever - they're all just forms of communication. BBS's were around before ARPANET became the Internet - before ftp, usenet, http, and personal computers.? I first started using them in 1976-77 (with a 300 baud modem and a VT-52 terminal), and ran my own in the 80's and 90's - first on a PDP-11/23, then a Commodore 64 and later on an Amiga.? Some people like to keep that tradition alive. -Jim From nospam at yrl.co.uk Thu Jun 28 18:45:22 2018 From: nospam at yrl.co.uk (Elliott Roper) Date: Thu, 28 Jun 2018 23:45:22 +0100 Subject: I lost nearly all my modules installing 3.7 References: <0001HW.20E54D9E037B46DA700000D972CF@news.giganews.com> Message-ID: <0001HW.20E59C82038DC45270000F6362CF@news.giganews.com> On 28 Jun 2018, Terry Reedy wrote (in article): > On 6/28/2018 1:08 PM, Elliott Roper wrote: > > I have done something stupid. Don't know what. > > It appears that you ran 3.7 expecting that modules installed for 3.6 > would magically be available for 3.7. Yes indeed. It worked for 3.4, 3.5, and 3.6 > > > There is a pip command for making an editable file of installed > packages. Run that in 3.6, perhaps after updating everything. > > > There is another pip command for using that file to install everything > listed. Run that in 3.7. I can't see the pip commands you mention for writing a file from 3.6 and reading it back for 3.7 Is it pip freeze -r followed by pip install -r? If so, what is meant by 'the given requirements file' in the freeze options? > > > > My $PATH looks like this > > XXXMac:~ elliott$ echo $PATH > > /Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Py > > th > > on.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/ > > 3. > > 5/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Users/elliott/b > > in > > > /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local > > > /MacGPG2/bin:/Applications/Wireshark.app/Contents/MacOS:/usr/local/git/bin > > > > pip3 list or pip3.7 list gives me > > Package Version > > ---------- ------- > > pip 10.0.1 > > setuptools 39.0.1 > > This is the content of the 3.7 site-packages. > > > > > > import numpy as np > > Traceback (most recent call last): > > File "", line 1, in > > ModuleNotFoundError: No module named 'numpy' > > So it is not lying to me!!! > > > > pip list or pip3.6 list > > gives the whole caboodle I was expecting with a far smaller version number > > for setuptools. > > The content of the 3.6 site-packages directory. When I look inside site-packages in ~/Library (see below) I see many packages that pip lists, but by no means all. F'instance numpy and scipy. They can be found in /Library's site-packages however. > > > > My understanding is that the whole $PATH is searched in order to resolve an > > import, but it isn't. > > The OS searches the OS path, which you listed above. > Python searches its sys.path, which it creates when started. > Run >>> import sys; sys.path to see the contents. > Unless macOS is more different than I think, you should see a 3.7 > site-packages when running 3.7. Aha! That is most helpful Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. (python prompt)>>> import sys .>>>sys.path ['', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', # no such file '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', # 207 items, none matching pip intstallable modules '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib- dynload',# 69 items, none matching pip installable modules '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site- packages'] # just pip and setuptools are in here .>>> ^D EiPro:~ elliott$ python3.6 Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. .>>> import sys (python prompt)>>> sys.path ['', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', # no such file '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', # 207 items, none matching pip intstallable modules '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib- dynload',# 65 items, none matching pip installable modules '/Users/elliott/Library/Python/3.6/lib/python/site-packages', # 103 items some matching items that appear in pip3.6 list '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- packages'] # numpy, scipy, pandas etc. are here. These might have been modules I needed sudo -H to update .>>> What I did not make clear that my 'elliott' user is not an Administrator. If I log into my admin account (which I hardly ever do), it thinks my Python3 is 3.7, list there also shows the hugely abbreviated collection of modules namely pip and setuptools. pip list shows a list of modules so old as to be unrecognisable. It looks like I have a tangled mess. Is there a way of getting rid of all the pythons except Apple's museum piece and starting again? It is a hobby for me. I have no need for backward compatibility. I think if I could install 3.7 site wide from my non-admin account, I would be happiest. The standard install pretty much worked up to 3.6 pip Would it be safe to delete everything on python's sys.path and re-install from the download .pkg > > > > It might be relevant that I have had a bit of hassle installing module > > updates in the past. I would get an error saying the module version being > > replaced could not be deleted with permissions errors which I resolved with > > a > > bit of sudo -H. > > > > Python 3.6 is still working properly when invoked explicitly Sorry, I am really out of my depth here. Thanks so much for your help -- To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96 3CF7 637F 896B C810 E199 7E5C A9E4 8E59 E248 From steve+comp.lang.python at pearwood.info Thu Jun 28 19:44:00 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 28 Jun 2018 23:44:00 +0000 (UTC) Subject: configparser v/s file variables References: <7fdd7092-14c2-26df-99d9-eda9cc35fa64@gmail.com> Message-ID: On Thu, 28 Jun 2018 10:58:36 -0700, Jim Lee wrote: > On 06/28/18 07:30, Grant Edwards wrote: >> I still maintain it's a bad idea to run arbitrary code found in >> user-edited config files. >> >> There may be cases where somebody has figured out how to muck with a >> config file that's shared among multiple users, or has tricked somebody >> into including something from an untrusted source in an include file. >> >> Or there could be users who don't know what they're doing and >> unwittingly type something harmful into a config file: >> >> bad_command = os.system("rm -rf ~/*") >> >> Yes, I know, users would never be that dumb... >> > I agree with you that it's a bad idea. Aside from the little fact that you described concerns about using Python code for settings as "silly". > I was pointing out that I look > at it from an input validation viewpoint rather than a security > viewpoint - that's all. You have made it abundantly clear that you aren't thinking about security. > Absolute security isn't a solvable problem.? It isn't even a technical > problem.? But that's a discussion for another time... Nobody is talking about "absolute security". We're talking about *one* aspect of security: given the need to collect user-supplied settings, is it acceptable to get the settings from executable Python code? Data validation is a red herring: it is no more or less necessary to validate user settings regardless of their source. Whether they come from reading an INI file or from importing a Python file, you still need to check that they have valid values. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From jlee54 at gmail.com Thu Jun 28 20:38:13 2018 From: jlee54 at gmail.com (Jim Lee) Date: Thu, 28 Jun 2018 17:38:13 -0700 Subject: configparser v/s file variables In-Reply-To: References: <7fdd7092-14c2-26df-99d9-eda9cc35fa64@gmail.com> Message-ID: On 06/28/18 16:44, Steven D'Aprano wrote: > >> I agree with you that it's a bad idea. > Aside from the little fact that you described concerns about using Python > code for settings as "silly". > Umm, no.? I said that worrying about arbitrary code execution in an interpreted language seemed silly.? Please be more accurate in your paraphrases. > > Data validation is a red herring: it is no more or less necessary to > validate user settings regardless of their source. Whether they come from > reading an INI file or from importing a Python file, you still need to > check that they have valid values. > > You are making a strawman argument, since you are (again) misrepresenting what I said.? Therefore, I will give you no more opportunities. -Jim From steve+comp.lang.python at pearwood.info Thu Jun 28 20:44:59 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 29 Jun 2018 00:44:59 +0000 (UTC) Subject: EXTERNAL: OSError: [Errno 48] Address already in use References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> Message-ID: On Thu, 28 Jun 2018 23:27:38 +0300, Marko Rauhamaa wrote: > Dan Stromberg : >> On Wed, Jun 27, 2018 at 10:31 PM, Marko Rauhamaa >> wrote: >>> Dan Stromberg : >>> >> > The problem can be solved by turning on the SO_REUSEADDR flag of >>> >> > the socket. >>> > BTW, it's a security feature you're turning off. If you're on a >>> > multiuser box, it prevents a second user from stealing lingering >>> > connections from a first user on the same port. >>> >>> Can you provide a brief proof of concept? >>> >> https://stackoverflow.com/questions/19960475/problems-related-to-so- reuseaddr > > I'm sorry but I couldn't find a working example behind the link. Could > you demonstrate the problem with a few lines of Python. Do you think attackers are limited to a few lines of Python? If you are asking from academic curiosity, limited by care factor ("I care about this enough to read a few lines of Python but not 100 lines or 20 lines of C...") that's fair enough. But if you're trying to express skepticism that this is a genuine concern, then "a few lines of Python" is an unreasonable limitation. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From tjreedy at udel.edu Thu Jun 28 20:52:25 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 Jun 2018 20:52:25 -0400 Subject: I lost nearly all my modules installing 3.7 In-Reply-To: <0001HW.20E59C82038DC45270000F6362CF@news.giganews.com> References: <0001HW.20E54D9E037B46DA700000D972CF@news.giganews.com> <0001HW.20E59C82038DC45270000F6362CF@news.giganews.com> Message-ID: On 6/28/2018 6:45 PM, Elliott Roper wrote: > On 28 Jun 2018, Terry Reedy wrote >> There is a pip command for making an editable file of installed >> packages. Run that in 3.6, perhaps after updating everything. >> >> >> There is another pip command for using that file to install everything >> listed. Run that in 3.7. > > I can't see the pip commands you mention for writing a file from 3.6 and > reading it back for 3.7 > Is it pip freeze -r followed by pip install -r? If so, what is > meant by 'the given requirements file' in the freeze options? 'pip freeze' sends the requirements list to stdout in alphabetical order. You redirect or copy-paste to a file. I have not done this, but apparently -r uses file as a template for selecting and ordering the requirements. I presume pip will ignore any versions in the template and list the actual installed versions. I believe you got the install right. > When I look inside site-packages in ~/Library (see below) I see many packages > that pip lists, but by no means all. F'instance numpy and scipy. They can be > found in /Library's site-packages however. >> >> >>> My understanding is that the whole $PATH is searched in order to resolve an >>> import, but it isn't. >> >> The OS searches the OS path, which you listed above. >> Python searches its sys.path, which it creates when started. >> Run >>> import sys; sys.path to see the contents. >> Unless macOS is more different than I think, you should see a 3.7 >> site-packages when running 3.7. > > Aha! That is most helpful > > Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) > [Clang 6.0 (clang-600.0.57)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > (python prompt)>>> import sys > .>>>sys.path > ['', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', # > no such file sys.path included directories that might be present. In this case, a zipped version of the stdlib. > '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', # 207 > items, none matching pip intstallable modules > '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib- > dynload',# 69 items, none matching pip installable modules > '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site- > packages'] # just pip and setuptools are in here > .>>> ^D site-packages is the default for 3rd parth packages. It can have .pth files that extend the directory to effectively include other directories. > EiPro:~ elliott$ python3.6 > Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31) > [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > .>>> import sys > (python prompt)>>> sys.path > ['', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', # > no such file > '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', # 207 > items, none matching pip intstallable modules > '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib- > dynload',# 65 items, none matching pip installable modules > '/Users/elliott/Library/Python/3.6/lib/python/site-packages', # 103 items > some matching items that appear in pip3.6 list > '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- > packages'] # numpy, scipy, pandas etc. are here. These might have been > modules I needed sudo -H to update > .>>> > > What I did not make clear that my 'elliott' user is not an Administrator. If > I log into my admin account (which I hardly ever do), it thinks my Python3 is > 3.7, list there also shows the hugely abbreviated collection of modules > namely pip and setuptools. pip list shows a list of modules so old as to be > unrecognisable. I expect the system install to be 2.7, python3 link to 3.7 either because that is the most recent 3x installed or the most recent version. > It looks like I have a tangled mess. Is there a way of getting rid of all the > pythons except Apple's museum piece and starting again? It is a hobby for me. > I have no need for backward compatibility. I think if I could install 3.7 > site wide from my non-admin account, I would be happiest. The standard > install pretty much worked up to 3.6 > pip > Would it be safe to delete everything on python's sys.path and re-install > from the download .pkg I suspect you can get rid of 3.6, 3.5, 3.4, but I am not a Mac user. I hope someone who is answers. -- Terry Jan Reedy From Avon at f101.n1.z21.fsxnet Thu Jun 28 20:53:28 2018 From: Avon at f101.n1.z21.fsxnet (Avon) Date: Fri, 29 Jun 2018 12:53:28 +1200 Subject: Where's the junk coming from? References: Message-ID: <1203644199@f101.n1.z21.fsxnet> On 06/28/18, Tim Golden pondered and said... TG> (Wearing my List Moderator hat) TG> TG> Thanks very much for addressing this for us, and to Cameron and others TG> who did the detective work. I admit I assumed at first it was some kind TG> of odd attack perhaps related to a dissatisfied poster so I'm glad it TG> was a misconfiguration issue. Hi Tim. You're most welcome. I try to jump on anything amiss as soon as I know about it. At the time of posting this reply I have not re-linked the node with the issue to my NNTP server but will likely do so in a few more days time. I just want to give him some time to sort his end out first :) Best wishes from New Zealand Cheers, Paul. From ben+python at benfinney.id.au Thu Jun 28 20:58:34 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 29 Jun 2018 10:58:34 +1000 Subject: Should nested classes in an Enum be Enum members? References: <5B33A3D5.7060208@stoneleaf.us> <85h8lnci7h.fsf@benfinney.id.au> Message-ID: <85d0wacssl.fsf@benfinney.id.au> Ian Kelly writes: > On Thu, Jun 28, 2018 at 4:38 AM Ben Finney wrote: > > > > Ethan Furman writes: > > > > Specifically, I can't make sense of why someone would want to have a > > class that is simultaneously behaving as an enumerated type, *and* > > has an API of custom callable attributes. > > You don't see value in enum members having properties? Is a Python property a callable attribute? >>> class Lorem: ... @property ... def spam(self): ... print(self) ... >>> foo = Lorem() >>> foo.spam() <__main__.Lorem object at 0x7ff5078bc710> Traceback (most recent call last): File "", line 1, in TypeError: 'NoneType' object is not callable It seems that no, a property is not a callable attribute. So I remain dumbfounded as to why anyone would want a class to *both* be an enumerated type, *and* have callable attributes in its API. -- \ ?It's dangerous to be right when the government is wrong.? | `\ ?Francois Marie Arouet Voltaire | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Thu Jun 28 21:00:15 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 29 Jun 2018 01:00:15 +0000 (UTC) Subject: Should nested classes in an Enum be Enum members? References: <5B33A3D5.7060208@stoneleaf.us> <5B35008F.3000102@stoneleaf.us> Message-ID: On Thu, 28 Jun 2018 08:36:47 -0700, Ethan Furman wrote: >>> Answer: >>> >>> - RED, GREEN, and BLUE are members >>> - lower and spam() are not >>> - SomeClass /is/ a member (but not its instances) >> >> Is that by accident or by design? > > By design. It is entirely possible to want an enum of types (int, > float, str, etc.). Seems strange to me. Why enum of types but not an enum of functions or methods? Perhaps you could have had an explicit decorator? class Colours(Enum): RED = 1 class Spam(object): pass @Enum.member class Eggs(object): pass Colours.Eggs will be an enum member, Spam will not be. But I suppose backwards compatibility rules that out. >> class Colour(Enum): >> class PrimaryColour(Enum): >> RED = 1 >> GREEN = 2 >> BLUE = 3 >> OCTARINE = 8 >> class SecondaryColour(Enum): >> PUCE = 101 >> MAUVE = 102 >> BEIGE = 103 >> TEAL = 104 > > This really seems to be the sticking point -- what should an Enum of > Enums look like? For example, should the above do > > --> list(Colour) > [Colour.PrimaryColour <...>, Colour.SecondaryColour <...>] > > or something else? I would expect the inner classes to disappear: [Colour.RED, Colour.GREEN, ... Colour.PUCE, ... ] unless I explicitly inspect their types: type(Colour.RED) => returns Colour.PrimaryColour But maybe there's another way to get that same effect? # ??? class PrimaryColour(Enum): RED = 1 ... class SecondaryColour(Enum): ... Colour = PrimaryColour + SecondaryColour -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From drsalists at gmail.com Thu Jun 28 21:04:16 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 28 Jun 2018 18:04:16 -0700 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: <87muvefyh1.fsf@elektro.pacujo.net> References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> Message-ID: On Thu, Jun 28, 2018 at 1:27 PM, Marko Rauhamaa wrote: > Dan Stromberg : > > On Wed, Jun 27, 2018 at 10:31 PM, Marko Rauhamaa > wrote: > >> Dan Stromberg : > >> >> > The problem can be solved by turning on the SO_REUSEADDR flag of > >> >> > the socket. > >> > BTW, it's a security feature you're turning off. If you're on a > >> > multiuser box, it prevents a second user from stealing lingering > >> > connections from a first user on the same port. > >> > >> Can you provide a brief proof of concept? > >> > > https://stackoverflow.com/questions/19960475/problems- > related-to-so-reuseaddr > > I'm sorry but I couldn't find a working example behind the link. Could > you demonstrate the problem with a few lines of Python. It's more practical to use English: Start an echo server process P that listens on tcp/5555. Initiate a connection from a client machine to process P at tcp/5555. It works as expected. Kill P. Initiate a connection from a client machine to process P at tcp/5555. It gives a connection refused as expected. If someone else comes along soon after and starts a different echo server process Q at tcp/5555 on the same server, it starts up immediately if P used SO_REUSEADDR. Then initiate a connection from the same (or different) client machine to process P (which no longer exists). Q gets the data intended for P. Naturally, for an echo server, we're just illustrating. But if it were a daemon that supports password-based authentication, it could be a problem. As security issues go, it's not the most severe one you'll ever see. It pretty much assumes there are people on your server who you don't trust. This is not Python-specific. That's about all I have the patience for. I'm not sure I'm going to write a few programs to demonstrate the issue. It's really not a "few lines of python". From Avon at f101.n1.z21.fsxnet Thu Jun 28 21:05:13 2018 From: Avon at f101.n1.z21.fsxnet (Avon) Date: Fri, 29 Jun 2018 13:05:13 +1200 Subject: [OT] Why are BBSes? [was Where's the junk coming from?] References: Message-ID: <3596501758@f101.n1.z21.fsxnet> On 06/28/18, Grant Edwards pondered and said... GE> OK, I've got to ask... GE> Why are there still BBSes? GE> GE> Who even has a modem these days? [OK, I'll admit my 11 year old GE> Thinkpad T500 has a built-in POTS modem, but it's never been used.] Hi Grant. How long do you have? :) Most BBS are connected using the internet these days and mostly run for fun, nostalgic and curiosity reasons by former and new sysops. Most systems don't enjoy the caller numbers of the heyday 1990s but rather are largely used by the sysop to engage in message networks and the BBS community that exists in 2018. I was a former sysop in my 20s in the 1990s and got back in to it around 2013. What I have found is that the scene is again growing, mostly due to nostalgia, but also out of a desire to escape big-brother social media e.g Facebook. People also like the simple UI for reading messages etc. As to the how... well, messages / files etc. are now largely sent via the internet not POTS (plain old telephone) and BinkP is a popular protocol using port 24554. BBS software is still under active development by a few authors who have kept their offerings in step with 2018. So I use Mystic BBS (mysticbbs.com) and you will see it offers a bunch of services and runs on Linux, Windows, Raspberry Pi. I also run a message network called fsxNet (fun, simple, experimental network) that has nodes in USA, New Zealand, Europe, Asia etc. you can find out more by heading to bbs.nz or download an infopack at bbs.nz/fsxnet.zip. Lastly info about setting up Mystic can be found on a YouTube channel I set up called Mystic Guy (there ends the sales pitch :)) Other developers of BBS software active in 2018 include Synchronet BBS, now offerings including Magicka BBS, Enigma1/2 BBS... and WWIV is still about too. Hope that helps, perhaps intrigues you further. I'm happy to answer any questions and/or offer support to folks interested in this stuff. Python is being added to Mystic as a scripting tool by the author at the moment so this newsgroup / mail list is of interest to a bunch of folks :) Best, Paul From steve+comp.lang.python at pearwood.info Thu Jun 28 21:12:25 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 29 Jun 2018 01:12:25 +0000 (UTC) Subject: Should nested classes in an Enum be Enum members? References: <5B33A3D5.7060208@stoneleaf.us> <85h8lnci7h.fsf@benfinney.id.au> Message-ID: On Thu, 28 Jun 2018 20:34:58 +1000, Ben Finney wrote: > Ethan Furman writes: > >> Consider the following Enum definition: >> >> class Color(Enum): >> RED = 1 >> GREEN = 2 >> BLUE = 3 >> @property >> def lower(self): >> return self.name.lower() >> def spam(self): >> return "I like %s eggs and spam!" % self.lower >> class SomeClass: >> pass > > That dumbfounds my intuitions. > > Specifically, I can't make sense of why someone would want to have a > class that is simultaneously behaving as an enumerated type, *and* has > an API of custom callable attributes. The PEP gives an example of enumerated members that themselves have methods. https://www.python.org/dev/peps/pep-0435/ There was another example somewhere (I don't remember where) of an enumeration of the planets, where planets can have attributes and methods: Planet.MARS.mass Planet.JUPITER.moons() which is no more weird than this: class Planet(Enum): MARS = "the red planet" Planet.MARS.upper() -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From ethan at stoneleaf.us Thu Jun 28 21:33:31 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 28 Jun 2018 18:33:31 -0700 Subject: Should nested classes in an Enum be Enum members? In-Reply-To: <85d0wacssl.fsf@benfinney.id.au> References: <5B33A3D5.7060208@stoneleaf.us> <85h8lnci7h.fsf@benfinney.id.au> <85d0wacssl.fsf@benfinney.id.au> Message-ID: <5B358C6B.7040406@stoneleaf.us> On 06/28/2018 05:58 PM, Ben Finney wrote: > So I remain dumbfounded as to why anyone would want a class to *both* be > an enumerated type, *and* have callable attributes in its API. Perhaps I am using Enum incorrectly, but here is my FederalHoliday Enum. Note that date(), next_business_day, and year() are all callables. The AutoEnum parent assigns values from 1 to n for each member. It's at Stackoverflow [1] if you'd like up- or down-vote it. ;) --- class FederalHoliday(AutoEnum): NewYear = "First day of the year.", 'absolute', Month.JANUARY, 1 MartinLutherKingJr = "Birth of Civil Rights leader.", 'relative', Month.JANUARY, Weekday.MONDAY, 3 President = "Birth of George Washington", 'relative', Month.FEBRUARY, Weekday.MONDAY, 3 Memorial = "Memory of fallen soldiers", 'relative', Month.MAY, Weekday.MONDAY, 5 Independence = "Declaration of Independence", 'absolute', Month.JULY, 4 Labor = "American Labor Movement", 'relative', Month.SEPTEMBER, Weekday.MONDAY, 1 Columbus = "Americas discovered", 'relative', Month.OCTOBER, Weekday.MONDAY, 2 Veterans = "Recognition of Armed Forces service", 'relative', Month.NOVEMBER, 11, 1 Thanksgiving = "Day of Thanks", 'relative', Month.NOVEMBER, Weekday.THURSDAY, 4 Christmas = "Birth of Jesus Christ", 'absolute', Month.DECEMBER, 25 def __init__(self, doc, type, month, day, occurance=None): self.__doc__ = doc self.type = type self.month = month self.day = day self.occurance = occurance def date(self, year): "returns the observed date of the holiday for `year`" if self.type == 'absolute' or isinstance(self.day, int): holiday = Date(year, self.month, self.day) if Weekday(holiday.isoweekday()) is Weekday.SUNDAY: holiday = holiday.replace(delta_day=1) return holiday days_in_month = days_per_month(year) target_end = self.occurance * 7 + 1 if target_end > days_in_month[self.month]: target_end = days_in_month[self.month] target_start = target_end - 7 target_week = list(xrange(start=Date(year, self.month, target_start), step=one_day, count=7)) for holiday in target_week: if Weekday(holiday.isoweekday()) is self.day: return holiday @classmethod def next_business_day(cls, date, days=1): """ Return the next `days` business day from date. """ holidays = cls.year(date.year) years = set([date.year]) while days > 0: date = date.replace(delta_day=1) if date.year not in years: holidays.extend(cls.year(date.year)) years.add(date.year) if Weekday(date.isoweekday()) in (Weekday.SATURDAY, Weekday.SUNDAY) or date in holidays: continue days -= 1 return date @classmethod def year(cls, year): """ Return a list of the actual FederalHoliday dates for `year`. """ holidays = [] for fh in cls: holidays.append(fh.date(year)) return holidays -- ~Ethan~ [1] https://stackoverflow.com/a/22594360/208880 From ben+python at benfinney.id.au Fri Jun 29 00:03:41 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 29 Jun 2018 14:03:41 +1000 Subject: Should nested classes in an Enum be Enum members? References: <5B33A3D5.7060208@stoneleaf.us> <85h8lnci7h.fsf@benfinney.id.au> <85d0wacssl.fsf@benfinney.id.au> <5B358C6B.7040406@stoneleaf.us> Message-ID: <858t6yck82.fsf@benfinney.id.au> Ethan Furman writes: > On 06/28/2018 05:58 PM, Ben Finney wrote: > > > So I remain dumbfounded as to why anyone would want a class to *both* be > > an enumerated type, *and* have callable attributes in its API. > > Perhaps I am using Enum incorrectly, but here is my FederalHoliday > Enum. [?] Thanks for the example. Yes, my personal impression is that class is not a good use of enum.Enum (nor enum.AutoEnum). To inherit from enum.Enum (or enum.AutoEnum) signals, to my mind, that the class is not really intended as a typical Python class, but instead is intended to be that special beast known as an ?enumerated type? which has little behaviour other than being a namespace for constant values. Adding all that other stuff just makes it quite unclear what the class means any more. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but me and Pippi Longstocking ? I mean, what would the | _o__) children look like?? ?_Pinky and The Brain_ | Ben Finney From tjreedy at udel.edu Fri Jun 29 01:04:07 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Jun 2018 01:04:07 -0400 Subject: [OT] Why are BBSes? [was Where's the junk coming from?] In-Reply-To: <3596501758@f101.n1.z21.fsxnet> References: <3596501758@f101.n1.z21.fsxnet> Message-ID: On 6/28/2018 9:05 PM, Avon wrote: > On 06/28/18, Grant Edwards pondered and said... > > GE> OK, I've got to ask... > GE> Why are there still BBSes? > GE> > GE> Who even has a modem these days? [OK, I'll admit my 11 year old > GE> Thinkpad T500 has a built-in POTS modem, but it's never been used.] > > Hi Grant. > > How long do you have? :) > > Most BBS are connected using the internet these days and mostly run for fun, > nostalgic and curiosity reasons by former and new sysops. Most systems don't > enjoy the caller numbers of the heyday 1990s but rather are largely used by > the sysop to engage in message networks and the BBS community that exists in > 2018. > > I was a former sysop in my 20s in the 1990s and got back in to it around > 2013. What I have found is that the scene is again growing, mostly due to > nostalgia, but also out of a desire to escape big-brother social media e.g > Facebook. Being able to send messages by ham radio is useful in disasters as well as nostalgic. I just don't know what people are doing these days. > People also like the simple UI for reading messages etc. > > As to the how... well, messages / files etc. are now largely sent via the > internet not POTS (plain old telephone) and BinkP is a popular protocol using > port 24554. > > BBS software is still under active development by a few authors who have kept > their offerings in step with 2018. So I use Mystic BBS (mysticbbs.com) and > you will see it offers a bunch of services and runs on Linux, Windows, > Raspberry Pi. I also run a message network called fsxNet (fun, simple, > experimental network) that has nodes in USA, New Zealand, Europe, Asia etc. > you can find out more by heading to bbs.nz or download an infopack at > bbs.nz/fsxnet.zip. Lastly info about setting up Mystic can be found on a > YouTube channel I set up called Mystic Guy (there ends the sales pitch :)) > > Other developers of BBS software active in 2018 include Synchronet BBS, now > offerings including Magicka BBS, Enigma1/2 BBS... and WWIV is still about too. > > Hope that helps, perhaps intrigues you further. I'm happy to answer any > questions and/or offer support to folks interested in this stuff. Python is > being added to Mystic as a scripting tool by the author at the moment so this > newsgroup / mail list is of interest to a bunch of folks :) > > Best, Paul > -- Terry Jan Reedy From marko at pacujo.net Fri Jun 29 01:30:02 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 29 Jun 2018 08:30:02 +0300 Subject: EXTERNAL: OSError: [Errno 48] Address already in use References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> Message-ID: <877emif9d1.fsf@elektro.pacujo.net> Dan Stromberg : > [on how SO_REUSEADDR is a security risk] > Start an echo server process P that listens on tcp/5555. > > Initiate a connection from a client machine to process P at tcp/5555. It > works as expected. > > Kill P. > > Initiate a connection from a client machine to process P at tcp/5555. It > gives a connection refused as expected. > > If someone else comes along soon after and starts a different echo server > process Q at tcp/5555 on the same server, it starts up immediately if P > used SO_REUSEADDR. > > Then initiate a connection from the same (or different) client machine to > process P (which no longer exists). Q gets the data intended for P. Well, the same security issue can be demonstrated without SO_REUSEADDR: DON'T start an echo server process P that listens on tcp/5555. Initiate a connection from a client machine to process P at tcp/5555. It gives a connection refused as expected. If someone else comes along and starts an echo server process Q at tcp/5555 on the same server, it starts up immediately. Then initiate a connection from the same (or different) client machine to process P (which never existed). Q gets the data intended for P. The security issue can be real but is not directly related with SO_REUSEADDR. Marko From steve+comp.lang.python at pearwood.info Fri Jun 29 01:52:36 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 29 Jun 2018 05:52:36 +0000 (UTC) Subject: Should nested classes in an Enum be Enum members? References: <5B33A3D5.7060208@stoneleaf.us> <85h8lnci7h.fsf@benfinney.id.au> <85d0wacssl.fsf@benfinney.id.au> <5B358C6B.7040406@stoneleaf.us> Message-ID: On Thu, 28 Jun 2018 18:33:31 -0700, Ethan Furman wrote: > On 06/28/2018 05:58 PM, Ben Finney wrote: > >> So I remain dumbfounded as to why anyone would want a class to *both* >> be an enumerated type, *and* have callable attributes in its API. > > Perhaps I am using Enum incorrectly, but here is my FederalHoliday Enum. > Note that date(), next_business_day, and year() are all callables. The > AutoEnum parent assigns values from 1 to n for each member. It's at > Stackoverflow [1] if you'd like up- or down-vote it. ;) It isn't clear to me why FederalHoliday is an Enum, especially as the API seems extremely baraque. > class FederalHoliday(AutoEnum): > NewYear = "First day of the year.", 'absolute', Month.JANUARY, 1 > MartinLutherKingJr = "Birth of Civil Rights leader.", \ > 'relative', Month.JANUARY, Weekday.MONDAY, 3 ... I think I get the idea... the first field is a description, the second tells us what month the holiday is in (hope you don't have to deal with movable holidays which can change months...). I'm not quite sure what the "absolute/relative" flags are (or why they are strings instead of enums). Possibly they determine whether the next field is treated as an ordinal (first, second, third...) or numerical (1, 2, 3...) value. But what isn't clear to me is why these holidays are *enums*. They're obviously date instances, with a rich API (at least three methods) and an extremely complex constructor (one with variable numbers of arguments). What makes them enums? Under what circumstances would you be comparing something to MartinLutherKingJr (Day) without caring about a *specific* Martin Luther King Jr Day? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From ian.g.kelly at gmail.com Fri Jun 29 03:17:02 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 29 Jun 2018 01:17:02 -0600 Subject: Should nested classes in an Enum be Enum members? In-Reply-To: <85d0wacssl.fsf@benfinney.id.au> References: <5B33A3D5.7060208@stoneleaf.us> <85h8lnci7h.fsf@benfinney.id.au> <85d0wacssl.fsf@benfinney.id.au> Message-ID: On Thu, Jun 28, 2018 at 7:01 PM Ben Finney wrote: > > Ian Kelly writes: > > > On Thu, Jun 28, 2018 at 4:38 AM Ben Finney wrote: > > > > > > Ethan Furman writes: > > > > > > Specifically, I can't make sense of why someone would want to have a > > > class that is simultaneously behaving as an enumerated type, *and* > > > has an API of custom callable attributes. > > > > You don't see value in enum members having properties? > > Is a Python property a callable attribute? I was referring to properties generically in the OOP sense, not to Python properties specifically. From amit.singh2241 at gmail.com Fri Jun 29 03:42:42 2018 From: amit.singh2241 at gmail.com (amit.singh2241 at gmail.com) Date: Fri, 29 Jun 2018 00:42:42 -0700 (PDT) Subject: Python27.dll module error from Python 2.7.15/PCbuild/get_externals.bat Message-ID: <7bc68fe3-806b-4514-8d12-3e3c508cb3c1@googlegroups.com> I am trying to compile the freshly downloaded Python 2.7.15. When the PCBuild/build.bat goes to pull-in the external modules along with their dependencies it encounters this error for each of the external modules. F:\Dev\depot\tools\source\python\Python-2.7.15>.\PCbuild\get_externals.bat Using "F:\Dev\depot\tools\source\python\Python-2.7.15\PCbuild\\..\externals\pyth onx86\tools\python.exe" (found in externals directory) Fetching external libraries... e is e Fetching bzip2-1.0.6... Traceback (most recent call last): File "F:\Dev\depot\tools\source\python\Python-2.7.15\PCbuild\\get_external.py" , line 7, in from urllib.request import urlretrieve File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools \lib\urllib\request.py", line 88, in import http.client File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools \lib\http\client.py", line 71, in import email.parser File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools \lib\email\parser.py", line 12, in from email.feedparser import FeedParser, BytesFeedParser File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools \lib\email\feedparser.py", line 27, in from email._policybase import compat32 File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools \lib\email\_policybase.py", line 9, in from email.utils import _has_surrogates File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools \lib\email\utils.py", line 29, in import socket File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools \lib\socket.py", line 49, in import _socket ImportError: Module use of python27.dll conflicts with this version of Python. Fetching bsddb-4.7.25.0... Traceback (most recent call last): File "F:\Dev\depot\tools\source\python\Python-2.7.15\PCbuild\\get_external.py" I tried installing python versions 3.6.4 and 2.7.15 to see if it works because I read in the build script that if python is already installed then it will use that else it will install it's own python in externals and use it. But no luck! It keeps giving me the same error again and again. Even if I execute "builds.bat -e" it gets into the same trap though it goes ahead and compiles but then compiler throws error due to half-baked external modules. Any help will be highly appreciated ! --Amit Kumar Singh From ian.g.kelly at gmail.com Fri Jun 29 04:01:24 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 29 Jun 2018 02:01:24 -0600 Subject: Should nested classes in an Enum be Enum members? In-Reply-To: <858t6yck82.fsf@benfinney.id.au> References: <5B33A3D5.7060208@stoneleaf.us> <85h8lnci7h.fsf@benfinney.id.au> <85d0wacssl.fsf@benfinney.id.au> <5B358C6B.7040406@stoneleaf.us> <858t6yck82.fsf@benfinney.id.au> Message-ID: On Thu, Jun 28, 2018 at 10:06 PM Ben Finney wrote: > > Ethan Furman writes: > > > On 06/28/2018 05:58 PM, Ben Finney wrote: > > > > > So I remain dumbfounded as to why anyone would want a class to *both* be > > > an enumerated type, *and* have callable attributes in its API. > > > > Perhaps I am using Enum incorrectly, but here is my FederalHoliday > > Enum. [?] > > Thanks for the example. Yes, my personal impression is that class > is not a good use of enum.Enum (nor enum.AutoEnum). > > To inherit from enum.Enum (or enum.AutoEnum) signals, to my mind, that > the class is not really intended as a typical Python class, but instead > is intended to be that special beast known as an ?enumerated type? which > has little behaviour other than being a namespace for constant values. That sounds like a C attitude talking. Python enums are heavily inspired by Java enums, which also permit enum members to have attributes and methods. In fact, that planets example that Steven mentioned is ripped straight out of the Java documentation. You may find it weird, but I actually find it really, really useful to be able to attach methods to enums. For example: class Color(Enum): RED = 'red' GREEN = 'green' BLUE = 'blue' def __str__(self): return 'the color %s' % self.value How else is one to override the str() of an enum? Another example: @total_ordering class ChessPiece(Enum): PAWN = 1, 'P' KNIGHT = 2, 'N' BISHOP = 3, 'B' ROOK = 4, 'R' # ... @property def label(self): return self.value[1] def __lt__(self, other): assert isinstance(other, ChessPiece) return self.value < other.value This enum type defines its own ordering based on the relative values of the chess pieces. To be fair, Java does this a bit better than Python does. For example, Java allows enum methods to be overridden by individual enum members. This makes it easy to, e.g., implement a Strategy pattern where the Strategy of choice depends upon an enum value. If you want to do that in Python, you're pretty much stuck with passing either lambdas or functions defined elsewhere as part of the enum member's value. But we can do it, which leads us to our next example: def pawn_moves(board, from_square): "Generate all pawn moves possible from the given square." # ... def knight_moves(board, from_square): "Generate all knight moves possible from the given square." # ... def pawn_attacks(board, from_square): "Generate all squares that would be attacked by a pawn a the given square." # ... # ... class ChessPiece(Enum): PAWN = 'P', pawn_moves, pawn_attacks KNIGHT = 'N', knight_moves, knight_attacks BISHOP = 'B', bishop_moves, bishop_attacks ROOK = 'R', rook_moves, rook_attacks # ... def moves(self, board, from_square): return self.value[1](board, from_square) def attacks(self, board, from_square): return self.value[2](board, from_square) Now, elsewhere we can easily do something like: all_moves = [] for square in board: piece = board[square] if piece: all_moves.extend(piece.moves(board, square)) Et voila. ChessPiece is still an enum as it should be, and it also has a useful API on top of that. From blindanagram at nowhere.com Fri Jun 29 06:14:34 2018 From: blindanagram at nowhere.com (BlindAnagram) Date: Fri, 29 Jun 2018 11:14:34 +0100 Subject: Python 3.7 Windows Help Behaviour Message-ID: In Python 3.7.0 on Windows the help file (python370.chm) displays with a fixed line length and does not adjust its line length when the user expands the help window horizontally. This behaviour is different to that of the Python 3.6 help file (python360.chm) which adjusts its text to fit the horizontal width of the help window. Is this a deliberate change or one that can be turned on or off in some way (I prefer the Python 3.6 behaviour)? From breamoreboy at gmail.com Fri Jun 29 06:55:38 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Fri, 29 Jun 2018 11:55:38 +0100 Subject: Where's the junk coming from? In-Reply-To: <1203644199@f101.n1.z21.fsxnet> References: <1203644199@f101.n1.z21.fsxnet> Message-ID: On 29/06/18 01:53, Avon wrote: > On 06/28/18, Tim Golden pondered and said... > > TG> (Wearing my List Moderator hat) > TG> > TG> Thanks very much for addressing this for us, and to Cameron and others > TG> who did the detective work. I admit I assumed at first it was some kind > TG> of odd attack perhaps related to a dissatisfied poster so I'm glad it > TG> was a misconfiguration issue. > > Hi Tim. > > You're most welcome. I try to jump on anything amiss as soon as I know about > it. At the time of posting this reply I have not re-linked the node with the > issue to my NNTP server but will likely do so in a few more days time. I just > want to give him some time to sort his end out first :) > > Best wishes from New Zealand > > Cheers, Paul. > As the person who started this thread I'll add my thanks for trying to sort things. Nothing last night is a good start :-) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From mal at europython.eu Fri Jun 29 08:23:26 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Fri, 29 Jun 2018 14:23:26 +0200 Subject: EuroPython 2018: Invoices available Message-ID: We have great news ! After many months of sorting the UK VAT registration issue, we have finally been registered for VAT in the UK. This is the number, we?ve all been waiting for: GB 297620469 We?ve now generated all the missing invoices for existing purchases and hope that this will make it easier for companies to now register their employees as well. EuroPython 2018: Get your tickets before we sell out https://ep2018.europython.eu/en/registration/buy-tickets/ Downloading Invoices -------------------- If you have already purchased tickets, you can find the invoices in your account. Simply log in, go to the profile page, select ?Orders, invoices & coupons? on the right and you should find the invoice links for your orders. The invoices are generated as PDFs, so you can print or archive them easily. Sorry for keeping you waiting so long. 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/175370400437/europython-2018-invoices-available Tweet: https://twitter.com/europython/status/1012670816352382977 Enjoy, -- EuroPython 2018 Team https://ep2018.europython.eu/ https://www.europython-society.org/ From mal at europython.eu Fri Jun 29 08:23:38 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Fri, 29 Jun 2018 14:23:38 +0200 Subject: =?UTF-8?Q?EuroPython_2018:_Beginners=e2=80=99_Day_Workshop?= Message-ID: <8a8d6838-045e-095f-d8b4-979dc76507c0@europython.eu> Maybe you?ve come to EuroPython as a programmer from another language. Or perhaps you have other tech skills or you really want to understand what it?s like to program in Python. Then come to our Beginners? Day at EuroPython. https://ep2018.europython.eu/en/events/beginners-day/ What is Beginners? Day ? ------------------------ Beginners? Day is a session we are running, just for newcomers to the Python programming language, on Tuesday, July 24th from 09:30 - 16:45, at the Edinburgh International Conference Center (EICC), the EuroPython 2018 venue, and just in time to get you ready for all the talks which follow on Wednesday, Thursday and Friday. You will need a conference pass to attend, but otherwise, it?s free, so if you?re thinking of coming to the conference, but you?re new to Python or programming, this could be the session for you. The workshop will be run by: - Vincent D. Warmerdam (PyData Amsterdam) - Christian Barra (EuroPython board member) Sign up for Beginners? Day -------------------------- Whether you?re totally new to programming or you already know another language - this full day session will give you a crash-course in Python, and the ecosystem around it. You?ll get the context you need to get the most out of the rest of the EuroPython conference. Bring your laptop, because this will be a hands-on session! This session will be presented in English (although a few of the coaches do speak basic Spanish, French, Italian and Portuguese). Please see the Beginners? Day page for the full program: https://ep2018.europython.eu/en/events/beginners-day/ If you?d like to come, please do register in advance for this session, so that we know how to plan to make it the best yet. We need to know the numbers for planing the workshop. Sign up for Beginners? Day https://docs.google.com/forms/d/e/1FAIpQLSf7hTdKbYm_Jn8SSYNyC4iQXe-W68ndj93NxQacOSJKhyUeIQ/viewform Call for Mentors ---------------- Already know Python ? Want to be a mentor ? Fantastic ! Especially if you can add an extra language to help non-English speakers feel comfortable asking questions, or if you?ve never mentored before and want to try to share your knowledge for the first time. Please sign up as a mentor on our mentor registration form: https://docs.google.com/forms/d/e/1FAIpQLSdkqmu8o2R0FN7BqlaLrv5trOKHqhEQyHtt5_RR2kYhqI-pJw/viewform 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/175370423057/europython-2018-beginners-day-workshop Tweet: https://twitter.com/europython/status/1012671128790290432 Enjoy, -- EuroPython 2018 Team https://ep2018.europython.eu/ https://www.europython-society.org/ From brgrt2 at gmail.com Fri Jun 29 10:44:50 2018 From: brgrt2 at gmail.com (T Berger) Date: Fri, 29 Jun 2018 07:44:50 -0700 (PDT) Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: <90c0eb64-201e-4b69-9d11-014cd4068dc2@googlegroups.com> References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <90c0eb64-201e-4b69-9d11-014cd4068dc2@googlegroups.com> Message-ID: On Thursday, June 28, 2018 at 1:21:32 AM UTC-4, T Berger wrote: > Hi Guys, > > Thanks for all the suggestions. I found the problem. I had saved my program in IDLE and quit out of the shell, and then tried to run the program in Terminal. Previously, restarting the shell was enough to break the connection with the port. This time, I guess, it wasn't. So after thinking about your suggestions, I bypassed IDLE and went directly to Terminal, and the program worked. > > Tamara I have to backtrack on my optimistic pronouncement. I know why I'm getting "address already in use" error messages, but I don't know how to avoid getting them. The problem is that I'm working with both IDLE and my Terminal at the same time. I have to close out of IDLE in some decisive way so that the connection with the port is cut. Otherwise I will get the error message. At first, just restarting the shell in IDLE worked. Then I actually had to close the app (which didn't seem like a flexible option to me). Now, even quitting out of IDLE doesn't work. So my revised question is: How do I work with both apps together so these error messages don't keep recurring? Thanks, Tamara From brgrt2 at gmail.com Fri Jun 29 11:05:25 2018 From: brgrt2 at gmail.com (T Berger) Date: Fri, 29 Jun 2018 08:05:25 -0700 (PDT) Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <90c0eb64-201e-4b69-9d11-014cd4068dc2@googlegroups.com> Message-ID: On Friday, June 29, 2018 at 10:45:10 AM UTC-4, T Berger wrote: > On Thursday, June 28, 2018 at 1:21:32 AM UTC-4, T Berger wrote: > > Hi Guys, > > > > Thanks for all the suggestions. I found the problem. I had saved my program in IDLE and quit out of the shell, and then tried to run the program in Terminal. Previously, restarting the shell was enough to break the connection with the port. This time, I guess, it wasn't. So after thinking about your suggestions, I bypassed IDLE and went directly to Terminal, and the program worked. > > > > Tamara > > I have to backtrack on my optimistic pronouncement. I know why I'm getting "address already in use" error messages, but I don't know how to avoid getting them. The problem is that I'm working with both IDLE and my Terminal at the same time. I have to close out of IDLE in some decisive way so that the connection with the port is cut. Otherwise I will get the error message. At first, just restarting the shell in IDLE worked. Then I actually had to close the app (which didn't seem like a flexible option to me). Now, even quitting out of IDLE doesn't work. So my revised question is: How do I work with both apps together so these error messages don't keep recurring? > > Thanks, > > Tamara Addendum I'm using the flask test web address http://127.0.0.1:5000/ for both IDLE and Terminal. From bc at freeuk.com Fri Jun 29 11:55:29 2018 From: bc at freeuk.com (Bart) Date: Fri, 29 Jun 2018 16:55:29 +0100 Subject: Should nested classes in an Enum be Enum members? In-Reply-To: References: <5B33A3D5.7060208@stoneleaf.us> <85h8lnci7h.fsf@benfinney.id.au> <85d0wacssl.fsf@benfinney.id.au> <5B358C6B.7040406@stoneleaf.us> <858t6yck82.fsf@benfinney.id.au> Message-ID: On 29/06/2018 09:01, Ian Kelly wrote: > On Thu, Jun 28, 2018 at 10:06 PM Ben Finney wrote: > @total_ordering > class ChessPiece(Enum): > PAWN = 1, 'P' > KNIGHT = 2, 'N' > BISHOP = 3, 'B' > ROOK = 4, 'R' > # ... > > @property > def label(self): > return self.value[1] > > def __lt__(self, other): > assert isinstance(other, ChessPiece) > return self.value < other.value > > This enum type defines its own ordering based on the relative values > of the chess pieces. > class ChessPiece(Enum): > PAWN = 'P', pawn_moves, pawn_attacks > KNIGHT = 'N', knight_moves, knight_attacks > BISHOP = 'B', bishop_moves, bishop_attacks > ROOK = 'R', rook_moves, rook_attacks > # ... > > def moves(self, board, from_square): > return self.value[1](board, from_square) > > def attacks(self, board, from_square): > return self.value[2](board, from_square) > > Now, elsewhere we can easily do something like: > > all_moves = [] > for square in board: > piece = board[square] > if piece: > all_moves.extend(piece.moves(board, square)) > > Et voila. ChessPiece is still an enum as it should be, and it also has > a useful API on top of that. I get the feeling is that the enum (PAWN, BISHOP etc) is a property of a piece, rather than being the cornerstone of everything you might think of doing with a chess-piece. That thinking keeps the that property as a simple type, a simple enum of six distinct values with nothing else piled on top to complicate matters. And it means the same enum can be used in other contexts associated with chess where that other data may be irrelevant. -- bart From jlee54 at gmail.com Fri Jun 29 12:40:33 2018 From: jlee54 at gmail.com (Jim Lee) Date: Fri, 29 Jun 2018 09:40:33 -0700 Subject: [OT] Why are BBSes? [was Where's the junk coming from?] In-Reply-To: References: <3596501758@f101.n1.z21.fsxnet> Message-ID: <0db9d8c6-7db2-b2d3-dff5-dc5ac0ca6f2c@gmail.com> On 06/29/18 07:15, Dennis Lee Bieber wrote: > > On 6/28/2018 9:05 PM, Avon wrote: >> Being able to send messages by ham radio is useful in disasters as well >> as nostalgic. I just don't know what people are doing these days. >> > Though I haven't heard much of the AX.25 Packet BBS systems in > decades... It seems APRS is mostly what remains of packet. > > AX.25 Packet Radio BBS's are still alive and well, though the number of active nodes has decreased significantly over the past 20 years. There are 3 of them within a 50 mile radius of me, but I haven't tried passing a message from coast to coast in several years. I suspect that some nodes are tunneling via the Internet, which sort of defeats the purpose. -Jim From tjreedy at udel.edu Fri Jun 29 12:40:50 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Jun 2018 12:40:50 -0400 Subject: Python27.dll module error from Python 2.7.15/PCbuild/get_externals.bat In-Reply-To: <7bc68fe3-806b-4514-8d12-3e3c508cb3c1@googlegroups.com> References: <7bc68fe3-806b-4514-8d12-3e3c508cb3c1@googlegroups.com> Message-ID: On 6/29/2018 3:42 AM, amit.singh2241 at gmail.com wrote: > I am trying to compile the freshly downloaded Python 2.7.15. > When the PCBuild/build.bat goes to pull-in the external modules along with their dependencies it encounters this error for each of the external modules. > > F:\Dev\depot\tools\source\python\Python-2.7.15>.\PCbuild\get_externals.bat > Using "F:\Dev\depot\tools\source\python\Python-2.7.15\PCbuild\\..\externals\pyth > onx86\tools\python.exe" (found in externals directory) > Fetching external libraries... > e is e > Fetching bzip2-1.0.6... > Traceback (most recent call last): > File "F:\Dev\depot\tools\source\python\Python-2.7.15\PCbuild\\get_external.py" > , line 7, in > from urllib.request import urlretrieve > File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools > \lib\urllib\request.py", line 88, in > import http.client > File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools > \lib\http\client.py", line 71, in > import email.parser > File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools > \lib\email\parser.py", line 12, in > from email.feedparser import FeedParser, BytesFeedParser > File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools > \lib\email\feedparser.py", line 27, in > from email._policybase import compat32 > File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools > \lib\email\_policybase.py", line 9, in > from email.utils import _has_surrogates > File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools > \lib\email\utils.py", line 29, in > import socket > File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools > \lib\socket.py", line 49, in > import _socket > ImportError: Module use of python27.dll conflicts with this version of Python. > Fetching bsddb-4.7.25.0... > Traceback (most recent call last): > File "F:\Dev\depot\tools\source\python\Python-2.7.15\PCbuild\\get_external.py" > > I tried installing python versions 3.6.4 and 2.7.15 to see if it works because I read in the build script that if python is already installed then it will use that else it will install it's own python in externals and use it. > But no luck! It keeps giving me the same error again and again. Even if I execute "builds.bat -e" it gets into the same trap though it goes ahead and compiles but then compiler throws error due to half-baked external modules. > > Any help will be highly appreciated ! I updated my repository, including the 2.7 branch and ran PCbuild\build.bat -e -d Everything built fine, but no external fetches were done. I renamed the bz dir and built again. Using py -3.6 (found with py.exe) Fetching external libraries... Fetching bzip2-1.0.6... ... blocksort.c bzlib.c compress.c crctable.c decompress.c huffman.c randtable.c Generating Code... bz2.vcxproj -> f:\dev\27\PCBuild\bz2_d.pyd as expected. So the .bat files are ok. You had > Using "F:\Dev\depot\tools\source\python\Python-2.7.15\PCbuild\\..\externals\pyth > onx86\tools\python.exe" (found in externals directory) and got > ImportError: Module use of python27.dll conflicts with this version of Python. I don't understand that at all, but I would remove the python.exe within external, as it did not work, so it cannot be used. Did you install the py launcher when you installed 3.6 (3.6.6 was just released). Here is the list of what you need. Fetching bzip2-1.0.6... bsddb-4.7.25.0 already exists, skipping. openssl-1.0.2o already exists, skipping. sqlite-3.14.2.0 already exists, skipping. tcl-8.5.19.0 already exists, skipping. tk-8.5.19.0 already exists, skipping. tix-8.4.3.5 already exists, skipping. Fetching external binaries... nasm-2.11.06 already exists, skipping. I would delete anything not in the list. -- Terry Jan Reedy From jlee54 at gmail.com Fri Jun 29 12:50:17 2018 From: jlee54 at gmail.com (Jim Lee) Date: Fri, 29 Jun 2018 09:50:17 -0700 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <90c0eb64-201e-4b69-9d11-014cd4068dc2@googlegroups.com> Message-ID: On 06/29/18 08:05, T Berger wrote: > On Friday, June 29, 2018 at 10:45:10 AM UTC-4, T Berger wrote: >> On Thursday, June 28, 2018 at 1:21:32 AM UTC-4, T Berger wrote: >>> Hi Guys, >>> >>> Thanks for all the suggestions. I found the problem. I had saved my program in IDLE and quit out of the shell, and then tried to run the program in Terminal. Previously, restarting the shell was enough to break the connection with the port. This time, I guess, it wasn't. So after thinking about your suggestions, I bypassed IDLE and went directly to Terminal, and the program worked. >>> >>> Tamara >> I have to backtrack on my optimistic pronouncement. I know why I'm getting "address already in use" error messages, but I don't know how to avoid getting them. The problem is that I'm working with both IDLE and my Terminal at the same time. I have to close out of IDLE in some decisive way so that the connection with the port is cut. Otherwise I will get the error message. At first, just restarting the shell in IDLE worked. Then I actually had to close the app (which didn't seem like a flexible option to me). Now, even quitting out of IDLE doesn't work. So my revised question is: How do I work with both apps together so these error messages don't keep recurring? >> >> Thanks, >> >> Tamara > Addendum > > I'm using the flask test web address http://127.0.0.1:5000/ for both IDLE and Terminal. That's not a "web address" - it's the address of your own machine. In other words, you're connecting to yourself.? You can't use it simultaneously for both applications - you'll need to change the port number to something other than 5000 in one of them. -Jim From tjreedy at udel.edu Fri Jun 29 12:53:15 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Jun 2018 12:53:15 -0400 Subject: Python 3.7 Windows Help Behaviour In-Reply-To: References: Message-ID: On 6/29/2018 6:14 AM, BlindAnagram wrote: > In Python 3.7.0 on Windows the help file (python370.chm) displays with a > fixed line length and does not adjust its line length when the user > expands the help window horizontally. This behaviour is different to > that of the Python 3.6 help file (python360.chm) which adjusts its text > to fit the horizontal width of the help window. > > Is this a deliberate change or one that can be turned on or off in some > way (I prefer the Python 3.6 behaviour)? I believe that this is a deliberate regression imposed by 'experts' who believe in form over function and 'controlling the user experience'. 3.6.6 has been 'fixated' also. -- Terry Jan Reedy From ethan at stoneleaf.us Fri Jun 29 13:36:45 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 29 Jun 2018 10:36:45 -0700 Subject: Should nested classes in an Enum be Enum members? In-Reply-To: References: <5B33A3D5.7060208@stoneleaf.us> <85h8lnci7h.fsf@benfinney.id.au> <85d0wacssl.fsf@benfinney.id.au> <5B358C6B.7040406@stoneleaf.us> Message-ID: <5B366E2D.3080409@stoneleaf.us> On 06/28/2018 10:52 PM, Steven D'Aprano wrote: > On Thu, 28 Jun 2018 18:33:31 -0700, Ethan Furman wrote: >> Perhaps I am using Enum incorrectly, but here is my FederalHoliday Enum. >> Note that date(), next_business_day, and year() are all callables. The >> AutoEnum parent assigns values from 1 to n for each member. It's at >> Stackoverflow [1] if you'd like up- or down-vote it. ;) > > It isn't clear to me why FederalHoliday is an Enum, especially as the API > seems extremely baraque. Huh. I had to look that word up, and I still don't know what you meant exactly, although I suspect it wasn't complimentary. ;-) >> class FederalHoliday(AutoEnum): >> NewYear = "First day of the year.", 'absolute', Month.JANUARY, 1 >> MartinLutherKingJr = "Birth of Civil Rights leader.", \ >> 'relative', Month.JANUARY, Weekday.MONDAY, 3 > ... > > > I think I get the idea... the first field is a description, the second > tells us what month the holiday is in (hope you don't have to deal with > movable holidays which can change months...). I'm not quite sure what the > "absolute/relative" flags are (or why they are strings instead of enums). > Possibly they determine whether the next field is treated as an ordinal > (first, second, third...) or numerical (1, 2, 3...) value. - description - type (absolute or relative) - month - if absolute: - date - else: - week day - which one > But what isn't clear to me is why these holidays are *enums*. They're > obviously date instances, with a rich API (at least three methods) and an > extremely complex constructor (one with variable numbers of arguments). They are the list of dates in which US banks are closed for electronic business (funds transfers and things). > What makes them enums? Under what circumstances would you be comparing > something to MartinLutherKingJr (Day) without caring about a *specific* > Martin Luther King Jr Day? Enums are also useful when the underlying value is relevant; the usual example is communicating with other languages' APIs. While those relevant values may have no intrinsic value, why is it a problem if they do? -- ~Ethan~ From cs at cskk.id.au Fri Jun 29 18:59:55 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 30 Jun 2018 08:59:55 +1000 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: Message-ID: <20180629225955.GA75408@cskk.homeip.net> On 29Jun2018 09:50, Jim Lee wrote: >On 06/29/18 08:05, T Berger wrote: >>On Friday, June 29, 2018 at 10:45:10 AM UTC-4, T Berger wrote: >>>On Thursday, June 28, 2018 at 1:21:32 AM UTC-4, T Berger wrote: >>>I have to backtrack on my optimistic pronouncement. I know why I'm getting >>>"address already in use" error messages, but I don't know how to avoid >>>getting them. The problem is that I'm working with both IDLE and my >>>Terminal at the same time. I have to close out of IDLE in some decisive way >>>so that the connection with the port is cut. Otherwise I will get the error >>>message. At first, just restarting the shell in IDLE worked. Then I actually >>>had to close the app (which didn't seem like a flexible option to me). Now, >>>even quitting out of IDLE doesn't work. So my revised question is: How do I >>>work with both apps together so these error messages don't keep recurring? > >>Addendum >>I'm using the flask test web address http://127.0.0.1:5000/ for both IDLE and >>Terminal. > >That's not a "web address" - it's the address of your own machine. In >other words, you're connecting to yourself.? You can't use it >simultaneously for both applications - you'll need to change the port number >to something other than 5000 in one of them. The key point here from Jim is "simultaneously". Are you properly shutting down the Flask instance in IDLE before running from Terminal, and vice versa? Otherwise both will try to use the same local port and There Can Be Only One. Do you need to run from both environments at the same time? I'd have thought not, which also leads me to: why are you flicking from IDLE to Terminal? I would have imagined using one or the other normally, not both. It isn't wrong to use both, just surprising. Cheers, Cameron Simpson From cs at cskk.id.au Fri Jun 29 19:02:37 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 30 Jun 2018 09:02:37 +1000 Subject: Should nested classes in an Enum be Enum members? In-Reply-To: <5B366E2D.3080409@stoneleaf.us> References: <5B366E2D.3080409@stoneleaf.us> Message-ID: <20180629230237.GA87879@cskk.homeip.net> On 29Jun2018 10:36, Ethan Furman wrote: >On 06/28/2018 10:52 PM, Steven D'Aprano wrote: >>On Thu, 28 Jun 2018 18:33:31 -0700, Ethan Furman wrote: >>>Perhaps I am using Enum incorrectly, but here is my FederalHoliday Enum. >>> Note that date(), next_business_day, and year() are all callables. The >>>AutoEnum parent assigns values from 1 to n for each member. It's at >>>Stackoverflow [1] if you'd like up- or down-vote it. ;) >> >>It isn't clear to me why FederalHoliday is an Enum, especially as the API >>seems extremely baraque. > >Huh. I had to look that word up, and I still don't know what you >meant exactly, although I suspect it wasn't complimentary. ;-) It tends to mean "weird", but perhaps a more nuanced phrasing might be unusual and strange, and usually connotes some degree of over complication. Cheers, Cameron Simpson From jlee54 at gmail.com Fri Jun 29 19:33:53 2018 From: jlee54 at gmail.com (Jim Lee) Date: Fri, 29 Jun 2018 16:33:53 -0700 Subject: Should nested classes in an Enum be Enum members? In-Reply-To: <20180629230237.GA87879@cskk.homeip.net> References: <5B366E2D.3080409@stoneleaf.us> <20180629230237.GA87879@cskk.homeip.net> Message-ID: On 06/29/18 16:02, Cameron Simpson wrote: > On 29Jun2018 10:36, Ethan Furman wrote: >> On 06/28/2018 10:52 PM, Steven D'Aprano wrote: >>> On Thu, 28 Jun 2018 18:33:31 -0700, Ethan Furman wrote: >>>> Perhaps I am using Enum incorrectly, but here is my FederalHoliday >>>> Enum. >>>> ?Note that date(), next_business_day, and year() are all >>>> callables.? The >>>> AutoEnum parent assigns values from 1 to n for each member. It's at >>>> Stackoverflow [1] if you'd like up- or down-vote it.? ;) >>> >>> It isn't clear to me why FederalHoliday is an Enum, especially as >>> the API >>> seems extremely baraque. >> >> Huh.? I had to look that word up, and I still don't know what you >> meant exactly, although I suspect it wasn't complimentary. ;-) > > It tends to mean "weird", but perhaps a more nuanced phrasing might be > unusual and strange, and usually connotes some degree of over > complication. > > Cheers, > Cameron Simpson It's actually "baroque", not "baraque", and Cameron has the right idea - lavish, extravagant, overly complicated. -Jim From greg.ewing at canterbury.ac.nz Fri Jun 29 20:05:36 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 30 Jun 2018 12:05:36 +1200 Subject: Should nested classes in an Enum be Enum members? In-Reply-To: References: <5B33A3D5.7060208@stoneleaf.us> <85h8lnci7h.fsf@benfinney.id.au> <85d0wacssl.fsf@benfinney.id.au> <5B358C6B.7040406@stoneleaf.us> <5B366E2D.3080409@stoneleaf.us> Message-ID: Ethan Furman wrote: > They are the list of dates in which US banks are closed for electronic > business (funds transfers and things). That sems like something that would be better specified in a configuration file than hard-wired into the code, in case the rules change. -- Greg From greg.ewing at canterbury.ac.nz Fri Jun 29 20:11:21 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 30 Jun 2018 12:11:21 +1200 Subject: Should nested classes in an Enum be Enum members? In-Reply-To: References: <5B366E2D.3080409@stoneleaf.us> <20180629230237.GA87879@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > It tends to mean "weird", but perhaps a more nuanced phrasing might be > unusual and strange, and usually connotes some degree of over complication. When used in a derogatory way it means "excessively elaborate". The Baroque period was characterised by extremely ornate architecture, music, etc. -- Greg From nospam at yrl.co.uk Fri Jun 29 20:33:28 2018 From: nospam at yrl.co.uk (Elliott Roper) Date: Sat, 30 Jun 2018 01:33:28 +0100 Subject: I lost nearly all my modules installing 3.7 References: <0001HW.20E54D9E037B46DA700000D972CF@news.giganews.com> <0001HW.20E59C82038DC45270000F6362CF@news.giganews.com> Message-ID: <0001HW.20E7075803E2CEB770000F6362CF@news.giganews.com> On 29 Jun 2018, Terry Reedy wrote (in article): > On 6/28/2018 6:45 PM, Elliott Roper wrote: > > On 28 Jun 2018, Terry Reedy wrote > > > > There is a pip command for making an editable file of installed > > > packages. Run that in 3.6, perhaps after updating everything. > > > > > > > > > There is another pip command for using that file to install everything > > > listed. Run that in 3.7. > > > > I can't see the pip commands you mention for writing a file from 3.6 > and > > reading it back for 3.7 > > Is it pip freeze -r followed by pip install -r? If so, what is > > meant by 'the given requirements file' in the freeze options? > > 'pip freeze' sends the requirements list to stdout in alphabetical > order. You redirect or copy-paste to a file. I have not done this, but > apparently -r uses file as a template for selecting and ordering > the requirements. I presume pip will ignore any versions in the > template and list the actual installed versions. Thanks Terry. The freeze worked but the install -r looked like it was doing the right thing but ended up doing nothing after complaining about matplotlib being unable to install one of its dependencies IIRC I have deleted every trace of python following every element on sys.path for every version I had except for Apple's 2.6 and then reinstalled 3.7 from python.org's downloads. Then using the output from my 3.6 freeze, I installed each package on that list one by one with the --user option. That worked well except for two of the biggies I wanted to play with -- scipy and matplotlib. I did get numpy and pandas to install that way, which is a large part I need for what I am playing with. install scipy wrote an error message longer than War and Peace that finished with:- ____________________________________________________________________________ error: library dfftpack has Fortran sources but no Fortran compiler found ---------------------------------------- Command "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/v2/gj68t3zx3bd6764zxc332ctc0000gr/T/pi p-install-np76k73m/scipy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/v2/gj68t3zx3bd6764zxc332ctc0000gr/T/pip-record- 0norcg4s/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /private/var/folders/v2/gj68t3zx3bd6764zxc332ctc0000gr/T/pip-install- np76k73m/scipy/ ______________________________________________________________________________ _ and matplotlib produced a beautifully formatted report that started with: __________________ Complete output from command python setup.py egg_info: IMPORTANT WARNING: pkg-config is not installed. matplotlib may not be able to find some of its dependencies ============================================================================ Edit setup.cfg to change the build options _______________________ and finished with * The following required packages can not be built: * png ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/v2/gj68t3zx3bd6764zxc332ctc0000gr/T/pip-install- 3fnvrt2b/matplotlib/ ___________________________________________________ Both look like not having write access to /private/var/folders/v2/gj68t3zx3bd6764zxc332ctc0000gr/T/pip-install- np76k73m/ since I was installing with the --user switch, it looks like a bug in pip. It should have guessed I was a non-priviliged user. But then that "Edit setup.cfg to change the build options" is intriguing, especially since 'pip3 config list' returns nothing. Still. I have got a fair way there. Thanks so much for your help. It would be great if there were a Mac user with as much patience for numpties. To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96 3CF7 637F 896B C810 E199 7E5C A9E4 8E59 E248 From steve+comp.lang.python at pearwood.info Fri Jun 29 20:51:57 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 30 Jun 2018 00:51:57 +0000 (UTC) Subject: Baroque [was Re: Should nested classes in an Enum be Enum members?] References: <5B366E2D.3080409@stoneleaf.us> <20180629230237.GA87879@cskk.homeip.net> Message-ID: On Sat, 30 Jun 2018 09:02:37 +1000, Cameron Simpson wrote: > On 29Jun2018 10:36, Ethan Furman wrote: >>On 06/28/2018 10:52 PM, Steven D'Aprano wrote: >>>It isn't clear to me why FederalHoliday is an Enum, especially as the >>>API seems extremely baraque. >> >>Huh. I had to look that word up, and I still don't know what you meant >>exactly, although I suspect it wasn't complimentary. ;-) > > It tends to mean "weird", but perhaps a more nuanced phrasing might be > unusual and strange, and usually connotes some degree of over > complication. It might have helped if I spelled it correctly, sorry. It should not mean "weird or bizarre", although I've seen a couple of lesser-quality dictionaries give that as a meaning. Which is itself weird and bizarre :-) The more established meanings are: - literally, it refers to the Baroque style of art, music and architecture popular in Europe between (approximately) 1600 and 1750; - figuratively, it means to be highly ornate and elaborate, with strong connotations of being *excessively* complicated to the point of being convoluted. https://en.oxforddictionaries.com/definition/baroque http://www.dictionary.com/browse/baroque So not especially complimentary (sorry Ethan, but that was my first impression) but not *necessarily* a bad thing either. The Jargon File adjective that comes closest is probably gnarly: http://www.catb.org/jargon/html/G/gnarly.html but that's probably stronger with even worse connotations than baroque. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Fri Jun 29 20:57:40 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Jun 2018 10:57:40 +1000 Subject: Baroque [was Re: Should nested classes in an Enum be Enum members?] In-Reply-To: References: <5B366E2D.3080409@stoneleaf.us> <20180629230237.GA87879@cskk.homeip.net> Message-ID: On Sat, Jun 30, 2018 at 10:51 AM, Steven D'Aprano wrote: > ["Baroque"] should not mean "weird or bizarre", although I've seen a couple of > lesser-quality dictionaries give that as a meaning. Which is itself weird > and bizarre :-) > I guess those dictionaries are baroque. Or maybe just broke. ChrisA From steve+comp.lang.python at pearwood.info Fri Jun 29 22:12:58 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 30 Jun 2018 02:12:58 +0000 (UTC) Subject: Should nested classes in an Enum be Enum members? References: <5B33A3D5.7060208@stoneleaf.us> <85h8lnci7h.fsf@benfinney.id.au> <85d0wacssl.fsf@benfinney.id.au> <5B358C6B.7040406@stoneleaf.us> <5B366E2D.3080409@stoneleaf.us> Message-ID: On Fri, 29 Jun 2018 10:36:45 -0700, Ethan Furman wrote: >> What makes them enums? Under what circumstances would you be comparing >> something to MartinLutherKingJr (Day) without caring about a *specific* >> Martin Luther King Jr Day? > > Enums are also useful when the underlying value is relevant; the usual > example is communicating with other languages' APIs. While those > relevant values may have no intrinsic value, why is it a problem if they > do? But surely the underlying value of holidays *is* something we care about: the date it falls. We don't just care about "Martin Luther King Jr Day" as an abstraction, we do care about the specific day it falls, we care about its relationship to other days: - what's the last business day before MKKJ Day? - what's the next business day after it? - what's the date of it this year? - will it ever fall on my birthday? etc. I think that once we start adding methods to enums, we're starting to move into a gray area where they aren't *really* arbitrary enumerated values any longer. (Maybe.) If your methods use "self", then they implicitly care about the value of the enum. I think it's a matter of degree. Past a certain level of complexity, the object isn't an enum any more. I don't have a problem with the "planets" example for enums. (Maybe I should?) But your example seems to have crossed that line for me. At one extreme, we have pure symbols, or atoms, where the values don't support any significant operations apart from such trivial operations such as a human-readable string representation. Examples in Python include None, Ellipsis and NotImplemented. https://en.wikipedia.org/wiki/Symbol_%28programming%29 On the other extreme, we have rich, complex data types which support many non-trivial operations, like dicts, tuples, floats and web server objects. These typically (but not always) support a notion of equality beyond just identity. I think enums naturally belong very close to the Symbol end of the continuum, and I can't help but feel your Federal Holiday example is sufficiently far from that end that using Enum feels uncomfortable to me. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From ethan at stoneleaf.us Fri Jun 29 22:44:15 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 29 Jun 2018 19:44:15 -0700 Subject: Baroque [was Re: Should nested classes in an Enum be Enum members?] In-Reply-To: References: <5B366E2D.3080409@stoneleaf.us> <20180629230237.GA87879@cskk.homeip.net> Message-ID: <5B36EE7F.5070703@stoneleaf.us> On 06/29/2018 05:51 PM, Steven D'Aprano wrote: > So not especially complimentary (sorry Ethan, but that was my first > impression) but not *necessarily* a bad thing either. No worries! :) > The Jargon File adjective that comes closest is probably gnarly: Wow, I haven't heard that word in a long time. Just for the record: https://en.wiktionary.org/wiki/baraque baraque f (plural baraques) shack, hut stall, stand (colloquial) pad, crib (house) (informal) a musclehead So, you can see why I was confused! -- ~Ethan~ From Avon at f101.n1.z21.fsxnet Sat Jun 30 00:08:28 2018 From: Avon at f101.n1.z21.fsxnet (Avon) Date: Sat, 30 Jun 2018 16:08:28 +1200 Subject: Where's the junk coming from? References: Message-ID: <3996747038@f101.n1.z21.fsxnet> On 06/29/18, Mark Lawrence pondered and said... ML> As the person who started this thread I'll add my thanks for trying to ML> sort things. Nothing last night is a good start :-) Thanks Mark... you're welcome :) Best, Paul From dieter at handshake.de Sat Jun 30 00:48:59 2018 From: dieter at handshake.de (dieter) Date: Sat, 30 Jun 2018 06:48:59 +0200 Subject: I lost nearly all my modules installing 3.7 References: <0001HW.20E54D9E037B46DA700000D972CF@news.giganews.com> <0001HW.20E59C82038DC45270000F6362CF@news.giganews.com> <0001HW.20E7075803E2CEB770000F6362CF@news.giganews.com> Message-ID: <87a7rcangk.fsf@handshake.de> Elliott Roper writes: > ... > install scipy wrote an error message longer than War and Peace that finished > with:- > ____________________________________________________________________________ > error: library dfftpack has Fortran sources but no Fortran compiler found An error message of the type I like: precise: Install a "Fortran compiler" and try again. > ... > and matplotlib produced a beautifully formatted report that started with: > __________________ > Complete output from command python setup.py egg_info: > IMPORTANT WARNING: This is a warning only (even though it is marked as important). > pkg-config is not installed. > matplotlib may not be able to find some of its dependencies And the warning message is precise again: install "pkg-config" to get rid of it. I do not know "pkg-config". The name seems to indicate an operating system package; but, it might also be a Python extension package (less likely). I would start with the "matplotlib" installation instructions to look for information about it. From drsalists at gmail.com Sat Jun 30 01:07:42 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 29 Jun 2018 22:07:42 -0700 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: <877emif9d1.fsf@elektro.pacujo.net> References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <877emif9d1.fsf@elektro.pacujo.net> Message-ID: On Thu, Jun 28, 2018 at 10:30 PM, Marko Rauhamaa wrote: > Well, the same security issue can be demonstrated without SO_REUSEADDR: > > The security issue can be real but is not directly related with > SO_REUSEADDR. > Yes, it can. It just takes longer. From jlee54 at gmail.com Sat Jun 30 01:41:54 2018 From: jlee54 at gmail.com (Jim Lee) Date: Fri, 29 Jun 2018 22:41:54 -0700 Subject: I lost nearly all my modules installing 3.7 In-Reply-To: <87a7rcangk.fsf@handshake.de> References: <0001HW.20E54D9E037B46DA700000D972CF@news.giganews.com> <0001HW.20E59C82038DC45270000F6362CF@news.giganews.com> <0001HW.20E7075803E2CEB770000F6362CF@news.giganews.com> <87a7rcangk.fsf@handshake.de> Message-ID: <28a5b83c-e467-9820-fd46-ccdea6756788@gmail.com> On 06/29/18 21:48, dieter wrote: > > I do not know "pkg-config". The name seems to indicate an > operating system package; but, it might also be a Python extension > package (less likely). > I would start with the "matplotlib" > installation instructions to look for information about it. > https://www.freedesktop.org/wiki/Software/pkg-config/ "pkg-config is a helper tool used when compiling applications and libraries. It helps you insert the correct compiler options on the command line so an application can use|gcc -o test test.c `pkg-config --libs --cflags glib-2.0`|for instance, rather than hard-coding values on where to find glib (or other libraries). It is language-agnostic, so it can be used for defining the location of documentation tools, for instance." -Jim From amit.singh2241 at gmail.com Sat Jun 30 03:06:31 2018 From: amit.singh2241 at gmail.com (Amit Kumar Singh) Date: Sat, 30 Jun 2018 00:06:31 -0700 (PDT) Subject: Python27.dll module error from Python 2.7.15/PCbuild/get_externals.bat In-Reply-To: References: <7bc68fe3-806b-4514-8d12-3e3c508cb3c1@googlegroups.com> Message-ID: <743c442d-07fe-4bfa-a81f-0fe99fcf2eb7@googlegroups.com> Yes pylauncher was installed when I installed 3.6.4. Moreover, the python in externals\pythonx86 is supposed to be able to parse it's own code but it errors out in my case. Can you provide me the list of all the external modules with it's dependencies if possible ? I will pull those separately and avoid executing get_externals.bat. I pulled out a few external packages individually using git command and that was just fine. I believe if I have the full externals downloaded on my machine then the build should g just fine. Earlier with 2.7.14 the "svn co" command used to get all the external modules at once and that way the build was good but here in 2.7.15 the mechanism is changed a bit and now get_externals.py is used which errors out in my case. On Friday, June 29, 2018 at 10:11:16 PM UTC+5:30, Terry Reedy wrote: > On 6/29/2018 3:42 AM, amit.singh2241 at gmail.com wrote: > > I am trying to compile the freshly downloaded Python 2.7.15. > > When the PCBuild/build.bat goes to pull-in the external modules along with their dependencies it encounters this error for each of the external modules. > > > > F:\Dev\depot\tools\source\python\Python-2.7.15>.\PCbuild\get_externals.bat > > Using "F:\Dev\depot\tools\source\python\Python-2.7.15\PCbuild\\..\externals\pyth > > onx86\tools\python.exe" (found in externals directory) > > Fetching external libraries... > > e is e > > Fetching bzip2-1.0.6... > > Traceback (most recent call last): > > File "F:\Dev\depot\tools\source\python\Python-2.7.15\PCbuild\\get_external.py" > > , line 7, in > > from urllib.request import urlretrieve > > File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools > > \lib\urllib\request.py", line 88, in > > import http.client > > File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools > > \lib\http\client.py", line 71, in > > import email.parser > > File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools > > \lib\email\parser.py", line 12, in > > from email.feedparser import FeedParser, BytesFeedParser > > File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools > > \lib\email\feedparser.py", line 27, in > > from email._policybase import compat32 > > File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools > > \lib\email\_policybase.py", line 9, in > > from email.utils import _has_surrogates > > File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools > > \lib\email\utils.py", line 29, in > > import socket > > File "F:\Dev\depot\tools\source\python\Python-2.7.15\externals\pythonx86\tools > > \lib\socket.py", line 49, in > > import _socket > > ImportError: Module use of python27.dll conflicts with this version of Python. > > Fetching bsddb-4.7.25.0... > > Traceback (most recent call last): > > File "F:\Dev\depot\tools\source\python\Python-2.7.15\PCbuild\\get_external.py" > > > > I tried installing python versions 3.6.4 and 2.7.15 to see if it works because I read in the build script that if python is already installed then it will use that else it will install it's own python in externals and use it. > > But no luck! It keeps giving me the same error again and again. Even if I execute "builds.bat -e" it gets into the same trap though it goes ahead and compiles but then compiler throws error due to half-baked external modules. > > > > Any help will be highly appreciated ! > > I updated my repository, including the 2.7 branch and ran > PCbuild\build.bat -e -d > Everything built fine, but no external fetches were done. > I renamed the bz dir and built again. > > Using py -3.6 (found with py.exe) > Fetching external libraries... > Fetching bzip2-1.0.6... > ... > blocksort.c > bzlib.c > compress.c > crctable.c > decompress.c > huffman.c > randtable.c > Generating Code... > bz2.vcxproj -> f:\dev\27\PCBuild\bz2_d.pyd > as expected. So the .bat files are ok. > > You had > > Using > "F:\Dev\depot\tools\source\python\Python-2.7.15\PCbuild\\..\externals\pyth > > onx86\tools\python.exe" (found in externals directory) > and got > > ImportError: Module use of python27.dll conflicts with this version > of Python. > > I don't understand that at all, but I would remove the python.exe within > external, as it did not work, so it cannot be used. Did you install the > py launcher when you installed 3.6 (3.6.6 was just released). > > Here is the list of what you need. > Fetching bzip2-1.0.6... > bsddb-4.7.25.0 already exists, skipping. > openssl-1.0.2o already exists, skipping. > sqlite-3.14.2.0 already exists, skipping. > tcl-8.5.19.0 already exists, skipping. > tk-8.5.19.0 already exists, skipping. > tix-8.4.3.5 already exists, skipping. > Fetching external binaries... > nasm-2.11.06 already exists, skipping. > > I would delete anything not in the list. > > -- > Terry Jan Reedy From blindanagram at nowhere.com Sat Jun 30 03:42:54 2018 From: blindanagram at nowhere.com (BlindAnagram) Date: Sat, 30 Jun 2018 08:42:54 +0100 Subject: Python 3.7 Windows Help Behaviour In-Reply-To: References: Message-ID: <2J6dnWZcB__iqarGnZ2dnUU78UOdnZ2d@brightview.co.uk> On 29/06/2018 17:53, Terry Reedy wrote: > On 6/29/2018 6:14 AM, BlindAnagram wrote: >> In Python 3.7.0 on Windows the help file (python370.chm) displays with a >> fixed line length and does not adjust its line length when the user >> expands the help window horizontally.? This behaviour is different to >> that of the Python 3.6 help file (python360.chm) which adjusts its text >> to fit the horizontal width of the help window. >> >> Is this a deliberate change or one that can be turned on or off in some >> way (I prefer the Python 3.6 behaviour)? > > I believe that this is a deliberate regression imposed by 'experts' who > believe in form over function and 'controlling the user experience'. > 3.6.6 has been 'fixated' also. Thank you for your response. If you are right it is a pity that the user choice of width has been removed since it now looks stupidly narrow on my high resolution display. It looks like I will have to use the Python 3.6 file even in Python 3.7 :-( From steve+comp.lang.python at pearwood.info Sat Jun 30 05:43:00 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 30 Jun 2018 09:43:00 +0000 (UTC) Subject: Python 3.7 Windows Help Behaviour References: Message-ID: On Fri, 29 Jun 2018 12:53:15 -0400, Terry Reedy wrote: > On 6/29/2018 6:14 AM, BlindAnagram wrote: >> In Python 3.7.0 on Windows the help file (python370.chm) displays with >> a fixed line length and does not adjust its line length when the user >> expands the help window horizontally. This behaviour is different to >> that of the Python 3.6 help file (python360.chm) which adjusts its text >> to fit the horizontal width of the help window. >> >> Is this a deliberate change or one that can be turned on or off in some >> way (I prefer the Python 3.6 behaviour)? > > I believe that this is a deliberate regression imposed by 'experts' who > believe in form over function and 'controlling the user experience'. > 3.6.6 has been 'fixated' also. Sounds like somebody should raise a bug report. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From sharan.basappa at gmail.com Sat Jun 30 07:05:22 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 30 Jun 2018 04:05:22 -0700 (PDT) Subject: error in os.chdir Message-ID: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> 0 down vote favorite I need to change directory to my local working directory in windows and then open a file for processing. Its just a 3 lines code, as below: import csv import os os.chdir('D:\Projects\Initiatives\machine learning\programs\assertion') The error is as follows: WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'D:\Projects\Initiatives\machine learning\programs\x07ssertion' Notice x07 character that has replaced character x07. I have a similar code but that goes through fine: import csv import os os.chdir('D:\Projects\Initiatives\machine learning\programs') with open('example.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=',') The only difference is directory assertion in the problematic code. I have tried single quoting, double quoting etc. for the chdir directive but nothing helps. I have also tried escaping as \assertion but that is not the issue From Karsten.Hilbert at gmx.net Sat Jun 30 07:16:21 2018 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sat, 30 Jun 2018 13:16:21 +0200 Subject: error in os.chdir In-Reply-To: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: <20180630111621.GB6376@hermes.hilbert.loc> On Sat, Jun 30, 2018 at 04:05:22AM -0700, Sharan Basappa wrote: > I need to change directory to my local working directory in windows and then open a file for processing. > Its just a 3 lines code, as below: > import csv > import os > os.chdir('D:\Projects\Initiatives\machine learning\programs\assertion') > The error is as follows: > WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'D:\Projects\Initiatives\machine learning\programs\x07ssertion' > Notice x07 character that has replaced character x07. > I have a similar code but that goes through fine: > import csv > import os > os.chdir('D:\Projects\Initiatives\machine learning\programs') > > with open('example.csv') as csvfile: > readCSV = csv.reader(csvfile, delimiter=',') > The only difference is directory assertion in the problematic code. > I have tried single quoting, double quoting etc. for the chdir directive but nothing helps. I have also tried escaping as \assertion but that is not the issue The quick fix: put an r in front of the directory string: r'...' Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From rosuav at gmail.com Sat Jun 30 07:21:33 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Jun 2018 21:21:33 +1000 Subject: error in os.chdir In-Reply-To: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sat, Jun 30, 2018 at 9:05 PM, Sharan Basappa wrote: > > 0 > down vote > favorite > > I need to change directory to my local working directory in windows and then open a file for processing. > Its just a 3 lines code, as below: > import csv > import os > os.chdir('D:\Projects\Initiatives\machine learning\programs\assertion') > The error is as follows: > WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'D:\Projects\Initiatives\machine learning\programs\x07ssertion' > Notice x07 character that has replaced character x07. > I have a similar code but that goes through fine: > import csv > import os > os.chdir('D:\Projects\Initiatives\machine learning\programs') Use forward slashes instead of backslashes for all paths. os.chdir('D:/Projects/Initiatives/machine learning/programs') ChrisA From arj.python at gmail.com Sat Jun 30 07:27:35 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sat, 30 Jun 2018 15:27:35 +0400 Subject: naming methods in python (std lib) Message-ID: normally, naming methods in python is given by method_name but i see some cases where this is not followed in the std lib ex : dict.fromkeys should it not have been from_keys? Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ From sharan.basappa at gmail.com Sat Jun 30 07:47:44 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 30 Jun 2018 04:47:44 -0700 (PDT) Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> <20180630111621.GB6376@hermes.hilbert.loc> Message-ID: On Saturday, 30 June 2018 16:51:53 UTC+5:30, Karsten Hilbert wrote: > On Sat, Jun 30, 2018 at 04:05:22AM -0700, Sharan Basappa wrote: > > > I need to change directory to my local working directory in windows and then open a file for processing. > > Its just a 3 lines code, as below: > > import csv > > import os > > os.chdir('D:\Projects\Initiatives\machine learning\programs\assertion') > > The error is as follows: > > WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'D:\Projects\Initiatives\machine learning\programs\x07ssertion' > > Notice x07 character that has replaced character x07. > > I have a similar code but that goes through fine: > > import csv > > import os > > os.chdir('D:\Projects\Initiatives\machine learning\programs') > > > > with open('example.csv') as csvfile: > > readCSV = csv.reader(csvfile, delimiter=',') > > The only difference is directory assertion in the problematic code. > > I have tried single quoting, double quoting etc. for the chdir directive but nothing helps. I have also tried escaping as \assertion but that is not the issue > > The quick fix: > > put an r in front of the directory string: r'...' > > Karsten > -- > GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B thanks. That works From sharan.basappa at gmail.com Sat Jun 30 07:50:10 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 30 Jun 2018 04:50:10 -0700 (PDT) Subject: list initialize with ? Message-ID: Can anyone explain to me what the ? does here: ignore_words = ['?'] From sharan.basappa at gmail.com Sat Jun 30 08:01:26 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 30 Jun 2018 05:01:26 -0700 (PDT) Subject: $s and %d in python Message-ID: <9ca45498-9b40-4214-88b3-445545332f87@googlegroups.com> Is there any difference in %d and %s below. I get the same result: my_name = 'Zed A. Shaw' my_age = 35 # not a lie my_height = 74 # inches print "Let's talk about %s." % my_name print "He's %d inches tall." % my_height print "He's %s inches tall." % my_height Let's talk about Zed A. Shaw. He's 74 inches tall. He's 74 inches tall. From arj.python at gmail.com Sat Jun 30 08:07:22 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sat, 30 Jun 2018 16:07:22 +0400 Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: for user input, a replace might be the solution, using / in internal code Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Use forward slashes instead of backslashes for all paths. > > os.chdir('D:/Projects/Initiatives/machine learning/programs') > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From steve+comp.lang.python at pearwood.info Sat Jun 30 08:15:29 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 30 Jun 2018 12:15:29 +0000 (UTC) Subject: list initialize with ? References: Message-ID: On Sat, 30 Jun 2018 04:50:10 -0700, Sharan Basappa wrote: > Can anyone explain to me what the ? does here: > > ignore_words = ['?'] Its a question mark inside a string, which is inside a list. You can put anything you like in strings: 'a' 'abcde' even punctuation like '?'. Then you can put the string inside a list. What you do with it, I have no idea -- presumably its your code. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sat Jun 30 08:20:22 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 30 Jun 2018 12:20:22 +0000 (UTC) Subject: naming methods in python (std lib) References: Message-ID: On Sat, 30 Jun 2018 15:27:35 +0400, Abdur-Rahmaan Janhangeer wrote: > normally, naming methods in python is given by > > method_name > > but i see some cases where this is not followed in the std lib > > ex : dict.fromkeys > > should it not have been > > from_keys? Python is about 25 years old (1993 I think it was first released) and not all the names follow the same convention. Sometimes that's because the names pre-date the convention. Sometimes its because the name follows some other convention, e.g. most of the "is" names look like isinstance, issubclass, string.islower etc rather than is_instance, is_subclass, is_lower. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sat Jun 30 08:32:27 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 30 Jun 2018 12:32:27 +0000 (UTC) Subject: error in os.chdir References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> <20180630111621.GB6376@hermes.hilbert.loc> Message-ID: On Sat, 30 Jun 2018 04:47:44 -0700, Sharan Basappa wrote: >> The quick fix: >> >> put an r in front of the directory string: r'...' > > thanks. That works Please don't do that. It's the wrong solution -- all you are doing is postponing failure. It will *seem* to work, until one day you will write something like this: directory = r'D:\directory\' and you will get a mysterious failure. Chris gave you the right solution: use forward slashes instead of backslashes for all paths. os.chdir('D:/Projects/Initiatives/machine learning/programs') -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From sharan.basappa at gmail.com Sat Jun 30 08:46:59 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 30 Jun 2018 05:46:59 -0700 (PDT) Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> <20180630111621.GB6376@hermes.hilbert.loc> Message-ID: <0e8eaf4e-83af-4e36-a260-a166ee560094@googlegroups.com> On Saturday, 30 June 2018 18:05:02 UTC+5:30, Steven D'Aprano wrote: > On Sat, 30 Jun 2018 04:47:44 -0700, Sharan Basappa wrote: > > >> The quick fix: > >> > >> put an r in front of the directory string: r'...' > > > > thanks. That works > > Please don't do that. It's the wrong solution -- all you are doing is > postponing failure. It will *seem* to work, until one day you will write > something like this: > > directory = r'D:\directory\' > > and you will get a mysterious failure. Chris gave you the right solution: > use forward slashes instead of backslashes for all paths. > > os.chdir('D:/Projects/Initiatives/machine learning/programs') > > > > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson alright. I will do that but still I don't have an answer why I got the error in the first place. From sharan.basappa at gmail.com Sat Jun 30 08:49:03 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 30 Jun 2018 05:49:03 -0700 (PDT) Subject: list initialize with ? In-Reply-To: References: Message-ID: <7d02e275-3847-4220-a0d1-4d2abd6b839a@googlegroups.com> On Saturday, 30 June 2018 17:48:05 UTC+5:30, Steven D'Aprano wrote: > On Sat, 30 Jun 2018 04:50:10 -0700, Sharan Basappa wrote: > > > Can anyone explain to me what the ? does here: > > > > ignore_words = ['?'] > > Its a question mark inside a string, which is inside a list. You can put > anything you like in strings: > > 'a' > > 'abcde' > > even punctuation like '?'. Then you can put the string inside a list. > > What you do with it, I have no idea -- presumably its your code. > > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson oh, ok. I assumed that ? has some special meaning. I should be able to find out more. PS: Actually, its not my code. I am using an online code as reference for my research. From sharan.basappa at gmail.com Sat Jun 30 08:57:15 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 30 Jun 2018 05:57:15 -0700 (PDT) Subject: is my interpreation correct Message-ID: <70c46c14-c425-45fc-8174-e321e3e09848@googlegroups.com> A code I am using as reference has the following line: from nltk.stem.lancaster import LancasterStemmer I am inferring the following based on above: 1) nltk is a package 2) nltk itself may have module because I see - nltk.word_tokenize(pattern['sentence']) in the code 3) nltk has a package named stem which has another package named Lancaster that has LancasterStemmer package Somehow, I get confused with what is the package, module and function in third party packages like above. From Karsten.Hilbert at gmx.net Sat Jun 30 09:12:42 2018 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sat, 30 Jun 2018 15:12:42 +0200 Subject: error in os.chdir In-Reply-To: <0e8eaf4e-83af-4e36-a260-a166ee560094@googlegroups.com> References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> <20180630111621.GB6376@hermes.hilbert.loc> <0e8eaf4e-83af-4e36-a260-a166ee560094@googlegroups.com> Message-ID: <20180630131242.GD6376@hermes.hilbert.loc> On Sat, Jun 30, 2018 at 05:46:59AM -0700, Sharan Basappa wrote: > > >> The quick fix: > > >> > > >> put an r in front of the directory string: r'...' > > > > Please don't do that. It's the wrong solution -- all you are doing is > > postponing failure. It will *seem* to work, until one day you will write > > something like this: > > > > directory = r'D:\directory\' > > > > and you will get a mysterious failure. Chris gave you the right solution: > > use forward slashes instead of backslashes for all paths. > > alright. I will do that but still I don't have an answer why I got the error in the first place. For that you'll have to read up on strings and escaping. https://docs.python.org/2/tutorial/introduction.html#strings Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From blindanagram at nowhere.com Sat Jun 30 09:50:25 2018 From: blindanagram at nowhere.com (BlindAnagram) Date: Sat, 30 Jun 2018 14:50:25 +0100 Subject: Python 3.7 Windows Help Behaviour In-Reply-To: References: Message-ID: On 30/06/2018 10:43, Steven D'Aprano wrote: > On Fri, 29 Jun 2018 12:53:15 -0400, Terry Reedy wrote: > >> On 6/29/2018 6:14 AM, BlindAnagram wrote: >>> In Python 3.7.0 on Windows the help file (python370.chm) displays with >>> a fixed line length and does not adjust its line length when the user >>> expands the help window horizontally. This behaviour is different to >>> that of the Python 3.6 help file (python360.chm) which adjusts its text >>> to fit the horizontal width of the help window. >>> >>> Is this a deliberate change or one that can be turned on or off in some >>> way (I prefer the Python 3.6 behaviour)? >> >> I believe that this is a deliberate regression imposed by 'experts' who >> believe in form over function and 'controlling the user experience'. >> 3.6.6 has been 'fixated' also. > > Sounds like somebody should raise a bug report. I see that this has been done: https://bugs.python.org/issue34006 From sharan.basappa at gmail.com Sat Jun 30 10:34:46 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 30 Jun 2018 07:34:46 -0700 (PDT) Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> <20180630111621.GB6376@hermes.hilbert.loc> <0e8eaf4e-83af-4e36-a260-a166ee560094@googlegroups.com> <20180630131242.GD6376@hermes.hilbert.loc> Message-ID: <8592a986-cd16-439a-8d8a-4f95a13c1fcd@googlegroups.com> On Saturday, 30 June 2018 18:55:53 UTC+5:30, Karsten Hilbert wrote: > On Sat, Jun 30, 2018 at 05:46:59AM -0700, Sharan Basappa wrote: > > > > >> The quick fix: > > > >> > > > >> put an r in front of the directory string: r'...' > > > > > > Please don't do that. It's the wrong solution -- all you are doing is > > > postponing failure. It will *seem* to work, until one day you will write > > > something like this: > > > > > > directory = r'D:\directory\' > > > > > > and you will get a mysterious failure. Chris gave you the right solution: > > > use forward slashes instead of backslashes for all paths. > > > > alright. I will do that but still I don't have an answer why I got the error in the first place. > > For that you'll have to read up on strings and escaping. > > https://docs.python.org/2/tutorial/introduction.html#strings > > Karsten > -- > GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B sorry. I mean why my code worked in one case but did not in the other one. This worked - os.chdir('D:\Projects\Initiatives\machine learning\programs') This did not work - os.chdir('D:\Projects\Initiatives\machine learning\programs\assertion') only difference is, I added an additional directory in the problematic case. From Karsten.Hilbert at gmx.net Sat Jun 30 11:15:59 2018 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sat, 30 Jun 2018 17:15:59 +0200 Subject: error in os.chdir In-Reply-To: <8592a986-cd16-439a-8d8a-4f95a13c1fcd@googlegroups.com> References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> <20180630111621.GB6376@hermes.hilbert.loc> <0e8eaf4e-83af-4e36-a260-a166ee560094@googlegroups.com> <20180630131242.GD6376@hermes.hilbert.loc> <8592a986-cd16-439a-8d8a-4f95a13c1fcd@googlegroups.com> Message-ID: <20180630151559.GE6376@hermes.hilbert.loc> On Sat, Jun 30, 2018 at 07:34:46AM -0700, Sharan Basappa wrote: > sorry. I mean why my code worked in one case but did not in the other one. > > This worked - os.chdir('D:\Projects\Initiatives\machine learning\programs') > > This did not work - os.chdir('D:\Projects\Initiatives\machine learning\programs\assertion') > > only difference is, I added an additional directory in the problematic case. The answer lies in the (inadvertant) use of escaping. Which is the very reason _why_ forward slashes were favoured over backward ones. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From sharan.basappa at gmail.com Sat Jun 30 12:46:32 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 30 Jun 2018 09:46:32 -0700 (PDT) Subject: using trace module in enthought Message-ID: <5f2a977e-da7a-4e76-a0e2-dd8406518fec@googlegroups.com> I am using enthought for python. Trace module seems to be very useful for my work but somehow I am unable to make it work. When I use the following option, I get the following error: %run -m trace --trace "D:/Projects/Initiatives/machine learning/programs/debug_1.py" UsageError: option --trace not recognized ( allowed: "nidtN:b:pD:l:rs:T:em:G" ) %run -m trace --trace "D:/Projects/Initiatives/machine learning/programs/debug_1.py" --trace UsageError: option --trace not recognized ( allowed: "nidtN:b:pD:l:rs:T:em:G" ) %run -m trace "D:/Projects/Initiatives/machine learning/programs/debug_1.py" --trace D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\trace.py: must specify one of --trace, --count, --report, --listfuncs, or --trackcalls SystemExitTraceback (most recent call last) D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\runpy.pyc in run_module(mod_name, init_globals, run_name, alter_sys) 186 if alter_sys: 187 return _run_module_code(code, init_globals, run_name, --> 188 fname, loader, pkg_name) 189 else: 190 # Leave the sys module alone D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\runpy.pyc in _run_module_code(code, init_globals, mod_name, mod_fname, mod_loader, pkg_name) 80 mod_globals = temp_module.module.__dict__ 81 _run_code(code, mod_globals, init_globals, ---> 82 mod_name, mod_fname, mod_loader, pkg_name) 83 # Copy the globals of the temporary module, as they 84 # may be cleared when the temporary module goes away D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\runpy.pyc in _run_code(code, run_globals, init_globals, mod_name, mod_fname, mod_loader, pkg_name) 70 __loader__ = mod_loader, 71 __package__ = pkg_name) ---> 72 exec code in run_globals 73 return run_globals 74 D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\trace.py in () 817 818 if __name__=='__main__': --> 819 main() D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\trace.py in main(argv) 770 771 if not (count or trace or report or listfuncs or countcallers): --> 772 _err_exit("must specify one of --trace, --count, --report, " 773 "--listfuncs, or --trackcalls") 774 D:\Users\sharanb\AppData\Local\Enthought\Canopy\edm\envs\User\lib\trace.py in _err_exit(msg) 655 def _err_exit(msg): 656 sys.stderr.write("%s: %s\n" % (sys.argv[0], msg)) --> 657 sys.exit(1) 658 659 def main(argv=None): SystemExit: 1 I don't know where I am going wrong. From sharan.basappa at gmail.com Sat Jun 30 13:02:13 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 30 Jun 2018 10:02:13 -0700 (PDT) Subject: Logger option Message-ID: Can anyone tell me if there are some good logger modules in Python. I have tried both logging and trace in Canopy and both are not working. Any help is appreciated. From nospam at yrl.co.uk Sat Jun 30 13:10:26 2018 From: nospam at yrl.co.uk (Elliott Roper) Date: Sat, 30 Jun 2018 18:10:26 +0100 Subject: I lost nearly all my modules installing 3.7 References: <0001HW.20E54D9E037B46DA700000D972CF@news.giganews.com> <0001HW.20E59C82038DC45270000F6362CF@news.giganews.com> <0001HW.20E7075803E2CEB770000F6362CF@news.giganews.com> <87a7rcangk.fsf@handshake.de> Message-ID: <0001HW.20E7F1020419929170000F6362CF@news.giganews.com> On 30 Jun 2018, dieter wrote (in article): > Elliott Roper writes: > > ... > > install scipy wrote an error message longer than War and Peace that finished > > with:- > > ____________________________________________________________________________ > > error: library dfftpack has Fortran sources but no Fortran compiler found > > An error message of the type I like: precise: > Install a "Fortran compiler" and try again. > > > ... > > and matplotlib produced a beautifully formatted report that started with: > > __________________ > > Complete output from command python setup.py egg_info: > > IMPORTANT WARNING: > > This is a warning only (even though it is marked as important). > > > pkg-config is not installed. > > matplotlib may not be able to find some of its dependencies > > And the warning message is precise again: install "pkg-config" > to get rid of it. > > I do not know "pkg-config". The name seems to indicate an > operating system package; but, it might also be a Python extension > package (less likely). > I would start with the "matplotlib" > installation instructions to look for information about it. Thanks Jim and dieter. I should have mentioned that none of this went wrong in 3.6. All I'm after are packages I can install with pip3. I really don't need to go down all the twisty passages installing Fortran I DID have pkg-config installed in ~/Library ..... site-packages. I uninstalled it and re-installed with an Admin account, where it appeared in /Library ... site-packages but that made no difference, pip3 install -- user matplotlib still complaining about pkg-config not being installed and not being able to find png I was wrong about Both look like not having write access to /private/var/folders/v2/gj68t3zx3bd6764zxc332ctc0000gr/T/pip-install- np76k73m/ I do have write access. It looks like a Mac specific per user directory tree for temporary stuff and installation records. I really am out of my depth here. I have found a post with a very similar problem on Stack Exchange https://stackoverflow.com/questions/51082934/matplotlib-2-2-2-installation- error-on-high-sierra sadly without an answer -- To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96 3CF7 637F 896B C810 E199 7E5C A9E4 8E59 E248 From Karsten.Hilbert at gmx.net Sat Jun 30 13:10:47 2018 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sat, 30 Jun 2018 19:10:47 +0200 Subject: Logger option In-Reply-To: References: Message-ID: <20180630171047.GF6376@hermes.hilbert.loc> On Sat, Jun 30, 2018 at 10:02:13AM -0700, Sharan Basappa wrote: > I have tried both logging and trace in Canopy and both are not working. You will have to be more specific. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From jlee54 at gmail.com Sat Jun 30 13:54:23 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sat, 30 Jun 2018 10:54:23 -0700 Subject: error in os.chdir In-Reply-To: <8592a986-cd16-439a-8d8a-4f95a13c1fcd@googlegroups.com> References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> <20180630111621.GB6376@hermes.hilbert.loc> <0e8eaf4e-83af-4e36-a260-a166ee560094@googlegroups.com> <20180630131242.GD6376@hermes.hilbert.loc> <8592a986-cd16-439a-8d8a-4f95a13c1fcd@googlegroups.com> Message-ID: <837a9597-0116-f436-ade8-7e5d6d62d1d7@gmail.com> On 06/30/18 07:34, Sharan Basappa wrote: > > sorry. I mean why my code worked in one case but did not in the other one. > > This worked - os.chdir('D:\Projects\Initiatives\machine learning\programs') > > This did not work - os.chdir('D:\Projects\Initiatives\machine learning\programs\assertion') > > only difference is, I added an additional directory in the problematic case. > In Python (and many other languages), certain non-printable characters are represented in strings by "escape sequences".? Those escape sequences begin with a backslash "\".? In your particular case, there are five (possible) escape sequences: "\P", "\I", "\m", "\p", and "\a".? All but the last one have no meaning to Python, so they are treated literally.? The last one, however, translates to "BEL", or 0x07, which is a non-printable code that was once sent to teletypes to ring the bell, alerting the operator to an incoming message, or to signal the completion of a long-running job. There are three ways to fix your code.? One is to replace the backslashes with forward slashes.? Python will translate them internally to the correct path separators for your operating system. Another way is to replace the backslashes with os.sep, which is a portable representation of the native path separator. A third way is to escape all literal backslashes by doubling them - "\\" instead of "\".? However, this will make your code Windows-only (but it already is, so that may not matter to you). -Jim From hjp-python at hjp.at Sat Jun 30 14:19:51 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 30 Jun 2018 20:19:51 +0200 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> Message-ID: <20180630181951.vwcgixxvu67a2ksb@hjp.at> On 2018-06-28 18:04:16 -0700, Dan Stromberg wrote: > On Thu, Jun 28, 2018 at 1:27 PM, Marko Rauhamaa wrote: > > Dan Stromberg : > > > On Wed, Jun 27, 2018 at 10:31 PM, Marko Rauhamaa > > > wrote: > > >> Dan Stromberg : > > >> >> > The problem can be solved by turning on the SO_REUSEADDR flag of > > >> >> > the socket. > > >> > BTW, it's a security feature you're turning off. If you're on a > > >> > multiuser box, it prevents a second user from stealing lingering > > >> > connections from a first user on the same port. [...] > Start an echo server process P that listens on tcp/5555. > > Initiate a connection from a client machine to process P at tcp/5555. It > works as expected. > > Kill P. > > Initiate a connection from a client machine to process P at tcp/5555. It > gives a connection refused as expected. > > If someone else comes along soon after and starts a different echo server > process Q at tcp/5555 on the same server, it starts up immediately if P > used SO_REUSEADDR. > > Then initiate a connection from the same (or different) client machine to > process P (which no longer exists). Q gets the data intended for P. I don't think this is the issue TIME_WAIT is intended to prevent. Firstly, why would this security issue stop to be a security issue after two minutes? Secondly, it depends on the attacker not knowing about SO_REUSEADDR, which seems overly optimistic. What TIME_WAIT is IMHO intended to prevent is mixing up two TCP connections: You have just killed P, but some packets from a connection are still in transit. Now you start P again and one of the clients starts another connection. While this connection is active, a packet from the previous connection arrives. If its sequence number is in the right range, it will be accepted as part of the current connection. This can be prevented by not restarting the server until all packets for old connections are guarantueed to have expired. In practice this scenario is pretty unlikely: Not only has the client have to get the same client port, it also needs to get the sequence numbers (which are 32 bit numbers chosen at random at connection time) just right. OTOH, having to wait 2 minutes before you can restart your server is a nuisance. Therefore, everybody uses SO_REUSEADDR. 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 jlee54 at gmail.com Sat Jun 30 14:51:36 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sat, 30 Jun 2018 11:51:36 -0700 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> Message-ID: On 06/28/18 18:04, Dan Stromberg wrote: > [snip] > Start an echo server process P that listens on tcp/5555. > > Initiate a connection from a client machine to process P at tcp/5555. It > works as expected. > > Kill P. > > Initiate a connection from a client machine to process P at tcp/5555. It > gives a connection refused as expected. > > If someone else comes along soon after and starts a different echo server > process Q at tcp/5555 on the same server, it starts up immediately if P > used SO_REUSEADDR. > > Then initiate a connection from the same (or different) client machine to > process P (which no longer exists). Q gets the data intended for P. > > There are all sorts of theoretical vulnerabilities that simply don't manifest in real life.? I think this is one of them. Me: "It hurts when I do this."? Doctor: "Well, don't do that." -Jim From drsalists at gmail.com Sat Jun 30 17:01:56 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 30 Jun 2018 14:01:56 -0700 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: <20180630181951.vwcgixxvu67a2ksb@hjp.at> References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <20180630181951.vwcgixxvu67a2ksb@hjp.at> Message-ID: On Sat, Jun 30, 2018 at 11:19 AM, Peter J. Holzer wrote: > On 2018-06-28 18:04:16 -0700, Dan Stromberg wrote: > > On Thu, Jun 28, 2018 at 1:27 PM, Marko Rauhamaa > wrote: > > Start an echo server process P that listens on tcp/5555. > > > > Initiate a connection from a client machine to process P at tcp/5555. It > > works as expected. > > > > Kill P. > > > > Initiate a connection from a client machine to process P at tcp/5555. It > > gives a connection refused as expected. > > > > If someone else comes along soon after and starts a different echo server > > process Q at tcp/5555 on the same server, it starts up immediately if P > > used SO_REUSEADDR. > > > > Then initiate a connection from the same (or different) client machine to > > process P (which no longer exists). Q gets the data intended for P. > > I don't think this is the issue TIME_WAIT is intended to prevent. > It handles more than one thing. Firstly, why would this security issue stop to be a security issue after > two minutes? It's a mitigation of both problems we've discussed. > Secondly, it depends on the attacker not knowing about > SO_REUSEADDR, which seems overly optimistic. > Not really, no. People on remote machines know little about process bounces. And it's pretty easy to write a script that will check if a process is up repeatedly, starting a daemon when its not. And you don't have to know about SO_REUSEADDR to write that script. What TIME_WAIT is IMHO intended to prevent is mixing up two TCP > connections: > Yes, it does this too. This can be prevented by not restarting the server until all packets for > old connections are guarantueed to have expired. > Yes, and not using SO_REUSEADDR helps this happen. > In practice this scenario is pretty unlikely: Not only has the client > have to get the same client port, it also needs to get the sequence > numbers (which are 32 bit numbers chosen at random at connection time) > just right. > Right, it's a mitigation. OTOH, having to wait 2 minutes before you can restart your server is a > nuisance. Therefore, everybody uses SO_REUSEADDR. > During development, it's a good practice to setsockopt SO_REUSEADDR. In production, different rules may or may not apply. On multiuser systems, it's more important than on most of today's single-purpose virtual machines. Some people feel that "security issues" must all be religiously 100% avoided completely, or they'll offend the computer gods. This evidences a lack of understanding about the practical aspects of security issues. Security is very much a spectrum - multidimensional even. From hjp-python at hjp.at Sat Jun 30 17:49:41 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 30 Jun 2018 23:49:41 +0200 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <20180630181951.vwcgixxvu67a2ksb@hjp.at> Message-ID: <20180630214941.j7tc4ar6xzdyvp55@hjp.at> On 2018-06-30 14:01:56 -0700, Dan Stromberg wrote: > On Sat, Jun 30, 2018 at 11:19 AM, Peter J. Holzer wrote: > > On 2018-06-28 18:04:16 -0700, Dan Stromberg wrote: > > > If someone else comes along soon after and starts a different echo server ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > > process Q at tcp/5555 on the same server, it starts up immediately if P > > > used SO_REUSEADDR. > > > > > > Then initiate a connection from the same (or different) client machine to > > > process P (which no longer exists). Q gets the data intended for P. > > > > I don't think this is the issue TIME_WAIT is intended to prevent. [...] > > Secondly, it depends on the attacker not knowing about > > SO_REUSEADDR, which seems overly optimistic. > > > Not really, no. People on remote machines know little about process > bounces. But the attack you described isn't remote. It is performed by another user on the same machine. > And it's pretty easy to write a script that will check if a process is > up repeatedly, starting a daemon when its not. Right. This is something the attacker can do (and I would assume they do). > And you don't have to know about SO_REUSEADDR to write that script. No. But if the attacker does know about SO_REUSEADDR they can start their own server as soon as the notice that the server is down. Otherwise they have to wait for two minutes. Actually, I overlooked something: If you don't use SO_REUSEADDR, but the attacker does, you have to wait, but the attacker doesn't - so this gives a huge advantage to the attacker. If you do use SO_REUSEADDR, at least you are an equal footing. > OTOH, having to wait 2 minutes before you can restart your server is a > > nuisance. Therefore, everybody uses SO_REUSEADDR. > > > During development, it's a good practice to setsockopt SO_REUSEADDR. > > In production, different rules may or may not apply. On multiuser systems, In production, being able to restart a failed server quickly is usually more important than to prevent a very low probability mixup on the TCP level. Especially as you can't rely on TCP for integrity and confidentiality anyway and have to put an extra layer (typically TLS) for that on top. > it's more important than on most of today's single-purpose virtual machines. > > Some people feel that "security issues" must all be religiously 100% > avoided completely, or they'll offend the computer gods. This evidences a > lack of understanding about the practical aspects of security issues. > Security is very much a spectrum - multidimensional even. I agree fully. The old adage that "security is binary" is utter balderdash. However, I do feel that we should only call something a "security feature" if it actually increases security. Not using SO_REUSEADDR doesn't - quite the opposite. 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 brgrt2 at gmail.com Sat Jun 30 18:01:48 2018 From: brgrt2 at gmail.com (T Berger) Date: Sat, 30 Jun 2018 15:01:48 -0700 (PDT) Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: <20180629225955.GA75408@cskk.homeip.net> Message-ID: On Friday, June 29, 2018 at 7:00:15 PM UTC-4, Cameron Simpson wrote: > The key point here from Jim is "simultaneously". Are you properly shutting down > the Flask instance in IDLE before running from Terminal, and vice versa? Cameron, I try every option to quit either program, but they don't work. Or I should say, they mostly don't work. Once in a while they do. The one option which works (which is not a feasible option) is rebooting my Mac (actually that might not work either. I think I got the error message again this morning when I rebooted). > Otherwise both will try to use the same local port and There Can Be Only One. > > Do you need to run from both environments at the same time? I'd have thought > not, which also leads me to: why are you flicking from IDLE to Terminal? I > would have imagined using one or the other normally, not both. It isn't wrong > to use both, just surprising. I'm working from a Python manual. I created the webapp in IDLE, and test it in Terminal, per the instructions in the manual. I use IDLE to edit my program, and then test it in terminal. When I go from one to the other, I get the error message. IDLE has a keyboard shortcut for quitting the shell?Cntl + C?but it doesn't work. Neither does restarting the shell. Neither does entering the kill command line, not in IDLE or terminal. Do you have any other suggestions? I'm going to email the writer. He doesn't mention how to deal with problems that might arise from working with two programs at the same time. Maybe Cntl+C should do it, but in my case it doesn't. Tamara > Cheers, > Cameron Simpson From tjreedy at udel.edu Sat Jun 30 18:03:00 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 30 Jun 2018 18:03:00 -0400 Subject: naming methods in python (std lib) In-Reply-To: References: Message-ID: On 6/30/2018 7:27 AM, Abdur-Rahmaan Janhangeer wrote: > normally, naming methods in python is given by > > method_name > > but i see some cases where this is not followed in the std lib > > ex : dict.fromkeys > > should it not have been > > from_keys? No. _ is an option, not a requirement and usually not used for short names. -- Terry Jan Reedy From tjreedy at udel.edu Sat Jun 30 18:05:22 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 30 Jun 2018 18:05:22 -0400 Subject: is my interpreation correct In-Reply-To: <70c46c14-c425-45fc-8174-e321e3e09848@googlegroups.com> References: <70c46c14-c425-45fc-8174-e321e3e09848@googlegroups.com> Message-ID: On 6/30/2018 8:57 AM, Sharan Basappa wrote: > A code I am using as reference has the following line: > from nltk.stem.lancaster import LancasterStemmer The CapitalName indicates a class. > I am inferring the following based on above: > 1) nltk is a package > 2) nltk itself may have module because I see - nltk.word_tokenize(pattern['sentence']) in the code word_tokenize is a function. > 3) nltk has a package named stem which has another package named Lancaster that has LancasterStemmer package Sometimes one should read the docs instead of guessing. -- Terry Jan Reedy From tjreedy at udel.edu Sat Jun 30 18:14:07 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 30 Jun 2018 18:14:07 -0400 Subject: using trace module in enthought In-Reply-To: <5f2a977e-da7a-4e76-a0e2-dd8406518fec@googlegroups.com> References: <5f2a977e-da7a-4e76-a0e2-dd8406518fec@googlegroups.com> Message-ID: On 6/30/2018 12:46 PM, Sharan Basappa wrote: > I am using enthought for python. Trace module seems to be very useful for my work but somehow I am unable to make it work. > > When I use the following option, I get the following error: > %run What is 'run' and what does it do? Does not exist on Windows. And why use it instead of 'python'? What OS? What Python version? -m trace --trace "D:/Projects/Initiatives/machine learning/programs/debug_1.py" > UsageError: option --trace not recognized ( allowed: "nidtN:b:pD:l:rs:T:em:G" ) This does not look error message from current trace module. f:\dev\3x>python -m trace -x Running Debug|Win32 interpreter... usage: trace.py [-h] [--version] [-c] [-t] [-l] [-T] [-r | -R] [-f FILE] [-C COVERDIR] [-m] [-s] [-g] [--ignore-module IGNORE_MODULE] [--ignore-dir IGNORE_DIR] [filename] ... trace.py: error: unrecognized arguments: -x -- Terry Jan Reedy From python at mrabarnett.plus.com Sat Jun 30 18:39:14 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 30 Jun 2018 23:39:14 +0100 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: <20180629225955.GA75408@cskk.homeip.net> Message-ID: On 2018-06-30 23:01, T Berger wrote: > On Friday, June 29, 2018 at 7:00:15 PM UTC-4, Cameron Simpson wrote: > >> The key point here from Jim is "simultaneously". Are you properly shutting down >> the Flask instance in IDLE before running from Terminal, and vice versa? > > Cameron, I try every option to quit either program, but they don't work. Or I should say, they mostly don't work. Once in a while they do. The one option which works (which is not a feasible option) is rebooting my Mac (actually that might not work either. I think I got the error message again this morning when I rebooted). > >> Otherwise both will try to use the same local port and There Can Be Only One. >> >> Do you need to run from both environments at the same time? I'd have thought >> not, which also leads me to: why are you flicking from IDLE to Terminal? I >> would have imagined using one or the other normally, not both. It isn't wrong >> to use both, just surprising. > > I'm working from a Python manual. I created the webapp in IDLE, and test it in Terminal, per the instructions in the manual. I use IDLE to edit my program, and then test it in terminal. When I go from one to the other, I get the error message. IDLE has a keyboard shortcut for quitting the shell?Cntl + C?but it doesn't work. Neither does restarting the shell. Neither does entering the kill command line, not in IDLE or terminal. Ctrl+C is the shortcut for interrupting a Python program running on IDLE's or Windows command line. In IDLE's editor, Ctrl+C is the shortcut for copying text the clipboard. The keyboard shortcut for quitting IDLE completely is Ctrl+Q. > > Do you have any other suggestions? I'm going to email the writer. He doesn't mention how to deal with problems that might arise from working with two programs at the same time. Maybe Cntl+C should do it, but in my case it doesn't. > From cs at cskk.id.au Sat Jun 30 19:04:31 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 1 Jul 2018 09:04:31 +1000 Subject: $s and %d in python In-Reply-To: <9ca45498-9b40-4214-88b3-445545332f87@googlegroups.com> References: <9ca45498-9b40-4214-88b3-445545332f87@googlegroups.com> Message-ID: <20180630230431.GA77467@cskk.homeip.net> On 30Jun2018 05:01, Sharan Basappa wrote: >Is there any difference in %d and %s below. I get the same result: > >my_name = 'Zed A. Shaw' >my_age = 35 # not a lie >my_height = 74 # inches > >print "Let's talk about %s." % my_name >print "He's %d inches tall." % my_height >print "He's %s inches tall." % my_height > >Let's talk about Zed A. Shaw. >He's 74 inches tall. >He's 74 inches tall. %d interpolates a decimal string repesentation of a numeric value. %s interpolates the default "str" representation of an arbitrary value. The variable my_height is an int, and for an int both these things are the same. Try: my_height = 7.3 and see what you get. Cheers, Cameron Simpson From eryksun at gmail.com Sat Jun 30 19:36:40 2018 From: eryksun at gmail.com (eryk sun) Date: Sat, 30 Jun 2018 23:36:40 +0000 Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sat, Jun 30, 2018 at 11:21 AM, Chris Angelico wrote: > On Sat, Jun 30, 2018 at 9:05 PM, Sharan Basappa > wrote: >> >> 0 >> down vote >> favorite >> >> I need to change directory to my local working directory in windows and then open a file for processing. >> Its just a 3 lines code, as below: >> import csv >> import os >> os.chdir('D:\Projects\Initiatives\machine learning\programs\assertion') >> The error is as follows: >> WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'D:\Projects\Initiatives\machine learning\programs\x07ssertion' >> Notice x07 character that has replaced character x07. >> I have a similar code but that goes through fine: >> import csv >> import os >> os.chdir('D:\Projects\Initiatives\machine learning\programs') > > Use forward slashes instead of backslashes for all paths. > > os.chdir('D:/Projects/Initiatives/machine learning/programs') Only use forward slashes for legacy DOS paths passed to Windows API functions. Do not use forward slashes for paths in command line arguments, \\?\ prefixed paths, or registry paths. From greg.ewing at canterbury.ac.nz Sat Jun 30 19:41:06 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 01 Jul 2018 11:41:06 +1200 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <877emif9d1.fsf@elektro.pacujo.net> Message-ID: Dan Stromberg wrote: > On Thu, Jun 28, 2018 at 10:30 PM, Marko Rauhamaa wrote: > >>Well, the same security issue can be demonstrated without SO_REUSEADDR: >> >>The security issue can be real but is not directly related with >>SO_REUSEADDR. > > Yes, it can. It just takes longer. I don't see how the address-reuse timeout can be a security measure, because the process trying to take over the address can easily circumvent it by setting SO_REUSEADDR. -- Greg From rosuav at gmail.com Sat Jun 30 19:42:42 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Jul 2018 09:42:42 +1000 Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sun, Jul 1, 2018 at 9:36 AM, eryk sun wrote: > On Sat, Jun 30, 2018 at 11:21 AM, Chris Angelico wrote: >> On Sat, Jun 30, 2018 at 9:05 PM, Sharan Basappa >> wrote: >>> >>> 0 >>> down vote >>> favorite >>> >>> I need to change directory to my local working directory in windows and then open a file for processing. >>> Its just a 3 lines code, as below: >>> import csv >>> import os >>> os.chdir('D:\Projects\Initiatives\machine learning\programs\assertion') >>> The error is as follows: >>> WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'D:\Projects\Initiatives\machine learning\programs\x07ssertion' >>> Notice x07 character that has replaced character x07. >>> I have a similar code but that goes through fine: >>> import csv >>> import os >>> os.chdir('D:\Projects\Initiatives\machine learning\programs') >> >> Use forward slashes instead of backslashes for all paths. >> >> os.chdir('D:/Projects/Initiatives/machine learning/programs') > > Only use forward slashes for legacy DOS paths passed to Windows API > functions. Do not use forward slashes for paths in command line > arguments, \\?\ prefixed paths, or registry paths. "Legacy" implies that it's the old standard that is now deprecated, but the truth is that MOST path names are going to work fine with forward slashes. Registry paths aren't file paths, command line arguments are interpreted by the target program (and in many MANY cases, forward slashes are absolutely fine), and so it's just the \\?\ paths that will need to be special. So, let me rephrase what you said: Forward slashes work for all Windows file paths, except those that are prefixed with \\?\. Is that correct? ChrisA From tjreedy at udel.edu Sat Jun 30 19:43:57 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 30 Jun 2018 19:43:57 -0400 Subject: $s and %d in python In-Reply-To: <20180630230431.GA77467@cskk.homeip.net> References: <9ca45498-9b40-4214-88b3-445545332f87@googlegroups.com> <20180630230431.GA77467@cskk.homeip.net> Message-ID: On 6/30/2018 7:04 PM, Cameron Simpson wrote: > On 30Jun2018 05:01, Sharan Basappa wrote: >> Is there any difference in %d and %s below. I get the same result: >> >> my_name = 'Zed A. Shaw' >> my_age = 35 # not a lie >> my_height = 74 # inches >> >> print "Let's talk about %s." % my_name >> print "He's %d inches tall." % my_height >> print "He's %s inches tall." % my_height >> >> Let's talk about Zed A. Shaw. >> He's 74 inches tall. >> He's 74 inches tall. > > %d interpolates a decimal string repesentation of a numeric value > %s interpolates the default "str" representation of an arbitrary value. > > The variable my_height is an int, and for an int both these things are > the same. > > Try: > > ?my_height = 7.3 > > and see what you get. or my_height = '74' -- Terry Jan Reedy From tjreedy at udel.edu Sat Jun 30 19:51:44 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 30 Jun 2018 19:51:44 -0400 Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On 6/30/2018 7:36 PM, eryk sun wrote: > On Sat, Jun 30, 2018 at 11:21 AM, Chris Angelico wrote: >> On Sat, Jun 30, 2018 at 9:05 PM, Sharan Basappa >> wrote: >>> >>> 0 >>> down vote >>> favorite >>> >>> I need to change directory to my local working directory in windows and then open a file for processing. >>> Its just a 3 lines code, as below: >>> import csv >>> import os >>> os.chdir('D:\Projects\Initiatives\machine learning\programs\assertion') >>> The error is as follows: >>> WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'D:\Projects\Initiatives\machine learning\programs\x07ssertion' >>> Notice x07 character that has replaced character x07. >>> I have a similar code but that goes through fine: >>> import csv >>> import os >>> os.chdir('D:\Projects\Initiatives\machine learning\programs') >> >> Use forward slashes instead of backslashes for all paths. >> >> os.chdir('D:/Projects/Initiatives/machine learning/programs') > > Only use forward slashes for legacy DOS paths passed to Windows API > functions. Do not use forward slashes for paths in command line > arguments, \\?\ prefixed paths, or registry paths. To the best of my memeory, forward slashes work in arguments. They do not work in paths to an executable. F:\>cd dev/3x works f:\dev\3x> ../pull prints '..' is not recognized as an internal or external command, operable program or batch file. because /pull is seen as an option switch. ..\pull does (because ..\pull.bat exists). -- Terry Jan Reedy From grant.b.edwards at gmail.com Sat Jun 30 20:09:12 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 1 Jul 2018 00:09:12 +0000 (UTC) Subject: EXTERNAL: OSError: [Errno 48] Address already in use References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <877emif9d1.fsf@elektro.pacujo.net> Message-ID: On 2018-06-30, Gregory Ewing wrote: > Dan Stromberg wrote: >> On Thu, Jun 28, 2018 at 10:30 PM, Marko Rauhamaa wrote: >> >>>Well, the same security issue can be demonstrated without SO_REUSEADDR: >>> >>>The security issue can be real but is not directly related with >>>SO_REUSEADDR. >> >> Yes, it can. It just takes longer. > > I don't see how the address-reuse timeout can be a security > measure, because the process trying to take over the address > can easily circumvent it by setting SO_REUSEADDR. I've been thinking the same thing. One _might_ be able to argue against the OS providing the SO_REUSEADDR option on security grounds. But given that it _does_ exist, I don't see how using it can be claimed to decrease security. -- Grant From eryksun at gmail.com Sat Jun 30 20:20:54 2018 From: eryksun at gmail.com (eryk sun) Date: Sun, 1 Jul 2018 00:20:54 +0000 Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sat, Jun 30, 2018 at 11:42 PM, Chris Angelico wrote: > On Sun, Jul 1, 2018 at 9:36 AM, eryk sun wrote: >> On Sat, Jun 30, 2018 at 11:21 AM, Chris Angelico wrote: >>> On Sat, Jun 30, 2018 at 9:05 PM, Sharan Basappa >>> wrote: >>>> >>>> 0 >>>> down vote >>>> favorite >>>> >>>> I need to change directory to my local working directory in windows and then open a file for processing. >>>> Its just a 3 lines code, as below: >>>> import csv >>>> import os >>>> os.chdir('D:\Projects\Initiatives\machine learning\programs\assertion') >>>> The error is as follows: >>>> WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'D:\Projects\Initiatives\machine learning\programs\x07ssertion' >>>> Notice x07 character that has replaced character x07. >>>> I have a similar code but that goes through fine: >>>> import csv >>>> import os >>>> os.chdir('D:\Projects\Initiatives\machine learning\programs') >>> >>> Use forward slashes instead of backslashes for all paths. >>> >>> os.chdir('D:/Projects/Initiatives/machine learning/programs') >> >> Only use forward slashes for legacy DOS paths passed to Windows API >> functions. Do not use forward slashes for paths in command line >> arguments, \\?\ prefixed paths, or registry paths. > > "Legacy" implies that it's the old standard that is now deprecated, I did not mean to imply that DOS paths are deprecated. That's not what legacy means to me. I only meant that they're inherited from an old system. The native API does not use forward slash as a path separator. It's just a name character in NT (except in most file-system implementations, which reserve forward slash as an invalid filename character to avoid confusion). This doesn't affect device names. You can call DefineDosDevice or native NtCreateSymbolicLinkObject to create a device name with a slash in it. The Windows file API supports forward slash as a path separator, which it implements by rewriting the path via ntdll library functions such as RtlDosPathNameToNtPathName_U_WithStatus. Paths prefixed with \\?\ bypass this normalization step, so they cannot use forward slash as the path separator. > Registry paths aren't file paths, You said to use forward slash for "all paths". Also, from the POV of the NT API, registry paths and file paths are all just paths, such as "\Registry\Machine\Software" and "\Device\HarddiskVolume2\Program Files". The executive's Object Manager parses the path up to an object with a ParseProcedure (e.g. "Registry" or "HarddiskVolume2"), which in turn parses the rest of the path. Registry paths in the Windows API are closer to native NT paths, since they don't support forward slash as a path separator and implement relative paths NT style, i.e. relative to a Key handle. The Windows API doesn't expose handle-relative paths for file paths, but it uses this feature implicitly by keeping a handle open for the process working directory. > command line arguments are interpreted by the target program (and in many > MANY cases, forward slashes are absolutely fine), You can't generalize this. In many cases it's not ok. Most command-line utilities that use ulib make a simply assumption when parsing the command line that forward slash is used for options (switches). It's best to normalize paths in a command line via os.path.normpath. From steve+comp.lang.python at pearwood.info Sat Jun 30 21:44:00 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 1 Jul 2018 01:44:00 +0000 (UTC) Subject: error in os.chdir References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sat, 30 Jun 2018 23:36:40 +0000, eryk sun wrote: > Only use forward slashes for legacy DOS paths passed to Windows API > functions. Do not use forward slashes for paths in command line > arguments, \\?\ prefixed paths, or registry paths. I don't see why this is relevant, or at least not the "command line arguments" and "registry paths" parts. We're talking about using file names in Python, not the Windows command line (Power Shell?), and not registry paths. I guess that if the user is using a path beginning with \\?\ they may or may not need to use backslashes, but I have no way of testing it, and I would expect that Python will correctly replace //?/ with backslashes the same as it does for any other file system path. I know that Chris said "for all paths" but in context that's to be understood as *file system paths*. We wouldn't interpret him as meaning this: import package/subpackage/module instead of using dots, so I think registry paths is irrelevant. (Besides, Python doesn't have an API for interacting directly with the registry.) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sat Jun 30 21:47:34 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 1 Jul 2018 01:47:34 +0000 (UTC) Subject: list initialize with ? References: <7d02e275-3847-4220-a0d1-4d2abd6b839a@googlegroups.com> Message-ID: On Sat, 30 Jun 2018 05:49:03 -0700, Sharan Basappa wrote: > On Saturday, 30 June 2018 17:48:05 UTC+5:30, Steven D'Aprano wrote: >> On Sat, 30 Jun 2018 04:50:10 -0700, Sharan Basappa wrote: >> >> > Can anyone explain to me what the ? does here: >> > >> > ignore_words = ['?'] >> >> Its a question mark inside a string, which is inside a list. You can >> put anything you like in strings: [...] > oh, ok. I assumed that ? has some special meaning. I should be able to > find out more. It could have whatever special meaning the creator of the code chooses to give it. Without knowing the context of what you are doing with it, what libraries you are using, what functions it gets passed to, it could mean anything. Your question is like asking: "I have a variable called x, what does it mean?" Without more information, how could we tell? > PS: Actually, its not my code. I am using an online code as reference > for my research. Then you should check the documentation for this online code. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sat Jun 30 21:48:08 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 1 Jul 2018 01:48:08 +0000 (UTC) Subject: list initialize with ? References: <7d02e275-3847-4220-a0d1-4d2abd6b839a@googlegroups.com> Message-ID: On Sat, 30 Jun 2018 05:49:03 -0700, Sharan Basappa wrote: > On Saturday, 30 June 2018 17:48:05 UTC+5:30, Steven D'Aprano wrote: >> On Sat, 30 Jun 2018 04:50:10 -0700, Sharan Basappa wrote: >> >> > Can anyone explain to me what the ? does here: >> > >> > ignore_words = ['?'] >> >> Its a question mark inside a string, which is inside a list. You can >> put anything you like in strings: [...] > oh, ok. I assumed that ? has some special meaning. I should be able to > find out more. It could have whatever special meaning the creator of the code chooses to give it. Without knowing the context of what you are doing with it, what libraries you are using, what functions it gets passed to, it could mean anything. Your question is like asking: "I have a variable called x, what does it mean?" Without more information, how could we tell? > PS: Actually, its not my code. I am using an online code as reference > for my research. Then you should check the documentation for this online code. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sat Jun 30 21:52:12 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 1 Jul 2018 01:52:12 +0000 (UTC) Subject: EXTERNAL: OSError: [Errno 48] Address already in use References: <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <20180630181951.vwcgixxvu67a2ksb@hjp.at> <20180630214941.j7tc4ar6xzdyvp55@hjp.at> Message-ID: On Sat, 30 Jun 2018 23:49:41 +0200, Peter J. Holzer wrote: > The old adage that "security is binary" is utter balderdash. I think that "old adage" is one of those ones that only people denying it actually use. I've never seen anyone say "security is binary" except to disagree with it, "don't make the mistake of thinking security is binary". I mean, we lock our front doors, even though burglars can break in through a window, right? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sat Jun 30 21:58:19 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Jul 2018 11:58:19 +1000 Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sun, Jul 1, 2018 at 10:20 AM, eryk sun wrote: > On Sat, Jun 30, 2018 at 11:42 PM, Chris Angelico wrote: >> "Legacy" implies that it's the old standard that is now deprecated, > > I did not mean to imply that DOS paths are deprecated. That's not what > legacy means to me. Unless you are Humpty Dumpty, you can't just say "that's not what it means to me". Sorry. People WILL see "legacy" as an implication that "only the old stuff goes that way". You are responding to a thread in which someone used a perfectly ordinary file path, and you said that only legacy paths can be done with slashes. At best, you are technically correct and functionally deceptive. >> Registry paths aren't file paths, > > You said to use forward slash for "all paths". *facepalm* Okay. I said "all paths", but I did not refer to XPath (although that also uses the slash character), nor registry paths, nor the footpath that runs parallel to the road outside my house. You're absolutely right, there are no forward slashes in the path that leads to my door. My bad. I'm sorry that the word "all" has to be interpreted within the context of the thread that it was used in. Whoops. >> command line arguments are interpreted by the target program (and in many >> MANY cases, forward slashes are absolutely fine), > > You can't generalize this. In many cases it's not ok. Most > command-line utilities that use ulib make a simply assumption when > parsing the command line that forward slash is used for options > (switches). It's best to normalize paths in a command line via > os.path.normpath. Ahh but I *can* generalize it. In many cases, forward slashes ARE fine, and I can prove it by listing off large numbers of programs that are perfectly happy to receive file paths with slashes in them. Surprise surprise, most of those programs are going to be taking those paths and handing them straight to the OS. In other words: THE OS SUPPORTS SLASHES. Does this surprise anyone? So what if, internally, that's done by converting them to backslashes? No Python program needs to care. In fact, there are other conversions, too - the underlying file system is most likely using UTF-16 paths, but your Python program needn't use UTF-16. No, it simply uses a plain old string literal - a Unicode string. The OP need not be concerned about any of these fiddlinesses, unless in some way they actually affect Python. Congratulations on being technically correct (maybe) and utterly unhelpful. ChrisA From steve+comp.lang.python at pearwood.info Sat Jun 30 22:03:59 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 1 Jul 2018 02:03:59 +0000 (UTC) Subject: Logger option References: Message-ID: On Sat, 30 Jun 2018 10:02:13 -0700, Sharan Basappa wrote: > Can anyone tell me if there are some good logger modules in Python. I > have tried both logging and trace in Canopy and both are not working. When you are talking about a standard module used by hundreds of thousands or millions of programmers around the world, and it "doesn't work", the chances are 99.9999999% certain that you are using it wrong, not that everyone else is too stupid to have noticed that their code isn't working. If you want help for using logging, start here: https://docs.python.org/3/howto/logging.html https://docs.python.org/2/howto/logging.html https://pymotw.com/3/logging/ https://pymotw.com/2/logging/ https://www.google.com/search?q=logging+getting+started+python -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sat Jun 30 22:11:54 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Jul 2018 12:11:54 +1000 Subject: Logger option In-Reply-To: References: Message-ID: On Sun, Jul 1, 2018 at 12:03 PM, Steven D'Aprano wrote: > On Sat, 30 Jun 2018 10:02:13 -0700, Sharan Basappa wrote: > >> Can anyone tell me if there are some good logger modules in Python. I >> have tried both logging and trace in Canopy and both are not working. > > When you are talking about a standard module used by hundreds of > thousands or millions of programmers around the world, and it "doesn't > work", the chances are 99.9999999% certain that you are using it wrong, > not that everyone else is too stupid to have noticed that their code > isn't working. To be fair, the OP said that it isn't working *in Canopy*, so it could be an interaction between the logging module and Canopy (which I have no experience with). So what I'd recommend is something like: https://www.google.com/search?q=python+logging+canopy and seeing if that gives any useful information. ChrisA From eryksun at gmail.com Sat Jun 30 22:22:41 2018 From: eryksun at gmail.com (eryk sun) Date: Sun, 1 Jul 2018 02:22:41 +0000 Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sun, Jul 1, 2018 at 1:58 AM, Chris Angelico wrote: > On Sun, Jul 1, 2018 at 10:20 AM, eryk sun wrote: >> On Sat, Jun 30, 2018 at 11:42 PM, Chris Angelico wrote: >>> "Legacy" implies that it's the old standard that is now deprecated, >> >> I did not mean to imply that DOS paths are deprecated. That's not what >> legacy means to me. > > Unless you are Humpty Dumpty, you can't just say "that's not what it > means to me". Sorry. People WILL see "legacy" as an implication that > "only the old stuff goes that way". You are responding to a thread in > which someone used a perfectly ordinary file path, and you said that > only legacy paths can be done with slashes. At best, you are > technically correct and functionally deceptive. That's fine, and I understand how I could have been misconstrued. I clarified what I meant. I did not intend to be deceptive. >>> Registry paths aren't file paths, >> >> You said to use forward slash for "all paths". > > *facepalm* Okay. I said "all paths", but I did not refer to XPath > (although that also uses the slash character), nor registry paths, nor > the footpath that runs parallel to the road outside my house. You're > absolutely right, there are no forward slashes in the path that leads > to my door. My bad. I'm sorry that the word "all" has to be > interpreted within the context of the thread that it was used in. > Whoops. I also clarified why to me your "all paths" statement needs to be qualified to the domain. I use the native API a lot, so for me registry and file paths are just paths. It's only the Windows API that separates the two and only the Windows API that allows forward slash as a path separator in file paths. >>> command line arguments are interpreted by the target program (and in many >>> MANY cases, forward slashes are absolutely fine), >> >> You can't generalize this. In many cases it's not ok. Most >> command-line utilities that use ulib make a simply assumption when >> parsing the command line that forward slash is used for options >> (switches). It's best to normalize paths in a command line via >> os.path.normpath. > > Ahh but I *can* generalize it. In many cases, forward slashes ARE > fine, and I can prove it by listing off large numbers of programs that > are perfectly happy to receive file paths with slashes in them. > Surprise surprise, most of those programs are going to be taking those > paths and handing them straight to the OS. In other words: THE OS > SUPPORTS SLASHES. Does this surprise anyone? There are many cases for common command-line utilities that do not support paths with forward slash -- even if you disambiguate by putting the path in double quotes. In the following examples, I have a file named "C:\Temp\test.txt" and an existing directory named "C:\Temp\dest". Internal CMD commands: C:\>dir /b "C:/Temp/test.txt" File Not Found C:\>type "C:/Temp/test.txt" The system cannot find the file specified. C:\>copy "C:/Temp/test.txt" "C:/Temp/dest" The system cannot find the file specified. 0 file(s) copied. C:\>del "C:/Temp/test.txt" The system cannot find the path specified. External utility commands: C:\>find "spam" "C:/Temp/*.txt" File not found - C:TEST.TXT C:\>findstr "spam" "C:/Temp/*.txt" FINDSTR: Cannot open C:test.txt C:\>fc "C:/Temp/test.txt" "C:/Temp/*.txt" FC: cannot open C:/TEMP/TEST.TXT - No such file or folder C:\>forfiles /p "C:/Temp" /m *.txt ERROR: The directory name is invalid. C:\>where /r "C:/Temp" test.txt ERROR: Invalid directory specified. C:\>icacls "C:/Temp/*.txt" C:test.txt: The system cannot find the file specified. Successfully processed 0 files; Failed processing 1 files C:\>takeown /f "C:/Temp/test.txt" ERROR: File or Directory not found. C:\>xcopy.exe "C:/Temp/test.txt" "C:/Temp/dest" 0 File(s) copied In the following case I create "C:\Temp\dest\test.txt" to be replaced using replace.exe, which silently fails to replace the file: C:\>replace "C:/Temp/test.txt" "C:/Temp/dest" C:\>fc C:\Temp\test.txt C:\Temp\dest\test.txt Comparing files C:\TEMP\test.txt and C:\TEMP\DEST\TEST.TXT ***** C:\TEMP\test.txt spam ***** C:\TEMP\DEST\TEST.TXT eggs ***** > So what if, internally, that's done by converting them to backslashes? > No Python program needs to care. In fact, there are other conversions, > too - the underlying file system is most likely using UTF-16 paths, > but your Python program needn't use UTF-16. No, it simply uses a plain > old string literal - a Unicode string. The OP need not be concerned > about any of these fiddlinesses, unless in some way they actually > affect Python. A few minor changes in in wording are both technically correct and don't make the text any more difficult to understand. You're the one blowing this up beyond proportion and making a mountain out of a small technical-correction mole hill. Please just let it pass. From rosuav at gmail.com Sat Jun 30 22:28:07 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Jul 2018 12:28:07 +1000 Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sun, Jul 1, 2018 at 12:22 PM, eryk sun wrote: >> So what if, internally, that's done by converting them to backslashes? >> No Python program needs to care. In fact, there are other conversions, >> too - the underlying file system is most likely using UTF-16 paths, >> but your Python program needn't use UTF-16. No, it simply uses a plain >> old string literal - a Unicode string. The OP need not be concerned >> about any of these fiddlinesses, unless in some way they actually >> affect Python. > > A few minor changes in in wording are both technically correct and > don't make the text any more difficult to understand. You're the one > blowing this up beyond proportion and making a mountain out of a small > technical-correction mole hill. Please just let it pass. If you can show me a way in which a Python program actually needs to care about any of these distinctions when dealing with files on Windows, then I'll admit that the technical correction was needed. You won't be shelling out to the "dir" command, for instance. ChrisA From greg.ewing at canterbury.ac.nz Sat Jun 30 22:30:12 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 01 Jul 2018 14:30:12 +1200 Subject: $s and %d in python In-Reply-To: References: <9ca45498-9b40-4214-88b3-445545332f87@googlegroups.com> <20180630230431.GA77467@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > The variable my_height is an int, and for an int both these things are > the same. But note that 'd' and 's' can give different results when other formatting options are present, e.g. >>> "%05d" % 42 '00042' >>> "%05s" % 42 ' 42' -- Greg From eryksun at gmail.com Sat Jun 30 22:43:21 2018 From: eryksun at gmail.com (eryk sun) Date: Sun, 1 Jul 2018 02:43:21 +0000 Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sun, Jul 1, 2018 at 2:28 AM, Chris Angelico wrote: > On Sun, Jul 1, 2018 at 12:22 PM, eryk sun wrote: >>> So what if, internally, that's done by converting them to backslashes? >>> No Python program needs to care. In fact, there are other conversions, >>> too - the underlying file system is most likely using UTF-16 paths, >>> but your Python program needn't use UTF-16. No, it simply uses a plain >>> old string literal - a Unicode string. The OP need not be concerned >>> about any of these fiddlinesses, unless in some way they actually >>> affect Python. >> >> A few minor changes in in wording are both technically correct and >> don't make the text any more difficult to understand. You're the one >> blowing this up beyond proportion and making a mountain out of a small >> technical-correction mole hill. Please just let it pass. > > If you can show me a way in which a Python program actually needs to > care about any of these distinctions when dealing with files on > Windows, then I'll admit that the technical correction was needed. You > won't be shelling out to the "dir" command, for instance. Python has no built-in support for Windows file security, so a Python program may decided to use icacls.exe, takeown.exe, or xcopy.exe (copy owner/ACL). It's best in general to normalize paths when integrating an external program -- unless you've already checked that the program(s) you're running support forward slash without a problem. Checking this in each case isn't worth the trouble when it's so simple to call normpath(). Doing a quick test isn't sufficient. Programs that fail in this case do so in different ways and not always consistently. Using forward slash may work in some cases (e.g. passing a explicit file vs passing a wildcard pattern), which may give someone a false perception that the program intentionally supports forward slash as a path separator, when it's only working by accident of implementation. From rosuav at gmail.com Sat Jun 30 22:48:58 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Jul 2018 12:48:58 +1000 Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sun, Jul 1, 2018 at 12:43 PM, eryk sun wrote: > On Sun, Jul 1, 2018 at 2:28 AM, Chris Angelico wrote: >> On Sun, Jul 1, 2018 at 12:22 PM, eryk sun wrote: >>>> So what if, internally, that's done by converting them to backslashes? >>>> No Python program needs to care. In fact, there are other conversions, >>>> too - the underlying file system is most likely using UTF-16 paths, >>>> but your Python program needn't use UTF-16. No, it simply uses a plain >>>> old string literal - a Unicode string. The OP need not be concerned >>>> about any of these fiddlinesses, unless in some way they actually >>>> affect Python. >>> >>> A few minor changes in in wording are both technically correct and >>> don't make the text any more difficult to understand. You're the one >>> blowing this up beyond proportion and making a mountain out of a small >>> technical-correction mole hill. Please just let it pass. >> >> If you can show me a way in which a Python program actually needs to >> care about any of these distinctions when dealing with files on >> Windows, then I'll admit that the technical correction was needed. You >> won't be shelling out to the "dir" command, for instance. > > Python has no built-in support for Windows file security, so a Python > program may decided to use icacls.exe, takeown.exe, or xcopy.exe (copy > owner/ACL). It's best in general to normalize paths when integrating > an external program -- unless you've already checked that the > program(s) you're running support forward slash without a problem. > Checking this in each case isn't worth the trouble when it's so simple > to call normpath(). Doing a quick test isn't sufficient. Programs that > fail in this case do so in different ways and not always consistently. > Using forward slash may work in some cases (e.g. passing a explicit > file vs passing a wildcard pattern), which may give someone a false > perception that the program intentionally supports forward slash as a > path separator, when it's only working by accident of implementation. Cool. Okay, so for people who don't know about pywin32, it's important to properly wrap up arguments to some of the external programs you might need. I'll grant you that. Internally, use forward slashes; then when you need to shell out to something, you process the arguments into something that will be accepted. ChrisA From eryksun at gmail.com Sat Jun 30 23:18:23 2018 From: eryksun at gmail.com (eryk sun) Date: Sun, 1 Jul 2018 03:18:23 +0000 Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sun, Jul 1, 2018 at 1:44 AM, Steven D'Aprano wrote: > On Sat, 30 Jun 2018 23:36:40 +0000, eryk sun wrote: > >> Only use forward slashes for legacy DOS paths passed to Windows API >> functions. Do not use forward slashes for paths in command line >> arguments, \\?\ prefixed paths, or registry paths. > > I don't see why this is relevant, or at least not the "command line > arguments" and "registry paths" parts. Command-line arguments are relevant to executing a child process, e.g. via subprocess.Popen. > I guess that if the user is using a path beginning with \\?\ they may or > may not need to use backslashes, but I have no way of testing it, and I > would expect that Python will correctly replace //?/ with backslashes the > same as it does for any other file system path. The Windows API handles this, but not for a path that begins with \\?\. The intent of this prefix is to bypass DOS-path normalization -- allowing paths with length up to 32K characters that can use otherwise reserved DOS-device names or names ending in spaces or dots. > (Besides, Python doesn't have an API for interacting directly with the > registry.) The standard library has winreg -- or _winreg in 2.x. Bear in mind that forward slash is just a name character in NT. If a coder assumes that Windows automatically replaces forward slash with backslash for registry paths, it could lead to a mistake such as the following: >>> hkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER, 'test') >>> subkeya = winreg.CreateKey(hkey, 'test_a1/test_a2/test_a3') >>> subkeyb = winreg.CreateKey(hkey, 'test_b1\\test_b2\\test_b3') >>> winreg.EnumKey(hkey, 0) 'test_a1/test_a2/test_a3' >>> winreg.EnumKey(hkey, 1) 'test_b1' In the test_a case, instead of a tree of keys "test_a1\test_a2\test_a3", we get a single key named "test_a1/test_a2/test_a3". The test_b case creates the intended tree. I grant that having to explicitly say that forward slash isn't supported in registry paths is certainly beyond what's required, as is having to state that forward slash isn't supported in the native API (e.g. NtCreateFile, NtOpenFile). We only need to clearly state that the Windows API allows using forward slash as the path separator in file paths that do not begin with the \\?\ prefix. I prefer to also add a warning about command-line arguments, since it isn't an improbable or inconsequential problem, and it's so easy to state upfront rather than letting someone waste hours unravelling a cryptic failure, given the path separator isn't something one is likely to consider as the source of the problem.